1-- Ring homomorphisms commute with the Leibniz determinant (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.DeterminantHom8import Determinant9import FiniteHom1011-- Entrywise mapping is useful independently of ring structure.12defgraph matrixMap (I A B h M : Set) (p ∈ I × I) : B := h(M(p))13requires matrix : RingMatrix(I, A, M)14requires function : h : A → B15proof16unfold RingMatrix at matrix17have entry := FunctionBetween.apply_closed at M, I × I, A, p with*18exact FunctionBetween.apply_closed at h, A, B, M(p) with*1920theorem matrixMap.matrix (I A B h M : Set)21requires matrix : RingMatrix(I, A, M)22requires function : h : A → B23shows RingMatrix(I, B, matrixMap(I, A, B, h, M))24proof25unfold RingMatrix26exact matrixMap.function with*2728theorem matrixMap.entry (I A B h M i j : Set)29requires matrix : RingMatrix(I, A, M)30requires function : h : A → B31requires row : i ∈ I32requires column : j ∈ I33shows matrixMap(I, A, B, h, M)[i, j] = h(M[i, j])34proof35have pair := product.pair at i, j, I, I with*36exact matrixMap.value with*3738section Homomorphisms39variable (A add zero neg mul one B plus z minus times unit h : Set)40notationring R := (A, add, zero, neg, mul, one)41notationring S := (B, plus, z, minus, times, unit)42hypothesis source : IsCommRing(R)43hypothesis target : IsCommRing(S)44hypothesis hom : IsRingHom(h, R, S)4546theorem permutationSign.map (I p : Set)47requires finite : Finite(I)48shows h(permutationSign(I, R, p)) = permutationSign(I, S, p)49proof50have inversionsFinite := inversions.finite at I, p with*51have count := cardinality.correct with inversionsFinite52have natural := count.left53have ordinary := IsCommRing.ring with source54have multiplicative := IsRing.multiplicative with ordinary55have oneIn := IsMonoid.unit_in_carrier with multiplicative56have negative := IsRing.neg_closed with ordinary, oneIn57have mapsOne := IsRingHom.one with hom58have mapsNegative := IsRingHom.neg at h, A, add, zero, neg, mul, one, B, plus, z, minus, times, unit, one with*59have power := IsRingHom.pow at A, add, zero, neg, mul, one, B, plus, z, minus, times, unit, h, R[-1], cardinality(inversions(I, p)) with*60simp [permutationSign]6162theorem determinant.map (n : Nat) (M N : Set)63requires matrixM : RingMatrix(n, R, M)64requires matrixN : RingMatrix(n, S, N)65requires entries : ∀ i ∈ n, ∀ j ∈ n, N[i, j] = h(M[i, j])66shows h(determinant(n, R, M)) = determinant(n, S, N)67proof68have finite := Finite.natural at n with*69have permutationsFinite := permutations.finite with finite70have weightsM := determinantTerms.function at n, A, add, zero, neg, mul, one, M with*71have weightsN := determinantTerms.function at n, B, plus, z, minus, times, unit, N with*72have terms : ∀ p ∈ permutations(n), determinantTerms(n, S, N)(p) = h(determinantTerms(n, R, M)(p))73intros p hp74have permutation := permutations.mem_iff.forward with hp75have injective := Bijective.injective with permutation76have function := Injective.function with injective77have entriesM := permutationEntries.function at n, A, M, p with*78have entriesN := permutationEntries.function at n, B, N, p with*79have pointwise : ∀ i ∈ n, permutationEntries(n, B, N, p)(i) = h(permutationEntries(n, A, M, p)(i))80intros i hi81have column := FunctionBetween.apply_closed at p, n, n, i with*82haveleft:= permutationEntries.value at n, B, N, p, i with*83haveright:= permutationEntries.value at n, A, M, p, i with*84rw [left, right]85exact entries with i, hi, p(i), column86have product := finiteRingProduct.map at A, add, zero, neg, mul, one, B, plus, z, minus, times, unit, h, n, permutationEntries(n, A, M, p), permutationEntries(n, B, N, p) with*87have sign := permutationSign.map at A, add, zero, neg, mul, one, B, plus, z, minus, times, unit, h, n, p with*88have multiply := IsRingHom.mul at h, A, add, zero, neg, mul, one, B, plus, z, minus, times, unit, permutationSign(n, R, p), finiteRingProduct(n, R, permutationEntries(n, A, M, p)) with*89have termM := determinantTerms.value at n, A, add, zero, neg, mul, one, M, p with*90have termN := determinantTerms.value at n, B, plus, z, minus, times, unit, N, p with*91rw [termM, termN, multiply, sign, product]92rfl93unfold determinant94exact finiteRingSum.map at A, add, zero, neg, mul, one, B, plus, z, minus, times, unit, h, permutations(n), determinantTerms(n, R, M), determinantTerms(n, S, N) with*9596theorem determinant.map_matrix (n : Nat) (M : Set)97requires matrix : RingMatrix(n, R, M)98shows h(determinant(n, R, M)) = determinant(n, S, matrixMap(n, R, S, h, M))99proof100have function := IsRingHom.function with hom101have mapped := matrixMap.matrix with*102have entries : ∀ i ∈ n, ∀ j ∈ n, matrixMap(n, R, S, h, M)[i, j] = h(M[i, j])103intros i hi j hj104exact matrixMap.entry with*105exact determinant.map with*106107end Homomorphisms108