-- The coefficient map of a partial derivative: the coefficient of m in -- ∂p/∂Xᵢ is (m(i) + 1) times the coefficient of the shifted monomial in -- p; its values, its finite support, and its membership in the polynomial -- carrier; with the generation of polynomials from the constants and the -- variables by sums and products, and the scaling of coefficients by a -- constant. -- Part of Cumulus, the Grace17 mathematics library. -- Copyright (c) 2026 Grant Passmore. -- Released under the Apache License 2.0. See LICENSE in the repository root. -- Authors: Grant Passmore module Grace.Cumulus.Algebra.Polynomial.DerivativeCoefficients import Grace.Cumulus.Algebra.Polynomial.ShiftMonomial import Grace.Cumulus.Cardinal.Dominance import Grace.Cumulus.Algebra.Polynomial.Generation -- The coefficient of m in ∂p/∂Xᵢ, which is (m(i) + 1) times the -- coefficient of the shifted monomial in p. def partialDerivativeOf (R I i p : Set) : Set := { c ∈ monomials(I) × Ring.carrier(R) | snd(c) = call2(Ring.mul(R), ringNat(Ring.add(R), Ring.zero(R), Ring.one(R), succ(fst(c)(i))), p(shiftMonomial(I, fst(c), i))) } -- The derivative's coefficient map: its values, its finite support (the -- shift injects the support of the derivative into the support of p), and -- so its membership in the polynomial carrier. def derivativeSupportShift (R I i p : Set) : Set := { q ∈ functionSupport(partialDerivativeOf(R, I, i, p), monomials(I), Ring.zero(R)) × functionSupport(p, monomials(I), Ring.zero(R)) | snd(q) = shiftMonomial(I, fst(q), i) } section Coefficients variable (R I i : Set) hypothesis ring : CommRing(R) hypothesis index : i ∈ I theorem partialDerivativeOf.numeral_mem (m : Set) requires monomial : m ∈ monomials(I) shows ringNat(R.add, R.zero, R.one, succ(m(i))) ∈ R.carrier proof have exponent := monomials.exponent with monomial, index have natural := Naturals.constructor.succ with exponent exact Ring.numeral_mem at R, succ(m(i)) with * theorem partialDerivativeOf.value_mem (p m : Set) requires polynomial : p ∈ polynomials(I, R.carrier, R.zero) requires monomial : m ∈ monomials(I) shows call2(R.mul, ringNat(R.add, R.zero, R.one, succ(m(i))), p(shiftMonomial(I, m, i))) ∈ R.carrier proof have numeral := partialDerivativeOf.numeral_mem at R, I, i, m with * have shifted := shiftMonomial.member at I, i, m with * have coefficient := polynomials.coefficient with polynomial, shifted exact Ring.mul_mem with * theorem partialDerivativeOf.function (p : Set) requires polynomial : p ∈ polynomials(I, R.carrier, R.zero) shows partialDerivativeOf(R, I, i, p) : monomials(I) → R.carrier proof constructor . intros e he exact he.left constructor . intros x y relatedY z relatedZ obtain ⟨_, shapeY⟩ := relatedY obtain ⟨_, shapeZ⟩ := relatedZ simp [fst.pair, snd.pair] at shapeY, shapeZ cc . intros m hm have valueIn := partialDerivativeOf.value_mem at R, I, i, p, m with * refine ⟨call2(R.mul, ringNat(R.add, R.zero, R.one, succ(m(i))), p(shiftMonomial(I, m, i))), valueIn, _⟩ apply partialDerivativeOf.membership.backward refine ⟨(product.pair with hm, valueIn), _⟩ simp [fst.pair, snd.pair] theorem partialDerivativeOf.coefficient (p m : Set) requires polynomial : p ∈ polynomials(I, R.carrier, R.zero) requires monomial : m ∈ monomials(I) shows partialDerivativeOf(R, I, i, p)(m) = call2(R.mul, ringNat(R.add, R.zero, R.one, succ(m(i))), p(shiftMonomial(I, m, i))) proof have function := partialDerivativeOf.function at R, I, i, p with * have valueIn := partialDerivativeOf.value_mem at R, I, i, p, m with * have related : relates(partialDerivativeOf(R, I, i, p), m, call2(R.mul, ringNat(R.add, R.zero, R.one, succ(m(i))), p(shiftMonomial(I, m, i)))) apply partialDerivativeOf.membership.backward refine ⟨(product.pair with monomial, valueIn), _⟩ simp [fst.pair, snd.pair] exact FunctionBetween.apply_value with function, monomial, related theorem partialDerivativeOf.support (p m : Set) requires polynomial : p ∈ polynomials(I, R.carrier, R.zero) requires supported : m ∈ functionSupport(partialDerivativeOf(R, I, i, p), monomials(I), R.zero) shows shiftMonomial(I, m, i) ∈ functionSupport(p, monomials(I), R.zero) proof have data := functionSupport.membership.forward with supported have monomial := data.left have shifted := shiftMonomial.member at I, i, m with * have value := partialDerivativeOf.coefficient at R, I, i, p, m with * have numeral := partialDerivativeOf.numeral_mem at R, I, i, m with * have parts := Ring.parts with (CommRing.to_ring with ring) have annihilate := IsRing.mul_zero with parts, numeral apply functionSupport.membership.backward refine ⟨shifted, _⟩ intro vanishes apply data.right rw [value, vanishes] exact annihilate theorem partialDerivativeOf.support_injection (p : Set) requires polynomial : p ∈ polynomials(I, R.carrier, R.zero) shows InjectiveBetween(derivativeSupportShift(R, I, i, p), functionSupport(partialDerivativeOf(R, I, i, p), monomials(I), R.zero), functionSupport(p, monomials(I), R.zero)) proof constructor . constructor . intros e he exact he.left constructor . intros x y relatedY z relatedZ obtain ⟨_, shapeY⟩ := relatedY obtain ⟨_, shapeZ⟩ := relatedZ simp [fst.pair, snd.pair] at shapeY, shapeZ cc . intros m hm have shifted := partialDerivativeOf.support at R, I, i, p, m with * refine ⟨shiftMonomial(I, m, i), shifted, _⟩ apply derivativeSupportShift.membership.backward refine ⟨(product.pair with hm, shifted), _⟩ simp [fst.pair, snd.pair] . intros x hx y hy z hz relatedX relatedY obtain ⟨_, shapeX⟩ := relatedX obtain ⟨_, shapeY⟩ := relatedY simp [fst.pair, snd.pair] at shapeX, shapeY have dataX := functionSupport.membership.forward with hx have dataY := functionSupport.membership.forward with hy have equal : shiftMonomial(I, x, i) = shiftMonomial(I, y, i) by cc exact shiftMonomial.injective at I, i, x, y with index, dataX.left, dataY.left, equal theorem partialDerivativeOf.finite_support (p : Set) requires polynomial : p ∈ polynomials(I, R.carrier, R.zero) shows Finite(functionSupport(partialDerivativeOf(R, I, i, p), monomials(I), R.zero)) proof have finite := polynomials.finite_support with polynomial have injective := partialDerivativeOf.support_injection at R, I, i, p with * have dominated : Dominated(functionSupport(partialDerivativeOf(R, I, i, p), monomials(I), R.zero), functionSupport(p, monomials(I), R.zero)) witness derivativeSupportShift(R, I, i, p) exact injective exact Finite.of_dominated with finite, dominated theorem partialDerivativeOf.member (p : Set) requires polynomial : p ∈ polynomials(I, R.carrier, R.zero) shows partialDerivativeOf(R, I, i, p) ∈ polynomials(I, R.carrier, R.zero) proof have function := partialDerivativeOf.function at R, I, i, p with * have finite := partialDerivativeOf.finite_support at R, I, i, p with * apply polynomials.contains unfold CoefficientMap exact ⟨function, finite⟩ end Coefficients -- Generation. Polynomials are generated from the constants and the -- variables by sums and products: the induction principle in that form, -- through the monomial induction on the terms with coefficient one. theorem polynomialConstant.term (I A zero a : Set) shows polynomialConstant(I, A, zero, a) = polynomialTerm(I, A, zero, a, monomialOne(I)) proof simp [Polynomial.polynomialConstant] theorem polynomials.generated (I A add zero neg mul one S p : Set) requires ring : IsCommRing(A, add, zero, neg, mul, one) requires member : p ∈ polynomials(I, A, zero) requires constants : ∀ a ∈ A, polynomialConstant(I, A, zero, a) ∈ S requires variables : ∀ j ∈ I, polynomialVariable(I, A, zero, one, j) ∈ S requires sums : ∀ f ∈ S, ∀ g ∈ S, coefficientAdd(monomials(I), A, add, zero, neg, mul, one, f, g) ∈ S requires products : ∀ f ∈ S, ∀ g ∈ S, polynomialProduct(I, A, add, zero, neg, mul, one, f, g) ∈ S shows p ∈ S proof have ordinary := IsCommRing.ring with ring have zeroIn := IsRing.zero_in_carrier with ordinary have multiplicative := IsRing.multiplicative with ordinary have oneIn := IsMonoid.unit_in_carrier with multiplicative have unitMonomial := monomialOne.member at I have base : constantFunction(monomials(I), A, zero) ∈ S have zeroConstant := polynomialConstant.zero at I, A, zero with zeroIn have inS := constants with zero, zeroIn rwa zeroConstant at inS have unit : monomialOne(I) ∈ subalgebraMonomials(I, A, zero, one, S) have inS := constants with one, oneIn rw polynomialConstant.term at inS exact subalgebraMonomials.membership.backward with ⟨unitMonomial, inS⟩ have monomialVariables : ∀ j ∈ I, monomialVariable(I, j) ∈ subalgebraMonomials(I, A, zero, one, S) intros j hj have inS := variables with j, hj have variable := monomialVariable.member at I, j unfold polynomialVariable at inS exact subalgebraMonomials.membership.backward with ⟨variable, inS⟩ have monomialProducts : ∀ m ∈ subalgebraMonomials(I, A, zero, one, S), ∀ n ∈ subalgebraMonomials(I, A, zero, one, S), monomialProduct(I, m, n) ∈ subalgebraMonomials(I, A, zero, one, S) intros m hm n hn have dataM := subalgebraMonomials.membership.forward with hm have dataN := subalgebraMonomials.membership.forward with hn have product := monomialProduct.member with dataM.left, dataN.left have termProduct := polynomialProduct.terms at I, A, add, zero, neg, mul, one, one, one, m, n with * have unitLaw := IsCommRing.one_right with ring, oneIn rw unitLaw at termProduct have inS := products with polynomialTerm(I, A, zero, one, m), dataM.right, polynomialTerm(I, A, zero, one, n), dataN.right rw termProduct at inS exact subalgebraMonomials.membership.backward with ⟨product, inS⟩ have terms : ∀ a ∈ A, ∀ m ∈ monomials(I), polynomialTerm(I, A, zero, a, m) ∈ S intros a ha m hm have generated := monomials.induction at I, subalgebraMonomials(I, A, zero, one, S), m with unit, monomialVariables, monomialProducts, hm have data := subalgebraMonomials.membership.forward with generated have constant := constants with a, ha have inS := products with polynomialConstant(I, A, zero, a), constant, polynomialTerm(I, A, zero, one, m), data.right have termProduct := polynomialProduct.terms at I, A, add, zero, neg, mul, one, a, one, monomialOne(I), m with * have scalar := IsCommRing.one_right with ring, ha have commute := monomialProduct.commutative with unitMonomial, hm have unitMonomialLaw := monomialProduct.one with hm rw polynomialConstant.term at inS rw [termProduct, scalar, commute, unitMonomialLaw] at inS exact inS exact polynomials.induction with ring, member, base, terms, sums -- Multiplication by a constant scales every coefficient, by the same -- induction on the polynomial. def constantMultiples (I A add zero neg mul one a : Set) : Set := { f ∈ polynomials(I, A, zero) | ∀ n ∈ monomials(I), polynomialProduct(I, A, add, zero, neg, mul, one, polynomialConstant(I, A, zero, a), f)(n) = call2(mul, a, f(n)) } theorem polynomialProduct.constant_scale (I A add zero neg mul one a q m : Set) requires ring : IsCommRing(A, add, zero, neg, mul, one) requires scalar : a ∈ A requires polynomial : q ∈ polynomials(I, A, zero) requires monomial : m ∈ monomials(I) shows polynomialProduct(I, A, add, zero, neg, mul, one, polynomialConstant(I, A, zero, a), q)(m) = call2(mul, a, q(m)) proof have ordinary := IsCommRing.ring with ring have zeroIn := IsRing.zero_in_carrier with ordinary have constant := polynomialConstant.member at I, A, zero, a with * have annihilate := IsRing.mul_zero with ordinary, scalar have unitMonomial := monomialOne.member at I have base : constantFunction(monomials(I), A, zero) ∈ constantMultiples(I, A, add, zero, neg, mul, one, a) have zeroPoly := polynomials.zero at I, A, add, zero, neg, mul, one with ring have product := polynomialProduct.zero_right at I, A, add, zero, neg, mul, one, polynomialConstant(I, A, zero, a) with * apply constantMultiples.membership.backward refine ⟨zeroPoly, _⟩ intros n hn have zeroValue := constantFunction.apply at monomials(I), A, n, zero with * rw [product, zeroValue] symm exact annihilate have terms : ∀ b ∈ A, ∀ n ∈ monomials(I), polynomialTerm(I, A, zero, b, n) ∈ constantMultiples(I, A, add, zero, neg, mul, one, a) intros b hb n hn have term := polynomialTerm.member at I, A, zero, b, n with * have termProduct := polynomialProduct.terms at I, A, add, zero, neg, mul, one, a, b, monomialOne(I), n with * have commute := monomialProduct.commutative with unitMonomial, hn have unitLaw := monomialProduct.one with hn have productIn := IsRing.mul_closed with ordinary, scalar, hb apply constantMultiples.membership.backward refine ⟨term, _⟩ intros k hk rw [polynomialConstant.term, termProduct, commute, unitLaw] have alternatives : k = n ∨ k ≠ n by tauto cases alternatives with same | different . rw same have left := polynomialTerm.same at I, A, zero, call2(mul, a, b), n with * have right := polynomialTerm.same at I, A, zero, b, n with * rw [left, right] rfl . have left := polynomialTerm.other at I, A, zero, call2(mul, a, b), n, k with * have right := polynomialTerm.other at I, A, zero, b, n, k with * rw [left, right] symm exact annihilate have sums : ∀ f ∈ constantMultiples(I, A, add, zero, neg, mul, one, a), ∀ g ∈ constantMultiples(I, A, add, zero, neg, mul, one, a), coefficientAdd(monomials(I), A, add, zero, neg, mul, one, f, g) ∈ constantMultiples(I, A, add, zero, neg, mul, one, a) intros f hf g hg have dataF := constantMultiples.membership.forward with hf have dataG := constantMultiples.membership.forward with hg have memberF := dataF.left have memberG := dataG.left have sum := polynomials.add at I, A, add, zero, neg, mul, one, f, g with * have distribute := polynomialProduct.add_right at I, A, add, zero, neg, mul, one, polynomialConstant(I, A, zero, a), f, g with * have productF := polynomialProduct.member at I, A, add, zero, neg, mul, one, polynomialConstant(I, A, zero, a), f with * have productG := polynomialProduct.member at I, A, add, zero, neg, mul, one, polynomialConstant(I, A, zero, a), g with * have functionF := polynomials.function with memberF have functionG := polynomials.function with memberG have functionPF := polynomials.function with productF have functionPG := polynomials.function with productG apply constantMultiples.membership.backward refine ⟨sum, _⟩ intros n hn have valueF := dataF.right with n, hn have valueG := dataG.right with n, hn have fIn := polynomials.coefficient at I, A, zero, f, n with * have gIn := polynomials.coefficient at I, A, zero, g, n with * have sumValue := coefficientAdd.value at monomials(I), A, add, zero, neg, mul, one, f, g, n with * have productValue := coefficientAdd.value at monomials(I), A, add, zero, neg, mul, one, polynomialProduct(I, A, add, zero, neg, mul, one, polynomialConstant(I, A, zero, a), f), polynomialProduct(I, A, add, zero, neg, mul, one, polynomialConstant(I, A, zero, a), g), n with * have law := IsCommRing.mul_add with ring, scalar, fIn, gIn rw [distribute, productValue, valueF, valueG, sumValue] symm exact law have generated := polynomials.induction with ring, polynomial, base, terms, sums have data := constantMultiples.membership.forward with generated exact data.right with m, monomial -- The bundled polynomial ring and its coefficient engine: membership in -- the ring is membership in the polynomial carrier, equality is -- coefficientwise, and the sum, negative, zero, and product have their -- coefficient formulas.