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