Show
Ignore:
Timestamp:
01.09.2008 18:29:05 (15 months ago)
Author:
csliam
Message:

Added production of the first intergation theorem and continued work on
process translation

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/Comorphisms/CspCASL2IsabelleHOL.hs

    r10574 r10619  
    3030import CspCASL.AS_CspCASL 
    3131import CspCASL.Trans_CspProver 
     32import CspCASL.Trans_Consts 
    3233import CspCASL.SignCSP 
    3334import qualified Data.List as List 
     
    8889          -- Next add the preAlpabet construction to the IsabelleHOL code 
    8990          return $ addCspCaslSentences ccSens 
     91                 $ addAllIntegrationTheorems sortList ccSign 
    9092                 $ addAllChooseFunctions sortList 
    9193                 $ addAllBarTypes sortList 
     
    107109-- | Add a list of CspCASL sentences to an Isabelle theory 
    108110addCspCaslSentences :: [Named CspCASLSentence] -> IsaTheory -> IsaTheory 
    109 addCspCaslSentences namedSens isaTh = foldl addCspCaslSentence isaTh namedSens 
     111addCspCaslSentences namedSens isaTh = 
     112    -- Create datatype for process names 
     113    -- crate constant 
     114    -- create primrec 
     115      -- create list of equations -- one for each sentence 
     116    foldl addCspCaslSentence isaTh namedSens 
    110117 
    111118-- | Add a single CspCASL sentence to an Isabelle theory 
     
    211218                test1 = if (sort == sort') then [binEq x y] else [] 
    212219                test2 = if (Set.member sort sort'SuperSet) 
    213                         then [binEq x (termAppl (getInjectionOp sort' sort) y)] 
     220                        then [binEq x (mkInjection sort' sort y)] 
    214221                        else [] 
    215222                test3 = if (Set.member sort' sortSuperSet) 
    216                         then [binEq (termAppl (getInjectionOp sort sort') x) y] 
     223                        then [binEq (mkInjection sort sort' x) y] 
    217224                        else [] 
    218225                test4 = if (null commonSuperList) 
    219226                        then [] 
    220227                        else map test4_atSort commonSuperList 
    221                 test4_atSort s = binEq (termAppl (getInjectionOp sort s) x) 
    222                                        (termAppl (getInjectionOp sort' s) y) 
     228                test4_atSort s = binEq (mkInjection sort  s x) 
     229                                       (mkInjection sort' s y) 
    223230            in binEq lhs rhs 
    224231        eqs = map mkEq sortList 
     
    293300    let x = mkFree "x" 
    294301        y = mkFree "y" 
    295         injOp = getInjectionOp s1 s2 
    296         injX = termAppl injOp x 
    297         injY = termAppl injOp y 
     302        injX = mkInjection s1 s2 x 
     303        injY = mkInjection s1 s2 y 
    298304        definedOp_s1 = getDefinedOp sorts s1 
    299305        definedOp_s2 = getDefinedOp sorts s2 
     
    339345addDecompositionTheorem pfolSign sorts sortRel isaTh (s1,s2,s3) = 
    340346    let x = mkFree "x" 
    341         injOp_s1_s2 = getInjectionOp s1 s2 
    342         injOp_s2_s3 = getInjectionOp s2 s3 
    343         injOp_s1_s3 = getInjectionOp s1 s3 
    344         inj_s1_s2_s3 = termAppl injOp_s2_s3 (termAppl injOp_s1_s2 x) 
    345         inj_s1_s3 = termAppl injOp_s1_s3 x 
     347        -- These 5 lines make use of currying 
     348        injOp_s1_s2 = mkInjection s1 s2 
     349        injOp_s2_s3 = mkInjection s2 s3 
     350        injOp_s1_s3 = mkInjection s1 s3 
     351        inj_s1_s2_s3_x = injOp_s2_s3 (injOp_s1_s2 x) 
     352        inj_s1_s3_x = injOp_s1_s3 x 
     353 
    346354        definedOp_s1 = getDefinedOp sorts s1 
    347355        definedOp_s3 = getDefinedOp sorts s3 
     
    352360        name = getDecompositionThmName(s1, s2, s3) 
    353361        conds = [] 
    354         concl = binEq inj_s1_s2_s3 inj_s1_s3 
    355  
    356         proof' = IsaProof [Apply(CaseTac (definedOp_s3 inj_s1_s2_s3)), 
     362        concl = binEq inj_s1_s2_s3_x inj_s1_s3_x 
     363 
     364        proof' = IsaProof [Apply(CaseTac (definedOp_s3 inj_s1_s2_s3_x)), 
    357365                           -- Case 1 
    358366                           Apply(SubgoalTac(definedOp_s1 x)), 
     
    363371                           -- Case 2 
    364372                           Apply(SubgoalTac( 
    365                                termAppl notOp(definedOp_s3 inj_s1_s3))), 
     373                               termAppl notOp(definedOp_s3 inj_s1_s3_x))), 
    366374                           Apply(SimpAdd Nothing collectionNotDefBotAx), 
    367375                           Apply(SimpAdd Nothing collectionTotAx)] 
     
    473481addAllChooseFunctions :: [SORT] -> IsaTheory -> IsaTheory 
    474482addAllChooseFunctions sorts isaTh = 
    475     foldl addChooseFunctions isaTh sorts 
     483    let isaTh' = foldl addChooseFunction isaTh sorts --add function and def 
     484    in foldl addChooseFunctionLemma isaTh' sorts --add theorem and proof 
    476485 
    477486-- | Add a single choose function for a given sort to an Isabelle 
     
    479488--   consts choose_Nat :: "Alphabet => Nat" 
    480489--   defs choose_Nat_def: "choose_Nat x == contents{y . class(C_Nat y) = x}" 
    481  
    482 addChooseFunctions ::  IsaTheory -> SORT -> IsaTheory 
    483 addChooseFunctions isaTh sort = 
     490addChooseFunction ::  IsaTheory -> SORT -> IsaTheory 
     491addChooseFunction isaTh sort = 
    484492    let --constant 
    485493        alphabetType = Type {typeId = alphabetS, 
    486                                 typeSort = [], 
    487                                 typeArgs =[]} 
    488         sortType = Type {typeId = convertSort2String sort, typeSort = [], 
    489                                   typeArgs =[]} 
     494                             typeSort = [], 
     495                             typeArgs =[]} 
     496        sortType = Type {typeId = convertSort2String sort, 
     497                         typeSort = [], 
     498                         typeArgs =[]} 
    490499        chooseFunName = mkChooseFunName sort 
    491500        chooseFunType = mkFunType alphabetType sortType 
     
    500509        lhs = chooseOp x 
    501510        rhs = contentsOp (Set subset) 
     511    in  addDef chooseFunName lhs rhs -- Add defintion to theory 
     512      $ addConst chooseFunName chooseFunType isaTh -- Add constant to theory 
     513 
     514-- | Add a single choose function lemma for a given sort to an 
     515--   Isabelle theory.  The following Isabelle code is produced by this 
     516--   function: lemma "choose_Nat (class (C_Nat x)) = x". The proof is 
     517--   also produced. 
     518 
     519addChooseFunctionLemma ::  IsaTheory -> SORT -> IsaTheory 
     520addChooseFunctionLemma isaTh sort = 
     521    let sortType = Type {typeId = convertSort2String sort, 
     522                         typeSort = [], 
     523                         typeArgs =[]} 
     524        chooseFunName = mkChooseFunName sort 
     525        x = mkFree "x" 
     526        y = mkFree "y" 
     527        chooseOp = termAppl (conDouble chooseFunName) 
     528        sortConsOp = termAppl (conDouble (mkPreAlphabetConstructor sort)) 
    502529        -- theorm 
    503530        subgoalTacTermLhsBinEq = binEq (classOp $ sortConsOp y) 
     
    516543                           Apply(Auto)] 
    517544                           Done 
    518     in  addThreomWithProof chooseFunName thmConds thmConcl proof' -- Add theorem 
    519       $ addDef chooseFunName lhs rhs -- Add defintion to theory 
    520       $ addConst chooseFunName chooseFunType isaTh -- Add constant to theory 
     545    in  addThreomWithProof chooseFunName thmConds thmConcl proof' isaTh 
     546 
     547-- | Add all the integration theorems. We need to know all the sorts 
     548--   to produce all the theorems. 
     549addAllIntegrationTheorems :: [SORT] -> CspCASLSign -> IsaTheory -> IsaTheory 
     550addAllIntegrationTheorems sorts ccSign isaTh = 
     551    let pairs = [(s1,s2) | s1 <- sorts, s2 <- sorts] 
     552    in foldl (addIntegrationTheorem_A ccSign) isaTh pairs 
     553 
     554-- | Add Integration theorem A -- Compare to elements of the Alphabet. 
     555--   We add the integration theorem based on the sorts of both 
     556--   elements of the alphabet. We need to know the subsort relation to 
     557--   find the highest common sort, but we pass in the CC signature for 
     558--   use in function calls. 
     559addIntegrationTheorem_A :: CspCASLSign -> IsaTheory -> (SORT,SORT) -> IsaTheory 
     560addIntegrationTheorem_A ccSign isaTh (s1,s2) = 
     561    let sortRel = Rel.toList(CASLSign.sortRel ccSign) 
     562        s1SuperSet = CASLSign.supersortsOf s1 ccSign 
     563        s2SuperSet = CASLSign.supersortsOf s2 ccSign 
     564        commonSuperList = Set.toList (Set.intersection 
     565                                         (Set.insert s1 s1SuperSet) 
     566                                         (Set.insert s2 s2SuperSet)) 
     567        x = mkFree "x" 
     568        y = mkFree "y" 
     569        s1ConsOp = termAppl (conDouble (mkPreAlphabetConstructor s1)) 
     570        s2ConsOp = termAppl (conDouble (mkPreAlphabetConstructor s2)) 
     571        rhs = binEq (classOp $ s1ConsOp x) (classOp $ s2ConsOp y) 
     572        lhs = if (null commonSuperList) 
     573              then false 
     574              else 
     575                  -- pick any common sort - we should pick the top most one. 
     576                  let s' = head commonSuperList 
     577                  in binEq (mkInjection s1 s' x) (mkInjection s2 s' y) 
     578        thmConds = [] 
     579        thmConcl = binEq rhs lhs 
     580        -- theorem names for proof 
     581        colInjThmNames = getColInjectivityThmName sortRel 
     582        colDecompThmNames = getColDecompositionThmName sortRel 
     583        proof' = IsaProof [Apply (SimpAdd Nothing ["quot_equality"]), 
     584                           Apply (Other ("unfold " ++ preAlphabetSimS 
     585                                             ++ "_def")), 
     586                           Apply (AutoSimpAdd Nothing 
     587                                  (colDecompThmNames ++ colInjThmNames))] 
     588                           Done 
     589    in  addThreomWithProof "IntegrationTheorem_A" thmConds thmConcl proof' isaTh 
    521590 
    522591-- Function to help keep strings consistent 
     
    531600binEq_PreAlphabet = binVNameAppl eq_PreAlphabetV 
    532601 
    533 alphabetS :: String 
    534 alphabetS = "Alphabet" 
    535  
    536 barExtS :: String 
    537 barExtS = "_Bar" 
    538  
    539 classS :: String 
    540 classS = "class" 
    541  
    542 classOp :: Term -> Term 
    543 classOp = termAppl (conDouble classS) 
    544602 
    545603quotEqualityS :: String 
     
    574632equivTypeClassS  = "equiv" 
    575633 
    576 -- | Return the injection name of the injection from one sort to another 
     634-- | Return the term representing the injection of a term from one sort to another 
     635--   note: the term is returned if both sorts are the same 
    577636--   This function is not implemented in a satisfactory way 
    578 getInjectionOp :: SORT -> SORT -> Term 
    579 getInjectionOp s s' = 
     637mkInjection :: SORT -> SORT -> Term -> Term 
     638mkInjection s s' t = 
    580639    let injName = getInjectionName s s' 
    581640        replace string c s1 = concat (map (\x -> if x==c 
    582641                                                 then s1 
    583642                                                 else [x]) string) 
    584     in Const { 
    585           termName= VName { 
    586             new = ("X_" ++ injName), 
    587             altSyn = Just (AltSyntax ((replace injName '_' "'_") 
    588                                       ++ "/'(_')") [3] 999) 
    589           }, 
    590           termType = Hide { 
    591             typ = Type { 
    592               typeId ="dummy", 
    593               typeSort = [IsaClass "type"], 
    594               typeArgs = [] 
    595             }, 
    596             kon = NA, 
    597             arit= Nothing 
    598           } 
    599         } 
    600  
     643        injOp = Const { 
     644                  termName= VName { 
     645                              new = ("X_" ++ injName), 
     646                              altSyn = Just (AltSyntax ((replace injName '_' "'_") 
     647                                                        ++ "/'(_')") [3] 999) 
     648                            }, 
     649                  termType = Hide { 
     650                               typ = Type { 
     651                                       typeId ="dummy", 
     652                                       typeSort = [IsaClass "type"], 
     653                                       typeArgs = [] 
     654                                     }, 
     655                               kon = NA, 
     656                               arit= Nothing 
     657                             } 
     658                } 
     659    in if s == s' 
     660       then t 
     661       else termAppl injOp t 
    601662 
    602663-- | Return the name of the injection as it is used in the alternative 
     
    706767    in map mkNotDefBotAxName [0 .. (length(sorts) - 1)] 
    707768 
    708 -- Convert a SORT to a string 
    709 convertSort2String :: SORT -> String 
    710 convertSort2String s = show s 
    711  
    712769-- Function that returns the constructor of PreAlphabet for a given sort 
    713770mkPreAlphabetConstructor :: SORT -> String