Repository: math-comp/math-comp
Pull request #1385: Generalize some results in matrix.v using potentally-zero (semi)rings
Author: login: pi8027
Labels: name: kind: enhancement
description: Issue or PR about addition of features.
Created: 2025-04-02T11:13:37Z | Merged: 2025-04-04T19:51:22Z

##### Motivation for this change

This PR propagates the changes made by #1319 to `matrix.v`. For example, the potentially-zero (semi)ring instances on square matrices do not require the structural condition that the size is `n.+1`.

##### Minimal TODO list

<!-- please fill in the following checklist -->
- [x] added changelog entries with `doc/changelog/make-entry.sh`

<!-- only append to minimize problems when merging/rebasing -->
<!-- consider the use of `changelog/changes.sh` from
     https://github.com/math-comp/tools to generate the changelog -->

- [x] added corresponding documentation in the headers
- [x] tried to abide by the [contribution guide](https://github.com/math-comp/math-comp/blob/master/CONTRIBUTING.md)
- [x] this PR contains an optimum number of meaningful commits

See [this Checklist](https://github.com/math-comp/math-comp/wiki/Checklist-for-creating-and-review-PRs) for details.

<!-- Cross-out the above items using ~crossed out item~ if they happen not to be relevant -->

<!-- leave this note as a reminder to reviewers -->
##### Automatic note to reviewers

Read [this Checklist](https://github.com/math-comp/math-comp/wiki/Checklist-for-creating-and-review-PRs).



Diff:
diff --git a/algebra/matrix.v b/algebra/matrix.v
index 15c62b4a4d..5d1defd901 100644
--- a/algebra/matrix.v
+++ b/algebra/matrix.v
@@ -110,14 +110,14 @@ From mathcomp Require Import prime binomial ssralg countalg finalg zmodp bigop.
 (*       vec_mx v == the inverse of mxvec, reshaping a vector of width m * n  *)
 (*                   back into into an m x n rectangular matrix.              *)
 (* In 'M[R]_(m, n), R can be any type, but 'M[R]_(m, n) inherits the eqType,  *)
-(* choiceType, countType, finType, zmodType structures of R; 'M[R]_(m, n)     *)
-(* also has a natural lmodType R structure when R has a nzRingType structure. *)
-(* Because the type of matrices specifies their dimension, only non-trivial   *)
-(* square matrices (of type 'M[R]_n.+1) can inherit the ring structure of R;  *)
-(* indeed they then have an algebra structure (lalgType R, or algType R if R  *)
-(* is a comNzRingType, or even unitAlgType if R is a comUnitRingType).        *)
+(* choiceType, countType, finType, nmodType, and zmodType structures from R;  *)
+(* 'M[R]_(m, n) also forms a natural lmodType R when R is a pzRingType.       *)
+(* Square matrices of type 'M[R]_n (resp. non-trivial square matrices of type *)
+(* 'M[R]_n.+1) inherit the pz(Semi)RingType (resp. nz(Semi)RingType) structure*)
+(* from R; indeed they then have an algebra structure (lalgType R, or algType *)
+(* R if R is a comNzRingType, or even unitAlgType if R is a comUnitRingType). *)
 (*   We thus provide separate syntax for the general matrix multiplication,   *)
-(* and other operations for matrices over a nzRingType R:                     *)
+(* and other operations for matrices over a pzRingType R:                     *)
 (*         A *m B == the matrix product of A and B; the width of A must be    *)
 (*                   equal to the height of B.                                *)
 (*           a%:M == the scalar matrix with a's on the main diagonal; in      *)
@@ -2274,9 +2274,9 @@ End MapZmodMatrix.
 
 Section MatrixAlgebra.
 
-Variable R : nzSemiRingType.
+Variable R : pzSemiRingType.
 
-Section NzSemiRingModule.
+Section SemiRingModule.
 
 (* The ring module/vector space structure *)
 
@@ -2305,7 +2305,7 @@ Proof. by apply/matrixP=> i j; rewrite !mxE mulrDr. Qed.
 Lemma scalemxA x y A : x *m: (y *m: A) = (x * y) *m: A.
 Proof. by apply/matrixP=> i j; rewrite !mxE mulrA. Qed.
 
-End NzSemiRingModule.
+End SemiRingModule.
 
 Lemma trmx_delta m n i j : (delta_mx i j)^T = delta_mx j i :> 'M[R]_(n, m).
 Proof. by apply/matrixP=> i' j'; rewrite !mxE andbC. Qed.
@@ -2734,20 +2734,13 @@ Lemma mxtrace1 : \tr (1%:M : 'M[R]_n) = n%:R. Proof. exact: mxtrace_scalar. Qed.
 
 End Trace.
 
-(* The matrix ring structure requires a structural condition (dimension of *)
-(* the form n.+1) to satisfy the nontriviality condition we have imposed.  *)
-Section MatrixNzSemiRing.
+Section MatrixSemiRing.
 
-Variable n' : nat.
-Local Notation n := n'.+1.
-
-Lemma matrix_nonzero1 : 1%:M != 0 :> 'M[R]_n.
-Proof. by apply/eqP=> /matrixP/(_ 0 0)/eqP; rewrite !mxE oner_eq0. Qed.
+Variable n : nat.
 
-HB.instance Definition _ := GRing.Nmodule_isNzSemiRing.Build 'M[R]_n
+HB.instance Definition _ := GRing.Nmodule_isPzSemiRing.Build 'M[R]_n
   (@mulmxA n n n n) (@mul1mx n n) (@mulmx1 n n)
-  (@mulmxDl n n n) (@mulmxDr n n n) (@mul0mx n n n) (@mulmx0 n n n)
-  matrix_nonzero1.
+  (@mulmxDl n n n) (@mulmxDr n n n) (@mul0mx n n n) (@mulmx0 n n n).
 
 Lemma mulmxE : mulmx = *%R. Proof. by []. Qed.
 Lemma idmxE : 1%:M = 1 :> 'M_n. Proof. by []. Qed.
@@ -2757,7 +2750,7 @@ Proof. by split=> //; apply: scalar_mxM. Qed.
 HB.instance Definition _ := GRing.isMultiplicative.Build R 'M_n (@scalar_mx _ n)
   scalar_mx_is_multiplicative.
 
-End MatrixNzSemiRing.
+End MatrixSemiRing.
 
 Section LiftPerm.
 
@@ -2833,12 +2826,23 @@ Notation "A *m B" := (mulmx A B) : ring_scope.
 Notation "\tr A" := (mxtrace A) : ring_scope.
 
 (* Non-commutative transpose requires multiplication in the converse ring.   *)
-Lemma trmx_mul_rev (R : nzSemiRingType) m n p
+Lemma trmx_mul_rev (R : pzSemiRingType) m n p
     (A : 'M[R]_(m, n)) (B : 'M[R]_(n, p)) :
   (A *m B)^T = (B : 'M[R^c]_(n, p))^T *m (A : 'M[R^c]_(m, n))^T.
-Proof.
-by apply/matrixP=> k i /[!mxE]; apply: eq_bigr => j _ /[!mxE].
-Qed.
+Proof. by apply/matrixP=> k i /[!mxE]; apply: eq_bigr => j _ /[!mxE]. Qed.
+
+Section MatrixNzSemiRing.
+
+Variables (R : nzSemiRingType) (n' : nat).
+Local Notation n := n'.+1.
+
+Lemma matrix_nonzero1 : 1%:M != 0 :> 'M[R]_n.
+Proof. by apply/eqP=> /matrixP/(_ 0 0)/eqP; rewrite !mxE oner_eq0. Qed.
+
+HB.instance Definition _ :=
+  GRing.PzSemiRing_isNonZero.Build 'M[R]_n matrix_nonzero1.
+
+End MatrixNzSemiRing.
 
 HB.instance Definition _ (M : countNmodType) m n :=
   [Countable of 'M[M]_(m, n) by <:].
@@ -2864,7 +2868,7 @@ HB.instance Definition _ (R : finNzSemiRingType) n :=
 (* Parametricity over the algebra structure. *)
 Section MapNzSemiRingMatrix.
 
-Variables (aR rR : nzSemiRingType) (f : {rmorphism aR -> rR}).
+Variables (aR rR : pzSemiRingType) (f : {rmorphism aR -> rR}).
 Local Notation "A ^f" := (map_mx f A) : ring_scope.
 
 Section FixedSize.
@@ -2904,13 +2908,12 @@ Proof. by rewrite rmorph_sum; apply: eq_bigr => i _; rewrite mxE. Qed.
 
 End FixedSize.
 
-Lemma map_mx_is_multiplicative n' (n := n'.+1) :
-  multiplicative (map_mx f : 'M_n -> 'M_n).
+Lemma map_mx_is_multiplicative n : multiplicative (map_mx f : 'M_n -> 'M_n).
 Proof. by split; [apply: map_mxM | apply: map_mx1]. Qed.
 
-HB.instance Definition _ n' :=
-  GRing.isMultiplicative.Build 'M[aR]_n'.+1 'M[rR]_n'.+1 (map_mx f)
-    (map_mx_is_multiplicative n').
+HB.instance Definition _ n :=
+  GRing.isMultiplicative.Build 'M[aR]_n 'M[rR]_n (map_mx f)
+    (map_mx_is_multiplicative n).
 
 End MapNzSemiRingMatrix.
 
@@ -2930,7 +2933,7 @@ Section CommMx.
 (* The boolean version comm_mxb is designed to be used with seq.allrel *)
 (***********************************************************************)
 
-Context {R : nzSemiRingType} {n : nat}.
+Context {R : pzSemiRingType} {n : nat}.
 Implicit Types (f g p : 'M[R]_n) (fs : seq 'M[R]_n) (d : 'rV[R]_n) (I : Type).
 
 Definition comm_mx  f g : Prop := f *m g =  g *m f.
@@ -2981,15 +2984,14 @@ Lemma all_comm_mx_cons f fs :
   all_comm_mx (f :: fs) = all (comm_mxb f) fs && all_comm_mx fs.
 Proof. by rewrite /comm_mxb /= all2rel_cons //= eqxx. Qed.
 
+Lemma comm_mxE : comm_mx = @GRing.comm _. Proof. by []. Qed.
+
 End CommMx.
 Notation all_comm_mx := (allrel comm_mxb).
 
-Lemma comm_mxE (R : nzRingType) (n : nat) : @comm_mx R n.+1 = @GRing.comm _.
-Proof. by []. Qed.
-
 Section ComMatrix.
 (* Lemmas for matrices with coefficients in a commutative ring *)
-Variable R : comNzSemiRingType.
+Variable R : comPzSemiRingType.
 
 Section AssocLeft.
 
@@ -3026,8 +3028,7 @@ Proof. exact: scalar_mxC. Qed.
 Lemma comm_scalar_mx n a (A : 'M[R]_n) : comm_mx a%:M A.
 Proof. exact/comm_mx_sym/comm_mx_scalar. Qed.
 
-Lemma mxtrace_mulC m n (A : 'M[R]_(m, n)) B :
-   \tr (A *m B) = \tr (B *m A).
+Lemma mxtrace_mulC m n (A : 'M[R]_(m, n)) B : \tr (A *m B) = \tr (B *m A).
 Proof.
 have expand_trM C D: \tr (C *m D) = \sum_i \sum_j C i j * D j i.
   by apply: eq_bigr => i _; rewrite mxE.
@@ -3049,7 +3050,7 @@ HB.instance Definition _ (R : finComNzSemiRingType) (n' : nat) :=
 
 Section MatrixAlgebra.
 
-Variable R : nzRingType.
+Variable R : pzRingType.
 
 Section RingModule.
 
@@ -3058,8 +3059,6 @@ Section RingModule.
 Variables m n : nat.
 Implicit Types A B : 'M[R]_(m, n).
 
-Local Notation "x *m: A" := (scalemx x A) (at level 40) : ring_scope.
-
 HB.instance Definition _ := GRing.Zmodule_isLmodule.Build R 'M[R]_(m, n)
   (@scalemxA R m n) (@scale1mx R m n) (@scalemxDr R m n) (@scalemxDl R m n).
 
@@ -3146,8 +3145,7 @@ apply/matrixP=> i j; rewrite summxE (bigD1_ord i) //= !mxE eqxx /=.
 by rewrite eq_sym mulr_natr big1 ?addr0 // => i'; rewrite !mxE eq_liftF mulr0.
 Qed.
 
-Lemma row_diag_mx n (d : 'rV_n) i :
-  row i (diag_mx d) = d 0 i *: delta_mx 0 i.
+Lemma row_diag_mx n (d : 'rV_n) i : row i (diag_mx d) = d 0 i *: delta_mx 0 i.
 Proof. by apply/rowP => j; rewrite !mxE eqxx eq_sym mulr_natr. Qed.
 
 (* Scalar matrix *)
@@ -3213,8 +3211,7 @@ Lemma mul_pid_mx_copid m n r :
   r <= n -> pid_mx r *m copid_mx r = 0 :> 'M_(m, n).
 Proof. by move=> le_r_n; rewrite mulmxBr mulmx1 pid_mx_id ?subrr. Qed.
 
-Lemma copid_mx_id n r :
-  r <= n -> copid_mx r *m copid_mx r = copid_mx r :> 'M_n.
+Lemma copid_mx_id n r : r <= n -> copid_mx r *m copid_mx r = copid_mx r :> 'M_n.
 Proof.
 by move=> le_r_n; rewrite mulmxBl mul1mx mul_pid_mx_copid // oppr0 addr0.
 Qed.
@@ -3316,19 +3313,11 @@ Proof. exact: scalarZ. Qed.
 
 End Trace.
 
-(* The matrix ring structure requires a structural condition (dimension of *)
-(* the form n.+1) to satisfy the nontriviality condition we have imposed.  *)
 Section MatrixRing.
 
-Variable n' : nat.
-Local Notation n := n'.+1.
-
-HB.instance Definition _ := GRing.NzSemiRing.on 'M[R]_n.
-HB.instance Definition _ := GRing.Lmodule_isLalgebra.Build R 'M[R]_n
-  (@scalemxAl n n n).
+Variable n : nat.
 
-#[warning="-HB.no-new-instance"]
-HB.instance Definition _ := GRing.RMorphism.on (@scalar_mx R n).
+HB.instance Definition _ := GRing.PzSemiRing.on 'M[R]_n.
 
 End MatrixRing.
 
@@ -3358,6 +3347,10 @@ Arguments mulmxr {_ _ _ _} B A /.
 Notation "'\det' A" := (determinant A) : ring_scope.
 Notation "'\adj' A" := (adjugate A) : ring_scope.
 
+HB.instance Definition _ (R : nzRingType) n := GRing.NzSemiRing.on 'M[R]_n.+1.
+HB.instance Definition _ (R : nzRingType) n :=
+  GRing.Lmodule_isLalgebra.Build R 'M[R]_n.+1 (@scalemxAl R n.+1 n.+1 n.+1).
+
 HB.instance Definition _ (M : countZmodType) m n :=
   [Countable of 'M[M]_(m, n) by <:].
 HB.instance Definition _ (R : countNzRingType) n :=
@@ -3385,7 +3378,7 @@ HB.instance Definition _ (R : finNzRingType) n :=
 (* Parametricity over the algebra structure. *)
 Section MapRingMatrix.
 
-Variables (aR rR : nzRingType) (f : {rmorphism aR -> rR}).
+Variables (aR rR : pzRingType) (f : {rmorphism aR -> rR}).
 Local Notation "A ^f" := (map_mx f A) : ring_scope.
 
 Section FixedSize.
@@ -3414,9 +3407,6 @@ End FixedSize.
 Lemma map_copid_mx n r : (copid_mx r)^f = copid_mx r :> 'M_n.
 Proof. by rewrite map_mxB map_mx1 map_pid_mx. Qed.
 
-#[warning="-HB.no-new-instance"]
-HB.instance Definition _ n' := GRing.RMorphism.on (@map_mx _ _ f n'.+1 n'.+1).
-
 Lemma map_lin1_mx m n (g : 'rV_m -> 'rV_n) gf :
   (forall v, (g v)^f = gf v^f) -> (lin1_mx g)^f = lin1_mx gf.
 Proof.
@@ -3440,7 +3430,7 @@ Section CommMx.
 (* See comment on top of NzSemiRing section CommMx above.                *)
 (***********************************************************************)
 
-Context {R : nzRingType} {n : nat}.
+Context {R : pzRingType} {n : nat}.
 Implicit Types (f g p : 'M[R]_n) (fs : seq 'M[R]_n) (d : 'rV[R]_n) (I : Type).
 
 Lemma comm_mxN f g : comm_mx f g -> comm_mx f (- g).
@@ -3453,9 +3443,9 @@ Proof. by move=> fg fg'; apply/comm_mxD => //; apply/comm_mxN. Qed.
 
 End CommMx.
 
-Section ComMatrix.
 (* Lemmas for matrices with coefficients in a commutative ring *)
-Variable R : comNzRingType.
+Section ComMatrix.
+Variable R : comPzRingType.
 
 Section AssocLeft.
 
@@ -3515,16 +3505,6 @@ rewrite mulmx_sum_row exchange_big; apply: eq_bigr => j _ /=.
 by rewrite mxE -scaler_suml.
 Qed.
 
-Section MatrixAlgType.
-
-Variable n' : nat.
-Local Notation n := n'.+1.
-
-HB.instance Definition _ := GRing.Lalgebra_isAlgebra.Build R 'M[R]_n
-  (fun k => scalemxAr k).
-
-End MatrixAlgType.
-
 Lemma mul_mx_scalar m n a (A : 'M[R]_(m, n)) : A *m a%:M = a *: A.
 Proof. by rewrite scalar_mxC mul_scalar_mx. Qed.
 
@@ -3721,16 +3701,6 @@ suffices kA: A' *m A = 1%:M by rewrite -[B]mul1mx -kA -(mulmxA A') AB1 mulmx1.
 by rewrite -scalemxAl mul_adj_mx scale_scalar_mx mulrC -det_mulmx AB1 det1.
 Qed.
 
-(* Only tall matrices have inverses. *)
-Lemma mulmx1_min m n (A : 'M[R]_(m, n)) B : A *m B = 1%:M -> m <= n.
-Proof.
-move=> AB1; rewrite leqNgt; apply/negP=> /subnKC; rewrite addSnnS.
-move: (_ - _)%N => m' def_m; move: AB1; rewrite -{m}def_m in A B *.
-rewrite -(vsubmxK A) -(hsubmxK B) mul_col_row scalar_mx_block.
-case/eq_block_mx=> /mulmx1C BlAu1 AuBr0 _ => /eqP/idPn[].
-by rewrite -[_ B]mul1mx -BlAu1 -mulmxA AuBr0 !mulmx0 eq_sym oner_neq0.
-Qed.
-
 Lemma det_ublock n1 n2 Aul (Aur : 'M[R]_(n1, n2)) Adr :
   \det (block_mx Aul Aur 0 Adr) = \det Aul * \det Adr.
 Proof.
@@ -3765,6 +3735,24 @@ End ComMatrix.
 Arguments lin_mul_row {R m n} u.
 Arguments lin_mulmx {R m n p} A.
 
+Section ComNzMatrix.
+Variable R : comNzRingType.
+
+(* Only tall matrices have inverses. *)
+Lemma mulmx1_min m n (A : 'M[R]_(m, n)) B : A *m B = 1%:M -> m <= n.
+Proof.
+move=> AB1; rewrite leqNgt; apply/negP=> /subnKC; rewrite addSnnS.
+move: (_ - _)%N => m' def_m; move: AB1; rewrite -{m}def_m in A B *.
+rewrite -(vsubmxK A) -(hsubmxK B) mul_col_row scalar_mx_block.
+case/eq_block_mx=> /mulmx1C BlAu1 AuBr0 _ => /eqP/idPn[].
+by rewrite -[_ B]mul1mx -BlAu1 -mulmxA AuBr0 !mulmx0 eq_sym oner_neq0.
+Qed.
+
+HB.instance Definition _ n := GRing.Lalgebra_isAlgebra.Build R 'M[R]_n.+1
+  (fun k => scalemxAr k).
+
+End ComNzMatrix.
+
 HB.instance Definition _ (R : finComNzRingType) (n' : nat) :=
   [Finite of 'M[R]_n'.+1 by <:].
 
@@ -4247,7 +4235,7 @@ HB.instance Definition _ (zmodS : zmodClosed M) :=
 End mxOverZmodule.
 
 Section mxOverRing.
-Context {R : nzRingType} {m n : nat}.
+Context {R : pzRingType} {m n : nat}.
 
 Lemma mxOver_scalar S c : 0 \in S -> c \in S -> c%:M \is a @mxOver n n R S.
 Proof. by move=> S0 cS; apply/mxOverP => i j; rewrite !mxE; case: eqP. Qed.
@@ -4295,11 +4283,11 @@ Qed.
 End mxOverRing.
 
 Section mxRingOver.
-Context {R : nzRingType} {n : nat}.
+Context {R : pzRingType} {n : nat}.
 
 Section semiring.
 Variable S : semiringClosed R.
-Fact mxOver_mul_subproof : mulr_closed (@mxOver n.+1 n.+1 _ S).
+Fact mxOver_mul_subproof : mulr_closed (@mxOver n n _ S).
 Proof. by split; rewrite ?mxOver_scalar ?rpred0 ?rpred1//; apply: mxOverM. Qed.
 HB.instance Definition _ := GRing.isMulClosed.Build _ (mxOver_pred S)
   mxOver_mul_subproof.
@@ -4677,7 +4665,7 @@ Qed.
 End BlockRowZmod.
 
 Section BlockRowRing.
-Context {R : nzRingType} {n : nat} {q_ : 'I_n -> nat}.
+Context {R : pzRingType} {n : nat} {q_ : 'I_n -> nat}.
 Notation sq := (\sum_i q_ i)%N.
 Implicit Type (s : 'I_sq).
 
@@ -4748,7 +4736,7 @@ Qed.
 End BlockColZmod.
 
 Section BlockColRing.
-Context {R : nzRingType} {n : nat} {p_ : 'I_n -> nat}.
+Context {R : pzRingType} {n : nat} {p_ : 'I_n -> nat}.
 Notation sp := (\sum_i p_ i)%N.
 Implicit Type (s : 'I_sp).
 
@@ -4824,7 +4812,7 @@ Qed.
 End BlockMatrixZmod.
 
 Section BlockMatrixRing.
-Context {R : nzRingType} {p q : nat} {p_ : 'I_p -> nat} {q_ : 'I_q -> nat}.
+Context {R : pzRingType} {p q : nat} {p_ : 'I_p -> nat} {q_ : 'I_q -> nat}.
 Notation sp := (\sum_i p_ i)%N.
 Notation sq := (\sum_i q_ i)%N.
 
@@ -4863,7 +4851,7 @@ Qed.
 
 End BlockMatrixRing.
 
-Lemma mul_mxblock {R : nzRingType} {p q r : nat}
+Lemma mul_mxblock {R : pzRingType} {p q r : nat}
     {p_ : 'I_p -> nat} {q_ : 'I_q -> nat} {r_ : 'I_r -> nat}
     (A_ : forall i j, 'M[R]_(p_ i, q_ j)) (B_ : forall j k, 'M_(q_ j, r_ k)) :
   \mxblock_(i, j) A_ i j *m \mxblock_(j, k) B_ j k =
@@ -5026,7 +5014,7 @@ Qed.
 
 Section SquareBlockMatrixRing.
 Import tagnat.
-Context {R : nzRingType} {p : nat} {p_ : 'I_p -> nat}.
+Context {R : pzRingType} {p : nat} {p_ : 'I_p -> nat}.
 Notation sp := (\sum_i p_ i)%N.
 Implicit Type (s : 'I_sp).
 
@@ -5072,7 +5060,7 @@ Qed.
 
 End SquareBlockMatrixRing.
 
-Lemma mul_mxrow_mxdiag {R : nzRingType} {p : nat} {p_ : 'I_p -> nat} m
+Lemma mul_mxrow_mxdiag {R : pzRingType} {p : nat} {p_ : 'I_p -> nat} m
     (R_ : forall i, 'M[R]_(m, p_ i)) (D_ : forall i, 'M[R]_(p_ i)) :
   \mxrow_i R_ i *m \mxdiag_i D_ i = \mxrow_i (R_ i *m D_ i).
 Proof.
@@ -5080,7 +5068,7 @@ apply: trmx_inj; rewrite trmx_mul_rev !tr_mxrow tr_mxdiag mul_mxdiag_mxcol.
 by apply/ eq_mxcol => i; rewrite trmx_mul_rev.
 Qed.
 
-Lemma mul_mxblock_mxdiag {R : nzRingType} {p q : nat}
+Lemma mul_mxblock_mxdiag {R : pzRingType} {p q : nat}
   {p_ : 'I_p -> nat} {q_ : 'I_q -> nat}
     (B_ : forall i j, 'M[R]_(p_ i, q_ j)) (D_ : forall j, 'M[R]_(q_ j)) :
   \mxblock_(i, j) B_ i j *m \mxdiag_j D_ j = \mxblock_(i, j) (B_ i j *m D_ j).
@@ -5088,7 +5076,7 @@ Proof.
 by rewrite !mxblockEh mul_mxrow_mxdiag; under eq_mxrow do rewrite mxcol_mul.
 Qed.
 
-Lemma mul_mxdiag_mxblock {R : nzRingType} {p q : nat}
+Lemma mul_mxdiag_mxblock {R : pzRingType} {p q : nat}
   {p_ : 'I_p -> nat} {q_ : 'I_q -> nat}
     (D_ : forall j, 'M[R]_(p_ j)) (B_ : forall i j, 'M[R]_(p_ i, q_ j)):
   \mxdiag_j D_ j *m \mxblock_(i, j) B_ i j = \mxblock_(i, j) (D_ i *m B_ i j).
@@ -5096,10 +5084,10 @@ Proof.
 by rewrite !mxblockEv mul_mxdiag_mxcol; under eq_mxcol do rewrite mul_mxrow.
 Qed.
 
-Definition Vandermonde (R : nzRingType) (m n : nat) (a : 'rV[R]_n) :=
+Definition Vandermonde (R : pzRingType) (m n : nat) (a : 'rV[R]_n) :=
   \matrix_(i < m, j < n) a 0 j ^+ i.
 
-Lemma det_Vandermonde (R : comNzRingType) (n : nat) (a : 'rV[R]_n) :
+Lemma det_Vandermonde (R : comPzRingType) (n : nat) (a : 'rV[R]_n) :
   \det (Vandermonde n a) = \prod_(i < n) \prod_(j < n | i < j) (a 0 j - a 0 i).
 Proof.
 set V := @Vandermonde R.
@@ -5118,7 +5106,7 @@ suff: D * V _ _ a = block_mx 1 (const_mx 1) 0 (V _ _ b *m C) :> 'M_(1 + n).
     by under eq_bigr do rewrite !mxE.
   apply: eq_bigr => i _; under eq_bigr do rewrite !mxE.
   by rewrite big_mkcond [RHS]big_mkcond big_ord_recl/= mul1r.
-rewrite mulrBl mul1r -scalerAl; apply/matrixP => i j; rewrite !mxE.
+rewrite mulrBl mul1r -[_ * _]scalemxAl; apply/matrixP => i j; rewrite !mxE.
 under eq_bigr do rewrite !mxE; case: splitP => [{i}_ -> /[!ord1]|{}i ->].
   rewrite !expr0 big1; last by move=> ?; rewrite mul0r.
   by rewrite ?mulr0 ?subr0 ?mxE; case: splitP => k; rewrite ?ord1 mxE//.
diff --git a/doc/changelog/02-changed/1385-propagate-pzrings.md b/doc/changelog/02-changed/1385-propagate-pzrings.md
new file mode 100644
index 0000000000..4791dd170f
--- /dev/null
+++ b/doc/changelog/02-changed/1385-propagate-pzrings.md
@@ -0,0 +1,71 @@
+- in `matrix.v`
+  + Definitions `mulmx`, `perm_mx`, `tperm_mx`, `is_perm_mx`, `pid_mx`,
+    `lift0_perm`, `lift0_mx`, `comm_mx`, `comm_mxb` generalized to
+    `pzSemiRingType`
+  + Definitions `copid_mx`, `lin1_mx`, `lin_mx`, `mulmxr`, `lin_mulmxr`,
+    `mxtrace`, `determinant`, `cofactor`, `adjugate`, `Vandermonde` generalized
+    to `pzRingType`
+  + Definition `lin_mul_row` generalized to `comPzRingType`
+  + The `pzSemiRingType` and `pzRingType` instances on square matrices
+    generalized to the case where the size is potentially zero
+  + The `lmodType` instance on matrices generalized to `pzRingType`
+  + The ring morphism instances on `scalar_mx` and `map_mx` generalized to
+    `pzSemiRingType` and the case where the size is potentially zero
+  + The linear function instances on `swizzle_mx`, `trmx`, `row`, `col`, `row'`,
+    `col'`, `mxsub`, `row_perm`, `col_perm`, `xrow`, `xcol`, `lsubmx`, `rsubmx`,
+    `usubmx`, `dsubmx`, `vec_mx`, `mxvec`, `diag_mx`, `mxtrace` generalized to
+    `pzRingType`
+  + The additive function instances on `mulmx`, `mulmxr`, `lin_mulmxr`
+    generalized to `pzRingType`
+  + The linear function instances on `mulmx`, `lin_mulmx`, `lin_mul_row`
+    generalized to `comPzRingType`
+  + The `semiringClosed` instance on `mxOver` generalized to `pzRingType`
+  + Lemmas `trmx_delta`, `delta_mx_lshift`, `delta_mx_rshift`,
+    `delta_mx_ushift`, `delta_mx_dshift`, `vec_mx_delta`, `mxvec_delta`,
+    `trmx1`, `row1`, `col1`, `mulmxA`, `mul0mx`, `mulmx0`, `mulmxDl`, `mulmxDr`,
+    `mulmx_suml`, `mulmx_sumr`, `rowE`, `colE`, `mul_rVP`, `row_mul`,
+    `mxsub_mul`, `mul_rowsub_mx`, `mulmx_colsub`, `mul_delta_mx_cond`,
+    `mul_delta_mx`, `mul_delta_mx_0`, `mul_diag_mx`, `mul_mx_diag`,
+    `mulmx_diag`, `scalar_mxM`, `mul1mx`, `mulmx1`, `rowsubE`, `mul_col_perm`,
+    `mul_row_perm`, `mul_xcol`, `col_permE`, `row_permE`, `xcolE`, `xrowE`,
+    `perm_mxEsub`, `tperm_mxEsub`, `tr_perm_mx`, `tr_tperm_mx`, `perm_mx1`,
+    `perm_mxM`, `is_perm_mxP`, `perm_mx_is_perm`, `is_perm_mx1`, `is_perm_mxMl`,
+    `is_perm_mx_tr`, `is_perm_mxMr`, `pid_mx_0`, `pid_mx_1`, `pid_mx_row`,
+    `pid_mx_col`, `pid_mx_block`, `tr_pid_mx`, `pid_mx_minv`, `pid_mx_minh`,
+    `mul_pid_mx`, `pid_mx_id`, `pid_mxErow`, `pid_mxEcol`, `mul_mx_row`,
+    `mul_col_mx`, `mul_row_col`, `mul_col_row`, `mul_row_block`,
+    `mul_block_col`, `mulmx_block`, `mulmx_lsub`, `mulmx_rsub`, `mul_usub_mx`,
+    `mul_dsub_mx`, `mxtrace1`, `mulmxE`, `idmxE`, `lift0_perm0`,
+    `lift0_perm_lift`, `lift0_permK`, `lift0_perm_eq0`, `lift0_mx_perm`,
+    `lift0_mx_is_perm`, `exp_block_diag_mx`, `trmx_mul_rev`, `map_mxM`,
+    `map_delta_mx`, `map_diag_mx`, `map_scalar_mx`, `map_mx1`, `map_perm_mx`,
+    `map_tperm_mx`, `map_pid_mx`, `trace_map_mx`, `comm_mx_sym`, `comm_mx_refl`,
+    `comm_mx0`, `comm0mx`, `comm_mx1`, `comm1mx`, `comm_mxD`, `comm_mxM`,
+    `comm_mx_sum`, `comm_mxP`, `all_comm_mxP`, `all_comm_mx1`, `all_comm_mx2P`,
+    `all_comm_mx_cons`, `comm_mxE` generalized to `pzSemiRingType`
+  + Lemmas `trmx_mul`, `diag_mxC`, `diag_mx_comm`, `scalar_mxC`,
+    `comm_mx_scalar`, `comm_scalar_mx`, `mxtrace_mulC` generalized to
+    `comPzSemiRingType`
+  + Lemams `scalemx_const`, `matrix_sum_delta`, `row_sum_delta`, `scale_row_mx`,
+    `scale_col_mx`, `scale_block_mx`, `diag_mx_sum_delta`, `row_diag_mx`,
+    `scale_scalar_mx`, `scalemx1`, `scalar_mx_sum_delta`, `mx1_sum_delta`,
+    `mulmxN`, `mulNmx`, `mulmxBl`, `mulmxBr`, `scalemxAl`, `mulmx_sum_row`,
+    `mul_scalar_mx`, `mul_copid_mx_pid`, `mul_pid_mx_copid`, `copid_mx_id`,
+    `mul_rV_lin1`, `mul_rV_lin`, `mul_vec_lin`, `mx_rV_lin`, `mx_vec_lin`,
+    `mxtraceZ`, `map_mxZ`, `det_map_mx`, `cofactor_map_mx`, `map_mx_adj`,
+    `map_copid_mx`, `map_lin1_mx`, `map_lin_mx`, `comm_mxN`, `comm_mxN1`,
+    `comm_mxB`, `mul_mxrow`, `mul_submxrow`, `mxcol_mul`, `submxcol_mul`,
+    `mul_mxrow_mxcol`, `mul_mxcol_mxrow`, `mul_mxrow_mxblock`,
+    `mul_mxblock_mxrow`, `mul_mxblock`, `mxtrace_mxblock`, `mxdiagZ`,
+    `diag_mxrow`, `mxtrace_mxdiag`, `mul_mxdiag_mxcol`, `mul_mxrow_mxdiag`,
+    `mul_mxblock_mxdiag`, `mul_mxdiag_mxblock` generalized to `pzRingType`
+  + Lemmas `scalemxAr`, `mul_vec_lin_row`, `mxvec_dotmul`, `mul_mx_scalar`,
+    `determinant_multilinear`, `determinant_alternate`, `det_tr`, `det_perm`,
+    `det1`, `det_mx00`, `detZ`, `det0`, `det_scalar`, `det_scalar1`, `det_mx11`,
+    `det_mulmx`, `detM`, `expand_cofactor`, `expand_det_row`, `cofactor_tr`,
+    `cofactorZ`, `expand_det_col`, `trmx_adj`, `adjZ`, `mul_mx_adj`,
+    `mul_adj_mx`, `adj1`, `mulmx1C`, `det_ublock`, `det_lblock`, `det_trig`,
+    `det_diag`, `mxOver_scalar`, `mxOver_scalarE`, `mxOverZ`, `mxOver_diag`,
+    `mxOver_diagE`, `mxOverM`, `det_Vandermonde` generalized to `comPzRingType`
+    ([#1385](https://github.com/math-comp/math-comp/pull/1385),
+    by Kazuhiko Sakaguchi).


Reviews:
user: login: pi8027
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-02T11:20:20Z
user: login: CohenCyril
state: APPROVED
author_association: MEMBER
submitted_at: 2025-04-02T13:16:53Z
user: login: proux01
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-03T06:34:36Z
user: login: pi8027
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-03T10:27:43Z
user: login: proux01
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-04-04T10:59:04Z
user: login: pi8027
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-04T11:08:35Z
user: login: pi8027
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-04T11:13:52Z
user: login: proux01
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-04T11:17:21Z
user: login: Tragicus
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-04T11:30:32Z
user: login: pi8027
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-04T13:22:09Z
user: login: pi8027
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-04T13:22:28Z
user: login: pi8027
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-04T13:52:55Z
user: login: proux01
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-04T14:32:51Z
user: login: pi8027
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-04T14:56:45Z
user: login: CohenCyril
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-04T16:50:30Z

Review comments:
diff_hunk: @@ -3357,6 +3355,10 @@ Arguments mulmxr {_ _ _ _} B A /.
 Notation "'\det' A" := (determinant A) : ring_scope.
 Notation "'\adj' A" := (adjugate A) : ring_scope.
 
+HB.instance Definition _ (R : nzRingType) n := GRing.NzSemiRing.on 'M[R]_n.+1.
+HB.instance Definition _ (R : nzRingType) n :=
+  GRing.Lmodule_isLalgebra.Build R 'M[R]_n.+1 (@scalemxAl R n.+1 n.+1 n.+1).
path: algebra/matrix.v
user: login: pi8027
body: This `lalgType` instance on square matrices still requires the scalar ring to be non-zero since algebra structures still inherit from non-zero rings (See #1386).
created_at: 2025-04-02T11:19:46Z
author_association: MEMBER
diff_hunk: @@ -5117,7 +5117,7 @@ suff: D * V _ _ a = block_mx 1 (const_mx 1) 0 (V _ _ b *m C) :> 'M_(1 + n).
     by under eq_bigr do rewrite !mxE.
   apply: eq_bigr => i _; under eq_bigr do rewrite !mxE.
   by rewrite big_mkcond [RHS]big_mkcond big_ord_recl/= mul1r.
-rewrite mulrBl mul1r -scalerAl; apply/matrixP => i j; rewrite !mxE.
+rewrite mulrBl mul1r -[_ * _]scalemxAl; apply/matrixP => i j; rewrite !mxE.
path: algebra/matrix.v
user: login: pi8027
body: As a result, I cannot use `scalerAl` here anymore.
created_at: 2025-04-02T11:20:12Z
author_association: MEMBER
diff_hunk: @@ -57,7 +57,7 @@ HB.export ZmoduleExports.
 HB.structure Definition NzSemiRing := {R of GRing.NzSemiRing R & Finite R}.
 
 #[deprecated(since="mathcomp 2.4.0",
-             note="Use FinNzSemiRing instead.")]
+             note="Use NzSemiRing instead.")]
path: algebra/finalg.v
user: login: proux01
body: Maybe
```suggestion
             note="Use FinRing.NzSemiRing instead.")]
```
(and same below)
created_at: 2025-04-03T06:34:35Z
author_association: CONTRIBUTOR
diff_hunk: @@ -57,7 +57,7 @@ HB.export ZmoduleExports.
 HB.structure Definition NzSemiRing := {R of GRing.NzSemiRing R & Finite R}.
 
 #[deprecated(since="mathcomp 2.4.0",
-             note="Use FinNzSemiRing instead.")]
+             note="Use NzSemiRing instead.")]
path: algebra/finalg.v
user: login: pi8027
body: Since the diff is becoming larger, I decided to open another PR for these fixes: #1388.
created_at: 2025-04-03T10:27:42Z
author_association: MEMBER
diff_hunk: @@ -111,13 +111,14 @@ From mathcomp Require Import prime binomial ssralg countalg finalg zmodp bigop.
 (*                   back into into an m x n rectangular matrix.              *)
 (* In 'M[R]_(m, n), R can be any type, but 'M[R]_(m, n) inherits the eqType,  *)
 (* choiceType, countType, finType, zmodType structures of R; 'M[R]_(m, n)     *)
-(* also has a natural lmodType R structure when R has a nzRingType structure. *)
-(* Because the type of matrices specifies their dimension, only non-trivial   *)
-(* square matrices (of type 'M[R]_n.+1) can inherit the ring structure of R;  *)
-(* indeed they then have an algebra structure (lalgType R, or algType R if R  *)
-(* is a comNzRingType, or even unitAlgType if R is a comUnitRingType).        *)
+(* also has a natural lmodType R structure when R has a pzRingType structure. *)
+(* Square matrices (of type 'M[R]_n) inherit the pzRingType structure.        *)
path: algebra/matrix.v
user: login: proux01
body: ```suggestion
(* Square matrices (of type 'M[R]_n) inherit the pzRingType structure of R.   *)
```
created_at: 2025-04-04T10:47:45Z
author_association: CONTRIBUTOR
diff_hunk: @@ -111,13 +111,14 @@ From mathcomp Require Import prime binomial ssralg countalg finalg zmodp bigop.
 (*                   back into into an m x n rectangular matrix.              *)
 (* In 'M[R]_(m, n), R can be any type, but 'M[R]_(m, n) inherits the eqType,  *)
 (* choiceType, countType, finType, zmodType structures of R; 'M[R]_(m, n)     *)
-(* also has a natural lmodType R structure when R has a nzRingType structure. *)
-(* Because the type of matrices specifies their dimension, only non-trivial   *)
-(* square matrices (of type 'M[R]_n.+1) can inherit the ring structure of R;  *)
-(* indeed they then have an algebra structure (lalgType R, or algType R if R  *)
-(* is a comNzRingType, or even unitAlgType if R is a comUnitRingType).        *)
+(* also has a natural lmodType R structure when R has a pzRingType structure. *)
+(* Square matrices (of type 'M[R]_n) inherit the pzRingType structure.        *)
+(* Non-trivial square matrices (of type 'M[R]_n.+1) inherits the nzRingType   *)
path: algebra/matrix.v
user: login: proux01
body: ```suggestion
(* Non-trivial square matrices (of type 'M[R]_n.+1) inherit the nzRingType    *)
```
created_at: 2025-04-04T10:48:48Z
author_association: CONTRIBUTOR
diff_hunk: @@ -2272,11 +2273,11 @@ End MapZmodMatrix.
 (*********** Matrix ring module, graded ring, and ring structures ************)
 (*****************************************************************************)
 
-Section MatrixAlgebra.
+Section PzMatrixAlgebra.
path: algebra/matrix.v
user: login: proux01
body: My understanding is that the final name (after deprecation phases) should be `ringType` for what's currently `pzEingType` and `nzRingType` for currently deprecated `rintType`. So maybe not worth this change of section names.
created_at: 2025-04-04T10:50:52Z
author_association: CONTRIBUTOR
diff_hunk: @@ -2734,20 +2735,13 @@ Lemma mxtrace1 : \tr (1%:M : 'M[R]_n) = n%:R. Proof. exact: mxtrace_scalar. Qed.
 
 End Trace.
 
-(* The matrix ring structure requires a structural condition (dimension of *)
-(* the form n.+1) to satisfy the nontriviality condition we have imposed.  *)
-Section MatrixNzSemiRing.
-
-Variable n' : nat.
-Local Notation n := n'.+1.
+Section MatrixPzSemiRing.
path: algebra/matrix.v
user: login: proux01
body: Maybe similarly imilarly
```suggestion
Section MatrixSemiRing.
```
created_at: 2025-04-04T10:52:11Z
author_association: CONTRIBUTOR
diff_hunk: @@ -3453,9 +3444,9 @@ Proof. by move=> fg fg'; apply/comm_mxD => //; apply/comm_mxN. Qed.
 
 End CommMx.
 
-Section ComMatrix.
 (* Lemmas for matrices with coefficients in a commutative ring *)
-Variable R : comNzRingType.
+Section ComPzMatrix.
path: algebra/matrix.v
user: login: proux01
body: Maybe
```suggestion
Section ComMatrix.
```
created_at: 2025-04-04T10:55:20Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,17 @@
+- in `matrix.v`
+  + Definitions `mulmx`, `perm_mx`, `tperm_mx`, `is_perm_mx`, `pid_mx`, `lift0_perm`, `lift0_mx`, `comm_mx`, `comm_mxb` generalized to `pzSemiRingType`
+  + Definitions `copid_mx`, `lin1_mx`, `lin_mx`, `mulmxr`, `lin_mulmxr`, `mxtrace`, `determinant`, `cofactor`, `adjugate`, `Vandermonde` generalized to `pzRingType`
+  + Definition `lin_mul_row` generalized to `comPzRingType`
+  + The `pzSemiRingType` and `pzRingType` instances on square matrices generalized to the case where the size is potentially zero
+  + The `lmodType` instance on matrices generalized to `pzRingType`
+  + The ring morphism instances on `scalar_mx` and `map_mx` generalized to `pzSemiRingType` and the case where the size is potentially zero
+  + The linear function instances on `swizzle_mx`, `trmx`, `row`, `col`, `row'`, `col'`, `mxsub`, `row_perm`, `col_perm`, `xrow`, `xcol`, `lsubmx`, `rsubmx`, `usubmx`, `dsubmx`, `vec_mx`, `mxvec`, `diag_mx`, `mxtrace` generalized to `pzRingType`
+  + The additive function instances on `mulmx`, `mulmxr`, `lin_mulmxr` generalized to `pzRingType`
+  + The linear function instances on `mulmx`, `lin_mulmx`, `lin_mul_row` generalized to `comPzRingType`
+  + The `semiringClosed` instance on `mxOver` generalized to `pzRingType`
+  + Lemmas `trmx_delta`, `delta_mx_lshift`, `delta_mx_rshift`, `delta_mx_ushift`, `delta_mx_dshift`, `vec_mx_delta`, `mxvec_delta`, `trmx1`, `row1`, `col1`, `mulmxA`, `mul0mx`, `mulmx0`, `mulmxDl`, `mulmxDr`, `mulmx_suml`, `mulmx_sumr`, `rowE`, `colE`, `mul_rVP`, `row_mul`, `mxsub_mul`, `mul_rowsub_mx`, `mulmx_colsub`, `mul_delta_mx_cond`, `mul_delta_mx`, `mul_delta_mx_0`, `mul_diag_mx`, `mul_mx_diag`, `mulmx_diag`, `scalar_mxM`, `mul1mx`, `mulmx1`, `rowsubE`, `mul_col_perm`, `mul_row_perm`, `mul_xcol`, `col_permE`, `row_permE`, `xcolE`, `xrowE`, `perm_mxEsub`, `tperm_mxEsub`, `tr_perm_mx`, `tr_tperm_mx`, `perm_mx1`, `perm_mxM`, `is_perm_mxP`, `perm_mx_is_perm`, `is_perm_mx1`, `is_perm_mxMl`, `is_perm_mx_tr`, `is_perm_mxMr`, `pid_mx_0`, `pid_mx_1`, `pid_mx_row`, `pid_mx_col`, `pid_mx_block`, `tr_pid_mx`, `pid_mx_minv`, `pid_mx_minh`, `mul_pid_mx`, `pid_mx_id`, `pid_mxErow`, `pid_mxEcol`, `mul_mx_row`, `mul_col_mx`, `mul_row_col`, `mul_col_row`, `mul_row_block`, `mul_block_col`, `mulmx_block`, `mulmx_lsub`, `mulmx_rsub`, `mul_usub_mx`, `mul_dsub_mx`, `mxtrace1`, `mulmxE`, `idmxE`, `lift0_perm0`, `lift0_perm_lift`, `lift0_permK`, `lift0_perm_eq0`, `lift0_mx_perm`, `lift0_mx_is_perm`, `exp_block_diag_mx`, `trmx_mul_rev`, `map_mxM`, `map_delta_mx`, `map_diag_mx`, `map_scalar_mx`, `map_mx1`, `map_perm_mx`, `map_tperm_mx`, `map_pid_mx`, `trace_map_mx`, `comm_mx_sym`, `comm_mx_refl`, `comm_mx0`, `comm0mx`, `comm_mx1`, `comm1mx`, `comm_mxD`, `comm_mxM`, `comm_mx_sum`, `comm_mxP`, `all_comm_mxP`, `all_comm_mx1`, `all_comm_mx2P`, `all_comm_mx_cons`, `comm_mxE` generalized to `pzSemiRingType`
+  + Lemmas `trmx_mul`, `diag_mxC`, `diag_mx_comm`, `scalar_mxC`, `comm_mx_scalar`, `comm_scalar_mx`, `mxtrace_mulC` generalized to `comPzSemiRingType`
+  + Lemams `scalemx_const`, `matrix_sum_delta`, `row_sum_delta`, `scale_row_mx`, `scale_col_mx`, `scale_block_mx`, `diag_mx_sum_delta`, `row_diag_mx`, `scale_scalar_mx`, `scalemx1`, `scalar_mx_sum_delta`, `mx1_sum_delta`, `mulmxN`, `mulNmx`, `mulmxBl`, `mulmxBr`, `scalemxAl`, `mulmx_sum_row`, `mul_scalar_mx`, `mul_copid_mx_pid`, `mul_pid_mx_copid`, `copid_mx_id`, `mul_rV_lin1`, `mul_rV_lin`, `mul_vec_lin`, `mx_rV_lin`, `mx_vec_lin`, `mxtraceZ`, `map_mxZ`, `det_map_mx`, `cofactor_map_mx`, `map_mx_adj`, `map_copid_mx`, `map_lin1_mx`, `map_lin_mx`, `comm_mxN`, `comm_mxN1`, `comm_mxB`, `mul_mxrow`, `mul_submxrow`, `mxcol_mul`, `submxcol_mul`, `mul_mxrow_mxcol`, `mul_mxcol_mxrow`, `mul_mxrow_mxblock`, `mul_mxblock_mxrow`, `mul_mxblock`, `mxtrace_mxblock`, `mxdiagZ`, `diag_mxrow`, `mxtrace_mxdiag`, `mul_mxdiag_mxcol`, `mul_mxrow_mxdiag`, `mul_mxblock_mxdiag`, `mul_mxdiag_mxblock` generalized to `pzRingType`
+  + Lemmas `scalemxAr`, `mul_vec_lin_row`, `mxvec_dotmul`, `mul_mx_scalar`, `determinant_multilinear`, `determinant_alternate`, `det_tr`, `det_perm`, `det1`, `det_mx00`, `detZ`, `det0`, `det_scalar`, `det_scalar1`, `det_mx11`, `det_mulmx`, `detM`, `expand_cofactor`, `expand_det_row`, `cofactor_tr`, `cofactorZ`, `expand_det_col`, `trmx_adj`, `adjZ`, `mul_mx_adj`, `mul_adj_mx`, `adj1`, `mulmx1C`, `det_ublock`, `det_lblock`, `det_trig`, `det_diag`, `mxOver_scalar`, `mxOver_scalarE`, `mxOverZ`, `mxOver_diag`, `mxOver_diagE`, `mxOverM`, `det_Vandermonde` generalized to `comPzRingType`
path: doc/changelog/02-changed/1385-propagate-pzrings.md
user: login: proux01
body: Maybe break these long lines (M-q in emacs, probably something similar in other editors)
created_at: 2025-04-04T10:58:59Z
author_association: CONTRIBUTOR
diff_hunk: @@ -2272,11 +2273,11 @@ End MapZmodMatrix.
 (*********** Matrix ring module, graded ring, and ring structures ************)
 (*****************************************************************************)
 
-Section MatrixAlgebra.
+Section PzMatrixAlgebra.
path: algebra/matrix.v
user: login: pi8027
body: I don't know since I was not following the discussion. Ping @CohenCyril @Tragicus 
created_at: 2025-04-04T11:08:35Z
author_association: MEMBER
diff_hunk: @@ -111,13 +111,14 @@ From mathcomp Require Import prime binomial ssralg countalg finalg zmodp bigop.
 (*                   back into into an m x n rectangular matrix.              *)
 (* In 'M[R]_(m, n), R can be any type, but 'M[R]_(m, n) inherits the eqType,  *)
 (* choiceType, countType, finType, zmodType structures of R; 'M[R]_(m, n)     *)
-(* also has a natural lmodType R structure when R has a nzRingType structure. *)
-(* Because the type of matrices specifies their dimension, only non-trivial   *)
-(* square matrices (of type 'M[R]_n.+1) can inherit the ring structure of R;  *)
-(* indeed they then have an algebra structure (lalgType R, or algType R if R  *)
-(* is a comNzRingType, or even unitAlgType if R is a comUnitRingType).        *)
+(* also has a natural lmodType R structure when R has a pzRingType structure. *)
+(* Square matrices (of type 'M[R]_n) inherit the pzRingType structure.        *)
path: algebra/matrix.v
user: login: pi8027
body: "on R" ?
created_at: 2025-04-04T11:13:51Z
author_association: MEMBER
diff_hunk: @@ -111,13 +111,14 @@ From mathcomp Require Import prime binomial ssralg countalg finalg zmodp bigop.
 (*                   back into into an m x n rectangular matrix.              *)
 (* In 'M[R]_(m, n), R can be any type, but 'M[R]_(m, n) inherits the eqType,  *)
 (* choiceType, countType, finType, zmodType structures of R; 'M[R]_(m, n)     *)
-(* also has a natural lmodType R structure when R has a nzRingType structure. *)
-(* Because the type of matrices specifies their dimension, only non-trivial   *)
-(* square matrices (of type 'M[R]_n.+1) can inherit the ring structure of R;  *)
-(* indeed they then have an algebra structure (lalgType R, or algType R if R  *)
-(* is a comNzRingType, or even unitAlgType if R is a comUnitRingType).        *)
+(* also has a natural lmodType R structure when R has a pzRingType structure. *)
+(* Square matrices (of type 'M[R]_n) inherit the pzRingType structure.        *)
path: algebra/matrix.v
user: login: proux01
body: Technicaly more precise but I keep a small preference for "of" or "from". I don't care that much though.
created_at: 2025-04-04T11:17:20Z
author_association: CONTRIBUTOR
diff_hunk: @@ -2272,11 +2273,11 @@ End MapZmodMatrix.
 (*********** Matrix ring module, graded ring, and ring structures ************)
 (*****************************************************************************)
 
-Section MatrixAlgebra.
+Section PzMatrixAlgebra.
path: algebra/matrix.v
user: login: Tragicus
body: That is correct, `pzRingType` will be replaced by `ringType`eventually (i.e. in the next next release).
created_at: 2025-04-04T11:30:32Z
author_association: CONTRIBUTOR
diff_hunk: @@ -111,13 +111,14 @@ From mathcomp Require Import prime binomial ssralg countalg finalg zmodp bigop.
 (*                   back into into an m x n rectangular matrix.              *)
 (* In 'M[R]_(m, n), R can be any type, but 'M[R]_(m, n) inherits the eqType,  *)
 (* choiceType, countType, finType, zmodType structures of R; 'M[R]_(m, n)     *)
-(* also has a natural lmodType R structure when R has a nzRingType structure. *)
-(* Because the type of matrices specifies their dimension, only non-trivial   *)
-(* square matrices (of type 'M[R]_n.+1) can inherit the ring structure of R;  *)
-(* indeed they then have an algebra structure (lalgType R, or algType R if R  *)
-(* is a comNzRingType, or even unitAlgType if R is a comUnitRingType).        *)
+(* also has a natural lmodType R structure when R has a pzRingType structure. *)
+(* Square matrices (of type 'M[R]_n) inherit the pzRingType structure.        *)
path: algebra/matrix.v
user: login: pi8027
body: In the end, I think "from" is better than "on" and "of" here.
created_at: 2025-04-04T13:22:09Z
author_association: MEMBER
diff_hunk: @@ -2272,11 +2273,11 @@ End MapZmodMatrix.
 (*********** Matrix ring module, graded ring, and ring structures ************)
 (*****************************************************************************)
 
-Section MatrixAlgebra.
+Section PzMatrixAlgebra.
path: algebra/matrix.v
user: login: pi8027
body: Thanks. Fixed.
created_at: 2025-04-04T13:22:28Z
author_association: MEMBER
diff_hunk: @@ -110,14 +110,14 @@ From mathcomp Require Import prime binomial ssralg countalg finalg zmodp bigop.
 (*       vec_mx v == the inverse of mxvec, reshaping a vector of width m * n  *)
 (*                   back into into an m x n rectangular matrix.              *)
 (* In 'M[R]_(m, n), R can be any type, but 'M[R]_(m, n) inherits the eqType,  *)
-(* choiceType, countType, finType, zmodType structures of R; 'M[R]_(m, n)     *)
-(* also has a natural lmodType R structure when R has a nzRingType structure. *)
-(* Because the type of matrices specifies their dimension, only non-trivial   *)
-(* square matrices (of type 'M[R]_n.+1) can inherit the ring structure of R;  *)
-(* indeed they then have an algebra structure (lalgType R, or algType R if R  *)
-(* is a comNzRingType, or even unitAlgType if R is a comUnitRingType).        *)
+(* choiceType, countType, finType, nmodType, and zmodType structures from R;  *)
+(* 'M[R]_(m, n) also forms a natural lmodType R when R is a pzRingType.       *)
+(* Square matrices of type 'M[R]_n (resp. non-trivial square matrices of type *)
+(* 'M[R]_n.+1) inherit the pz(Semi)RingType (resp. nz(Semi)RingType) structure*)
+(* from R; indeed they then have an algebra structure (lalgType R, or algType *)
+(* R if R is a comNzRingType, or even unitAlgType if R is a comUnitRingType). *)
path: algebra/matrix.v
user: login: pi8027
body: In the end, I found this part of the header doc a little bit absurd:
- It isn't easy to make sure that it is up to date. (For example, N-module and semiring instances on matrices were introduced a while ago, I guess. I will soon have to rewrite it again when I introduce semimodule and semialgebra instances on matrices: #1269.)
- HB should give us this kind of information.
created_at: 2025-04-04T13:52:55Z
author_association: MEMBER
diff_hunk: @@ -110,14 +110,14 @@ From mathcomp Require Import prime binomial ssralg countalg finalg zmodp bigop.
 (*       vec_mx v == the inverse of mxvec, reshaping a vector of width m * n  *)
 (*                   back into into an m x n rectangular matrix.              *)
 (* In 'M[R]_(m, n), R can be any type, but 'M[R]_(m, n) inherits the eqType,  *)
-(* choiceType, countType, finType, zmodType structures of R; 'M[R]_(m, n)     *)
-(* also has a natural lmodType R structure when R has a nzRingType structure. *)
-(* Because the type of matrices specifies their dimension, only non-trivial   *)
-(* square matrices (of type 'M[R]_n.+1) can inherit the ring structure of R;  *)
-(* indeed they then have an algebra structure (lalgType R, or algType R if R  *)
-(* is a comNzRingType, or even unitAlgType if R is a comUnitRingType).        *)
+(* choiceType, countType, finType, nmodType, and zmodType structures from R;  *)
+(* 'M[R]_(m, n) also forms a natural lmodType R when R is a pzRingType.       *)
+(* Square matrices of type 'M[R]_n (resp. non-trivial square matrices of type *)
+(* 'M[R]_n.+1) inherit the pz(Semi)RingType (resp. nz(Semi)RingType) structure*)
+(* from R; indeed they then have an algebra structure (lalgType R, or algType *)
+(* R if R is a comNzRingType, or even unitAlgType if R is a comUnitRingType). *)
path: algebra/matrix.v
user: login: proux01
body: Indeed, maybe you can replace this with a more generic sentence along the lines of "'M[R]_(m, n) inherits many structures from R, look at [HB comand to get instances on matrix] for more details.".
created_at: 2025-04-04T14:32:51Z
author_association: CONTRIBUTOR
diff_hunk: @@ -110,14 +110,14 @@ From mathcomp Require Import prime binomial ssralg countalg finalg zmodp bigop.
 (*       vec_mx v == the inverse of mxvec, reshaping a vector of width m * n  *)
 (*                   back into into an m x n rectangular matrix.              *)
 (* In 'M[R]_(m, n), R can be any type, but 'M[R]_(m, n) inherits the eqType,  *)
-(* choiceType, countType, finType, zmodType structures of R; 'M[R]_(m, n)     *)
-(* also has a natural lmodType R structure when R has a nzRingType structure. *)
-(* Because the type of matrices specifies their dimension, only non-trivial   *)
-(* square matrices (of type 'M[R]_n.+1) can inherit the ring structure of R;  *)
-(* indeed they then have an algebra structure (lalgType R, or algType R if R  *)
-(* is a comNzRingType, or even unitAlgType if R is a comUnitRingType).        *)
+(* choiceType, countType, finType, nmodType, and zmodType structures from R;  *)
+(* 'M[R]_(m, n) also forms a natural lmodType R when R is a pzRingType.       *)
+(* Square matrices of type 'M[R]_n (resp. non-trivial square matrices of type *)
+(* 'M[R]_n.+1) inherit the pz(Semi)RingType (resp. nz(Semi)RingType) structure*)
+(* from R; indeed they then have an algebra structure (lalgType R, or algType *)
+(* R if R is a comNzRingType, or even unitAlgType if R is a comUnitRingType). *)
path: algebra/matrix.v
user: login: pi8027
body: I would like to keep it as is for the moment, and discuss how we should document instances in general in the MathComp meeting.
created_at: 2025-04-04T14:56:45Z
author_association: MEMBER
diff_hunk: @@ -2833,12 +2826,23 @@ Notation "A *m B" := (mulmx A B) : ring_scope.
 Notation "\tr A" := (mxtrace A) : ring_scope.
 
 (* Non-commutative transpose requires multiplication in the converse ring.   *)
-Lemma trmx_mul_rev (R : nzSemiRingType) m n p
+Lemma trmx_mul_rev (R : pzSemiRingType) m n p
     (A : 'M[R]_(m, n)) (B : 'M[R]_(n, p)) :
   (A *m B)^T = (B : 'M[R^c]_(n, p))^T *m (A : 'M[R^c]_(m, n))^T.
-Proof.
-by apply/matrixP=> k i /[!mxE]; apply: eq_bigr => j _ /[!mxE].
-Qed.
+Proof. by apply/matrixP=> k i /[!mxE]; apply: eq_bigr => j _ /[!mxE]. Qed.
+
+Section MatrixNzSemiRing.
+
+Variables (R : nzSemiRingType) (n' : nat).
+Local Notation n := n'.+1.
path: algebra/matrix.v
user: login: CohenCyril
body: @proux01 side note: at some point one should try to generalize those specialisations to `posnat`, where ``posnat := {itv nat & `[1, +oo[}``                                       
created_at: 2025-04-04T16:50:30Z
author_association: MEMBER

PR comments:
user: login: pi8027
created_at: 2025-04-02T11:26:06Z
body: We should take a look at the result of `grep "\(nz\|Nz\)\(Semi\)\?Ring" **/*.v ` and do the same for other files.
author_association: MEMBER
user: login: pi8027
created_at: 2025-04-02T15:37:44Z
body: ~The second and third commits (or even the last three commits) should be squashed, but I keep them separate to ease the reviewing process for the moment.~ It's not the case anymore: I separated the first commit to #1388, and squashed the rest.

Writing the changelog entry took longer than changing stuff in `matrix.v`. Perhaps some sort of semantic diff tool is useful here.
author_association: MEMBER
user: login: pi8027
created_at: 2025-04-04T18:20:52Z
body: CI green
author_association: MEMBER