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

from judgment import Session, implies


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

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

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