PrioG.thy
author zhangx
Thu, 28 Jan 2016 07:43:05 +0800
changeset 85 d239aa953315
child 88 83dd5345d5d0
permissions -rw-r--r--
Added PrioG.thy as a parallel copy of Correctness.thy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
85
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
     1
theory Correctness
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
     2
imports PIPBasics
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
     3
begin
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
     4
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
     5
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
     6
text {* 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
     7
  The following two auxiliary lemmas are used to reason about @{term Max}.
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
     8
*}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
     9
lemma image_Max_eqI: 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    10
  assumes "finite B"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    11
  and "b \<in> B"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    12
  and "\<forall> x \<in> B. f x \<le> f b"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    13
  shows "Max (f ` B) = f b"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    14
  using assms
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    15
  using Max_eqI by blast 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    16
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    17
lemma image_Max_subset:
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    18
  assumes "finite A"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    19
  and "B \<subseteq> A"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    20
  and "a \<in> B"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    21
  and "Max (f ` A) = f a"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    22
  shows "Max (f ` B) = f a"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    23
proof(rule image_Max_eqI)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    24
  show "finite B"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    25
    using assms(1) assms(2) finite_subset by auto 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    26
next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    27
  show "a \<in> B" using assms by simp
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    28
next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    29
  show "\<forall>x\<in>B. f x \<le> f a"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    30
    by (metis Max_ge assms(1) assms(2) assms(4) 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    31
            finite_imageI image_eqI subsetCE) 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    32
qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    33
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    34
text {*
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    35
  The following locale @{text "highest_gen"} sets the basic context for our
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    36
  investigation: supposing thread @{text th} holds the highest @{term cp}-value
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    37
  in state @{text s}, which means the task for @{text th} is the 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    38
  most urgent. We want to show that  
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    39
  @{text th} is treated correctly by PIP, which means
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    40
  @{text th} will not be blocked unreasonably by other less urgent
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    41
  threads. 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    42
*}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    43
locale highest_gen =
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    44
  fixes s th prio tm
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    45
  assumes vt_s: "vt s"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    46
  and threads_s: "th \<in> threads s"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    47
  and highest: "preced th s = Max ((cp s)`threads s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    48
  -- {* The internal structure of @{term th}'s precedence is exposed:*}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    49
  and preced_th: "preced th s = Prc prio tm" 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    50
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    51
-- {* @{term s} is a valid trace, so it will inherit all results derived for
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    52
      a valid trace: *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    53
sublocale highest_gen < vat_s: valid_trace "s"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    54
  by (unfold_locales, insert vt_s, simp)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    55
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    56
context highest_gen
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    57
begin
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    58
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    59
text {*
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    60
  @{term tm} is the time when the precedence of @{term th} is set, so 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    61
  @{term tm} must be a valid moment index into @{term s}.
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
lemma lt_tm: "tm < length s"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    64
  by (insert preced_tm_lt[OF threads_s preced_th], simp)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    65
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    66
text {*
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    67
  Since @{term th} holds the highest precedence and @{text "cp"}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    68
  is the highest precedence of all threads in the sub-tree of 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    69
  @{text "th"} and @{text th} is among these threads, 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    70
  its @{term cp} must equal to its precedence:
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_s_th: "cp s th = preced th s" (is "?L = ?R")
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    73
proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    74
  have "?L \<le> ?R"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    75
  by (unfold highest, rule Max_ge, 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    76
        auto simp:threads_s finite_threads)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    77
  moreover have "?R \<le> ?L"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    78
    by (unfold vat_s.cp_rec, rule Max_ge, 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    79
        auto simp:the_preced_def vat_s.fsbttRAGs.finite_children)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    80
  ultimately show ?thesis by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    81
qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    82
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    83
lemma highest_cp_preced: "cp s th = Max (the_preced s ` threads s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    84
  using eq_cp_s_th highest max_cp_eq the_preced_def by presburger
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    85
  
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    86
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    87
lemma highest_preced_thread: "preced th s = Max (the_preced s ` threads s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    88
  by (fold eq_cp_s_th, unfold highest_cp_preced, simp)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    89
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    90
lemma highest': "cp s th = Max (cp s ` threads s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    91
  by (simp add: eq_cp_s_th highest)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    92
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    93
end
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    94
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    95
locale extend_highest_gen = highest_gen + 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    96
  fixes t 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    97
  assumes vt_t: "vt (t@s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    98
  and create_low: "Create th' prio' \<in> set t \<Longrightarrow> prio' \<le> prio"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
    99
  and set_diff_low: "Set th' prio' \<in> set t \<Longrightarrow> th' \<noteq> th \<and> prio' \<le> prio"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   100
  and exit_diff: "Exit th' \<in> set t \<Longrightarrow> th' \<noteq> th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   101
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   102
sublocale extend_highest_gen < vat_t: valid_trace "t@s"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   103
  by (unfold_locales, insert vt_t, simp)
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 step_back_vt_app: 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   106
  assumes vt_ts: "vt (t@s)" 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   107
  shows "vt s"
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 vt_ts show ?thesis
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   110
  proof(induct t)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   111
    case Nil
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   112
    from Nil show ?case by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   113
  next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   114
    case (Cons e t)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   115
    assume ih: " vt (t @ s) \<Longrightarrow> vt s"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   116
      and vt_et: "vt ((e # t) @ s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   117
    show ?case
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   118
    proof(rule ih)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   119
      show "vt (t @ s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   120
      proof(rule step_back_vt)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   121
        from vt_et show "vt (e # t @ s)" by simp
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   122
      qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   123
    qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   124
  qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   125
qed
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
(* locale red_extend_highest_gen = extend_highest_gen +
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   128
   fixes i::nat
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
sublocale red_extend_highest_gen <   red_moment: extend_highest_gen "s" "th" "prio" "tm" "(moment i t)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   133
  apply (insert extend_highest_gen_axioms, subst (asm) (1) moment_restm_s [of i t, symmetric])
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   134
  apply (unfold extend_highest_gen_def extend_highest_gen_axioms_def, clarsimp)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   135
  by (unfold highest_gen_def, auto dest:step_back_vt_app)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   136
*)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   137
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   138
context extend_highest_gen
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   139
begin
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   140
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   141
 lemma ind [consumes 0, case_names Nil Cons, induct type]:
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   142
  assumes 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   143
    h0: "R []"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   144
  and h2: "\<And> e t. \<lbrakk>vt (t@s); step (t@s) e; 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   145
                    extend_highest_gen s th prio tm t; 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   146
                    extend_highest_gen s th prio tm (e#t); R t\<rbrakk> \<Longrightarrow> R (e#t)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   147
  shows "R t"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   148
proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   149
  from vt_t extend_highest_gen_axioms show ?thesis
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   150
  proof(induct t)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   151
    from h0 show "R []" .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   152
  next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   153
    case (Cons e t')
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   154
    assume ih: "\<lbrakk>vt (t' @ s); extend_highest_gen s th prio tm t'\<rbrakk> \<Longrightarrow> R t'"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   155
      and vt_e: "vt ((e # t') @ s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   156
      and et: "extend_highest_gen s th prio tm (e # t')"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   157
    from vt_e and step_back_step have stp: "step (t'@s) e" by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   158
    from vt_e and step_back_vt have vt_ts: "vt (t'@s)" by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   159
    show ?case
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   160
    proof(rule h2 [OF vt_ts stp _ _ _ ])
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   161
      show "R t'"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   162
      proof(rule ih)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   163
        from et show ext': "extend_highest_gen s th prio tm t'"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   164
          by (unfold extend_highest_gen_def extend_highest_gen_axioms_def, auto dest:step_back_vt)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   165
      next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   166
        from vt_ts show "vt (t' @ s)" .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   167
      qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   168
    next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   169
      from et show "extend_highest_gen s th prio tm (e # t')" .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   170
    next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   171
      from et show ext': "extend_highest_gen s th prio tm t'"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   172
          by (unfold extend_highest_gen_def extend_highest_gen_axioms_def, auto dest:step_back_vt)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   173
    qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   174
  qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   175
qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   176
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   177
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   178
lemma th_kept: "th \<in> threads (t @ s) \<and> 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   179
                 preced th (t@s) = preced th s" (is "?Q t") 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   180
proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   181
  show ?thesis
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   182
  proof(induct rule:ind)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   183
    case Nil
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   184
    from threads_s
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   185
    show ?case
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   186
      by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   187
  next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   188
    case (Cons e t)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   189
    interpret h_e: extend_highest_gen _ _ _ _ "(e # t)" using Cons by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   190
    interpret h_t: extend_highest_gen _ _ _ _ t using Cons by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   191
    show ?case
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   192
    proof(cases e)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   193
      case (Create thread prio)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   194
      show ?thesis
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   195
      proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   196
        from Cons and Create have "step (t@s) (Create thread prio)" by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   197
        hence "th \<noteq> thread"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   198
        proof(cases)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   199
          case thread_create
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   200
          with Cons show ?thesis by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   201
        qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   202
        hence "preced th ((e # t) @ s)  = preced th (t @ s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   203
          by (unfold Create, auto simp:preced_def)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   204
        moreover note Cons
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   205
        ultimately show ?thesis
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   206
          by (auto simp:Create)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   207
      qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   208
    next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   209
      case (Exit thread)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   210
      from h_e.exit_diff and Exit
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   211
      have neq_th: "thread \<noteq> th" by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   212
      with Cons
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   213
      show ?thesis
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   214
        by (unfold Exit, auto simp:preced_def)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   215
    next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   216
      case (P thread cs)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   217
      with Cons
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   218
      show ?thesis 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   219
        by (auto simp:P preced_def)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   220
    next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   221
      case (V thread cs)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   222
      with Cons
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   223
      show ?thesis 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   224
        by (auto simp:V preced_def)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   225
    next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   226
      case (Set thread prio')
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   227
      show ?thesis
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   228
      proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   229
        from h_e.set_diff_low and Set
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   230
        have "th \<noteq> thread" by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   231
        hence "preced th ((e # t) @ s)  = preced th (t @ s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   232
          by (unfold Set, auto simp:preced_def)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   233
        moreover note Cons
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   234
        ultimately show ?thesis
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   235
          by (auto simp:Set)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   236
      qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   237
    qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   238
  qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   239
qed
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
text {*
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   242
  According to @{thm th_kept}, thread @{text "th"} has its living status
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   243
  and precedence kept along the way of @{text "t"}. The following lemma
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   244
  shows that this preserved precedence of @{text "th"} remains as the highest
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   245
  along the way of @{text "t"}.
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   246
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   247
  The proof goes by induction over @{text "t"} using the specialized
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   248
  induction rule @{thm ind}, followed by case analysis of each possible 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   249
  operations of PIP. All cases follow the same pattern rendered by the 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   250
  generalized introduction rule @{thm "image_Max_eqI"}. 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   251
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   252
  The very essence is to show that precedences, no matter whether they 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   253
  are newly introduced or modified, are always lower than the one held 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   254
  by @{term "th"}, which by @{thm th_kept} is preserved along the way.
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   255
*}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   256
lemma max_kept: "Max (the_preced (t @ s) ` (threads (t@s))) = preced th s"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   257
proof(induct rule:ind)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   258
  case Nil
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   259
  from highest_preced_thread
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   260
  show ?case by simp
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   261
next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   262
  case (Cons e t)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   263
    interpret h_e: extend_highest_gen _ _ _ _ "(e # t)" using Cons by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   264
    interpret h_t: extend_highest_gen _ _ _ _ t using Cons by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   265
  show ?case
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   266
  proof(cases e)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   267
    case (Create thread prio')
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   268
    show ?thesis (is "Max (?f ` ?A) = ?t")
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   269
    proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   270
      -- {* The following is the common pattern of each branch of the case analysis. *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   271
      -- {* The major part is to show that @{text "th"} holds the highest precedence: *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   272
      have "Max (?f ` ?A) = ?f th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   273
      proof(rule image_Max_eqI)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   274
        show "finite ?A" using h_e.finite_threads by auto 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   275
      next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   276
        show "th \<in> ?A" using h_e.th_kept by auto 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   277
      next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   278
        show "\<forall>x\<in>?A. ?f x \<le> ?f th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   279
        proof 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   280
          fix x
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   281
          assume "x \<in> ?A"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   282
          hence "x = thread \<or> x \<in> threads (t@s)" by (auto simp:Create)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   283
          thus "?f x \<le> ?f th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   284
          proof
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   285
            assume "x = thread"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   286
            thus ?thesis 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   287
              apply (simp add:Create the_preced_def preced_def, fold preced_def)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   288
              using Create h_e.create_low h_t.th_kept lt_tm preced_leI2 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   289
              preced_th by force
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   290
          next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   291
            assume h: "x \<in> threads (t @ s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   292
            from Cons(2)[unfolded Create] 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   293
            have "x \<noteq> thread" using h by (cases, auto)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   294
            hence "?f x = the_preced (t@s) x" 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   295
              by (simp add:Create the_preced_def preced_def)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   296
            hence "?f x \<le> Max (the_preced (t@s) ` threads (t@s))"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   297
              by (simp add: h_t.finite_threads h)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   298
            also have "... = ?f th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   299
              by (metis Cons.hyps(5) h_e.th_kept the_preced_def) 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   300
            finally show ?thesis .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   301
          qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   302
        qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   303
      qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   304
     -- {* The minor part is to show that the precedence of @{text "th"} 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   305
           equals to preserved one, given by the foregoing lemma @{thm th_kept} *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   306
      also have "... = ?t" using h_e.th_kept the_preced_def by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   307
      -- {* Then it follows trivially that the precedence preserved
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   308
            for @{term "th"} remains the maximum of all living threads along the way. *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   309
      finally show ?thesis .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   310
    qed 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   311
  next 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   312
    case (Exit thread)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   313
    show ?thesis (is "Max (?f ` ?A) = ?t")
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   314
    proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   315
      have "Max (?f ` ?A) = ?f th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   316
      proof(rule image_Max_eqI)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   317
        show "finite ?A" using h_e.finite_threads by auto 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   318
      next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   319
        show "th \<in> ?A" using h_e.th_kept by auto 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   320
      next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   321
        show "\<forall>x\<in>?A. ?f x \<le> ?f th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   322
        proof 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   323
          fix x
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   324
          assume "x \<in> ?A"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   325
          hence "x \<in> threads (t@s)" by (simp add: Exit) 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   326
          hence "?f x \<le> Max (?f ` threads (t@s))" 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   327
            by (simp add: h_t.finite_threads) 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   328
          also have "... \<le> ?f th" 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   329
            apply (simp add:Exit the_preced_def preced_def, fold preced_def)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   330
            using Cons.hyps(5) h_t.th_kept the_preced_def by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   331
          finally show "?f x \<le> ?f th" .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   332
        qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   333
      qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   334
      also have "... = ?t" using h_e.th_kept the_preced_def by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   335
      finally show ?thesis .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   336
    qed 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   337
  next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   338
    case (P thread cs)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   339
    with Cons
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   340
    show ?thesis by (auto simp:preced_def the_preced_def)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   341
  next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   342
    case (V thread cs)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   343
    with Cons
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   344
    show ?thesis by (auto simp:preced_def the_preced_def)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   345
  next 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   346
    case (Set thread prio')
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   347
    show ?thesis (is "Max (?f ` ?A) = ?t")
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   348
    proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   349
      have "Max (?f ` ?A) = ?f th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   350
      proof(rule image_Max_eqI)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   351
        show "finite ?A" using h_e.finite_threads by auto 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   352
      next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   353
        show "th \<in> ?A" using h_e.th_kept by auto 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   354
      next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   355
        show "\<forall>x\<in>?A. ?f x \<le> ?f th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   356
        proof 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   357
          fix x
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   358
          assume h: "x \<in> ?A"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   359
          show "?f x \<le> ?f th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   360
          proof(cases "x = thread")
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   361
            case True
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   362
            moreover have "the_preced (Set thread prio' # t @ s) thread \<le> the_preced (t @ s) th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   363
            proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   364
              have "the_preced (t @ s) th = Prc prio tm"  
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   365
                using h_t.th_kept preced_th by (simp add:the_preced_def)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   366
              moreover have "prio' \<le> prio" using Set h_e.set_diff_low by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   367
              ultimately show ?thesis by (insert lt_tm, auto simp:the_preced_def preced_def)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   368
            qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   369
            ultimately show ?thesis
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   370
              by (unfold Set, simp add:the_preced_def preced_def)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   371
          next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   372
            case False
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   373
            then have "?f x  = the_preced (t@s) x"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   374
              by (simp add:the_preced_def preced_def Set)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   375
            also have "... \<le> Max (the_preced (t@s) ` threads (t@s))"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   376
              using Set h h_t.finite_threads by auto 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   377
            also have "... = ?f th" by (metis Cons.hyps(5) h_e.th_kept the_preced_def) 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   378
            finally show ?thesis .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   379
          qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   380
        qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   381
      qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   382
      also have "... = ?t" using h_e.th_kept the_preced_def by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   383
      finally show ?thesis .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   384
    qed 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   385
  qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   386
qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   387
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   388
lemma max_preced: "preced th (t@s) = Max (the_preced (t@s) ` (threads (t@s)))"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   389
  by (insert th_kept max_kept, auto)
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
text {*
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   392
  The reason behind the following lemma is that:
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   393
  Since @{term "cp"} is defined as the maximum precedence 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   394
  of those threads contained in the sub-tree of node @{term "Th th"} 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   395
  in @{term "RAG (t@s)"}, and all these threads are living threads, and 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   396
  @{term "th"} is also among them, the maximum precedence of 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   397
  them all must be the one for @{text "th"}.
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   398
*}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   399
lemma th_cp_max_preced: 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   400
  "cp (t@s) th = Max (the_preced (t@s) ` (threads (t@s)))" (is "?L = ?R") 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   401
proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   402
  let ?f = "the_preced (t@s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   403
  have "?L = ?f th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   404
  proof(unfold cp_alt_def, rule image_Max_eqI)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   405
    show "finite {th'. Th th' \<in> subtree (RAG (t @ s)) (Th th)}"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   406
    proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   407
      have "{th'. Th th' \<in> subtree (RAG (t @ s)) (Th th)} = 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   408
            the_thread ` {n . n \<in> subtree (RAG (t @ s)) (Th th) \<and>
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   409
                            (\<exists> th'. n = Th th')}"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   410
      by (smt Collect_cong Setcompr_eq_image mem_Collect_eq the_thread.simps)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   411
      moreover have "finite ..." by (simp add: vat_t.fsbtRAGs.finite_subtree) 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   412
      ultimately show ?thesis by simp
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   413
    qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   414
  next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   415
    show "th \<in> {th'. Th th' \<in> subtree (RAG (t @ s)) (Th th)}"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   416
      by (auto simp:subtree_def)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   417
  next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   418
    show "\<forall>x\<in>{th'. Th th' \<in> subtree (RAG (t @ s)) (Th th)}.
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   419
               the_preced (t @ s) x \<le> the_preced (t @ s) th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   420
    proof
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   421
      fix th'
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   422
      assume "th' \<in> {th'. Th th' \<in> subtree (RAG (t @ s)) (Th th)}"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   423
      hence "Th th' \<in> subtree (RAG (t @ s)) (Th th)" by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   424
      moreover have "... \<subseteq> Field (RAG (t @ s)) \<union> {Th th}"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   425
        by (meson subtree_Field)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   426
      ultimately have "Th th' \<in> ..." by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   427
      hence "th' \<in> threads (t@s)" 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   428
      proof
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   429
        assume "Th th' \<in> {Th th}"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   430
        thus ?thesis using th_kept by auto 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   431
      next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   432
        assume "Th th' \<in> Field (RAG (t @ s))"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   433
        thus ?thesis using vat_t.not_in_thread_isolated by blast 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   434
      qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   435
      thus "the_preced (t @ s) th' \<le> the_preced (t @ s) th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   436
        by (metis Max_ge finite_imageI finite_threads image_eqI 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   437
               max_kept th_kept the_preced_def)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   438
    qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   439
  qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   440
  also have "... = ?R" by (simp add: max_preced the_preced_def) 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   441
  finally show ?thesis .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   442
qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   443
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   444
lemma th_cp_max[simp]: "Max (cp (t@s) ` threads (t@s)) = cp (t@s) th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   445
  using max_cp_eq th_cp_max_preced the_preced_def vt_t by presburger
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   446
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   447
lemma [simp]: "Max (cp (t@s) ` threads (t@s)) = Max (the_preced (t@s) ` threads (t@s))"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   448
  by (simp add: th_cp_max_preced)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   449
  
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   450
lemma [simp]: "Max (the_preced (t@s) ` threads (t@s)) = the_preced (t@s) th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   451
  using max_kept th_kept the_preced_def by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   452
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   453
lemma [simp]: "the_preced (t@s) th = preced th (t@s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   454
  using the_preced_def by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   455
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   456
lemma [simp]: "preced th (t@s) = preced th s"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   457
  by (simp add: th_kept)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   458
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   459
lemma [simp]: "cp s th = preced th s"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   460
  by (simp add: eq_cp_s_th)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   461
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   462
lemma th_cp_preced [simp]: "cp (t@s) th = preced th s"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   463
  by (fold max_kept, unfold th_cp_max_preced, simp)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   464
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   465
lemma preced_less:
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   466
  assumes th'_in: "th' \<in> threads s"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   467
  and neq_th': "th' \<noteq> th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   468
  shows "preced th' s < preced th s"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   469
  using assms
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   470
by (metis Max.coboundedI finite_imageI highest not_le order.trans 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   471
    preced_linorder rev_image_eqI threads_s vat_s.finite_threads 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   472
    vat_s.le_cp)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   473
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   474
section {* The `blocking thread` *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   475
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   476
text {* 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   477
  The purpose of PIP is to ensure that the most 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   478
  urgent thread @{term th} is not blocked unreasonably. 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   479
  Therefore, a clear picture of the blocking thread is essential 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   480
  to assure people that the purpose is fulfilled. 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   481
  
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   482
  In this section, we are going to derive a series of lemmas 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   483
  with finally give rise to a picture of the blocking thread. 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   484
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   485
  By `blocking thread`, we mean a thread in running state but 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   486
  different from thread @{term th}.
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   487
*}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   488
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   489
text {*
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   490
  The following lemmas shows that the @{term cp}-value 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   491
  of the blocking thread @{text th'} equals to the highest
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   492
  precedence in the whole system.
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   493
*}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   494
lemma runing_preced_inversion:
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   495
  assumes runing': "th' \<in> runing (t@s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   496
  shows "cp (t@s) th' = preced th s" (is "?L = ?R")
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   497
proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   498
  have "?L = Max (cp (t @ s) ` readys (t @ s))" using assms
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   499
      by (unfold runing_def, auto)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   500
  also have "\<dots> = ?R"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   501
      by (metis th_cp_max th_cp_preced vat_t.max_cp_readys_threads) 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   502
  finally show ?thesis .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   503
qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   504
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   505
text {*
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   506
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   507
  The following lemma shows how the counters for @{term "P"} and
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   508
  @{term "V"} operations relate to the running threads in the states
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   509
  @{term s} and @{term "t @ s"}.  The lemma shows that if a thread's
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   510
  @{term "P"}-count equals its @{term "V"}-count (which means it no
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   511
  longer has any resource in its possession), it cannot be a running
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   512
  thread.
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   513
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   514
  The proof is by contraction with the assumption @{text "th' \<noteq> th"}.
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   515
  The key is the use of @{thm count_eq_dependants} to derive the
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   516
  emptiness of @{text th'}s @{term dependants}-set from the balance of
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   517
  its @{term P} and @{term V} counts.  From this, it can be shown
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   518
  @{text th'}s @{term cp}-value equals to its own precedence.
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   519
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   520
  On the other hand, since @{text th'} is running, by @{thm
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   521
  runing_preced_inversion}, its @{term cp}-value equals to the
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   522
  precedence of @{term th}.
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   523
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   524
  Combining the above two resukts we have that @{text th'} and @{term
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   525
  th} have the same precedence. By uniqueness of precedences, we have
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   526
  @{text "th' = th"}, which is in contradiction with the assumption
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   527
  @{text "th' \<noteq> th"}.
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   528
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   529
*} 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   530
                      
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   531
lemma eq_pv_blocked: (* ddd *)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   532
  assumes neq_th': "th' \<noteq> th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   533
  and eq_pv: "cntP (t@s) th' = cntV (t@s) th'"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   534
  shows "th' \<notin> runing (t@s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   535
proof
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   536
  assume otherwise: "th' \<in> runing (t@s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   537
  show False
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   538
  proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   539
    have th'_in: "th' \<in> threads (t@s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   540
        using otherwise readys_threads runing_def by auto 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   541
    have "th' = th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   542
    proof(rule preced_unique)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   543
      -- {* The proof goes like this: 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   544
            it is first shown that the @{term preced}-value of @{term th'} 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   545
            equals to that of @{term th}, then by uniqueness 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   546
            of @{term preced}-values (given by lemma @{thm preced_unique}), 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   547
            @{term th'} equals to @{term th}: *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   548
      show "preced th' (t @ s) = preced th (t @ s)" (is "?L = ?R")
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   549
      proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   550
        -- {* Since the counts of @{term th'} are balanced, the subtree
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   551
              of it contains only itself, so, its @{term cp}-value
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   552
              equals its @{term preced}-value: *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   553
        have "?L = cp (t@s) th'"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   554
          by (unfold cp_eq_cpreced cpreced_def count_eq_dependants[OF eq_pv], simp)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   555
        -- {* Since @{term "th'"} is running, by @{thm runing_preced_inversion},
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   556
              its @{term cp}-value equals @{term "preced th s"}, 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   557
              which equals to @{term "?R"} by simplification: *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   558
        also have "... = ?R" 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   559
        thm runing_preced_inversion
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   560
            using runing_preced_inversion[OF otherwise] by simp
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   561
        finally show ?thesis .
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
    qed (auto simp: th'_in th_kept)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   564
    with `th' \<noteq> th` show ?thesis by simp
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
qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   567
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   568
text {*
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   569
  The following lemma is the extrapolation of @{thm eq_pv_blocked}.
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   570
  It says if a thread, different from @{term th}, 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   571
  does not hold any resource at the very beginning,
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   572
  it will keep hand-emptied in the future @{term "t@s"}.
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
lemma eq_pv_persist: (* ddd *)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   575
  assumes neq_th': "th' \<noteq> th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   576
  and eq_pv: "cntP s th' = cntV s th'"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   577
  shows "cntP (t@s) th' = cntV (t@s) th'"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   578
proof(induction rule:ind) -- {* The proof goes by induction. *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   579
  -- {* The nontrivial case is for the @{term Cons}: *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   580
  case (Cons e t)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   581
  -- {* All results derived so far hold for both @{term s} and @{term "t@s"}: *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   582
  interpret vat_t: extend_highest_gen s th prio tm t using Cons by simp
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   583
  interpret vat_e: extend_highest_gen s th prio tm "(e # t)" using Cons by simp
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   584
  show ?case
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   585
  proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   586
    -- {* It can be proved that @{term cntP}-value of @{term th'} does not change
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   587
          by the happening of event @{term e}: *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   588
    have "cntP ((e#t)@s) th' = cntP (t@s) th'"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   589
    proof(rule ccontr) -- {* Proof by contradiction. *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   590
      -- {* Suppose @{term cntP}-value of @{term th'} is changed by @{term e}: *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   591
      assume otherwise: "cntP ((e # t) @ s) th' \<noteq> cntP (t @ s) th'"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   592
      -- {* Then the actor of @{term e} must be @{term th'} and @{term e}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   593
            must be a @{term P}-event: *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   594
      hence "isP e" "actor e = th'" by (auto simp:cntP_diff_inv) 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   595
      with vat_t.actor_inv[OF Cons(2)]
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   596
      -- {* According to @{thm actor_inv}, @{term th'} must be running at 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   597
            the moment @{term "t@s"}: *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   598
      have "th' \<in> runing (t@s)" by (cases e, auto)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   599
      -- {* However, an application of @{thm eq_pv_blocked} to induction hypothesis
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   600
            shows @{term th'} can not be running at moment  @{term "t@s"}: *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   601
      moreover have "th' \<notin> runing (t@s)" 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   602
               using vat_t.eq_pv_blocked[OF neq_th' Cons(5)] .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   603
      -- {* Contradiction is finally derived: *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   604
      ultimately show False by simp
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   605
    qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   606
    -- {* It can also be proved that @{term cntV}-value of @{term th'} does not change
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   607
          by the happening of event @{term e}: *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   608
    -- {* The proof follows exactly the same pattern as the case for @{term cntP}-value: *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   609
    moreover have "cntV ((e#t)@s) th' = cntV (t@s) th'"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   610
    proof(rule ccontr) -- {* Proof by contradiction. *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   611
      assume otherwise: "cntV ((e # t) @ s) th' \<noteq> cntV (t @ s) th'"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   612
      hence "isV e" "actor e = th'" by (auto simp:cntV_diff_inv) 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   613
      with vat_t.actor_inv[OF Cons(2)]
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   614
      have "th' \<in> runing (t@s)" by (cases e, auto)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   615
      moreover have "th' \<notin> runing (t@s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   616
          using vat_t.eq_pv_blocked[OF neq_th' Cons(5)] .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   617
      ultimately show False by simp
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   618
    qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   619
    -- {* Finally, it can be shown that the @{term cntP} and @{term cntV} 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   620
          value for @{term th'} are still in balance, so @{term th'} 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   621
          is still hand-emptied after the execution of event @{term e}: *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   622
    ultimately show ?thesis using Cons(5) by metis
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
qed (auto simp:eq_pv)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   625
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   626
text {*
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   627
  By combining @{thm  eq_pv_blocked} and @{thm eq_pv_persist},
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   628
  it can be derived easily that @{term th'} can not be running in the future:
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   629
*}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   630
lemma eq_pv_blocked_persist:
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   631
  assumes neq_th': "th' \<noteq> th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   632
  and eq_pv: "cntP s th' = cntV s th'"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   633
  shows "th' \<notin> runing (t@s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   634
  using assms
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   635
  by (simp add: eq_pv_blocked eq_pv_persist) 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   636
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   637
text {*
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   638
  The following lemma shows the blocking thread @{term th'}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   639
  must hold some resource in the very beginning. 
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
lemma runing_cntP_cntV_inv: (* ddd *)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   642
  assumes is_runing: "th' \<in> runing (t@s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   643
  and neq_th': "th' \<noteq> th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   644
  shows "cntP s th' > cntV s th'"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   645
  using assms
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   646
proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   647
  -- {* First, it can be shown that the number of @{term P} and
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   648
        @{term V} operations can not be equal for thred @{term th'} *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   649
  have "cntP s th' \<noteq> cntV s th'"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   650
  proof
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   651
     -- {* The proof goes by contradiction, suppose otherwise: *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   652
    assume otherwise: "cntP s th' = cntV s th'"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   653
    -- {* By applying @{thm  eq_pv_blocked_persist} to this: *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   654
    from eq_pv_blocked_persist[OF neq_th' otherwise] 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   655
    -- {* we have that @{term th'} can not be running at moment @{term "t@s"}: *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   656
    have "th' \<notin> runing (t@s)" .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   657
    -- {* This is obvious in contradiction with assumption @{thm is_runing}  *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   658
    thus False using is_runing by simp
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   659
  qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   660
  -- {* However, the number of @{term V} is always less or equal to @{term P}: *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   661
  moreover have "cntV s th' \<le> cntP s th'" using vat_s.cnp_cnv_cncs by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   662
  -- {* Thesis is finally derived by combining the these two results: *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   663
  ultimately show ?thesis by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   664
qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   665
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   666
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   667
text {*
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   668
  The following lemmas shows the blocking thread @{text th'} must be live 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   669
  at the very beginning, i.e. the moment (or state) @{term s}. 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   670
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   671
  The proof is a  simple combination of the results above:
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 runing_threads_inv: 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   674
  assumes runing': "th' \<in> runing (t@s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   675
  and neq_th': "th' \<noteq> th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   676
  shows "th' \<in> threads s"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   677
proof(rule ccontr) -- {* Proof by contradiction: *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   678
  assume otherwise: "th' \<notin> threads s" 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   679
  have "th' \<notin> runing (t @ s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   680
  proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   681
    from vat_s.cnp_cnv_eq[OF otherwise]
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   682
    have "cntP s th' = cntV s th'" .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   683
    from eq_pv_blocked_persist[OF neq_th' this]
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   684
    show ?thesis .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   685
  qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   686
  with runing' show False by simp
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   687
qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   688
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   689
text {*
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   690
  The following lemma summarizes several foregoing 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   691
  lemmas to give an overall picture of the blocking thread @{text "th'"}:
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   692
*}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   693
lemma runing_inversion: (* ddd, one of the main lemmas to present *)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   694
  assumes runing': "th' \<in> runing (t@s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   695
  and neq_th: "th' \<noteq> th"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   696
  shows "th' \<in> threads s"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   697
  and    "\<not>detached s th'"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   698
  and    "cp (t@s) th' = preced th s"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   699
proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   700
  from runing_threads_inv[OF assms]
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   701
  show "th' \<in> threads s" .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   702
next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   703
  from runing_cntP_cntV_inv[OF runing' neq_th]
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   704
  show "\<not>detached s th'" using vat_s.detached_eq by simp
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   705
next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   706
  from runing_preced_inversion[OF runing']
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   707
  show "cp (t@s) th' = preced th s" .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   708
qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   709
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   710
section {* The existence of `blocking thread` *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   711
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   712
text {* 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   713
  Suppose @{term th} is not running, it is first shown that
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   714
  there is a path in RAG leading from node @{term th} to another thread @{text "th'"} 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   715
  in the @{term readys}-set (So @{text "th'"} is an ancestor of @{term th}}).
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   716
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   717
  Now, since @{term readys}-set is non-empty, there must be
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   718
  one in it which holds the highest @{term cp}-value, which, by definition, 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   719
  is the @{term runing}-thread. However, we are going to show more: this running thread
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   720
  is exactly @{term "th'"}.
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   721
     *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   722
lemma th_blockedE: (* ddd, the other main lemma to be presented: *)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   723
  assumes "th \<notin> runing (t@s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   724
  obtains th' where "Th th' \<in> ancestors (RAG (t @ s)) (Th th)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   725
                    "th' \<in> runing (t@s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   726
proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   727
  -- {* According to @{thm vat_t.th_chain_to_ready}, either 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   728
        @{term "th"} is in @{term "readys"} or there is path leading from it to 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   729
        one thread in @{term "readys"}. *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   730
  have "th \<in> readys (t @ s) \<or> (\<exists>th'. th' \<in> readys (t @ s) \<and> (Th th, Th th') \<in> (RAG (t @ s))\<^sup>+)" 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   731
    using th_kept vat_t.th_chain_to_ready by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   732
  -- {* However, @{term th} can not be in @{term readys}, because otherwise, since 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   733
       @{term th} holds the highest @{term cp}-value, it must be @{term "runing"}. *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   734
  moreover have "th \<notin> readys (t@s)" 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   735
    using assms runing_def th_cp_max vat_t.max_cp_readys_threads by auto 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   736
  -- {* So, there must be a path from @{term th} to another thread @{text "th'"} in 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   737
        term @{term readys}: *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   738
  ultimately obtain th' where th'_in: "th' \<in> readys (t@s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   739
                          and dp: "(Th th, Th th') \<in> (RAG (t @ s))\<^sup>+" by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   740
  -- {* We are going to show that this @{term th'} is running. *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   741
  have "th' \<in> runing (t@s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   742
  proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   743
    -- {* We only need to show that this @{term th'} holds the highest @{term cp}-value: *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   744
    have "cp (t@s) th' = Max (cp (t@s) ` readys (t@s))" (is "?L = ?R")
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   745
    proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   746
      have "?L =  Max ((the_preced (t @ s) \<circ> the_thread) ` subtree (tRAG (t @ s)) (Th th'))"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   747
        by (unfold cp_alt_def1, simp)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   748
      also have "... = (the_preced (t @ s) \<circ> the_thread) (Th th)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   749
      proof(rule image_Max_subset)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   750
        show "finite (Th ` (threads (t@s)))" by (simp add: vat_t.finite_threads)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   751
      next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   752
        show "subtree (tRAG (t @ s)) (Th th') \<subseteq> Th ` threads (t @ s)"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   753
          by (metis Range.intros dp trancl_range vat_t.range_in vat_t.subtree_tRAG_thread) 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   754
      next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   755
        show "Th th \<in> subtree (tRAG (t @ s)) (Th th')" using dp
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   756
                    by (unfold tRAG_subtree_eq, auto simp:subtree_def)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   757
      next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   758
        show "Max ((the_preced (t @ s) \<circ> the_thread) ` Th ` threads (t @ s)) =
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   759
                      (the_preced (t @ s) \<circ> the_thread) (Th th)" (is "Max ?L = _")
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   760
        proof -
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   761
          have "?L = the_preced (t @ s) `  threads (t @ s)" 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   762
                     by (unfold image_comp, rule image_cong, auto)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   763
          thus ?thesis using max_preced the_preced_def by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   764
        qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   765
      qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   766
      also have "... = ?R"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   767
        using th_cp_max th_cp_preced th_kept 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   768
              the_preced_def vat_t.max_cp_readys_threads by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   769
      finally show ?thesis .
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   770
    qed 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   771
    -- {* Now, since @{term th'} holds the highest @{term cp} 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   772
          and we have already show it is in @{term readys},
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   773
          it is @{term runing} by definition. *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   774
    with `th' \<in> readys (t@s)` show ?thesis by (simp add: runing_def) 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   775
  qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   776
  -- {* It is easy to show @{term th'} is an ancestor of @{term th}: *}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   777
  moreover have "Th th' \<in> ancestors (RAG (t @ s)) (Th th)" 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   778
    using `(Th th, Th th') \<in> (RAG (t @ s))\<^sup>+` by (auto simp:ancestors_def)
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   779
  ultimately show ?thesis using that by metis
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   780
qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   781
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   782
text {*
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   783
  Now it is easy to see there is always a thread to run by case analysis
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   784
  on whether thread @{term th} is running: if the answer is Yes, the 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   785
  the running thread is obviously @{term th} itself; otherwise, the running
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   786
  thread is the @{text th'} given by lemma @{thm th_blockedE}.
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   787
*}
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   788
lemma live: "runing (t@s) \<noteq> {}"
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   789
proof(cases "th \<in> runing (t@s)") 
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   790
  case True thus ?thesis by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   791
next
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   792
  case False
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   793
  thus ?thesis using th_blockedE by auto
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   794
qed
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   795
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   796
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   797
end
d239aa953315 Added PrioG.thy as a parallel copy of Correctness.thy
zhangx
parents:
diff changeset
   798
end