1-- Natural numbers inside a ring: ringNat(add, zero, one, n) is the n-fold sum2-- of one. Scoped ring numerals above 1 elaborate to it, and the ring tactic3-- adds and multiplies such coefficients through the laws proved here.4-- Part of Cumulus, the Grace17 mathematics library.5-- Copyright (c) 2026 Grant Passmore.6-- Released under the Apache License 2.0. See LICENSE in the repository root.7-- Authors: Grant Passmore89module Grace.Cumulus.Algebra.Ring.Numeral10import Core11import Nat.Core1213def ringNat (plus z u : Set, n : Nat) →Set14| plus, z, u, zero => z15| plus, z, u, succ(k) => plus(ringNat(plus, z, u, k), u)1617theorem ringNat.zero (add zero one : Set)18shows ringNat(add, zero, one, 0) = zero19proof20simp [ringNat]2122theorem ringNat.succ (add zero one : Set, n : Nat)23shows ringNat(add, zero, one, succ(n)) =24 call2(add, ringNat(add, zero, one, n), one)25proof26simp [ringNat]2728theorem IsRing.numeral_closed (A add zero neg mul one : Set, n : Nat)29requiresring : IsRing(A, add, zero, neg, mul, one)30shows ringNat(add, zero, one, n) ∈ A31proof32induction n33| zero =>34rw ringNat.zero35exact IsRing.zero_in_carrier withring36| succ(k) using ih =>37have monoid := IsRing.multiplicative withring38have oneInA := IsMonoid.unit_in_carrier with monoid39rw ringNat.succ40exact IsRing.add_closed withring, ih, oneInA4142theorem IsRing.numeral_one (A add zero neg mul one : Set)43requiresring : IsRing(A, add, zero, neg, mul, one)44shows ringNat(add, zero, one, 1) = one45proof46have monoid := IsRing.multiplicative withring47have oneInA := IsMonoid.unit_in_carrier with monoid48simp [ringNat]49exact IsRing.add_left_identity withring, oneInA5051theorem IsCommRing.numeral_add (A add zero neg mul one : Set, m n : Nat)52requiresring : IsCommRing(A, add, zero, neg, mul, one)53shows ringNat(add, zero, one, m + n) =54 call2(add, ringNat(add, zero, one, m), ringNat(add, zero, one, n))55proof56induction n57| zero =>58have ordinary := IsCommRing.ring withring59have mInA := IsRing.numeral_closed at A, add, zero, neg, mul, one, m60with ordinary61rw [add.right_unit, ringNat.zero]62have rightIdentity := IsRing.add_right_identity with ordinary, mInA63rw rightIdentity64rfl65| succ(k) using ih =>66have ordinary := IsCommRing.ring withring67have mInA := IsRing.numeral_closed at A, add, zero, neg, mul, one, m68with ordinary69have kInA := IsRing.numeral_closed at A, add, zero, neg, mul, one, k70with ordinary71have monoid := IsRing.multiplicative with ordinary72have oneInA := IsMonoid.unit_in_carrier with monoid73rw [add.succ_right, ringNat.succ, ringNat.succ, ih]74have reassociate := IsCommRing.add_assoc withring, mInA, kInA, oneInA75rw reassociate76rfl7778theorem IsCommRing.numeral_mul (A add zero neg mul one : Set, m n : Nat)79requiresring : IsCommRing(A, add, zero, neg, mul, one)80shows ringNat(add, zero, one, m * n) =81 call2(mul, ringNat(add, zero, one, m), ringNat(add, zero, one, n))82proof83induction n84| zero =>85have ordinary := IsCommRing.ring withring86have mInA := IsRing.numeral_closed at A, add, zero, neg, mul, one, m87with ordinary88rw [mul.right_zero, ringNat.zero]89have annihilate := IsRing.mul_zero with ordinary, mInA90rw annihilate91rfl92| succ(k) using ih =>93have ordinary := IsCommRing.ring withring94have mInA := IsRing.numeral_closed at A, add, zero, neg, mul, one, m95with ordinary96have kInA := IsRing.numeral_closed at A, add, zero, neg, mul, one, k97with ordinary98have monoid := IsRing.multiplicative with ordinary99have oneInA := IsMonoid.unit_in_carrier with monoid100have productInA := IsRing.mul_closed with ordinary, mInA, kInA101rw [mul.succ_right, ringNat.succ]102havesplit:= IsCommRing.numeral_add at A, add, zero, neg, mul, one, m,103 m * k104withring105rw [split, ih]106have distribute := IsCommRing.mul_add withring, mInA, kInA, oneInA107have unit := IsCommRing.one_right withring, mInA108have commute := IsCommRing.add_comm withring, mInA, productInA109rw [distribute, unit, commute]110rfl111