CspCASL2IsabelleHOL.hs revision 286f4deb69d3912337bb09dd7f81284d12912ce8
81d182b21020b815887e9057959228546cf61b6bChristian MaederModule : $Header$
81d182b21020b815887e9057959228546cf61b6bChristian MaederDescription : embedding from CspCASL to Isabelle-HOL
66267bcb678a9c341272c323b299337bcfdb7cc5Christian MaederCopyright : (c) Andy Gimblett, Liam O'Reilly and Markus Roggenbach,
66267bcb678a9c341272c323b299337bcfdb7cc5Christian Maeder Swansea University 2008
3f69b6948966979163bdfe8331c38833d5d90ecdChristian MaederLicense : similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt
ffd01020a4f35f434b912844ad6e0d6918fadffdChristian MaederMaintainer : csliam@swansea.ac.uk
66267bcb678a9c341272c323b299337bcfdb7cc5Christian MaederStability : provisional
66267bcb678a9c341272c323b299337bcfdb7cc5Christian MaederPortability : non-portable (imports Logic.Logic)
fb69cd512eab767747f109e40322df7cae2f7bdfChristian MaederThe comorphism from CspCASL to Isabelle-HOL.
e8ffec0fa3d3061061bdc16e44247b9cf96b050fChristian Maeder CspCASL2IsabelleHOL(..)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederimport CASL.Morphism (RawSymbol)
5d7e4bf173534e7eb3fc84dce7bb0151079d3f8aChristian Maederimport qualified CASL.Inject as CASLInject
ad270004874ce1d0697fb30d7309f180553bb315Christian Maederimport qualified CASL.Sign as CASLSign
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederimport qualified Common.Lib.Rel as Rel
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederimport qualified Comorphisms.CASL2PCFOL as CASL2PCFOL
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederimport qualified Comorphisms.CASL2SubCFOL as CASL2SubCFOL
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederimport qualified Comorphisms.CFOL2IsabelleHOL as CFOL2IsabelleHOL
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederimport Comorphisms.CFOL2IsabelleHOL(IsaTheory)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederimport CspCASL.AS_CspCASL_Process (PROCESS_NAME)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederimport qualified Data.List as List
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederimport qualified Data.Set as Set
024621f43239cfe9629e35d35a8669fad7acbba2Christian Maederimport qualified Data.Map as Map
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederimport Isabelle.IsaConsts as IsaConsts
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederimport Isabelle.IsaSign as IsaSign
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- | The identity of the comorphism
5c933f3c61d2cfa7e76e4eb610a4b0bac988be47Christian Maederdata CspCASL2IsabelleHOL = CspCASL2IsabelleHOL deriving Show
5c933f3c61d2cfa7e76e4eb610a4b0bac988be47Christian Maederinstance Language CspCASL2IsabelleHOL where
8c81b727b788d90ff3b8cbda7b0900c9009243bbChristian Maeder language_name CspCASL2IsabelleHOL = "CspCASL2Isabelle"
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederinstance Comorphism CspCASL2IsabelleHOL
76647324ed70f33b95a881b536d883daccf9568dChristian Maeder CspBasicSpec CspCASLSen SYMB_ITEMS SYMB_MAP_ITEMS
05e2a3161e4589a717c6fe5c7306820273a473c5Christian Maeder Symbol RawSymbol ()
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder Isabelle () () IsaSign.Sentence () ()
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder IsabelleMorphism () () () where
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder sourceLogic CspCASL2IsabelleHOL = cspCASL
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder sourceSublogic CspCASL2IsabelleHOL = ()
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder targetLogic CspCASL2IsabelleHOL = Isabelle
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder mapSublogic _cid _sl = Just ()
c438c79d00fc438f99627e612498744bdc0d0c89Christian Maeder map_theory CspCASL2IsabelleHOL = transCCTheory
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder map_morphism = mapDefaultMorphism
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder map_sentence CspCASL2IsabelleHOL sign = transCCSentence sign
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder has_model_expansion CspCASL2IsabelleHOL = False
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder is_weakly_amalgamable CspCASL2IsabelleHOL = False
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder isInclusionComorphism CspCASL2IsabelleHOL = True
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- Functions for translating CspCasl theories and sentences to IsabelleHOL
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- | Translate CspCASL theories to Isabelle
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedertransCCTheory :: (CspCASLSign, [Named CspCASLSen]) -> Result IsaTheory
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedertransCCTheory ccTheory =
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder let ccSign = fst ccTheory
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder ccSens = snd ccTheory
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder caslSign = ccSig2CASLSign ccSign
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder cspSign = ccSig2CspSign ccSign
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder casl2pcfol = (map_theory CASL2PCFOL.CASL2PCFOL)
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder pcfol2cfol = (map_theory CASL2SubCFOL.defaultCASL2SubCFOL)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder cfol2isabelleHol = (map_theory CFOL2IsabelleHOL.CFOL2IsabelleHOL)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder sortList = Set.toList(CASLSign.sortSet caslSign)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder fakeType = Type {typeId = "Fake_Type" , typeSort = [], typeArgs =[]}
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder in do -- Remove Subsorting from the CASL part of the CspCASL specification
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder translation1 <- casl2pcfol (caslSign,[])
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder -- Next Remove partial functions
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder translation2 <- pcfol2cfol translation1
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder -- Next Translate to IsabelleHOL code
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder translation3 <- cfol2isabelleHol translation2
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder -- Next add the preAlphabet construction to the IsabelleHOL code
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder return $ addProcMap ccSens caslSign
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder $ addProcNameDatatype cspSign
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder $ addAllIntegrationTheorems sortList ccSign
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder $ addAllChooseFunctions sortList
5c933f3c61d2cfa7e76e4eb610a4b0bac988be47Christian Maeder $ addAllBarTypes sortList
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder $ addAlphabetType
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder $ addInstansanceOfEquiv
81d182b21020b815887e9057959228546cf61b6bChristian Maeder $ addJustificationTheorems ccSign (fst translation1)
5c933f3c61d2cfa7e76e4eb610a4b0bac988be47Christian Maeder $ addEqFun sortList
c438c79d00fc438f99627e612498744bdc0d0c89Christian Maeder $ addAllCompareWithFun ccSign
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder $ addPreAlphabet sortList
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder -- hack: show the casl sentences
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder -- addConst (show(ccSens)) fakeType
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder $ translation3
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- BUG This is not implemented in a sensible way yet and is not used
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedertransCCSentence :: CspCASLSign -> CspCASLSen -> Result IsaSign.Sentence
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedertransCCSentence _ (ProcessEq pn _ _ _) =
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder do return (mkSen (Const (mkVName (show pn))
76647324ed70f33b95a881b536d883daccf9568dChristian Maeder (Disp (Type "byeWorld" [] []) TFun Nothing)))
8aea46773664711e0910accc5cf80ef9ee1bcfbfChristian Maeder--------------------------------------------------------------------------
8aea46773664711e0910accc5cf80ef9ee1bcfbfChristian Maeder-- Functions for adding the process name datatype to an Isabelle theory --
8aea46773664711e0910accc5cf80ef9ee1bcfbfChristian Maeder--------------------------------------------------------------------------
8aea46773664711e0910accc5cf80ef9ee1bcfbfChristian Maeder-- | Add process name datatype which has a constructor for each
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- process name (along with the arguments for the process) in the
8aea46773664711e0910accc5cf80ef9ee1bcfbfChristian Maeder-- CspCASL Signature to an Isabelle theory
8aea46773664711e0910accc5cf80ef9ee1bcfbfChristian MaederaddProcNameDatatype :: CspSign -> IsaTheory -> IsaTheory
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederaddProcNameDatatype cspSign isaTh =
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder let -- Create a list of pairs of process names and thier profiles
8aea46773664711e0910accc5cf80ef9ee1bcfbfChristian Maeder procSetList = Map.toList (procSet cspSign)
8aea46773664711e0910accc5cf80ef9ee1bcfbfChristian Maeder procNameDomainEntry = mkProcNameDE procSetList
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder in updateDomainTab procNameDomainEntry isaTh
61091743da1a9ed6dfd5e077fdcc972553358962Christian Maeder-- | Make a proccess name Domain Entry from ...
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedermkProcNameDE :: [(PROCESS_NAME, ProcProfile)] -> DomainEntry
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedermkProcNameDE processes =
08b724e8dcbba5820d80f0974b9a5385140815baChristian Maeder let -- The a list of pairs of constructors and their arguments
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder constructors = map mk_cons processes
5d7e4bf173534e7eb3fc84dce7bb0151079d3f8aChristian Maeder -- Take a proccess name and its argument sorts (also its
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder -- commAlpha - thrown away) and make a pair representing the
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder -- constructor and the argument types
5d7e4bf173534e7eb3fc84dce7bb0151079d3f8aChristian Maeder mk_cons (procName, (ProcProfile sorts _)) =
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder (mkVName (mkProcNameConstructor procName), map sortToTyp sorts)
5d7e4bf173534e7eb3fc84dce7bb0151079d3f8aChristian Maeder -- Turn a sort in to a Typ suitable for the domain entry The
5d7e4bf173534e7eb3fc84dce7bb0151079d3f8aChristian Maeder -- processes need to have arguments of the bar variants of
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder -- the sorts not the original sorts
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder sortToTyp sort = Type {typeId = mkSortBarString sort,
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder typeSort = [isaTerm],
76647324ed70f33b95a881b536d883daccf9568dChristian Maeder typeArgs = []}
76647324ed70f33b95a881b536d883daccf9568dChristian Maeder (procNameType, constructors)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-------------------------------------------------------------------------
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- Functions adding the process map fucntion to an Isabelle theory --
76647324ed70f33b95a881b536d883daccf9568dChristian Maeder-------------------------------------------------------------------------
405b95208385572f491e1e0207d8d14e31022fa6Christian Maeder-- | Add the fucction procMap to an Isabelle theory. This function
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- maps process names to real processes build using the same names
8c81b727b788d90ff3b8cbda7b0900c9009243bbChristian Maeder-- and the alphabet i.e., ProcName => (ProcName, Alphabet) proc. We
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- need to know the CspCASL sentences and the casl signature (data
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederaddProcMap :: [Named CspCASLSen] -> CASLSign.Sign () () -> IsaTheory ->
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederaddProcMap namedSens caslSign isaTh =
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder -- Build new Isabelle theory with additional constant
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder isaThWithConst = addConst procMapS procMapType isaTh
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder -- Get the plain sentences from the named senetences
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder sens = map (\namedsen -> sentence namedsen) namedSens
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder -- Filter so we only have proccess equations and no CASL senetences
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder processEqs = filter isProcessEq sens
05e2a3161e4589a717c6fe5c7306820273a473c5Christian Maeder -- the term representing the procMap that tajes a term as a
76647324ed70f33b95a881b536d883daccf9568dChristian Maeder procMapTerm = termAppl (conDouble procMapS)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder -- Make a single equation for the primrec from a process equation
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder -- BUG HERE - this next part is not right - underscore is bad
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder mkEq (ProcessEq procName vars _ proc) =
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder let -- Make the name (string) for this process
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder procNameString = convertProcessName2String procName
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder -- Change the name to a term
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian Maeder procNameTerm = conDouble procNameString
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian Maeder -- Turn the list of variables into a list of Isabelle
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder -- free variables
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder varTerms = [] -- BUG - should be somehting like map (\x -> mkFree (show x)) vars
sortSuperSet = CASLSign.supersortsOf sort ccSign
sort'SuperSet =CASLSign.supersortsOf sort' ccSign
test2 = if (Set.member sort sort'SuperSet)
test3 = if (Set.member sort' sortSuperSet)
addJustificationTheorems :: CspCASLSign -> CASLSign.CASLSign ->
addAllInjectivityTheorems :: CASLSign.CASLSign -> [SORT] -> [(SORT,SORT)] ->
addInjectivityTheorem :: CASLSign.CASLSign -> [SORT] -> [(SORT,SORT)] ->
addAllDecompositionTheorem :: CASLSign.CASLSign -> [SORT] -> [(SORT,SORT)] ->
-- sorts. e.g. (S,T,U) means produce the lemma and proof for
addDecompositionTheorem :: CASLSign.CASLSign -> [SORT] -> [(SORT,SORT)] ->
abbrsNew = Map.insert alphabetS ([], preAlphabetQuotType) myabbrs
s1SuperSet = CASLSign.supersortsOf s1 ccSign
s2SuperSet = CASLSign.supersortsOf s2 ccSign
(Set.insert s1 s1SuperSet)
(Set.insert s2 s2SuperSet))
CASLSign.opArgs = [s],
CASLSign.opRes = s'})
injName = show $ CASLInject.uniqueInjName t
let index = List.elemIndex s sorts
getCollectionTotAx :: CASLSign.CASLSign -> [String]
totFilter (_,setOpType) = let listOpType = Set.toList setOpType
in CASLSign.opKind (head listOpType) == Total
Map.insert (mkVName cName) cType isaTh_sign_ConstTab