Created
February 22, 2018 04:32
-
-
Save LeventErkok/f02973129e209c501137b74cdabd994a to your computer and use it in GitHub Desktop.
Using "17-bit-vectors" in SBV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Monad.Trans (liftIO) | |
import Control.Monad.Reader (ask) | |
import Data.SBV.Dynamic | |
-------------------------------------------------------------------------------- | |
-- I should really export the following four definitions from SBV.Dynamic | |
mkWordN :: Int -> String -> Symbolic SVal | |
mkWordN w nm = ask >>= liftIO . svMkSymVar Nothing (KBounded False w) (Just nm) | |
mkWordN_ :: Int -> Symbolic SVal | |
mkWordN_ w = ask >>= liftIO . svMkSymVar Nothing (KBounded False w) Nothing | |
mkIntN :: Int -> String -> Symbolic SVal | |
mkIntN w nm = ask >>= liftIO . svMkSymVar Nothing (KBounded True w) (Just nm) | |
mkIntN_ :: Int -> Symbolic SVal | |
mkIntN_ w = ask >>= liftIO . svMkSymVar Nothing (KBounded True w) Nothing | |
-------------------------------------------------------------------------------- | |
-- proves (x-y)*(x+y) = x*x - y*y | |
good = proveWith z3{verbose=True} $ do | |
x <- mkWordN 17 "x" | |
y <- mkWordN 17 "y" | |
let lhs = (x `svMinus` y) `svTimes` (x `svPlus` y) | |
rhs = (x `svTimes` x) `svMinus` (y `svTimes` y) | |
return $ lhs `svEqual` rhs | |
-- shows that (x-y)-(x+y) = x*x - y*y does not hold! | |
bad = proveWith z3{verbose=True} $ do | |
x <- mkWordN 17 "x" | |
y <- mkWordN 17 "y" | |
let lhs = (x `svMinus` y) `svMinus` (x `svPlus` y) | |
rhs = (x `svTimes` x) `svMinus` (y `svTimes` y) | |
return $ lhs `svEqual` rhs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment