SymbolMapAnalysis.hs revision 03136b84a0c70d877e227444f0875e209506b9e4
e9458b1a7a19a63aa4c179f9ab20f4d50681c168Jens ElknerModule : $Header$
e6d40133bc9f858308654afb1262b8b483ec5922Till MossakowskiDescription : symbol map analysis for the CASL logic.
b03274844ecd270f9e9331f51cc4236a33e2e671Christian MaederCopyright : (c) Till Mossakowski, C. Maeder and Uni Bremen 2002-2005
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu ProdescuLicense : similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt
cfbd735270fe52115cef0508d265785efcb99cd7Christian MaederMaintainer : Christian.Maeder@dfki.de
120eec9ff1748e1ae786e2ab073234198bc0f701Christian MaederStability : provisional
120eec9ff1748e1ae786e2ab073234198bc0f701Christian MaederPortability : portable
e6d40133bc9f858308654afb1262b8b483ec5922Till MossakowskiSymbol map analysis for the CASL logic.
120eec9ff1748e1ae786e2ab073234198bc0f701Christian Maeder Follows Sect. III:4.1 of the CASL Reference Manual.
120eec9ff1748e1ae786e2ab073234198bc0f701Christian Maeder ( inducedFromMorphism
2ed75b9c0aced535e9bc446cd294fd0f530e7fe0Christian Maeder , inducedFromToMorphism
54ea981a0503c396c2923a1c06421c6235baf27fChristian Maeder , cogeneratedSign
120eec9ff1748e1ae786e2ab073234198bc0f701Christian Maeder , generatedSign
54ea981a0503c396c2923a1c06421c6235baf27fChristian Maederimport qualified Data.Map as Map
120eec9ff1748e1ae786e2ab073234198bc0f701Christian Maederimport qualified Data.Set as Set
b2e92fd7a332d07a52e0284ea7a40618e0ff5656Christian Maederimport qualified Common.Lib.Rel as Rel
95a43f69d0da78c0cb804b6ea6c907d6e831a203Christian MaederinducedFromMorphism :: RawSymbolMap -> sign -> Result morphism
f45fad43ee1673ab280fbc700821d5d20a493eaaChristian MaederHere is Bartek Klin's algorithm that has benn used for CATS.
95a43f69d0da78c0cb804b6ea6c907d6e831a203Christian MaederOur algorithm deviates from it. The exact details need to be checked.
f45fad43ee1673ab280fbc700821d5d20a493eaaChristian MaederInducing morphism from raw symbol map and signature
f45fad43ee1673ab280fbc700821d5d20a493eaaChristian MaederInput: raw symbol map "Rsm"
f45fad43ee1673ab280fbc700821d5d20a493eaaChristian Maeder signature "Sigma1"
f45fad43ee1673ab280fbc700821d5d20a493eaaChristian MaederOutput: morphims "Mrph": Sigma1 -> "Sigma2".
cd9ca21a6446db25db7dca76a01c14231d4d48d5Cui Jian//preparation
388d584887dcaee44aa6f27dc9a054a3df4890a5Christian Maeder1. let "Ssm" be an empty list of pairs (symbol, raw symbol).
afe76697dd6888856a066934a1112a38809b27faChristian Maeder2. for each pair "Rsym1,Rsym2" in Rsm do:
afe76697dd6888856a066934a1112a38809b27faChristian Maeder 2.1. if there is no symbol in Sigma1 matching Rsym1, return error.
afe76697dd6888856a066934a1112a38809b27faChristian Maeder 2.2. for each symbol "Sym" from Sigma1 matching Rsym1
94d9a4cf9aca9662f2a35f1d53170e86739baf24Cui Jian 2.2.1. add a pair "Sym,Rsym2" to Ssm.
95a43f69d0da78c0cb804b6ea6c907d6e831a203Christian Maeder//computing the "sort part" of the morphism
95a43f69d0da78c0cb804b6ea6c907d6e831a203Christian Maeder3. let Sigma2 be an empty signature.
95a43f69d0da78c0cb804b6ea6c907d6e831a203Christian Maeder4. let Mrph be an empty "morphism" from Sigma1 to Sigma2.
afe76697dd6888856a066934a1112a38809b27faChristian Maeder5. for each pair "Sym,Rsym2" in Ssm such that Sym is a sort symbol
afe76697dd6888856a066934a1112a38809b27faChristian Maeder 5.1. if Rsym2 is not a sort raw symbol, return error.
4b136ad539bd9f4e115dff4eee4d552a42d4437eChristian Maeder 5.2. if in Mrph there is a mapping of sort in Sym to sort with
0d0278c34a374b29c2d6c58b39b8b56e283d48e8Christian Maeder name other than that in Rsym2, return error.
94d9a4cf9aca9662f2a35f1d53170e86739baf24Cui Jian 5.3. if in Mrph there is no mappinh of sort in Sym
95a43f69d0da78c0cb804b6ea6c907d6e831a203Christian Maeder 5.3.1. add sort from Rsym2 to Sigma2
3fe83d4c932a8266edcf0304a97814c59821d91fChristian Maeder 5.3.2. add mapping from sort(Sym) to sort(Rsym2) to Mrph.
3fe83d4c932a8266edcf0304a97814c59821d91fChristian Maeder6. for each sort symbol "S" in Sigma1
544b866d340cdef36332f59ecd899daa1807f6c7Cui Jian 6.1. if S is not mapped by Mrph,
95a43f69d0da78c0cb804b6ea6c907d6e831a203Christian Maeder 6.1.1. add sort S to Sigma2
120eec9ff1748e1ae786e2ab073234198bc0f701Christian Maeder 6.1.2. add mapping from S to S to Mrph.
da955132262baab309a50fdffe228c9efe68251dCui Jian//computing the "function/predicate part" of the morphism
6948b7295a0521212803f15cf919395d2073e2c9Christian Maeder7. for each pair "Sym,Rsym2" in Ssm such that Sym is a function/predicate
3fe83d4c932a8266edcf0304a97814c59821d91fChristian Maeder 7.1. let "F" be name contained in Sym, let "Fprof" be the profile.
3fe83d4c932a8266edcf0304a97814c59821d91fChristian Maeder 7.2. let "Fprof1" be the value of Fprof via Mrph
95a43f69d0da78c0cb804b6ea6c907d6e831a203Christian Maeder (it can be computed, as we already have the "sort" part of
95a43f69d0da78c0cb804b6ea6c907d6e831a203Christian Maeder 7.3. if Rsym2 is not of appriopriate type, return error, otherwise
2c81e2bd9f9dee247c74a642c03620a2f799d0a4Razvan Pascanu let "F2" be the name of the symbol.
31009d997a07e58087aa8acb84bc6ac90cb82942Till Mossakowski 7.4. if Rsym2 enforces the profile of the symbol (i.e., it is not
95a43f69d0da78c0cb804b6ea6c907d6e831a203Christian Maeder an implicit symbol), compare the profile to Fprof1. If it is
6948b7295a0521212803f15cf919395d2073e2c9Christian Maeder not equal, return error.
5129a6bc64bcdb44aa111adb7bd2d0683f452b7aChristian Maeder 7.5. if in Mrph there is a mapping of F1 with profile Fprof to
5129a6bc64bcdb44aa111adb7bd2d0683f452b7aChristian Maeder some name different than F2, return error.
c458c6f5a2ce173d8af7a7f5cb434813eb870937Jorina Freya Gerken 7.6. add an operation/predicate with name F2 and profile Fprof1 to
95a43f69d0da78c0cb804b6ea6c907d6e831a203Christian Maeder Sigma2. If it is a partial function and if in Sigma2 there
95a43f69d0da78c0cb804b6ea6c907d6e831a203Christian Maeder exists a total function with the same name and profile, do not
95a43f69d0da78c0cb804b6ea6c907d6e831a203Christian Maeder add it. Otherwise if it is a total function and if in Sigma2
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder there exists a partial function with the same name and profile,
95a43f69d0da78c0cb804b6ea6c907d6e831a203Christian Maeder add the total function removing the partial one.
95a43f69d0da78c0cb804b6ea6c907d6e831a203Christian Maeder 7.7. add to Mrph a mapping from operation/predicate of name F1 and
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder profile Fprof to name F2.
95a43f69d0da78c0cb804b6ea6c907d6e831a203Christian Maeder8. for each operation/predicate symbol "F" with profile "Fprof" in Sigma1
95a43f69d0da78c0cb804b6ea6c907d6e831a203Christian Maeder that is not mapped by Mrph,
10e12ec6ab28a40706609341c727422a0cd8d34dChristian Maeder 8.1. as in 7.2
10e12ec6ab28a40706609341c727422a0cd8d34dChristian Maeder 8.2. as in 7.6, replacing F2 with F1.
95a43f69d0da78c0cb804b6ea6c907d6e831a203Christian Maeder 8.3. as in 7.7, replacing F2 with F1.
95a43f69d0da78c0cb804b6ea6c907d6e831a203Christian Maeder9. for each sort relation "S1,S2" in Sigma1,
95a43f69d0da78c0cb804b6ea6c907d6e831a203Christian Maeder 9.1. compute S3=(S1 via Mrph) and S4=(S2 via Mrph)
10e12ec6ab28a40706609341c727422a0cd8d34dChristian Maeder 9.2. add sort relation "S3,S4" in Sigma2.
2ed75b9c0aced535e9bc446cd294fd0f530e7fe0Christian Maeder10. Compute transitive closure of subsorting relation in Sigma2.
31009d997a07e58087aa8acb84bc6ac90cb82942Till MossakowskiinducedFromMorphism :: (Pretty e, Pretty f) =>
b73d620aafdd5aef1d6dfbc5adc2060aa38818a9Christian Maeder m -> RawSymbolMap -> Sign f e -> Result (Morphism f e m)
120eec9ff1748e1ae786e2ab073234198bc0f701Christian MaederinducedFromMorphism extEm rmap sigma = do
e953bea49e7f0e1a43bccf2a66c5e2a2b50848e0Christian Maeder -- ??? Missing: check preservation of overloading relation
95a43f69d0da78c0cb804b6ea6c907d6e831a203Christian Maeder -- first check: do all source raw symbols match with source signature?
95a43f69d0da78c0cb804b6ea6c907d6e831a203Christian Maeder let syms = symOf sigma
120eec9ff1748e1ae786e2ab073234198bc0f701Christian Maeder sortsSigma = sortSet sigma
31009d997a07e58087aa8acb84bc6ac90cb82942Till Mossakowski incorrectRsyms = Map.foldWithKey
b73d620aafdd5aef1d6dfbc5adc2060aa38818a9Christian Maeder (\rsy _ -> if any (matchesND rsy) $ Set.toList syms
95a43f69d0da78c0cb804b6ea6c907d6e831a203Christian Maeder matchesND rsy sy =
95a43f69d0da78c0cb804b6ea6c907d6e831a203Christian Maeder sy `matches` rsy &&
62e5d73e5f0b5b4df9999aa4e523ed8f54cc24a6Christian Maeder ASymbol _ -> True
95a43f69d0da78c0cb804b6ea6c907d6e831a203Christian Maeder -- unqualified raw symbols need some matching symbol
120eec9ff1748e1ae786e2ab073234198bc0f701Christian Maeder -- that is not directly mapped
b03274844ecd270f9e9331f51cc4236a33e2e671Christian Maeder _ -> Map.lookup (ASymbol sy) rmap == Nothing
120eec9ff1748e1ae786e2ab073234198bc0f701Christian Maeder -- ... if not, generate an error
120eec9ff1748e1ae786e2ab073234198bc0f701Christian Maeder if Set.null incorrectRsyms then return () else fatal_error
95a43f69d0da78c0cb804b6ea6c907d6e831a203Christian Maeder ("the following symbols: "
120eec9ff1748e1ae786e2ab073234198bc0f701Christian Maeder ++ showDoc incorrectRsyms
b2e92fd7a332d07a52e0284ea7a40618e0ff5656Christian Maeder "\nare already mapped directly or do not match with signature\n"
b2e92fd7a332d07a52e0284ea7a40618e0ff5656Christian Maeder ++ showDoc sigma "")
6948b7295a0521212803f15cf919395d2073e2c9Christian Maeder $ getSetRange incorrectRsyms
120eec9ff1748e1ae786e2ab073234198bc0f701Christian Maeder -- compute the sort map (as a Map)
120eec9ff1748e1ae786e2ab073234198bc0f701Christian Maeder (\s m -> do s' <- sortFun rmap s
b2e92fd7a332d07a52e0284ea7a40618e0ff5656Christian Maeder if s' == s then m else do
b2e92fd7a332d07a52e0284ea7a40618e0ff5656Christian Maeder return $ Map.insert s s' m1)
96caff87d2db43ba90e69e5ac3adb24c9f88b3deChristian Maeder (return Map.empty) sortsSigma
120eec9ff1748e1ae786e2ab073234198bc0f701Christian Maeder -- compute the op map (as a Map)
95a43f69d0da78c0cb804b6ea6c907d6e831a203Christian Maeder op_Map <- Map.foldWithKey (opFun rmap sort_Map)
120eec9ff1748e1ae786e2ab073234198bc0f701Christian Maeder (return Map.empty) (opMap sigma)
f45fad43ee1673ab280fbc700821d5d20a493eaaChristian Maeder -- compute the pred map (as a Map)
f45fad43ee1673ab280fbc700821d5d20a493eaaChristian Maeder pred_Map <- Map.foldWithKey (predFun rmap sort_Map)
f45fad43ee1673ab280fbc700821d5d20a493eaaChristian Maeder (return Map.empty) (predMap sigma)
f45fad43ee1673ab280fbc700821d5d20a493eaaChristian Maeder -- compute target signature
f45fad43ee1673ab280fbc700821d5d20a493eaaChristian Maeder {sortSet = Set.map (mapSort sort_Map) sortsSigma,
f45fad43ee1673ab280fbc700821d5d20a493eaaChristian Maeder sortRel = Rel.transClosure $ Rel.irreflex $
f45fad43ee1673ab280fbc700821d5d20a493eaaChristian Maeder Rel.map (mapSort sort_Map) (sortRel sigma),
f45fad43ee1673ab280fbc700821d5d20a493eaaChristian Maeder opMap = Map.foldWithKey (mapOps sort_Map op_Map)
120eec9ff1748e1ae786e2ab073234198bc0f701Christian Maeder assocOps = Map.foldWithKey (mapOps sort_Map op_Map)
120eec9ff1748e1ae786e2ab073234198bc0f701Christian Maeder Map.empty (assocOps sigma),
120eec9ff1748e1ae786e2ab073234198bc0f701Christian Maeder predMap = Map.foldWithKey (mapPreds sort_Map pred_Map)
f5002b03ad30aeef45e2c2254dd2ede20efbaa5eTill Mossakowski Map.empty (predMap sigma),
cfbe82ead3f3127387072a21cc151e39f4fa51c6Christian Maeder -- return assembled morphism
cfbe82ead3f3127387072a21cc151e39f4fa51c6Christian Maeder return (embedMorphism extEm sigma sigma')
cfbe82ead3f3127387072a21cc151e39f4fa51c6Christian Maeder { sort_map = sort_Map
be5ff99194b2ba0a1a35093e0ea21d4da332b526Christian Maeder , fun_map = op_Map
3fe83d4c932a8266edcf0304a97814c59821d91fChristian Maeder , pred_map = pred_Map }
f45fad43ee1673ab280fbc700821d5d20a493eaaChristian Maeder -- the sorts of the source signature
e0f1794e365dd347e97b37d7d22b2fce27296fa1Christian Maeder -- sortFun is the sort map as a Haskell function
cfbe82ead3f3127387072a21cc151e39f4fa51c6Christian MaedersortFun :: RawSymbolMap -> Id -> Result Id
120eec9ff1748e1ae786e2ab073234198bc0f701Christian MaedersortFun rmap s =
31009d997a07e58087aa8acb84bc6ac90cb82942Till Mossakowski -- rsys contains the raw symbols to which s is mapped to
120eec9ff1748e1ae786e2ab073234198bc0f701Christian Maeder if Set.null rsys then return s -- use default = identity mapping
3fe83d4c932a8266edcf0304a97814c59821d91fChristian Maeder return $ rawSymName $ Set.findMin rsys -- take the unique rsy
3fe83d4c932a8266edcf0304a97814c59821d91fChristian Maeder else plain_error s -- ambiguity! generate an error
3fe83d4c932a8266edcf0304a97814c59821d91fChristian Maeder ("Sort " ++ showId s
95a43f69d0da78c0cb804b6ea6c907d6e831a203Christian Maeder " is mapped ambiguously: " ++ showDoc rsys "")
be5ff99194b2ba0a1a35093e0ea21d4da332b526Christian Maeder $ getSetRange rsys
95a43f69d0da78c0cb804b6ea6c907d6e831a203Christian Maeder -- get all raw symbols to which s is mapped to
120eec9ff1748e1ae786e2ab073234198bc0f701Christian Maeder rsys = Set.unions $ map ( \ x -> case Map.lookup x rmap of
57d320fc4d0fe1a1c08cfe6cd9ebec09b86c2cbfTill Mossakowski [ASymbol $ idToSortSymbol s, AnID s, AKindedId SortKind s]
3fe83d4c932a8266edcf0304a97814c59821d91fChristian Maeder {- to a Fun_map, add everything resulting from mapping (id, ots)
3fe83d4c932a8266edcf0304a97814c59821d91fChristian Maeder according to rmap -}
3fe83d4c932a8266edcf0304a97814c59821d91fChristian MaederopFun :: RawSymbolMap -> Sort_map -> Id -> Set.Set OpType
f1b1b26670c370355bc36a27c99ed974ab223537Christian Maeder -> Result Fun_map -> Result Fun_map
f1b1b26670c370355bc36a27c99ed974ab223537Christian MaederopFun rmap sort_Map ide ots m =
3fe83d4c932a8266edcf0304a97814c59821d91fChristian Maeder -- first consider all directly mapped profiles
120eec9ff1748e1ae786e2ab073234198bc0f701Christian Maeder let (ots1,m1) = Set.fold (directOpMap rmap sort_Map ide) (Set.empty,m) ots
f45fad43ee1673ab280fbc700821d5d20a493eaaChristian Maeder -- now try the remaining ones with (un)kinded raw symbol
f45fad43ee1673ab280fbc700821d5d20a493eaaChristian Maeder in case (Map.lookup (AKindedId FunKind ide) rmap,
fb88eac77c89b668f5c306173a6fbe2d513e4bccMarkus Gross Map.lookup (AnID ide) rmap) of
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder (Just rsy1, Just rsy2) ->
fb88eac77c89b668f5c306173a6fbe2d513e4bccMarkus Gross plain_error m'
d24317c8197e565e60c8f41309de246249c1e57eChristian Maeder ("Operation " ++ showId ide
f45fad43ee1673ab280fbc700821d5d20a493eaaChristian Maeder " is mapped twice: "
f45fad43ee1673ab280fbc700821d5d20a493eaaChristian Maeder ++ showDoc (rsy1, rsy2) "")
95a43f69d0da78c0cb804b6ea6c907d6e831a203Christian Maeder $ appRange (getRange rsy1) $ getRange rsy2
4b136ad539bd9f4e115dff4eee4d552a42d4437eChristian Maeder (Just rsy, Nothing) ->
b03274844ecd270f9e9331f51cc4236a33e2e671Christian Maeder Set.fold (insertmapOpSym sort_Map ide rsy) m1 ots1
4b136ad539bd9f4e115dff4eee4d552a42d4437eChristian Maeder (Nothing, Just rsy) ->
edd35c6c970fa1707dc6ad7a3ba26119e0046223Cui Jian Set.fold (insertmapOpSym sort_Map ide rsy) m1 ots1
0ea3fd177b4e67c85346500a53cebe2f9fae4cb8Christian Maeder -- Anything not mapped explicitly is left unchanged
0ea3fd177b4e67c85346500a53cebe2f9fae4cb8Christian Maeder (Nothing,Nothing) -> m1
e89d9f79e335f5051eb8d8d913b0b2c716d4e57aChristian Maeder -- try to map an operation symbol directly
e89d9f79e335f5051eb8d8d913b0b2c716d4e57aChristian Maeder -- collect all opTypes that cannot be mapped directly
e89d9f79e335f5051eb8d8d913b0b2c716d4e57aChristian MaederdirectOpMap :: RawSymbolMap -> Sort_map -> Id -> OpType
4b136ad539bd9f4e115dff4eee4d552a42d4437eChristian Maeder -> (Set.Set OpType,Result Fun_map)
709653bffee501341e2fdc55b9223e4921047c65Till Mossakowski -> (Set.Set OpType,Result Fun_map)
95a43f69d0da78c0cb804b6ea6c907d6e831a203Christian MaederdirectOpMap rmap sort_Map ide' ot (ots',m') =
e89d9f79e335f5051eb8d8d913b0b2c716d4e57aChristian Maeder case Map.lookup (ASymbol (idToOpSymbol ide' ot)) rmap of
b73d620aafdd5aef1d6dfbc5adc2060aa38818a9Christian Maeder (ots',insertmapOpSym sort_Map ide' rsy ot m')
e89d9f79e335f5051eb8d8d913b0b2c716d4e57aChristian Maeder Nothing -> (Set.insert ot ots',m')
def1779795c7ca2a1ae420e43e90cbd66c438faaTill Mossakowski -- map op symbol (ide,ot) to raw symbol rsy
afddef51d985ac2ea76a6bd846f04cbbc4311305Razvan PascanumappedOpSym :: Sort_map -> Id -> OpType -> RawSymbol -> Result (Id,FunKind)
b1789f0752d87f0f0dac2b2427794d18d2a21b41Christian MaedermappedOpSym sort_Map ide ot rsy =
f4ae50539e67874b6162f8334f6782a0d66acefaCui Jian let opSym = "Operation symbol " ++ showDoc (idToOpSymbol ide ot)
95cb954c00f873306bf1a60b62d3209d3cff4102Christian Maeder " is mapped to "
b73d620aafdd5aef1d6dfbc5adc2060aa38818a9Christian Maeder in case rsy of
95cb954c00f873306bf1a60b62d3209d3cff4102Christian Maeder ASymbol (Symbol ide' (OpAsItemType ot')) ->
95cb954c00f873306bf1a60b62d3209d3cff4102Christian Maeder if compatibleOpTypes (mapOpType sort_Map ot) ot'
e1c24b1dbf5cb1c9bb22b14a40167a4ba7806501Christian Maeder then return (ide',opKind ot')
e1c24b1dbf5cb1c9bb22b14a40167a4ba7806501Christian Maeder else plain_error (ide, opKind ot)
e1c24b1dbf5cb1c9bb22b14a40167a4ba7806501Christian Maeder (opSym ++ "type " ++ showDoc ot'
95cb954c00f873306bf1a60b62d3209d3cff4102Christian Maeder " but should be mapped to type " ++
95cb954c00f873306bf1a60b62d3209d3cff4102Christian Maeder showDoc (mapOpType sort_Map ot)"") $ getRange rsy
95cb954c00f873306bf1a60b62d3209d3cff4102Christian Maeder AnID ide' -> return (ide',opKind ot)
95cb954c00f873306bf1a60b62d3209d3cff4102Christian Maeder AKindedId FunKind ide' -> return (ide',opKind ot)
95cb954c00f873306bf1a60b62d3209d3cff4102Christian Maeder _ -> plain_error (ide,opKind ot)
e1c24b1dbf5cb1c9bb22b14a40167a4ba7806501Christian Maeder (opSym ++ "symbol of wrong kind: " ++ showDoc rsy "")
e1c24b1dbf5cb1c9bb22b14a40167a4ba7806501Christian Maeder $ getRange rsy
e1c24b1dbf5cb1c9bb22b14a40167a4ba7806501Christian Maeder -- insert mapping of op symbol (ide,ot) to raw symbol rsy into m
e1c24b1dbf5cb1c9bb22b14a40167a4ba7806501Christian MaederinsertmapOpSym :: Sort_map -> Id -> RawSymbol -> OpType
e1c24b1dbf5cb1c9bb22b14a40167a4ba7806501Christian Maeder -> Result Fun_map -> Result Fun_map
return (Map.insert (ide, ot {opKind = Partial}) (ide',kind') m1)
mapOps :: Sort_map -> Fun_map -> Id -> Set.Set OpType -> OpMap -> OpMap
Set.fold mapOp m ots
in Rel.setInsert ide' ot' m1
predFun :: RawSymbolMap -> Sort_map -> Id -> Set.Set PredType
let (pts1,m1) = Set.fold (directPredMap rmap sort_Map ide)
(Set.empty,m) pts
in case (Map.lookup (AKindedId PredKind ide) rmap,
Map.lookup (AnID ide) rmap) of
Set.fold (insertmapPredSym sort_Map ide rsy) m1 pts1
Set.fold (insertmapPredSym sort_Map ide rsy) m1 pts1
-> (Set.Set PredType,Result Pred_map)
-> (Set.Set PredType,Result Pred_map)
case Map.lookup (ASymbol (idToPredSymbol ide pt)) rmap of
Nothing -> (Set.insert pt pts,m)
return (Map.insert (ide, pt) ide' m1)
mapPreds :: Sort_map -> Pred_map -> Id -> Set.Set PredType
Set.fold mapPred m pts
in Rel.setInsert ide' pt' m1
The algorithm has additionally to take care of default values (i.e.
1. compute the morphism mor1 induced by rmap and sigma1 (i.e. the renaming)
can be mapped to each sym2 in symset1 union symset2 (i.e., they are
both sorts or operations/predicates of the same arity, and
(i.e. one with minimal cardinality of symset1 union symset2).
(it can clash if sym1 and sym2 are operations/predicates,
5.5. for each sub/supersort s of sym1, restrict the possible
mappings of s in posmap to sub/supersorts of sym2
5.6. for each operation/predicate f in dom(posmap) involving
5.7. if sym1 and sym2 are operations/predicates,
Map.foldWithKey match1 True rmap
case Map.lookup (idToSortSymbol s1) smap of
-- (this can fail if sym1 and sym2 are operations/predicates,
then Just $ Map.insert sym1 sym2 akmap
type PosMap = (Map.Map Symbol (SymbolSet,(Bool,Int)),
Map.Map (Bool,Int) [(Symbol,SymbolSet)])
(Map.delete sym posmap1,
Map.update removeSym1 card posmap2)
(Map.insert sym (symset,card) posmap1,
where card = (postponeEntry sym symset,Set.size symset)
Set.fold restrictPosMap1 posmap' symset1'
case Map.lookup sym1 posmap1 of
addToPosmap sym1 (symset1 `Set.intersection` symset2)
-- for each sub/supersort s of sym1 in sigma1, restrict the possible
-- mappings of s in posmap to sub/supersorts of sym2 in sigma2
sub1 = Set.insert s1 $ subsortsOf s1 sigma1
sub2 = Set.insert s2 $ subsortsOf s2 sigma2
subsyms1 = Set.map idToSortSymbol sub1
subsyms2 = Set.map idToSortSymbol sub2
super1 = Set.insert s1 $ supersortsOf s1 sigma1
super2 = Set.insert s2 $ supersortsOf s2 sigma2
supersyms1 = Set.map idToSortSymbol super1
supersyms2 = Set.map idToSortSymbol super2
case Map.lookup sym1 posmap1 of
if sym2 `Set.member` symset
then Just $ addToPosmap sym1 (Set.singleton sym2)
$ Set.findMin sortSet2 }
let addCard sym s = (s,(postponeEntry sym s,Set.size s))
ins1 sym = Map.insert sym
(addCard sym $ Set.filter (canBeMapped rmap sym) symset2)
case Map.lookup (True,0) posmap2 of
smap <- tryToInduce sigma1 sigma2 Map.empty posmap
$ concatMapRange getRange $ Map.keys rmap
if Map.null posmap2 then return $ Just akmap -- 4a.
(card,(sym1,symset):_symsets) = Map.findMin posmap2
(symset1,symset2) = Set.partition (preservesName sym1) symset
-> Set.Set Symbol -> Result (Maybe SymbolMap)
Set.fold (tryToInduce2 sigma1 sigma2 akmap posmap sym1)
-- for an operation/predicate symbol
let shorten = Map.filterWithKey (/=) in
"") $ concatMapRange getRange $ Map.elems $ shorten smap1
if not (sys `Set.isSubsetOf` symset) -- 2.
, opMap = Map.empty
, predMap = Map.empty }) sys -- 4.
sigma2 = sigma1 {sortRel = sortRel sigma `Rel.restrict` sortSet sigma1}
sigma1 {sortSet = Set.insert (symName sy) $ sortSet sigma1}
sigma1 {sortSet = foldr Set.insert (sortSet sigma1) (opRes ot:opArgs ot),
opMap = Rel.setInsert (symName sy) ot $ opMap sigma1}
sigma1 {sortSet = foldr Set.insert (sortSet sigma1) (predArgs pt),
predMap = Rel.setInsert (symName sy) pt $ predMap sigma1}
3.1.1.2. For each function/predicate symbol in
(not (symset `Set.isSubsetOf` symset0)) -- 2.
symset1 = Set.fold revealSym' symset0 symset -- 3.
Set.filter (not . profileContains (symName sy) . symbType)
$ Set.delete sy symset1'
Set.delete sy symset1'
Set.delete sy symset1'
getSetRange :: PosItem a => Set.Set a -> Range
getSetRange = concatMapRange getRange . Set.toList