6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmann{-# LANGUAGE MultiParamTypeClasses, TypeSynonymInstances, FlexibleInstances #-}
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel HausmannDescription : translating from HolLight to Isabelle
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel HausmannCopyright : (c) Jonathan von Schroeder and M. Codescu, DFKI 2010
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel HausmannLicense : GPLv2 or higher, see LICENSE.txt
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel HausmannMaintainer : jonathan.von_schroeder@dfki.de
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel HausmannStability : provisional
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel HausmannPortability : non-portable (imports Logic.Logic)
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmannimport qualified Isabelle.IsaSign as IsaSign
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmannimport Isabelle.IsaConsts as IsaConsts
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmannimport qualified Data.Map as Map
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmanndata HolLight2Isabelle = HolLight2Isabelle deriving Show
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmanninstance Language HolLight2Isabelle
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmanninstance Comorphism HolLight2Isabelle
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmann HolLightSL -- sublogic
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmann () -- basic_spec
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmann Sentence -- sentence
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmann () -- symb_items
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmann () -- symb_map_items
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmann HolLightMorphism -- morphism
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmann () -- raw_symbol
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmann () -- proof_tree
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmann Isabelle () () IsaSign.Sentence () ()
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmann IsabelleMorphism () () () where
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmann sourceLogic _ = HolLight
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmann sourceSublogic _ = Top
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmann targetLogic _ = Isabelle
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmann mapSublogic _ _ = Just ()
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmann map_theory HolLight2Isabelle = mapTheory
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmann map_sentence HolLight2Isabelle = mapSentence
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmann-- mapping sentences
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel HausmannmapSentence :: Sign -> Sentence -> Result IsaSign.Sentence
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel HausmannmapSentence _ s = return $ mapHolSen s
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel HausmannmapHolSen :: Sentence -> IsaSign.Sentence
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel HausmannmapHolSen (Sentence t _) = IsaSign.Sentence {
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmann IsaSign.Term $ translateTerm t (allVars t)
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmanntp2DTyp :: HolType -> IsaSign.DTyp
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel HausmannconstMap = Map.fromList [("+", IsaConsts.plusV)
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel HausmannnotIgnore :: [String]
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel HausmannnotIgnore = ["+", "-", "*"]
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmannignore :: [String]
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmannignore = map fst (Map.toList constMap) \\ notIgnore
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel HausmanntransConstS :: String -> HolType -> IsaSign.VName
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel HausmanntransConstS s t = case (Map.lookup s constMap, elem s notIgnore) of
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmann (Just v, False) -> v
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmann (_, _) -> IsaConsts.mkVName $ typedName s t
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel HausmanntypedName :: String -> HolType -> String
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel HausmanntypedName s _t = transConstStringT bs s -- ++ "_" ++ (show $ pp_print_type t)
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmannunpack_gabs :: Term -> [String] -> (IsaSign.Term, [IsaSign.Term], IsaSign.Term, IsaSign.Term)
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmannunpack_gabs t vs = case unpack_gabs' t vs [] of
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmann Just (q, vars, tm) ->
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmann let (pat, res) = case tm of
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmann Comb (Comb (Const "GEQ" _ _)
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmann (Comb (Var "f" _ _) pat1)) res1 -> (pat1, res1)
6a4fa2d53294f484fa8788a75656eff4ad1fd703Daniel Hausmann _ -> error "unpack_gabs failed"
makeForAll q (v : vs) t = IsaSign.App q
(IsaSign.Abs v
handleGabs :: Bool -> Term -> [String] -> IsaSign.Term
let t1 = IsaSign.Abs n
(IsaSign.Case n [(pat, res)])
in if b then makeForAll q vars (IsaSign.App q t1
mkAbs :: Term -> [String] -> IsaSign.Term
(IsaSign.App (translateTerm t (name : vs))
mkQuantifier :: Term -> [String] -> IsaSign.Term
(IsaSign.App (translateTerm t (name : vs))
varNames :: [IsaSign.Term] -> [String]
translateTerm :: Term -> [String] -> IsaSign.Term
translateTerm (Var s tp _) _ = IsaSign.Free $ transConstS s tp
translateTerm (Const s tp _) _ = IsaSign.Const (transConstS s tp) $ tp2DTyp tp
IsaSign.If (translateTerm i vs) (translateTerm t vs)
(translateTerm e vs) IsaSign.NotCont
then IsaSign.App
else IsaSign.App (translateTerm c1 vs)
translateTerm (Comb tm1 tm2) vs = IsaSign.App (translateTerm tm1 vs)
translateTerm (Abs tm1 tm2) vs = IsaSign.Abs (translateTerm tm1 vs)
bs :: IsaSign.BaseSig
bs = IsaSign.MainHC_thy
mapSign :: Sign -> IsaSign.Sign
mapSign (Sign t o) = IsaSign.emptySign {
IsaSign.constTab = mapOps o,
IsaSign.tsig = mapTypes t
mapOps f = Map.fromList
tp2Typ :: HolType -> IsaSign.Typ
tp2Typ (TyVar ('\'' : s')) = IsaSign.TFree ('\'' : transTypeStringT bs s')
tp2Typ (TyVar s) = IsaSign.Type (transTypeStringT bs s) holType []
_ -> IsaSign.Type (transTypeStringT bs s) holType $ map tp2Typ tps
arity2tp i = [(isaTerm, map (\ k -> (IsaSign.TFree ("'a" ++ show k) [],
mapTypes tps = IsaSign.emptyTypeSig {
mapNamedSen :: Named Sentence -> Named IsaSign.Sentence