"""Rewrite one occurrence in a nested expression using explicit evidence."""

from judgment import Session, implies


def main():
    s = Session()
    P = s.prop("P")
    Q = s.prop("Q")
    R = s.prop("R")
    before = (~P & R) | (~P & R)
    after = (~P & R) | (~Q & R)
    target = implies(P == Q, before == after)
    proof = s.theorem("rewrite_second", target)
    h = proof.intro("h")

    _ = proof.lhs().at(P, occurrence=2).to(Q, using=h)
    proof.rfl()
    theorem = proof.finish()
    assert theorem.statement().same_as(target)
    print(theorem)


if __name__ == "__main__":
    main()
