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