Conversions.hs revision bfe34c9d0a279f8f86eae778b761f32e4788d42d
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian MaederModule : $Header$
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian MaederDescription : Functions to convert to internal SP* data structures.
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian MaederCopyright : (c) Rene Wagner, Klaus L�ttich, Uni Bremen 2005
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian MaederLicense : similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian MaederMaintainer : luecke@informatik.uni-bremen.de
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian MaederStability : provisional
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian MaederPortability : unknown
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian MaederFunctions to convert to internal SP* data structures.
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maederimport qualified Data.Map as Map
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maederimport qualified Data.Set as Set
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maederimport qualified Common.Lib.Rel as Rel
8191ab400cc9ebb5a3f6c6f18104a208aae187e8Christian Maeder Converts a Sign to an initial (no axioms or goals) SPLogicalPart.
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian MaedersignToSPLogicalPart :: Sign -> SPLogicalPart
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian MaedersignToSPLogicalPart s =
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder assert (checkArities s)
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder (emptySPLogicalPart {symbolList = sList,
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder declarationList = Just decList,
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder formulaLists = if null decList
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder else [predArgRestrictions]
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder sList = if Rel.null (sortRel s) && Map.null (funcMap s) &&
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder Map.null (predMap s) && Map.null (sortMap s)
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder else Just emptySymbolList
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder { functions =
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder map (\(f, ts) ->
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder SPSignSym {sym = f,
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder arity = length (fst (head
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder map (\(p, ts) ->
186de7a36bdf5910e0616c3a0447603e98217dc7Christian Maeder SPSignSym {sym = p,
186de7a36bdf5910e0616c3a0447603e98217dc7Christian Maeder arity = length (head
186de7a36bdf5910e0616c3a0447603e98217dc7Christian Maeder sorts = map SPSimpleSignSym $ Map.keys $ sortMap s }
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder decList = if (singleSorted s &&
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder (null . Map.elems . sortMap) s ) then []
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder else subsortDecl ++ termDecl ++ predDecl ++ genDecl
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder subsortDecl = map (\(a, b) -> SPSubsortDecl {sortSymA = a, sortSymB = b})
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder termDecl = concatMap termDecls (Map.toList (funcMap s))
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder termDecls (fsym, tset) = map (toFDecl fsym) (Set.toList tset)
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder toFDecl fsym (args, ret) =
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder then SPSimpleTermDecl
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder (SPComplexTerm {symbol = SPCustomSymbol ret,
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder arguments = [SPSimpleTerm
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder (SPCustomSymbol fsym)]})
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder else SPTermDecl {
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder termDeclTermList =
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder map (\(t, i) -> SPComplexTerm {symbol = SPCustomSymbol t,
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder arguments = [SPSimpleTerm
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder (mkSPCustomSymbol ('X' : (show i)))]})
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder (zip args [(1::Int)..]),
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder termDeclTerm = SPComplexTerm {symbol = SPCustomSymbol ret,
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder [SPComplexTerm {symbol = SPCustomSymbol fsym,
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder arguments = map
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder (SPSimpleTerm . mkSPCustomSymbol
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder . ('X':) . show . snd)
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder (zip args [(1::Int)..])}]}}
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder predArgRestrictions =
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder SPFormulaList { originType = SPOriginAxioms
8191ab400cc9ebb5a3f6c6f18104a208aae187e8Christian Maeder , formulae = Map.foldWithKey toArgRestriction []
| Set.size tset == 1 = acc ++
$ Set.toList tset)
(let argLists = Set.toList tset
then error "SoftFOL.Conversions.makeTerm: no propositional constants"
predDecl = concatMap predDecls (Map.toList (predMap s))
predDecls (p, tset) = -- assert (Set.size tset == 1)
concatMap (toPDecl p) (Set.toList tset)
(filter (isJust . snd) (Map.toList (sortMap s)))
SoftFOL.Sign.version = Nothing,
checkPredArities = Map.fold checkSet True
where checkSet s bv = bv && not (Set.null s) &&
where hd : tl = Set.toList s