Morphism.hs revision 3df765bba27034f17ba60ee9b90d7dbd3643ea9e
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus RoggenbachModule : $Header$
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus RoggenbachDescription : Symbols and signature morphisms for the CASL logic
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus RoggenbachCopyright : (c) Christian Maeder, Till Mossakowski and Uni Bremen 2002-2004
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus RoggenbachLicense : similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus RoggenbachMaintainer : Christian.Maeder@dfki.de
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus RoggenbachStability : provisional
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus RoggenbachPortability : portable
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus RoggenbachSymbols and signature morphisms for the CASL logic
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbachissue warning for symbols lists like __ * __, __ + __: Elem * Elem -> Elem
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbachthe qualification only applies to __+__ !
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbachpossibly reuse SYMB_KIND for Kind
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbachimport qualified Data.Map as Map
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbachimport qualified Data.Set as Set
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbachimport qualified Common.Lib.Rel as Rel
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbachtype SymbolSet = Set.Set Symbol
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbachtype SymbolMap = Map.Map Symbol Symbol
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbachdata RawSymbol = ASymbol Symbol | AnID Id | AKindedId Kind Id
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbach deriving (Show, Eq, Ord)
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbachinstance PosItem RawSymbol where
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbach ASymbol s -> getRange s
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbach AnID i -> getRange i
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbach AKindedId _ i -> getRange i
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbachtype RawSymbolSet = Set.Set RawSymbol
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbachtype RawSymbolMap = Map.Map RawSymbol RawSymbol
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbachdata Kind = SortKind | FunKind | PredKind
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbach deriving (Show, Eq, Ord)
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbachtype Sort_map = Map.Map SORT SORT
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbach-- allways use the partial profile as key!
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbachtype Fun_map = Map.Map (Id,OpType) (Id, FunKind)
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbachtype Pred_map = Map.Map (Id,PredType) Id
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbachdata Morphism f e m = Morphism
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbach { msource :: Sign f e
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbach , mtarget :: Sign f e
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbach , sort_map :: Sort_map
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbach , fun_map :: Fun_map
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbach , pred_map :: Pred_map
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbach , extended_map :: m
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbach } deriving (Eq, Show)
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus RoggenbachmapSort :: Sort_map -> SORT -> SORT
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus RoggenbachmapSort sorts s = Map.findWithDefault s s sorts
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus RoggenbachmapOpType :: Sort_map -> OpType -> OpType
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus RoggenbachmapOpType sorts t = if Map.null sorts then t else
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbach t { opArgs = map (mapSort sorts) $ opArgs t
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbach , opRes = mapSort sorts $ opRes t }
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus RoggenbachmapOpTypeK :: Sort_map -> FunKind -> OpType -> OpType
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus RoggenbachmapOpTypeK sorts k t = makeTotal k $ mapOpType sorts t
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus RoggenbachmakeTotal :: FunKind -> OpType -> OpType
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus RoggenbachmakeTotal Total t = t { opKind = Total }
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus RoggenbachmakeTotal _ t = t
case Map.lookup (i, ot {opKind = Partial} ) fMap of
mapPredType sorts t = if Map.null sorts then t else
(Map.findWithDefault i (i, pt) fMap, mapPredType sMap pt)
, sort_map = Map.empty
, fun_map = Map.empty
, pred_map = Map.empty
let sorts = Set.map idToSortSymbol $ sortSet sigma
ops = Set.fromList $
$ Set.toList ts) $
Map.toList $ opMap sigma
preds = Set.fromList $
$ Set.toList ts) $
Map.toList $ predMap sigma
in Set.unions [sorts, ops, preds]
foldl insertRsys (return Map.empty) (concat ls)
case Map.lookup rsy1 m1 of
Nothing -> return $ Map.insert rsy1 rsy2 m1
case Map.lookup (Symbol {symName = s, symbType = SortAsItemType}) smap
Map.insert s t m
mapFun i ots m = Set.fold (insFun i) m ots
case Map.lookup (Symbol {symName = i, symbType = OpAsItemType ot}) smap
else Map.insert (i, ot {opKind = Partial}) (j, k) m
mapPred i pts m = Set.fold (insPred i) m pts
case Map.lookup (Symbol {symName = i, symbType = PredAsItemType pt}) smap
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
where src = Map.keys symmap
pretty (Map.filterWithKey (/=) $ morphismToSymbMap mor)