Analysis.hs revision 61091743da1a9ed6dfd5e077fdcc972553358962
bbae6e6ca0de7f2ffbb44d2c8da179f2b717237fChristian Maeder{-# OPTIONS -fallow-undecidable-instances #-}
bbae6e6ca0de7f2ffbb44d2c8da179f2b717237fChristian MaederModule : $Header$
75a6279dbae159d018ef812185416cf6df386c10Till MossakowskiDescription : Instance of class Logic for propositional logic
bbae6e6ca0de7f2ffbb44d2c8da179f2b717237fChristian MaederCopyright : (c) Dominik Luecke, Uni Bremen 2007
bbae6e6ca0de7f2ffbb44d2c8da179f2b717237fChristian MaederLicense : similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt
bbae6e6ca0de7f2ffbb44d2c8da179f2b717237fChristian MaederMaintainer : luecke@tzi.de
bbae6e6ca0de7f2ffbb44d2c8da179f2b717237fChristian MaederStability : experimental
bbae6e6ca0de7f2ffbb44d2c8da179f2b717237fChristian MaederPortability : portable
bbae6e6ca0de7f2ffbb44d2c8da179f2b717237fChristian MaederBasic and static analysis for propositional logic
bbae6e6ca0de7f2ffbb44d2c8da179f2b717237fChristian Maeder <http://en.wikipedia.org/wiki/Propositional_logic>
bbae6e6ca0de7f2ffbb44d2c8da179f2b717237fChristian Maeder basicPropositionalAnalysis
bbae6e6ca0de7f2ffbb44d2c8da179f2b717237fChristian Maeder ,mkStatSymbItems
e774ab5733a1d673b123b0e63b14dd533e6fd4fcChristian Maeder ,mkStatSymbMapItem
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian Maeder ,inducedFromMorphism
e774ab5733a1d673b123b0e63b14dd533e6fd4fcChristian Maeder ,inducedFromToMorphism
7abd0c58a5ce51db13f93de82407b2188d55d298Christian Maederimport qualified Propositional.AS_BASIC_Propositional as AS_BASIC
7abd0c58a5ce51db13f93de82407b2188d55d298Christian Maederimport qualified Propositional.Sign as Sign
7abd0c58a5ce51db13f93de82407b2188d55d298Christian Maederimport qualified Common.GlobalAnnotations as GlobalAnnos
df638d53c2d5fe5e80b943a58609c8936848ed82Christian Maederimport qualified Common.AS_Annotation as AS_Anno
7abd0c58a5ce51db13f93de82407b2188d55d298Christian Maederimport qualified Common.Result as Result
bbae6e6ca0de7f2ffbb44d2c8da179f2b717237fChristian Maederimport qualified Common.Id as Id
7abd0c58a5ce51db13f93de82407b2188d55d298Christian Maederimport qualified Data.List as List
7abd0c58a5ce51db13f93de82407b2188d55d298Christian Maederimport qualified Data.Set as Set
bbae6e6ca0de7f2ffbb44d2c8da179f2b717237fChristian Maederimport qualified Data.Map as Map
7abd0c58a5ce51db13f93de82407b2188d55d298Christian Maederimport qualified Propositional.Symbol as Symbol
7abd0c58a5ce51db13f93de82407b2188d55d298Christian Maederimport qualified Propositional.Morphism as Morphism
bbae6e6ca0de7f2ffbb44d2c8da179f2b717237fChristian Maeder-- | Datatype for formulas with diagnosis data
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian Maederdata DIAG_FORM = DiagForm
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian Maeder formula :: AS_Anno.Named (AS_BASIC.FORMULA),
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian Maeder-- | Formula annotated with a number
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian Maederdata NUM_FORM = NumForm
df638d53c2d5fe5e80b943a58609c8936848ed82Christian Maeder nfformula :: AS_Anno.Annoted (AS_BASIC.FORMULA)
df638d53c2d5fe5e80b943a58609c8936848ed82Christian Maeder , nfnum :: Integer
df638d53c2d5fe5e80b943a58609c8936848ed82Christian Maederdata TEST_SIG = TestSig
bbae6e6ca0de7f2ffbb44d2c8da179f2b717237fChristian Maeder , occurence :: Int
bbae6e6ca0de7f2ffbb44d2c8da179f2b717237fChristian Maeder , tdiagnosis :: [Result.Diagnosis]
bbae6e6ca0de7f2ffbb44d2c8da179f2b717237fChristian Maeder-- | Retrieves the signature out of a basic spec
bbae6e6ca0de7f2ffbb44d2c8da179f2b717237fChristian Maeder -> Sign.Sign -- Input Signature
bbae6e6ca0de7f2ffbb44d2c8da179f2b717237fChristian Maeder -> TEST_SIG -- Output Signature
bbae6e6ca0de7f2ffbb44d2c8da179f2b717237fChristian MaedermakeSig (AS_BASIC.Basic_spec spec) sig = List.foldl retrieveBasicItem
bbae6e6ca0de7f2ffbb44d2c8da179f2b717237fChristian Maeder (TestSig{ msign=sig
bbae6e6ca0de7f2ffbb44d2c8da179f2b717237fChristian Maeder , occurence=0
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian Maeder , tdiagnosis = []
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian Maeder-- Helper for makeSig
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian MaederretrieveBasicItem ::
bbae6e6ca0de7f2ffbb44d2c8da179f2b717237fChristian Maeder TEST_SIG -- Input Signature
e774ab5733a1d673b123b0e63b14dd533e6fd4fcChristian Maeder -> AS_Anno.Annoted (AS_BASIC.BASIC_ITEMS) -- Input Item
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian Maeder -> TEST_SIG -- Output Signature
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian MaederretrieveBasicItem tsig x =
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian Maeder occ = occurence tsig
bbae6e6ca0de7f2ffbb44d2c8da179f2b717237fChristian Maeder if (occ == 0)
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian Maeder (\asig ax-> TestSig{
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian Maeder msign = Sign.addToSig (msign asig) $ Id.simpleIdToId ax
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian Maeder , occurence = occ
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian Maeder , tdiagnosis = tdiagnosis tsig ++
e774ab5733a1d673b123b0e63b14dd533e6fd4fcChristian Maeder tsig $ (\(AS_BASIC.Pred_item xs _)-> xs) apred
e774ab5733a1d673b123b0e63b14dd533e6fd4fcChristian Maeder (\asig ax-> TestSig{
e774ab5733a1d673b123b0e63b14dd533e6fd4fcChristian Maeder msign = Sign.addToSig (msign asig) $ Id.simpleIdToId ax
e774ab5733a1d673b123b0e63b14dd533e6fd4fcChristian Maeder , occurence = occ
e774ab5733a1d673b123b0e63b14dd533e6fd4fcChristian Maeder , tdiagnosis = tdiagnosis tsig ++
e774ab5733a1d673b123b0e63b14dd533e6fd4fcChristian Maeder , Result.diagString = "Definition of proposition " ++
e774ab5733a1d673b123b0e63b14dd533e6fd4fcChristian Maeder (show $ pretty ax) ++
tsig $ (\(AS_BASIC.Pred_item xs _)-> xs) apred
(AS_BASIC.Axiom_items _) -> TestSig { msign = msign tsig
, Result.diagString = "First axiom"
-> Sign.Sign
makeFormulas (AS_BASIC.Basic_spec bspec) sig =
List.foldl (\xs bs -> retrieveFormulaItem xs bs sig) [] bspec
-> Sign.Sign
case (AS_Anno.item x) of
(AS_BASIC.Pred_decl _) -> axs
(AS_BASIC.Axiom_items ax) ->
List.foldl (\xs bs -> addFormula xs bs sig) axs $ numberFormulae ax 0
label = AS_Anno.getRLabel x
-> Sign.Sign
, diagnosis = Result.Diag
, Result.diagString = "All fine"
, Result.diagPos = lnum
, diagnosis = Result.Diag
, Result.diagString = "Unknown propositions "
, Result.diagPos = lnum
nakedFormula = AS_Anno.item f
isLegal = Sign.isSubSigOf varsOfFormula sign
difference = Sign.sigDiff varsOfFormula sign
lnum = AS_Anno.opt_pos f
makeNamed f i = (AS_Anno.makeNamed (if label == "" then "Ax_" ++ show i
else label) $ AS_Anno.item f)
{ AS_Anno.isAxiom = not isTheorem }
label = AS_Anno.getRLabel f
annos = AS_Anno.r_annos f
isImplies = foldl (\y x -> AS_Anno.isImplies x || y) False annos
isImplied = foldl (\y x -> AS_Anno.isImplied x || y) False annos
propsOfFormula (AS_BASIC.Negation form _) = propsOfFormula form
Id.simpleIdToId x }
basicAnalysis :: AS_BASIC.BASIC_SPEC
-> Sign.Sign
-> Result.Result (
| exErrs == False = Result.Result diags $ Just (bs, sigItems, formulae)
| otherwise = Result.Result diags $ Nothing
exErrs = Result.hasErrors diags
-- | Wrapper for the interface defined in Logic.Logic
-> Result.Result (
mkStatSymbMapItem :: [AS_BASIC.SYMB_MAP_ITEMS]
Result.diags = []
, Result.maybeResult = Just $
AS_BASIC.Symb_map_items sitem _ ->
Map.union smap $ statSymbMapItem sitem
statSymbMapItem :: [AS_BASIC.SYMB_OR_MAP]
AS_BASIC.Symb_map s1 s2 _
-> Map.insert (symbToSymbol s1) (symbToSymbol s2) mmap
mkStatSymbItems a = Result.Result
Result.diags = []
, Result.maybeResult = Just $ statSymbItems a
symbItemsToSymbol (AS_BASIC.Symb_items syms _) = map symbToSymbol syms
symbToSymbol (AS_BASIC.Symb_id tok) =
-> Sign.Sign
Result.diags = []
sigItems = Sign.items sig
Set.fold (
Map.insert x y
Map.empty sigItems
Morphism.source = sig
, Morphism.propMap = pMap
{Sign.items =
Sign.items sig
-> Sign.Sign
-> Sign.Sign
sigItems = Sign.items sig
Set.fold (
Map.insert x y
Map.empty sigItems
targetSig = Sign.Sign
{Sign.items =
Sign.items sig
True -> Result.Result
Result.diags = []
Morphism.source = sig
, Morphism.propMap = pMap
, Morphism.target = tSig
False -> Result.Result
, Result.diagString = "Incompatible mapping"
, Result.maybeResult = Nothing