thys/TM_Assemble.thy
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Fri, 30 May 2014 12:04:49 +0100
changeset 20 e04123f4bacc
parent 18 d826899bc424
permissions -rw-r--r--
soem more work
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
     1
theory TM_Assemble
18
d826899bc424 deleted AList theory, which is not necessary
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 6
diff changeset
     2
imports Hoare_tm StateMonad
4
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
     3
        "~~/src/HOL/Library/FinFun_Syntax"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
     4
        "~~/src/HOL/Library/Sublist"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
     5
        LetElim
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
     6
begin
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
     7
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
     8
section {* The assembler based on Benton's x86 paper *}
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
     9
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    10
text {*
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    11
  The problem with the assembler is that it is too slow to be useful.
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    12
*}
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    13
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    14
primrec pass1 :: "tpg \<Rightarrow> (unit, (nat \<times> nat \<times> (nat \<rightharpoonup> nat))) SM" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    15
  where 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    16
  "pass1 (TInstr ai) = sm_map (\<lambda> (pos, lno, lmap). (pos + 1, lno, lmap))" |
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    17
  "pass1 (TSeq p1 p2) = do {pass1 p1; pass1 p2 }" |
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    18
  "pass1 (TLocal fp) = do { lno \<leftarrow> tap (\<lambda> (pos, lno, lmap). lno); 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    19
                            sm_map (\<lambda> (pos, lno, lmap). (pos, lno+1, lmap)); 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    20
                            pass1 (fp lno) }" |
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    21
  "pass1 (TLabel l) = sm_map ((\<lambda> (pos, lno, lmap). (pos, lno, lmap(l \<mapsto> pos))))"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    22
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    23
declare pass1.simps[simp del]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    24
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    25
type_synonym ('a, 'b) alist = "('a \<times> 'b) list"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    26
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    27
primrec pass2 :: "tpg \<Rightarrow> (nat \<rightharpoonup> nat) \<Rightarrow> (unit, (nat \<times> nat \<times> (nat, tm_inst) alist)) SM" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    28
  where
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    29
  "pass2 (TInstr ai) lmap = sm_map (\<lambda> (pos, lno, prog). (pos + 1, lno, (pos, ai)#prog))" |
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    30
  "pass2 (TSeq p1 p2) lmap = do {pass2 p1 lmap; pass2 p2 lmap}" |
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    31
  "pass2 (TLocal fp) lmap = do { lno \<leftarrow> tap (\<lambda> (pos, lno, prog). lno);
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    32
                                 sm_map (\<lambda> (pos, lno, prog). (pos, lno + 1, prog));
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    33
                                 (case (lmap lno) of
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    34
                                    Some l => pass2 (fp l) lmap |
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    35
                                    None => (raise ''Undefined label''))} " |
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    36
  "pass2 (TLabel l) lmap = do { pos \<leftarrow> tap (\<lambda> (pos, lno, prog). pos);
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    37
                                if (l = pos) then return ()
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    38
                                             else (raise ''Label mismatch'') }"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    39
declare pass2.simps[simp del]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    40
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    41
definition "assembleM i tpg = 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    42
  do {(x, (pos, lno, lmap)) \<leftarrow> execute (pass1 tpg) (i, 0, empty);
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    43
      execute (pass2 tpg lmap) (i, 0, [])}"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    44
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    45
definition 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    46
 "assemble i tpg = Option.map (\<lambda> (x, (j, lno, prog)).(prog, j)) (assembleM i tpg)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    47
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    48
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    49
lemma tprog_set_union:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    50
  assumes "(fst ` set pg3) \<inter> (fst ` set pg2) = {}"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    51
  shows "tprog_set (map_of pg3 ++ map_of pg2) = tprog_set (map_of pg3) \<union> tprog_set (map_of pg2)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    52
proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    53
  from assms have "dom (map_of pg3) \<inter> dom (map_of pg2) = {}"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    54
    by (metis dom_map_of_conv_image_fst)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    55
  hence map_comm: "map_of pg3 ++ map_of pg2 = map_of pg2 ++ map_of pg3"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    56
    by (metis map_add_comm)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    57
  show ?thesis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    58
  proof
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    59
    show "tprog_set (map_of pg3 ++ map_of pg2) \<subseteq> tprog_set (map_of pg3) \<union> tprog_set (map_of pg2)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    60
    proof
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    61
      fix x
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    62
      assume " x \<in> tprog_set (map_of pg3 ++ map_of pg2)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    63
      then obtain i inst where h:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    64
            "x = TC i inst"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    65
            "(map_of pg3 ++ map_of pg2) i = Some inst"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    66
        apply (unfold tprog_set_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    67
        by (smt mem_Collect_eq)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    68
      from map_add_SomeD[OF h(2)] h(1)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    69
      show " x \<in> tprog_set (map_of pg3) \<union> tprog_set (map_of pg2)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    70
        apply (unfold tprog_set_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    71
        by (smt mem_Collect_eq sup1CI sup_Un_eq)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    72
    qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    73
  next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    74
    show "tprog_set (map_of pg3) \<union> tprog_set (map_of pg2) \<subseteq> tprog_set (map_of pg3 ++ map_of pg2)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    75
    proof
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    76
      fix x
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    77
      assume " x \<in> tprog_set (map_of pg3) \<union> tprog_set (map_of pg2)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    78
      then obtain i inst
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    79
        where h: "x = TC i inst" "map_of pg3 i = Some inst \<or> map_of pg2 i = Some inst"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    80
        apply (unfold tprog_set_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    81
        by (smt Un_iff mem_Collect_eq)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    82
      from h(2)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    83
      show "x \<in> tprog_set (map_of pg3 ++ map_of pg2)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    84
      proof
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    85
        assume "map_of pg2 i = Some inst"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    86
        hence "(map_of pg3 ++ map_of pg2) i = Some inst"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    87
          by (metis map_add_find_right)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    88
        with h(1) show ?thesis 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    89
          apply (unfold tprog_set_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    90
          by (smt mem_Collect_eq)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    91
      next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    92
        assume "map_of pg3 i = Some inst"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    93
        hence "(map_of pg2 ++ map_of pg3) i = Some inst"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    94
          by (metis map_add_find_right)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    95
        with h(1) show ?thesis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    96
          apply (unfold map_comm)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    97
          apply (unfold tprog_set_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    98
          by (smt mem_Collect_eq)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
    99
      qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   100
    qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   101
  qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   102
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   103
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   104
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   105
lemma assumes "assemble i c = Some (prog, j)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   106
  shows "(i:[c]:j) (tprog_set (map_of prog))"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   107
proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   108
  from assms obtain x lno
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   109
    where "(assembleM i c) = Some (x, (j, lno, prog))"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   110
    apply(unfold assemble_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   111
    by (cases "(assembleM i c)", auto)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   112
  then obtain y pos lno' lmap where
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   113
       "execute (pass1 c) (i, 0, empty) = Some (y, (pos, lno', lmap))"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   114
       "execute (pass2 c lmap) (i, 0, []) = Some (x, (j, lno, prog))"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   115
    apply (unfold assembleM_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   116
    by (cases "execute (pass1 c) (i, 0, Map.empty)", auto simp:Option.bind.simps)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   117
  hence mid: "effect (pass1 c) (i, 0, empty) (pos, lno', lmap) y"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   118
             "effect (pass2 c lmap) (i, 0, []) (j, lno, prog) x"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   119
    by (auto intro:effectI)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   120
  { fix lnos lmap lmap' prog1 prog2
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   121
    assume "effect (pass2 c lmap') (i, lnos, prog1) (j, lno, prog2) x"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   122
    hence "\<exists> prog. (prog2 = prog@prog1 \<and> (i:[c]:j) (tprog_set (map_of prog)) \<and>
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   123
                   (\<forall> k \<in> fst ` (set prog). i \<le> k \<and> k < j) \<and> i \<le> j)" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   124
    proof(induct c arbitrary:lmap' i lnos prog1 j lno prog2 x)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   125
      case  (TInstr instr lmap' i lnos prog1 j lno prog2 x)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   126
      thus ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   127
        apply (auto simp: effect_def assemble_def assembleM_def execute.simps sm_map_def sm_def 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   128
                    tprog_set_def tassemble_to.simps sg_def pass1.simps pass2.simps
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   129
                     split:if_splits)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   130
        by (cases instr, auto)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   131
    next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   132
      case (TLabel l lmap' i lnos prog1 j lno prog2 x)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   133
      thus ?case 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   134
        apply (rule_tac x = "[]" in exI)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   135
        apply (unfold tassemble_to.simps)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   136
        by (auto simp: effect_def assemble_def assembleM_def execute.simps sm_map_def sm_def 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   137
                    tprog_set_def tassemble_to.simps sg_def pass1.simps pass2.simps tap_def bind_def
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   138
                    return_def raise_def sep_empty_def set_ins_def
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   139
                     split:if_splits)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   140
    next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   141
      case (TSeq c1 c2 lmap' i lnos prog1 j lno prog2 x)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   142
      from TSeq(3)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   143
      obtain h' r where 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   144
        "effect (pass2 c1 lmap') (i, lnos, prog1) h' r"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   145
        "effect (pass2 c2 lmap') h' (j, lno, prog2) x"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   146
        apply (unfold pass2.simps)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   147
        by (auto elim!:effect_elims)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   148
      then obtain pos1 lno1 pg1
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   149
        where h:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   150
        "effect (pass2 c1 lmap') (i, lnos, prog1) (pos1, lno1, pg1) r"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   151
        "effect (pass2 c2 lmap') (pos1, lno1, pg1) (j, lno, prog2) x"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   152
        by (cases h', auto)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   153
      from TSeq(1)[OF h(1)] TSeq(2)[OF h(2)]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   154
      obtain pg2 pg3
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   155
        where hh: "pg1 = pg2 @ prog1 \<and> (i :[ c1 ]: pos1) (tprog_set (map_of pg2))"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   156
                  "(\<forall>k\<in> fst ` (set pg2). i \<le> k \<and> k < pos1)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   157
                  "i \<le> pos1"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   158
                  "prog2 = pg3 @ pg1 \<and> (pos1 :[ c2 ]: j) (tprog_set (map_of pg3))"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   159
                  "(\<forall>k\<in>fst ` (set pg3). pos1 \<le> k \<and> k < j)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   160
                  "pos1 \<le> j"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   161
        by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   162
      thus ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   163
        apply (rule_tac x = "pg3 @ pg2" in exI, auto)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   164
        apply (unfold tassemble_to.simps)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   165
        apply (rule_tac x = pos1 in EXS_intro)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   166
        my_block have 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   167
          "(tprog_set (map_of pg2 ++ map_of pg3)) = tprog_set (map_of pg2) \<union> tprog_set (map_of pg3)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   168
          proof(rule tprog_set_union)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   169
            from hh(2, 5) show "fst ` set pg2 \<inter> fst ` set pg3 = {}"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   170
              by (smt disjoint_iff_not_equal)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   171
          qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   172
        my_block_end
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   173
        apply (unfold this, insert this)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   174
        my_block
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   175
          have "tprog_set (map_of pg2) \<inter>  tprog_set (map_of pg3) = {}" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   176
          proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   177
            { fix x
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   178
              assume h: "x \<in> tprog_set (map_of pg2)" "x \<in> tprog_set (map_of pg3)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   179
              then obtain i inst where "x = TC i inst" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   180
                                       "map_of pg2 i = Some inst" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   181
                                       "map_of pg3 i = Some inst"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   182
                apply (unfold tprog_set_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   183
                by (smt mem_Collect_eq tresource.inject(2))
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   184
              hence "(i, inst) \<in> set pg2" "(i, inst) \<in> set pg3"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   185
                by (metis map_of_SomeD)+
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   186
              with hh(2, 5)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   187
              have "False"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   188
                by (smt rev_image_eqI)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   189
            } thus ?thesis by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   190
          qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   191
        my_block_end
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   192
        apply (insert this)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   193
        apply (fold set_ins_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   194
        by (rule sep_conjI, assumption+, simp)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   195
    next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   196
      case (TLocal body lmap' i lnos prog1 j lno prog2 x)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   197
      from TLocal(2)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   198
      obtain l where h:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   199
        "lmap' lnos = Some l"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   200
        "effect (pass2 (body l) lmap') (i, Suc lnos, prog1) (j, lno, prog2) ()"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   201
        apply (unfold pass2.simps)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   202
        by (auto elim!:effect_elims split:option.splits simp:sm_map_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   203
      from TLocal(1)[OF this(2)]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   204
      obtain pg where hh: "prog2 = pg @ prog1 \<and> (i :[ body l ]: j) (tprog_set (map_of pg))"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   205
                          "(\<forall>k\<in> fst ` (set pg). i \<le> k \<and> k < j)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   206
                          "i \<le> j"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   207
        by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   208
      thus ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   209
        apply (rule_tac x = pg in exI, auto)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   210
        apply (unfold tassemble_to.simps)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   211
        by (rule_tac x = l in EXS_intro, auto)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   212
    qed 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   213
  } from this[OF mid(2)] show ?thesis by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   214
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   215
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   216
definition "valid_tpg tpg = (\<forall> i. \<exists> j prog. assemble i tpg = Some (j, prog))"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   217
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   218
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   219
section {* A new method based on DB indexing *}
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   220
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   221
text {*
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   222
  In this section, we introduced a new method based on DB-indexing to provide a quick check of 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   223
   assemblebility of TM assmbly programs in the format of @{text "tpg"}. The 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   224
   lemma @{text "ct_left_until_zero"} at the end shows how the well-formedness of @{text "left_until_zero"}
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   225
   is proved in a modular way.
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   226
*}
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   227
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   228
datatype cpg = 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   229
   CInstr tm_inst
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   230
 | CLabel nat
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   231
 | CSeq cpg cpg
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   232
 | CLocal cpg
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   233
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   234
datatype status = Free | Bound
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   235
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   236
definition "lift_b t i j = (if (j \<ge> t) then (j + i) else j)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   237
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   238
fun lift_t :: "nat \<Rightarrow> nat \<Rightarrow> cpg \<Rightarrow> cpg"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   239
where "lift_t t i (CInstr ((act0, l0), (act1, l1))) = 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   240
                           (CInstr ((act0, lift_b t i l0), (act1, lift_b t i l1)))" |
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   241
      "lift_t t i (CLabel l) = CLabel (lift_b t i l)" |
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   242
      "lift_t t i (CSeq c1 c2) = CSeq (lift_t t i c1) (lift_t t i c2)" |
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   243
      "lift_t t i (CLocal c) = CLocal (lift_t (t + 1) i c)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   244
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   245
definition "lift0 (i::nat) cpg = lift_t 0 i cpg"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   246
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   247
definition "perm_b t i j k = (if ((k::nat) = i \<and> i < t \<and> j < t) then j else 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   248
                              if (k = j \<and> i < t \<and> j < t) then i else k)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   249
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   250
lemma inj_perm_b: "inj (perm_b t i j)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   251
proof(induct rule:injI)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   252
  case (1 x y)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   253
  thus ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   254
    by (unfold perm_b_def, auto split:if_splits)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   255
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   256
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   257
fun perm :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> cpg \<Rightarrow> cpg"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   258
where "perm t i j (CInstr ((act0, l0), (act1, l1))) = 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   259
                           (CInstr ((act0, perm_b t i j l0), (act1, perm_b t i j l1)))" |
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   260
      "perm t i j (CLabel l) = CLabel (perm_b t i j l)" |
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   261
      "perm t i j (CSeq c1 c2) = CSeq (perm t i j c1) (perm t i j c2)" |
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   262
      "perm t i j (CLocal c) = CLocal (perm (t + 1) (i + 1) (j + 1) c)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   263
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   264
definition "map_idx f sts = map (\<lambda> k. sts!(f (nat k))) [0 .. int (length sts) - 1]"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   265
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   266
definition "perm_s i j sts = map_idx (perm_b (length sts) i j) sts" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   267
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   268
value "perm_s 2 5 [(0::int), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   269
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   270
lemma "perm_s 2 20 [(0::int), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] = x"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   271
  apply (unfold perm_s_def map_idx_def perm_b_def, simp add:upto.simps)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   272
  oops
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   273
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   274
lemma upto_len: "length [i .. j] = (if j < i then 0 else (nat (j - i + 1)))"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   275
proof(induct i j rule:upto.induct)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   276
  case (1 i j)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   277
  show ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   278
  proof(cases "j < i")
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   279
    case True
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   280
    thus ?thesis by simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   281
  next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   282
    case False
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   283
    hence eq_ij: "[i..j] = i # [i + 1..j]" by (simp add:upto.simps)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   284
    from 1 False
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   285
    show ?thesis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   286
      by (auto simp:eq_ij)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   287
  qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   288
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   289
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   290
lemma perm_s_len: "length (perm_s i j sts') = length sts'"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   291
  apply (unfold perm_s_def map_idx_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   292
  by (smt Nil_is_map_conv length_0_conv length_greater_0_conv length_map neq_if_length_neq upto_len)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   293
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   294
fun c2t :: "nat list \<Rightarrow> cpg \<Rightarrow> tpg" where 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   295
  "c2t env (CInstr ((act0, st0), (act1, st1))) = TInstr ((act0, env!st0), (act1, env!st1))" |
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   296
  "c2t env (CLabel l) = TLabel (env!l)" |
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   297
  "c2t env (CSeq cpg1 cpg2) = TSeq (c2t env cpg1) (c2t env cpg2)" |
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   298
  "c2t env (CLocal cpg) = TLocal (\<lambda> x. c2t (x#env) cpg)" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   299
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   300
instantiation status :: minus
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   301
begin
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   302
   fun minus_status :: "status \<Rightarrow> status \<Rightarrow> status" where
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   303
     "minus_status Bound Bound = Free" |
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   304
     "minus_status Bound Free = Bound" |
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   305
     "minus_status Free x = Free "
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   306
   instance ..
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   307
end
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   308
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   309
instantiation status :: plus
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   310
begin
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   311
   fun plus_status :: "status \<Rightarrow> status \<Rightarrow> status" where
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   312
     "plus_status Free x = x" |
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   313
     "plus_status Bound x = Bound"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   314
   instance ..
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   315
end
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   316
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   317
instantiation list :: (plus)plus
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   318
begin
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   319
   fun plus_list :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list" where
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   320
     "plus_list [] ys = []" |
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   321
     "plus_list (x#xs) [] = []" |
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   322
     "plus_list (x#xs) (y#ys) = ((x + y)#plus_list xs ys)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   323
   instance ..
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   324
end
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   325
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   326
instantiation list :: (minus)minus
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   327
begin
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   328
   fun minus_list :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list" where
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   329
     "minus_list [] ys = []" |
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   330
     "minus_list (x#xs) [] = []" |
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   331
     "minus_list (x#xs) (y#ys) = ((x - y)#minus_list xs ys)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   332
   instance ..
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   333
end
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   334
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   335
(* consts castr :: "nat list \<Rightarrow> nat \<Rightarrow> cpg \<Rightarrow> nat \<Rightarrow> tassert"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   336
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   337
definition "castr env i cpg j = (i:[c2t env cpg]:j)" *)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   338
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   339
(*
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   340
definition 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   341
   "c2p sts i cpg j = (\<forall> x. ((length x = length sts \<and> 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   342
                               (\<forall> k < length sts. sts!k = Bound \<longrightarrow> (\<exists> f. x!k = f i)))
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   343
                                \<longrightarrow> (\<exists> s. (i:[(c2t x cpg)]:j) s)))"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   344
*)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   345
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   346
definition 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   347
   "c2p sts i cpg j = 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   348
           (\<exists> f. \<forall> x. ((length x = length sts \<and> 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   349
                        (\<forall> k < length sts. sts!k = Bound \<longrightarrow> (x!k = f i k)))
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   350
                   \<longrightarrow> (\<exists> s. (i:[(c2t x cpg)]:j) s)))"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   351
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   352
fun  wf_cpg_test :: "status list \<Rightarrow> cpg \<Rightarrow> (bool \<times> status list)" where
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   353
  "wf_cpg_test sts (CInstr ((a0, l0), (a1, l1))) = ((l0 < length sts \<and> l1 < length sts), sts)" |
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   354
  "wf_cpg_test sts (CLabel l) = ((l < length sts) \<and> sts!l = Free, sts[l:=Bound])" |
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   355
  "wf_cpg_test sts (CSeq c1 c2) = (let (b1, sts1) = wf_cpg_test sts c1;
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   356
                                  (b2, sts2) = wf_cpg_test sts1 c2 in
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   357
                                     (b1 \<and> b2, sts2))" |
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   358
  "wf_cpg_test sts (CLocal body) = (let (b, sts') = (wf_cpg_test (Free#sts) body) in 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   359
                                   (b, tl sts'))" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   360
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   361
instantiation status :: order
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   362
begin
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   363
  definition less_eq_status_def: "((st1::status) \<le> st2) = (st1 = Free \<or> st2 = Bound)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   364
  definition less_status_def: "((st1::status) < st2) = (st1 \<le> st2 \<and> st1 \<noteq> st2)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   365
instance
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   366
proof
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   367
  fix x y 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   368
  show "(x < (y::status)) = (x \<le> y \<and> \<not> y \<le> x)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   369
    by (metis less_eq_status_def less_status_def status.distinct(1))
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   370
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   371
  fix x show "x \<le> (x::status)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   372
    by (metis (full_types) less_eq_status_def status.exhaust)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   373
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   374
  fix x y z
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   375
  assume "x \<le> y" "y \<le> (z::status)" show "x \<le> (z::status)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   376
    by (metis `x \<le> y` `y \<le> z` less_eq_status_def status.distinct(1))
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   377
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   378
  fix x y
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   379
  assume "x \<le> y" "y \<le> (x::status)" show "x = y"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   380
    by (metis `x \<le> y` `y \<le> x` less_eq_status_def status.distinct(1))
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   381
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   382
end
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   383
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   384
instantiation list :: (order)order
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   385
begin
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   386
  definition "((sts::('a::order) list)  \<le> sts') = 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   387
                   ((length sts = length sts') \<and> (\<forall> i < length sts. sts!i \<le> sts'!i))"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   388
  definition "((sts::('a::order) list)  < sts') = ((sts \<le> sts') \<and> sts \<noteq> sts')"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   389
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   390
  lemma anti_sym: assumes h: "x \<le> (y::'a list)" "y \<le> x"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   391
      shows "x = y"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   392
  proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   393
    from h have "length x = length y"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   394
      by (metis less_eq_list_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   395
    moreover from h have " (\<forall> i < length x. x!i = y!i)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   396
      by (metis (full_types) antisym_conv less_eq_list_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   397
    ultimately show ?thesis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   398
      by (metis nth_equalityI)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   399
  qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   400
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   401
  lemma refl: "x \<le> (x::('a::order) list)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   402
    apply (unfold less_eq_list_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   403
    by (metis order_refl)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   404
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   405
  instance
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   406
  proof
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   407
    fix x y
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   408
    show "((x::('a::order) list) < y) = (x \<le> y \<and> \<not> y \<le> x)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   409
    proof
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   410
      assume h: "x \<le> y \<and> \<not> y \<le> x"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   411
      have "x \<noteq> y"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   412
      proof
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   413
        assume "x = y" with h have "\<not> (x \<le> x)" by simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   414
        with refl show False by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   415
      qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   416
      moreover from h have "x \<le> y" by blast
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   417
      ultimately show "x < y" by (auto simp:less_list_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   418
    next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   419
      assume h: "x < y"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   420
      hence hh: "x \<le> y"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   421
        by (metis TM_Assemble.less_list_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   422
      moreover have "\<not> y \<le> x"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   423
      proof
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   424
        assume "y \<le> x"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   425
        from anti_sym[OF hh this] have "x = y" .
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   426
        with h show False
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   427
          by (metis less_list_def) 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   428
      qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   429
      ultimately show "x \<le> y \<and> \<not> y \<le> x" by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   430
    qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   431
  next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   432
    fix x from refl show "(x::'a list) \<le> x" .
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   433
  next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   434
    fix x y assume "(x::'a list) \<le> y" "y \<le> x" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   435
    from anti_sym[OF this] show "x = y" .
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   436
  next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   437
    fix x y z
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   438
    assume h: "(x::'a list) \<le> y" "y \<le> z"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   439
    show "x \<le> z"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   440
    proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   441
      from h have "length x = length z" by (metis TM_Assemble.less_eq_list_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   442
      moreover from h have "\<forall> i < length x. x!i \<le> z!i"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   443
        by (metis TM_Assemble.less_eq_list_def order_trans)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   444
      ultimately show "x \<le> z"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   445
        by (metis TM_Assemble.less_eq_list_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   446
    qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   447
  qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   448
end
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   449
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   450
lemma sts_bound_le: "sts \<le> sts[l := Bound]"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   451
proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   452
  have "length sts = length (sts[l := Bound])"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   453
    by (metis length_list_update)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   454
  moreover have "\<forall> i < length sts. sts!i \<le> (sts[l:=Bound])!i"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   455
  proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   456
    { fix i
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   457
      assume "i < length sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   458
      have "sts ! i \<le> sts[l := Bound] ! i"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   459
      proof(cases "l < length sts")
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   460
        case True
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   461
        note le_l = this
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   462
        show ?thesis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   463
        proof(cases "l = i")
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   464
          case True with le_l
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   465
          have "sts[l := Bound] ! i = Bound" by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   466
          thus ?thesis by (metis less_eq_status_def) 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   467
        next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   468
          case False
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   469
          with le_l have "sts[l := Bound] ! i = sts!i" by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   470
          thus ?thesis by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   471
        qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   472
      next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   473
        case False
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   474
        hence "sts[l := Bound] = sts" by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   475
        thus ?thesis by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   476
      qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   477
    } thus ?thesis by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   478
  qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   479
  ultimately show ?thesis by (metis less_eq_list_def) 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   480
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   481
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   482
lemma sts_tl_le:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   483
  assumes "sts \<le> sts'"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   484
  shows "tl sts \<le> tl sts'"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   485
proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   486
  from assms have "length (tl sts) = length (tl sts')"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   487
    by (metis (hide_lams, no_types) length_tl less_eq_list_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   488
  moreover from assms have "\<forall> i < length (tl sts). (tl sts)!i \<le> (tl sts')!i"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   489
    by (smt calculation length_tl less_eq_list_def nth_tl)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   490
  ultimately show ?thesis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   491
    by (metis less_eq_list_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   492
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   493
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   494
lemma wf_cpg_test_le:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   495
  assumes "wf_cpg_test sts cpg = (True, sts')"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   496
  shows "sts \<le> sts'" using assms
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   497
proof(induct cpg arbitrary:sts sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   498
  case (CInstr instr sts sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   499
  obtain a0 l0 a1 l1 where eq_instr: "instr = ((a0, l0), (a1, l1))" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   500
    by (metis prod.exhaust)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   501
  from CInstr[unfolded this]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   502
  show ?case by simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   503
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   504
  case (CLabel l sts sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   505
  thus ?case by (auto simp:sts_bound_le)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   506
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   507
  case (CLocal body sts sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   508
  from this(2)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   509
  obtain sts1 where h: "wf_cpg_test (Free # sts) body = (True, sts1)" "sts' = tl sts1"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   510
    by (auto split:prod.splits)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   511
  from CLocal(1)[OF this(1)] have "Free # sts \<le> sts1" .
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   512
  from sts_tl_le[OF this]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   513
  have "sts \<le> tl sts1" by simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   514
  from this[folded h(2)]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   515
  show ?case .
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   516
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   517
  case (CSeq cpg1 cpg2 sts sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   518
  from this(3)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   519
  show ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   520
    by (auto split:prod.splits dest!:CSeq(1, 2))
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   521
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   522
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   523
lemma c2p_assert:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   524
  assumes "(c2p [] i cpg j)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   525
  shows "\<exists> s. (i :[(c2t [] cpg)]: j) s"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   526
proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   527
  from assms obtain f where
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   528
    h [rule_format]: 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   529
    "\<forall> x. length x = length [] \<and> (\<forall>k<length []. [] ! k = Bound \<longrightarrow> (x ! k = f i k)) \<longrightarrow>
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   530
                        (\<exists> s. (i :[ c2t [] cpg ]: j) s)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   531
    by (unfold c2p_def, auto)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   532
  have "length [] = length [] \<and> (\<forall>k<length []. [] ! k = Bound \<longrightarrow> ([] ! k = f i k))"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   533
    by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   534
  from h[OF this] obtain s where "(i :[ c2t [] cpg ]: j) s" by blast
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   535
  thus ?thesis by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   536
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   537
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   538
definition "sts_disj sts sts' = ((length sts = length sts') \<and> 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   539
                                 (\<forall> i < length sts. \<not>(sts!i = Bound \<and> sts'!i = Bound)))"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   540
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   541
lemma length_sts_plus:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   542
  assumes "length (sts1 :: status list) = length sts2"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   543
  shows "length (sts1 + sts2) = length sts1"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   544
  using assms
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   545
proof(induct sts1 arbitrary: sts2)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   546
  case Nil
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   547
  thus ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   548
    by (metis plus_list.simps(1))
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   549
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   550
  case (Cons s' sts' sts2)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   551
  thus ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   552
  proof(cases "sts2 = []")
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   553
    case True
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   554
    with Cons show ?thesis by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   555
  next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   556
    case False
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   557
    then obtain s'' sts'' where eq_sts2: "sts2 = s''#sts''"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   558
      by (metis neq_Nil_conv)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   559
    with Cons
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   560
    show ?thesis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   561
      by (metis length_Suc_conv list.inject plus_list.simps(3))
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   562
  qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   563
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   564
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   565
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   566
lemma nth_sts_plus:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   567
  assumes "i < length ((sts1::status list) + sts2)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   568
  shows "(sts1 + sts2)!i = sts1!i + sts2!i"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   569
  using assms
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   570
proof(induct sts1 arbitrary:i sts2)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   571
  case (Nil i sts2)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   572
  thus ?case by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   573
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   574
  case (Cons s' sts' i sts2)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   575
  show ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   576
  proof(cases "sts2 = []")
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   577
    case True
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   578
    with Cons show ?thesis by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   579
  next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   580
    case False
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   581
    then obtain s'' sts'' where eq_sts2: "sts2 = s''#sts''"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   582
      by (metis neq_Nil_conv)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   583
    with Cons
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   584
    show ?thesis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   585
      by (smt list.size(4) nth_Cons' plus_list.simps(3))
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   586
  qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   587
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   588
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   589
lemma nth_sts_minus:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   590
  assumes "i < length ((sts1::status list) - sts2)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   591
  shows "(sts1 - sts2)!i = sts1!i - sts2!i"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   592
  using assms
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   593
proof(induct  arbitrary:i rule:minus_list.induct)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   594
  case (3 x xs y ys i)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   595
  show ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   596
  proof(cases i)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   597
    case 0
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   598
    thus ?thesis by simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   599
  next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   600
    case (Suc k)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   601
    with 3(2) have "k < length (xs - ys)" by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   602
    from 3(1)[OF this] and Suc
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   603
    show ?thesis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   604
      by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   605
  qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   606
qed auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   607
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   608
fun taddr :: "tresource \<Rightarrow> nat" where
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   609
   "taddr (TC i instr) = i"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   610
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   611
lemma tassemble_to_range:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   612
  assumes "(i :[tpg]: j) s"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   613
  shows "(i \<le> j) \<and> (\<forall> r \<in> s. i \<le> taddr r \<and> taddr r < j)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   614
  using assms
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   615
proof(induct tpg arbitrary: i j s)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   616
  case (TInstr instr i j s)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   617
  obtain a0 l0 a1 l1 where "instr = ((a0, l0), (a1, l1))"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   618
    by (metis pair_collapse)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   619
  with TInstr
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   620
  show ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   621
    apply (simp add:tassemble_to.simps sg_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   622
    by (smt `instr = ((a0, l0), a1, l1)` cond_eq cond_true_eq1 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   623
        empty_iff insert_iff le_refl lessI sep.mult_commute taddr.simps)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   624
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   625
  case (TLabel l i j s)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   626
  thus ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   627
    apply (simp add:tassemble_to.simps)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   628
    by (smt equals0D pasrt_def set_zero_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   629
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   630
  case (TSeq c1 c2 i j s)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   631
  from TSeq(3) obtain s1 s2 j' where 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   632
    h: "(i :[ c1 ]: j') s1" "(j' :[ c2 ]: j) s2" "s1 ## s2" "s = s1 + s2"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   633
    by (auto simp:tassemble_to.simps elim!:EXS_elim sep_conjE)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   634
  show ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   635
  proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   636
    { fix r 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   637
      assume "r \<in> s"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   638
      with h (3, 4) have "r \<in> s1 \<or> r \<in> s2"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   639
        by (auto simp:set_ins_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   640
      hence "i \<le> j \<and> i \<le> taddr r \<and> taddr r < j" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   641
      proof
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   642
        assume " r \<in> s1"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   643
        from TSeq(1)[OF h(1)]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   644
        have "i \<le> j'" "(\<forall>r\<in>s1. i \<le> taddr r \<and> taddr r < j')" by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   645
        from this(2)[rule_format, OF `r \<in> s1`]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   646
        have "i \<le> taddr r" "taddr r < j'" by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   647
        with TSeq(2)[OF h(2)]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   648
        show ?thesis by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   649
      next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   650
        assume "r \<in> s2"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   651
        from TSeq(2)[OF h(2)]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   652
        have "j' \<le> j" "(\<forall>r\<in>s2. j' \<le> taddr r \<and> taddr r < j)" by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   653
        from this(2)[rule_format, OF `r \<in> s2`]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   654
        have "j' \<le> taddr r" "taddr r < j" by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   655
        with TSeq(1)[OF h(1)]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   656
        show ?thesis by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   657
      qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   658
    } thus ?thesis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   659
      by (smt TSeq.hyps(1) TSeq.hyps(2) h(1) h(2))
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   660
  qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   661
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   662
  case (TLocal body i j s)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   663
  from this(2) obtain l s' where "(i :[ body l ]: j) s"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   664
    by (simp add:tassemble_to.simps, auto elim!:EXS_elim)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   665
  from TLocal(1)[OF this]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   666
  show ?case by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   667
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   668
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   669
lemma c2p_seq:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   670
  assumes "c2p sts1 i cpg1 j'"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   671
          "c2p sts2 j' cpg2 j"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   672
          "sts_disj sts1 sts2"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   673
  shows "(c2p (sts1 + sts2) i (CSeq cpg1 cpg2) j)" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   674
proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   675
  from assms(1)[unfolded c2p_def]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   676
  obtain f1 where
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   677
    h1[rule_format]: 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   678
        "\<forall>x. length x = length sts1 \<and> (\<forall>k<length sts1. sts1 ! k = Bound \<longrightarrow> (x ! k = f1 i k)) \<longrightarrow>
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   679
              Ex (i :[ c2t x cpg1 ]: j')" by blast
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   680
  from assms(2)[unfolded c2p_def]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   681
  obtain f2 where h2[rule_format]: 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   682
        "\<forall>x. length x = length sts2 \<and> (\<forall>k<length sts2. sts2 ! k = Bound \<longrightarrow> (x ! k = f2 j' k)) \<longrightarrow>
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   683
              Ex (j' :[ c2t x cpg2 ]: j)" by blast
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   684
  from assms(3)[unfolded sts_disj_def]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   685
  have h3: "length sts1 = length sts2" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   686
    and h4[rule_format]: 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   687
        "(\<forall>i<length sts1. \<not> (sts1 ! i = Bound \<and> sts2 ! i = Bound))" by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   688
  let ?f = "\<lambda> i k. if (sts1!k = Bound) then f1 i k else f2 j' k"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   689
  { fix x 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   690
    assume h5: "length x = length (sts1 + sts2)" and
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   691
           h6[rule_format]: "(\<forall>k<length (sts1 + sts2). (sts1 + sts2) ! k = Bound \<longrightarrow> x ! k = ?f i k)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   692
    obtain s1 where h_s1: "(i :[ c2t x cpg1 ]: j') s1"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   693
    proof(atomize_elim, rule h1)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   694
      from h3 h5 have "length x = length sts1"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   695
        by (metis length_sts_plus)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   696
      moreover {
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   697
        fix k assume hh: "k<length sts1" "sts1 ! k = Bound"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   698
        from hh(1) h3 h5 have p1: "k < length (sts1 + sts2)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   699
          by (metis calculation)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   700
        from h3 hh(2) have p2: "(sts1 + sts2)!k = Bound"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   701
          by (metis nth_sts_plus p1 plus_status.simps(2))
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   702
        from h6[OF p1 p2] have "x ! k = (if sts1 ! k = Bound then f1 i k else f2 j' k)" .
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   703
        with hh(2)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   704
        have "x ! k = f1 i k" by simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   705
      } ultimately show "length x = length sts1 \<and> 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   706
          (\<forall>k<length sts1. sts1 ! k = Bound \<longrightarrow> (x ! k = f1 i k))"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   707
        by blast
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   708
    qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   709
    obtain s2 where h_s2: "(j' :[ c2t x cpg2 ]: j) s2"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   710
    proof(atomize_elim, rule h2)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   711
      from h3 h5 have "length x = length sts2"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   712
        by (metis length_sts_plus) 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   713
      moreover {
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   714
        fix k
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   715
        assume hh: "k<length sts2" "sts2 ! k = Bound"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   716
        from hh(1) h3 h5 have p1: "k < length (sts1 + sts2)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   717
          by (metis calculation)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   718
        from  hh(1) h3 h5 hh(2) have p2: "(sts1 + sts2)!k = Bound"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   719
          by (metis `length sts1 = length sts2 \<and> 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   720
               (\<forall>i<length sts1. \<not> (sts1 ! i = Bound \<and> sts2 ! i = Bound))` 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   721
             calculation nth_sts_plus plus_status.simps(1) status.distinct(1) status.exhaust)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   722
        from h6[OF p1 p2] have "x ! k = (if sts1 ! k = Bound then f1 i k else f2 j' k)" .
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   723
        moreover from h4[OF hh(1)[folded h3]] hh(2) have "sts1!k \<noteq> Bound" by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   724
        ultimately have "x!k = f2 j' k" by simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   725
      } ultimately show "length x = length sts2 \<and> 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   726
                               (\<forall>k<length sts2. sts2 ! k = Bound \<longrightarrow> (x ! k = f2 j' k))"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   727
        by blast
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   728
    qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   729
    have h_s12: "s1 ## s2"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   730
    proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   731
      { fix r assume h: "r \<in> s1" "r \<in> s2"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   732
        with h_s1 h_s2
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   733
        have "False"by (smt tassemble_to_range) 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   734
      } thus ?thesis by (auto simp:set_ins_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   735
    qed  
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   736
    have "(EXS j'. i :[ c2t x cpg1 ]: j' \<and>* j' :[ c2t x cpg2 ]: j) (s1 + s2)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   737
    proof(rule_tac x = j' in EXS_intro)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   738
      from h_s1 h_s2 h_s12
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   739
      show "(i :[ c2t x cpg1 ]: j' \<and>* j' :[ c2t x cpg2 ]: j) (s1 + s2)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   740
        by (metis sep_conjI)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   741
    qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   742
    hence "\<exists> s. (i :[ c2t x (CSeq cpg1 cpg2) ]: j) s" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   743
      by (auto simp:tassemble_to.simps)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   744
  }
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   745
  hence "\<exists>f. \<forall>x. length x = length (sts1 + sts2) \<and>
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   746
               (\<forall>k<length (sts1 + sts2). (sts1 + sts2) ! k = Bound \<longrightarrow> x ! k = f i k) \<longrightarrow>
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   747
               Ex (i :[ c2t x (CSeq cpg1 cpg2) ]: j)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   748
    by (rule_tac x = ?f in exI, auto)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   749
  thus ?thesis 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   750
    by(unfold c2p_def, auto)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   751
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   752
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   753
lemma plus_list_len:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   754
  "length ((sts1::status list) + sts2) = min (length sts1) (length sts2)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   755
  by(induct rule:plus_list.induct, auto)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   756
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   757
lemma minus_list_len:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   758
  "length ((sts1::status list) - sts2) = min (length sts1) (length sts2)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   759
  by(induct rule:minus_list.induct, auto)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   760
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   761
lemma sts_le_comb:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   762
  assumes "sts1 \<le> sts2"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   763
  and "sts2 \<le> sts3"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   764
  shows "sts_disj (sts2 - sts1) (sts3 - sts2)" and
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   765
        "(sts3 - sts1) = (sts2 - sts1) + (sts3 - sts2)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   766
proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   767
  from assms 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   768
  have h1: "length sts1 = length sts2" "\<forall>i<length sts1. sts1 ! i \<le> sts2 ! i"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   769
    and h2: "length sts2 = length sts3" "\<forall>i<length sts1. sts2 ! i \<le> sts3 ! i"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   770
    by (unfold less_eq_list_def, auto)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   771
  have "sts_disj (sts2 - sts1) (sts3 - sts2)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   772
  proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   773
    from h1(1) h2(1)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   774
    have "length (sts2 - sts1) = length (sts3 - sts2)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   775
      by (metis minus_list_len)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   776
    moreover {
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   777
      fix i
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   778
      assume lt_i: "i<length (sts2 - sts1)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   779
      from lt_i h1(1) h2(1) have "i < length sts1"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   780
        by (smt minus_list_len)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   781
      from h1(2)[rule_format, of i, OF this] h2(2)[rule_format, of i, OF this]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   782
      have "sts1 ! i \<le> sts2 ! i" "sts2 ! i \<le> sts3 ! i" .
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   783
      moreover have "(sts2 - sts1) ! i = sts2!i - sts1!i"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   784
        by (metis lt_i nth_sts_minus)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   785
      moreover have "(sts3 - sts2)!i = sts3!i - sts2!i"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   786
        by (metis `length (sts2 - sts1) = length (sts3 - sts2)` lt_i nth_sts_minus)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   787
      ultimately have " \<not> ((sts2 - sts1) ! i = Bound \<and> (sts3 - sts2) ! i = Bound)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   788
        apply (cases "sts2!i", cases "sts1!i", cases "sts3!i", simp, simp)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   789
        apply (cases "sts3!i", simp, simp)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   790
        apply (cases "sts1!i", cases "sts3!i", simp, simp)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   791
        by (cases "sts3!i", simp, simp)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   792
    } ultimately show ?thesis by (unfold sts_disj_def, auto)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   793
  qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   794
  moreover have "(sts3 - sts1) = (sts2 - sts1) + (sts3 - sts2)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   795
  proof(induct rule:nth_equalityI)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   796
    case 1
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   797
    show ?case by (metis h1(1) h2(1) length_sts_plus minus_list_len)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   798
  next 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   799
    case 2
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   800
    { fix i
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   801
      assume lt_i: "i<length (sts3 - sts1)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   802
      have "(sts3 - sts1) ! i = (sts2 - sts1 + (sts3 - sts2)) ! i" (is "?L = ?R")
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   803
      proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   804
        have "?R = sts2!i - sts1!i + (sts3!i - sts2!i)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   805
          by (smt `i < length (sts3 - sts1)` h2(1) minus_list_len nth_sts_minus 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   806
                   nth_sts_plus plus_list_len)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   807
        moreover have "?L = sts3!i - sts1!i"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   808
          by (metis `i < length (sts3 - sts1)` nth_sts_minus)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   809
        moreover 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   810
        have "sts2!i - sts1!i + (sts3!i - sts2!i) = sts3!i - sts1!i"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   811
        proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   812
          from lt_i h1(1) h2(1) have "i < length sts1"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   813
            by (smt minus_list_len)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   814
          from h1(2)[rule_format, of i, OF this] h2(2)[rule_format, of i, OF this]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   815
          show ?thesis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   816
            apply (cases "sts2!i", cases "sts1!i", cases "sts3!i", simp, simp)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   817
            apply (cases "sts3!i", simp, simp)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   818
            apply (cases "sts1!i", cases "sts3!i", simp, simp)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   819
            by (cases "sts3!i", simp, simp)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   820
        qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   821
        ultimately show ?thesis by simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   822
      qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   823
    } thus ?case by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   824
  qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   825
  ultimately show "sts_disj (sts2 - sts1) (sts3 - sts2)" and
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   826
                  "(sts3 - sts1) = (sts2 - sts1) + (sts3 - sts2)" by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   827
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   828
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   829
lemma wf_cpg_test_correct: 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   830
  assumes "wf_cpg_test sts cpg = (True, sts')"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   831
  shows "(\<forall> i. \<exists> j. (c2p (sts' - sts) i cpg j))" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   832
  using assms
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   833
proof(induct cpg arbitrary:sts sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   834
  case (CInstr instr sts sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   835
  obtain a0 l0 a1 l1 where eq_instr: "instr = ((a0, l0), (a1, l1))" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   836
    by (metis prod.exhaust)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   837
  show ?case 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   838
  proof(unfold eq_instr c2p_def, clarsimp simp:tassemble_to.simps)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   839
    fix i
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   840
    let ?a = "Suc i" and ?f = "\<lambda> i k. i"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   841
    show "\<exists>a f. \<forall>x. length x = length (sts' - sts) \<and>
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   842
                  (\<forall>k<length (sts' - sts). (sts' - sts) ! k = Bound \<longrightarrow> x ! k = f i k) \<longrightarrow>
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   843
                  Ex (sg {TC i ((a0, x ! l0), a1, x ! l1)} \<and>* <(a = Suc i)>)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   844
    proof(rule_tac x = ?a in exI, rule_tac x = ?f in exI, default, clarsimp)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   845
      fix x
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   846
      let ?j = "Suc i"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   847
      let ?s = " {TC i ((a0, x ! l0), a1, x ! l1)}"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   848
      have "(sg {TC i ((a0, x ! l0), a1, x ! l1)} \<and>* <(Suc i = Suc i)>) ?s"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   849
        by (simp add:tassemble_to.simps sg_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   850
      thus "Ex (sg {TC i ((a0, x ! l0), a1, x ! l1)})" by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   851
    qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   852
  qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   853
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   854
  case (CLabel l sts sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   855
  show ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   856
  proof
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   857
    fix i
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   858
    from CLabel 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   859
    have h1: "l < length sts" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   860
      and h2: "sts ! l = Free"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   861
      and h3: "sts[l := Bound] = sts'" by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   862
    let ?f = "\<lambda> i k. i"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   863
    have "\<exists>a f. \<forall>x. length x = length (sts' - sts) \<and>
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   864
                  (\<forall>k<length (sts' - sts). (sts' - sts) ! k = Bound \<longrightarrow> x ! k = f (i::nat) k) \<longrightarrow>
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   865
                  Ex (<(i = a \<and> a = x ! l)>)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   866
    proof(rule_tac x = i in exI, rule_tac x = ?f in exI, clarsimp)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   867
      fix x
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   868
      assume h[rule_format]:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   869
        "\<forall>k<length (sts' - sts). (sts' - sts) ! k = Bound \<longrightarrow> x ! k = i"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   870
      from h1 h3 have p1: "l < length (sts' - sts)"
6
38cef5407d82 updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 4
diff changeset
   871
        by (metis length_list_update min.idem minus_list_len)
4
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   872
      from p1 h2 h3 have p2: "(sts' - sts)!l = Bound"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   873
        by (metis h1 minus_status.simps(2) nth_list_update_eq nth_sts_minus)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   874
      from h[OF p1 p2] have "(<(i = x ! l)>) 0" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   875
        by (simp add:set_ins_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   876
      thus "\<exists> s.  (<(i = x ! l)>) s" by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   877
    qed 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   878
    thus "\<exists>a. c2p (sts' - sts) i (CLabel l) a"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   879
      by (auto simp:c2p_def tassemble_to.simps)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   880
  qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   881
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   882
  case (CSeq cpg1 cpg2 sts sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   883
  show ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   884
  proof
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   885
    fix i
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   886
    from CSeq(3)[unfolded wf_cpg_test.simps] 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   887
    show "\<exists> j. c2p (sts' - sts) i (CSeq cpg1 cpg2) j"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   888
    proof(let_elim) 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   889
      case (LetE b1 sts1)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   890
      from this(1)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   891
      obtain b2 where h: "(b2, sts') = wf_cpg_test sts1 cpg2" "b1=True" "b2=True" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   892
        by (atomize_elim, unfold Let_def, auto split:prod.splits)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   893
      from wf_cpg_test_le[OF LetE(2)[symmetric, unfolded h(2)]]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   894
      have sts_le1: "sts \<le> sts1" .
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   895
      from CSeq(1)[OF LetE(2)[unfolded h(2), symmetric], rule_format, of i]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   896
      obtain j1 where h1: "(c2p (sts1 - sts) i cpg1 j1)" by blast
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   897
      from wf_cpg_test_le[OF h(1)[symmetric, unfolded h(3)]]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   898
      have sts_le2: "sts1 \<le> sts'" .
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   899
      from sts_le_comb[OF sts_le1 sts_le2]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   900
      have hh: "sts_disj (sts1 - sts) (sts' - sts1)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   901
               "sts' - sts = (sts1 - sts) + (sts' - sts1)" .
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   902
      from CSeq(2)[OF h(1)[symmetric, unfolded h(3)], rule_format, of j1]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   903
      obtain j2 where h2: "(c2p (sts' - sts1) j1 cpg2 j2)" by blast
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   904
      have "c2p (sts' - sts) i (CSeq cpg1 cpg2) j2"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   905
        by(unfold hh(2), rule c2p_seq[OF h1 h2 hh(1)])
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   906
      thus ?thesis by blast 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   907
    qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   908
  qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   909
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   910
  case (CLocal body sts sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   911
  from this(2) obtain b sts1 s where 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   912
      h: "wf_cpg_test (Free # sts) body = (True, sts1)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   913
         "sts' = tl sts1" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   914
    by (unfold wf_cpg_test.simps, auto split:prod.splits)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   915
  from wf_cpg_test_le[OF h(1), unfolded less_eq_list_def] h(2)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   916
  obtain s where eq_sts1: "sts1 = s#sts'"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   917
    by (metis Suc_length_conv list.size(4) tl.simps(2))
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   918
  from CLocal(1)[OF h(1)] have p1: "\<forall>i. \<exists>a. c2p (sts1 - (Free # sts)) i body a" .
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   919
  show ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   920
  proof
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   921
    fix i
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   922
    from p1[rule_format, of i] obtain j where "(c2p (sts1 - (Free # sts)) i body) j" by blast
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   923
    then obtain f where hh [rule_format]: 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   924
           "\<forall>x. length x = length (sts1 - (Free # sts)) \<and>
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   925
                (\<forall>k<length (sts1 - (Free # sts)). (sts1 - (Free # sts)) ! k = Bound \<longrightarrow> x ! k = f i k) \<longrightarrow>
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   926
                        (\<exists>s. (i :[ c2t x body ]: j) s)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   927
      by (auto simp:c2p_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   928
    let ?f = "\<lambda> i k. f i (Suc k)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   929
    have "\<exists>j f. \<forall>x. length x = length (sts' - sts) \<and>
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   930
              (\<forall>k<length (sts' - sts). (sts' - sts) ! k = Bound \<longrightarrow> x ! k = f i k) \<longrightarrow>
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   931
              (\<exists>s. (i :[ (TL xa. c2t (xa # x) body) ]: j) s)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   932
    proof(rule_tac x = j in exI, rule_tac x = ?f in exI, default, clarsimp)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   933
      fix x
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   934
      assume h1: "length x = length (sts' - sts)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   935
        and h2: "\<forall>k<length (sts' - sts). (sts' - sts) ! k = Bound \<longrightarrow> x ! k = f i (Suc k)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   936
      let ?l = "f i 0" let ?x = " ?l#x"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   937
      from wf_cpg_test_le[OF h(1)] have "length (Free#sts) = length sts1"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   938
        by (unfold less_eq_list_def, simp)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   939
      with h1 h(2) have q1: "length (?l # x) = length (sts1 - (Free # sts))"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   940
        by (smt Suc_length_conv length_Suc_conv list.inject list.size(4) 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   941
                minus_list.simps(3) minus_list_len tl.simps(2))
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   942
      have q2: "(\<forall>k<length (sts1 - (Free # sts)). 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   943
                  (sts1 - (Free # sts)) ! k = Bound \<longrightarrow> (f i 0 # x) ! k = f i k)" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   944
      proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   945
        { fix k
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   946
          assume lt_k: "k<length (sts1 - (Free # sts))"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   947
            and  bd_k: "(sts1 - (Free # sts)) ! k = Bound"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   948
          have "(f i 0 # x) ! k = f i k"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   949
          proof(cases "k")
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   950
            case (Suc k')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   951
            moreover have "x ! k' = f i (Suc k')"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   952
            proof(rule h2[rule_format])
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   953
              from bd_k Suc eq_sts1 show "(sts' - sts) ! k' = Bound" by simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   954
            next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   955
              from Suc lt_k eq_sts1 show "k' < length (sts' - sts)" by simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   956
            qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   957
            ultimately show ?thesis by simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   958
          qed simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   959
        } thus ?thesis by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   960
      qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   961
      from conjI[THEN hh[of ?x], OF q1 q2] obtain s 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   962
        where h_s: "(i :[ c2t (f i 0 # x) body ]: j) s" by blast
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   963
      thus "\<exists>s. (i :[ (TL xa. c2t (xa # x) body) ]: j) s"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   964
        apply (simp add:tassemble_to.simps)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   965
        by (rule_tac x = s in exI, rule_tac x = ?l in EXS_intro, simp)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   966
    qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   967
    thus "\<exists>j. c2p (sts' - sts) i (CLocal body) j" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   968
      by (auto simp:c2p_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   969
  qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   970
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   971
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   972
lemma 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   973
  assumes "wf_cpg_test [] cpg = (True, sts')"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   974
  and "tpg = c2t [] cpg"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   975
  shows "\<forall> i. \<exists> j s.  ((i:[tpg]:j) s)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   976
proof
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   977
  fix i
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   978
  have eq_sts_minus: "(sts' - []) = []"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   979
    by (metis list.exhaust minus_list.simps(1) minus_list.simps(2))
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   980
  from wf_cpg_test_correct[OF assms(1), rule_format, of i]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   981
  obtain j where "c2p (sts' - []) i cpg j" by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   982
  from c2p_assert [OF this[unfolded eq_sts_minus]]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   983
  obtain s where "(i :[ c2t [] cpg ]: j) s" by blast
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   984
  from this[folded assms(2)]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   985
  show " \<exists> j s.  ((i:[tpg]:j) s)" by blast
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   986
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   987
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   988
lemma replicate_nth: "(replicate n x @ sts) ! (l + n)  = sts!l"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   989
  by (smt length_replicate nth_append)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   990
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   991
lemma replicate_update: 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   992
  "(replicate n x @ sts)[l + n := v] = replicate n x @ sts[l := v]"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   993
  by (smt length_replicate list_update_append)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   994
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   995
lemma l_n_v_orig:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   996
  assumes "l0 < length env"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   997
  and "t \<le> l0"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   998
  shows "(take t env @ es @ drop t env) ! (l0 + length es) = env ! l0"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
   999
proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1000
  from assms(1, 2) have "t < length env" by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1001
  hence h: "env = take t env @ drop t env" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1002
           "length (take t env) = t"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1003
    apply (metis append_take_drop_id)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1004
    by (smt `t < length env` length_take)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1005
  with assms(2) have eq_sts_l: "env!l0 = (drop t env)!(l0 - t)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1006
    by (metis nth_app)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1007
  from h(2) have "length (take t env @ es) = t + length es"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1008
    by (metis length_append length_replicate nat_add_commute)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1009
  moreover from assms(2) have "t + (length es) \<le> l0 + (length es)" by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1010
  ultimately have "((take t env @ es) @ drop t env)!(l0 + length es) = 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1011
                          (drop t env)!(l0+ length es - (t + length es))"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1012
    by (smt length_replicate length_splice nth_append)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1013
  with eq_sts_l[symmetric, unfolded assms]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1014
  show ?thesis by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1015
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1016
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1017
lemma l_n_v:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1018
  assumes "l < length sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1019
  and "sts!l = v"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1020
  and "t \<le> l"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1021
  shows "(take t sts @ replicate n x @ drop t sts) ! (l + n) = v"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1022
proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1023
  from l_n_v_orig[OF assms(1) assms(3), of "replicate n x"]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1024
  and assms(2)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1025
  show ?thesis by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1026
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1027
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1028
lemma l_n_v_s:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1029
  assumes "l < length sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1030
  and "t \<le> l"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1031
  shows "(take t sts @ sts0 @ drop t sts)[l + length sts0 := v] = 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1032
          take t (sts[l:=v])@ sts0 @ drop t (sts[l:=v])"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1033
proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1034
  let ?n = "length sts0"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1035
  from assms(1, 2) have "t < length sts" by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1036
  hence h: "sts = take t sts @ drop t sts" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1037
           "length (take t sts) = t"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1038
    apply (metis append_take_drop_id)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1039
    by (smt `t < length sts` length_take)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1040
  with assms(2) have eq_sts_l: "sts[l:=v] = take t sts @ drop t sts [(l - t) := v]"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1041
    by (smt list_update_append)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1042
  with h(2) have eq_take_drop_t: "take t (sts[l:=v]) = take t sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1043
                                 "drop t (sts[l:=v]) = (drop t sts)[l - t:=v]"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1044
    apply (metis append_eq_conv_conj)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1045
    by (metis append_eq_conv_conj eq_sts_l h(2))
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1046
  from h(2) have "length (take t sts @ sts0) = t + ?n"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1047
    by (metis length_append length_replicate nat_add_commute)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1048
  moreover from assms(2) have "t + ?n \<le> l + ?n" by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1049
  ultimately have "((take t sts @ sts0) @ drop t sts)[l + ?n := v] = 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1050
                   (take t sts @ sts0) @ (drop t sts)[(l + ?n - (t + ?n)) := v]"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1051
    by (smt list_update_append replicate_nth)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1052
  with eq_take_drop_t
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1053
  show ?thesis by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1054
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1055
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1056
lemma l_n_v_s1: 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1057
  assumes "l < length sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1058
      and "\<not> t \<le> l"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1059
  shows "(take t sts @ sts0 @ drop t sts)[l := v] =
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1060
         take t (sts[l := v]) @ sts0 @ drop t (sts[l := v])"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1061
proof(cases "t < length sts")
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1062
  case False
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1063
  hence h: "take t sts = sts" "drop t sts = []"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1064
           "take t (sts[l:=v]) = sts [l:=v]"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1065
           "drop t (sts[l:=v]) = []"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1066
    by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1067
  with assms(1)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1068
  show ?thesis 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1069
    by (metis list_update_append)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1070
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1071
  case True
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1072
  with assms(2)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1073
  have h: "(take t sts)[l:=v] = take t (sts[l:=v])"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1074
          "(sts[l:=v]) = (take t sts)[l:=v]@drop t sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1075
          "length (take t sts) = t"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1076
    apply (smt length_list_update length_take nth_equalityI nth_list_update nth_take)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1077
    apply (smt True append_take_drop_id assms(2) length_take list_update_append1)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1078
    by (smt True length_take)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1079
  from h(2,3) have "drop t (sts[l := v]) = drop t sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1080
    by (metis append_eq_conv_conj length_list_update)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1081
  with h(1)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1082
  show ?thesis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1083
    apply simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1084
    by (metis assms(2) h(3) list_update_append1 not_leE)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1085
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1086
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1087
lemma l_n_v_s2:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1088
  assumes "l0 < length env"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1089
  and "t \<le> l0"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1090
  and "\<not> t \<le> l1"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1091
  shows "(take t env @ es @ drop t env) ! l1 = env ! l1"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1092
proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1093
  from assms(1, 2) have "t < length env" by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1094
  hence  h: "env = take t env @ drop t env" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1095
            "length (take t env) = t"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1096
    apply (metis append_take_drop_id)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1097
    by (smt `t < length env` length_take)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1098
  with assms(3) show ?thesis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1099
    by (smt nth_append)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1100
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1101
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1102
lemma l_n_v_s3:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1103
  assumes "l0 < length env"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1104
  and "\<not> t \<le> l0"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1105
  shows "(take t env @ es @ drop t env) ! l0 = env ! l0"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1106
proof(cases "t < length env")
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1107
  case True
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1108
   hence  h: "env = take t env @ drop t env" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1109
            "length (take t env) = t"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1110
    apply (metis append_take_drop_id)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1111
    by (smt `t < length env` length_take)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1112
  with assms(2)  show ?thesis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1113
    by (smt nth_append)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1114
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1115
  case False
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1116
  hence "take t env = env" by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1117
  with assms(1) show ?thesis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1118
    by (metis nth_append)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1119
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1120
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1121
lemma lift_wf_cpg_test:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1122
  assumes "wf_cpg_test sts cpg = (True, sts')"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1123
  shows "wf_cpg_test (take t sts @ sts0 @ drop t sts) (lift_t t (length sts0) cpg) = 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1124
               (True, take t sts' @ sts0 @ drop t sts')"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1125
  using assms
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1126
proof(induct cpg arbitrary:t sts0 sts sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1127
  case (CInstr instr t sts0 sts sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1128
  obtain a0 l0 a1 l1 where eq_instr: "instr = ((a0, l0), (a1, l1))" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1129
    by (metis prod.exhaust)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1130
  from CInstr
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1131
  show ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1132
    by (auto simp:eq_instr lift_b_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1133
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1134
  case (CLabel l t sts0 sts sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1135
  thus ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1136
    apply (auto simp:lift_b_def
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1137
                   replicate_nth replicate_update l_n_v_orig l_n_v_s)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1138
    apply (metis (mono_tags) diff_diff_cancel length_drop length_rev 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1139
             linear not_less nth_append nth_take rev_take take_all)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1140
    by (simp add:l_n_v_s1)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1141
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1142
  case (CSeq c1 c2 sts0 sts sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1143
  thus ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1144
    by (auto simp: lift0_def lift_b_def split:prod.splits)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1145
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1146
  case (CLocal body t sts0 sts sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1147
  from this(2) obtain sts1 where h: "wf_cpg_test (Free # sts) body = (True, sts1)" "tl sts1 = sts'"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1148
    by (auto simp:lift0_def lift_b_def split:prod.splits)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1149
  let ?lift_s = "\<lambda> t sts. take t sts @ sts0 @ drop t sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1150
  have eq_lift_1: "(?lift_s (Suc t) (Free # sts)) = Free#?lift_s t  sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1151
    by (simp)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1152
  from wf_cpg_test_le[OF h(1)] have "length (Free#sts) = length sts1"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1153
    by (unfold less_eq_list_def, simp)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1154
  hence eq_sts1: "sts1 = hd sts1 # tl sts1"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1155
    by (metis append_Nil append_eq_conv_conj hd.simps list.exhaust tl.simps(2))
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1156
  from CLocal(1)[OF h(1), of "Suc t", of "sts0", unfolded eq_lift_1]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1157
  show ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1158
    apply (simp, subst eq_sts1, simp)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1159
    apply (simp add:h(2))
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1160
    by (subst eq_sts1, simp add:h(2))
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1161
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1162
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1163
lemma lift_c2t:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1164
  assumes "wf_cpg_test sts cpg = (True, sts')"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1165
  and "length env = length sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1166
  shows "c2t (take t env @ es @ drop t env) (lift_t t (length es) cpg) = 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1167
         c2t env cpg"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1168
  using assms
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1169
proof(induct cpg arbitrary: t env es sts sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1170
  case (CInstr instr t env es sts sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1171
  obtain a0 l0 a1 l1 where eq_instr: "instr = ((a0, l0), (a1, l1))" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1172
    by (metis prod.exhaust)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1173
  from CInstr have h: "l0 < length env" "l1 < length env"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1174
    by (auto simp:eq_instr)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1175
  with CInstr(2)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1176
  show ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1177
    by (auto simp:eq_instr lift_b_def l_n_v_orig l_n_v_s2 l_n_v_s3)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1178
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1179
  case (CLabel l t env es sts sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1180
  thus ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1181
    by (auto simp:lift_b_def
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1182
                replicate_nth replicate_update l_n_v_orig l_n_v_s3)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1183
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1184
  case (CSeq c1 c2 t env es sts sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1185
  from CSeq(3) obtain sts1
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1186
    where h: "wf_cpg_test sts c1 = (True, sts1)" "wf_cpg_test sts1 c2 = (True, sts')"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1187
    by (auto split:prod.splits)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1188
  from wf_cpg_test_le[OF h(1)] have "length sts = length sts1"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1189
    by (auto simp:less_eq_list_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1190
  from CSeq(4)[unfolded this] have eq_len_env: "length env = length sts1" .
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1191
  from CSeq(1)[OF h(1) CSeq(4)]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1192
       CSeq(2)[OF h(2) eq_len_env]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1193
  show ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1194
    by (auto simp: lift0_def lift_b_def split:prod.splits)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1195
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1196
  case (CLocal body t env es sts sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1197
  { fix x
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1198
    from CLocal(2)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1199
    obtain sts1 where h1: "wf_cpg_test (Free # sts) body = (True, sts1)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1200
      by (auto split:prod.splits)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1201
    from CLocal(3) have "length (x#env) = length (Free # sts)" by simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1202
    from CLocal(1)[OF h1 this, of "Suc t"]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1203
    have "c2t (x # take t env @ es @ drop t env) (lift_t (Suc t) (length es) body) =
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1204
          c2t (x # env) body"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1205
      by simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1206
  } thus ?case by simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1207
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1208
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1209
pr 20
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1210
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1211
lemma upto_append:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1212
  assumes "x \<le> y + 1"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1213
  shows  "[x .. y + 1] = [x .. y]@[y + 1]"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1214
  using assms
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1215
  by (induct x y rule:upto.induct, auto simp:upto.simps)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1216
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1217
lemma nth_upto:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1218
  assumes "l < length sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1219
  shows "[0..(int (length sts)) - 1]!l = int l"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1220
  using assms
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1221
proof(induct sts arbitrary:l)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1222
  case Nil
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1223
  thus ?case by simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1224
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1225
  case (Cons s sts l)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1226
  from Cons(2)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1227
  have "0 \<le> (int (length sts) - 1) + 1" by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1228
  from upto_append[OF this]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1229
  have eq_upto: "[0..int (length sts)] = [0..int (length sts) - 1] @ [int (length sts)]"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1230
    by simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1231
  show ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1232
  proof(cases "l < length sts")
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1233
    case True
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1234
    with Cons(1)[OF True] eq_upto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1235
    show ?thesis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1236
      apply simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1237
      by (smt nth_append take_eq_Nil upto_len)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1238
  next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1239
    case False
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1240
    with Cons(2) have eq_l: "l = length sts" by simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1241
    show ?thesis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1242
    proof(cases sts)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1243
      case (Cons x xs)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1244
      have "[0..1 + int (length xs)] = [0 .. int (length xs)]@[1 + int (length xs)]"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1245
        by (smt upto_append)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1246
      moreover have "length [0 .. int (length xs)] = Suc (length xs)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1247
        by (smt upto_len)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1248
      moreover note Cons
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1249
      ultimately show ?thesis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1250
        apply (simp add:eq_l)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1251
        by (smt nth_Cons' nth_append)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1252
    qed (simp add:upto_len upto.simps eq_l)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1253
  qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1254
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1255
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1256
lemma map_idx_idx: 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1257
  assumes "l < length sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1258
  shows "(map_idx f sts)!l = sts!(f l)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1259
proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1260
  from assms have lt_l: "l < length [0..int (length sts) - 1]"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1261
    by (smt upto_len)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1262
  show ?thesis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1263
    apply (unfold map_idx_def nth_map[OF lt_l])
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1264
    by (metis assms nat_int nth_upto)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1265
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1266
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1267
lemma map_idx_len: "length (map_idx f sts) = length sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1268
  apply (unfold map_idx_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1269
  by (smt length_map upto_len)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1270
  
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1271
lemma map_idx_eq:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1272
  assumes "\<forall> l < length sts. f l = g l"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1273
  shows "map_idx f sts = map_idx g sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1274
proof(induct rule: nth_equalityI)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1275
  case 1
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1276
  show "length (map_idx f sts) = length (map_idx g sts)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1277
    by (metis map_idx_len)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1278
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1279
  case 2
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1280
  { fix l
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1281
    assume "l < length (map_idx f sts)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1282
    hence "l < length sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1283
      by (metis map_idx_len)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1284
    from map_idx_idx[OF this] and assms and this
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1285
    have "map_idx f sts ! l = map_idx g sts ! l"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1286
      by (smt list_eq_iff_nth_eq map_idx_idx map_idx_len)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1287
  } thus ?case by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1288
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1289
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1290
lemma perm_s_commut: "perm_s i j sts = perm_s j i sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1291
  apply (unfold perm_s_def, rule map_idx_eq, unfold perm_b_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1292
  by smt
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1293
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1294
lemma map_idx_id: "map_idx id sts = sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1295
proof(induct rule:nth_equalityI)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1296
  case 1
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1297
  from map_idx_len show "length (map_idx id sts) = length sts" .
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1298
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1299
  case 2
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1300
  { fix l
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1301
    assume "l < length (map_idx id sts)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1302
    from map_idx_idx[OF this[unfolded map_idx_len]]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1303
    have "map_idx id sts ! l = sts ! l" by simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1304
  } thus ?case by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1305
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1306
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1307
lemma perm_s_lt_i: 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1308
  assumes "\<not> i < length sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1309
  shows "perm_s i j sts = sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1310
proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1311
  have "map_idx (perm_b (length sts) i j) sts = map_idx id sts" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1312
  proof(rule map_idx_eq, default, clarsimp)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1313
    fix l
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1314
    assume "l < length sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1315
    with assms
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1316
    show "perm_b (length sts) i j l = l"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1317
      by (unfold perm_b_def, auto)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1318
  qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1319
  with map_idx_id
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1320
  have "map_idx (perm_b (length sts) i j) sts = sts" by simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1321
  thus ?thesis by (simp add:perm_s_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1322
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1323
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1324
lemma perm_s_lt:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1325
  assumes "\<not> i < length sts \<or> \<not> j < length sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1326
  shows "perm_s i j sts = sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1327
  using assms
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1328
proof
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1329
  assume "\<not> i < length sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1330
  from perm_s_lt_i[OF this] show ?thesis .
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1331
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1332
  assume "\<not> j < length sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1333
  from perm_s_lt_i[OF this, of i, unfolded perm_s_commut]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1334
  show ?thesis .
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1335
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1336
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1337
lemma perm_s_update_i:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1338
  assumes "i < length sts" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1339
  and "j < length sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1340
  shows "sts ! i = perm_s i j sts ! j"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1341
proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1342
  from map_idx_idx[OF assms(2)]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1343
  have "map_idx (perm_b (length sts) i j) sts ! j = sts!(perm_b (length sts) i j j)" .
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1344
  with assms
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1345
  show ?thesis 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1346
    by (auto simp:perm_s_def perm_b_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1347
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1348
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1349
lemma nth_perm_s_neq:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1350
  assumes "l \<noteq> j"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1351
  and "l \<noteq> i"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1352
  and "l < length sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1353
  shows "sts ! l = perm_s i j sts ! l"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1354
proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1355
  have "map_idx (perm_b (length sts) i j) sts ! l = sts!(perm_b (length sts) i j l)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1356
    by (metis assms(3) map_idx_def map_idx_idx)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1357
  with assms
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1358
  show ?thesis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1359
    by (unfold perm_s_def perm_b_def, auto)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1360
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1361
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1362
lemma map_idx_update:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1363
  assumes "f j = i"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1364
  and "inj f"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1365
  and "i < length sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1366
  and "j < length sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1367
  shows "map_idx f (sts[i:=v]) = map_idx f sts[j := v]"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1368
proof(induct rule:nth_equalityI)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1369
  case 1
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1370
  show "length (map_idx f (sts[i := v])) = length (map_idx f sts[j := v])"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1371
    by (metis length_list_update map_idx_len)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1372
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1373
  case 2
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1374
  { fix l
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1375
    assume lt_l: "l < length (map_idx f (sts[i := v]))"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1376
    have eq_nth: "sts[i := v] ! f l = map_idx f sts[j := v] ! l"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1377
    proof(cases "f l = i")
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1378
      case False
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1379
      from lt_l have "l < length sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1380
        by (metis length_list_update map_idx_len)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1381
      from map_idx_idx[OF this, of f] have " map_idx f sts ! l = sts ! f l" .
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1382
      moreover from False assms have "l \<noteq> j" by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1383
      moreover note False
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1384
      ultimately show ?thesis by simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1385
    next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1386
      case True
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1387
      with assms have eq_l: "l = j" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1388
        by (metis inj_eq)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1389
      moreover from lt_l eq_l 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1390
      have "j < length (map_idx f sts[j := v])"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1391
        by (metis length_list_update map_idx_len)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1392
      moreover note True assms
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1393
      ultimately show ?thesis by simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1394
    qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1395
    from lt_l have "l < length (sts[i := v])"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1396
      by (metis map_idx_len)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1397
    from map_idx_idx[OF this] eq_nth
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1398
    have "map_idx f (sts[i := v]) ! l = map_idx f sts[j := v] ! l" by simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1399
  } thus ?case by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1400
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1401
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1402
lemma perm_s_update:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1403
  assumes "i < length sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1404
  and "j < length sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1405
  shows "(perm_s i j sts)[i := v] = perm_s i j (sts[j := v])"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1406
proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1407
  have "map_idx (perm_b (length (sts[j := v])) i j) (sts[j := v]) = 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1408
        map_idx (perm_b (length (sts[j := v])) i j) sts[i := v]"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1409
    proof(rule  map_idx_update[OF _ _ assms(2, 1)])
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1410
      from inj_perm_b show "inj (perm_b (length (sts[j := v])) i j)" .
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1411
    next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1412
      from assms show "perm_b (length (sts[j := v])) i j i = j"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1413
        by (auto simp:perm_b_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1414
    qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1415
  hence "map_idx (perm_b (length sts) i j) sts[i := v] =
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1416
        map_idx (perm_b (length (sts[j := v])) i j) (sts[j := v])"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1417
    by simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1418
  thus ?thesis by (simp add:perm_s_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1419
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1420
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1421
lemma perm_s_update_neq:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1422
  assumes "l \<noteq> i"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1423
  and "l \<noteq> j"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1424
  shows "perm_s i j sts[l := v] = perm_s i j (sts[l := v])"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1425
proof(cases "i < length sts \<and> j < length sts")
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1426
  case False
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1427
  with perm_s_lt have "perm_s i j sts = sts" by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1428
  moreover have "perm_s i j (sts[l:=v]) = sts[l:=v]"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1429
  proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1430
    have "length (sts[l:=v]) = length sts" by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1431
    from False[folded this] perm_s_lt
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1432
    show ?thesis by metis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1433
  qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1434
  ultimately show ?thesis by simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1435
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1436
  case True
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1437
  note lt_ij = this
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1438
  show ?thesis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1439
  proof(cases "l < length sts")
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1440
    case False
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1441
    hence "sts[l:=v] = sts" by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1442
    moreover have "perm_s i j sts[l := v] = perm_s i j sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1443
    proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1444
      from False and perm_s_len
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1445
      have "\<not> l < length (perm_s i j sts)" by metis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1446
      thus ?thesis by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1447
    qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1448
    ultimately show ?thesis by simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1449
  next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1450
    case True
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1451
    show ?thesis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1452
    proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1453
      have "map_idx (perm_b (length (sts[l := v])) i j) (sts[l := v]) = 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1454
            map_idx (perm_b (length (sts[l := v])) i j) sts[l := v]"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1455
      proof(induct rule:map_idx_update [OF _ inj_perm_b True True])
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1456
        case 1
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1457
        from assms lt_ij
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1458
        show ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1459
          by (unfold perm_b_def, auto)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1460
      qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1461
      thus ?thesis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1462
        by (unfold perm_s_def, simp)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1463
    qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1464
  qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1465
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1466
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1467
lemma perm_sb: "(perm_s i j sts)[perm_b (length sts) i j l := v] = perm_s i j (sts[l := v])"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1468
  apply(subst perm_b_def, auto simp:perm_s_len perm_s_lt perm_s_update)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1469
  apply (subst perm_s_commut, subst (2) perm_s_commut, rule_tac perm_s_update, auto)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1470
  by (rule_tac perm_s_update_neq, auto)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1471
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1472
lemma perm_s_id: "perm_s i i sts = sts" (is "?L = ?R")
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1473
proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1474
  from map_idx_id have "?R = map_idx id sts" by metis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1475
  also have "\<dots> = ?L"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1476
    by (unfold perm_s_def, rule map_idx_eq, unfold perm_b_def, auto)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1477
  finally show ?thesis by simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1478
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1479
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1480
lemma upto_map:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1481
  assumes "i \<le> j"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1482
  shows "[i .. j] = i # map (\<lambda> x. x + 1) [i .. (j - 1)]"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1483
  using assms
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1484
proof(induct i j rule:upto.induct)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1485
  case (1 i j)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1486
  show ?case (is "?L = ?R")
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1487
  proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1488
    from 1(2)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1489
    have eq_l: "?L = i # [i+1 .. j]" by (simp add:upto.simps)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1490
    show ?thesis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1491
    proof(cases "i + 1 \<le> j")
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1492
      case False
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1493
      with eq_l show ?thesis by (auto simp:upto.simps)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1494
    next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1495
      case True
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1496
      have "[i + 1..j] =  map (\<lambda>x. x + 1) [i..j - 1]"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1497
        by (smt "1.hyps" Cons_eq_map_conv True upto.simps)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1498
      with eq_l
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1499
      show ?thesis by simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1500
    qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1501
  qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1502
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1503
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1504
lemma perm_s_cons: "(perm_s (Suc i) (Suc j) (s # sts)) = s#perm_s i j sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1505
proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1506
  have le_0: "0 \<le> int (length (s # sts)) - 1" by simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1507
  have "map (\<lambda>k. (s # sts) ! perm_b (length (s # sts)) (Suc i) (Suc j) (nat k))
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1508
          [0..int (length (s # sts)) - 1] =
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1509
                 s # map (\<lambda>k. sts ! perm_b (length sts) i j (nat k)) [0..int (length sts) - 1]"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1510
    by (unfold upto_map[OF le_0], auto simp:perm_b_def, smt+)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1511
  thus ?thesis by (unfold perm_s_def map_idx_def, simp)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1512
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1513
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1514
lemma perm_wf_cpg_test:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1515
  assumes "wf_cpg_test sts cpg = (True, sts')"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1516
  shows "wf_cpg_test (perm_s i j sts) (perm (length sts) i j cpg) = 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1517
               (True, perm_s i j sts')"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1518
  using assms
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1519
proof(induct cpg arbitrary:t i j sts sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1520
  case (CInstr instr i j sts sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1521
  obtain a0 l0 a1 l1 where eq_instr: "instr = ((a0, l0), (a1, l1))" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1522
    by (metis prod.exhaust)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1523
  from CInstr
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1524
  show ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1525
    apply (unfold eq_instr, clarsimp)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1526
    by (unfold perm_s_len perm_b_def, clarsimp)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1527
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1528
  case (CLabel l i j sts sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1529
  have "(perm_s i j sts)[perm_b (length sts) i j l := Bound] = perm_s i j (sts[l := Bound])"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1530
    by (metis perm_sb)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1531
  with CLabel
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1532
  show ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1533
    apply (auto simp:perm_s_len perm_sb)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1534
    apply (subst perm_b_def, auto simp:perm_sb)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1535
    apply (subst perm_b_def, auto simp:perm_s_lt perm_s_update_i)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1536
    apply (unfold perm_s_id, subst perm_s_commut, simp add: perm_s_update_i[symmetric])
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1537
    apply (simp add:perm_s_update_i[symmetric])
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1538
    by (simp add: nth_perm_s_neq[symmetric])
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1539
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1540
  case (CSeq c1 c2 i j sts sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1541
  thus ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1542
    apply (auto  split:prod.splits)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1543
    apply (metis (hide_lams, no_types) less_eq_list_def prod.inject wf_cpg_test_le)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1544
    by (metis (hide_lams, no_types) less_eq_list_def prod.inject wf_cpg_test_le)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1545
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1546
  case (CLocal body i j sts sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1547
  from this(2) obtain sts1 where h: "wf_cpg_test (Free # sts) body = (True, sts1)" "tl sts1 = sts'"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1548
    by (auto simp:lift0_def lift_b_def split:prod.splits)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1549
  from wf_cpg_test_le[OF h(1)] have "length (Free#sts) = length sts1"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1550
    by (unfold less_eq_list_def, simp)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1551
  hence eq_sts1: "sts1 = hd sts1 # tl sts1"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1552
    by (metis append_Nil append_eq_conv_conj hd.simps list.exhaust tl.simps(2))
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1553
  from CLocal(1)[OF h(1), of "Suc i" "Suc j"] h(2) eq_sts1
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1554
  show ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1555
    apply (auto split:prod.splits simp:perm_s_cons)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1556
    by (metis perm_s_cons tl.simps(2))
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1557
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1558
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1559
lemma nth_perm_sb:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1560
  assumes "l0 < length env"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1561
  shows "perm_s i j env ! perm_b (length env) i j l0 = env ! l0"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1562
  by (metis assms nth_perm_s_neq perm_b_def perm_s_commut perm_s_lt perm_s_update_i)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1563
  
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1564
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1565
lemma perm_c2t:  
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1566
  assumes "wf_cpg_test sts cpg = (True, sts')"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1567
  and "length env = length sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1568
  shows "c2t  (perm_s i j env) (perm (length env) i j cpg)  = 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1569
         c2t env cpg"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1570
  using assms
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1571
proof(induct cpg arbitrary:i j env sts sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1572
  case (CInstr instr i j env sts sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1573
  obtain a0 l0 a1 l1 where eq_instr: "instr = ((a0, l0), (a1, l1))" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1574
    by (metis prod.exhaust)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1575
  from CInstr have h: "l0 < length env" "l1 < length env"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1576
    by (auto simp:eq_instr)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1577
  with CInstr(2)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1578
  show ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1579
    apply (auto simp:eq_instr)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1580
    by (metis nth_perm_sb)+
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1581
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1582
  case (CLabel l t env es sts sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1583
  thus ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1584
    apply (auto)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1585
    by (metis nth_perm_sb)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1586
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1587
  case (CSeq c1 c2 i j env sts sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1588
  from CSeq(3) obtain sts1
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1589
    where h: "wf_cpg_test sts c1 = (True, sts1)" "wf_cpg_test sts1 c2 = (True, sts')"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1590
    by (auto split:prod.splits)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1591
  from wf_cpg_test_le[OF h(1)] have "length sts = length sts1"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1592
    by (auto simp:less_eq_list_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1593
  from CSeq(4)[unfolded this] have eq_len_env: "length env = length sts1" .
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1594
  from CSeq(1)[OF h(1) CSeq(4)]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1595
       CSeq(2)[OF h(2) eq_len_env]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1596
  show ?case by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1597
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1598
  case (CLocal body i j env sts sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1599
  { fix x
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1600
    from CLocal(2, 3)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1601
    obtain sts1 where "wf_cpg_test (Free # sts) body = (True, sts1)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1602
                      "length (x#env) = length (Free # sts)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1603
      by (auto split:prod.splits)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1604
    from CLocal(1)[OF this]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1605
    have "(c2t (x # perm_s i j env) (perm (Suc (length env)) (Suc i) (Suc j) body)) =
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1606
                 (c2t (x # env) body)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1607
      by (metis Suc_length_conv perm_s_cons)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1608
  } thus ?case by simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1609
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1610
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1611
lemma wf_cpg_test_disj_aux1:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1612
  assumes "sts_disj sts1 (sts[l := Bound] - sts)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1613
              "l < length sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1614
              "sts ! l = Free"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1615
  shows "(sts1 + sts) ! l = Free"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1616
proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1617
  from assms(1)[unfolded sts_disj_def]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1618
  have h: "length sts1 = length (sts[l := Bound] - sts)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1619
          "(\<forall>i<length sts1. \<not> (sts1 ! i = Bound \<and> (sts[l := Bound] - sts) ! i = Bound))"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1620
    by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1621
  from h(1) assms(2) 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1622
  have lt_l: "l < length sts1" 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1623
             "l < length (sts[l := Bound] - sts)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1624
             "l < length (sts1 + sts)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1625
    apply (smt length_list_update minus_list_len)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1626
    apply (smt assms(2) length_list_update minus_list_len)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1627
    by (smt assms(2) h(1) length_list_update length_sts_plus minus_list_len)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1628
  from h(2)[rule_format, of l, OF this(1)] 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1629
  have " \<not> (sts1 ! l = Bound \<and> (sts[l := Bound] - sts) ! l = Bound)" .
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1630
  with assms(3) nth_sts_minus[OF lt_l(2)] nth_sts_plus[OF lt_l(3)] assms(2)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1631
  show ?thesis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1632
    by (cases "sts1!l", auto)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1633
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1634
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1635
lemma  wf_cpg_test_disj_aux2: 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1636
  assumes "sts_disj sts1 (sts[l := Bound] - sts)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1637
          " l < length sts"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1638
  shows "(sts1 + sts)[l := Bound] = sts1 + sts[l := Bound]"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1639
proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1640
 from assms have lt_l: "l < length (sts1 + sts[l:=Bound])"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1641
                       "l < length (sts1 + sts)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1642
   apply (smt length_list_update length_sts_plus minus_list_len sts_disj_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1643
   by (smt assms(1) assms(2) length_list_update length_sts_plus minus_list_len sts_disj_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1644
 show ?thesis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1645
 proof(induct rule:nth_equalityI)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1646
   case 1
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1647
   show ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1648
     by (smt assms(1) length_list_update length_sts_plus minus_list_len sts_disj_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1649
 next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1650
   case 2
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1651
   { fix i 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1652
     assume lt_i: "i < length ((sts1 + sts)[l := Bound])"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1653
     have " (sts1 + sts)[l := Bound] ! i = (sts1 + sts[l := Bound]) ! i"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1654
     proof(cases "i = l")
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1655
       case True
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1656
       with nth_sts_plus[OF lt_l(1)] assms(2) nth_sts_plus[OF lt_l(2)] lt_l
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1657
       show ?thesis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1658
         by (cases "sts1 ! l", auto)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1659
     next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1660
       case False
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1661
       from lt_i have "i < length (sts1 + sts)" "i < length (sts1 + sts[l := Bound])"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1662
         apply auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1663
         by (metis length_list_update plus_list_len)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1664
       from nth_sts_plus[OF this(1)] nth_sts_plus[OF this(2)] lt_i lt_l False
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1665
       show ?thesis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1666
         by simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1667
     qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1668
   } thus ?case by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1669
 qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1670
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1671
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1672
lemma sts_list_plus_commut:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1673
  shows "sts1 + sts2 = sts2 + (sts1:: status list)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1674
proof(induct rule:nth_equalityI)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1675
  case 1
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1676
  show ?case
6
38cef5407d82 updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 4
diff changeset
  1677
    by (metis min.commute plus_list_len)
4
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1678
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1679
  case 2
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1680
  { fix i
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1681
    assume lt_i1: "i<length (sts1 + sts2)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1682
    hence lt_i2: "i < length (sts2 + sts1)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1683
      by (smt plus_list_len)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1684
    from nth_sts_plus[OF this] nth_sts_plus[OF lt_i1]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1685
    have "(sts1 + sts2) ! i = (sts2 + sts1) ! i"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1686
      apply simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1687
      apply (cases "sts1!i", cases "sts2!i", auto)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1688
      by (cases "sts2!i", auto)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1689
  } thus ?case by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1690
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1691
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1692
lemma sts_disj_cons:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1693
  assumes "sts_disj sts1 sts2"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1694
  shows "sts_disj (Free # sts1) (s # sts2)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1695
  using assms
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1696
proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1697
  from assms 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1698
  have h: "length sts1 = length sts2"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1699
          "(\<forall>i<length sts1. \<not> (sts1 ! i = Bound \<and> sts2 ! i = Bound))"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1700
    by (unfold sts_disj_def, auto)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1701
  from h(1) have "length (Free # sts1) = length (s # sts2)" by simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1702
  moreover {
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1703
    fix i
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1704
    assume lt_i: "i<length (Free # sts1)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1705
    have "\<not> ((Free # sts1) ! i = Bound \<and> (s # sts2) ! i = Bound)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1706
    proof(cases "i")
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1707
      case 0
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1708
      thus ?thesis by simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1709
    next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1710
      case (Suc k)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1711
      from h(2)[rule_format, of k] lt_i[unfolded Suc] Suc
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1712
      show ?thesis by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1713
    qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1714
  }
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1715
  ultimately show ?thesis by (auto simp:sts_disj_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1716
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1717
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1718
lemma sts_disj_uncomb:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1719
  assumes "sts_disj sts (sts1 + sts2)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1720
  and "sts_disj sts1 sts2"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1721
  shows "sts_disj sts sts1" "sts_disj sts sts2"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1722
  using assms
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1723
  apply  (smt assms(1) assms(2) length_sts_plus nth_sts_plus plus_status.simps(2) sts_disj_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1724
  by (smt assms(1) assms(2) length_sts_plus nth_sts_plus 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1725
       plus_status.simps(2) sts_disj_def sts_list_plus_commut)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1726
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1727
lemma wf_cpg_test_disj:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1728
  assumes "wf_cpg_test sts cpg = (True, sts')"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1729
  and "sts_disj sts1 (sts' - sts)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1730
  shows "wf_cpg_test (sts1 + sts) cpg = (True, sts1 + sts')"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1731
  using assms
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1732
proof(induct cpg arbitrary:sts sts1 sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1733
  case (CInstr instr sts sts1 sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1734
  obtain a0 l0 a1 l1 where eq_instr: "instr = ((a0, l0), (a1, l1))"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1735
    by (metis pair_collapse)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1736
  with CInstr(1) have h: "l0 < length sts" "l1 < length sts" "sts = sts'" by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1737
  with CInstr eq_instr
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1738
  show ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1739
    apply (auto)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1740
    by (smt length_sts_plus minus_list_len sts_disj_def)+
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1741
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1742
  case (CLabel l sts sts1 sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1743
  thus ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1744
    apply auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1745
    apply (smt length_list_update length_sts_plus minus_list_len sts_disj_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1746
    by (auto simp: wf_cpg_test_disj_aux1 wf_cpg_test_disj_aux2)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1747
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1748
  case (CSeq c1 c2 sts sts1 sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1749
  from CSeq(3) obtain sts''
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1750
    where h: "wf_cpg_test sts c1 = (True, sts'')" "wf_cpg_test sts'' c2 = (True, sts')"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1751
    by (auto split:prod.splits)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1752
  from wf_cpg_test_le[OF h(1)] have "length sts = length sts''"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1753
    by (auto simp:less_eq_list_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1754
  from sts_le_comb[OF wf_cpg_test_le[OF h(1)] wf_cpg_test_le[OF h(2)]]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1755
  have " sts' - sts = (sts'' - sts) + (sts' - sts'')" "sts_disj (sts'' - sts) (sts' - sts'')"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1756
    by auto
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1757
  from sts_disj_uncomb[OF CSeq(4)[unfolded this(1)] this(2)]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1758
  have "sts_disj sts1 (sts'' - sts)" "sts_disj sts1 (sts' - sts'')" .
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1759
  from CSeq(1)[OF h(1) this(1)] CSeq(2)[OF h(2) this(2)]
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1760
  have "wf_cpg_test (sts1 + sts) c1 = (True, sts1 + sts'')"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1761
       "wf_cpg_test (sts1 + sts'') c2 = (True, sts1 + sts')" .
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1762
  thus ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1763
    by simp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1764
next
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1765
  case (CLocal body sts sts1 sts')
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1766
  from this(2)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1767
  obtain sts'' where h: "wf_cpg_test (Free # sts) body = (True, sts'')" "sts' = tl sts''"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1768
    by (auto split:prod.splits)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1769
  from wf_cpg_test_le[OF h(1), unfolded less_eq_list_def] h(2)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1770
  obtain s where eq_sts'': "sts'' = s#sts'"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1771
    by (metis Suc_length_conv list.size(4) tl.simps(2))
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1772
  let ?sts = "Free#sts1"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1773
  from CLocal(3) have "sts_disj ?sts (sts'' - (Free # sts))"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1774
    apply (unfold eq_sts'', simp)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1775
    by (metis sts_disj_cons)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1776
  from CLocal(1)[OF h(1) this] eq_sts''
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1777
  show ?case
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1778
    by (auto split:prod.splits)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1779
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1780
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1781
section {* Application of the theory above *}
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1782
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1783
definition "move_left_skel = CLocal (CSeq (CInstr ((L, 0), (L, 0))) (CLabel 0))"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1784
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1785
lemma wt_move_left: "wf_cpg_test [] move_left_skel = (True, [])"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1786
  by (unfold move_left_skel_def, simp)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1787
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1788
lemma ct_move_left: "c2t [] move_left_skel = move_left"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1789
  by (unfold move_left_skel_def move_left_def, simp)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1790
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1791
lemma wf_move_left: "\<forall> i. \<exists> s j. (i:[move_left]:j ) s"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1792
proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1793
  from wf_cpg_test_correct[OF wt_move_left] ct_move_left
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1794
  show ?thesis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1795
    by (unfold c2p_def, simp, metis)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1796
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1797
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1798
definition "jmp_skel = CInstr ((W0, 0), (W1, 0))"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1799
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1800
lemma wt_jmp: "wf_cpg_test [Free] jmp_skel = (True, [Free])"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1801
  by (unfold jmp_skel_def, simp)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1802
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1803
lemma ct_jmp: "c2t [l] jmp_skel = (jmp l)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1804
  by (unfold jmp_skel_def jmp_def, simp)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1805
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1806
lemma wf_jmp: "\<forall> i. \<exists> s j. (i:[jmp l]:j ) s"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1807
proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1808
  from wf_cpg_test_correct[OF wt_jmp] ct_jmp
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1809
  show ?thesis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1810
    apply (unfold c2p_def, simp)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1811
    by (metis One_nat_def Suc_eq_plus1 list.size(3) list.size(4))
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1812
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1813
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1814
definition "label_skel = CLabel 0"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1815
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1816
lemma wt_label: "wf_cpg_test [Free] label_skel = (True, [Bound])"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1817
  by (simp add:label_skel_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1818
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1819
lemma ct_label: "c2t [l] label_skel = (TLabel l)"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1820
  by (simp add:label_skel_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1821
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1822
thm if_zero_def
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1823
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1824
definition "if_zero_skel = CLocal (CSeq (CInstr ((W0, 1), (W1, 0))) (
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1825
                                   CLabel 0
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1826
                                  )
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1827
                           )"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1828
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1829
lemma wt_if_zero: "wf_cpg_test [Free] if_zero_skel = (True, [Free])"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1830
  by (simp add:if_zero_skel_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1831
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1832
definition "left_until_zero_skel = CLocal (CLocal (
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1833
                                      CSeq (CLabel 1) (
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1834
                                      CSeq if_zero_skel (
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1835
                                      CSeq move_left_skel (
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1836
                                      CSeq (lift_t 0 1 jmp_skel) (
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1837
                                      label_skel
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1838
                                      ))))
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1839
                                   ))"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1840
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1841
lemma w1: "wf_cpg_test [Free, Bound] if_zero_skel = (True, [Free, Bound])"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1842
  by (simp add:if_zero_skel_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1843
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1844
lemma w2: "wf_cpg_test [Free, Bound] move_left_skel = (True, [Free, Bound])"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1845
  by (simp add:move_left_skel_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1846
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1847
lemma w3: "wf_cpg_test [Free, Bound] (lift_t 0 (Suc 0) jmp_skel) = 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1848
            (True,  [Free, Bound])"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1849
  by (simp add:jmp_skel_def lift_b_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1850
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1851
lemma w4: "wf_cpg_test [Free, Bound] label_skel = (True, [Bound, Bound])"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1852
  by (unfold label_skel_def, simp)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1853
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1854
lemma wt_left_until_zero: 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1855
     "wf_cpg_test [] left_until_zero_skel = (True, [])"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1856
  by (unfold left_until_zero_skel_def, simp add:w1 w2 w3 w4)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1857
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1858
lemma c1: "c2t [xa, x] if_zero_skel = if_zero xa"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1859
  by (simp add:if_zero_skel_def if_zero_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1860
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1861
lemma c2: "c2t [xa, x] move_left_skel = move_left"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1862
  by (simp add:move_left_skel_def move_left_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1863
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1864
lemma c3: "c2t [xa, x] (lift_t 0 (Suc 0) jmp_skel) = 
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1865
              jmp x"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1866
  by (simp add:jmp_skel_def jmp_def lift_b_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1867
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1868
lemma c4: "c2t [xa, x] label_skel = TLabel xa"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1869
  by (simp add:label_skel_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1870
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1871
lemma ct_left_until_zero:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1872
     "c2t [] left_until_zero_skel = left_until_zero"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1873
  apply (unfold left_until_zero_def left_until_zero_skel_def)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1874
  by (simp add:c1 c2 c3 c4)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1875
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1876
lemma wf_left_until_zero:
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1877
   "\<forall> i. \<exists> s j. (i:[left_until_zero]:j) s"
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1878
proof -
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1879
  from wf_cpg_test_correct[OF wt_left_until_zero] ct_left_until_zero
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1880
  show ?thesis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1881
    apply (unfold c2p_def, simp)
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1882
    by metis
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1883
qed
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1884
  
ceb0bdc99893 A new file
ibm@ibm-PC
parents:
diff changeset
  1885
end