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