ExtGG.thy
author zhangx
Tue, 22 Dec 2015 23:13:31 +0800
changeset 62 031d2ae9c9b8
parent 35 92f61f6a0fe7
child 63 b620a2a0806a
permissions -rw-r--r--
In the middle of retrofiting ExtGG.thy.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
theory ExtGG
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
     2
imports PrioG CpsG
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     3
begin
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 0
diff changeset
     5
lemma birth_time_lt:  "s \<noteq> [] \<Longrightarrow> last_set th s < length s"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
  apply (induct s, simp)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     8
  fix a s
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 0
diff changeset
     9
  assume ih: "s \<noteq> [] \<Longrightarrow> last_set th s < length s"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    10
    and eq_as: "a # s \<noteq> []"
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 0
diff changeset
    11
  show "last_set th (a # s) < length (a # s)"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    12
  proof(cases "s \<noteq> []")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    13
    case False
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    14
    from False show ?thesis
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 0
diff changeset
    15
      by (cases a, auto simp:last_set.simps)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    16
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    17
    case True
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    18
    from ih [OF True] show ?thesis
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 0
diff changeset
    19
      by (cases a, auto simp:last_set.simps)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    20
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    21
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    22
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    23
lemma th_in_ne: "th \<in> threads s \<Longrightarrow> s \<noteq> []"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    24
  by (induct s, auto simp:threads.simps)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
lemma preced_tm_lt: "th \<in> threads s \<Longrightarrow> preced th s = Prc x y \<Longrightarrow> y < length s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
  apply (drule_tac th_in_ne)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
  by (unfold preced_def, auto intro: birth_time_lt)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    29
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    30
locale highest_gen =
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    31
  fixes s th prio tm
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    32
  assumes vt_s: "vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
  and threads_s: "th \<in> threads s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
  and highest: "preced th s = Max ((cp s)`threads s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    35
  and preced_th: "preced th s = Prc prio tm"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
    37
sublocale highest_gen < vat_s: valid_trace "s"
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
    38
  by (unfold_locales, insert vt_s, simp)
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
    39
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    40
context highest_gen
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    41
begin
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    42
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    43
lemma lt_tm: "tm < length s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    44
  by (insert preced_tm_lt[OF threads_s preced_th], simp)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
    46
lemma eq_cp_s_th: "cp s th = preced th s" (is "?L = ?R")
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    47
proof -
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
    48
  have "?L \<le> ?R"
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
    49
  by (unfold highest, rule Max_ge, 
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
    50
        auto simp:threads_s finite_threads[OF vt_s])
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
    51
  moreover have "?R \<le> ?L"
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
    52
    by (unfold vat_s.cp_rec, rule Max_ge, 
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
    53
        auto simp:the_preced_def vat_s.fsbttRAGs.finite_children)
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
    54
  ultimately show ?thesis by auto
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    55
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    56
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    57
lemma highest_cp_preced: "cp s th = Max ((\<lambda> th'. preced th' s) ` threads s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    58
  by (fold max_cp_eq[OF vt_s], unfold eq_cp_s_th, insert highest, simp)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    59
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    60
lemma highest_preced_thread: "preced th s = Max ((\<lambda> th'. preced th' s) ` threads s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    61
  by (fold eq_cp_s_th, unfold highest_cp_preced, simp)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    62
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    63
lemma highest': "cp s th = Max (cp s ` threads s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    64
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    65
  from highest_cp_preced max_cp_eq[OF vt_s, symmetric]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    66
  show ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    67
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    68
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    69
end
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    70
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    71
locale extend_highest_gen = highest_gen + 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    72
  fixes t 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    73
  assumes vt_t: "vt (t@s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    74
  and create_low: "Create th' prio' \<in> set t \<Longrightarrow> prio' \<le> prio"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    75
  and set_diff_low: "Set th' prio' \<in> set t \<Longrightarrow> th' \<noteq> th \<and> prio' \<le> prio"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    76
  and exit_diff: "Exit th' \<in> set t \<Longrightarrow> th' \<noteq> th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    77
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    78
lemma step_back_vt_app: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    79
  assumes vt_ts: "vt (t@s)" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    80
  shows "vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    81
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    82
  from vt_ts show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    83
  proof(induct t)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    84
    case Nil
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    85
    from Nil show ?case by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    86
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    87
    case (Cons e t)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    88
    assume ih: " vt (t @ s) \<Longrightarrow> vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    89
      and vt_et: "vt ((e # t) @ s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    90
    show ?case
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    91
    proof(rule ih)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    92
      show "vt (t @ s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    93
      proof(rule step_back_vt)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    94
        from vt_et show "vt (e # t @ s)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    95
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    96
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    97
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    98
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    99
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   100
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   101
locale red_extend_highest_gen = extend_highest_gen +
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   102
   fixes i::nat
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   103
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   104
sublocale red_extend_highest_gen <   red_moment: extend_highest_gen "s" "th" "prio" "tm" "(moment i t)"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   105
  apply (insert extend_highest_gen_axioms, subst (asm) (1) moment_restm_s [of i t, symmetric])
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   106
  apply (unfold extend_highest_gen_def extend_highest_gen_axioms_def, clarsimp)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   107
  by (unfold highest_gen_def, auto dest:step_back_vt_app)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   108
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   109
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   110
context extend_highest_gen
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   111
begin
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   112
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   113
(*
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   114
 lemma red_moment:
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   115
  "extend_highest_gen s th prio tm (moment i t)"
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   116
  apply (insert extend_highest_gen_axioms, subst (asm) (1) moment_restm_s [of i t, symmetric])
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   117
  apply (unfold extend_highest_gen_def extend_highest_gen_axioms_def, clarsimp)
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   118
  by (unfold highest_gen_def, auto dest:step_back_vt_app) 
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   119
*)
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   120
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   121
 lemma ind [consumes 0, case_names Nil Cons, induct type]:
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   122
  assumes 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   123
    h0: "R []"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   124
  and h2: "\<And> e t. \<lbrakk>vt (t@s); step (t@s) e; 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   125
                    extend_highest_gen s th prio tm t; 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   126
                    extend_highest_gen s th prio tm (e#t); R t\<rbrakk> \<Longrightarrow> R (e#t)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   127
  shows "R t"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   128
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   129
  from vt_t extend_highest_gen_axioms show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   130
  proof(induct t)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   131
    from h0 show "R []" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   132
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   133
    case (Cons e t')
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   134
    assume ih: "\<lbrakk>vt (t' @ s); extend_highest_gen s th prio tm t'\<rbrakk> \<Longrightarrow> R t'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   135
      and vt_e: "vt ((e # t') @ s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   136
      and et: "extend_highest_gen s th prio tm (e # t')"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   137
    from vt_e and step_back_step have stp: "step (t'@s) e" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   138
    from vt_e and step_back_vt have vt_ts: "vt (t'@s)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   139
    show ?case
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   140
    proof(rule h2 [OF vt_ts stp _ _ _ ])
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   141
      show "R t'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   142
      proof(rule ih)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   143
        from et show ext': "extend_highest_gen s th prio tm t'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   144
          by (unfold extend_highest_gen_def extend_highest_gen_axioms_def, auto dest:step_back_vt)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   145
      next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   146
        from vt_ts show "vt (t' @ s)" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   147
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   148
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   149
      from et show "extend_highest_gen s th prio tm (e # t')" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   150
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   151
      from et show ext': "extend_highest_gen s th prio tm t'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   152
          by (unfold extend_highest_gen_def extend_highest_gen_axioms_def, auto dest:step_back_vt)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   153
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   154
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   155
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   156
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   157
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   158
lemma th_kept: "th \<in> threads (t @ s) \<and> 
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   159
                 preced th (t@s) = preced th s" (is "?Q t") 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   160
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   161
  show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   162
  proof(induct rule:ind)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   163
    case Nil
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   164
    from threads_s
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   165
    show ?case
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   166
      by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   167
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   168
    case (Cons e t)
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   169
    interpret h_e: extend_highest_gen _ _ _ _ "(e # t)" using Cons by auto
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   170
    interpret h_t: extend_highest_gen _ _ _ _ t using Cons by auto
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   171
    show ?case
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   172
    proof(cases e)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   173
      case (Create thread prio)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   174
      show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   175
      proof -
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   176
        from Cons and Create have "step (t@s) (Create thread prio)" by auto
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   177
        hence "th \<noteq> thread"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   178
        proof(cases)
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   179
          case thread_create
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   180
          with Cons show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   181
        qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   182
        hence "preced th ((e # t) @ s)  = preced th (t @ s)"
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   183
          by (unfold Create, auto simp:preced_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   184
        moreover note Cons
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   185
        ultimately show ?thesis
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   186
          by (auto simp:Create)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   187
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   188
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   189
      case (Exit thread)
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   190
      from h_e.exit_diff and Exit
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   191
      have neq_th: "thread \<noteq> th" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   192
      with Cons
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   193
      show ?thesis
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   194
        by (unfold Exit, auto simp:preced_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   195
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   196
      case (P thread cs)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   197
      with Cons
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   198
      show ?thesis 
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   199
        by (auto simp:P preced_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   200
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   201
      case (V thread cs)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   202
      with Cons
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   203
      show ?thesis 
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   204
        by (auto simp:V preced_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   205
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   206
      case (Set thread prio')
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   207
      show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   208
      proof -
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   209
        from h_e.set_diff_low and Set
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   210
        have "th \<noteq> thread" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   211
        hence "preced th ((e # t) @ s)  = preced th (t @ s)"
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   212
          by (unfold Set, auto simp:preced_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   213
        moreover note Cons
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   214
        ultimately show ?thesis
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   215
          by (auto simp:Set)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   216
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   217
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   218
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   219
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   220
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   221
lemma Max_remove_less:
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   222
  assumes "finite A"
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   223
  and "a \<in> A"
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   224
  and "b \<in> A"
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   225
  and "a \<noteq> b"
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   226
  and "inj_on f A"
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   227
  and "f a = Max (f ` A)" 
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   228
  shows "Max (f ` (A - {b})) = (Max (f ` A))"
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   229
proof -
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   230
  have "Max (f ` (A - {b})) = Max (f`A - {f b})"
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   231
  proof -
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   232
    have "f ` (A - {b}) = f ` A - f ` {b}"
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   233
    by (rule inj_on_image_set_diff[OF assms(5)], insert assms(3), auto)
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   234
    thus ?thesis by simp
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   235
  qed
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   236
  also have "... =  
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   237
       (if f ` A - {f b} - {f a} = {} then f a else max (f a) (Max (f ` A - {f b} - {f a})))" 
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   238
  proof(subst Max.remove)
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   239
    from assms show "f a \<in> f ` A - {f b}"
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   240
      by (meson DiffI empty_iff imageI inj_on_eq_iff insert_iff) 
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   241
  next
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   242
    from assms(1) show "finite (f ` A - {f b})" by auto
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   243
  qed auto
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   244
  also have "... = Max (f ` A)" (is "?L = ?R")
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   245
  proof(cases "f ` A - {f b} - {f a} = {}")
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   246
    case True
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   247
    with assms show ?thesis by auto
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   248
  next
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   249
    case False
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   250
    hence "?L =  max (f a) (Max (f ` A - {f b} - {f a}))" 
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   251
      by simp
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   252
    also have "... = ?R" 
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   253
    proof -
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   254
      from assms False
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   255
      have "(Max (f ` A - {f b} - {f a})) \<le> f a" by auto
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   256
      thus ?thesis by (simp add: assms(6) max_def) 
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   257
    qed
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   258
    finally show ?thesis .
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   259
  qed
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   260
  finally show ?thesis .
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   261
qed
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   262
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   263
lemma max_kept: "Max (the_preced (t @ s) ` (threads (t@s))) = preced th s"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   264
proof(induct rule:ind)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   265
  case Nil
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   266
  from highest_preced_thread
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   267
  show ?case
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   268
    by (unfold the_preced_def, simp)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   269
next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   270
  case (Cons e t)
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   271
    interpret h_e: extend_highest_gen _ _ _ _ "(e # t)" using Cons by auto
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   272
    interpret h_t: extend_highest_gen _ _ _ _ t using Cons by auto
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   273
  show ?case
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   274
  proof(cases e)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   275
    case (Create thread prio')
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   276
    from Cons(2)[unfolded this] 
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   277
    have thread_not_in: "thread \<notin> threads (t@s)" by (cases, simp)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   278
    show ?thesis (is "Max (?f ` ?A) = ?t")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   279
    proof -
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   280
      have "Max (?f ` ?A) = Max (insert (?f thread) (?f ` (threads (t@s))))"
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   281
        by (unfold Create, simp)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   282
      moreover have "\<dots> = max (?f thread) (Max (?f ` (threads (t@s))))"
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   283
      proof(rule Max.insert)
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   284
        from finite_threads[OF Cons(1)]
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   285
        show "finite (?f ` (threads (t@s)))" by simp
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   286
      qed (insert h_t.th_kept, auto)
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   287
      moreover have "(Max (?f ` (threads (t@s)))) = ?t" 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   288
      proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   289
        have "(\<lambda>th'. preced th' ((e # t) @ s)) ` threads (t @ s) = 
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   290
                (\<lambda>th'. preced th' (t @ s)) ` threads (t @ s)" 
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   291
        by (intro f_image_eq, insert thread_not_in, auto simp:Create preced_def)
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   292
        with Cons show ?thesis by (auto simp:the_preced_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   293
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   294
      moreover have "?f thread < ?t"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   295
      proof -
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   296
        from h_e.create_low and Create
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   297
        have "prio' \<le> prio" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   298
        thus ?thesis
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   299
        by (unfold preced_th, unfold Create, insert lt_tm, 
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   300
          auto simp:preced_def precedence_less_def preced_th the_preced_def)
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   301
     qed
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   302
     ultimately show ?thesis by (auto simp:max_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   303
    qed
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   304
  next 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   305
    case (Exit thread)
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   306
    show ?thesis
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   307
    proof -
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   308
      have "Max (the_preced (t @ s) ` (threads (t @ s) - {thread})) = 
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   309
            Max (the_preced (t @ s) ` (threads (t @ s)))"
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   310
      proof(rule Max_remove_less)
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   311
        show "th \<noteq> thread" using Exit h_e.exit_diff by auto 
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   312
      next
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   313
        from Cons(2)[unfolded Exit]
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   314
        show "thread \<in> threads (t @ s)" 
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   315
          by (cases, simp add: readys_def runing_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   316
      next
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   317
        show "finite (threads (t @ s))" by (simp add: finite_threads h_t.vt_t) 
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   318
      next
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   319
        show "th \<in> threads (t @ s)" by (simp add: h_t.th_kept) 
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   320
      next
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   321
        show "inj_on (the_preced (t @ s)) (threads (t @ s))" by (simp add: inj_the_preced) 
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   322
      next
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   323
        show "the_preced (t @ s) th = Max (the_preced (t @ s) ` threads (t @ s))"
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   324
            by (simp add: Cons.hyps(5) h_t.th_kept the_preced_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   325
      qed
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   326
      from this[unfolded Cons(5)]
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   327
      have "Max (the_preced (t @ s) ` (threads (t @ s) - {thread})) = preced th s" .
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   328
      moreover have "the_preced ((e # t) @ s) = the_preced (t@s)"
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   329
                             by (auto simp:Exit the_preced_def preced_def)
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   330
      ultimately show ?thesis by (simp add:Exit)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   331
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   332
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   333
    case (P thread cs)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   334
    with Cons
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   335
    show ?thesis by (auto simp:preced_def the_preced_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   336
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   337
    case (V thread cs)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   338
    with Cons
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   339
    show ?thesis by (auto simp:preced_def the_preced_def)
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   340
  next (* ccc *)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   341
    case (Set thread prio')
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   342
    show ?thesis
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   343
    apply (unfold Set, simp, insert Cons(5)) (* ccc *)
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   344
    find_theorems priority Set
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 35
diff changeset
   345
    find_theorems preced Set
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   346
    proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   347
      let ?B = "threads (t@s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   348
      from Cons have "extend_highest_gen s th prio tm (e # t)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   349
      from extend_highest_gen.set_diff_low[OF this] and Set
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   350
      have neq_thread: "thread \<noteq> th" and le_p: "prio' \<le> prio" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   351
      from Set have "Max (?f ` ?A) = Max (?f ` ?B)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   352
      also have "\<dots> = ?t"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   353
      proof(rule Max_eqI)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   354
        fix y
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   355
        assume y_in: "y \<in> ?f ` ?B"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   356
        then obtain th1 where 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   357
          th1_in: "th1 \<in> ?B" and eq_y: "y = ?f th1" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   358
        show "y \<le> ?t"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   359
        proof(cases "th1 = thread")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   360
          case True
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   361
          with neq_thread le_p eq_y Set
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   362
          show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   363
            apply (subst preced_th, insert lt_tm)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   364
            by (auto simp:preced_def precedence_le_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   365
        next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   366
          case False
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   367
          with Set eq_y
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   368
          have "y  = preced th1 (t@s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   369
            by (simp add:preced_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   370
          moreover have "\<dots> \<le> ?t"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   371
          proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   372
            from Cons
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   373
            have "?t = Max ((\<lambda> th'. preced th' (t@s)) ` (threads (t@s)))"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   374
              by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   375
            moreover have "preced th1 (t@s) \<le> \<dots>"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   376
            proof(rule Max_ge)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   377
              from th1_in 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   378
              show "preced th1 (t @ s) \<in> (\<lambda>th'. preced th' (t @ s)) ` threads (t @ s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   379
                by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   380
            next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   381
              show "finite ((\<lambda>th'. preced th' (t @ s)) ` threads (t @ s))"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   382
              proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   383
                from Cons have "vt (t @ s)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   384
                from finite_threads[OF this] show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   385
              qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   386
            qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   387
            ultimately show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   388
          qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   389
          ultimately show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   390
        qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   391
      next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   392
        from Cons and finite_threads
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   393
        show "finite (?f ` ?B)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   394
      next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   395
        from Cons have "extend_highest_gen s th prio tm t" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   396
        from extend_highest_gen.th_kept [OF this]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   397
        have h: "th \<in> threads (t @ s) \<and> preced th (t @ s) = preced th s" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   398
        show "?t \<in> (?f ` ?B)" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   399
        proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   400
          from neq_thread Set h
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   401
          have "?t = ?f th" by (auto simp:preced_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   402
          with h show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   403
        qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   404
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   405
      finally show ?thesis .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   406
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   407
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   408
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   409
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   410
lemma max_preced: "preced th (t@s) = Max ((\<lambda> th'. preced th' (t @ s)) ` (threads (t@s)))"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   411
  by (insert th_kept max_kept, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   412
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   413
lemma th_cp_max_preced: "cp (t@s) th = Max ((\<lambda> th'. preced th' (t @ s)) ` (threads (t@s)))" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   414
  (is "?L = ?R")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   415
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   416
  have "?L = cpreced (wq (t@s)) (t@s) th" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   417
    by (unfold cp_eq_cpreced, simp)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   418
  also have "\<dots> = ?R"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   419
  proof(unfold cpreced_def)
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 0
diff changeset
   420
    show "Max ((\<lambda>th. preced th (t @ s)) ` ({th} \<union> dependants (wq (t @ s)) th)) =
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   421
          Max ((\<lambda>th'. preced th' (t @ s)) ` threads (t @ s))"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   422
      (is "Max (?f ` ({th} \<union> ?A)) = Max (?f ` ?B)")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   423
    proof(cases "?A = {}")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   424
      case False
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   425
      have "Max (?f ` ({th} \<union> ?A)) = Max (insert (?f th) (?f ` ?A))" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   426
      moreover have "\<dots> = max (?f th) (Max (?f ` ?A))"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   427
      proof(rule Max_insert)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   428
        show "finite (?f ` ?A)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   429
        proof -
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 0
diff changeset
   430
          from dependants_threads[OF vt_t]
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   431
          have "?A \<subseteq> threads (t@s)" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   432
          moreover from finite_threads[OF vt_t] have "finite \<dots>" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   433
          ultimately show ?thesis 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   434
            by (auto simp:finite_subset)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   435
        qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   436
      next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   437
        from False show "(?f ` ?A) \<noteq> {}" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   438
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   439
      moreover have "\<dots> = Max (?f ` ?B)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   440
      proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   441
        from max_preced have "?f th = Max (?f ` ?B)" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   442
        moreover have "Max (?f ` ?A) \<le> \<dots>" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   443
        proof(rule Max_mono)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   444
          from False show "(?f ` ?A) \<noteq> {}" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   445
        next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   446
          show "?f ` ?A \<subseteq> ?f ` ?B" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   447
          proof -
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 0
diff changeset
   448
            have "?A \<subseteq> ?B" by (rule dependants_threads[OF vt_t])
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   449
            thus ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   450
          qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   451
        next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   452
          from finite_threads[OF vt_t] 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   453
          show "finite (?f ` ?B)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   454
        qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   455
        ultimately show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   456
          by (auto simp:max_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   457
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   458
      ultimately show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   459
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   460
      case True
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   461
      with max_preced show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   462
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   463
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   464
  finally show ?thesis .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   465
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   466
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   467
lemma th_cp_max: "cp (t@s) th = Max (cp (t@s) ` threads (t@s))"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   468
  by (unfold max_cp_eq[OF vt_t] th_cp_max_preced, simp)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   469
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   470
lemma th_cp_preced: "cp (t@s) th = preced th s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   471
  by (fold max_kept, unfold th_cp_max_preced, simp)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   472
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   473
lemma preced_less:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   474
  fixes th'
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   475
  assumes th'_in: "th' \<in> threads s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   476
  and neq_th': "th' \<noteq> th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   477
  shows "preced th' s < preced th s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   478
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   479
  have "preced th' s \<le> Max ((\<lambda>th'. preced th' s) ` threads s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   480
  proof(rule Max_ge)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   481
    from finite_threads [OF vt_s]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   482
    show "finite ((\<lambda>th'. preced th' s) ` threads s)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   483
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   484
    from th'_in show "preced th' s \<in> (\<lambda>th'. preced th' s) ` threads s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   485
      by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   486
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   487
  moreover have "preced th' s \<noteq> preced th s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   488
  proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   489
    assume "preced th' s = preced th s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   490
    from preced_unique[OF this th'_in] neq_th' threads_s
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   491
    show "False" by  (auto simp:readys_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   492
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   493
  ultimately show ?thesis using highest_preced_thread
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   494
    by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   495
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   496
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   497
lemma pv_blocked_pre:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   498
  fixes th'
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   499
  assumes th'_in: "th' \<in> threads (t@s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   500
  and neq_th': "th' \<noteq> th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   501
  and eq_pv: "cntP (t@s) th' = cntV (t@s) th'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   502
  shows "th' \<notin> runing (t@s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   503
proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   504
  assume "th' \<in> runing (t@s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   505
  hence "cp (t@s) th' = Max (cp (t@s) ` readys (t@s))" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   506
    by (auto simp:runing_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   507
  with max_cp_readys_threads [OF vt_t]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   508
  have "cp (t @ s) th' = Max (cp (t@s) ` threads (t@s))"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   509
    by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   510
  moreover from th_cp_max have "cp (t @ s) th = \<dots>" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   511
  ultimately have "cp (t @ s) th' = cp (t @ s) th" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   512
  moreover from th_cp_preced and th_kept have "\<dots> = preced th (t @ s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   513
    by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   514
  finally have h: "cp (t @ s) th' = preced th (t @ s)" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   515
  show False
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   516
  proof -
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 0
diff changeset
   517
    have "dependants (wq (t @ s)) th' = {}" 
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 0
diff changeset
   518
      by (rule count_eq_dependants [OF vt_t eq_pv])
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   519
    moreover have "preced th' (t @ s) \<noteq> preced th (t @ s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   520
    proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   521
      assume "preced th' (t @ s) = preced th (t @ s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   522
      hence "th' = th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   523
      proof(rule preced_unique)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   524
        from th_kept show "th \<in> threads (t @ s)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   525
      next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   526
        from th'_in show "th' \<in> threads (t @ s)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   527
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   528
      with assms show False by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   529
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   530
    ultimately show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   531
      by (insert h, unfold cp_eq_cpreced cpreced_def, simp)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   532
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   533
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   534
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   535
lemmas pv_blocked = pv_blocked_pre[folded detached_eq [OF vt_t]]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   536
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   537
lemma runing_precond_pre:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   538
  fixes th'
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   539
  assumes th'_in: "th' \<in> threads s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   540
  and eq_pv: "cntP s th' = cntV s th'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   541
  and neq_th': "th' \<noteq> th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   542
  shows "th' \<in> threads (t@s) \<and>
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   543
         cntP (t@s) th' = cntV (t@s) th'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   544
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   545
  show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   546
  proof(induct rule:ind)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   547
    case (Cons e t)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   548
    from Cons
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   549
    have in_thread: "th' \<in> threads (t @ s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   550
      and not_holding: "cntP (t @ s) th' = cntV (t @ s) th'" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   551
    from Cons have "extend_highest_gen s th prio tm t" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   552
    then have not_runing: "th' \<notin> runing (t @ s)" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   553
      apply(rule extend_highest_gen.pv_blocked) 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   554
      using Cons(1) in_thread neq_th' not_holding
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   555
      apply(simp_all add: detached_eq)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   556
      done
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   557
    show ?case
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   558
    proof(cases e)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   559
      case (V thread cs)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   560
      from Cons and V have vt_v: "vt (V thread cs#(t@s))" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   561
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   562
      show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   563
      proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   564
        from Cons and V have "step (t@s) (V thread cs)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   565
        hence neq_th': "thread \<noteq> th'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   566
        proof(cases)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   567
          assume "thread \<in> runing (t@s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   568
          moreover have "th' \<notin> runing (t@s)" by fact
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   569
          ultimately show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   570
        qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   571
        with not_holding have cnt_eq: "cntP ((e # t) @ s) th' = cntV ((e # t) @ s) th'" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   572
          by (unfold V, simp add:cntP_def cntV_def count_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   573
        moreover from in_thread
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   574
        have in_thread': "th' \<in> threads ((e # t) @ s)" by (unfold V, simp)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   575
        ultimately show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   576
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   577
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   578
      case (P thread cs)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   579
      from Cons and P have "step (t@s) (P thread cs)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   580
      hence neq_th': "thread \<noteq> th'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   581
      proof(cases)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   582
        assume "thread \<in> runing (t@s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   583
        moreover note not_runing
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   584
        ultimately show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   585
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   586
      with Cons and P have eq_cnt: "cntP ((e # t) @ s) th' = cntV ((e # t) @ s) th'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   587
        by (auto simp:cntP_def cntV_def count_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   588
      moreover from Cons and P have in_thread': "th' \<in> threads ((e # t) @ s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   589
        by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   590
      ultimately show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   591
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   592
      case (Create thread prio')
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   593
      from Cons and Create have "step (t@s) (Create thread prio')" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   594
      hence neq_th': "thread \<noteq> th'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   595
      proof(cases)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   596
        assume "thread \<notin> threads (t @ s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   597
        moreover have "th' \<in> threads (t@s)" by fact
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   598
        ultimately show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   599
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   600
      with Cons and Create 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   601
      have eq_cnt: "cntP ((e # t) @ s) th' = cntV ((e # t) @ s) th'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   602
        by (auto simp:cntP_def cntV_def count_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   603
      moreover from Cons and Create 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   604
      have in_thread': "th' \<in> threads ((e # t) @ s)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   605
      ultimately show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   606
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   607
      case (Exit thread)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   608
      from Cons and Exit have "step (t@s) (Exit thread)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   609
      hence neq_th': "thread \<noteq> th'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   610
      proof(cases)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   611
        assume "thread \<in> runing (t @ s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   612
        moreover note not_runing
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   613
        ultimately show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   614
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   615
      with Cons and Exit 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   616
      have eq_cnt: "cntP ((e # t) @ s) th' = cntV ((e # t) @ s) th'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   617
        by (auto simp:cntP_def cntV_def count_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   618
      moreover from Cons and Exit and neq_th' 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   619
      have in_thread': "th' \<in> threads ((e # t) @ s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   620
        by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   621
      ultimately show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   622
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   623
      case (Set thread prio')
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   624
      with Cons
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   625
      show ?thesis 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   626
        by (auto simp:cntP_def cntV_def count_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   627
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   628
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   629
    case Nil
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   630
    with assms
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   631
    show ?case by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   632
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   633
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   634
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   635
(*
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   636
lemma runing_precond:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   637
  fixes th'
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   638
  assumes th'_in: "th' \<in> threads s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   639
  and eq_pv: "cntP s th' = cntV s th'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   640
  and neq_th': "th' \<noteq> th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   641
  shows "th' \<notin> runing (t@s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   642
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   643
  from runing_precond_pre[OF th'_in eq_pv neq_th']
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   644
  have h1: "th' \<in> threads (t @ s)"  and h2: "cntP (t @ s) th' = cntV (t @ s) th'" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   645
  from pv_blocked[OF h1 neq_th' h2] 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   646
  show ?thesis .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   647
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   648
*)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   649
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   650
lemmas runing_precond_pre_dtc = runing_precond_pre[folded detached_eq[OF vt_t] detached_eq[OF vt_s]]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   651
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   652
lemma runing_precond:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   653
  fixes th'
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   654
  assumes th'_in: "th' \<in> threads s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   655
  and neq_th': "th' \<noteq> th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   656
  and is_runing: "th' \<in> runing (t@s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   657
  shows "cntP s th' > cntV s th'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   658
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   659
  have "cntP s th' \<noteq> cntV s th'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   660
  proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   661
    assume eq_pv: "cntP s th' = cntV s th'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   662
    from runing_precond_pre[OF th'_in eq_pv neq_th']
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   663
    have h1: "th' \<in> threads (t @ s)"  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   664
      and h2: "cntP (t @ s) th' = cntV (t @ s) th'" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   665
    from pv_blocked_pre[OF h1 neq_th' h2] have " th' \<notin> runing (t @ s)" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   666
    with is_runing show "False" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   667
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   668
  moreover from cnp_cnv_cncs[OF vt_s, of th'] 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   669
  have "cntV s th' \<le> cntP s th'" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   670
  ultimately show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   671
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   672
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   673
lemma moment_blocked_pre:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   674
  assumes neq_th': "th' \<noteq> th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   675
  and th'_in: "th' \<in> threads ((moment i t)@s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   676
  and eq_pv: "cntP ((moment i t)@s) th' = cntV ((moment i t)@s) th'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   677
  shows "cntP ((moment (i+j) t)@s) th' = cntV ((moment (i+j) t)@s) th' \<and>
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   678
         th' \<in> threads ((moment (i+j) t)@s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   679
proof(induct j)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   680
  case (Suc k)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   681
  show ?case
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   682
  proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   683
    { assume True: "Suc (i+k) \<le> length t"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   684
      from moment_head [OF this] 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   685
      obtain e where
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   686
        eq_me: "moment (Suc(i+k)) t = e#(moment (i+k) t)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   687
        by blast
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   688
      from red_moment[of "Suc(i+k)"]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   689
      and eq_me have "extend_highest_gen s th prio tm (e # moment (i + k) t)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   690
      hence vt_e: "vt (e#(moment (i + k) t)@s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   691
        by (unfold extend_highest_gen_def extend_highest_gen_axioms_def 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   692
                          highest_gen_def, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   693
      have not_runing': "th' \<notin>  runing (moment (i + k) t @ s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   694
      proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   695
        show "th' \<notin> runing (moment (i + k) t @ s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   696
        proof(rule extend_highest_gen.pv_blocked)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   697
          from Suc show "th' \<in> threads (moment (i + k) t @ s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   698
            by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   699
        next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   700
          from neq_th' show "th' \<noteq> th" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   701
        next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   702
          from red_moment show "extend_highest_gen s th prio tm (moment (i + k) t)" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   703
        next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   704
          from Suc vt_e show "detached (moment (i + k) t @ s) th'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   705
            apply(subst detached_eq)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   706
            apply(auto intro: vt_e evt_cons)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   707
            done
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   708
        qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   709
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   710
      from step_back_step[OF vt_e]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   711
      have "step ((moment (i + k) t)@s) e" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   712
      hence "cntP (e#(moment (i + k) t)@s) th' = cntV (e#(moment (i + k) t)@s) th' \<and>
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   713
        th' \<in> threads (e#(moment (i + k) t)@s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   714
      proof(cases)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   715
        case (thread_create thread prio)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   716
        with Suc show ?thesis by (auto simp:cntP_def cntV_def count_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   717
      next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   718
        case (thread_exit thread)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   719
        moreover have "thread \<noteq> th'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   720
        proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   721
          have "thread \<in> runing (moment (i + k) t @ s)" by fact
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   722
          moreover note not_runing'
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   723
          ultimately show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   724
        qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   725
        moreover note Suc 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   726
        ultimately show ?thesis by (auto simp:cntP_def cntV_def count_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   727
      next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   728
        case (thread_P thread cs)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   729
        moreover have "thread \<noteq> th'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   730
        proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   731
          have "thread \<in> runing (moment (i + k) t @ s)" by fact
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   732
          moreover note not_runing'
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   733
          ultimately show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   734
        qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   735
        moreover note Suc 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   736
        ultimately show ?thesis by (auto simp:cntP_def cntV_def count_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   737
      next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   738
        case (thread_V thread cs)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   739
        moreover have "thread \<noteq> th'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   740
        proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   741
          have "thread \<in> runing (moment (i + k) t @ s)" by fact
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   742
          moreover note not_runing'
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   743
          ultimately show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   744
        qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   745
        moreover note Suc 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   746
        ultimately show ?thesis by (auto simp:cntP_def cntV_def count_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   747
      next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   748
        case (thread_set thread prio')
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   749
        with Suc show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   750
          by (auto simp:cntP_def cntV_def count_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   751
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   752
      with eq_me have ?thesis using eq_me by auto 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   753
    } note h = this
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   754
    show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   755
    proof(cases "Suc (i+k) \<le> length t")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   756
      case True
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   757
      from h [OF this] show ?thesis .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   758
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   759
      case False
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   760
      with moment_ge
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   761
      have eq_m: "moment (i + Suc k) t = moment (i+k) t" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   762
      with Suc show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   763
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   764
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   765
next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   766
  case 0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   767
  from assms show ?case by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   768
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   769
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   770
lemma moment_blocked_eqpv:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   771
  assumes neq_th': "th' \<noteq> th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   772
  and th'_in: "th' \<in> threads ((moment i t)@s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   773
  and eq_pv: "cntP ((moment i t)@s) th' = cntV ((moment i t)@s) th'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   774
  and le_ij: "i \<le> j"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   775
  shows "cntP ((moment j t)@s) th' = cntV ((moment j t)@s) th' \<and>
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   776
         th' \<in> threads ((moment j t)@s) \<and>
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   777
         th' \<notin> runing ((moment j t)@s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   778
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   779
  from moment_blocked_pre [OF neq_th' th'_in eq_pv, of "j-i"] and le_ij
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   780
  have h1: "cntP ((moment j t)@s) th' = cntV ((moment j t)@s) th'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   781
    and h2: "th' \<in> threads ((moment j t)@s)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   782
  with extend_highest_gen.pv_blocked 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   783
  show ?thesis 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   784
    using  red_moment [of j] h2 neq_th' h1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   785
    apply(auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   786
    by (metis extend_highest_gen.pv_blocked_pre)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   787
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   788
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   789
lemma moment_blocked:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   790
  assumes neq_th': "th' \<noteq> th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   791
  and th'_in: "th' \<in> threads ((moment i t)@s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   792
  and dtc: "detached (moment i t @ s) th'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   793
  and le_ij: "i \<le> j"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   794
  shows "detached (moment j t @ s) th' \<and>
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   795
         th' \<in> threads ((moment j t)@s) \<and>
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   796
         th' \<notin> runing ((moment j t)@s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   797
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   798
  from vt_moment[OF vt_t, of "i+length s"] moment_prefix[of i t s]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   799
  have vt_i: "vt (moment i t @ s)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   800
  from vt_moment[OF vt_t, of "j+length s"] moment_prefix[of j t s]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   801
  have vt_j: "vt  (moment j t @ s)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   802
  from moment_blocked_eqpv [OF neq_th' th'_in detached_elim [OF vt_i dtc] le_ij, 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   803
  folded detached_eq[OF vt_j]]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   804
  show ?thesis .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   805
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   806
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   807
lemma runing_inversion_1:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   808
  assumes neq_th': "th' \<noteq> th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   809
  and runing': "th' \<in> runing (t@s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   810
  shows "th' \<in> threads s \<and> cntV s th' < cntP s th'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   811
proof(cases "th' \<in> threads s")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   812
  case True
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   813
  with runing_precond [OF this neq_th' runing'] show ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   814
next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   815
  case False
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   816
  let ?Q = "\<lambda> t. th' \<in> threads (t@s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   817
  let ?q = "moment 0 t"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   818
  from moment_eq and False have not_thread: "\<not> ?Q ?q" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   819
  from runing' have "th' \<in> threads (t@s)" by (simp add:runing_def readys_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   820
  from p_split_gen [of ?Q, OF this not_thread]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   821
  obtain i where lt_its: "i < length t"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   822
    and le_i: "0 \<le> i"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   823
    and pre: " th' \<notin> threads (moment i t @ s)" (is "th' \<notin> threads ?pre")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   824
    and post: "(\<forall>i'>i. th' \<in> threads (moment i' t @ s))" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   825
  from lt_its have "Suc i \<le> length t" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   826
  from moment_head[OF this] obtain e where 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   827
   eq_me: "moment (Suc i) t = e # moment i t" by blast
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   828
  from red_moment[of "Suc i"] and eq_me
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   829
  have "extend_highest_gen s th prio tm (e # moment i t)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   830
  hence vt_e: "vt (e#(moment i t)@s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   831
    by (unfold extend_highest_gen_def extend_highest_gen_axioms_def 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   832
      highest_gen_def, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   833
  from step_back_step[OF this] have stp_i: "step (moment i t @ s) e" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   834
  from post[rule_format, of "Suc i"] and eq_me 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   835
  have not_in': "th' \<in> threads (e # moment i t@s)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   836
  from create_pre[OF stp_i pre this] 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   837
  obtain prio where eq_e: "e = Create th' prio" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   838
  have "cntP (moment i t@s) th' = cntV (moment i t@s) th'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   839
  proof(rule cnp_cnv_eq)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   840
    from step_back_vt [OF vt_e] 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   841
    show "vt (moment i t @ s)" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   842
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   843
    from eq_e and stp_i 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   844
    have "step (moment i t @ s) (Create th' prio)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   845
    thus "th' \<notin> threads (moment i t @ s)" by (cases, simp)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   846
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   847
  with eq_e
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   848
  have "cntP ((e#moment i t)@s) th' = cntV ((e#moment i t)@s) th'" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   849
    by (simp add:cntP_def cntV_def count_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   850
  with eq_me[symmetric]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   851
  have h1: "cntP (moment (Suc i) t @ s) th' = cntV (moment (Suc i) t@ s) th'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   852
    by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   853
  from eq_e have "th' \<in> threads ((e#moment i t)@s)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   854
  with eq_me [symmetric]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   855
  have h2: "th' \<in> threads (moment (Suc i) t @ s)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   856
  from moment_blocked_eqpv [OF neq_th' h2 h1, of "length t"] and lt_its
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   857
  and moment_ge
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   858
  have "th' \<notin> runing (t @ s)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   859
  with runing'
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   860
  show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   861
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   862
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   863
lemma runing_inversion_2:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   864
  assumes runing': "th' \<in> runing (t@s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   865
  shows "th' = th \<or> (th' \<noteq> th \<and> th' \<in> threads s \<and> cntV s th' < cntP s th')"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   866
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   867
  from runing_inversion_1[OF _ runing']
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   868
  show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   869
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   870
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   871
lemma runing_preced_inversion:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   872
  assumes runing': "th' \<in> runing (t@s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   873
  shows "cp (t@s) th' = preced th s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   874
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   875
  from runing' have "cp (t@s) th' = Max (cp (t @ s) ` readys (t @ s))"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   876
    by (unfold runing_def, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   877
  also have "\<dots> = preced th s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   878
  proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   879
    from max_cp_readys_threads[OF vt_t]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   880
    have "\<dots> =  Max (cp (t @ s) ` threads (t @ s))" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   881
    also have "\<dots> = preced th s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   882
    proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   883
      from max_kept
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   884
      and max_cp_eq [OF vt_t]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   885
      show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   886
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   887
    finally show ?thesis .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   888
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   889
  finally show ?thesis .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   890
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   891
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   892
lemma runing_inversion_3:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   893
  assumes runing': "th' \<in> runing (t@s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   894
  and neq_th: "th' \<noteq> th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   895
  shows "th' \<in> threads s \<and> (cntV s th' < cntP s th' \<and> cp (t@s) th' = preced th s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   896
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   897
  from runing_inversion_2 [OF runing'] 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   898
    and neq_th 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   899
    and runing_preced_inversion[OF runing']
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   900
  show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   901
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   902
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   903
lemma runing_inversion_4:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   904
  assumes runing': "th' \<in> runing (t@s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   905
  and neq_th: "th' \<noteq> th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   906
  shows "th' \<in> threads s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   907
  and    "\<not>detached s th'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   908
  and    "cp (t@s) th' = preced th s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   909
using runing_inversion_3 [OF runing'] 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   910
  and neq_th 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   911
  and runing_preced_inversion[OF runing']
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   912
apply(auto simp add: detached_eq[OF vt_s])
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   913
done
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   914
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   915
lemma live: "runing (t@s) \<noteq> {}"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   916
proof(cases "th \<in> runing (t@s)")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   917
  case True thus ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   918
next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   919
  case False
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   920
  then have not_ready: "th \<notin> readys (t@s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   921
    apply (unfold runing_def, 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   922
            insert th_cp_max max_cp_readys_threads[OF vt_t, symmetric])
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   923
    by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   924
  from th_kept have "th \<in> threads (t@s)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   925
  from th_chain_to_ready[OF vt_t this] and not_ready
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   926
  obtain th' where th'_in: "th' \<in> readys (t@s)"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   927
    and dp: "(Th th, Th th') \<in> (RAG (t @ s))\<^sup>+" by auto
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   928
  have "th' \<in> runing (t@s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   929
  proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   930
    have "cp (t @ s) th' = Max (cp (t @ s) ` readys (t @ s))"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   931
    proof -
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 0
diff changeset
   932
      have " Max ((\<lambda>th. preced th (t @ s)) ` ({th'} \<union> dependants (wq (t @ s)) th')) = 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   933
               preced th (t@s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   934
      proof(rule Max_eqI)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   935
        fix y
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 0
diff changeset
   936
        assume "y \<in> (\<lambda>th. preced th (t @ s)) ` ({th'} \<union> dependants (wq (t @ s)) th')"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   937
        then obtain th1 where
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 0
diff changeset
   938
          h1: "th1 = th' \<or> th1 \<in>  dependants (wq (t @ s)) th'"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   939
          and eq_y: "y = preced th1 (t@s)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   940
        show "y \<le> preced th (t @ s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   941
        proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   942
          from max_preced
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   943
          have "preced th (t @ s) = Max ((\<lambda>th'. preced th' (t @ s)) ` threads (t @ s))" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   944
          moreover have "y \<le> \<dots>"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   945
          proof(rule Max_ge)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   946
            from h1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   947
            have "th1 \<in> threads (t@s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   948
            proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   949
              assume "th1 = th'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   950
              with th'_in show ?thesis by (simp add:readys_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   951
            next
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 0
diff changeset
   952
              assume "th1 \<in> dependants (wq (t @ s)) th'"
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 0
diff changeset
   953
              with dependants_threads [OF vt_t]
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   954
              show "th1 \<in> threads (t @ s)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   955
            qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   956
            with eq_y show " y \<in> (\<lambda>th'. preced th' (t @ s)) ` threads (t @ s)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   957
          next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   958
            from finite_threads[OF vt_t]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   959
            show "finite ((\<lambda>th'. preced th' (t @ s)) ` threads (t @ s))" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   960
          qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   961
          ultimately show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   962
        qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   963
      next
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 0
diff changeset
   964
        from finite_threads[OF vt_t] dependants_threads [OF vt_t, of th']
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 0
diff changeset
   965
        show "finite ((\<lambda>th. preced th (t @ s)) ` ({th'} \<union> dependants (wq (t @ s)) th'))"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   966
          by (auto intro:finite_subset)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   967
      next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   968
        from dp
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 0
diff changeset
   969
        have "th \<in> dependants (wq (t @ s)) th'" 
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   970
          by (unfold cs_dependants_def, auto simp:eq_RAG)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   971
        thus "preced th (t @ s) \<in> 
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 0
diff changeset
   972
                (\<lambda>th. preced th (t @ s)) ` ({th'} \<union> dependants (wq (t @ s)) th')"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   973
          by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   974
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   975
      moreover have "\<dots> = Max (cp (t @ s) ` readys (t @ s))"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   976
      proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   977
        from max_preced and max_cp_eq[OF vt_t, symmetric]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   978
        have "preced th (t @ s) = Max (cp (t @ s) ` threads (t @ s))" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   979
        with max_cp_readys_threads[OF vt_t] show ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   980
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   981
      ultimately show ?thesis by (unfold cp_eq_cpreced cpreced_def, simp)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   982
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   983
    with th'_in show ?thesis by (auto simp:runing_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   984
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   985
  thus ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   986
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   987
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   988
end
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   989
end
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   990
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   991
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   992