GTheory.hs revision 834b3148bd0b947226a10a04aa7a69ec08a33a6f
66267bcb678a9c341272c323b299337bcfdb7cc5Christian Maeder{-# LANGUAGE ExistentialQuantification, DeriveDataTypeable
66267bcb678a9c341272c323b299337bcfdb7cc5Christian Maeder , GeneralizedNewtypeDeriving #-}
66267bcb678a9c341272c323b299337bcfdb7cc5Christian MaederModule : $Header$
e7ce154edb906685b3fa7f6c0a764e18a4658068Christian MaederDescription : theory datastructure for development graphs
66267bcb678a9c341272c323b299337bcfdb7cc5Christian MaederCopyright : (c) Till Mossakowski, Uni Bremen 2002-2006
ffd01020a4f35f434b912844ad6e0d6918fadffdChristian MaederLicense : GPLv2 or higher, see LICENSE.txt
66267bcb678a9c341272c323b299337bcfdb7cc5Christian MaederMaintainer : till@informatik.uni-bremen.de
66267bcb678a9c341272c323b299337bcfdb7cc5Christian MaederStability : provisional
fb69cd512eab767747f109e40322df7cae2f7bdfChristian MaederPortability : non-portable(Logic)
fb69cd512eab767747f109e40322df7cae2f7bdfChristian Maedertheory datastructure for development graphs
712f5e5ca1c3a5cfdd28518154ecf2dd0994cdb5Christian Maederimport qualified Common.OrderedMap as OMap
cf3232cec840a6945667bdb06f5b47b22243bc8fChristian Maederimport qualified Data.Map as Map
cf3232cec840a6945667bdb06f5b47b22243bc8fChristian Maeder-- a theory index describing a set of sentences
cf3232cec840a6945667bdb06f5b47b22243bc8fChristian Maedernewtype ThId = ThId Int
cf3232cec840a6945667bdb06f5b47b22243bc8fChristian Maeder deriving (Typeable, Show, Eq, Ord, Enum, ShATermConvertible)
e1839fb37a3a2ccd457464cb0dcc5efd466dbe22Christian MaederstartThId :: ThId
e1839fb37a3a2ccd457464cb0dcc5efd466dbe22Christian MaederstartThId = ThId 0
5e26bfc8d7b18cf3a3fa7b919b4450fb669f37a5Christian Maeder-- | Grothendieck theories with lookup indices
5e26bfc8d7b18cf3a3fa7b919b4450fb669f37a5Christian Maederdata G_theory = forall lid sublogics
715ffaf874309df081d1e1cd8e05073fc1227729Christian Maeder basic_spec sentence symb_items symb_map_items
715ffaf874309df081d1e1cd8e05073fc1227729Christian Maeder sign morphism symbol raw_symbol proof_tree .
715ffaf874309df081d1e1cd8e05073fc1227729Christian Maeder Logic lid sublogics
5e26bfc8d7b18cf3a3fa7b919b4450fb669f37a5Christian Maeder basic_spec sentence symb_items symb_map_items
fb50920e621bfc152c19147cb52077ff06b3526bChristian Maeder sign morphism symbol raw_symbol proof_tree => G_theory
fb50920e621bfc152c19147cb52077ff06b3526bChristian Maeder { gTheoryLogic :: lid
5e26bfc8d7b18cf3a3fa7b919b4450fb669f37a5Christian Maeder , gTheorySyntax :: Maybe IRI
5e26bfc8d7b18cf3a3fa7b919b4450fb669f37a5Christian Maeder , gTheorySign :: ExtSign sign symbol
5e26bfc8d7b18cf3a3fa7b919b4450fb669f37a5Christian Maeder , gTheorySignIdx :: SigId -- ^ index to lookup 'G_sign' (using 'signOf')
715ffaf874309df081d1e1cd8e05073fc1227729Christian Maeder , gTheorySens :: ThSens sentence (AnyComorphism, BasicProof)
5e26bfc8d7b18cf3a3fa7b919b4450fb669f37a5Christian Maeder , gTheorySelfIdx :: ThId -- ^ index to lookup this 'G_theory' in theory map
5e26bfc8d7b18cf3a3fa7b919b4450fb669f37a5Christian Maeder } deriving Typeable
cf3232cec840a6945667bdb06f5b47b22243bc8fChristian MaedercreateGThWith :: G_theory -> SigId -> ThId -> G_theory
c18e9c3c6d5039618f1f2c05526ece84c7794ea3Christian MaedercreateGThWith (G_theory gtl gsub gts _ _ _) si =
715ffaf874309df081d1e1cd8e05073fc1227729Christian Maeder G_theory gtl gsub gts si noSens
715ffaf874309df081d1e1cd8e05073fc1227729Christian MaedercoerceThSens ::
715ffaf874309df081d1e1cd8e05073fc1227729Christian Maeder ( Logic lid1 sublogics1 basic_spec1 sentence1 symb_items1 symb_map_items1
fb69cd512eab767747f109e40322df7cae2f7bdfChristian Maeder sign1 morphism1 symbol1 raw_symbol1 proof_tree1
31242f7541fd6ef179e4eb5be7522ddf54ae397bChristian Maeder , Logic lid2 sublogics2 basic_spec2 sentence2 symb_items2 symb_map_items2
31242f7541fd6ef179e4eb5be7522ddf54ae397bChristian Maeder sign2 morphism2 symbol2 raw_symbol2 proof_tree2
31242f7541fd6ef179e4eb5be7522ddf54ae397bChristian Maeder , Monad m, Typeable b)
31242f7541fd6ef179e4eb5be7522ddf54ae397bChristian Maeder => lid1 -> lid2 -> String -> ThSens sentence1 b -> m (ThSens sentence2 b)
628310b42327ad76ce471caf0dde6563d6fa6307Christian MaedercoerceThSens = primCoerce
715ffaf874309df081d1e1cd8e05073fc1227729Christian Maederinstance Eq G_theory where
715ffaf874309df081d1e1cd8e05073fc1227729Christian Maeder G_theory l1 ser1 sig1 ind1 sens1 ind1'
628310b42327ad76ce471caf0dde6563d6fa6307Christian Maeder == G_theory l2 ser2 sig2 ind2 sens2 ind2' = ser1 == ser2
715ffaf874309df081d1e1cd8e05073fc1227729Christian Maeder && G_sign l1 sig1 ind1 == G_sign l2 sig2 ind2
04dada28736b4a237745e92063d8bdd49a362debChristian Maeder && (ind1' > startThId && ind2' > startThId && ind1' == ind2'
e7ce154edb906685b3fa7f6c0a764e18a4658068Christian Maeder || coerceThSens l1 l2 "" sens1 == Just sens2)
715ffaf874309df081d1e1cd8e05073fc1227729Christian Maederinstance Show G_theory where
628310b42327ad76ce471caf0dde6563d6fa6307Christian Maeder show (G_theory _ _ sign _ sens _) =
628310b42327ad76ce471caf0dde6563d6fa6307Christian Maeder shows sign $ '\n' : show sens
628310b42327ad76ce471caf0dde6563d6fa6307Christian Maederinstance Pretty G_theory where
628310b42327ad76ce471caf0dde6563d6fa6307Christian Maeder pretty g = prettyFullGTheory (gTheorySyntax g) g
715ffaf874309df081d1e1cd8e05073fc1227729Christian MaederprettyFullGTheory :: Maybe IRI -> G_theory -> Doc
ffd01020a4f35f434b912844ad6e0d6918fadffdChristian MaederprettyFullGTheory sm g = prettyGTheorySL g $++$ prettyGTheory sm g
ffd01020a4f35f434b912844ad6e0d6918fadffdChristian MaederprettyGTheorySL :: G_theory -> Doc
f0742398d4587242b1a115de113cd17f63dcb6d0Christian MaederprettyGTheorySL g = keyword logicS <+> structId (show $ sublogicOfTh g)
715ffaf874309df081d1e1cd8e05073fc1227729Christian MaederprettyGTheory :: Maybe IRI -> G_theory -> Doc
715ffaf874309df081d1e1cd8e05073fc1227729Christian MaederprettyGTheory sm g = case simplifyTh g of
715ffaf874309df081d1e1cd8e05073fc1227729Christian Maeder G_theory lid _ sign@(ExtSign s _) _ sens _ -> let l = toNamedList sens in
715ffaf874309df081d1e1cd8e05073fc1227729Christian Maeder if null l && ext_is_subsig lid sign (ext_empty_signature lid) then
5e26bfc8d7b18cf3a3fa7b919b4450fb669f37a5Christian Maeder specBraces Common.Doc.empty else printTheory sm lid (s, l)
5e26bfc8d7b18cf3a3fa7b919b4450fb669f37a5Christian Maeder-- | compute sublogic of a theory
c1031ac42b3f3d7d0fe7d9d6b54423a092d473a0Christian MaedersublogicOfTh :: G_theory -> G_sublogics
c1031ac42b3f3d7d0fe7d9d6b54423a092d473a0Christian MaedersublogicOfTh (G_theory lid _ (ExtSign sigma _) _ sens _) =
e7ce154edb906685b3fa7f6c0a764e18a4658068Christian Maeder let sub = foldl join
e7ce154edb906685b3fa7f6c0a764e18a4658068Christian Maeder (minSublogic sigma)
e7ce154edb906685b3fa7f6c0a764e18a4658068Christian Maeder OMap.map (minSublogic . sentence)
fb69cd512eab767747f109e40322df7cae2f7bdfChristian Maeder in G_sublogics lid sub
4954b30d3c209d7dee4e43016cee8189daf646e8Christian Maeder-- | get theorem names with their best proof results
4954b30d3c209d7dee4e43016cee8189daf646e8Christian MaedergetThGoals :: G_theory -> [(String, Maybe BasicProof)]
08b724e8dcbba5820d80f0974b9a5385140815baChristian MaedergetThGoals (G_theory _ _ _ _ sens _) = map toGoal . OMap.toList
4954b30d3c209d7dee4e43016cee8189daf646e8Christian Maeder $ OMap.filter (not . isAxiom) sens
08b724e8dcbba5820d80f0974b9a5385140815baChristian Maeder where toGoal (n, st) = let ts = thmStatus st in
4954b30d3c209d7dee4e43016cee8189daf646e8Christian Maeder (n, if null ts then Nothing else Just $ maximum $ map snd ts)
4954b30d3c209d7dee4e43016cee8189daf646e8Christian Maeder-- | get axiom names plus True for former theorem
5ea4161a514362065110614dd0d92adb13bf7cc3Christian MaedergetThAxioms :: G_theory -> [(String, Bool)]
4954b30d3c209d7dee4e43016cee8189daf646e8Christian MaedergetThAxioms (G_theory _ _ _ _ sens _) = map
5ea4161a514362065110614dd0d92adb13bf7cc3Christian Maeder (\ (k, s) -> (k, wasTheorem s))
08b724e8dcbba5820d80f0974b9a5385140815baChristian Maeder-- | get sentence names
08b724e8dcbba5820d80f0974b9a5385140815baChristian MaedergetThSens :: G_theory -> [String]
08b724e8dcbba5820d80f0974b9a5385140815baChristian MaedergetThSens (G_theory _ _ _ _ sens _) = map fst $ OMap.toList sens
715ffaf874309df081d1e1cd8e05073fc1227729Christian Maeder-- | simplify a theory (throw away qualifications)
715ffaf874309df081d1e1cd8e05073fc1227729Christian MaedersimplifyTh :: G_theory -> G_theory
08b724e8dcbba5820d80f0974b9a5385140815baChristian MaedersimplifyTh (G_theory lid gsyn sigma@(ExtSign s _) ind1 sens ind2) =
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder G_theory lid gsyn sigma ind1
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder (OMap.map (mapValue $ simplify_sen lid s) sens) ind2
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder-- | apply a comorphism to a theory
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian MaedermapG_theory :: AnyComorphism -> G_theory -> Result G_theory
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian MaedermapG_theory (Comorphism cid) (G_theory lid _ (ExtSign sign _) ind1 sens ind2) =
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder bTh <- coerceBasicTheory lid (sourceLogic cid)
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder ("unapplicable comorphism '" ++ language_name cid ++ "'\n")
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder (sign, toNamedList sens)
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder (sign', sens') <- wrapMapTheory cid bTh
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder return $ G_theory (targetLogic cid) Nothing (mkExtSign sign')
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder ind1 (toThSens sens') ind2
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder-- | Translation of a G_theory along a GMorphism
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian MaedertranslateG_theory :: GMorphism -> G_theory -> Result G_theory
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian MaedertranslateG_theory (GMorphism cid _ _ morphism2 _)
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder (G_theory lid _ (ExtSign sign _) _ sens _) = do
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder let tlid = targetLogic cid
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder bTh <- coerceBasicTheory lid (sourceLogic cid)
case OMap.lookup k sens of
newSens = OMap.map
in ( all fst $ OMap.elems newSens
, G_theory lid syn sig si (OMap.map snd newSens) startThId)
(axs, ths) = OMap.partition (\ s -> isAxiom s || isProvenSenStatus s) sens
in Map.union axs $ proveSensAux lid axs ths
(proveSensAux lid (OMap.filter (\ s -> isAxiom s || isProvenSenStatus s)
case Map.lookup (sentence sen) axSet of
e { OMap.ele = sen { senAttr = ThmStatus $
if Map.null ps then locTh else
cDiag <- convertNodes Graph.empty dNodes
ensures_amalgamability lid (options, diag, sink', Graph.empty)