-- Partial derivatives of polynomials: the formal derivative in one -- variable as a function on the bundled polynomial ring, and the rules for -- constants, variables, sums, negatives, products, and powers. -- 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.Derivative import Grace.Cumulus.Algebra.Polynomial.DerivativeCoefficients import Grace.Cumulus.Algebra.Polynomial.Bundled import Grace.Cumulus.Algebra.Polynomial.BundledCoefficients -- The derivative in the variable i as a function on the polynomial ring. def partialDerivative (R I i : Set) : Set := { q ∈ Ring.carrier(polynomialRing(R, I)) × Ring.carrier(polynomialRing(R, I)) | snd(q) = partialDerivativeOf(R, I, i, fst(q)) } -- The rules of differentiation. The derivative is a function on the -- carrier with the coefficient formula; it is additive, kills constants, -- sends Xᵢ to 1 and the other variables to 0, satisfies the Leibniz rule -- (first against a constant and a variable, then for all polynomials by -- generation), and so the power rule. predicate LeibnizRule (R I i p : Set) := ∀ q ∈ Ring.carrier(polynomialRing(R, I)), partialDerivative(R, I, i)(call2(Ring.mul(polynomialRing(R, I)), p, q)) = call2(Ring.add(polynomialRing(R, I)), call2(Ring.mul(polynomialRing(R, I)), partialDerivative(R, I, i)(p), q), call2(Ring.mul(polynomialRing(R, I)), p, partialDerivative(R, I, i)(q))) def leibnizPolynomials (R I i : Set) : Set := { f ∈ polynomials(I, Ring.carrier(R), Ring.zero(R)) | LeibnizRule(R, I, i, f) } section Rules variable (R I i : Set) hypothesis ring : CommRing(R) hypothesis polynomials : CommRing(polynomialRing(R, I)) hypothesis index : i ∈ I theorem partialDerivative.function shows partialDerivative(R, I, i) : Ring.carrier(polynomialRing(R, I)) → Ring.carrier(polynomialRing(R, I)) 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 p hp have polynomial := polynomialRing.member_parts at R, I, p with * have derivative := partialDerivativeOf.member at R, I, i, p with * have inCarrier := polynomialRing.member_of_parts at R, I, partialDerivativeOf(R, I, i, p) with * refine ⟨partialDerivativeOf(R, I, i, p), inCarrier, _⟩ apply partialDerivative.membership.backward refine ⟨(product.pair with hp, inCarrier), _⟩ simp [fst.pair, snd.pair] theorem partialDerivative.apply (p : polynomialRing(R, I)) shows partialDerivative(R, I, i)(p) = partialDerivativeOf(R, I, i, p) proof have member : p ∈ Ring.carrier(polynomialRing(R, I)) by assumption have polynomial := polynomialRing.member_parts at R, I, p with * have function := partialDerivative.function at R, I, i with * have derivative := partialDerivativeOf.member at R, I, i, p with * have inCarrier := polynomialRing.member_of_parts at R, I, partialDerivativeOf(R, I, i, p) with * have related : relates(partialDerivative(R, I, i), p, partialDerivativeOf(R, I, i, p)) apply partialDerivative.membership.backward refine ⟨(product.pair with member, inCarrier), _⟩ simp [fst.pair, snd.pair] exact FunctionBetween.apply_value with function, member, related instance partialDerivative.map_mem (p : polynomialRing(R, I)) shows partialDerivative(R, I, i)(p) ∈ polynomialRing(R, I) proof have member : p ∈ Ring.carrier(polynomialRing(R, I)) by assumption have function := partialDerivative.function at R, I, i with * exact FunctionBetween.apply_closed with function, member theorem partialDerivative.coefficient (p : polynomialRing(R, I)) (m : Set) requires monomial : m ∈ monomials(I) shows partialDerivative(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 polynomial := polynomialRing.member_parts at R, I, p with * have value := partialDerivative.apply at R, I, i, p with * rw value exact partialDerivativeOf.coefficient at R, I, i, p, m with * theorem partialDerivative.add (p q : polynomialRing(R, I)) shows partialDerivative(R, I, i)(p + q) = partialDerivative(R, I, i)(p) + partialDerivative(R, I, i)(q) proof have sumIn : p + q ∈ polynomialRing(R, I) := Ring.add_mem with * have leftIn : partialDerivative(R, I, i)(p) ∈ polynomialRing(R, I) := partialDerivative.map_mem at R, I, i, p with * have rightIn : partialDerivative(R, I, i)(q) ∈ polynomialRing(R, I) := partialDerivative.map_mem at R, I, i, q with * have coefficients : ∀ m ∈ monomials(I), partialDerivative(R, I, i)(p + q)(m) = (partialDerivative(R, I, i)(p) + partialDerivative(R, I, i)(q))(m) intros m hm have shifted := shiftMonomial.member at I, i, m with * have numeral := partialDerivativeOf.numeral_mem at R, I, i, m with * have pIn := polynomialRing.coefficient_mem at R, I, p, shiftMonomial(I, m, i) with * have qIn := polynomialRing.coefficient_mem at R, I, q, shiftMonomial(I, m, i) with * have left := partialDerivative.coefficient at R, I, i, p + q, m with * have right := polynomialRing.coefficient_add at R, I, partialDerivative(R, I, i)(p), partialDerivative(R, I, i)(q), m with * have derivativeP := partialDerivative.coefficient at R, I, i, p, m with * have derivativeQ := partialDerivative.coefficient at R, I, i, q, m with * have sum := polynomialRing.coefficient_add at R, I, p, q, shiftMonomial(I, m, i) with * rw [left, right, derivativeP, derivativeQ, sum] ring exact polynomialRing.ext at R, I, partialDerivative(R, I, i)(p + q), partialDerivative(R, I, i)(p) + partialDerivative(R, I, i)(q) with * theorem partialDerivative.neg (p : polynomialRing(R, I)) shows partialDerivative(R, I, i)(-p) = -partialDerivative(R, I, i)(p) proof have negIn : -p ∈ polynomialRing(R, I) := Ring.neg_mem with * have derivativeIn : partialDerivative(R, I, i)(p) ∈ polynomialRing(R, I) := partialDerivative.map_mem at R, I, i, p with * have coefficients : ∀ m ∈ monomials(I), partialDerivative(R, I, i)(-p)(m) = (-partialDerivative(R, I, i)(p))(m) intros m hm have shifted := shiftMonomial.member at I, i, m with * have numeral := partialDerivativeOf.numeral_mem at R, I, i, m with * have pIn := polynomialRing.coefficient_mem at R, I, p, shiftMonomial(I, m, i) with * have left := partialDerivative.coefficient at R, I, i, -p, m with * have right := polynomialRing.coefficient_neg at R, I, partialDerivative(R, I, i)(p), m with * have derivativeP := partialDerivative.coefficient at R, I, i, p, m with * have negative := polynomialRing.coefficient_neg at R, I, p, shiftMonomial(I, m, i) with * rw [left, right, derivativeP, negative] ring exact polynomialRing.ext at R, I, partialDerivative(R, I, i)(-p), -partialDerivative(R, I, i)(p) with * theorem partialDerivative.constant (a : R) shows partialDerivative(R, I, i)(polynomialConstant(R, I)(a)) = Ring.zero(polynomialRing(R, I)) proof have aIn : a ∈ R by assumption have constantIn : polynomialConstant(R, I)(a) ∈ polynomialRing(R, I) := polynomialConstant.mem at R, I, a with * have zeroPoly : Ring.zero(polynomialRing(R, I)) ∈ polynomialRing(R, I) := Ring.zero_mem with * have coefficients : ∀ m ∈ monomials(I), partialDerivative(R, I, i)(polynomialConstant(R, I)(a))(m) = Ring.zero(polynomialRing(R, I))(m) intros m hm have shifted := shiftMonomial.member at I, i, m with * have numeral := partialDerivativeOf.numeral_mem at R, I, i, m with * have different := shiftMonomial.ne_one at I, i, m with * have left := partialDerivative.coefficient at R, I, i, polynomialConstant(R, I)(a), m with * have right := polynomialRing.coefficient_zero at R, I, m with * have vanishes := polynomialConstant.coefficient_other at R, I, a, shiftMonomial(I, m, i) with * rw [left, right, vanishes] ring exact polynomialRing.ext at R, I, partialDerivative(R, I, i)(polynomialConstant(R, I)(a)), Ring.zero(polynomialRing(R, I)) with * theorem partialDerivative.X_self shows partialDerivative(R, I, i)(X(R, I, i)) = Ring.one(polynomialRing(R, I)) proof have zeroIn : R[0] ∈ R := Ring.zero_mem with * have oneIn : R[1] ∈ R := Ring.one_mem with * have variableIn : X(R, I, i) ∈ polynomialRing(R, I) := X.mem at R, I, i with * have onePoly : Ring.one(polynomialRing(R, I)) ∈ polynomialRing(R, I) := Ring.one_mem with * have unit := monomialOne.member at I have variable := monomialVariable.member at I, i have shiftUnit : shiftMonomial(I, monomialOne(I), i) = monomialVariable(I, i) have product := shiftMonomial.product at I, i, monomialOne(I) with * have law := monomialProduct.one with variable cc have coefficients : ∀ m ∈ monomials(I), partialDerivative(R, I, i)(X(R, I, i))(m) = Ring.one(polynomialRing(R, I))(m) intros m hm have shifted := shiftMonomial.member at I, i, m with * have numeral := partialDerivativeOf.numeral_mem at R, I, i, m with * have left := partialDerivative.coefficient at R, I, i, X(R, I, i), m with * rw [left, polynomialRing.oneOf] have alternatives : m = monomialOne(I) ∨ m ≠ monomialOne(I) by tauto cases alternatives with same | different . rw same have variableValue := X.coefficient_same at R, I, i with * have constantValue := polynomialConstant.coefficient at I, R.carrier, R.zero, R.one with * have unitExponent := monomialOne.value at I, i with index have zeroNat := Naturals.constructor.zero have step := ringNat.succ at R.add, R.zero, R.one, 0 with * have base := ringNat.zero at R.add, R.zero, R.one rw [shiftUnit, variableValue, constantValue, unitExponent, step, base] ring . have shiftDifferent : shiftMonomial(I, m, i) ≠ monomialVariable(I, i) intro equal rw ← shiftUnit at equal have same := shiftMonomial.injective at I, i, m, monomialOne(I) with * exact different with same have variableValue := X.coefficient_other at R, I, i, shiftMonomial(I, m, i) with * have selected := polynomialConstant.value at I, R.carrier, R.zero, R.one, m with * have other := singleValue.other at R.carrier, R.zero, R.one, monomialOne(I), m with * rw [variableValue, selected, other] ring exact polynomialRing.ext at R, I, partialDerivative(R, I, i)(X(R, I, i)), Ring.one(polynomialRing(R, I)) with * theorem partialDerivative.X_other (j : Set) requires other : j ∈ I requires apart : j ≠ i shows partialDerivative(R, I, i)(X(R, I, j)) = Ring.zero(polynomialRing(R, I)) proof have zeroIn : R[0] ∈ R := Ring.zero_mem with * have variableIn : X(R, I, j) ∈ polynomialRing(R, I) := X.mem at R, I, j with * have zeroPoly : Ring.zero(polynomialRing(R, I)) ∈ polynomialRing(R, I) := Ring.zero_mem with * have coefficients : ∀ m ∈ monomials(I), partialDerivative(R, I, i)(X(R, I, j))(m) = Ring.zero(polynomialRing(R, I))(m) intros m hm have shifted := shiftMonomial.member at I, i, m with * have numeral := partialDerivativeOf.numeral_mem at R, I, i, m with * have different := shiftMonomial.ne_variable at I, i, m, j with * have left := partialDerivative.coefficient at R, I, i, X(R, I, j), m with * have right := polynomialRing.coefficient_zero at R, I, m with * have variableValue := X.coefficient_other at R, I, j, shiftMonomial(I, m, i) with * rw [left, right, variableValue] ring exact polynomialRing.ext at R, I, partialDerivative(R, I, i)(X(R, I, j)), Ring.zero(polynomialRing(R, I)) with * -- The Leibniz rule against a constant and against a variable. theorem partialDerivative.constant_mul (a : R) (q : polynomialRing(R, I)) shows partialDerivative(R, I, i)(polynomialConstant(R, I)(a) * q) = polynomialConstant(R, I)(a) * partialDerivative(R, I, i)(q) proof have aIn : a ∈ R by assumption have constantIn : polynomialConstant(R, I)(a) ∈ polynomialRing(R, I) := polynomialConstant.mem at R, I, a with * have productIn : polynomialConstant(R, I)(a) * q ∈ polynomialRing(R, I) := Ring.mul_mem with * have derivativeIn : partialDerivative(R, I, i)(q) ∈ polynomialRing(R, I) := partialDerivative.map_mem at R, I, i, q with * have rightIn : polynomialConstant(R, I)(a) * partialDerivative(R, I, i)(q) ∈ polynomialRing(R, I) := Ring.mul_mem with * have coefficients : ∀ m ∈ monomials(I), partialDerivative(R, I, i)(polynomialConstant(R, I)(a) * q)(m) = (polynomialConstant(R, I)(a) * partialDerivative(R, I, i)(q))(m) intros m hm have shifted := shiftMonomial.member at I, i, m with * have numeral := partialDerivativeOf.numeral_mem at R, I, i, m with * have qIn := polynomialRing.coefficient_mem at R, I, q, shiftMonomial(I, m, i) with * have left := partialDerivative.coefficient at R, I, i, polynomialConstant(R, I)(a) * q, m with * have productValue := polynomialRing.constant_mul at R, I, a, q, shiftMonomial(I, m, i) with * have right := polynomialRing.constant_mul at R, I, a, partialDerivative(R, I, i)(q), m with * have derivativeQ := partialDerivative.coefficient at R, I, i, q, m with * rw [left, productValue, right, derivativeQ] ring exact polynomialRing.ext at R, I, partialDerivative(R, I, i)(polynomialConstant(R, I)(a) * q), polynomialConstant(R, I)(a) * partialDerivative(R, I, i)(q) with * theorem partialDerivative.X_self_mul (q : polynomialRing(R, I)) shows partialDerivative(R, I, i)(X(R, I, i) * q) = q + X(R, I, i) * partialDerivative(R, I, i)(q) proof have qIn : q ∈ polynomialRing(R, I) by assumption have variableIn : X(R, I, i) ∈ polynomialRing(R, I) := X.mem at R, I, i with * have productIn : X(R, I, i) * q ∈ polynomialRing(R, I) := Ring.mul_mem with * have derivativeIn : partialDerivative(R, I, i)(q) ∈ polynomialRing(R, I) := partialDerivative.map_mem at R, I, i, q with * have shiftedIn : X(R, I, i) * partialDerivative(R, I, i)(q) ∈ polynomialRing(R, I) := Ring.mul_mem with * have rightIn : q + X(R, I, i) * partialDerivative(R, I, i)(q) ∈ polynomialRing(R, I) := Ring.add_mem with * have coefficients : ∀ m ∈ monomials(I), partialDerivative(R, I, i)(X(R, I, i) * q)(m) = (q + X(R, I, i) * partialDerivative(R, I, i)(q))(m) intros m hm have shifted := shiftMonomial.member at I, i, m with * have numeral := partialDerivativeOf.numeral_mem at R, I, i, m with * have qValue := polynomialRing.coefficient_mem at R, I, q, m with * have left := partialDerivative.coefficient at R, I, i, X(R, I, i) * q, m with * have productForm := shiftMonomial.product at I, i, m with * have productValue := polynomialRing.X_mul at R, I, i, q, m with * have right := polynomialRing.coefficient_add at R, I, q, X(R, I, i) * partialDerivative(R, I, i)(q), m with * rw [left, productForm, productValue, right] have alternatives : m(i) = 0 ∨ m(i) ≠ 0 by tauto cases alternatives with vanishes | nonzero . have shiftValue := polynomialRing.X_mul_zero at R, I, i, partialDerivative(R, I, i)(q), m with * have zeroNat := Naturals.constructor.zero have step := ringNat.succ at R.add, R.zero, R.one, 0 with * have base := ringNat.zero at R.add, R.zero, R.one rw [shiftValue, vanishes, step, base] ring . obtain ⟨n, hn, equal⟩ := monomials.unshift at I, i, m with * have shiftN := shiftMonomial.member at I, i, n with * have exponentN := monomials.exponent with hn, index have naturalN := Naturals.constructor.succ with exponentN have numeralN := partialDerivativeOf.numeral_mem at R, I, i, n with * have productN := shiftMonomial.product at I, i, n with * have exponentM : m(i) = succ(n(i)) have same := shiftMonomial.same at I, i, n with * rw equal exact same have shiftValue : (X(R, I, i) * partialDerivative(R, I, i)(q))(m) = partialDerivative(R, I, i)(q)(n) have value := polynomialRing.X_mul at R, I, i, partialDerivative(R, I, i)(q), n with * rw [equal, productN] exact value have derivativeN := partialDerivative.coefficient at R, I, i, q, n with * have qShift : q(shiftMonomial(I, n, i)) = q(m) rw equal rfl have step := ringNat.succ at R.add, R.zero, R.one, succ(n(i)) with * rw [shiftValue, derivativeN, qShift, exponentM, step] ring exact polynomialRing.ext at R, I, partialDerivative(R, I, i)(X(R, I, i) * q), q + X(R, I, i) * partialDerivative(R, I, i)(q) with * theorem partialDerivative.X_other_mul (j : Set) (q : polynomialRing(R, I)) requires other : j ∈ I requires apart : j ≠ i shows partialDerivative(R, I, i)(X(R, I, j) * q) = X(R, I, j) * partialDerivative(R, I, i)(q) proof have qIn : q ∈ polynomialRing(R, I) by assumption have reverse : i ≠ j by cc have variableIn : X(R, I, j) ∈ polynomialRing(R, I) := X.mem at R, I, j with * have productIn : X(R, I, j) * q ∈ polynomialRing(R, I) := Ring.mul_mem with * have derivativeIn : partialDerivative(R, I, i)(q) ∈ polynomialRing(R, I) := partialDerivative.map_mem at R, I, i, q with * have rightIn : X(R, I, j) * partialDerivative(R, I, i)(q) ∈ polynomialRing(R, I) := Ring.mul_mem with * have variableI := monomialVariable.member at I, i have variableJ := monomialVariable.member at I, j have coefficients : ∀ m ∈ monomials(I), partialDerivative(R, I, i)(X(R, I, j) * q)(m) = (X(R, I, j) * partialDerivative(R, I, i)(q))(m) intros m hm have shifted := shiftMonomial.member at I, i, m with * have numeral := partialDerivativeOf.numeral_mem at R, I, i, m with * have left := partialDerivative.coefficient at R, I, i, X(R, I, j) * q, m with * rw left have alternatives : m(j) = 0 ∨ m(j) ≠ 0 by tauto cases alternatives with vanishes | nonzero . have shiftExponent : shiftMonomial(I, m, i)(j) = 0 have value := shiftMonomial.other at I, i, m, j with * rw value exact vanishes have productValue := polynomialRing.X_mul_zero at R, I, j, q, shiftMonomial(I, m, i) with * have right := polynomialRing.X_mul_zero at R, I, j, partialDerivative(R, I, i)(q), m with * rw [productValue, right] ring . obtain ⟨n, hn, equal⟩ := monomials.unshift at I, j, m with * have productN := shiftMonomial.product at I, j, n with * have shiftN := shiftMonomial.member at I, i, n with * have exponentM : m(i) = n(i) have value := shiftMonomial.other at I, j, n, i with * rw equal exact value have commute : shiftMonomial(I, m, i) = monomialProduct(I, monomialVariable(I, j), shiftMonomial(I, n, i)) have productM := shiftMonomial.product at I, i, m with * have productIN := shiftMonomial.product at I, i, n with * have assocLeft := monomialProduct.associative with variableI, variableJ, hn have swap := monomialProduct.commutative with variableI, variableJ have assocRight := monomialProduct.associative with variableJ, variableI, hn cc have productValue : (X(R, I, j) * q)(shiftMonomial(I, m, i)) = q(shiftMonomial(I, n, i)) have value := polynomialRing.X_mul at R, I, j, q, shiftMonomial(I, n, i) with * rw commute exact value have right : (X(R, I, j) * partialDerivative(R, I, i)(q))(m) = partialDerivative(R, I, i)(q)(n) have value := polynomialRing.X_mul at R, I, j, partialDerivative(R, I, i)(q), n with * rw [equal, productN] exact value have derivativeN := partialDerivative.coefficient at R, I, i, q, n with * rw [productValue, right, derivativeN, exponentM] rfl exact polynomialRing.ext at R, I, partialDerivative(R, I, i)(X(R, I, j) * q), X(R, I, j) * partialDerivative(R, I, i)(q) with * -- The Leibniz rule for all polynomials, by generation: the set of the -- polynomials satisfying it contains the constants and the variables and -- is closed under sums and products. theorem partialDerivative.mul (p q : polynomialRing(R, I)) shows partialDerivative(R, I, i)(p * q) = partialDerivative(R, I, i)(p) * q + p * partialDerivative(R, I, i)(q) proof have parts := CommRing.parts with ring have pParts := polynomialRing.member_parts at R, I, p with * have qIn : q ∈ Ring.carrier(polynomialRing(R, I)) by assumption have constants : ∀ a ∈ R.carrier, polynomialConstant(I, R.carrier, R.zero, a) ∈ leibnizPolynomials(R, I, i) intros a ha have value := polynomialConstant.apply at R, I, a with * have constantIn : polynomialConstant(R, I)(a) ∈ polynomialRing(R, I) := polynomialConstant.mem at R, I, a with * have constantParts := polynomialRing.member_parts at R, I, polynomialConstant(R, I)(a) with * rw ← value apply leibnizPolynomials.membership.backward refine ⟨constantParts, _⟩ intros f hf have derivativeF : partialDerivative(R, I, i)(f) ∈ polynomialRing(R, I) := partialDerivative.map_mem at R, I, i, f with * have scaled := partialDerivative.constant_mul at R, I, i, a, f with * have vanishes := partialDerivative.constant at R, I, i, a with * rw [scaled, vanishes] ring have variables : ∀ j ∈ I, polynomialVariable(I, R.carrier, R.zero, R.one, j) ∈ leibnizPolynomials(R, I, i) intros j hj have variableIn : X(R, I, j) ∈ polynomialRing(R, I) := X.mem at R, I, j with * have variableParts := polynomialRing.member_parts at R, I, X(R, I, j) with * rw ← X.value apply leibnizPolynomials.membership.backward refine ⟨variableParts, _⟩ intros f hf have derivativeF : partialDerivative(R, I, i)(f) ∈ polynomialRing(R, I) := partialDerivative.map_mem at R, I, i, f with * have alternatives : j = i ∨ j ≠ i by tauto cases alternatives with same | apart . rw same have variableI : X(R, I, i) ∈ polynomialRing(R, I) := X.mem at R, I, i with * have rule := partialDerivative.X_self_mul at R, I, i, f with * have unit := partialDerivative.X_self at R, I, i with * rw [rule, unit] ring . have rule := partialDerivative.X_other_mul at R, I, i, j, f with * have vanishes := partialDerivative.X_other at R, I, i, j with * rw [rule, vanishes] ring have sums : ∀ f ∈ leibnizPolynomials(R, I, i), ∀ g ∈ leibnizPolynomials(R, I, i), coefficientAdd(monomials(I), R.carrier, R.add, R.zero, R.neg, R.mul, R.one, f, g) ∈ leibnizPolynomials(R, I, i) intros f hf g hg have dataF := leibnizPolynomials.membership.forward with hf have dataG := leibnizPolynomials.membership.forward with hg have fParts := dataF.left have fIn := polynomialRing.member_of_parts at R, I, f with * have gParts := dataG.left have gIn := polynomialRing.member_of_parts at R, I, g with * have sumForm := polynomialRing.add_apply at R, I, f, g with * have sumIn : f + g ∈ polynomialRing(R, I) := Ring.add_mem with * have sumParts := polynomialRing.member_parts at R, I, f + g with * rw ← sumForm apply leibnizPolynomials.membership.backward refine ⟨sumParts, _⟩ intros h hh have fh : f * h ∈ polynomialRing(R, I) := Ring.mul_mem with * have gh : g * h ∈ polynomialRing(R, I) := Ring.mul_mem with * have derivativeF : partialDerivative(R, I, i)(f) ∈ polynomialRing(R, I) := partialDerivative.map_mem at R, I, i, f with * have derivativeG : partialDerivative(R, I, i)(g) ∈ polynomialRing(R, I) := partialDerivative.map_mem at R, I, i, g with * have derivativeH : partialDerivative(R, I, i)(h) ∈ polynomialRing(R, I) := partialDerivative.map_mem at R, I, i, h with * have ruleF := dataF.right with h, hh have ruleG := dataG.right with h, hh have distribute : (f + g) * h = f * h + g * h by ring have additive := partialDerivative.add at R, I, i, f * h, g * h with * have additiveFG := partialDerivative.add at R, I, i, f, g with * rw [distribute, additive, ruleF, ruleG, additiveFG] ring have products : ∀ f ∈ leibnizPolynomials(R, I, i), ∀ g ∈ leibnizPolynomials(R, I, i), polynomialProduct(I, R.carrier, R.add, R.zero, R.neg, R.mul, R.one, f, g) ∈ leibnizPolynomials(R, I, i) intros f hf g hg have dataF := leibnizPolynomials.membership.forward with hf have dataG := leibnizPolynomials.membership.forward with hg have fParts := dataF.left have fIn := polynomialRing.member_of_parts at R, I, f with * have gParts := dataG.left have gIn := polynomialRing.member_of_parts at R, I, g with * have productForm := polynomialRing.mul_apply at R, I, f, g with * have productIn : f * g ∈ polynomialRing(R, I) := Ring.mul_mem with * have productParts := polynomialRing.member_parts at R, I, f * g with * rw ← productForm apply leibnizPolynomials.membership.backward refine ⟨productParts, _⟩ intros h hh have gh : g * h ∈ polynomialRing(R, I) := Ring.mul_mem with * have derivativeF : partialDerivative(R, I, i)(f) ∈ polynomialRing(R, I) := partialDerivative.map_mem at R, I, i, f with * have derivativeG : partialDerivative(R, I, i)(g) ∈ polynomialRing(R, I) := partialDerivative.map_mem at R, I, i, g with * have derivativeH : partialDerivative(R, I, i)(h) ∈ polynomialRing(R, I) := partialDerivative.map_mem at R, I, i, h with * have derivativeGH : partialDerivative(R, I, i)(g * h) ∈ polynomialRing(R, I) := partialDerivative.map_mem at R, I, i, g * h with * have ruleF := dataF.right with g * h, gh have ruleG := dataG.right with h, hh have ruleFG := dataF.right with g, gIn have reassociate : (f * g) * h = f * (g * h) by ring rw [reassociate, ruleF, ruleG, ruleFG] ring have generated := polynomials.generated at I, R.carrier, R.add, R.zero, R.neg, R.mul, R.one, leibnizPolynomials(R, I, i), p with parts, pParts, constants, variables, sums, products have data := leibnizPolynomials.membership.forward with generated exact data.right with q, qIn theorem partialDerivative.pow (p : polynomialRing(R, I)) (n : Nat) shows partialDerivative(R, I, i)(p ^ (n + 1)) = ringNat(Ring.add(polynomialRing(R, I)), Ring.zero(polynomialRing(R, I)), Ring.one(polynomialRing(R, I)), n + 1) * p ^ n * partialDerivative(R, I, i)(p) proof induction n | zero => have pIn : p ∈ polynomialRing(R, I) by assumption have derivativeIn : partialDerivative(R, I, i)(p) ∈ polynomialRing(R, I) := partialDerivative.map_mem at R, I, i, p with * have onePoly : Ring.one(polynomialRing(R, I)) ∈ polynomialRing(R, I) := Ring.one_mem with * have plus := add.left_unit at 1 have one := Ring.pow_one at polynomialRing(R, I), p with * have zeroPow := Ring.pow_zero at polynomialRing(R, I), p with * have numeralOne := IsRing.numeral_one with (Ring.parts with (CommRing.to_ring with polynomials)) rw [plus, one, zeroPow, numeralOne] ring | succ(k) using ih => have pIn : p ∈ polynomialRing(R, I) by assumption have derivativeIn : partialDerivative(R, I, i)(p) ∈ polynomialRing(R, I) := partialDerivative.map_mem at R, I, i, p with * have shift := add.right_one at k with * rw ← shift have powerIn : p ^ (k + 1) ∈ polynomialRing(R, I) := Ring.pow_mem at polynomialRing(R, I), p, k + 1 with * have powerK : p ^ k ∈ polynomialRing(R, I) := Ring.pow_mem at polynomialRing(R, I), p, k with * have numeralIn : ringNat(Ring.add(polynomialRing(R, I)), Ring.zero(polynomialRing(R, I)), Ring.one(polynomialRing(R, I)), k + 1) ∈ polynomialRing(R, I) := Ring.numeral_mem at polynomialRing(R, I), k + 1 with * have step := Ring.pow_succ at polynomialRing(R, I), p, k + 1 with * have product := partialDerivative.mul at R, I, i, p ^ (k + 1), p with * have powStep := Ring.pow_succ at polynomialRing(R, I), p, k with * have shiftOne := add.right_one at k + 1 with * have numeralStep := ringNat.succ at Ring.add(polynomialRing(R, I)), Ring.zero(polynomialRing(R, I)), Ring.one(polynomialRing(R, I)), k + 1 with * rw [step, product, ih, shiftOne, numeralStep, powStep] ring end Rules