ProveWithTruthTable.hs revision 98890889ffb2e8f6f722b00e265a211f13b5a861
87708bde16713bc02ff2598f4a82f98c699a2f2dMark AndrewsModule : $Header$
87708bde16713bc02ff2598f4a82f98c699a2f2dMark AndrewsDescription : Provers for propositional logic
87708bde16713bc02ff2598f4a82f98c699a2f2dMark AndrewsCopyright : (c) Till Mossakowski, Uni Bremen 2008
87708bde16713bc02ff2598f4a82f98c699a2f2dMark AndrewsLicense : GPLv2 or higher, see LICENSE.txt
87708bde16713bc02ff2598f4a82f98c699a2f2dMark AndrewsMaintainer : till@informatik.uni-bremen.de
87708bde16713bc02ff2598f4a82f98c699a2f2dMark AndrewsStability : experimental
87708bde16713bc02ff2598f4a82f98c699a2f2dMark AndrewsPortability : portable
87708bde16713bc02ff2598f4a82f98c699a2f2dMark AndrewsA truth table prover for propositional logic.
87708bde16713bc02ff2598f4a82f98c699a2f2dMark AndrewsInefficient, but useful for learning purposes.
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews , ttConsistencyChecker
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver , ttConservativityChecker
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryverimport qualified Propositional.Morphism as PMorphism
475b1ed9cced1f92ce34bc2e59b3065dae48f366Mark Andrewsimport qualified Propositional.ProverState as PState
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryverimport qualified Propositional.Sign as Sig
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsimport Propositional.Sublogic (PropSL, top)
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryverimport qualified Logic.Prover as LP
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryverimport qualified Interfaces.GenericATPState as ATPState
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryverimport GUI.Utils (infoDialog, createTextSaveDisplay)
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryverimport qualified Common.AS_Annotation as AS_Anno
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryverimport qualified Common.Id as Id
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryverimport qualified Data.Set as Set
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryverimport qualified Common.OrderedMap as OMap
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryverimport qualified Common.Result as Result
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryverimport Data.Time (midnight)
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver-- * Prover implementation
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver-- | the name of the prover
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon SchryverttS = "truth tables"
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver-- maximal size of the signature
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon SchryvermaxSigSize :: Int
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon SchryvermaxSigSize = 17
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver-- display error message when signature is too large
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon SchryversigTooLarge :: Int -> String
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon SchryversigTooLarge sigSize = unlines
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver [ "Signature is too large."
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver , "It should contain < " ++ show maxSigSize ++ " symbols,"
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver , "but it contains " ++ show sigSize ++ " symbols." ]
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon SchryverttHelpText :: String
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon SchryverttHelpText = "An implementation of the truth table method.\n"
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver ++ "Very inefficient, but useful for learning and teaching\n"
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver ++ "Works well for signatures with less than " ++ show maxSigSize
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver ++ " symbols."
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver Models and evaluation of sentences
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryvertype Model = Set.Set Id.Id -- a model specifies which propositions are true
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver-- | show Bools in truth table
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon SchryvershowBool :: Bool -> String
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon SchryvershowBool True = "T"
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon SchryvershowBool False = "F"
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver-- | evaluation of sentences in a model
7b4b6f361b2fb2291c2019b377a9c0c8e80cfd6bMark Andrewseval :: Model -> FORMULA -> Bool
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryvereval m (Negation phi _) = not $ eval m phi
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryvereval m (Conjunction phis _) = all (eval m) phis
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryvereval m (Disjunction phis _) = any (eval m) phis
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewseval m (Implication phi1 phi2 _) = not (eval m phi1) || eval m phi2
evalNamed :: Model -> AS_Anno.Named FORMULA -> Bool
evalNamed m = eval m . AS_Anno.sentence
amalg = Set.union
evalNamedFormulaOrFree :: Model -> AS_Anno.Named FormulaOrFree -> Bool
evalNamedFormulaOrFree m = evalFormulaOrFree m . AS_Anno.sentence
reduceModel :: Sig.Sign -> Model -> Model
reduceModel sig m = Set.intersection m (items sig)
leq = Set.isSubsetOf
let diffsig = Sign (items freetar `Set.difference` items freesrc)
where freemor = LP.freeDefMorphism freedef
freesrc = PMorphism.source freemor
freetar = PMorphism.target freemor
isCo = LP.isCofree freedef
allModels sig = allModels1 $ Set.toList $ items sig
where allModels1 [] = [Set.empty]
in models ++ map (Set.insert p) models
$ Header (rowtype r) : map (const (Header "")) [2..length (rextrows r)]
emptyPrefix = map (const "") [1..length common]
ttProver = LP.mkProverTemplate ttS top ttProveGUI
PMorphism.Morphism ProofTree
ttConsistencyChecker = LP.mkConsChecker ttS top consCheck
consCheck :: String -> LP.TacticScript
-> IO (LP.CCStatus ProofTree)
consCheck _ _ tm _freedefs = case LP.tTarget tm of
LP.Theory sig nSens ->
let sigSize = Set.size (items sig) in
return $ LP.CCStatus (ProofTree $ sigTooLarge sigSize) midnight Nothing
sigList = Set.toList $ items sig
let evalAx = map (eval m . AS_Anno.sentence . snd) axs
in TTRow { rprops = map (`Set.member` m) sigList
return $ LP.CCStatus (ProofTree body) midnight $ Just isOK
-> IO([LP.ProofStatus ProofTree]) -- ^ proof status for each goal
genericATPgui (atpFun thName) True (LP.proverName ttProver) thName th
atpFun thName = ATPState.ATPFunctions
, ATPState.goalOutput = goalProblem thName
, ATPState.proverHelpText = ttHelpText
, ATPState.runProver = runTt
, ATPState.batchTimeEnv = ""
{ ATPState.problemOutput = ".tt"
, ATPState.proverOutput = ".tt"
, ATPState.theoryConfiguration = ".tt"}
, ATPState.createProverOptions = createTtOptions
runTt :: PState.PropProverState
-> ATPState.GenericConfig ProofTree
-> AS_Anno.Named FORMULA
let sig = PState.initialSignature pState
sigSize = Set.size $ items sig
return (ATPState.ATPTLimitExceeded,
cfg { ATPState.proofStatus = defaultProofStatus nGoal })
let axs = PState.initialAxioms pState
freedefs = PState.freeDefs pState
sens = map (AS_Anno.mapNamed Formula) axs ++ map nameFree freedefs
sigList = Set.toList $ items sig
, haxioms = map AS_Anno.senAttr sens
, hgoal = Just $ AS_Anno.senAttr nGoal
in TTRow { rprops = map (`Set.member` m) sigList
else LP.Disproved
return (ATPState.ATPSuccess,
cfg { ATPState.proofStatus = status
, ATPState.resultOutput = [body] })
createTtOptions :: ATPState.GenericConfig ProofTree -> [String]
-> PState.PropProverState -- ^ initial Prover state
-> AS_Anno.Named FORMULA -- ^ goal to prove
(Sign, [AS_Anno.Named FORMULA]) -- ^ Initial sign and formulas
-> PMorphism.Morphism -- ^ morhpism between specs
-> [AS_Anno.Named FORMULA] -- ^ Formulas of extended spec
-> IO (Result.Result (Maybe (Conservativity, [FORMULA])))
let srcAxs = filter AS_Anno.isAxiom srcSens
tarAxs = filter AS_Anno.isAxiom tarSens
srcSig = items $ PMorphism.source mor
imageSigList = Set.toList imageSig
tarSig = items $ PMorphism.target mor
newSig = Set.difference tarSig imageSig
sigSize = Set.size tarSig
newSigList = Set.toList newSig
haxioms = map AS_Anno.senAttr srcAxs,
hextaxioms = map AS_Anno.senAttr tarAxs,
in TTExtRow { rextprops = map (`Set.member` m') newSigList,
in TTRow { rprops = map (`Set.member` m) imageSigList,