Grothendieck.hs revision 6ccaeced9d4aa7b1c0268eea85e2b6118ee1dff7
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder{-# LANGUAGE ExistentialQuantification, MultiParamTypeClasses
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder , DeriveDataTypeable, GeneralizedNewtypeDeriving #-}
1549f3abf73c1122acff724f718b615c82fa3648Till MossakowskiModule : $Header$
97018cf5fa25b494adffd7e9b4e87320dae6bf47Christian MaederDescription : Grothendieck logic (flattening of logic graph to a single logic)
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian MaederCopyright : (c) Till Mossakowski, and Uni Bremen 2002-2006
3f69b6948966979163bdfe8331c38833d5d90ecdChristian MaederLicense : GPLv2 or higher, see LICENSE.txt
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian MaederMaintainer : till@informatik.uni-bremen.de
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian MaederStability : provisional
f3a94a197960e548ecd6520bb768cb0d547457bbChristian MaederPortability : non-portable (overlapping instances, dynamics, existentials)
1549f3abf73c1122acff724f718b615c82fa3648Till MossakowskiGrothendieck logic (flattening of logic graph to a single logic)
1549f3abf73c1122acff724f718b615c82fa3648Till MossakowskiThe Grothendieck logic is defined to be the
1549f3abf73c1122acff724f718b615c82fa3648Till Mossakowski heterogeneous logic over the logic graph.
1549f3abf73c1122acff724f718b615c82fa3648Till Mossakowski This will be the logic over which the data
1549f3abf73c1122acff724f718b615c82fa3648Till Mossakowski structures and algorithms for specification in-the-large
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder This module heavily works with existential types, see
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder <http://haskell.org/hawiki/ExistentialTypes> and chapter 7 of /Heterogeneous
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder specification and the heterogeneous tool set/
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder (<http://www.informatik.uni-bremen.de/~till/papers/habil.ps>).
ad270004874ce1d0697fb30d7309f180553bb315Christian Maeder R. Diaconescu:
ad270004874ce1d0697fb30d7309f180553bb315Christian Maeder Grothendieck institutions
5e46b572ed576c0494768998b043d9d340594122Till Mossakowski J. applied categorical structures 10, 2002, p. 383-402.
23a00c966f2aa8da525d7a7c51933c99964426c0Christian Maeder T. Mossakowski:
575a55eadc8dcab8ee350324b417cbd9e52e69c0Christian Maeder Comorphism-based Grothendieck institutions.
575a55eadc8dcab8ee350324b417cbd9e52e69c0Christian Maeder In K. Diks, W. Rytter (Eds.), Mathematical foundations of computer science,
575a55eadc8dcab8ee350324b417cbd9e52e69c0Christian Maeder LNCS 2420, pp. 593-604
575a55eadc8dcab8ee350324b417cbd9e52e69c0Christian Maeder T. Mossakowski:
575a55eadc8dcab8ee350324b417cbd9e52e69c0Christian Maeder Heterogeneous specification and the heterogeneous tool set.
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder ( G_basic_spec (..)
0e2ae85e2453466d03c1fc5884a3d693235bb9d9Christian Maeder , G_sign (..)
c438c79d00fc438f99627e612498744bdc0d0c89Christian Maeder , isHomSubGsign
ca020e82eb3567e7bdbb1cf70729efbd07e9caa4Klaus Luettich , logicOfGsign
ca020e82eb3567e7bdbb1cf70729efbd07e9caa4Klaus Luettich , G_symbolmap (..)
ca020e82eb3567e7bdbb1cf70729efbd07e9caa4Klaus Luettich , G_mapofsymbol (..)
ca020e82eb3567e7bdbb1cf70729efbd07e9caa4Klaus Luettich , G_symbol (..)
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder , G_symb_items_list (..)
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder , G_symb_map_items_list (..)
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski , G_sublogics (..)
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder , isProperSublogic
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder , joinSublogics
4b6aa93c12e4db86ccc7694a48a73e9cf7262d06Christian Maeder , G_morphism (..)
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski , mkG_morphism
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder , lessSublogicComor
8e80792f474d154ff11762fac081a422e34f1accChristian Maeder , LogicGraph (..)
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder , setCurLogic
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder , emptyLogicGraph
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder , lookupLogic
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder , lookupCurrentLogic
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder , lookupCompComorphism
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder , lookupComorphism
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder , lookupModification
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder , GMorphism (..)
4b6aa93c12e4db86ccc7694a48a73e9cf7262d06Christian Maeder , isHomogeneous
4b6aa93c12e4db86ccc7694a48a73e9cf7262d06Christian Maeder , isHomInclusion
4b6aa93c12e4db86ccc7694a48a73e9cf7262d06Christian Maeder , Grothendieck (..)
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder , gEmbedComorphism
4b6aa93c12e4db86ccc7694a48a73e9cf7262d06Christian Maeder , gsigManyUnion
5e46b572ed576c0494768998b043d9d340594122Till Mossakowski , homogeneousMorManyUnion
5e46b572ed576c0494768998b043d9d340594122Till Mossakowski , logicInclusion
4b6aa93c12e4db86ccc7694a48a73e9cf7262d06Christian Maeder , updateMorIndex
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder , toG_morphism
4b6aa93c12e4db86ccc7694a48a73e9cf7262d06Christian Maeder , compInclusion
7a47fbe6b987bd69a5056ce5d00fc8710f6c5e8aChristian Maeder , findComorphismPaths
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder , findComorphism
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder , isTransportable
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maeder , Square (..)
7a47fbe6b987bd69a5056ce5d00fc8710f6c5e8aChristian Maeder , LaxTriangle (..)
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder , mkDefSquare
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski , mirrorSquare
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski , lookupSquare
03136b84a0c70d877e227444f0875e209506b9e4Christian Maederimport Data.Maybe (mapMaybe)
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maederimport qualified Data.Map as Map
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maederimport Text.ParserCombinators.Parsec (Parser, parse, eof, (<|>))
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder-- for looking up modifications
7a47fbe6b987bd69a5056ce5d00fc8710f6c5e8aChristian Maeder-- * \"Grothendieck\" versions of the various parts of type class Logic
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder-- | Grothendieck basic specifications
03136b84a0c70d877e227444f0875e209506b9e4Christian Maederdata G_basic_spec = forall lid sublogics
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder basic_spec sentence symb_items symb_map_items
5e46b572ed576c0494768998b043d9d340594122Till Mossakowski sign morphism symbol raw_symbol proof_tree .
1f086d5155f47fdad9a0de4e46bbebb2c4b33d30Christian Maeder Logic lid sublogics
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder basic_spec sentence symb_items symb_map_items
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder sign morphism symbol raw_symbol proof_tree =>
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder G_basic_spec lid basic_spec
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder deriving Typeable
03136b84a0c70d877e227444f0875e209506b9e4Christian Maederinstance Show G_basic_spec where
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder show (G_basic_spec _ s) = show s
03136b84a0c70d877e227444f0875e209506b9e4Christian Maederinstance Pretty G_basic_spec where
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder pretty (G_basic_spec _ s) = pretty s
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowskiinstance GetRange G_basic_spec
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski-- dummy instances for development graphs
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maederinstance Ord G_basic_spec where
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski compare _ _ = EQ
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowskiinstance Eq G_basic_spec where
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski _ == _ = True
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder-- | index for signatures
575a55eadc8dcab8ee350324b417cbd9e52e69c0Christian Maedernewtype SigId = SigId Int
575a55eadc8dcab8ee350324b417cbd9e52e69c0Christian Maeder deriving (Typeable, Show, Eq, Ord, Enum, ShATermConvertible)
03136b84a0c70d877e227444f0875e209506b9e4Christian MaederstartSigId :: SigId
03136b84a0c70d877e227444f0875e209506b9e4Christian MaederstartSigId = SigId 0
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder{- | Grothendieck signatures with an lookup index. Zero indices
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder indicate unknown ones. It would be nice to have special (may be
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder negative) indices for empty signatures (one for every logic). -}
03136b84a0c70d877e227444f0875e209506b9e4Christian Maederdata G_sign = forall lid sublogics
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder basic_spec sentence symb_items symb_map_items
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder sign morphism symbol raw_symbol proof_tree .
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder Logic lid sublogics
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder basic_spec sentence symb_items symb_map_items
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski sign morphism symbol raw_symbol proof_tree => G_sign
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski { gSignLogic :: lid
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder , gSign :: ExtSign sign symbol
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski , gSignSelfIdx :: SigId -- ^ index to lookup this 'G_sign' in sign map
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder } deriving Typeable
03136b84a0c70d877e227444f0875e209506b9e4Christian Maederinstance Eq G_sign where
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski a == b = compare a b == EQ
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maederinstance Ord G_sign where
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maeder compare (G_sign l1 sigma1 s1) (G_sign l2 sigma2 s2) =
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder if s1 > startSigId && s2 > startSigId && s1 == s2 then EQ else
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder case compare (language_name l1) $ language_name l2 of
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder EQ -> compare (coerceSign l1 l2 "Eq G_sign" sigma1) $ Just sigma2
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski-- | prefer a faster subsignature test if possible
03136b84a0c70d877e227444f0875e209506b9e4Christian MaederisHomSubGsign :: G_sign -> G_sign -> Bool
03136b84a0c70d877e227444f0875e209506b9e4Christian MaederisHomSubGsign (G_sign l1 sigma1 s1) (G_sign l2 sigma2 s2) =
575a55eadc8dcab8ee350324b417cbd9e52e69c0Christian Maeder (s1 > startSigId && s2 > startSigId && s1 == s2) ||
575a55eadc8dcab8ee350324b417cbd9e52e69c0Christian Maeder maybe False (ext_is_subsig l1 sigma1)
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder (coerceSign l2 l1 "isHomSubGsign" sigma2)
03136b84a0c70d877e227444f0875e209506b9e4Christian MaederisSubGsign :: LogicGraph -> G_sign -> G_sign -> Bool
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian MaederisSubGsign lg (G_sign lid1 (ExtSign sigma1 _) _)
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maeder (G_sign lid2 (ExtSign sigma2 _) _) =
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder do Comorphism cid <- resultToMaybe $
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder logicInclusion lg (Logic lid1) (Logic lid2)
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maeder sigma1' <- coercePlainSign lid1 (sourceLogic cid)
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maeder "Grothendieck.isSubGsign: cannot happen" sigma1
3df765bba27034f17ba60ee9b90d7dbd3643ea9eChristian Maeder sigma2' <- coercePlainSign lid2 (targetLogic cid)
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maeder "Grothendieck.isSubGsign: cannot happen" sigma2
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maeder sigma1t <- resultToMaybe $ map_sign cid sigma1'
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maeder return $ is_subsig (targetLogic cid) (fst sigma1t) sigma2'
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maederinstance Show G_sign where
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder show (G_sign _ s _) = show s
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maederinstance Pretty G_sign where
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maeder pretty (G_sign _ (ExtSign s _) _) = pretty s
03136b84a0c70d877e227444f0875e209506b9e4Christian MaederlogicOfGsign :: G_sign -> AnyLogic
0e2ae85e2453466d03c1fc5884a3d693235bb9d9Christian MaederlogicOfGsign (G_sign lid _ _) = Logic lid
200849122a9c65773e5b2ba8084ac3490d0490b5Christian Maeder-- | Grothendieck maps with symbol as keys
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maederdata G_symbolmap a = forall lid sublogics
200849122a9c65773e5b2ba8084ac3490d0490b5Christian Maeder basic_spec sentence symb_items symb_map_items
200849122a9c65773e5b2ba8084ac3490d0490b5Christian Maeder sign morphism symbol raw_symbol proof_tree .
200849122a9c65773e5b2ba8084ac3490d0490b5Christian Maeder Logic lid sublogics
200849122a9c65773e5b2ba8084ac3490d0490b5Christian Maeder basic_spec sentence symb_items symb_map_items
200849122a9c65773e5b2ba8084ac3490d0490b5Christian Maeder sign morphism symbol raw_symbol proof_tree =>
200849122a9c65773e5b2ba8084ac3490d0490b5Christian Maeder G_symbolmap lid (Map.Map symbol a)
200849122a9c65773e5b2ba8084ac3490d0490b5Christian Maeder deriving Typeable
200849122a9c65773e5b2ba8084ac3490d0490b5Christian Maederinstance Show a => Show (G_symbolmap a) where
200849122a9c65773e5b2ba8084ac3490d0490b5Christian Maeder show (G_symbolmap _ sm) = show sm
200849122a9c65773e5b2ba8084ac3490d0490b5Christian Maederinstance (Typeable a, Ord a) => Eq (G_symbolmap a) where
0b6f6d3eeb7b3b36292e60f1b3da5a5ce42eef1aChristian Maeder a == b = compare a b == EQ
200849122a9c65773e5b2ba8084ac3490d0490b5Christian Maederinstance (Typeable a, Ord a) => Ord (G_symbolmap a) where
200849122a9c65773e5b2ba8084ac3490d0490b5Christian Maeder compare (G_symbolmap l1 sm1) (G_symbolmap l2 sm2) =
200849122a9c65773e5b2ba8084ac3490d0490b5Christian Maeder case compare (language_name l1) $ language_name l2 of
200849122a9c65773e5b2ba8084ac3490d0490b5Christian Maeder EQ -> compare (coerceSymbolmap l1 l2 sm1) sm2
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder-- | Grothendieck maps with symbol as values
03136b84a0c70d877e227444f0875e209506b9e4Christian Maederdata G_mapofsymbol a = forall lid sublogics
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder basic_spec sentence symb_items symb_map_items
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder sign morphism symbol raw_symbol proof_tree .
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder Logic lid sublogics
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder basic_spec sentence symb_items symb_map_items
1f086d5155f47fdad9a0de4e46bbebb2c4b33d30Christian Maeder sign morphism symbol raw_symbol proof_tree =>
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder G_mapofsymbol lid (Map.Map a symbol)
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder deriving Typeable
7a47fbe6b987bd69a5056ce5d00fc8710f6c5e8aChristian Maederinstance Show a => Show (G_mapofsymbol a) where
7a47fbe6b987bd69a5056ce5d00fc8710f6c5e8aChristian Maeder show (G_mapofsymbol _ sm) = show sm
0e2ae85e2453466d03c1fc5884a3d693235bb9d9Christian Maederinstance (Typeable a, Ord a) => Eq (G_mapofsymbol a) where
0e2ae85e2453466d03c1fc5884a3d693235bb9d9Christian Maeder a == b = compare a b == EQ
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maederinstance (Typeable a, Ord a) => Ord (G_mapofsymbol a) where
0e2ae85e2453466d03c1fc5884a3d693235bb9d9Christian Maeder compare (G_mapofsymbol l1 sm1) (G_mapofsymbol l2 sm2) =
0e2ae85e2453466d03c1fc5884a3d693235bb9d9Christian Maeder case compare (language_name l1) $ language_name l2 of
7a47fbe6b987bd69a5056ce5d00fc8710f6c5e8aChristian Maeder EQ -> compare (coerceMapofsymbol l1 l2 sm1) sm2
0e2ae85e2453466d03c1fc5884a3d693235bb9d9Christian Maeder-- | Grothendieck symbols
7a47fbe6b987bd69a5056ce5d00fc8710f6c5e8aChristian Maederdata G_symbol = forall lid sublogics
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder basic_spec sentence symb_items symb_map_items
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder sign morphism symbol raw_symbol proof_tree .
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder Logic lid sublogics
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder basic_spec sentence symb_items symb_map_items
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maeder sign morphism symbol raw_symbol proof_tree =>
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maeder G_symbol lid symbol
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maeder deriving Typeable
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maederinstance GetRange G_symbol where
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maeder getRange (G_symbol _ s) = getRange s
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maeder rangeSpan (G_symbol _ s) = rangeSpan s
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowskiinstance Show G_symbol where
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder show (G_symbol _ s) = show s
5e46b572ed576c0494768998b043d9d340594122Till Mossakowskiinstance Pretty G_symbol where
4601edb679f0ba530bbb085b25d82a411cd070aaChristian Maeder pretty (G_symbol _ s) = pretty s
03136b84a0c70d877e227444f0875e209506b9e4Christian Maederinstance Eq G_symbol where
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder a == b = compare a b == EQ
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maederinstance Ord G_symbol where
68138d26bcddf5e89c30206aa83ab5ec006d170dChristian Maeder compare (G_symbol l1 s1) (G_symbol l2 s2) =
68138d26bcddf5e89c30206aa83ab5ec006d170dChristian Maeder case compare (language_name l1) $ language_name l2 of
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder EQ -> compare (coerceSymbol l1 l2 s1) s2
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder-- | Grothendieck symbol lists
4fc727afa544a757d1959ce77c02208f8bf330dcChristian Maederdata G_symb_items_list = forall lid sublogics
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder basic_spec sentence symb_items symb_map_items
68138d26bcddf5e89c30206aa83ab5ec006d170dChristian Maeder sign morphism symbol raw_symbol proof_tree .
68138d26bcddf5e89c30206aa83ab5ec006d170dChristian Maeder Logic lid sublogics
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder basic_spec sentence symb_items symb_map_items
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder sign morphism symbol raw_symbol proof_tree =>
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder G_symb_items_list lid [symb_items]
4fc727afa544a757d1959ce77c02208f8bf330dcChristian Maeder deriving Typeable
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maederinstance GetRange G_symb_items_list
68138d26bcddf5e89c30206aa83ab5ec006d170dChristian Maederinstance Show G_symb_items_list where
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder show (G_symb_items_list _ l) = show l
68138d26bcddf5e89c30206aa83ab5ec006d170dChristian Maederinstance Pretty G_symb_items_list where
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder pretty (G_symb_items_list _ l) = ppWithCommas l
4fc727afa544a757d1959ce77c02208f8bf330dcChristian Maederinstance Eq G_symb_items_list where
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder (G_symb_items_list i1 s1) == (G_symb_items_list i2 s2) =
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder coerceSymbItemsList i1 i2 "Eq G_symb_items_list" s1 == Just s2
68138d26bcddf5e89c30206aa83ab5ec006d170dChristian Maeder-- | Grothendieck symbol maps
68138d26bcddf5e89c30206aa83ab5ec006d170dChristian Maederdata G_symb_map_items_list = forall lid sublogics
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder basic_spec sentence symb_items symb_map_items
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder sign morphism symbol raw_symbol proof_tree .
b1caf27fb0c879dd39600d09d501074a2dfd865aChristian Maeder Logic lid sublogics
5e46b572ed576c0494768998b043d9d340594122Till Mossakowski basic_spec sentence symb_items symb_map_items
1f086d5155f47fdad9a0de4e46bbebb2c4b33d30Christian Maeder sign morphism symbol raw_symbol proof_tree =>
5e46b572ed576c0494768998b043d9d340594122Till Mossakowski G_symb_map_items_list lid [symb_map_items]
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder deriving Typeable
5e46b572ed576c0494768998b043d9d340594122Till Mossakowskiinstance GetRange G_symb_map_items_list
5e46b572ed576c0494768998b043d9d340594122Till Mossakowskiinstance Show G_symb_map_items_list where
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder show (G_symb_map_items_list _ l) = show l
5e46b572ed576c0494768998b043d9d340594122Till Mossakowskiinstance Pretty G_symb_map_items_list where
5e46b572ed576c0494768998b043d9d340594122Till Mossakowski pretty (G_symb_map_items_list _ l) = ppWithCommas l
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maederinstance Eq G_symb_map_items_list where
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder (G_symb_map_items_list i1 s1) == (G_symb_map_items_list i2 s2) =
5e46b572ed576c0494768998b043d9d340594122Till Mossakowski coerceSymbMapItemsList i1 i2 "Eq G_symb_map_items_list" s1 == Just s2
5e46b572ed576c0494768998b043d9d340594122Till Mossakowski-- | Grothendieck sublogics
329d1810c6d5a5a0827e1d07503d94431578d176Christian Maederdata G_sublogics = forall lid sublogics
329d1810c6d5a5a0827e1d07503d94431578d176Christian Maeder basic_spec sentence symb_items symb_map_items
329d1810c6d5a5a0827e1d07503d94431578d176Christian Maeder sign morphism symbol raw_symbol proof_tree .
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder Logic lid sublogics
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder basic_spec sentence symb_items symb_map_items
329d1810c6d5a5a0827e1d07503d94431578d176Christian Maeder sign morphism symbol raw_symbol proof_tree =>
329d1810c6d5a5a0827e1d07503d94431578d176Christian Maeder G_sublogics lid sublogics
329d1810c6d5a5a0827e1d07503d94431578d176Christian Maeder deriving Typeable
329d1810c6d5a5a0827e1d07503d94431578d176Christian Maederinstance Show G_sublogics where
329d1810c6d5a5a0827e1d07503d94431578d176Christian Maeder show (G_sublogics lid sub) = language_name lid ++ case sublogicName sub of
329d1810c6d5a5a0827e1d07503d94431578d176Christian Maederinstance Eq G_sublogics where
329d1810c6d5a5a0827e1d07503d94431578d176Christian Maeder g1 == g2 = compare g1 g2 == EQ
5e46b572ed576c0494768998b043d9d340594122Till Mossakowskiinstance Ord G_sublogics where
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder compare (G_sublogics lid1 l1) (G_sublogics lid2 l2) =
0e2ae85e2453466d03c1fc5884a3d693235bb9d9Christian Maeder case compare (language_name lid1) $ language_name lid2 of
0e2ae85e2453466d03c1fc5884a3d693235bb9d9Christian Maeder EQ -> compare (forceCoerceSublogic lid1 lid2 l1) l2
243b39800f5ea9033daca8ce5475531d114e1877Christian MaederisProperSublogic :: G_sublogics -> G_sublogics -> Bool
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill MossakowskiisProperSublogic a@(G_sublogics lid1 l1) b@(G_sublogics lid2 l2) =
0e2ae85e2453466d03c1fc5884a3d693235bb9d9Christian Maeder isSubElem (forceCoerceSublogic lid1 lid2 l1) l2 && a /= b
4601edb679f0ba530bbb085b25d82a411cd070aaChristian MaederjoinSublogics :: G_sublogics -> G_sublogics -> Maybe G_sublogics
746440cc1b984a852f5864235b8fa3930963a081Christian MaederjoinSublogics (G_sublogics lid1 l1) (G_sublogics lid2 l2) =
746440cc1b984a852f5864235b8fa3930963a081Christian Maeder case coerceSublogic lid1 lid2 "coerce Sublogic" l1 of
7a47fbe6b987bd69a5056ce5d00fc8710f6c5e8aChristian Maeder Just sl -> Just (G_sublogics lid2 (join sl l2))
7a47fbe6b987bd69a5056ce5d00fc8710f6c5e8aChristian Maeder Nothing -> Nothing
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder-- | index for morphisms
e68f45f355ed9d4026ee9baff5aa75aa7c911cc2Christian Maedernewtype MorId = MorId Int
e68f45f355ed9d4026ee9baff5aa75aa7c911cc2Christian Maeder deriving (Typeable, Show, Eq, Ord, Enum, ShATermConvertible)
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian MaederstartMorId :: MorId
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian MaederstartMorId = MorId 0
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder{- | Homogeneous Grothendieck signature morphisms with indices. For
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maederthe domain index it would be nice it showed also the emptiness. -}
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maederdata G_morphism = forall lid sublogics
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder basic_spec sentence symb_items symb_map_items
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder sign morphism symbol raw_symbol proof_tree .
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder Logic lid sublogics
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder basic_spec sentence symb_items symb_map_items
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder sign morphism symbol raw_symbol proof_tree => G_morphism
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder { gMorphismLogic :: lid
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder , gMorphism :: morphism
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder , gMorphismSelfIdx :: MorId -- ^ lookup index in morphism map
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder } deriving Typeable
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maederinstance Show G_morphism where
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder show (G_morphism _ m _) = show m
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maederinstance Pretty G_morphism where
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder pretty (G_morphism _ m _) = pretty m
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian MaedermkG_morphism :: forall lid sublogics
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder basic_spec sentence symb_items symb_map_items
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder sign morphism symbol raw_symbol proof_tree .
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder Logic lid sublogics
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder basic_spec sentence symb_items symb_map_items
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder sign morphism symbol raw_symbol proof_tree
575a55eadc8dcab8ee350324b417cbd9e52e69c0Christian Maeder => lid -> morphism -> G_morphism
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian MaedermkG_morphism l m = G_morphism l m startMorId
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder-- | check if sublogic fits for comorphism
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian MaederlessSublogicComor :: G_sublogics -> AnyComorphism -> Bool
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian MaederlessSublogicComor (G_sublogics lid1 sub1) (Comorphism cid) =
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder let lid2 = sourceLogic cid
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder in language_name lid2 == language_name lid1
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder && isSubElem (forceCoerceSublogic lid1 lid2 sub1) (sourceSublogic cid)
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder-- | Logic graph
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maederdata LogicGraph = LogicGraph
575a55eadc8dcab8ee350324b417cbd9e52e69c0Christian Maeder { logics :: Map.Map String AnyLogic
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder , currentLogic :: String
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder , comorphisms :: Map.Map String AnyComorphism
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder , inclusions :: Map.Map (String, String) AnyComorphism
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder , unions :: Map.Map (String, String) (AnyComorphism, AnyComorphism)
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder , morphisms :: Map.Map String AnyMorphism
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder , modifications :: Map.Map String AnyModification
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder , squares :: Map.Map (AnyComorphism, AnyComorphism) [Square]
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder , qTATranslations :: Map.Map String AnyComorphism
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder } deriving Show
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian MaederemptyLogicGraph :: LogicGraph
03136b84a0c70d877e227444f0875e209506b9e4Christian MaederemptyLogicGraph = LogicGraph
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder , currentLogic = "CASL"
746440cc1b984a852f5864235b8fa3930963a081Christian Maeder , comorphisms = Map.empty
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder , modifications = Map.empty
3b70d8ee5c2927f843d5d907e6ef724f867f1b40Till Mossakowski , qTATranslations = Map.empty }
3b70d8ee5c2927f843d5d907e6ef724f867f1b40Till MossakowskisetCurLogic :: String -> LogicGraph -> LogicGraph
ca732bc259f74cb4f3f725daab7fe80fc7e1d9a0Till MossakowskisetCurLogic s lg = lg { currentLogic = s }
ca732bc259f74cb4f3f725daab7fe80fc7e1d9a0Till Mossakowskiinstance Pretty LogicGraph where
ca732bc259f74cb4f3f725daab7fe80fc7e1d9a0Till Mossakowski pretty lg = text ("current logic is: " ++ currentLogic lg)
ca732bc259f74cb4f3f725daab7fe80fc7e1d9a0Till Mossakowski $+$ text "all logics:"
ca732bc259f74cb4f3f725daab7fe80fc7e1d9a0Till Mossakowski $+$ sepByCommas (map text $ Map.keys $ logics lg)
ca732bc259f74cb4f3f725daab7fe80fc7e1d9a0Till Mossakowski $+$ text "comorphism inclusions:"
db453fe9625a9dab5d108f7a5e464598814144b8Jian Chun Wang $+$ vcat (map pretty $ Map.elems $ inclusions lg)
c438c79d00fc438f99627e612498744bdc0d0c89Christian Maeder $+$ text "all comorphisms:"
db453fe9625a9dab5d108f7a5e464598814144b8Jian Chun Wang $+$ vcat (map pretty $ Map.elems $ comorphisms lg)
db453fe9625a9dab5d108f7a5e464598814144b8Jian Chun Wang-- | find a logic in a logic graph
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill MossakowskilookupLogic :: Monad m => String -> String -> LogicGraph -> m AnyLogic
db453fe9625a9dab5d108f7a5e464598814144b8Jian Chun WanglookupLogic error_prefix logname logicGraph =
db453fe9625a9dab5d108f7a5e464598814144b8Jian Chun Wang case Map.lookup logname $ logics logicGraph of
db453fe9625a9dab5d108f7a5e464598814144b8Jian Chun Wang Nothing -> fail $ error_prefix ++ " in LogicGraph logic \""
db453fe9625a9dab5d108f7a5e464598814144b8Jian Chun Wang ++ logname ++ "\" unknown"
db453fe9625a9dab5d108f7a5e464598814144b8Jian Chun Wang Just lid -> return lid
db453fe9625a9dab5d108f7a5e464598814144b8Jian Chun WanglookupCurrentLogic :: Monad m => String -> LogicGraph -> m AnyLogic
db453fe9625a9dab5d108f7a5e464598814144b8Jian Chun WanglookupCurrentLogic msg lg = lookupLogic msg (currentLogic lg) lg
db453fe9625a9dab5d108f7a5e464598814144b8Jian Chun Wang-- | union to two logics
db453fe9625a9dab5d108f7a5e464598814144b8Jian Chun WanglogicUnion :: LogicGraph -> AnyLogic -> AnyLogic
c438c79d00fc438f99627e612498744bdc0d0c89Christian Maeder -> Result (AnyComorphism, AnyComorphism)
db453fe9625a9dab5d108f7a5e464598814144b8Jian Chun WanglogicUnion lg l1@(Logic lid1) l2@(Logic lid2) =
db453fe9625a9dab5d108f7a5e464598814144b8Jian Chun Wang case logicInclusion lg l1 l2 of
db453fe9625a9dab5d108f7a5e464598814144b8Jian Chun Wang Result _ (Just c) -> return (c, idComorphism l2)
db453fe9625a9dab5d108f7a5e464598814144b8Jian Chun Wang _ -> case logicInclusion lg l2 l1 of
db453fe9625a9dab5d108f7a5e464598814144b8Jian Chun Wang Result _ (Just c) -> return (idComorphism l1, c)
_ -> case Map.lookup (ln1, ln2) (unions lg) of
Nothing -> case Map.lookup (ln2, ln1) (unions lg) of
$ Map.lookup mainLogic (logics logicGraph)
$ Map.lookup name (comorphisms logicGraph)
case Map.lookup name (comorphisms lG) of
case Map.lookup name (modifications lG) of
"Ord GMorphism.coerceMorphism" mor1) (Just mor2)
mor2' <- coerceMorphism lid4 lid2 "Grothendieck.comp" mor2
mor1' <- coerceMorphism lid2 lid3 "Grothendieck.comp" mor1
case coerceSublogic lid2 lid3 "Grothendieck.comp"
sigma1' <- coerceSign lid1 lid3 "Grothendieck.comp" sigma1
else case Map.lookup (ln1, ln2) (inclusions logicGraph) of
coMors = Map.elems $ comorphisms lg
sqL1 <- Map.lookup (com1, com2) $ squares lg
sqL2 <- Map.lookup (com2, com1) $ squares lg