Skip to content

Commit 9f03146

Browse files
committed
Rework stdlib clones
1 parent fa18670 commit 9f03146

File tree

2 files changed

+17
-73
lines changed

2 files changed

+17
-73
lines changed

theories/algebra/Poly.ec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ qed.
504504
lemma onep_neq0 : poly1 <> poly0.
505505
proof. by apply/negP => /poly_eqP /(_ 0); rewrite !polyCE /= oner_neq0. qed.
506506

507-
clone import Ring.ComRing as PolyComRing with
507+
clone export Ring.ComRing as PolyComRing with
508508
type t <= poly ,
509509
op zeror <= poly0,
510510
op oner <= poly1,

theories/algebra/PolyReduce.ec

Lines changed: 16 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,22 @@ require import Ring StdOrder IntDiv ZModP Ideal Poly.
88

99
(* ==================================================================== *)
1010
abstract theory PolyReduce.
11+
type coeff.
1112

12-
clone import PolyComRing as BasePoly with
13-
(* We currently don't care about inverting polynomials *)
14-
pred PolyComRing.unit <= fun p => exists q, polyM q p = oner,
15-
op PolyComRing.invr <= fun p => choiceb (fun q => polyM q p = oner) p
16-
proof PolyComRing.mulVr, PolyComRing.unitP, PolyComRing.unitout.
17-
realize PolyComRing.mulVr by smt(choicebP).
18-
realize PolyComRing.unitP by smt().
19-
realize PolyComRing.unitout by smt(choiceb_dfl).
13+
clone import ComRing as Coeff with type t <= coeff.
2014

21-
(*-*) import Coeff PolyComRing BigPoly BigCf.
15+
clone export PolyComRing as BasePoly
16+
with type coeff <- coeff,
17+
theory Coeff <- Coeff.
18+
19+
import Coeff BigPoly BigCf.
2220

2321
(* -------------------------------------------------------------------- *)
2422
clone import IdealComRing as PIdeal with
25-
type t <- BasePoly.poly,
26-
op IComRing.zeror <- BasePoly.poly0,
27-
op IComRing.oner <- BasePoly.poly1,
28-
op IComRing.( + ) <- BasePoly.PolyComRing.( + ),
29-
op IComRing.([-]) <- BasePoly.PolyComRing.([-]),
30-
op IComRing.( * ) <- BasePoly.PolyComRing.( * ),
31-
op IComRing.invr <- BasePoly.PolyComRing.invr,
32-
pred IComRing.unit <- BasePoly.PolyComRing.unit,
33-
op BigDom.BAdd.big <- BasePoly.BigPoly.PCA.big<:'a>,
34-
op BigDom.BMul.big <- BasePoly.BigPoly.PCM.big<:'a>
35-
36-
proof IComRing.addrA by exact: BasePoly.PolyComRing.addrA ,
37-
IComRing.addrC by exact: BasePoly.PolyComRing.addrC ,
38-
IComRing.add0r by exact: BasePoly.PolyComRing.add0r ,
39-
IComRing.addNr by exact: BasePoly.PolyComRing.addNr ,
40-
IComRing.oner_neq0 by exact: BasePoly.PolyComRing.oner_neq0,
41-
IComRing.mulrA by exact: BasePoly.PolyComRing.mulrA ,
42-
IComRing.mulrC by exact: BasePoly.PolyComRing.mulrC ,
43-
IComRing.mul1r by exact: BasePoly.PolyComRing.mul1r ,
44-
IComRing.mulrDl by exact: BasePoly.PolyComRing.mulrDl ,
45-
IComRing.mulVr by exact: BasePoly.PolyComRing.mulVr ,
46-
IComRing.unitP by exact: BasePoly.PolyComRing.unitP ,
47-
IComRing.unitout by exact: BasePoly.PolyComRing.unitout
48-
49-
remove abbrev IComRing.(-)
50-
remove abbrev IComRing.(/)
23+
type t <- BasePoly.poly,
24+
theory IComRing <- BasePoly.PolyComRing,
25+
op BigDom.BAdd.big <- BasePoly.BigPoly.PCA.big<:'a>,
26+
op BigDom.BMul.big <- BasePoly.BigPoly.PCM.big<:'a>
5127

5228
remove abbrev BigDom.BAdd.bigi
5329
remove abbrev BigDom.BMul.bigi.
@@ -484,56 +460,24 @@ end PolyReduce.
484460

485461
(* ==================================================================== *)
486462
abstract theory PolyReduceZp.
463+
type coeff.
487464

488465
op p : { int | 2 <= p } as ge2_p.
489466

490467
clone import ZModRing as Zp with
491468
op p <= p
492469
proof ge2_p by exact/ge2_p.
493470

494-
type Zp = zmod.
495-
496-
clone include PolyReduce with
497-
type BasePoly.coeff <- Zp,
498-
pred BasePoly.Coeff.unit <- Zp.unit,
499-
op BasePoly.Coeff.zeror <- Zp.zero,
500-
op BasePoly.Coeff.oner <- Zp.one,
501-
op BasePoly.Coeff.( + ) <- Zp.( + ),
502-
op BasePoly.Coeff.([-]) <- Zp.([-]),
503-
op BasePoly.Coeff.( * ) <- Zp.( * ),
504-
op BasePoly.Coeff.invr <- Zp.inv,
505-
op BasePoly.Coeff.ofint <- Zp.ZModpRing.ofint,
506-
op BasePoly.Coeff.exp <- Zp.ZModpRing.exp,
507-
op BasePoly.Coeff.intmul <- Zp.ZModpRing.intmul,
508-
op BasePoly.Coeff.lreg <- Zp.ZModpRing.lreg
509-
proof BasePoly.Coeff.addrA by exact Zp.ZModpRing.addrA
510-
proof BasePoly.Coeff.addrC by exact Zp.ZModpRing.addrC
511-
proof BasePoly.Coeff.add0r by exact Zp.ZModpRing.add0r
512-
proof BasePoly.Coeff.addNr by exact Zp.ZModpRing.addNr
513-
proof BasePoly.Coeff.oner_neq0 by exact Zp.ZModpRing.oner_neq0
514-
proof BasePoly.Coeff.mulrA by exact Zp.ZModpRing.mulrA
515-
proof BasePoly.Coeff.mulrC by exact Zp.ZModpRing.mulrC
516-
proof BasePoly.Coeff.mul1r by exact Zp.ZModpRing.mul1r
517-
proof BasePoly.Coeff.mulrDl by exact Zp.ZModpRing.mulrDl
518-
proof BasePoly.Coeff.mulVr by exact Zp.ZModpRing.mulVr
519-
proof BasePoly.Coeff.unitP by exact Zp.ZModpRing.unitP
520-
proof BasePoly.Coeff.unitout by exact Zp.ZModpRing.unitout
521-
remove abbrev BasePoly.Coeff.(-)
522-
remove abbrev BasePoly.Coeff.(/).
523-
524-
clear [BasePoly.Coeff.*].
525-
clear [BasePoly.Coeff.AddMonoid.*].
526-
clear [BasePoly.Coeff.MulMonoid.*].
527-
528-
(* -------------------------------------------------------------------- *)
529-
import BasePoly.
471+
clone import PolyReduce with
472+
type coeff <- Zp.zmod,
473+
theory Coeff <- ZModpRing.
530474

531475
(* ==================================================================== *)
532476
(* We already know that polyXnD1 is finite. However, we prove here that *)
533477
(* we can build the full-uniform distribution over polyXnD1 by sampling *)
534478
(* uniformly each coefficient in the reduced form representation. *)
535479

536-
op dpolyX (dcoeff : Zp distr) : polyXnD1 distr =
480+
op dpolyX (dcoeff : zmod distr) : polyXnD1 distr =
537481
dmap (dpoly n dcoeff) pinject.
538482

539483
lemma dpolyX_ll d : is_lossless d => is_lossless (dpolyX d).

0 commit comments

Comments
 (0)