"""Specify constants by a theorem, and define an overloaded constant at two types."""

from judgment import Session, forall, implies


def main():
    s = Session()
    T = s.declare_type("T")
    z = s.symbol("z", T)

    # A witness of the form ∀v. v = t → φ specifies a constant satisfying φ, with no equation.
    witness = s.theorem("witness")
    v = witness.bound_var("v", T)
    witness.goal(forall(v, implies(v == z, v == z)))
    t = witness.tactics()
    _ = witness.by(t.intro_var("a").then(t.intro("h")).then(t.assumption()))
    spec = s.specification(["c"], witness.finish())
    print(spec.law())

    # An overloaded constant has one opaque equation per instance.
    header = s.overloaded("default")
    A = header.type_var("A")
    default = header.finish(A)
    at_t = s.instance_definition(default, [T], z)
    print(at_t)
    print(s.instance_definition(default, [s.prop_type()], s.true_()))
    proof = s.theorem("default_is_z", default.symbol([T]) == z)
    proof.exact(at_t)
    print(proof.finish())


if __name__ == "__main__":
    main()
