PreComorphism.hs revision fecce42517d20490f893c4a9dee29b000e1653ea
545f1a3ee91056d6de32adab10c2eab26db89f27dpejeshimport qualified Data.List as List
545f1a3ee91056d6de32adab10c2eab26db89f27dpejeshimport qualified Data.Set as Set
545f1a3ee91056d6de32adab10c2eab26db89f27dpejeshimport qualified Data.Map as Map
96ad5d81ee4a2cc66a4ae19893efc8aa6d06fae7jailletcimport qualified Maude.Sign as MSign
7add1372edb1ee95a2c4d1314df4c7567bda7c62jimimport qualified Maude.Sentence as MSentence
7add1372edb1ee95a2c4d1314df4c7567bda7c62jimimport qualified Maude.Morphism as MMorphism
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowenimport qualified Maude.AS_Maude as MAS
2e545ce2450a9953665f701bb05350f0d3f26275ndimport qualified Maude.Symbol as MSym
7add1372edb1ee95a2c4d1314df4c7567bda7c62jimimport qualified CASL.Sign as CSign
5a58787efeb02a1c3f06569d019ad81fd2efa06endimport qualified CASL.Morphism as CMorphism
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowenimport qualified CASL.AS_Basic_CASL as CAS
3b3b7fc78d1f5bfc2769903375050048ff41ff26ndimport qualified Common.Lib.Rel as Rel
7add1372edb1ee95a2c4d1314df4c7567bda7c62jimtype IdMap = Map.Map Id Id
00b49f91367894cf867206991ff1373cfeabb759gryzortype OpTransTuple = (CSign.OpMap, CSign.OpMap, [Named CAS.CASLFORMULA], Set.Set Component)
e609c337f729875bc20e01096c7e610f45356f54nilgun-- | generates a CASL morphism from a Maude morphism
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjungmapMorphism :: MMorphism.Morphism -> Result (CMorphism.CASLMor)
3b3b7fc78d1f5bfc2769903375050048ff41ff26ndmapMorphism morph =
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen mk = arrangeKinds (MSign.sorts src) (MSign.subsorts src)
c68aa7f213d409d464eaa6b963afb28678548f4frbowen cs = kindsFromMap mk
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen smap' = applySortMap2CASLSorts smap cs
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen omap' = maudeOpMap2CASLOpMap mk omap
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen pmap = createPredMap mk smap
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen (src', _) = maude2casl src []
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen (tgt', _) = maude2casl tgt []
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen in return $ CMorphism.Morphism src' tgt' smap' omap' pmap ()
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen-- | translates the Maude morphism between operators into a CASL morpshim between
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen-- operators
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowenmaudeOpMap2CASLOpMap :: IdMap -> MMorphism.OpMap -> CMorphism.Op_map
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowenmaudeOpMap2CASLOpMap im = Map.foldWithKey (translateOpMapEntry im) Map.empty
aaf7b7f4cc1be050310c3d7f48bce0ec67e174e4nd-- | translates the mapping between two symbols representing operators into
5a58787efeb02a1c3f06569d019ad81fd2efa06end-- a CASL operators map
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowentranslateOpMapEntry :: IdMap -> MSym.Symbol -> MSym.Symbol -> CMorphism.Op_map
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowentranslateOpMapEntry im (MSym.Operator from ar co) (MSym.Operator to _ _) copm = copm'
a56ff98d3082c853f69e8de5c3e8bcab2734c0earbowen where f = token2id . getName
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh g = \ x -> fromJust $ Map.lookup (f x) im
5a58787efeb02a1c3f06569d019ad81fd2efa06end cop = (token2id from, ot)
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen to' = (token2id to, CAS.Total)
aaf7b7f4cc1be050310c3d7f48bce0ec67e174e4nd copm' = Map.insert cop to' copm
c68aa7f213d409d464eaa6b963afb28678548f4frbowentranslateOpMapEntry _ _ _ _ = Map.empty
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen-- | generates a set of CASL symbol from a Maude Symbol
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsfmapSymbol :: MSign.Sign -> MSym.Symbol -> Set.Set CSign.Symbol
aaf7b7f4cc1be050310c3d7f48bce0ec67e174e4nd where mk = arrangeKinds (MSign.sorts sg) (MSign.subsorts sg)
4aa603e6448b99f9371397d439795c91a93637eand sym_id = token2id q
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen kind = fromJust $ Map.lookup sym_id mk
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen pred_data = CSign.PredType [kind]
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen csym = CSign.Symbol sym_id $ CSign.PredAsItemType pred_data
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen where mk = arrangeKinds (MSign.sorts sg) (MSign.subsorts sg)
aaf7b7f4cc1be050310c3d7f48bce0ec67e174e4nd q' = token2id q
c68aa7f213d409d464eaa6b963afb28678548f4frbowen ar' = map (maudeSort2caslId mk) ar
aaf7b7f4cc1be050310c3d7f48bce0ec67e174e4nd co' = token2id $ getName co
aaf7b7f4cc1be050310c3d7f48bce0ec67e174e4ndmapSymbol _ _ = Set.empty
aaf7b7f4cc1be050310c3d7f48bce0ec67e174e4nd-- | returns the sort in CASL of the Maude sort symbol
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowenmaudeSort2caslId :: IdMap -> MSym.Symbol -> Id
4126704c4950bfd46d32ad54e3b106ac6d868a73sfmaudeSort2caslId im sym = fromJust $ Map.lookup (token2id $ getName sym) im
4126704c4950bfd46d32ad54e3b106ac6d868a73sf-- | creates the predicate map for the CASL morphism from the Maude sort map and
4126704c4950bfd46d32ad54e3b106ac6d868a73sf-- the map between sorts and kinds
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowencreatePredMap :: IdMap -> MMorphism.SortMap -> CMorphism.Pred_map
aaf7b7f4cc1be050310c3d7f48bce0ec67e174e4ndcreatePredMap im = Map.foldWithKey (createPredMap4sort im) Map.empty
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen-- | creates an entry of the predicate map for a single sort
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowencreatePredMap4sort :: IdMap -> MSym.Symbol -> MSym.Symbol -> CMorphism.Pred_map
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowencreatePredMap4sort im from to m = Map.insert key id_to m
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen where id_from = token2id $ getName from
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen id_to = token2id $ getName to
aaf7b7f4cc1be050310c3d7f48bce0ec67e174e4nd kind = fromJust $ Map.lookup id_from im
00b49f91367894cf867206991ff1373cfeabb759gryzor key = (id_from, CSign.PredType [kind])
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen-- | computes the sort morphism of CASL from the sort morphism in Maude and the set
aaf7b7f4cc1be050310c3d7f48bce0ec67e174e4nd-- of kinds
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowenapplySortMap2CASLSorts :: MMorphism.SortMap -> Set.Set Id -> CMorphism.Sort_map
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowenapplySortMap2CASLSorts sm = Set.fold (applySortMap2CASLSort sm) Map.empty
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen-- | computes the morphism for a single kind
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowenapplySortMap2CASLSort :: MMorphism.SortMap -> Id -> CMorphism.Sort_map -> CMorphism.Sort_map
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowenapplySortMap2CASLSort sm sort csm = new_csm
157312a2bcbad225c12462fc6d74b1aa3f32dceehumbedooh where toks = getTokens sort
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen new_toks = map (rename sm) toks
aaf7b7f4cc1be050310c3d7f48bce0ec67e174e4nd new_sort = mkId new_toks
545f1a3ee91056d6de32adab10c2eab26db89f27dpejesh new_csm = if new_sort == sort
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen else Map.insert sort new_sort csm
545f1a3ee91056d6de32adab10c2eab26db89f27dpejesh-- | renames the sorts in a given kind
545f1a3ee91056d6de32adab10c2eab26db89f27dpejeshrename :: MMorphism.SortMap -> Token -> Token
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowenrename sm tok = new_tok
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen where sym = MSym.Sort tok
545f1a3ee91056d6de32adab10c2eab26db89f27dpejesh sym' = if Map.member sym sm
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen then fromJust $ Map.lookup sym sm
545f1a3ee91056d6de32adab10c2eab26db89f27dpejesh new_tok = getName sym'
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen-- | translates a Maude sentence into a CASL formula
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowenmapSentence :: MSign.Sign -> MSentence.Sentence -> Result CAS.CASLFORMULA
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowenmapSentence sg sen@(MSentence.Equation eq) = case any MAS.owise ats of
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen False -> return $ sentence $ noOwiseSen2Formula mk named
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen True -> let
aaf7b7f4cc1be050310c3d7f48bce0ec67e174e4nd sg_sens = map (makeNamed "") $ Set.toList $ MSign.sentences sg
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen (no_owise_sens, _, _) = splitOwiseEqs sg_sens
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen no_owise_forms = map (noOwiseSen2Formula mk) no_owise_sens
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen trans = sentence $ owiseSen2Formula mk no_owise_forms named
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen in return trans
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen where mk = arrangeKinds (MSign.sorts sg) (MSign.subsorts sg)
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen MAS.Eq _ _ _ ats = eq
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen named = makeNamed "" sen
00b49f91367894cf867206991ff1373cfeabb759gryzormapSentence sg sen@(MSentence.Membership mb) = return $ sentence form
00b49f91367894cf867206991ff1373cfeabb759gryzor where mk = arrangeKinds (MSign.sorts sg) (MSign.subsorts sg)
545f1a3ee91056d6de32adab10c2eab26db89f27dpejesh MAS.Mb _ _ _ _ = mb
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim named = makeNamed "" sen
5a58787efeb02a1c3f06569d019ad81fd2efa06end form = mb_rl2formula mk named
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowenmapSentence sg sen@(MSentence.Rule rl) = return $ sentence form
aaf7b7f4cc1be050310c3d7f48bce0ec67e174e4nd where mk = arrangeKinds (MSign.sorts sg) (MSign.subsorts sg)
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen MAS.Rl _ _ _ _ = rl
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen named = makeNamed "" sen
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen form = mb_rl2formula mk named
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen-- | applies maude2casl to compute the CASL signature and sentences from
aaf7b7f4cc1be050310c3d7f48bce0ec67e174e4nd-- the Maude ones, and wraps them into a Result datatype
545f1a3ee91056d6de32adab10c2eab26db89f27dpejeshmapTheory :: (MSign.Sign, [Named MSentence.Sentence])
545f1a3ee91056d6de32adab10c2eab26db89f27dpejeshmapTheory (sg, nsens) = return $ maude2casl sg nsens
545f1a3ee91056d6de32adab10c2eab26db89f27dpejesh-- | computes new signature and sentences of CASL associated to the
545f1a3ee91056d6de32adab10c2eab26db89f27dpejesh-- given Maude signature and sentences
bbcc277fef0330ac4c1f937cb0dea78248225c0ahumbedoohmaude2casl msign nsens = (csign { CSign.sortSet = cs,
545f1a3ee91056d6de32adab10c2eab26db89f27dpejesh CSign.declaredSymbols = syms }, new_sens)
db99fa79ac42b9cc42b63386eb289aecb0f3cb9cnd where csign = CSign.emptySign ()
545f1a3ee91056d6de32adab10c2eab26db89f27dpejesh mk' = arrangeKinds (MSign.sorts msign) (MSign.subsorts msign)
bf082801b4063fe22a99661889cbd9a7701dae9fnd cs = kindsFromMap mk'
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen mk = Map.insert (token2id $ mkSimpleId "Universal") (token2id $ mkSimpleId "[Universal]") mk'
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen ks = kindPredicates mk
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf rp = rewPredicates ks cs
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf rs = rewPredicatesSens cs
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen ksyms = kinds2syms cs
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen (cops, assoc_ops, ops_forms, comps) = translateOps mk ops
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen ctor_sen = [ctorSen False (cs, Rel.empty, comps)]
a56ff98d3082c853f69e8de5c3e8bcab2734c0earbowen cops' = predefinedOps cs cops
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen ops_syms = ops2symbols cops
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen (no_owise_sens, owise_sens, mbs_rls_sens) = splitOwiseEqs nsens
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen no_owise_forms = map (noOwiseSen2Formula mk) no_owise_sens
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen owise_forms = map (owiseSen2Formula mk no_owise_forms) owise_sens
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen mb_rl_forms = map (mb_rl2formula mk) mbs_rls_sens
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen preds_syms = preds2syms preds
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen syms = Set.union ksyms $ Set.union ops_syms preds_syms
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen new_sens = concat [rs, ops_forms, no_owise_forms, owise_forms, mb_rl_forms, ctor_sen]
9e213c30f8f58680f0350736a2a6221baad94131humbedoohpredefinedOps kinds om = Set.fold predefinedOpKind om'' kinds
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen where if_id = token2id $ mkSimpleId "if_then_else_fi"
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen double_eq_id = token2id $ mkSimpleId "_==_"
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen neg_double_eq_id = token2id $ mkSimpleId "_=/=_"
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen om'' = Map.delete neg_double_eq_id om'
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowenpredefinedOpKind kind om = om3
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen where if_id = token2id $ mkSimpleId "if_then_else_fi"
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen double_eq_id = token2id $ mkSimpleId "_==_"
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen neg_double_eq_id = token2id $ mkSimpleId "_=/=_"
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen bool_id = token2id $ mkSimpleId "[Bool]"
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen if_opt = Set.singleton $ CSign.OpType CAS.Total [bool_id, kind, kind] kind
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen eq_opt = Set.singleton $ CSign.OpType CAS.Total [kind, kind] bool_id
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen om2 = Map.insertWith Set.union double_eq_id eq_opt om1
c35acdcbd4d173d3c536cf0be1295fa6c510cf8drbowen om3 = Map.insertWith Set.union neg_double_eq_id eq_opt om2
7add1372edb1ee95a2c4d1314df4c7567bda7c62jimpredefinedSens = Set.fold predefinedSensKind []
00b49f91367894cf867206991ff1373cfeabb759gryzorpredefinedSensKind :: Id -> [Named CAS.CASLFORMULA] -> [Named CAS.CASLFORMULA]
7f5b59ccc63c0c0e3e678a168f09ee6a2f51f9d0ndpredefinedSensKind kind acc = concat [iss, eqs, neqs, psen, acc]
e609c337f729875bc20e01096c7e610f45356f54nilgun where iss = ifSens kind
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung eqs = equalitySens kind
727872d18412fc021f03969b8641810d8896820bhumbedooh neqs = nonEqualitySens kind
0d0ba3a410038e179b695446bb149cce6264e0abnd psen = plusSen
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedoohifSens :: Id -> [Named CAS.CASLFORMULA]
0d0ba3a410038e179b695446bb149cce6264e0abndifSens kind = [form'', neg_form'']
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedooh where v1 = newVarIndex 1 kind
727872d18412fc021f03969b8641810d8896820bhumbedooh v2 = newVarIndex 2 kind
0d0ba3a410038e179b695446bb149cce6264e0abnd bv = newVarIndex 2 $ token2id $ mkSimpleId "[Bool]"
0d0ba3a410038e179b695446bb149cce6264e0abnd true_id = CAS.Op_name $ token2id $ mkSimpleId "true"
0d0ba3a410038e179b695446bb149cce6264e0abnd true_term = CAS.Application true_id [] nullRange
ac082aefa89416cbdc9a1836eaf3bed9698201c8humbedooh if_id = CAS.Op_name $ token2id $ mkSimpleId "if_then_else_fi"
0d0ba3a410038e179b695446bb149cce6264e0abnd if_term = CAS.Application if_id [bv, v1, v2] nullRange
0d0ba3a410038e179b695446bb149cce6264e0abnd prem = CAS.Strong_equation bv true_term nullRange
0d0ba3a410038e179b695446bb149cce6264e0abnd concl = CAS.Strong_equation if_term v1 nullRange
727872d18412fc021f03969b8641810d8896820bhumbedooh form = CAS.Implication prem concl True nullRange
0d0ba3a410038e179b695446bb149cce6264e0abnd form' = quantifyUniversally form
0d0ba3a410038e179b695446bb149cce6264e0abnd neg_prem = CAS.Negation prem nullRange
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh neg_concl = CAS.Strong_equation if_term v2 nullRange
205f749042ed530040a4f0080dbcb47ceae8a374rjung neg_form = CAS.Implication neg_prem neg_concl True nullRange
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen neg_form' = quantifyUniversally neg_form
0d0ba3a410038e179b695446bb149cce6264e0abnd name1 = show kind ++ "_if_true"
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd name2 = show kind ++ "_if_false"
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd form'' = makeNamed name1 form'
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd neg_form'' = makeNamed name2 neg_form'
equalitySens :: Id -> [Named CAS.CASLFORMULA]
true_id = CAS.Op_name $ token2id $ mkSimpleId "true"
true_term = CAS.Application true_id [] nullRange
false_id = CAS.Op_name $ token2id $ mkSimpleId "false"
false_term = CAS.Application false_id [] nullRange
prem = CAS.Strong_equation v1 v2 nullRange
double_eq_id = CAS.Op_name $ token2id $ mkSimpleId "_==_"
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.Op_name $ token2id $ mkSimpleId "true"
true_term = CAS.Application true_id [] nullRange
false_id = CAS.Op_name $ token2id $ mkSimpleId "false"
false_term = CAS.Application false_id [] nullRange
prem = CAS.Strong_equation v1 v2 nullRange
double_eq_id = CAS.Op_name $ token2id $ mkSimpleId "_=/=_"
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
plusSen :: [Named CAS.CASLFORMULA]
plus_id = CAS.Op_name $ token2id $ mkSimpleId "_+_"
succ_id = CAS.Op_name $ token2id $ mkSimpleId "s_"
succ_v1 = CAS.Application succ_id [v1] nullRange
lhs = CAS.Application plus_id [succ_v1, v2] nullRange
add_term = CAS.Application plus_id [v1, v2] nullRange
rhs = CAS.Application succ_id [add_term] nullRange
form = CAS.Strong_equation lhs rhs 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
sym = head $ Set.toList syms
cop_type = Set.singleton ot
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)
g = \ x -> fromJust $ Map.lookup (f x) im
ops2pred im = Set.fold (op2pred im) []
op2pred im (MSym.Operator op ar co) acc = case co of
MSym.Sort s -> let
op' = CAS.Op_name $ token2id op
pred_name = CAS.Pred_name co'
op_term = CAS.Application op' vars nullRange
op_pred = CAS.Predication pred_name [op_term] nullRange
else CAS.Implication conj_form op_pred True nullRange
createConjForm [] = CAS.True_atom nullRange
createConjForm fs = CAS.Conjunction fs nullRange
ops2predPremises im (MSym.Sort s : ss) i = (var : terms, form : forms)
kind = fromJust $ Map.lookup s' im
pred_name = CAS.Pred_name s'
form = CAS.Predication pred_name [var] nullRange
ops2predPremises im (MSym.Kind k : ss) i = (var : terms, forms)
kind = fromJust $ Map.lookup 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
kind = fromJust $ Map.lookup (token2id sub') im
sub_pred_name = CAS.Pred_name $ token2id sub'
super_pred_name = CAS.Pred_name $ token2id super'
sub_form = CAS.Predication sub_pred_name [var] nullRange
super_form = CAS.Predication super_pred_name [var] nullRange
form = CAS.Implication sub_form super_form True 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
form = CAS.Implication conds_form concl_form True nullRange
imp_form = CAS.Implication ex_form eq_form True 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
pred_name = CAS.Pred_name $ token2id $ getName s
form = CAS.Predication pred_name [ct] nullRange
mb2formula im (MAS.Mb t s conds@(_ : _) _) = quantifyUniversally form
pred_name = CAS.Pred_name $ token2id $ getName s
concl_form = CAS.Predication pred_name [ct] nullRange
form = CAS.Implication conds_form concl_form True nullRange
rl2formula im (MAS.Rl t t' [] _) = quantifyUniversally form
pred_name = CAS.Pred_name rewID
form = CAS.Predication pred_name [ct, ct'] nullRange
rl2formula im (MAS.Rl t t' conds@(_:_) _) = quantifyUniversally form
pred_name = CAS.Pred_name rewID
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
pred_name = CAS.Pred_name $ token2id $ getName s
pred_name = CAS.Pred_name rewID
where kind = fromJust $ Map.lookup (token2id $ getName ty) im
rewPredicatesSens = Set.fold rewPredicateSens []
reflSen :: Id -> Named CAS.CASLFORMULA
pn = CAS.Pred_name rewID
form = CAS.Predication pn [v, v] nullRange
transSen :: Id -> Named CAS.CASLFORMULA
pn = CAS.Pred_name rewID
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
rewPredicates m = Set.fold rewPredicate m
kindsFromMap :: IdMap -> Set.Set Id
where tops = List.sort $ getTop r s
tc = Rel.transClosure r
f = \ x y z -> Map.insert (sym2id y) (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
listVarDecl = Map.foldWithKey f []
noQuantification (CAS.Quantification _ vars form _) = (form, vars)
kinds2syms = Set.map kind2sym
kind2sym :: Id -> CSign.Symbol
pred2sym pn spt acc = Set.union set acc
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