Morphism.hs revision 831bfb0c3598d0508b976cd36fa97c65839ed5a3
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai CodescuModule : $Header$
e9458b1a7a19a63aa4c179f9ab20f4d50681c168Jens ElknerCopyright : (c) Christian Maeder, Till Mossakowski and Uni Bremen 2002-2004
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai CodescuLicense : similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai CodescuMaintainer : maeder@tzi.de
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai CodescuStability : provisional
1e09f2a31712311820bd128b55ab4792603959bbJonathan von SchroederPortability : portable
1e09f2a31712311820bd128b55ab4792603959bbJonathan von SchroederSymbols and signature morphisms for the CASL logic
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescuissue warning for symbols lists like __ * __, __ + __: Elem * Elem -> Elem
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescuthe qualification only applies to __+__ !
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescupossibly reuse SYMB_KIND for Kind
a6c883b6eaec47ce57e62656b09577cab13e1be7Jonathan von Schroederimport qualified Common.Lib.Map as Map
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescuimport qualified Common.Lib.Set as Set
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescuimport qualified Common.Lib.Rel as Rel
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescudata SymbType = OpAsItemType OpType
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu -- since symbols do not speak about totality, the totality
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu -- information in OpType has to be ignored
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu | PredAsItemType PredType
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu | SortAsItemType
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu deriving (Show)
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu-- Ordering and equality of symbol types has to ingore totality information
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescuinstance Ord SymbType where
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu compare (OpAsItemType ot1) (OpAsItemType ot2) =
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu compare (opArgs ot1,opRes ot1) (opArgs ot2,opRes ot2)
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu compare (OpAsItemType _) _ = LT
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu compare (PredAsItemType pt1) (PredAsItemType pt2) =
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu compare pt1 pt2
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu compare (PredAsItemType _) (OpAsItemType _) = GT
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu compare (PredAsItemType _) SortAsItemType = LT
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu compare SortAsItemType SortAsItemType = EQ
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu compare SortAsItemType _ = GT
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescuinstance Eq SymbType where
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu t1 == t2 = compare t1 t2 == EQ
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescudata Symbol = Symbol {symName :: Id, symbType :: SymbType}
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu deriving (Show, Eq, Ord)
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescuinstance PosItem Symbol where
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu getRange = getRange . symName
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescutype SymbolSet = Set.Set Symbol
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescutype SymbolMap = Map.Map Symbol Symbol
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescudata RawSymbol = ASymbol Symbol | AnID Id | AKindedId Kind Id
34626ff7551c3ceead22d049427a0b0e0d33a2e6Christian Maeder deriving (Show, Eq, Ord)
34626ff7551c3ceead22d049427a0b0e0d33a2e6Christian Maederinstance PosItem RawSymbol where
34626ff7551c3ceead22d049427a0b0e0d33a2e6Christian Maeder getRange rs =
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu ASymbol s -> getRange s
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu AnID i -> getRange i
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu AKindedId _ i -> getRange i
34626ff7551c3ceead22d049427a0b0e0d33a2e6Christian Maedertype RawSymbolSet = Set.Set RawSymbol
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescutype RawSymbolMap = Map.Map RawSymbol RawSymbol
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescudata Kind = SortKind | FunKind | PredKind
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu deriving (Show, Eq, Ord)
3dfdf17a4bbad3dde93fab8ac588d5acda8a6f42Jonathan von Schroedertype Sort_map = Map.Map SORT SORT
34626ff7551c3ceead22d049427a0b0e0d33a2e6Christian Maeder-- allways use the partial profile as key!
34626ff7551c3ceead22d049427a0b0e0d33a2e6Christian Maedertype Fun_map = Map.Map (Id,OpType) (Id, FunKind)
34626ff7551c3ceead22d049427a0b0e0d33a2e6Christian Maedertype Pred_map = Map.Map (Id,PredType) Id
1dfa74e3151ce63c12483d7268fe096d82e82076Jonathan von Schroederdata Morphism f e m = Morphism {msource :: Sign f e,
1dfa74e3151ce63c12483d7268fe096d82e82076Jonathan von Schroeder mtarget :: Sign f e,
34626ff7551c3ceead22d049427a0b0e0d33a2e6Christian Maeder sort_map :: Sort_map,
34626ff7551c3ceead22d049427a0b0e0d33a2e6Christian Maeder fun_map :: Fun_map,
34626ff7551c3ceead22d049427a0b0e0d33a2e6Christian Maeder pred_map :: Pred_map,
34626ff7551c3ceead22d049427a0b0e0d33a2e6Christian Maeder extended_map :: m}
34626ff7551c3ceead22d049427a0b0e0d33a2e6Christian Maeder deriving (Eq, Show)
1dfa74e3151ce63c12483d7268fe096d82e82076Jonathan von SchroedermapSort :: Sort_map -> SORT -> SORT
1dfa74e3151ce63c12483d7268fe096d82e82076Jonathan von SchroedermapSort sorts s = Map.findWithDefault s s sorts
3dfdf17a4bbad3dde93fab8ac588d5acda8a6f42Jonathan von SchroedermapOpType :: Sort_map -> OpType -> OpType
a6c883b6eaec47ce57e62656b09577cab13e1be7Jonathan von SchroedermapOpType sorts t = if Map.null sorts then t else
34626ff7551c3ceead22d049427a0b0e0d33a2e6Christian Maeder t { opArgs = map (mapSort sorts) $ opArgs t
a6c883b6eaec47ce57e62656b09577cab13e1be7Jonathan von Schroeder , opRes = mapSort sorts $ opRes t }
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroedermapOpTypeK :: Sort_map -> FunKind -> OpType -> OpType
69fd87e4b078ee518487bbfa5f4589392a132993Jonathan von SchroedermapOpTypeK sorts k t = makeTotal k $ mapOpType sorts t
a6c883b6eaec47ce57e62656b09577cab13e1be7Jonathan von SchroedermakeTotal :: FunKind -> OpType -> OpType
34626ff7551c3ceead22d049427a0b0e0d33a2e6Christian MaedermakeTotal Total t = t { opKind = Total }
1dfa74e3151ce63c12483d7268fe096d82e82076Jonathan von SchroedermakeTotal _ t = t
6164cea1d448f9e9dccd9b4c79e57763b2758ddeJonathan von SchroedermapOpSym :: Sort_map -> Fun_map -> (Id, OpType) -> (Id, OpType)
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroedermapOpSym sMap fMap (i, ot) =
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von Schroeder let mot = mapOpType sMap ot in
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von Schroeder case Map.lookup (i, ot {opKind = Partial} ) fMap of
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von Schroeder Nothing -> (i, mot)
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von Schroeder Just (j, k) -> (j, makeTotal k mot)
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von Schroeder-- | Check if two OpTypes are equal modulo totality or partiality
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von SchroedercompatibleOpTypes :: OpType -> OpType -> Bool
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von SchroedercompatibleOpTypes ot1 ot2 = opArgs ot1 == opArgs ot2 && opRes ot1 == opRes ot2
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von SchroedermapPredType :: Sort_map -> PredType -> PredType
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von SchroedermapPredType sorts t = if Map.null sorts then t else
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von Schroeder t { predArgs = map (mapSort sorts) $ predArgs t }
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroedermapPredSym :: Sort_map -> Pred_map -> (Id, PredType) -> (Id, PredType)
3f232df590a3fafc60a218589c3a3f0a3c359b44Jonathan von SchroedermapPredSym sMap fMap (i, pt) =
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder (Map.findWithDefault i (i, pt) fMap, mapPredType sMap pt)
3f232df590a3fafc60a218589c3a3f0a3c359b44Jonathan von Schroedertype Ext f e m = Sign f e -> Sign f e -> m
ae20fe3ef7832827a9ee018899f30eeae98a706dJonathan von SchroederembedMorphism :: Ext f e m -> Sign f e -> Sign f e -> Morphism f e m
34626ff7551c3ceead22d049427a0b0e0d33a2e6Christian MaederembedMorphism extEm a b =
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von Schroeder , extended_map = extEm a b
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederidToSortSymbol :: Id -> Symbol
3f232df590a3fafc60a218589c3a3f0a3c359b44Jonathan von SchroederidToSortSymbol idt = Symbol idt SortAsItemType
3f232df590a3fafc60a218589c3a3f0a3c359b44Jonathan von SchroederidToOpSymbol :: Id -> OpType -> Symbol
87836973cf6a4ed22295454c58242fc926a83f42Jonathan von SchroederidToOpSymbol idt typ = Symbol idt (OpAsItemType typ)
87836973cf6a4ed22295454c58242fc926a83f42Jonathan von SchroederidToPredSymbol :: Id -> PredType -> Symbol
ae20fe3ef7832827a9ee018899f30eeae98a706dJonathan von SchroederidToPredSymbol idt typ = Symbol idt (PredAsItemType typ)
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von SchroedersymbTypeToKind :: SymbType -> Kind
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von SchroedersymbTypeToKind (OpAsItemType _) = FunKind
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von SchroedersymbTypeToKind (PredAsItemType _) = PredKind
1dfa74e3151ce63c12483d7268fe096d82e82076Jonathan von SchroedersymbTypeToKind SortAsItemType = SortKind
1dfa74e3151ce63c12483d7268fe096d82e82076Jonathan von SchroedersymbolToRaw :: Symbol -> RawSymbol
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von SchroedersymbolToRaw sym = ASymbol sym
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von SchroederidToRaw :: Id -> RawSymbol
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von SchroederidToRaw x = AnID x
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von SchroederrawSymName :: RawSymbol -> Id
1dfa74e3151ce63c12483d7268fe096d82e82076Jonathan von SchroederrawSymName (ASymbol sym) = symName sym
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederrawSymName (AnID i) = i
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von SchroederrawSymName (AKindedId _ i) = i
1dfa74e3151ce63c12483d7268fe096d82e82076Jonathan von SchroedersymOf :: Sign f e -> SymbolSet
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von Schroeder let sorts = Set.map idToSortSymbol $ sortSet sigma
ab148c20add4ca4c956e36f56859dcc5c4dde187Jonathan von Schroeder concatMap (\ (i, ts) -> map ( \ t -> idToOpSymbol i t)
ab148c20add4ca4c956e36f56859dcc5c4dde187Jonathan von Schroeder concatMap (\ (i, ts) -> map ( \ t -> idToPredSymbol i t)
34626ff7551c3ceead22d049427a0b0e0d33a2e6Christian Maeder Map.toList $ predMap sigma
ab148c20add4ca4c956e36f56859dcc5c4dde187Jonathan von Schroeder in Set.unions [sorts, ops, preds]
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von SchroederstatSymbMapItems :: [SYMB_MAP_ITEMS] -> Result RawSymbolMap
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von SchroederstatSymbMapItems sl = do
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder ls <- sequence $ map s1 sl
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder foldl insertRsys (return Map.empty) (concat ls)
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von Schroeder s1 (Symb_map_items kind l _) = sequence (map (symbOrMapToRaw kind) l)
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder insertRsys m (rsy1,rsy2) = do
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von Schroeder Nothing -> return $ Map.insert rsy1 rsy2 m1
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von Schroeder plain_error m1 ("Symbol " ++ showPretty rsy1 " mapped twice to "
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder ++ showPretty rsy2 " and " ++ showPretty rsy3 "") nullRange
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederpairM :: Monad m => (m a,m b) -> m (a,b)
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von SchroederpairM (x,y) = do
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroedersymbOrMapToRaw :: SYMB_KIND -> SYMB_OR_MAP -> Result (RawSymbol,RawSymbol)
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroedersymbOrMapToRaw k (Symb s) = pairM (symbToRaw k s,symbToRaw k s)
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroedersymbOrMapToRaw k (Symb_map s t _) = pairM (symbToRaw k s,symbToRaw k t)
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederstatSymbItems :: [SYMB_ITEMS] -> Result [RawSymbol]
ab148c20add4ca4c956e36f56859dcc5c4dde187Jonathan von SchroederstatSymbItems sl =
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von Schroeder fmap concat (sequence (map s1 sl))
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von Schroeder where s1 (Symb_items kind l _) = sequence (map (symbToRaw kind) l)
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von SchroedersymbToRaw :: SYMB_KIND -> SYMB -> Result RawSymbol
ab148c20add4ca4c956e36f56859dcc5c4dde187Jonathan von SchroedersymbToRaw k (Symb_id idt) = return $ symbKindToRaw k idt
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroedersymbToRaw k (Qual_id idt t _) = typedSymbKindToRaw k idt t
87836973cf6a4ed22295454c58242fc926a83f42Jonathan von SchroedersymbKindToRaw :: SYMB_KIND -> Id -> RawSymbol
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von SchroedersymbKindToRaw sk idt = case sk of
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von Schroeder Implicit -> AnID idt
ab148c20add4ca4c956e36f56859dcc5c4dde187Jonathan von Schroeder _ -> AKindedId (case sk of
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von Schroeder Sorts_kind -> SortKind
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von Schroeder Preds_kind -> PredKind
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu _ -> FunKind) idt
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai CodescutypedSymbKindToRaw :: SYMB_KIND -> Id -> TYPE -> Result RawSymbol
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai CodescutypedSymbKindToRaw k idt t =
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu let err = plain_error (AnID idt)
34626ff7551c3ceead22d049427a0b0e0d33a2e6Christian Maeder (showPretty idt ":" ++ showPretty t
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu "does not have kind" ++ showPretty k "") nullRange
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu aSymb = ASymbol $ case t of
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu O_type ot -> idToOpSymbol idt $ toOpType ot
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu P_type pt -> idToPredSymbol idt $ toPredType pt
ae20fe3ef7832827a9ee018899f30eeae98a706dJonathan von Schroeder -- in case of ambiguity, return a constant function type
9e30b0e74760a90c03c444cd290ba9af9d917f6eChristian Maeder -- this deviates from the CASL summary !!!
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu let ot = OpType {opKind = Total, opArgs = [], opRes = s}
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von Schroeder in idToOpSymbol idt ot
6f3b0aa6cccf5105b22a1ae366ff59706538d937Jonathan von Schroeder Implicit -> return aSymb
6f3b0aa6cccf5105b22a1ae366ff59706538d937Jonathan von Schroeder Sorts_kind -> return $ AKindedId SortKind idt
6f3b0aa6cccf5105b22a1ae366ff59706538d937Jonathan von Schroeder Ops_kind -> case t of
6f3b0aa6cccf5105b22a1ae366ff59706538d937Jonathan von Schroeder P_type _ -> err
6f3b0aa6cccf5105b22a1ae366ff59706538d937Jonathan von Schroeder _ -> return aSymb
6164cea1d448f9e9dccd9b4c79e57763b2758ddeJonathan von Schroeder Preds_kind -> case t of
34626ff7551c3ceead22d049427a0b0e0d33a2e6Christian Maeder O_type _ -> err
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder A_type s -> return $ ASymbol $
abbba0121ac69d254389160a7b92c52dc279b960Mihai Codescu let pt = PredType {predArgs = [s]}
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu in idToPredSymbol idt pt
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder P_type _ -> return aSymb
9e30b0e74760a90c03c444cd290ba9af9d917f6eChristian MaedersymbMapToMorphism :: Ext f e m -> Sign f e -> Sign f e
9e30b0e74760a90c03c444cd290ba9af9d917f6eChristian Maeder -> SymbolMap -> Result (Morphism f e m)
9e30b0e74760a90c03c444cd290ba9af9d917f6eChristian MaedersymbMapToMorphism extEm sigma1 sigma2 smap = let
3dfdf17a4bbad3dde93fab8ac588d5acda8a6f42Jonathan von Schroeder sort_map1 = Set.fold mapMSort Map.empty (sortSet sigma1)
9e30b0e74760a90c03c444cd290ba9af9d917f6eChristian Maeder mapMSort s m =
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu case Map.lookup (Symbol {symName = s, symbType = SortAsItemType}) smap
b93d7514eff107392e0ee8d7b659320fed06d64cJonathan von Schroeder of Just sym -> let t = symName sym in if s == t then m else
b93d7514eff107392e0ee8d7b659320fed06d64cJonathan von Schroeder fun_map1 = Map.foldWithKey mapFun Map.empty (opMap sigma1)
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von Schroeder pred_map1 = Map.foldWithKey mapPred Map.empty (predMap sigma1)
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder mapFun i ots m = Set.fold (insFun i) m ots
3596e64ec2f7c1d70dc4e975f7e3ec23a8e1eb67Jonathan von Schroeder insFun i ot m =
34626ff7551c3ceead22d049427a0b0e0d33a2e6Christian Maeder case Map.lookup (Symbol {symName = i, symbType = OpAsItemType ot}) smap
34626ff7551c3ceead22d049427a0b0e0d33a2e6Christian Maeder of Just sym -> let j = symName sym in case symbType sym of
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu OpAsItemType oty -> let k = opKind oty in
0fa7a99c279b7b59df56d86c3ada137b191fe8ebJonathan von Schroeder if j == i && opKind ot == k then m
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu else Map.insert (i, ot {opKind = Partial}) (j, k) m
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu mapPred i pts m = Set.fold (insPred i) m pts
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu insPred i pt m =
6fc41a5f93c1859888c6e6d6eb0ddff86d48fb45Mihai Codescu case Map.lookup (Symbol {symName = i, symbType = PredAsItemType pt}) smap
34626ff7551c3ceead22d049427a0b0e0d33a2e6Christian Maeder of Just sym -> let j = symName sym in case symbType sym of
PredAsItemType _ -> if i == j then m else Map.insert (i, pt) j m
Map.empty $ sortSet src
opSymMap = Map.foldWithKey
( \ i s m -> Set.fold
( \ t -> Map.insert (idToOpSymbol i t)
Map.empty $ opMap src
predSymMap = Map.foldWithKey
( \ i s m -> Set.fold
( \ t -> Map.insert (idToPredSymbol i t)
Map.empty $ predMap src
foldr Map.union sortSymMap [opSymMap,predSymMap]
sMap = if Map.null sMap2 then sMap1 else
Set.fold ( \ i ->
if i == j then id else Map.insert i j)
Map.empty $ sortSet src
fun_map = if Map.null fMap2 then fMap1 else
Map.foldWithKey ( \ i t m ->
Set.fold ( \ ot ->
Map.insert (i, ot {opKind = Partial }) (ni, k)) m t)
Map.empty $ opMap src,
pred_map = if Map.null pMap2 then pMap1 else
Map.foldWithKey ( \ i t m ->
Set.fold ( \ pt ->
if i == ni then id else Map.insert (i, pt) ni) m t)
Map.empty $ predMap src,
Map.foldWithKey (\s sset b -> b && legalSort s && all legalSort
(Set.toList sset))
True (Rel.toMap (sortRel sigma))
legalSort s = Set.member s sorts
msorts = Set.map (mapSort smap) $ sortSet s1
mops = Map.foldWithKey ( \ i ->
flip $ Set.fold ( \ ot ->
mpreds = Map.foldWithKey ( \ i ->
flip $ Set.fold ( \ pt ->
&& Set.isSubsetOf msorts (sortSet s2)
uo1 = foldr delOp (opMap s1) $ Map.keys omap1
uo2 = foldr delOp (opMap s2) $ Map.keys omap2
delOp (n, ot) m = diffMapSet m $ Map.singleton n $
Set.fromList [ot {opKind = Partial}, ot {opKind =Total}]
up1 = foldr delPred (predMap s1) $ Map.keys pmap1
up2 = foldr delPred (predMap s2) $ Map.keys pmap2
(sds, smap) = foldr ( \ (i, j) (ds, m) -> case Map.lookup i m of
Nothing -> (ds, Map.insert i j m)
(Map.toList smap2 ++ map (\ a -> (a, a))
case Map.lookup isc m of
Nothing -> (ds, Map.insert isc jsc m)
else (ds, Map.insert isc (j, Total) m) else
(sds, omap1) (Map.toList omap2 ++ concatMap
case Map.lookup isc m of
Nothing -> (ds, Map.insert isc j m)
(Map.toList pmap2 ++ concatMap ( \ (a, s) -> map
sort_map = Map.filterWithKey (/=) smap,
fun_map = Map.filterWithKey
(\ (i, ot) (j, k) -> i /= j || k == Total && Set.member ot
pred_map = Map.filterWithKey (\ (i, _) j -> i /= j) pmap,
src = Map.keys sm
printSymbolMap (Map.filterWithKey (/=) $ morphismToSymbMap mor)