"""Rewrite beneath a quantifier through an explicit fresh-variable scope."""

from judgment import Session, forall


def main():
    s = Session()
    A = s.declare_type("A")
    proof = s.theorem("replace_under_forall")
    values = proof.vars("a b", A)
    a, b = values[0], values[1]
    equality = proof.given("equality", a == b)
    x = proof.bound_var("x", A)
    proof.goal(forall(x, x == a) == forall(x, x == b))

    opened = proof.lhs().under("z")
    _ = opened.body().at(a).rw(equality)
    _ = opened.finish()
    proof.rfl()
    print(proof.finish())


if __name__ == "__main__":
    main()
