1-- Entries of the bundled matrix operations: under CommRing(R) a binder2-- (M : R ^ n × n) is a square matrix, its elements carry M + N,3-- M * N, and -M, the constants are matrixRing(R, n)[0] and4-- matrixRing(R, n)[1], and each operation is read entry by entry; the5-- determinant and the adjugate of a square matrix are det(M) and adj(M)6-- Part of Cumulus, the Grace17 mathematics library.7-- Copyright (c) 2026 Grant Passmore.8-- Released under the Apache License 2.0. See LICENSE in the repository root.9-- Authors: Grant Passmore1011module Grace.Cumulus.Algebra.Ring.MatrixEntries12import MatrixRing1314section Entries15variable (R : Set) (n : Nat)16hypothesis comm : CommRing(R)1718theorem matrixRing.add_entry (M N : R ^ n × n) (i j : Set)19requires row : i ∈ n20requires column : j ∈ n21shows (M + N)[i, j] = M[i, j] + N[i, j]22proof23have matrixM := Matrix.square at M, R, n withassumption24have matrixN := Matrix.square at N, R, n withassumption25have sum := matrixAddition.apply at R, n, M, N with*26have entry := matrixSum.entry at R, n, M, N, i, j with*27rw [matrixRing.addOf, sum, entry]28rfl2930theorem matrixRing.mul_entry (M N : R ^ n × n) (i j : Set)31requires row : i ∈ n32requires column : j ∈ n33shows (M * N)[i, j] = matrixProductEntry(n, Ring.carrier(R), Ring.add(R),34 Ring.zero(R), Ring.neg(R), Ring.mul(R), Ring.one(R), M, N, i, j)35proof36have matrixM := Matrix.square at M, R, n withassumption37have matrixN := Matrix.square at N, R, n withassumption38have product := matrixMultiplication.apply at R, n, M, N with*39have entry := matrixProduct.entry at R, n, M, N, i, j with*40rw [matrixRing.mulOf, product, entry]41rfl4243theorem matrixRing.neg_entry (M : R ^ n × n) (i j : Set)44requires row : i ∈ n45requires column : j ∈ n46shows (-M)[i, j] = -M[i, j]47proof48have matrix := Matrix.square at M, R, n withassumption49have negation := matrixNegation.value at R, n, M with*50have entry := matrixNegative.entry at R, n, M, i, j with*51rw [matrixRing.negOf, negation, entry]52rfl5354theorem matrixRing.zero_entry (i j : Set)55requires row : i ∈ n56requires column : j ∈ n57shows matrixRing(R, n)[0][i, j] = R[0]58proof59have entry := zeroMatrix.entry at R, n, i, j with*60rw [matrixRing.zeroOf, entry]61rfl6263theorem matrixRing.one_entry (i j : Set)64requires row : i ∈ n65requires column : j ∈ n66shows matrixRing(R, n)[1][i, j] = singleValue(R.carrier, R.zero, R.one, j, i)67proof68have entry := oneMatrix.entry at R, n, i, j with*69rw [matrixRing.oneOf, entry]70rfl7172theorem matrixRing.ext (M N : R ^ n × n)73requires entries : ∀ i ∈ n, ∀ j ∈ n, M[i, j] = N[i, j]74shows M = N75proof76have matrixM := Matrix.square at M, R, n withassumption77have matrixN := Matrix.square at N, R, n withassumption78exact squareMatrices.ext with matrixM, matrixN, entries7980-- The determinant and the adjugate of a square matrix.81theorem Matrix.det_mem (M : R ^ n × n)82shows det(M) ∈ R83proof84have parts := CommRing.parts with comm85have matrix := Matrix.square at M, R, n withassumption86have shape := squareMatrices.membership.forward with matrix87exact determinant.closed with parts, shape8889theorem Matrix.adj_matrix (M : R ^ n × n)90shows adj(M) : R ^ n × n91proof92have parts := CommRing.parts with comm93have matrix := Matrix.square at M, R, n withassumption94have shape := squareMatrices.membership.forward with matrix95have finite := Finite.natural at n96have adjugate := adjugate.matrix at n, R.carrier, R.add, R.zero, R.neg,97 R.mul, R.one, M with*98have square := squareMatrices.membership.backward with adjugate99exact Matrix.of_square with square100101theorem Matrix.adj_entry (M : R ^ n × n) (i j : Set)102requires row : i ∈ n103requires column : j ∈ n104shows adj(M)[i, j] = cofactorRow(n, R.carrier, R.add, R.zero, R.neg, R.mul,105 R.one, M, j)(i)106proof107have parts := CommRing.parts with comm108have matrix := Matrix.square at M, R, n withassumption109have shape := squareMatrices.membership.forward with matrix110have finite := Finite.natural at n111exact adjugate.entry with*112113end Entries114