1-- Inserting fresh indices into canonical finite sums (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.Ring.SumExtension8import FiniteSetSum910theorem finiteRingSum.empty (A add zero neg mul one w : Set)11requiresring : IsCommRing(A, add, zero, neg, mul, one)12requires weights : w : ∅→ A13shows finiteRingSum(∅, A, add, zero, neg, mul, one, w) = zero14proof15have finite := Finite.empty16have values : ∀ x ∈∅, w(x) = zero17intros x impossible18exfalso19exactset.empty with impossible20exact finiteRingSum.zero withring, finite, weights, values2122theorem finiteRingSum.insert (V A add zero neg mul one w a : Set)23requiresring : IsCommRing(A, add, zero, neg, mul, one)24requires finite : Finite(V)25requires weights : w : insert(a, V) → A26requires fresh : ¬(a ∈ V)27shows finiteRingSum(insert(a, V), A, add, zero, neg, mul, one, w) =28 call2(add, finiteRingSum(V, A, add, zero, neg, mul, one, restrict(w, V)), w(a))29proof30have subset : V ⊆ insert(a, V)31intros x hx32exact insert.contains with hx33have closed : ∀ x ∈ V, w(x) ∈ A34intros x hx35have member := insert.contains at x, a, V with hx36exact FunctionBetween.apply_closed at w, insert(a, V), A, x with*37have restricted := restrict.function at w, insert(a, V), A, V, A with*38have selected := finiteRingSum.selected at V, A, add, zero, neg, mul, one, restrict(w, V) with*39obtain⟨n, natural, f, enumeration, equation⟩:= selected.right40have injective := Bijective.injective with enumeration41have function := Injective.function with injective42have nFresh := membership.irreflexive at n43have extended := adjoinMap.bijective with enumeration, nFresh, fresh44have successor := natural.successor_as_insert with natural45rw← successor at extended46have extendedInjective := Bijective.injective with extended47have extendedFunction := Injective.function with extendedInjective48have extendedSum := finiteRingSum.enumeration at insert(a, V), A, add, zero, neg, mul, one, w, adjoinMap(f, n, a), succ(n) with*49have oldValues : ∀ i ∈ n, w(adjoinMap(f, n, a)(i)) = restrict(w, V)(f(i))50intros i hi51have oldMember := FunctionBetween.apply_closed at f, n, V, i with*52have oldEdge := FunctionBetween.relates_apply at f, n, V, i with*53have edge := adjoinMap.relates_old at f, n, a, i, f(i) with oldEdge54have next := membership.into_successor at i, n with*55have value := FunctionBetween.apply_value at adjoinMap(f, n, a), succ(n), insert(a, V), i, f(i) with*56have restrictedValue := restrict.apply at w, insert(a, V), A, V, A, f(i) with*57cc58have congr := indexedRingSum.congr at w, restrict(w, V), adjoinMap(f, n, a), f, add, zero, n with natural59haveprefix:= congr with oldValues60have newIndex := membership.self_successor with natural61have newEdge := adjoinMap.relates_new at f, n, a62have newValue := FunctionBetween.apply_value at adjoinMap(f, n, a), succ(n), insert(a, V), n, a with*63rw [extendedSum, indexedRingSum, prefix, newValue, equation]64rfl6566theorem finiteRingSum.insert_zero (V A add zero neg mul one w a : Set)67requiresring : IsCommRing(A, add, zero, neg, mul, one)68requires finite : Finite(V)69requires weights : w : insert(a, V) → A70requires fresh : ¬(a ∈ V)71requires vanishes : w(a) = zero72shows finiteRingSum(insert(a, V), A, add, zero, neg, mul, one, w) =73 finiteRingSum(V, A, add, zero, neg, mul, one, restrict(w, V))74proof75have inserted := finiteRingSum.insert with*76have subset : V ⊆ insert(a, V)77intros x hx78exact insert.contains with hx79have closed : ∀ x ∈ V, w(x) ∈ A80intros x hx81have member := insert.contains at x, a, V with hx82exact FunctionBetween.apply_closed with*83have restricted := restrict.function with*84have sumIn := finiteRingSum.closed with*85rw [inserted, vanishes]86ring87