1-- The determinant is linear in each row over any commutative ring (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.DeterminantLinearity8import Determinant9import FiniteLinearity1011section Rings12variable (A add zero neg mul one : Set)13notationring R := (A, add, zero, neg, mul, one)14hypothesisring : IsCommRing(R)1516-- The three matrices agree off row i; row i of P is a times M plus b times N.17theorem determinant.row_linear (n : Nat) (M N P i a b : Set)18requires matrixM : RingMatrix(n, R, M)19requires matrixN : RingMatrix(n, R, N)20requires matrixP : RingMatrix(n, R, P)21requires row : i ∈ n22requires scalarA : a ∈ R23requires scalarB : b ∈ R24requires outsideN : ∀ k ∈ n, ¬(k = i) →∀ j ∈ n, N[k, j] = M[k, j]25requires outsideP : ∀ k ∈ n, ¬(k = i) →∀ j ∈ n, P[k, j] = M[k, j]26requires entries : ∀ j ∈ n, P[i, j] = a * M[i, j] + b * N[i, j]27shows determinant(n, R, P) = a * determinant(n, R, M) + b * determinant(n, R, N)28proof29have finite := Finite.natural at n with*30have permutationsFinite := permutations.finite with finite31have weightsM := determinantTerms.function at n, A, add, zero, neg, mul, one, M with*32have weightsN := determinantTerms.function at n, A, add, zero, neg, mul, one, N with*33have weightsP := determinantTerms.function at n, A, add, zero, neg, mul, one, P with*34have terms : ∀ p ∈ permutations(n), determinantTerms(n, R, P)(p) = a * determinantTerms(n, R, M)(p) + b * determinantTerms(n, R, N)(p)35intros p hp36have permutation := permutations.mem_iff.forward with hp37have injective := Bijective.injective with permutation38have function := Injective.function with injective39have column := FunctionBetween.apply_closed at p, n, n, i with*40have entriesM := permutationEntries.function at n, A, M, p with*41have entriesN := permutationEntries.function at n, A, N, p with*42have entriesP := permutationEntries.function at n, A, P, p with*43have outsideNEntries : ∀ k ∈ n, ¬(k = i) → permutationEntries(n, A, N, p)(k) = permutationEntries(n, A, M, p)(k)44intros k hk distinct45have image := FunctionBetween.apply_closed at p, n, n, k with*46have leftValue := permutationEntries.value at n, A, N, p, k with*47have rightValue := permutationEntries.value at n, A, M, p, k with*48rw [leftValue, rightValue]49exact outsideN with k, hk, distinct, p(k), image50have outsidePEntries : ∀ k ∈ n, ¬(k = i) → permutationEntries(n, A, P, p)(k) = permutationEntries(n, A, M, p)(k)51intros k hk distinct52have image := FunctionBetween.apply_closed at p, n, n, k with*53have leftValue := permutationEntries.value at n, A, P, p, k with*54have rightValue := permutationEntries.value at n, A, M, p, k with*55rw [leftValue, rightValue]56exact outsideP with k, hk, distinct, p(k), image57have entry : permutationEntries(n, A, P, p)(i) = a * permutationEntries(n, A, M, p)(i) + b * permutationEntries(n, A, N, p)(i)58have valueM := permutationEntries.value at n, A, M, p, i with*59have valueN := permutationEntries.value at n, A, N, p, i with*60have valueP := permutationEntries.value at n, A, P, p, i with*61rw [valueP, valueM, valueN]62exact entries with p(i), column63have product := finiteRingProduct.linear_at at n, A, add, zero, neg, mul, one, permutationEntries(n, A, M, p), permutationEntries(n, A, N, p), permutationEntries(n, A, P, p), i, a, b with*64have sign := permutationSign.closed at A, add, zero, neg, mul, one, n, p with*65have closedM := finiteRingProduct.closed at n, A, add, zero, neg, mul, one, permutationEntries(n, A, M, p) with*66have closedN := finiteRingProduct.closed at n, A, add, zero, neg, mul, one, permutationEntries(n, A, N, p) with*67have termM := determinantTerms.value at n, A, add, zero, neg, mul, one, M, p with*68have termN := determinantTerms.value at n, A, add, zero, neg, mul, one, N, p with*69have termP := determinantTerms.value at n, A, add, zero, neg, mul, one, P, p with*70rw [termP, termM, termN, product]71ring72unfold determinant73exact finiteRingSum.linear at permutations(n), A, add, zero, neg, mul, one, determinantTerms(n, R, M), determinantTerms(n, R, N), determinantTerms(n, R, P), a, b with*7475end Rings76