Grace/Cumulus/Algebra/Polynomial/DerivativeCoefficients.g17

Open in Workbench Download source

Imports

Grace.Cumulus.Algebra.Polynomial.ShiftMonomial · Grace.Cumulus.Cardinal.Dominance · Grace.Cumulus.Algebra.Polynomial.Generation

Declarations

Source

1-- The coefficient map of a partial derivative: the coefficient of m in2-- ∂p/∂Xᵢ is (m(i) + 1) times the coefficient of the shifted monomial in3-- p; its values, its finite support, and its membership in the polynomial4-- carrier; with the generation of polynomials from the constants and the5-- variables by sums and products, and the scaling of coefficients by a6-- constant.7-- Part of Cumulus, the Grace17 mathematics library.8-- Copyright (c) 2026 Grant Passmore.9-- Released under the Apache License 2.0. See LICENSE in the repository root.10-- Authors: Grant Passmore1112module Grace.Cumulus.Algebra.Polynomial.DerivativeCoefficients13import Grace.Cumulus.Algebra.Polynomial.ShiftMonomial14import Grace.Cumulus.Cardinal.Dominance15import Grace.Cumulus.Algebra.Polynomial.Generation1617-- The coefficient of m in ∂p/∂Xᵢ, which is (m(i) + 1) times the18-- coefficient of the shifted monomial in p.19def partialDerivativeOf (R I i p : Set) : Set :=20  { c ∈ monomials(I) × Ring.carrier(R) |21    snd(c) = call2(Ring.mul(R),22      ringNat(Ring.add(R), Ring.zero(R), Ring.one(R), succ(fst(c)(i))),23      p(shiftMonomial(I, fst(c), i))) }2425-- The derivative's coefficient map: its values, its finite support (the26-- shift injects the support of the derivative into the support of p), and27-- so its membership in the polynomial carrier.28def derivativeSupportShift (R I i p : Set) : Set :=29  { q ∈ functionSupport(partialDerivativeOf(R, I, i, p), monomials(I),30      Ring.zero(R)) × functionSupport(p, monomials(I), Ring.zero(R)) |31    snd(q) = shiftMonomial(I, fst(q), i) }3233section Coefficients34variable (R I i : Set)35hypothesis ring : CommRing(R)36hypothesis index : i ∈ I3738theorem partialDerivativeOf.numeral_mem (m : Set)39  requires monomial : m ∈ monomials(I)40  shows ringNat(R.add, R.zero, R.one, succ(m(i))) ∈ R.carrier41proof42  have exponent := monomials.exponent with monomial, index43  have natural := Naturals.constructor.succ with exponent44  exact Ring.numeral_mem at R, succ(m(i)) with *4546theorem partialDerivativeOf.value_mem (p m : Set)47  requires polynomial : p ∈ polynomials(I, R.carrier, R.zero)48  requires monomial : m ∈ monomials(I)49  shows call2(R.mul, ringNat(R.add, R.zero, R.one, succ(m(i))),50    p(shiftMonomial(I, m, i))) ∈ R.carrier51proof52  have numeral := partialDerivativeOf.numeral_mem at R, I, i, m with *53  have shifted := shiftMonomial.member at I, i, m with *54  have coefficient := polynomials.coefficient with polynomial, shifted55  exact Ring.mul_mem with *5657theorem partialDerivativeOf.function (p : Set)58  requires polynomial : p ∈ polynomials(I, R.carrier, R.zero)59  shows partialDerivativeOf(R, I, i, p) : monomials(I) → R.carrier60proof61  constructor62  . intros e he63    exact he.left64  constructor65  . intros x y relatedY z relatedZ66    obtain ⟨_, shapeY⟩ := relatedY67    obtain ⟨_, shapeZ⟩ := relatedZ68    simp [fst.pair, snd.pair] at shapeY, shapeZ69    cc70  . intros m hm71    have valueIn := partialDerivativeOf.value_mem at R, I, i, p, m with *72    refine ⟨call2(R.mul, ringNat(R.add, R.zero, R.one, succ(m(i))),73      p(shiftMonomial(I, m, i))), valueIn, _⟩74    apply partialDerivativeOf.membership.backward75    refine ⟨(product.pair with hm, valueIn), _⟩76    simp [fst.pair, snd.pair]7778theorem partialDerivativeOf.coefficient (p m : Set)79  requires polynomial : p ∈ polynomials(I, R.carrier, R.zero)80  requires monomial : m ∈ monomials(I)81  shows partialDerivativeOf(R, I, i, p)(m) =82    call2(R.mul, ringNat(R.add, R.zero, R.one, succ(m(i))),83      p(shiftMonomial(I, m, i)))84proof85  have function := partialDerivativeOf.function at R, I, i, p with *86  have valueIn := partialDerivativeOf.value_mem at R, I, i, p, m with *87  have related : relates(partialDerivativeOf(R, I, i, p), m,88      call2(R.mul, ringNat(R.add, R.zero, R.one, succ(m(i))),89        p(shiftMonomial(I, m, i))))90    apply partialDerivativeOf.membership.backward91    refine ⟨(product.pair with monomial, valueIn), _⟩92    simp [fst.pair, snd.pair]93  exact FunctionBetween.apply_value with function, monomial, related9495theorem partialDerivativeOf.support (p m : Set)96  requires polynomial : p ∈ polynomials(I, R.carrier, R.zero)97  requires supported : m ∈ functionSupport(partialDerivativeOf(R, I, i, p),98    monomials(I), R.zero)99  shows shiftMonomial(I, m, i) ∈ functionSupport(p, monomials(I), R.zero)100proof101  have data := functionSupport.membership.forward with supported102  have monomial := data.left103  have shifted := shiftMonomial.member at I, i, m with *104  have value := partialDerivativeOf.coefficient at R, I, i, p, m with *105  have numeral := partialDerivativeOf.numeral_mem at R, I, i, m with *106  have parts := Ring.parts with (CommRing.to_ring with ring)107  have annihilate := IsRing.mul_zero with parts, numeral108  apply functionSupport.membership.backward109  refine ⟨shifted, _⟩110  intro vanishes111  apply data.right112  rw [value, vanishes]113  exact annihilate114115theorem partialDerivativeOf.support_injection (p : Set)116  requires polynomial : p ∈ polynomials(I, R.carrier, R.zero)117  shows InjectiveBetween(derivativeSupportShift(R, I, i, p),118    functionSupport(partialDerivativeOf(R, I, i, p), monomials(I), R.zero),119    functionSupport(p, monomials(I), R.zero))120proof121  constructor122  . constructor123    . intros e he124      exact he.left125    constructor126    . intros x y relatedY z relatedZ127      obtain ⟨_, shapeY⟩ := relatedY128      obtain ⟨_, shapeZ⟩ := relatedZ129      simp [fst.pair, snd.pair] at shapeY, shapeZ130      cc131    . intros m hm132      have shifted := partialDerivativeOf.support at R, I, i, p, m with *133      refine ⟨shiftMonomial(I, m, i), shifted, _⟩134      apply derivativeSupportShift.membership.backward135      refine ⟨(product.pair with hm, shifted), _⟩136      simp [fst.pair, snd.pair]137  . intros x hx y hy z hz relatedX relatedY138    obtain ⟨_, shapeX⟩ := relatedX139    obtain ⟨_, shapeY⟩ := relatedY140    simp [fst.pair, snd.pair] at shapeX, shapeY141    have dataX := functionSupport.membership.forward with hx142    have dataY := functionSupport.membership.forward with hy143    have equal : shiftMonomial(I, x, i) = shiftMonomial(I, y, i) by cc144    exact shiftMonomial.injective at I, i, x, y145      with index, dataX.left, dataY.left, equal146147theorem partialDerivativeOf.finite_support (p : Set)148  requires polynomial : p ∈ polynomials(I, R.carrier, R.zero)149  shows Finite(functionSupport(partialDerivativeOf(R, I, i, p), monomials(I),150    R.zero))151proof152  have finite := polynomials.finite_support with polynomial153  have injective :=154    partialDerivativeOf.support_injection at R, I, i, p with *155  have dominated : Dominated(functionSupport(partialDerivativeOf(R, I, i, p),156      monomials(I), R.zero), functionSupport(p, monomials(I), R.zero))157    witness derivativeSupportShift(R, I, i, p)158    exact injective159  exact Finite.of_dominated with finite, dominated160161theorem partialDerivativeOf.member (p : Set)162  requires polynomial : p ∈ polynomials(I, R.carrier, R.zero)163  shows partialDerivativeOf(R, I, i, p) ∈ polynomials(I, R.carrier, R.zero)164proof165  have function := partialDerivativeOf.function at R, I, i, p with *166  have finite := partialDerivativeOf.finite_support at R, I, i, p with *167  apply polynomials.contains168  unfold CoefficientMap169  exact ⟨function, finite⟩170171end Coefficients172173-- Generation. Polynomials are generated from the constants and the174-- variables by sums and products: the induction principle in that form,175-- through the monomial induction on the terms with coefficient one.176theorem polynomialConstant.term (I A zero a : Set)177  shows polynomialConstant(I, A, zero, a) =178    polynomialTerm(I, A, zero, a, monomialOne(I))179proof180  simp [Polynomial.polynomialConstant]181182theorem polynomials.generated (I A add zero neg mul one S p : Set)183  requires ring : IsCommRing(A, add, zero, neg, mul, one)184  requires member : p ∈ polynomials(I, A, zero)185  requires constants : ∀ a ∈ A, polynomialConstant(I, A, zero, a) ∈ S186  requires variables : ∀ j ∈ I, polynomialVariable(I, A, zero, one, j) ∈ S187  requires sums : ∀ f ∈ S, ∀ g ∈ S,188    coefficientAdd(monomials(I), A, add, zero, neg, mul, one, f, g) ∈ S189  requires products : ∀ f ∈ S, ∀ g ∈ S,190    polynomialProduct(I, A, add, zero, neg, mul, one, f, g) ∈ S191  shows p ∈ S192proof193  have ordinary := IsCommRing.ring with ring194  have zeroIn := IsRing.zero_in_carrier with ordinary195  have multiplicative := IsRing.multiplicative with ordinary196  have oneIn := IsMonoid.unit_in_carrier with multiplicative197  have unitMonomial := monomialOne.member at I198  have base : constantFunction(monomials(I), A, zero) ∈ S199    have zeroConstant := polynomialConstant.zero at I, A, zero with zeroIn200    have inS := constants with zero, zeroIn201    rwa zeroConstant at inS202  have unit : monomialOne(I) ∈ subalgebraMonomials(I, A, zero, one, S)203    have inS := constants with one, oneIn204    rw polynomialConstant.term at inS205    exact subalgebraMonomials.membership.backward with ⟨unitMonomial, inS⟩206  have monomialVariables : ∀ j ∈ I,207      monomialVariable(I, j) ∈ subalgebraMonomials(I, A, zero, one, S)208    intros j hj209    have inS := variables with j, hj210    have variable := monomialVariable.member at I, j211    unfold polynomialVariable at inS212    exact subalgebraMonomials.membership.backward with ⟨variable, inS⟩213  have monomialProducts : ∀ m ∈ subalgebraMonomials(I, A, zero, one, S),214      ∀ n ∈ subalgebraMonomials(I, A, zero, one, S),215      monomialProduct(I, m, n) ∈ subalgebraMonomials(I, A, zero, one, S)216    intros m hm n hn217    have dataM := subalgebraMonomials.membership.forward with hm218    have dataN := subalgebraMonomials.membership.forward with hn219    have product := monomialProduct.member with dataM.left, dataN.left220    have termProduct := polynomialProduct.terms at I, A, add, zero, neg, mul,221      one, one, one, m, n with *222    have unitLaw := IsCommRing.one_right with ring, oneIn223    rw unitLaw at termProduct224    have inS := products with polynomialTerm(I, A, zero, one, m), dataM.right,225      polynomialTerm(I, A, zero, one, n), dataN.right226    rw termProduct at inS227    exact subalgebraMonomials.membership.backward with ⟨product, inS⟩228  have terms : ∀ a ∈ A, ∀ m ∈ monomials(I),229      polynomialTerm(I, A, zero, a, m) ∈ S230    intros a ha m hm231    have generated := monomials.induction232      at I, subalgebraMonomials(I, A, zero, one, S), m233      with unit, monomialVariables, monomialProducts, hm234    have data := subalgebraMonomials.membership.forward with generated235    have constant := constants with a, ha236    have inS := products with polynomialConstant(I, A, zero, a), constant,237      polynomialTerm(I, A, zero, one, m), data.right238    have termProduct := polynomialProduct.terms at I, A, add, zero, neg, mul,239      one, a, one, monomialOne(I), m with *240    have scalar := IsCommRing.one_right with ring, ha241    have commute := monomialProduct.commutative with unitMonomial, hm242    have unitMonomialLaw := monomialProduct.one with hm243    rw polynomialConstant.term at inS244    rw [termProduct, scalar, commute, unitMonomialLaw] at inS245    exact inS246  exact polynomials.induction with ring, member, base, terms, sums247248-- Multiplication by a constant scales every coefficient, by the same249-- induction on the polynomial.250def constantMultiples (I A add zero neg mul one a : Set) : Set :=251  { f ∈ polynomials(I, A, zero) | ∀ n ∈ monomials(I),252    polynomialProduct(I, A, add, zero, neg, mul, one,253      polynomialConstant(I, A, zero, a), f)(n) = call2(mul, a, f(n)) }254255theorem polynomialProduct.constant_scale (I A add zero neg mul one a q m : Set)256  requires ring : IsCommRing(A, add, zero, neg, mul, one)257  requires scalar : a ∈ A258  requires polynomial : q ∈ polynomials(I, A, zero)259  requires monomial : m ∈ monomials(I)260  shows polynomialProduct(I, A, add, zero, neg, mul, one,261    polynomialConstant(I, A, zero, a), q)(m) = call2(mul, a, q(m))262proof263  have ordinary := IsCommRing.ring with ring264  have zeroIn := IsRing.zero_in_carrier with ordinary265  have constant := polynomialConstant.member at I, A, zero, a with *266  have annihilate := IsRing.mul_zero with ordinary, scalar267  have unitMonomial := monomialOne.member at I268  have base : constantFunction(monomials(I), A, zero) ∈269      constantMultiples(I, A, add, zero, neg, mul, one, a)270    have zeroPoly :=271      polynomials.zero at I, A, add, zero, neg, mul, one with ring272    have product := polynomialProduct.zero_right at I, A, add, zero, neg,273      mul, one, polynomialConstant(I, A, zero, a) with *274    apply constantMultiples.membership.backward275    refine ⟨zeroPoly, _⟩276    intros n hn277    have zeroValue := constantFunction.apply at monomials(I), A, n, zero with *278    rw [product, zeroValue]279    symm280    exact annihilate281  have terms : ∀ b ∈ A, ∀ n ∈ monomials(I),282      polynomialTerm(I, A, zero, b, n) ∈283        constantMultiples(I, A, add, zero, neg, mul, one, a)284    intros b hb n hn285    have term := polynomialTerm.member at I, A, zero, b, n with *286    have termProduct := polynomialProduct.terms at I, A, add, zero, neg, mul,287      one, a, b, monomialOne(I), n with *288    have commute := monomialProduct.commutative with unitMonomial, hn289    have unitLaw := monomialProduct.one with hn290    have productIn := IsRing.mul_closed with ordinary, scalar, hb291    apply constantMultiples.membership.backward292    refine ⟨term, _⟩293    intros k hk294    rw [polynomialConstant.term, termProduct, commute, unitLaw]295    have alternatives : k = n ∨ k ≠ n by tauto296    cases alternatives with same | different297    . rw same298      have left :=299        polynomialTerm.same at I, A, zero, call2(mul, a, b), n with *300      have right := polynomialTerm.same at I, A, zero, b, n with *301      rw [left, right]302      rfl303    . have left :=304        polynomialTerm.other at I, A, zero, call2(mul, a, b), n, k with *305      have right := polynomialTerm.other at I, A, zero, b, n, k with *306      rw [left, right]307      symm308      exact annihilate309  have sums : ∀ f ∈ constantMultiples(I, A, add, zero, neg, mul, one, a),310      ∀ g ∈ constantMultiples(I, A, add, zero, neg, mul, one, a),311      coefficientAdd(monomials(I), A, add, zero, neg, mul, one, f, g) ∈312        constantMultiples(I, A, add, zero, neg, mul, one, a)313    intros f hf g hg314    have dataF := constantMultiples.membership.forward with hf315    have dataG := constantMultiples.membership.forward with hg316    have memberF := dataF.left317    have memberG := dataG.left318    have sum := polynomials.add at I, A, add, zero, neg, mul, one, f, g with *319    have distribute := polynomialProduct.add_right at I, A, add, zero, neg,320      mul, one, polynomialConstant(I, A, zero, a), f, g with *321    have productF := polynomialProduct.member at I, A, add, zero, neg, mul,322      one, polynomialConstant(I, A, zero, a), f with *323    have productG := polynomialProduct.member at I, A, add, zero, neg, mul,324      one, polynomialConstant(I, A, zero, a), g with *325    have functionF := polynomials.function with memberF326    have functionG := polynomials.function with memberG327    have functionPF := polynomials.function with productF328    have functionPG := polynomials.function with productG329    apply constantMultiples.membership.backward330    refine ⟨sum, _⟩331    intros n hn332    have valueF := dataF.right with n, hn333    have valueG := dataG.right with n, hn334    have fIn := polynomials.coefficient at I, A, zero, f, n with *335    have gIn := polynomials.coefficient at I, A, zero, g, n with *336    have sumValue := coefficientAdd.value at monomials(I), A, add, zero, neg,337      mul, one, f, g, n with *338    have productValue := coefficientAdd.value at monomials(I), A, add, zero,339      neg, mul, one,340      polynomialProduct(I, A, add, zero, neg, mul, one,341        polynomialConstant(I, A, zero, a), f),342      polynomialProduct(I, A, add, zero, neg, mul, one,343        polynomialConstant(I, A, zero, a), g), n with *344    have law := IsCommRing.mul_add with ring, scalar, fIn, gIn345    rw [distribute, productValue, valueF, valueG, sumValue]346    symm347    exact law348  have generated :=349    polynomials.induction with ring, polynomial, base, terms, sums350  have data := constantMultiples.membership.forward with generated351  exact data.right with m, monomial352353-- The bundled polynomial ring and its coefficient engine: membership in354-- the ring is membership in the polynomial carrier, equality is355-- coefficientwise, and the sum, negative, zero, and product have their356-- coefficient formulas.357