hex

1.3. Elementary operations🔗

The elementary row operations work over any ring. Each has a determinant law, proved in HexDeterminant. HexRowReduce uses them for Gauss-Jordan reduction over a field.

🔗def
Hex.Matrix.rowSwap.{u_1} {R : Type u_1} {n m : } (M : Hex.Matrix R n m) (i j : Fin n) : Hex.Matrix R n m
Hex.Matrix.rowSwap.{u_1} {R : Type u_1} {n m : } (M : Hex.Matrix R n m) (i j : Fin n) : Hex.Matrix R n m

Swap rows i and j in a dense matrix.

Implemented with Vector.swap, which updates the dense backing store in place when M is uniquely referenced, rather than reading both rows and writing them back through two sets (which forces a copy of the outer vector).

🔗def
Hex.Matrix.rowScale.{u_1} {R : Type u_1} {n m : } [Mul R] (M : Hex.Matrix R n m) (i : Fin n) (c : R) : Hex.Matrix R n m
Hex.Matrix.rowScale.{u_1} {R : Type u_1} {n m : } [Mul R] (M : Hex.Matrix R n m) (i : Fin n) (c : R) : Hex.Matrix R n m

Scale row i by c.

Vector.modify frees the row slot before applying the update, so when M is uniquely referenced both the outer vector and the row itself are updated in place: Vector.map reuses the freed row's backing store.

🔗def
Hex.Matrix.rowAdd.{u_1} {R : Type u_1} {n m : } [Mul R] [Add R] (M : Hex.Matrix R n m) (src dst : Fin n) (c : R) : Hex.Matrix R n m
Hex.Matrix.rowAdd.{u_1} {R : Type u_1} {n m : } [Mul R] [Add R] (M : Hex.Matrix R n m) (src dst : Fin n) (c : R) : Hex.Matrix R n m

Replace row dst by row dst + c * row src.

The source row is read once into rsrc, so the only remaining reference to M is the consuming Vector.modify, which updates the outer vector in place when M is uniquely referenced (dropping the old row dst). The replacement row is built fresh, since every entry of it changes.