"""Use an existential fact through its scoped witness and checked property."""

from judgment import Session, arrow, exists, implies


def main():
    s = Session()
    proof = s.theorem("project_exists")
    A = proof.type_var("A")
    P = proof.var("P", arrow(A, s.prop_type()))
    Q = proof.var("Q", arrow(A, s.prop_type()))
    x = proof.bound_var("x", A)
    proof.goal(implies(exists(x, P(x) & Q(x)), exists(x, P(x))))

    h = proof.intro()
    w, hw = proof.obtain(h, "w")
    print("Witness:", w.format())
    print("Its property:", hw.statement().format())
    proof.witness(w)
    proof.exact(proof.left(hw))

    theorem = proof.finish()
    print(theorem)
    print("Axiom dependencies:", len(theorem.axioms()))


if __name__ == "__main__":
    main()
