"""Prove a square-of-sum identity through three readable, checked steps."""

from judgment import Session
from arithmetic_setup import arithmetic_setup


def main() raises:
    var s = Session()
    var algebra = arithmetic_setup(s)
    var proof = s.theorem("sum_squared")
    var ab = proof.vars("a b", algebra.kind)
    var a, b = ab[0], ab[1]
    proof.goal((a + b)**2 == a**2 + 2 * a * b + b**2)

    _ = (
        proof.lhs()
        .change((a + b) * (a + b))
        .to(a**2 + a * b + b * a + b**2, using=algebra.expand)
        .to(a**2 + 2 * a * b + b**2, using=algebra.collect)
    )
    proof.rfl()
    var theorem = proof.finish()
    print(theorem)
