"""Inspect open and deferred goals, then the finished theorem."""

from judgment import Session, implies


def main():
    s = Session()
    P = s.prop("P")
    proof = s.theorem("duplicate", implies(P, P & P))
    premise = proof.intro("premise")
    proof.split()
    print("After splitting:")
    print(proof.format())
    captured = proof.obligations()[0]
    assert len(captured.assumptions()) == 1

    left = proof.select("left")
    left.exact(premise)
    right = proof.select("right")
    right.sorry()
    print("After solving left and deferring right:")
    print(proof.format())
    assert len(proof.obligations()) == 1

    # A Goal is a snapshot. Select the outstanding goal again before resuming it.
    right = proof.select(proof.obligations()[0])
    right.resume()
    right.exact(premise)
    print("Before finish:")
    print(proof.format())
    assert len(proof.obligations()) == 0
    theorem = proof.finish()
    print("Theorem:", theorem)
    print("Axioms:", len(theorem.axioms()), "Admissions:", len(theorem.admissions()))


if __name__ == "__main__":
    main()
