{-# OPTIONS_GHC -Wall -Werror #-}
module Documentation.SBV.Examples.Misc.Definitions where
import Data.SBV
sumToN :: SInteger -> SInteger
sumToN :: SInteger -> SInteger
sumToN = String -> SInteger -> SInteger
forall a. Uninterpreted a => String -> a
uninterpret String
"sumToN"
defineSum :: Symbolic ()
defineSum :: Symbolic ()
defineSum = String -> [String] -> Symbolic ()
forall (m :: * -> *). SolverContext m => String -> [String] -> m ()
addSMTDefinition String
"sumToN"
[ String
"(define-fun-rec sumToN ((x Int)) Int"
, String
" (ite (<= x 0)"
, String
" 0"
, String
" (+ x (sumToN (- x 1)))))"
]
badExample :: IO ThmResult
badExample :: IO ThmResult
badExample = Predicate -> IO ThmResult
forall a. Provable a => a -> IO ThmResult
prove (Predicate -> IO ThmResult) -> Predicate -> IO ThmResult
forall a b. (a -> b) -> a -> b
$ do
let check :: SBool
check = SInteger -> SInteger
sumToN SInteger
5 SInteger -> SInteger -> SBool
forall a. EqSymbolic a => a -> a -> SBool
.== SInteger
15
SBool -> Predicate
forall (f :: * -> *) a. Applicative f => a -> f a
pure SBool
check :: Predicate
goodExample :: IO ThmResult
goodExample :: IO ThmResult
goodExample = Predicate -> IO ThmResult
forall a. Provable a => a -> IO ThmResult
prove (Predicate -> IO ThmResult) -> Predicate -> IO ThmResult
forall a b. (a -> b) -> a -> b
$ do
Symbolic ()
defineSum
let check :: SBool
check = SInteger -> SInteger
sumToN SInteger
5 SInteger -> SInteger -> SBool
forall a. EqSymbolic a => a -> a -> SBool
.== SInteger
15
SBool -> Predicate
forall (f :: * -> *) a. Applicative f => a -> f a
pure SBool
check :: Predicate