Implementation.thy
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Wed, 06 Jan 2016 16:34:26 +0000
changeset 64 b4bcd1edbb6d
parent 63 CpsG.thy@b620a2a0806a
child 65 633b1fc8631b
permissions -rw-r--r--
renamed files
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
53
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 45
diff changeset
     1
section {*
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 45
diff changeset
     2
  This file contains lemmas used to guide the recalculation of current precedence 
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 45
diff changeset
     3
  after every system call (or system operation)
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 45
diff changeset
     4
*}
64
b4bcd1edbb6d renamed files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
     5
theory Implementation
b4bcd1edbb6d renamed files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
     6
imports PIPBasics Max RTree
56
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
     7
begin
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
     8
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
     9
text {* @{text "the_preced"} is also the same as @{text "preced"}, the only
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
    10
       difference is the order of arguemts. *}
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
    11
definition "the_preced s th = preced th s"
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
    12
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 61
diff changeset
    13
lemma inj_the_preced: 
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 61
diff changeset
    14
  "inj_on (the_preced s) (threads s)"
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 61
diff changeset
    15
  by (metis inj_onI preced_unique the_preced_def)
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 61
diff changeset
    16
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
    17
text {* @{term "the_thread"} extracts thread out of RAG node. *}
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
    18
fun the_thread :: "node \<Rightarrow> thread" where
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
    19
   "the_thread (Th th) = th"
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
    20
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
    21
text {* The following @{text "wRAG"} is the waiting sub-graph of @{text "RAG"}. *}
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    22
definition "wRAG (s::state) = {(Th th, Cs cs) | th cs. waiting s th cs}"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    23
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
    24
text {* The following @{text "hRAG"} is the holding sub-graph of @{text "RAG"}. *}
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    25
definition "hRAG (s::state) =  {(Cs cs, Th th) | th cs. holding s th cs}"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    26
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
    27
text {* The following lemma splits @{term "RAG"} graph into the above two sub-graphs. *}
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    28
lemma RAG_split: "RAG s = (wRAG s \<union> hRAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    29
  by (unfold s_RAG_abv wRAG_def hRAG_def s_waiting_abv 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    30
             s_holding_abv cs_RAG_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    31
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
    32
text {* 
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
    33
  The following @{text "tRAG"} is the thread-graph derived from @{term "RAG"}.
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
    34
  It characterizes the dependency between threads when calculating current
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
    35
  precedences. It is defined as the composition of the above two sub-graphs, 
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
    36
  names @{term "wRAG"} and @{term "hRAG"}.
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
    37
 *}
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
    38
definition "tRAG s = wRAG s O hRAG s"
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
    39
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
    40
(* ccc *)
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
    41
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
    42
definition "cp_gen s x =
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
    43
                  Max ((the_preced s \<circ> the_thread) ` subtree (tRAG s) x)"
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
    44
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    45
lemma tRAG_alt_def: 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    46
  "tRAG s = {(Th th1, Th th2) | th1 th2. 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    47
                  \<exists> cs. (Th th1, Cs cs) \<in> RAG s \<and> (Cs cs, Th th2) \<in> RAG s}"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    48
 by (auto simp:tRAG_def RAG_split wRAG_def hRAG_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    49
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
    50
lemma tRAG_Field:
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
    51
  "Field (tRAG s) \<subseteq> Field (RAG s)"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
    52
  by (unfold tRAG_alt_def Field_def, auto)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
    53
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
    54
lemma tRAG_ancestorsE:
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
    55
  assumes "x \<in> ancestors (tRAG s) u"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
    56
  obtains th where "x = Th th"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
    57
proof -
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
    58
  from assms have "(u, x) \<in> (tRAG s)^+" 
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
    59
      by (unfold ancestors_def, auto)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
    60
  from tranclE[OF this] obtain c where "(c, x) \<in> tRAG s" by auto
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
    61
  then obtain th where "x = Th th"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
    62
    by (unfold tRAG_alt_def, auto)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
    63
  from that[OF this] show ?thesis .
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
    64
qed
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
    65
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    66
lemma tRAG_mono:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    67
  assumes "RAG s' \<subseteq> RAG s"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    68
  shows "tRAG s' \<subseteq> tRAG s"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    69
  using assms 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    70
  by (unfold tRAG_alt_def, auto)
56
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
    71
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    72
lemma holding_next_thI:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    73
  assumes "holding s th cs"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    74
  and "length (wq s cs) > 1"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    75
  obtains th' where "next_th s th cs th'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    76
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    77
  from assms(1)[folded eq_holding, unfolded cs_holding_def]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    78
  have " th \<in> set (wq s cs) \<and> th = hd (wq s cs)" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    79
  then obtain rest where h1: "wq s cs = th#rest" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    80
    by (cases "wq s cs", auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    81
  with assms(2) have h2: "rest \<noteq> []" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    82
  let ?th' = "hd (SOME q. distinct q \<and> set q = set rest)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    83
  have "next_th s th cs ?th'" using  h1(1) h2 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    84
    by (unfold next_th_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    85
  from that[OF this] show ?thesis .
56
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
    86
qed
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
    87
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    88
lemma RAG_tRAG_transfer:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    89
  assumes "vt s'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    90
  assumes "RAG s = RAG s' \<union> {(Th th, Cs cs)}"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    91
  and "(Cs cs, Th th'') \<in> RAG s'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    92
  shows "tRAG s = tRAG s' \<union> {(Th th, Th th'')}" (is "?L = ?R")
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    93
proof -
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    94
  interpret vt_s': valid_trace "s'" using assms(1)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    95
    by (unfold_locales, simp)
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    96
  interpret rtree: rtree "RAG s'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    97
  proof
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    98
  show "single_valued (RAG s')"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
    99
  apply (intro_locales)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   100
    by (unfold single_valued_def, 
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   101
        auto intro:vt_s'.unique_RAG)
56
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   102
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   103
  show "acyclic (RAG s')"
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   104
     by (rule vt_s'.acyclic_RAG)
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   105
  qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   106
  { fix n1 n2
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   107
    assume "(n1, n2) \<in> ?L"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   108
    from this[unfolded tRAG_alt_def]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   109
    obtain th1 th2 cs' where 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   110
      h: "n1 = Th th1" "n2 = Th th2" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   111
         "(Th th1, Cs cs') \<in> RAG s"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   112
         "(Cs cs', Th th2) \<in> RAG s" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   113
    from h(4) and assms(2) have cs_in: "(Cs cs', Th th2) \<in> RAG s'" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   114
    from h(3) and assms(2) 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   115
    have "(Th th1, Cs cs') = (Th th, Cs cs) \<or> 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   116
          (Th th1, Cs cs') \<in> RAG s'" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   117
    hence "(n1, n2) \<in> ?R"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   118
    proof
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   119
      assume h1: "(Th th1, Cs cs') = (Th th, Cs cs)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   120
      hence eq_th1: "th1 = th" by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   121
      moreover have "th2 = th''"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   122
      proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   123
        from h1 have "cs' = cs" by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   124
        from assms(3) cs_in[unfolded this] rtree.sgv
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   125
        show ?thesis
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   126
          by (unfold single_valued_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   127
      qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   128
      ultimately show ?thesis using h(1,2) by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   129
    next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   130
      assume "(Th th1, Cs cs') \<in> RAG s'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   131
      with cs_in have "(Th th1, Th th2) \<in> tRAG s'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   132
        by (unfold tRAG_alt_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   133
      from this[folded h(1, 2)] show ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   134
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   135
  } moreover {
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   136
    fix n1 n2
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   137
    assume "(n1, n2) \<in> ?R"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   138
    hence "(n1, n2) \<in>tRAG s' \<or> (n1, n2) = (Th th, Th th'')" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   139
    hence "(n1, n2) \<in> ?L" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   140
    proof
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   141
      assume "(n1, n2) \<in> tRAG s'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   142
      moreover have "... \<subseteq> ?L"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   143
      proof(rule tRAG_mono)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   144
        show "RAG s' \<subseteq> RAG s" by (unfold assms(2), auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   145
      qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   146
      ultimately show ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   147
    next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   148
      assume eq_n: "(n1, n2) = (Th th, Th th'')"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   149
      from assms(2, 3) have "(Cs cs, Th th'') \<in> RAG s" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   150
      moreover have "(Th th, Cs cs) \<in> RAG s" using assms(2) by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   151
      ultimately show ?thesis 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   152
        by (unfold eq_n tRAG_alt_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   153
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   154
  } ultimately show ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   155
qed
56
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   156
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   157
context valid_trace
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   158
begin
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   159
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   160
lemmas RAG_tRAG_transfer = RAG_tRAG_transfer[OF vt]
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   161
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   162
end
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   163
56
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   164
lemma cp_alt_def:
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   165
  "cp s th =  
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   166
           Max ((the_preced s) ` {th'. Th th' \<in> (subtree (RAG s) (Th th))})"
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   167
proof -
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   168
  have "Max (the_preced s ` ({th} \<union> dependants (wq s) th)) =
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   169
        Max (the_preced s ` {th'. Th th' \<in> subtree (RAG s) (Th th)})" 
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   170
          (is "Max (_ ` ?L) = Max (_ ` ?R)")
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   171
  proof -
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   172
    have "?L = ?R" 
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   173
    by (auto dest:rtranclD simp:cs_dependants_def cs_RAG_def s_RAG_def subtree_def)
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   174
    thus ?thesis by simp
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   175
  qed
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   176
  thus ?thesis by (unfold cp_eq_cpreced cpreced_def, fold the_preced_def, simp)
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   177
qed
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   178
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   179
lemma cp_gen_alt_def:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   180
  "cp_gen s = (Max \<circ> (\<lambda>x. (the_preced s \<circ> the_thread) ` subtree (tRAG s) x))"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   181
    by (auto simp:cp_gen_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   182
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   183
lemma tRAG_nodeE:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   184
  assumes "(n1, n2) \<in> tRAG s"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   185
  obtains th1 th2 where "n1 = Th th1" "n2 = Th th2"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   186
  using assms
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   187
  by (auto simp: tRAG_def wRAG_def hRAG_def tRAG_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   188
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   189
lemma subtree_nodeE:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   190
  assumes "n \<in> subtree (tRAG s) (Th th)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   191
  obtains th1 where "n = Th th1"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   192
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   193
  show ?thesis
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   194
  proof(rule subtreeE[OF assms])
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   195
    assume "n = Th th"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   196
    from that[OF this] show ?thesis .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   197
  next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   198
    assume "Th th \<in> ancestors (tRAG s) n"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   199
    hence "(n, Th th) \<in> (tRAG s)^+" by (auto simp:ancestors_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   200
    hence "\<exists> th1. n = Th th1"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   201
    proof(induct)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   202
      case (base y)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   203
      from tRAG_nodeE[OF this] show ?case by metis
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   204
    next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   205
      case (step y z)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   206
      thus ?case by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   207
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   208
    with that show ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   209
  qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   210
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   211
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   212
lemma tRAG_star_RAG: "(tRAG s)^* \<subseteq> (RAG s)^*"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   213
proof -
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   214
  have "(wRAG s O hRAG s)^* \<subseteq> (RAG s O RAG s)^*" 
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   215
    by (rule rtrancl_mono, auto simp:RAG_split)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   216
  also have "... \<subseteq> ((RAG s)^*)^*"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   217
    by (rule rtrancl_mono, auto)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   218
  also have "... = (RAG s)^*" by simp
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   219
  finally show ?thesis by (unfold tRAG_def, simp)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   220
qed
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   221
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   222
lemma tRAG_subtree_RAG: "subtree (tRAG s) x \<subseteq> subtree (RAG s) x"
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   223
proof -
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   224
  { fix a
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   225
    assume "a \<in> subtree (tRAG s) x"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   226
    hence "(a, x) \<in> (tRAG s)^*" by (auto simp:subtree_def)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   227
    with tRAG_star_RAG[of s]
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   228
    have "(a, x) \<in> (RAG s)^*" by auto
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   229
    hence "a \<in> subtree (RAG s) x" by (auto simp:subtree_def)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   230
  } thus ?thesis by auto
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   231
qed
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   232
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   233
lemma tRAG_trancl_eq:
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   234
   "{th'. (Th th', Th th)  \<in> (tRAG s)^+} = 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   235
    {th'. (Th th', Th th)  \<in> (RAG s)^+}"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   236
   (is "?L = ?R")
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   237
proof -
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   238
  { fix th'
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   239
    assume "th' \<in> ?L"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   240
    hence "(Th th', Th th) \<in> (tRAG s)^+" by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   241
    from tranclD[OF this]
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   242
    obtain z where h: "(Th th', z) \<in> tRAG s" "(z, Th th) \<in> (tRAG s)\<^sup>*" by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   243
    from tRAG_subtree_RAG[of s] and this(2)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   244
    have "(z, Th th) \<in> (RAG s)^*" by (meson subsetCE tRAG_star_RAG) 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   245
    moreover from h(1) have "(Th th', z) \<in> (RAG s)^+" using tRAG_alt_def by auto 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   246
    ultimately have "th' \<in> ?R"  by auto 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   247
  } moreover 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   248
  { fix th'
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   249
    assume "th' \<in> ?R"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   250
    hence "(Th th', Th th) \<in> (RAG s)^+" by (auto)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   251
    from plus_rpath[OF this]
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   252
    obtain xs where rp: "rpath (RAG s) (Th th') xs (Th th)" "xs \<noteq> []" by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   253
    hence "(Th th', Th th) \<in> (tRAG s)^+"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   254
    proof(induct xs arbitrary:th' th rule:length_induct)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   255
      case (1 xs th' th)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   256
      then obtain x1 xs1 where Cons1: "xs = x1#xs1" by (cases xs, auto)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   257
      show ?case
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   258
      proof(cases "xs1")
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   259
        case Nil
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   260
        from 1(2)[unfolded Cons1 Nil]
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   261
        have rp: "rpath (RAG s) (Th th') [x1] (Th th)" .
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   262
        hence "(Th th', x1) \<in> (RAG s)" by (cases, simp)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   263
        then obtain cs where "x1 = Cs cs" 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   264
              by (unfold s_RAG_def, auto)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   265
        from rpath_nnl_lastE[OF rp[unfolded this]]
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   266
        show ?thesis by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   267
      next
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   268
        case (Cons x2 xs2)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   269
        from 1(2)[unfolded Cons1[unfolded this]]
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   270
        have rp: "rpath (RAG s) (Th th') (x1 # x2 # xs2) (Th th)" .
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   271
        from rpath_edges_on[OF this]
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   272
        have eds: "edges_on (Th th' # x1 # x2 # xs2) \<subseteq> RAG s" .
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   273
        have "(Th th', x1) \<in> edges_on (Th th' # x1 # x2 # xs2)"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   274
            by (simp add: edges_on_unfold)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   275
        with eds have rg1: "(Th th', x1) \<in> RAG s" by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   276
        then obtain cs1 where eq_x1: "x1 = Cs cs1" by (unfold s_RAG_def, auto)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   277
        have "(x1, x2) \<in> edges_on (Th th' # x1 # x2 # xs2)"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   278
            by (simp add: edges_on_unfold)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   279
        from this eds
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   280
        have rg2: "(x1, x2) \<in> RAG s" by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   281
        from this[unfolded eq_x1] 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   282
        obtain th1 where eq_x2: "x2 = Th th1" by (unfold s_RAG_def, auto)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   283
        from rg1[unfolded eq_x1] rg2[unfolded eq_x1 eq_x2]
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   284
        have rt1: "(Th th', Th th1) \<in> tRAG s" by (unfold tRAG_alt_def, auto)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   285
        from rp have "rpath (RAG s) x2 xs2 (Th th)"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   286
           by  (elim rpath_ConsE, simp)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   287
        from this[unfolded eq_x2] have rp': "rpath (RAG s) (Th th1) xs2 (Th th)" .
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   288
        show ?thesis
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   289
        proof(cases "xs2 = []")
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   290
          case True
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   291
          from rpath_nilE[OF rp'[unfolded this]]
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   292
          have "th1 = th" by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   293
          from rt1[unfolded this] show ?thesis by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   294
        next
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   295
          case False
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   296
          from 1(1)[rule_format, OF _ rp' this, unfolded Cons1 Cons]
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   297
          have "(Th th1, Th th) \<in> (tRAG s)\<^sup>+" by simp
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   298
          with rt1 show ?thesis by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   299
        qed
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   300
      qed
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   301
    qed
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   302
    hence "th' \<in> ?L" by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   303
  } ultimately show ?thesis by blast
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   304
qed
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   305
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   306
lemma tRAG_trancl_eq_Th:
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   307
   "{Th th' | th'. (Th th', Th th)  \<in> (tRAG s)^+} = 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   308
    {Th th' | th'. (Th th', Th th)  \<in> (RAG s)^+}"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   309
    using tRAG_trancl_eq by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   310
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   311
lemma dependants_alt_def:
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   312
  "dependants s th = {th'. (Th th', Th th) \<in> (tRAG s)^+}"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   313
  by (metis eq_RAG s_dependants_def tRAG_trancl_eq)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   314
  
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   315
context valid_trace
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   316
begin
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   317
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   318
lemma count_eq_tRAG_plus:
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   319
  assumes "cntP s th = cntV s th"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   320
  shows "{th'. (Th th', Th th) \<in> (tRAG s)^+} = {}"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   321
  using assms count_eq_dependants dependants_alt_def eq_dependants by auto 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   322
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   323
lemma count_eq_RAG_plus:
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   324
  assumes "cntP s th = cntV s th"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   325
  shows "{th'. (Th th', Th th) \<in> (RAG s)^+} = {}"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   326
  using assms count_eq_dependants cs_dependants_def eq_RAG by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   327
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   328
lemma count_eq_RAG_plus_Th:
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   329
  assumes "cntP s th = cntV s th"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   330
  shows "{Th th' | th'. (Th th', Th th) \<in> (RAG s)^+} = {}"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   331
  using count_eq_RAG_plus[OF assms] by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   332
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   333
lemma count_eq_tRAG_plus_Th:
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   334
  assumes "cntP s th = cntV s th"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   335
  shows "{Th th' | th'. (Th th', Th th) \<in> (tRAG s)^+} = {}"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   336
   using count_eq_tRAG_plus[OF assms] by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   337
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   338
end
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   339
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   340
lemma tRAG_subtree_eq: 
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   341
   "(subtree (tRAG s) (Th th)) = {Th th' | th'. Th th'  \<in> (subtree (RAG s) (Th th))}"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   342
   (is "?L = ?R")
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   343
proof -
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   344
  { fix n 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   345
    assume h: "n \<in> ?L"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   346
    hence "n \<in> ?R"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   347
    by (smt mem_Collect_eq subsetCE subtree_def subtree_nodeE tRAG_subtree_RAG) 
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   348
  } moreover {
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   349
    fix n
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   350
    assume "n \<in> ?R"
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   351
    then obtain th' where h: "n = Th th'" "(Th th', Th th) \<in> (RAG s)^*"
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   352
      by (auto simp:subtree_def)
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   353
    from rtranclD[OF this(2)]
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   354
    have "n \<in> ?L"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   355
    proof
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   356
      assume "Th th' \<noteq> Th th \<and> (Th th', Th th) \<in> (RAG s)\<^sup>+"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   357
      with h have "n \<in> {Th th' | th'. (Th th', Th th)  \<in> (RAG s)^+}" by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   358
      thus ?thesis using subtree_def tRAG_trancl_eq by fastforce
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   359
    qed (insert h, auto simp:subtree_def)
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   360
  } ultimately show ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   361
qed
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   362
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   363
lemma threads_set_eq: 
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   364
   "the_thread ` (subtree (tRAG s) (Th th)) = 
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   365
                  {th'. Th th' \<in> (subtree (RAG s) (Th th))}" (is "?L = ?R")
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   366
   by (auto intro:rev_image_eqI simp:tRAG_subtree_eq)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   367
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   368
lemma cp_alt_def1: 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   369
  "cp s th = Max ((the_preced s o the_thread) ` (subtree (tRAG s) (Th th)))"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   370
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   371
  have "(the_preced s ` the_thread ` subtree (tRAG s) (Th th)) =
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   372
       ((the_preced s \<circ> the_thread) ` subtree (tRAG s) (Th th))"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   373
       by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   374
  thus ?thesis by (unfold cp_alt_def, fold threads_set_eq, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   375
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   376
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   377
lemma cp_gen_def_cond: 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   378
  assumes "x = Th th"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   379
  shows "cp s th = cp_gen s (Th th)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   380
by (unfold cp_alt_def1 cp_gen_def, simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   381
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   382
lemma cp_gen_over_set:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   383
  assumes "\<forall> x \<in> A. \<exists> th. x = Th th"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   384
  shows "cp_gen s ` A = (cp s \<circ> the_thread) ` A"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   385
proof(rule f_image_eq)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   386
  fix a
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   387
  assume "a \<in> A"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   388
  from assms[rule_format, OF this]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   389
  obtain th where eq_a: "a = Th th" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   390
  show "cp_gen s a = (cp s \<circ> the_thread) a"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   391
    by  (unfold eq_a, simp, unfold cp_gen_def_cond[OF refl[of "Th th"]], simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   392
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   393
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   394
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   395
context valid_trace
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   396
begin
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   397
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   398
lemma RAG_threads:
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   399
  assumes "(Th th) \<in> Field (RAG s)"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   400
  shows "th \<in> threads s"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   401
  using assms
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   402
  by (metis Field_def UnE dm_RAG_threads range_in vt)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   403
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   404
lemma subtree_tRAG_thread:
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   405
  assumes "th \<in> threads s"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   406
  shows "subtree (tRAG s) (Th th) \<subseteq> Th ` threads s" (is "?L \<subseteq> ?R")
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   407
proof -
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   408
  have "?L = {Th th' |th'. Th th' \<in> subtree (RAG s) (Th th)}"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   409
    by (unfold tRAG_subtree_eq, simp)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   410
  also have "... \<subseteq> ?R"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   411
  proof
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   412
    fix x
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   413
    assume "x \<in> {Th th' |th'. Th th' \<in> subtree (RAG s) (Th th)}"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   414
    then obtain th' where h: "x = Th th'" "Th th' \<in> subtree (RAG s) (Th th)" by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   415
    from this(2)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   416
    show "x \<in> ?R"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   417
    proof(cases rule:subtreeE)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   418
      case 1
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   419
      thus ?thesis by (simp add: assms h(1)) 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   420
    next
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   421
      case 2
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   422
      thus ?thesis by (metis ancestors_Field dm_RAG_threads h(1) image_eqI) 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   423
    qed
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   424
  qed
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   425
  finally show ?thesis .
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   426
qed
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   427
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   428
lemma readys_root:
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   429
  assumes "th \<in> readys s"
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   430
  shows "root (RAG s) (Th th)"
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   431
proof -
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   432
  { fix x
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   433
    assume "x \<in> ancestors (RAG s) (Th th)"
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   434
    hence h: "(Th th, x) \<in> (RAG s)^+" by (auto simp:ancestors_def)
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   435
    from tranclD[OF this]
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   436
    obtain z where "(Th th, z) \<in> RAG s" by auto
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   437
    with assms(1) have False
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   438
         apply (case_tac z, auto simp:readys_def s_RAG_def s_waiting_def cs_waiting_def)
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   439
         by (fold wq_def, blast)
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   440
  } thus ?thesis by (unfold root_def, auto)
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   441
qed
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   442
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   443
lemma readys_in_no_subtree:
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   444
  assumes "th \<in> readys s"
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   445
  and "th' \<noteq> th"
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   446
  shows "Th th \<notin> subtree (RAG s) (Th th')" 
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   447
proof
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   448
   assume "Th th \<in> subtree (RAG s) (Th th')"
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   449
   thus False
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   450
   proof(cases rule:subtreeE)
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   451
      case 1
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   452
      with assms show ?thesis by auto
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   453
   next
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   454
      case 2
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   455
      with readys_root[OF assms(1)]
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   456
      show ?thesis by (auto simp:root_def)
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   457
   qed
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   458
qed
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   459
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   460
lemma not_in_thread_isolated:
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   461
  assumes "th \<notin> threads s"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   462
  shows "(Th th) \<notin> Field (RAG s)"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   463
proof
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   464
  assume "(Th th) \<in> Field (RAG s)"
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   465
  with dm_RAG_threads and range_in assms
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   466
  show False by (unfold Field_def, blast)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   467
qed
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
   468
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   469
lemma wf_RAG: "wf (RAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   470
proof(rule finite_acyclic_wf)
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   471
  from finite_RAG show "finite (RAG s)" .
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   472
next
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   473
  from acyclic_RAG show "acyclic (RAG s)" .
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   474
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   475
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   476
lemma sgv_wRAG: "single_valued (wRAG s)"
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   477
  using waiting_unique
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   478
  by (unfold single_valued_def wRAG_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   479
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   480
lemma sgv_hRAG: "single_valued (hRAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   481
  using holding_unique 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   482
  by (unfold single_valued_def hRAG_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   483
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   484
lemma sgv_tRAG: "single_valued (tRAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   485
  by (unfold tRAG_def, rule single_valued_relcomp, 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   486
              insert sgv_wRAG sgv_hRAG, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   487
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   488
lemma acyclic_tRAG: "acyclic (tRAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   489
proof(unfold tRAG_def, rule acyclic_compose)
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   490
  show "acyclic (RAG s)" using acyclic_RAG .
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   491
next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   492
  show "wRAG s \<subseteq> RAG s" unfolding RAG_split by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   493
next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   494
  show "hRAG s \<subseteq> RAG s" unfolding RAG_split by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   495
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   496
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   497
lemma sgv_RAG: "single_valued (RAG s)"
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   498
  using unique_RAG by (auto simp:single_valued_def)
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   499
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   500
lemma rtree_RAG: "rtree (RAG s)"
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   501
  using sgv_RAG acyclic_RAG
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   502
  by (unfold rtree_def rtree_axioms_def sgv_def, auto)
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   503
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   504
end
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   505
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   506
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   507
sublocale valid_trace < rtree_RAG: rtree "RAG s"
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   508
proof
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   509
  show "single_valued (RAG s)"
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   510
  apply (intro_locales)
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   511
    by (unfold single_valued_def, 
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   512
        auto intro:unique_RAG)
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   513
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   514
  show "acyclic (RAG s)"
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   515
     by (rule acyclic_RAG)
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   516
qed
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   517
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   518
sublocale valid_trace < rtree_s: rtree "tRAG s"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   519
proof(unfold_locales)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   520
  from sgv_tRAG show "single_valued (tRAG s)" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   521
next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   522
  from acyclic_tRAG show "acyclic (tRAG s)" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   523
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   524
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   525
sublocale valid_trace < fsbtRAGs : fsubtree "RAG s"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   526
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   527
  show "fsubtree (RAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   528
  proof(intro_locales)
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   529
    show "fbranch (RAG s)" using finite_fbranchI[OF finite_RAG] .
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   530
  next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   531
    show "fsubtree_axioms (RAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   532
    proof(unfold fsubtree_axioms_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   533
    find_theorems wf RAG
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   534
      from wf_RAG show "wf (RAG s)" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   535
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   536
  qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   537
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   538
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   539
sublocale valid_trace < fsbttRAGs: fsubtree "tRAG s"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   540
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   541
  have "fsubtree (tRAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   542
  proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   543
    have "fbranch (tRAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   544
    proof(unfold tRAG_def, rule fbranch_compose)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   545
        show "fbranch (wRAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   546
        proof(rule finite_fbranchI)
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   547
           from finite_RAG show "finite (wRAG s)"
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   548
           by (unfold RAG_split, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   549
        qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   550
    next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   551
        show "fbranch (hRAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   552
        proof(rule finite_fbranchI)
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   553
           from finite_RAG 
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   554
           show "finite (hRAG s)" by (unfold RAG_split, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   555
        qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   556
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   557
    moreover have "wf (tRAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   558
    proof(rule wf_subset)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   559
      show "wf (RAG s O RAG s)" using wf_RAG
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   560
        by (fold wf_comp_self, simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   561
    next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   562
      show "tRAG s \<subseteq> (RAG s O RAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   563
        by (unfold tRAG_alt_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   564
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   565
    ultimately show ?thesis
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   566
      by (unfold fsubtree_def fsubtree_axioms_def,auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   567
  qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   568
  from this[folded tRAG_def] show "fsubtree (tRAG s)" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   569
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   570
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   571
lemma Max_UNION: 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   572
  assumes "finite A"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   573
  and "A \<noteq> {}"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   574
  and "\<forall> M \<in> f ` A. finite M"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   575
  and "\<forall> M \<in> f ` A. M \<noteq> {}"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   576
  shows "Max (\<Union>x\<in> A. f x) = Max (Max ` f ` A)" (is "?L = ?R")
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   577
  using assms[simp]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   578
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   579
  have "?L = Max (\<Union>(f ` A))"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   580
    by (fold Union_image_eq, simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   581
  also have "... = ?R"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   582
    by (subst Max_Union, simp+)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   583
  finally show ?thesis .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   584
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   585
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   586
lemma max_Max_eq:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   587
  assumes "finite A"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   588
    and "A \<noteq> {}"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   589
    and "x = y"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   590
  shows "max x (Max A) = Max ({y} \<union> A)" (is "?L = ?R")
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   591
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   592
  have "?R = Max (insert y A)" by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   593
  also from assms have "... = ?L"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   594
      by (subst Max.insert, simp+)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   595
  finally show ?thesis by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   596
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   597
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   598
context valid_trace
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   599
begin
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   600
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   601
(* ddd *)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   602
lemma cp_gen_rec:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   603
  assumes "x = Th th"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   604
  shows "cp_gen s x = Max ({the_preced s th} \<union> (cp_gen s) ` children (tRAG s) x)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   605
proof(cases "children (tRAG s) x = {}")
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   606
  case True
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   607
  show ?thesis
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   608
    by (unfold True cp_gen_def subtree_children, simp add:assms)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   609
next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   610
  case False
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   611
  hence [simp]: "children (tRAG s) x \<noteq> {}" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   612
  note fsbttRAGs.finite_subtree[simp]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   613
  have [simp]: "finite (children (tRAG s) x)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   614
     by (intro rev_finite_subset[OF fsbttRAGs.finite_subtree], 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   615
            rule children_subtree)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   616
  { fix r x
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   617
    have "subtree r x \<noteq> {}" by (auto simp:subtree_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   618
  } note this[simp]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   619
  have [simp]: "\<exists>x\<in>children (tRAG s) x. subtree (tRAG s) x \<noteq> {}"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   620
  proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   621
    from False obtain q where "q \<in> children (tRAG s) x" by blast
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   622
    moreover have "subtree (tRAG s) q \<noteq> {}" by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   623
    ultimately show ?thesis by blast
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   624
  qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   625
  have h: "Max ((the_preced s \<circ> the_thread) `
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   626
                ({x} \<union> \<Union>(subtree (tRAG s) ` children (tRAG s) x))) =
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   627
        Max ({the_preced s th} \<union> cp_gen s ` children (tRAG s) x)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   628
                     (is "?L = ?R")
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   629
  proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   630
    let "Max (?f ` (?A \<union> \<Union> (?g ` ?B)))" = ?L
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   631
    let "Max (_ \<union> (?h ` ?B))" = ?R
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   632
    let ?L1 = "?f ` \<Union>(?g ` ?B)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   633
    have eq_Max_L1: "Max ?L1 = Max (?h ` ?B)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   634
    proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   635
      have "?L1 = ?f ` (\<Union> x \<in> ?B.(?g x))" by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   636
      also have "... =  (\<Union> x \<in> ?B. ?f ` (?g x))" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   637
      finally have "Max ?L1 = Max ..." by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   638
      also have "... = Max (Max ` (\<lambda>x. ?f ` subtree (tRAG s) x) ` ?B)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   639
        by (subst Max_UNION, simp+)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   640
      also have "... = Max (cp_gen s ` children (tRAG s) x)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   641
          by (unfold image_comp cp_gen_alt_def, simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   642
      finally show ?thesis .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   643
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   644
    show ?thesis
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   645
    proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   646
      have "?L = Max (?f ` ?A \<union> ?L1)" by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   647
      also have "... = max (the_preced s (the_thread x)) (Max ?L1)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   648
            by (subst Max_Un, simp+)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   649
      also have "... = max (?f x) (Max (?h ` ?B))"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   650
        by (unfold eq_Max_L1, simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   651
      also have "... =?R"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   652
        by (rule max_Max_eq, (simp)+, unfold assms, simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   653
      finally show ?thesis .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   654
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   655
  qed  thus ?thesis 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   656
          by (fold h subtree_children, unfold cp_gen_def, simp) 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   657
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   658
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   659
lemma cp_rec:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   660
  "cp s th = Max ({the_preced s th} \<union> 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   661
                     (cp s o the_thread) ` children (tRAG s) (Th th))"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   662
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   663
  have "Th th = Th th" by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   664
  note h =  cp_gen_def_cond[OF this] cp_gen_rec[OF this]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   665
  show ?thesis 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   666
  proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   667
    have "cp_gen s ` children (tRAG s) (Th th) = 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   668
                (cp s \<circ> the_thread) ` children (tRAG s) (Th th)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   669
    proof(rule cp_gen_over_set)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   670
      show " \<forall>x\<in>children (tRAG s) (Th th). \<exists>th. x = Th th"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   671
        by (unfold tRAG_alt_def, auto simp:children_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   672
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   673
    thus ?thesis by (subst (1) h(1), unfold h(2), simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   674
  qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   675
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   676
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   677
end
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   678
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   679
(* keep *)
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   680
lemma next_th_holding:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   681
  assumes vt: "vt s"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   682
  and nxt: "next_th s th cs th'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   683
  shows "holding (wq s) th cs"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   684
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   685
  from nxt[unfolded next_th_def]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   686
  obtain rest where h: "wq s cs = th # rest"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   687
                       "rest \<noteq> []" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   688
                       "th' = hd (SOME q. distinct q \<and> set q = set rest)" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   689
  thus ?thesis
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   690
    by (unfold cs_holding_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   691
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   692
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   693
context valid_trace
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   694
begin
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   695
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   696
lemma next_th_waiting:
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   697
  assumes nxt: "next_th s th cs th'"
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   698
  shows "waiting (wq s) th' cs"
55
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   699
proof -
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   700
  from nxt[unfolded next_th_def]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   701
  obtain rest where h: "wq s cs = th # rest"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   702
                       "rest \<noteq> []" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   703
                       "th' = hd (SOME q. distinct q \<and> set q = set rest)" by auto
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   704
  from wq_distinct[of cs, unfolded h]
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   705
  have dst: "distinct (th # rest)" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   706
  have in_rest: "th' \<in> set rest"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   707
  proof(unfold h, rule someI2)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   708
    show "distinct rest \<and> set rest = set rest" using dst by auto
55
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   709
  next
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   710
    fix x assume "distinct x \<and> set x = set rest"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   711
    with h(2)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   712
    show "hd x \<in> set (rest)" by (cases x, auto)
55
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   713
  qed
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   714
  hence "th' \<in> set (wq s cs)" by (unfold h(1), auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   715
  moreover have "th' \<noteq> hd (wq s cs)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   716
    by (unfold h(1), insert in_rest dst, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   717
  ultimately show ?thesis by (auto simp:cs_waiting_def)
55
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   718
qed
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   719
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   720
lemma next_th_RAG:
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   721
  assumes nxt: "next_th (s::event list) th cs th'"
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   722
  shows "{(Cs cs, Th th), (Th th', Cs cs)} \<subseteq> RAG s"
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   723
  using vt assms next_th_holding next_th_waiting
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   724
  by (unfold s_RAG_def, simp)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   725
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   726
end
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   727
56
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   728
-- {* A useless definition *}
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   729
definition cps:: "state \<Rightarrow> (thread \<times> precedence) set"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   730
where "cps s = {(th, cp s th) | th . th \<in> threads s}"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   731
56
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   732
55
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   733
text {* (* ddd *)
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   734
  One beauty of our modelling is that we follow the definitional extension tradition of HOL.
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   735
  The benefit of such a concise and miniature model is that  large number of intuitively 
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   736
  obvious facts are derived as lemmas, rather than asserted as axioms.
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   737
*}
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   738
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   739
text {*
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   740
  However, the lemmas in the forthcoming several locales are no longer 
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   741
  obvious. These lemmas show how the current precedences should be recalculated 
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   742
  after every execution step (in our model, every step is represented by an event, 
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   743
  which in turn, represents a system call, or operation). Each operation is 
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   744
  treated in a separate locale.
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   745
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   746
  The complication of current precedence recalculation comes 
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   747
  because the changing of RAG needs to be taken into account, 
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   748
  in addition to the changing of precedence. 
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   749
  The reason RAG changing affects current precedence is that,
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   750
  according to the definition, current precedence 
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   751
  of a thread is the maximum of the precedences of its dependants, 
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   752
  where the dependants are defined in terms of RAG.
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   753
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   754
  Therefore, each operation, lemmas concerning the change of the precedences 
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   755
  and RAG are derived first, so that the lemmas about
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   756
  current precedence recalculation can be based on.
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   757
*}
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   758
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   759
text {* (* ddd *)
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   760
  The following locale @{text "step_set_cps"} investigates the recalculation 
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   761
  after the @{text "Set"} operation.
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   762
*}
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   763
locale step_set_cps =
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   764
  fixes s' th prio s 
55
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   765
  -- {* @{text "s'"} is the system state before the operation *}
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   766
  -- {* @{text "s"} is the system state after the operation *}
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   767
  defines s_def : "s \<equiv> (Set th prio#s')" 
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   768
  -- {* @{text "s"} is assumed to be a legitimate state, from which
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   769
         the legitimacy of @{text "s"} can be derived. *}
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   770
  assumes vt_s: "vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   771
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   772
sublocale step_set_cps < vat_s : valid_trace "s"
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   773
proof
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   774
  from vt_s show "vt s" .
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   775
qed
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   776
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   777
sublocale step_set_cps < vat_s' : valid_trace "s'"
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   778
proof
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   779
  from step_back_vt[OF vt_s[unfolded s_def]] show "vt s'" .
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   780
qed
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   781
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   782
context step_set_cps 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   783
begin
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   784
55
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   785
text {* (* ddd *)
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   786
  The following two lemmas confirm that @{text "Set"}-operating only changes the precedence 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   787
  of the initiating thread.
55
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   788
*}
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   789
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   790
lemma eq_preced:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   791
  assumes "th' \<noteq> th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   792
  shows "preced th' s = preced th' s'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   793
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   794
  from assms show ?thesis 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   795
    by (unfold s_def, auto simp:preced_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   796
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   797
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   798
lemma eq_the_preced: 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   799
  fixes th'
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   800
  assumes "th' \<noteq> th"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   801
  shows "the_preced s th' = the_preced s' th'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   802
  using assms
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   803
  by (unfold the_preced_def, intro eq_preced, simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   804
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   805
text {*
55
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   806
  The following lemma assures that the resetting of priority does not change the RAG. 
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   807
*}
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   808
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   809
lemma eq_dep: "RAG s = RAG s'"
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   810
  by (unfold s_def RAG_set_unchanged, auto)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   811
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   812
text {* (* ddd *)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   813
  Th following lemma @{text "eq_cp_pre"} says the priority change of @{text "th"}
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   814
  only affects those threads, which as @{text "Th th"} in their sub-trees.
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   815
  
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   816
  The proof of this lemma is simplified by using the alternative definition of @{text "cp"}. 
55
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   817
*}
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   818
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   819
lemma eq_cp_pre:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   820
  fixes th' 
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   821
  assumes nd: "Th th \<notin> subtree (RAG s') (Th th')"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   822
  shows "cp s th' = cp s' th'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   823
proof -
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   824
  -- {* After unfolding using the alternative definition, elements 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   825
        affecting the @{term "cp"}-value of threads become explicit. 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   826
        We only need to prove the following: *}
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   827
  have "Max (the_preced s ` {th'a. Th th'a \<in> subtree (RAG s) (Th th')}) =
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   828
        Max (the_preced s' ` {th'a. Th th'a \<in> subtree (RAG s') (Th th')})"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   829
        (is "Max (?f ` ?S1) = Max (?g ` ?S2)")
55
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   830
  proof -
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   831
    -- {* The base sets are equal. *}
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   832
    have "?S1 = ?S2" using eq_dep by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   833
    -- {* The function values on the base set are equal as well. *}
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   834
    moreover have "\<forall> e \<in> ?S2. ?f e = ?g e"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   835
    proof
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   836
      fix th1
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   837
      assume "th1 \<in> ?S2"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   838
      with nd have "th1 \<noteq> th" by (auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   839
      from eq_the_preced[OF this]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   840
      show "the_preced s th1 = the_preced s' th1" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   841
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   842
    -- {* Therefore, the image of the functions are equal. *}
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   843
    ultimately have "(?f ` ?S1) = (?g ` ?S2)" by (auto intro!:f_image_eq)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   844
    thus ?thesis by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   845
  qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   846
  thus ?thesis by (simp add:cp_alt_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   847
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   848
55
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   849
text {*
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   850
  The following lemma shows that @{term "th"} is not in the 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   851
  sub-tree of any other thread. 
55
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   852
*}
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   853
lemma th_in_no_subtree:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   854
  assumes "th' \<noteq> th"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   855
  shows "Th th \<notin> subtree (RAG s') (Th th')"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   856
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   857
  have "th \<in> readys s'"
55
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   858
  proof -
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   859
    from step_back_step [OF vt_s[unfolded s_def]]
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   860
    have "step s' (Set th prio)" .
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   861
    hence "th \<in> runing s'" by (cases, simp)
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   862
    thus ?thesis by (simp add:readys_def runing_def)
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   863
  qed
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   864
  find_theorems readys subtree
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   865
  from vat_s'.readys_in_no_subtree[OF this assms(1)]
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   866
  show ?thesis by blast
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   867
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   868
55
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   869
text {* 
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   870
  By combining @{thm "eq_cp_pre"} and @{thm "th_in_no_subtree"}, 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   871
  it is obvious that the change of priority only affects the @{text "cp"}-value 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   872
  of the initiating thread @{text "th"}.
55
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   873
*}
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   874
lemma eq_cp:
55
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   875
  fixes th' 
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   876
  assumes "th' \<noteq> th"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   877
  shows "cp s th' = cp s' th'"
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   878
  by (rule eq_cp_pre[OF th_in_no_subtree[OF assms]])
55
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   879
56
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   880
end
55
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   881
56
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   882
text {*
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   883
  The following @{text "step_v_cps"} is the locale for @{text "V"}-operation.
55
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   884
*}
b85cfbd58f59 Comments for Set-operation finished
xingyuan zhang <xingyuanzhang@126.com>
parents: 53
diff changeset
   885
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   886
locale step_v_cps =
56
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   887
  -- {* @{text "th"} is the initiating thread *}
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   888
  -- {* @{text "cs"} is the critical resource release by the @{text "V"}-operation *}
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   889
  fixes s' th cs s    -- {* @{text "s'"} is the state before operation*}
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   890
  defines s_def : "s \<equiv> (V th cs#s')" -- {* @{text "s"} is the state after operation*}
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   891
  -- {* @{text "s"} is assumed to be valid, which implies the validity of @{text "s'"} *}
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   892
  assumes vt_s: "vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   893
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   894
sublocale step_v_cps < vat_s : valid_trace "s"
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   895
proof
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   896
  from vt_s show "vt s" .
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   897
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   898
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   899
sublocale step_v_cps < vat_s' : valid_trace "s'"
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   900
proof
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   901
  from step_back_vt[OF vt_s[unfolded s_def]] show "vt s'" .
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   902
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   903
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   904
context step_v_cps
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   905
begin
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   906
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   907
lemma ready_th_s': "th \<in> readys s'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   908
  using step_back_step[OF vt_s[unfolded s_def]]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   909
  by (cases, simp add:runing_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   910
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   911
lemma ancestors_th: "ancestors (RAG s') (Th th) = {}"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   912
proof -
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   913
  from vat_s'.readys_root[OF ready_th_s']
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   914
  show ?thesis
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   915
  by (unfold root_def, simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   916
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   917
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   918
lemma holding_th: "holding s' th cs"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   919
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   920
  from vt_s[unfolded s_def]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   921
  have " PIP s' (V th cs)" by (cases, simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   922
  thus ?thesis by (cases, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   923
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   924
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   925
lemma edge_of_th:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   926
    "(Cs cs, Th th) \<in> RAG s'" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   927
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   928
 from holding_th
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   929
 show ?thesis 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   930
    by (unfold s_RAG_def holding_eq, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   931
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   932
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   933
lemma ancestors_cs: 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   934
  "ancestors (RAG s') (Cs cs) = {Th th}"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   935
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   936
  have "ancestors (RAG s') (Cs cs) = ancestors (RAG s') (Th th)  \<union>  {Th th}"
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
   937
  proof(rule vat_s'.rtree_RAG.ancestors_accum)
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   938
    from vt_s[unfolded s_def]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   939
    have " PIP s' (V th cs)" by (cases, simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   940
    thus "(Cs cs, Th th) \<in> RAG s'" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   941
    proof(cases)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   942
      assume "holding s' th cs"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   943
      from this[unfolded holding_eq]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   944
      show ?thesis by (unfold s_RAG_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   945
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   946
  qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   947
  from this[unfolded ancestors_th] show ?thesis by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   948
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   949
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   950
lemma preced_kept: "the_preced s = the_preced s'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   951
  by (auto simp: s_def the_preced_def preced_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   952
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   953
end
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
   954
56
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   955
text {*
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   956
  The following @{text "step_v_cps_nt"} is the sub-locale for @{text "V"}-operation, 
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   957
  which represents the case when there is another thread @{text "th'"}
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   958
  to take over the critical resource released by the initiating thread @{text "th"}.
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   959
*}
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   960
locale step_v_cps_nt = step_v_cps +
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   961
  fixes th'
56
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   962
  -- {* @{text "th'"} is assumed to take over @{text "cs"} *}
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   963
  assumes nt: "next_th s' th cs th'" 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   964
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   965
context step_v_cps_nt
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   966
begin
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   967
56
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   968
text {*
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   969
  Lemma @{text "RAG_s"} confirms the change of RAG:
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   970
  two edges removed and one added, as shown by the following diagram.
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   971
*}
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   972
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   973
(*
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   974
  RAG before the V-operation
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   975
    th1 ----|
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   976
            |
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   977
    th' ----|
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   978
            |----> cs -----|
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   979
    th2 ----|              |
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   980
            |              |
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   981
    th3 ----|              |
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   982
                           |------> th
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   983
    th4 ----|              |
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   984
            |              |
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   985
    th5 ----|              |
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   986
            |----> cs'-----|
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   987
    th6 ----|
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   988
            |
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   989
    th7 ----|
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   990
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   991
 RAG after the V-operation
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   992
    th1 ----|
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   993
            |
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   994
            |----> cs ----> th'
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   995
    th2 ----|              
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   996
            |              
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   997
    th3 ----|              
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   998
                           
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
   999
    th4 ----|              
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
  1000
            |              
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
  1001
    th5 ----|              
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
  1002
            |----> cs'----> th
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
  1003
    th6 ----|
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
  1004
            |
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
  1005
    th7 ----|
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
  1006
*)
0fd478e14e87 Before switching to generic theory of relational trees.
xingyuan zhang <xingyuanzhang@126.com>
parents: 55
diff changeset
  1007
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1008
lemma sub_RAGs': "{(Cs cs, Th th), (Th th', Cs cs)} \<subseteq> RAG s'"
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  1009
                using next_th_RAG[OF nt]  .
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1010
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1011
lemma ancestors_th': 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1012
  "ancestors (RAG s') (Th th') = {Th th, Cs cs}" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1013
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1014
  have "ancestors (RAG s') (Th th') = ancestors (RAG s') (Cs cs) \<union> {Cs cs}"
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  1015
  proof(rule  vat_s'.rtree_RAG.ancestors_accum)
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1016
    from sub_RAGs' show "(Th th', Cs cs) \<in> RAG s'" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1017
  qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1018
  thus ?thesis using ancestors_th ancestors_cs by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1019
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1020
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
  1021
lemma RAG_s:
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
  1022
  "RAG s = (RAG s' - {(Cs cs, Th th), (Th th', Cs cs)}) \<union>
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1023
                                         {(Cs cs, Th th')}"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1024
proof -
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
  1025
  from step_RAG_v[OF vt_s[unfolded s_def], folded s_def]
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1026
    and nt show ?thesis  by (auto intro:next_th_unique)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1027
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1028
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1029
lemma subtree_kept:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1030
  assumes "th1 \<notin> {th, th'}"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1031
  shows "subtree (RAG s) (Th th1) = subtree (RAG s') (Th th1)" (is "_ = ?R")
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1032
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1033
  let ?RAG' = "(RAG s' - {(Cs cs, Th th), (Th th', Cs cs)})"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1034
  let ?RAG'' = "?RAG' \<union> {(Cs cs, Th th')}"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1035
  have "subtree ?RAG' (Th th1) = ?R" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1036
  proof(rule subset_del_subtree_outside)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1037
    show "Range {(Cs cs, Th th), (Th th', Cs cs)} \<inter> subtree (RAG s') (Th th1) = {}"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1038
    proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1039
      have "(Th th) \<notin> subtree (RAG s') (Th th1)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1040
      proof(rule subtree_refute)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1041
        show "Th th1 \<notin> ancestors (RAG s') (Th th)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1042
          by (unfold ancestors_th, simp)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1043
      next
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1044
        from assms show "Th th1 \<noteq> Th th" by simp
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1045
      qed
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1046
      moreover have "(Cs cs) \<notin>  subtree (RAG s') (Th th1)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1047
      proof(rule subtree_refute)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1048
        show "Th th1 \<notin> ancestors (RAG s') (Cs cs)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1049
          by (unfold ancestors_cs, insert assms, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1050
      qed simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1051
      ultimately have "{Th th, Cs cs} \<inter> subtree (RAG s') (Th th1) = {}" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1052
      thus ?thesis by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1053
     qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1054
  qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1055
  moreover have "subtree ?RAG'' (Th th1) =  subtree ?RAG' (Th th1)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1056
  proof(rule subtree_insert_next)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1057
    show "Th th' \<notin> subtree (RAG s' - {(Cs cs, Th th), (Th th', Cs cs)}) (Th th1)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1058
    proof(rule subtree_refute)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1059
      show "Th th1 \<notin> ancestors (RAG s' - {(Cs cs, Th th), (Th th', Cs cs)}) (Th th')"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1060
            (is "_ \<notin> ?R")
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1061
      proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1062
          have "?R \<subseteq> ancestors (RAG s') (Th th')" by (rule ancestors_mono, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1063
          moreover have "Th th1 \<notin> ..." using ancestors_th' assms by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1064
          ultimately show ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1065
      qed
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1066
    next
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1067
      from assms show "Th th1 \<noteq> Th th'" by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1068
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1069
  qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1070
  ultimately show ?thesis by (unfold RAG_s, simp)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1071
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1072
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1073
lemma cp_kept:
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1074
  assumes "th1 \<notin> {th, th'}"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1075
  shows "cp s th1 = cp s' th1"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1076
    by (unfold cp_alt_def preced_kept subtree_kept[OF assms], simp)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1077
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1078
end
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1079
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1080
locale step_v_cps_nnt = step_v_cps +
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1081
  assumes nnt: "\<And> th'. (\<not> next_th s' th cs th')"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1082
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1083
context step_v_cps_nnt
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1084
begin
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1085
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
  1086
lemma RAG_s: "RAG s = RAG s' - {(Cs cs, Th th)}"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1087
proof -
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
  1088
  from nnt and  step_RAG_v[OF vt_s[unfolded s_def], folded s_def]
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1089
  show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1090
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1091
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1092
lemma subtree_kept:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1093
  assumes "th1 \<noteq> th"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1094
  shows "subtree (RAG s) (Th th1) = subtree (RAG s') (Th th1)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1095
proof(unfold RAG_s, rule subset_del_subtree_outside)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1096
  show "Range {(Cs cs, Th th)} \<inter> subtree (RAG s') (Th th1) = {}"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1097
  proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1098
    have "(Th th) \<notin> subtree (RAG s') (Th th1)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1099
    proof(rule subtree_refute)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1100
      show "Th th1 \<notin> ancestors (RAG s') (Th th)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1101
          by (unfold ancestors_th, simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1102
    next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1103
      from assms show "Th th1 \<noteq> Th th" by simp
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1104
    qed
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1105
    thus ?thesis by auto
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1106
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1107
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1108
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1109
lemma cp_kept_1:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1110
  assumes "th1 \<noteq> th"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1111
  shows "cp s th1 = cp s' th1"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1112
    by (unfold cp_alt_def preced_kept subtree_kept[OF assms], simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1113
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1114
lemma subtree_cs: "subtree (RAG s') (Cs cs) = {Cs cs}"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1115
proof -
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1116
  { fix n
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1117
    have "(Cs cs) \<notin> ancestors (RAG s') n"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1118
    proof
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1119
      assume "Cs cs \<in> ancestors (RAG s') n"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1120
      hence "(n, Cs cs) \<in> (RAG s')^+" by (auto simp:ancestors_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1121
      from tranclE[OF this] obtain nn where h: "(nn, Cs cs) \<in> RAG s'" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1122
      then obtain th' where "nn = Th th'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1123
        by (unfold s_RAG_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1124
      from h[unfolded this] have "(Th th', Cs cs) \<in> RAG s'" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1125
      from this[unfolded s_RAG_def]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1126
      have "waiting (wq s') th' cs" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1127
      from this[unfolded cs_waiting_def]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1128
      have "1 < length (wq s' cs)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1129
          by (cases "wq s' cs", auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1130
      from holding_next_thI[OF holding_th this]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1131
      obtain th' where "next_th s' th cs th'" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1132
      with nnt show False by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1133
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1134
  } note h = this
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1135
  {  fix n
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1136
     assume "n \<in> subtree (RAG s') (Cs cs)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1137
     hence "n = (Cs cs)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1138
     by (elim subtreeE, insert h, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1139
  } moreover have "(Cs cs) \<in> subtree (RAG s') (Cs cs)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1140
      by (auto simp:subtree_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1141
  ultimately show ?thesis by auto 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1142
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1143
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1144
lemma subtree_th: 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1145
  "subtree (RAG s) (Th th) = subtree (RAG s') (Th th) - {Cs cs}"
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  1146
find_theorems "subtree" "_ - _" RAG
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  1147
proof(unfold RAG_s, fold subtree_cs, rule vat_s'.rtree_RAG.subtree_del_inside)
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1148
  from edge_of_th
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1149
  show "(Cs cs, Th th) \<in> edges_in (RAG s') (Th th)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1150
    by (unfold edges_in_def, auto simp:subtree_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1151
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1152
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1153
lemma cp_kept_2: 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1154
  shows "cp s th = cp s' th" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1155
 by (unfold cp_alt_def subtree_th preced_kept, auto)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1156
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1157
lemma eq_cp:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1158
  fixes th' 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1159
  shows "cp s th' = cp s' th'"
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1160
  using cp_kept_1 cp_kept_2
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1161
  by (cases "th' = th", auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1162
end
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1163
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1164
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1165
locale step_P_cps =
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1166
  fixes s' th cs s 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1167
  defines s_def : "s \<equiv> (P th cs#s')"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1168
  assumes vt_s: "vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1169
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1170
sublocale step_P_cps < vat_s : valid_trace "s"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1171
proof
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1172
  from vt_s show "vt s" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1173
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1174
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1175
sublocale step_P_cps < vat_s' : valid_trace "s'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1176
proof
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1177
  from step_back_vt[OF vt_s[unfolded s_def]] show "vt s'" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1178
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1179
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1180
context step_P_cps
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1181
begin
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1182
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1183
lemma readys_th: "th \<in> readys s'"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1184
proof -
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1185
    from step_back_step [OF vt_s[unfolded s_def]]
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1186
    have "PIP s' (P th cs)" .
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1187
    hence "th \<in> runing s'" by (cases, simp)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1188
    thus ?thesis by (simp add:readys_def runing_def)
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1189
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1190
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1191
lemma root_th: "root (RAG s') (Th th)"
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  1192
  using readys_root[OF readys_th] .
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1193
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1194
lemma in_no_others_subtree:
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1195
  assumes "th' \<noteq> th"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1196
  shows "Th th \<notin> subtree (RAG s') (Th th')"
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1197
proof
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1198
  assume "Th th \<in> subtree (RAG s') (Th th')"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1199
  thus False
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1200
  proof(cases rule:subtreeE)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1201
    case 1
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1202
    with assms show ?thesis by auto
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1203
  next
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1204
    case 2
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1205
    with root_th show ?thesis by (auto simp:root_def)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1206
  qed
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1207
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1208
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1209
lemma preced_kept: "the_preced s = the_preced s'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1210
  by (auto simp: s_def the_preced_def preced_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1211
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1212
end
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1213
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1214
locale step_P_cps_ne =step_P_cps +
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1215
  fixes th'
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1216
  assumes ne: "wq s' cs \<noteq> []"
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1217
  defines th'_def: "th' \<equiv> hd (wq s' cs)"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1218
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1219
locale step_P_cps_e =step_P_cps +
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1220
  assumes ee: "wq s' cs = []"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1221
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1222
context step_P_cps_e
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1223
begin
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1224
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
  1225
lemma RAG_s: "RAG s = RAG s' \<union> {(Cs cs, Th th)}"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1226
proof -
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
  1227
  from ee and  step_RAG_p[OF vt_s[unfolded s_def], folded s_def]
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1228
  show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1229
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1230
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1231
lemma subtree_kept:
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1232
  assumes "th' \<noteq> th"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1233
  shows "subtree (RAG s) (Th th') = subtree (RAG s') (Th th')"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1234
proof(unfold RAG_s, rule subtree_insert_next)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1235
  from in_no_others_subtree[OF assms] 
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1236
  show "Th th \<notin> subtree (RAG s') (Th th')" .
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1237
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1238
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1239
lemma cp_kept: 
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1240
  assumes "th' \<noteq> th"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1241
  shows "cp s th' = cp s' th'"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1242
proof -
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1243
  have "(the_preced s ` {th'a. Th th'a \<in> subtree (RAG s) (Th th')}) =
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1244
        (the_preced s' ` {th'a. Th th'a \<in> subtree (RAG s') (Th th')})"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1245
        by (unfold preced_kept subtree_kept[OF assms], simp)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1246
  thus ?thesis by (unfold cp_alt_def, simp)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1247
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1248
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1249
end
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1250
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1251
context step_P_cps_ne 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1252
begin
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1253
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
  1254
lemma RAG_s: "RAG s = RAG s' \<union> {(Th th, Cs cs)}"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1255
proof -
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
  1256
  from step_RAG_p[OF vt_s[unfolded s_def]] and ne
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1257
  show ?thesis by (simp add:s_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1258
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1259
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1260
lemma cs_held: "(Cs cs, Th th') \<in> RAG s'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1261
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1262
  have "(Cs cs, Th th') \<in> hRAG s'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1263
  proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1264
    from ne
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1265
    have " holding s' th' cs"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1266
      by (unfold th'_def holding_eq cs_holding_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1267
    thus ?thesis 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1268
      by (unfold hRAG_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1269
  qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1270
  thus ?thesis by (unfold RAG_split, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1271
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1272
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1273
lemma tRAG_s: 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1274
  "tRAG s = tRAG s' \<union> {(Th th, Th th')}"
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  1275
  using RAG_tRAG_transfer[OF RAG_s cs_held] .
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1276
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1277
lemma cp_kept:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1278
  assumes "Th th'' \<notin> ancestors (tRAG s) (Th th)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1279
  shows "cp s th'' = cp s' th''"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1280
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1281
  have h: "subtree (tRAG s) (Th th'') = subtree (tRAG s') (Th th'')"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1282
  proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1283
    have "Th th' \<notin> subtree (tRAG s') (Th th'')"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1284
    proof
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1285
      assume "Th th' \<in> subtree (tRAG s') (Th th'')"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1286
      thus False
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1287
      proof(rule subtreeE)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1288
         assume "Th th' = Th th''"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1289
         from assms[unfolded tRAG_s ancestors_def, folded this]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1290
         show ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1291
      next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1292
         assume "Th th'' \<in> ancestors (tRAG s') (Th th')"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1293
         moreover have "... \<subseteq> ancestors (tRAG s) (Th th')"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1294
         proof(rule ancestors_mono)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1295
            show "tRAG s' \<subseteq> tRAG s" by (unfold tRAG_s, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1296
         qed 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1297
         ultimately have "Th th'' \<in> ancestors (tRAG s) (Th th')" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1298
         moreover have "Th th' \<in> ancestors (tRAG s) (Th th)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1299
           by (unfold tRAG_s, auto simp:ancestors_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1300
         ultimately have "Th th'' \<in> ancestors (tRAG s) (Th th)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1301
                       by (auto simp:ancestors_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1302
         with assms show ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1303
      qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1304
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1305
    from subtree_insert_next[OF this]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1306
    have "subtree (tRAG s' \<union> {(Th th, Th th')}) (Th th'') = subtree (tRAG s') (Th th'')" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1307
    from this[folded tRAG_s] show ?thesis .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1308
  qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1309
  show ?thesis by (unfold cp_alt_def1 h preced_kept, simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1310
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1311
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1312
lemma cp_gen_update_stop: (* ddd *)
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1313
  assumes "u \<in> ancestors (tRAG s) (Th th)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1314
  and "cp_gen s u = cp_gen s' u"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1315
  and "y \<in> ancestors (tRAG s) u"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1316
  shows "cp_gen s y = cp_gen s' y"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1317
  using assms(3)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1318
proof(induct rule:wf_induct[OF vat_s.fsbttRAGs.wf])
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1319
  case (1 x)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1320
  show ?case (is "?L = ?R")
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1321
  proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1322
    from tRAG_ancestorsE[OF 1(2)]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1323
    obtain th2 where eq_x: "x = Th th2" by blast
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1324
    from vat_s.cp_gen_rec[OF this]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1325
    have "?L = 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1326
          Max ({the_preced s th2} \<union> cp_gen s ` RTree.children (tRAG s) x)" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1327
    also have "... = 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1328
          Max ({the_preced s' th2} \<union> cp_gen s' ` RTree.children (tRAG s') x)"
59
0a069a667301 removed some fixes about which Isabelle complains
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 58
diff changeset
  1329
  
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1330
    proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1331
      from preced_kept have "the_preced s th2 = the_preced s' th2" by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1332
      moreover have "cp_gen s ` RTree.children (tRAG s) x =
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1333
                     cp_gen s' ` RTree.children (tRAG s') x"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1334
      proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1335
        have "RTree.children (tRAG s) x =  RTree.children (tRAG s') x"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1336
        proof(unfold tRAG_s, rule children_union_kept)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1337
          have start: "(Th th, Th th') \<in> tRAG s"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1338
            by (unfold tRAG_s, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1339
          note x_u = 1(2)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1340
          show "x \<notin> Range {(Th th, Th th')}"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1341
          proof
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1342
            assume "x \<in> Range {(Th th, Th th')}"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1343
            hence eq_x: "x = Th th'" using RangeE by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1344
            show False
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1345
            proof(cases rule:vat_s.rtree_s.ancestors_headE[OF assms(1) start])
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1346
              case 1
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1347
              from x_u[folded this, unfolded eq_x] vat_s.acyclic_tRAG
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1348
              show ?thesis by (auto simp:ancestors_def acyclic_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1349
            next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1350
              case 2
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1351
              with x_u[unfolded eq_x]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1352
              have "(Th th', Th th') \<in> (tRAG s)^+" by (auto simp:ancestors_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1353
              with vat_s.acyclic_tRAG show ?thesis by (auto simp:acyclic_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1354
            qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1355
          qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1356
        qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1357
        moreover have "cp_gen s ` RTree.children (tRAG s) x =
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1358
                       cp_gen s' ` RTree.children (tRAG s) x" (is "?f ` ?A = ?g ` ?A")
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1359
        proof(rule f_image_eq)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1360
          fix a
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1361
          assume a_in: "a \<in> ?A"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1362
          from 1(2)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1363
          show "?f a = ?g a"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1364
          proof(cases rule:vat_s.rtree_s.ancestors_childrenE[case_names in_ch out_ch])
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1365
             case in_ch
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1366
             show ?thesis
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1367
             proof(cases "a = u")
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1368
                case True
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1369
                from assms(2)[folded this] show ?thesis .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1370
             next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1371
                case False
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1372
                have a_not_in: "a \<notin> ancestors (tRAG s) (Th th)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1373
                proof
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1374
                  assume a_in': "a \<in> ancestors (tRAG s) (Th th)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1375
                  have "a = u"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1376
                  proof(rule vat_s.rtree_s.ancestors_children_unique)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1377
                    from a_in' a_in show "a \<in> ancestors (tRAG s) (Th th) \<inter> 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1378
                                          RTree.children (tRAG s) x" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1379
                  next 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1380
                    from assms(1) in_ch show "u \<in> ancestors (tRAG s) (Th th) \<inter> 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1381
                                      RTree.children (tRAG s) x" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1382
                  qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1383
                  with False show False by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1384
                qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1385
                from a_in obtain th_a where eq_a: "a = Th th_a" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1386
                    by (unfold RTree.children_def tRAG_alt_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1387
                from cp_kept[OF a_not_in[unfolded eq_a]]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1388
                have "cp s th_a = cp s' th_a" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1389
                from this [unfolded cp_gen_def_cond[OF eq_a], folded eq_a]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1390
                show ?thesis .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1391
             qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1392
          next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1393
            case (out_ch z)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1394
            hence h: "z \<in> ancestors (tRAG s) u" "z \<in> RTree.children (tRAG s) x" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1395
            show ?thesis
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1396
            proof(cases "a = z")
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1397
              case True
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1398
              from h(2) have zx_in: "(z, x) \<in> (tRAG s)" by (auto simp:RTree.children_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1399
              from 1(1)[rule_format, OF this h(1)]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1400
              have eq_cp_gen: "cp_gen s z = cp_gen s' z" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1401
              with True show ?thesis by metis
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1402
            next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1403
              case False
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1404
              from a_in obtain th_a where eq_a: "a = Th th_a"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1405
                by (auto simp:RTree.children_def tRAG_alt_def)
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1406
              have "a \<notin> ancestors (tRAG s) (Th th)"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1407
              proof
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1408
                assume a_in': "a \<in> ancestors (tRAG s) (Th th)"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1409
                have "a = z"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1410
                proof(rule vat_s.rtree_s.ancestors_children_unique)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1411
                  from assms(1) h(1) have "z \<in> ancestors (tRAG s) (Th th)"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1412
                      by (auto simp:ancestors_def)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1413
                  with h(2) show " z \<in> ancestors (tRAG s) (Th th) \<inter> 
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1414
                                       RTree.children (tRAG s) x" by auto
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1415
                next
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1416
                  from a_in a_in'
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1417
                  show "a \<in> ancestors (tRAG s) (Th th) \<inter> RTree.children (tRAG s) x"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1418
                    by auto
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1419
                qed
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1420
                with False show False by auto
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1421
              qed
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1422
              from cp_kept[OF this[unfolded eq_a]]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1423
              have "cp s th_a = cp s' th_a" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1424
              from this[unfolded cp_gen_def_cond[OF eq_a], folded eq_a]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1425
              show ?thesis .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1426
            qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1427
          qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1428
        qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1429
        ultimately show ?thesis by metis
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1430
      qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1431
      ultimately show ?thesis by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1432
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1433
    also have "... = ?R"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1434
      by (fold vat_s'.cp_gen_rec[OF eq_x], simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1435
    finally show ?thesis .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1436
  qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1437
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 56
diff changeset
  1438
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1439
lemma cp_up:
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1440
  assumes "(Th th') \<in> ancestors (tRAG s) (Th th)"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1441
  and "cp s th' = cp s' th'"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1442
  and "(Th th'') \<in> ancestors (tRAG s) (Th th')"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1443
  shows "cp s th'' = cp s' th''"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1444
proof -
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1445
  have "cp_gen s (Th th'') = cp_gen s' (Th th'')"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1446
  proof(rule cp_gen_update_stop[OF assms(1) _ assms(3)])
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1447
    from assms(2) cp_gen_def_cond[OF refl[of "Th th'"]]
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1448
    show "cp_gen s (Th th') = cp_gen s' (Th th')" by metis
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1449
  qed
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1450
  with cp_gen_def_cond[OF refl[of "Th th''"]]
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1451
  show ?thesis by metis
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1452
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1453
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1454
end
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1455
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1456
locale step_create_cps =
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1457
  fixes s' th prio s 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1458
  defines s_def : "s \<equiv> (Create th prio#s')"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1459
  assumes vt_s: "vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1460
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1461
sublocale step_create_cps < vat_s: valid_trace "s"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1462
  by (unfold_locales, insert vt_s, simp)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1463
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1464
sublocale step_create_cps < vat_s': valid_trace "s'"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1465
  by (unfold_locales, insert step_back_vt[OF vt_s[unfolded s_def]], simp)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1466
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1467
context step_create_cps
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1468
begin
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1469
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1470
lemma RAG_kept: "RAG s = RAG s'"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
  1471
  by (unfold s_def RAG_create_unchanged, auto)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1472
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1473
lemma tRAG_kept: "tRAG s = tRAG s'"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1474
  by (unfold tRAG_alt_def RAG_kept, auto)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1475
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1476
lemma preced_kept:
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1477
  assumes "th' \<noteq> th"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1478
  shows "the_preced s th' = the_preced s' th'"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1479
  by (unfold s_def the_preced_def preced_def, insert assms, auto)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1480
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1481
lemma th_not_in: "Th th \<notin> Field (tRAG s')"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1482
proof -
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1483
  from vt_s[unfolded s_def]
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1484
  have "PIP s' (Create th prio)" by (cases, simp)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1485
  hence "th \<notin> threads s'" by(cases, simp)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1486
  from vat_s'.not_in_thread_isolated[OF this]
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1487
  have "Th th \<notin> Field (RAG s')" .
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1488
  with tRAG_Field show ?thesis by auto
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1489
qed
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1490
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1491
lemma eq_cp:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1492
  assumes neq_th: "th' \<noteq> th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1493
  shows "cp s th' = cp s' th'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1494
proof -
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1495
  have "(the_preced s \<circ> the_thread) ` subtree (tRAG s) (Th th') =
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1496
        (the_preced s' \<circ> the_thread) ` subtree (tRAG s') (Th th')"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1497
  proof(unfold tRAG_kept, rule f_image_eq)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1498
    fix a
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1499
    assume a_in: "a \<in> subtree (tRAG s') (Th th')"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1500
    then obtain th_a where eq_a: "a = Th th_a" 
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1501
    proof(cases rule:subtreeE)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1502
      case 2
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1503
      from ancestors_Field[OF 2(2)]
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1504
      and that show ?thesis by (unfold tRAG_alt_def, auto)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1505
    qed auto
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1506
    have neq_th_a: "th_a \<noteq> th"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1507
    proof -
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1508
      have "(Th th) \<notin> subtree (tRAG s') (Th th')"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1509
      proof
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1510
        assume "Th th \<in> subtree (tRAG s') (Th th')"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1511
        thus False
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1512
        proof(cases rule:subtreeE)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1513
          case 2
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1514
          from ancestors_Field[OF this(2)]
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1515
          and th_not_in[unfolded Field_def]
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1516
          show ?thesis by auto
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1517
        qed (insert assms, auto)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1518
      qed
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1519
      with a_in[unfolded eq_a] show ?thesis by auto
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1520
    qed
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1521
    from preced_kept[OF this]
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1522
    show "(the_preced s \<circ> the_thread) a = (the_preced s' \<circ> the_thread) a"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1523
      by (unfold eq_a, simp)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1524
  qed
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1525
  thus ?thesis by (unfold cp_alt_def1, simp)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1526
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1527
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1528
lemma children_of_th: "RTree.children (tRAG s) (Th th) = {}"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1529
proof -
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1530
  { fix a
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1531
    assume "a \<in> RTree.children (tRAG s) (Th th)"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1532
    hence "(a, Th th) \<in> tRAG s" by (auto simp:RTree.children_def)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1533
    with th_not_in have False 
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1534
     by (unfold Field_def tRAG_kept, auto)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1535
  } thus ?thesis by auto
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1536
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1537
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1538
lemma eq_cp_th: "cp s th = preced th s"
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1539
 by (unfold vat_s.cp_rec children_of_th, simp add:the_preced_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1540
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1541
end
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1542
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1543
locale step_exit_cps =
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1544
  fixes s' th prio s 
33
9b9f2117561f simplified the cp_rec proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1545
  defines s_def : "s \<equiv> Exit th # s'"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1546
  assumes vt_s: "vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1547
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1548
sublocale step_exit_cps < vat_s: valid_trace "s"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1549
  by (unfold_locales, insert vt_s, simp)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1550
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1551
sublocale step_exit_cps < vat_s': valid_trace "s'"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1552
  by (unfold_locales, insert step_back_vt[OF vt_s[unfolded s_def]], simp)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1553
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1554
context step_exit_cps
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1555
begin
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1556
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1557
lemma preced_kept:
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1558
  assumes "th' \<noteq> th"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1559
  shows "the_preced s th' = the_preced s' th'"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1560
  by (unfold s_def the_preced_def preced_def, insert assms, auto)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1561
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1562
lemma RAG_kept: "RAG s = RAG s'"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
  1563
  by (unfold s_def RAG_exit_unchanged, auto)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1564
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1565
lemma tRAG_kept: "tRAG s = tRAG s'"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1566
  by (unfold tRAG_alt_def RAG_kept, auto)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1567
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1568
lemma th_ready: "th \<in> readys s'"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1569
proof -
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1570
  from vt_s[unfolded s_def]
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1571
  have "PIP s' (Exit th)" by (cases, simp)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1572
  hence h: "th \<in> runing s' \<and> holdents s' th = {}" by (cases, metis)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1573
  thus ?thesis by (unfold runing_def, auto)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1574
qed
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1575
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1576
lemma th_holdents: "holdents s' th = {}"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1577
proof -
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1578
 from vt_s[unfolded s_def]
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1579
  have "PIP s' (Exit th)" by (cases, simp)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1580
  thus ?thesis by (cases, metis)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1581
qed
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1582
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1583
lemma th_RAG: "Th th \<notin> Field (RAG s')"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1584
proof -
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1585
  have "Th th \<notin> Range (RAG s')"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1586
  proof
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1587
    assume "Th th \<in> Range (RAG s')"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1588
    then obtain cs where "holding (wq s') th cs"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1589
      by (unfold Range_iff s_RAG_def, auto)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1590
    with th_holdents[unfolded holdents_def]
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1591
    show False by (unfold eq_holding, auto)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1592
  qed
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1593
  moreover have "Th th \<notin> Domain (RAG s')"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1594
  proof
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1595
    assume "Th th \<in> Domain (RAG s')"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1596
    then obtain cs where "waiting (wq s') th cs"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1597
      by (unfold Domain_iff s_RAG_def, auto)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1598
    with th_ready show False by (unfold readys_def eq_waiting, auto)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1599
  qed
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1600
  ultimately show ?thesis by (auto simp:Field_def)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1601
qed
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1602
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1603
lemma th_tRAG: "(Th th) \<notin> Field (tRAG s')"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1604
  using th_RAG tRAG_Field[of s'] by auto
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1605
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1606
lemma eq_cp:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1607
  assumes neq_th: "th' \<noteq> th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1608
  shows "cp s th' = cp s' th'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1609
proof -
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1610
  have "(the_preced s \<circ> the_thread) ` subtree (tRAG s) (Th th') =
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1611
        (the_preced s' \<circ> the_thread) ` subtree (tRAG s') (Th th')"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1612
  proof(unfold tRAG_kept, rule f_image_eq)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1613
    fix a
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1614
    assume a_in: "a \<in> subtree (tRAG s') (Th th')"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1615
    then obtain th_a where eq_a: "a = Th th_a" 
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1616
    proof(cases rule:subtreeE)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1617
      case 2
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1618
      from ancestors_Field[OF 2(2)]
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1619
      and that show ?thesis by (unfold tRAG_alt_def, auto)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1620
    qed auto
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1621
    have neq_th_a: "th_a \<noteq> th"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1622
    proof -
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  1623
    find_theorems readys subtree s'
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  1624
      from vat_s'.readys_in_no_subtree[OF th_ready assms]
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1625
      have "(Th th) \<notin> subtree (RAG s') (Th th')" .
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1626
      with tRAG_subtree_RAG[of s' "Th th'"]
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1627
      have "(Th th) \<notin> subtree (tRAG s') (Th th')" by auto
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1628
      with a_in[unfolded eq_a] show ?thesis by auto
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1629
    qed
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1630
    from preced_kept[OF this]
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1631
    show "(the_preced s \<circ> the_thread) a = (the_preced s' \<circ> the_thread) a"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1632
      by (unfold eq_a, simp)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1633
  qed
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1634
  thus ?thesis by (unfold cp_alt_def1, simp)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1635
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1636
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1637
end
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  1638
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1639
end
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1640