PreComorphism.hs revision 51c15129e8118fed5c33c334f8df82619ce98e7d
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeleModule : $Header$
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeleDescription : Maude Comorphisms
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeleCopyright : (c) Adrian Riesco, Facultad de Informatica UCM 2009
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeleLicense : similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeleMaintainer : ariesco@fdi.ucm.es
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeleStability : experimental
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelePortability : portable
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeleComorphism from Maude to CASL.
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeleimport qualified Data.List as List
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeleimport qualified Data.Set as Set
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeleimport qualified Data.Map as Map
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeleimport qualified Maude.Sign as MSign
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeleimport qualified Maude.Sentence as MSentence
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeleimport qualified Maude.Morphism as MMorphism
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeleimport qualified Maude.AS_Maude as MAS
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeleimport qualified Maude.Symbol as MSym
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeleimport qualified CASL.Sign as CSign
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeleimport qualified CASL.Morphism as CMorphism
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeleimport qualified CASL.AS_Basic_CASL as CAS
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeleimport Common.ProofUtils (charMap)
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeleimport qualified Common.Lib.Rel as Rel
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeletype IdMap = Map.Map Id Id
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeletype OpTransTuple = (CSign.OpMap, CSign.OpMap, Set.Set Component)
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele-- | generates a CASL morphism from a Maude morphism
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelemapMorphism :: MMorphism.Morphism -> Result (CMorphism.CASLMor)
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelemapMorphism morph =
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele mk = arrangeKinds (MSign.sorts src) (MSign.subsorts src)
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele cs = kindsFromMap mk
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele smap' = applySortMap2CASLSorts smap cs
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele omap' = maudeOpMap2CASLOpMap mk omap
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele pmap = createPredMap mk smap
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele (src', _) = maude2casl src []
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele (tgt', _) = maude2casl tgt []
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele in return $ CMorphism.Morphism src' tgt' smap' omap' pmap ()
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele-- | translates the Maude morphism between operators into a CASL morpshim between
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelemaudeOpMap2CASLOpMap :: IdMap -> MMorphism.OpMap -> CMorphism.Op_map
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelemaudeOpMap2CASLOpMap im = Map.foldWithKey (translateOpMapEntry im) Map.empty
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele-- | translates the mapping between two symbols representing operators into
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele-- a CASL operators map
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeletranslateOpMapEntry :: IdMap -> MSym.Symbol -> MSym.Symbol -> CMorphism.Op_map
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeletranslateOpMapEntry im (MSym.Operator from ar co) (MSym.Operator to _ _) copm = copm'
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele where f = token2id . getName
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele g = \ x -> Map.findWithDefault (errorId "translate op map entry") (f x) im
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele cop = (token2id from, ot)
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele to' = (token2id to, CAS.Total)
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele copm' = Map.insert cop to' copm
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeletranslateOpMapEntry _ _ _ _ = Map.empty
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele-- | generates a set of CASL symbol from a Maude Symbol
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelemapSymbol :: MSign.Sign -> MSym.Symbol -> Set.Set CSign.Symbol
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele where mk = arrangeKinds (MSign.sorts sg) (MSign.subsorts sg)
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele sym_id = token2id q
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele kind = Map.findWithDefault (errorId "map symbol") sym_id mk
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele pred_data = CSign.PredType [kind]
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele csym = CSign.Symbol sym_id $ CSign.PredAsItemType pred_data
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelemapSymbol sg (MSym.Operator q ar co) = Set.singleton csym
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele where mk = arrangeKinds (MSign.sorts sg) (MSign.subsorts sg)
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele q' = token2id q
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele ar' = map (maudeSort2caslId mk) ar
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele co' = token2id $ getName co
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele csym = CSign.Symbol q' $ CSign.OpAsItemType op_data
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelemapSymbol _ _ = Set.empty
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele-- | returns the sort in CASL of the Maude sort symbol
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelemaudeSort2caslId :: IdMap -> MSym.Symbol -> Id
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelemaudeSort2caslId im sym = Map.findWithDefault (errorId "sort to id") (token2id $ getName sym) im
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele-- | creates the predicate map for the CASL morphism from the Maude sort map and
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele-- the map between sorts and kinds
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelecreatePredMap :: IdMap -> MMorphism.SortMap -> CMorphism.Pred_map
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelecreatePredMap im = Map.foldWithKey (createPredMap4sort im) Map.empty
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele-- | creates an entry of the predicate map for a single sort
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelecreatePredMap4sort :: IdMap -> MSym.Symbol -> MSym.Symbol -> CMorphism.Pred_map
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelecreatePredMap4sort im from to m = Map.insert key id_to m
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele where id_from = token2id $ getName from
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele id_to = token2id $ getName to
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele kind = Map.findWithDefault (errorId "predicate for sort") id_from im
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele key = (id_from, CSign.PredType [kind])
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele-- | computes the sort morphism of CASL from the sort morphism in Maude and the set
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeleapplySortMap2CASLSorts :: MMorphism.SortMap -> Set.Set Id -> CMorphism.Sort_map
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeleapplySortMap2CASLSorts sm = Set.fold (applySortMap2CASLSort sm) Map.empty
a3388213b2b4d46b356be205e38204e67b4304d8rbowen-- | computes the morphism for a single kind
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeleapplySortMap2CASLSort :: MMorphism.SortMap -> Id -> CMorphism.Sort_map -> CMorphism.Sort_map
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeleapplySortMap2CASLSort sm sort csm = new_csm
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele where toks = getTokens sort
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele new_toks = map (rename sm) toks
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele new_sort = mkId new_toks
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele new_csm = if new_sort == sort
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele else Map.insert sort new_sort csm
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele-- | renames the sorts in a given kind
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelerename :: MMorphism.SortMap -> Token -> Token
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelerename sm tok = new_tok
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele where sym = MSym.Sort tok
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele sym' = if Map.member sym sm
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele then fromJust $ Map.lookup sym sm
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele new_tok = getName sym'
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele-- | translates a Maude sentence into a CASL formula
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelemapSentence :: MSign.Sign -> MSentence.Sentence -> Result CAS.CASLFORMULA
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelemapSentence sg sen@(MSentence.Equation eq) = case any MAS.owise ats of
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele False -> return $ sentence $ noOwiseSen2Formula mk named
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele sg_sens = map (makeNamed "") $ Set.toList $ MSign.sentences sg
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele (no_owise_sens, _, _) = splitOwiseEqs sg_sens
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele no_owise_forms = map (noOwiseSen2Formula mk) no_owise_sens
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele trans = sentence $ owiseSen2Formula mk no_owise_forms named
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele in return trans
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele where mk = arrangeKinds (MSign.sorts sg) (MSign.subsorts sg)
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele MAS.Eq _ _ _ ats = eq
a3388213b2b4d46b356be205e38204e67b4304d8rbowen named = makeNamed "" sen
a3388213b2b4d46b356be205e38204e67b4304d8rbowenmapSentence sg sen@(MSentence.Membership mb) = return $ sentence form
a3388213b2b4d46b356be205e38204e67b4304d8rbowen where mk = arrangeKinds (MSign.sorts sg) (MSign.subsorts sg)
a3388213b2b4d46b356be205e38204e67b4304d8rbowen MAS.Mb _ _ _ _ = mb
a3388213b2b4d46b356be205e38204e67b4304d8rbowen named = makeNamed "" sen
a3388213b2b4d46b356be205e38204e67b4304d8rbowen form = mb_rl2formula mk named
a3388213b2b4d46b356be205e38204e67b4304d8rbowenmapSentence sg sen@(MSentence.Rule rl) = return $ sentence form
a3388213b2b4d46b356be205e38204e67b4304d8rbowen where mk = arrangeKinds (MSign.sorts sg) (MSign.subsorts sg)
a3388213b2b4d46b356be205e38204e67b4304d8rbowen MAS.Rl _ _ _ _ = rl
a3388213b2b4d46b356be205e38204e67b4304d8rbowen named = makeNamed "" sen
a3388213b2b4d46b356be205e38204e67b4304d8rbowen form = mb_rl2formula mk named
a3388213b2b4d46b356be205e38204e67b4304d8rbowen-- | applies maude2casl to compute the CASL signature and sentences from
a3388213b2b4d46b356be205e38204e67b4304d8rbowen-- the Maude ones, and wraps them into a Result datatype
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele -> Result (CSign.CASLSign, [Named CAS.CASLFORMULA])
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelemapTheory (sg, nsens) = return $ maude2casl sg nsens
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele-- | computes new signature and sentences of CASL associated to the
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele-- given Maude signature and sentences
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelemaude2casl :: MSign.Sign -> [Named MSentence.Sentence]
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelemaude2casl msign nsens = (csign { CSign.sortSet = cs,
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele CSign.declaredSymbols = syms }, new_sens)
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele where csign = CSign.emptySign ()
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele ss' = Set.map sym2id ss
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele mk = arrangeKinds ss (MSign.subsorts msign)
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele sbs' = maudeSbs2caslSbs sbs mk
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele cs = Set.union ss' (kindsFromMap mk)
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele preds = rewPredicates cs
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele rs = rewPredicatesSens cs
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele ops = deleteUniversal $ MSign.ops msign
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele ksyms = kinds2syms cs
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele (cops, assoc_ops, comps) = translateOps mk ops
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele ctor_sen = [ctorSen False (cs, Rel.empty, comps)]
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele cops' = universalOps cs cops $ booleanImported ops
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele rs' = rewPredicatesCongSens cops'
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele pred_forms = loadLibraries (MSign.sorts msign) ops
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele ops_syms = ops2symbols cops'
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele (no_owise_sens, owise_sens, mbs_rls_sens) = splitOwiseEqs nsens
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele no_owise_forms = map (noOwiseSen2Formula mk) no_owise_sens
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele owise_forms = map (owiseSen2Formula mk no_owise_forms) owise_sens
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele mb_rl_forms = map (mb_rl2formula mk) mbs_rls_sens
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele preds_syms = preds2syms preds
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele syms = Set.union ksyms $ Set.union ops_syms preds_syms
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele new_sens = concat [rs, rs', no_owise_forms, owise_forms,
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele mb_rl_forms, ctor_sen, pred_forms]
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele-- | translates the Maude subsorts into CASL subsorts, and adds the subsorts
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele-- for the kinds
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelemaudeSbs2caslSbs :: MSign.SubsortRel -> IdMap -> Rel.Rel CAS.SORT
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelemaudeSbs2caslSbs sbs im = Rel.fromDistinctMap m
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele l1 = map maudeSb2caslSb l
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele l2 = idList2Subsorts $ Map.toList im
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele m = Map.fromList $ concat [l1, l2]
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeleidList2Subsorts :: [(Id, Id)] -> [(Id, Set.Set Id)]
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeleidList2Subsorts [] = []
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeleidList2Subsorts ((id1, id2) : il) = (id1, Set.singleton id2) : idList2Subsorts il
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelemaudeSb2caslSb :: (MSym.Symbol, Set.Set MSym.Symbol) -> (Id, Set.Set Id)
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelemaudeSb2caslSb (sym, st) = (sortSym2id sym, Set.map sortSym2id st)
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelesortSym2id :: MSym.Symbol -> Id
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelesortSym2id (MSym.Sort q) = token2id q
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelesortSym2id _ = token2id $ mkSimpleId $ "error_translation"
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele-- | generates the sentences to state that the rew predicates are a congruence
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelerewPredicatesCongSens :: CSign.OpMap -> [Named CAS.CASLFORMULA]
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelerewPredicatesCongSens = Map.foldWithKey rewPredCongSet []
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele-- | generates the sentences to state that the rew predicates are a congruence
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele-- for the operator types in the set
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelerewPredCongSet :: Id -> Set.Set CSign.OpType -> [Named CAS.CASLFORMULA] -> [Named CAS.CASLFORMULA]
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelerewPredCongSet idn ots fs = fs ++ fs'
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele where fs' = Set.fold (rewPredCong idn) [] ots
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele-- | generates the sentences to state that the rew predicates are a congruence
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele-- for a single operator
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelerewPredCong :: Id -> CSign.OpType -> [Named CAS.CASLFORMULA] -> [Named CAS.CASLFORMULA]
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelerewPredCong op ot fs = case args of
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele _ -> nq_form : fs
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele where args = CSign.opArgs ot
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele vars1 = rewPredCongPremise 0 args
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele vars2 = rewPredCongPremise (length args) args
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele res_pred_type = CAS.Pred_type [res, res] nullRange
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele pn = CAS.Qual_pred_name rewID res_pred_type nullRange
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele name = "rew_cong_" ++ show op
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele prems = rewPredsCong args vars1 vars2
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele prems_conj = createConjForm prems
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele os = CAS.Qual_op_name op (CSign.toOP_TYPE ot) nullRange
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele conc_term1 = CAS.Application os vars1 nullRange
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele conc_term2 = CAS.Application os vars2 nullRange
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele conc_form = CAS.Predication pn [conc_term1, conc_term2] nullRange
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele form = createImpForm prems_conj conc_form
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele nq_form = makeNamed name $ quantifyUniversally form
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele-- | generates a list of variables of the given sorts
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelerewPredCongPremise :: Int -> [CAS.SORT] -> [CAS.CASLTERM]
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelerewPredCongPremise n (s : ss) = newVarIndex n s : rewPredCongPremise (n + 1) ss
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelerewPredCongPremise _ [] = []
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele-- | generates a list of rew predicates with the given variables
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelerewPredsCong :: [CAS.SORT] -> [CAS.CASLTERM] -> [CAS.CASLTERM] -> [CAS.CASLFORMULA]
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelerewPredsCong (s : ss) (t : ts) (t' : ts') = form : forms
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele where pred_type = CAS.Pred_type [s, s] nullRange
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele pn = CAS.Qual_pred_name rewID pred_type nullRange
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele form = CAS.Predication pn [t, t'] nullRange
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele forms = rewPredsCong ss ts ts'
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelerewPredsCong _ _ _ = []
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele-- | load the CASL libraries for the Maude built-in operators
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeleloadLibraries :: MSign.SortSet -> MSign.OpMap -> [Named CAS.CASLFORMULA]
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeleloadLibraries ss om = case natImported ss om of
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele True -> loadNaturalNatSens
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele-- | loads the sentences associated to the natural numbers
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeleloadNaturalNatSens :: [Named CAS.CASLFORMULA]
4ab980a06412fd86f52a6d054fb7e26de155c530erikabeleloadNaturalNatSens =
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele let lib = head $ unsafePerformIO $ readLib "Maude/MaudeNumbers.casl"
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele in case lib of
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele G_theory lid _ _ thSens _ -> let sens = toNamedList thSens
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele sens' <- coerceSens lid CASL "" sens
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele filter (not . ctorCons) sens'
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele-- | checks if a sentence is an constructor sentence
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelectorCons :: Named CAS.CASLFORMULA -> Bool
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelectorCons f = case sentence f of
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele-- | checks if the boolean values are imported
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelebooleanImported :: MSign.OpMap -> Bool
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelebooleanImported = Map.member (mkSimpleId "if_then_else_fi")
4ab980a06412fd86f52a6d054fb7e26de155c530erikabele-- | checks if the natural numbers are imported
4ab980a06412fd86f52a6d054fb7e26de155c530erikabelenatImported :: MSign.SortSet -> MSign.OpMap -> Bool
b2 = Map.member (mkSimpleId "s_") om
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.Strong_equation bv true_term nullRange
concl = CAS.Strong_equation if_term v1 nullRange
form = CAS.Implication prem concl True nullRange
neg_prem = CAS.Negation prem nullRange
neg_concl = CAS.Strong_equation if_term v2 nullRange
neg_form = CAS.Implication neg_prem neg_concl True nullRange
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.Strong_equation v1 v2 nullRange
double_eq_id = CAS.Qual_op_name double_eq_name double_eq_type nullRange
double_eq_term = CAS.Application double_eq_id [v1, v2] nullRange
concl = CAS.Strong_equation double_eq_term true_term nullRange
form = CAS.Implication prem concl True nullRange
neg_prem = CAS.Negation prem nullRange
new_concl = CAS.Strong_equation double_eq_term false_term nullRange
comp_form = CAS.Implication neg_prem new_concl True nullRange
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.Strong_equation v1 v2 nullRange
double_eq_id = CAS.Qual_op_name double_eq_name double_eq_type nullRange
double_eq_term = CAS.Application double_eq_id [v1, v2] nullRange
concl = CAS.Strong_equation double_eq_term false_term nullRange
form = CAS.Implication prem concl True nullRange
neg_prem = CAS.Negation prem nullRange
new_concl = CAS.Strong_equation double_eq_term true_term nullRange
comp_form = CAS.Implication neg_prem new_concl True nullRange
translateOps :: IdMap -> MSign.OpMap -> OpTransTuple
translateOpDeclSet :: IdMap -> MSign.OpDeclSet -> OpTransTuple -> OpTransTuple
translateOpDeclSet im ods tpl = Set.fold (translateOpDecl im) tpl ods
translateOpDecl :: IdMap -> MSign.OpDecl -> OpTransTuple -> OpTransTuple
where sym = head $ Set.toList syms
assoc_ops' = if any MAS.assoc ats
cs' = if any MAS.ctor ats
then Set.insert (Component cop_id ot) cs
maudeSym2CASLOp im (MSym.Operator op ar co) = Just (token2id op, ot, ot')
g = \ x -> maudeSymbol2caslSort x im -- \ x -> Map.findWithDefault (errorId "Maude_sym2CASL_sym") (f x) im
createConjForm [] = CAS.True_atom nullRange
createConjForm fs = CAS.Conjunction fs nullRange
createImpForm (CAS.True_atom _) form = form
createImpForm form1 form2 = CAS.Implication form1 form2 True nullRange
ops2predPremises im (MSym.Sort s : ss) i = (var : terms, form : forms)
kind = Map.findWithDefault (errorId "mb of op as predicate") s' im
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") k' im
splitOwiseEqs :: [Named MSentence.Sentence] ->
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.False_atom nullRange
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.Strong_equation ct ct' nullRange
noOwiseEq2Formula im (MAS.Eq t t' conds@(_:_) _) = quantifyUniversally form
concl_form = CAS.Strong_equation ct ct' nullRange
then CAS.Conjunction ex_forms nullRange
conj_form = CAS.Conjunction prems nullRange
neg_form = CAS.Negation ex_form nullRange
createEqs (t1 : ts1) (t2 : ts2) = CAS.Strong_equation t1 t2 nullRange : ls
getLeftApp (CAS.Strong_equation term _ _) = case getLeftAppTerm term of
getLeftApp (CAS.Implication prem concl _ _) = case getLeftApp concl of
getLeftAppTerm (CAS.Application op ts _) = Just (op, ts)
getPremisesImplication (CAS.Conjunction forms _) = forms
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.Implication conds_form concl_form True nullRange
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.Implication conds_form concl_form True nullRange
conds2formula im conds = CAS.Conjunction forms nullRange
kind = Map.findWithDefault (errorId "mb cond to formula") s' im
pred_type = CAS.Pred_type [kind] nullRange
pred_name = CAS.Qual_pred_name s' pred_type nullRange
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.Conjunction [prem1, prem2] nullRange
form = CAS.Implication conj_form concl True nullRange
kindsFromMap :: IdMap -> Set.Set Id
where tops = List.sort $ getTop r s
tc = Rel.transClosure r
f = \ x y z -> Map.insert (sym2id y) (kindId $ sort2id x) z
sameKindList t r (t' : ts) = if MSym.sameKind r t t'
sortsTranslation ss r = sortsTranslationList (Set.toList ss) r
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 = head $ List.sort syms
listVarDecl = Map.foldWithKey f []
noQuantification (CAS.Quantification _ vars form _) = (form, vars)
kinds2syms = Set.map kind2sym
kind2sym :: Id -> CSign.Symbol
pred2sym pn spt acc = Set.fold (createSym4id pn) acc spt
createSym4id pn pt acc = Set.insert sym acc
op2sym on sot acc = Set.union set acc
createSymOp4id on ot acc = Set.insert sym acc
getVars (CAS.Quantification _ _ f _) = getVars f
getVars (CAS.Negation f _) = getVars f
getVars (CAS.Definedness t _) = getVarsTerm t
getVars (CAS.Membership t _ _) = getVarsTerm t
getVars (CAS.Mixfix_formula t) = getVarsTerm t
getVars _ = Map.empty
getVarsTerm (CAS.Sorted_term t _ _) = getVarsTerm t
getVarsTerm (CAS.Cast t _ _) = getVarsTerm t
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
resType _ (CAS.Op_name _) = False
getIndex s = maybe (-1) id $ List.findIndex (== 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.Sort_gen_ax constrs isFree
ms2vcs s = case Map.member s stringMap of
True -> Map.findWithDefault "" s stringMap
False -> let f = \ x y -> if Map.member x charMap
stringMap :: Map.Map String String
stringMap = Map.fromList