"""Seal a base theory snapshot, then open a new Session over it and import its declarations."""

from judgment import Session, arrow, forall


def main():
    # Build a base theory in one session and seal it into an immutable Snapshot.
    base = Session()
    nat = base.declare_type("nat")
    zero = base.symbol("zero", nat)
    succ = base.symbol("succ", arrow(nat, nat))
    n = base.bound_var("n", nat)
    _ = base.axiom("succ_ne_zero", forall(n, ~(succ(n) == zero)))
    snapshot = base.seal()

    # Open a new session over the snapshot and import the declarations it needs.
    s = Session.open(snapshot)
    N = s.import_type("nat")
    z = s.import_symbol("zero")
    S = s.import_symbol("succ")
    axiom = s.import_fact("succ_ne_zero")
    print(axiom)
    proof = s.theorem("one_ne_zero", ~(S(z) == z))
    proof.exact(proof.use(axiom, terms=[z]))
    result = proof.finish()
    print(result)
    print(result.axioms()[0], N.format())
    exported = result.step()
    print(len(exported.hypotheses()) == 0)


if __name__ == "__main__":
    main()
