Correctness.thy
author Christian Urban <urbanc@in.tum.de>
Tue, 27 Jun 2017 14:49:42 +0100
changeset 179 f9e6c4166476
parent 170 def87c589516
child 197 ca4ddf26a7c7
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
93
524bd3caa6b6 The overwriten original .thy files are working now. The ones in last revision aren't.
zhangx
parents: 92
diff changeset
     1
theory Correctness
524bd3caa6b6 The overwriten original .thy files are working now. The ones in last revision aren't.
zhangx
parents: 92
diff changeset
     2
imports PIPBasics
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     3
begin
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
179
f9e6c4166476 updated
Christian Urban <urbanc@in.tum.de>
parents: 170
diff changeset
     5
(* hg cat -r 176 Correctness.thy *)
f9e6c4166476 updated
Christian Urban <urbanc@in.tum.de>
parents: 170
diff changeset
     6
154
9756a51f2223 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 145
diff changeset
     7
lemma actions_of_len_cons [iff]: 
9756a51f2223 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 145
diff changeset
     8
    "length (actions_of ts (e#t)) \<le> length ((actions_of ts t)) + 1"
9756a51f2223 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 145
diff changeset
     9
      by  (unfold actions_of_def, simp)
9756a51f2223 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 145
diff changeset
    10
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    11
text {* 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    12
  The following two auxiliary lemmas are used to reason about @{term Max}.
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    13
*}
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    14
lemma image_Max_eqI: 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    15
  assumes "finite B"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    16
  and "b \<in> B"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    17
  and "\<forall> x \<in> B. f x \<le> f b"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    18
  shows "Max (f ` B) = f b"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    19
  using assms
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    20
  using Max_eqI by blast 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    21
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    22
lemma image_Max_subset:
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    23
  assumes "finite A"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    24
  and "B \<subseteq> A"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    25
  and "a \<in> B"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    26
  and "Max (f ` A) = f a"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    27
  shows "Max (f ` B) = f a"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    28
proof(rule image_Max_eqI)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    29
  show "finite B"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    30
    using assms(1) assms(2) finite_subset by auto 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    31
next
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    32
  show "a \<in> B" using assms by simp
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    33
next
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    34
  show "\<forall>x\<in>B. f x \<le> f a"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    35
    by (metis Max_ge assms(1) assms(2) assms(4) 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    36
            finite_imageI image_eqI subsetCE) 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    38
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    39
text {*
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    40
  The following locale @{text "highest_gen"} sets the basic context for our
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    41
  investigation: supposing thread @{text th} holds the highest @{term cp}-value
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    42
  in state @{text s}, which means the task for @{text th} is the 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    43
  most urgent. We want to show that  
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    44
  @{text th} is treated correctly by PIP, which means
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    45
  @{text th} will not be blocked unreasonably by other less urgent
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    46
  threads. 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    47
*}
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    48
locale highest_gen =
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    49
  fixes s th prio tm
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    50
  assumes vt_s: "vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    51
  and threads_s: "th \<in> threads s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    52
  and highest: "preced th s = Max ((cp s)`threads s)"
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    53
  -- {* The internal structure of @{term th}'s precedence is exposed:*}
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    54
  and preced_th: "preced th s = Prc prio tm" 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    55
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    56
-- {* @{term s} is a valid trace, so it will inherit all results derived for
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    57
      a valid trace: *}
122
420e03a2d9cc all updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 116
diff changeset
    58
sublocale highest_gen < vat_s?: valid_trace "s"
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
    59
  by (unfold_locales, insert vt_s, simp)
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
    60
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
    61
fun occs where
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
    62
  "occs Q [] = (if Q [] then 1 else 0::nat)" |
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
    63
  "occs Q (x#xs) = (if Q (x#xs) then (1 + occs Q xs) else occs Q xs)"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
    64
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
    65
lemma occs_le: "occs Q t + occs (\<lambda> e. \<not> Q e) t \<le> (1 + length t)"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
    66
  by  (induct t, auto)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
    67
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    68
context highest_gen
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    69
begin
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    70
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    71
text {*
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    72
  @{term tm} is the time when the precedence of @{term th} is set, so 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    73
  @{term tm} must be a valid moment index into @{term s}.
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    74
*}
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    75
lemma lt_tm: "tm < length s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    76
  by (insert preced_tm_lt[OF threads_s preced_th], simp)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    77
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    78
text {*
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    79
  Since @{term th} holds the highest precedence and @{text "cp"}
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    80
  is the highest precedence of all threads in the sub-tree of 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    81
  @{text "th"} and @{text th} is among these threads, 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    82
  its @{term cp} must equal to its precedence:
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    83
*}
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
    84
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
    85
lemma eq_cp_s_th: "cp s th = preced th s" (is "?L = ?R")
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    86
proof -
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
    87
  have "?L \<le> ?R"
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
    88
  by (unfold highest, rule Max_ge, 
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
    89
        auto simp:threads_s finite_threads)
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
    90
  moreover have "?R \<le> ?L"
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
    91
    by (unfold vat_s.cp_rec, rule Max_ge, 
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
    92
        auto simp:the_preced_def vat_s.fsbttRAGs.finite_children)
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
    93
  ultimately show ?thesis by auto
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    94
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    95
68
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
    96
lemma highest_cp_preced: "cp s th = Max (the_preced s ` threads s)"
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
    97
  using eq_cp_s_th highest max_cp_eq the_preced_def by presburger
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
    98
  
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    99
68
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   100
lemma highest_preced_thread: "preced th s = Max (the_preced s ` threads s)"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   101
  by (fold eq_cp_s_th, unfold highest_cp_preced, simp)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   102
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   103
lemma highest': "cp s th = Max (cp s ` threads s)"
68
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   104
  by (simp add: eq_cp_s_th highest)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   105
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   106
end
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   107
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   108
locale extend_highest_gen = highest_gen + 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   109
  fixes t 
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   110
  assumes vt_t: "vt (t@s)"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   111
  and create_low: "Create th' prio' \<in> set t \<Longrightarrow> prio' \<le> prio"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   112
  and set_diff_low: "Set th' prio' \<in> set t \<Longrightarrow> th' \<noteq> th \<and> prio' \<le> prio"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   113
  and exit_diff: "Exit th' \<in> set t \<Longrightarrow> th' \<noteq> th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   114
122
420e03a2d9cc all updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 116
diff changeset
   115
sublocale extend_highest_gen < vat_t?: valid_trace "t@s"
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   116
  by (unfold_locales, insert vt_t, simp)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   117
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   118
lemma step_back_vt_app: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   119
  assumes vt_ts: "vt (t@s)" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   120
  shows "vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   121
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   122
  from vt_ts show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   123
  proof(induct t)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   124
    case Nil
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   125
    from Nil show ?case by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   126
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   127
    case (Cons e t)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   128
    assume ih: " vt (t @ s) \<Longrightarrow> vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   129
      and vt_et: "vt ((e # t) @ s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   130
    show ?case
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   131
    proof(rule ih)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   132
      show "vt (t @ s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   133
      proof(rule step_back_vt)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   134
        from vt_et show "vt (e # t @ s)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   135
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   136
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   137
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   138
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   139
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   140
(* locale red_extend_highest_gen = extend_highest_gen +
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   141
   fixes i::nat
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   142
*)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   143
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   144
(*
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   145
sublocale red_extend_highest_gen <   red_moment: extend_highest_gen "s" "th" "prio" "tm" "(moment i t)"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   146
  apply (insert extend_highest_gen_axioms, subst (asm) (1) moment_restm_s [of i t, symmetric])
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   147
  apply (unfold extend_highest_gen_def extend_highest_gen_axioms_def, clarsimp)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   148
  by (unfold highest_gen_def, auto dest:step_back_vt_app)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   149
*)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   150
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   151
context extend_highest_gen
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   152
begin
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   153
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   154
 lemma ind [consumes 0, case_names Nil Cons, induct type]:
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   155
  assumes 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   156
    h0: "R []"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   157
  and h2: "\<And> e t. \<lbrakk>vt (t@s); step (t@s) e; 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   158
                    extend_highest_gen s th prio tm t; 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   159
                    extend_highest_gen s th prio tm (e#t); R t\<rbrakk> \<Longrightarrow> R (e#t)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   160
  shows "R t"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   161
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   162
  from vt_t extend_highest_gen_axioms show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   163
  proof(induct t)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   164
    from h0 show "R []" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   165
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   166
    case (Cons e t')
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   167
    assume ih: "\<lbrakk>vt (t' @ s); extend_highest_gen s th prio tm t'\<rbrakk> \<Longrightarrow> R t'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   168
      and vt_e: "vt ((e # t') @ s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   169
      and et: "extend_highest_gen s th prio tm (e # t')"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   170
    from vt_e and step_back_step have stp: "step (t'@s) e" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   171
    from vt_e and step_back_vt have vt_ts: "vt (t'@s)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   172
    show ?case
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   173
    proof(rule h2 [OF vt_ts stp _ _ _ ])
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   174
      show "R t'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   175
      proof(rule ih)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   176
        from et show ext': "extend_highest_gen s th prio tm t'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   177
          by (unfold extend_highest_gen_def extend_highest_gen_axioms_def, auto dest:step_back_vt)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   178
      next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   179
        from vt_ts show "vt (t' @ s)" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   180
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   181
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   182
      from et show "extend_highest_gen s th prio tm (e # t')" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   183
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   184
      from et show ext': "extend_highest_gen s th prio tm t'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   185
          by (unfold extend_highest_gen_def extend_highest_gen_axioms_def, auto dest:step_back_vt)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   186
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   187
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   188
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   189
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   190
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   191
lemma th_kept: "th \<in> threads (t @ s) \<and> 
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   192
                 preced th (t@s) = preced th s" (is "?Q t") 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   193
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   194
  show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   195
  proof(induct rule:ind)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   196
    case Nil
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   197
    from threads_s
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   198
    show ?case
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   199
      by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   200
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   201
    case (Cons e t)
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   202
    interpret h_e: extend_highest_gen _ _ _ _ "(e # t)" using Cons by auto
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   203
    interpret h_t: extend_highest_gen _ _ _ _ t using Cons by auto
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   204
    show ?case
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   205
    proof(cases e)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   206
      case (Create thread prio)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   207
      show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   208
      proof -
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   209
        from Cons and Create have "step (t@s) (Create thread prio)" by auto
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   210
        hence "th \<noteq> thread"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   211
        proof(cases)
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   212
          case thread_create
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   213
          with Cons show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   214
        qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   215
        hence "preced th ((e # t) @ s)  = preced th (t @ s)"
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   216
          by (unfold Create, auto simp:preced_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   217
        moreover note Cons
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   218
        ultimately show ?thesis
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   219
          by (auto simp:Create)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   220
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   221
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   222
      case (Exit thread)
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   223
      from h_e.exit_diff and Exit
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   224
      have neq_th: "thread \<noteq> th" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   225
      with Cons
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   226
      show ?thesis
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   227
        by (unfold Exit, auto simp:preced_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   228
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   229
      case (P thread cs)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   230
      with Cons
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   231
      show ?thesis 
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   232
        by (auto simp:P preced_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   233
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   234
      case (V thread cs)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   235
      with Cons
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   236
      show ?thesis 
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   237
        by (auto simp:V preced_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   238
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   239
      case (Set thread prio')
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   240
      show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   241
      proof -
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   242
        from h_e.set_diff_low and Set
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   243
        have "th \<noteq> thread" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   244
        hence "preced th ((e # t) @ s)  = preced th (t @ s)"
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   245
          by (unfold Set, auto simp:preced_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   246
        moreover note Cons
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   247
        ultimately show ?thesis
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   248
          by (auto simp:Set)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   249
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   250
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   251
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   252
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   253
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   254
text {*
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   255
  According to @{thm th_kept}, thread @{text "th"} has its living status
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   256
  and precedence kept along the way of @{text "t"}. The following lemma
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   257
  shows that this preserved precedence of @{text "th"} remains as the highest
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   258
  along the way of @{text "t"}.
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   259
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   260
  The proof goes by induction over @{text "t"} using the specialized
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   261
  induction rule @{thm ind}, followed by case analysis of each possible 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   262
  operations of PIP. All cases follow the same pattern rendered by the 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   263
  generalized introduction rule @{thm "image_Max_eqI"}. 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   264
68
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   265
  The very essence is to show that precedences, no matter whether they 
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   266
  are newly introduced or modified, are always lower than the one held 
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   267
  by @{term "th"}, which by @{thm th_kept} is preserved along the way.
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   268
*}
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   269
lemma max_kept: "Max (the_preced (t @ s) ` (threads (t@s))) = preced th s"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   270
proof(induct rule:ind)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   271
  case Nil
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   272
  from highest_preced_thread
68
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   273
  show ?case by simp
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   274
next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   275
  case (Cons e t)
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   276
    interpret h_e: extend_highest_gen _ _ _ _ "(e # t)" using Cons by auto
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   277
    interpret h_t: extend_highest_gen _ _ _ _ t using Cons by auto
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   278
  show ?case
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   279
  proof(cases e)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   280
    case (Create thread prio')
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   281
    show ?thesis (is "Max (?f ` ?A) = ?t")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   282
    proof -
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   283
      -- {* The following is the common pattern of each branch of the case analysis. *}
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   284
      -- {* The major part is to show that @{text "th"} holds the highest precedence: *}
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   285
      have "Max (?f ` ?A) = ?f th"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   286
      proof(rule image_Max_eqI)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   287
        show "finite ?A" using h_e.finite_threads by auto 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   288
      next
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   289
        show "th \<in> ?A" using h_e.th_kept by auto 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   290
      next
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   291
        show "\<forall>x\<in>?A. ?f x \<le> ?f th"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   292
        proof 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   293
          fix x
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   294
          assume "x \<in> ?A"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   295
          hence "x = thread \<or> x \<in> threads (t@s)" by (auto simp:Create)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   296
          thus "?f x \<le> ?f th"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   297
          proof
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   298
            assume "x = thread"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   299
            thus ?thesis 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   300
              apply (simp add:Create the_preced_def preced_def, fold preced_def)
68
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   301
              using Create h_e.create_low h_t.th_kept lt_tm preced_leI2 
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   302
              preced_th by force
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   303
          next
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   304
            assume h: "x \<in> threads (t @ s)"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   305
            from Cons(2)[unfolded Create] 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   306
            have "x \<noteq> thread" using h by (cases, auto)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   307
            hence "?f x = the_preced (t@s) x" 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   308
              by (simp add:Create the_preced_def preced_def)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   309
            hence "?f x \<le> Max (the_preced (t@s) ` threads (t@s))"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   310
              by (simp add: h_t.finite_threads h)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   311
            also have "... = ?f th"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   312
              by (metis Cons.hyps(5) h_e.th_kept the_preced_def) 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   313
            finally show ?thesis .
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   314
          qed
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   315
        qed
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   316
      qed
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   317
     -- {* The minor part is to show that the precedence of @{text "th"} 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   318
           equals to preserved one, given by the foregoing lemma @{thm th_kept} *}
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   319
      also have "... = ?t" using h_e.th_kept the_preced_def by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   320
      -- {* Then it follows trivially that the precedence preserved
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   321
            for @{term "th"} remains the maximum of all living threads along the way. *}
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   322
      finally show ?thesis .
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   323
    qed 
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   324
  next 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   325
    case (Exit thread)
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   326
    show ?thesis (is "Max (?f ` ?A) = ?t")
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   327
    proof -
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   328
      have "Max (?f ` ?A) = ?f th"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   329
      proof(rule image_Max_eqI)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   330
        show "finite ?A" using h_e.finite_threads by auto 
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   331
      next
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   332
        show "th \<in> ?A" using h_e.th_kept by auto 
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   333
      next
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   334
        show "\<forall>x\<in>?A. ?f x \<le> ?f th"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   335
        proof 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   336
          fix x
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   337
          assume "x \<in> ?A"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   338
          hence "x \<in> threads (t@s)" by (simp add: Exit) 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   339
          hence "?f x \<le> Max (?f ` threads (t@s))" 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   340
            by (simp add: h_t.finite_threads) 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   341
          also have "... \<le> ?f th" 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   342
            apply (simp add:Exit the_preced_def preced_def, fold preced_def)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   343
            using Cons.hyps(5) h_t.th_kept the_preced_def by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   344
          finally show "?f x \<le> ?f th" .
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   345
        qed
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   346
      qed
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   347
      also have "... = ?t" using h_e.th_kept the_preced_def by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   348
      finally show ?thesis .
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   349
    qed 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   350
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   351
    case (P thread cs)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   352
    with Cons
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   353
    show ?thesis by (auto simp:preced_def the_preced_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   354
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   355
    case (V thread cs)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   356
    with Cons
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   357
    show ?thesis by (auto simp:preced_def the_preced_def)
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   358
  next 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   359
    case (Set thread prio')
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   360
    show ?thesis (is "Max (?f ` ?A) = ?t")
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   361
    proof -
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   362
      have "Max (?f ` ?A) = ?f th"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   363
      proof(rule image_Max_eqI)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   364
        show "finite ?A" using h_e.finite_threads by auto 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   365
      next
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   366
        show "th \<in> ?A" using h_e.th_kept by auto 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   367
      next
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   368
        show "\<forall>x\<in>?A. ?f x \<le> ?f th"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   369
        proof 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   370
          fix x
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   371
          assume h: "x \<in> ?A"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   372
          show "?f x \<le> ?f th"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   373
          proof(cases "x = thread")
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   374
            case True
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   375
            moreover have "the_preced (Set thread prio' # t @ s) thread \<le> the_preced (t @ s) th"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   376
            proof -
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   377
              have "the_preced (t @ s) th = Prc prio tm"  
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   378
                using h_t.th_kept preced_th by (simp add:the_preced_def)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   379
              moreover have "prio' \<le> prio" using Set h_e.set_diff_low by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   380
              ultimately show ?thesis by (insert lt_tm, auto simp:the_preced_def preced_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   381
            qed
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   382
            ultimately show ?thesis
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   383
              by (unfold Set, simp add:the_preced_def preced_def)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   384
          next
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   385
            case False
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   386
            then have "?f x  = the_preced (t@s) x"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   387
              by (simp add:the_preced_def preced_def Set)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   388
            also have "... \<le> Max (the_preced (t@s) ` threads (t@s))"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   389
              using Set h h_t.finite_threads by auto 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   390
            also have "... = ?f th" by (metis Cons.hyps(5) h_e.th_kept the_preced_def) 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   391
            finally show ?thesis .
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   392
          qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   393
        qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   394
      qed
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   395
      also have "... = ?t" using h_e.th_kept the_preced_def by auto
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   396
      finally show ?thesis .
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   397
    qed 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   398
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   399
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   400
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   401
lemma max_preced: "preced th (t@s) = Max (the_preced (t@s) ` (threads (t@s)))"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   402
  by (insert th_kept max_kept, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   403
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   404
text {*
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   405
  The reason behind the following lemma is that:
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   406
  Since @{term "cp"} is defined as the maximum precedence 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   407
  of those threads contained in the sub-tree of node @{term "Th th"} 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   408
  in @{term "RAG (t@s)"}, and all these threads are living threads, and 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   409
  @{term "th"} is also among them, the maximum precedence of 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   410
  them all must be the one for @{text "th"}.
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   411
*}
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   412
lemma th_cp_max_preced: 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   413
  "cp (t@s) th = Max (the_preced (t@s) ` (threads (t@s)))" (is "?L = ?R") 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   414
proof -
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   415
  let ?f = "the_preced (t@s)"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   416
  have "?L = ?f th"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   417
  proof(unfold cp_alt_def, rule image_Max_eqI)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   418
    show "finite {th'. Th th' \<in> subtree (RAG (t @ s)) (Th th)}"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   419
    proof -
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   420
      have "{th'. Th th' \<in> subtree (RAG (t @ s)) (Th th)} = 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   421
            the_thread ` {n . n \<in> subtree (RAG (t @ s)) (Th th) \<and>
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   422
                            (\<exists> th'. n = Th th')}"
107
30ed212f268a updated Correctness, Implementation and PIPBasics so that they work with Isabelle 2014 and 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
   423
        by (force)
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   424
      moreover have "finite ..." by (simp add: vat_t.fsbtRAGs.finite_subtree) 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   425
      ultimately show ?thesis by simp
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   426
    qed
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   427
  next
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   428
    show "th \<in> {th'. Th th' \<in> subtree (RAG (t @ s)) (Th th)}"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   429
      by (auto simp:subtree_def)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   430
  next
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   431
    show "\<forall>x\<in>{th'. Th th' \<in> subtree (RAG (t @ s)) (Th th)}.
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   432
               the_preced (t @ s) x \<le> the_preced (t @ s) th"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   433
    proof
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   434
      fix th'
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   435
      assume "th' \<in> {th'. Th th' \<in> subtree (RAG (t @ s)) (Th th)}"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   436
      hence "Th th' \<in> subtree (RAG (t @ s)) (Th th)" by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   437
      moreover have "... \<subseteq> Field (RAG (t @ s)) \<union> {Th th}"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   438
        by (meson subtree_Field)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   439
      ultimately have "Th th' \<in> ..." by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   440
      hence "th' \<in> threads (t@s)" 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   441
      proof
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   442
        assume "Th th' \<in> {Th th}"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   443
        thus ?thesis using th_kept by auto 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   444
      next
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   445
        assume "Th th' \<in> Field (RAG (t @ s))"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   446
        thus ?thesis using vat_t.not_in_thread_isolated by blast 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   447
      qed
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   448
      thus "the_preced (t @ s) th' \<le> the_preced (t @ s) th"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   449
        by (metis Max_ge finite_imageI finite_threads image_eqI 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   450
               max_kept th_kept the_preced_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   451
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   452
  qed
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   453
  also have "... = ?R" by (simp add: max_preced the_preced_def) 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   454
  finally show ?thesis .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   455
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   456
68
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   457
lemma th_cp_max[simp]: "Max (cp (t@s) ` threads (t@s)) = cp (t@s) th"
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   458
  using max_cp_eq th_cp_max_preced the_preced_def vt_t by presburger
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   459
68
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   460
lemma [simp]: "Max (cp (t@s) ` threads (t@s)) = Max (the_preced (t@s) ` threads (t@s))"
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   461
  by (simp add: th_cp_max_preced)
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   462
  
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   463
lemma [simp]: "Max (the_preced (t@s) ` threads (t@s)) = the_preced (t@s) th"
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   464
  using max_kept th_kept the_preced_def by auto
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   465
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   466
lemma [simp]: "the_preced (t@s) th = preced th (t@s)"
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   467
  using the_preced_def by auto
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   468
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   469
lemma [simp]: "preced th (t@s) = preced th s"
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   470
  by (simp add: th_kept)
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   471
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   472
lemma [simp]: "cp s th = preced th s"
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   473
  by (simp add: eq_cp_s_th)
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   474
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   475
lemma th_cp_preced [simp]: "cp (t@s) th = preced th s"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   476
  by (fold max_kept, unfold th_cp_max_preced, simp)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   477
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   478
lemma preced_less:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   479
  assumes th'_in: "th' \<in> threads s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   480
  and neq_th': "th' \<noteq> th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   481
  shows "preced th' s < preced th s"
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   482
  using assms
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   483
by (metis Max.coboundedI finite_imageI highest not_le order.trans 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   484
    preced_linorder rev_image_eqI threads_s vat_s.finite_threads 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   485
    vat_s.le_cp)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   486
68
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   487
section {* The `blocking thread` *}
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   488
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   489
text {* 
106
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   490
  The purpose of PIP is to ensure that the most 
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   491
  urgent thread @{term th} is not blocked unreasonably. 
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   492
  Therefore, a clear picture of the blocking thread is essential 
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   493
  to assure people that the purpose is fulfilled. 
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   494
  
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   495
  In this section, we are going to derive a series of lemmas 
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   496
  with finally give rise to a picture of the blocking thread. 
68
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   497
106
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   498
  By `blocking thread`, we mean a thread in running state but 
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   499
  different from thread @{term th}.
68
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   500
*}
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   501
106
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   502
text {*
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   503
  The following lemmas shows that the @{term cp}-value 
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   504
  of the blocking thread @{text th'} equals to the highest
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   505
  precedence in the whole system.
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   506
*}
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
   507
lemma running_preced_inversion:
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   508
  assumes running': "th' \<in> running (t@s)"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   509
  shows "cp (t@s) th' = preced th s" (is "?L = ?R")
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   510
proof -
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   511
  have "?L = Max (cp (t @ s) ` readys (t @ s))" using assms
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   512
      by (unfold running_def, auto)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   513
  also have "\<dots> = ?R"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   514
      by (metis th_cp_max th_cp_preced vat_t.max_cp_readys_threads) 
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   515
  finally show ?thesis .
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   516
qed
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   517
68
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   518
text {*
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   519
106
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   520
  The following lemma shows how the counters for @{term "P"} and
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   521
  @{term "V"} operations relate to the running threads in the states
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   522
  @{term s} and @{term "t @ s"}.  The lemma shows that if a thread's
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   523
  @{term "P"}-count equals its @{term "V"}-count (which means it no
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   524
  longer has any resource in its possession), it cannot be a running
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   525
  thread.
179
f9e6c4166476 updated
Christian Urban <urbanc@in.tum.de>
parents: 170
diff changeset
   526
  
f9e6c4166476 updated
Christian Urban <urbanc@in.tum.de>
parents: 170
diff changeset
   527
  (* eee *)
f9e6c4166476 updated
Christian Urban <urbanc@in.tum.de>
parents: 170
diff changeset
   528
  The proof is by contradiction:
f9e6c4166476 updated
Christian Urban <urbanc@in.tum.de>
parents: 170
diff changeset
   529
  If @{text th'} is running, it can be derived that @{text "th' = th"} which 
f9e6c4166476 updated
Christian Urban <urbanc@in.tum.de>
parents: 170
diff changeset
   530
  is in contradiction with the assume @{text "th' \<noteq> th"}.
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   531
179
f9e6c4166476 updated
Christian Urban <urbanc@in.tum.de>
parents: 170
diff changeset
   532
  The derivation of @{text "th' = th"} uses @{thm preced_unique}, according to which
f9e6c4166476 updated
Christian Urban <urbanc@in.tum.de>
parents: 170
diff changeset
   533
  we need to show the @{text th'} and @{text th} have the same precedence. The proof
f9e6c4166476 updated
Christian Urban <urbanc@in.tum.de>
parents: 170
diff changeset
   534
  of this is based on the combination of the following two facts:
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   535
179
f9e6c4166476 updated
Christian Urban <urbanc@in.tum.de>
parents: 170
diff changeset
   536
  From @{thm vat_t.detached_intro} and assume 
f9e6c4166476 updated
Christian Urban <urbanc@in.tum.de>
parents: 170
diff changeset
   537
  @{text "cntP (t@s) th' = cntV (t@s) th'"} it can be derived that 
f9e6c4166476 updated
Christian Urban <urbanc@in.tum.de>
parents: 170
diff changeset
   538
  @{text th'} is detached. From this and @{thm detached_cp_preced}
f9e6c4166476 updated
Christian Urban <urbanc@in.tum.de>
parents: 170
diff changeset
   539
  it following the precedence of @{text th'} equals to its own @{text cp}-value.
68
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   540
179
f9e6c4166476 updated
Christian Urban <urbanc@in.tum.de>
parents: 170
diff changeset
   541
  Since @{text th'} is running, from this and @{thm
f9e6c4166476 updated
Christian Urban <urbanc@in.tum.de>
parents: 170
diff changeset
   542
  running_preced_inversion}, the precedence of @{text th'} equals to
f9e6c4166476 updated
Christian Urban <urbanc@in.tum.de>
parents: 170
diff changeset
   543
  the precedence of @{term th}.
f9e6c4166476 updated
Christian Urban <urbanc@in.tum.de>
parents: 170
diff changeset
   544
f9e6c4166476 updated
Christian Urban <urbanc@in.tum.de>
parents: 170
diff changeset
   545
  By combining the above two results we have that @{text th'} and @{term
f9e6c4166476 updated
Christian Urban <urbanc@in.tum.de>
parents: 170
diff changeset
   546
  th} have the same precedence. 
76
b6ea51cd2e88 some small changes to the paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
   547
68
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   548
*} 
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   549
                      
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   550
lemma eq_pv_blocked: (* ddd *)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   551
  assumes neq_th': "th' \<noteq> th"
106
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   552
  and eq_pv: "cntP (t@s) th' = cntV (t@s) th'"
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
   553
  shows "th' \<notin> running (t@s)"
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   554
proof
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
   555
  assume otherwise: "th' \<in> running (t@s)"
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   556
  show False
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   557
  proof -
106
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   558
    have th'_in: "th' \<in> threads (t@s)"
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
   559
        using otherwise readys_threads running_def by auto 
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   560
    have "th' = th"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   561
    proof(rule preced_unique)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   562
      -- {* The proof goes like this: 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   563
            it is first shown that the @{term preced}-value of @{term th'} 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   564
            equals to that of @{term th}, then by uniqueness 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   565
            of @{term preced}-values (given by lemma @{thm preced_unique}), 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   566
            @{term th'} equals to @{term th}: *}
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   567
      show "preced th' (t @ s) = preced th (t @ s)" (is "?L = ?R")
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   568
      proof -
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   569
        -- {* Since the counts of @{term th'} are balanced, the subtree
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   570
              of it contains only itself, so, its @{term cp}-value
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   571
              equals its @{term preced}-value: *}
106
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   572
        have "?L = cp (t@s) th'"
130
0f124691c191 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 127
diff changeset
   573
          by (simp add: detached_cp_preced eq_pv vat_t.detached_intro)
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
   574
        -- {* Since @{term "th'"} is running, by @{thm running_preced_inversion},
68
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   575
              its @{term cp}-value equals @{term "preced th s"}, 
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   576
              which equals to @{term "?R"} by simplification: *}
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   577
        also have "... = ?R" 
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
   578
            using running_preced_inversion[OF otherwise] by simp
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   579
        finally show ?thesis .
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   580
      qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   581
    qed (auto simp: th'_in th_kept)
68
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
   582
    with `th' \<noteq> th` show ?thesis by simp
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   583
 qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   584
qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   585
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   586
text {*
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   587
  The following lemma is the extrapolation of @{thm eq_pv_blocked}.
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   588
  It says if a thread, different from @{term th}, 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   589
  does not hold any resource at the very beginning,
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   590
  it will keep hand-emptied in the future @{term "t@s"}.
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   591
*}
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   592
lemma eq_pv_persist: (* ddd *)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   593
  assumes neq_th': "th' \<noteq> th"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   594
  and eq_pv: "cntP s th' = cntV s th'"
106
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   595
  shows "cntP (t@s) th' = cntV (t@s) th'"
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   596
proof(induction rule:ind) -- {* The proof goes by induction. *}
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   597
  -- {* The nontrivial case is for the @{term Cons}: *}
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   598
  case (Cons e t)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   599
  -- {* All results derived so far hold for both @{term s} and @{term "t@s"}: *}
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   600
  interpret vat_t: extend_highest_gen s th prio tm t using Cons by simp
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   601
  interpret vat_e: extend_highest_gen s th prio tm "(e # t)" using Cons by simp
102
3a801bbd2687 Reorganizing PIPBasics.thy and making small changes to Implementation.thy and Correctness.thy.
zhangx
parents: 93
diff changeset
   602
  interpret vat_es: valid_trace_e "t@s" e using Cons(1,2) by (unfold_locales, auto)
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   603
  show ?case
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   604
  proof -
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   605
    -- {* It can be proved that @{term cntP}-value of @{term th'} does not change
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   606
          by the happening of event @{term e}: *}
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   607
    have "cntP ((e#t)@s) th' = cntP (t@s) th'"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   608
    proof(rule ccontr) -- {* Proof by contradiction. *}
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   609
      -- {* Suppose @{term cntP}-value of @{term th'} is changed by @{term e}: *}
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   610
      assume otherwise: "cntP ((e # t) @ s) th' \<noteq> cntP (t @ s) th'"
116
a7441db6f4e1 PIPBasics.thy is tidied up now.
zhangx
parents: 108
diff changeset
   611
      from cntP_diff_inv[OF this[simplified]]
a7441db6f4e1 PIPBasics.thy is tidied up now.
zhangx
parents: 108
diff changeset
   612
      obtain cs' where "e = P th' cs'" by auto
a7441db6f4e1 PIPBasics.thy is tidied up now.
zhangx
parents: 108
diff changeset
   613
      from vat_es.pip_e[unfolded this]
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
   614
      have "th' \<in> running (t@s)" 
116
a7441db6f4e1 PIPBasics.thy is tidied up now.
zhangx
parents: 108
diff changeset
   615
        by (cases, simp)
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   616
      -- {* However, an application of @{thm eq_pv_blocked} to induction hypothesis
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   617
            shows @{term th'} can not be running at moment  @{term "t@s"}: *}
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
   618
      moreover have "th' \<notin> running (t@s)" 
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   619
               using vat_t.eq_pv_blocked[OF neq_th' Cons(5)] .
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   620
      -- {* Contradiction is finally derived: *}
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   621
      ultimately show False by simp
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   622
    qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   623
    -- {* It can also be proved that @{term cntV}-value of @{term th'} does not change
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   624
          by the happening of event @{term e}: *}
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   625
    -- {* The proof follows exactly the same pattern as the case for @{term cntP}-value: *}
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   626
    moreover have "cntV ((e#t)@s) th' = cntV (t@s) th'"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   627
    proof(rule ccontr) -- {* Proof by contradiction. *}
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   628
      assume otherwise: "cntV ((e # t) @ s) th' \<noteq> cntV (t @ s) th'"
116
a7441db6f4e1 PIPBasics.thy is tidied up now.
zhangx
parents: 108
diff changeset
   629
      from cntV_diff_inv[OF this[simplified]]
a7441db6f4e1 PIPBasics.thy is tidied up now.
zhangx
parents: 108
diff changeset
   630
      obtain cs' where "e = V th' cs'" by auto
a7441db6f4e1 PIPBasics.thy is tidied up now.
zhangx
parents: 108
diff changeset
   631
      from vat_es.pip_e[unfolded this]
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
   632
      have "th' \<in> running (t@s)" by (cases, auto)
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
   633
      moreover have "th' \<notin> running (t@s)"
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   634
          using vat_t.eq_pv_blocked[OF neq_th' Cons(5)] .
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   635
      ultimately show False by simp
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   636
    qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   637
    -- {* Finally, it can be shown that the @{term cntP} and @{term cntV} 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   638
          value for @{term th'} are still in balance, so @{term th'} 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   639
          is still hand-emptied after the execution of event @{term e}: *}
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   640
    ultimately show ?thesis using Cons(5) by metis
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   641
  qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   642
qed (auto simp:eq_pv)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   643
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   644
text {*
106
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   645
  By combining @{thm  eq_pv_blocked} and @{thm eq_pv_persist},
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   646
  it can be derived easily that @{term th'} can not be running in the future:
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   647
*}
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   648
lemma eq_pv_blocked_persist:
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   649
  assumes neq_th': "th' \<noteq> th"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   650
  and eq_pv: "cntP s th' = cntV s th'"
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
   651
  shows "th' \<notin> running (t@s)"
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   652
  using assms
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   653
  by (simp add: eq_pv_blocked eq_pv_persist) 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   654
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   655
text {*
106
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   656
  The following lemma shows the blocking thread @{term th'}
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   657
  must hold some resource in the very beginning. 
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   658
*}
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
   659
lemma running_cntP_cntV_inv: (* ddd *)
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
   660
  assumes is_running: "th' \<in> running (t@s)"
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   661
  and neq_th': "th' \<noteq> th"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   662
  shows "cntP s th' > cntV s th'"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   663
  using assms
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   664
proof -
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   665
  -- {* First, it can be shown that the number of @{term P} and
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   666
        @{term V} operations can not be equal for thred @{term th'} *}
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   667
  have "cntP s th' \<noteq> cntV s th'"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   668
  proof
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   669
     -- {* The proof goes by contradiction, suppose otherwise: *}
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   670
    assume otherwise: "cntP s th' = cntV s th'"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   671
    -- {* By applying @{thm  eq_pv_blocked_persist} to this: *}
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   672
    from eq_pv_blocked_persist[OF neq_th' otherwise] 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   673
    -- {* we have that @{term th'} can not be running at moment @{term "t@s"}: *}
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
   674
    have "th' \<notin> running (t@s)" .
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
   675
    -- {* This is obvious in contradiction with assumption @{thm is_running}  *}
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
   676
    thus False using is_running by simp
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   677
  qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   678
  -- {* However, the number of @{term V} is always less or equal to @{term P}: *}
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   679
  moreover have "cntV s th' \<le> cntP s th'" using vat_s.cnp_cnv_cncs by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   680
  -- {* Thesis is finally derived by combining the these two results: *}
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   681
  ultimately show ?thesis by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   682
qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   683
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   684
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   685
text {*
106
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   686
  The following lemmas shows the blocking thread @{text th'} must be live 
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   687
  at the very beginning, i.e. the moment (or state) @{term s}. 
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   688
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   689
  The proof is a  simple combination of the results above:
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   690
*}
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
   691
lemma running_threads_inv: 
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
   692
  assumes running': "th' \<in> running (t@s)"
66
2af87bb52fca Some small improvements in Correctness.thy.
zhangx
parents: 65
diff changeset
   693
  and neq_th': "th' \<noteq> th"
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   694
  shows "th' \<in> threads s"
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   695
proof(rule ccontr) -- {* Proof by contradiction: *}
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   696
  assume otherwise: "th' \<notin> threads s" 
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
   697
  have "th' \<notin> running (t @ s)"
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   698
  proof -
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   699
    from vat_s.cnp_cnv_eq[OF otherwise]
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   700
    have "cntP s th' = cntV s th'" .
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   701
    from eq_pv_blocked_persist[OF neq_th' this]
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   702
    show ?thesis .
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   703
  qed
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
   704
  with running' show False by simp
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   705
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   706
66
2af87bb52fca Some small improvements in Correctness.thy.
zhangx
parents: 65
diff changeset
   707
text {*
106
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   708
  The following lemma summarizes several foregoing 
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   709
  lemmas to give an overall picture of the blocking thread @{text "th'"}:
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   710
*}
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
   711
lemma running_inversion: (* ddd, one of the main lemmas to present *)
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
   712
  assumes running': "th' \<in> running (t@s)"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   713
  and neq_th: "th' \<noteq> th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   714
  shows "th' \<in> threads s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   715
  and    "\<not>detached s th'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   716
  and    "cp (t@s) th' = preced th s"
66
2af87bb52fca Some small improvements in Correctness.thy.
zhangx
parents: 65
diff changeset
   717
proof -
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
   718
  from running_threads_inv[OF assms]
66
2af87bb52fca Some small improvements in Correctness.thy.
zhangx
parents: 65
diff changeset
   719
  show "th' \<in> threads s" .
2af87bb52fca Some small improvements in Correctness.thy.
zhangx
parents: 65
diff changeset
   720
next
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
   721
  from running_cntP_cntV_inv[OF running' neq_th]
66
2af87bb52fca Some small improvements in Correctness.thy.
zhangx
parents: 65
diff changeset
   722
  show "\<not>detached s th'" using vat_s.detached_eq by simp
2af87bb52fca Some small improvements in Correctness.thy.
zhangx
parents: 65
diff changeset
   723
next
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
   724
  from running_preced_inversion[OF running']
66
2af87bb52fca Some small improvements in Correctness.thy.
zhangx
parents: 65
diff changeset
   725
  show "cp (t@s) th' = preced th s" .
2af87bb52fca Some small improvements in Correctness.thy.
zhangx
parents: 65
diff changeset
   726
qed
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   727
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   728
section {* The existence of `blocking thread` *}
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   729
145
188fe0c81ac7 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   730
text {* 
188fe0c81ac7 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   731
  Suppose @{term th} is not running, it is first shown that
188fe0c81ac7 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   732
  there is a path in RAG leading from node @{term th} to another thread @{text "th'"} 
188fe0c81ac7 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   733
  in the @{term readys}-set (So @{text "th'"} is an ancestor of @{term th}}).
188fe0c81ac7 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   734
188fe0c81ac7 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   735
  Now, since @{term readys}-set is non-empty, there must be
188fe0c81ac7 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   736
  one in it which holds the highest @{term cp}-value, which, by definition, 
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   737
  is the @{term running}-thread. However, we are going to show more: this running thread
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   738
  is exactly @{term "th'"}.
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   739
     *}
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   740
lemma th_blockedE: (* ddd, the other main lemma to be presented: *)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   741
  assumes "th \<notin> running (t@s)"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   742
  obtains th' where "Th th' \<in> ancestors (RAG (t @ s)) (Th th)"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   743
                    "th' \<in> running (t@s)"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   744
proof -
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   745
  -- {* According to @{thm vat_t.th_chain_to_ready}, either 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   746
        @{term "th"} is in @{term "readys"} or there is path leading from it to 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   747
        one thread in @{term "readys"}. *}
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   748
  have "th \<in> readys (t @ s) \<or> (\<exists>th'. th' \<in> readys (t @ s) \<and> (Th th, Th th') \<in> (RAG (t @ s))\<^sup>+)" 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   749
    using th_kept vat_t.th_chain_to_ready by auto
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   750
  -- {* However, @{term th} can not be in @{term readys}, because otherwise, since 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   751
       @{term th} holds the highest @{term cp}-value, it must be @{term "running"}. *}
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   752
  moreover have "th \<notin> readys (t@s)" 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   753
    using assms running_def th_cp_max vat_t.max_cp_readys_threads by auto 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   754
  -- {* So, there must be a path from @{term th} to another thread @{text "th'"} in 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   755
        term @{term readys}: *}
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   756
  ultimately obtain th' where th'_in: "th' \<in> readys (t@s)"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   757
                          and dp: "(Th th, Th th') \<in> (RAG (t @ s))\<^sup>+" by auto
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   758
  -- {* We are going to show that this @{term th'} is running. *}
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   759
  have "th' \<in> running (t@s)"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   760
  proof -
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   761
    -- {* We only need to show that this @{term th'} holds the highest @{term cp}-value: *}
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   762
    have "cp (t@s) th' = Max (cp (t@s) ` readys (t@s))" (is "?L = ?R")
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   763
    proof -
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   764
      -- {* First, by the alternative definition of @{term cp} (I mean @{thm cp_alt_def1}),
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   765
            the  @{term cp}-value of @{term th'} is the maximum of 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   766
            all precedences of all thread nodes in its @{term tRAG}-subtree: *}
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   767
      have "?L =  Max ((the_preced (t @ s) \<circ> the_thread) ` subtree (tRAG (t @ s)) (Th th'))"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   768
        by (unfold cp_alt_def1, simp)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   769
      also have "... = (the_preced (t @ s) \<circ> the_thread) (Th th)"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   770
      proof(rule image_Max_subset)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   771
        show "finite (Th ` (threads (t@s)))" by (simp add: vat_t.finite_threads)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   772
      next
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   773
        show "subtree (tRAG (t @ s)) (Th th') \<subseteq> Th ` threads (t @ s)"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   774
          by (metis Range.intros dp trancl_range vat_t.rg_RAG_threads vat_t.subtree_tRAG_thread) 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   775
      next
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   776
        show "Th th \<in> subtree (tRAG (t @ s)) (Th th')" using dp
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   777
                    by (unfold tRAG_subtree_eq, auto simp:subtree_def)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   778
      next
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   779
        show "Max ((the_preced (t @ s) \<circ> the_thread) ` Th ` threads (t @ s)) =
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   780
                      (the_preced (t @ s) \<circ> the_thread) (Th th)" (is "Max ?L = _")
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   781
        proof -
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   782
          have "?L = the_preced (t @ s) `  threads (t @ s)" 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   783
                     by (unfold image_comp, rule image_cong, auto)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   784
          thus ?thesis using max_preced the_preced_def by auto
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   785
        qed
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   786
      qed
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   787
      thm the_preced_def
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   788
      also have "... = ?R"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   789
        using th_cp_max th_cp_preced th_kept 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   790
              the_preced_def vat_t.max_cp_readys_threads by auto
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   791
              thm th_cp_max th_cp_preced th_kept 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   792
              the_preced_def vat_t.max_cp_readys_threads
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   793
      finally show ?thesis .
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   794
    qed 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   795
    -- {* Now, since @{term th'} holds the highest @{term cp} 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   796
          and we have already show it is in @{term readys},
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   797
          it is @{term running} by definition. *}
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   798
    with `th' \<in> readys (t@s)` show ?thesis by (simp add: running_def) 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   799
  qed
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   800
  -- {* It is easy to show @{term th'} is an ancestor of @{term th}: *}
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   801
  moreover have "Th th' \<in> ancestors (RAG (t @ s)) (Th th)" 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   802
    using `(Th th, Th th') \<in> (RAG (t @ s))\<^sup>+` by (auto simp:ancestors_def)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   803
  ultimately show ?thesis using that by metis
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   804
qed
145
188fe0c81ac7 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   805
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   806
lemma (* new proof of th_blockedE *)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   807
  assumes "th \<notin> running (t @ s)"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   808
  obtains th' where "Th th' \<in> ancestors (RAG (t @ s)) (Th th)"
145
188fe0c81ac7 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   809
                    "th' \<in> running (t @ s)"
188fe0c81ac7 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   810
proof -
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   811
  
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   812
  -- {* According to @{thm vat_t.th_chain_to_ready}, either @{term "th"} is 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   813
        in @{term "readys"} or there is path in the @{term RAG} leading from 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   814
        it to a thread that is in @{term "readys"}. However, @{term th} cannot 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   815
        be in @{term readys}, because otherwise, since @{term th} holds the 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   816
        highest @{term cp}-value, it must be @{term "running"}. This would
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   817
        violate our assumption. *}
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   818
  have "th \<notin> readys (t @ s)" 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   819
    using assms running_def th_cp_max vat_t.max_cp_readys_threads by auto 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   820
  then have "\<exists>th'. th' \<in> readys (t @ s) \<and> (Th th, Th th') \<in> (RAG (t @ s))\<^sup>+" 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   821
    using th_kept vat_t.th_chain_to_ready by auto
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   822
  then obtain th' where th'_in: "th' \<in> readys (t@s)"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   823
                    and dp: "(Th th, Th th') \<in> (RAG (t @ s))\<^sup>+" by auto
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   824
  
145
188fe0c81ac7 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   825
  -- {* We are going to first show that this @{term th'} is running. *}
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   826
  have "th' \<in> running (t @ s)"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   827
  proof -
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   828
    -- {* For this we need to show that @{term th'} holds the highest @{term cp}-value: *}
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   829
    have "cp (t @ s) th' = Max (cp (t @ s) ` readys (t @ s))" (is "?L = ?R")
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   830
    proof -
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   831
      -- {* First, by the alternative definition of @{term cp} (I mean @{thm cp_alt_def1}),
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   832
            the  @{term cp}-value of @{term th'} is the maximum of 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   833
            all precedences of all thread nodes in its @{term tRAG}-subtree: *}
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   834
      have "?L =  Max (the_preced (t @ s) ` (the_thread ` subtree (tRAG (t @ s)) (Th th')))"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   835
      proof -
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   836
        have "(the_preced (t @ s) \<circ> the_thread) ` subtree (tRAG (t @ s)) (Th th') =
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   837
              the_preced (t @ s) ` the_thread ` subtree (tRAG (t @ s)) (Th th')"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   838
                by fastforce
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   839
        thus ?thesis by (unfold cp_alt_def1, simp)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   840
      qed
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   841
      also have "... = (the_preced (t @ s) th)"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   842
      proof(rule image_Max_subset)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   843
        show "finite (threads (t @ s))" by (simp add: vat_t.finite_threads)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   844
      next
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   845
        show "the_thread ` subtree (tRAG (t @ s)) (Th th') \<subseteq> threads (t @ s)"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   846
          by (smt imageE mem_Collect_eq readys_def subsetCE subsetI th'_in 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   847
                the_thread.simps vat_t.subtree_tRAG_thread)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   848
      next
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   849
        show "th \<in> the_thread ` subtree (tRAG (t @ s)) (Th th')"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   850
        proof -
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   851
          have "Th th \<in> subtree (tRAG (t @ s)) (Th th')" using dp
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   852
                    by (unfold tRAG_subtree_eq, auto simp:subtree_def)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   853
          thus ?thesis by force
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   854
        qed
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   855
      next
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   856
        show "Max (the_preced (t @ s) ` threads (t @ s)) = the_preced (t @ s) th"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   857
          by simp
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   858
      qed
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   859
      also have "... = ?R"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   860
        using th_cp_max th_cp_preced th_kept 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   861
              the_preced_def vat_t.max_cp_readys_threads by auto
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   862
      finally show "cp (t @ s) th' = Max (cp (t @ s) ` readys (t @ s))" .
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   863
    qed 
145
188fe0c81ac7 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   864
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   865
    -- {* Now, since @{term th'} holds the highest @{term cp}-value in readys, 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   866
          it is @{term running} by definition. *}
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   867
    with `th' \<in> readys (t @ s)` show "th' \<in> running (t @ s)" by (simp add: running_def) 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   868
  qed
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   869
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   870
  -- {* It is easy to show @{term th'} is an ancestor of @{term th}: *}
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   871
  moreover have "Th th' \<in> ancestors (RAG (t @ s)) (Th th)" 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   872
    using `(Th th, Th th') \<in> (RAG (t @ s))\<^sup>+` by (auto simp:ancestors_def)
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   873
  ultimately show ?thesis using that by metis
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   874
qed
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   875
126
a88af0e4731f minor update
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 125
diff changeset
   876
lemma th_blockedE_pretty:
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   877
  assumes "th \<notin> running (t@s)"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   878
  shows "\<exists>th'. Th th' \<in> ancestors (RAG (t @ s)) (Th th) \<and> th' \<in> running (t@s)"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   879
using th_blockedE assms by blast
137
785c0f6b8184 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 136
diff changeset
   880
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   881
text {*
106
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   882
  Now it is easy to see there is always a thread to run by case analysis
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   883
  on whether thread @{term th} is running: if the answer is Yes, the 
106
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   884
  the running thread is obviously @{term th} itself; otherwise, the running
5454387e42ce updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   885
  thread is the @{text th'} given by lemma @{thm th_blockedE}.
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
   886
*}
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   887
lemma live: "running (t@s) \<noteq> {}"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   888
proof(cases "th \<in> running (t@s)") 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   889
  case True thus ?thesis by auto
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   890
next
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   891
  case False
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   892
  thus ?thesis using th_blockedE by auto
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   893
qed
138
20c1d3a14143 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 137
diff changeset
   894
20c1d3a14143 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 137
diff changeset
   895
lemma blockedE:
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   896
  assumes "th \<notin> running (t@s)"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   897
  obtains th' where "Th th' \<in> ancestors (RAG (t @ s)) (Th th)"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   898
                    "th' \<in> running (t@s)"
138
20c1d3a14143 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 137
diff changeset
   899
                    "th' \<in> threads s"
20c1d3a14143 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 137
diff changeset
   900
                    "\<not>detached s th'"
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   901
                    "cp (t@s) th' = preced th s"
138
20c1d3a14143 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 137
diff changeset
   902
                    "th' \<noteq> th"
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   903
by (metis assms running_inversion(2) running_preced_inversion running_threads_inv th_blockedE)
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   904
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
   905
lemma detached_not_running:
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   906
  assumes "detached (t@s) th'"
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   907
  and "th' \<noteq> th"
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   908
  shows "th' \<notin> running (t@s)"
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   909
proof
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
   910
    assume otherwise: "th' \<in> running (t @ s)"
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   911
    have "cp (t@s) th' = cp (t@s) th"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   912
    proof -
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   913
      have "cp (t@s) th' = Max (cp (t@s) ` readys (t@s))" using otherwise
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
   914
          by (simp add:running_def)
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   915
      moreover have "cp (t@s) th = ..." by (simp add: vat_t.max_cp_readys_threads)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   916
      ultimately show ?thesis by simp
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   917
    qed
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   918
    moreover have "cp (t@s) th' = preced th' (t@s)" using assms(1)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   919
      by (simp add: detached_cp_preced)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   920
    moreover have "cp (t@s) th = preced th (t@s)" by simp
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   921
    ultimately have "preced th' (t@s) = preced th (t@s)" by simp
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   922
    from preced_unique[OF this] 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   923
    have "th' \<in> threads (t @ s) \<Longrightarrow> th \<in> threads (t @ s) \<Longrightarrow> th' = th" .
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   924
    moreover have "th' \<in> threads (t@s)" 
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
   925
      using otherwise by (unfold running_def readys_def, auto)
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   926
    moreover have "th \<in> threads (t@s)" by (simp add: th_kept) 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   927
    ultimately have "th' = th" by metis
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   928
    with assms(2) show False by simp
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   929
qed
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   930
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   931
section {* The correctness theorem of PIP *}
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   932
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   933
text {*
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   934
  In this section, we identify two more conditions in addition to the ones already 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   935
  specified in the forgoing locales, based on which the correctness of PIP is 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   936
  formally proved. 
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   937
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   938
  Note that Priority Inversion refers to the phenomenon where the thread with highest priority 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   939
  is blocked by one with lower priority because the resource it is requesting is 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   940
  currently held by the later. The objective of PIP is to avoid {\em Indefinite Priority Inversion}, 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   941
  i.e. the number of occurrences of {\em Prioirty Inversion} becomes indefinitely large. 
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   942
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   943
  For PIP to be correct, a finite upper bound needs to be found for the occurrence number, 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   944
  and the existence. This section makes explicit two more conditions so that the existence 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   945
  of such a upper bound can be proved to exist. 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   946
*}
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   947
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   948
text {*
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   949
  The following set @{text "blockers"} characterizes the set of threads which 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   950
  might block @{term th} in @{term t}:
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   951
*}
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   952
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   953
definition "blockers = {th'. \<not>detached s th' \<and> th' \<noteq> th}"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   954
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   955
text {*
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   956
  The following lemma shows that the definition of @{term "blockers"} is correct, 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   957
  i.e. blockers do block @{term "th"}. It is a very simple corollary of @{thm blockedE}.
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   958
*}
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
   959
lemma runningE:
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
   960
  assumes "th' \<in> running (t@s)"
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   961
  obtains (is_th) "th' = th"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   962
        | (is_other) "th' \<in> blockers"
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
   963
  using assms blockers_def running_inversion(2) by auto
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   964
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   965
text {*
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   966
  The following lemma shows that the number of blockers are finite.
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   967
  The reason is simple, because blockers are subset of thread set, which
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   968
  has been shown finite.
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   969
*}
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   970
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   971
lemma finite_blockers: "finite blockers"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   972
proof -
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   973
  have "finite {th'. \<not>detached s th'}"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   974
  proof -
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   975
    have "finite {th'. Th th' \<in> Field (RAG s)}"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   976
    proof -
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   977
      have "{th'. Th th' \<in> Field (RAG s)} \<subseteq> threads s"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   978
      proof
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   979
        fix x
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   980
        assume "x \<in> {th'. Th th' \<in> Field (RAG s)}"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   981
        thus "x \<in> threads s" using vat_s.RAG_threads by auto
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   982
      qed
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   983
      moreover have "finite ..." by (simp add: vat_s.finite_threads) 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   984
      ultimately show ?thesis using rev_finite_subset by auto 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   985
    qed
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   986
    thus ?thesis by (unfold detached_test, auto)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   987
  qed
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   988
  thus ?thesis unfolding blockers_def by simp
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   989
qed
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   990
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   991
text {*
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   992
  The following lemma shows that a blocker may never die
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   993
  as long as the highest thread @{term th} is living. 
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
   994
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   995
  The reason for this is that, before a thread can execute an @{term Exit} operation,
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   996
  it must give up all its resource. However, the high priority inherited by a blocker 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   997
  thread also goes with the resources it once held, and the consequence is the lost of 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   998
  right to run, the other precondition for it to execute its own  @{term Exit} operation.
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
   999
  For this reason, a blocker may never exit before the exit of the highest thread @{term th}.
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1000
*}
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1001
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1002
lemma blockers_kept:
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1003
  assumes "th' \<in> blockers"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1004
  shows "th' \<in> threads (t@s)"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1005
proof(induct rule:ind)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1006
  case Nil
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1007
  from assms[unfolded blockers_def detached_test]
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1008
  have "Th th' \<in> Field (RAG s)" by simp
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1009
  from vat_s.RAG_threads[OF this]
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1010
  show ?case by simp
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1011
next
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1012
  case h: (Cons e t)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1013
  interpret et: extend_highest_gen s th prio tm t
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1014
    using h by simp
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1015
  show ?case
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1016
  proof -
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1017
    { assume otherwise: "th' \<notin> threads ((e # t) @ s)"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1018
      from threads_Exit[OF h(5)] this have eq_e: "e = Exit th'" by auto
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1019
      from h(2)[unfolded this]
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1020
      have False
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1021
      proof(cases)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1022
        case h: (thread_exit)
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
  1023
        hence "th' \<in> readys (t@s)" by (auto simp:running_def)
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1024
        from readys_holdents_detached[OF this h(2)]
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1025
        have "detached (t @ s) th'" .
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
  1026
        from et.detached_not_running[OF this] assms[unfolded blockers_def]
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
  1027
        have "th' \<notin> running (t @ s)" by auto
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1028
        with h(1) show ?thesis by simp
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1029
      qed
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1030
    } thus ?thesis by auto
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1031
  qed
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1032
qed
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1033
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1034
text {*
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1035
  The following lemma shows that a blocker may never execute its @{term Create}-operation
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1036
  during the period of @{term t}. The reason is that for a thread to be created 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1037
  (or executing its @{term Create} operation), it must be non-existing (or dead). 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1038
  However, since lemma @{thm blockers_kept} shows that blockers are always living, 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1039
  it can not be created. 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1040
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1041
  A thread is created only when there is some external reason, there is need for it to run. 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1042
  The precondition for this is that it has already died (or get out of existence).
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1043
*}
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1044
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1045
lemma blockers_no_create:
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1046
  assumes "th' \<in> blockers"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1047
  and "e \<in> set t"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1048
  and "actor e = th'"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1049
  shows "\<not> isCreate e"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1050
  using assms(2,3)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1051
proof(induct rule:ind)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1052
  case h: (Cons e' t)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1053
  interpret et: extend_highest_gen s th prio tm t
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1054
    using h by simp
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1055
  { assume eq_e: "e = e'"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1056
    from et.blockers_kept assms
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1057
    have "th' \<in> threads (t @ s)" by auto
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1058
    with h(2,7)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1059
    have ?case 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1060
      by (unfold eq_e, cases, auto simp:blockers_def)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1061
  } with h
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1062
  show ?case by auto
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1063
qed auto
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1064
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1065
text {*
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1066
  The following lemma shows that, same as blockers, 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1067
  the highest thread @{term th} also can not execute its @{term Create}-operation.
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1068
  And the reason is similar: since @{thm th_kept} says that thread @{term th} is kept live
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1069
  during @{term t}, it can not (or need not) be created another time.
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1070
*}
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1071
lemma th_no_create:
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1072
  assumes "e \<in> set t"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1073
  and "actor e = th"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1074
  shows "\<not> isCreate e"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1075
  using assms
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1076
proof(induct rule:ind)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1077
  case h:(Cons e' t)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1078
  interpret et: extend_highest_gen s th prio tm t
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1079
    using h by simp
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1080
  { assume eq_e: "e = e'"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1081
    from et.th_kept have "th \<in> threads (t @ s)" by simp
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1082
    with h(2,7)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1083
    have ?case by (unfold eq_e, cases, auto)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1084
  } with h
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1085
  show ?case by auto
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1086
qed auto
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1087
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1088
text {*
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1089
  The following is a preliminary lemma in order to show that the number of 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1090
  actions (or operations) taken by the highest thread @{term th} is 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1091
  less or equal to the number of occurrences when @{term th} is in running
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1092
  state. What is proved in this lemma is essentially a strengthening, which 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1093
  says the inequality holds even if the occurrence at the very beginning is
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1094
  ignored.
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1095
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1096
  The reason for this lemma is that for every operation to be executed, its actor must
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1097
  be in running state. Therefore, there is one occurrence of running state
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1098
  behind every action. 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1099
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1100
  However, this property does not hold in general, because, for 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1101
  the execution of @{term Create}-operation, the actor does not have to be in running state. 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1102
  Actually, the actor must be in dead state, in order to be created. For @{term th}, this 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1103
  property holds because, according to lemma @{thm th_no_create}, @{term th} can not execute
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1104
  any @{term Create}-operation during the period of @{term t}.
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1105
*}
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1106
lemma actions_th_occs_pre:
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1107
  assumes "t = e'#t'"
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
  1108
  shows "length (actions_of {th} t) \<le> occs (\<lambda> t'. th \<in> running (t'@s)) t'"
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1109
  using assms
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1110
proof(induct arbitrary: e' t' rule:ind)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1111
  case h: (Cons e t e' t')
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1112
  interpret vt: valid_trace "(t@s)" using h(1)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1113
    by (unfold_locales, simp)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1114
  interpret ve:  extend_highest_gen s th prio tm t using h by simp
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1115
  interpret ve':  extend_highest_gen s th prio tm "e#t" using h by simp
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1116
  show ?case (is "?L \<le> ?R")
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1117
  proof(cases t)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1118
    case Nil
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1119
    show ?thesis
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1120
    proof(cases "actor e = th")
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1121
      case True
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1122
      from ve'.th_no_create[OF _ this]
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1123
      have "\<not> isCreate e" by auto
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1124
      from PIP_actorE[OF h(2) True this] Nil
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
  1125
      have "th \<in> running s" by simp
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1126
      hence "?R = 1" using Nil h by simp
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1127
      moreover have "?L = 1" using True Nil by (simp add:actions_of_def)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1128
      ultimately show ?thesis by simp
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1129
    next
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1130
      case False
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1131
      with Nil
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1132
      show ?thesis by (auto simp:actions_of_def)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1133
    qed
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1134
  next
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1135
    case h1: (Cons e1 t1)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1136
    hence eq_t': "t' = e1#t1" using h by simp
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1137
    from h(5)[OF h1]
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
  1138
    have le: "length (actions_of {th} t) \<le> occs (\<lambda>t'. th \<in> running (t' @ s)) t1" 
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1139
      (is "?F t \<le> ?G t1") .
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1140
    show ?thesis 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1141
    proof(cases "actor e = th")
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1142
      case True
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1143
      from ve'.th_no_create[OF _ this]
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1144
      have "\<not> isCreate e" by auto
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1145
      from PIP_actorE[OF h(2) True this]
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
  1146
      have "th \<in> running (t@s)" by simp
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1147
      hence "?R = 1 + ?G t1" by (unfold h1 eq_t', simp)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1148
      moreover have "?L = 1 + ?F t" using True by (simp add:actions_of_def)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1149
      ultimately show ?thesis using le by simp
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1150
    next
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1151
      case False
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1152
      with le
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1153
      show ?thesis by (unfold h1 eq_t', simp add:actions_of_def)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1154
    qed
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1155
  qed
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1156
qed auto
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1157
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1158
text {*
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1159
  The following lemma is a simple corollary of @{thm actions_th_occs_pre}. It is the
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1160
  lemma really needed in later proofs.
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1161
*}
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1162
lemma actions_th_occs:
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
  1163
  shows "length (actions_of {th} t) \<le> occs (\<lambda> t'. th \<in> running (t'@s)) t"
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1164
proof(cases t)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1165
  case (Cons e' t')
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1166
  from actions_th_occs_pre[OF this]
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
  1167
  have "length (actions_of {th} t) \<le> occs (\<lambda>t'. th \<in> running (t' @ s)) t'" .
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
  1168
  moreover have "... \<le> occs (\<lambda>t'. th \<in> running (t' @ s)) t" 
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1169
    by (unfold Cons, auto)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1170
  ultimately show ?thesis by simp
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1171
qed (auto simp:actions_of_def)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1172
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1173
text {*
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1174
  The following lemma splits all the operations in @{term t} into three
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1175
  disjoint sets, namely the operations of @{term th}, the operations of 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1176
  blockers and @{term Create}-operations. These sets are mutually disjoint
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1177
  because: @{term "{th}"} and @{term blockers} are disjoint by definition, 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1178
  and neither @{term th} nor any blocker can execute @{term Create}-operation
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1179
  (according to lemma @{thm th_no_create} and @{thm blockers_no_create}).
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1180
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1181
  One important caveat noted by this lemma is that: 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1182
  Although according to assumption @{thm create_low}, each thread created in 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1183
  @{term t} has precedence lower than @{term th}, therefore, will get no
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1184
  change to run after creation, therefore, can not acquire any resource 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1185
  to become a blocker, the @{term Create}-operations of such 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1186
  lower threads may still consume overall execution time of duration @{term t}, therefore,
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1187
  may compete for execution time with the most urgent thread @{term th}.
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1188
  For PIP to be correct, the number of such competing operations needs to be 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1189
  bounded somehow.
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1190
*}
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1191
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1192
lemma actions_split:
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1193
  "length t = length (actions_of {th} t) + 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1194
              length (actions_of blockers t) + 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1195
              length (filter (isCreate) t)"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1196
proof(induct rule:ind)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1197
  case h: (Cons e t)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1198
  interpret ve :  extend_highest_gen s th prio tm t using h by simp
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1199
  interpret ve':  extend_highest_gen s th prio tm "e#t" using h by simp
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1200
  show ?case (is "?L (e#t) = ?T (e#t) + ?O (e#t) + ?C (e#t)")
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
  1201
  proof(cases "actor e \<in> running (t@s)")
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1202
    case True
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1203
    thus ?thesis
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
  1204
    proof(rule ve.runningE)
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1205
      assume 1: "actor e = th"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1206
      have "?T (e#t) = 1 + ?T (t)" using 1 by (simp add:actions_of_def)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1207
      moreover have "?O (e#t) = ?O t" 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1208
      proof -
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1209
        have "actor e \<notin> blockers" using 1
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1210
          by (simp add:actions_of_def blockers_def)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1211
        thus ?thesis by (simp add:actions_of_def)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1212
      qed
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1213
      moreover have "?C (e#t) = ?C t"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1214
      proof -
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1215
        from ve'.th_no_create[OF _ 1]
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1216
        have "\<not> isCreate e" by auto
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1217
        thus ?thesis by (simp add:actions_of_def)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1218
      qed
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1219
      ultimately show ?thesis using h by simp
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1220
    next
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1221
      assume 2: "actor e \<in> ve'.blockers"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1222
      have "?T (e#t) = ?T (t)"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1223
      proof -
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1224
        from 2 have "actor e \<noteq> th" by (auto simp:blockers_def)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1225
        thus ?thesis by (auto simp:actions_of_def)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1226
      qed
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1227
      moreover have "?O (e#t) = 1 + ?O(t)" using 2
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1228
        by (auto simp:actions_of_def)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1229
      moreover have "?C (e#t) = ?C(t)"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1230
      proof -
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1231
        from ve'.blockers_no_create[OF 2, of e]
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1232
        have "\<not> isCreate e" by auto
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1233
        thus ?thesis by (simp add:actions_of_def)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1234
      qed
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1235
      ultimately show ?thesis using h by simp
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1236
    qed
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1237
  next
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1238
    case False
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1239
    from h(2)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1240
    have is_create: "isCreate e"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1241
      by (cases; insert False, auto)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1242
    have "?T (e#t) = ?T t"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1243
    proof -
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1244
      have "actor e \<noteq> th"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1245
      proof
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1246
        assume "actor e = th"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1247
        from ve'.th_no_create[OF _ this]
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1248
        have "\<not> isCreate e" by auto
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1249
        with is_create show False by simp
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1250
      qed
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1251
      thus ?thesis by (auto simp:actions_of_def)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1252
    qed
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1253
    moreover have "?O (e#t) = ?O t"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1254
    proof -
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1255
      have "actor e \<notin> blockers"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1256
      proof
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1257
        assume "actor e \<in> blockers"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1258
        from ve'.blockers_no_create[OF this, of e]
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1259
        have "\<not> isCreate e" by simp
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1260
        with is_create show False by simp
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1261
      qed
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1262
      thus ?thesis by (simp add:actions_of_def)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1263
    qed
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1264
    moreover have "?C (e#t) = 1 + ?C t" using is_create
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1265
        by (auto simp:actions_of_def)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1266
    ultimately show ?thesis using h by simp
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1267
  qed
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1268
qed (auto simp:actions_of_def)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1269
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1270
text {*
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1271
  By combining several of forging lemmas, this lemma gives a upper bound
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1272
  of the occurrence number when the most urgent thread @{term th} is blocked.
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1273
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1274
  It says, the occasions when @{term th} is blocked during period @{term t} 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1275
  is no more than the number of @{term Create}-operations and 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1276
  the operations taken by blockers plus one. 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1277
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1278
  Since the length of @{term t} may extend indefinitely, if @{term t} is full
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1279
  of the above mentioned blocking operations, @{term th} may have not chance to run. 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1280
  And, since @{term t} can extend indefinitely, @{term th} my be blocked indefinitely 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1281
  with the growth of @{term t}. Therefore, this lemma alone does not ensure 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1282
  the correctness of PIP. 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1283
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1284
*}
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1285
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1286
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1287
end
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1288
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1289
(* ccc *)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1290
159
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1291
fun postfixes where 
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1292
  "postfixes [] = []" |
170
def87c589516 updated
Christian Urban <urbanc@in.tum.de>
parents: 161
diff changeset
  1293
  "postfixes (x#xs) = xs # postfixes xs" 
159
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1294
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1295
definition "up_to s t = map (\<lambda> t'. t'@s) (postfixes t)"
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1296
170
def87c589516 updated
Christian Urban <urbanc@in.tum.de>
parents: 161
diff changeset
  1297
fun upto where
def87c589516 updated
Christian Urban <urbanc@in.tum.de>
parents: 161
diff changeset
  1298
  "upto s [] = []" |
def87c589516 updated
Christian Urban <urbanc@in.tum.de>
parents: 161
diff changeset
  1299
  "upto s (e # es) = (es @ s) # upto s es"
161
f1d82f6c05a3 updated
Christian Urban <urbanc@in.tum.de>
parents: 160
diff changeset
  1300
170
def87c589516 updated
Christian Urban <urbanc@in.tum.de>
parents: 161
diff changeset
  1301
value "up_to [s3, s2, s1] [e5, e4, e3, e2, e1] "
def87c589516 updated
Christian Urban <urbanc@in.tum.de>
parents: 161
diff changeset
  1302
value "upto [s3, s2, s1] [e5, e4, e3, e2, e1] "
def87c589516 updated
Christian Urban <urbanc@in.tum.de>
parents: 161
diff changeset
  1303
def87c589516 updated
Christian Urban <urbanc@in.tum.de>
parents: 161
diff changeset
  1304
lemma "upto s t = up_to s t"
def87c589516 updated
Christian Urban <urbanc@in.tum.de>
parents: 161
diff changeset
  1305
apply(induct t arbitrary: s)
def87c589516 updated
Christian Urban <urbanc@in.tum.de>
parents: 161
diff changeset
  1306
apply(auto simp add: up_to_def)
def87c589516 updated
Christian Urban <urbanc@in.tum.de>
parents: 161
diff changeset
  1307
done
161
f1d82f6c05a3 updated
Christian Urban <urbanc@in.tum.de>
parents: 160
diff changeset
  1308
f1d82f6c05a3 updated
Christian Urban <urbanc@in.tum.de>
parents: 160
diff changeset
  1309
159
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1310
definition "occs' Q tt = length (filter Q (postfixes tt))"
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1311
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1312
lemma occs'_nil [simp]: "occs' Q [] = 0"
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1313
        by (unfold occs'_def, simp)
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1314
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1315
lemma occs'_cons [simp]: 
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1316
  shows "occs' Q (x#xs) = (if Q xs then 1 + occs' Q xs else occs' Q xs)"
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1317
  using assms   
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1318
  by (unfold occs'_def, simp)
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1319
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1320
lemma occs_len': "occs' Q t + occs' (\<lambda>e. \<not> Q e) t = length t"
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1321
  unfolding occs'_def
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1322
  by (induct t, auto)
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1323
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1324
lemma [simp]: "Q [] \<Longrightarrow> occs' Q [] + 1 = occs Q []"
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1325
  by (unfold occs'_def, simp)
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1326
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1327
lemma [simp]: "\<not> Q [] \<Longrightarrow> occs' Q [] = occs Q []"
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1328
  by (unfold occs'_def, simp)
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1329
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1330
lemma [simp]: "l \<noteq> [] \<Longrightarrow> Q l \<Longrightarrow> Suc (occs Q (tl l)) = occs Q l"
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1331
  by (induct l, auto)
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1332
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1333
lemma [simp]: "l \<noteq> [] \<Longrightarrow> \<not> Q l \<Longrightarrow> (occs Q (tl l)) = occs Q l"
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1334
  by (induct l, auto)
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1335
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1336
lemma "l \<noteq> [] \<Longrightarrow> occs' Q l = occs Q (tl l)"
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1337
proof(unfold occs'_def, induct l)
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1338
  case (Cons a l)
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1339
  show ?case
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1340
  proof(cases "l = []")
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1341
    case False
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1342
    from Cons(1)[OF this] have "length (filter Q (postfixes l)) = occs Q (tl l)" .
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1343
    with False
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1344
    show ?thesis by auto
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1345
  qed simp
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1346
qed auto
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1347
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1348
context extend_highest_gen
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1349
begin
159
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1350
023bdcc221ea updated
Christian Urban <urbanc@in.tum.de>
parents: 158
diff changeset
  1351
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1352
(* (* this lemma does not hold *)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1353
lemma actions_th_occs': "length (actions_of {th} t) = occs' (\<lambda>t'. th \<in> running (t' @ s)) t"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1354
  sorry 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1355
*)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1356
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1357
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1358
lemma actions_th_occs'_pre:
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1359
  assumes "t = e'#t'"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1360
  shows "length (actions_of {th} t) \<le> occs' (\<lambda> t'. th \<in> running (t'@s)) t"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1361
  using assms
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1362
proof(induct arbitrary: e' t' rule:ind)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1363
  case h: (Cons e t e' t')
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1364
  interpret vt: valid_trace "(t@s)" using h(1)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1365
    by (unfold_locales, simp)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1366
  interpret ve:  extend_highest_gen s th prio tm t using h by simp
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1367
  interpret ve':  extend_highest_gen s th prio tm "e#t" using h by simp
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1368
  show ?case (is "?L \<le> ?R")
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1369
  proof(cases t)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1370
    case Nil
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1371
    show ?thesis
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1372
    proof(cases "actor e = th")
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1373
      case True
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1374
      from ve'.th_no_create[OF _ this]
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1375
      have "\<not> isCreate e" by auto
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1376
      from PIP_actorE[OF h(2) True this] Nil
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1377
      have "th \<in> running s" by simp
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1378
      hence "?R = 1" using Nil h by simp
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1379
      moreover have "?L = 1" using True Nil by (simp add:actions_of_def)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1380
      ultimately show ?thesis by simp
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1381
    next
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1382
      case False
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1383
      with Nil
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1384
      show ?thesis by (auto simp:actions_of_def)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1385
    qed
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1386
  next
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1387
    case h1: (Cons e1 t1)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1388
    hence eq_t': "t' = e1#t1" using h by simp
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1389
    from h(5)[OF h1]
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1390
    have le: "length (actions_of {th} t) \<le> occs' (\<lambda>t'. th \<in> running (t' @ s)) t" 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1391
      (is "?F t \<le> ?G t1") .
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1392
    show ?thesis 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1393
    proof(cases "actor e = th")
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1394
      case True
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1395
      from ve'.th_no_create[OF _ this]
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1396
      have "\<not> isCreate e" by auto
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1397
      from PIP_actorE[OF h(2) True this]
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1398
      have "th \<in> running (t@s)" by simp
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1399
      hence "?R = 1 + ?G t1" by (unfold h1 eq_t', simp)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1400
      moreover have "?L = 1 + ?F t" using True by (simp add:actions_of_def)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1401
      ultimately show ?thesis using le by simp
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1402
    next
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1403
      case False
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1404
      with le
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1405
      show ?thesis by (unfold h1 eq_t', simp add:actions_of_def)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1406
    qed
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1407
  qed
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1408
qed auto
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1409
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1410
text {*
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1411
  The following lemma is a simple corollary of @{thm actions_th_occs_pre}. It is the
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1412
  lemma really needed in later proofs.
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1413
*}
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1414
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1415
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1416
lemma occs'_replacement1: "occs' (\<lambda> t'. th \<in> running (t'@s)) t = length (filter (\<lambda> s'. th \<in> running s') (up_to s t))"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1417
proof -
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1418
  have h: "((\<lambda>s'. th \<in> running s') \<circ> (\<lambda>t'. t' @ s)) = (\<lambda> t'. th \<in> running (t' @ s))" by (rule ext, simp)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1419
  thus ?thesis
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1420
    by (unfold occs'_def up_to_def length_filter_map h, simp)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1421
qed
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1422
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1423
lemma occs'_replacement2: "occs' (\<lambda> t'. th \<notin> running (t'@s)) t = length (filter (\<lambda> s'. th \<notin> running s') (up_to s t))"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1424
proof -
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1425
  have h: "((\<lambda>s'. th \<notin> running s') \<circ> (\<lambda>t'. t' @ s)) = (\<lambda> t'. th \<notin> running (t' @ s))" by (rule ext, simp)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1426
  thus ?thesis
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1427
    by (unfold occs'_def up_to_def length_filter_map h, simp)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1428
qed
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1429
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1430
lemma actions_th_occs':
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1431
  shows "length (actions_of {th} t) \<le> occs' (\<lambda> t'. th \<in> running (t'@s)) t"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1432
proof(cases t)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1433
  case (Cons e' t')
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1434
  from actions_th_occs'_pre[OF this]
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1435
  have "length (actions_of {th} t) \<le> occs' (\<lambda>t'. th \<in> running (t' @ s)) t" .
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1436
  thus ?thesis by simp
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1437
qed (auto simp:actions_of_def)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1438
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1439
theorem bound_priority_inversion':
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1440
  "occs' (\<lambda> t'. th \<notin> running (t'@s)) t \<le> 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1441
          (length (actions_of blockers t) + length (filter (isCreate) t))"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1442
   (is "?L \<le> ?R")
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1443
proof - 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1444
  let ?Q = "(\<lambda> t'. th \<in> running (t'@s))"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1445
  from occs_len'[of ?Q t] 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1446
  have "?L \<le> (length t) - occs' ?Q t" by simp
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1447
  also have "... \<le> ?R"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1448
  proof -
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1449
    have "length t - (length (actions_of blockers t) + length (filter (isCreate) t))
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1450
              \<le> occs' (\<lambda> t'. th \<in> running (t'@s)) t" (is "?L1 \<le> ?R1")
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1451
    proof -
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1452
      have "?L1 = length (actions_of {th} t)" using actions_split by arith
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1453
      also have "... \<le> ?R1" using actions_th_occs' by simp
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1454
      finally show ?thesis .
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1455
    qed            
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1456
    thus ?thesis by simp
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1457
  qed
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1458
  finally show ?thesis .
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1459
qed
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1460
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1461
theorem bound_priority_inversion:
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1462
  "occs (\<lambda> t'. th \<notin> running (t'@s)) t \<le> 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1463
          1 + (length (actions_of blockers t) + length (filter (isCreate) t))"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1464
   (is "?L \<le> ?R")
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1465
proof - 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1466
  let ?Q = "(\<lambda> t'. th \<in> running (t'@s))"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1467
  from occs_le[of ?Q t] 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1468
  have "?L \<le> 1 + (length t) - occs ?Q t" by simp
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1469
  also have "... \<le> ?R"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1470
  proof -
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1471
    have "length t - (length (actions_of blockers t) + length (filter (isCreate) t))
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1472
              \<le> occs (\<lambda> t'. th \<in> running (t'@s)) t" (is "?L1 \<le> ?R1")
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1473
    proof -
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1474
      have "?L1 = length (actions_of {th} t)" using actions_split by arith
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1475
      also have "... \<le> ?R1" using actions_th_occs by simp
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1476
      finally show ?thesis .
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1477
    qed            
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1478
    thus ?thesis by simp
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1479
  qed
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1480
  finally show ?thesis .
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1481
qed
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1482
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1483
end
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1484
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1485
text {*
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1486
  As explained before, lemma @{text bound_priority_inversion} alone does not
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1487
  ensure the correctness of PIP. For PIP to be correct, the number of blocking operations 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1488
  (by {\em blocking operation}, we mean the @{term Create}-operations and 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1489
           operations taken by blockers) has to be bounded somehow.
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1490
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1491
  And the following lemma is for this purpose.
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1492
*}
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1493
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1494
locale bounded_extend_highest = extend_highest_gen + 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1495
  -- {*
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1496
    To bound operations of blockers, the locale specifies that each blocker 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1497
    releases all resources and becomes detached after a certain number 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1498
    of operations. In the assumption, this number is given by the 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1499
    existential variable @{text span}. Notice that this number is fixed for each 
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1500
    blocker regardless of any particular instance of @{term t'} in which it operates.
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1501
    
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1502
    This assumption is reasonable, because it is a common sense that 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1503
    the total number of operations take by any standalone thread (or process) 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1504
    is only determined by its own input, and should not be affected by 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1505
    the particular environment in which it operates. In this particular case,
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1506
    we regard the @{term t} as the environment of thread @{term th}.
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1507
  *}
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1508
  (*
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1509
  assumes finite_span: 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1510
          "th' \<in> blockers \<Longrightarrow>
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1511
                 (\<exists> span. \<forall> t'. extend_highest_gen s th prio tm t' \<longrightarrow>
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1512
                                length (actions_of {th'} t') = span \<longrightarrow> detached (t'@s) th')"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1513
   *)
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1514
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1515
  -- {*
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1516
    The above definition and explain is problematic because the number of actions taken
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1517
    by @{term th'} may be affected by is environment not modeled by the events of our
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1518
    PIP model.
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1519
  *}
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1520
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1521
  -- {*
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1522
    However, we still need to express the idea that every blocker becomes detached in bounded 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1523
    number of steps. Supposing @{term span} is such a bound, the following @{term finite_span}
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1524
    assumption says if @{term th'} is not @{term detached} in state (t'@s), then its number 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1525
    of actions must be less than this bound @{term span}:
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1526
  *}
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1527
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1528
  assumes finite_span: 
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1529
          "th' \<in> blockers \<Longrightarrow>
154
9756a51f2223 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 145
diff changeset
  1530
                 (\<exists> span. \<forall> t'. extend_highest_gen s th prio tm t' \<longrightarrow> 
9756a51f2223 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 145
diff changeset
  1531
                                  \<not> detached (t'@s) th' \<longrightarrow> length (actions_of {th'} t') < span)"
9756a51f2223 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 145
diff changeset
  1532
9756a51f2223 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 145
diff changeset
  1533
  -- {*
9756a51f2223 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 145
diff changeset
  1534
    The difference between this @{text finite_span} and the former one is to allow the number
9756a51f2223 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 145
diff changeset
  1535
    of action steps to change with execution paths (i.e. different value of @{term "t'@s"}}).
9756a51f2223 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 145
diff changeset
  1536
    The @{term span} is a upper bound on these step numbers. 
9756a51f2223 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 145
diff changeset
  1537
  *}
9756a51f2223 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 145
diff changeset
  1538
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1539
  -- {* The following @{text BC} is bound of @{term Create}-operations *}
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1540
  fixes BC
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1541
  -- {* 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1542
  The following assumption requires the number of @{term Create}-operations is 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1543
  less or equal to @{term BC} regardless of any particular extension of @{term t}.
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1544
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1545
   Although this assumption might seem doubtful at first sight, it is necessary 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1546
   to ensure the occasions when @{term th} is blocked to be finite. Just consider
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1547
   the extreme case when @{term Create}-operations consume all the time in duration 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1548
   @{term "t"} and leave no space for neither @{term "th"} nor blockers to operate.
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1549
   An investigate of the precondition for @{term Create}-operation in the definition 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1550
   of @{term PIP} may reveal that such extreme cases are well possible, because it 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1551
   is only required the thread to be created be a fresh (or dead one), and there 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1552
   are infinitely many such threads. 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1553
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1554
   However, if we relax the correctness criterion of PIP, allowing @{term th} to be 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1555
   blocked indefinitely while still attaining a certain portion of @{term t} to complete 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1556
   its task, then this bound @{term BC} can be lifted to function depending on @{term t}
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1557
   where @{text "BC t"} is of a certain proportion of @{term "length t"}.
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1558
  *}
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1559
  assumes finite_create: 
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1560
          "\<forall> t'. extend_highest_gen s th prio tm t' \<longrightarrow> length (filter isCreate t') < BC"
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1561
begin 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1562
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1563
text {*
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1564
  The following lemmas show that the number of @{term Create}-operations is bound by @{term BC}:
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1565
*}
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1566
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1567
lemma create_bc: 
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1568
  shows "length (filter isCreate t) < BC"
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1569
    by (meson extend_highest_gen_axioms finite_create)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1570
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1571
text {*
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1572
  The following @{term span}-function gives the upper bound of 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1573
  operations take by each particular blocker.
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1574
*}
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1575
definition "span th' = (SOME span.
154
9756a51f2223 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 145
diff changeset
  1576
         \<forall> t'. extend_highest_gen s th prio tm t' \<longrightarrow> 
9756a51f2223 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 145
diff changeset
  1577
                  \<not> detached (t'@s) th' \<longrightarrow> length (actions_of {th'} t') < span)"
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1578
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1579
text {*
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1580
  The following lemmas shows the correctness of @{term span}, i.e. 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1581
  the number of operations of taken by @{term th'} is given by 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1582
  @{term "span th"}.
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1583
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1584
  The reason for this lemma is that since @{term th'} gives up all resources 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1585
  after @{term "span th'"} operations and becomes detached,
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1586
  its inherited high priority is lost, with which the right to run goes as well.
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1587
*}
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1588
lemma le_span:
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1589
  assumes "th' \<in> blockers"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1590
  shows "length (actions_of {th'} t) \<le> span th'"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1591
proof -
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1592
  from finite_span[OF assms(1)] obtain span' 
154
9756a51f2223 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 145
diff changeset
  1593
  where span': "\<forall> t'. extend_highest_gen s th prio tm t' \<longrightarrow> 
9756a51f2223 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 145
diff changeset
  1594
                       \<not> detached (t'@s) th' \<longrightarrow> length (actions_of {th'} t') < span'" (is "?P span'")
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1595
                     by auto
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1596
  have "length (actions_of {th'} t) \<le> (SOME span. ?P span)"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1597
  proof(rule someI2[where a = span'])
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1598
    fix span
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1599
    assume fs: "?P span" 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1600
    show "length (actions_of {th'} t) \<le> span"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1601
    proof(induct rule:ind)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1602
      case h: (Cons e t)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1603
        interpret ve':  extend_highest_gen s th prio tm "e#t" using h by simp
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1604
      show ?case
154
9756a51f2223 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 145
diff changeset
  1605
      proof(cases "detached (t@s) th'")
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1606
        case True
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1607
        have "actor e \<noteq> th'"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1608
        proof
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1609
          assume otherwise: "actor e = th'"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1610
          from ve'.blockers_no_create [OF assms _ this]
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1611
          have "\<not> isCreate e" by auto
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1612
          from PIP_actorE[OF h(2) otherwise this]
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
  1613
          have "th' \<in> running (t @ s)" .
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
  1614
          moreover have "th' \<notin> running (t @ s)"
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1615
          proof -
154
9756a51f2223 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 145
diff changeset
  1616
            from extend_highest_gen.detached_not_running[OF h(3) True] assms
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1617
            show ?thesis by (auto simp:blockers_def)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1618
          qed
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1619
          ultimately show False by simp
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1620
        qed
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1621
        with h show ?thesis by (auto simp:actions_of_def)
154
9756a51f2223 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 145
diff changeset
  1622
      next
9756a51f2223 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 145
diff changeset
  1623
        case False
9756a51f2223 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 145
diff changeset
  1624
        from fs[rule_format, OF h(3) this] and actions_of_len_cons
9756a51f2223 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 145
diff changeset
  1625
        show ?thesis by (meson discrete order.trans) 
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1626
      qed
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1627
    qed (simp add: actions_of_def)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1628
  next
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1629
    from span'
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1630
    show "?P span'" .
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1631
  qed
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1632
  thus ?thesis by (unfold span_def, auto)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1633
qed
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1634
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1635
text {*
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1636
  The following lemma is a corollary of @{thm le_span}, which says 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1637
  the total operations of blockers is bounded by the 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1638
  sum of @{term span}-values of all blockers.
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1639
*}
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1640
lemma len_action_blockers: 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1641
  "length (actions_of blockers t) \<le> (\<Sum> th' \<in> blockers . span th')"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1642
    (is "?L \<le> ?R")
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1643
proof -
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1644
  from len_actions_of_sigma[OF finite_blockers]
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1645
  have "?L  = (\<Sum>th'\<in>blockers. length (actions_of {th'} t))" by simp
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1646
  also have "... \<le> ?R"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1647
    by (rule Groups_Big.setsum_mono, insert le_span, auto)
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1648
  finally show ?thesis .
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1649
qed
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1650
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1651
text {*
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1652
  By combining forgoing lemmas, it is proved that the number of 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1653
  blocked occurrences of the most urgent thread @{term th} is finitely bounded:
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1654
*}
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1655
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1656
theorem priority_inversion_is_finite':
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1657
  "occs' (\<lambda> t'. th \<notin> running (t'@s)) t \<le> 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1658
          ((\<Sum> th' \<in> blockers . span th') + BC)" (is "?L \<le> ?R" is "_ \<le> (?A + ?B)" )
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1659
proof -
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1660
  from bound_priority_inversion'
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1661
  have "?L \<le> (length (actions_of blockers t) + length (filter isCreate t))" 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1662
      (is "_ \<le> (?A' + ?B')") .
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1663
  moreover have "?A' \<le> ?A" using len_action_blockers .
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1664
  moreover have "?B' \<le> ?B" using create_bc by auto
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1665
  ultimately show ?thesis by simp
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1666
qed
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1667
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1668
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1669
theorem priority_inversion_is_finite_upto:
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1670
  "length [s'\<leftarrow>up_to s t . th \<notin> running s'] \<le> 
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1671
          ((\<Sum> th' \<in> blockers . span th') + BC)"
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1672
 using priority_inversion_is_finite'[unfolded occs'_replacement2] by simp
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1673
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1674
theorem priority_inversion_is_finite:
127
38c6acf03f68 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
  1675
  "occs (\<lambda> t'. th \<notin> running (t'@s)) t \<le> 
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1676
          1 + ((\<Sum> th' \<in> blockers . span th') + BC)" (is "?L \<le> ?R" is "_ \<le> 1 + (?A + ?B)" )
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1677
proof -
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1678
  from bound_priority_inversion
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1679
  have "?L \<le> 1 + (length (actions_of blockers t) + length (filter isCreate t))" 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1680
      (is "_ \<le> 1 + (?A' + ?B')") .
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1681
  moreover have "?A' \<le> ?A" using len_action_blockers .
160
83da37e8b1d2 "up_to" added and main theorems improved.
zhangx
parents: 159
diff changeset
  1682
  moreover have "?B' \<le> ?B" using create_bc by auto
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1683
  ultimately show ?thesis by simp
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1684
qed
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1685
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1686
text {*
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1687
  The following lemma says the most urgent thread @{term th} will get as many 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1688
  as operations it wishes, provided @{term t} is long enough. 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1689
  Similar result can also be obtained under the slightly weaker assumption where
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1690
  @{term BC} is lifted to a function and @{text "BC t"} is a portion of 
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1691
  @{term "length t"}.
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1692
*}
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1693
theorem enough_actions_for_the_highest:
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1694
  "length t - ((\<Sum> th' \<in> blockers . span th') + BC) \<le> length (actions_of {th} t)"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1695
  using actions_split create_bc len_action_blockers by linarith
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1696
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1697
end
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1698
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 122
diff changeset
  1699
end