1-- Copying a matrix row as a function graph, with coordinate equations (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.MatrixRows8import Determinant910defunique matrixCopyRowEntry (I A M i r p : Set) (a ∈ A) :=11∃ k ∈ I, ∃ j ∈ I, p = (k, j) ∧12 (k = i → a = M[r, j]) ∧ (k ≠ i → a = M[k, j])13requires matrix : RingMatrix(I, A, M)14requires source : r ∈ I15requires pair : p ∈ I × I16proof17obtain⟨bound, k, hk, j, hj, shape⟩:= product.membership.forward at18 I, I, p with pair19have original := RingMatrix.entry at I, A, M, k, j with*20have copied := RingMatrix.entry at I, A, M, r, j with*21have alternatives : k = i ∨ k ≠ i22tauto23cases alternatives with same | different24 . refine⟨M[r, j], copied, k, hk, j, hj, shape, ?_⟩25constructor26 . intro equal27rfl28 . intro unequal29exfalso30exact unequal with same31 . refine⟨M[k, j], original, k, hk, j, hj, shape, ?_⟩32constructor33 . intro equal34exfalso35exact different with equal36 . intro unequal37rfl38uniqueness39intros u hu first v hv second40obtain⟨k, hk, j, hj, shapeU, sameU, otherU⟩:= first41obtain⟨l, hl, s, hs, shapeV, sameV, otherV⟩:= second42have pairs : (k, j) = (l, s)43cc44have coordinates := orderedPair.injective at k, j, l, s with pairs45have alternatives : k = i ∨ k ≠ i46tauto47cases alternatives with same | different48 . haveleft : u = M[r, j]49exact sameU with same50haveright : v = M[r, s]51apply sameV52cc53cc54 . haveleft : u = M[k, j]55exact otherU with different56have distinct : l ≠ i57intro equal58apply different59cc60haveright:= otherV with distinct61cc6263defgraph matrixCopyRow (I A M i r : Set) (p ∈ I × I) : A := matrixCopyRowEntry(I, A, M, i, r, p)64requires matrix : RingMatrix(I, A, M)65requires source : r ∈ I66proof67have selected := matrixCopyRowEntry.selected at I, A, M, i, r, p with*68exact selected.left6970theorem matrixCopyRow.matrix (I A M i r : Set)71requires matrix : RingMatrix(I, A, M)72requires source : r ∈ I73shows RingMatrix(I, A, matrixCopyRow(I, A, M, i, r))74proof75unfold RingMatrix76exact matrixCopyRow.function with*7778theorem matrixCopyRow.entry (I A M i r k j : Set)79requires matrix : RingMatrix(I, A, M)80requires source : r ∈ I81requires row : k ∈ I82requires column : j ∈ I83shows (k = i → matrixCopyRow(I, A, M, i, r)[k, j] = M[r, j]) ∧84 (k ≠ i → matrixCopyRow(I, A, M, i, r)[k, j] = M[k, j])85proof86have pair := product.pair at k, j, I, I with*87have value := matrixCopyRow.value at I, A, M, i, r, (k, j) with*88have selected := matrixCopyRowEntry.selected at I, A, M, i, r, (k, j) with*89obtain⟨l, hl, s, hs, shape, same, other⟩:= selected.right90have coordinates := orderedPair.injective with shape91rw value92constructor93 . intro equal94have match : l = i bycc95have result := same with match96cc97 . intro different98have distinct : l ≠ i99intro equal100apply different101cc102have result := other with distinct103cc104105-- Public rewrite lemmas avoid unpacking the conditional specification.106theorem matrixCopyRow.same (I A M i r j : Set)107requires matrix : RingMatrix(I, A, M)108requires source : r ∈ I109requires row : i ∈ I110requires column : j ∈ I111shows matrixCopyRow(I, A, M, i, r)[i, j] = M[r, j]112proof113have entry := matrixCopyRow.entry at I, A, M, i, r, i, j with*114have equal : i = i byrfl115exact entry.left with equal116117theorem matrixCopyRow.other (I A M i r k j : Set)118requires matrix : RingMatrix(I, A, M)119requires source : r ∈ I120requires row : k ∈ I121requires column : j ∈ I122requires different : k ≠ i123shows matrixCopyRow(I, A, M, i, r)[k, j] = M[k, j]124proof125have entry := matrixCopyRow.entry at I, A, M, i, r, k, j with*126exact entry.right with different127