Skip to content

Instantly share code, notes, and snippets.

@cryptica
Created May 14, 2014 19:54
Show Gist options
  • Select an option

  • Save cryptica/cd98b6833c3499740ca3 to your computer and use it in GitHub Desktop.

Select an option

Save cryptica/cd98b6833c3499740ca3 to your computer and use it in GitHub Desktop.
Haskell program repeatedly calling sat from the SBV library with an increasing number of variables
import System.Environment (getArgs)
import Control.Monad (unless)
import Data.SBV
testInt :: Int -> Predicate
testInt n = do
vars <- mkExistVars n
let s = sum vars
return $ s .>= (1::SInteger) &&& s .<= 5 &&& s ./= 3
testRun :: Int -> Int -> IO ()
testRun n i = do
putStrLn $ "Test run " ++ show i
result <- sat $ testInt n
unless (modelExists result) (error "Predicate should be satisfiable")
testVars :: Int -> IO ()
testVars n = do
putStrLn $ "Test with n = " ++ show n
mapM_ (testRun n) [0..10]
main :: IO ()
main = do
args <- getArgs
let maxN = read $ head args
mapM_ testVars [1..maxN]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment