ExtGG.thy
author zhangx
Thu, 28 Jan 2016 16:36:46 +0800
changeset 89 2056d9f481e2
parent 88 83dd5345d5d0
child 105 0c89419b4742
permissions -rw-r--r--
Slightly modified ExtGG.thy and PrioG.thy.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
85
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
     1
section {*
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
     2
  This file contains lemmas used to guide the recalculation of current precedence 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
     3
  after every system call (or system operation)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
     4
*}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
     5
theory ExtGG
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
     6
imports CpsG
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
     7
begin
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
     8
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
     9
text {* (* ddd *)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    10
  One beauty of our modelling is that we follow the definitional extension tradition of HOL.
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    11
  The benefit of such a concise and miniature model is that  large number of intuitively 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    12
  obvious facts are derived as lemmas, rather than asserted as axioms.
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    13
*}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    14
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    15
text {*
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    16
  However, the lemmas in the forthcoming several locales are no longer 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    17
  obvious. These lemmas show how the current precedences should be recalculated 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    18
  after every execution step (in our model, every step is represented by an event, 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    19
  which in turn, represents a system call, or operation). Each operation is 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    20
  treated in a separate locale.
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    21
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    22
  The complication of current precedence recalculation comes 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    23
  because the changing of RAG needs to be taken into account, 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    24
  in addition to the changing of precedence. 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    25
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    26
  The reason RAG changing affects current precedence is that,
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    27
  according to the definition, current precedence 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    28
  of a thread is the maximum of the precedences of every threads in its subtree, 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    29
  where the notion of sub-tree in RAG is defined in RTree.thy.
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    30
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    31
  Therefore, for each operation, lemmas about the change of precedences 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    32
  and RAG are derived first, on which lemmas about current precedence 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    33
  recalculation are based on.
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    34
*}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    35
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    36
section {* The @{term Set} operation *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    37
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    38
context valid_trace_set
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    39
begin
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    40
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    41
text {* (* ddd *)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    42
  The following two lemmas confirm that @{text "Set"}-operation
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    43
  only changes the precedence of the initiating thread (or actor)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    44
  of the operation (or event).
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    45
*}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    46
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    47
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    48
lemma eq_preced:
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    49
  assumes "th' \<noteq> th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    50
  shows "preced th' (e#s) = preced th' s"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    51
proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    52
  from assms show ?thesis 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    53
    by (unfold is_set, auto simp:preced_def)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    54
qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    55
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    56
lemma eq_the_preced: 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    57
  assumes "th' \<noteq> th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    58
  shows "the_preced (e#s) th' = the_preced s th'"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    59
  using assms
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    60
  by (unfold the_preced_def, intro eq_preced, simp)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    61
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    62
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    63
text {* (* ddd *)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    64
  Th following lemma @{text "eq_cp_pre"} says that the priority change of @{text "th"}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    65
  only affects those threads, which as @{text "Th th"} in their sub-trees.
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    66
  
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    67
  The proof of this lemma is simplified by using the alternative definition 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    68
  of @{text "cp"}. 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    69
*}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    70
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    71
lemma eq_cp_pre:
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    72
  assumes nd: "Th th \<notin> subtree (RAG s) (Th th')"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    73
  shows "cp (e#s) th' = cp s th'"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    74
proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    75
  -- {* After unfolding using the alternative definition, elements 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    76
        affecting the @{term "cp"}-value of threads become explicit. 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    77
        We only need to prove the following: *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    78
  have "Max (the_preced (e#s) ` {th'a. Th th'a \<in> subtree (RAG (e#s)) (Th th')}) =
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    79
        Max (the_preced s ` {th'a. Th th'a \<in> subtree (RAG s) (Th th')})"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    80
        (is "Max (?f ` ?S1) = Max (?g ` ?S2)")
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    81
  proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    82
    -- {* The base sets are equal. *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    83
    have "?S1 = ?S2" using RAG_unchanged by simp
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    84
    -- {* The function values on the base set are equal as well. *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    85
    moreover have "\<forall> e \<in> ?S2. ?f e = ?g e"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    86
    proof
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    87
      fix th1
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    88
      assume "th1 \<in> ?S2"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    89
      with nd have "th1 \<noteq> th" by (auto)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    90
      from eq_the_preced[OF this]
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    91
      show "the_preced (e#s) th1 = the_preced s th1" .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    92
    qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    93
    -- {* Therefore, the image of the functions are equal. *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    94
    ultimately have "(?f ` ?S1) = (?g ` ?S2)" by (auto intro!:f_image_eq)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    95
    thus ?thesis by simp
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    96
  qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    97
  thus ?thesis by (simp add:cp_alt_def)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    98
qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    99
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   100
text {*
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   101
  The following lemma shows that @{term "th"} is not in the 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   102
  sub-tree of any other thread. 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   103
*}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   104
lemma th_in_no_subtree:
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   105
  assumes "th' \<noteq> th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   106
  shows "Th th \<notin> subtree (RAG s) (Th th')"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   107
proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   108
  from readys_in_no_subtree[OF th_ready_s assms(1)]
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   109
  show ?thesis by blast
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   110
qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   111
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   112
text {* 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   113
  By combining @{thm "eq_cp_pre"} and @{thm "th_in_no_subtree"}, 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   114
  it is obvious that the change of priority only affects the @{text "cp"}-value 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   115
  of the initiating thread @{text "th"}.
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   116
*}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   117
lemma eq_cp:
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   118
  assumes "th' \<noteq> th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   119
  shows "cp (e#s) th' = cp s th'"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   120
  by (rule eq_cp_pre[OF th_in_no_subtree[OF assms]])
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   121
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   122
end
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   123
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   124
section {* The @{term V} operation *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   125
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   126
text {*
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   127
  The following @{text "step_v_cps"} is the locale for @{text "V"}-operation.
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   128
*}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   129
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   130
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   131
context valid_trace_v
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   132
begin
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   133
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   134
lemma ancestors_th: "ancestors (RAG s) (Th th) = {}"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   135
proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   136
  from readys_root[OF th_ready_s]
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   137
  show ?thesis
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   138
  by (unfold root_def, simp)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   139
qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   140
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   141
lemma edge_of_th:
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   142
    "(Cs cs, Th th) \<in> RAG s" 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   143
proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   144
 from holding_th_cs_s
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   145
 show ?thesis 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   146
    by (unfold s_RAG_def holding_eq, auto)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   147
qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   148
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   149
lemma ancestors_cs: 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   150
  "ancestors (RAG s) (Cs cs) = {Th th}"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   151
proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   152
  have "ancestors (RAG s) (Cs cs) = ancestors (RAG s) (Th th)  \<union>  {Th th}"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   153
   by (rule rtree_RAG.ancestors_accum[OF edge_of_th])
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   154
  from this[unfolded ancestors_th] show ?thesis by simp
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   155
qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   156
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   157
end
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   158
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   159
text {*
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   160
  The following @{text "step_v_cps_nt"} is the sub-locale for @{text "V"}-operation, 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   161
  which represents the case when there is another thread @{text "th'"}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   162
  to take over the critical resource released by the initiating thread @{text "th"}.
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   163
*}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   164
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   165
context valid_trace_v_n
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   166
begin
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   167
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   168
lemma sub_RAGs': 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   169
  "{(Cs cs, Th th), (Th taker, Cs cs)} \<subseteq> RAG s"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   170
     using next_th_RAG[OF next_th_taker]  .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   171
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   172
lemma ancestors_th': 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   173
  "ancestors (RAG s) (Th taker) = {Th th, Cs cs}" 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   174
proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   175
  have "ancestors (RAG s) (Th taker) = ancestors (RAG s) (Cs cs) \<union> {Cs cs}"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   176
  proof(rule  rtree_RAG.ancestors_accum)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   177
    from sub_RAGs' show "(Th taker, Cs cs) \<in> RAG s" by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   178
  qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   179
  thus ?thesis using ancestors_th ancestors_cs by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   180
qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   181
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   182
lemma RAG_s:
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   183
  "RAG (e#s) = (RAG s - {(Cs cs, Th th), (Th taker, Cs cs)}) \<union>
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   184
                                         {(Cs cs, Th taker)}"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   185
 by (unfold RAG_es waiting_set_eq holding_set_eq, auto)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   186
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   187
lemma subtree_kept: (* ddd *)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   188
  assumes "th1 \<notin> {th, taker}"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   189
  shows "subtree (RAG (e#s)) (Th th1) = 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   190
                     subtree (RAG s) (Th th1)" (is "_ = ?R")
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   191
proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   192
  let ?RAG' = "(RAG s - {(Cs cs, Th th), (Th taker, Cs cs)})"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   193
  let ?RAG'' = "?RAG' \<union> {(Cs cs, Th taker)}"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   194
  have "subtree ?RAG' (Th th1) = ?R" 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   195
  proof(rule subset_del_subtree_outside)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   196
    show "Range {(Cs cs, Th th), (Th taker, Cs cs)} \<inter> subtree (RAG s) (Th th1) = {}"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   197
    proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   198
      have "(Th th) \<notin> subtree (RAG s) (Th th1)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   199
      proof(rule subtree_refute)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   200
        show "Th th1 \<notin> ancestors (RAG s) (Th th)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   201
          by (unfold ancestors_th, simp)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   202
      next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   203
        from assms show "Th th1 \<noteq> Th th" by simp
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   204
      qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   205
      moreover have "(Cs cs) \<notin>  subtree (RAG s) (Th th1)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   206
      proof(rule subtree_refute)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   207
        show "Th th1 \<notin> ancestors (RAG s) (Cs cs)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   208
          by (unfold ancestors_cs, insert assms, auto)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   209
      qed simp
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   210
      ultimately have "{Th th, Cs cs} \<inter> subtree (RAG s) (Th th1) = {}" by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   211
      thus ?thesis by simp
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   212
     qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   213
  qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   214
  moreover have "subtree ?RAG'' (Th th1) =  subtree ?RAG' (Th th1)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   215
  proof(rule subtree_insert_next)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   216
    show "Th taker \<notin> subtree (RAG s - {(Cs cs, Th th), (Th taker, Cs cs)}) (Th th1)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   217
    proof(rule subtree_refute)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   218
      show "Th th1 \<notin> ancestors (RAG s - {(Cs cs, Th th), (Th taker, Cs cs)}) (Th taker)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   219
            (is "_ \<notin> ?R")
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   220
      proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   221
          have "?R \<subseteq> ancestors (RAG s) (Th taker)" by (rule ancestors_mono, auto)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   222
          moreover have "Th th1 \<notin> ..." using ancestors_th' assms by simp
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   223
          ultimately show ?thesis by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   224
      qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   225
    next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   226
      from assms show "Th th1 \<noteq> Th taker" by simp
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   227
    qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   228
  qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   229
  ultimately show ?thesis by (unfold RAG_s, simp)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   230
qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   231
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   232
lemma cp_kept:
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   233
  assumes "th1 \<notin> {th, taker}"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   234
  shows "cp (e#s) th1 = cp s th1"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   235
    by (unfold cp_alt_def the_preced_es subtree_kept[OF assms], simp)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   236
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   237
end
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   238
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   239
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   240
context valid_trace_v_e
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   241
begin
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   242
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   243
find_theorems RAG s e
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   244
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   245
lemma RAG_s: "RAG (e#s) = RAG s - {(Cs cs, Th th)}"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   246
  by (unfold RAG_es waiting_set_eq holding_set_eq, simp)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   247
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   248
lemma subtree_kept:
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   249
  assumes "th1 \<noteq> th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   250
  shows "subtree (RAG (e#s)) (Th th1) = subtree (RAG s) (Th th1)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   251
proof(unfold RAG_s, rule subset_del_subtree_outside)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   252
  show "Range {(Cs cs, Th th)} \<inter> subtree (RAG s) (Th th1) = {}"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   253
  proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   254
    have "(Th th) \<notin> subtree (RAG s) (Th th1)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   255
    proof(rule subtree_refute)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   256
      show "Th th1 \<notin> ancestors (RAG s) (Th th)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   257
          by (unfold ancestors_th, simp)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   258
    next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   259
      from assms show "Th th1 \<noteq> Th th" by simp
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   260
    qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   261
    thus ?thesis by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   262
  qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   263
qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   264
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   265
lemma cp_kept_1:
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   266
  assumes "th1 \<noteq> th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   267
  shows "cp (e#s) th1 = cp s th1"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   268
    by (unfold cp_alt_def the_preced_es subtree_kept[OF assms], simp)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   269
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   270
lemma subtree_cs: "subtree (RAG s) (Cs cs) = {Cs cs}"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   271
proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   272
  { fix n
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   273
    have "(Cs cs) \<notin> ancestors (RAG s) n"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   274
    proof
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   275
      assume "Cs cs \<in> ancestors (RAG s) n"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   276
      hence "(n, Cs cs) \<in> (RAG s)^+" by (auto simp:ancestors_def)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   277
      from tranclE[OF this] obtain nn where h: "(nn, Cs cs) \<in> RAG s" by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   278
      then obtain th' where "nn = Th th'"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   279
        by (unfold s_RAG_def, auto)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   280
      from h[unfolded this] have "(Th th', Cs cs) \<in> RAG s" .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   281
      from this[unfolded s_RAG_def]
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   282
      have "waiting (wq s) th' cs" by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   283
      from this[unfolded cs_waiting_def]
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   284
      have "1 < length (wq s cs)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   285
          by (cases "wq s cs", auto)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   286
      from holding_next_thI[OF holding_th_cs_s this]
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   287
      obtain th' where "next_th s th cs th'" by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   288
      thus False using no_taker by blast
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   289
    qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   290
  } note h = this
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   291
  {  fix n
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   292
     assume "n \<in> subtree (RAG s) (Cs cs)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   293
     hence "n = (Cs cs)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   294
     by (elim subtreeE, insert h, auto)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   295
  } moreover have "(Cs cs) \<in> subtree (RAG s) (Cs cs)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   296
      by (auto simp:subtree_def)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   297
  ultimately show ?thesis by auto 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   298
qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   299
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   300
lemma subtree_th: 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   301
  "subtree (RAG (e#s)) (Th th) = subtree (RAG s) (Th th) - {Cs cs}"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   302
proof(unfold RAG_s, fold subtree_cs, rule rtree_RAG.subtree_del_inside)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   303
  from edge_of_th
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   304
  show "(Cs cs, Th th) \<in> edges_in (RAG s) (Th th)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   305
    by (unfold edges_in_def, auto simp:subtree_def)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   306
qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   307
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   308
lemma cp_kept_2: 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   309
  shows "cp (e#s) th = cp s th" 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   310
 by (unfold cp_alt_def subtree_th the_preced_es, auto)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   311
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   312
lemma eq_cp:
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   313
  shows "cp (e#s) th' = cp s th'"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   314
  using cp_kept_1 cp_kept_2
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   315
  by (cases "th' = th", auto)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   316
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   317
end
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   318
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   319
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   320
section {* The @{term P} operation *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   321
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   322
context valid_trace_p
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   323
begin
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   324
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   325
lemma root_th: "root (RAG s) (Th th)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   326
  by (simp add: ready_th_s readys_root)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   327
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   328
lemma in_no_others_subtree:
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   329
  assumes "th' \<noteq> th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   330
  shows "Th th \<notin> subtree (RAG s) (Th th')"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   331
proof
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   332
  assume "Th th \<in> subtree (RAG s) (Th th')"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   333
  thus False
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   334
  proof(cases rule:subtreeE)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   335
    case 1
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   336
    with assms show ?thesis by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   337
  next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   338
    case 2
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   339
    with root_th show ?thesis by (auto simp:root_def)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   340
  qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   341
qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   342
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   343
lemma preced_kept: "the_preced (e#s) = the_preced s"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   344
proof
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   345
  fix th'
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   346
  show "the_preced (e # s) th' = the_preced s th'"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   347
    by (unfold the_preced_def is_p preced_def, simp)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   348
qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   349
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   350
end
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   351
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   352
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   353
context valid_trace_p_h
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   354
begin
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   355
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   356
lemma subtree_kept:
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   357
  assumes "th' \<noteq> th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   358
  shows "subtree (RAG (e#s)) (Th th') = subtree (RAG s) (Th th')"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   359
proof(unfold RAG_es, rule subtree_insert_next)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   360
  from in_no_others_subtree[OF assms] 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   361
  show "Th th \<notin> subtree (RAG s) (Th th')" .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   362
qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   363
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   364
lemma cp_kept: 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   365
  assumes "th' \<noteq> th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   366
  shows "cp (e#s) th' = cp s th'"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   367
proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   368
  have "(the_preced (e#s) ` {th'a. Th th'a \<in> subtree (RAG (e#s)) (Th th')}) =
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   369
        (the_preced s ` {th'a. Th th'a \<in> subtree (RAG s) (Th th')})"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   370
        by (unfold preced_kept subtree_kept[OF assms], simp)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   371
  thus ?thesis by (unfold cp_alt_def, simp)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   372
qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   373
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   374
end
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   375
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   376
context valid_trace_p_w
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   377
begin
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   378
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   379
interpretation vat_e: valid_trace "e#s"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   380
  by (unfold_locales, insert vt_e, simp)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   381
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   382
lemma cs_held: "(Cs cs, Th holder) \<in> RAG s"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   383
  using holding_s_holder
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   384
  by (unfold s_RAG_def, fold holding_eq, auto)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   385
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   386
lemma tRAG_s: 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   387
  "tRAG (e#s) = tRAG s \<union> {(Th th, Th holder)}"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   388
  using local.RAG_tRAG_transfer[OF RAG_es cs_held] .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   389
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   390
lemma cp_kept:
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   391
  assumes "Th th'' \<notin> ancestors (tRAG (e#s)) (Th th)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   392
  shows "cp (e#s) th'' = cp s th''"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   393
proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   394
  have h: "subtree (tRAG (e#s)) (Th th'') = subtree (tRAG s) (Th th'')"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   395
  proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   396
    have "Th holder \<notin> subtree (tRAG s) (Th th'')"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   397
    proof
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   398
      assume "Th holder \<in> subtree (tRAG s) (Th th'')"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   399
      thus False
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   400
      proof(rule subtreeE)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   401
         assume "Th holder = Th th''"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   402
         from assms[unfolded tRAG_s ancestors_def, folded this]
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   403
         show ?thesis by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   404
      next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   405
         assume "Th th'' \<in> ancestors (tRAG s) (Th holder)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   406
         moreover have "... \<subseteq> ancestors (tRAG (e#s)) (Th holder)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   407
         proof(rule ancestors_mono)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   408
            show "tRAG s \<subseteq> tRAG (e#s)" by (unfold tRAG_s, auto)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   409
         qed 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   410
         ultimately have "Th th'' \<in> ancestors (tRAG (e#s)) (Th holder)" by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   411
         moreover have "Th holder \<in> ancestors (tRAG (e#s)) (Th th)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   412
           by (unfold tRAG_s, auto simp:ancestors_def)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   413
         ultimately have "Th th'' \<in> ancestors (tRAG (e#s)) (Th th)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   414
                       by (auto simp:ancestors_def)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   415
         with assms show ?thesis by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   416
      qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   417
    qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   418
    from subtree_insert_next[OF this]
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   419
    have "subtree (tRAG s \<union> {(Th th, Th holder)}) (Th th'') = subtree (tRAG s) (Th th'')" .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   420
    from this[folded tRAG_s] show ?thesis .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   421
  qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   422
  show ?thesis by (unfold cp_alt_def1 h preced_kept, simp)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   423
qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   424
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   425
lemma cp_gen_update_stop: (* ddd *)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   426
  assumes "u \<in> ancestors (tRAG (e#s)) (Th th)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   427
  and "cp_gen (e#s) u = cp_gen s u"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   428
  and "y \<in> ancestors (tRAG (e#s)) u"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   429
  shows "cp_gen (e#s) y = cp_gen s y"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   430
  using assms(3)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   431
proof(induct rule:wf_induct[OF vat_e.fsbttRAGs.wf])
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   432
  case (1 x)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   433
  show ?case (is "?L = ?R")
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   434
  proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   435
    from tRAG_ancestorsE[OF 1(2)]
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   436
    obtain th2 where eq_x: "x = Th th2" by blast
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   437
    from vat_e.cp_gen_rec[OF this]
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   438
    have "?L = 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   439
          Max ({the_preced (e#s) th2} \<union> cp_gen (e#s) ` RTree.children (tRAG (e#s)) x)" .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   440
    also have "... = 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   441
          Max ({the_preced s th2} \<union> cp_gen s ` RTree.children (tRAG s) x)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   442
    proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   443
      from preced_kept have "the_preced (e#s) th2 = the_preced s th2" by simp
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   444
      moreover have "cp_gen (e#s) ` RTree.children (tRAG (e#s)) x =
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   445
                     cp_gen s ` RTree.children (tRAG s) x"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   446
      proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   447
        have "RTree.children (tRAG (e#s)) x =  RTree.children (tRAG s) x"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   448
        proof(unfold tRAG_s, rule children_union_kept)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   449
          have start: "(Th th, Th holder) \<in> tRAG (e#s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   450
            by (unfold tRAG_s, auto)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   451
          note x_u = 1(2)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   452
          show "x \<notin> Range {(Th th, Th holder)}"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   453
          proof
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   454
            assume "x \<in> Range {(Th th, Th holder)}"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   455
            hence eq_x: "x = Th holder" using RangeE by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   456
            show False
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   457
            proof(cases rule:vat_e.ancestors_headE[OF assms(1) start])
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   458
              case 1
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   459
              from x_u[folded this, unfolded eq_x] vat_e.acyclic_tRAG
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   460
              show ?thesis by (auto simp:ancestors_def acyclic_def)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   461
            next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   462
              case 2
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   463
              with x_u[unfolded eq_x]
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   464
              have "(Th holder, Th holder) \<in> (tRAG (e#s))^+" by (auto simp:ancestors_def)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   465
              with vat_e.acyclic_tRAG show ?thesis by (auto simp:acyclic_def)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   466
            qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   467
          qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   468
        qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   469
        moreover have "cp_gen (e#s) ` RTree.children (tRAG (e#s)) x =
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   470
                       cp_gen s ` RTree.children (tRAG (e#s)) x" (is "?f ` ?A = ?g ` ?A")
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   471
        proof(rule f_image_eq)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   472
          fix a
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   473
          assume a_in: "a \<in> ?A"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   474
          from 1(2)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   475
          show "?f a = ?g a"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   476
          proof(cases rule:vat_e.rtree_s.ancestors_childrenE[case_names in_ch out_ch])
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   477
             case in_ch
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   478
             show ?thesis
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   479
             proof(cases "a = u")
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   480
                case True
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   481
                from assms(2)[folded this] show ?thesis .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   482
             next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   483
                case False
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   484
                have a_not_in: "a \<notin> ancestors (tRAG (e#s)) (Th th)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   485
                proof
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   486
                  assume a_in': "a \<in> ancestors (tRAG (e#s)) (Th th)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   487
                  have "a = u"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   488
                  proof(rule vat_e.rtree_s.ancestors_children_unique)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   489
                    from a_in' a_in show "a \<in> ancestors (tRAG (e#s)) (Th th) \<inter> 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   490
                                          RTree.children (tRAG (e#s)) x" by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   491
                  next 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   492
                    from assms(1) in_ch show "u \<in> ancestors (tRAG (e#s)) (Th th) \<inter> 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   493
                                      RTree.children (tRAG (e#s)) x" by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   494
                  qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   495
                  with False show False by simp
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   496
                qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   497
                from a_in obtain th_a where eq_a: "a = Th th_a" 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   498
                    by (unfold RTree.children_def tRAG_alt_def, auto)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   499
                from cp_kept[OF a_not_in[unfolded eq_a]]
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   500
                have "cp (e#s) th_a = cp s th_a" .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   501
                from this [unfolded cp_gen_def_cond[OF eq_a], folded eq_a]
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   502
                show ?thesis .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   503
             qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   504
          next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   505
            case (out_ch z)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   506
            hence h: "z \<in> ancestors (tRAG (e#s)) u" "z \<in> RTree.children (tRAG (e#s)) x" by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   507
            show ?thesis
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   508
            proof(cases "a = z")
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   509
              case True
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   510
              from h(2) have zx_in: "(z, x) \<in> (tRAG (e#s))" by (auto simp:RTree.children_def)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   511
              from 1(1)[rule_format, OF this h(1)]
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   512
              have eq_cp_gen: "cp_gen (e#s) z = cp_gen s z" .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   513
              with True show ?thesis by metis
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   514
            next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   515
              case False
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   516
              from a_in obtain th_a where eq_a: "a = Th th_a"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   517
                by (auto simp:RTree.children_def tRAG_alt_def)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   518
              have "a \<notin> ancestors (tRAG (e#s)) (Th th)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   519
              proof
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   520
                assume a_in': "a \<in> ancestors (tRAG (e#s)) (Th th)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   521
                have "a = z"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   522
                proof(rule vat_e.rtree_s.ancestors_children_unique)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   523
                  from assms(1) h(1) have "z \<in> ancestors (tRAG (e#s)) (Th th)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   524
                      by (auto simp:ancestors_def)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   525
                  with h(2) show " z \<in> ancestors (tRAG (e#s)) (Th th) \<inter> 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   526
                                       RTree.children (tRAG (e#s)) x" by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   527
                next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   528
                  from a_in a_in'
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   529
                  show "a \<in> ancestors (tRAG (e#s)) (Th th) \<inter> RTree.children (tRAG (e#s)) x"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   530
                    by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   531
                qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   532
                with False show False by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   533
              qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   534
              from cp_kept[OF this[unfolded eq_a]]
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   535
              have "cp (e#s) th_a = cp s th_a" .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   536
              from this[unfolded cp_gen_def_cond[OF eq_a], folded eq_a]
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   537
              show ?thesis .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   538
            qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   539
          qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   540
        qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   541
        ultimately show ?thesis by metis
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   542
      qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   543
      ultimately show ?thesis by simp
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   544
    qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   545
    also have "... = ?R"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   546
      by (fold cp_gen_rec[OF eq_x], simp)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   547
    finally show ?thesis .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   548
  qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   549
qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   550
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   551
lemma cp_up:
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   552
  assumes "(Th th') \<in> ancestors (tRAG (e#s)) (Th th)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   553
  and "cp (e#s) th' = cp s th'"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   554
  and "(Th th'') \<in> ancestors (tRAG (e#s)) (Th th')"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   555
  shows "cp (e#s) th'' = cp s th''"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   556
proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   557
  have "cp_gen (e#s) (Th th'') = cp_gen s (Th th'')"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   558
  proof(rule cp_gen_update_stop[OF assms(1) _ assms(3)])
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   559
    from assms(2) cp_gen_def_cond[OF refl[of "Th th'"]]
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   560
    show "cp_gen (e#s) (Th th') = cp_gen s (Th th')" by metis
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   561
  qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   562
  with cp_gen_def_cond[OF refl[of "Th th''"]]
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   563
  show ?thesis by metis
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   564
qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   565
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   566
end
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   567
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   568
section {* The @{term Create} operation *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   569
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   570
context valid_trace_create
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   571
begin 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   572
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   573
interpretation vat_e: valid_trace "e#s"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   574
  by (unfold_locales, insert vt_e, simp)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   575
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   576
lemma tRAG_kept: "tRAG (e#s) = tRAG s"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   577
  by (unfold tRAG_alt_def RAG_unchanged, auto)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   578
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   579
lemma preced_kept:
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   580
  assumes "th' \<noteq> th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   581
  shows "the_preced (e#s) th' = the_preced s th'"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   582
  by (unfold the_preced_def preced_def is_create, insert assms, auto)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   583
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   584
lemma th_not_in: "Th th \<notin> Field (tRAG s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   585
  by (meson not_in_thread_isolated subsetCE tRAG_Field th_not_live_s)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   586
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   587
lemma eq_cp:
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   588
  assumes neq_th: "th' \<noteq> th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   589
  shows "cp (e#s) th' = cp s th'"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   590
proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   591
  have "(the_preced (e#s) \<circ> the_thread) ` subtree (tRAG (e#s)) (Th th') =
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   592
        (the_preced s \<circ> the_thread) ` subtree (tRAG s) (Th th')"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   593
  proof(unfold tRAG_kept, rule f_image_eq)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   594
    fix a
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   595
    assume a_in: "a \<in> subtree (tRAG s) (Th th')"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   596
    then obtain th_a where eq_a: "a = Th th_a" 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   597
    proof(cases rule:subtreeE)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   598
      case 2
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   599
      from ancestors_Field[OF 2(2)]
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   600
      and that show ?thesis by (unfold tRAG_alt_def, auto)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   601
    qed auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   602
    have neq_th_a: "th_a \<noteq> th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   603
    proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   604
      have "(Th th) \<notin> subtree (tRAG s) (Th th')"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   605
      proof
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   606
        assume "Th th \<in> subtree (tRAG s) (Th th')"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   607
        thus False
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   608
        proof(cases rule:subtreeE)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   609
          case 2
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   610
          from ancestors_Field[OF this(2)]
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   611
          and th_not_in[unfolded Field_def]
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   612
          show ?thesis by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   613
        qed (insert assms, auto)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   614
      qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   615
      with a_in[unfolded eq_a] show ?thesis by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   616
    qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   617
    from preced_kept[OF this]
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   618
    show "(the_preced (e#s) \<circ> the_thread) a = (the_preced s \<circ> the_thread) a"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   619
      by (unfold eq_a, simp)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   620
  qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   621
  thus ?thesis by (unfold cp_alt_def1, simp)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   622
qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   623
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   624
lemma children_of_th: "RTree.children (tRAG (e#s)) (Th th) = {}"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   625
proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   626
  { fix a
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   627
    assume "a \<in> RTree.children (tRAG (e#s)) (Th th)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   628
    hence "(a, Th th) \<in> tRAG (e#s)" by (auto simp:RTree.children_def)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   629
    with th_not_in have False 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   630
     by (unfold Field_def tRAG_kept, auto)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   631
  } thus ?thesis by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   632
qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   633
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   634
lemma eq_cp_th: "cp (e#s) th = preced th (e#s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   635
 by (unfold vat_e.cp_rec children_of_th, simp add:the_preced_def)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   636
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   637
end
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   638
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   639
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   640
context valid_trace_exit
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   641
begin
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   642
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   643
lemma preced_kept:
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   644
  assumes "th' \<noteq> th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   645
  shows "the_preced (e#s) th' = the_preced s th'"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   646
  using assms
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   647
  by (unfold the_preced_def is_exit preced_def, simp)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   648
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   649
lemma tRAG_kept: "tRAG (e#s) = tRAG s"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   650
  by (unfold tRAG_alt_def RAG_unchanged, auto)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   651
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   652
lemma th_RAG: "Th th \<notin> Field (RAG s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   653
proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   654
  have "Th th \<notin> Range (RAG s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   655
  proof
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   656
    assume "Th th \<in> Range (RAG s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   657
    then obtain cs where "holding (wq s) th cs"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   658
      by (unfold Range_iff s_RAG_def, auto)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   659
    with holdents_th_s[unfolded holdents_def]
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   660
    show False by (unfold holding_eq, auto)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   661
  qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   662
  moreover have "Th th \<notin> Domain (RAG s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   663
  proof
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   664
    assume "Th th \<in> Domain (RAG s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   665
    then obtain cs where "waiting (wq s) th cs"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   666
      by (unfold Domain_iff s_RAG_def, auto)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   667
    with th_ready_s show False by (unfold readys_def waiting_eq, auto)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   668
  qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   669
  ultimately show ?thesis by (auto simp:Field_def)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   670
qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   671
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   672
lemma th_tRAG: "(Th th) \<notin> Field (tRAG s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   673
  using th_RAG tRAG_Field by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   674
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   675
lemma eq_cp:
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   676
  assumes neq_th: "th' \<noteq> th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   677
  shows "cp (e#s) th' = cp s th'"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   678
proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   679
  have "(the_preced (e#s) \<circ> the_thread) ` subtree (tRAG (e#s)) (Th th') =
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   680
        (the_preced s \<circ> the_thread) ` subtree (tRAG s) (Th th')"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   681
  proof(unfold tRAG_kept, rule f_image_eq)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   682
    fix a
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   683
    assume a_in: "a \<in> subtree (tRAG s) (Th th')"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   684
    then obtain th_a where eq_a: "a = Th th_a" 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   685
    proof(cases rule:subtreeE)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   686
      case 2
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   687
      from ancestors_Field[OF 2(2)]
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   688
      and that show ?thesis by (unfold tRAG_alt_def, auto)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   689
    qed auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   690
    have neq_th_a: "th_a \<noteq> th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   691
    proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   692
      from readys_in_no_subtree[OF th_ready_s assms]
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   693
      have "(Th th) \<notin> subtree (RAG s) (Th th')" .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   694
      with tRAG_subtree_RAG[of s "Th th'"]
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   695
      have "(Th th) \<notin> subtree (tRAG s) (Th th')" by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   696
      with a_in[unfolded eq_a] show ?thesis by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   697
    qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   698
    from preced_kept[OF this]
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   699
    show "(the_preced (e#s) \<circ> the_thread) a = (the_preced s \<circ> the_thread) a"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   700
      by (unfold eq_a, simp)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   701
  qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   702
  thus ?thesis by (unfold cp_alt_def1, simp)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   703
qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   704
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   705
end
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   706
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   707
end
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   708
88
83dd5345d5d0 Merged back ExtGG.thy and PrioG.thy.
zhangx
parents: 85 87
diff changeset
   709
=======
87
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   710
theory ExtGG
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   711
imports PrioG CpsG
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   712
begin
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   713
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   714
text {* 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   715
  The following two auxiliary lemmas are used to reason about @{term Max}.
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   716
*}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   717
lemma image_Max_eqI: 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   718
  assumes "finite B"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   719
  and "b \<in> B"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   720
  and "\<forall> x \<in> B. f x \<le> f b"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   721
  shows "Max (f ` B) = f b"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   722
  using assms
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   723
  using Max_eqI by blast 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   724
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   725
lemma image_Max_subset:
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   726
  assumes "finite A"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   727
  and "B \<subseteq> A"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   728
  and "a \<in> B"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   729
  and "Max (f ` A) = f a"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   730
  shows "Max (f ` B) = f a"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   731
proof(rule image_Max_eqI)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   732
  show "finite B"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   733
    using assms(1) assms(2) finite_subset by auto 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   734
next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   735
  show "a \<in> B" using assms by simp
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   736
next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   737
  show "\<forall>x\<in>B. f x \<le> f a"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   738
    by (metis Max_ge assms(1) assms(2) assms(4) 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   739
            finite_imageI image_eqI subsetCE) 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   740
qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   741
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   742
text {*
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   743
  The following locale @{text "highest_gen"} sets the basic context for our
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   744
  investigation: supposing thread @{text th} holds the highest @{term cp}-value
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   745
  in state @{text s}, which means the task for @{text th} is the 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   746
  most urgent. We want to show that  
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   747
  @{text th} is treated correctly by PIP, which means
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   748
  @{text th} will not be blocked unreasonably by other less urgent
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   749
  threads. 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   750
*}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   751
locale highest_gen =
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   752
  fixes s th prio tm
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   753
  assumes vt_s: "vt s"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   754
  and threads_s: "th \<in> threads s"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   755
  and highest: "preced th s = Max ((cp s)`threads s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   756
  -- {* The internal structure of @{term th}'s precedence is exposed:*}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   757
  and preced_th: "preced th s = Prc prio tm" 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   758
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   759
-- {* @{term s} is a valid trace, so it will inherit all results derived for
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   760
      a valid trace: *}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   761
sublocale highest_gen < vat_s: valid_trace "s"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   762
  by (unfold_locales, insert vt_s, simp)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   763
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   764
context highest_gen
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   765
begin
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   766
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   767
text {*
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   768
  @{term tm} is the time when the precedence of @{term th} is set, so 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   769
  @{term tm} must be a valid moment index into @{term s}.
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   770
*}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   771
lemma lt_tm: "tm < length s"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   772
  by (insert preced_tm_lt[OF threads_s preced_th], simp)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   773
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   774
text {*
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   775
  Since @{term th} holds the highest precedence and @{text "cp"}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   776
  is the highest precedence of all threads in the sub-tree of 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   777
  @{text "th"} and @{text th} is among these threads, 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   778
  its @{term cp} must equal to its precedence:
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   779
*}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   780
lemma eq_cp_s_th: "cp s th = preced th s" (is "?L = ?R")
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   781
proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   782
  have "?L \<le> ?R"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   783
  by (unfold highest, rule Max_ge, 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   784
        auto simp:threads_s finite_threads)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   785
  moreover have "?R \<le> ?L"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   786
    by (unfold vat_s.cp_rec, rule Max_ge, 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   787
        auto simp:the_preced_def vat_s.fsbttRAGs.finite_children)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   788
  ultimately show ?thesis by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   789
qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   790
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   791
(* ccc *)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   792
lemma highest_cp_preced: "cp s th = Max ((\<lambda> th'. preced th' s) ` threads s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   793
  by (fold max_cp_eq, unfold eq_cp_s_th, insert highest, simp)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   794
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   795
lemma highest_preced_thread: "preced th s = Max ((\<lambda> th'. preced th' s) ` threads s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   796
  by (fold eq_cp_s_th, unfold highest_cp_preced, simp)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   797
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   798
lemma highest': "cp s th = Max (cp s ` threads s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   799
proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   800
  from highest_cp_preced max_cp_eq[symmetric]
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   801
  show ?thesis by simp
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   802
qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   803
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   804
end
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   805
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   806
locale extend_highest_gen = highest_gen + 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   807
  fixes t 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   808
  assumes vt_t: "vt (t@s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   809
  and create_low: "Create th' prio' \<in> set t \<Longrightarrow> prio' \<le> prio"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   810
  and set_diff_low: "Set th' prio' \<in> set t \<Longrightarrow> th' \<noteq> th \<and> prio' \<le> prio"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   811
  and exit_diff: "Exit th' \<in> set t \<Longrightarrow> th' \<noteq> th"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   812
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   813
sublocale extend_highest_gen < vat_t: valid_trace "t@s"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   814
  by (unfold_locales, insert vt_t, simp)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   815
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   816
lemma step_back_vt_app: 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   817
  assumes vt_ts: "vt (t@s)" 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   818
  shows "vt s"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   819
proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   820
  from vt_ts show ?thesis
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   821
  proof(induct t)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   822
    case Nil
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   823
    from Nil show ?case by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   824
  next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   825
    case (Cons e t)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   826
    assume ih: " vt (t @ s) \<Longrightarrow> vt s"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   827
      and vt_et: "vt ((e # t) @ s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   828
    show ?case
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   829
    proof(rule ih)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   830
      show "vt (t @ s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   831
      proof(rule step_back_vt)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   832
        from vt_et show "vt (e # t @ s)" by simp
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   833
      qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   834
    qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   835
  qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   836
qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   837
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   838
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   839
locale red_extend_highest_gen = extend_highest_gen +
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   840
   fixes i::nat
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   841
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   842
sublocale red_extend_highest_gen <   red_moment: extend_highest_gen "s" "th" "prio" "tm" "(moment i t)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   843
  apply (insert extend_highest_gen_axioms, subst (asm) (1) moment_restm_s [of i t, symmetric])
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   844
  apply (unfold extend_highest_gen_def extend_highest_gen_axioms_def, clarsimp)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   845
  by (unfold highest_gen_def, auto dest:step_back_vt_app)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   846
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   847
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   848
context extend_highest_gen
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   849
begin
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   850
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   851
 lemma ind [consumes 0, case_names Nil Cons, induct type]:
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   852
  assumes 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   853
    h0: "R []"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   854
  and h2: "\<And> e t. \<lbrakk>vt (t@s); step (t@s) e; 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   855
                    extend_highest_gen s th prio tm t; 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   856
                    extend_highest_gen s th prio tm (e#t); R t\<rbrakk> \<Longrightarrow> R (e#t)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   857
  shows "R t"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   858
proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   859
  from vt_t extend_highest_gen_axioms show ?thesis
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   860
  proof(induct t)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   861
    from h0 show "R []" .
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   862
  next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   863
    case (Cons e t')
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   864
    assume ih: "\<lbrakk>vt (t' @ s); extend_highest_gen s th prio tm t'\<rbrakk> \<Longrightarrow> R t'"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   865
      and vt_e: "vt ((e # t') @ s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   866
      and et: "extend_highest_gen s th prio tm (e # t')"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   867
    from vt_e and step_back_step have stp: "step (t'@s) e" by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   868
    from vt_e and step_back_vt have vt_ts: "vt (t'@s)" by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   869
    show ?case
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   870
    proof(rule h2 [OF vt_ts stp _ _ _ ])
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   871
      show "R t'"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   872
      proof(rule ih)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   873
        from et show ext': "extend_highest_gen s th prio tm t'"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   874
          by (unfold extend_highest_gen_def extend_highest_gen_axioms_def, auto dest:step_back_vt)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   875
      next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   876
        from vt_ts show "vt (t' @ s)" .
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   877
      qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   878
    next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   879
      from et show "extend_highest_gen s th prio tm (e # t')" .
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   880
    next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   881
      from et show ext': "extend_highest_gen s th prio tm t'"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   882
          by (unfold extend_highest_gen_def extend_highest_gen_axioms_def, auto dest:step_back_vt)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   883
    qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   884
  qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   885
qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   886
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   887
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   888
lemma th_kept: "th \<in> threads (t @ s) \<and> 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   889
                 preced th (t@s) = preced th s" (is "?Q t") 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   890
proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   891
  show ?thesis
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   892
  proof(induct rule:ind)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   893
    case Nil
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   894
    from threads_s
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   895
    show ?case
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   896
      by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   897
  next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   898
    case (Cons e t)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   899
    interpret h_e: extend_highest_gen _ _ _ _ "(e # t)" using Cons by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   900
    interpret h_t: extend_highest_gen _ _ _ _ t using Cons by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   901
    show ?case
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   902
    proof(cases e)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   903
      case (Create thread prio)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   904
      show ?thesis
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   905
      proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   906
        from Cons and Create have "step (t@s) (Create thread prio)" by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   907
        hence "th \<noteq> thread"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   908
        proof(cases)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   909
          case thread_create
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   910
          with Cons show ?thesis by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   911
        qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   912
        hence "preced th ((e # t) @ s)  = preced th (t @ s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   913
          by (unfold Create, auto simp:preced_def)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   914
        moreover note Cons
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   915
        ultimately show ?thesis
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   916
          by (auto simp:Create)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   917
      qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   918
    next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   919
      case (Exit thread)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   920
      from h_e.exit_diff and Exit
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   921
      have neq_th: "thread \<noteq> th" by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   922
      with Cons
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   923
      show ?thesis
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   924
        by (unfold Exit, auto simp:preced_def)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   925
    next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   926
      case (P thread cs)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   927
      with Cons
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   928
      show ?thesis 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   929
        by (auto simp:P preced_def)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   930
    next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   931
      case (V thread cs)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   932
      with Cons
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   933
      show ?thesis 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   934
        by (auto simp:V preced_def)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   935
    next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   936
      case (Set thread prio')
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   937
      show ?thesis
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   938
      proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   939
        from h_e.set_diff_low and Set
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   940
        have "th \<noteq> thread" by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   941
        hence "preced th ((e # t) @ s)  = preced th (t @ s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   942
          by (unfold Set, auto simp:preced_def)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   943
        moreover note Cons
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   944
        ultimately show ?thesis
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   945
          by (auto simp:Set)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   946
      qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   947
    qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   948
  qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   949
qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   950
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   951
text {*
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   952
  According to @{thm th_kept}, thread @{text "th"} has its living status
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   953
  and precedence kept along the way of @{text "t"}. The following lemma
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   954
  shows that this preserved precedence of @{text "th"} remains as the highest
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   955
  along the way of @{text "t"}.
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   956
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   957
  The proof goes by induction over @{text "t"} using the specialized
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   958
  induction rule @{thm ind}, followed by case analysis of each possible 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   959
  operations of PIP. All cases follow the same pattern rendered by the 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   960
  generalized introduction rule @{thm "image_Max_eqI"}. 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   961
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   962
  The very essence is to show that precedences, no matter whether they are newly introduced 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   963
  or modified, are always lower than the one held by @{term "th"},
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   964
  which by @{thm th_kept} is preserved along the way.
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   965
*}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   966
lemma max_kept: "Max (the_preced (t @ s) ` (threads (t@s))) = preced th s"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   967
proof(induct rule:ind)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   968
  case Nil
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   969
  from highest_preced_thread
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   970
  show ?case
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   971
    by (unfold the_preced_def, simp)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   972
next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   973
  case (Cons e t)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   974
    interpret h_e: extend_highest_gen _ _ _ _ "(e # t)" using Cons by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   975
    interpret h_t: extend_highest_gen _ _ _ _ t using Cons by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   976
  show ?case
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   977
  proof(cases e)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   978
    case (Create thread prio')
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   979
    show ?thesis (is "Max (?f ` ?A) = ?t")
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   980
    proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   981
      -- {* The following is the common pattern of each branch of the case analysis. *}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   982
      -- {* The major part is to show that @{text "th"} holds the highest precedence: *}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   983
      have "Max (?f ` ?A) = ?f th"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   984
      proof(rule image_Max_eqI)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   985
        show "finite ?A" using h_e.finite_threads by auto 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   986
      next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   987
        show "th \<in> ?A" using h_e.th_kept by auto 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   988
      next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   989
        show "\<forall>x\<in>?A. ?f x \<le> ?f th"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   990
        proof 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   991
          fix x
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   992
          assume "x \<in> ?A"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   993
          hence "x = thread \<or> x \<in> threads (t@s)" by (auto simp:Create)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   994
          thus "?f x \<le> ?f th"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   995
          proof
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   996
            assume "x = thread"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   997
            thus ?thesis 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   998
              apply (simp add:Create the_preced_def preced_def, fold preced_def)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
   999
              using Create h_e.create_low h_t.th_kept lt_tm preced_leI2 preced_th by force
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1000
          next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1001
            assume h: "x \<in> threads (t @ s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1002
            from Cons(2)[unfolded Create] 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1003
            have "x \<noteq> thread" using h by (cases, auto)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1004
            hence "?f x = the_preced (t@s) x" 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1005
              by (simp add:Create the_preced_def preced_def)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1006
            hence "?f x \<le> Max (the_preced (t@s) ` threads (t@s))"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1007
              by (simp add: h_t.finite_threads h)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1008
            also have "... = ?f th"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1009
              by (metis Cons.hyps(5) h_e.th_kept the_preced_def) 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1010
            finally show ?thesis .
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1011
          qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1012
        qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1013
      qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1014
     -- {* The minor part is to show that the precedence of @{text "th"} 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1015
           equals to preserved one, given by the foregoing lemma @{thm th_kept} *}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1016
      also have "... = ?t" using h_e.th_kept the_preced_def by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1017
      -- {* Then it follows trivially that the precedence preserved
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1018
            for @{term "th"} remains the maximum of all living threads along the way. *}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1019
      finally show ?thesis .
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1020
    qed 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1021
  next 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1022
    case (Exit thread)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1023
    show ?thesis (is "Max (?f ` ?A) = ?t")
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1024
    proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1025
      have "Max (?f ` ?A) = ?f th"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1026
      proof(rule image_Max_eqI)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1027
        show "finite ?A" using h_e.finite_threads by auto 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1028
      next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1029
        show "th \<in> ?A" using h_e.th_kept by auto 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1030
      next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1031
        show "\<forall>x\<in>?A. ?f x \<le> ?f th"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1032
        proof 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1033
          fix x
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1034
          assume "x \<in> ?A"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1035
          hence "x \<in> threads (t@s)" by (simp add: Exit) 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1036
          hence "?f x \<le> Max (?f ` threads (t@s))" 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1037
            by (simp add: h_t.finite_threads) 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1038
          also have "... \<le> ?f th" 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1039
            apply (simp add:Exit the_preced_def preced_def, fold preced_def)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1040
            using Cons.hyps(5) h_t.th_kept the_preced_def by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1041
          finally show "?f x \<le> ?f th" .
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1042
        qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1043
      qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1044
      also have "... = ?t" using h_e.th_kept the_preced_def by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1045
      finally show ?thesis .
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1046
    qed 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1047
  next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1048
    case (P thread cs)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1049
    with Cons
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1050
    show ?thesis by (auto simp:preced_def the_preced_def)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1051
  next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1052
    case (V thread cs)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1053
    with Cons
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1054
    show ?thesis by (auto simp:preced_def the_preced_def)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1055
  next 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1056
    case (Set thread prio')
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1057
    show ?thesis (is "Max (?f ` ?A) = ?t")
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1058
    proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1059
      have "Max (?f ` ?A) = ?f th"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1060
      proof(rule image_Max_eqI)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1061
        show "finite ?A" using h_e.finite_threads by auto 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1062
      next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1063
        show "th \<in> ?A" using h_e.th_kept by auto 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1064
      next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1065
        show "\<forall>x\<in>?A. ?f x \<le> ?f th"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1066
        proof 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1067
          fix x
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1068
          assume h: "x \<in> ?A"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1069
          show "?f x \<le> ?f th"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1070
          proof(cases "x = thread")
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1071
            case True
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1072
            moreover have "the_preced (Set thread prio' # t @ s) thread \<le> the_preced (t @ s) th"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1073
            proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1074
              have "the_preced (t @ s) th = Prc prio tm"  
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1075
                using h_t.th_kept preced_th by (simp add:the_preced_def)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1076
              moreover have "prio' \<le> prio" using Set h_e.set_diff_low by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1077
              ultimately show ?thesis by (insert lt_tm, auto simp:the_preced_def preced_def)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1078
            qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1079
            ultimately show ?thesis
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1080
              by (unfold Set, simp add:the_preced_def preced_def)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1081
          next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1082
            case False
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1083
            then have "?f x  = the_preced (t@s) x"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1084
              by (simp add:the_preced_def preced_def Set)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1085
            also have "... \<le> Max (the_preced (t@s) ` threads (t@s))"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1086
              using Set h h_t.finite_threads by auto 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1087
            also have "... = ?f th" by (metis Cons.hyps(5) h_e.th_kept the_preced_def) 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1088
            finally show ?thesis .
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1089
          qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1090
        qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1091
      qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1092
      also have "... = ?t" using h_e.th_kept the_preced_def by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1093
      finally show ?thesis .
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1094
    qed 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1095
  qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1096
qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1097
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1098
lemma max_preced: "preced th (t@s) = Max (the_preced (t@s) ` (threads (t@s)))"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1099
  by (insert th_kept max_kept, auto)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1100
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1101
text {*
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1102
  The reason behind the following lemma is that:
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1103
  Since @{term "cp"} is defined as the maximum precedence 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1104
  of those threads contained in the sub-tree of node @{term "Th th"} 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1105
  in @{term "RAG (t@s)"}, and all these threads are living threads, and 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1106
  @{term "th"} is also among them, the maximum precedence of 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1107
  them all must be the one for @{text "th"}.
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1108
*}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1109
lemma th_cp_max_preced: 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1110
  "cp (t@s) th = Max (the_preced (t@s) ` (threads (t@s)))" (is "?L = ?R") 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1111
proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1112
  let ?f = "the_preced (t@s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1113
  have "?L = ?f th"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1114
  proof(unfold cp_alt_def, rule image_Max_eqI)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1115
    show "finite {th'. Th th' \<in> subtree (RAG (t @ s)) (Th th)}"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1116
    proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1117
      have "{th'. Th th' \<in> subtree (RAG (t @ s)) (Th th)} = 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1118
            the_thread ` {n . n \<in> subtree (RAG (t @ s)) (Th th) \<and>
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1119
                            (\<exists> th'. n = Th th')}"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1120
      by (smt Collect_cong Setcompr_eq_image mem_Collect_eq the_thread.simps)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1121
      moreover have "finite ..." by (simp add: vat_t.fsbtRAGs.finite_subtree) 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1122
      ultimately show ?thesis by simp
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1123
    qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1124
  next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1125
    show "th \<in> {th'. Th th' \<in> subtree (RAG (t @ s)) (Th th)}"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1126
      by (auto simp:subtree_def)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1127
  next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1128
    show "\<forall>x\<in>{th'. Th th' \<in> subtree (RAG (t @ s)) (Th th)}.
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1129
               the_preced (t @ s) x \<le> the_preced (t @ s) th"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1130
    proof
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1131
      fix th'
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1132
      assume "th' \<in> {th'. Th th' \<in> subtree (RAG (t @ s)) (Th th)}"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1133
      hence "Th th' \<in> subtree (RAG (t @ s)) (Th th)" by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1134
      moreover have "... \<subseteq> Field (RAG (t @ s)) \<union> {Th th}"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1135
        by (meson subtree_Field)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1136
      ultimately have "Th th' \<in> ..." by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1137
      hence "th' \<in> threads (t@s)" 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1138
      proof
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1139
        assume "Th th' \<in> {Th th}"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1140
        thus ?thesis using th_kept by auto 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1141
      next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1142
        assume "Th th' \<in> Field (RAG (t @ s))"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1143
        thus ?thesis using vat_t.not_in_thread_isolated by blast 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1144
      qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1145
      thus "the_preced (t @ s) th' \<le> the_preced (t @ s) th"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1146
        by (metis Max_ge finite_imageI finite_threads image_eqI 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1147
               max_kept th_kept the_preced_def)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1148
    qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1149
  qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1150
  also have "... = ?R" by (simp add: max_preced the_preced_def) 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1151
  finally show ?thesis .
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1152
qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1153
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1154
lemma th_cp_max: "cp (t@s) th = Max (cp (t@s) ` threads (t@s))"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1155
  using max_cp_eq th_cp_max_preced the_preced_def vt_t by presburger
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1156
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1157
lemma th_cp_preced: "cp (t@s) th = preced th s"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1158
  by (fold max_kept, unfold th_cp_max_preced, simp)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1159
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1160
lemma preced_less:
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1161
  assumes th'_in: "th' \<in> threads s"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1162
  and neq_th': "th' \<noteq> th"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1163
  shows "preced th' s < preced th s"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1164
  using assms
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1165
by (metis Max.coboundedI finite_imageI highest not_le order.trans 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1166
    preced_linorder rev_image_eqI threads_s vat_s.finite_threads 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1167
    vat_s.le_cp)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1168
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1169
text {*
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1170
  Counting of the number of @{term "P"} and @{term "V"} operations 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1171
  is the cornerstone of a large number of the following proofs. 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1172
  The reason is that this counting is quite easy to calculate and 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1173
  convenient to use in the reasoning. 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1174
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1175
  The following lemma shows that the counting controls whether 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1176
  a thread is running or not.
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1177
*}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1178
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1179
lemma pv_blocked_pre:
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1180
  assumes th'_in: "th' \<in> threads (t@s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1181
  and neq_th': "th' \<noteq> th"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1182
  and eq_pv: "cntP (t@s) th' = cntV (t@s) th'"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1183
  shows "th' \<notin> runing (t@s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1184
proof
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1185
  assume otherwise: "th' \<in> runing (t@s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1186
  show False
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1187
  proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1188
    have "th' = th"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1189
    proof(rule preced_unique)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1190
      show "preced th' (t @ s) = preced th (t @ s)" (is "?L = ?R")
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1191
      proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1192
        have "?L = cp (t@s) th'"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1193
          by (unfold cp_eq_cpreced cpreced_def count_eq_dependants[OF eq_pv], simp)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1194
        also have "... = cp (t @ s) th" using otherwise 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1195
          by (metis (mono_tags, lifting) mem_Collect_eq 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1196
                    runing_def th_cp_max vat_t.max_cp_readys_threads)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1197
        also have "... = ?R" by (metis th_cp_preced th_kept) 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1198
        finally show ?thesis .
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1199
      qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1200
    qed (auto simp: th'_in th_kept)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1201
    moreover have "th' \<noteq> th" using neq_th' .
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1202
    ultimately show ?thesis by simp
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1203
 qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1204
qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1205
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1206
lemmas pv_blocked = pv_blocked_pre[folded detached_eq]
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1207
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1208
lemma runing_precond_pre:
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1209
  fixes th'
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1210
  assumes th'_in: "th' \<in> threads s"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1211
  and eq_pv: "cntP s th' = cntV s th'"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1212
  and neq_th': "th' \<noteq> th"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1213
  shows "th' \<in> threads (t@s) \<and>
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1214
         cntP (t@s) th' = cntV (t@s) th'"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1215
proof(induct rule:ind)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1216
  case (Cons e t)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1217
    interpret vat_t: extend_highest_gen s th prio tm t using Cons by simp
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1218
    interpret vat_e: extend_highest_gen s th prio tm "(e # t)" using Cons by simp
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1219
    show ?case
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1220
    proof(cases e)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1221
      case (P thread cs)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1222
      show ?thesis
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1223
      proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1224
        have "cntP ((e # t) @ s) th' = cntV ((e # t) @ s) th'"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1225
        proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1226
          have "thread \<noteq> th'"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1227
          proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1228
            have "step (t@s) (P thread cs)" using Cons P by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1229
            thus ?thesis
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1230
            proof(cases)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1231
              assume "thread \<in> runing (t@s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1232
              moreover have "th' \<notin> runing (t@s)" using Cons(5)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1233
                by (metis neq_th' vat_t.pv_blocked_pre) 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1234
              ultimately show ?thesis by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1235
            qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1236
          qed with Cons show ?thesis
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1237
            by (unfold P, simp add:cntP_def cntV_def count_def)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1238
        qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1239
        moreover have "th' \<in> threads ((e # t) @ s)" using Cons by (unfold P, simp)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1240
        ultimately show ?thesis by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1241
      qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1242
    next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1243
      case (V thread cs)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1244
      show ?thesis
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1245
      proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1246
        have "cntP ((e # t) @ s) th' = cntV ((e # t) @ s) th'"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1247
        proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1248
          have "thread \<noteq> th'"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1249
          proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1250
            have "step (t@s) (V thread cs)" using Cons V by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1251
            thus ?thesis
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1252
            proof(cases)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1253
              assume "thread \<in> runing (t@s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1254
              moreover have "th' \<notin> runing (t@s)" using Cons(5)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1255
                by (metis neq_th' vat_t.pv_blocked_pre) 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1256
              ultimately show ?thesis by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1257
            qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1258
          qed with Cons show ?thesis
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1259
            by (unfold V, simp add:cntP_def cntV_def count_def)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1260
        qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1261
        moreover have "th' \<in> threads ((e # t) @ s)" using Cons by (unfold V, simp)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1262
        ultimately show ?thesis by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1263
      qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1264
    next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1265
      case (Create thread prio')
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1266
      show ?thesis
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1267
      proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1268
        have "cntP ((e # t) @ s) th' = cntV ((e # t) @ s) th'"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1269
        proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1270
          have "thread \<noteq> th'"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1271
          proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1272
            have "step (t@s) (Create thread prio')" using Cons Create by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1273
            thus ?thesis using Cons(5) by (cases, auto)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1274
          qed with Cons show ?thesis
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1275
            by (unfold Create, simp add:cntP_def cntV_def count_def)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1276
        qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1277
        moreover have "th' \<in> threads ((e # t) @ s)" using Cons by (unfold Create, simp)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1278
        ultimately show ?thesis by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1279
      qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1280
    next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1281
      case (Exit thread)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1282
      show ?thesis
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1283
      proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1284
        have neq_thread: "thread \<noteq> th'"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1285
        proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1286
          have "step (t@s) (Exit thread)" using Cons Exit by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1287
          thus ?thesis apply (cases) using Cons(5)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1288
                by (metis neq_th' vat_t.pv_blocked_pre) 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1289
        qed 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1290
        hence "cntP ((e # t) @ s) th' = cntV ((e # t) @ s) th'" using Cons
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1291
            by (unfold Exit, simp add:cntP_def cntV_def count_def)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1292
        moreover have "th' \<in> threads ((e # t) @ s)" using Cons neq_thread 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1293
          by (unfold Exit, simp) 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1294
        ultimately show ?thesis by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1295
      qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1296
    next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1297
      case (Set thread prio')
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1298
      with Cons
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1299
      show ?thesis 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1300
        by (auto simp:cntP_def cntV_def count_def)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1301
    qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1302
next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1303
  case Nil
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1304
  with assms
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1305
  show ?case by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1306
qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1307
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1308
text {* Changing counting balance to detachedness *}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1309
lemmas runing_precond_pre_dtc = runing_precond_pre
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1310
         [folded vat_t.detached_eq vat_s.detached_eq]
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1311
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1312
lemma runing_precond:
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1313
  fixes th'
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1314
  assumes th'_in: "th' \<in> threads s"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1315
  and neq_th': "th' \<noteq> th"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1316
  and is_runing: "th' \<in> runing (t@s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1317
  shows "cntP s th' > cntV s th'"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1318
  using assms
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1319
proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1320
  have "cntP s th' \<noteq> cntV s th'"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1321
    by (metis is_runing neq_th' pv_blocked_pre runing_precond_pre th'_in)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1322
  moreover have "cntV s th' \<le> cntP s th'" using vat_s.cnp_cnv_cncs by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1323
  ultimately show ?thesis by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1324
qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1325
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1326
lemma moment_blocked_pre:
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1327
  assumes neq_th': "th' \<noteq> th"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1328
  and th'_in: "th' \<in> threads ((moment i t)@s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1329
  and eq_pv: "cntP ((moment i t)@s) th' = cntV ((moment i t)@s) th'"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1330
  shows "cntP ((moment (i+j) t)@s) th' = cntV ((moment (i+j) t)@s) th' \<and>
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1331
         th' \<in> threads ((moment (i+j) t)@s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1332
proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1333
  interpret h_i: red_extend_highest_gen _ _ _ _ _ i
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1334
      by (unfold_locales)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1335
  interpret h_j: red_extend_highest_gen _ _ _ _ _ "i+j"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1336
      by (unfold_locales)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1337
  interpret h:  extend_highest_gen "((moment i t)@s)" th prio tm "moment j (restm i t)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1338
  proof(unfold_locales)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1339
    show "vt (moment i t @ s)" by (metis h_i.vt_t) 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1340
  next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1341
    show "th \<in> threads (moment i t @ s)" by (metis h_i.th_kept)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1342
  next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1343
    show "preced th (moment i t @ s) = 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1344
            Max (cp (moment i t @ s) ` threads (moment i t @ s))"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1345
              by (metis h_i.th_cp_max h_i.th_cp_preced h_i.th_kept)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1346
  next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1347
    show "preced th (moment i t @ s) = Prc prio tm" by (metis h_i.th_kept preced_th) 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1348
  next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1349
    show "vt (moment j (restm i t) @ moment i t @ s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1350
      using moment_plus_split by (metis add.commute append_assoc h_j.vt_t)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1351
  next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1352
    fix th' prio'
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1353
    assume "Create th' prio' \<in> set (moment j (restm i t))"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1354
    thus "prio' \<le> prio" using assms
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1355
       by (metis Un_iff add.commute h_j.create_low moment_plus_split set_append)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1356
  next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1357
    fix th' prio'
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1358
    assume "Set th' prio' \<in> set (moment j (restm i t))"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1359
    thus "th' \<noteq> th \<and> prio' \<le> prio"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1360
    by (metis Un_iff add.commute h_j.set_diff_low moment_plus_split set_append)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1361
  next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1362
    fix th'
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1363
    assume "Exit th' \<in> set (moment j (restm i t))"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1364
    thus "th' \<noteq> th"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1365
      by (metis Un_iff add.commute h_j.exit_diff moment_plus_split set_append)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1366
  qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1367
  show ?thesis 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1368
    by (metis add.commute append_assoc eq_pv h.runing_precond_pre
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1369
          moment_plus_split neq_th' th'_in)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1370
qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1371
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1372
lemma moment_blocked_eqpv:
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1373
  assumes neq_th': "th' \<noteq> th"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1374
  and th'_in: "th' \<in> threads ((moment i t)@s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1375
  and eq_pv: "cntP ((moment i t)@s) th' = cntV ((moment i t)@s) th'"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1376
  and le_ij: "i \<le> j"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1377
  shows "cntP ((moment j t)@s) th' = cntV ((moment j t)@s) th' \<and>
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1378
         th' \<in> threads ((moment j t)@s) \<and>
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1379
         th' \<notin> runing ((moment j t)@s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1380
proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1381
  from moment_blocked_pre [OF neq_th' th'_in eq_pv, of "j-i"] and le_ij
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1382
  have h1: "cntP ((moment j t)@s) th' = cntV ((moment j t)@s) th'"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1383
   and h2: "th' \<in> threads ((moment j t)@s)" by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1384
  moreover have "th' \<notin> runing ((moment j t)@s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1385
  proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1386
    interpret h: red_extend_highest_gen _ _ _ _ _ j by (unfold_locales)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1387
    show ?thesis
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1388
      using h.pv_blocked_pre h1 h2 neq_th' by auto 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1389
  qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1390
  ultimately show ?thesis by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1391
qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1392
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1393
(* The foregoing two lemmas are preparation for this one, but
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1394
   in long run can be combined. Maybe I am wrong.
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1395
*)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1396
lemma moment_blocked:
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1397
  assumes neq_th': "th' \<noteq> th"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1398
  and th'_in: "th' \<in> threads ((moment i t)@s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1399
  and dtc: "detached (moment i t @ s) th'"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1400
  and le_ij: "i \<le> j"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1401
  shows "detached (moment j t @ s) th' \<and>
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1402
         th' \<in> threads ((moment j t)@s) \<and>
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1403
         th' \<notin> runing ((moment j t)@s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1404
proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1405
  interpret h_i: red_extend_highest_gen _ _ _ _ _ i by (unfold_locales)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1406
  interpret h_j: red_extend_highest_gen _ _ _ _ _ j by (unfold_locales) 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1407
  have cnt_i: "cntP (moment i t @ s) th' = cntV (moment i t @ s) th'"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1408
                by (metis dtc h_i.detached_elim)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1409
  from moment_blocked_eqpv[OF neq_th' th'_in cnt_i le_ij]
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1410
  show ?thesis by (metis h_j.detached_intro) 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1411
qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1412
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1413
lemma runing_preced_inversion:
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1414
  assumes runing': "th' \<in> runing (t@s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1415
  shows "cp (t@s) th' = preced th s" (is "?L = ?R")
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1416
proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1417
  have "?L = Max (cp (t @ s) ` readys (t @ s))" using assms
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1418
      by (unfold runing_def, auto)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1419
  also have "\<dots> = ?R"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1420
      by (metis th_cp_max th_cp_preced vat_t.max_cp_readys_threads) 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1421
  finally show ?thesis .
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1422
qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1423
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1424
text {*
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1425
  The situation when @{term "th"} is blocked is analyzed by the following lemmas.
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1426
*}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1427
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1428
text {*
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1429
  The following lemmas shows the running thread @{text "th'"}, if it is different from
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1430
  @{term th}, must be live at the very beginning. By the term {\em the very beginning},
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1431
  we mean the moment where the formal investigation starts, i.e. the moment (or state)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1432
  @{term s}. 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1433
*}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1434
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1435
lemma runing_inversion_0:
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1436
  assumes neq_th': "th' \<noteq> th"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1437
  and runing': "th' \<in> runing (t@s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1438
  shows "th' \<in> threads s"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1439
proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1440
    -- {* The proof is by contradiction: *}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1441
    { assume otherwise: "\<not> ?thesis"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1442
      have "th' \<notin> runing (t @ s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1443
      proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1444
        -- {* Since @{term "th'"} is running at time @{term "t@s"}, so it exists that time. *}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1445
        have th'_in: "th' \<in> threads (t@s)" using runing' by (simp add:runing_def readys_def)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1446
        -- {* However, @{text "th'"} does not exist at very beginning. *}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1447
        have th'_notin: "th' \<notin> threads (moment 0 t @ s)" using otherwise
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1448
          by (metis append.simps(1) moment_zero)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1449
        -- {* Therefore, there must be a moment during @{text "t"}, when 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1450
              @{text "th'"} came into being. *}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1451
        -- {* Let us suppose the moment being @{text "i"}: *}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1452
        from p_split_gen[OF th'_in th'_notin]
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1453
        obtain i where lt_its: "i < length t"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1454
                 and le_i: "0 \<le> i"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1455
                 and pre: " th' \<notin> threads (moment i t @ s)" (is "th' \<notin> threads ?pre")
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1456
                 and post: "(\<forall>i'>i. th' \<in> threads (moment i' t @ s))" by (auto)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1457
        interpret h_i: red_extend_highest_gen _ _ _ _ _ i by (unfold_locales)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1458
        interpret h_i': red_extend_highest_gen _ _ _ _ _ "(Suc i)" by (unfold_locales)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1459
        from lt_its have "Suc i \<le> length t" by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1460
        -- {* Let us also suppose the event which makes this change is @{text e}: *}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1461
        from moment_head[OF this] obtain e where 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1462
          eq_me: "moment (Suc i) t = e # moment i t" by blast
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1463
        hence "vt (e # (moment i t @ s))" by (metis append_Cons h_i'.vt_t) 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1464
        hence "PIP (moment i t @ s) e" by (cases, simp)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1465
        -- {* It can be derived that this event @{text "e"}, which 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1466
              gives birth to @{term "th'"} must be a @{term "Create"}: *}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1467
        from create_pre[OF this, of th']
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1468
        obtain prio where eq_e: "e = Create th' prio"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1469
            by (metis append_Cons eq_me lessI post pre) 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1470
        have h1: "th' \<in> threads (moment (Suc i) t @ s)" using post by auto 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1471
        have h2: "cntP (moment (Suc i) t @ s) th' = cntV (moment (Suc i) t@ s) th'"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1472
        proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1473
          have "cntP (moment i t@s) th' = cntV (moment i t@s) th'"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1474
            by (metis h_i.cnp_cnv_eq pre)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1475
          thus ?thesis by (simp add:eq_me eq_e cntP_def cntV_def count_def)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1476
        qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1477
        show ?thesis 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1478
          using moment_blocked_eqpv [OF neq_th' h1 h2, of "length t"] lt_its moment_ge
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1479
            by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1480
      qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1481
      with `th' \<in> runing (t@s)`
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1482
      have False by simp
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1483
    } thus ?thesis by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1484
qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1485
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1486
text {* 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1487
  The second lemma says, if the running thread @{text th'} is different from 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1488
  @{term th}, then this @{text th'} must in the possession of some resources
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1489
  at the very beginning. 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1490
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1491
  To ease the reasoning of resource possession of one particular thread, 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1492
  we used two auxiliary functions @{term cntV} and @{term cntP}, 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1493
  which are the counters of @{term P}-operations and 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1494
  @{term V}-operations respectively. 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1495
  If the number of @{term V}-operation is less than the number of 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1496
  @{term "P"}-operations, the thread must have some unreleased resource. 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1497
*}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1498
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1499
lemma runing_inversion_1: (* ddd *)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1500
  assumes neq_th': "th' \<noteq> th"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1501
  and runing': "th' \<in> runing (t@s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1502
  -- {* thread @{term "th'"} is a live on in state @{term "s"} and 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1503
        it has some unreleased resource. *}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1504
  shows "th' \<in> threads s \<and> cntV s th' < cntP s th'"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1505
proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1506
  -- {* The proof is a simple composition of @{thm runing_inversion_0} and 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1507
        @{thm runing_precond}: *}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1508
  -- {* By applying @{thm runing_inversion_0} to assumptions,
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1509
        it can be shown that @{term th'} is live in state @{term s}: *}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1510
  have "th' \<in> threads s"  using runing_inversion_0[OF assms(1,2)] .
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1511
  -- {* Then the thesis is derived easily by applying @{thm runing_precond}: *}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1512
  with runing_precond [OF this neq_th' runing'] show ?thesis by simp
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1513
qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1514
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1515
text {* 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1516
  The following lemma is just a rephrasing of @{thm runing_inversion_1}:
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1517
*}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1518
lemma runing_inversion_2:
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1519
  assumes runing': "th' \<in> runing (t@s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1520
  shows "th' = th \<or> (th' \<noteq> th \<and> th' \<in> threads s \<and> cntV s th' < cntP s th')"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1521
proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1522
  from runing_inversion_1[OF _ runing']
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1523
  show ?thesis by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1524
qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1525
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1526
lemma runing_inversion_3:
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1527
  assumes runing': "th' \<in> runing (t@s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1528
  and neq_th: "th' \<noteq> th"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1529
  shows "th' \<in> threads s \<and> (cntV s th' < cntP s th' \<and> cp (t@s) th' = preced th s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1530
  by (metis neq_th runing' runing_inversion_2 runing_preced_inversion)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1531
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1532
lemma runing_inversion_4:
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1533
  assumes runing': "th' \<in> runing (t@s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1534
  and neq_th: "th' \<noteq> th"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1535
  shows "th' \<in> threads s"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1536
  and    "\<not>detached s th'"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1537
  and    "cp (t@s) th' = preced th s"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1538
  apply (metis neq_th runing' runing_inversion_2)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1539
  apply (metis neq_th pv_blocked runing' runing_inversion_2 runing_precond_pre_dtc)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1540
  by (metis neq_th runing' runing_inversion_3)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1541
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1542
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1543
text {* 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1544
  Suppose @{term th} is not running, it is first shown that
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1545
  there is a path in RAG leading from node @{term th} to another thread @{text "th'"} 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1546
  in the @{term readys}-set (So @{text "th'"} is an ancestor of @{term th}}).
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1547
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1548
  Now, since @{term readys}-set is non-empty, there must be
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1549
  one in it which holds the highest @{term cp}-value, which, by definition, 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1550
  is the @{term runing}-thread. However, we are going to show more: this running thread
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1551
  is exactly @{term "th'"}.
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1552
     *}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1553
lemma th_blockedE: (* ddd *)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1554
  assumes "th \<notin> runing (t@s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1555
  obtains th' where "Th th' \<in> ancestors (RAG (t @ s)) (Th th)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1556
                    "th' \<in> runing (t@s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1557
proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1558
  -- {* According to @{thm vat_t.th_chain_to_ready}, either 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1559
        @{term "th"} is in @{term "readys"} or there is path leading from it to 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1560
        one thread in @{term "readys"}. *}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1561
  have "th \<in> readys (t @ s) \<or> (\<exists>th'. th' \<in> readys (t @ s) \<and> (Th th, Th th') \<in> (RAG (t @ s))\<^sup>+)" 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1562
    using th_kept vat_t.th_chain_to_ready by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1563
  -- {* However, @{term th} can not be in @{term readys}, because otherwise, since 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1564
       @{term th} holds the highest @{term cp}-value, it must be @{term "runing"}. *}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1565
  moreover have "th \<notin> readys (t@s)" 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1566
    using assms runing_def th_cp_max vat_t.max_cp_readys_threads by auto 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1567
  -- {* So, there must be a path from @{term th} to another thread @{text "th'"} in 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1568
        term @{term readys}: *}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1569
  ultimately obtain th' where th'_in: "th' \<in> readys (t@s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1570
                          and dp: "(Th th, Th th') \<in> (RAG (t @ s))\<^sup>+" by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1571
  -- {* We are going to show that this @{term th'} is running. *}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1572
  have "th' \<in> runing (t@s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1573
  proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1574
    -- {* We only need to show that this @{term th'} holds the highest @{term cp}-value: *}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1575
    have "cp (t@s) th' = Max (cp (t@s) ` readys (t@s))" (is "?L = ?R")
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1576
    proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1577
      have "?L =  Max ((the_preced (t @ s) \<circ> the_thread) ` subtree (tRAG (t @ s)) (Th th'))"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1578
        by (unfold cp_alt_def1, simp)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1579
      also have "... = (the_preced (t @ s) \<circ> the_thread) (Th th)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1580
      proof(rule image_Max_subset)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1581
        show "finite (Th ` (threads (t@s)))" by (simp add: vat_t.finite_threads)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1582
      next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1583
        show "subtree (tRAG (t @ s)) (Th th') \<subseteq> Th ` threads (t @ s)"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1584
          by (metis Range.intros dp trancl_range vat_t.range_in vat_t.subtree_tRAG_thread) 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1585
      next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1586
        show "Th th \<in> subtree (tRAG (t @ s)) (Th th')" using dp
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1587
                    by (unfold tRAG_subtree_eq, auto simp:subtree_def)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1588
      next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1589
        show "Max ((the_preced (t @ s) \<circ> the_thread) ` Th ` threads (t @ s)) =
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1590
                      (the_preced (t @ s) \<circ> the_thread) (Th th)" (is "Max ?L = _")
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1591
        proof -
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1592
          have "?L = the_preced (t @ s) `  threads (t @ s)" 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1593
                     by (unfold image_comp, rule image_cong, auto)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1594
          thus ?thesis using max_preced the_preced_def by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1595
        qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1596
      qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1597
      also have "... = ?R"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1598
        using th_cp_max th_cp_preced th_kept 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1599
              the_preced_def vat_t.max_cp_readys_threads by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1600
      finally show ?thesis .
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1601
    qed 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1602
    -- {* Now, since @{term th'} holds the highest @{term cp} 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1603
          and we have already show it is in @{term readys},
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1604
          it is @{term runing} by definition. *}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1605
    with `th' \<in> readys (t@s)` show ?thesis by (simp add: runing_def) 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1606
  qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1607
  -- {* It is easy to show @{term th'} is an ancestor of @{term th}: *}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1608
  moreover have "Th th' \<in> ancestors (RAG (t @ s)) (Th th)" 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1609
    using `(Th th, Th th') \<in> (RAG (t @ s))\<^sup>+` by (auto simp:ancestors_def)
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1610
  ultimately show ?thesis using that by metis
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1611
qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1612
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1613
text {*
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1614
  Now it is easy to see there is always a thread to run by case analysis
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1615
  on whether thread @{term th} is running: if the answer is Yes, the 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1616
  the running thread is obviously @{term th} itself; otherwise, the running
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1617
  thread is the @{text th'} given by lemma @{thm th_blockedE}.
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1618
*}
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1619
lemma live: "runing (t@s) \<noteq> {}"
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1620
proof(cases "th \<in> runing (t@s)") 
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1621
  case True thus ?thesis by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1622
next
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1623
  case False
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1624
  thus ?thesis using th_blockedE by auto
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1625
qed
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1626
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1627
end
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1628
end
33cb65e00ac0 Tracking ExtGG.thy etc., so that a update to 83 is possible.
zhangx
parents:
diff changeset
  1629