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