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