"""Retain replacement results and discard temporary work explicitly."""

from judgment import Session


def main():
    s = Session()
    scope = s.transaction()
    P = s.prop("P")
    proof = s.theorem("reflexivity", P == P)
    proof.rfl()
    kept = scope.commit(expressions=[P], facts=[proof.finish()])

    live_P = kept.expressions()[0]
    reused = s.theorem("reused", live_P == live_P)
    reused.exact(kept.facts()[0])
    print(reused.finish())

    temporary = s.transaction()
    _ = s.prop("temporary")
    temporary.discard()
    print("Registered theorems:", len(s.find()))


if __name__ == "__main__":
    main()
