"""State a generic theorem with typed parameters and rewrite an argument."""

from judgment import Session, arrow


def main():
    s = Session()
    proof = s.theorem("congruence")
    A = proof.type_var("A")
    a = proof.var("a", A)
    b = proof.var("b", A)
    f = proof.var("f", arrow(A, A))
    h = proof.given("h", a == b)
    proof.goal(f(a) == f(b))

    _ = proof.lhs().at(a).rw(h)
    proof.rfl()
    theorem = proof.finish()
    assert theorem.type_params()[0].same_as(A)
    assert theorem.statement().format() == "∀a:A. ∀b:A. ∀f:(A → A). a = b → f(a) = f(b)"
    print(theorem)


if __name__ == "__main__":
    main()
