PreComorphism.hs revision 94e112d16f89130a688db8b03ad3224903f5e97e
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzorModule : $Header$
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzorDescription : Maude Comorphisms
a99c5d4cc3cab6a62b04d52000dbc22ce1fa2d94coarCopyright : (c) Adrian Riesco, Facultad de Informatica UCM 2009
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzorLicense : GPLv2 or higher, see LICENSE.txt
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzorMaintainer : ariesco@fdi.ucm.es
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzorStability : experimental
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzorPortability : portable
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzorComorphism from Maude to CASL.
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzorimport qualified Data.List as List
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzorimport qualified Data.Set as Set
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzorimport qualified Data.Map as Map
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzorimport qualified Maude.Sign as MSign
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzorimport qualified Maude.Sentence as MSentence
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzorimport qualified Maude.Morphism as MMorphism
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzorimport qualified Maude.AS_Maude as MAS
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzorimport qualified Maude.Symbol as MSym
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentisimport qualified CASL.Sign as CSign
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzorimport qualified CASL.Morphism as CMorphism
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzorimport qualified CASL.AS_Basic_CASL as CAS
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzorimport Common.ProofUtils (charMap)
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentisimport qualified Common.Lib.Rel as Rel
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzorimport qualified Common.Lib.MapSet as MapSet
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentistype IdMap = Map.Map Id Id
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentistype OpTransTuple = (CSign.OpMap, CSign.OpMap, Set.Set Component)
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor-- | generates a CASL morphism from a Maude morphism
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzormapMorphism :: MMorphism.Morphism -> Result CMorphism.CASLMor
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzormapMorphism morph =
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor mk = kindMapId $ MSign.kindRel src
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor mk' = kindMapId $ MSign.kindRel tgt
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis smap' = applySortMap2CASLSorts smap mk mk'
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor omap' = maudeOpMap2CASLOpMap mk omap
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor pmap = createPredMap mk smap
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor (src', _) = maude2casl src []
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor (tgt', _) = maude2casl tgt []
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor in return $ CMorphism.Morphism src' tgt' smap' omap' pmap ()
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis{- | translates the Maude morphism between operators into a CASL morpshim
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentisbetween operators -}
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzormaudeOpMap2CASLOpMap :: IdMap -> MMorphism.OpMap -> CMorphism.Op_map
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzormaudeOpMap2CASLOpMap im = Map.foldWithKey (translateOpMapEntry im) Map.empty
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor{- | translates the mapping between two symbols representing operators into
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzora CASL operators map -}
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzortranslateOpMapEntry :: IdMap -> MSym.Symbol -> MSym.Symbol -> CMorphism.Op_map
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzortranslateOpMapEntry im (MSym.Operator from ar co) (MSym.Operator to _ _) copm
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor where f = token2id . getName
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor g x = Map.findWithDefault (errorId "translate op map entry")
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis cop = (token2id from, ot)
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor to' = (token2id to, CAS.Total)
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor copm' = Map.insert cop to' copm
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentistranslateOpMapEntry _ _ _ _ = Map.empty
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis-- | generates a set of CASL symbol from a Maude Symbol
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzormapSymbol :: MSign.Sign -> MSym.Symbol -> Set.Set CSign.Symbol
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor where mk = kindMapId $ MSign.kindRel sg
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor sym_id = token2id q
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor kind = Map.findWithDefault (errorId "map symbol") sym_id mk
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis pred_data = CSign.PredType [kind]
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis csym = CSign.Symbol sym_id $ CSign.PredAsItemType pred_data
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentismapSymbol sg (MSym.Operator q ar co) = Set.singleton csym
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis where mk = kindMapId $ MSign.kindRel sg
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis q' = token2id q
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis ar' = map (maudeSort2caslId mk) ar
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis co' = token2id $ getName co
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentismapSymbol _ _ = Set.empty
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor-- | returns the sort in CASL of the Maude sort symbol
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzormaudeSort2caslId :: IdMap -> MSym.Symbol -> Id
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzormaudeSort2caslId im sym = Map.findWithDefault (errorId "sort to id")
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor (token2id $ getName sym) im
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor{- | creates the predicate map for the CASL morphism from the Maude sort map and
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzorthe map between sorts and kinds -}
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentiscreatePredMap :: IdMap -> MMorphism.SortMap -> CMorphism.Pred_map
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentiscreatePredMap im = Map.foldWithKey (createPredMap4sort im) Map.empty
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor-- | creates an entry of the predicate map for a single sort
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzorcreatePredMap4sort :: IdMap -> MSym.Symbol -> MSym.Symbol -> CMorphism.Pred_map
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzorcreatePredMap4sort im from to = Map.insert key id_to
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis where id_from = token2id $ getName from
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis id_to = token2id $ getName to
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor kind = Map.findWithDefault (errorId "predicate for sort")
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor key = (id_from, CSign.PredType [kind])
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor{- | computes the sort morphism of CASL from the sort morphism in Maude
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzorand the set of kinds -}
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzorapplySortMap2CASLSorts :: MMorphism.SortMap -> IdMap -> IdMap
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzorapplySortMap2CASLSorts sm im im' = Map.fromList sml'
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor where sml = Map.toList sm
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor sml' = foldr (applySortMap2CASLSort im im') [] sml
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis-- | computes the morphism for a single sort pair
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzorapplySortMap2CASLSort :: IdMap -> IdMap -> (MSym.Symbol, MSym.Symbol)
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor -> [(Id, Id)] -> [(Id, Id)]
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzorapplySortMap2CASLSort im im' (s1, s2) l = l'
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis where p1 = (mSym2caslId s1, mSym2caslId s2)
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor (errorId $ "err" ++ show (mSym2caslId x)) (mSym2caslId x)
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis p2 = (f s1 im, f s2 im')
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis l' = if s1 == s2
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor then p1 : l
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis else p1 : p2 : l
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis-- | renames the sorts in a given kind
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzorrename :: MMorphism.SortMap -> Token -> Token
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzorrename sm tok = new_tok
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor where sym = MSym.Sort tok
4f1f74609a2656ae7d9061991ccfd16d25f1befalgentis sym' = if Map.member sym sm
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor then fromJust $ Map.lookup sym sm
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor new_tok = getName sym'
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis-- | translates a Maude sentence into a CASL formula
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentismapSentence :: MSign.Sign -> MSentence.Sentence -> Result CAS.CASLFORMULA
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentismapSentence sg sen = let
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis mk = kindMapId $ MSign.kindRel sg
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis named = makeNamed "" sen
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis form = mb_rl2formula mk named
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis in return $ sentence $ case sen of
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis MSentence.Equation (MAS.Eq _ _ _ ats) -> if any MAS.owise ats then let
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor sg_sens = map (makeNamed "") $ Set.toList $ MSign.sentences sg
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis (no_owise_sens, _, _) = splitOwiseEqs sg_sens
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor no_owise_forms = map (noOwiseSen2Formula mk) no_owise_sens
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis in owiseSen2Formula mk no_owise_forms named
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor else noOwiseSen2Formula mk named
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor{- | applies maude2casl to compute the CASL signature and sentences from
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzorthe Maude ones, and wraps them into a Result datatype -}
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzormapTheory (sg, nsens) = return $ maude2casl sg nsens
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis{- | computes new signature and sentences of CASL associated to the
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzorgiven Maude signature and sentences -}
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzormaude2casl :: MSign.Sign -> [Named MSentence.Sentence]
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentismaude2casl msign nsens = (csign {
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor CSign.declaredSymbols = syms }, new_sens)
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor where csign = CSign.emptySign ()
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor ss' = Set.map sym2id ss
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor mk = kindMapId $ MSign.kindRel msign
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor sbs' = maudeSbs2caslSbs sbs mk
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis cs = Set.union ss' $ kindsFromMap mk
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis preds = rewPredicates cs
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis rs = rewPredicatesSens cs
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis ops = deleteUniversal $ MSign.ops msign
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor ksyms = kinds2syms cs
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor (cops, assoc_ops, _) = translateOps mk ops -- (cops, assoc_ops, comps)
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis axSens = axiomsSens mk ops
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor ctor_sen = [] -- [ctorSen False (cs, Rel.empty, comps)]
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis cops' = universalOps cs cops $ booleanImported ops
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis rs' = rewPredicatesCongSens cops'
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor pred_forms = loadLibraries (MSign.sorts msign) ops
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor ops_syms = ops2symbols cops'
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor (no_owise_sens, owise_sens, mbs_rls_sens) = splitOwiseEqs nsens
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor no_owise_forms = map (noOwiseSen2Formula mk) no_owise_sens
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis owise_forms = map (owiseSen2Formula mk no_owise_forms) owise_sens
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor mb_rl_forms = map (mb_rl2formula mk) mbs_rls_sens
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor preds_syms = preds2syms preds
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor syms = Set.union ksyms $ Set.union ops_syms preds_syms
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis new_sens = concat [rs, rs', no_owise_forms, owise_forms,
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis mb_rl_forms, ctor_sen, pred_forms, axSens]
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentis{- | translates the Maude subsorts into CASL subsorts, and adds the subsorts
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzorfor the kinds -}
fdcdd4e9cdf3f0213c5f63dac906531a1e5707a7lgentismaudeSbs2caslSbs :: MSign.SubsortRel -> IdMap -> Rel.Rel CAS.SORT
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzormaudeSbs2caslSbs sbs im = Rel.fromMap m4
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor l1 = [] -- map maudeSb2caslSb l
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor l2 = idList2Subsorts $ Map.toList im
1ffad0b9e645e3d784e55b63f972293da99d81a7gryzor l3 = map subsorts2Ids l
idList2Subsorts :: [(Id, Id)] -> [(Id, Set.Set Id)]
where t1 = (id1, Set.singleton id2)
maudeSb2caslSb (sym, st) = (sortSym2id sym, Set.map (kindId . sortSym2id) st)
subsorts2Ids (sym, st) = (sortSym2id sym, Set.map sortSym2id st)
sortSym2id :: MSym.Symbol -> Id
sortSym2id (MSym.Sort q) = token2id q
rewPredicatesCongSens = MapSet.foldWithKey rewPredCong []
-> [Named CAS.CASLFORMULA]
where args = CSign.opArgs ot
res = CSign.opRes ot
res_pred_type = CAS.Pred_type [res, res] nullRange
pn = CAS.Qual_pred_name rewID res_pred_type nullRange
conc_term1 = CAS.Application os vars1 nullRange
conc_term2 = CAS.Application os vars2 nullRange
conc_form = CAS.Predication pn [conc_term1, conc_term2] nullRange
-> [CAS.CASLFORMULA]
where pred_type = CAS.Pred_type [s, s] nullRange
pn = CAS.Qual_pred_name rewID pred_type nullRange
form = CAS.Predication pn [t, t'] nullRange
loadNaturalNatSens :: [Named CAS.CASLFORMULA]
case unsafePerformIO $ readLib "Maude/MaudeNumbers.casl" of
_ -> error "Maude.loadNaturalNatSens"
ctorCons :: Named CAS.CASLFORMULA -> Bool
CAS.Sort_gen_ax _ _ -> True
booleanImported :: MSign.OpMap -> Bool
booleanImported = Map.member (mkSimpleId "if_then_else_fi")
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.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 = head $ Set.toList syms
tl = tail $ 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.Sort_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
where sym = head $ Set.toList syms
tl = tail $ 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')
maudeSymbol2caslSort' (MSym.Sort q) _ =