1-- Coordinatewise monomial divisibility and quotient monomials (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.Divisibility8import Monomial910predicate MonomialDivides (I m n : Set) :=∀ i ∈ I, m(i) ≤ n(i)1112theorem MonomialDivides.reflexive (I m : Set)13requires member : m ∈ monomials(I)14shows MonomialDivides(I, m, m)15proof16intros i hi17have natural := monomials.exponent with*18exact LessEqual.reflexive with*1920theorem MonomialDivides.transitive (I m n p : Set)21requires memberM : m ∈ monomials(I)22requires memberN : n ∈ monomials(I)23requires third : p ∈ monomials(I)24requiresleft : MonomialDivides(I, m, n)25requiresright : MonomialDivides(I, n, p)26shows MonomialDivides(I, m, p)27proof28intros i hi29have mNat := monomials.exponent at I, m, i with*30have nNat := monomials.exponent at I, n, i with*31have pNat := monomials.exponent at I, p, i with*32have mn :=leftwith i, hi33have np :=rightwith i, hi34exact LessEqual.transitive with*3536theorem MonomialDivides.antisymmetric (I m n : Set)37requires memberM : m ∈ monomials(I)38requires memberN : n ∈ monomials(I)39requiresleft : MonomialDivides(I, m, n)40requiresright : MonomialDivides(I, n, m)41shows m = n42proof43apply monomials.ext with memberM, memberN44intros i hi45have mNat := monomials.exponent at I, m, i with*46have nNat := monomials.exponent at I, n, i with*47have mn :=leftwith i, hi48have nm :=rightwith i, hi49exact LessEqual.antisymmetric with*5051theorem MonomialDivides.insert (I j m n : Set)52requires previous : MonomialDivides(I, m, n)53requires coordinate : m(j) ≤ n(j)54shows MonomialDivides(insert(j, I), m, n)55proof56intros i hi57have alternatives := insert.membership.forward with hi58cases alternatives with equal | old59 . rw equal60exact coordinate61 . exact previous with i, old6263defunique naturalDifference (a b : Nat) (k ∈ ℕ) := a + k = b64requires bounded : a ≤ b65proof66obtain⟨k, natural, equation⟩:= bounded67have member := nat.omega.forward with natural68refine⟨k, member, equation⟩69uniqueness70intros u hu memberM v hv memberN71have equal : a + u = a + v bycc72exact add.left_cancel with equal7374theorem naturalDifference.natural (a b : Nat)75requires bounded : a ≤ b76showsNat(naturalDifference(a, b))77proof78have selected := naturalDifference.selected at a, b with*79exact nat.omega.backward with selected.left8081theorem naturalDifference.add (a b : Nat)82requires bounded : a ≤ b83shows a + naturalDifference(a, b) = b84proof85have selected := naturalDifference.selected at a, b with*86exact selected.right8788defgraph monomialQuotient (I m n : Set) (i ∈ I) : ℕ := naturalDifference(m(i), n(i))89requires memberM : m ∈ monomials(I)90requires memberN : n ∈ monomials(I)91requires divides : MonomialDivides(I, m, n)92proof93have mNat := monomials.exponent at I, m, i with*94have nNat := monomials.exponent at I, n, i with*95have bounded := divides with i, member96have selected := naturalDifference.selected at m(i), n(i) with*97exact selected.left9899theorem monomialQuotient.equation (I m n i : Set)100requires memberM : m ∈ monomials(I)101requires memberN : n ∈ monomials(I)102requires divides : MonomialDivides(I, m, n)103requires index : i ∈ I104shows m(i) + monomialQuotient(I, m, n)(i) = n(i)105proof106have value := monomialQuotient.value at I, m, n, i with*107have mNat := monomials.exponent at I, m, i with*108have nNat := monomials.exponent at I, n, i with*109have bounded := divides with i, index110rw value111exact naturalDifference.add with*112113theorem monomialQuotient.support (I m n : Set)114requires memberM : m ∈ monomials(I)115requires memberN : n ∈ monomials(I)116requires divides : MonomialDivides(I, m, n)117shows functionSupport(monomialQuotient(I, m, n), I, 0) ⊆ functionSupport(n, I, 0)118proof119have function := monomialQuotient.function at I, m, n with*120intros i hi121have data := functionSupport.membership.forward with hi122have mNat := monomials.exponent at I, m, i with*123have valueIn := FunctionBetween.apply_closed at monomialQuotient(I, m, n), I, ℕ, i with*124have qNat := nat.omega.backward with valueIn125have equation := monomialQuotient.equation at I, m, n, i with*126have nonzero : n(i) ≠0127intro zeroValue128rw zeroValue at equation129have zeros := add.eq_zero at monomialQuotient(I, m, n)(i), m(i) with*130have both := zeros with equation131exact data.right with both.right132exact functionSupport.membership.backward with⟨data.left, nonzero⟩133134theorem monomialQuotient.member (I m n : Set)135requires memberM : m ∈ monomials(I)136requires memberN : n ∈ monomials(I)137requires divides : MonomialDivides(I, m, n)138shows monomialQuotient(I, m, n) ∈ monomials(I)139proof140have map := monomials.map with memberN141have finite := CoefficientMap.finite_support with map142have support := monomialQuotient.support with*143have finiteQ := Finite.subset with finite, support144have function := monomialQuotient.function at I, m, n with*145apply monomials.contains146unfold CoefficientMap147refine⟨function, finiteQ⟩148149theorem monomialQuotient.product (I m n : Set)150requires memberM : m ∈ monomials(I)151requires memberN : n ∈ monomials(I)152requires divides : MonomialDivides(I, m, n)153shows monomialProduct(I, m, monomialQuotient(I, m, n)) = n154proof155have quotient := monomialQuotient.member with*156have product := monomialProduct.member at I, m, monomialQuotient(I, m, n) with*157apply monomials.ext with product, memberN158intros i hi159have value := monomialProduct.value at I, m, monomialQuotient(I, m, n), i with*160rw value161exact monomialQuotient.equation with*162163theorem MonomialDivides.product (I m q : Set)164requires memberM : m ∈ monomials(I)165requires memberN : q ∈ monomials(I)166shows MonomialDivides(I, m, monomialProduct(I, m, q))167proof168intros i hi169have mNat := monomials.exponent at I, m, i with*170have qNat := monomials.exponent at I, q, i with*171have value := monomialProduct.value at I, m, q, i with*172rw value173exact LessEqual.add_right with*174175theorem MonomialDivides.iff_factor (I m n : Set)176requires memberM : m ∈ monomials(I)177requires memberN : n ∈ monomials(I)178shows MonomialDivides(I, m, n) ↔∃ q ∈ monomials(I), monomialProduct(I, m, q) = n179proof180constructor181 . intro divides182have quotient := monomialQuotient.member with*183have product := monomialQuotient.product with*184refine⟨monomialQuotient(I, m, n), quotient, product⟩185 . intro factored186obtain⟨q, member, equation⟩:= factored187have divides := MonomialDivides.product at I, m, q with*188 rwa equation at divides189