PreComorphism.hs revision e9458b1a7a19a63aa4c179f9ab20f4d50681c168
0b152383e04dbeb10dba29bcdfaa0981e4d9df27Simon UlbrichtDescription : Maude Comorphisms
0b152383e04dbeb10dba29bcdfaa0981e4d9df27Simon UlbrichtCopyright : (c) Adrian Riesco, Facultad de Informatica UCM 2009
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu ProdescuLicense : GPLv2 or higher, see LICENSE.txt
0b152383e04dbeb10dba29bcdfaa0981e4d9df27Simon UlbrichtMaintainer : ariesco@fdi.ucm.es
0b152383e04dbeb10dba29bcdfaa0981e4d9df27Simon UlbrichtStability : experimental
0b152383e04dbeb10dba29bcdfaa0981e4d9df27Simon UlbrichtPortability : portable
0b152383e04dbeb10dba29bcdfaa0981e4d9df27Simon UlbrichtComorphism from Maude to CASL.
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbrichtimport qualified Data.List as List
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbrichtimport qualified Data.Set as Set
d815d2b83e945875100ceca322ebd50d96714206Simon Ulbrichtimport qualified Data.Map as Map
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbrichtimport qualified Maude.Sign as MSign
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbrichtimport qualified Maude.Sentence as MSentence
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbrichtimport qualified Maude.Morphism as MMorphism
a210c2e5add831cd438183c8602ed8e610922beaSimon Ulbrichtimport qualified Maude.AS_Maude as MAS
d815d2b83e945875100ceca322ebd50d96714206Simon Ulbrichtimport qualified Maude.Symbol as MSym
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbrichtimport qualified CASL.Sign as CSign
9da6e0cb2ea6e43f5b09dcd2a9af5468a5d0fcf4Christian Maederimport qualified CASL.Morphism as CMorphism
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbrichtimport qualified CASL.AS_Basic_CASL as CAS
a210c2e5add831cd438183c8602ed8e610922beaSimon Ulbrichtimport qualified Common.Lib.Rel as Rel
9da6e0cb2ea6e43f5b09dcd2a9af5468a5d0fcf4Christian Maederimport qualified Common.Lib.MapSet as MapSet
9da6e0cb2ea6e43f5b09dcd2a9af5468a5d0fcf4Christian Maedertype IdMap = Map.Map Id Id
9da6e0cb2ea6e43f5b09dcd2a9af5468a5d0fcf4Christian Maedertype OpTransTuple = (CSign.OpMap, CSign.OpMap, Set.Set Component)
9da6e0cb2ea6e43f5b09dcd2a9af5468a5d0fcf4Christian Maeder-- | generates a CASL morphism from a Maude morphism
9da6e0cb2ea6e43f5b09dcd2a9af5468a5d0fcf4Christian MaedermapMorphism :: MMorphism.Morphism -> Result CMorphism.CASLMor
9da6e0cb2ea6e43f5b09dcd2a9af5468a5d0fcf4Christian MaedermapMorphism morph =
9da6e0cb2ea6e43f5b09dcd2a9af5468a5d0fcf4Christian Maeder mk = kindMapId $ MSign.kindRel src
9da6e0cb2ea6e43f5b09dcd2a9af5468a5d0fcf4Christian Maeder mk' = kindMapId $ MSign.kindRel tgt
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht smap' = applySortMap2CASLSorts smap mk mk'
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht omap' = maudeOpMap2CASLOpMap mk omap
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maeder pmap = createPredMap mk smap
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maeder (src', _) = maude2casl src []
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maeder (tgt', _) = maude2casl tgt []
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maeder in return $ CMorphism.Morphism src' tgt' smap' omap' pmap ()
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht{- | translates the Maude morphism between operators into a CASL morpshim
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbrichtbetween operators -}
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon UlbrichtmaudeOpMap2CASLOpMap :: IdMap -> MMorphism.OpMap -> CMorphism.Op_map
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon UlbrichtmaudeOpMap2CASLOpMap im = Map.foldWithKey (translateOpMapEntry im) Map.empty
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht{- | translates the mapping between two symbols representing operators into
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbrichta CASL operators map -}
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon UlbrichttranslateOpMapEntry :: IdMap -> MSym.Symbol -> MSym.Symbol -> CMorphism.Op_map
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon UlbrichttranslateOpMapEntry im (MSym.Operator from ar co) (MSym.Operator to _ _) copm
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht where f = token2id . getName
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maeder g x = Map.findWithDefault (errorId "translate op map entry")
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht ot = CSign.OpType CAS.Total (map g ar) (g co)
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht cop = (token2id from, ot)
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maeder to' = (token2id to, CAS.Total)
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht copm' = Map.insert cop to' copm
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon UlbrichttranslateOpMapEntry _ _ _ _ = Map.empty
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht-- | generates a set of CASL symbol from a Maude Symbol
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon UlbrichtmapSymbol :: MSign.Sign -> MSym.Symbol -> Set.Set CSign.Symbol
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon UlbrichtmapSymbol sg (MSym.Sort q) = Set.singleton csym
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht where mk = kindMapId $ MSign.kindRel sg
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht sym_id = token2id q
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht kind = Map.findWithDefault (errorId "map symbol") sym_id mk
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maeder pred_data = CSign.PredType [kind]
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht csym = CSign.Symbol sym_id $ CSign.PredAsItemType pred_data
65660c22133e6de16f9ece7b36ac6423014b20aaChristian MaedermapSymbol sg (MSym.Operator q ar co) = Set.singleton csym
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maeder where mk = kindMapId $ MSign.kindRel sg
432ac7c08e2592af0660e026051ffb052e88a100Simon Ulbricht q' = token2id q
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht ar' = map (maudeSort2caslId mk) ar
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht co' = token2id $ getName co
432ac7c08e2592af0660e026051ffb052e88a100Simon Ulbricht csym = CSign.Symbol q' $ CSign.OpAsItemType op_data
432ac7c08e2592af0660e026051ffb052e88a100Simon UlbrichtmapSymbol _ _ = Set.empty
432ac7c08e2592af0660e026051ffb052e88a100Simon Ulbricht-- | returns the sort in CASL of the Maude sort symbol
432ac7c08e2592af0660e026051ffb052e88a100Simon UlbrichtmaudeSort2caslId :: IdMap -> MSym.Symbol -> Id
432ac7c08e2592af0660e026051ffb052e88a100Simon UlbrichtmaudeSort2caslId im sym = Map.findWithDefault (errorId "sort to id")
432ac7c08e2592af0660e026051ffb052e88a100Simon Ulbricht (token2id $ getName sym) im
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht{- | creates the predicate map for the CASL morphism from the Maude sort map and
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maederthe map between sorts and kinds -}
65660c22133e6de16f9ece7b36ac6423014b20aaChristian MaedercreatePredMap :: IdMap -> MMorphism.SortMap -> CMorphism.Pred_map
a210c2e5add831cd438183c8602ed8e610922beaSimon UlbrichtcreatePredMap im = Map.foldWithKey (createPredMap4sort im) Map.empty
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht-- | creates an entry of the predicate map for a single sort
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon UlbrichtcreatePredMap4sort :: IdMap -> MSym.Symbol -> MSym.Symbol -> CMorphism.Pred_map
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon UlbrichtcreatePredMap4sort im from to = Map.insert key id_to
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht where id_from = token2id $ getName from
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht id_to = token2id $ getName to
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht kind = Map.findWithDefault (errorId "predicate for sort")
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht key = (id_from, CSign.PredType [kind])
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maeder{- | computes the sort morphism of CASL from the sort morphism in Maude
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maederand the set of kinds -}
6a26171b5bc5b6ec3e1b02ae30dcfb6f03d7ffefSimon UlbrichtapplySortMap2CASLSorts :: MMorphism.SortMap -> IdMap -> IdMap
abea93ed557b22ea833e1524ee5ca11afc12208aSimon UlbrichtapplySortMap2CASLSorts sm im im' = Map.fromList sml'
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbricht where sml = Map.toList sm
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbricht sml' = foldr (applySortMap2CASLSort im im') [] sml
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbricht-- | computes the morphism for a single sort pair
abea93ed557b22ea833e1524ee5ca11afc12208aSimon UlbrichtapplySortMap2CASLSort :: IdMap -> IdMap -> (MSym.Symbol, MSym.Symbol)
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbricht -> [(Id, Id)] -> [(Id, Id)]
abea93ed557b22ea833e1524ee5ca11afc12208aSimon UlbrichtapplySortMap2CASLSort im im' (s1, s2) l = l'
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbricht where p1 = (mSym2caslId s1, mSym2caslId s2)
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbricht (errorId $ "err" ++ show (mSym2caslId x)) (mSym2caslId x)
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbricht p2 = (f s1 im, f s2 im')
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbricht l' = p1 : if s1 == s2
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbricht then l else p2 : l
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbricht-- | renames the sorts in a given kind
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbrichtrename :: MMorphism.SortMap -> Token -> Token
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbrichtrename sm tok = new_tok
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maeder where sym = MSym.Sort tok
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maeder sym' = if Map.member sym sm
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maeder then fromJust $ Map.lookup sym sm
a210c2e5add831cd438183c8602ed8e610922beaSimon Ulbricht new_tok = getName sym'
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht-- | translates a Maude sentence into a CASL formula
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon UlbrichtmapSentence :: MSign.Sign -> MSentence.Sentence -> Result CAS.CASLFORMULA
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon UlbrichtmapSentence sg sen = let
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht mk = kindMapId $ MSign.kindRel sg
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht named = makeNamed "" sen
a210c2e5add831cd438183c8602ed8e610922beaSimon Ulbricht form = mb_rl2formula mk named
a210c2e5add831cd438183c8602ed8e610922beaSimon Ulbricht in return $ sentence $ case sen of
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht MSentence.Equation (MAS.Eq _ _ _ ats) -> if any MAS.owise ats then let
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht sg_sens = map (makeNamed "") $ Set.toList $ MSign.sentences sg
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht (no_owise_sens, _, _) = splitOwiseEqs sg_sens
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht no_owise_forms = map (noOwiseSen2Formula mk) no_owise_sens
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht in owiseSen2Formula mk no_owise_forms named
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht else noOwiseSen2Formula mk named
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht{- | applies maude2casl to compute the CASL signature and sentences from
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbrichtthe Maude ones, and wraps them into a Result datatype -}
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon UlbrichtmapTheory :: (MSign.Sign, [Named MSentence.Sentence])
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht -> Result (CSign.CASLSign, [Named CAS.CASLFORMULA])
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon UlbrichtmapTheory (sg, nsens) = return $ maude2casl sg nsens
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht{- | computes new signature and sentences of CASL associated to the
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbrichtgiven Maude signature and sentences -}
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbrichtmaude2casl :: MSign.Sign -> [Named MSentence.Sentence]
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbrichtmaude2casl msign nsens = (csign {
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht CSign.declaredSymbols = syms }, new_sens)
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht where csign = CSign.emptySign ()
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht ss' = Set.map sym2id ss
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht mk = kindMapId $ MSign.kindRel msign
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht sbs' = maudeSbs2caslSbs sbs mk
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht cs = Set.union ss' $ kindsFromMap mk
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht preds = rewPredicates cs
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht rs = rewPredicatesSens cs
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht ops = deleteUniversal $ MSign.ops msign
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht ksyms = kinds2syms cs
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht (cops, assoc_ops, _) = translateOps mk ops -- (cops, assoc_ops, comps)
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht axSens = axiomsSens mk ops
a210c2e5add831cd438183c8602ed8e610922beaSimon Ulbricht ctor_sen = [] -- [ctorSen False (cs, Rel.empty, comps)]
1651c7f5055453e18a8c34f96c333e2aa702a34eSimon Ulbricht cops' = universalOps cs cops $ booleanImported ops
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht rs' = rewPredicatesCongSens cops'
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht pred_forms = loadLibraries (MSign.sorts msign) ops
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht ops_syms = ops2symbols cops'
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht (no_owise_sens, owise_sens, mbs_rls_sens) = splitOwiseEqs nsens
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht no_owise_forms = map (noOwiseSen2Formula mk) no_owise_sens
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht owise_forms = map (owiseSen2Formula mk no_owise_forms) owise_sens
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht mb_rl_forms = map (mb_rl2formula mk) mbs_rls_sens
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht preds_syms = preds2syms preds
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht syms = Set.union ksyms $ Set.union ops_syms preds_syms
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht new_sens = concat [rs, rs', no_owise_forms, owise_forms,
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht mb_rl_forms, ctor_sen, pred_forms, axSens]
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht{- | translates the Maude subsorts into CASL subsorts, and adds the subsorts
a210c2e5add831cd438183c8602ed8e610922beaSimon Ulbrichtfor the kinds -}
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon UlbrichtmaudeSbs2caslSbs :: MSign.SubsortRel -> IdMap -> Rel.Rel CAS.SORT
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon UlbrichtmaudeSbs2caslSbs sbs im = Rel.fromMap m4
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht l1 = [] -- map maudeSb2caslSb l
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht l2 = idList2Subsorts $ Map.toList im
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht l3 = map subsorts2Ids l
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht m4 = Map.unionWith Set.union m1 $ Map.unionWith Set.union m2 m3
1651c7f5055453e18a8c34f96c333e2aa702a34eSimon UlbrichtidList2Subsorts :: [(Id, Id)] -> [(Id, Set.Set Id)]
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon UlbrichtidList2Subsorts [] = []
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon UlbrichtidList2Subsorts ((id1, id2) : il) = t1 : idList2Subsorts il
1651c7f5055453e18a8c34f96c333e2aa702a34eSimon Ulbricht where t1 = (id1, Set.singleton id2)
a210c2e5add831cd438183c8602ed8e610922beaSimon UlbrichtmaudeSb2caslSb :: (MSym.Symbol, Set.Set MSym.Symbol) -> (Id, Set.Set Id)
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon UlbrichtmaudeSb2caslSb (sym, st) = (sortSym2id sym, Set.map (kindId . sortSym2id) st)
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maedersubsorts2Ids :: (MSym.Symbol, Set.Set MSym.Symbol) -> (Id, Set.Set Id)
a210c2e5add831cd438183c8602ed8e610922beaSimon Ulbrichtsubsorts2Ids (sym, st) = (sortSym2id sym, Set.map sortSym2id st)
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon UlbrichtsortSym2id :: MSym.Symbol -> Id
1651c7f5055453e18a8c34f96c333e2aa702a34eSimon UlbrichtsortSym2id (MSym.Sort q) = token2id q
1651c7f5055453e18a8c34f96c333e2aa702a34eSimon UlbrichtsortSym2id _ = token2id $ mkSimpleId "error_translation"
1651c7f5055453e18a8c34f96c333e2aa702a34eSimon Ulbricht-- | generates the sentences to state that the rew predicates are a congruence
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon UlbrichtrewPredicatesCongSens :: CSign.OpMap -> [Named CAS.CASLFORMULA]
1651c7f5055453e18a8c34f96c333e2aa702a34eSimon UlbrichtrewPredicatesCongSens = MapSet.foldWithKey rewPredCong []
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht{- | generates the sentences to state that the rew predicates are a congruence
a210c2e5add831cd438183c8602ed8e610922beaSimon Ulbrichtfor a single operator -}
1651c7f5055453e18a8c34f96c333e2aa702a34eSimon UlbrichtrewPredCong :: Id -> CSign.OpType -> [Named CAS.CASLFORMULA]
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon UlbrichtrewPredCong op ot fs = case args of
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht _ -> nq_form : fs
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht where args = CSign.opArgs ot
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht vars1 = rewPredCongPremise 0 args
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht vars2 = rewPredCongPremise (length args) args
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht res_pred_type = CAS.Pred_type [res, res] nullRange
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht pn = CAS.Qual_pred_name rewID res_pred_type nullRange
ea9768c548fe6ae05d275380869c2923c3392244Simon Ulbricht name = "rew_cong_" ++ show op
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht prems = rewPredsCong args vars1 vars2
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht prems_conj = createConjForm prems
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht os = CAS.Qual_op_name op (CSign.toOP_TYPE ot) nullRange
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maeder conc_term1 = CAS.Application os vars1 nullRange
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maeder conc_term2 = CAS.Application os vars2 nullRange
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maeder conc_form = CAS.Predication pn [conc_term1, conc_term2] nullRange
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maeder form = createImpForm prems_conj conc_form
987c9ee1092c7fd8b53242abefe4f3cf8e9a1011Simon Ulbricht nq_form = makeNamed name $ quantifyUniversally form
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht-- | generates a list of variables of the given sorts
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon UlbrichtrewPredCongPremise :: Int -> [CAS.SORT] -> [CAS.CASLTERM]
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon UlbrichtrewPredCongPremise n (s : ss) = newVarIndex n s : rewPredCongPremise (n + 1) ss
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon UlbrichtrewPredCongPremise _ [] = []
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht-- | generates a list of rew predicates with the given variables
ea9768c548fe6ae05d275380869c2923c3392244Simon UlbrichtrewPredsCong :: [CAS.SORT] -> [CAS.CASLTERM] -> [CAS.CASLTERM]
a210c2e5add831cd438183c8602ed8e610922beaSimon UlbrichtrewPredsCong (s : ss) (t : ts) (t' : ts') = form : forms
1651c7f5055453e18a8c34f96c333e2aa702a34eSimon Ulbricht where pred_type = CAS.Pred_type [s, s] nullRange
1651c7f5055453e18a8c34f96c333e2aa702a34eSimon Ulbricht pn = CAS.Qual_pred_name rewID pred_type nullRange
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht form = CAS.Predication pn [t, t'] nullRange
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht forms = rewPredsCong ss ts ts'
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon UlbrichtrewPredsCong _ _ _ = []
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maeder-- | load the CASL libraries for the Maude built-in operators
65660c22133e6de16f9ece7b36ac6423014b20aaChristian MaederloadLibraries :: MSign.SortSet -> MSign.OpMap -> [Named CAS.CASLFORMULA]
a210c2e5add831cd438183c8602ed8e610922beaSimon UlbrichtloadLibraries ss om = if natImported ss om then loadNaturalNatSens else []
53d3b5d18cae658f0e54872ade90ab5259b52b95Simon Ulbricht-- | loads the sentences associated to the natural numbers
53d3b5d18cae658f0e54872ade90ab5259b52b95Simon UlbrichtloadNaturalNatSens :: [Named CAS.CASLFORMULA]
53d3b5d18cae658f0e54872ade90ab5259b52b95Simon UlbrichtloadNaturalNatSens = [] -- retrieve code from Rev 17944 if needed again!
3ac14720aa7f1e0715311bd1598e7d78c37dd3c6Simon Ulbricht-- | checks if a sentence is an constructor sentence
53d3b5d18cae658f0e54872ade90ab5259b52b95Simon UlbrichtctorCons :: Named CAS.CASLFORMULA -> Bool
53d3b5d18cae658f0e54872ade90ab5259b52b95Simon UlbrichtctorCons f = case sentence f of
53d3b5d18cae658f0e54872ade90ab5259b52b95Simon Ulbricht-- | checks if the boolean values are imported
53d3b5d18cae658f0e54872ade90ab5259b52b95Simon UlbrichtbooleanImported :: MSign.OpMap -> Bool
53d3b5d18cae658f0e54872ade90ab5259b52b95Simon UlbrichtbooleanImported = Map.member (mkSimpleId "if_then_else_fi")
53d3b5d18cae658f0e54872ade90ab5259b52b95Simon Ulbricht-- | checks if the natural numbers are imported
53d3b5d18cae658f0e54872ade90ab5259b52b95Simon UlbrichtnatImported :: MSign.SortSet -> MSign.OpMap -> Bool
53d3b5d18cae658f0e54872ade90ab5259b52b95Simon UlbrichtnatImported ss om = b1 && b2 && b3
53d3b5d18cae658f0e54872ade90ab5259b52b95Simon Ulbricht where b1 = Set.member (MSym.Sort $ mkSimpleId "Nat") ss
a210c2e5add831cd438183c8602ed8e610922beaSimon Ulbricht b2 = Map.member (mkSimpleId "s_") om
1651c7f5055453e18a8c34f96c333e2aa702a34eSimon Ulbricht b3 = not b2 || specialZeroSet (om Map.! mkSimpleId "s_")
specialZeroSet :: MSign.OpDeclSet -> Bool
specialZeroSet = Set.fold specialZero False
specialZero :: MSign.OpDecl -> Bool -> Bool
isSpecial :: [MAS.Attr] -> Bool
isSpecial (MAS.Special _ : _) = True
where om1 = Map.delete (mkSimpleId "if_then_else_fi") om
om2 = Map.delete (mkSimpleId "_==_") om1
om3 = Map.delete (mkSimpleId "_=/=_") om2
om4 = Map.delete (mkSimpleId "upTerm") om3
om5 = Map.delete (mkSimpleId "downTerm") om4
universalOps kinds om True = Set.fold universalOpKind om kinds
universalSens = Set.fold universalSensKind []
ifSens :: Id -> [Named CAS.CASLFORMULA]
true_id = CAS.Qual_op_name (str2id "true") true_type nullRange
true_term = CAS.Application true_id [] nullRange
if_id = CAS.Qual_op_name if_name if_type nullRange
if_term = CAS.Application if_id [bv, v1, v2] nullRange
prem = CAS.mkStEq bv true_term
concl = CAS.mkStEq if_term v1
form = CAS.mkImpl prem concl
neg_prem = CAS.Negation prem nullRange
neg_concl = CAS.mkStEq if_term v2
neg_form = CAS.mkImpl neg_prem neg_concl
equalitySens :: Id -> [Named CAS.CASLFORMULA]
true_id = CAS.Qual_op_name (str2id "true") b_type nullRange
true_term = CAS.Application true_id [] nullRange
false_id = CAS.Qual_op_name (str2id "false") b_type nullRange
false_term = CAS.Application false_id [] nullRange
prem = CAS.mkStEq v1 v2
double_eq_id = CAS.mkQualOp double_eq_name double_eq_type
double_eq_term = CAS.Application double_eq_id [v1, v2] nullRange
concl = CAS.mkStEq double_eq_term true_term
form = CAS.mkImpl prem concl
neg_prem = CAS.Negation prem nullRange
new_concl = CAS.mkStEq double_eq_term false_term
comp_form = CAS.mkImpl neg_prem new_concl
nonEqualitySens :: Id -> [Named CAS.CASLFORMULA]
true_id = CAS.Qual_op_name (str2id "true") b_type nullRange
true_term = CAS.Application true_id [] nullRange
false_id = CAS.Qual_op_name (str2id "false") b_type nullRange
false_term = CAS.Application false_id [] nullRange
prem = CAS.mkStEq v1 v2
double_eq_id = CAS.mkQualOp double_eq_name double_eq_type
double_eq_term = CAS.Application double_eq_id [v1, v2] nullRange
concl = CAS.mkStEq double_eq_term false_term
form = CAS.mkImpl prem concl
neg_prem = CAS.Negation prem nullRange
new_concl = CAS.mkStEq double_eq_term true_term
comp_form = CAS.mkImpl neg_prem new_concl
axiomsSens im = Map.fold (axiomsSensODS im) []
-> [Named CAS.CASLFORMULA]
axiomsSensODS im ods l = Set.fold (axiomsSensOD im) l ods
-> [Named CAS.CASLFORMULA]
axiomsSensOD im (ss, ats) l = Set.fold (axiomsSensSS im ats) l ss
-> [Named CAS.CASLFORMULA]
axiomsSensSS im ats (MSym.Operator q ar co) l = l ++ l1
where l1 = if elem MAS.Comm ats
-> [Named CAS.CASLFORMULA]
os = CAS.Qual_op_name q' ot nullRange
t1 = CAS.Application os [v1, v2] nullRange
t2 = CAS.Application os [v2, v1] nullRange
form = CAS.mkStEq t1 t2
translateOps :: IdMap -> MSign.OpMap -> OpTransTuple
translateOps im = Map.fold (translateOpDeclSet im)
translateOpDeclSet :: IdMap -> MSign.OpDeclSet -> OpTransTuple -> OpTransTuple
translateOpDeclSet im ods tpl = Set.fold (translateOpDecl im) tpl ods
translateOpDecl :: IdMap -> MSign.OpDecl -> OpTransTuple -> OpTransTuple
where sym : tl = Set.toList syms
syms' = Set.fromList tl
ops' = MapSet.insert cop_id ot ops
assoc_ops' = if any MAS.assoc ats
then MapSet.insert cop_id ot assoc_ops
cs' = if any MAS.ctor ats
then Set.insert (Component cop_id ot) cs
maudeSym2CASLOp :: IdMap -> MSym.Symbol
maudeSym2CASLOp im (MSym.Operator op ar co) = Just (token2id op, ot, ot')
createConjForm = CAS.conjunct
createImpForm (CAS.Atom True _) form = form
createImpForm form1 form2 = CAS.mkImpl form1 form2
ops2predPremises :: IdMap -> [MSym.Symbol] -> Int
ops2predPremises im (MSym.Sort s : ss) i = (var : terms, form : forms)
kind = Map.findWithDefault (errorId "mb of op as predicate")
pred_type = CAS.Pred_type [kind] nullRange
pred_name = CAS.Qual_pred_name s' pred_type nullRange
form = CAS.Predication pred_name [var] nullRange
ops2predPremises im (MSym.Kind k : ss) i = (var : terms, forms)
kind = Map.findWithDefault (errorId "mb of op as predicate")
if any MAS.owise ats
noOwiseSen2Formula :: IdMap -> Named MSentence.Sentence
-> Named CAS.CASLFORMULA
where MSentence.Equation eq = sentence s
owiseSen2Formula :: IdMap -> [Named CAS.CASLFORMULA]
where MSentence.Equation eq = sentence s
MSentence.Membership mb -> let
MSentence.Rule rl -> let
_ -> makeNamed "" CAS.falseForm
newVarIndex :: Int -> Id -> CAS.CASLTERM
newVarIndex i sort = CAS.Qual_var var sort nullRange
newVar :: Id -> CAS.CASLTERM
newVar sort = CAS.Qual_var var sort nullRange
noOwiseEq2Formula im (MAS.Eq t t' [] _) = quantifyUniversally form
form = CAS.mkStEq ct ct'
noOwiseEq2Formula im (MAS.Eq t t' conds@(_ : _) _) = quantifyUniversally form
concl_form = CAS.mkStEq ct ct'
form = CAS.mkForall vars imp_form
form = CAS.conjunct ex_forms
conj_form = CAS.conjunct prems
CAS.mkExist vars' conj_form
neg_form = CAS.mkNeg ex_form
qualifyExVarsTerm (CAS.Qual_var var sort r) =
CAS.Qual_var (qualifyExVarAux var) sort r
qualifyExVarsTerm (CAS.Sorted_term t s r) =
CAS.Sorted_term (qualifyExVarsTerm t) s r
qualifyExVarsTerm (CAS.Mixfix_parenthesized ts r) =
CAS.Mixfix_parenthesized ts' r
createEqs (t1 : ts1) (t2 : ts2) = CAS.mkStEq t1 t2 : ls
getLeftApp :: CAS.CASLFORMULA
getLeftApp (CAS.Relation prem c concl _) = case getLeftApp concl of
Just (op, ts, _) | c /= CAS.Equivalence -> Just (op, ts, conds)
getLeftAppTerm (CAS.Application op ts _) = Just (op, ts)
mb2formula im (MAS.Mb t s [] _) = quantifyUniversally form
form = CAS.Membership ct s' nullRange
mb2formula im (MAS.Mb t s conds@(_ : _) _) = quantifyUniversally form
concl_form = CAS.Membership ct s' nullRange
form = CAS.mkImpl conds_form concl_form
rl2formula im (MAS.Rl t t' [] _) = quantifyUniversally form
where ty = token2id $ getName $ MAS.getTermType t
kind = Map.findWithDefault (errorId "rl to formula") ty im
pred_type = CAS.Pred_type [kind, kind] nullRange
pred_name = CAS.Qual_pred_name rewID pred_type nullRange
form = CAS.Predication pred_name [ct, ct'] nullRange
rl2formula im (MAS.Rl t t' conds@(_ : _) _) = quantifyUniversally form
where ty = token2id $ getName $ MAS.getTermType t
kind = Map.findWithDefault (errorId "rl to formula") ty im
pred_type = CAS.Pred_type [kind, kind] nullRange
pred_name = CAS.Qual_pred_name rewID pred_type nullRange
concl_form = CAS.Predication pred_name [ct, ct'] nullRange
form = CAS.mkImpl conds_form concl_form
conds2formula im conds = CAS.conjunct forms
ty = token2id $ getName $ MAS.getTermType t
kind = Map.findWithDefault (errorId "rw cond to formula") ty im
pred_type = CAS.Pred_type [kind, kind] nullRange
pred_name = CAS.Qual_pred_name rewID pred_type nullRange
op = CAS.Qual_op_name name op_type nullRange
op = CAS.Qual_op_name name op_type nullRange
maudeSymbol2caslSort (MSym.Sort q) _ = token2id q
maudeType2caslSort (MAS.TypeSort q) _ = token2id $ getName q
getTypes :: [CAS.CASLTERM] -> [Id]
getType :: CAS.CASLTERM -> Maybe Id
getType (CAS.Qual_var _ kind _) = Just kind
getType (CAS.Application op _ _) = case op of
rewPredicatesSens = Set.fold rewPredicateSens []
reflSen :: Id -> Named CAS.CASLFORMULA
pred_type = CAS.Pred_type [kind, kind] nullRange
pn = CAS.Qual_pred_name rewID pred_type nullRange
form = CAS.Predication pn [v, v] nullRange
transSen :: Id -> Named CAS.CASLFORMULA
pred_type = CAS.Pred_type [kind, kind] nullRange
pn = CAS.Qual_pred_name rewID pred_type nullRange
prem1 = CAS.Predication pn [v1, v2] nullRange
prem2 = CAS.Predication pn [v2, v3] nullRange
concl = CAS.Predication pn [v1, v3] nullRange
conj_form = CAS.conjunct [prem1, prem2]
form = CAS.mkImpl conj_form concl
kindsFromMap :: IdMap -> Set.Set Id
sortsTranslation = sortsTranslationList . Set.toList
sortsTranslationList [] _ = Set.empty
sortsTranslationList (s : ss) r = Set.insert (sort2id tops) res
where tops@(top : _) = List.sort $ getTop r s
deleteRelated ss sym r = foldr (f sym tc) Set.empty ss
where tc = Rel.transClosure r
f sort trC x y = if MSym.sameKind trC sort x
else Set.insert x y
sym2id :: MSym.Symbol -> Id
sort2id :: [MSym.Symbol] -> Id
where sym : _ = List.sort syms
quantifyUniversally form = CAS.mkForall var_decl form
listVarDecl = Map.foldWithKey f []
noQuantification (CAS.Quantification _ vars form _) = (form, vars)
kinds2syms = Set.map kind2sym
kind2sym :: Id -> CSign.Symbol
createSym4id pn pt = Set.insert sym
createSymOp4id on ot = Set.insert sym
getVars (CAS.Quantification _ _ f _) = getVars f
getVars (CAS.Junction _ fs _) =
getVars (CAS.Negation f _) = getVars f
getVars (CAS.Predication _ ts _) =
getVars (CAS.Definedness t _) = getVarsTerm t
getVars (CAS.Membership t _ _) = getVarsTerm t
getVars (CAS.Mixfix_formula t) = getVarsTerm t
getVars _ = Map.empty
getVarsTerm (CAS.Qual_var var sort _) =
getVarsTerm (CAS.Application _ ts _) =
getVarsTerm (CAS.Sorted_term t _ _) = getVarsTerm t
getVarsTerm (CAS.Cast t _ _) = getVarsTerm t
getVarsTerm (CAS.Mixfix_term ts) =
getVarsTerm (CAS.Mixfix_parenthesized ts _) =
getVarsTerm (CAS.Mixfix_bracketed ts _) =
getVarsTerm (CAS.Mixfix_braced ts _) =
getVarsTerm _ = Map.empty
ctorSen :: Bool -> GenAx -> Named CAS.CASLFORMULA
let sortList = Set.toList sorts
opSyms = map ( \ c -> let ide = compId c in CAS.Qual_op_name ide
(CSign.toOP_TYPE $ compType c) $ posOfId ide)
$ Set.toList ops
resType _ (CAS.Op_name _) = False
getIndex s = fromMaybe (-1) $ List.elemIndex s sortList
addIndices (CAS.Op_name _) =
error "CASL/StaticAna: Internal error in function addIndices"
addIndices os@(CAS.Qual_op_name _ t _) =
(os, map getIndex $ CAS.args_OP_TYPE t)
CAS.Constraint s (map addIndices $ filter (resType s) allSyms) s
f = CAS.mkSort_gen_ax constrs isFree
ms2vcs s = if Map.member s stringMap
| Map.member x charMap = (charMap Map.! x) ++ "'" ++ y
stringMap :: Map.Map String String
stringMap = Map.fromList
kindMapId :: MSign.KindRel -> IdMap
kindMapId kr = Map.fromList krl'
where krl = Map.toList kr
mSym2caslId :: MSym.Symbol -> Id
mSym2caslId (MSym.Sort q) = token2id q
mSym2caslId (MSym.Kind q) = kindId q'
atLeastOneSort om = Map.fromList lom'
where lom = Map.toList om
hd = if Set.null ods'
atLeastOneSortODS ods = Set.fromList lods'
where lods = Set.toList ods
res = if Set.null ss'
atLeastOneSortSS = Set.filter hasOneSort
hasOneSort :: MSym.Symbol -> Bool
hasOneSort (MSym.Operator _ ar co) = any isSymSort (co : ar)
isSymSort :: MSym.Symbol -> Bool
isSymSort (MSym.Sort _) = True
translateOps' :: IdMap -> MSign.OpMap -> OpTransTuple
translateOps' im = Map.fold (translateOpDeclSet' im)
translateOpDeclSet' :: IdMap -> MSign.OpDeclSet -> OpTransTuple -> OpTransTuple
translateOpDeclSet' im ods tpl = Set.fold (translateOpDecl' im) tpl ods
translateOpDecl' :: IdMap -> MSign.OpDecl -> OpTransTuple -> OpTransTuple
if Set.null syms'
where (sym, syms') = Set.deleteFindMin syms
ops' = MapSet.insert cop_id ot ops
assoc_ops' = if any MAS.assoc ats
then MapSet.insert cop_id ot assoc_ops
cs' = if any MAS.ctor ats
then Set.insert (Component cop_id ot) cs
maudeSym2CASLOp' :: IdMap -> MSym.Symbol
maudeSym2CASLOp' im (MSym.Operator op ar co) = Just (token2id op, ot, ot')
maudeSymbol2caslSort' (MSym.Sort q) _ =