Grace/Cumulus/Algebra/Polynomial/BundledCoefficients.g17

Open in Workbench Download source

Imports

Grace.Cumulus.Algebra.Polynomial.DerivativeCoefficients · Grace.Cumulus.Algebra.Polynomial.Bundled

Declarations

Source

1-- The coefficient engine of the bundled polynomial ring: membership in2-- polynomialRing(R, I) is membership in the polynomial carrier, equality3-- is coefficientwise, the sum, negative, zero, and product have their4-- coefficient formulas, and the coefficients of a variable, a constant,5-- and a product by either are read off; everything here is ZF6-- Part of Cumulus, the Grace17 mathematics library.7-- Copyright (c) 2026 Grant Passmore.8-- Released under the Apache License 2.0. See LICENSE in the repository root.9-- Authors: Grant Passmore1011module Grace.Cumulus.Algebra.Polynomial.BundledCoefficients12import Grace.Cumulus.Algebra.Polynomial.DerivativeCoefficients13import Grace.Cumulus.Algebra.Polynomial.Bundled1415-- The bundled polynomial ring and its coefficient engine: membership in16-- the ring is membership in the polynomial carrier, equality is17-- coefficientwise, and the sum, negative, zero, and product have their18-- coefficient formulas.19section Carrier20variable (R I : Set)21hypothesis ring : CommRing(R)22hypothesis polynomials : CommRing(polynomialRing(R, I))2324theorem polynomialRing.member_parts (p : polynomialRing(R, I))25  shows p ∈ polynomials(I, R.carrier, R.zero)26proof27  have member : p ∈ Ring.carrier(polynomialRing(R, I)) by assumption28  rw polynomialRing.carrierOf at member29  exact member3031theorem polynomialRing.member_of_parts (p : Set)32  requires polynomial : p ∈ polynomials(I, R.carrier, R.zero)33  shows p ∈ Ring.carrier(polynomialRing(R, I))34proof35  rw polynomialRing.carrierOf36  exact polynomial3738theorem polynomialRing.coefficient_mem (p : polynomialRing(R, I)) (m : Set)39  requires monomial : m ∈ monomials(I)40  shows p(m) ∈ R.carrier41proof42  have polynomial := polynomialRing.member_parts at R, I, p with *43  exact polynomials.coefficient with polynomial, monomial4445theorem polynomialRing.ext (p q : polynomialRing(R, I))46  requires coefficients : ∀ m ∈ monomials(I), p(m) = q(m)47  shows p = q48proof49  have left := polynomialRing.member_parts at R, I, p with *50  have right := polynomialRing.member_parts at R, I, q with *51  exact polynomials.ext with left, right, coefficients5253theorem polynomialRing.add_apply (p q : polynomialRing(R, I))54  shows p + q = coefficientAdd(monomials(I), R.carrier, R.add, R.zero, R.neg,55    R.mul, R.one, p, q)56proof57  have parts := CommRing.parts with ring58  have left := polynomialRing.member_parts at R, I, p with *59  have right := polynomialRing.member_parts at R, I, q with *60  have value := polynomialAdd.apply at I, R.carrier, R.add, R.zero, R.neg,61    R.mul, R.one, p, q with *62  rw polynomialRing.addOf63  exact value6465theorem polynomialRing.coefficient_add (p q : polynomialRing(R, I)) (m : Set)66  requires monomial : m ∈ monomials(I)67  shows (p + q)(m) = call2(R.add, p(m), q(m))68proof69  have parts := CommRing.parts with ring70  have left := polynomialRing.member_parts at R, I, p with *71  have right := polynomialRing.member_parts at R, I, q with *72  have functionP := polynomials.function with left73  have functionQ := polynomials.function with right74  have sum := polynomialRing.add_apply at R, I, p, q with *75  rw sum76  exact coefficientAdd.value at monomials(I), R.carrier, R.add, R.zero, R.neg,77    R.mul, R.one, p, q, m with *7879theorem polynomialRing.neg_apply (p : polynomialRing(R, I))80  shows -p = coefficientNeg(monomials(I), R.carrier, R.add, R.zero, R.neg,81    R.mul, R.one, p)82proof83  have parts := CommRing.parts with ring84  have member := polynomialRing.member_parts at R, I, p with *85  have value := polynomialNeg.apply at I, R.carrier, R.add, R.zero, R.neg,86    R.mul, R.one, p with *87  rw polynomialRing.negOf88  exact value8990theorem polynomialRing.coefficient_neg (p : polynomialRing(R, I)) (m : Set)91  requires monomial : m ∈ monomials(I)92  shows (-p)(m) = R.neg(p(m))93proof94  have parts := CommRing.parts with ring95  have member := polynomialRing.member_parts at R, I, p with *96  have function := polynomials.function with member97  have negative := polynomialRing.neg_apply at R, I, p with *98  rw negative99  exact coefficientNeg.value at monomials(I), R.carrier, R.add, R.zero, R.neg,100    R.mul, R.one, p, m with *101102theorem polynomialRing.coefficient_zero (m : Set)103  requires monomial : m ∈ monomials(I)104  shows Ring.zero(polynomialRing(R, I))(m) = R.zero105proof106  have zeroIn : R[0] ∈ R := Ring.zero_mem with *107  rw polynomialRing.zeroOf108  exact constantFunction.apply with monomial, zeroIn109110theorem polynomialRing.mul_apply (p q : polynomialRing(R, I))111  shows p * q = polynomialProduct(I, R.carrier, R.add, R.zero, R.neg, R.mul,112    R.one, p, q)113proof114  have parts := CommRing.parts with ring115  have left := polynomialRing.member_parts at R, I, p with *116  have right := polynomialRing.member_parts at R, I, q with *117  have value := polynomialMul.apply at I, R.carrier, R.add, R.zero, R.neg,118    R.mul, R.one, p, q with *119  rw polynomialRing.mulOf120  exact value121122-- The coefficients of a variable and of a constant.123theorem X.coefficient_same (j : Set)124  requires member : j ∈ I125  shows X(R, I, j)(monomialVariable(I, j)) = R.one126proof127  have zeroIn : R[0] ∈ R := Ring.zero_mem with *128  have oneIn : R[1] ∈ R := Ring.one_mem with *129  rw X.value130  exact polynomialVariable.coefficient at I, R.carrier, R.zero, R.one, j with *131132theorem X.coefficient_other (j n : Set)133  requires monomial : n ∈ monomials(I)134  requires different : n ≠ monomialVariable(I, j)135  shows X(R, I, j)(n) = R.zero136proof137  have zeroIn : R[0] ∈ R := Ring.zero_mem with *138  have oneIn : R[1] ∈ R := Ring.one_mem with *139  rw X.value140  unfold polynomialVariable141  exact polynomialTerm.other at I, R.carrier, R.zero, R.one,142    monomialVariable(I, j), n with *143144theorem polynomialConstant.coefficient_other (a : R) (n : Set)145  requires monomial : n ∈ monomials(I)146  requires different : n ≠ monomialOne(I)147  shows polynomialConstant(R, I)(a)(n) = R.zero148proof149  have aIn : a ∈ R by assumption150  have zeroIn : R[0] ∈ R := Ring.zero_mem with *151  have value := polynomialConstant.apply at R, I, a with *152  have selected :=153    polynomialConstant.value at I, R.carrier, R.zero, a, n with *154  have other :=155    singleValue.other at R.carrier, R.zero, a, monomialOne(I), n with *156  rw [value, selected, other]157  rfl158159-- The coefficients of a product by a constant and by a variable: a160-- constant scales every coefficient; Xⱼ moves the coefficient at n to the161-- monomial Xⱼ·n and leaves zero at every monomial with exponent zero in j.162theorem polynomialRing.constant_mul (a : R) (q : polynomialRing(R, I)) (m : Set)163  requires monomial : m ∈ monomials(I)164  shows (polynomialConstant(R, I)(a) * q)(m) = call2(R.mul, a, q(m))165proof166  have aIn : a ∈ R by assumption167  have parts := CommRing.parts with ring168  have constantIn : polynomialConstant(R, I)(a) ∈ polynomialRing(R, I) :=169    polynomialConstant.mem at R, I, a with *170  have qParts := polynomialRing.member_parts at R, I, q with *171  have product :=172    polynomialRing.mul_apply at R, I, polynomialConstant(R, I)(a), q with *173  have value := polynomialConstant.apply at R, I, a with *174  rw [product, value]175  exact polynomialProduct.constant_scale at I, R.carrier, R.add, R.zero,176    R.neg, R.mul, R.one, a, q, m with *177178theorem polynomialRing.X_mul (j : Set) (q : polynomialRing(R, I)) (n : Set)179  requires member : j ∈ I180  requires monomial : n ∈ monomials(I)181  shows (X(R, I, j) * q)(monomialProduct(I, monomialVariable(I, j), n)) = q(n)182proof183  have parts := CommRing.parts with ring184  have variableIn : X(R, I, j) ∈ polynomialRing(R, I) :=185    X.mem at R, I, j with *186  have qParts := polynomialRing.member_parts at R, I, q with *187  have variable := monomialVariable.member at I, j188  have product := polynomialRing.mul_apply at R, I, X(R, I, j), q with *189  rw [product, X.value]190  unfold polynomialVariable191  exact polynomialProduct.monomial_shift at I, R.carrier, R.add, R.zero,192    R.neg, R.mul, R.one, monomialVariable(I, j), n, q with *193194theorem polynomialRing.X_mul_zero (j : Set) (q : polynomialRing(R, I)) (m : Set)195  requires member : j ∈ I196  requires monomial : m ∈ monomials(I)197  requires exponent : m(j) = 0198  shows (X(R, I, j) * q)(m) = R.zero199proof200  have parts := CommRing.parts with ring201  have variableIn : X(R, I, j) ∈ polynomialRing(R, I) :=202    X.mem at R, I, j with *203  have qParts := polynomialRing.member_parts at R, I, q with *204  have product := polynomialRing.mul_apply at R, I, X(R, I, j), q with *205  rw [product, X.value]206  exact polynomialProduct.variable_zero at I, R.carrier, R.add, R.zero, R.neg,207    R.mul, R.one, j, m, q with *208209end Carrier210