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