1-- Linear evaluation of finite-support polynomials from monomial values (ZF).2-- Part of Cumulus, the Grace17 mathematics library.3-- Copyright (c) 2026 Grant Passmore.4-- Released under the Apache License 2.0. See LICENSE in the repository root.5-- Authors: Grant Passmore67module Grace.Cumulus.Algebra.Polynomial.Evaluation8import Origin910defgraph polynomialEvaluationWeights (I D A add zero neg mul one h p : Set) (m ∈ D) : A := call2(mul, p(m), h(m))11requiresring : IsCommRing(A, add, zero, neg, mul, one)12requires values : h : monomials(I) → A13requires polynomial : p ∈ polynomials(I, A, zero)14requires domain : D ⊆ monomials(I)15proof16unfold Subset at domain17have monomial := domain with m, member18have coefficient := polynomials.coefficient at I, A, zero, p, m with*19have image := FunctionBetween.apply_closed at h, monomials(I), A, m with*20have ordinary := IsCommRing.ring withring21exact IsRing.mul_closed at A, add, zero, neg, mul, one, p(m), h(m) with*2223defgraph polynomialEvaluate (I A add zero neg mul one h : Set) (p ∈ polynomials(I, A, zero)) : A :=24 finiteRingSum(functionSupport(p, monomials(I), zero), A, add, zero, neg, mul, one, polynomialEvaluationWeights(I, functionSupport(p, monomials(I), zero), A, add, zero, neg, mul, one, h, p))25requiresring : IsCommRing(A, add, zero, neg, mul, one)26requires values : h : monomials(I) → A27proof28have domain := functionSupport.subset at p, monomials(I), zero29have finite := polynomials.finite_support with member30have weights := polynomialEvaluationWeights.function at I, functionSupport(p, monomials(I), zero), A, add, zero, neg, mul, one, h, p with*31exact finiteRingSum.closed at functionSupport(p, monomials(I), zero), A, add, zero, neg, mul, one, polynomialEvaluationWeights(I, functionSupport(p, monomials(I), zero), A, add, zero, neg, mul, one, h, p) with*3233section Values34variable (I A add zero neg mul one h : Set)35hypothesisring : IsCommRing(A, add, zero, neg, mul, one)36hypothesis values : h : monomials(I) → A37notationring R := (A, add, zero, neg, mul, one)3839theorem polynomialEvaluate.on_domain (p D : Set)40requires polynomial : p ∈ polynomials(I, A, zero)41requires domain : D ⊆ monomials(I)42requires finite : Finite(D)43requires covers : functionSupport(p, monomials(I), zero) ⊆ D44shows polynomialEvaluate(I, A, add, zero, neg, mul, one, h)(p) = finiteRingSum(D, A, add, zero, neg, mul, one, polynomialEvaluationWeights(I, D, A, add, zero, neg, mul, one, h, p))45proof46have ordinary := IsCommRing.ring withring47have zeroIn := IsRing.zero_in_carrier with ordinary48have supportDomain := functionSupport.subset at p, monomials(I), zero49have weights := polynomialEvaluationWeights.function at I, D, A, add, zero, neg, mul, one, h, p with*50have supported := polynomialEvaluationWeights.function at I, functionSupport(p, monomials(I), zero), A, add, zero, neg, mul, one, h, p with*51have agreement : ∀ m ∈ functionSupport(p, monomials(I), zero), polynomialEvaluationWeights(I, D, A, add, zero, neg, mul, one, h, p)(m) = polynomialEvaluationWeights(I, functionSupport(p, monomials(I), zero), A, add, zero, neg, mul, one, h, p)(m)52intros m hm53have included := covers54have inD := included with m, hm55haveleft:= polynomialEvaluationWeights.value at I, D, A, add, zero, neg, mul, one, h, p, m with*56haveright:= polynomialEvaluationWeights.value at I, functionSupport(p, monomials(I), zero), A, add, zero, neg, mul, one, h, p, m with*57cc58have vanishes : ∀ m ∈ D, ¬(m ∈ functionSupport(p, monomials(I), zero)) → polynomialEvaluationWeights(I, D, A, add, zero, neg, mul, one, h, p)(m) = zero59intros m hm outside60have included := domain61have monomial := included with m, hm62have image := FunctionBetween.apply_closed at h, monomials(I), A, m with*63have coefficient := functionSupport.outside at p, monomials(I), zero, m with*64have weight := polynomialEvaluationWeights.value at I, D, A, add, zero, neg, mul, one, h, p, m with*65rw [weight, coefficient]66ring67have extended := finiteRingSum.zero_extension at D, functionSupport(p, monomials(I), zero), A, add, zero, neg, mul, one, polynomialEvaluationWeights(I, D, A, add, zero, neg, mul, one, h, p), polynomialEvaluationWeights(I, functionSupport(p, monomials(I), zero), A, add, zero, neg, mul, one, h, p) with*68have value := polynomialEvaluate.value at I, A, add, zero, neg, mul, one, h, p with*69cc7071theorem polynomialEvaluate.term (a m : Set)72requires coefficient : a ∈ A73requires monomial : m ∈ monomials(I)74shows polynomialEvaluate(I, A, add, zero, neg, mul, one, h)(polynomialTerm(I, A, zero, a, m)) = a * h(m)75proof76have ordinary := IsCommRing.ring withring77have zeroIn := IsRing.zero_in_carrier with ordinary78have polynomial := polynomialTerm.member at I, A, zero, a, m with*79have covers := polynomialTerm.support at I, A, zero, a, m with*80have domain : {m} ⊆ monomials(I) bysimp [Subset, singleton.membership]81have finite := Finite.singleton at m82have member := singleton.self at m83have bounded := polynomialEvaluate.on_domain with*84have weights := polynomialEvaluationWeights.function at I, {m}, A, add, zero, neg, mul, one, h, polynomialTerm(I, A, zero, a, m) with*85have sum := finiteRingSum.singleton with*86have weight := polynomialEvaluationWeights.value at I, {m}, A, add, zero, neg, mul, one, h, polynomialTerm(I, A, zero, a, m), m with*87have point := polynomialTerm.same at I, A, zero, a, m with*88cc8990theorem polynomialEvaluate.zero91shows polynomialEvaluate(I, A, add, zero, neg, mul, one, h)(constantFunction(monomials(I), A, zero)) = zero92proof93have ordinary := IsCommRing.ring withring94have zeroIn := IsRing.zero_in_carrier with ordinary95have unit := monomialOne.member at I96have image := FunctionBetween.apply_closed with*97have selected := polynomialEvaluate.term at I, A, add, zero, neg, mul, one, h, zero, monomialOne(I) with*98have constant := polynomialConstant.zero at I, A, zero with*99unfold polynomialConstant at constant100have zeroProduct : zero * h(monomialOne(I)) = zero byring101cc102103theorem polynomialEvaluationWeights.add (p q D : Set)104requires memberP : p ∈ polynomials(I, A, zero)105requires memberQ : q ∈ polynomials(I, A, zero)106requires domain : D ⊆ monomials(I)107shows polynomialEvaluationWeights(I, D, A, add, zero, neg, mul, one, h, coefficientAdd(monomials(I), A, add, zero, neg, mul, one, p, q)) = coefficientAdd(D, A, add, zero, neg, mul, one, polynomialEvaluationWeights(I, D, A, add, zero, neg, mul, one, h, p), polynomialEvaluationWeights(I, D, A, add, zero, neg, mul, one, h, q))108proof109have memberSum := polynomials.add at I, A, add, zero, neg, mul, one, p, q with*110have functionP := polynomials.function with memberP111have functionQ := polynomials.function with memberQ112have weightsP := polynomialEvaluationWeights.function at I, D, A, add, zero, neg, mul, one, h, p with*113have weightsQ := polynomialEvaluationWeights.function at I, D, A, add, zero, neg, mul, one, h, q with*114have leftFunction := polynomialEvaluationWeights.function at I, D, A, add, zero, neg, mul, one, h, coefficientAdd(monomials(I), A, add, zero, neg, mul, one, p, q) with*115have rightFunction := coefficientAdd.function at D, A, add, zero, neg, mul, one, polynomialEvaluationWeights(I, D, A, add, zero, neg, mul, one, h, p), polynomialEvaluationWeights(I, D, A, add, zero, neg, mul, one, h, q) with*116apply FunctionBetween.ext with leftFunction, rightFunction117intros m hm118have included := domain119have monomial := included with m, hm120have coefficientP := polynomials.coefficient at I, A, zero, p, m with*121have coefficientQ := polynomials.coefficient at I, A, zero, q, m with*122have image := FunctionBetween.apply_closed at h, monomials(I), A, m with*123have source := coefficientAdd.value at monomials(I), A, add, zero, neg, mul, one, p, q, m with*124haveleft:= polynomialEvaluationWeights.value at I, D, A, add, zero, neg, mul, one, h, coefficientAdd(monomials(I), A, add, zero, neg, mul, one, p, q), m with*125have first := polynomialEvaluationWeights.value at I, D, A, add, zero, neg, mul, one, h, p, m with*126have second := polynomialEvaluationWeights.value at I, D, A, add, zero, neg, mul, one, h, q, m with*127haveright:= coefficientAdd.value at D, A, add, zero, neg, mul, one, polynomialEvaluationWeights(I, D, A, add, zero, neg, mul, one, h, p), polynomialEvaluationWeights(I, D, A, add, zero, neg, mul, one, h, q), m with*128have distribute : (p(m) + q(m)) * h(m) = p(m) * h(m) + q(m) * h(m) byring129cc130131theorem polynomialEvaluate.add (p q : Set)132requires memberP : p ∈ polynomials(I, A, zero)133requires memberQ : q ∈ polynomials(I, A, zero)134shows polynomialEvaluate(I, A, add, zero, neg, mul, one, h)(coefficientAdd(monomials(I), A, add, zero, neg, mul, one, p, q)) = polynomialEvaluate(I, A, add, zero, neg, mul, one, h)(p) + polynomialEvaluate(I, A, add, zero, neg, mul, one, h)(q)135proof136have memberSum := polynomials.add at I, A, add, zero, neg, mul, one, p, q with*137have functionP := polynomials.function with memberP138have functionQ := polynomials.function with memberQ139have finiteP := polynomials.finite_support with memberP140have finiteQ := polynomials.finite_support with memberQ141have finite := Finite.union with finiteP, finiteQ142have domainP := functionSupport.subset at p, monomials(I), zero143have domainQ := functionSupport.subset at q, monomials(I), zero144have domain : functionSupport(p, monomials(I), zero) ∪ functionSupport(q, monomials(I), zero) ⊆ monomials(I)145simp [Subset, union2.membership]146have coversP : functionSupport(p, monomials(I), zero) ⊆ functionSupport(p, monomials(I), zero) ∪ functionSupport(q, monomials(I), zero)147simp [Subset, union2.membership]148have coversQ : functionSupport(q, monomials(I), zero) ⊆ functionSupport(p, monomials(I), zero) ∪ functionSupport(q, monomials(I), zero)149simp [Subset, union2.membership]150have coversSum := coefficientAdd.support at monomials(I), A, add, zero, neg, mul, one, p, q with*151have sumValue := polynomialEvaluate.on_domain withring, values, memberSum, domain, finite, coversSum152have firstValue := polynomialEvaluate.on_domain withring, values, memberP, domain, finite, coversP153have secondValue := polynomialEvaluate.on_domain withring, values, memberQ, domain, finite, coversQ154have weightsP := polynomialEvaluationWeights.function at I, functionSupport(p, monomials(I), zero) ∪ functionSupport(q, monomials(I), zero), A, add, zero, neg, mul, one, h, p with*155have weightsQ := polynomialEvaluationWeights.function at I, functionSupport(p, monomials(I), zero) ∪ functionSupport(q, monomials(I), zero), A, add, zero, neg, mul, one, h, q with*156have weightsSum := polynomialEvaluationWeights.add at I, A, add, zero, neg, mul, one, h, p, q, functionSupport(p, monomials(I), zero) ∪ functionSupport(q, monomials(I), zero) with*157have distribute := finiteRingSum.add at functionSupport(p, monomials(I), zero) ∪ functionSupport(q, monomials(I), zero), A, add, zero, neg, mul, one, polynomialEvaluationWeights(I, functionSupport(p, monomials(I), zero) ∪ functionSupport(q, monomials(I), zero), A, add, zero, neg, mul, one, h, p), polynomialEvaluationWeights(I, functionSupport(p, monomials(I), zero) ∪ functionSupport(q, monomials(I), zero), A, add, zero, neg, mul, one, h, q) with*158cc159160theorem polynomialEvaluate.in_carrier (p : Set)161requires polynomial : p ∈ polynomials(I, A, zero)162shows polynomialEvaluate(I, A, add, zero, neg, mul, one, h)(p) ∈ A163proof164have function := polynomialEvaluate.function at I, A, add, zero, neg, mul, one, h with*165exact FunctionBetween.apply_closed with function, polynomial166167theorem polynomialEvaluate.neg (p : Set)168requires polynomial : p ∈ polynomials(I, A, zero)169shows polynomialEvaluate(I, A, add, zero, neg, mul, one, h)(coefficientNeg(monomials(I), A, add, zero, neg, mul, one, p)) = -polynomialEvaluate(I, A, add, zero, neg, mul, one, h)(p)170proof171have negative := polynomials.neg with*172have valueP := polynomialEvaluate.in_carrier at I, A, add, zero, neg, mul, one, h, p with*173have valueNeg := polynomialEvaluate.in_carrier at I, A, add, zero, neg, mul, one, h, coefficientNeg(monomials(I), A, add, zero, neg, mul, one, p) with*174have functionP := polynomials.function with polynomial175have inverse := coefficientAdd.inverse at monomials(I), A, add, zero, neg, mul, one, p with*176have sum := polynomialEvaluate.add at I, A, add, zero, neg, mul, one, h, p, coefficientNeg(monomials(I), A, add, zero, neg, mul, one, p) with*177have zeroValue := polynomialEvaluate.zero at I, A, add, zero, neg, mul, one, h with*178have equation : polynomialEvaluate(I, A, add, zero, neg, mul, one, h)(p) + polynomialEvaluate(I, A, add, zero, neg, mul, one, h)(coefficientNeg(monomials(I), A, add, zero, neg, mul, one, p)) = zero179cc180linear_combination equation181182end Values183