Comorphism.hs revision 3d3889e0cefcdce9b3f43c53aaa201943ac2e895
967e5f3c25249c779575864692935627004d3f9eChristian Maeder{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, DeriveDataTypeable
967e5f3c25249c779575864692935627004d3f9eChristian Maeder , FlexibleInstances, UndecidableInstances, ExistentialQuantification #-}
81d182b21020b815887e9057959228546cf61b6bChristian Maeder{- |
f11f713bebd8e1e623a0a4361065df256033de47Christian MaederModule : $Header$
97018cf5fa25b494adffd7e9b4e87320dae6bf47Christian MaederDescription : interface and class for logic translations
967e5f3c25249c779575864692935627004d3f9eChristian MaederCopyright : (c) Till Mossakowski, Uni Bremen 2002-2006
3f69b6948966979163bdfe8331c38833d5d90ecdChristian MaederLicense : GPLv2 or higher, see LICENSE.txt
967e5f3c25249c779575864692935627004d3f9eChristian MaederMaintainer : till@informatik.uni-bremen.de
89054b2b95a3f92e78324dc852f3d34704e2ca49Christian MaederStability : provisional
f3a94a197960e548ecd6520bb768cb0d547457bbChristian MaederPortability : non-portable (via Logic)
717686b54b9650402e2ebfbaadf433eab8ba5171Christian Maeder
717686b54b9650402e2ebfbaadf433eab8ba5171Christian MaederCentral interface (type class) for logic translations (comorphisms) in Hets
967e5f3c25249c779575864692935627004d3f9eChristian Maeder These are just collections of
967e5f3c25249c779575864692935627004d3f9eChristian Maeder functions between (some of) the types of logics.
967e5f3c25249c779575864692935627004d3f9eChristian Maeder
967e5f3c25249c779575864692935627004d3f9eChristian Maeder References: see Logic.hs
967e5f3c25249c779575864692935627004d3f9eChristian Maeder-}
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder
67d92da5e9610aabad39055a16031154b4dc3748Christian Maedermodule Logic.Comorphism
650bafe7709533bc5f82bb9daf8fa06f431cd963Christian Maeder ( CompComorphism (..)
9cb4aa4ea6685489a38f9b609f5dbe5d37f25bc7Christian Maeder , InclComorphism
7221c71b38c871ce66eee4537cb681d468308dfbChristian Maeder , inclusion_logic
ac19f8695aa1b2d2d1cd1319da2530edd8f46a96Christian Maeder , inclusion_source_sublogic
8b9fda012e5ee53b7b2320c0638896a0ff6e99f3Christian Maeder , inclusion_target_sublogic
e1839fb37a3a2ccd457464cb0dcc5efd466dbe22Christian Maeder , mkInclComorphism
4ef2a978e66e2246ff0b7f00c77deb7aabb28b8eChristian Maeder , mkIdComorphism
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian Maeder , Comorphism (..)
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder , targetSublogic
967e5f3c25249c779575864692935627004d3f9eChristian Maeder , map_sign
ad187062b0009820118c1b773a232e29b879a2faChristian Maeder , wrapMapTheory
ad270004874ce1d0697fb30d7309f180553bb315Christian Maeder , mkTheoryMapping
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder , AnyComorphism (..)
717686b54b9650402e2ebfbaadf433eab8ba5171Christian Maeder , idComorphism
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder , isIdComorphism
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder , isModelTransportable
967e5f3c25249c779575864692935627004d3f9eChristian Maeder , hasModelExpansion
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian Maeder , isWeaklyAmalgamable
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian Maeder , compComorphism
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian Maeder ) where
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian Maeder
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian Maederimport Logic.Logic
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian Maederimport Logic.Coerce
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian Maeder
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian Maederimport Common.AS_Annotation
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maederimport Common.Doc
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maederimport Common.DocUtils
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maederimport Common.Id
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maederimport Common.LibName
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maederimport Common.ProofUtils
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maederimport Common.Result
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maederimport Data.Maybe
67d92da5e9610aabad39055a16031154b4dc3748Christian Maederimport qualified Data.Set as Set
67d92da5e9610aabad39055a16031154b4dc3748Christian Maederimport Data.Typeable
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder
67d92da5e9610aabad39055a16031154b4dc3748Christian Maederclass (Language cid,
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder Logic lid1 sublogics1
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder basic_spec1 sentence1 symb_items1 symb_map_items1
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder sign1 morphism1 symbol1 raw_symbol1 proof_tree1,
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder Logic lid2 sublogics2
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder basic_spec2 sentence2 symb_items2 symb_map_items2
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder sign2 morphism2 symbol2 raw_symbol2 proof_tree2) =>
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder Comorphism cid
7a879b08ae0ca30006f9be887a73212b07f10204Christian Maeder lid1 sublogics1 basic_spec1 sentence1 symb_items1 symb_map_items1
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder sign1 morphism1 symbol1 raw_symbol1 proof_tree1
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder lid2 sublogics2 basic_spec2 sentence2 symb_items2 symb_map_items2
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder sign2 morphism2 symbol2 raw_symbol2 proof_tree2
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder | cid -> lid1 sublogics1 basic_spec1 sentence1 symb_items1 symb_map_items1
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder sign1 morphism1 symbol1 raw_symbol1 proof_tree1
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder lid2 sublogics2 basic_spec2 sentence2 symb_items2 symb_map_items2
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder sign2 morphism2 symbol2 raw_symbol2 proof_tree2
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder where
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder {- source and target logic and sublogic
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder the source sublogic is the maximal one for which the comorphism works -}
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder sourceLogic :: cid -> lid1
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder sourceSublogic :: cid -> sublogics1
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder sourceSublogic cid = top_sublogic $ sourceLogic cid
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder minSourceTheory :: cid -> Maybe (LibName, String)
7a879b08ae0ca30006f9be887a73212b07f10204Christian Maeder minSourceTheory _ = Nothing
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder targetLogic :: cid -> lid2
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder {- finer information of target sublogics corresponding to source sublogics
b66eb6038bfbcd2fe520d87c151bb4f1f510e985Christian Maeder this function must be partial because mapTheory is partial -}
a89389521ddf76109168a0b339031575aafbd512Christian Maeder mapSublogic :: cid -> sublogics1 -> Maybe sublogics2
a89389521ddf76109168a0b339031575aafbd512Christian Maeder mapSublogic cid _ = Just $ top_sublogic $ targetLogic cid
a89389521ddf76109168a0b339031575aafbd512Christian Maeder {- the translation functions are partial
a89389521ddf76109168a0b339031575aafbd512Christian Maeder because the target may be a sublanguage
a89389521ddf76109168a0b339031575aafbd512Christian Maeder map_basic_spec :: cid -> basic_spec1 -> Result basic_spec2
a89389521ddf76109168a0b339031575aafbd512Christian Maeder cover theoroidal comorphisms as well -}
a89389521ddf76109168a0b339031575aafbd512Christian Maeder map_theory :: cid -> (sign1, [Named sentence1])
a89389521ddf76109168a0b339031575aafbd512Christian Maeder -> Result (sign2, [Named sentence2])
a89389521ddf76109168a0b339031575aafbd512Christian Maeder map_morphism :: cid -> morphism1 -> Result morphism2
a89389521ddf76109168a0b339031575aafbd512Christian Maeder map_morphism = mapDefaultMorphism
a89389521ddf76109168a0b339031575aafbd512Christian Maeder map_sentence :: cid -> sign1 -> sentence1 -> Result sentence2
a89389521ddf76109168a0b339031575aafbd512Christian Maeder {- also covers semi-comorphisms
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder with no sentence translation
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder - but these are spans! -}
a89389521ddf76109168a0b339031575aafbd512Christian Maeder map_sentence = failMapSentence
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder map_symbol :: cid -> sign1 -> symbol1 -> Set.Set symbol2
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder map_symbol = errMapSymbol
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder extractModel :: cid -> sign1 -> proof_tree2
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder -> Result (sign1, [Named sentence1])
e1839fb37a3a2ccd457464cb0dcc5efd466dbe22Christian Maeder extractModel cid _ _ = fail
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder $ "extractModel not implemented for comorphism "
b66eb6038bfbcd2fe520d87c151bb4f1f510e985Christian Maeder ++ language_name cid
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder -- properties of comorphisms
5e26bfc8d7b18cf3a3fa7b919b4450fb669f37a5Christian Maeder is_model_transportable :: cid -> Bool
588c0c022a0f4e129a89c3bc569daf6a835e182dChristian Maeder {- a comorphism (\phi, \alpha, \beta) is model-transportable
588c0c022a0f4e129a89c3bc569daf6a835e182dChristian Maeder if for any signature \Sigma,
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder any \Sigma-model M and any \phi(\Sigma)-model N
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder for any isomorphism h : \beta_\Sigma(N) -> M
67086e0fe40a985c5e8a3cf50e611f43234580c2Christian Maeder there exists an isomorphism h': N -> M' such that \beta_\Sigma(h') = h -}
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder is_model_transportable _ = False
5e26bfc8d7b18cf3a3fa7b919b4450fb669f37a5Christian Maeder has_model_expansion :: cid -> Bool
e7ce154edb906685b3fa7f6c0a764e18a4658068Christian Maeder has_model_expansion _ = False
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder is_weakly_amalgamable :: cid -> Bool
67086e0fe40a985c5e8a3cf50e611f43234580c2Christian Maeder is_weakly_amalgamable _ = False
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder constituents :: cid -> [String]
67086e0fe40a985c5e8a3cf50e611f43234580c2Christian Maeder constituents cid = [language_name cid]
67086e0fe40a985c5e8a3cf50e611f43234580c2Christian Maeder isInclusionComorphism :: cid -> Bool
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder isInclusionComorphism _ = False
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder
67086e0fe40a985c5e8a3cf50e611f43234580c2Christian MaedertargetSublogic :: Comorphism cid
67086e0fe40a985c5e8a3cf50e611f43234580c2Christian Maeder lid1 sublogics1 basic_spec1 sentence1 symb_items1 symb_map_items1
588c0c022a0f4e129a89c3bc569daf6a835e182dChristian Maeder sign1 morphism1 symbol1 raw_symbol1 proof_tree1
717686b54b9650402e2ebfbaadf433eab8ba5171Christian Maeder lid2 sublogics2 basic_spec2 sentence2 symb_items2 symb_map_items2
717686b54b9650402e2ebfbaadf433eab8ba5171Christian Maeder sign2 morphism2 symbol2 raw_symbol2 proof_tree2
d48085f765fca838c1d972d2123601997174583dChristian Maeder => cid -> sublogics2
d48085f765fca838c1d972d2123601997174583dChristian MaedertargetSublogic cid = fromMaybe (top_sublogic $ targetLogic cid)
717686b54b9650402e2ebfbaadf433eab8ba5171Christian Maeder $ mapSublogic cid $ sourceSublogic cid
d48085f765fca838c1d972d2123601997174583dChristian Maeder
d48085f765fca838c1d972d2123601997174583dChristian Maeder-- | this function is base on 'map_theory' using no sentences as input
588c0c022a0f4e129a89c3bc569daf6a835e182dChristian Maedermap_sign :: Comorphism cid
d48085f765fca838c1d972d2123601997174583dChristian Maeder lid1 sublogics1 basic_spec1 sentence1 symb_items1 symb_map_items1
717686b54b9650402e2ebfbaadf433eab8ba5171Christian Maeder sign1 morphism1 symbol1 raw_symbol1 proof_tree1
717686b54b9650402e2ebfbaadf433eab8ba5171Christian Maeder lid2 sublogics2 basic_spec2 sentence2 symb_items2 symb_map_items2
e7ce154edb906685b3fa7f6c0a764e18a4658068Christian Maeder sign2 morphism2 symbol2 raw_symbol2 proof_tree2
b66eb6038bfbcd2fe520d87c151bb4f1f510e985Christian Maeder => cid -> sign1 -> Result (sign2, [Named sentence2])
b66eb6038bfbcd2fe520d87c151bb4f1f510e985Christian Maedermap_sign cid sign = wrapMapTheory cid (sign, [])
b66eb6038bfbcd2fe520d87c151bb4f1f510e985Christian Maeder
1a75698c909ad515d59c76e65bd783f015c21c4dChristian MaedermapDefaultMorphism :: Comorphism cid
b66eb6038bfbcd2fe520d87c151bb4f1f510e985Christian Maeder lid1 sublogics1 basic_spec1 sentence1 symb_items1 symb_map_items1
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder sign1 morphism1 symbol1 raw_symbol1 proof_tree1
b66eb6038bfbcd2fe520d87c151bb4f1f510e985Christian Maeder lid2 sublogics2 basic_spec2 sentence2 symb_items2 symb_map_items2
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder sign2 morphism2 symbol2 raw_symbol2 proof_tree2
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder => cid -> morphism1 -> Result morphism2
b66eb6038bfbcd2fe520d87c151bb4f1f510e985Christian MaedermapDefaultMorphism cid mor = do
b66eb6038bfbcd2fe520d87c151bb4f1f510e985Christian Maeder (sig1, _) <- map_sign cid $ dom mor
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder (sig2, _) <- map_sign cid $ cod mor
b66eb6038bfbcd2fe520d87c151bb4f1f510e985Christian Maeder inclusion (targetLogic cid) sig1 sig2
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder
1a75698c909ad515d59c76e65bd783f015c21c4dChristian MaederfailMapSentence :: Comorphism cid
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder lid1 sublogics1 basic_spec1 sentence1 symb_items1 symb_map_items1
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder sign1 morphism1 symbol1 raw_symbol1 proof_tree1
f11f713bebd8e1e623a0a4361065df256033de47Christian Maeder lid2 sublogics2 basic_spec2 sentence2 symb_items2 symb_map_items2
0a8ea95bcf0e3f84fed0b725c049ec2a956a4a28Christian Maeder sign2 morphism2 symbol2 raw_symbol2 proof_tree2
83814002b4922114cbe7e9ba728472a0bf44aac5Christian Maeder => cid -> sign1 -> sentence1 -> Result sentence2
a578ec30cded5e396a7ce9a3b469e8cd3a88246aChristian MaederfailMapSentence cid _ _ =
83814002b4922114cbe7e9ba728472a0bf44aac5Christian Maeder fail $ "Unsupported sentence translation " ++ show cid
967e5f3c25249c779575864692935627004d3f9eChristian Maeder
83814002b4922114cbe7e9ba728472a0bf44aac5Christian MaedererrMapSymbol :: Comorphism cid
dedabc954aa15f6ad0764472a9434dc6dafe3db2Christian Maeder lid1 sublogics1 basic_spec1 sentence1 symb_items1 symb_map_items1
e1839fb37a3a2ccd457464cb0dcc5efd466dbe22Christian Maeder sign1 morphism1 symbol1 raw_symbol1 proof_tree1
588c0c022a0f4e129a89c3bc569daf6a835e182dChristian Maeder lid2 sublogics2 basic_spec2 sentence2 symb_items2 symb_map_items2
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder sign2 morphism2 symbol2 raw_symbol2 proof_tree2
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder => cid -> sign1 -> symbol1 -> Set.Set symbol2
e1839fb37a3a2ccd457464cb0dcc5efd466dbe22Christian MaedererrMapSymbol cid _ _ = error $ "no symbol mapping for " ++ show cid
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder
588c0c022a0f4e129a89c3bc569daf6a835e182dChristian Maeder-- | use this function instead of 'map_theory'
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian MaederwrapMapTheory :: Comorphism cid
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian Maeder lid1 sublogics1 basic_spec1 sentence1 symb_items1 symb_map_items1
2e9985cd67e4f2414becb670ef33b8f16513e41dChristian Maeder sign1 morphism1 symbol1 raw_symbol1 proof_tree1
f2ee9fc53048ea92bad79e3f5d292d83efd7f8beMihai Codescu lid2 sublogics2 basic_spec2 sentence2 symb_items2 symb_map_items2
f2ee9fc53048ea92bad79e3f5d292d83efd7f8beMihai Codescu sign2 morphism2 symbol2 raw_symbol2 proof_tree2
81d182b21020b815887e9057959228546cf61b6bChristian Maeder => cid -> (sign1, [Named sentence1])
242397ba0f1cc490e892130bf0df239deeecf5daChristian Maeder -> Result (sign2, [Named sentence2])
2e9985cd67e4f2414becb670ef33b8f16513e41dChristian MaederwrapMapTheory cid (sign, sens) =
242397ba0f1cc490e892130bf0df239deeecf5daChristian Maeder let res = map_theory cid (sign, sens)
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian Maeder lid1 = sourceLogic cid
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian Maeder thDoc = show (vcat $ pretty sign : map (print_named lid1) sens)
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian Maeder in
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian Maeder if isIdComorphism $ Comorphism cid then res else case sourceSublogic cid of
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian Maeder sub -> case minSublogic sign of
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian Maeder sigLog -> case foldl join sigLog
2e9985cd67e4f2414becb670ef33b8f16513e41dChristian Maeder $ map (minSublogic . sentence) sens of
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder senLog ->
588c0c022a0f4e129a89c3bc569daf6a835e182dChristian Maeder if isSubElem senLog sub
2e9985cd67e4f2414becb670ef33b8f16513e41dChristian Maeder then res
ad187062b0009820118c1b773a232e29b879a2faChristian Maeder else Result
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder [ Diag Hint thDoc nullRange
ad187062b0009820118c1b773a232e29b879a2faChristian Maeder , Diag Error
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian Maeder ("for '" ++ language_name cid ++
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder "' expected sublogic '" ++
dedabc954aa15f6ad0764472a9434dc6dafe3db2Christian Maeder sublogicName sub ++
bfa9e03532243ceb487f0384d0f6a447f1ce7670Till Mossakowski "'\n but found sublogic '" ++
7221c71b38c871ce66eee4537cb681d468308dfbChristian Maeder sublogicName senLog ++
7221c71b38c871ce66eee4537cb681d468308dfbChristian Maeder "' with signature sublogic '" ++
7221c71b38c871ce66eee4537cb681d468308dfbChristian Maeder sublogicName sigLog ++ "'") nullRange] Nothing
588c0c022a0f4e129a89c3bc569daf6a835e182dChristian Maeder
842eedc62639561781b6c33533d1949693ef6cc5Christian MaedermkTheoryMapping :: Monad m => (sign1 -> m (sign2, [Named sentence2]))
42c01284bba8d7c8d995c8dfb96ace57d28ed1bcTill Mossakowski -> (sign1 -> sentence1 -> m sentence2)
842eedc62639561781b6c33533d1949693ef6cc5Christian Maeder -> (sign1, [Named sentence1])
842eedc62639561781b6c33533d1949693ef6cc5Christian Maeder -> m (sign2, [Named sentence2])
588c0c022a0f4e129a89c3bc569daf6a835e182dChristian MaedermkTheoryMapping mapSig mapSen (sign, sens) = do
588c0c022a0f4e129a89c3bc569daf6a835e182dChristian Maeder (sign', sens') <- mapSig sign
588c0c022a0f4e129a89c3bc569daf6a835e182dChristian Maeder sens'' <- mapM (mapNamedM $ mapSen sign) sens
842eedc62639561781b6c33533d1949693ef6cc5Christian Maeder return (sign', nameAndDisambiguate $ sens' ++ sens'')
bfa9e03532243ceb487f0384d0f6a447f1ce7670Till Mossakowski
967e5f3c25249c779575864692935627004d3f9eChristian Maederdata InclComorphism lid sublogics = InclComorphism
967e5f3c25249c779575864692935627004d3f9eChristian Maeder { inclusion_logic :: lid
f2ee9fc53048ea92bad79e3f5d292d83efd7f8beMihai Codescu , inclusion_source_sublogic :: sublogics
967e5f3c25249c779575864692935627004d3f9eChristian Maeder , inclusion_target_sublogic :: sublogics }
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder deriving Show
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder-- | construction of an identity comorphism
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian MaedermkIdComorphism :: (Logic lid sublogics
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder basic_spec sentence symb_items symb_map_items
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder sign morphism symbol raw_symbol proof_tree) =>
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder lid -> sublogics -> InclComorphism lid sublogics
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian MaedermkIdComorphism lid sub = InclComorphism
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder { inclusion_logic = lid
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder , inclusion_source_sublogic = sub
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder , inclusion_target_sublogic = sub }
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder
967e5f3c25249c779575864692935627004d3f9eChristian Maeder-- | construction of an inclusion comorphism
967e5f3c25249c779575864692935627004d3f9eChristian MaedermkInclComorphism :: (Logic lid sublogics
ad187062b0009820118c1b773a232e29b879a2faChristian Maeder basic_spec sentence symb_items symb_map_items
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder sign morphism symbol raw_symbol proof_tree,
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder Monad m) =>
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder lid -> sublogics -> sublogics
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder -> m (InclComorphism lid sublogics)
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian MaedermkInclComorphism lid srcSub trgSub =
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder if isSubElem srcSub trgSub
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder then return InclComorphism
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder { inclusion_logic = lid
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder , inclusion_source_sublogic = srcSub
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder , inclusion_target_sublogic = trgSub }
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder else fail ("mkInclComorphism: first sublogic must be a " ++
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder "subElem of the second sublogic")
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maederinstance (Language lid, Eq sublogics, Show sublogics, SublogicName sublogics)
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder => Language (InclComorphism lid sublogics) where
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder language_name (InclComorphism lid sub_src sub_trg) =
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder let sblName = sublogicName sub_src
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder lname = language_name lid
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder in if sub_src == sub_trg
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder then "id_" ++ lname ++
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder if null sblName then "" else '.' : sblName
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder else "incl_" ++ lname ++ ':'
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder : sblName ++ "->" ++ sublogicName sub_trg
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maederinstance Logic lid sublogics
ad187062b0009820118c1b773a232e29b879a2faChristian Maeder basic_spec sentence symb_items symb_map_items
ad187062b0009820118c1b773a232e29b879a2faChristian Maeder sign morphism symbol raw_symbol proof_tree =>
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder Comorphism (InclComorphism lid sublogics)
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder lid sublogics
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder basic_spec sentence symb_items symb_map_items
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder sign morphism symbol raw_symbol proof_tree
ad187062b0009820118c1b773a232e29b879a2faChristian Maeder lid sublogics
ad187062b0009820118c1b773a232e29b879a2faChristian Maeder basic_spec sentence symb_items symb_map_items
ad187062b0009820118c1b773a232e29b879a2faChristian Maeder sign morphism symbol raw_symbol proof_tree
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder where
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder sourceLogic = inclusion_logic
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder targetLogic = inclusion_logic
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder sourceSublogic = inclusion_source_sublogic
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder mapSublogic cid subl =
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder if isSubElem subl $ inclusion_source_sublogic cid
9659c509ce5e78adc51d7b02a76274eddcba9338Christian Maeder then Just subl
9659c509ce5e78adc51d7b02a76274eddcba9338Christian Maeder else Nothing
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder map_theory _ = return
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder map_morphism _ = return
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder map_sentence _ _ = return
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder map_symbol _ _ = Set.singleton
9659c509ce5e78adc51d7b02a76274eddcba9338Christian Maeder constituents cid =
9659c509ce5e78adc51d7b02a76274eddcba9338Christian Maeder if inclusion_source_sublogic cid
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian Maeder == inclusion_target_sublogic cid
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder then []
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder else [language_name cid]
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder is_model_transportable _ = True
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder has_model_expansion _ = True
83814002b4922114cbe7e9ba728472a0bf44aac5Christian Maeder is_weakly_amalgamable _ = True
83814002b4922114cbe7e9ba728472a0bf44aac5Christian Maeder isInclusionComorphism _ = True
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder
97ee7048e63953c5617342ce38c30cbcb35cc0beChristian Maederdata CompComorphism cid1 cid2 = CompComorphism cid1 cid2 deriving Show
97ee7048e63953c5617342ce38c30cbcb35cc0beChristian Maeder
b66eb6038bfbcd2fe520d87c151bb4f1f510e985Christian Maederinstance (Language cid1, Language cid2)
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder => Language (CompComorphism cid1 cid2) where
b66eb6038bfbcd2fe520d87c151bb4f1f510e985Christian Maeder language_name (CompComorphism cid1 cid2) =
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder language_name cid1 ++ ";" ++ language_name cid2
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maederinstance (Comorphism cid1
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder lid1 sublogics1 basic_spec1 sentence1 symb_items1 symb_map_items1
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder sign1 morphism1 symbol1 raw_symbol1 proof_tree1
588c0c022a0f4e129a89c3bc569daf6a835e182dChristian Maeder lid2 sublogics2 basic_spec2 sentence2 symb_items2 symb_map_items2
b66eb6038bfbcd2fe520d87c151bb4f1f510e985Christian Maeder sign2 morphism2 symbol2 raw_symbol2 proof_tree2,
2dfc7b04f2db681992ca04175f2beb0f127c9844Christian Maeder Comorphism cid2
2dfc7b04f2db681992ca04175f2beb0f127c9844Christian Maeder lid4 sublogics4 basic_spec4 sentence4 symb_items4 symb_map_items4
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder sign4 morphism4 symbol4 raw_symbol4 proof_tree4
dedabc954aa15f6ad0764472a9434dc6dafe3db2Christian Maeder lid3 sublogics3 basic_spec3 sentence3 symb_items3 symb_map_items3
ad187062b0009820118c1b773a232e29b879a2faChristian Maeder sign3 morphism3 symbol3 raw_symbol3 proof_tree3)
ad187062b0009820118c1b773a232e29b879a2faChristian Maeder => Comorphism (CompComorphism cid1 cid2)
588c0c022a0f4e129a89c3bc569daf6a835e182dChristian Maeder lid1 sublogics1 basic_spec1 sentence1 symb_items1 symb_map_items1
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder sign1 morphism1 symbol1 raw_symbol1 proof_tree1
588c0c022a0f4e129a89c3bc569daf6a835e182dChristian Maeder lid3 sublogics3 basic_spec3 sentence3 symb_items3 symb_map_items3
ad187062b0009820118c1b773a232e29b879a2faChristian Maeder sign3 morphism3 symbol3 raw_symbol3 proof_tree3 where
07b72edb610ee53b4832d132e96b0a3d8423f8ebChristian Maeder sourceLogic (CompComorphism cid1 _) =
sourceLogic cid1
targetLogic (CompComorphism _ cid2) =
targetLogic cid2
sourceSublogic (CompComorphism cid1 _) =
sourceSublogic cid1
mapSublogic (CompComorphism cid1 cid2) sl =
mapSublogic cid1 sl >>=
mapSublogic cid2 .
forceCoerceSublogic (targetLogic cid1) (sourceLogic cid2)
map_sentence (CompComorphism cid1 cid2) si1 se1 =
do (si2, _) <- map_sign cid1 si1
se2 <- map_sentence cid1 si1 se1
(si2', se2') <- coerceBasicTheory
(targetLogic cid1) (sourceLogic cid2)
"Mapping sentence along comorphism" (si2, [makeNamed "" se2])
case se2' of
[x] -> map_sentence cid2 si2' $ sentence x
_ -> error "CompComorphism.map_sentence"
map_theory (CompComorphism cid1 cid2) ti1 =
do ti2 <- map_theory cid1 ti1
ti2' <- coerceBasicTheory (targetLogic cid1) (sourceLogic cid2)
"Mapping theory along comorphism" ti2
wrapMapTheory cid2 ti2'
map_morphism (CompComorphism cid1 cid2) m1 =
do m2 <- map_morphism cid1 m1
m3 <- coerceMorphism (targetLogic cid1) (sourceLogic cid2)
"Mapping signature morphism along comorphism" m2
map_morphism cid2 m3
map_symbol (CompComorphism cid1 cid2) sig1 = let
th = map_sign cid1 sig1 in
case maybeResult th of
Nothing -> error "failed translating signature"
Just (sig2', _) -> let
th2 = coerceBasicTheory
(targetLogic cid1) (sourceLogic cid2)
"Mapping symbol along comorphism" (sig2', [])
in case maybeResult th2 of
Nothing -> error "failed coercing"
Just (sig2, _) ->
\ s1 ->
let mycast = coerceSymbol (targetLogic cid1) (sourceLogic cid2)
in Set.unions
(map (map_symbol cid2 sig2 . mycast)
(Set.toList (map_symbol cid1 sig1 s1)))
extractModel (CompComorphism cid1 cid2) sign pt3 =
let lid1 = sourceLogic cid1
lid3 = sourceLogic cid2
in if language_name lid1 == language_name lid3 then do
bTh1 <- map_sign cid1 sign
(sign1, _) <-
coerceBasicTheory (targetLogic cid1) lid3 "extractModel1" bTh1
bTh2 <- extractModel cid2 sign1 pt3
coerceBasicTheory lid3 lid1 "extractModel2" bTh2
else fail $ "extractModel not implemented for comorphism composition with "
++ language_name cid1
constituents (CompComorphism cid1 cid2) =
constituents cid1 ++ constituents cid2
is_model_transportable (CompComorphism cid1 cid2) =
is_model_transportable cid1 && is_model_transportable cid2
has_model_expansion (CompComorphism cid1 cid2) =
has_model_expansion cid1 && has_model_expansion cid2
is_weakly_amalgamable (CompComorphism cid1 cid2) =
is_weakly_amalgamable cid1 && is_weakly_amalgamable cid2
isInclusionComorphism (CompComorphism cid1 cid2) =
isInclusionComorphism cid1 && isInclusionComorphism cid2
-- * Comorphisms and existential types for the logic graph
-- | Existential type for comorphisms
data AnyComorphism = forall cid lid1 sublogics1
basic_spec1 sentence1 symb_items1 symb_map_items1
sign1 morphism1 symbol1 raw_symbol1 proof_tree1
lid2 sublogics2
basic_spec2 sentence2 symb_items2 symb_map_items2
sign2 morphism2 symbol2 raw_symbol2 proof_tree2 .
Comorphism cid
lid1 sublogics1 basic_spec1 sentence1
symb_items1 symb_map_items1
sign1 morphism1 symbol1 raw_symbol1 proof_tree1
lid2 sublogics2 basic_spec2 sentence2
symb_items2 symb_map_items2
sign2 morphism2 symbol2 raw_symbol2 proof_tree2 =>
Comorphism cid deriving Typeable -- used for GTheory
instance Eq AnyComorphism where
a == b = compare a b == EQ
instance Ord AnyComorphism where
compare (Comorphism cid1) (Comorphism cid2) = compare
(language_name cid1, constituents cid1)
(language_name cid2, constituents cid2)
-- maybe needs to be refined, using comorphism translations?
instance Show AnyComorphism where
show (Comorphism cid) = language_name cid
++ " : " ++ language_name (sourceLogic cid)
++ " -> " ++ language_name (targetLogic cid)
instance Pretty AnyComorphism where
pretty = text . show
-- | compute the identity comorphism for a logic
idComorphism :: AnyLogic -> AnyComorphism
idComorphism (Logic lid) = Comorphism (mkIdComorphism lid (top_sublogic lid))
-- | Test whether a comporphism is the identity
isIdComorphism :: AnyComorphism -> Bool
isIdComorphism (Comorphism cid) = null $ constituents cid
-- * Properties of comorphisms
-- | Test whether a comorphism is model-transportable
isModelTransportable :: AnyComorphism -> Bool
isModelTransportable (Comorphism cid) = is_model_transportable cid
-- | Test whether a comorphism has model expansion
hasModelExpansion :: AnyComorphism -> Bool
hasModelExpansion (Comorphism cid) = has_model_expansion cid
-- | Test whether a comorphism is weakly amalgamable
isWeaklyAmalgamable :: AnyComorphism -> Bool
isWeaklyAmalgamable (Comorphism cid) = is_weakly_amalgamable cid
-- | Compose comorphisms
compComorphism :: Monad m => AnyComorphism -> AnyComorphism -> m AnyComorphism
compComorphism (Comorphism cid1) (Comorphism cid2) =
let l1 = targetLogic cid1
l2 = sourceLogic cid2
msg = "ogic mismatch in composition of " ++ language_name cid1
++ " and " ++ language_name cid2
in
if language_name l1 == language_name l2 then
if isSubElem (forceCoerceSublogic l1 l2 $ targetSublogic cid1)
$ sourceSublogic cid2
then return $ Comorphism (CompComorphism cid1 cid2)
else fail $ "Subl" ++ msg ++ " (Expected sublogic "
++ sublogicName (sourceSublogic cid2)
++ " but found sublogic "
++ sublogicName (targetSublogic cid1) ++ ")"
else fail $ 'L' : msg ++ " (Expected logic "
++ language_name l2
++ " but found logic "
++ language_name l1 ++ ")"