@@ -62,25 +62,24 @@ Variable R : comRingType.
6262
6363Fixpoint bareiss_rec m (a : {poly R}) :
6464 'M[{poly R}]_(1 + m, 1 + m) -> {poly R} :=
65- match m with
66- | S p => fun M =>
65+ if m is p.+1 then
66+ fun M =>
6767 let d := M 0 0 in
6868 let l := ursubmx M in
6969 let c := dlsubmx M in
7070 let N := drsubmx M in
71- let M' := ( d *: N - c *m l) in
71+ let M' := d *: N - c *m l in
7272 let M'' := map_mx (fun x => rdivp x a) M' in
73- bareiss_rec d M''
74- | _ => fun M => M 0 0
75- end .
73+ bareiss_rec d M''
74+ else fun M => M 0 0.
7675
77- Definition bareiss n (M : 'M_(1 + n, 1 + n)) : {poly R} := bareiss_rec 1 M.
76+ Definition bareiss n (M : 'M_(1 + n, 1 + n)) : {poly R} := bareiss_rec 1 M.
7877
7978Definition bareiss_char_poly n (M : 'M_(1 + n, 1 + n)) : {poly R} :=
8079 bareiss (char_poly_mx M).
8180
8281(* The actual determinant function based on Bareiss *)
83- Definition bdet n (M : 'M_(1 + n, 1 + n)) : R :=
82+ Definition bdet n (M : 'M_(1 + n, 1 + n)) : R :=
8483 (bareiss_char_poly (- M))`_0.
8584
8685End bareiss.
@@ -91,8 +90,8 @@ Variable R : comRingType.
9190
9291Lemma bareiss_recE : forall m a (M : 'M[{poly R}]_(1 + m)),
9392 a \is monic ->
94- (forall p (h h' : p < 1 + m), pminor h h' M \is monic) ->
95- (forall k (f g : 'I_k.+1 -> 'I_m.+1), rdvdp (a ^+ k) (minor f g M)) ->
93+ (forall p (h h' : p < 1 + m), pminor h h' M \is monic) ->
94+ (forall k (f g : 'I_k.+1 -> 'I_m.+1), rdvdp (a ^+ k) (minor f g M)) ->
9695 a ^+ m * (bareiss_rec a M) = \det M.
9796Proof .
9897elim=> [a M _ _ _|m ih a M am hpm hdvd] /=.
@@ -101,12 +100,12 @@ have ak_monic k : a ^+ k \is monic by apply/monic_exp.
101100set d := M 0 0; set M' := (_ - _); set M'' := map_mx _ _; rewrite /= in M' M'' *.
102101have d_monic : d \is monic.
103102 have -> // : d = pminor (ltn0Sn _) (ltn0Sn _) M.
104- have h : widen_ord (ltn0Sn m.+1) =1 (fun _ => 0)
103+ have h : widen_ord (ltn0Sn m.+1) =1 (fun=> 0)
105104 by move=> x; apply/ord_inj; rewrite [x]ord1.
106105 by rewrite /pminor (minor_eq h h) minor1.
107106have dk_monic : forall k, d ^+ k \is monic by move=> k; apply/monic_exp.
108107have hM' : M' = a *: M''.
109- pose f := fun m (i : 'I_m) (x : 'I_2) => if x == 0 then 0 else ( lift 0 i) .
108+ pose f := fun m (i : 'I_m) (x : 'I_2) => if x == 0 then 0 else lift 0 i.
110109 apply/matrixP => i j.
111110 rewrite !mxE big_ord1 !rshift1 [a * _]mulrC rdivpK ?(eqP am,expr1n,mulr1) //.
112111 move: (hdvd 1%nat (f _ i) (f _ j)).
@@ -122,7 +121,7 @@ case/rdvdpP: (hdvd _ (lift_pred f) (lift_pred g)) => // x hx.
122121apply/rdvdpP => //; exists x.
123122apply/(@lregX _ _ k.+1 (monic_lreg am))/(monic_lreg d_monic).
124123rewrite -detZ -submatrix_scale -hM' bareiss_block_key_lemma_sub.
125- by rewrite mulrA [x * _]mulrC mulrACA -exprS [_ * x]mulrC -hx.
124+ by rewrite mulrA [x * _]mulrC mulrACA -exprS [_ * x]mulrC -hx.
126125Qed .
127126
128127Lemma bareissE n (M : 'M[{poly R}]_(1 + n))
@@ -166,9 +165,7 @@ Proof.
166165rewrite /dvd_step => n a M hj.
167166rewrite -detZ; f_equal.
168167apply/matrixP => i j; rewrite !mxE.
169- case: odivrP.
170- - move => d /=; by rewrite mulrC.
171- move => h.
168+ case: odivrP=>[d|h] /=; first by rewrite mulrC.
172169case/dvdrP: (hj i j) => d hd.
173170by move: (h d); rewrite hd eqxx.
174171Qed .
@@ -200,17 +197,15 @@ Proof.
200197rewrite !mxE.
201198case: splitP => x //; rewrite [x]ord1 {x} !mxE => _.
202199case: splitP => x; first by rewrite [x]ord1.
203- rewrite /= /bump /leq0n => /eqP; rewrite eqSS => /eqP h.
204- by have -> : i = x by apply/ord_inj.
200+ by rewrite /= /bump /leq0n => /eqP; rewrite eqSS => /eqP/ord_inj->.
205201Qed .
206202
207203Lemma blockEi0 m n d (l: 'rV[R]_n) (c: 'cV[R]_m) (M: 'M[R]_(m,n)) i:
208204 (block_mx d%:M l c M) (lift 0 i) 0 = (c i 0).
209205Proof .
210206rewrite !mxE.
211207case: splitP => x; first by rewrite [x]ord1.
212- rewrite /= /bump /leq0n => /eqP; rewrite eqSS => /eqP h.
213- have -> : i = x by apply/ord_inj.
208+ rewrite /= /bump /leq0n => /eqP; rewrite eqSS => /eqP/ord_inj->.
214209rewrite !mxE.
215210by case: splitP => y //; rewrite [y]ord1 {y} => _.
216211Qed .
@@ -220,12 +215,10 @@ Lemma blockEij m n d (l: 'rV[R]_n) (c: 'cV[R]_m) (M: 'M[R]_(m,n)) i j:
220215Proof .
221216rewrite !mxE.
222217case: splitP => x; first by rewrite [x]ord1.
223- rewrite /= /bump /leq0n => /eqP; rewrite eqSS => /eqP h.
224- have -> : i = x by apply/ord_inj.
218+ rewrite /= /bump /leq0n => /eqP; rewrite eqSS => /eqP/ord_inj->.
225219rewrite !mxE.
226220case: splitP => y; first by rewrite [y]ord1.
227- rewrite /= /bump /leq0n => /eqP; rewrite eqSS => /eqP h'.
228- by have -> : j = y by apply/ord_inj.
221+ by rewrite /= /bump /leq0n => /eqP; rewrite eqSS => /eqP/ord_inj->.
229222Qed .
230223
231224(*
@@ -275,10 +268,8 @@ have h4 : forall i j, a %| M' i j.
275268*)
276269have h6 : forall i j, M' i j = a * M'' i j.
277270- move => i j; rewrite [(dvd_step _ _) i j]mxE.
278- case: odivrP.
279- + move => dv /=; by rewrite mulrC.
280- move => h.
281- case/dvdrP: (h4 i j ) => dv hdv.
271+ case: odivrP => [dv|h] /=; first by rewrite mulrC.
272+ case/dvdrP: (h4 i j) => dv hdv.
282273 by move: (h dv); rewrite hdv eqxx.
283274have h6' : M' = a *: M'' by apply/matrixP => i j; rewrite h6 !mxE.
284275(*
@@ -308,10 +299,7 @@ have h10 : forall k (f1: 'I_k.+1 -> 'I_m) (f2: 'I_k.+1 -> 'I_n),
308299 have hMk : d^+ k.+1 != 0 by apply/lregP/lregX.
309300 rewrite -(@dvdr_mul2l _ d) // mulrA h8 //.
310301 by rewrite mulrAC -exprS dvdr_mul2l //.
311- split.
312- - exact : h2.
313- - exact : h10.
314- - exact : h6'.
302+ split=> //.
315303rewrite -/M'' => p h h'.
316304apply/(@lregMl _ (a ^+ p.+1)).
317305rewrite -h7.
@@ -330,17 +318,16 @@ Qed.
330318 formal definition of bareiss algorithm
331319 *)
332320Fixpoint bareiss_rec m a : 'M[R]_(1 + m) -> R :=
333- match m return 'M[R]_(1 + m) -> R with
334- | S p => fun (M: 'M[R]_(1 + _)) =>
335- let d := M 0 0 in
336- let l := ursubmx M in
337- let c := dlsubmx M in
338- let N := drsubmx M in
339- let : M' := d *: N - c *m l in
340- let : M'' := dvd_step a M' in
341- bareiss_rec d M''
342- | _ => fun M => M 0 0
343- end .
321+ if m is p.+1 return 'M[R]_(1 + m) -> R then
322+ fun (M: 'M[R]_(1 + _)) =>
323+ let d := M 0 0 in
324+ let l := ursubmx M in
325+ let c := dlsubmx M in
326+ let N := drsubmx M in
327+ let M' := d *: N - c *m l in
328+ let M'' := dvd_step a M' in
329+ bareiss_rec d M''
330+ else fun M => M 0 0.
344331
345332(*
346333 from sketch, we can express the properties of bareiss
@@ -444,9 +431,7 @@ Lemma char_poly_altE : forall n (M: 'M[R]_(1 + n)),
444431 char_poly_alt M = char_poly M.
445432Proof .
446433rewrite /char_poly_alt /char_poly => n M.
447- rewrite bareissE //.
448- move => p h h'; apply/monic_lreg.
449- apply pminor_char_poly_mx_monic.
434+ by rewrite bareissE // => p h h'; exact/monic_lreg/pminor_char_poly_mx_monic.
450435Qed .
451436
452437(* The actual determinant function based on bareiss *)
0 commit comments