Skip to content

Commit

Permalink
Merge pull request #1778 from GaloisInc/T1777-isNumeric-prime
Browse files Browse the repository at this point in the history
Add `prime` to `isNumeric`, define `cryPrime` SMT-LIB function
  • Loading branch information
RyanGlScott authored Nov 27, 2024
2 parents 4485d70 + f8dffb9 commit 9a53006
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
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

0 comments on commit 9a53006

Please sign in to comment.