Skip to content

Commit

Permalink
Add prime to isNumeric, define cryPrime SMT-LIB function
Browse files Browse the repository at this point in the history
Fixes #1777.
  • Loading branch information
RyanGlScott committed Nov 27, 2024
1 parent 3f2e3ca commit bcf5672
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
17 changes: 17 additions & 0 deletions lib/CryptolTC.z3
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@
(cryBool true)
)


(declare-fun cryPrimeUnknown (Int) Bool)

(define-fun cryPrimeTable ((x Int)) Bool
(or (= x 2)
(or (= x 3)
(or (= x 5)
(or (= x 7)
(cryPrimeUnknown x)))))
)

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


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

Expand Down
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

0 comments on commit bcf5672

Please sign in to comment.