Skip to content

ring

data RingExpr

Syntax of commutative-semiring expressions over Nat: variables by index, numerals, sums and products.

def ringNth (ρ : List Nat) (i : Nat) : Nat

Looks up the i-th variable in an environment, defaulting to zero when the index is out of range.

def ringEval (ρ : List Nat) (e : RingExpr) : Nat

Evaluates a ring expression in Nat under the given variable environment.

def ringLeN (m : Nat) (n : Nat) : Bool

Boolean less-or-equal on Nat, used to order variables inside monomials.

def monoLe (a : List Nat) (b : List Nat) : Bool

Lexicographic comparison of monomials, used to keep polynomials sorted (affects completeness only).

def monoEval (ρ : List Nat) (m : List Nat) : Nat

Evaluates a monomial (a list of variable indices) as the product of those variables.

def monoInsB (b : Bool) (i : Nat) (j : Nat) (t : List Nat) (rest : List Nat) : List Nat

Insertion step for monoIns: places i before j when the comparison flag is true, otherwise keeps j and uses the recursive result.

def monoIns (i : Nat) (m : List Nat) : List Nat

Inserts a variable index into a sorted monomial.

def ringMulSwap (a : Nat) (b : Nat) (c : Nat) : mul b (mul a c) = mul a (mul b c)

Swapping the outer factors of a nested product: b * (a * c) equals a * (b * c).

def monoInsBSound (ρ : List Nat) (b : Bool) (i : Nat) (j : Nat) (t : List Nat) (rest : List Nat) (ih : monoEval ρ rest = mul (ringNth ρ i) (monoEval ρ t)) : monoEval ρ (monoInsB b i j t rest) = mul (ringNth ρ i) (mul (ringNth ρ j) (monoEval ρ t))

Soundness of one monoInsB step: the result evaluates to i’s value times j’s value times the tail.

def monoInsSound (ρ : List Nat) (i : Nat) (m : List Nat) : monoEval ρ (monoIns i m) = mul (ringNth ρ i) (monoEval ρ m)

Soundness of monoIns: inserting i multiplies the monomial’s value by the value of variable i.

def monoMul (m : List Nat) (n : List Nat) : List Nat

Multiplies two monomials by merging their sorted variable lists.

def monoMulSound (ρ : List Nat) (m : List Nat) (n : List Nat) : monoEval ρ (monoMul m n) = mul (monoEval ρ m) (monoEval ρ n)

Soundness of monoMul: the product monomial evaluates to the product of the two values.

def polyEval (ρ : List Nat) (p : List (List Nat)) : Nat

Evaluates a polynomial (a list of monomials) as the sum of its monomials.

def ringAddSwap (a : Nat) (b : Nat) (c : Nat) : add b (add a c) = add a (add b c)

Swapping the outer summands of a nested sum: b + (a + c) equals a + (b + c).

def polyInsB (b : Bool) (m : List Nat) (n : List Nat) (t : List (List Nat)) (rest : List (List Nat)) : List (List Nat)

Insertion step for polyIns: places m before n when the comparison flag is true, otherwise keeps n and uses the recursive result.

def polyIns (m : List Nat) (p : List (List Nat)) : List (List Nat)

Inserts a monomial into a sorted polynomial.

def polyInsBSound (ρ : List Nat) (b : Bool) (m : List Nat) (n : List Nat) (t : List (List Nat)) (rest : List (List Nat)) (ih : polyEval ρ rest = add (monoEval ρ m) (polyEval ρ t)) : polyEval ρ (polyInsB b m n t rest) = add (monoEval ρ m) (add (monoEval ρ n) (polyEval ρ t))

Soundness of one polyInsB step: the result evaluates to m’s value plus n’s value plus the tail.

def polyInsSound (ρ : List Nat) (m : List Nat) (p : List (List Nat)) : polyEval ρ (polyIns m p) = add (monoEval ρ m) (polyEval ρ p)

Soundness of polyIns: inserting a monomial adds its value to the polynomial’s value.

def polyAdd (p : List (List Nat)) (q : List (List Nat)) : List (List Nat)

Adds two polynomials by inserting the monomials of the first into the second.

def polyAddSound (ρ : List Nat) (p : List (List Nat)) (q : List (List Nat)) : polyEval ρ (polyAdd p q) = add (polyEval ρ p) (polyEval ρ q)

Soundness of polyAdd: the sum polynomial evaluates to the sum of the two values.

def polyScale (m : List Nat) (q : List (List Nat)) : List (List Nat)

Multiplies every monomial of a polynomial by a fixed monomial.

def polyScaleSound (ρ : List Nat) (m : List Nat) (q : List (List Nat)) : polyEval ρ (polyScale m q) = mul (monoEval ρ m) (polyEval ρ q)

Soundness of polyScale: scaling by a monomial multiplies the polynomial’s value by that monomial’s value.

def polyMul (p : List (List Nat)) (q : List (List Nat)) : List (List Nat)

Multiplies two polynomials by distributing over the monomials of the first.

def polyMulSound (ρ : List Nat) (p : List (List Nat)) (q : List (List Nat)) : polyEval ρ (polyMul p q) = mul (polyEval ρ p) (polyEval ρ q)

Soundness of polyMul: the product polynomial evaluates to the product of the two values.

def polyNum (n : Nat) : List (List Nat)

Represents a numeral n as the polynomial with n copies of the empty (unit) monomial.

def polyNumSound (ρ : List Nat) (n : Nat) : polyEval ρ (polyNum n) = n

Soundness of polyNum: the polynomial for n evaluates to n.

def ringNorm (e : RingExpr) : List (List Nat)

Normalizes a ring expression to a sorted polynomial; this is the computation the ring tactic relies on.

def ringNormSound (ρ : List Nat) (e : RingExpr) : polyEval ρ (ringNorm e) = ringEval ρ e

Soundness of the ring normalizer: the normal form evaluates to the same value as the expression under every environment.

def ringEq (ρ : List Nat) (a : RingExpr) (b : RingExpr) (h : ringNorm a = ringNorm b) : ringEval ρ a = ringEval ρ b

The certificate the ring tactic produces: equal normal forms imply equal values under every environment.

def ringEqTestComm (x : Nat) (y : Nat) : mul x y = mul y x

Example of using ringEq directly to prove commutativity of multiplication without the tactic.