Skip to content
This repository has been archived by the owner on Jun 9, 2021. It is now read-only.

Add a stub typeclass dictionary for the Field instance for Z n #75

Merged
merged 2 commits into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cryptol-saw-core/saw/Cryptol.sawcore
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,20 @@ PFieldRational =
};


PFieldIntMod : (n : Nat) -> PField (IntMod n);
PFieldIntMod n =
{ fieldRing = PRingIntMod n
, recip = \(x : IntMod n) -> error (IntMod n) "Unimplemented: recip IntMod"
, fieldDiv = \(x y : IntMod n) -> error (IntMod n) "Unimplemented: (/.) IntMod"
};

PFieldIntModNum : (n : Num) -> PField (IntModNum n);
PFieldIntModNum num =
Num#rec (\ (n : Num) -> PField (IntModNum n))
PFieldIntMod
(error (PField (IntModNum TCInf)) "PFieldIntModNum: no instance for inf")
num;

-- Round class

PRound : sort 0 -> sort 1;
Expand Down
5 changes: 5 additions & 0 deletions cryptol-saw-core/src/Verifier/SAW/Cryptol.hs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ importPC sc pc =
C.PGeq -> panic "importPC PGeq" []
C.PFin -> panic "importPC PFin" []
C.PHas _ -> panic "importPC PHas" []
C.PPrime -> panic "importPC PPrime" []
C.PZero -> scGlobalDef sc "Cryptol.PZero"
C.PLogic -> scGlobalDef sc "Cryptol.PLogic"
C.PRing -> scGlobalDef sc "Cryptol.PRing"
Expand Down Expand Up @@ -449,6 +450,10 @@ proveProp sc env prop =
-- instance Field Rational
(C.pIsField -> Just (C.tIsRational -> True))
-> do scGlobalApply sc "Cryptol.PFieldRational" []
-- instance (prime p) => Field (Z p)
(C.pIsField -> Just (C.tIsIntMod -> Just n))
-> do n' <- importType sc env n
scGlobalApply sc "Cryptol.PFieldIntModNum" [n']
-- instance (ValidFloat e p) => Field (Float e p)
(C.pIsField -> Just (C.tIsFloat -> Just (e, p)))
-> do e' <- importType sc env e
Expand Down
4 changes: 4 additions & 0 deletions cryptol-saw-core/test/instance.cry
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ fieldRational = recip
fieldFloat : {e, p} (ValidFloat e p) => Float e p -> Float e p
fieldFloat = recip

/* instance (prime p) => Field (Z p) */
fieldZ : {p} prime p => Z p -> Z p
fieldZ = recip

////////////////////////////////////////////////////////////////////////////////
// Round

Expand Down