Skip to content

Commit 1cecf59

Browse files
committed
More zify instances for nat and N
1 parent f8f3070 commit 1cecf59

File tree

1 file changed

+90
-2
lines changed

1 file changed

+90
-2
lines changed

theories/zify_algebra.v

+90-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,82 @@ Local Delimit Scope Z_scope with Z.
1717

1818
Import Order.Theory GRing.Theory Num.Theory SsreflectZifyInstances.
1919

20+
(******************************************************************************)
21+
(* nat *)
22+
(******************************************************************************)
23+
24+
#[global]
25+
Instance Op_nat_0 : CstOp (0%R : nat) := ZifyInst.Op_O.
26+
Add Zify CstOp Op_nat_0.
27+
28+
#[global]
29+
Instance Op_nat_add : BinOp (+%R : nat -> nat -> nat) := Op_addn.
30+
Add Zify BinOp Op_nat_add.
31+
32+
#[global]
33+
Instance Op_nat_1 : CstOp (1%R : nat) := { TCst := 1%Z; TCstInj := erefl }.
34+
Add Zify CstOp Op_nat_1.
35+
36+
#[global]
37+
Instance Op_nat_mul : BinOp ( *%R : nat -> nat -> nat) := Op_muln.
38+
Add Zify BinOp Op_nat_mul.
39+
40+
Fact Op_nat_natmul_subproof (n m : nat) :
41+
Z.of_nat (n *+ m)%R = (Z.of_nat n * Z.of_nat m)%Z.
42+
Proof. by rewrite raddfMn -mulr_natr -[m in RHS]natn rmorph_nat. Qed.
43+
44+
#[global]
45+
Instance Op_nat_natmul : BinOp (@GRing.natmul _ : nat -> nat -> nat) :=
46+
{ TBOp := Z.mul; TBOpInj := Op_nat_natmul_subproof }.
47+
Add Zify BinOp Op_nat_natmul.
48+
49+
Fact Op_nat_exp_subproof (n : nat) (m : nat) :
50+
Z_of_nat (n ^+ m)%R = (Z_of_int n ^ Z.of_nat m)%Z.
51+
Proof. rewrite -Zpower_nat_Z; elim: m => //= m <-; rewrite exprS; lia. Qed.
52+
53+
#[global]
54+
Instance Op_nat_exp : BinOp (@GRing.exp _ : nat -> nat -> nat) :=
55+
{ TBOp := Z.pow; TBOpInj := Op_nat_exp_subproof }.
56+
Add Zify BinOp Op_nat_exp.
57+
58+
(******************************************************************************)
59+
(* N *)
60+
(******************************************************************************)
61+
62+
#[global]
63+
Instance Op_N_0 : CstOp (0%R : N) := ZifyInst.Op_N_N0.
64+
Add Zify CstOp Op_N_0.
65+
66+
#[global]
67+
Instance Op_N_add : BinOp (+%R : N -> N -> N) := ZifyInst.Op_N_add.
68+
Add Zify BinOp Op_N_add.
69+
70+
#[global]
71+
Instance Op_N_1 : CstOp (1%R : N) := { TCst := 1%Z; TCstInj := erefl }.
72+
Add Zify CstOp Op_N_1.
73+
74+
#[global]
75+
Instance Op_N_mul : BinOp ( *%R : N -> N -> N) := ZifyInst.Op_N_mul.
76+
Add Zify BinOp Op_N_mul.
77+
78+
Fact Op_N_natmul_subproof (n : N) (m : nat) :
79+
Z.of_N (n *+ m)%R = (Z.of_N n * Z.of_nat m)%Z.
80+
Proof. by rewrite raddfMn -mulr_natr -[m in RHS]natn rmorph_nat. Qed.
81+
82+
#[global]
83+
Instance Op_N_natmul : BinOp (@GRing.natmul _ : N -> nat -> N) :=
84+
{ TBOp := Z.mul; TBOpInj := Op_N_natmul_subproof }.
85+
Add Zify BinOp Op_N_natmul.
86+
87+
Fact Op_N_exp_subproof (n : N) (m : nat) :
88+
Z_of_N (n ^+ m)%R = (Z_of_N n ^ Z.of_nat m)%Z.
89+
Proof. rewrite -Zpower_nat_Z; elim: m => //= m <-; rewrite exprS; lia. Qed.
90+
91+
#[global]
92+
Instance Op_N_exp : BinOp (@GRing.exp _ : N -> nat -> N) :=
93+
{ TBOp := Z.pow; TBOpInj := Op_N_exp_subproof }.
94+
Add Zify BinOp Op_N_exp.
95+
2096
(******************************************************************************)
2197
(* ssrint *)
2298
(******************************************************************************)
@@ -287,7 +363,7 @@ Instance Op_Z_exp : BinOp (@GRing.exp _ : Z -> nat -> Z) :=
287363
Add Zify BinOp Op_Z_exp.
288364

289365
#[global]
290-
Instance Op_unitZ : UnOp (has_quality 1 ZInstances.unitZ : Z -> bool) :=
366+
Instance Op_unitZ : UnOp (has_quality 1 Instances.unitZ : Z -> bool) :=
291367
{ TUOp x := (x =? 1)%Z || (x =? - 1)%Z; TUOpInj _ := erefl }.
292368
Add Zify UnOp Op_unitZ.
293369

@@ -296,7 +372,7 @@ Instance Op_Z_unit : UnOp (has_quality 1 GRing.unit : Z -> bool) := Op_unitZ.
296372
Add Zify UnOp Op_Z_unit.
297373

298374
#[global]
299-
Instance Op_invZ : UnOp ZInstances.invZ := { TUOp := id; TUOpInj _ := erefl }.
375+
Instance Op_invZ : UnOp Instances.invZ := { TUOp := id; TUOpInj _ := erefl }.
300376
Add Zify UnOp Op_invZ.
301377

302378
#[global]
@@ -427,6 +503,18 @@ Instance Op_coprimez : BinOp coprimez :=
427503
Add Zify BinOp Op_coprimez.
428504

429505
Module Exports.
506+
Add Zify CstOp Op_nat_0.
507+
Add Zify BinOp Op_nat_add.
508+
Add Zify CstOp Op_nat_1.
509+
Add Zify BinOp Op_nat_mul.
510+
Add Zify BinOp Op_nat_natmul.
511+
Add Zify BinOp Op_nat_exp.
512+
Add Zify CstOp Op_N_0.
513+
Add Zify BinOp Op_N_add.
514+
Add Zify CstOp Op_N_1.
515+
Add Zify BinOp Op_N_mul.
516+
Add Zify BinOp Op_N_natmul.
517+
Add Zify BinOp Op_N_exp.
430518
Add Zify InjTyp Inj_int_Z.
431519
Add Zify UnOp Op_Z_of_int.
432520
Add Zify UnOp Op_Posz.

0 commit comments

Comments
 (0)