SuleCFOL2SoftFOL.hs revision 9e5c10805bd50b5baaf6bf1f6a3f085c7afb17d8
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett{-# LANGUAGE MultiParamTypeClasses, TypeSynonymInstances #-}
e071fb22ea9923a2a4ff41184d80ca46b55ee932Till MossakowskiModule : $Header$
020cdb5dad6b871aba61136a0e1567c00426de87Andy GimblettDescription : Coding of a CASL subset into SoftFOL
020cdb5dad6b871aba61136a0e1567c00426de87Andy GimblettCopyright : (c) Klaus Luettich and Uni Bremen 2005
020cdb5dad6b871aba61136a0e1567c00426de87Andy GimblettLicense : GPLv2 or higher, see LICENSE.txt
020cdb5dad6b871aba61136a0e1567c00426de87Andy GimblettMaintainer : luecke@informatik.uni-bremen.de
020cdb5dad6b871aba61136a0e1567c00426de87Andy GimblettStability : provisional
020cdb5dad6b871aba61136a0e1567c00426de87Andy GimblettPortability : non-portable (imports Logic.Logic)
020cdb5dad6b871aba61136a0e1567c00426de87Andy GimblettThe translating comorphism from a CASL subset to SoftFOL.
aa0d5f8be9950e788884f7431cf4cb7bee74788cAndy Gimblett (SuleCFOL2SoftFOL(..), SuleCFOL2SoftFOLInduction(..))
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblettimport Logic.Logic as Logic
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblettimport qualified Common.Lib.Rel as Rel
aa0d5f8be9950e788884f7431cf4cb7bee74788cAndy Gimblettimport qualified Data.Map as Map
aa0d5f8be9950e788884f7431cf4cb7bee74788cAndy Gimblettimport qualified Data.Set as Set
567db7182e691cce5816365d8c912d09ffe92f86Andy Gimblettimport CASL.Sign as CSign
aa0d5f8be9950e788884f7431cf4cb7bee74788cAndy Gimblettimport CASL.Induction (generateInductionLemmas)
aa0d5f8be9950e788884f7431cf4cb7bee74788cAndy Gimblettimport SoftFOL.Sign as SPSign
69b3701bf367eacfedd3efef1b95f697228e592aAndy Gimblett-- | The identity of the comorphisms
69b3701bf367eacfedd3efef1b95f697228e592aAndy Gimblettdata SuleCFOL2SoftFOL = SuleCFOL2SoftFOL deriving Show
69b3701bf367eacfedd3efef1b95f697228e592aAndy Gimblettdata SuleCFOL2SoftFOLInduction = SuleCFOL2SoftFOLInduction deriving Show
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett-- | SoftFOL theories
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimbletttype SoftFOLTheory = (SPSign.Sign,[Named SPTerm])
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblettdata CType = CSort
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett deriving (Eq,Ord,Show)
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy GimbletttoCKType :: CType -> CKType
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy GimbletttoCKType ct = case ct of
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett CSort -> CKSort
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett CVar _ -> CKVar
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett CPred _ -> CKPred
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett COp _ -> CKOp
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett-- | CASL Ids with Types mapped to SPIdentifier
edc768ab3a40d51bf18761330cfc4b4d460c0822Andy Gimbletttype IdTypeSPIdMap = Map.Map Id (Map.Map CType SPIdentifier)
29ac9ecacf0983a565b89f133ff2bdf2ac02b0c4Andy Gimblett-- | specialized lookup for IdTypeSPIdMap
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy GimblettlookupSPId :: Id -> CType -> IdTypeSPIdMap ->
edc768ab3a40d51bf18761330cfc4b4d460c0822Andy Gimblett Maybe SPIdentifier
edc768ab3a40d51bf18761330cfc4b4d460c0822Andy GimblettlookupSPId i t = maybe Nothing (Map.lookup t) . Map.lookup i
29ac9ecacf0983a565b89f133ff2bdf2ac02b0c4Andy Gimblett-- | specialized insert (with error) for IdTypeSPIdMap
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy GimblettinsertSPId :: Id -> CType ->
edc768ab3a40d51bf18761330cfc4b4d460c0822Andy Gimblett SPIdentifier ->
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett IdTypeSPIdMap ->
edc768ab3a40d51bf18761330cfc4b4d460c0822Andy Gimblett IdTypeSPIdMap
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy GimblettinsertSPId i t spid m =
edc768ab3a40d51bf18761330cfc4b4d460c0822Andy Gimblett assert (checkIdentifier (toCKType t) $ show spid) $
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett Map.insertWith (Map.unionWith err) i (Map.insert t spid Map.empty) m
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett where err = error ("SuleCFOL2SoftFOL: for Id \"" ++ show i ++
edc768ab3a40d51bf18761330cfc4b4d460c0822Andy Gimblett "\" the type \"" ++ show t ++
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett "\" can't be mapped to different SoftFOL identifiers")
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy GimblettdeleteSPId :: Id -> CType ->
edc768ab3a40d51bf18761330cfc4b4d460c0822Andy Gimblett IdTypeSPIdMap ->
29ac9ecacf0983a565b89f133ff2bdf2ac02b0c4Andy Gimblett IdTypeSPIdMap
29ac9ecacf0983a565b89f133ff2bdf2ac02b0c4Andy GimblettdeleteSPId i t m =
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett maybe m (\ m2 -> let m2' = Map.delete t m2
29ac9ecacf0983a565b89f133ff2bdf2ac02b0c4Andy Gimblett else Map.insert i m2' m) $
7371f8fe3a9a286a74ea30a3cd18e7740f67d537Andy Gimblett-- | specialized elems into a set for IdTypeSPIdMap
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy GimblettelemsSPIdSet :: IdTypeSPIdMap -> Set.Set SPIdentifier
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy GimblettelemsSPIdSet = Map.fold (\ m res -> Set.union res
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett-- extended signature translation
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimbletttype SignTranslator f e = CSign.Sign f e -> e -> SoftFOLTheory -> SoftFOLTheory
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett-- extended signature translation for CASL
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy GimblettsigTrCASL :: SignTranslator () ()
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy GimblettsigTrCASL _ _ = id
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett-- extended formula translation
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimbletttype FormulaTranslator f e =
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett CSign.Sign f e -> IdTypeSPIdMap -> f -> SPTerm
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett-- extended formula translation for CASL
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy GimblettformTrCASL :: FormulaTranslator () ()
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy GimblettformTrCASL _ _ = error "SuleCFOL2SoftFOL: No extended formulas allowed in CASL"
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblettinstance Language SuleCFOL2SoftFOL where
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett language_name SuleCFOL2SoftFOL = "CASL2SoftFOL"
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblettinstance Language SuleCFOL2SoftFOLInduction where
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett language_name SuleCFOL2SoftFOLInduction = "CASL2SoftFOLInduction"
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblettinstance Comorphism SuleCFOL2SoftFOL
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett CASL CASL_Sublogics
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett CASLBasicSpec CASLFORMULA SYMB_ITEMS SYMB_MAP_ITEMS
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett CSign.Symbol RawSymbol ProofTree
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett SoftFOL () () SPTerm () ()
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett SoftFOLMorphism SFSymbol () ProofTree where
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett sourceLogic SuleCFOL2SoftFOL = CASL
19ef749a762ef2c09579549715a63b364f0395d5Andy Gimblett sourceSublogic SuleCFOL2SoftFOL = SL.cFol
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett { sub_features = LocFilSub
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett , cons_features = emptyMapConsFeature
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett , has_empty_sorts = True }
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett targetLogic SuleCFOL2SoftFOL = SoftFOL
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett mapSublogic SuleCFOL2SoftFOL sl =
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett if isSubElem sl $ sourceSublogic SuleCFOL2SoftFOL
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett then Just () else Nothing
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett map_theory SuleCFOL2SoftFOL = transTheory sigTrCASL formTrCASL
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett map_morphism = mapDefaultMorphism
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett map_sentence SuleCFOL2SoftFOL sign =
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett return . mapSen (isSingleSorted sign) formTrCASL sign
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett extractModel SuleCFOL2SoftFOL = extractCASLModel
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett has_model_expansion SuleCFOL2SoftFOL = True
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblettinstance Comorphism SuleCFOL2SoftFOLInduction
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett CASL CASL_Sublogics
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett CASLBasicSpec CASLFORMULA SYMB_ITEMS SYMB_MAP_ITEMS
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett CSign.Symbol RawSymbol ProofTree
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett SoftFOL () () SPTerm () ()
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett SoftFOLMorphism SFSymbol () ProofTree where
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett sourceLogic SuleCFOL2SoftFOLInduction = CASL
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett sourceSublogic SuleCFOL2SoftFOLInduction = SL.cFol
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett { sub_features = LocFilSub
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett , cons_features = emptyMapConsFeature }
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett targetLogic SuleCFOL2SoftFOLInduction = SoftFOL
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett mapSublogic SuleCFOL2SoftFOLInduction sl =
7371f8fe3a9a286a74ea30a3cd18e7740f67d537Andy Gimblett if isSubElem sl $ sourceSublogic SuleCFOL2SoftFOLInduction
7371f8fe3a9a286a74ea30a3cd18e7740f67d537Andy Gimblett then Just () else Nothing
7371f8fe3a9a286a74ea30a3cd18e7740f67d537Andy Gimblett map_theory SuleCFOL2SoftFOLInduction =
7371f8fe3a9a286a74ea30a3cd18e7740f67d537Andy Gimblett transTheory sigTrCASL formTrCASL . generateInductionLemmas
7371f8fe3a9a286a74ea30a3cd18e7740f67d537Andy Gimblett map_morphism = mapDefaultMorphism
7371f8fe3a9a286a74ea30a3cd18e7740f67d537Andy Gimblett map_sentence SuleCFOL2SoftFOLInduction sign =
7371f8fe3a9a286a74ea30a3cd18e7740f67d537Andy Gimblett return . mapSen (isSingleSorted sign) formTrCASL sign
7371f8fe3a9a286a74ea30a3cd18e7740f67d537Andy Gimblett extractModel SuleCFOL2SoftFOLInduction = extractCASLModel
7371f8fe3a9a286a74ea30a3cd18e7740f67d537Andy Gimblett has_model_expansion SuleCFOL2SoftFOLInduction = True
7371f8fe3a9a286a74ea30a3cd18e7740f67d537Andy Gimblett---------------------------- Signature -----------------------------
7371f8fe3a9a286a74ea30a3cd18e7740f67d537Andy GimbletttransFuncMap :: IdTypeSPIdMap ->
7371f8fe3a9a286a74ea30a3cd18e7740f67d537Andy Gimblett (FuncMap, IdTypeSPIdMap)
7371f8fe3a9a286a74ea30a3cd18e7740f67d537Andy GimbletttransFuncMap idMap sign =
7371f8fe3a9a286a74ea30a3cd18e7740f67d537Andy Gimblett Map.foldrWithKey toSPOpType (Map.empty,idMap) (CSign.opMap sign)
if Set.null typeSet then
let oType = Set.findMin typeSet
else Set.fold insOIdSet (fm,im) $
(partArities (length . CSign.opArgs) typeSet)
let sid' = sid fm' (Set.findMax tset)
Set.fold (\ x -> insertSPId iden (COp x) sid')
partArities len = part 0 Set.empty
| Set.null s = acc
case Set.partition (\ x -> len x == i) s of
part (i+1) (if Set.null ar_i
else Set.insert ar_i acc) rest
CSign.Sign e f ->
if Set.null typeSet then
let pType = Set.findMin typeSet
(Set.singleton typeSet) of
Set.fold insOIdSet (fm,im) splitTySet
let sid' = sid fm' (Set.findMax tset)
Set.fold (\ x -> insertSPId iden (CPred x) sid')
-> Set.Set SPIdentifier -- ^ SoftFOL Identifiers already in use
lkup x = Set.member (mkSimpleId x) idSet
transOpType :: CSign.OpType -> ([SPIdentifier],SPIdentifier)
transOpType ot = (map transIdSort (CSign.opArgs ot),
transIdSort (CSign.opRes ot))
transPredType :: CSign.PredType -> [SPIdentifier]
transPredType = map transIdSort . CSign.predArgs
SPSign.Sign ->
Result (IdTypeSPIdMap, SPSign.Sign, [Named SPTerm])
in assert (Map.size spSortMap' ==
Map.union (funcMap sign)
, SPSign.predMap =
(SPSign.predMap sign)
makeGenGoals :: SPSign.Sign -> IdTypeSPIdMap -> [Named (FORMULA f)]
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.foldrWithKey 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 newMap -> case pl of
Map.empty eqPreds) }
if Map.member pId pMap
then Map.adjust insPredSet pId pMap
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 :: Pretty f => Bool -> CSign.Sign f e -> IdTypeSPIdMap
maybe (error ("SuleCFOL2SoftFOL.tF: no SoftFOL Id found for \"" ++
error "SuleCFOL2SoftFOL.transFORMULA: Sort_gen_ax"
error ("SuleCFOL2SoftFOL.transFORMULA: unknown FORMULA '" ++ showDoc f "'")
transTERM :: Pretty 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 t "'")
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