Skip to content

Instantly share code, notes, and snippets.

@LeventErkok
Created February 22, 2018 04:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeventErkok/f02973129e209c501137b74cdabd994a to your computer and use it in GitHub Desktop.
Save LeventErkok/f02973129e209c501137b74cdabd994a to your computer and use it in GitHub Desktop.
Using "17-bit-vectors" in SBV
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