"""Prove a common consequence in two independently scoped cases."""

from judgment import Session, implies


def main():
    s = Session()
    P = s.prop("P")
    Q = s.prop("Q")
    R = s.prop("R")
    proof = s.theorem("common_consequence")
    either = proof.given("either", P | Q)
    from_p = proof.given("from_p", implies(P, R))
    from_q = proof.given("from_q", implies(Q, R))
    proof.goal(R)

    _ = proof.cases(either, left_name="hp", right_name="hq")
    p_case = proof.select("left")
    _ = p_case.apply(from_p, using=[p_case.fact("hp")])
    q_case = proof.select("right")
    _ = q_case.apply(from_q, using=[q_case.fact("hq")])

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


if __name__ == "__main__":
    main()
