Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add prime to isNumeric, define cryPrime SMT-LIB function #1778

Merged
merged 3 commits into from
Nov 27, 2024
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
17 changes: 13 additions & 4 deletions lib/CryptolTC.z3
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@
(cryBool true)
)


(declare-fun cryPrimeUnknown (Int) Bool)

(define-fun cryPrime ((x InfNat)) MaybeBool
(ite (isErr x) cryErrProp
(cryBool (and (isFin x) (cryPrimeUnknown (value x)))))
)


; ------------------------------------------------------------------------------
; Basic Cryptol assume/assert

Expand Down Expand Up @@ -327,14 +336,14 @@

; (declare-fun L () InfNat)
; (declare-fun w () InfNat)
;
;
; (assert (cryVar L))
; (assert (cryVar w))
;
;
; (assert (cryAssume (cryFin w)))
; (assert (cryAssume (cryGeq w (cryNat 1))))
; (assert (cryAssume (cryGeq (cryMul (cryNat 2) w) (cryWidth L))))
;
;
; (assert (cryProve
; (cryGeq
; (cryMul
Expand All @@ -343,7 +352,7 @@
; (cryMul (cryNat 16) w))
; (cryMul (cryNat 16) w))
; (cryAdd (cryNat 1) (cryAdd L (cryMul (cryNat 2) w))))))
;
;
; (check-sat)


4 changes: 3 additions & 1 deletion src/Cryptol/TypeCheck/Solver/SMT.hs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ flatGoal g = [ g { goal = p } | p <- pSplitAnd (goal g) ]

-- | Assumes no 'And'
isNumeric :: Prop -> Bool
isNumeric ty = matchDefault False $ msum [ is (|=|), is (|/=|), is (|>=|), is aFin ]
isNumeric ty = matchDefault False $ msum [ is (|=|), is (|/=|), is (|>=|)
, is aFin, is aPrime ]
where
is f = f ty >> return True

Expand All @@ -368,6 +369,7 @@ toSMT tvs ty = matchDefault (panic "toSMT" [ "Unexpected type", show ty ])
, aNat ~> "cryNat"

, aFin ~> "cryFin"
, aPrime ~> "cryPrime"
, (|=|) ~> "cryEq"
, (|/=|) ~> "cryNeq"
, (|>=|) ~> "cryGeq"
Expand Down
5 changes: 4 additions & 1 deletion src/Cryptol/TypeCheck/TypePat.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module Cryptol.TypeCheck.TypePat
, aRec
, (|->|)

, aFin, (|=|), (|/=|), (|>=|)
, aFin, aPrime, (|=|), (|/=|), (|>=|)
, aAnd
, aTrue

Expand Down Expand Up @@ -165,6 +165,9 @@ aRec = \a -> case tNoUser a of
aFin :: Pat Prop Type
aFin = tp PFin ar1

aPrime :: Pat Prop Type
aPrime = tp PPrime ar1

(|=|) :: Pat Prop (Type,Type)
(|=|) = tp PEqual ar2

Expand Down
Loading