"""Shared, explicitly assumed commutative ring laws for arithmetic examples."""

from judgment import Expr, Fact, JudgmentError, Session, TypeExpr


def assume_commutative_ring_laws(s, kind, zero, one, prefix):
    """Declare eight named axioms using the carrier's bound arithmetic notation.

    Addition, multiplication, and negation must already be bound. Each axiom is
    published as prefix.slot. The returned entries can be extended with order
    or coefficient laws before constructing ArithmeticLaws. This assumes laws;
    it does not prove them or register exact arithmetic.
    """
    names = ["add_assoc", "add_comm", "add_zero", "mul_assoc", "mul_comm", "mul_one", "add_inverse", "left_distrib"]
    arities = [3, 2, 1, 3, 2, 1, 1, 3]
    entries = []
    for i in range(len(names)):
        law = s.axiom(prefix + "." + names[i])
        x = law.var("x", kind)
        y = zero
        z = zero
        if arities[i] > 1:
            y = law.var("y", kind)
        if arities[i] > 2:
            z = law.var("z", kind)
        statement = None
        if i == 0:
            statement = (x + y) + z == x + (y + z)
        elif i == 1:
            statement = x + y == y + x
        elif i == 2:
            statement = zero + x == x
        elif i == 3:
            statement = (x * y) * z == x * (y * z)
        elif i == 4:
            statement = x * y == y * x
        elif i == 5:
            statement = one * x == x
        elif i == 6:
            statement = x + (-x) == zero
        else:
            statement = x * (y + z) == x * y + x * z
        entries.append((names[i], law.finish(statement)))
    return entries
