Comorphism.hs revision 8a77240a809197c92c0736c431b4b88947a7bac1
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, DeriveDataTypeable
8267b99c0d7a187abe6f87ad50530dc08f5d1cdcAndy Gimblett , FlexibleInstances, UndecidableInstances, ExistentialQuantification #-}
020cdb5dad6b871aba61136a0e1567c00426de87Andy GimblettModule : $Header$
020cdb5dad6b871aba61136a0e1567c00426de87Andy GimblettDescription : interface and class for logic translations
020cdb5dad6b871aba61136a0e1567c00426de87Andy GimblettCopyright : (c) Till Mossakowski, Uni Bremen 2002-2006
020cdb5dad6b871aba61136a0e1567c00426de87Andy GimblettLicense : similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt
020cdb5dad6b871aba61136a0e1567c00426de87Andy GimblettMaintainer : till@informatik.uni-bremen.de
020cdb5dad6b871aba61136a0e1567c00426de87Andy GimblettStability : provisional
020cdb5dad6b871aba61136a0e1567c00426de87Andy GimblettPortability : non-portable (via Logic)
020cdb5dad6b871aba61136a0e1567c00426de87Andy GimblettCentral interface (type class) for logic translations (comorphisms) in Hets
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett These are just collections of
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett functions between (some of) the types of logics.
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett References: see Logic.hs
f909337bf7012aca169c0b56b89efbd4a310f8daAndy Gimblett ( CompComorphism (..)
f909337bf7012aca169c0b56b89efbd4a310f8daAndy Gimblett , InclComorphism
f909337bf7012aca169c0b56b89efbd4a310f8daAndy Gimblett , inclusion_logic
f909337bf7012aca169c0b56b89efbd4a310f8daAndy Gimblett , inclusion_source_sublogic
f909337bf7012aca169c0b56b89efbd4a310f8daAndy Gimblett , inclusion_target_sublogic
04ceed96d1528b939f2e592d0656290d81d1c045Andy Gimblett , mkInclComorphism
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett , mkIdComorphism
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett , Comorphism (..)
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett , targetSublogic
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett , ext_map_sign
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett , mapDefaultMorphism
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett , wrapMapTheory
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett , simpleTheoryMapping
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett , mkTheoryMapping
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett , AnyComorphism (..)
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett , idComorphism
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett , isIdComorphism
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett , isModelTransportable
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett , hasModelExpansion
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett , isWeaklyAmalgamable
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett , compComorphism
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblettimport qualified Data.Set as Set
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblettclass (Language cid,
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett Logic lid1 sublogics1
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett basic_spec1 sentence1 symb_items1 symb_map_items1
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett sign1 morphism1 symbol1 raw_symbol1 proof_tree1,
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett Logic lid2 sublogics2
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett basic_spec2 sentence2 symb_items2 symb_map_items2
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett sign2 morphism2 symbol2 raw_symbol2 proof_tree2) =>
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett Comorphism cid
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett lid1 sublogics1 basic_spec1 sentence1 symb_items1 symb_map_items1
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett sign1 morphism1 symbol1 raw_symbol1 proof_tree1
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett lid2 sublogics2 basic_spec2 sentence2 symb_items2 symb_map_items2
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett sign2 morphism2 symbol2 raw_symbol2 proof_tree2
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett | cid -> lid1 sublogics1 basic_spec1 sentence1 symb_items1 symb_map_items1
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett sign1 morphism1 symbol1 raw_symbol1 proof_tree1
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett lid2 sublogics2 basic_spec2 sentence2 symb_items2 symb_map_items2
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett sign2 morphism2 symbol2 raw_symbol2 proof_tree2
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett -- source and target logic and sublogic
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett -- the source sublogic is the maximal one for which the comorphism works
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett sourceLogic :: cid -> lid1
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett sourceSublogic :: cid -> sublogics1
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett targetLogic :: cid -> lid2
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett -- finer information of target sublogics corresponding to source sublogics
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett -- this function must be partial because mapTheory is partial
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett mapSublogic :: cid -> sublogics1 -> Maybe sublogics2
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett -- the translation functions are partial
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett -- because the target may be a sublanguage
29ac9ecacf0983a565b89f133ff2bdf2ac02b0c4Andy Gimblett -- map_basic_spec :: cid -> basic_spec1 -> Result basic_spec2
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett -- cover theoroidal comorphisms as well
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett map_theory :: cid -> (sign1,[Named sentence1])
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett -> Result (sign2,[Named sentence2])
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett map_morphism :: cid -> morphism1 -> Result morphism2
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett map_sentence :: cid -> sign1 -> sentence1 -> Result sentence2
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett -- also covers semi-comorphisms
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett -- with no sentence translation
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett -- - but these are spans!
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett map_sentence = failMapSentence
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett map_symbol :: cid -> sign1 -> symbol1 -> Set.Set symbol2
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett map_symbol = errMapSymbol
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett extractModel :: cid -> sign1 -> proof_tree2
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett -> Result (sign1, [Named sentence1])
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett extractModel cid _ _ = fail
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett $ "extractModel not implemented for comorphism "
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett ++ language_name cid
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett --properties of comorphisms
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett is_model_transportable :: cid -> Bool
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett -- a comorphism (\phi, \alpha, \beta) is model-transportable
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett -- if for any signature \Sigma,
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett -- any \Sigma-model M and any \phi(\Sigma)-model N
2f06b54890375b6cac90394b80b07bd451d728fcAndy Gimblett -- for any isomorphism h : \beta_\Sigma(N) -> M
2f06b54890375b6cac90394b80b07bd451d728fcAndy Gimblett -- there exists an isomorphism h': N -> M' such that \beta_\Sigma(h') = h
2f06b54890375b6cac90394b80b07bd451d728fcAndy Gimblett is_model_transportable _ = False
2f06b54890375b6cac90394b80b07bd451d728fcAndy Gimblett has_model_expansion :: cid -> Bool
2f06b54890375b6cac90394b80b07bd451d728fcAndy Gimblett has_model_expansion _ = False
2f06b54890375b6cac90394b80b07bd451d728fcAndy Gimblett is_weakly_amalgamable :: cid -> Bool
2f06b54890375b6cac90394b80b07bd451d728fcAndy Gimblett is_weakly_amalgamable _ = False
2f06b54890375b6cac90394b80b07bd451d728fcAndy Gimblett constituents :: cid -> [String]
2f06b54890375b6cac90394b80b07bd451d728fcAndy Gimblett constituents cid = [language_name cid]
2f06b54890375b6cac90394b80b07bd451d728fcAndy Gimblett isInclusionComorphism :: cid -> Bool
2f06b54890375b6cac90394b80b07bd451d728fcAndy Gimblett isInclusionComorphism _ = False
a09bfcbcb0fba5663fca1968aa82daebf2e092c4Andy GimbletttargetSublogic :: Comorphism cid
a09bfcbcb0fba5663fca1968aa82daebf2e092c4Andy Gimblett lid1 sublogics1 basic_spec1 sentence1 symb_items1 symb_map_items1
a09bfcbcb0fba5663fca1968aa82daebf2e092c4Andy Gimblett sign1 morphism1 symbol1 raw_symbol1 proof_tree1
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett lid2 sublogics2 basic_spec2 sentence2 symb_items2 symb_map_items2
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett sign2 morphism2 symbol2 raw_symbol2 proof_tree2
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett => cid -> sublogics2
f909337bf7012aca169c0b56b89efbd4a310f8daAndy GimbletttargetSublogic cid = fromMaybe (top_sublogic $ targetLogic cid)
f909337bf7012aca169c0b56b89efbd4a310f8daAndy Gimblett $ mapSublogic cid $ sourceSublogic cid
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett-- | this function is base on 'map_theory' using no sentences as input
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblettmap_sign :: Comorphism cid
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett lid1 sublogics1 basic_spec1 sentence1 symb_items1 symb_map_items1
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett sign1 morphism1 symbol1 raw_symbol1 proof_tree1
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett lid2 sublogics2 basic_spec2 sentence2 symb_items2 symb_map_items2
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett sign2 morphism2 symbol2 raw_symbol2 proof_tree2
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett => cid -> sign1 -> Result (sign2,[Named sentence2])
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblettmap_sign cid sign = wrapMapTheory cid (sign,[])
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblettext_map_sign :: Comorphism cid
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett lid1 sublogics1 basic_spec1 sentence1 symb_items1 symb_map_items1
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett sign1 morphism1 symbol1 raw_symbol1 proof_tree1
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett lid2 sublogics2 basic_spec2 sentence2 symb_items2 symb_map_items2
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett sign2 morphism2 symbol2 raw_symbol2 proof_tree2
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett => cid -> ExtSign sign1 symbol1
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett -> Result (ExtSign sign2 symbol2, [Named sentence2])
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblettext_map_sign cid (ExtSign sign _) = do
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett (sign2, sens2) <- map_sign cid sign
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett return (makeExtSign (targetLogic cid) sign2, sens2)
2f06b54890375b6cac90394b80b07bd451d728fcAndy GimblettmapDefaultMorphism :: Comorphism cid
2f06b54890375b6cac90394b80b07bd451d728fcAndy Gimblett lid1 sublogics1 basic_spec1 sentence1 symb_items1 symb_map_items1
2f06b54890375b6cac90394b80b07bd451d728fcAndy Gimblett sign1 morphism1 symbol1 raw_symbol1 proof_tree1
a09bfcbcb0fba5663fca1968aa82daebf2e092c4Andy Gimblett lid2 sublogics2 basic_spec2 sentence2 symb_items2 symb_map_items2
a09bfcbcb0fba5663fca1968aa82daebf2e092c4Andy Gimblett sign2 morphism2 symbol2 raw_symbol2 proof_tree2
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett => cid -> morphism1 -> Result morphism2
=> cid -> sign1 -> symbol1 -> Set.Set symbol2
map_symbol _ _ = Set.singleton
_ -> error "CompComorphism.map_sentence"
in Set.unions
(Set.toList (map_symbol cid1 sig1 s1)))