SuleCFOL2SoftFOL.hs revision 3d86f079b07a6a058cdd6c112d287e01a69d9c0c
8a77240a809197c92c0736c431b4b88947a7bac1Christian Maeder{-# LANGUAGE MultiParamTypeClasses, TypeSynonymInstances, FlexibleInstances #-}
8a77240a809197c92c0736c431b4b88947a7bac1Christian MaederModule : $Header$
adea2e45fa61f1097aadc490a0aeaf4831b729ccChristian MaederDescription : Coding of a CASL subset into SoftFOL
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till MossakowskiCopyright : (c) Klaus Luettich and Uni Bremen 2005
09b431a868c79a92ae7c9bd141565f43f9034144Christian MaederLicense : GPLv2 or higher, see LICENSE.txt
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu ProdescuMaintainer : luecke@informatik.uni-bremen.de
2eeec5240b424984e3ee26296da1eeab6c6d739eChristian MaederStability : provisional
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till MossakowskiPortability : non-portable (imports Logic.Logic)
f3a94a197960e548ecd6520bb768cb0d547457bbChristian MaederThe translating comorphism from a CASL subset to SoftFOL.
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski ( suleCFOL2SoftFOL
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski , suleCFOL2SoftFOLInduction
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder , suleCFOL2SoftFOLInduction2
ad270004874ce1d0697fb30d7309f180553bb315Christian Maederimport qualified Common.Lib.Rel as Rel
1a38107941725211e7c3f051f7a8f5e12199f03acmaederimport qualified Common.Lib.MapSet as MapSet
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maederimport qualified Data.Map as Map
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maederimport qualified Data.Set as Set
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maederimport CASL.Induction (generateInductionLemmas)
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maederimport SoftFOL.Sign as SPSign
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowskidata PlainSoftFOL = PlainSoftFOL
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowskiinstance Show PlainSoftFOL where
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski show PlainSoftFOL = "SoftFOL"
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maederdata SoftFOLInduction = SoftFOLInduction deriving Show
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maederdata SoftFOLInduction2 = SoftFOLInduction2 deriving Show
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder-- | The identity of the comorphisms
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroederdata GenSuleCFOL2SoftFOL a = GenSuleCFOL2SoftFOL a deriving Show
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroedersuleCFOL2SoftFOL :: GenSuleCFOL2SoftFOL PlainSoftFOL
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroedersuleCFOL2SoftFOL = GenSuleCFOL2SoftFOL PlainSoftFOL
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroedersuleCFOL2SoftFOLInduction :: GenSuleCFOL2SoftFOL SoftFOLInduction
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till MossakowskisuleCFOL2SoftFOLInduction = GenSuleCFOL2SoftFOL SoftFOLInduction
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till MossakowskisuleCFOL2SoftFOLInduction2 :: GenSuleCFOL2SoftFOL SoftFOLInduction2
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroedersuleCFOL2SoftFOLInduction2 = GenSuleCFOL2SoftFOL SoftFOLInduction2
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder-- | SoftFOL theories
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maedertype SoftFOLTheory = (SPSign.Sign, [Named SPTerm])
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowskidata CType = CSort
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski deriving (Eq, Ord, Show)
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till MossakowskitoCKType :: CType -> CKType
09b431a868c79a92ae7c9bd141565f43f9034144Christian MaedertoCKType ct = case ct of
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski CSort -> CKSort
4ef5e33657aae95850b7e6941f67ac1fb73cd13fChristian Maeder CVar _ -> CKVar
4ef5e33657aae95850b7e6941f67ac1fb73cd13fChristian Maeder CPred _ -> CKPred
4ef5e33657aae95850b7e6941f67ac1fb73cd13fChristian Maeder COp _ -> CKOp
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski-- | CASL Ids with Types mapped to SPIdentifier
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowskitype IdTypeSPIdMap = Map.Map Id (Map.Map CType SPIdentifier)
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder-- | specialized lookup for IdTypeSPIdMap
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till MossakowskilookupSPId :: Id -> CType -> IdTypeSPIdMap ->
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski Maybe SPIdentifier
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till MossakowskilookupSPId i t = maybe Nothing (Map.lookup t) . Map.lookup i
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski-- | specialized insert (with error) for IdTypeSPIdMap
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till MossakowskiinsertSPId :: Id -> CType ->
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder SPIdentifier ->
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski IdTypeSPIdMap ->
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski IdTypeSPIdMap
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till MossakowskiinsertSPId i t spid m =
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski assert (checkIdentifier (toCKType t) $ show spid) $
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski Map.insertWith (Map.unionWith err) i (Map.insert t spid Map.empty) m
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder where err = error ("SuleCFOL2SoftFOL: for Id \"" ++ show i ++
a98fd29a06e80e447af26d898044c23497adbc73Mihai Codescu "\" the type \"" ++ show t ++
a98fd29a06e80e447af26d898044c23497adbc73Mihai Codescu "\" can't be mapped to different SoftFOL identifiers")
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till MossakowskideleteSPId :: Id -> CType ->
e7d2b3903c7b44db432538b0d720c21062c24823Christian Maeder IdTypeSPIdMap ->
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder IdTypeSPIdMap
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till MossakowskideleteSPId i t m =
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski maybe m (\ m2 -> let m2' = Map.delete t m2
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski else Map.insert i m2' m) $
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski-- | specialized elems into a set for IdTypeSPIdMap
09b431a868c79a92ae7c9bd141565f43f9034144Christian MaederelemsSPIdSet :: IdTypeSPIdMap -> Set.Set SPIdentifier
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till MossakowskielemsSPIdSet = Map.fold (\ m res -> Set.union res
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder-- extended signature translation
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowskitype SignTranslator f e = CSign.Sign f e -> e -> SoftFOLTheory -> SoftFOLTheory
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski-- extended signature translation for CASL
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till MossakowskisigTrCASL :: SignTranslator () ()
09b431a868c79a92ae7c9bd141565f43f9034144Christian MaedersigTrCASL _ _ = id
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder-- extended formula translation
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maedertype FormulaTranslator f e =
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder CSign.Sign f e -> IdTypeSPIdMap -> f -> SPTerm
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder-- extended formula translation for CASL
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederformTrCASL :: FormulaTranslator () ()
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederformTrCASL _ _ = error "SuleCFOL2SoftFOL: No extended formulas allowed in CASL"
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroederinstance Show a => Language (GenSuleCFOL2SoftFOL a) where
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder language_name (GenSuleCFOL2SoftFOL a) = "CASL2" ++ show a
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroederinstance Show a => Comorphism (GenSuleCFOL2SoftFOL a)
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder CASL CASL_Sublogics
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder CASLBasicSpec CASLFORMULA SYMB_ITEMS SYMB_MAP_ITEMS
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder CSign.Symbol RawSymbol ProofTree
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder SoftFOL () () SPTerm () ()
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder SoftFOLMorphism SFSymbol () ProofTree where
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder sourceLogic (GenSuleCFOL2SoftFOL _) = CASL
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder sourceSublogic (GenSuleCFOL2SoftFOL a) = SL.cFol
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder { sub_features = LocFilSub
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder , cons_features = emptyMapConsFeature
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder , has_empty_sorts = show a == show PlainSoftFOL }
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder targetLogic (GenSuleCFOL2SoftFOL _) = SoftFOL
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder mapSublogic cid sl =
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder if isSubElem sl $ sourceSublogic cid
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder then Just () else Nothing
c911a0ec80ca4a178399c68f1e28be4e2bf42fceChristian Maeder map_theory (GenSuleCFOL2SoftFOL a) = transTheory sigTrCASL formTrCASL
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder . case show a of
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder str | str == show SoftFOLInduction -> generateInductionLemmas True
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder | str == show SoftFOLInduction2 -> generateInductionLemmas False
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder | otherwise -> id
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder map_sentence (GenSuleCFOL2SoftFOL _) sign =
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder return . mapSen (isSingleSorted sign) formTrCASL sign
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder extractModel (GenSuleCFOL2SoftFOL _) = extractCASLModel
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder has_model_expansion (GenSuleCFOL2SoftFOL _) = True
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder-- -------------------------- Signature -----------------------------
09b431a868c79a92ae7c9bd141565f43f9034144Christian MaedertransFuncMap :: IdTypeSPIdMap ->
4d7d53fec6b551333c79da6ae3b8ca2af0a741abChristian Maeder (FuncMap, IdTypeSPIdMap)
09b431a868c79a92ae7c9bd141565f43f9034144Christian MaedertransFuncMap idMap sign = Map.foldWithKey toSPOpType (Map.empty, idMap)
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder where toSPOpType iden typeSet (fm, im) =
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder if not (Set.null typeSet) && Set.null (Set.deleteMin typeSet) then
d3c9318c22fcf44d9135a3b2c64f880b9a785babChristian Maeder let oType = Set.findMin typeSet
d3c9318c22fcf44d9135a3b2c64f880b9a785babChristian Maeder sid' = sid fm oType
d3c9318c22fcf44d9135a3b2c64f880b9a785babChristian Maeder in (Map.insert sid' (Set.singleton (transOpType oType)) fm,
d3c9318c22fcf44d9135a3b2c64f880b9a785babChristian Maeder insertSPId iden (COp oType) sid' im)
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder else Set.fold insOIdSet (fm, im) $
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder partOverload (leqF sign)
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder (partArities (length . CSign.opArgs) typeSet)
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder where insOIdSet tset (fm', im') =
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder let sid' = sid fm' (Set.findMax tset)
cd6e5706893519bfcf24539afa252fcbed5097ddKlaus Luettich in (Map.insert sid' (Set.map transOpType tset) fm',
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder Set.fold (\ x -> insertSPId iden (COp x) sid')
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder sid fma t = disSPOId CKOp (transId CKOp iden)
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder (uType (transOpType t))
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder (elemsSPIdSet idMap))
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder uType t = fst t ++ [snd t]
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder-- 1. devide into sets with different arities
09b431a868c79a92ae7c9bd141565f43f9034144Christian MaederpartArities :: (Ord a) => (a -> Int) -> Set.Set a -> Set.Set (Set.Set a)
e7d2b3903c7b44db432538b0d720c21062c24823Christian MaederpartArities len = part 0 Set.empty
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder where part i acc s
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder | otherwise =
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder case Set.partition (\ x -> len x == i) s of
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder (ar_i, rest) ->
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder part (i + 1) (if Set.null ar_i
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder else Set.insert ar_i acc) rest
09b431a868c79a92ae7c9bd141565f43f9034144Christian MaederpartOverload :: Ord a => (a -> a -> Bool) -> Set.Set (Set.Set a)
09b431a868c79a92ae7c9bd141565f43f9034144Christian MaederpartOverload leq =
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder Set.fold (Set.union . Set.fromList . Rel.partSet leq) Set.empty
09b431a868c79a92ae7c9bd141565f43f9034144Christian MaedertransPredMap :: IdTypeSPIdMap ->
cd6e5706893519bfcf24539afa252fcbed5097ddKlaus Luettich (SPSign.PredMap, IdTypeSPIdMap, [Named SPTerm])
09b431a868c79a92ae7c9bd141565f43f9034144Christian MaedertransPredMap idMap sign =
e7d2b3903c7b44db432538b0d720c21062c24823Christian Maeder Map.foldWithKey toSPPredType (Map.empty, idMap, []) . MapSet.toMap
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder where toSPPredType iden typeSet (fm, im, sen) =
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder if not (Set.null typeSet) && Set.null (Set.deleteMin typeSet) then
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder let pType = Set.findMin typeSet
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder sid' = sid fm pType
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder in (Map.insert sid' (Set.singleton (transPredType pType)) fm
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder , insertSPId iden (CPred pType) sid' im
a7be28e157e9ceeec73a8fd0e642c36ea29d4218Christian Maeder else case -- genPredImplicationDisjunctions sign $
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder partOverload (leqP sign)
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder (splitTySet) ->
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder let (fm', im') =
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder Set.fold insOIdSet (fm, im) splitTySet
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder in (fm', im', sen)
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder where insOIdSet tset (fm', im') =
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder let sid' = sid fm' (Set.findMax tset)
8c7aa750542dcadb94b971be712564a9a8f1d189Christian Maeder in (Map.insert sid' (Set.map transPredType tset) fm',
8c7aa750542dcadb94b971be712564a9a8f1d189Christian Maeder Set.fold (\ x -> insertSPId iden (CPred x) sid')
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder sid fma t = disSPOId CKPred (transId CKPred iden)
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder (transPredType t)
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder (elemsSPIdSet idMap))
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder{- left typing implies right typing; explicit overloading sentences
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maederare generated from these pairs, type TypePair = (CType,CType) -}
a98fd29a06e80e447af26d898044c23497adbc73Mihai Codescu-- | disambiguation of SoftFOL Identifiers
a98fd29a06e80e447af26d898044c23497adbc73Mihai CodescudisSPOId :: CKType -- ^ Type of CASl identifier
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder -> SPIdentifier -- ^ translated CASL Identifier
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder -> [SPIdentifier] {- ^ translated Sort Symbols of the profile
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder (maybe empty) -}
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder -> Set.Set SPIdentifier -- ^ SoftFOL Identifiers already in use
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder -> SPIdentifier {- ^ fresh Identifier generated from second argument;
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder if the identifier was not in the set this is just the second argument -}
09b431a868c79a92ae7c9bd141565f43f9034144Christian MaederdisSPOId cType sid ty idSet
a98fd29a06e80e447af26d898044c23497adbc73Mihai Codescu | checkIdentifier cType (show sid) && not (lkup $ show sid) = sid
a98fd29a06e80e447af26d898044c23497adbc73Mihai Codescu | otherwise = let nSid = disSPOId' $ show sid
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder in assert (checkIdentifier cType nSid) $ mkSimpleId nSid
a98fd29a06e80e447af26d898044c23497adbc73Mihai Codescu where disSPOId' sid'
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder | not (lkup asid) = asid
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder | otherwise = addType asid 1
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder where asid = sid' ++ case cType of
c911a0ec80ca4a178399c68f1e28be4e2bf42fceChristian Maeder x -> '_' : show (length ty - (case x of
c911a0ec80ca4a178399c68f1e28be4e2bf42fceChristian Maeder addType res n =
c911a0ec80ca4a178399c68f1e28be4e2bf42fceChristian Maeder let nres = asid ++ '_' : fc n
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder nres' = nres ++ '_' : show n
c911a0ec80ca4a178399c68f1e28be4e2bf42fceChristian Maeder in if nres == res
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder then if nres' == res
c911a0ec80ca4a178399c68f1e28be4e2bf42fceChristian Maeder then error ("SuleCFOL2SoftFOL: "
c911a0ec80ca4a178399c68f1e28be4e2bf42fceChristian Maeder ++ "cannot calculate"
c911a0ec80ca4a178399c68f1e28be4e2bf42fceChristian Maeder ++ " unambiguous id for "
c911a0ec80ca4a178399c68f1e28be4e2bf42fceChristian Maeder ++ show sid ++ " with type "
4ef5e33657aae95850b7e6941f67ac1fb73cd13fChristian Maeder ++ " and nres = " ++ nres
c911a0ec80ca4a178399c68f1e28be4e2bf42fceChristian Maeder ++ "\n with idSet "
4ef5e33657aae95850b7e6941f67ac1fb73cd13fChristian Maeder ++ show idSet)
4ef5e33657aae95850b7e6941f67ac1fb73cd13fChristian Maeder else if not (lkup nres')
4ef5e33657aae95850b7e6941f67ac1fb73cd13fChristian Maeder else addType nres (n + 1)
4ef5e33657aae95850b7e6941f67ac1fb73cd13fChristian Maeder else if not (lkup nres)
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder else addType nres (n + 1)
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder lkup x = Set.member (mkSimpleId x) idSet
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder fc n = concatMap (take n . show) ty
09b431a868c79a92ae7c9bd141565f43f9034144Christian MaedertransOpType :: CSign.OpType -> ([SPIdentifier], SPIdentifier)
09b431a868c79a92ae7c9bd141565f43f9034144Christian MaedertransOpType ot = (map transIdSort (CSign.opArgs ot),
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder transIdSort (CSign.opRes ot))
09b431a868c79a92ae7c9bd141565f43f9034144Christian MaedertransPredType :: CSign.PredType -> [SPIdentifier]
e8eb2b9d68adc3024eb1aa9899b902ed5a3fb460Christian MaedertransPredType = map transIdSort . CSign.predArgs
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder-- | translate every Id as Sort
e8eb2b9d68adc3024eb1aa9899b902ed5a3fb460Christian MaedertransIdSort :: Id -> SPIdentifier
09b431a868c79a92ae7c9bd141565f43f9034144Christian MaedertransIdSort = transId CKSort
09b431a868c79a92ae7c9bd141565f43f9034144Christian MaederintegrateGenerated :: IdTypeSPIdMap -> [Named (FORMULA f)] ->
09b431a868c79a92ae7c9bd141565f43f9034144Christian Maeder Result (IdTypeSPIdMap, SPSign.Sign, [Named SPTerm])
cd6e5706893519bfcf24539afa252fcbed5097ddKlaus LuettichintegrateGenerated idMap genSens sign
cd6e5706893519bfcf24539afa252fcbed5097ddKlaus Luettich | null genSens = return (idMap, sign, [])
c40a1fdc8ec6978bd27240d6780d0e0a7b6b0056Dominik Luecke | otherwise =
cd6e5706893519bfcf24539afa252fcbed5097ddKlaus Luettich case partition isAxiom genSens of
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder (genAxs, genGoals) ->
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder case makeGenGoals sign idMap genGoals of
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder (newPredsMap, idMap', goalsAndSentences) ->
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder -- makeGens must not invent new sorts
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder case makeGens sign idMap' genAxs of
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder Result dias mv ->
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder maybe (Result dias Nothing)
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder (\ (spSortMap_makeGens, newOpsMap, idMap'', exhaustSens) ->
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder let spSortMap' =
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder Map.union spSortMap_makeGens (SPSign.sortMap sign)
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder in assert (Map.size spSortMap' ==
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder (Just (idMap'',
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder sign { sortMap = spSortMap'
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder newPredsMap},
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder mkInjSentences idMap' newOpsMap ++
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder goalsAndSentences ++
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder exhaustSens))))
556f473448dfcceee22afaa89ed7a364489cdbbbChristian MaedermakeGenGoals :: SPSign.Sign -> IdTypeSPIdMap -> [Named (FORMULA f)]
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder -> (SPSign.PredMap, IdTypeSPIdMap, [Named SPTerm])
556f473448dfcceee22afaa89ed7a364489cdbbbChristian MaedermakeGenGoals sign idMap fs =
Nothing -> (Map.empty, idMap, [])
in (Map.empty, idMap', fs'')
makeGens :: SPSign.Sign -> IdTypeSPIdMap -> [Named (FORMULA f)]
case foldl (makeGen sign) (return (Map.empty, idMap, [], [])) fs of
(Just (foldr (uncurry Map.insert)
Map.empty pairs,
makeGen :: SPSign.Sign
hasTheSort _ _ = error "SuleCFOL2SoftFOL.hasTheSort"
ops_of_s = List.filter (hasTheSort s) ops
s' = fromMaybe (error $ "SuleCFOL2SoftFOL.makeGen: "
$ if Rel.member ta (transIdSort res)
$ SPSign.sortRel sign
not (Set.member (mkSimpleId x) usedIds))
ot' = CSign.toOpType ot
usedNames = Map.keysSet opM
err = error ("SuleCFOL2SoftFOL.mkInjOp: Cannot find SPId for '"
mkInjOp _ _ = error "SuleCFOL2SoftFOL.mkInjOp: Wrong constructor!!"
mkInjSentences idMap = Map.foldWithKey genInjs []
where genInjs k tset fs = Set.fold (genInj k) fs tset
fromJust (find (\ x -> not (Set.member (mkSimpleId x) usedIds))
Translate a CASL signature into SoftFOL signature 'SoftFOL.Sign.Sign'.
transSign :: CSign.Sign f e ->
(SPSign.Sign, IdTypeSPIdMap, [Named SPTerm])
, SPSign.predMap = pMap
Set.fold (\ i (sm, im) ->
(Map.keysSet sm)
in (Map.insert sid Nothing sm,
(CSign.sortSet sign)
nonEmptySortSens :: Set.Set SPIdentifier -> SortMap -> [Named SPTerm]
if s `Set.member` emptySorts then res else extSen s : res)
disjointTopSorts :: CSign.Sign f e -> IdTypeSPIdMap -> [Named SPTerm]
s = CSign.sortSet sign
sl = Rel.partSet (haveCommonSupersorts True sign) s
l = map (\ p -> case keepMinimals1 False sign id $ Set.toList p of
-> (CSign.Sign f e, [Named (FORMULA f)])
fmap (trSig sign (CSign.extendedInfo sign))
let tSignElim = if SPSign.singleSortNotGen tSign'
then tSign' {sortMap = Map.empty} else tSign'
emptySorts = Set.map transIdSort (emptySortSet sign)
(eqPreds, realSens') = foldl findEqPredicates (Set.empty, []) realSens
_ -> error "SuleCFOL2SoftFOL.transTheory.insInjOps"
(CSign.predMap sig)
(Set.fold (\ pl -> case pl of
Pred_name pn -> MapSet.insert pn (PredType [])
MapSet.empty eqPreds) }
findEqPredicates :: (Eq f) => (Set.Set PRED_SYMB, [Named (FORMULA f)])
-> (Set.Set PRED_SYMB, [Named (FORMULA f)])
&& (Map.toAscList
(Map.fromList $ sortedVarTermList [eq_t1, eq_t2])
then (Set.insert eq_pred_symb eqPreds, sens)
Finds a 'CASL.AS_Basic_CASL.Qual_var' term recursively if super term(s) is
fromMaybe (error $ "SuleCFOL2SoftFOL.transOPSYMB: unknown op: " ++ show qo)
(lookupSPId op (COp (CSign.toOpType ot)) idMap)
(error $ "SuleCFOL2SoftFOL.transPREDSYMB: unknown pred: " ++ show qp)
(lookupSPId p (CPred (CSign.toPredType pt)) idMap)
transVarTup :: (Set.Set SPIdentifier, IdTypeSPIdMap) ->
((Set.Set SPIdentifier, IdTypeSPIdMap),
((Set.insert sid usedIds,
-> CSign.Sign f e -> FORMULA f -> SPTerm
mapSen siSo trForm sign = transFORM siSo Set.empty sign
-> Set.Set PRED_SYMB -- ^ list of predicates to substitute
-> CSign.Sign f e
transFORMULA :: FormExtension f => Bool -> CSign.Sign f e -> IdTypeSPIdMap
maybe (error ("SuleCFOL2SoftFOL.tF: no SoftFOL Id found for \"" ++
error "SuleCFOL2SoftFOL.transFORMULA: Sort_gen_ax"
("SuleCFOL2SoftFOL.transFORMULA: unknown FORMULA '" ++ showDoc form "'")
transTERM :: FormExtension f => Bool -> CSign.Sign f e -> IdTypeSPIdMap
("SuleCFOL2SoftFOL.tT: no SoftFOL Id found for \"" ++ showDoc v "\""))
error "SuleCFOL2SoftFOL.transTERM: Conditional terms must be coded out."
_ -> error ("SuleCFOL2SoftFOL.transTERM: unknown TERM '" ++ showDoc term "'")
isSingleSorted :: CSign.Sign f e -> Bool
&& Set.null (emptySortSet sign) -- empty sorts need relativization
nops = Map.filter (\ v -> case v of
$ Map.toList nops
dts <- foldM getUneqElems Set.empty fs
$ Set.toList dts
type RMap = Map.Map SPIdentifier (CType, Maybe Id)
CSort -> Map.insert s (CPred $ PredType [i], Nothing)
$ map (\ (ty, _) -> Set.insert ty $ supersortsOf ty sign) ds
rm = foldr Map.delete m vs
m2 = foldr Map.delete nm vs
in (errs, Map.union m m2)
case Map.lookup cst m of
SPComplexTerm (SPCustomSymbol cst) args -> case Map.lookup cst m of
(fb, Map.insert cst (CVar r, Nothing) fm, ty)
else (fb, Map.insert cst
rm = foldr Map.delete m vs
case Map.lookup cst m of
SPComplexTerm (SPCustomSymbol cst) args -> case Map.lookup cst m of
SPComplexTerm (SPCustomSymbol cst) [] | isVar cst -> case Map.lookup cst m of