4673N/A{-# LANGUAGE MultiParamTypeClasses, TypeSynonymInstances, FlexibleInstances #-}
4673N/ADescription : embedding from CASL (CFOL) to Isabelle-HOL
4673N/ACopyright : (c) Till Mossakowski and Uni Bremen 2003-2005
4673N/AMaintainer : Christian.Maeder@dfki.de
4673N/AThe embedding comorphism from CASL to Isabelle-HOL.
4673N/A-- | The identity of the comorphism
4673N/Adata CFOL2IsabelleHOL = CFOL2IsabelleHOL deriving Show
4673N/A-- extended signature translation
4673N/A-- extended signature translation for CASL
4673N/AsigTrCASL :: SignTranslator () ()
4673N/A-- extended formula translation
4673N/A-- extended formula translation for CASL
4673N/AformTrCASL :: FormulaTranslator () ()
4673N/AformTrCASL _ _ = error "CFOL2IsabelleHOL: No extended formulas allowed in CASL"
4673N/Ainstance Language CFOL2IsabelleHOL where
4673N/A language_name CFOL2IsabelleHOL = "CASL2Isabelle"
4673N/Ainstance Comorphism CFOL2IsabelleHOL
4673N/A CASLBasicSpec CASLFORMULA SYMB_ITEMS SYMB_MAP_ITEMS
4673N/A IsabelleMorphism () () () where
4673N/A sourceLogic CFOL2IsabelleHOL = CASL
4673N/A targetLogic CFOL2IsabelleHOL = Isabelle
4673N/A mapSublogic cid sl = if sl `isSubElem` sourceSublogic cid
4673N/A map_theory CFOL2IsabelleHOL = return . transTheory sigTrCASL formTrCASL
4673N/A map_sentence CFOL2IsabelleHOL sign =
4673N/A return . mapSen formTrCASL sign (typeToks sign)
4673N/A has_model_expansion CFOL2IsabelleHOL = True
4673N/A is_weakly_amalgamable CFOL2IsabelleHOL = True
4673N/A isInclusionComorphism CFOL2IsabelleHOL = True
4673N/A-- -------------------------- Signature -----------------------------
4673N/AtransTheory :: FormExtension f => SignTranslator f e ->
4673N/AtransTheory trSig trForm (sign, sens) =
4673N/A tsig = emptyTypeSig {arities =
4673N/A map (\ (s, n) -> makeNamed ("ga_induction_" ++ show n) $ myMapSen s)
4673N/A map (mapNamed myMapSen) real_sens)
4673N/A -- for now, no new sentences
map (inductionScheme . fst) genTypes
myMapSen = mkSen . transFORMULA sign tyToks trForm (getAssumpsToks sign)
(real_sens, sort_gen_axs) = foldr ( \ s (rs, cs) -> case sentence s of
Sort_gen_ax c b -> (rs, (c, b) : cs)
_ -> (s : rs, cs)) ([], []) sens
unique_sort_gen_axs = nubOrdOn (
Set.fromList . map newSort . fst)
(freeTypes, genTypes) = partition snd unique_sort_gen_axs
dtDefs = makeDtDefs sign tyToks $ map fst freeTypes
insertOps op ts m = if isSingleton ts then
(mkIsaConstT False ga (length $ opArgs t) op baseSign tyToks)
(mkIsaConstIT False ga (length $ opArgs t) op i baseSign tyToks)
insertPreds pre ts m = if isSingleton ts then
(mkIsaConstT True ga (length $ predArgs t) pre baseSign tyToks)
(mkIsaConstIT True ga (length $ predArgs t) pre i baseSign tyToks)
-> [[(Typ, [(VName, [Typ])])]]
makeDtDefs sign = map . makeDtDef sign
-> [(Typ, [(VName, [Typ])])]
makeDtDef sign tyToks constrs = map makeDt srts where
(srts, ops, _maps) = recover_Sort_gen_ax constrs
makeDt s = (transSort s, map makeOp (filter (hasTheSort s) ops))
makeOp opSym = (transOpSymb sign tyToks opSym, transArgs opSym)
hasTheSort s (Qual_op_name _ ot _) = s == res_OP_TYPE ot
transArgs (Qual_op_name _ ot _) = map transSort $ args_OP_TYPE ot
transSort s = Type (showIsaTypeT s baseSign) [] []
transOpType :: OpType -> Typ
transOpType ot = mkCurryFunType (map transSort $ opArgs ot)
transPredType :: PredType -> Typ
transPredType pt = mkCurryFunType (map transSort $ predArgs pt) boolType
-- ---------------------------- Formulas ------------------------------
$ map ( \ (_, o) -> getConstIsaToks i o baseSign)
$ map ( \ (_, o) -> getConstIsaToks i o baseSign)
transVar ::
Set.Set String -> VAR -> String
s = showIsaConstT (simpleIdToId v) baseSign
renVar t = if
Set.member t toks then renVar $ "X_" ++ t else t
quantifyIsa :: String -> (String, Typ) -> Term -> Term
quantifyIsa q (v, _) phi =
termAppl (conDouble q) (Abs (mkFree v) phi NotCont)
quantify ::
Set.Set String -> QUANTIFIER -> (VAR, SORT) -> Term -> Term
quantifyIsa (qname q) (transVar toks v, transSort t)
qname Unique_existential = ex1S
transOpSymb sign tyToks qo = case qo of
Qual_op_name op ot _ -> let
l = length $ args_OP_TYPE ot
[] -> error $ "CASL2Isabelle unknown op: " ++ show op
[_] -> mkIsaConstT False ga l op baseSign tyToks
ots -> case elemIndex (toOpType ot) ots of
Just i -> mkIsaConstIT False ga l op (i + 1) baseSign tyToks
Nothing -> error $ "CASL2Isabelle unknown type for op: " ++ show op
Op_name op -> error $ "CASL2Isabelle: unqualified op: " ++ show op
transPredSymb sign tyToks qp =
d = mkIsaConstT True ga (-1) (predSymbName qp) baseSign tyToks
-- for predicate names in induction schemes
Qual_pred_name p pt@(Pred_type args _) _ -> let
[_] -> mkIsaConstT True ga l p baseSign tyToks
pts -> case elemIndex (toPredType pt) pts of
Just i -> mkIsaConstIT True ga l p (i + 1) baseSign tyToks
mapSen trForm sign tyToks =
mkSen . transFORMULA sign tyToks trForm (getAssumpsToks sign)
->
Set.Set String -> Record f Term Term
transRecord sign tyToks tr toks = Record
{ foldQuantification = \ _ qu vdecl phi _ ->
foldr (quantify toks qu) phi (flatVAR_DECLs vdecl)
, foldJunction = \ _ j phis _ -> let
in if null phis then n else foldr1 op phis
, foldRelation = \ _ phi1 c phi2 _ -> (if c == Equivalence
then binEqv else binImpl) phi1 phi2
, foldNegation = \ _ phi _ -> termAppl notOp phi
, foldAtom = \ _ b _ -> if b then true else false
, foldPredication = \ _ psymb args _ ->
foldl termAppl (con $ transPredSymb sign tyToks psymb) args
, foldDefinedness = \ _ _ _ -> true -- totality assumed
, foldEquation = \ _ t1 _ t2 _ -> binEq t1 t2 -- equal types assumed
, foldMembership = \ _ _ _ _ -> true -- no subsorting assumed
, foldMixfix_formula = error "transRecord: Mixfix_formula"
, foldSort_gen_ax = error "transRecord: Sort_gen_ax"
, foldQuantOp = error "transRecord: QuantOp"
, foldQuantPred = error "transRecord: QuantPred"
, foldExtFORMULA = \ _ -> tr sign tyToks
, foldQual_var = \ _ v _ _ -> mkFree $ transVar toks v
, foldApplication = \ _ opsymb args _ ->
foldl termAppl (con $ transOpSymb sign tyToks opsymb) args
, foldSorted_term = \ _ t _ _ -> t -- no subsorting assumed
, foldCast = \ _ t _ _ -> t -- no subsorting assumed
, foldConditional = \ _ t1 phi t2 _ -> -- equal types assumed
, foldMixfix_qual_pred = error "transRecord: Mixfix_qual_pred"
, foldMixfix_term = error "transRecord: Mixfix_term"
, foldMixfix_token = error "transRecord: Mixfix_token"
, foldMixfix_sorted_term = error "transRecord: Mixfix_sorted_term"
, foldMixfix_cast = error "transRecord: Mixfix_cast"
, foldMixfix_parenthesized = error "transRecord: Mixfix_parenthesized"
, foldMixfix_bracketed = error "transRecord: Mixfix_bracketed"
, foldMixfix_braced = error "transRecord: Mixfix_braced"
, foldExtTERM = error "transRecord: ExtTERM"
->
Set.Set String -> FORMULA f -> Term
transFORMULA sign tyToks tr = foldFormula . transRecord sign tyToks tr