{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -Wall -Werror #-}
module Documentation.SBV.Examples.Uninterpreted.Deduce where
import Data.SBV
import Prelude hiding (not, or, and)
data B
mkUninterpretedSort ''B
and :: SB -> SB -> SB
and :: SBV B -> SBV B -> SBV B
and = String -> SBV B -> SBV B -> SBV B
forall a. Uninterpreted a => String -> a
uninterpret String
"AND"
or :: SB -> SB -> SB
or :: SBV B -> SBV B -> SBV B
or = String -> SBV B -> SBV B -> SBV B
forall a. Uninterpreted a => String -> a
uninterpret String
"OR"
not :: SB -> SB
not :: SBV B -> SBV B
not = String -> SBV B -> SBV B
forall a. Uninterpreted a => String -> a
uninterpret String
"NOT"
ax1 :: [String]
ax1 :: [String]
ax1 = [ String
"(assert (forall ((p B) (q B) (r B))"
, String
" (= (AND (OR p q) (OR p r))"
, String
" (OR p (AND q r)))))"
]
ax2 :: [String]
ax2 :: [String]
ax2 = [ String
"(assert (forall ((p B) (q B))"
, String
" (= (NOT (OR p q))"
, String
" (AND (NOT p) (NOT q)))))"
]
ax3 :: [String]
ax3 :: [String]
ax3 = [String
"(assert (forall ((p B)) (= (NOT (NOT p)) p)))"]
test :: IO ThmResult
test :: IO ThmResult
test = SymbolicT IO SBool -> IO ThmResult
forall a. Provable a => a -> IO ThmResult
prove (SymbolicT IO SBool -> IO ThmResult)
-> SymbolicT IO SBool -> IO ThmResult
forall a b. (a -> b) -> a -> b
$ do String -> [String] -> SymbolicT IO ()
forall (m :: * -> *). SolverContext m => String -> [String] -> m ()
addAxiom String
"OR distributes over AND" [String]
ax1
String -> [String] -> SymbolicT IO ()
forall (m :: * -> *). SolverContext m => String -> [String] -> m ()
addAxiom String
"de Morgan" [String]
ax2
String -> [String] -> SymbolicT IO ()
forall (m :: * -> *). SolverContext m => String -> [String] -> m ()
addAxiom String
"double negation" [String]
ax3
SBV B
p <- String -> Symbolic (SBV B)
forall a. SymVal a => String -> Symbolic (SBV a)
free String
"p"
SBV B
q <- String -> Symbolic (SBV B)
forall a. SymVal a => String -> Symbolic (SBV a)
free String
"q"
SBV B
r <- String -> Symbolic (SBV B)
forall a. SymVal a => String -> Symbolic (SBV a)
free String
"r"
SBool -> SymbolicT IO SBool
forall (m :: * -> *) a. Monad m => a -> m a
return (SBool -> SymbolicT IO SBool) -> SBool -> SymbolicT IO SBool
forall a b. (a -> b) -> a -> b
$ SBV B -> SBV B
not (SBV B
p SBV B -> SBV B -> SBV B
`or` (SBV B
q SBV B -> SBV B -> SBV B
`and` SBV B
r))
SBV B -> SBV B -> SBool
forall a. EqSymbolic a => a -> a -> SBool
.== (SBV B -> SBV B
not SBV B
p SBV B -> SBV B -> SBV B
`and` SBV B -> SBV B
not SBV B
q) SBV B -> SBV B -> SBV B
`or` (SBV B -> SBV B
not SBV B
p SBV B -> SBV B -> SBV B
`and` SBV B -> SBV B
not SBV B
r)