Comorphism.hs revision 2b565fe5cfb9f99857fd25b52304758d8544e266
c797f343be2f3619bb1f5569753166ec49d27bdbChristian Maeder{-# OPTIONS -fglasgow-exts -fallow-undecidable-instances #-}
81d182b21020b815887e9057959228546cf61b6bChristian MaederModule : $Header$
10397bcc134edbcfbe3ae2c7ea4c6080036aae22Christian MaederDescription : central interface (type class) for logic translations (comorphisms) in Hets
97018cf5fa25b494adffd7e9b4e87320dae6bf47Christian MaederCopyright : (c) Till Mossakowski, Uni Bremen 2002-2006
c797f343be2f3619bb1f5569753166ec49d27bdbChristian MaederLicense : similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt
3f69b6948966979163bdfe8331c38833d5d90ecdChristian MaederMaintainer : till@tzi.de
c797f343be2f3619bb1f5569753166ec49d27bdbChristian MaederStability : provisional
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian MaederPortability : non-portable (via Logic)
f3a94a197960e548ecd6520bb768cb0d547457bbChristian MaederCentral interface (type class) for logic translations (comorphisms) in Hets
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder These are just collections of
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder functions between (some of) the types of logics.
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder References: see Logic.hs
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maedermodule Logic.Comorphism ( CompComorphism(..)
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder , IdComorphism
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder , InclComorphism
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder , inclusion_logic
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder , inclusion_source_sublogic
10397bcc134edbcfbe3ae2c7ea4c6080036aae22Christian Maeder , inclusion_target_sublogic
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder , mkInclComorphism
04dada28736b4a237745e92063d8bdd49a362debChristian Maeder , mkIdComorphism
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder , Comorphism(..)
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder , targetSublogic
ad270004874ce1d0697fb30d7309f180553bb315Christian Maeder , mapDefaultMorphism
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder -- , failMapSentence
89054b2b95a3f92e78324dc852f3d34704e2ca49Christian Maeder -- , errMapSymbol
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder , wrapMapTheory
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder , simpleTheoryMapping
8b9fda012e5ee53b7b2320c0638896a0ff6e99f3Christian Maeder , mkTheoryMapping) where
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maederimport qualified Data.Set as Set
42c01284bba8d7c8d995c8dfb96ace57d28ed1bcTill Mossakowskiclass (Language cid,
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder Logic lid1 sublogics1
b190f5c7cf3ddda73724efe5ce82b9585ed76be1Christian Maeder basic_spec1 sentence1 symb_items1 symb_map_items1
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder sign1 morphism1 symbol1 raw_symbol1 proof_tree1,
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder Logic lid2 sublogics2
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder basic_spec2 sentence2 symb_items2 symb_map_items2
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder sign2 morphism2 symbol2 raw_symbol2 proof_tree2) =>
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder Comorphism cid
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder lid1 sublogics1 basic_spec1 sentence1 symb_items1 symb_map_items1
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder sign1 morphism1 symbol1 raw_symbol1 proof_tree1
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder lid2 sublogics2 basic_spec2 sentence2 symb_items2 symb_map_items2
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder sign2 morphism2 symbol2 raw_symbol2 proof_tree2
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder | cid -> lid1 sublogics1 basic_spec1 sentence1 symb_items1 symb_map_items1
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder sign1 morphism1 symbol1 raw_symbol1 proof_tree1
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder lid2 sublogics2 basic_spec2 sentence2 symb_items2 symb_map_items2
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder sign2 morphism2 symbol2 raw_symbol2 proof_tree2
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder -- source and target logic and sublogic
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder -- the source sublogic is the maximal one for which the comorphism works
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder sourceLogic :: cid -> lid1
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder sourceSublogic :: cid -> sublogics1
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder targetLogic :: cid -> lid2
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder -- finer information of target sublogics corresponding to source sublogics
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder -- this function must be partial because mapTheory is partial
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder mapSublogic :: cid -> sublogics1 -> Maybe sublogics2
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder -- the translation functions are partial
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder -- because the target may be a sublanguage
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder -- map_basic_spec :: cid -> basic_spec1 -> Result basic_spec2
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder -- cover theoroidal comorphisms as well
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder map_theory :: cid -> (sign1,[Named sentence1])
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder -> Result (sign2,[Named sentence2])
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder map_morphism :: cid -> morphism1 -> Result morphism2
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder map_sentence :: cid -> sign1 -> sentence1 -> Result sentence2
f4741f6b7da52b5417899c8fcbe4349b920b006eChristian Maeder -- also covers semi-comorphisms
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder -- with no sentence translation
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder -- - but these are spans!
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder map_symbol :: cid -> symbol1 -> Set.Set symbol2
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder --properties of comorphisms
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder is_model_transportable :: cid -> Bool
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder -- a comorphism (\phi, \alpha, \beta) is model-transportable
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder -- if for any signature \Sigma, any \Sigma-model M and any \phi(\Sigma)-model N
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder -- for any isomorphism h : \beta_\Sigma(N) -> M
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder -- there exists an isomorphism h': N -> M' such that \beta_\Sigma(h') = h
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder has_model_expansion :: cid -> Bool
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder is_weakly_amalgamable :: cid -> Bool
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder --default implementation for properties
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder is_model_transportable _ = False
27912d626bf179b82fcb337077e5cd9653bb71cfChristian Maeder has_model_expansion _ = False
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder is_weakly_amalgamable _ = False
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder constituents :: cid -> [String]
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder -- default implementation
f4741f6b7da52b5417899c8fcbe4349b920b006eChristian Maeder constituents cid = [language_name cid]
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder map_sentence = failMapSentence
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder map_symbol = errMapSymbol
27912d626bf179b82fcb337077e5cd9653bb71cfChristian MaedertargetSublogic :: Comorphism cid
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder lid1 sublogics1 basic_spec1 sentence1 symb_items1 symb_map_items1
04dada28736b4a237745e92063d8bdd49a362debChristian Maeder sign1 morphism1 symbol1 raw_symbol1 proof_tree1
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder lid2 sublogics2 basic_spec2 sentence2 symb_items2 symb_map_items2
15bb922b665fcd44c6230a1202785d0c7890e90cChristian Maeder sign2 morphism2 symbol2 raw_symbol2 proof_tree2
42c01284bba8d7c8d995c8dfb96ace57d28ed1bcTill Mossakowski => cid -> sublogics2
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian MaedertargetSublogic cid = maybe (error ("Logic.Comorphism: " ++
04dada28736b4a237745e92063d8bdd49a362debChristian Maeder language_name cid ++
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian Maeder " does not provide a mapping for it's " ++
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder "source sublogic"))
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder id $ mapSublogic cid $ sourceSublogic cid
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder-- | this function is base on 'map_theory' using no sentences as input
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maedermap_sign :: Comorphism cid
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder lid1 sublogics1 basic_spec1 sentence1 symb_items1 symb_map_items1
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder sign1 morphism1 symbol1 raw_symbol1 proof_tree1
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder lid2 sublogics2 basic_spec2 sentence2 symb_items2 symb_map_items2
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder sign2 morphism2 symbol2 raw_symbol2 proof_tree2
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder => cid -> sign1 -> Result (sign2,[Named sentence2])
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maedermap_sign cid sign = wrapMapTheory cid (sign,[])
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian MaedermapDefaultMorphism :: Comorphism cid
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder lid1 sublogics1 basic_spec1 sentence1 symb_items1 symb_map_items1
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder sign1 morphism1 symbol1 raw_symbol1 proof_tree1
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder lid2 sublogics2 basic_spec2 sentence2 symb_items2 symb_map_items2
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder sign2 morphism2 symbol2 raw_symbol2 proof_tree2
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder => cid -> morphism1 -> Result morphism2
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian MaedermapDefaultMorphism cid mor = do
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder let src = sourceLogic cid
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder (sig1, _) <- map_sign cid $ dom src mor
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder (sig2, _) <- map_sign cid $ cod src mor
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder inclusion (targetLogic cid) sig1 sig2
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian MaederfailMapSentence :: Comorphism cid
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder lid1 sublogics1 basic_spec1 sentence1 symb_items1 symb_map_items1
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder sign1 morphism1 symbol1 raw_symbol1 proof_tree1
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder lid2 sublogics2 basic_spec2 sentence2 symb_items2 symb_map_items2
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder sign2 morphism2 symbol2 raw_symbol2 proof_tree2
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder => cid -> sign1 -> sentence1 -> Result sentence2
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian MaederfailMapSentence cid _ _ =
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder fail $ "Unsupported sentence translation " ++ show cid
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian MaedererrMapSymbol :: Comorphism cid
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder lid1 sublogics1 basic_spec1 sentence1 symb_items1 symb_map_items1
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder sign1 morphism1 symbol1 raw_symbol1 proof_tree1
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder lid2 sublogics2 basic_spec2 sentence2 symb_items2 symb_map_items2
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder sign2 morphism2 symbol2 raw_symbol2 proof_tree2
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder => cid -> symbol1 -> Set.Set symbol2
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian MaedererrMapSymbol cid _ = error $ "no symbol mapping for " ++ show cid
975642b989852fc24119c59cf40bc1af653608ffChristian Maeder-- | use this function instead of 'map_theory'
975642b989852fc24119c59cf40bc1af653608ffChristian MaederwrapMapTheory :: Comorphism cid
975642b989852fc24119c59cf40bc1af653608ffChristian Maeder lid1 sublogics1 basic_spec1 sentence1 symb_items1 symb_map_items1
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder sign1 morphism1 symbol1 raw_symbol1 proof_tree1
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder lid2 sublogics2 basic_spec2 sentence2 symb_items2 symb_map_items2
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder sign2 morphism2 symbol2 raw_symbol2 proof_tree2
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder => cid -> (sign1, [Named sentence1])
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder -> Result (sign2, [Named sentence2])
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian MaederwrapMapTheory cid (sign, sens) =
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder case sourceSublogic cid of
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder sub -> case minSublogic sign of
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder sigLog -> case foldl join sigLog
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder $ map (minSublogic . sentence) sens of
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder if isSubElem senLog sub
962d5c684e2b86d1f9c556c096b426e10cc74026Christian Maeder then map_theory cid (sign, sens)
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder else fail $ "for '" ++ language_name cid ++
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder "' expected sublogic '" ++
962d5c684e2b86d1f9c556c096b426e10cc74026Christian Maeder concat (sublogic_names sub) ++
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder "'\n but found sublogic '" ++
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder concat (sublogic_names senLog) ++
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder "' with signature sublogic '" ++
962d5c684e2b86d1f9c556c096b426e10cc74026Christian Maeder concat (sublogic_names sigLog) ++ "'\n" ++
962d5c684e2b86d1f9c556c096b426e10cc74026Christian Maeder show (vcat $ pretty sign : map
962d5c684e2b86d1f9c556c096b426e10cc74026Christian Maeder (print_named $ sourceLogic cid) sens)
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaedersimpleTheoryMapping :: (sign1 -> sign2) -> (sentence1 -> sentence2)
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder -> (sign1, [Named sentence1])
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder -> (sign2, [Named sentence2])
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian MaedersimpleTheoryMapping mapSig mapSen (sign,sens) =
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder (mapSig sign, map (mapNamed mapSen) sens)
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian MaedermkTheoryMapping :: (Monad m) => (sign1 -> m (sign2, [Named sentence2]))
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder -> (sign1 -> sentence1 -> m sentence2)
27912d626bf179b82fcb337077e5cd9653bb71cfChristian Maeder -> (sign1, [Named sentence1])
27912d626bf179b82fcb337077e5cd9653bb71cfChristian Maeder -> m (sign2, [Named sentence2])
2ac1742771a267119f1d839054b5e45d0a468085Christian MaedermkTheoryMapping mapSig mapSen (sign,sens) = do
2ac1742771a267119f1d839054b5e45d0a468085Christian Maeder (sign',sens') <- mapSig sign
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder sens'' <- mapM (mapNamedM $ mapSen sign) sens
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maeder return (sign', disambiguateSens Set.empty . nameSens $ sens' ++ sens'')
6cca02cb6a5ae882d887a879f8b7a71941c3715cChristian Maedertype IdComorphism lid sublogics = InclComorphism lid sublogics
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maederdata InclComorphism lid sublogics =
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder InclComorphism { inclusion_logic :: lid
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian Maeder , inclusion_source_sublogic :: sublogics
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder , inclusion_target_sublogic :: sublogics
15bb922b665fcd44c6230a1202785d0c7890e90cChristian Maeder-- | construction of an identity comorphism
e95bbf384f5cbcb7eb23286d5f15dffbd471db17Christian MaedermkIdComorphism :: (Logic lid sublogics
42c01284bba8d7c8d995c8dfb96ace57d28ed1bcTill Mossakowski basic_spec sentence symb_items symb_map_items
map_symbol _ = Set.singleton
_ -> error "CompComorphism.map_sentence"
in Set.unions
(Set.toList (map_symbol cid1 s1)))