1-- Ring homomorphisms preserve finite sums and products, pointwise (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.FiniteHom8import FiniteProduct9import Group.Power1011section Homomorphisms12variable (A add zero neg mul one B plus z minus times unit h : Set)13notationring R := (A, add, zero, neg, mul, one)14notationring S := (B, plus, z, minus, times, unit)15hypothesis source : IsCommRing(R)16hypothesis target : IsCommRing(S)17hypothesis hom : IsRingHom(h, R, S)1819theorem indexedRingSum.map (w v f : Set, n : Nat)20shows WeightedValues(w, f, A, n) →21 (∀ i ∈ n, v(f(i)) = h(w(f(i)))) →22 h(indexedRingSum(w, f, add, zero, n)) = indexedRingSum(v, f, plus, z, n)23proof24induction n25| zero =>26intros values equations27rw [indexedRingSum, indexedRingSum]28exact IsRingHom.zero with hom29| succ(k) using ih =>30intros values equations31haveprefix:= WeightedValues.prefix at w, f, A, k with*32have last := WeightedValues.last at w, f, A, k with*33have smaller : ∀ i ∈ k, v(f(i)) = h(w(f(i)))34intros i hi35have next := membership.into_successor at i, k with*36exact equations with i, next37have lastEquation := equations with k, membership.self_successor at k with*38have previous := ih withprefix, smaller39have closure := indexedRingSum.closed at A, add, zero, neg, mul, one, w, f, k with*40have prefixIn := closure withprefix41have preserved := IsRingHom.add at h, A, add, zero, neg, mul, one, B, plus, z, minus, times, unit, indexedRingSum(w, f, add, zero, k), w(f(k)) with*42rw [indexedRingSum, indexedRingSum, preserved, previous, lastEquation]43rfl4445theorem finiteRingSum.map (V w v : Set)46requires finite : Finite(V)47requires weightsW : w : V → R48requires weightsV : v : V → S49requires entries : ∀ i ∈ V, v(i) = h(w(i))50shows h(finiteRingSum(V, R, w)) = finiteRingSum(V, S, v)51proof52have selected := finiteRingSum.selected at V, A, add, zero, neg, mul, one, w with*53obtain⟨n, natural, f, enumeration, equationW⟩:= selected.right54have injective := Bijective.injective with enumeration55have function := Injective.function with injective56have values := WeightedValues.of_functions with weightsW, function57have equationV := finiteRingSum.enumeration at V, B, plus, z, minus, times, unit, v, f, n with*58have equations : ∀ i ∈ n, v(f(i)) = h(w(f(i)))59intros i hi60have member := FunctionBetween.apply_closed with*61exact entries with f(i), member62have preserved := indexedRingSum.map at A, add, zero, neg, mul, one, B, plus, z, minus, times, unit, h, w, v, f, n with*63rw [equationW, equationV]64exact preserved with values, equations6566theorem indexedRingProduct.map (w v f : Set, n : Nat)67shows WeightedValues(w, f, A, n) →68 (∀ i ∈ n, v(f(i)) = h(w(f(i)))) →69 h(indexedRingProduct(w, f, mul, one, n)) = indexedRingProduct(v, f, times, unit, n)70proof71induction n72| zero =>73intros values equations74rw [indexedRingProduct, indexedRingProduct]75exact IsRingHom.one with hom76| succ(k) using ih =>77intros values equations78haveprefix:= WeightedValues.prefix at w, f, A, k with*79have last := WeightedValues.last at w, f, A, k with*80have smaller : ∀ i ∈ k, v(f(i)) = h(w(f(i)))81intros i hi82have next := membership.into_successor at i, k with*83exact equations with i, next84have lastEquation := equations with k, membership.self_successor at k with*85have previous := ih withprefix, smaller86have closure := indexedRingProduct.closed at A, add, zero, neg, mul, one, w, f, k with*87have prefixIn := closure withprefix88have preserved := IsRingHom.mul at h, A, add, zero, neg, mul, one, B, plus, z, minus, times, unit, indexedRingProduct(w, f, mul, one, k), w(f(k)) with*89rw [indexedRingProduct, indexedRingProduct, preserved, previous, lastEquation]90rfl9192theorem finiteRingProduct.map (V w v : Set)93requires finite : Finite(V)94requires weightsW : w : V → R95requires weightsV : v : V → S96requires entries : ∀ i ∈ V, v(i) = h(w(i))97shows h(finiteRingProduct(V, R, w)) = finiteRingProduct(V, S, v)98proof99have selected := finiteRingProduct.selected at V, A, add, zero, neg, mul, one, w with*100obtain⟨n, natural, f, enumeration, equationW⟩:= selected.right101have injective := Bijective.injective with enumeration102have function := Injective.function with injective103have values := WeightedValues.of_functions with weightsW, function104have equationV := finiteRingProduct.enumeration at V, B, plus, z, minus, times, unit, v, f, n with*105have equations : ∀ i ∈ n, v(f(i)) = h(w(f(i)))106intros i hi107have member := FunctionBetween.apply_closed with*108exact entries with f(i), member109have preserved := indexedRingProduct.map at A, add, zero, neg, mul, one, B, plus, z, minus, times, unit, h, w, v, f, n with*110rw [equationW, equationV]111exact preserved with values, equations112113theorem IsRingHom.pow (x : Set, n : Nat)114requires element : x ∈ R115shows h(monoidPow(R, x, n)) = monoidPow(S, h(x), n)116proof117induction n118| zero =>119rw [monoidPow.zero, monoidPow.zero]120exact IsRingHom.one with hom121| succ(k) using ih =>122have ordinary := IsCommRing.ring with source123have multiplicative := IsRing.multiplicative with ordinary124have product := IsRingHom.mul at h, A, add, zero, neg, mul, one, B, plus, z, minus, times, unit, x, monoidPow(R, x, k) with*125rw [monoidPow.succ, monoidPow.succ, product, ih]126rfl127128end Homomorphisms129