@@ -449,7 +449,10 @@ Qed.
449449Lemma fgscaleA c1 c2 g : c1 *:g (c2 *:g g) = (c1 * c2) *:g g.
450450Proof . by apply/malgP=> x; rewrite !fgscaleE mulrA. Qed .
451451
452- Lemma fgscale1r D: 1 *:g D = D.
452+ Lemma fgscale0r g : 0 *:g g = 0.
453+ Proof . by apply/malgP=> k; rewrite fgscaleE mul0r mcoeff0. Qed .
454+
455+ Lemma fgscale1r g : 1 *:g g = g.
453456Proof . by apply/malgP=> k; rewrite !fgscaleE mul1r. Qed .
454457
455458Lemma fgscaleDr c g1 g2 : c *:g (g1 + g2) = c *:g g1 + c *:g g2.
@@ -458,37 +461,28 @@ Proof. by apply/malgP=> k; rewrite !(mcoeffD, fgscaleE) mulrDr. Qed.
458461Lemma fgscaleDl g c1 c2: (c1 + c2) *:g g = c1 *:g g + c2 *:g g.
459462Proof . by apply/malgP=> x; rewrite !(mcoeffD, fgscaleE) mulrDl. Qed .
460463
461- End MalgSemiRingTheory.
462-
463- (* -------------------------------------------------------------------- *)
464- Section MalgRingTheory.
465-
466- Context {K : choiceType} {R : ringType}.
467-
468- Implicit Types (g : {malg R[K]}).
469-
470- (* TODO: Add a semi-module structure and generalize this section *)
471- HB.instance Definition _ := GRing.Zmodule_isLmodule.Build R {malg R[K]}
472- fgscaleA fgscale1r fgscaleDr fgscaleDl.
464+ HB.instance Definition _ := GRing.Nmodule_isLSemiModule.Build R {malg R [K]}
465+ fgscaleA fgscale0r fgscale1r fgscaleDr fgscaleDl.
473466
474467Lemma malgZ_def c g : c *: g = fgscale c g.
475468Proof . by []. Qed .
476469
477470Lemma mcoeffZ c g k : (c *: g)@_k = c * g@_k.
478471Proof . exact/fgscaleE. Qed .
479472
480- (* FIXME: make the production of a LRMorphism fail below *)
481- (* HB.instance Definition _ m := *)
482- (* GRing.isLinear.Build R [lmodType R of {malg R[K]}] R *%R (mcoeff m) *)
483- (* (fun c g => mcoeffZ c g m). *)
473+ (* FIXME: this instance has to be declared after the RMorphism instance of *)
474+ (* [mcoeff 1%M] to produce the LRMorphism instance. *)
475+ (* HB.instance Definition _ k := *)
476+ (* GRing.isSemilinear.Build R {malg R[K]} R *%R (mcoeff k) *)
477+ (* (fun c g => mcoeffZ c g k, mcoeffD k). *)
484478
485479Lemma msuppZ_le c g : msupp (c *: g) `<=` msupp g.
486480Proof .
487481apply/fsubsetP=> k; rewrite -!mcoeff_neq0 mcoeffZ.
488482by apply/contraTneq=> ->; rewrite mulr0 negbK.
489483Qed .
490484
491- End MalgRingTheory .
485+ End MalgSemiRingTheory .
492486
493487(* -------------------------------------------------------------------- *)
494488Section MalgLmodTheoryIntegralDomain.
@@ -579,15 +573,14 @@ Lemma fgmullw (d1 d2 : {fset K}) g1 g2 :
579573 msupp g1 `<=` d1 -> msupp g2 `<=` d2 ->
580574 fgmul g1 g2 = \sum_(k1 <- d1) \sum_(k2 <- d2) g1 *M_[k1, k2] g2.
581575Proof .
582- move=> le_d1 le_d2; rewrite fgmull (big_fset_incl _ le_d1) /=.
583- apply/eq_bigr=> k1 _; apply/big_fset_incl => // k _ /mcoeff_outdom ->.
584- by rewrite mulr0 monalgU0.
585- move=> k _ /mcoeff_outdom g1k.
586- by rewrite big1 => // k' _; rewrite g1k mul0r monalgU0.
576+ move=> le_d1 le_d2; rewrite -(big_fset_incl _ le_d1)/=; last first.
577+ by move=> k _ /mcoeff_outdom g1k; apply/big1 => ?; rewrite g1k mul0r monalgU0.
578+ apply/eq_bigr=> k1 _; apply/big_fset_incl => // k _ /mcoeff_outdom ->.
579+ by rewrite mulr0 monalgU0.
587580Qed .
588581
589- Lemma fgmulrw (d1 d2 : {fset K}) g1 g2 : msupp g1 `<=` d1 -> msupp g2 `<=` d2
590- -> fgmul g1 g2 = \sum_(k2 <- d2) \sum_(k1 <- d1) g1 *M_[k1, k2] g2.
582+ Lemma fgmulrw (d1 d2 : {fset K}) g1 g2 : msupp g1 `<=` d1 -> msupp g2 `<=` d2 ->
583+ fgmul g1 g2 = \sum_(k2 <- d2) \sum_(k1 <- d1) g1 *M_[k1, k2] g2.
591584Proof . by move=> le_d1 le_d2; rewrite (fgmullw le_d1 le_d2) exchange_big. Qed .
592585
593586Definition fgmullwl (d1 : {fset K}) {g1 g2} (le : msupp g1 `<=` d1) :=
@@ -605,14 +598,14 @@ Proof. by move=> g; rewrite fgmulr msupp0 big_seq_fset0. Qed.
605598Lemma fgmulUg c k g :
606599 fgmul << c *g k >> g = \sum_(k' <- msupp g) << c * g@_k' *g k * k' >>.
607600Proof .
608- rewrite (fgmullw msuppU_le (fsubset_refl _) ) big_seq_fset1.
601+ rewrite (fgmullwl msuppU_le) big_seq_fset1.
609602by apply/eq_bigr => k' _; rewrite mcoeffUU.
610603Qed .
611604
612605Lemma fgmulgU c k g :
613606 fgmul g << c *g k >> = \sum_(k' <- msupp g) << g@_k' * c *g k' * k >>.
614607Proof .
615- rewrite (fgmulrw (fsubset_refl _) msuppU_le) big_seq_fset1.
608+ rewrite (fgmulrwl msuppU_le) big_seq_fset1.
616609by apply/eq_bigr=> k' _; rewrite mcoeffUU.
617610Qed .
618611
@@ -658,6 +651,9 @@ rewrite -big_split /=; apply/eq_bigr => k2 _.
658651by rewrite mcoeffD mulrDr monalgUD.
659652Qed .
660653
654+ #[local] HB.instance Definition _ g :=
655+ GRing.isSemiAdditive.Build _ _ (fgmul g) (fgmulg0 g, fgmulgDr g).
656+
661657Lemma fgmulA : associative fgmul.
662658Proof .
663659move=> g1 g2 g3.
@@ -678,6 +674,10 @@ HB.instance Definition _ := GRing.Nmodule_isSemiRing.Build {malg R[K]}
678674
679675End MalgSemiRingType.
680676
677+ (* TODO: HB.saturate *)
678+ HB.instance Definition _ (K : monomType) (R : ringType) :=
679+ GRing.SemiRing.on {malg R[K]}.
680+
681681(* -------------------------------------------------------------------- *)
682682Section MalgSemiRingTheory.
683683
@@ -799,45 +799,39 @@ rewrite !raddf_sum !big1 ?addr0 //= => k; rewrite in_fsetD1 => /andP [ne1_k _].
799799by rewrite mcoeffU mul1m (negbTE ne1_k).
800800Qed .
801801
802+ (* FIXME: this instance declaration fails if the [Linear] instance is *)
803+ (* declared first. *)
802804HB.instance Definition _ :=
803- GRing.isMultiplicative.Build {malg R[K]} R (@ mcoeff K R 1%M)
805+ GRing.isMultiplicative.Build {malg R[K]} R (mcoeff 1%M)
804806 mcoeff1g_is_multiplicative.
805807
806- End MalgSemiRingTheory.
807-
808- (* -------------------------------------------------------------------- *)
809- Section MalgRingTheory.
810-
811- Context {K : monomType} {R : ringType}.
812-
813- Implicit Types (g : {malg R[K]}) (k l : K).
814-
815- HB.instance Definition _ := GRing.SemiRing.on {malg R[K]}.
816-
817808Lemma mul_malgC c g : c%:MP * g = c *: g.
818809Proof .
819810rewrite malgM_def malgZ_def fgmulUg.
820811by apply/eq_bigr=> /= k _; rewrite mul1m.
821812Qed .
822813
823- (* FIXME: building Linear instance here so as to not trigger the creation
824- of a LRMorphism that fails on above command (but is built just below anyway) *)
825- HB.instance Definition _ m :=
826- GRing.isScalable.Build R {malg R[K]} R *%R (mcoeff m)
827- (fun c => (mcoeffZ c)^~ m).
828-
829814Lemma fgscaleAl c g1 g2 : c *: (g1 * g2) = (c *: g1) * g2.
830815Proof . by rewrite -!mul_malgC mulrA. Qed .
831816
832- HB.instance Definition _ := GRing.Lmodule_isLalgebra.Build R {malg R[K]}
833- fgscaleAl.
817+ HB.instance Definition _ :=
818+ GRing.LSemiModule_isLSemiAlgebra.Build R {malg R[K]} fgscaleAl.
834819
835- End MalgRingTheory.
820+ End MalgSemiRingTheory.
821+
822+ (* FIXME: the [Linear] instance moved from above *)
823+ HB.instance Definition _ (K : choiceType) (R : semiRingType) k :=
824+ GRing.isScalable.Build R {malg R[K]} R *%R (mcoeff k)
825+ (fun c g => mcoeffZ c g k).
826+
827+ (* FIXME: HB.saturate? *)
828+ HB.instance Definition _ (K : monomType) (R : semiRingType) :=
829+ GRing.Linear.on (mcoeff 1%M : {malg R[K]} -> R).
836830
837831(* -------------------------------------------------------------------- *)
838- Section MalgComRingType .
832+ Section MalgComSemiRingType .
839833
840- Context {K : conomType} {R : comRingType }.
834+ Context {K : conomType} {R : comSemiRingType }.
841835
842836Lemma fgmulC : @commutative {malg R[K]} _ *%R.
843837Proof .
@@ -846,12 +840,20 @@ apply/eq_bigr=> /= k1 _; apply/eq_bigr=> /= k2 _.
846840by rewrite mulrC [X in X==k]mulmC.
847841Qed .
848842
849- HB.instance Definition _ := GRing.Ring_hasCommutativeMul.Build (malg K R)
850- fgmulC.
843+ HB.instance Definition _ :=
844+ GRing.SemiRing_hasCommutativeMul.Build {malg R[K]} fgmulC.
845+
846+ HB.instance Definition _ :=
847+ GRing.LSemiAlgebra_isComSemiAlgebra.Build R {malg R[K]}.
851848
852- HB.instance Definition _ := GRing.Lalgebra_isComAlgebra.Build R {malg R[K]} .
849+ End MalgComSemiRingType .
853850
854- End MalgComRingType.
851+ (* FIXME: HB.saturate *)
852+ HB.instance Definition _ (K : monomType) (R : ringType) :=
853+ GRing.Lmodule.on {malg R[K]}.
854+ HB.instance Definition _ (K : conomType) (R : comRingType) :=
855+ GRing.Lmodule.on {malg R[K]}.
856+ (* /FIXME *)
855857
856858(* -------------------------------------------------------------------- *)
857859Section MalgMorphism.
@@ -916,10 +918,9 @@ Lemma mmapMNn n : {morph mmap f h: x / x *- n} . Proof. exact: raddfMNn. Qed.
916918
917919End Additive.
918920
919- (* TODO: generalize following sections to semirings *)
920921Section CommrMultiplicative.
921922
922- Context {K : monomType} {R : ringType } {S : ringType }.
923+ Context {K : monomType} {R : semiRingType } {S : semiRingType }.
923924Context (f : {rmorphism R -> S}) (h : {mmorphism K -> S}).
924925
925926Implicit Types (c : R) (g : {malg R[K]}).
@@ -951,7 +952,7 @@ End CommrMultiplicative.
951952(* -------------------------------------------------------------------- *)
952953Section Multiplicative.
953954
954- Context {K : monomType} {R : ringType } {S : comRingType }.
955+ Context {K : monomType} {R : semiRingType } {S : comSemiRingType }.
955956Context (f : {rmorphism R -> S}) (h : {mmorphism K -> S}).
956957
957958Lemma mmap_is_multiplicative : multiplicative (mmap f h).
@@ -966,7 +967,7 @@ End Multiplicative.
966967(* -------------------------------------------------------------------- *)
967968Section Linear.
968969
969- Context {K : monomType} {R : comRingType } (h : {mmorphism K -> R}).
970+ Context {K : monomType} {R : comSemiRingType } (h : {mmorphism K -> R}).
970971
971972Lemma mmap_is_linear : scalable_for *%R (mmap idfun h).
972973Proof . by move=> /= c g; rewrite -mul_malgC rmorphM /= mmapC. Qed .
@@ -976,7 +977,6 @@ HB.instance Definition _ :=
976977 mmap_is_linear.
977978
978979End Linear.
979- (* /TODO *)
980980End MalgMorphism.
981981
982982(* -------------------------------------------------------------------- *)
@@ -1065,10 +1065,9 @@ HB.instance Definition _ := GRing.isOppClosed.Build _ (monalgOver_pred zmodS)
10651065End MonalgOverOpp.
10661066
10671067(* -------------------------------------------------------------------- *)
1068- (* TODO: generalize to R : semiRingType *)
10691068Section MonalgOverSemiring.
10701069
1071- Context (K : monomType) (R : ringType ) (S : semiringClosed R).
1070+ Context (K : monomType) (R : semiRingType ) (S : semiringClosed R).
10721071
10731072Local Notation monalgOver := (@monalgOver K R).
10741073
@@ -1106,10 +1105,9 @@ by move=> /= k; rewrite rpredM.
11061105Qed .
11071106
11081107End MonalgOverSemiring.
1109- (* /TODO *)
11101108
11111109HB.instance Definition _
1112- (K : monomType) (R : ringType ) (ringS : subringClosed R) :=
1110+ (K : monomType) (R : semiRingType ) (ringS : semiringClosed R) :=
11131111 GRing.isMulClosed.Build _ (monalgOver_pred ringS)
11141112 (monalgOver_mulr_closed K ringS).
11151113
0 commit comments