Utils.hs revision bcd914850de931848b86d7728192a149f9c0108b
e9458b1a7a19a63aa4c179f9ab20f4d50681c168Jens ElknerModule : $Header$
726baec6dfb69adb27f2afb4b2027fe5e7670c4aTill MossakowskiDescription : Utilities for CspCASLProver related to the actual
726baec6dfb69adb27f2afb4b2027fe5e7670c4aTill Mossakowski construction of Isabelle theories.
726baec6dfb69adb27f2afb4b2027fe5e7670c4aTill MossakowskiCopyright : (c) Liam O'Reilly and Markus Roggenbach,
726baec6dfb69adb27f2afb4b2027fe5e7670c4aTill Mossakowski Swansea University 2009
726baec6dfb69adb27f2afb4b2027fe5e7670c4aTill MossakowskiLicense : GPLv2 or higher, see LICENSE.txt
726baec6dfb69adb27f2afb4b2027fe5e7670c4aTill MossakowskiMaintainer : csliam@swansea.ac.uk
726baec6dfb69adb27f2afb4b2027fe5e7670c4aTill MossakowskiStability : provisional
726baec6dfb69adb27f2afb4b2027fe5e7670c4aTill MossakowskiPortability : portable
726baec6dfb69adb27f2afb4b2027fe5e7670c4aTill MossakowskiUtilities for CspCASLProver related to the actual construction of
726baec6dfb69adb27f2afb4b2027fe5e7670c4aTill MossakowskiIsabelle theories.
726baec6dfb69adb27f2afb4b2027fe5e7670c4aTill Mossakowski ( addAlphabetType
726baec6dfb69adb27f2afb4b2027fe5e7670c4aTill Mossakowski , addAllBarTypes
726baec6dfb69adb27f2afb4b2027fe5e7670c4aTill Mossakowski , addAllChooseFunctions
726baec6dfb69adb27f2afb4b2027fe5e7670c4aTill Mossakowski , addAllCompareWithFun
27de5bf664bde811f402d8e43db0721d3c58362cTill Mossakowski , addAllIntegrationTheorems
80875f917d741946a39d0ec0b5721e46ba609823Till Mossakowski , addAllGaAxiomsCollections
726baec6dfb69adb27f2afb4b2027fe5e7670c4aTill Mossakowski , addEventDataType
726baec6dfb69adb27f2afb4b2027fe5e7670c4aTill Mossakowski , addFlatTypes
726baec6dfb69adb27f2afb4b2027fe5e7670c4aTill Mossakowski , addInstansanceOfEquiv
726baec6dfb69adb27f2afb4b2027fe5e7670c4aTill Mossakowski , addJustificationTheorems
b6f5631ceb98f1be235d3b53e145f83fd7565bfamcodescu , addPreAlphabet
80875f917d741946a39d0ec0b5721e46ba609823Till Mossakowski , addProcNameDatatype
726baec6dfb69adb27f2afb4b2027fe5e7670c4aTill Mossakowski , addProjFlatFun
726baec6dfb69adb27f2afb4b2027fe5e7670c4aTill Mossakowski , addProcTheorems
27de5bf664bde811f402d8e43db0721d3c58362cTill Mossakowskiimport qualified CASL.Fold as CASL_Fold
27de5bf664bde811f402d8e43db0721d3c58362cTill Mossakowskiimport qualified CASL.Sign as CASLSign
27ae03fc2f67c39292e72f0a69837f34b2521c29mcodescuimport qualified CASL.Inject as CASLInject
09e732ce6115cf6aaedc2622e8e78696bb875b60mcodescuimport Common.AS_Annotation (makeNamed, Named, SenAttr (..))
09e732ce6115cf6aaedc2622e8e78696bb875b60mcodescuimport qualified Common.Lib.Rel as Rel
09e732ce6115cf6aaedc2622e8e78696bb875b60mcodescuimport Comorphisms.CASL2PCFOL (mkEmbInjName, mkTransAxiomName, mkIdAxiomName)
b0dc688d623e51d3848b4b56d090669f18fc8f17mcodescuimport Comorphisms.CASL2SubCFOL (mkNotDefBotAxiomName, mkTotalityAxiomName)
27ae03fc2f67c39292e72f0a69837f34b2521c29mcodescuimport Comorphisms.CFOL2IsabelleHOL (IsaTheory)
04f798a5a79477754ad20e255444d99757911be0mcodescuimport qualified Comorphisms.CFOL2IsabelleHOL as CFOL2IsabelleHOL
82a602f211abdebc623f4823b913c8ffea10af06mcodescuimport CspCASLProver.TransProcesses (transProcess, VarSource (..))
80875f917d741946a39d0ec0b5721e46ba609823Till Mossakowskiimport qualified Data.List as List
156ff56fb6d907911e63df36d12df9220877981amcodescuimport qualified Data.Map as Map
156ff56fb6d907911e63df36d12df9220877981amcodescuimport qualified Data.Set as Set
27de5bf664bde811f402d8e43db0721d3c58362cTill Mossakowskiimport Isabelle.Translate (transString)
27de5bf664bde811f402d8e43db0721d3c58362cTill Mossakowski-- -----------------------------------------------------------------------
27de5bf664bde811f402d8e43db0721d3c58362cTill Mossakowski-- Functions for adding the PreAlphabet datatype to an Isabelle theory --
27de5bf664bde811f402d8e43db0721d3c58362cTill Mossakowski-- -----------------------------------------------------------------------
27de5bf664bde811f402d8e43db0721d3c58362cTill Mossakowski-- | Add the PreAlphabet (built from a list of sorts) to an Isabelle
04f798a5a79477754ad20e255444d99757911be0mcodescuaddPreAlphabet :: [SORT] -> IsaTheory -> IsaTheory
04f798a5a79477754ad20e255444d99757911be0mcodescuaddPreAlphabet sortList isaTh =
04f798a5a79477754ad20e255444d99757911be0mcodescu let preAlphabetDomainEntry = mkPreAlphabetDE sortList
27ae03fc2f67c39292e72f0a69837f34b2521c29mcodescu -- Add to the isabelle signature the new domain entry
80875f917d741946a39d0ec0b5721e46ba609823Till Mossakowski in updateDomainTab preAlphabetDomainEntry isaTh
c0ca1d8524a3ca7f687adf192468541ae68802c9mcodescu-- | Make a Domain Entry for the PreAlphabet from a list of sorts.
76212ada4c518a69f3125b3531b716c7f5151177mcodescumkPreAlphabetDE :: [SORT] -> DomainEntry
04f798a5a79477754ad20e255444d99757911be0mcodescumkPreAlphabetDE sorts =
80875f917d741946a39d0ec0b5721e46ba609823Till Mossakowski (mkSType preAlphabetS,
80875f917d741946a39d0ec0b5721e46ba609823Till Mossakowski map (\ sort ->
b6f5631ceb98f1be235d3b53e145f83fd7565bfamcodescu (mkVName (mkPreAlphabetConstructor sort),
04f798a5a79477754ad20e255444d99757911be0mcodescu [mkSType $ convertSort2String sort])
09e732ce6115cf6aaedc2622e8e78696bb875b60mcodescu-- --------------------------------------------------------------
09e732ce6115cf6aaedc2622e8e78696bb875b60mcodescu-- Functions for adding the eq functions and the compare_with --
09e732ce6115cf6aaedc2622e8e78696bb875b60mcodescu-- functions to an Isabelle theory --
80875f917d741946a39d0ec0b5721e46ba609823Till Mossakowski-- --------------------------------------------------------------
04f798a5a79477754ad20e255444d99757911be0mcodescu-- | Add the eq function to an Isabelle theory using a list of sorts
04f798a5a79477754ad20e255444d99757911be0mcodescuaddEqFun :: [SORT] -> IsaTheory -> IsaTheory
04f798a5a79477754ad20e255444d99757911be0mcodescuaddEqFun sortList isaTh =
04f798a5a79477754ad20e255444d99757911be0mcodescu let eqtype = mkFunType preAlphabetType $ mkFunType preAlphabetType boolType
80875f917d741946a39d0ec0b5721e46ba609823Till Mossakowski isaThWithConst = addConst eq_PreAlphabetS eqtype isaTh
b6f5631ceb98f1be235d3b53e145f83fd7565bfamcodescu let x = mkFree "x"
c0ca1d8524a3ca7f687adf192468541ae68802c9mcodescu y = mkFree "y"
82a602f211abdebc623f4823b913c8ffea10af06mcodescu lhs = binEq_PreAlphabet lhs_a y
b6f5631ceb98f1be235d3b53e145f83fd7565bfamcodescu lhs_a = termAppl (conDouble (mkPreAlphabetConstructor sort)) x
27ae03fc2f67c39292e72f0a69837f34b2521c29mcodescu rhs = termAppl rhs_a y
27ae03fc2f67c39292e72f0a69837f34b2521c29mcodescu rhs_a = termAppl (conDouble (mkCompareWithFunName sort)) x
b6f5631ceb98f1be235d3b53e145f83fd7565bfamcodescu in binEq lhs rhs
04f798a5a79477754ad20e255444d99757911be0mcodescu eqs = map mkEq sortList
09e732ce6115cf6aaedc2622e8e78696bb875b60mcodescu in addPrimRec eqs isaThWithConst
04f798a5a79477754ad20e255444d99757911be0mcodescu-- | Add all compare_with functions for a given list of sorts to an
04f798a5a79477754ad20e255444d99757911be0mcodescu-- Isabelle theory. We need to know about the casl signature (data
80875f917d741946a39d0ec0b5721e46ba609823Till Mossakowski-- part of a CspCASL spec) so that we can pass it on to the
b6f5631ceb98f1be235d3b53e145f83fd7565bfamcodescu-- addCompareWithFun function
b6f5631ceb98f1be235d3b53e145f83fd7565bfamcodescuaddAllCompareWithFun :: CASLSign.CASLSign -> IsaTheory -> IsaTheory
b6f5631ceb98f1be235d3b53e145f83fd7565bfamcodescuaddAllCompareWithFun caslSign isaTh =
04f798a5a79477754ad20e255444d99757911be0mcodescu let sortList = Set.toList (CASLSign.sortSet caslSign)
35f4256bb7c21011ecd0656f32cd8e3275253ff7mcodescu in foldl (addCompareWithFun caslSign) isaTh sortList
04f798a5a79477754ad20e255444d99757911be0mcodescu-- | Add a single compare_with function for a given sort to an
04f798a5a79477754ad20e255444d99757911be0mcodescu-- Isabelle theory. We need to know about the casl signature (data
35f4256bb7c21011ecd0656f32cd8e3275253ff7mcodescu-- part of a CspCASL spec) to work out the RHS of the equations.
35f4256bb7c21011ecd0656f32cd8e3275253ff7mcodescuaddCompareWithFun :: CASLSign.CASLSign -> IsaTheory -> SORT -> IsaTheory
80875f917d741946a39d0ec0b5721e46ba609823Till MossakowskiaddCompareWithFun caslSign isaTh sort =
35f4256bb7c21011ecd0656f32cd8e3275253ff7mcodescu let sortList = Set.toList (CASLSign.sortSet caslSign)
b6f5631ceb98f1be235d3b53e145f83fd7565bfamcodescu sortType = Type {typeId = convertSort2String sort, typeSort = [],
35f4256bb7c21011ecd0656f32cd8e3275253ff7mcodescu typeArgs = []}
b6f5631ceb98f1be235d3b53e145f83fd7565bfamcodescu funName = mkCompareWithFunName sort
80875f917d741946a39d0ec0b5721e46ba609823Till Mossakowski funType = mkFunType sortType $ mkFunType preAlphabetType boolType
80875f917d741946a39d0ec0b5721e46ba609823Till Mossakowski isaThWithConst = addConst funName funType isaTh
35f4256bb7c21011ecd0656f32cd8e3275253ff7mcodescu sortSuperSet = CASLSign.supersortsOf sort caslSign
35f4256bb7c21011ecd0656f32cd8e3275253ff7mcodescu mkEq sort' =
04f798a5a79477754ad20e255444d99757911be0mcodescu let x = mkFree "x"
b6f5631ceb98f1be235d3b53e145f83fd7565bfamcodescu y = mkFree "y"
b6f5631ceb98f1be235d3b53e145f83fd7565bfamcodescu sort'Constructor = mkPreAlphabetConstructor sort'
80875f917d741946a39d0ec0b5721e46ba609823Till Mossakowski lhs = termAppl lhs_a lhs_b
27de5bf664bde811f402d8e43db0721d3c58362cTill Mossakowski lhs_a = termAppl (conDouble funName) x
27de5bf664bde811f402d8e43db0721d3c58362cTill Mossakowski lhs_b = termAppl (conDouble sort'Constructor) y
sort'SuperSet = CASLSign.supersortsOf sort' caslSign
test2 = if Set.member sort sort'SuperSet
test3 = if Set.member sort' sortSuperSet
-- to PCFOL (i.e. without subsorting)
-- translation to PCFOL (i.e. without subsorting)
-- sorts. e.g. (S,T,U) means produce the lemma and proof for
addAllInjectivityTheorems :: CASLSign.CASLSign -> [SORT] -> [(SORT, SORT)] ->
addInjectivityTheorem :: CASLSign.CASLSign -> [SORT] -> [(SORT, SORT)] ->
abbrsNew = Map.insert alphabetS ([], preAlphabetQuotType) myabbrs
addAllIntegrationTheorems :: [SORT] -> CASLSign.CASLSign -> IsaTheory ->
addIntegrationTheorem_A :: CASLSign.CASLSign -> IsaTheory -> (SORT, SORT) ->
s1SuperSet = CASLSign.supersortsOf s1 caslSign
s2SuperSet = CASLSign.supersortsOf s2 caslSign
(Set.insert s1 s1SuperSet)
(Set.insert s2 s2SuperSet))
addEventDataType :: Rel.Rel SORT -> ChanNameMap -> IsaTheory -> IsaTheory
mkEventDE :: Rel.Rel SORT -> ChanNameMap -> DomainEntry
-- procSetList = Map.toList (procSet cspSign)
procNameDomainEntry = error "NYI: CspCASLProver.Utils.addProcNameDatatype: Not updated for new signatures yet"-- mkProcNameDE procSetList
-- names to real processes build using the same names and the alphabet i.e.,
tyToks = CFOL2IsabelleHOL.typeToks caslSign
trForm = CFOL2IsabelleHOL.formTrCASL
strs = CFOL2IsabelleHOL.getAssumpsToks caslSign
transVar fqVar = CASL_Fold.foldTerm
-- implied i.e., where axiom=true. first filter the axioms only then
procNameString = error "Error CspCASLProver.Utils.addProcMap: NYI with new signatures yet" -- convertProcessName2String procName
Qual_var v _ _ -> Map.insert v GlobalParameter vdm'
_ -> error "CspCASLProver.Utils.addProcMap: Term other than fully qualified variable in process parameter variable list"
vdm = foldr addToVdm Map.empty fqVars
-- implied i.e., where axiom=false. first filter the axioms only then
let -- the LHS a a process in abstract syntax i.e. process name with
lhs' = error "Error CspCASLProver.Utils.addProcTheorms: NYI with new signatures yet"-- NamedProcess procName fqVars nullRange
Qual_var v _ _ -> Map.insert v GlobalParameter vdm'
_ -> error "CspCASLProver.Utils.addProcMap: Term other than fully qualified variable in process parameter variable list"
vdm = foldr addToVdm Map.empty fqVars
getCollectionTotAx :: CASLSign.CASLSign -> [String]
totFilter (_, setOpType) = let listOpType = Set.toList setOpType
in CASLSign.opKind (head listOpType) == Total
let index = List.elemIndex s sorts
CASLSign.opArgs = [s],
CASLSign.opRes = s'})
injName = show $ CASLInject.uniqueInjName t
getCollectionTransAx :: CASLSign.CASLSign -> [String]
getCollectionIdentityAx :: CASLSign.CASLSign -> [String]