PrioG.thy~
author zhangx
Fri, 18 Dec 2015 22:47:32 +0800
changeset 61 f8194fd6214f
parent 58 ad57323fd4d6
child 62 031d2ae9c9b8
permissions -rw-r--r--
CpsG.thy has been cleaned up. The next step is to add more comments and make slight changes along the way.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
     1
theory PrioG
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
     2
imports PrioGDef 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
     3
begin
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
     4
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
     5
lemma runing_ready: 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
     6
  shows "runing s \<subseteq> readys s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
     7
  unfolding runing_def readys_def
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
     8
  by auto 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
     9
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    10
lemma readys_threads:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    11
  shows "readys s \<subseteq> threads s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    12
  unfolding readys_def
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    13
  by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    14
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    15
lemma wq_v_neq:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    16
   "cs \<noteq> cs' \<Longrightarrow> wq (V thread cs#s) cs' = wq s cs'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    17
  by (auto simp:wq_def Let_def cp_def split:list.splits)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    18
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    19
lemma wq_distinct: "vt s \<Longrightarrow> distinct (wq s cs)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    20
proof(erule_tac vt.induct, simp add:wq_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    21
  fix s e
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    22
  assume h1: "step s e"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    23
  and h2: "distinct (wq s cs)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    24
  thus "distinct (wq (e # s) cs)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    25
  proof(induct rule:step.induct, auto simp: wq_def Let_def split:list.splits)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    26
    fix thread s
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    27
    assume h1: "(Cs cs, Th thread) \<notin> (RAG s)\<^sup>+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    28
      and h2: "thread \<in> set (wq_fun (schs s) cs)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    29
      and h3: "thread \<in> runing s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    30
    show "False" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    31
    proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    32
      from h3 have "\<And> cs. thread \<in>  set (wq_fun (schs s) cs) \<Longrightarrow> 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    33
                             thread = hd ((wq_fun (schs s) cs))" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    34
        by (simp add:runing_def readys_def s_waiting_def wq_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    35
      from this [OF h2] have "thread = hd (wq_fun (schs s) cs)" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    36
      with h2
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    37
      have "(Cs cs, Th thread) \<in> (RAG s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    38
        by (simp add:s_RAG_def s_holding_def wq_def cs_holding_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    39
      with h1 show False by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    40
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    41
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    42
    fix thread s a list
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    43
    assume dst: "distinct list"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    44
    show "distinct (SOME q. distinct q \<and> set q = set list)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    45
    proof(rule someI2)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    46
      from dst show  "distinct list \<and> set list = set list" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    47
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    48
      fix q assume "distinct q \<and> set q = set list"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    49
      thus "distinct q" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    50
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    51
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    52
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    53
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    54
text {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    55
  The following lemma shows that only the @{text "P"}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    56
  operation can add new thread into waiting queues. 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    57
  Such kind of lemmas are very obvious, but need to be checked formally.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    58
  This is a kind of confirmation that our modelling is correct.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    59
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    60
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    61
lemma block_pre: 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    62
  fixes thread cs s
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    63
  assumes vt_e: "vt (e#s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    64
  and s_ni: "thread \<notin>  set (wq s cs)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    65
  and s_i: "thread \<in> set (wq (e#s) cs)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    66
  shows "e = P thread cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    67
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    68
  show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    69
  proof(cases e)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    70
    case (P th cs)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    71
    with assms
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    72
    show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    73
      by (auto simp:wq_def Let_def split:if_splits)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    74
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    75
    case (Create th prio)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    76
    with assms show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    77
      by (auto simp:wq_def Let_def split:if_splits)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    78
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    79
    case (Exit th)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    80
    with assms show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    81
      by (auto simp:wq_def Let_def split:if_splits)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    82
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    83
    case (Set th prio)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    84
    with assms show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    85
      by (auto simp:wq_def Let_def split:if_splits)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    86
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    87
    case (V th cs)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    88
    with assms show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    89
      apply (auto simp:wq_def Let_def split:if_splits)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    90
    proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    91
      fix q qs
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    92
      assume h1: "thread \<notin> set (wq_fun (schs s) cs)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    93
        and h2: "q # qs = wq_fun (schs s) cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    94
        and h3: "thread \<in> set (SOME q. distinct q \<and> set q = set qs)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    95
        and vt: "vt (V th cs # s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    96
      from h1 and h2[symmetric] have "thread \<notin> set (q # qs)" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    97
      moreover have "thread \<in> set qs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    98
      proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    99
        have "set (SOME q. distinct q \<and> set q = set qs) = set qs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   100
        proof(rule someI2)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   101
          from wq_distinct [OF step_back_vt[OF vt], of cs]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   102
          and h2[symmetric, folded wq_def]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   103
          show "distinct qs \<and> set qs = set qs" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   104
        next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   105
          fix x assume "distinct x \<and> set x = set qs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   106
          thus "set x = set qs" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   107
        qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   108
        with h3 show ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   109
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   110
      ultimately show "False" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   111
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   112
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   113
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   114
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   115
text {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   116
  The following lemmas is also obvious and shallow. It says
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   117
  that only running thread can request for a critical resource 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   118
  and that the requested resource must be one which is
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   119
  not current held by the thread.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   120
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   121
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   122
lemma p_pre: "\<lbrakk>vt ((P thread cs)#s)\<rbrakk> \<Longrightarrow> 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   123
  thread \<in> runing s \<and> (Cs cs, Th thread)  \<notin> (RAG s)^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   124
apply (ind_cases "vt ((P thread cs)#s)")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   125
apply (ind_cases "step s (P thread cs)")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   126
by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   127
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   128
lemma abs1:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   129
  fixes e es
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   130
  assumes ein: "e \<in> set es"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   131
  and neq: "hd es \<noteq> hd (es @ [x])"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   132
  shows "False"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   133
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   134
  from ein have "es \<noteq> []" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   135
  then obtain e ess where "es = e # ess" by (cases es, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   136
  with neq show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   137
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   138
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   139
lemma q_head: "Q (hd es) \<Longrightarrow> hd es = hd [th\<leftarrow>es . Q th]"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   140
  by (cases es, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   141
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   142
inductive_cases evt_cons: "vt (a#s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   143
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   144
lemma abs2:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   145
  assumes vt: "vt (e#s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   146
  and inq: "thread \<in> set (wq s cs)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   147
  and nh: "thread = hd (wq s cs)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   148
  and qt: "thread \<noteq> hd (wq (e#s) cs)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   149
  and inq': "thread \<in> set (wq (e#s) cs)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   150
  shows "False"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   151
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   152
  from assms show "False"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   153
    apply (cases e)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   154
    apply ((simp split:if_splits add:Let_def wq_def)[1])+
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   155
    apply (insert abs1, fast)[1]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   156
    apply (auto simp:wq_def simp:Let_def split:if_splits list.splits)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   157
  proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   158
    fix th qs
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   159
    assume vt: "vt (V th cs # s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   160
      and th_in: "thread \<in> set (SOME q. distinct q \<and> set q = set qs)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   161
      and eq_wq: "wq_fun (schs s) cs = thread # qs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   162
    show "False"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   163
    proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   164
      from wq_distinct[OF step_back_vt[OF vt], of cs]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   165
        and eq_wq[folded wq_def] have "distinct (thread#qs)" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   166
      moreover have "thread \<in> set qs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   167
      proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   168
        have "set (SOME q. distinct q \<and> set q = set qs) = set qs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   169
        proof(rule someI2)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   170
          from wq_distinct [OF step_back_vt[OF vt], of cs]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   171
          and eq_wq [folded wq_def]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   172
          show "distinct qs \<and> set qs = set qs" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   173
        next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   174
          fix x assume "distinct x \<and> set x = set qs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   175
          thus "set x = set qs" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   176
        qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   177
        with th_in show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   178
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   179
      ultimately show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   180
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   181
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   182
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   183
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   184
lemma vt_moment: "\<And> t. \<lbrakk>vt s\<rbrakk> \<Longrightarrow> vt (moment t s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   185
proof(induct s, simp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   186
  fix a s t
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   187
  assume h: "\<And>t.\<lbrakk>vt s\<rbrakk> \<Longrightarrow> vt (moment t s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   188
    and vt_a: "vt (a # s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   189
  show "vt (moment t (a # s))"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   190
  proof(cases "t \<ge> length (a#s)")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   191
    case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   192
    from True have "moment t (a#s) = a#s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   193
    with vt_a show ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   194
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   195
    case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   196
    hence le_t1: "t \<le> length s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   197
    from vt_a have "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   198
      by (erule_tac evt_cons, simp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   199
    from h [OF this] have "vt (moment t s)" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   200
    moreover have "moment t (a#s) = moment t s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   201
    proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   202
      from moment_app [OF le_t1, of "[a]"] 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   203
      show ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   204
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   205
    ultimately show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   206
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   207
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   208
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   209
(* Wrong:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   210
    lemma \<lbrakk>thread \<in> set (wq_fun cs1 s); thread \<in> set (wq_fun cs2 s)\<rbrakk> \<Longrightarrow> cs1 = cs2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   211
*)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   212
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   213
text {* (* ddd *)
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   214
  The nature of the work is like this: since it starts from a very simple and basic 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   215
  model, even intuitively very `basic` and `obvious` properties need to derived from scratch.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   216
  For instance, the fact 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   217
  that one thread can not be blocked by two critical resources at the same time
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   218
  is obvious, because only running threads can make new requests, if one is waiting for 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   219
  a critical resource and get blocked, it can not make another resource request and get 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   220
  blocked the second time (because it is not running). 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   221
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   222
  To derive this fact, one needs to prove by contraction and 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   223
  reason about time (or @{text "moement"}). The reasoning is based on a generic theorem
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   224
  named @{text "p_split"}, which is about status changing along the time axis. It says if 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   225
  a condition @{text "Q"} is @{text "True"} at a state @{text "s"},
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   226
  but it was @{text "False"} at the very beginning, then there must exits a moment @{text "t"} 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   227
  in the history of @{text "s"} (notice that @{text "s"} itself is essentially the history 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   228
  of events leading to it), such that @{text "Q"} switched 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   229
  from being @{text "False"} to @{text "True"} and kept being @{text "True"}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   230
  till the last moment of @{text "s"}.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   231
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   232
  Suppose a thread @{text "th"} is blocked
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   233
  on @{text "cs1"} and @{text "cs2"} in some state @{text "s"}, 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   234
  since no thread is blocked at the very beginning, by applying 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   235
  @{text "p_split"} to these two blocking facts, there exist 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   236
  two moments @{text "t1"} and @{text "t2"}  in @{text "s"}, such that 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   237
  @{text "th"} got blocked on @{text "cs1"} and @{text "cs2"} 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   238
  and kept on blocked on them respectively ever since.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   239
 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   240
  Without lose of generality, we assume @{text "t1"} is earlier than @{text "t2"}.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   241
  However, since @{text "th"} was blocked ever since memonent @{text "t1"}, so it was still
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   242
  in blocked state at moment @{text "t2"} and could not
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   243
  make any request and get blocked the second time: Contradiction.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   244
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   245
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   246
lemma waiting_unique_pre:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   247
  fixes cs1 cs2 s thread
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   248
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   249
  and h11: "thread \<in> set (wq s cs1)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   250
  and h12: "thread \<noteq> hd (wq s cs1)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   251
  assumes h21: "thread \<in> set (wq s cs2)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   252
  and h22: "thread \<noteq> hd (wq s cs2)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   253
  and neq12: "cs1 \<noteq> cs2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   254
  shows "False"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   255
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   256
  let "?Q cs s" = "thread \<in> set (wq s cs) \<and> thread \<noteq> hd (wq s cs)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   257
  from h11 and h12 have q1: "?Q cs1 s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   258
  from h21 and h22 have q2: "?Q cs2 s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   259
  have nq1: "\<not> ?Q cs1 []" by (simp add:wq_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   260
  have nq2: "\<not> ?Q cs2 []" by (simp add:wq_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   261
  from p_split [of "?Q cs1", OF q1 nq1]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   262
  obtain t1 where lt1: "t1 < length s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   263
    and np1: "\<not>(thread \<in> set (wq (moment t1 s) cs1) \<and>
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   264
        thread \<noteq> hd (wq (moment t1 s) cs1))"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   265
    and nn1: "(\<forall>i'>t1. thread \<in> set (wq (moment i' s) cs1) \<and>
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   266
             thread \<noteq> hd (wq (moment i' s) cs1))" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   267
  from p_split [of "?Q cs2", OF q2 nq2]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   268
  obtain t2 where lt2: "t2 < length s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   269
    and np2: "\<not>(thread \<in> set (wq (moment t2 s) cs2) \<and>
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   270
        thread \<noteq> hd (wq (moment t2 s) cs2))"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   271
    and nn2: "(\<forall>i'>t2. thread \<in> set (wq (moment i' s) cs2) \<and>
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   272
             thread \<noteq> hd (wq (moment i' s) cs2))" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   273
  show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   274
  proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   275
    { 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   276
      assume lt12: "t1 < t2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   277
      let ?t3 = "Suc t2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   278
      from lt2 have le_t3: "?t3 \<le> length s" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   279
      from moment_plus [OF this] 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   280
      obtain e where eq_m: "moment ?t3 s = e#moment t2 s" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   281
      have "t2 < ?t3" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   282
      from nn2 [rule_format, OF this] and eq_m
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   283
      have h1: "thread \<in> set (wq (e#moment t2 s) cs2)" and
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   284
        h2: "thread \<noteq> hd (wq (e#moment t2 s) cs2)" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   285
      have vt_e: "vt (e#moment t2 s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   286
      proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   287
        from vt_moment [OF vt]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   288
        have "vt (moment ?t3 s)" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   289
        with eq_m show ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   290
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   291
      have ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   292
      proof(cases "thread \<in> set (wq (moment t2 s) cs2)")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   293
        case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   294
        from True and np2 have eq_th: "thread = hd (wq (moment t2 s) cs2)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   295
          by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   296
          thm abs2
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   297
        from abs2 [OF vt_e True eq_th h2 h1]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   298
        show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   299
      next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   300
        case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   301
        from block_pre [OF vt_e False h1]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   302
        have "e = P thread cs2" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   303
        with vt_e have "vt ((P thread cs2)# moment t2 s)" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   304
        from p_pre [OF this] have "thread \<in> runing (moment t2 s)" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   305
        with runing_ready have "thread \<in> readys (moment t2 s)" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   306
        with nn1 [rule_format, OF lt12]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   307
        show ?thesis  by (simp add:readys_def wq_def s_waiting_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   308
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   309
    } moreover {
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   310
      assume lt12: "t2 < t1"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   311
      let ?t3 = "Suc t1"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   312
      from lt1 have le_t3: "?t3 \<le> length s" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   313
      from moment_plus [OF this] 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   314
      obtain e where eq_m: "moment ?t3 s = e#moment t1 s" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   315
      have lt_t3: "t1 < ?t3" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   316
      from nn1 [rule_format, OF this] and eq_m
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   317
      have h1: "thread \<in> set (wq (e#moment t1 s) cs1)" and
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   318
        h2: "thread \<noteq> hd (wq (e#moment t1 s) cs1)" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   319
      have vt_e: "vt  (e#moment t1 s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   320
      proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   321
        from vt_moment [OF vt]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   322
        have "vt (moment ?t3 s)" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   323
        with eq_m show ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   324
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   325
      have ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   326
      proof(cases "thread \<in> set (wq (moment t1 s) cs1)")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   327
        case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   328
        from True and np1 have eq_th: "thread = hd (wq (moment t1 s) cs1)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   329
          by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   330
        from abs2 [OF vt_e True eq_th h2 h1]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   331
        show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   332
      next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   333
        case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   334
        from block_pre [OF vt_e False h1]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   335
        have "e = P thread cs1" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   336
        with vt_e have "vt ((P thread cs1)# moment t1 s)" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   337
        from p_pre [OF this] have "thread \<in> runing (moment t1 s)" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   338
        with runing_ready have "thread \<in> readys (moment t1 s)" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   339
        with nn2 [rule_format, OF lt12]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   340
        show ?thesis  by (simp add:readys_def wq_def s_waiting_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   341
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   342
    } moreover {
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   343
      assume eqt12: "t1 = t2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   344
      let ?t3 = "Suc t1"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   345
      from lt1 have le_t3: "?t3 \<le> length s" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   346
      from moment_plus [OF this] 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   347
      obtain e where eq_m: "moment ?t3 s = e#moment t1 s" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   348
      have lt_t3: "t1 < ?t3" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   349
      from nn1 [rule_format, OF this] and eq_m
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   350
      have h1: "thread \<in> set (wq (e#moment t1 s) cs1)" and
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   351
        h2: "thread \<noteq> hd (wq (e#moment t1 s) cs1)" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   352
      have vt_e: "vt (e#moment t1 s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   353
      proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   354
        from vt_moment [OF vt]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   355
        have "vt (moment ?t3 s)" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   356
        with eq_m show ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   357
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   358
      have ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   359
      proof(cases "thread \<in> set (wq (moment t1 s) cs1)")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   360
        case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   361
        from True and np1 have eq_th: "thread = hd (wq (moment t1 s) cs1)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   362
          by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   363
        from abs2 [OF vt_e True eq_th h2 h1]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   364
        show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   365
      next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   366
        case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   367
        from block_pre [OF vt_e False h1]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   368
        have eq_e1: "e = P thread cs1" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   369
        have lt_t3: "t1 < ?t3" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   370
        with eqt12 have "t2 < ?t3" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   371
        from nn2 [rule_format, OF this] and eq_m and eqt12
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   372
        have h1: "thread \<in> set (wq (e#moment t2 s) cs2)" and
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   373
          h2: "thread \<noteq> hd (wq (e#moment t2 s) cs2)" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   374
        show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   375
        proof(cases "thread \<in> set (wq (moment t2 s) cs2)")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   376
          case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   377
          from True and np2 have eq_th: "thread = hd (wq (moment t2 s) cs2)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   378
            by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   379
          from vt_e and eqt12 have "vt (e#moment t2 s)" by simp 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   380
          from abs2 [OF this True eq_th h2 h1]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   381
          show ?thesis .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   382
        next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   383
          case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   384
          have vt_e: "vt (e#moment t2 s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   385
          proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   386
            from vt_moment [OF vt] eqt12
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   387
            have "vt (moment (Suc t2) s)" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   388
            with eq_m eqt12 show ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   389
          qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   390
          from block_pre [OF vt_e False h1]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   391
          have "e = P thread cs2" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   392
          with eq_e1 neq12 show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   393
        qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   394
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   395
    } ultimately show ?thesis by arith
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   396
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   397
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   398
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   399
text {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   400
  This lemma is a simple corrolary of @{text "waiting_unique_pre"}.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   401
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   402
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   403
lemma waiting_unique:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   404
  fixes s cs1 cs2
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   405
  assumes "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   406
  and "waiting s th cs1"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   407
  and "waiting s th cs2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   408
  shows "cs1 = cs2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   409
using waiting_unique_pre assms
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   410
unfolding wq_def s_waiting_def
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   411
by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   412
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   413
(* not used *)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   414
text {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   415
  Every thread can only be blocked on one critical resource, 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   416
  symmetrically, every critical resource can only be held by one thread. 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   417
  This fact is much more easier according to our definition. 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   418
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   419
lemma held_unique:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   420
  fixes s::"state"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   421
  assumes "holding s th1 cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   422
  and "holding s th2 cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   423
  shows "th1 = th2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   424
using assms
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   425
unfolding s_holding_def
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   426
by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   427
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   428
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   429
lemma last_set_lt: "th \<in> threads s \<Longrightarrow> last_set th s < length s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   430
  apply (induct s, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   431
  by (case_tac a, auto split:if_splits)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   432
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   433
lemma last_set_unique: 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   434
  "\<lbrakk>last_set th1 s = last_set th2 s; th1 \<in> threads s; th2 \<in> threads s\<rbrakk>
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   435
          \<Longrightarrow> th1 = th2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   436
  apply (induct s, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   437
  by (case_tac a, auto split:if_splits dest:last_set_lt)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   438
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   439
lemma preced_unique : 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   440
  assumes pcd_eq: "preced th1 s = preced th2 s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   441
  and th_in1: "th1 \<in> threads s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   442
  and th_in2: " th2 \<in> threads s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   443
  shows "th1 = th2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   444
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   445
  from pcd_eq have "last_set th1 s = last_set th2 s" by (simp add:preced_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   446
  from last_set_unique [OF this th_in1 th_in2]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   447
  show ?thesis .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   448
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   449
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   450
lemma preced_linorder: 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   451
  assumes neq_12: "th1 \<noteq> th2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   452
  and th_in1: "th1 \<in> threads s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   453
  and th_in2: " th2 \<in> threads s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   454
  shows "preced th1 s < preced th2 s \<or> preced th1 s > preced th2 s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   455
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   456
  from preced_unique [OF _ th_in1 th_in2] and neq_12 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   457
  have "preced th1 s \<noteq> preced th2 s" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   458
  thus ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   459
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   460
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   461
(* An aux lemma used later *)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   462
lemma unique_minus:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   463
  fixes x y z r
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   464
  assumes unique: "\<And> a b c. \<lbrakk>(a, b) \<in> r; (a, c) \<in> r\<rbrakk> \<Longrightarrow> b = c"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   465
  and xy: "(x, y) \<in> r"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   466
  and xz: "(x, z) \<in> r^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   467
  and neq: "y \<noteq> z"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   468
  shows "(y, z) \<in> r^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   469
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   470
 from xz and neq show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   471
 proof(induct)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   472
   case (base ya)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   473
   have "(x, ya) \<in> r" by fact
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   474
   from unique [OF xy this] have "y = ya" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   475
   with base show ?case by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   476
 next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   477
   case (step ya z)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   478
   show ?case
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   479
   proof(cases "y = ya")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   480
     case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   481
     from step True show ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   482
   next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   483
     case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   484
     from step False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   485
     show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   486
   qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   487
 qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   488
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   489
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   490
lemma unique_base:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   491
  fixes r x y z
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   492
  assumes unique: "\<And> a b c. \<lbrakk>(a, b) \<in> r; (a, c) \<in> r\<rbrakk> \<Longrightarrow> b = c"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   493
  and xy: "(x, y) \<in> r"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   494
  and xz: "(x, z) \<in> r^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   495
  and neq_yz: "y \<noteq> z"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   496
  shows "(y, z) \<in> r^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   497
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   498
  from xz neq_yz show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   499
  proof(induct)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   500
    case (base ya)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   501
    from xy unique base show ?case by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   502
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   503
    case (step ya z)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   504
    show ?case
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   505
    proof(cases "y = ya")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   506
      case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   507
      from True step show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   508
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   509
      case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   510
      from False step 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   511
      have "(y, ya) \<in> r\<^sup>+" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   512
      with step show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   513
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   514
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   515
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   516
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   517
lemma unique_chain:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   518
  fixes r x y z
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   519
  assumes unique: "\<And> a b c. \<lbrakk>(a, b) \<in> r; (a, c) \<in> r\<rbrakk> \<Longrightarrow> b = c"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   520
  and xy: "(x, y) \<in> r^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   521
  and xz: "(x, z) \<in> r^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   522
  and neq_yz: "y \<noteq> z"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   523
  shows "(y, z) \<in> r^+ \<or> (z, y) \<in> r^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   524
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   525
  from xy xz neq_yz show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   526
  proof(induct)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   527
    case (base y)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   528
    have h1: "(x, y) \<in> r" and h2: "(x, z) \<in> r\<^sup>+" and h3: "y \<noteq> z" using base by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   529
    from unique_base [OF _ h1 h2 h3] and unique show ?case by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   530
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   531
    case (step y za)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   532
    show ?case
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   533
    proof(cases "y = z")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   534
      case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   535
      from True step show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   536
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   537
      case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   538
      from False step have "(y, z) \<in> r\<^sup>+ \<or> (z, y) \<in> r\<^sup>+" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   539
      thus ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   540
      proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   541
        assume "(z, y) \<in> r\<^sup>+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   542
        with step have "(z, za) \<in> r\<^sup>+" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   543
        thus ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   544
      next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   545
        assume h: "(y, z) \<in> r\<^sup>+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   546
        from step have yza: "(y, za) \<in> r" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   547
        from step have "za \<noteq> z" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   548
        from unique_minus [OF _ yza h this] and unique
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   549
        have "(za, z) \<in> r\<^sup>+" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   550
        thus ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   551
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   552
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   553
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   554
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   555
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   556
text {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   557
  The following three lemmas show that @{text "RAG"} does not change
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   558
  by the happening of @{text "Set"}, @{text "Create"} and @{text "Exit"}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   559
  events, respectively.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   560
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   561
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   562
lemma RAG_set_unchanged: "(RAG (Set th prio # s)) = RAG s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   563
apply (unfold s_RAG_def s_waiting_def wq_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   564
by (simp add:Let_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   565
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   566
lemma RAG_create_unchanged: "(RAG (Create th prio # s)) = RAG s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   567
apply (unfold s_RAG_def s_waiting_def wq_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   568
by (simp add:Let_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   569
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   570
lemma RAG_exit_unchanged: "(RAG (Exit th # s)) = RAG s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   571
apply (unfold s_RAG_def s_waiting_def wq_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   572
by (simp add:Let_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   573
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   574
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   575
text {* 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   576
  The following lemmas are used in the proof of 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   577
  lemma @{text "step_RAG_v"}, which characterizes how the @{text "RAG"} is changed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   578
  by @{text "V"}-events. 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   579
  However, since our model is very concise, such  seemingly obvious lemmas need to be derived from scratch,
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   580
  starting from the model definitions.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   581
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   582
lemma step_v_hold_inv[elim_format]:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   583
  "\<And>c t. \<lbrakk>vt (V th cs # s); 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   584
          \<not> holding (wq s) t c; holding (wq (V th cs # s)) t c\<rbrakk> \<Longrightarrow> 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   585
            next_th s th cs t \<and> c = cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   586
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   587
  fix c t
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   588
  assume vt: "vt (V th cs # s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   589
    and nhd: "\<not> holding (wq s) t c"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   590
    and hd: "holding (wq (V th cs # s)) t c"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   591
  show "next_th s th cs t \<and> c = cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   592
  proof(cases "c = cs")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   593
    case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   594
    with nhd hd show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   595
      by (unfold cs_holding_def wq_def, auto simp:Let_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   596
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   597
    case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   598
    with step_back_step [OF vt] 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   599
    have "step s (V th c)" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   600
    hence "next_th s th cs t"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   601
    proof(cases)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   602
      assume "holding s th c"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   603
      with nhd hd show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   604
        apply (unfold s_holding_def cs_holding_def wq_def next_th_def,
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   605
               auto simp:Let_def split:list.splits if_splits)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   606
        proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   607
          assume " hd (SOME q. distinct q \<and> q = []) \<in> set (SOME q. distinct q \<and> q = [])"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   608
          moreover have "\<dots> = set []"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   609
          proof(rule someI2)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   610
            show "distinct [] \<and> [] = []" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   611
          next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   612
            fix x assume "distinct x \<and> x = []"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   613
            thus "set x = set []" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   614
          qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   615
          ultimately show False by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   616
        next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   617
          assume " hd (SOME q. distinct q \<and> q = []) \<in> set (SOME q. distinct q \<and> q = [])"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   618
          moreover have "\<dots> = set []"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   619
          proof(rule someI2)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   620
            show "distinct [] \<and> [] = []" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   621
          next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   622
            fix x assume "distinct x \<and> x = []"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   623
            thus "set x = set []" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   624
          qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   625
          ultimately show False by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   626
        qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   627
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   628
    with True show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   629
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   630
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   631
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   632
text {* 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   633
  The following @{text "step_v_wait_inv"} is also an obvious lemma, which, however, needs to be
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   634
  derived from scratch, which confirms the correctness of the definition of @{text "next_th"}.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   635
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   636
lemma step_v_wait_inv[elim_format]:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   637
    "\<And>t c. \<lbrakk>vt (V th cs # s); \<not> waiting (wq (V th cs # s)) t c; waiting (wq s) t c
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   638
           \<rbrakk>
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   639
          \<Longrightarrow> (next_th s th cs t \<and> cs = c)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   640
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   641
  fix t c 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   642
  assume vt: "vt (V th cs # s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   643
    and nw: "\<not> waiting (wq (V th cs # s)) t c"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   644
    and wt: "waiting (wq s) t c"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   645
  show "next_th s th cs t \<and> cs = c"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   646
  proof(cases "cs = c")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   647
    case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   648
    with nw wt show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   649
      by (auto simp:cs_waiting_def wq_def Let_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   650
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   651
    case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   652
    from nw[folded True] wt[folded True]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   653
    have "next_th s th cs t"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   654
      apply (unfold next_th_def, auto simp:cs_waiting_def wq_def Let_def split:list.splits)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   655
    proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   656
      fix a list
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   657
      assume t_in: "t \<in> set list"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   658
        and t_ni: "t \<notin> set (SOME q. distinct q \<and> set q = set list)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   659
        and eq_wq: "wq_fun (schs s) cs = a # list"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   660
      have " set (SOME q. distinct q \<and> set q = set list) = set list"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   661
      proof(rule someI2)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   662
        from wq_distinct[OF step_back_vt[OF vt], of cs] and eq_wq[folded wq_def]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   663
        show "distinct list \<and> set list = set list" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   664
      next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   665
        show "\<And>x. distinct x \<and> set x = set list \<Longrightarrow> set x = set list"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   666
          by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   667
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   668
      with t_ni and t_in show "a = th" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   669
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   670
      fix a list
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   671
      assume t_in: "t \<in> set list"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   672
        and t_ni: "t \<notin> set (SOME q. distinct q \<and> set q = set list)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   673
        and eq_wq: "wq_fun (schs s) cs = a # list"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   674
      have " set (SOME q. distinct q \<and> set q = set list) = set list"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   675
      proof(rule someI2)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   676
        from wq_distinct[OF step_back_vt[OF vt], of cs] and eq_wq[folded wq_def]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   677
        show "distinct list \<and> set list = set list" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   678
      next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   679
        show "\<And>x. distinct x \<and> set x = set list \<Longrightarrow> set x = set list"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   680
          by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   681
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   682
      with t_ni and t_in show "t = hd (SOME q. distinct q \<and> set q = set list)" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   683
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   684
      fix a list
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   685
      assume eq_wq: "wq_fun (schs s) cs = a # list"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   686
      from step_back_step[OF vt]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   687
      show "a = th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   688
      proof(cases)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   689
        assume "holding s th cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   690
        with eq_wq show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   691
          by (unfold s_holding_def wq_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   692
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   693
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   694
    with True show ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   695
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   696
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   697
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   698
lemma step_v_not_wait[consumes 3]:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   699
  "\<lbrakk>vt (V th cs # s); next_th s th cs t; waiting (wq (V th cs # s)) t cs\<rbrakk> \<Longrightarrow> False"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   700
  by (unfold next_th_def cs_waiting_def wq_def, auto simp:Let_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   701
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   702
lemma step_v_release:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   703
  "\<lbrakk>vt (V th cs # s); holding (wq (V th cs # s)) th cs\<rbrakk> \<Longrightarrow> False"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   704
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   705
  assume vt: "vt (V th cs # s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   706
    and hd: "holding (wq (V th cs # s)) th cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   707
  from step_back_step [OF vt] and hd
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   708
  show "False"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   709
  proof(cases)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   710
    assume "holding (wq (V th cs # s)) th cs" and "holding s th cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   711
    thus ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   712
      apply (unfold s_holding_def wq_def cs_holding_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   713
      apply (auto simp:Let_def split:list.splits)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   714
    proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   715
      fix list
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   716
      assume eq_wq[folded wq_def]: 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   717
        "wq_fun (schs s) cs = hd (SOME q. distinct q \<and> set q = set list) # list"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   718
      and hd_in: "hd (SOME q. distinct q \<and> set q = set list)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   719
            \<in> set (SOME q. distinct q \<and> set q = set list)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   720
      have "set (SOME q. distinct q \<and> set q = set list) = set list"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   721
      proof(rule someI2)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   722
        from wq_distinct[OF step_back_vt[OF vt], of cs] and eq_wq
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   723
        show "distinct list \<and> set list = set list" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   724
      next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   725
        show "\<And>x. distinct x \<and> set x = set list \<Longrightarrow> set x = set list"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   726
          by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   727
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   728
      moreover have "distinct  (hd (SOME q. distinct q \<and> set q = set list) # list)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   729
      proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   730
        from wq_distinct[OF step_back_vt[OF vt], of cs] and eq_wq
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   731
        show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   732
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   733
      moreover note eq_wq and hd_in
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   734
      ultimately show "False" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   735
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   736
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   737
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   738
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   739
lemma step_v_get_hold:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   740
  "\<And>th'. \<lbrakk>vt (V th cs # s); \<not> holding (wq (V th cs # s)) th' cs; next_th s th cs th'\<rbrakk> \<Longrightarrow> False"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   741
  apply (unfold cs_holding_def next_th_def wq_def,
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   742
         auto simp:Let_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   743
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   744
  fix rest
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   745
  assume vt: "vt (V th cs # s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   746
    and eq_wq[folded wq_def]: " wq_fun (schs s) cs = th # rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   747
    and nrest: "rest \<noteq> []"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   748
    and ni: "hd (SOME q. distinct q \<and> set q = set rest)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   749
            \<notin> set (SOME q. distinct q \<and> set q = set rest)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   750
  have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   751
  proof(rule someI2)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   752
    from wq_distinct[OF step_back_vt[OF vt], of cs] and eq_wq
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   753
    show "distinct rest \<and> set rest = set rest" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   754
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   755
    fix x assume "distinct x \<and> set x = set rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   756
    hence "set x = set rest" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   757
    with nrest
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   758
    show "x \<noteq> []" by (case_tac x, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   759
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   760
  with ni show "False" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   761
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   762
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   763
lemma step_v_release_inv[elim_format]:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   764
"\<And>c t. \<lbrakk>vt (V th cs # s); \<not> holding (wq (V th cs # s)) t c; holding (wq s) t c\<rbrakk> \<Longrightarrow> 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   765
  c = cs \<and> t = th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   766
  apply (unfold cs_holding_def wq_def, auto simp:Let_def split:if_splits list.splits)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   767
  proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   768
    fix a list
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   769
    assume vt: "vt (V th cs # s)" and eq_wq: "wq_fun (schs s) cs = a # list"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   770
    from step_back_step [OF vt] show "a = th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   771
    proof(cases)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   772
      assume "holding s th cs" with eq_wq
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   773
      show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   774
        by (unfold s_holding_def wq_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   775
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   776
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   777
    fix a list
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   778
    assume vt: "vt (V th cs # s)" and eq_wq: "wq_fun (schs s) cs = a # list"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   779
    from step_back_step [OF vt] show "a = th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   780
    proof(cases)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   781
      assume "holding s th cs" with eq_wq
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   782
      show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   783
        by (unfold s_holding_def wq_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   784
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   785
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   786
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   787
lemma step_v_waiting_mono:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   788
  "\<And>t c. \<lbrakk>vt (V th cs # s); waiting (wq (V th cs # s)) t c\<rbrakk> \<Longrightarrow> waiting (wq s) t c"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   789
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   790
  fix t c
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   791
  let ?s' = "(V th cs # s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   792
  assume vt: "vt ?s'" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   793
    and wt: "waiting (wq ?s') t c"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   794
  show "waiting (wq s) t c"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   795
  proof(cases "c = cs")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   796
    case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   797
    assume neq_cs: "c \<noteq> cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   798
    hence "waiting (wq ?s') t c = waiting (wq s) t c"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   799
      by (unfold cs_waiting_def wq_def, auto simp:Let_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   800
    with wt show ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   801
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   802
    case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   803
    with wt show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   804
      apply (unfold cs_waiting_def wq_def, auto simp:Let_def split:list.splits)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   805
    proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   806
      fix a list
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   807
      assume not_in: "t \<notin> set list"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   808
        and is_in: "t \<in> set (SOME q. distinct q \<and> set q = set list)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   809
        and eq_wq: "wq_fun (schs s) cs = a # list"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   810
      have "set (SOME q. distinct q \<and> set q = set list) = set list"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   811
      proof(rule someI2)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   812
        from wq_distinct [OF step_back_vt[OF vt], of cs]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   813
        and eq_wq[folded wq_def]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   814
        show "distinct list \<and> set list = set list" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   815
      next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   816
        fix x assume "distinct x \<and> set x = set list"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   817
        thus "set x = set list" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   818
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   819
      with not_in is_in show "t = a" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   820
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   821
      fix list
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   822
      assume is_waiting: "waiting (wq (V th cs # s)) t cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   823
      and eq_wq: "wq_fun (schs s) cs = t # list"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   824
      hence "t \<in> set list"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   825
        apply (unfold wq_def, auto simp:Let_def cs_waiting_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   826
      proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   827
        assume " t \<in> set (SOME q. distinct q \<and> set q = set list)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   828
        moreover have "\<dots> = set list" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   829
        proof(rule someI2)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   830
          from wq_distinct [OF step_back_vt[OF vt], of cs]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   831
            and eq_wq[folded wq_def]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   832
          show "distinct list \<and> set list = set list" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   833
        next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   834
          fix x assume "distinct x \<and> set x = set list" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   835
          thus "set x = set list" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   836
        qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   837
        ultimately show "t \<in> set list" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   838
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   839
      with eq_wq and wq_distinct [OF step_back_vt[OF vt], of cs, unfolded wq_def]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   840
      show False by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   841
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   842
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   843
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   844
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
   845
text {* (* ddd *) 
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   846
  The following @{text "step_RAG_v"} lemma charaterizes how @{text "RAG"} is changed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   847
  with the happening of @{text "V"}-events:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   848
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   849
lemma step_RAG_v:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   850
fixes th::thread
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   851
assumes vt:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   852
  "vt (V th cs#s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   853
shows "
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   854
  RAG (V th cs # s) =
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   855
  RAG s - {(Cs cs, Th th)} -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   856
  {(Th th', Cs cs) |th'. next_th s th cs th'} \<union>
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   857
  {(Cs cs, Th th') |th'.  next_th s th cs th'}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   858
  apply (insert vt, unfold s_RAG_def) 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   859
  apply (auto split:if_splits list.splits simp:Let_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   860
  apply (auto elim: step_v_waiting_mono step_v_hold_inv 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   861
              step_v_release step_v_wait_inv
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   862
              step_v_get_hold step_v_release_inv)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   863
  apply (erule_tac step_v_not_wait, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   864
  done
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   865
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   866
text {* 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   867
  The following @{text "step_RAG_p"} lemma charaterizes how @{text "RAG"} is changed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   868
  with the happening of @{text "P"}-events:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   869
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   870
lemma step_RAG_p:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   871
  "vt (P th cs#s) \<Longrightarrow>
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   872
  RAG (P th cs # s) =  (if (wq s cs = []) then RAG s \<union> {(Cs cs, Th th)}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   873
                                             else RAG s \<union> {(Th th, Cs cs)})"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   874
  apply(simp only: s_RAG_def wq_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   875
  apply (auto split:list.splits prod.splits simp:Let_def wq_def cs_waiting_def cs_holding_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   876
  apply(case_tac "csa = cs", auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   877
  apply(fold wq_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   878
  apply(drule_tac step_back_step)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   879
  apply(ind_cases " step s (P (hd (wq s cs)) cs)")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   880
  apply(simp add:s_RAG_def wq_def cs_holding_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   881
  apply(auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   882
  done
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   883
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   884
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   885
lemma RAG_target_th: "(Th th, x) \<in> RAG (s::state) \<Longrightarrow> \<exists> cs. x = Cs cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   886
  by (unfold s_RAG_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   887
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   888
text {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   889
  The following lemma shows that @{text "RAG"} is acyclic.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   890
  The overall structure is by induction on the formation of @{text "vt s"}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   891
  and then case analysis on event @{text "e"}, where the non-trivial cases 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   892
  for those for @{text "V"} and @{text "P"} events.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   893
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   894
lemma acyclic_RAG: 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   895
  fixes s
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   896
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   897
  shows "acyclic (RAG s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   898
using assms
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   899
proof(induct)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   900
  case (vt_cons s e)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   901
  assume ih: "acyclic (RAG s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   902
    and stp: "step s e"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   903
    and vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   904
  show ?case
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   905
  proof(cases e)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   906
    case (Create th prio)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   907
    with ih
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   908
    show ?thesis by (simp add:RAG_create_unchanged)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   909
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   910
    case (Exit th)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   911
    with ih show ?thesis by (simp add:RAG_exit_unchanged)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   912
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   913
    case (V th cs)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   914
    from V vt stp have vtt: "vt (V th cs#s)" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   915
    from step_RAG_v [OF this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   916
    have eq_de: 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   917
      "RAG (e # s) = 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   918
      RAG s - {(Cs cs, Th th)} - {(Th th', Cs cs) |th'. next_th s th cs th'} \<union>
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   919
      {(Cs cs, Th th') |th'. next_th s th cs th'}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   920
      (is "?L = (?A - ?B - ?C) \<union> ?D") by (simp add:V)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   921
    from ih have ac: "acyclic (?A - ?B - ?C)" by (auto elim:acyclic_subset)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   922
    from step_back_step [OF vtt]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   923
    have "step s (V th cs)" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   924
    thus ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   925
    proof(cases)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   926
      assume "holding s th cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   927
      hence th_in: "th \<in> set (wq s cs)" and
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   928
        eq_hd: "th = hd (wq s cs)" unfolding s_holding_def wq_def by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   929
      then obtain rest where
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   930
        eq_wq: "wq s cs = th#rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   931
        by (cases "wq s cs", auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   932
      show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   933
      proof(cases "rest = []")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   934
        case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   935
        let ?th' = "hd (SOME q. distinct q \<and> set q = set rest)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   936
        from eq_wq False have eq_D: "?D = {(Cs cs, Th ?th')}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   937
          by (unfold next_th_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   938
        let ?E = "(?A - ?B - ?C)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   939
        have "(Th ?th', Cs cs) \<notin> ?E\<^sup>*"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   940
        proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   941
          assume "(Th ?th', Cs cs) \<in> ?E\<^sup>*"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   942
          hence " (Th ?th', Cs cs) \<in> ?E\<^sup>+" by (simp add: rtrancl_eq_or_trancl)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   943
          from tranclD [OF this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   944
          obtain x where th'_e: "(Th ?th', x) \<in> ?E" by blast
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   945
          hence th_d: "(Th ?th', x) \<in> ?A" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   946
          from RAG_target_th [OF this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   947
          obtain cs' where eq_x: "x = Cs cs'" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   948
          with th_d have "(Th ?th', Cs cs') \<in> ?A" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   949
          hence wt_th': "waiting s ?th' cs'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   950
            unfolding s_RAG_def s_waiting_def cs_waiting_def wq_def by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   951
          hence "cs' = cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   952
          proof(rule waiting_unique [OF vt])
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   953
            from eq_wq wq_distinct[OF vt, of cs]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   954
            show "waiting s ?th' cs" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   955
              apply (unfold s_waiting_def wq_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   956
            proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   957
              assume hd_in: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   958
                and eq_wq: "wq_fun (schs s) cs = th # rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   959
              have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   960
              proof(rule someI2)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   961
                from wq_distinct[OF vt, of cs] and eq_wq
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   962
                show "distinct rest \<and> set rest = set rest" unfolding wq_def by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   963
              next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   964
                fix x assume "distinct x \<and> set x = set rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   965
                with False show "x \<noteq> []" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   966
              qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   967
              hence "hd (SOME q. distinct q \<and> set q = set rest) \<in> 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   968
                set (SOME q. distinct q \<and> set q = set rest)" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   969
              moreover have "\<dots> = set rest" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   970
              proof(rule someI2)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   971
                from wq_distinct[OF vt, of cs] and eq_wq
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   972
                show "distinct rest \<and> set rest = set rest" unfolding wq_def by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   973
              next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   974
                show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   975
              qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   976
              moreover note hd_in
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   977
              ultimately show "hd (SOME q. distinct q \<and> set q = set rest) = th" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   978
            next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   979
              assume hd_in: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   980
                and eq_wq: "wq s cs = hd (SOME q. distinct q \<and> set q = set rest) # rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   981
              have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   982
              proof(rule someI2)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   983
                from wq_distinct[OF vt, of cs] and eq_wq
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   984
                show "distinct rest \<and> set rest = set rest" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   985
              next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   986
                fix x assume "distinct x \<and> set x = set rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   987
                with False show "x \<noteq> []" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   988
              qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   989
              hence "hd (SOME q. distinct q \<and> set q = set rest) \<in> 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   990
                set (SOME q. distinct q \<and> set q = set rest)" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   991
              moreover have "\<dots> = set rest" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   992
              proof(rule someI2)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   993
                from wq_distinct[OF vt, of cs] and eq_wq
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   994
                show "distinct rest \<and> set rest = set rest" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   995
              next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   996
                show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   997
              qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   998
              moreover note hd_in
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   999
              ultimately show False by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1000
            qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1001
          qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1002
          with th'_e eq_x have "(Th ?th', Cs cs) \<in> ?E" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1003
          with False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1004
          show "False" by (auto simp: next_th_def eq_wq)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1005
        qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1006
        with acyclic_insert[symmetric] and ac
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1007
          and eq_de eq_D show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1008
      next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1009
        case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1010
        with eq_wq
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1011
        have eq_D: "?D = {}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1012
          by (unfold next_th_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1013
        with eq_de ac
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1014
        show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1015
      qed 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1016
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1017
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1018
    case (P th cs)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1019
    from P vt stp have vtt: "vt (P th cs#s)" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1020
    from step_RAG_p [OF this] P
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1021
    have "RAG (e # s) = 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1022
      (if wq s cs = [] then RAG s \<union> {(Cs cs, Th th)} else 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1023
      RAG s \<union> {(Th th, Cs cs)})" (is "?L = ?R")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1024
      by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1025
    moreover have "acyclic ?R"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1026
    proof(cases "wq s cs = []")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1027
      case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1028
      hence eq_r: "?R =  RAG s \<union> {(Cs cs, Th th)}" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1029
      have "(Th th, Cs cs) \<notin> (RAG s)\<^sup>*"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1030
      proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1031
        assume "(Th th, Cs cs) \<in> (RAG s)\<^sup>*"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1032
        hence "(Th th, Cs cs) \<in> (RAG s)\<^sup>+" by (simp add: rtrancl_eq_or_trancl)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1033
        from tranclD2 [OF this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1034
        obtain x where "(x, Cs cs) \<in> RAG s" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1035
        with True show False by (auto simp:s_RAG_def cs_waiting_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1036
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1037
      with acyclic_insert ih eq_r show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1038
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1039
      case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1040
      hence eq_r: "?R =  RAG s \<union> {(Th th, Cs cs)}" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1041
      have "(Cs cs, Th th) \<notin> (RAG s)\<^sup>*"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1042
      proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1043
        assume "(Cs cs, Th th) \<in> (RAG s)\<^sup>*"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1044
        hence "(Cs cs, Th th) \<in> (RAG s)\<^sup>+" by (simp add: rtrancl_eq_or_trancl)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1045
        moreover from step_back_step [OF vtt] have "step s (P th cs)" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1046
        ultimately show False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1047
        proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1048
          show " \<lbrakk>(Cs cs, Th th) \<in> (RAG s)\<^sup>+; step s (P th cs)\<rbrakk> \<Longrightarrow> False"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1049
            by (ind_cases "step s (P th cs)", simp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1050
        qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1051
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1052
      with acyclic_insert ih eq_r show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1053
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1054
      ultimately show ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1055
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1056
      case (Set thread prio)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1057
      with ih
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1058
      thm RAG_set_unchanged
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1059
      show ?thesis by (simp add:RAG_set_unchanged)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1060
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1061
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1062
    case vt_nil
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1063
    show "acyclic (RAG ([]::state))"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1064
      by (auto simp: s_RAG_def cs_waiting_def 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1065
        cs_holding_def wq_def acyclic_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1066
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1067
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1068
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1069
lemma finite_RAG: 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1070
  fixes s
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1071
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1072
  shows "finite (RAG s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1073
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1074
  from vt show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1075
  proof(induct)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1076
    case (vt_cons s e)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1077
    assume ih: "finite (RAG s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1078
      and stp: "step s e"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1079
      and vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1080
    show ?case
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1081
    proof(cases e)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1082
      case (Create th prio)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1083
      with ih
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1084
      show ?thesis by (simp add:RAG_create_unchanged)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1085
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1086
      case (Exit th)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1087
      with ih show ?thesis by (simp add:RAG_exit_unchanged)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1088
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1089
      case (V th cs)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1090
      from V vt stp have vtt: "vt (V th cs#s)" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1091
      from step_RAG_v [OF this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1092
      have eq_de: "RAG (e # s) = 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1093
                   RAG s - {(Cs cs, Th th)} - {(Th th', Cs cs) |th'. next_th s th cs th'} \<union>
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1094
                      {(Cs cs, Th th') |th'. next_th s th cs th'}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1095
"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1096
        (is "?L = (?A - ?B - ?C) \<union> ?D") by (simp add:V)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1097
      moreover from ih have ac: "finite (?A - ?B - ?C)" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1098
      moreover have "finite ?D"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1099
      proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1100
        have "?D = {} \<or> (\<exists> a. ?D = {a})" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1101
          by (unfold next_th_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1102
        thus ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1103
        proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1104
          assume h: "?D = {}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1105
          show ?thesis by (unfold h, simp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1106
        next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1107
          assume "\<exists> a. ?D = {a}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1108
          thus ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1109
            by (metis finite.simps)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1110
        qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1111
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1112
      ultimately show ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1113
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1114
      case (P th cs)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1115
      from P vt stp have vtt: "vt (P th cs#s)" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1116
      from step_RAG_p [OF this] P
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1117
      have "RAG (e # s) = 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1118
              (if wq s cs = [] then RAG s \<union> {(Cs cs, Th th)} else 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1119
                                    RAG s \<union> {(Th th, Cs cs)})" (is "?L = ?R")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1120
        by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1121
      moreover have "finite ?R"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1122
      proof(cases "wq s cs = []")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1123
        case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1124
        hence eq_r: "?R =  RAG s \<union> {(Cs cs, Th th)}" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1125
        with True and ih show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1126
      next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1127
        case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1128
        hence "?R = RAG s \<union> {(Th th, Cs cs)}" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1129
        with False and ih show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1130
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1131
      ultimately show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1132
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1133
      case (Set thread prio)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1134
      with ih
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1135
      show ?thesis by (simp add:RAG_set_unchanged)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1136
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1137
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1138
    case vt_nil
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1139
    show "finite (RAG ([]::state))"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1140
      by (auto simp: s_RAG_def cs_waiting_def 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1141
                   cs_holding_def wq_def acyclic_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1142
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1143
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1144
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1145
text {* Several useful lemmas *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1146
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1147
lemma wf_dep_converse: 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1148
  fixes s
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1149
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1150
  shows "wf ((RAG s)^-1)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1151
proof(rule finite_acyclic_wf_converse)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1152
  from finite_RAG [OF vt]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1153
  show "finite (RAG s)" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1154
next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1155
  from acyclic_RAG[OF vt]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1156
  show "acyclic (RAG s)" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1157
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1158
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1159
lemma hd_np_in: "x \<in> set l \<Longrightarrow> hd l \<in> set l"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1160
by (induct l, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1161
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1162
lemma th_chasing: "(Th th, Cs cs) \<in> RAG (s::state) \<Longrightarrow> \<exists> th'. (Cs cs, Th th') \<in> RAG s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1163
  by (auto simp:s_RAG_def s_holding_def cs_holding_def cs_waiting_def wq_def dest:hd_np_in)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1164
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1165
lemma wq_threads: 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1166
  fixes s cs
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1167
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1168
  and h: "th \<in> set (wq s cs)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1169
  shows "th \<in> threads s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1170
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1171
 from vt and h show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1172
  proof(induct arbitrary: th cs)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1173
    case (vt_cons s e)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1174
    assume ih: "\<And>th cs. th \<in> set (wq s cs) \<Longrightarrow> th \<in> threads s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1175
      and stp: "step s e"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1176
      and vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1177
      and h: "th \<in> set (wq (e # s) cs)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1178
    show ?case
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1179
    proof(cases e)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1180
      case (Create th' prio)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1181
      with ih h show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1182
        by (auto simp:wq_def Let_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1183
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1184
      case (Exit th')
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1185
      with stp ih h show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1186
        apply (auto simp:wq_def Let_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1187
        apply (ind_cases "step s (Exit th')")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1188
        apply (auto simp:runing_def readys_def s_holding_def s_waiting_def holdents_def
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1189
               s_RAG_def s_holding_def cs_holding_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1190
        done
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1191
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1192
      case (V th' cs')
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1193
      show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1194
      proof(cases "cs' = cs")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1195
        case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1196
        with h
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1197
        show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1198
          apply(unfold wq_def V, auto simp:Let_def V split:prod.splits, fold wq_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1199
          by (drule_tac ih, simp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1200
      next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1201
        case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1202
        from h
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1203
        show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1204
        proof(unfold V wq_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1205
          assume th_in: "th \<in> set (wq_fun (schs (V th' cs' # s)) cs)" (is "th \<in> set ?l")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1206
          show "th \<in> threads (V th' cs' # s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1207
          proof(cases "cs = cs'")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1208
            case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1209
            hence "?l = wq_fun (schs s) cs" by (simp add:Let_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1210
            with th_in have " th \<in> set (wq s cs)" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1211
              by (fold wq_def, simp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1212
            from ih [OF this] show ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1213
          next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1214
            case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1215
            show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1216
            proof(cases "wq_fun (schs s) cs'")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1217
              case Nil
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1218
              with h V show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1219
                apply (auto simp:wq_def Let_def split:if_splits)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1220
                by (fold wq_def, drule_tac ih, simp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1221
            next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1222
              case (Cons a rest)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1223
              assume eq_wq: "wq_fun (schs s) cs' = a # rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1224
              with h V show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1225
                apply (auto simp:Let_def wq_def split:if_splits)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1226
              proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1227
                assume th_in: "th \<in> set (SOME q. distinct q \<and> set q = set rest)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1228
                have "set (SOME q. distinct q \<and> set q = set rest) = set rest" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1229
                proof(rule someI2)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1230
                  from wq_distinct[OF vt, of cs'] and eq_wq[folded wq_def]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1231
                  show "distinct rest \<and> set rest = set rest" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1232
                next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1233
                  show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1234
                    by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1235
                qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1236
                with eq_wq th_in have "th \<in> set (wq_fun (schs s) cs')" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1237
                from ih[OF this[folded wq_def]] show "th \<in> threads s" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1238
              next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1239
                assume th_in: "th \<in> set (wq_fun (schs s) cs)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1240
                from ih[OF this[folded wq_def]]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1241
                show "th \<in> threads s" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1242
              qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1243
            qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1244
          qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1245
        qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1246
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1247
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1248
      case (P th' cs')
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1249
      from h stp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1250
      show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1251
        apply (unfold P wq_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1252
        apply (auto simp:Let_def split:if_splits, fold wq_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1253
        apply (auto intro:ih)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1254
        apply(ind_cases "step s (P th' cs')")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1255
        by (unfold runing_def readys_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1256
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1257
      case (Set thread prio)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1258
      with ih h show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1259
        by (auto simp:wq_def Let_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1260
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1261
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1262
    case vt_nil
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1263
    thus ?case by (auto simp:wq_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1264
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1265
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1266
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1267
lemma range_in: "\<lbrakk>vt s; (Th th) \<in> Range (RAG (s::state))\<rbrakk> \<Longrightarrow> th \<in> threads s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1268
  apply(unfold s_RAG_def cs_waiting_def cs_holding_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1269
  by (auto intro:wq_threads)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1270
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1271
lemma readys_v_eq:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1272
  fixes th thread cs rest
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1273
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1274
  and neq_th: "th \<noteq> thread"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1275
  and eq_wq: "wq s cs = thread#rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1276
  and not_in: "th \<notin>  set rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1277
  shows "(th \<in> readys (V thread cs#s)) = (th \<in> readys s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1278
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1279
  from assms show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1280
    apply (auto simp:readys_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1281
    apply(simp add:s_waiting_def[folded wq_def])
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1282
    apply (erule_tac x = csa in allE)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1283
    apply (simp add:s_waiting_def wq_def Let_def split:if_splits)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1284
    apply (case_tac "csa = cs", simp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1285
    apply (erule_tac x = cs in allE)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1286
    apply(auto simp add: s_waiting_def[folded wq_def] Let_def split: list.splits)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1287
    apply(auto simp add: wq_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1288
    apply (auto simp:s_waiting_def wq_def Let_def split:list.splits)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1289
    proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1290
       assume th_nin: "th \<notin> set rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1291
        and th_in: "th \<in> set (SOME q. distinct q \<and> set q = set rest)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1292
        and eq_wq: "wq_fun (schs s) cs = thread # rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1293
      have "set (SOME q. distinct q \<and> set q = set rest) = set rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1294
      proof(rule someI2)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1295
        from wq_distinct[OF vt, of cs, unfolded wq_def] and eq_wq[unfolded wq_def]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1296
        show "distinct rest \<and> set rest = set rest" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1297
      next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1298
        show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1299
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1300
      with th_nin th_in show False by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1301
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1302
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1303
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1304
text {* \noindent
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1305
  The following lemmas shows that: starting from any node in @{text "RAG"}, 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1306
  by chasing out-going edges, it is always possible to reach a node representing a ready
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1307
  thread. In this lemma, it is the @{text "th'"}.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1308
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1309
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1310
lemma chain_building:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1311
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1312
  shows "node \<in> Domain (RAG s) \<longrightarrow> (\<exists> th'. th' \<in> readys s \<and> (node, Th th') \<in> (RAG s)^+)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1313
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1314
  from wf_dep_converse [OF vt]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1315
  have h: "wf ((RAG s)\<inverse>)" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1316
  show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1317
  proof(induct rule:wf_induct [OF h])
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1318
    fix x
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1319
    assume ih [rule_format]: 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1320
      "\<forall>y. (y, x) \<in> (RAG s)\<inverse> \<longrightarrow> 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1321
           y \<in> Domain (RAG s) \<longrightarrow> (\<exists>th'. th' \<in> readys s \<and> (y, Th th') \<in> (RAG s)\<^sup>+)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1322
    show "x \<in> Domain (RAG s) \<longrightarrow> (\<exists>th'. th' \<in> readys s \<and> (x, Th th') \<in> (RAG s)\<^sup>+)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1323
    proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1324
      assume x_d: "x \<in> Domain (RAG s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1325
      show "\<exists>th'. th' \<in> readys s \<and> (x, Th th') \<in> (RAG s)\<^sup>+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1326
      proof(cases x)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1327
        case (Th th)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1328
        from x_d Th obtain cs where x_in: "(Th th, Cs cs) \<in> RAG s" by (auto simp:s_RAG_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1329
        with Th have x_in_r: "(Cs cs, x) \<in> (RAG s)^-1" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1330
        from th_chasing [OF x_in] obtain th' where "(Cs cs, Th th') \<in> RAG s" by blast
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1331
        hence "Cs cs \<in> Domain (RAG s)" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1332
        from ih [OF x_in_r this] obtain th'
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1333
          where th'_ready: " th' \<in> readys s" and cs_in: "(Cs cs, Th th') \<in> (RAG s)\<^sup>+" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1334
        have "(x, Th th') \<in> (RAG s)\<^sup>+" using Th x_in cs_in by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1335
        with th'_ready show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1336
      next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1337
        case (Cs cs)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1338
        from x_d Cs obtain th' where th'_d: "(Th th', x) \<in> (RAG s)^-1" by (auto simp:s_RAG_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1339
        show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1340
        proof(cases "th' \<in> readys s")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1341
          case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1342
          from True and th'_d show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1343
        next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1344
          case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1345
          from th'_d and range_in [OF vt] have "th' \<in> threads s" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1346
          with False have "Th th' \<in> Domain (RAG s)" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1347
            by (auto simp:readys_def wq_def s_waiting_def s_RAG_def cs_waiting_def Domain_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1348
          from ih [OF th'_d this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1349
          obtain th'' where 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1350
            th''_r: "th'' \<in> readys s" and 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1351
            th''_in: "(Th th', Th th'') \<in> (RAG s)\<^sup>+" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1352
          from th'_d and th''_in 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1353
          have "(x, Th th'') \<in> (RAG s)\<^sup>+" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1354
          with th''_r show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1355
        qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1356
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1357
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1358
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1359
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1360
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1361
text {* \noindent
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1362
  The following is just an instance of @{text "chain_building"}.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1363
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1364
lemma th_chain_to_ready:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1365
  fixes s th
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1366
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1367
  and th_in: "th \<in> threads s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1368
  shows "th \<in> readys s \<or> (\<exists> th'. th' \<in> readys s \<and> (Th th, Th th') \<in> (RAG s)^+)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1369
proof(cases "th \<in> readys s")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1370
  case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1371
  thus ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1372
next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1373
  case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1374
  from False and th_in have "Th th \<in> Domain (RAG s)" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1375
    by (auto simp:readys_def s_waiting_def s_RAG_def wq_def cs_waiting_def Domain_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1376
  from chain_building [rule_format, OF vt this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1377
  show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1378
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1379
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1380
lemma waiting_eq: "waiting s th cs = waiting (wq s) th cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1381
  by  (unfold s_waiting_def cs_waiting_def wq_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1382
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1383
lemma holding_eq: "holding (s::state) th cs = holding (wq s) th cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1384
  by (unfold s_holding_def wq_def cs_holding_def, simp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1385
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1386
lemma holding_unique: "\<lbrakk>holding (s::state) th1 cs; holding s th2 cs\<rbrakk> \<Longrightarrow> th1 = th2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1387
  by (unfold s_holding_def cs_holding_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1388
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1389
lemma unique_RAG: "\<lbrakk>vt s; (n, n1) \<in> RAG s; (n, n2) \<in> RAG s\<rbrakk> \<Longrightarrow> n1 = n2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1390
  apply(unfold s_RAG_def, auto, fold waiting_eq holding_eq)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1391
  by(auto elim:waiting_unique holding_unique)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1392
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1393
lemma trancl_split: "(a, b) \<in> r^+ \<Longrightarrow> \<exists> c. (a, c) \<in> r"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1394
by (induct rule:trancl_induct, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1395
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1396
lemma dchain_unique:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1397
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1398
  and th1_d: "(n, Th th1) \<in> (RAG s)^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1399
  and th1_r: "th1 \<in> readys s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1400
  and th2_d: "(n, Th th2) \<in> (RAG s)^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1401
  and th2_r: "th2 \<in> readys s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1402
  shows "th1 = th2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1403
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1404
  { assume neq: "th1 \<noteq> th2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1405
    hence "Th th1 \<noteq> Th th2" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1406
    from unique_chain [OF _ th1_d th2_d this] and unique_RAG [OF vt]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1407
    have "(Th th1, Th th2) \<in> (RAG s)\<^sup>+ \<or> (Th th2, Th th1) \<in> (RAG s)\<^sup>+" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1408
    hence "False"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1409
    proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1410
      assume "(Th th1, Th th2) \<in> (RAG s)\<^sup>+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1411
      from trancl_split [OF this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1412
      obtain n where dd: "(Th th1, n) \<in> RAG s" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1413
      then obtain cs where eq_n: "n = Cs cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1414
        by (auto simp:s_RAG_def s_holding_def cs_holding_def cs_waiting_def wq_def dest:hd_np_in)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1415
      from dd eq_n have "th1 \<notin> readys s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1416
        by (auto simp:readys_def s_RAG_def wq_def s_waiting_def cs_waiting_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1417
      with th1_r show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1418
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1419
      assume "(Th th2, Th th1) \<in> (RAG s)\<^sup>+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1420
      from trancl_split [OF this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1421
      obtain n where dd: "(Th th2, n) \<in> RAG s" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1422
      then obtain cs where eq_n: "n = Cs cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1423
        by (auto simp:s_RAG_def s_holding_def cs_holding_def cs_waiting_def wq_def dest:hd_np_in)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1424
      from dd eq_n have "th2 \<notin> readys s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1425
        by (auto simp:readys_def wq_def s_RAG_def s_waiting_def cs_waiting_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1426
      with th2_r show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1427
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1428
  } thus ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1429
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1430
             
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1431
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1432
lemma step_holdents_p_add:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1433
  fixes th cs s
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1434
  assumes vt: "vt (P th cs#s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1435
  and "wq s cs = []"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1436
  shows "holdents (P th cs#s) th = holdents s th \<union> {cs}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1437
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1438
  from assms show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1439
  unfolding  holdents_test step_RAG_p[OF vt] by (auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1440
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1441
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1442
lemma step_holdents_p_eq:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1443
  fixes th cs s
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1444
  assumes vt: "vt (P th cs#s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1445
  and "wq s cs \<noteq> []"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1446
  shows "holdents (P th cs#s) th = holdents s th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1447
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1448
  from assms show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1449
  unfolding  holdents_test step_RAG_p[OF vt] by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1450
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1451
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1452
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1453
lemma finite_holding:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1454
  fixes s th cs
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1455
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1456
  shows "finite (holdents s th)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1457
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1458
  let ?F = "\<lambda> (x, y). the_cs x"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1459
  from finite_RAG [OF vt]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1460
  have "finite (RAG s)" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1461
  hence "finite (?F `(RAG s))" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1462
  moreover have "{cs . (Cs cs, Th th) \<in> RAG s} \<subseteq> \<dots>" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1463
  proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1464
    { have h: "\<And> a A f. a \<in> A \<Longrightarrow> f a \<in> f ` A" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1465
      fix x assume "(Cs x, Th th) \<in> RAG s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1466
      hence "?F (Cs x, Th th) \<in> ?F `(RAG s)" by (rule h)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1467
      moreover have "?F (Cs x, Th th) = x" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1468
      ultimately have "x \<in> (\<lambda>(x, y). the_cs x) ` RAG s" by simp 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1469
    } thus ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1470
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1471
  ultimately show ?thesis by (unfold holdents_test, auto intro:finite_subset)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1472
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1473
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1474
lemma cntCS_v_dec: 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1475
  fixes s thread cs
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1476
  assumes vtv: "vt (V thread cs#s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1477
  shows "(cntCS (V thread cs#s) thread + 1) = cntCS s thread"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1478
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1479
  from step_back_step[OF vtv]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1480
  have cs_in: "cs \<in> holdents s thread" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1481
    apply (cases, unfold holdents_test s_RAG_def, simp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1482
    by (unfold cs_holding_def s_holding_def wq_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1483
  moreover have cs_not_in: 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1484
    "(holdents (V thread cs#s) thread) = holdents s thread - {cs}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1485
    apply (insert wq_distinct[OF step_back_vt[OF vtv], of cs])
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1486
    apply (unfold holdents_test, unfold step_RAG_v[OF vtv],
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1487
            auto simp:next_th_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1488
  proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1489
    fix rest
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1490
    assume dst: "distinct (rest::thread list)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1491
      and ne: "rest \<noteq> []"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1492
    and hd_ni: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1493
    moreover have "set (SOME q. distinct q \<and> set q = set rest) = set rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1494
    proof(rule someI2)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1495
      from dst show "distinct rest \<and> set rest = set rest" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1496
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1497
      show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1498
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1499
    ultimately have "hd (SOME q. distinct q \<and> set q = set rest) \<notin> 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1500
                     set (SOME q. distinct q \<and> set q = set rest)" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1501
    moreover have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1502
    proof(rule someI2)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1503
      from dst show "distinct rest \<and> set rest = set rest" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1504
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1505
      fix x assume " distinct x \<and> set x = set rest" with ne
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1506
      show "x \<noteq> []" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1507
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1508
    ultimately 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1509
    show "(Cs cs, Th (hd (SOME q. distinct q \<and> set q = set rest))) \<in> RAG s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1510
      by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1511
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1512
    fix rest
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1513
    assume dst: "distinct (rest::thread list)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1514
      and ne: "rest \<noteq> []"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1515
    and hd_ni: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1516
    moreover have "set (SOME q. distinct q \<and> set q = set rest) = set rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1517
    proof(rule someI2)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1518
      from dst show "distinct rest \<and> set rest = set rest" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1519
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1520
      show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1521
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1522
    ultimately have "hd (SOME q. distinct q \<and> set q = set rest) \<notin> 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1523
                     set (SOME q. distinct q \<and> set q = set rest)" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1524
    moreover have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1525
    proof(rule someI2)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1526
      from dst show "distinct rest \<and> set rest = set rest" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1527
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1528
      fix x assume " distinct x \<and> set x = set rest" with ne
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1529
      show "x \<noteq> []" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1530
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1531
    ultimately show "False" by auto 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1532
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1533
  ultimately 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1534
  have "holdents s thread = insert cs (holdents (V thread cs#s) thread)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1535
    by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1536
  moreover have "card \<dots> = 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1537
                    Suc (card ((holdents (V thread cs#s) thread) - {cs}))"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1538
  proof(rule card_insert)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1539
    from finite_holding [OF vtv]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1540
    show " finite (holdents (V thread cs # s) thread)" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1541
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1542
  moreover from cs_not_in 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1543
  have "cs \<notin> (holdents (V thread cs#s) thread)" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1544
  ultimately show ?thesis by (simp add:cntCS_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1545
qed 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1546
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  1547
text {* (* ddd *) \noindent
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1548
  The relationship between @{text "cntP"}, @{text "cntV"} and @{text "cntCS"} 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1549
  of one particular thread. 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1550
*} 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1551
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1552
lemma cnp_cnv_cncs:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1553
  fixes s th
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1554
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1555
  shows "cntP s th = cntV s th + (if (th \<in> readys s \<or> th \<notin> threads s) 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1556
                                       then cntCS s th else cntCS s th + 1)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1557
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1558
  from vt show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1559
  proof(induct arbitrary:th)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1560
    case (vt_cons s e)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1561
    assume vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1562
    and ih: "\<And>th. cntP s th  = cntV s th +
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1563
               (if (th \<in> readys s \<or> th \<notin> threads s) then cntCS s th else cntCS s th + 1)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1564
    and stp: "step s e"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1565
    from stp show ?case
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1566
    proof(cases)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1567
      case (thread_create thread prio)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1568
      assume eq_e: "e = Create thread prio"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1569
        and not_in: "thread \<notin> threads s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1570
      show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1571
      proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1572
        { fix cs 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1573
          assume "thread \<in> set (wq s cs)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1574
          from wq_threads [OF vt this] have "thread \<in> threads s" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1575
          with not_in have "False" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1576
        } with eq_e have eq_readys: "readys (e#s) = readys s \<union> {thread}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1577
          by (auto simp:readys_def threads.simps s_waiting_def 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1578
            wq_def cs_waiting_def Let_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1579
        from eq_e have eq_cnp: "cntP (e#s) th = cntP s th" by (simp add:cntP_def count_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1580
        from eq_e have eq_cnv: "cntV (e#s) th = cntV s th" by (simp add:cntV_def count_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1581
        have eq_cncs: "cntCS (e#s) th = cntCS s th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1582
          unfolding cntCS_def holdents_test
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1583
          by (simp add:RAG_create_unchanged eq_e)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1584
        { assume "th \<noteq> thread"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1585
          with eq_readys eq_e
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1586
          have "(th \<in> readys (e # s) \<or> th \<notin> threads (e # s)) = 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1587
                      (th \<in> readys (s) \<or> th \<notin> threads (s))" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1588
            by (simp add:threads.simps)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1589
          with eq_cnp eq_cnv eq_cncs ih not_in
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1590
          have ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1591
        } moreover {
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1592
          assume eq_th: "th = thread"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1593
          with not_in ih have " cntP s th  = cntV s th + cntCS s th" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1594
          moreover from eq_th and eq_readys have "th \<in> readys (e#s)" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1595
          moreover note eq_cnp eq_cnv eq_cncs
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1596
          ultimately have ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1597
        } ultimately show ?thesis by blast
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1598
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1599
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1600
      case (thread_exit thread)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1601
      assume eq_e: "e = Exit thread" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1602
      and is_runing: "thread \<in> runing s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1603
      and no_hold: "holdents s thread = {}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1604
      from eq_e have eq_cnp: "cntP (e#s) th = cntP s th" by (simp add:cntP_def count_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1605
      from eq_e have eq_cnv: "cntV (e#s) th = cntV s th" by (simp add:cntV_def count_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1606
      have eq_cncs: "cntCS (e#s) th = cntCS s th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1607
        unfolding cntCS_def holdents_test
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1608
        by (simp add:RAG_exit_unchanged eq_e)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1609
      { assume "th \<noteq> thread"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1610
        with eq_e
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1611
        have "(th \<in> readys (e # s) \<or> th \<notin> threads (e # s)) = 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1612
          (th \<in> readys (s) \<or> th \<notin> threads (s))" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1613
          apply (simp add:threads.simps readys_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1614
          apply (subst s_waiting_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1615
          apply (simp add:Let_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1616
          apply (subst s_waiting_def, simp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1617
          done
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1618
        with eq_cnp eq_cnv eq_cncs ih
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1619
        have ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1620
      } moreover {
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1621
        assume eq_th: "th = thread"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1622
        with ih is_runing have " cntP s th = cntV s th + cntCS s th" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1623
          by (simp add:runing_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1624
        moreover from eq_th eq_e have "th \<notin> threads (e#s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1625
          by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1626
        moreover note eq_cnp eq_cnv eq_cncs
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1627
        ultimately have ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1628
      } ultimately show ?thesis by blast
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1629
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1630
      case (thread_P thread cs)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1631
      assume eq_e: "e = P thread cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1632
        and is_runing: "thread \<in> runing s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1633
        and no_dep: "(Cs cs, Th thread) \<notin> (RAG s)\<^sup>+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1634
      from thread_P vt stp ih  have vtp: "vt (P thread cs#s)" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1635
      show ?thesis 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1636
      proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1637
        { have hh: "\<And> A B C. (B = C) \<Longrightarrow> (A \<and> B) = (A \<and> C)" by blast
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1638
          assume neq_th: "th \<noteq> thread"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1639
          with eq_e
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1640
          have eq_readys: "(th \<in> readys (e#s)) = (th \<in> readys (s))"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1641
            apply (simp add:readys_def s_waiting_def wq_def Let_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1642
            apply (rule_tac hh)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1643
             apply (intro iffI allI, clarify)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1644
            apply (erule_tac x = csa in allE, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1645
            apply (subgoal_tac "wq_fun (schs s) cs \<noteq> []", auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1646
            apply (erule_tac x = cs in allE, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1647
            by (case_tac "(wq_fun (schs s) cs)", auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1648
          moreover from neq_th eq_e have "cntCS (e # s) th = cntCS s th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1649
            apply (simp add:cntCS_def holdents_test)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1650
            by (unfold  step_RAG_p [OF vtp], auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1651
          moreover from eq_e neq_th have "cntP (e # s) th = cntP s th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1652
            by (simp add:cntP_def count_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1653
          moreover from eq_e neq_th have "cntV (e#s) th = cntV s th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1654
            by (simp add:cntV_def count_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1655
          moreover from eq_e neq_th have "threads (e#s) = threads s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1656
          moreover note ih [of th] 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1657
          ultimately have ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1658
        } moreover {
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1659
          assume eq_th: "th = thread"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1660
          have ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1661
          proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1662
            from eq_e eq_th have eq_cnp: "cntP (e # s) th  = 1 + (cntP s th)" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1663
              by (simp add:cntP_def count_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1664
            from eq_e eq_th have eq_cnv: "cntV (e#s) th = cntV s th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1665
              by (simp add:cntV_def count_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1666
            show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1667
            proof (cases "wq s cs = []")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1668
              case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1669
              with is_runing
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1670
              have "th \<in> readys (e#s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1671
                apply (unfold eq_e wq_def, unfold readys_def s_RAG_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1672
                apply (simp add: wq_def[symmetric] runing_def eq_th s_waiting_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1673
                by (auto simp:readys_def wq_def Let_def s_waiting_def wq_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1674
              moreover have "cntCS (e # s) th = 1 + cntCS s th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1675
              proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1676
                have "card {csa. csa = cs \<or> (Cs csa, Th thread) \<in> RAG s} =
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1677
                  Suc (card {cs. (Cs cs, Th thread) \<in> RAG s})" (is "card ?L = Suc (card ?R)")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1678
                proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1679
                  have "?L = insert cs ?R" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1680
                  moreover have "card \<dots> = Suc (card (?R - {cs}))" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1681
                  proof(rule card_insert)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1682
                    from finite_holding [OF vt, of thread]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1683
                    show " finite {cs. (Cs cs, Th thread) \<in> RAG s}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1684
                      by (unfold holdents_test, simp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1685
                  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1686
                  moreover have "?R - {cs} = ?R"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1687
                  proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1688
                    have "cs \<notin> ?R"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1689
                    proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1690
                      assume "cs \<in> {cs. (Cs cs, Th thread) \<in> RAG s}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1691
                      with no_dep show False by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1692
                    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1693
                    thus ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1694
                  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1695
                  ultimately show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1696
                qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1697
                thus ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1698
                  apply (unfold eq_e eq_th cntCS_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1699
                  apply (simp add: holdents_test)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1700
                  by (unfold step_RAG_p [OF vtp], auto simp:True)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1701
              qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1702
              moreover from is_runing have "th \<in> readys s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1703
                by (simp add:runing_def eq_th)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1704
              moreover note eq_cnp eq_cnv ih [of th]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1705
              ultimately show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1706
            next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1707
              case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1708
              have eq_wq: "wq (e#s) cs = wq s cs @ [th]"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1709
                    by (unfold eq_th eq_e wq_def, auto simp:Let_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1710
              have "th \<notin> readys (e#s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1711
              proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1712
                assume "th \<in> readys (e#s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1713
                hence "\<forall>cs. \<not> waiting (e # s) th cs" by (simp add:readys_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1714
                from this[rule_format, of cs] have " \<not> waiting (e # s) th cs" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1715
                hence "th \<in> set (wq (e#s) cs) \<Longrightarrow> th = hd (wq (e#s) cs)" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1716
                  by (simp add:s_waiting_def wq_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1717
                moreover from eq_wq have "th \<in> set (wq (e#s) cs)" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1718
                ultimately have "th = hd (wq (e#s) cs)" by blast
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1719
                with eq_wq have "th = hd (wq s cs @ [th])" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1720
                hence "th = hd (wq s cs)" using False by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1721
                with False eq_wq wq_distinct [OF vtp, of cs]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1722
                show False by (fold eq_e, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1723
              qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1724
              moreover from is_runing have "th \<in> threads (e#s)" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1725
                by (unfold eq_e, auto simp:runing_def readys_def eq_th)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1726
              moreover have "cntCS (e # s) th = cntCS s th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1727
                apply (unfold cntCS_def holdents_test eq_e step_RAG_p[OF vtp])
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1728
                by (auto simp:False)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1729
              moreover note eq_cnp eq_cnv ih[of th]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1730
              moreover from is_runing have "th \<in> readys s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1731
                by (simp add:runing_def eq_th)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1732
              ultimately show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1733
            qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1734
          qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1735
        } ultimately show ?thesis by blast
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1736
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1737
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1738
      case (thread_V thread cs)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1739
      from assms vt stp ih thread_V have vtv: "vt (V thread cs # s)" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1740
      assume eq_e: "e = V thread cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1741
        and is_runing: "thread \<in> runing s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1742
        and hold: "holding s thread cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1743
      from hold obtain rest 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1744
        where eq_wq: "wq s cs = thread # rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1745
        by (case_tac "wq s cs", auto simp: wq_def s_holding_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1746
      have eq_threads: "threads (e#s) = threads s" by (simp add: eq_e)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1747
      have eq_set: "set (SOME q. distinct q \<and> set q = set rest) = set rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1748
      proof(rule someI2)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1749
        from wq_distinct[OF step_back_vt[OF vtv], of cs] and eq_wq
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1750
        show "distinct rest \<and> set rest = set rest" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1751
      next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1752
        show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1753
          by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1754
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1755
      show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1756
      proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1757
        { assume eq_th: "th = thread"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1758
          from eq_th have eq_cnp: "cntP (e # s) th = cntP s th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1759
            by (unfold eq_e, simp add:cntP_def count_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1760
          moreover from eq_th have eq_cnv: "cntV (e#s) th = 1 + cntV s th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1761
            by (unfold eq_e, simp add:cntV_def count_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1762
          moreover from cntCS_v_dec [OF vtv] 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1763
          have "cntCS (e # s) thread + 1 = cntCS s thread"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1764
            by (simp add:eq_e)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1765
          moreover from is_runing have rd_before: "thread \<in> readys s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1766
            by (unfold runing_def, simp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1767
          moreover have "thread \<in> readys (e # s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1768
          proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1769
            from is_runing
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1770
            have "thread \<in> threads (e#s)" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1771
              by (unfold eq_e, auto simp:runing_def readys_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1772
            moreover have "\<forall> cs1. \<not> waiting (e#s) thread cs1"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1773
            proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1774
              fix cs1
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1775
              { assume eq_cs: "cs1 = cs" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1776
                have "\<not> waiting (e # s) thread cs1"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1777
                proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1778
                  from eq_wq
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1779
                  have "thread \<notin> set (wq (e#s) cs1)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1780
                    apply(unfold eq_e wq_def eq_cs s_holding_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1781
                    apply (auto simp:Let_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1782
                  proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1783
                    assume "thread \<in> set (SOME q. distinct q \<and> set q = set rest)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1784
                    with eq_set have "thread \<in> set rest" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1785
                    with wq_distinct[OF step_back_vt[OF vtv], of cs]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1786
                    and eq_wq show False by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1787
                  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1788
                  thus ?thesis by (simp add:wq_def s_waiting_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1789
                qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1790
              } moreover {
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1791
                assume neq_cs: "cs1 \<noteq> cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1792
                  have "\<not> waiting (e # s) thread cs1" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1793
                  proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1794
                    from wq_v_neq [OF neq_cs[symmetric]]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1795
                    have "wq (V thread cs # s) cs1 = wq s cs1" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1796
                    moreover have "\<not> waiting s thread cs1" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1797
                    proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1798
                      from runing_ready and is_runing
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1799
                      have "thread \<in> readys s" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1800
                      thus ?thesis by (simp add:readys_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1801
                    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1802
                    ultimately show ?thesis 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1803
                      by (auto simp:wq_def s_waiting_def eq_e)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1804
                  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1805
              } ultimately show "\<not> waiting (e # s) thread cs1" by blast
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1806
            qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1807
            ultimately show ?thesis by (simp add:readys_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1808
          qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1809
          moreover note eq_th ih
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1810
          ultimately have ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1811
        } moreover {
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1812
          assume neq_th: "th \<noteq> thread"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1813
          from neq_th eq_e have eq_cnp: "cntP (e # s) th = cntP s th" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1814
            by (simp add:cntP_def count_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1815
          from neq_th eq_e have eq_cnv: "cntV (e # s) th = cntV s th" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1816
            by (simp add:cntV_def count_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1817
          have ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1818
          proof(cases "th \<in> set rest")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1819
            case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1820
            have "(th \<in> readys (e # s)) = (th \<in> readys s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1821
              apply (insert step_back_vt[OF vtv])
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1822
              by (unfold eq_e, rule readys_v_eq [OF _ neq_th eq_wq False], auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1823
            moreover have "cntCS (e#s) th = cntCS s th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1824
              apply (insert neq_th, unfold eq_e cntCS_def holdents_test step_RAG_v[OF vtv], auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1825
              proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1826
                have "{csa. (Cs csa, Th th) \<in> RAG s \<or> csa = cs \<and> next_th s thread cs th} =
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1827
                      {cs. (Cs cs, Th th) \<in> RAG s}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1828
                proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1829
                  from False eq_wq
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1830
                  have " next_th s thread cs th \<Longrightarrow> (Cs cs, Th th) \<in> RAG s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1831
                    apply (unfold next_th_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1832
                  proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1833
                    assume ne: "rest \<noteq> []"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1834
                      and ni: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1835
                      and eq_wq: "wq s cs = thread # rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1836
                    from eq_set ni have "hd (SOME q. distinct q \<and> set q = set rest) \<notin> 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1837
                                  set (SOME q. distinct q \<and> set q = set rest)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1838
                                  " by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1839
                    moreover have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1840
                    proof(rule someI2)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1841
                      from wq_distinct[OF step_back_vt[OF vtv], of cs] and eq_wq
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1842
                      show "distinct rest \<and> set rest = set rest" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1843
                    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1844
                      fix x assume "distinct x \<and> set x = set rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1845
                      with ne show "x \<noteq> []" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1846
                    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1847
                    ultimately show 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1848
                      "(Cs cs, Th (hd (SOME q. distinct q \<and> set q = set rest))) \<in> RAG s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1849
                      by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1850
                  qed    
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1851
                  thus ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1852
                qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1853
                thus "card {csa. (Cs csa, Th th) \<in> RAG s \<or> csa = cs \<and> next_th s thread cs th} =
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1854
                             card {cs. (Cs cs, Th th) \<in> RAG s}" by simp 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1855
              qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1856
            moreover note ih eq_cnp eq_cnv eq_threads
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1857
            ultimately show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1858
          next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1859
            case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1860
            assume th_in: "th \<in> set rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1861
            show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1862
            proof(cases "next_th s thread cs th")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1863
              case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1864
              with eq_wq and th_in have 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1865
                neq_hd: "th \<noteq> hd (SOME q. distinct q \<and> set q = set rest)" (is "th \<noteq> hd ?rest")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1866
                by (auto simp:next_th_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1867
              have "(th \<in> readys (e # s)) = (th \<in> readys s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1868
              proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1869
                from eq_wq and th_in
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1870
                have "\<not> th \<in> readys s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1871
                  apply (auto simp:readys_def s_waiting_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1872
                  apply (rule_tac x = cs in exI, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1873
                  by (insert wq_distinct[OF step_back_vt[OF vtv], of cs], auto simp add: wq_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1874
                moreover 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1875
                from eq_wq and th_in and neq_hd
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1876
                have "\<not> (th \<in> readys (e # s))"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1877
                  apply (auto simp:readys_def s_waiting_def eq_e wq_def Let_def split:list.splits)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1878
                  by (rule_tac x = cs in exI, auto simp:eq_set)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1879
                ultimately show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1880
              qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1881
              moreover have "cntCS (e#s) th = cntCS s th" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1882
              proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1883
                from eq_wq and  th_in and neq_hd
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1884
                have "(holdents (e # s) th) = (holdents s th)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1885
                  apply (unfold eq_e step_RAG_v[OF vtv], 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1886
                         auto simp:next_th_def eq_set s_RAG_def holdents_test wq_def
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1887
                                   Let_def cs_holding_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1888
                  by (insert wq_distinct[OF step_back_vt[OF vtv], of cs], auto simp:wq_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1889
                thus ?thesis by (simp add:cntCS_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1890
              qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1891
              moreover note ih eq_cnp eq_cnv eq_threads
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1892
              ultimately show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1893
            next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1894
              case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1895
              let ?rest = " (SOME q. distinct q \<and> set q = set rest)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1896
              let ?t = "hd ?rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1897
              from True eq_wq th_in neq_th
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1898
              have "th \<in> readys (e # s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1899
                apply (auto simp:eq_e readys_def s_waiting_def wq_def
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1900
                        Let_def next_th_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1901
              proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1902
                assume eq_wq: "wq_fun (schs s) cs = thread # rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1903
                  and t_in: "?t \<in> set rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1904
                show "?t \<in> threads s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1905
                proof(rule wq_threads[OF step_back_vt[OF vtv]])
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1906
                  from eq_wq and t_in
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1907
                  show "?t \<in> set (wq s cs)" by (auto simp:wq_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1908
                qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1909
              next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1910
                fix csa
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1911
                assume eq_wq: "wq_fun (schs s) cs = thread # rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1912
                  and t_in: "?t \<in> set rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1913
                  and neq_cs: "csa \<noteq> cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1914
                  and t_in': "?t \<in>  set (wq_fun (schs s) csa)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1915
                show "?t = hd (wq_fun (schs s) csa)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1916
                proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1917
                  { assume neq_hd': "?t \<noteq> hd (wq_fun (schs s) csa)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1918
                    from wq_distinct[OF step_back_vt[OF vtv], of cs] and 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1919
                    eq_wq[folded wq_def] and t_in eq_wq
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1920
                    have "?t \<noteq> thread" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1921
                    with eq_wq and t_in
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1922
                    have w1: "waiting s ?t cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1923
                      by (auto simp:s_waiting_def wq_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1924
                    from t_in' neq_hd'
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1925
                    have w2: "waiting s ?t csa"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1926
                      by (auto simp:s_waiting_def wq_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1927
                    from waiting_unique[OF step_back_vt[OF vtv] w1 w2]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1928
                    and neq_cs have "False" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1929
                  } thus ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1930
                qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1931
              qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1932
              moreover have "cntP s th = cntV s th + cntCS s th + 1"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1933
              proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1934
                have "th \<notin> readys s" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1935
                proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1936
                  from True eq_wq neq_th th_in
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1937
                  show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1938
                    apply (unfold readys_def s_waiting_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1939
                    by (rule_tac x = cs in exI, auto simp add: wq_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1940
                qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1941
                moreover have "th \<in> threads s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1942
                proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1943
                  from th_in eq_wq
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1944
                  have "th \<in> set (wq s cs)" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1945
                  from wq_threads [OF step_back_vt[OF vtv] this] 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1946
                  show ?thesis .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1947
                qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1948
                ultimately show ?thesis using ih by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1949
              qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1950
              moreover from True neq_th have "cntCS (e # s) th = 1 + cntCS s th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1951
                apply (unfold cntCS_def holdents_test eq_e step_RAG_v[OF vtv], auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1952
              proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1953
                show "card {csa. (Cs csa, Th th) \<in> RAG s \<or> csa = cs} =
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1954
                               Suc (card {cs. (Cs cs, Th th) \<in> RAG s})"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1955
                  (is "card ?A = Suc (card ?B)")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1956
                proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1957
                  have "?A = insert cs ?B" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1958
                  hence "card ?A = card (insert cs ?B)" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1959
                  also have "\<dots> = Suc (card ?B)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1960
                  proof(rule card_insert_disjoint)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1961
                    have "?B \<subseteq> ((\<lambda> (x, y). the_cs x) ` RAG s)" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1962
                      apply (auto simp:image_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1963
                      by (rule_tac x = "(Cs x, Th th)" in bexI, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1964
                    with finite_RAG[OF step_back_vt[OF vtv]]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1965
                    show "finite {cs. (Cs cs, Th th) \<in> RAG s}" by (auto intro:finite_subset)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1966
                  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1967
                    show "cs \<notin> {cs. (Cs cs, Th th) \<in> RAG s}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1968
                    proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1969
                      assume "cs \<in> {cs. (Cs cs, Th th) \<in> RAG s}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1970
                      hence "(Cs cs, Th th) \<in> RAG s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1971
                      with True neq_th eq_wq show False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1972
                        by (auto simp:next_th_def s_RAG_def cs_holding_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1973
                    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1974
                  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1975
                  finally show ?thesis .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1976
                qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1977
              qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1978
              moreover note eq_cnp eq_cnv
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1979
              ultimately show ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1980
            qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1981
          qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1982
        } ultimately show ?thesis by blast
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1983
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1984
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1985
      case (thread_set thread prio)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1986
      assume eq_e: "e = Set thread prio"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1987
        and is_runing: "thread \<in> runing s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1988
      show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1989
      proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1990
        from eq_e have eq_cnp: "cntP (e#s) th = cntP s th" by (simp add:cntP_def count_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1991
        from eq_e have eq_cnv: "cntV (e#s) th = cntV s th" by (simp add:cntV_def count_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1992
        have eq_cncs: "cntCS (e#s) th = cntCS s th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1993
          unfolding cntCS_def holdents_test
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1994
          by (simp add:RAG_set_unchanged eq_e)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1995
        from eq_e have eq_readys: "readys (e#s) = readys s" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1996
          by (simp add:readys_def cs_waiting_def s_waiting_def wq_def,
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1997
                  auto simp:Let_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1998
        { assume "th \<noteq> thread"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1999
          with eq_readys eq_e
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2000
          have "(th \<in> readys (e # s) \<or> th \<notin> threads (e # s)) = 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2001
                      (th \<in> readys (s) \<or> th \<notin> threads (s))" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2002
            by (simp add:threads.simps)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2003
          with eq_cnp eq_cnv eq_cncs ih is_runing
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2004
          have ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2005
        } moreover {
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2006
          assume eq_th: "th = thread"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2007
          with is_runing ih have " cntP s th  = cntV s th + cntCS s th" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2008
            by (unfold runing_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2009
          moreover from eq_th and eq_readys is_runing have "th \<in> readys (e#s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2010
            by (simp add:runing_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2011
          moreover note eq_cnp eq_cnv eq_cncs
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2012
          ultimately have ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2013
        } ultimately show ?thesis by blast
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2014
      qed   
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2015
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2016
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2017
    case vt_nil
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2018
    show ?case 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2019
      by (unfold cntP_def cntV_def cntCS_def, 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2020
        auto simp:count_def holdents_test s_RAG_def wq_def cs_holding_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2021
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2022
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2023
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2024
lemma not_thread_cncs:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2025
  fixes th s
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2026
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2027
  and not_in: "th \<notin> threads s" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2028
  shows "cntCS s th = 0"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2029
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2030
  from vt not_in show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2031
  proof(induct arbitrary:th)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2032
    case (vt_cons s e th)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2033
    assume vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2034
      and ih: "\<And>th. th \<notin> threads s \<Longrightarrow> cntCS s th = 0"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2035
      and stp: "step s e"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2036
      and not_in: "th \<notin> threads (e # s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2037
    from stp show ?case
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2038
    proof(cases)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2039
      case (thread_create thread prio)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2040
      assume eq_e: "e = Create thread prio"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2041
        and not_in': "thread \<notin> threads s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2042
      have "cntCS (e # s) th = cntCS s th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2043
        apply (unfold eq_e cntCS_def holdents_test)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2044
        by (simp add:RAG_create_unchanged)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2045
      moreover have "th \<notin> threads s" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2046
      proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2047
        from not_in eq_e show ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2048
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2049
      moreover note ih ultimately show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2050
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2051
      case (thread_exit thread)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2052
      assume eq_e: "e = Exit thread"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2053
      and nh: "holdents s thread = {}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2054
      have eq_cns: "cntCS (e # s) th = cntCS s th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2055
        apply (unfold eq_e cntCS_def holdents_test)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2056
        by (simp add:RAG_exit_unchanged)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2057
      show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2058
      proof(cases "th = thread")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2059
        case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2060
        have "cntCS s th = 0" by (unfold cntCS_def, auto simp:nh True)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2061
        with eq_cns show ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2062
      next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2063
        case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2064
        with not_in and eq_e
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2065
        have "th \<notin> threads s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2066
        from ih[OF this] and eq_cns show ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2067
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2068
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2069
      case (thread_P thread cs)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2070
      assume eq_e: "e = P thread cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2071
      and is_runing: "thread \<in> runing s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2072
      from assms thread_P ih vt stp thread_P have vtp: "vt (P thread cs#s)" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2073
      have neq_th: "th \<noteq> thread" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2074
      proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2075
        from not_in eq_e have "th \<notin> threads s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2076
        moreover from is_runing have "thread \<in> threads s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2077
          by (simp add:runing_def readys_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2078
        ultimately show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2079
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2080
      hence "cntCS (e # s) th  = cntCS s th "
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2081
        apply (unfold cntCS_def holdents_test eq_e)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2082
        by (unfold step_RAG_p[OF vtp], auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2083
      moreover have "cntCS s th = 0"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2084
      proof(rule ih)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2085
        from not_in eq_e show "th \<notin> threads s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2086
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2087
      ultimately show ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2088
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2089
      case (thread_V thread cs)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2090
      assume eq_e: "e = V thread cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2091
        and is_runing: "thread \<in> runing s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2092
        and hold: "holding s thread cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2093
      have neq_th: "th \<noteq> thread" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2094
      proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2095
        from not_in eq_e have "th \<notin> threads s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2096
        moreover from is_runing have "thread \<in> threads s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2097
          by (simp add:runing_def readys_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2098
        ultimately show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2099
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2100
      from assms thread_V vt stp ih have vtv: "vt (V thread cs#s)" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2101
      from hold obtain rest 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2102
        where eq_wq: "wq s cs = thread # rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2103
        by (case_tac "wq s cs", auto simp: wq_def s_holding_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2104
      from not_in eq_e eq_wq
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2105
      have "\<not> next_th s thread cs th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2106
        apply (auto simp:next_th_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2107
      proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2108
        assume ne: "rest \<noteq> []"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2109
          and ni: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> threads s" (is "?t \<notin> threads s")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2110
        have "?t \<in> set rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2111
        proof(rule someI2)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2112
          from wq_distinct[OF step_back_vt[OF vtv], of cs] and eq_wq
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2113
          show "distinct rest \<and> set rest = set rest" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2114
        next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2115
          fix x assume "distinct x \<and> set x = set rest" with ne
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2116
          show "hd x \<in> set rest" by (cases x, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2117
        qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2118
        with eq_wq have "?t \<in> set (wq s cs)" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2119
        from wq_threads[OF step_back_vt[OF vtv], OF this] and ni
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2120
        show False by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2121
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2122
      moreover note neq_th eq_wq
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2123
      ultimately have "cntCS (e # s) th  = cntCS s th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2124
        by (unfold eq_e cntCS_def holdents_test step_RAG_v[OF vtv], auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2125
      moreover have "cntCS s th = 0"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2126
      proof(rule ih)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2127
        from not_in eq_e show "th \<notin> threads s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2128
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2129
      ultimately show ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2130
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2131
      case (thread_set thread prio)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2132
      print_facts
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2133
      assume eq_e: "e = Set thread prio"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2134
        and is_runing: "thread \<in> runing s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2135
      from not_in and eq_e have "th \<notin> threads s" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2136
      from ih [OF this] and eq_e
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2137
      show ?thesis 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2138
        apply (unfold eq_e cntCS_def holdents_test)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2139
        by (simp add:RAG_set_unchanged)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2140
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2141
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2142
      case vt_nil
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2143
      show ?case
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2144
      by (unfold cntCS_def, 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2145
        auto simp:count_def holdents_test s_RAG_def wq_def cs_holding_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2146
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2147
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2148
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2149
lemma eq_waiting: "waiting (wq (s::state)) th cs = waiting s th cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2150
  by (auto simp:s_waiting_def cs_waiting_def wq_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2151
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2152
lemma dm_RAG_threads:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2153
  fixes th s
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2154
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2155
  and in_dom: "(Th th) \<in> Domain (RAG s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2156
  shows "th \<in> threads s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2157
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2158
  from in_dom obtain n where "(Th th, n) \<in> RAG s" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2159
  moreover from RAG_target_th[OF this] obtain cs where "n = Cs cs" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2160
  ultimately have "(Th th, Cs cs) \<in> RAG s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2161
  hence "th \<in> set (wq s cs)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2162
    by (unfold s_RAG_def, auto simp:cs_waiting_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2163
  from wq_threads [OF vt this] show ?thesis .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2164
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2165
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2166
lemma cp_eq_cpreced: "cp s th = cpreced (wq s) s th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2167
unfolding cp_def wq_def
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2168
apply(induct s rule: schs.induct)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2169
thm cpreced_initial
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2170
apply(simp add: Let_def cpreced_initial)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2171
apply(simp add: Let_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2172
apply(simp add: Let_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2173
apply(simp add: Let_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2174
apply(subst (2) schs.simps)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2175
apply(simp add: Let_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2176
apply(subst (2) schs.simps)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2177
apply(simp add: Let_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2178
done
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2179
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2180
(* FIXME: NOT NEEDED *)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2181
lemma runing_unique:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2182
  fixes th1 th2 s
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2183
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2184
  and runing_1: "th1 \<in> runing s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2185
  and runing_2: "th2 \<in> runing s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2186
  shows "th1 = th2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2187
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2188
  from runing_1 and runing_2 have "cp s th1 = cp s th2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2189
    unfolding runing_def
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2190
    apply(simp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2191
    done
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2192
  hence eq_max: "Max ((\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1)) =
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2193
                 Max ((\<lambda>th. preced th s) ` ({th2} \<union> dependants (wq s) th2))"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2194
    (is "Max (?f ` ?A) = Max (?f ` ?B)")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2195
    unfolding cp_eq_cpreced 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2196
    unfolding cpreced_def .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2197
  obtain th1' where th1_in: "th1' \<in> ?A" and eq_f_th1: "?f th1' = Max (?f ` ?A)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2198
  proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2199
    have h1: "finite (?f ` ?A)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2200
    proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2201
      have "finite ?A" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2202
      proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2203
        have "finite (dependants (wq s) th1)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2204
        proof-
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2205
          have "finite {th'. (Th th', Th th1) \<in> (RAG (wq s))\<^sup>+}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2206
          proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2207
            let ?F = "\<lambda> (x, y). the_th x"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2208
            have "{th'. (Th th', Th th1) \<in> (RAG (wq s))\<^sup>+} \<subseteq> ?F ` ((RAG (wq s))\<^sup>+)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2209
              apply (auto simp:image_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2210
              by (rule_tac x = "(Th x, Th th1)" in bexI, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2211
            moreover have "finite \<dots>"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2212
            proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2213
              from finite_RAG[OF vt] have "finite (RAG s)" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2214
              hence "finite ((RAG (wq s))\<^sup>+)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2215
                apply (unfold finite_trancl)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2216
                by (auto simp: s_RAG_def cs_RAG_def wq_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2217
              thus ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2218
            qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2219
            ultimately show ?thesis by (auto intro:finite_subset)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2220
          qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2221
          thus ?thesis by (simp add:cs_dependants_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2222
        qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2223
        thus ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2224
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2225
      thus ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2226
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2227
    moreover have h2: "(?f ` ?A) \<noteq> {}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2228
    proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2229
      have "?A \<noteq> {}" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2230
      thus ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2231
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2232
    from Max_in [OF h1 h2]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2233
    have "Max (?f ` ?A) \<in> (?f ` ?A)" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2234
    thus ?thesis 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2235
      thm cpreced_def
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2236
      unfolding cpreced_def[symmetric] 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2237
      unfolding cp_eq_cpreced[symmetric] 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2238
      unfolding cpreced_def 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2239
      using that[intro] by (auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2240
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2241
  obtain th2' where th2_in: "th2' \<in> ?B" and eq_f_th2: "?f th2' = Max (?f ` ?B)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2242
  proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2243
    have h1: "finite (?f ` ?B)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2244
    proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2245
      have "finite ?B" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2246
      proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2247
        have "finite (dependants (wq s) th2)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2248
        proof-
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2249
          have "finite {th'. (Th th', Th th2) \<in> (RAG (wq s))\<^sup>+}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2250
          proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2251
            let ?F = "\<lambda> (x, y). the_th x"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2252
            have "{th'. (Th th', Th th2) \<in> (RAG (wq s))\<^sup>+} \<subseteq> ?F ` ((RAG (wq s))\<^sup>+)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2253
              apply (auto simp:image_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2254
              by (rule_tac x = "(Th x, Th th2)" in bexI, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2255
            moreover have "finite \<dots>"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2256
            proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2257
              from finite_RAG[OF vt] have "finite (RAG s)" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2258
              hence "finite ((RAG (wq s))\<^sup>+)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2259
                apply (unfold finite_trancl)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2260
                by (auto simp: s_RAG_def cs_RAG_def wq_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2261
              thus ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2262
            qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2263
            ultimately show ?thesis by (auto intro:finite_subset)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2264
          qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2265
          thus ?thesis by (simp add:cs_dependants_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2266
        qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2267
        thus ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2268
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2269
      thus ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2270
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2271
    moreover have h2: "(?f ` ?B) \<noteq> {}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2272
    proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2273
      have "?B \<noteq> {}" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2274
      thus ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2275
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2276
    from Max_in [OF h1 h2]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2277
    have "Max (?f ` ?B) \<in> (?f ` ?B)" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2278
    thus ?thesis by (auto intro:that)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2279
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2280
  from eq_f_th1 eq_f_th2 eq_max 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2281
  have eq_preced: "preced th1' s = preced th2' s" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2282
  hence eq_th12: "th1' = th2'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2283
  proof (rule preced_unique)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2284
    from th1_in have "th1' = th1 \<or> (th1' \<in> dependants (wq s) th1)" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2285
    thus "th1' \<in> threads s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2286
    proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2287
      assume "th1' \<in> dependants (wq s) th1"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2288
      hence "(Th th1') \<in> Domain ((RAG s)^+)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2289
        apply (unfold cs_dependants_def cs_RAG_def s_RAG_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2290
        by (auto simp:Domain_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2291
      hence "(Th th1') \<in> Domain (RAG s)" by (simp add:trancl_domain)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2292
      from dm_RAG_threads[OF vt this] show ?thesis .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2293
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2294
      assume "th1' = th1"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2295
      with runing_1 show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2296
        by (unfold runing_def readys_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2297
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2298
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2299
    from th2_in have "th2' = th2 \<or> (th2' \<in> dependants (wq s) th2)" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2300
    thus "th2' \<in> threads s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2301
    proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2302
      assume "th2' \<in> dependants (wq s) th2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2303
      hence "(Th th2') \<in> Domain ((RAG s)^+)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2304
        apply (unfold cs_dependants_def cs_RAG_def s_RAG_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2305
        by (auto simp:Domain_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2306
      hence "(Th th2') \<in> Domain (RAG s)" by (simp add:trancl_domain)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2307
      from dm_RAG_threads[OF vt this] show ?thesis .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2308
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2309
      assume "th2' = th2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2310
      with runing_2 show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2311
        by (unfold runing_def readys_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2312
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2313
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2314
  from th1_in have "th1' = th1 \<or> th1' \<in> dependants (wq s) th1" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2315
  thus ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2316
  proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2317
    assume eq_th': "th1' = th1"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2318
    from th2_in have "th2' = th2 \<or> th2' \<in> dependants (wq s) th2" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2319
    thus ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2320
    proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2321
      assume "th2' = th2" thus ?thesis using eq_th' eq_th12 by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2322
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2323
      assume "th2' \<in> dependants (wq s) th2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2324
      with eq_th12 eq_th' have "th1 \<in> dependants (wq s) th2" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2325
      hence "(Th th1, Th th2) \<in> (RAG s)^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2326
        by (unfold cs_dependants_def s_RAG_def cs_RAG_def, simp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2327
      hence "Th th1 \<in> Domain ((RAG s)^+)" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2328
        apply (unfold cs_dependants_def cs_RAG_def s_RAG_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2329
        by (auto simp:Domain_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2330
      hence "Th th1 \<in> Domain (RAG s)" by (simp add:trancl_domain)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2331
      then obtain n where d: "(Th th1, n) \<in> RAG s" by (auto simp:Domain_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2332
      from RAG_target_th [OF this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2333
      obtain cs' where "n = Cs cs'" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2334
      with d have "(Th th1, Cs cs') \<in> RAG s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2335
      with runing_1 have "False"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2336
        apply (unfold runing_def readys_def s_RAG_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2337
        by (auto simp:eq_waiting)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2338
      thus ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2339
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2340
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2341
    assume th1'_in: "th1' \<in> dependants (wq s) th1"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2342
    from th2_in have "th2' = th2 \<or> th2' \<in> dependants (wq s) th2" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2343
    thus ?thesis 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2344
    proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2345
      assume "th2' = th2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2346
      with th1'_in eq_th12 have "th2 \<in> dependants (wq s) th1" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2347
      hence "(Th th2, Th th1) \<in> (RAG s)^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2348
        by (unfold cs_dependants_def s_RAG_def cs_RAG_def, simp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2349
      hence "Th th2 \<in> Domain ((RAG s)^+)" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2350
        apply (unfold cs_dependants_def cs_RAG_def s_RAG_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2351
        by (auto simp:Domain_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2352
      hence "Th th2 \<in> Domain (RAG s)" by (simp add:trancl_domain)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2353
      then obtain n where d: "(Th th2, n) \<in> RAG s" by (auto simp:Domain_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2354
      from RAG_target_th [OF this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2355
      obtain cs' where "n = Cs cs'" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2356
      with d have "(Th th2, Cs cs') \<in> RAG s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2357
      with runing_2 have "False"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2358
        apply (unfold runing_def readys_def s_RAG_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2359
        by (auto simp:eq_waiting)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2360
      thus ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2361
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2362
      assume "th2' \<in> dependants (wq s) th2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2363
      with eq_th12 have "th1' \<in> dependants (wq s) th2" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2364
      hence h1: "(Th th1', Th th2) \<in> (RAG s)^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2365
        by (unfold cs_dependants_def s_RAG_def cs_RAG_def, simp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2366
      from th1'_in have h2: "(Th th1', Th th1) \<in> (RAG s)^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2367
        by (unfold cs_dependants_def s_RAG_def cs_RAG_def, simp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2368
      show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2369
      proof(rule dchain_unique[OF vt h1 _ h2, symmetric])
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2370
        from runing_1 show "th1 \<in> readys s" by (simp add:runing_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2371
        from runing_2 show "th2 \<in> readys s" by (simp add:runing_def) 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2372
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2373
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2374
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2375
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2376
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2377
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2378
lemma "vt s \<Longrightarrow> card (runing s) \<le> 1"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2379
apply(subgoal_tac "finite (runing s)")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2380
prefer 2
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2381
apply (metis finite_nat_set_iff_bounded lessI runing_unique)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2382
apply(rule ccontr)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2383
apply(simp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2384
apply(case_tac "Suc (Suc 0) \<le> card (runing s)")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2385
apply(subst (asm) card_le_Suc_iff)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2386
apply(simp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2387
apply(auto)[1]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2388
apply (metis insertCI runing_unique)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2389
apply(auto) 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2390
done
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2391
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2392
lemma create_pre:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2393
  assumes stp: "step s e"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2394
  and not_in: "th \<notin> threads s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2395
  and is_in: "th \<in> threads (e#s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2396
  obtains prio where "e = Create th prio"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2397
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2398
  from assms  
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2399
  show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2400
  proof(cases)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2401
    case (thread_create thread prio)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2402
    with is_in not_in have "e = Create th prio" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2403
    from that[OF this] show ?thesis .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2404
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2405
    case (thread_exit thread)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2406
    with assms show ?thesis by (auto intro!:that)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2407
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2408
    case (thread_P thread)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2409
    with assms show ?thesis by (auto intro!:that)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2410
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2411
    case (thread_V thread)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2412
    with assms show ?thesis by (auto intro!:that)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2413
  next 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2414
    case (thread_set thread)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2415
    with assms show ?thesis by (auto intro!:that)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2416
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2417
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2418
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2419
lemma length_down_to_in: 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2420
  assumes le_ij: "i \<le> j"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2421
    and le_js: "j \<le> length s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2422
  shows "length (down_to j i s) = j - i"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2423
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2424
  have "length (down_to j i s) = length (from_to i j (rev s))"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2425
    by (unfold down_to_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2426
  also have "\<dots> = j - i"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2427
  proof(rule length_from_to_in[OF le_ij])
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2428
    from le_js show "j \<le> length (rev s)" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2429
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2430
  finally show ?thesis .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2431
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2432
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2433
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2434
lemma moment_head: 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2435
  assumes le_it: "Suc i \<le> length t"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2436
  obtains e where "moment (Suc i) t = e#moment i t"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2437
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2438
  have "i \<le> Suc i" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2439
  from length_down_to_in [OF this le_it]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2440
  have "length (down_to (Suc i) i t) = 1" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2441
  then obtain e where "down_to (Suc i) i t = [e]"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2442
    apply (cases "(down_to (Suc i) i t)") by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2443
  moreover have "down_to (Suc i) 0 t = down_to (Suc i) i t @ down_to i 0 t"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2444
    by (rule down_to_conc[symmetric], auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2445
  ultimately have eq_me: "moment (Suc i) t = e#(moment i t)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2446
    by (auto simp:down_to_moment)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2447
  from that [OF this] show ?thesis .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2448
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2449
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2450
lemma cnp_cnv_eq:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2451
  fixes th s
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2452
  assumes "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2453
  and "th \<notin> threads s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2454
  shows "cntP s th = cntV s th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2455
 by (simp add: assms(1) assms(2) cnp_cnv_cncs not_thread_cncs)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2456
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2457
lemma eq_RAG: 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2458
  "RAG (wq s) = RAG s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2459
by (unfold cs_RAG_def s_RAG_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2460
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2461
lemma count_eq_dependants:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2462
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2463
  and eq_pv: "cntP s th = cntV s th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2464
  shows "dependants (wq s) th = {}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2465
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2466
  from cnp_cnv_cncs[OF vt] and eq_pv
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2467
  have "cntCS s th = 0" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2468
    by (auto split:if_splits)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2469
  moreover have "finite {cs. (Cs cs, Th th) \<in> RAG s}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2470
  proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2471
    from finite_holding[OF vt, of th] show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2472
      by (simp add:holdents_test)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2473
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2474
  ultimately have h: "{cs. (Cs cs, Th th) \<in> RAG s} = {}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2475
    by (unfold cntCS_def holdents_test cs_dependants_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2476
  show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2477
  proof(unfold cs_dependants_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2478
    { assume "{th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+} \<noteq> {}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2479
      then obtain th' where "(Th th', Th th) \<in> (RAG (wq s))\<^sup>+" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2480
      hence "False"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2481
      proof(cases)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2482
        assume "(Th th', Th th) \<in> RAG (wq s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2483
        thus "False" by (auto simp:cs_RAG_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2484
      next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2485
        fix c
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2486
        assume "(c, Th th) \<in> RAG (wq s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2487
        with h and eq_RAG show "False"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2488
          by (cases c, auto simp:cs_RAG_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2489
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2490
    } thus "{th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+} = {}" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2491
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2492
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2493
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2494
lemma dependants_threads:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2495
  fixes s th
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2496
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2497
  shows "dependants (wq s) th \<subseteq> threads s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2498
proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2499
  { fix th th'
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2500
    assume h: "th \<in> {th'a. (Th th'a, Th th') \<in> (RAG (wq s))\<^sup>+}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2501
    have "Th th \<in> Domain (RAG s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2502
    proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2503
      from h obtain th' where "(Th th, Th th') \<in> (RAG (wq s))\<^sup>+" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2504
      hence "(Th th) \<in> Domain ( (RAG (wq s))\<^sup>+)" by (auto simp:Domain_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2505
      with trancl_domain have "(Th th) \<in> Domain (RAG (wq s))" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2506
      thus ?thesis using eq_RAG by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2507
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2508
    from dm_RAG_threads[OF vt this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2509
    have "th \<in> threads s" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2510
  } note hh = this
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2511
  fix th1 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2512
  assume "th1 \<in> dependants (wq s) th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2513
  hence "th1 \<in> {th'a. (Th th'a, Th th) \<in> (RAG (wq s))\<^sup>+}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2514
    by (unfold cs_dependants_def, simp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2515
  from hh [OF this] show "th1 \<in> threads s" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2516
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2517
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2518
lemma finite_threads:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2519
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2520
  shows "finite (threads s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2521
using vt
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2522
by (induct) (auto elim: step.cases)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2523
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2524
lemma Max_f_mono:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2525
  assumes seq: "A \<subseteq> B"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2526
  and np: "A \<noteq> {}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2527
  and fnt: "finite B"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2528
  shows "Max (f ` A) \<le> Max (f ` B)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2529
proof(rule Max_mono)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2530
  from seq show "f ` A \<subseteq> f ` B" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2531
next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2532
  from np show "f ` A \<noteq> {}" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2533
next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2534
  from fnt and seq show "finite (f ` B)" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2535
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2536
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2537
lemma cp_le:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2538
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2539
  and th_in: "th \<in> threads s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2540
  shows "cp s th \<le> Max ((\<lambda> th. (preced th s)) ` threads s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2541
proof(unfold cp_eq_cpreced cpreced_def cs_dependants_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2542
  show "Max ((\<lambda>th. preced th s) ` ({th} \<union> {th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+}))
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2543
         \<le> Max ((\<lambda>th. preced th s) ` threads s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2544
    (is "Max (?f ` ?A) \<le> Max (?f ` ?B)")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2545
  proof(rule Max_f_mono)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2546
    show "{th} \<union> {th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+} \<noteq> {}" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2547
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2548
    from finite_threads [OF vt]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2549
    show "finite (threads s)" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2550
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2551
    from th_in
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2552
    show "{th} \<union> {th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+} \<subseteq> threads s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2553
      apply (auto simp:Domain_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2554
      apply (rule_tac dm_RAG_threads[OF vt])
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2555
      apply (unfold trancl_domain [of "RAG s", symmetric])
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2556
      by (unfold cs_RAG_def s_RAG_def, auto simp:Domain_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2557
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2558
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2559
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2560
lemma le_cp:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2561
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2562
  shows "preced th s \<le> cp s th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2563
proof(unfold cp_eq_cpreced preced_def cpreced_def, simp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2564
  show "Prc (priority th s) (last_set th s)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2565
    \<le> Max (insert (Prc (priority th s) (last_set th s))
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2566
            ((\<lambda>th. Prc (priority th s) (last_set th s)) ` dependants (wq s) th))"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2567
    (is "?l \<le> Max (insert ?l ?A)")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2568
  proof(cases "?A = {}")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2569
    case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2570
    have "finite ?A" (is "finite (?f ` ?B)")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2571
    proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2572
      have "finite ?B" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2573
      proof-
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2574
        have "finite {th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2575
        proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2576
          let ?F = "\<lambda> (x, y). the_th x"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2577
          have "{th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+} \<subseteq> ?F ` ((RAG (wq s))\<^sup>+)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2578
            apply (auto simp:image_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2579
            by (rule_tac x = "(Th x, Th th)" in bexI, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2580
          moreover have "finite \<dots>"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2581
          proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2582
            from finite_RAG[OF vt] have "finite (RAG s)" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2583
            hence "finite ((RAG (wq s))\<^sup>+)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2584
              apply (unfold finite_trancl)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2585
              by (auto simp: s_RAG_def cs_RAG_def wq_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2586
            thus ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2587
          qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2588
          ultimately show ?thesis by (auto intro:finite_subset)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2589
        qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2590
        thus ?thesis by (simp add:cs_dependants_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2591
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2592
      thus ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2593
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2594
    from Max_insert [OF this False, of ?l] show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2595
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2596
    case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2597
    thus ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2598
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2599
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2600
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2601
lemma max_cp_eq: 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2602
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2603
  shows "Max ((cp s) ` threads s) = Max ((\<lambda> th. (preced th s)) ` threads s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2604
  (is "?l = ?r")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2605
proof(cases "threads s = {}")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2606
  case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2607
  thus ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2608
next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2609
  case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2610
  have "?l \<in> ((cp s) ` threads s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2611
  proof(rule Max_in)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2612
    from finite_threads[OF vt] 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2613
    show "finite (cp s ` threads s)" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2614
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2615
    from False show "cp s ` threads s \<noteq> {}" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2616
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2617
  then obtain th 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2618
    where th_in: "th \<in> threads s" and eq_l: "?l = cp s th" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2619
  have "\<dots> \<le> ?r" by (rule cp_le[OF vt th_in])
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2620
  moreover have "?r \<le> cp s th" (is "Max (?f ` ?A) \<le> cp s th")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2621
  proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2622
    have "?r \<in> (?f ` ?A)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2623
    proof(rule Max_in)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2624
      from finite_threads[OF vt]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2625
      show " finite ((\<lambda>th. preced th s) ` threads s)" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2626
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2627
      from False show " (\<lambda>th. preced th s) ` threads s \<noteq> {}" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2628
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2629
    then obtain th' where 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2630
      th_in': "th' \<in> ?A " and eq_r: "?r = ?f th'" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2631
    from le_cp [OF vt, of th']  eq_r
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2632
    have "?r \<le> cp s th'" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2633
    moreover have "\<dots> \<le> cp s th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2634
    proof(fold eq_l)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2635
      show " cp s th' \<le> Max (cp s ` threads s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2636
      proof(rule Max_ge)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2637
        from th_in' show "cp s th' \<in> cp s ` threads s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2638
          by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2639
      next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2640
        from finite_threads[OF vt]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2641
        show "finite (cp s ` threads s)" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2642
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2643
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2644
    ultimately show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2645
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2646
  ultimately show ?thesis using eq_l by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2647
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2648
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2649
lemma max_cp_readys_threads_pre:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2650
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2651
  and np: "threads s \<noteq> {}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2652
  shows "Max (cp s ` readys s) = Max (cp s ` threads s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2653
proof(unfold max_cp_eq[OF vt])
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2654
  show "Max (cp s ` readys s) = Max ((\<lambda>th. preced th s) ` threads s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2655
  proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2656
    let ?p = "Max ((\<lambda>th. preced th s) ` threads s)" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2657
    let ?f = "(\<lambda>th. preced th s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2658
    have "?p \<in> ((\<lambda>th. preced th s) ` threads s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2659
    proof(rule Max_in)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2660
      from finite_threads[OF vt] show "finite (?f ` threads s)" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2661
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2662
      from np show "?f ` threads s \<noteq> {}" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2663
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2664
    then obtain tm where tm_max: "?f tm = ?p" and tm_in: "tm \<in> threads s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2665
      by (auto simp:Image_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2666
    from th_chain_to_ready [OF vt tm_in]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2667
    have "tm \<in> readys s \<or> (\<exists>th'. th' \<in> readys s \<and> (Th tm, Th th') \<in> (RAG s)\<^sup>+)" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2668
    thus ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2669
    proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2670
      assume "\<exists>th'. th' \<in> readys s \<and> (Th tm, Th th') \<in> (RAG s)\<^sup>+ "
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2671
      then obtain th' where th'_in: "th' \<in> readys s" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2672
        and tm_chain:"(Th tm, Th th') \<in> (RAG s)\<^sup>+" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2673
      have "cp s th' = ?f tm"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2674
      proof(subst cp_eq_cpreced, subst cpreced_def, rule Max_eqI)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2675
        from dependants_threads[OF vt] finite_threads[OF vt]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2676
        show "finite ((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th'))" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2677
          by (auto intro:finite_subset)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2678
      next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2679
        fix p assume p_in: "p \<in> (\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2680
        from tm_max have " preced tm s = Max ((\<lambda>th. preced th s) ` threads s)" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2681
        moreover have "p \<le> \<dots>"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2682
        proof(rule Max_ge)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2683
          from finite_threads[OF vt]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2684
          show "finite ((\<lambda>th. preced th s) ` threads s)" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2685
        next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2686
          from p_in and th'_in and dependants_threads[OF vt, of th']
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2687
          show "p \<in> (\<lambda>th. preced th s) ` threads s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2688
            by (auto simp:readys_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2689
        qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2690
        ultimately show "p \<le> preced tm s" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2691
      next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2692
        show "preced tm s \<in> (\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2693
        proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2694
          from tm_chain
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2695
          have "tm \<in> dependants (wq s) th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2696
            by (unfold cs_dependants_def s_RAG_def cs_RAG_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2697
          thus ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2698
        qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2699
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2700
      with tm_max
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2701
      have h: "cp s th' = Max ((\<lambda>th. preced th s) ` threads s)" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2702
      show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2703
      proof (fold h, rule Max_eqI)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2704
        fix q 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2705
        assume "q \<in> cp s ` readys s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2706
        then obtain th1 where th1_in: "th1 \<in> readys s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2707
          and eq_q: "q = cp s th1" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2708
        show "q \<le> cp s th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2709
          apply (unfold h eq_q)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2710
          apply (unfold cp_eq_cpreced cpreced_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2711
          apply (rule Max_mono)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2712
        proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2713
          from dependants_threads [OF vt, of th1] th1_in
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2714
          show "(\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1) \<subseteq> 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2715
                 (\<lambda>th. preced th s) ` threads s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2716
            by (auto simp:readys_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2717
        next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2718
          show "(\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1) \<noteq> {}" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2719
        next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2720
          from finite_threads[OF vt] 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2721
          show " finite ((\<lambda>th. preced th s) ` threads s)" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2722
        qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2723
      next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2724
        from finite_threads[OF vt]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2725
        show "finite (cp s ` readys s)" by (auto simp:readys_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2726
      next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2727
        from th'_in
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2728
        show "cp s th' \<in> cp s ` readys s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2729
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2730
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2731
      assume tm_ready: "tm \<in> readys s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2732
      show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2733
      proof(fold tm_max)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2734
        have cp_eq_p: "cp s tm = preced tm s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2735
        proof(unfold cp_eq_cpreced cpreced_def, rule Max_eqI)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2736
          fix y 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2737
          assume hy: "y \<in> (\<lambda>th. preced th s) ` ({tm} \<union> dependants (wq s) tm)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2738
          show "y \<le> preced tm s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2739
          proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2740
            { fix y'
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2741
              assume hy' : "y' \<in> ((\<lambda>th. preced th s) ` dependants (wq s) tm)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2742
              have "y' \<le> preced tm s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2743
              proof(unfold tm_max, rule Max_ge)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2744
                from hy' dependants_threads[OF vt, of tm]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2745
                show "y' \<in> (\<lambda>th. preced th s) ` threads s" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2746
              next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2747
                from finite_threads[OF vt] 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2748
                show "finite ((\<lambda>th. preced th s) ` threads s)" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2749
              qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2750
            } with hy show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2751
          qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2752
        next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2753
          from dependants_threads[OF vt, of tm] finite_threads[OF vt]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2754
          show "finite ((\<lambda>th. preced th s) ` ({tm} \<union> dependants (wq s) tm))"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2755
            by (auto intro:finite_subset)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2756
        next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2757
          show "preced tm s \<in> (\<lambda>th. preced th s) ` ({tm} \<union> dependants (wq s) tm)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2758
            by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2759
        qed 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2760
        moreover have "Max (cp s ` readys s) = cp s tm"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2761
        proof(rule Max_eqI)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2762
          from tm_ready show "cp s tm \<in> cp s ` readys s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2763
        next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2764
          from finite_threads[OF vt]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2765
          show "finite (cp s ` readys s)" by (auto simp:readys_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2766
        next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2767
          fix y assume "y \<in> cp s ` readys s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2768
          then obtain th1 where th1_readys: "th1 \<in> readys s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2769
            and h: "y = cp s th1" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2770
          show "y \<le> cp s tm"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2771
            apply(unfold cp_eq_p h)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2772
            apply(unfold cp_eq_cpreced cpreced_def tm_max, rule Max_mono)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2773
          proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2774
            from finite_threads[OF vt]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2775
            show "finite ((\<lambda>th. preced th s) ` threads s)" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2776
          next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2777
            show "(\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1) \<noteq> {}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2778
              by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2779
          next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2780
            from dependants_threads[OF vt, of th1] th1_readys
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2781
            show "(\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1) 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2782
                    \<subseteq> (\<lambda>th. preced th s) ` threads s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2783
              by (auto simp:readys_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2784
          qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2785
        qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2786
        ultimately show " Max (cp s ` readys s) = preced tm s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2787
      qed 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2788
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2789
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2790
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2791
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2792
text {* (* ccc *) \noindent
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2793
  Since the current precedence of the threads in ready queue will always be boosted,
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2794
  there must be one inside it has the maximum precedence of the whole system. 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2795
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2796
lemma max_cp_readys_threads:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2797
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2798
  shows "Max (cp s ` readys s) = Max (cp s ` threads s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2799
proof(cases "threads s = {}")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2800
  case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2801
  thus ?thesis 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2802
    by (auto simp:readys_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2803
next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2804
  case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2805
  show ?thesis by (rule max_cp_readys_threads_pre[OF vt False])
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2806
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2807
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2808
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2809
lemma eq_holding: "holding (wq s) th cs = holding s th cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2810
  apply (unfold s_holding_def cs_holding_def wq_def, simp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2811
  done
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2812
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2813
lemma f_image_eq:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2814
  assumes h: "\<And> a. a \<in> A \<Longrightarrow> f a = g a"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2815
  shows "f ` A = g ` A"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2816
proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2817
  show "f ` A \<subseteq> g ` A"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2818
    by(rule image_subsetI, auto intro:h)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2819
next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2820
  show "g ` A \<subseteq> f ` A"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2821
   by (rule image_subsetI, auto intro:h[symmetric])
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2822
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2823
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2824
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2825
definition detached :: "state \<Rightarrow> thread \<Rightarrow> bool"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2826
  where "detached s th \<equiv> (\<not>(\<exists> cs. holding s th cs)) \<and> (\<not>(\<exists>cs. waiting s th cs))"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2827
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2828
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2829
lemma detached_test:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2830
  shows "detached s th = (Th th \<notin> Field (RAG s))"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2831
apply(simp add: detached_def Field_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2832
apply(simp add: s_RAG_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2833
apply(simp add: s_holding_abv s_waiting_abv)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2834
apply(simp add: Domain_iff Range_iff)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2835
apply(simp add: wq_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2836
apply(auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2837
done
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2838
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2839
lemma detached_intro:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2840
  fixes s th
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2841
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2842
  and eq_pv: "cntP s th = cntV s th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2843
  shows "detached s th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2844
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2845
 from cnp_cnv_cncs[OF vt]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2846
  have eq_cnt: "cntP s th =
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2847
    cntV s th + (if th \<in> readys s \<or> th \<notin> threads s then cntCS s th else cntCS s th + 1)" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2848
  hence cncs_zero: "cntCS s th = 0"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2849
    by (auto simp:eq_pv split:if_splits)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2850
  with eq_cnt
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2851
  have "th \<in> readys s \<or> th \<notin> threads s" by (auto simp:eq_pv)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2852
  thus ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2853
  proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2854
    assume "th \<notin> threads s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2855
    with range_in[OF vt] dm_RAG_threads[OF vt]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2856
    show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2857
      by (auto simp add: detached_def s_RAG_def s_waiting_abv s_holding_abv wq_def Domain_iff Range_iff)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2858
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2859
    assume "th \<in> readys s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2860
    moreover have "Th th \<notin> Range (RAG s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2861
    proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2862
      from card_0_eq [OF finite_holding [OF vt]] and cncs_zero
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2863
      have "holdents s th = {}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2864
        by (simp add:cntCS_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2865
      thus ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2866
        apply(auto simp:holdents_test)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2867
        apply(case_tac a)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2868
        apply(auto simp:holdents_test s_RAG_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2869
        done
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2870
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2871
    ultimately show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2872
      by (auto simp add: detached_def s_RAG_def s_waiting_abv s_holding_abv wq_def readys_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2873
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2874
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2875
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2876
lemma detached_elim:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2877
  fixes s th
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2878
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2879
  and dtc: "detached s th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2880
  shows "cntP s th = cntV s th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2881
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2882
  from cnp_cnv_cncs[OF vt]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2883
  have eq_pv: " cntP s th =
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2884
    cntV s th + (if th \<in> readys s \<or> th \<notin> threads s then cntCS s th else cntCS s th + 1)" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2885
  have cncs_z: "cntCS s th = 0"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2886
  proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2887
    from dtc have "holdents s th = {}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2888
      unfolding detached_def holdents_test s_RAG_def
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2889
      by (simp add: s_waiting_abv wq_def s_holding_abv Domain_iff Range_iff)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2890
    thus ?thesis by (auto simp:cntCS_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2891
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2892
  show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2893
  proof(cases "th \<in> threads s")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2894
    case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2895
    with dtc 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2896
    have "th \<in> readys s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2897
      by (unfold readys_def detached_def Field_def Domain_def Range_def, 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2898
           auto simp:eq_waiting s_RAG_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2899
    with cncs_z and eq_pv show ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2900
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2901
    case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2902
    with cncs_z and eq_pv show ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2903
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2904
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2905
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2906
lemma detached_eq:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2907
  fixes s th
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2908
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2909
  shows "(detached s th) = (cntP s th = cntV s th)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2910
  by (insert vt, auto intro:detached_intro detached_elim)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2911
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2912
text {* 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2913
  The lemmas in this .thy file are all obvious lemmas, however, they still needs to be derived
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2914
  from the concise and miniature model of PIP given in PrioGDef.thy.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2915
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2916
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  2917
end