c7e03d0708369f944b6f235057b39142a21599f2Mihai Codescu{-# LANGUAGE MultiParamTypeClasses, TypeSynonymInstances, FlexibleInstances #-}
c7e03d0708369f944b6f235057b39142a21599f2Mihai CodescuCopyright : (c) Klaus Luettich, Uni Bremen 2002-2004
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu ProdescuLicense : GPLv2 or higher, see LICENSE.txt
c7e03d0708369f944b6f235057b39142a21599f2Mihai CodescuMaintainer : Christian.Maeder@dfki.de
c7e03d0708369f944b6f235057b39142a21599f2Mihai CodescuStability : provisional
c7e03d0708369f944b6f235057b39142a21599f2Mihai CodescuPortability : portable
90d7cac36f60438bd35124e3389b5bce6d114b46Christian MaederCoding out subsorting into unary predicates.
c7e03d0708369f944b6f235057b39142a21599f2Mihai Codescu New concept for proving Ontologies.
c7e03d0708369f944b6f235057b39142a21599f2Mihai Codescugeneratedness via non-injective datatype constructors
c7e03d0708369f944b6f235057b39142a21599f2Mihai Codescu(i.e. proper data constructors) is simply ignored
c7e03d0708369f944b6f235057b39142a21599f2Mihai Codescutotal functions my become partial because i.e. division is total
c7e03d0708369f944b6f235057b39142a21599f2Mihai Codescufor a second non-zero argument but partial otherwise.
c7e03d0708369f944b6f235057b39142a21599f2Mihai Codescupartial functions remain partial unless they fall to together
c208973c890b8f993297720fd0247bc7481d4304Christian Maederwith an overloaded total function
d90c545f128262b3ed863e447bc068ab2b9b2ff6Christian Maedermodule Comorphisms.CASL2TopSort (CASL2TopSort (..)) where
d90c545f128262b3ed863e447bc068ab2b9b2ff6Christian Maederimport qualified Common.Lib.Rel as Rel
d90c545f128262b3ed863e447bc068ab2b9b2ff6Christian Maederimport qualified Common.Lib.MapSet as MapSet
4f3a84cb1b7e55ce38df8f4ac71d06b574b23cb1mscodescuimport CASL.StaticAna (sortsOfArgs)
4b136ad539bd9f4e115dff4eee4d552a42d4437eChristian Maederimport qualified Data.Map as Map
36f69d35e01d2d6b6bdc165b49661f2a80af8687Mihai Codescuimport qualified Data.Set as Set
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder-- | The identity of the comorphism
4f3a84cb1b7e55ce38df8f4ac71d06b574b23cb1mscodescudata CASL2TopSort = CASL2TopSort deriving Show
4b136ad539bd9f4e115dff4eee4d552a42d4437eChristian Maederinstance Language CASL2TopSort where
fb891ddc67e73a126dfca1664396ec75068fd8cbMihai Codescu language_name CASL2TopSort = "CASL2PCFOLTopSort"
47e0312a5350da31881e35fe148233f9e252630fMihai Codescuinstance Comorphism CASL2TopSort
4b136ad539bd9f4e115dff4eee4d552a42d4437eChristian Maeder CASL CASL_Sublogics
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder CASLBasicSpec CASLFORMULA SYMB_ITEMS SYMB_MAP_ITEMS
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder Symbol RawSymbol ProofTree
d87ee0dd97c1e61947cf8522346c3126debcd8c1Christian Maeder CASL CASL_Sublogics
d87ee0dd97c1e61947cf8522346c3126debcd8c1Christian Maeder CASLBasicSpec CASLFORMULA SYMB_ITEMS SYMB_MAP_ITEMS
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder Symbol RawSymbol ProofTree where
28f6b9a4625b910f79be69a4dd819bbbd6e3f7b9Till Mossakowski sourceLogic CASL2TopSort = CASL
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder sourceSublogic CASL2TopSort = SL.caslTop
90d7cac36f60438bd35124e3389b5bce6d114b46Christian Maeder { sub_features = LocFilSub
d90c545f128262b3ed863e447bc068ab2b9b2ff6Christian Maeder , cons_features = emptyMapConsFeature }
d90c545f128262b3ed863e447bc068ab2b9b2ff6Christian Maeder targetLogic CASL2TopSort = CASL
d90c545f128262b3ed863e447bc068ab2b9b2ff6Christian Maeder mapSublogic CASL2TopSort sub =
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder if sub `isSubElem` sourceSublogic CASL2TopSort
d90c545f128262b3ed863e447bc068ab2b9b2ff6Christian Maeder sub { sub_features = NoSub -- subsorting is coded out
d90c545f128262b3ed863e447bc068ab2b9b2ff6Christian Maeder , cons_features = NoSortGen -- special Sort_gen_ax is coded out
d90c545f128262b3ed863e447bc068ab2b9b2ff6Christian Maeder , which_logic = max Horn (which_logic sub)
d90c545f128262b3ed863e447bc068ab2b9b2ff6Christian Maeder , has_eq = True {- was in the original targetLogic
d90c545f128262b3ed863e447bc068ab2b9b2ff6Christian Maeder may be avoided through predications of sort-preds
d90c545f128262b3ed863e447bc068ab2b9b2ff6Christian Maeder with the result terms of functions instead of formulas like:
d90c545f128262b3ed863e447bc068ab2b9b2ff6Christian Maeder forall x : T . bot = x => a(x)
36f69d35e01d2d6b6bdc165b49661f2a80af8687Mihai Codescu better: . a(bot) -}
36f69d35e01d2d6b6bdc165b49661f2a80af8687Mihai Codescu , has_pred = True
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder , has_part = True }
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder {- subsorting is coded out and
c7e03d0708369f944b6f235057b39142a21599f2Mihai Codescu special Sort_gen_ax are coded out -}
d90c545f128262b3ed863e447bc068ab2b9b2ff6Christian Maeder map_theory CASL2TopSort = mkTheoryMapping transSig transSen
c7e03d0708369f944b6f235057b39142a21599f2Mihai Codescu map_morphism CASL2TopSort mor = do
d90c545f128262b3ed863e447bc068ab2b9b2ff6Christian Maeder let trSig = fmap fst . transSig
d90c545f128262b3ed863e447bc068ab2b9b2ff6Christian Maeder sigSour <- trSig $ msource mor
d90c545f128262b3ed863e447bc068ab2b9b2ff6Christian Maeder sigTarg <- trSig $ mtarget mor
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder { msource = sigSour
c1d06b3018b34ede2b3fb6c7fe2ad28cd5ce5b68Christian Maeder , mtarget = sigTarg }
d90c545f128262b3ed863e447bc068ab2b9b2ff6Christian Maeder map_sentence CASL2TopSort = transSen
36f69d35e01d2d6b6bdc165b49661f2a80af8687Mihai Codescu map_symbol CASL2TopSort _ = Set.singleton . id
96d8cf9817eeb0d26cba09ca192fc5a33e27bc09mcodescu has_model_expansion CASL2TopSort = True
d90c545f128262b3ed863e447bc068ab2b9b2ff6Christian Maederdata PredInfo = PredInfo { topSortPI :: SORT
d90c545f128262b3ed863e447bc068ab2b9b2ff6Christian Maeder , directSuperSortsPI :: Set.Set SORT
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder , predicatePI :: PRED_NAME
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder } deriving Show
d90c545f128262b3ed863e447bc068ab2b9b2ff6Christian Maedertype SubSortMap = Map.Map SORT PredInfo
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroedergenerateSubSortMap :: Rel.Rel SORT -> PredMap -> SubSortMap
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroedergenerateSubSortMap sortRels pMap =
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder let disAmbMap = Map.map disAmbPred
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder disAmbPred v = let pn = predicatePI v in
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder case dropWhile (`Set.member` MapSet.keysSet pMap)
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder $ pn : map (\x -> appendString (predicatePI v) $ show x)
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder n : _ -> v { predicatePI = n }
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder [] -> error "generateSubSortMap"
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder Rel.partSet (\ x y -> Rel.member x y sortRels &&
(Rel.mostRight sortRels)
let ts = case filter (flip (Rel.member k) sortRels)
$ Set.toList mR of
_ -> error "CASL2TopSort.generateSubSortMap.toPredInfo"
, directSuperSortsPI = Set.difference e mR
(Map.mapWithKey toPredInfo
$ let sortRels = Rel.rmNullSets $ sortRel sig in
if Rel.nullKeys sortRels then (sig, []) else
newPreds = foldr (\ pI -> MapSet.insert (predicatePI pI)
newPredMap = MapSet.union (transPredMap subSortMap
{ sortRel = Rel.fromKeysSet
transPredMap subSortMap = MapSet.map transType
transOpMap :: Rel.Rel SORT -> SubSortMap -> OpMap -> OpMap
transOpMap sRel subSortMap = rmOrAddPartsMap True . MapSet.map transType
(\ a na -> a == na || Rel.member na a sRel)
procOpMapping :: SubSortMap -> OP_NAME -> Set.Set OpType
(++) . Map.foldWithKey procProfMapOpMapping [] . mkProfMapOp subSortMap
procProfMapOpMapping :: [SORT] -> (OpKind, Set.Set [Maybe PRED_NAME])
symmetryAxioms :: SubSortMap -> Rel.Rel SORT -> [Named (FORMULA ())]
let symSets = Rel.sccOfClosure sortRels
) . Set.toList
axs = Map.foldWithKey (procOpMapping subSortMap) []
$ MapSet.toMap oMap
Map.foldWithKey (\ pName ->
(++) . Map.foldWithKey
[] $ MapSet.toMap pMap
supPreds = map (lkupPred subSortMap) $ Set.toList set
) $ Map.elems subSortMap
mkProfMapPred :: SubSortMap -> Set.Set PredType
where seperate pt = MapSet.setInsert (pt2topSorts pt) (pt2preds pt)
mkProfMapOp :: SubSortMap -> Set.Set OpType
Map.insertWith (\ (k1, s1) (k2, s2) ->
(min k1 k2, Set.union s1 s2))
(fKind, Set.singleton $ pt2preds joinedList)
lkupTop ssm s = maybe s topSortPI (Map.lookup s ssm)
lkupPredM ssm s = fmap predicatePI $ Map.lookup s ssm
lkupPred ssm = fromMaybe (error "CASL2TopSort.lkupPred") . lkupPredM ssm
-> [SORT] -> Set.Set [Maybe PRED_NAME]
_ -> error "CASL2TopSort.genOpEquation: no result variable"
-> Set.Set [Maybe PRED_NAME]
genDisjunction :: [VAR_DECL] -> Set.Set [Maybe PRED_NAME] -> Maybe (FORMULA f)
| Set.size spn == 1 =
_ -> error "CASL2TopSort.genDisjunction: this cannot happen"
where disjs = foldl genConjunction [] (Set.toList spn)
transSen sig f = let sortRels = Rel.rmNullSets $ sortRel sig in
if Rel.noPairs sortRels then return f else do
error "CASL2TopSort.mapTerm: got untyped application"
ts = MapSet.lookup on opM
nK = if Set.member t1 ts then Total else Partial
error "CASL2TopSort.mapSen: got untyped predication"
_ -> error "CASL2TopSort.genEitherAxiom.groupedInjOps"
Op_name _ -> error "CASL2TopSort.genEitherAxiom.isInjObj"
resultSort _ = error "CASL2TopSort.genEitherAxiom.resultSort"
argSort _ = error "CASL2TopSort.genEitherAxiom.argSort"
else error "CASL2TopSort.genEitherAxiom.genImpl"
_ -> error "CASL2TopSort.genEitherAxiom.genImpl No OP_SYMB found"