PrioG.thy
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Fri, 30 May 2014 07:56:39 +0100
changeset 38 c89013dca1aa
parent 36 af38526275f8
child 39 7ea6b019ce24
permissions -rw-r--r--
finished proof of acyclity
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
theory PrioG
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
imports PrioGDef 
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
lemma runing_ready: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
  shows "runing s \<subseteq> readys s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
  unfolding runing_def readys_def
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     8
  by auto 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     9
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    10
lemma readys_threads:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
  shows "readys s \<subseteq> threads s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    12
  unfolding readys_def
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    13
  by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    14
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
lemma wq_v_neq:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    16
   "cs \<noteq> cs' \<Longrightarrow> wq (V thread cs#s) cs' = wq s cs'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    17
  by (auto simp:wq_def Let_def cp_def split:list.splits)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    18
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    19
lemma wq_distinct: "vt s \<Longrightarrow> distinct (wq s cs)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    20
proof(erule_tac vt.induct, simp add:wq_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    21
  fix s e
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    22
  assume h1: "step s e"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    23
  and h2: "distinct (wq s cs)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    24
  thus "distinct (wq (e # s) cs)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
  proof(induct rule:step.induct, auto simp: wq_def Let_def split:list.splits)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
    fix thread s
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
    27
    assume h1: "(Cs cs, Th thread) \<notin> (RAG s)\<^sup>+"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
      and h2: "thread \<in> set (wq_fun (schs s) cs)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    29
      and h3: "thread \<in> runing s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    30
    show "False" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    31
    proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    32
      from h3 have "\<And> cs. thread \<in>  set (wq_fun (schs s) cs) \<Longrightarrow> 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
                             thread = hd ((wq_fun (schs s) cs))" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
        by (simp add:runing_def readys_def s_waiting_def wq_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    35
      from this [OF h2] have "thread = hd (wq_fun (schs s) cs)" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
      with h2
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
    37
      have "(Cs cs, Th thread) \<in> (RAG s)"
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
    38
        by (simp add:s_RAG_def s_holding_def wq_def cs_holding_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    39
      with h1 show False by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    40
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    41
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    42
    fix thread s a list
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    43
    assume dst: "distinct list"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    44
    show "distinct (SOME q. distinct q \<and> set q = set list)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
    proof(rule someI2)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    46
      from dst show  "distinct list \<and> set list = set list" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    47
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    48
      fix q assume "distinct q \<and> set q = set list"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    49
      thus "distinct q" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    50
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    51
  qed
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
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    54
lemma step_back_vt: "vt (e#s) \<Longrightarrow> vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    55
  by(ind_cases "vt (e#s)", simp)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    56
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    57
lemma step_back_step: "vt (e#s) \<Longrightarrow> step s e"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    58
  by(ind_cases "vt (e#s)", simp)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    59
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    60
lemma block_pre: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    61
  fixes thread cs s
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    62
  assumes vt_e: "vt (e#s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    63
  and s_ni: "thread \<notin>  set (wq s cs)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    64
  and s_i: "thread \<in> set (wq (e#s) cs)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    65
  shows "e = P thread cs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    66
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    67
  show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    68
  proof(cases e)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    69
    case (P th cs)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    70
    with assms
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    71
    show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    72
      by (auto simp:wq_def Let_def split:if_splits)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    73
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    74
    case (Create th prio)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    75
    with assms show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    76
      by (auto simp:wq_def Let_def split:if_splits)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    77
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    78
    case (Exit th)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    79
    with assms show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    80
      by (auto simp:wq_def Let_def split:if_splits)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    81
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    82
    case (Set th prio)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    83
    with assms show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    84
      by (auto simp:wq_def Let_def split:if_splits)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    85
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    86
    case (V th cs)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    87
    with assms show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    88
      apply (auto simp:wq_def Let_def split:if_splits)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    89
    proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    90
      fix q qs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    91
      assume h1: "thread \<notin> set (wq_fun (schs s) cs)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    92
        and h2: "q # qs = wq_fun (schs s) cs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    93
        and h3: "thread \<in> set (SOME q. distinct q \<and> set q = set qs)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    94
        and vt: "vt (V th cs # s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    95
      from h1 and h2[symmetric] have "thread \<notin> set (q # qs)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    96
      moreover have "thread \<in> set qs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    97
      proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    98
        have "set (SOME q. distinct q \<and> set q = set qs) = set qs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    99
        proof(rule someI2)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   100
          from wq_distinct [OF step_back_vt[OF vt], of cs]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   101
          and h2[symmetric, folded wq_def]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   102
          show "distinct qs \<and> set qs = set qs" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   103
        next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   104
          fix x assume "distinct x \<and> set x = set qs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   105
          thus "set x = set qs" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   106
        qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   107
        with h3 show ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   108
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   109
      ultimately show "False" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   110
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   111
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   112
qed
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 p_pre: "\<lbrakk>vt ((P thread cs)#s)\<rbrakk> \<Longrightarrow> 
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   115
  thread \<in> runing s \<and> (Cs cs, Th thread)  \<notin> (RAG s)^+"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   116
apply (ind_cases "vt ((P thread cs)#s)")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   117
apply (ind_cases "step s (P thread cs)")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   118
by auto
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 abs1:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   121
  fixes e es
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   122
  assumes ein: "e \<in> set es"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   123
  and neq: "hd es \<noteq> hd (es @ [x])"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   124
  shows "False"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   125
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   126
  from ein have "es \<noteq> []" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   127
  then obtain e ess where "es = e # ess" by (cases es, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   128
  with neq show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   129
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   130
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   131
lemma q_head: "Q (hd es) \<Longrightarrow> hd es = hd [th\<leftarrow>es . Q th]"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   132
  by (cases es, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   133
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   134
inductive_cases evt_cons: "vt (a#s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   135
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   136
lemma abs2:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   137
  assumes vt: "vt (e#s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   138
  and inq: "thread \<in> set (wq s cs)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   139
  and nh: "thread = hd (wq s cs)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   140
  and qt: "thread \<noteq> hd (wq (e#s) cs)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   141
  and inq': "thread \<in> set (wq (e#s) cs)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   142
  shows "False"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   143
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   144
  from assms show "False"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   145
    apply (cases e)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   146
    apply ((simp split:if_splits add:Let_def wq_def)[1])+
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   147
    apply (insert abs1, fast)[1]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   148
    apply (auto simp:wq_def simp:Let_def split:if_splits list.splits)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   149
  proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   150
    fix th qs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   151
    assume vt: "vt (V th cs # s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   152
      and th_in: "thread \<in> set (SOME q. distinct q \<and> set q = set qs)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   153
      and eq_wq: "wq_fun (schs s) cs = thread # qs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   154
    show "False"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   155
    proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   156
      from wq_distinct[OF step_back_vt[OF vt], of cs]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   157
        and eq_wq[folded wq_def] have "distinct (thread#qs)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   158
      moreover have "thread \<in> set qs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   159
      proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   160
        have "set (SOME q. distinct q \<and> set q = set qs) = set qs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   161
        proof(rule someI2)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   162
          from wq_distinct [OF step_back_vt[OF vt], of cs]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   163
          and eq_wq [folded wq_def]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   164
          show "distinct qs \<and> set qs = set qs" 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
          fix x assume "distinct x \<and> set x = set qs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   167
          thus "set x = set qs" 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
        with th_in show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   170
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   171
      ultimately show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   172
    qed
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
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   175
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   176
lemma vt_moment: "\<And> t. \<lbrakk>vt s\<rbrakk> \<Longrightarrow> vt (moment t s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   177
proof(induct s, simp)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   178
  fix a s t
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   179
  assume h: "\<And>t.\<lbrakk>vt s\<rbrakk> \<Longrightarrow> vt (moment t s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   180
    and vt_a: "vt (a # s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   181
  show "vt (moment t (a # s))"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   182
  proof(cases "t \<ge> length (a#s)")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   183
    case True
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   184
    from True have "moment t (a#s) = a#s" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   185
    with vt_a show ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   186
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   187
    case False
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   188
    hence le_t1: "t \<le> length s" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   189
    from vt_a have "vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   190
      by (erule_tac evt_cons, simp)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   191
    from h [OF this] have "vt (moment t s)" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   192
    moreover have "moment t (a#s) = moment t s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   193
    proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   194
      from moment_app [OF le_t1, of "[a]"] 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   195
      show ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   196
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   197
    ultimately show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   198
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   199
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   200
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   201
(* Wrong:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   202
    lemma \<lbrakk>thread \<in> set (wq_fun cs1 s); thread \<in> set (wq_fun cs2 s)\<rbrakk> \<Longrightarrow> cs1 = cs2"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   203
*)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   204
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   205
lemma waiting_unique_pre:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   206
  fixes cs1 cs2 s thread
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   207
  assumes vt: "vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   208
  and h11: "thread \<in> set (wq s cs1)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   209
  and h12: "thread \<noteq> hd (wq s cs1)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   210
  assumes h21: "thread \<in> set (wq s cs2)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   211
  and h22: "thread \<noteq> hd (wq s cs2)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   212
  and neq12: "cs1 \<noteq> cs2"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   213
  shows "False"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   214
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   215
  let "?Q cs s" = "thread \<in> set (wq s cs) \<and> thread \<noteq> hd (wq s cs)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   216
  from h11 and h12 have q1: "?Q cs1 s" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   217
  from h21 and h22 have q2: "?Q cs2 s" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   218
  have nq1: "\<not> ?Q cs1 []" by (simp add:wq_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   219
  have nq2: "\<not> ?Q cs2 []" by (simp add:wq_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   220
  from p_split [of "?Q cs1", OF q1 nq1]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   221
  obtain t1 where lt1: "t1 < length s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   222
    and np1: "\<not>(thread \<in> set (wq (moment t1 s) cs1) \<and>
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   223
        thread \<noteq> hd (wq (moment t1 s) cs1))"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   224
    and nn1: "(\<forall>i'>t1. thread \<in> set (wq (moment i' s) cs1) \<and>
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   225
             thread \<noteq> hd (wq (moment i' s) cs1))" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   226
  from p_split [of "?Q cs2", OF q2 nq2]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   227
  obtain t2 where lt2: "t2 < length s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   228
    and np2: "\<not>(thread \<in> set (wq (moment t2 s) cs2) \<and>
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   229
        thread \<noteq> hd (wq (moment t2 s) cs2))"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   230
    and nn2: "(\<forall>i'>t2. thread \<in> set (wq (moment i' s) cs2) \<and>
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   231
             thread \<noteq> hd (wq (moment i' s) cs2))" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   232
  show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   233
  proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   234
    { 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   235
      assume lt12: "t1 < t2"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   236
      let ?t3 = "Suc t2"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   237
      from lt2 have le_t3: "?t3 \<le> length s" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   238
      from moment_plus [OF this] 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   239
      obtain e where eq_m: "moment ?t3 s = e#moment t2 s" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   240
      have "t2 < ?t3" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   241
      from nn2 [rule_format, OF this] and eq_m
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   242
      have h1: "thread \<in> set (wq (e#moment t2 s) cs2)" and
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   243
        h2: "thread \<noteq> hd (wq (e#moment t2 s) cs2)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   244
      have vt_e: "vt (e#moment t2 s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   245
      proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   246
        from vt_moment [OF vt]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   247
        have "vt (moment ?t3 s)" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   248
        with eq_m show ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   249
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   250
      have ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   251
      proof(cases "thread \<in> set (wq (moment t2 s) cs2)")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   252
        case True
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   253
        from True and np2 have eq_th: "thread = hd (wq (moment t2 s) cs2)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   254
          by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   255
        from abs2 [OF vt_e True eq_th h2 h1]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   256
        show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   257
      next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   258
        case False
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   259
        from block_pre [OF vt_e False h1]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   260
        have "e = P thread cs2" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   261
        with vt_e have "vt ((P thread cs2)# moment t2 s)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   262
        from p_pre [OF this] have "thread \<in> runing (moment t2 s)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   263
        with runing_ready have "thread \<in> readys (moment t2 s)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   264
        with nn1 [rule_format, OF lt12]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   265
        show ?thesis  by (simp add:readys_def wq_def s_waiting_def, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   266
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   267
    } moreover {
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   268
      assume lt12: "t2 < t1"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   269
      let ?t3 = "Suc t1"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   270
      from lt1 have le_t3: "?t3 \<le> length s" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   271
      from moment_plus [OF this] 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   272
      obtain e where eq_m: "moment ?t3 s = e#moment t1 s" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   273
      have lt_t3: "t1 < ?t3" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   274
      from nn1 [rule_format, OF this] and eq_m
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   275
      have h1: "thread \<in> set (wq (e#moment t1 s) cs1)" and
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   276
        h2: "thread \<noteq> hd (wq (e#moment t1 s) cs1)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   277
      have vt_e: "vt  (e#moment t1 s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   278
      proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   279
        from vt_moment [OF vt]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   280
        have "vt (moment ?t3 s)" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   281
        with eq_m show ?thesis by simp
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
      have ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   284
      proof(cases "thread \<in> set (wq (moment t1 s) cs1)")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   285
        case True
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   286
        from True and np1 have eq_th: "thread = hd (wq (moment t1 s) cs1)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   287
          by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   288
        from abs2 [OF vt_e True eq_th h2 h1]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   289
        show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   290
      next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   291
        case False
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   292
        from block_pre [OF vt_e False h1]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   293
        have "e = P thread cs1" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   294
        with vt_e have "vt ((P thread cs1)# moment t1 s)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   295
        from p_pre [OF this] have "thread \<in> runing (moment t1 s)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   296
        with runing_ready have "thread \<in> readys (moment t1 s)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   297
        with nn2 [rule_format, OF lt12]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   298
        show ?thesis  by (simp add:readys_def wq_def s_waiting_def, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   299
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   300
    } moreover {
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   301
      assume eqt12: "t1 = t2"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   302
      let ?t3 = "Suc t1"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   303
      from lt1 have le_t3: "?t3 \<le> length s" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   304
      from moment_plus [OF this] 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   305
      obtain e where eq_m: "moment ?t3 s = e#moment t1 s" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   306
      have lt_t3: "t1 < ?t3" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   307
      from nn1 [rule_format, OF this] and eq_m
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   308
      have h1: "thread \<in> set (wq (e#moment t1 s) cs1)" and
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   309
        h2: "thread \<noteq> hd (wq (e#moment t1 s) cs1)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   310
      have vt_e: "vt (e#moment t1 s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   311
      proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   312
        from vt_moment [OF vt]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   313
        have "vt (moment ?t3 s)" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   314
        with eq_m show ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   315
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   316
      have ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   317
      proof(cases "thread \<in> set (wq (moment t1 s) cs1)")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   318
        case True
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   319
        from True and np1 have eq_th: "thread = hd (wq (moment t1 s) cs1)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   320
          by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   321
        from abs2 [OF vt_e True eq_th h2 h1]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   322
        show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   323
      next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   324
        case False
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   325
        from block_pre [OF vt_e False h1]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   326
        have eq_e1: "e = P thread cs1" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   327
        have lt_t3: "t1 < ?t3" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   328
        with eqt12 have "t2 < ?t3" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   329
        from nn2 [rule_format, OF this] and eq_m and eqt12
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   330
        have h1: "thread \<in> set (wq (e#moment t2 s) cs2)" and
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   331
          h2: "thread \<noteq> hd (wq (e#moment t2 s) cs2)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   332
        show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   333
        proof(cases "thread \<in> set (wq (moment t2 s) cs2)")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   334
          case True
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   335
          from True and np2 have eq_th: "thread = hd (wq (moment t2 s) cs2)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   336
            by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   337
          from vt_e and eqt12 have "vt (e#moment t2 s)" by simp 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   338
          from abs2 [OF this True eq_th h2 h1]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   339
          show ?thesis .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   340
        next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   341
          case False
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   342
          have vt_e: "vt (e#moment t2 s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   343
          proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   344
            from vt_moment [OF vt] eqt12
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   345
            have "vt (moment (Suc t2) s)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   346
            with eq_m eqt12 show ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   347
          qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   348
          from block_pre [OF vt_e False h1]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   349
          have "e = P thread cs2" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   350
          with eq_e1 neq12 show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   351
        qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   352
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   353
    } ultimately show ?thesis by arith
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   354
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   355
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   356
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   357
lemma waiting_unique:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   358
  fixes s cs1 cs2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   359
  assumes "vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   360
  and "waiting s th cs1"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   361
  and "waiting s th cs2"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   362
  shows "cs1 = cs2"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   363
using waiting_unique_pre assms
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   364
unfolding wq_def s_waiting_def
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   365
by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   366
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   367
(* not used *)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   368
lemma held_unique:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   369
  fixes s::"state"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   370
  assumes "holding s th1 cs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   371
  and "holding s th2 cs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   372
  shows "th1 = th2"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   373
using assms
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   374
unfolding s_holding_def
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   375
by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   376
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   377
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
   378
lemma last_set_lt: "th \<in> threads s \<Longrightarrow> last_set th s < length s"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   379
  apply (induct s, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   380
  by (case_tac a, auto split:if_splits)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   381
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
   382
lemma last_set_unique: 
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
   383
  "\<lbrakk>last_set th1 s = last_set th2 s; th1 \<in> threads s; th2 \<in> threads s\<rbrakk>
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   384
          \<Longrightarrow> th1 = th2"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   385
  apply (induct s, auto)
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
   386
  by (case_tac a, auto split:if_splits dest:last_set_lt)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   387
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   388
lemma preced_unique : 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   389
  assumes pcd_eq: "preced th1 s = preced th2 s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   390
  and th_in1: "th1 \<in> threads s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   391
  and th_in2: " th2 \<in> threads s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   392
  shows "th1 = th2"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   393
proof -
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
   394
  from pcd_eq have "last_set th1 s = last_set th2 s" by (simp add:preced_def)
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
   395
  from last_set_unique [OF this th_in1 th_in2]
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   396
  show ?thesis .
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
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   399
lemma preced_linorder: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   400
  assumes neq_12: "th1 \<noteq> th2"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   401
  and th_in1: "th1 \<in> threads s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   402
  and th_in2: " th2 \<in> threads s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   403
  shows "preced th1 s < preced th2 s \<or> preced th1 s > preced th2 s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   404
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   405
  from preced_unique [OF _ th_in1 th_in2] and neq_12 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   406
  have "preced th1 s \<noteq> preced th2 s" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   407
  thus ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   408
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   409
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   410
lemma unique_minus:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   411
  fixes x y z r
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   412
  assumes unique: "\<And> a b c. \<lbrakk>(a, b) \<in> r; (a, c) \<in> r\<rbrakk> \<Longrightarrow> b = c"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   413
  and xy: "(x, y) \<in> r"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   414
  and xz: "(x, z) \<in> r^+"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   415
  and neq: "y \<noteq> z"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   416
  shows "(y, z) \<in> r^+"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   417
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   418
 from xz and neq show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   419
 proof(induct)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   420
   case (base ya)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   421
   have "(x, ya) \<in> r" by fact
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   422
   from unique [OF xy this] have "y = ya" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   423
   with base show ?case by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   424
 next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   425
   case (step ya z)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   426
   show ?case
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   427
   proof(cases "y = ya")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   428
     case True
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   429
     from step True show ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   430
   next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   431
     case False
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   432
     from step False
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   433
     show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   434
   qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   435
 qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   436
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   437
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   438
lemma unique_base:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   439
  fixes r x y z
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   440
  assumes unique: "\<And> a b c. \<lbrakk>(a, b) \<in> r; (a, c) \<in> r\<rbrakk> \<Longrightarrow> b = c"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   441
  and xy: "(x, y) \<in> r"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   442
  and xz: "(x, z) \<in> r^+"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   443
  and neq_yz: "y \<noteq> z"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   444
  shows "(y, z) \<in> r^+"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   445
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   446
  from xz neq_yz show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   447
  proof(induct)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   448
    case (base ya)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   449
    from xy unique base show ?case by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   450
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   451
    case (step ya z)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   452
    show ?case
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   453
    proof(cases "y = ya")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   454
      case True
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   455
      from True step show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   456
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   457
      case False
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   458
      from False step 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   459
      have "(y, ya) \<in> r\<^sup>+" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   460
      with step show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   461
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   462
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   463
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   464
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   465
lemma unique_chain:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   466
  fixes r x y z
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   467
  assumes unique: "\<And> a b c. \<lbrakk>(a, b) \<in> r; (a, c) \<in> r\<rbrakk> \<Longrightarrow> b = c"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   468
  and xy: "(x, y) \<in> r^+"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   469
  and xz: "(x, z) \<in> r^+"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   470
  and neq_yz: "y \<noteq> z"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   471
  shows "(y, z) \<in> r^+ \<or> (z, y) \<in> r^+"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   472
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   473
  from xy xz neq_yz show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   474
  proof(induct)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   475
    case (base y)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   476
    have h1: "(x, y) \<in> r" and h2: "(x, z) \<in> r\<^sup>+" and h3: "y \<noteq> z" using base by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   477
    from unique_base [OF _ h1 h2 h3] and unique show ?case by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   478
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   479
    case (step y za)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   480
    show ?case
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   481
    proof(cases "y = z")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   482
      case True
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   483
      from True step show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   484
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   485
      case False
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   486
      from False step have "(y, z) \<in> r\<^sup>+ \<or> (z, y) \<in> r\<^sup>+" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   487
      thus ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   488
      proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   489
        assume "(z, y) \<in> r\<^sup>+"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   490
        with step have "(z, za) \<in> r\<^sup>+" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   491
        thus ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   492
      next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   493
        assume h: "(y, z) \<in> r\<^sup>+"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   494
        from step have yza: "(y, za) \<in> r" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   495
        from step have "za \<noteq> z" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   496
        from unique_minus [OF _ yza h this] and unique
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   497
        have "(za, z) \<in> r\<^sup>+" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   498
        thus ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   499
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   500
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   501
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   502
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   503
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   504
lemma RAG_set_unchanged: "(RAG (Set th prio # s)) = RAG s"
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   505
apply (unfold s_RAG_def s_waiting_def wq_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   506
by (simp add:Let_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   507
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   508
lemma RAG_create_unchanged: "(RAG (Create th prio # s)) = RAG s"
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   509
apply (unfold s_RAG_def s_waiting_def wq_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   510
by (simp add:Let_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   511
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   512
lemma RAG_exit_unchanged: "(RAG (Exit th # s)) = RAG s"
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   513
apply (unfold s_RAG_def s_waiting_def wq_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   514
by (simp add:Let_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   515
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   516
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   517
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   518
lemma step_v_hold_inv[elim_format]:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   519
  "\<And>c t. \<lbrakk>vt (V th cs # s); 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   520
  \<not> holding (wq s) t c; holding (wq (V th cs # s)) t c\<rbrakk> \<Longrightarrow> next_th s th cs t \<and> c = cs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   521
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   522
  fix c t
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   523
  assume vt: "vt (V th cs # s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   524
    and nhd: "\<not> holding (wq s) t c"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   525
    and hd: "holding (wq (V th cs # s)) t c"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   526
  show "next_th s th cs t \<and> c = cs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   527
  proof(cases "c = cs")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   528
    case False
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   529
    with nhd hd show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   530
      by (unfold cs_holding_def wq_def, auto simp:Let_def)
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
    case True
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   533
    with step_back_step [OF vt] 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   534
    have "step s (V th c)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   535
    hence "next_th s th cs t"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   536
    proof(cases)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   537
      assume "holding s th c"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   538
      with nhd hd show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   539
        apply (unfold s_holding_def cs_holding_def wq_def next_th_def,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   540
               auto simp:Let_def split:list.splits if_splits)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   541
        proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   542
          assume " hd (SOME q. distinct q \<and> q = []) \<in> set (SOME q. distinct q \<and> q = [])"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   543
          moreover have "\<dots> = set []"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   544
          proof(rule someI2)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   545
            show "distinct [] \<and> [] = []" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   546
          next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   547
            fix x assume "distinct x \<and> x = []"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   548
            thus "set x = set []" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   549
          qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   550
          ultimately show False by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   551
        next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   552
          assume " hd (SOME q. distinct q \<and> q = []) \<in> set (SOME q. distinct q \<and> q = [])"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   553
          moreover have "\<dots> = set []"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   554
          proof(rule someI2)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   555
            show "distinct [] \<and> [] = []" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   556
          next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   557
            fix x assume "distinct x \<and> x = []"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   558
            thus "set x = set []" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   559
          qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   560
          ultimately show False by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   561
        qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   562
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   563
    with True show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   564
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   565
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   566
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   567
lemma step_v_wait_inv[elim_format]:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   568
    "\<And>t c. \<lbrakk>vt (V th cs # s); \<not> waiting (wq (V th cs # s)) t c; waiting (wq s) t c
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   569
           \<rbrakk>
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   570
          \<Longrightarrow> (next_th s th cs t \<and> cs = c)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   571
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   572
  fix t c 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   573
  assume vt: "vt (V th cs # s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   574
    and nw: "\<not> waiting (wq (V th cs # s)) t c"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   575
    and wt: "waiting (wq s) t c"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   576
  show "next_th s th cs t \<and> cs = c"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   577
  proof(cases "cs = c")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   578
    case False
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   579
    with nw wt show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   580
      by (auto simp:cs_waiting_def wq_def Let_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   581
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   582
    case True
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   583
    from nw[folded True] wt[folded True]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   584
    have "next_th s th cs t"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   585
      apply (unfold next_th_def, auto simp:cs_waiting_def wq_def Let_def split:list.splits)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   586
    proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   587
      fix a list
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   588
      assume t_in: "t \<in> set list"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   589
        and t_ni: "t \<notin> set (SOME q. distinct q \<and> set q = set list)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   590
        and eq_wq: "wq_fun (schs s) cs = a # list"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   591
      have " set (SOME q. distinct q \<and> set q = set list) = set list"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   592
      proof(rule someI2)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   593
        from wq_distinct[OF step_back_vt[OF vt], of cs] and eq_wq[folded wq_def]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   594
        show "distinct list \<and> set list = set list" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   595
      next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   596
        show "\<And>x. distinct x \<and> set x = set list \<Longrightarrow> set x = set list"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   597
          by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   598
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   599
      with t_ni and t_in show "a = th" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   600
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   601
      fix a list
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   602
      assume t_in: "t \<in> set list"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   603
        and t_ni: "t \<notin> set (SOME q. distinct q \<and> set q = set list)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   604
        and eq_wq: "wq_fun (schs s) cs = a # list"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   605
      have " set (SOME q. distinct q \<and> set q = set list) = set list"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   606
      proof(rule someI2)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   607
        from wq_distinct[OF step_back_vt[OF vt], of cs] and eq_wq[folded wq_def]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   608
        show "distinct list \<and> set list = set list" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   609
      next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   610
        show "\<And>x. distinct x \<and> set x = set list \<Longrightarrow> set x = set list"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   611
          by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   612
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   613
      with t_ni and t_in show "t = hd (SOME q. distinct q \<and> set q = set list)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   614
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   615
      fix a list
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   616
      assume eq_wq: "wq_fun (schs s) cs = a # list"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   617
      from step_back_step[OF vt]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   618
      show "a = th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   619
      proof(cases)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   620
        assume "holding s th cs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   621
        with eq_wq show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   622
          by (unfold s_holding_def wq_def, auto)
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
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   625
    with True show ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   626
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   627
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   628
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   629
lemma step_v_not_wait[consumes 3]:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   630
  "\<lbrakk>vt (V th cs # s); next_th s th cs t; waiting (wq (V th cs # s)) t cs\<rbrakk> \<Longrightarrow> False"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   631
  by (unfold next_th_def cs_waiting_def wq_def, auto simp:Let_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   632
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   633
lemma step_v_release:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   634
  "\<lbrakk>vt (V th cs # s); holding (wq (V th cs # s)) th cs\<rbrakk> \<Longrightarrow> False"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   635
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   636
  assume vt: "vt (V th cs # s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   637
    and hd: "holding (wq (V th cs # s)) th cs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   638
  from step_back_step [OF vt] and hd
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   639
  show "False"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   640
  proof(cases)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   641
    assume "holding (wq (V th cs # s)) th cs" and "holding s th cs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   642
    thus ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   643
      apply (unfold s_holding_def wq_def cs_holding_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   644
      apply (auto simp:Let_def split:list.splits)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   645
    proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   646
      fix list
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   647
      assume eq_wq[folded wq_def]: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   648
        "wq_fun (schs s) cs = hd (SOME q. distinct q \<and> set q = set list) # list"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   649
      and hd_in: "hd (SOME q. distinct q \<and> set q = set list)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   650
            \<in> set (SOME q. distinct q \<and> set q = set list)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   651
      have "set (SOME q. distinct q \<and> set q = set list) = set list"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   652
      proof(rule someI2)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   653
        from wq_distinct[OF step_back_vt[OF vt], of cs] and eq_wq
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   654
        show "distinct list \<and> set list = set list" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   655
      next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   656
        show "\<And>x. distinct x \<and> set x = set list \<Longrightarrow> set x = set list"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   657
          by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   658
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   659
      moreover have "distinct  (hd (SOME q. distinct q \<and> set q = set list) # list)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   660
      proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   661
        from wq_distinct[OF step_back_vt[OF vt], of cs] and eq_wq
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   662
        show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   663
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   664
      moreover note eq_wq and hd_in
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   665
      ultimately show "False" by auto
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
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   668
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   669
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   670
lemma step_v_get_hold:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   671
  "\<And>th'. \<lbrakk>vt (V th cs # s); \<not> holding (wq (V th cs # s)) th' cs; next_th s th cs th'\<rbrakk> \<Longrightarrow> False"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   672
  apply (unfold cs_holding_def next_th_def wq_def,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   673
         auto simp:Let_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   674
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   675
  fix rest
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   676
  assume vt: "vt (V th cs # s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   677
    and eq_wq[folded wq_def]: " wq_fun (schs s) cs = th # rest"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   678
    and nrest: "rest \<noteq> []"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   679
    and ni: "hd (SOME q. distinct q \<and> set q = set rest)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   680
            \<notin> set (SOME q. distinct q \<and> set q = set rest)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   681
  have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   682
  proof(rule someI2)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   683
    from wq_distinct[OF step_back_vt[OF vt], of cs] and eq_wq
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   684
    show "distinct rest \<and> set rest = set rest" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   685
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   686
    fix x assume "distinct x \<and> set x = set rest"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   687
    hence "set x = set rest" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   688
    with nrest
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   689
    show "x \<noteq> []" by (case_tac x, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   690
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   691
  with ni show "False" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   692
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   693
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   694
lemma step_v_release_inv[elim_format]:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   695
"\<And>c t. \<lbrakk>vt (V th cs # s); \<not> holding (wq (V th cs # s)) t c; holding (wq s) t c\<rbrakk> \<Longrightarrow> 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   696
  c = cs \<and> t = th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   697
  apply (unfold cs_holding_def wq_def, auto simp:Let_def split:if_splits list.splits)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   698
  proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   699
    fix a list
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   700
    assume vt: "vt (V th cs # s)" and eq_wq: "wq_fun (schs s) cs = a # list"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   701
    from step_back_step [OF vt] show "a = th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   702
    proof(cases)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   703
      assume "holding s th cs" with eq_wq
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   704
      show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   705
        by (unfold s_holding_def wq_def, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   706
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   707
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   708
    fix a list
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   709
    assume vt: "vt (V th cs # s)" and eq_wq: "wq_fun (schs s) cs = a # list"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   710
    from step_back_step [OF vt] show "a = th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   711
    proof(cases)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   712
      assume "holding s th cs" with eq_wq
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   713
      show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   714
        by (unfold s_holding_def wq_def, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   715
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   716
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   717
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   718
lemma step_v_waiting_mono:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   719
  "\<And>t c. \<lbrakk>vt (V th cs # s); waiting (wq (V th cs # s)) t c\<rbrakk> \<Longrightarrow> waiting (wq s) t c"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   720
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   721
  fix t c
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   722
  let ?s' = "(V th cs # s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   723
  assume vt: "vt ?s'" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   724
    and wt: "waiting (wq ?s') t c"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   725
  show "waiting (wq s) t c"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   726
  proof(cases "c = cs")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   727
    case False
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   728
    assume neq_cs: "c \<noteq> cs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   729
    hence "waiting (wq ?s') t c = waiting (wq s) t c"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   730
      by (unfold cs_waiting_def wq_def, auto simp:Let_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   731
    with wt show ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   732
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   733
    case True
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   734
    with wt show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   735
      apply (unfold cs_waiting_def wq_def, auto simp:Let_def split:list.splits)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   736
    proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   737
      fix a list
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   738
      assume not_in: "t \<notin> set list"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   739
        and is_in: "t \<in> set (SOME q. distinct q \<and> set q = set list)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   740
        and eq_wq: "wq_fun (schs s) cs = a # list"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   741
      have "set (SOME q. distinct q \<and> set q = set list) = set list"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   742
      proof(rule someI2)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   743
        from wq_distinct [OF step_back_vt[OF vt], of cs]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   744
        and eq_wq[folded wq_def]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   745
        show "distinct list \<and> set list = set list" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   746
      next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   747
        fix x assume "distinct x \<and> set x = set list"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   748
        thus "set x = set list" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   749
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   750
      with not_in is_in show "t = a" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   751
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   752
      fix list
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   753
      assume is_waiting: "waiting (wq (V th cs # s)) t cs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   754
      and eq_wq: "wq_fun (schs s) cs = t # list"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   755
      hence "t \<in> set list"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   756
        apply (unfold wq_def, auto simp:Let_def cs_waiting_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   757
      proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   758
        assume " t \<in> set (SOME q. distinct q \<and> set q = set list)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   759
        moreover have "\<dots> = set list" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   760
        proof(rule someI2)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   761
          from wq_distinct [OF step_back_vt[OF vt], of cs]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   762
            and eq_wq[folded wq_def]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   763
          show "distinct list \<and> set list = set list" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   764
        next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   765
          fix x assume "distinct x \<and> set x = set list" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   766
          thus "set x = set list" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   767
        qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   768
        ultimately show "t \<in> set list" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   769
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   770
      with eq_wq and wq_distinct [OF step_back_vt[OF vt], of cs, unfolded wq_def]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   771
      show False by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   772
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   773
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   774
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   775
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   776
lemma step_RAG_v:
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   777
fixes th::thread
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   778
assumes vt:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   779
  "vt (V th cs#s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   780
shows "
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   781
  RAG (V th cs # s) =
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   782
  RAG s - {(Cs cs, Th th)} -
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   783
  {(Th th', Cs cs) |th'. next_th s th cs th'} \<union>
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   784
  {(Cs cs, Th th') |th'.  next_th s th cs th'}"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   785
  apply (insert vt, unfold s_RAG_def) 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   786
  apply (auto split:if_splits list.splits simp:Let_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   787
  apply (auto elim: step_v_waiting_mono step_v_hold_inv 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   788
              step_v_release step_v_wait_inv
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   789
              step_v_get_hold step_v_release_inv)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   790
  apply (erule_tac step_v_not_wait, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   791
  done
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   792
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   793
lemma step_RAG_p:
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   794
  "vt (P th cs#s) \<Longrightarrow>
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   795
  RAG (P th cs # s) =  (if (wq s cs = []) then RAG s \<union> {(Cs cs, Th th)}
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   796
                                             else RAG s \<union> {(Th th, Cs cs)})"
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   797
  apply(simp only: s_RAG_def wq_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   798
  apply (auto split:list.splits prod.splits simp:Let_def wq_def cs_waiting_def cs_holding_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   799
  apply(case_tac "csa = cs", auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   800
  apply(fold wq_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   801
  apply(drule_tac step_back_step)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   802
  apply(ind_cases " step s (P (hd (wq s cs)) cs)")
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   803
  apply(simp add:s_RAG_def wq_def cs_holding_def)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   804
  apply(auto)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   805
  done
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   806
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   807
(* FIXME: Unused
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   808
lemma simple_A:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   809
  fixes A
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   810
  assumes h: "\<And> x y. \<lbrakk>x \<in> A; y \<in> A\<rbrakk> \<Longrightarrow> x = y"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   811
  shows "A = {} \<or> (\<exists> a. A = {a})"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   812
proof(cases "A = {}")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   813
  case True thus ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   814
next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   815
  case False then obtain a where "a \<in> A" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   816
  with h have "A = {a}" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   817
  thus ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   818
qed
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   819
*)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   820
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   821
lemma RAG_target_th: "(Th th, x) \<in> RAG (s::state) \<Longrightarrow> \<exists> cs. x = Cs cs"
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   822
  by (unfold s_RAG_def, auto)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   823
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   824
lemma acyclic_RAG: 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   825
  fixes s
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   826
  assumes vt: "vt s"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   827
  shows "acyclic (RAG s)"
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   828
using assms
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   829
proof(induct)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   830
  case (vt_cons s e)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   831
  assume ih: "acyclic (RAG s)"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   832
    and stp: "step s e"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   833
    and vt: "vt s"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   834
  show ?case
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   835
  proof(cases e)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   836
    case (Create th prio)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   837
    with ih
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   838
    show ?thesis by (simp add:RAG_create_unchanged)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   839
  next
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   840
    case (Exit th)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   841
    with ih show ?thesis by (simp add:RAG_exit_unchanged)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   842
  next
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   843
    case (V th cs)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   844
    from V vt stp have vtt: "vt (V th cs#s)" by auto
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   845
    from step_RAG_v [OF this]
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   846
    have eq_de: 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   847
      "RAG (e # s) = 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   848
      RAG s - {(Cs cs, Th th)} - {(Th th', Cs cs) |th'. next_th s th cs th'} \<union>
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   849
      {(Cs cs, Th th') |th'. next_th s th cs th'}"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   850
      (is "?L = (?A - ?B - ?C) \<union> ?D") by (simp add:V)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   851
    from ih have ac: "acyclic (?A - ?B - ?C)" by (auto elim:acyclic_subset)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   852
    from step_back_step [OF vtt]
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   853
    have "step s (V th cs)" .
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   854
    thus ?thesis
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   855
    proof(cases)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   856
      assume "holding s th cs"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   857
      hence th_in: "th \<in> set (wq s cs)" and
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   858
        eq_hd: "th = hd (wq s cs)" unfolding s_holding_def wq_def by auto
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   859
      then obtain rest where
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   860
        eq_wq: "wq s cs = th#rest"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   861
        by (cases "wq s cs", auto)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   862
      show ?thesis
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   863
      proof(cases "rest = []")
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   864
        case False
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   865
        let ?th' = "hd (SOME q. distinct q \<and> set q = set rest)"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   866
        from eq_wq False have eq_D: "?D = {(Cs cs, Th ?th')}"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   867
          by (unfold next_th_def, auto)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   868
        let ?E = "(?A - ?B - ?C)"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   869
        have "(Th ?th', Cs cs) \<notin> ?E\<^sup>*"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   870
        proof
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   871
          assume "(Th ?th', Cs cs) \<in> ?E\<^sup>*"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   872
          hence " (Th ?th', Cs cs) \<in> ?E\<^sup>+" by (simp add: rtrancl_eq_or_trancl)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   873
          from tranclD [OF this]
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   874
          obtain x where th'_e: "(Th ?th', x) \<in> ?E" by blast
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   875
          hence th_d: "(Th ?th', x) \<in> ?A" by simp
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   876
          from RAG_target_th [OF this]
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   877
          obtain cs' where eq_x: "x = Cs cs'" by auto
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   878
          with th_d have "(Th ?th', Cs cs') \<in> ?A" by simp
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   879
          hence wt_th': "waiting s ?th' cs'"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   880
            unfolding s_RAG_def s_waiting_def cs_waiting_def wq_def by simp
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   881
          hence "cs' = cs"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   882
          proof(rule waiting_unique [OF vt])
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   883
            from eq_wq wq_distinct[OF vt, of cs]
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   884
            show "waiting s ?th' cs" 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   885
              apply (unfold s_waiting_def wq_def, auto)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   886
            proof -
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   887
              assume hd_in: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   888
                and eq_wq: "wq_fun (schs s) cs = th # rest"
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   889
              have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   890
              proof(rule someI2)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   891
                from wq_distinct[OF vt, of cs] and eq_wq
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   892
                show "distinct rest \<and> set rest = set rest" unfolding wq_def by auto
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   893
              next
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   894
                fix x assume "distinct x \<and> set x = set rest"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   895
                with False show "x \<noteq> []" by auto
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   896
              qed
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   897
              hence "hd (SOME q. distinct q \<and> set q = set rest) \<in> 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   898
                set (SOME q. distinct q \<and> set q = set rest)" by auto
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   899
              moreover have "\<dots> = set rest" 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   900
              proof(rule someI2)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   901
                from wq_distinct[OF vt, of cs] and eq_wq
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   902
                show "distinct rest \<and> set rest = set rest" unfolding wq_def by auto
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   903
              next
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   904
                show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   905
              qed
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   906
              moreover note hd_in
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   907
              ultimately show "hd (SOME q. distinct q \<and> set q = set rest) = th" by auto
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   908
            next
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   909
              assume hd_in: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   910
                and eq_wq: "wq s cs = hd (SOME q. distinct q \<and> set q = set rest) # rest"
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   911
              have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   912
              proof(rule someI2)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   913
                from wq_distinct[OF vt, of cs] and eq_wq
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   914
                show "distinct rest \<and> set rest = set rest" by auto
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   915
              next
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   916
                fix x assume "distinct x \<and> set x = set rest"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   917
                with False show "x \<noteq> []" by auto
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   918
              qed
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   919
              hence "hd (SOME q. distinct q \<and> set q = set rest) \<in> 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   920
                set (SOME q. distinct q \<and> set q = set rest)" by auto
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   921
              moreover have "\<dots> = set rest" 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   922
              proof(rule someI2)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   923
                from wq_distinct[OF vt, of cs] and eq_wq
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   924
                show "distinct rest \<and> set rest = set rest" by auto
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   925
              next
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   926
                show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   927
              qed
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   928
              moreover note hd_in
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   929
              ultimately show False by auto
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   930
            qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   931
          qed
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   932
          with th'_e eq_x have "(Th ?th', Cs cs) \<in> ?E" by simp
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   933
          with False
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   934
          show "False" by (auto simp: next_th_def eq_wq)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   935
        qed
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   936
        with acyclic_insert[symmetric] and ac
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   937
          and eq_de eq_D show ?thesis by auto
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   938
      next
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   939
        case True
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   940
        with eq_wq
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   941
        have eq_D: "?D = {}"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   942
          by (unfold next_th_def, auto)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   943
        with eq_de ac
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   944
        show ?thesis by auto
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   945
      qed 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   946
    qed
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   947
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   948
    case (P th cs)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   949
    from P vt stp have vtt: "vt (P th cs#s)" by auto
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   950
    from step_RAG_p [OF this] P
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   951
    have "RAG (e # s) = 
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   952
      (if wq s cs = [] then RAG s \<union> {(Cs cs, Th th)} else 
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   953
      RAG s \<union> {(Th th, Cs cs)})" (is "?L = ?R")
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   954
      by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   955
    moreover have "acyclic ?R"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   956
    proof(cases "wq s cs = []")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   957
      case True
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   958
      hence eq_r: "?R =  RAG s \<union> {(Cs cs, Th th)}" by simp
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   959
      have "(Th th, Cs cs) \<notin> (RAG s)\<^sup>*"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   960
      proof
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   961
        assume "(Th th, Cs cs) \<in> (RAG s)\<^sup>*"
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   962
        hence "(Th th, Cs cs) \<in> (RAG s)\<^sup>+" by (simp add: rtrancl_eq_or_trancl)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   963
        from tranclD2 [OF this]
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   964
        obtain x where "(x, Cs cs) \<in> RAG s" by auto
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   965
        with True show False by (auto simp:s_RAG_def cs_waiting_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   966
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   967
      with acyclic_insert ih eq_r show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   968
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   969
      case False
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   970
      hence eq_r: "?R =  RAG s \<union> {(Th th, Cs cs)}" by simp
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   971
      have "(Cs cs, Th th) \<notin> (RAG s)\<^sup>*"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   972
      proof
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   973
        assume "(Cs cs, Th th) \<in> (RAG s)\<^sup>*"
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   974
        hence "(Cs cs, Th th) \<in> (RAG s)\<^sup>+" by (simp add: rtrancl_eq_or_trancl)
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   975
        moreover from step_back_step [OF vtt] have "step s (P th cs)" .
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   976
        ultimately show False
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   977
        proof -
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   978
          show " \<lbrakk>(Cs cs, Th th) \<in> (RAG s)\<^sup>+; step s (P th cs)\<rbrakk> \<Longrightarrow> False"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   979
            by (ind_cases "step s (P th cs)", simp)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   980
        qed
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   981
      qed
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   982
      with acyclic_insert ih eq_r show ?thesis by auto
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   983
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   984
      ultimately show ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   985
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   986
      case (Set thread prio)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   987
      with ih
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   988
      thm RAG_set_unchanged
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   989
      show ?thesis by (simp add:RAG_set_unchanged)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   990
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   991
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   992
    case vt_nil
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   993
    show "acyclic (RAG ([]::state))"
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   994
      by (auto simp: s_RAG_def cs_waiting_def 
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   995
        cs_holding_def wq_def acyclic_def)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   996
qed
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   997
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   998
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   999
lemma finite_RAG: 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1000
  fixes s
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1001
  assumes vt: "vt s"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1002
  shows "finite (RAG s)"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1003
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1004
  from vt show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1005
  proof(induct)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1006
    case (vt_cons s e)
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1007
    assume ih: "finite (RAG s)"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1008
      and stp: "step s e"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1009
      and vt: "vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1010
    show ?case
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1011
    proof(cases e)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1012
      case (Create th prio)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1013
      with ih
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1014
      show ?thesis by (simp add:RAG_create_unchanged)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1015
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1016
      case (Exit th)
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1017
      with ih show ?thesis by (simp add:RAG_exit_unchanged)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1018
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1019
      case (V th cs)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1020
      from V vt stp have vtt: "vt (V th cs#s)" by auto
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1021
      from step_RAG_v [OF this]
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1022
      have eq_de: "RAG (e # s) = 
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1023
                   RAG s - {(Cs cs, Th th)} - {(Th th', Cs cs) |th'. next_th s th cs th'} \<union>
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1024
                      {(Cs cs, Th th') |th'. next_th s th cs th'}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1025
"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1026
        (is "?L = (?A - ?B - ?C) \<union> ?D") by (simp add:V)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1027
      moreover from ih have ac: "finite (?A - ?B - ?C)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1028
      moreover have "finite ?D"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1029
      proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1030
        have "?D = {} \<or> (\<exists> a. ?D = {a})" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1031
          by (unfold next_th_def, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1032
        thus ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1033
        proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1034
          assume h: "?D = {}"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1035
          show ?thesis by (unfold h, simp)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1036
        next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1037
          assume "\<exists> a. ?D = {a}"
3
51019d035a79 made everything working
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 0
diff changeset
  1038
          thus ?thesis
51019d035a79 made everything working
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 0
diff changeset
  1039
            by (metis finite.simps)
0
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
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1042
      ultimately show ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1043
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1044
      case (P th cs)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1045
      from P vt stp have vtt: "vt (P th cs#s)" by auto
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1046
      from step_RAG_p [OF this] P
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1047
      have "RAG (e # s) = 
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1048
              (if wq s cs = [] then RAG s \<union> {(Cs cs, Th th)} else 
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1049
                                    RAG s \<union> {(Th th, Cs cs)})" (is "?L = ?R")
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1050
        by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1051
      moreover have "finite ?R"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1052
      proof(cases "wq s cs = []")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1053
        case True
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1054
        hence eq_r: "?R =  RAG s \<union> {(Cs cs, Th th)}" by simp
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1055
        with True and ih show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1056
      next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1057
        case False
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1058
        hence "?R = RAG s \<union> {(Th th, Cs cs)}" by simp
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1059
        with False and ih show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1060
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1061
      ultimately show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1062
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1063
      case (Set thread prio)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1064
      with ih
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1065
      show ?thesis by (simp add:RAG_set_unchanged)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1066
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1067
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1068
    case vt_nil
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1069
    show "finite (RAG ([]::state))"
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1070
      by (auto simp: s_RAG_def cs_waiting_def 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1071
                   cs_holding_def wq_def acyclic_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1072
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1073
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1074
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1075
text {* Several useful lemmas *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1076
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1077
lemma wf_dep_converse: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1078
  fixes s
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1079
  assumes vt: "vt s"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1080
  shows "wf ((RAG s)^-1)"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1081
proof(rule finite_acyclic_wf_converse)
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1082
  from finite_RAG [OF vt]
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1083
  show "finite (RAG s)" .
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1084
next
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1085
  from acyclic_RAG[OF vt]
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1086
  show "acyclic (RAG s)" .
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1087
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1088
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1089
lemma hd_np_in: "x \<in> set l \<Longrightarrow> hd l \<in> set l"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1090
by (induct l, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1091
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1092
lemma th_chasing: "(Th th, Cs cs) \<in> RAG (s::state) \<Longrightarrow> \<exists> th'. (Cs cs, Th th') \<in> RAG s"
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1093
  by (auto simp:s_RAG_def s_holding_def cs_holding_def cs_waiting_def wq_def dest:hd_np_in)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1094
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1095
lemma wq_threads: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1096
  fixes s cs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1097
  assumes vt: "vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1098
  and h: "th \<in> set (wq s cs)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1099
  shows "th \<in> threads s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1100
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1101
 from vt and h show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1102
  proof(induct arbitrary: th cs)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1103
    case (vt_cons s e)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1104
    assume ih: "\<And>th cs. th \<in> set (wq s cs) \<Longrightarrow> th \<in> threads s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1105
      and stp: "step s e"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1106
      and vt: "vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1107
      and h: "th \<in> set (wq (e # s) cs)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1108
    show ?case
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1109
    proof(cases e)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1110
      case (Create th' prio)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1111
      with ih h show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1112
        by (auto simp:wq_def Let_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1113
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1114
      case (Exit th')
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1115
      with stp ih h show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1116
        apply (auto simp:wq_def Let_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1117
        apply (ind_cases "step s (Exit th')")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1118
        apply (auto simp:runing_def readys_def s_holding_def s_waiting_def holdents_def
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1119
               s_RAG_def s_holding_def cs_holding_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1120
        done
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1121
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1122
      case (V th' cs')
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1123
      show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1124
      proof(cases "cs' = cs")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1125
        case False
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1126
        with h
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1127
        show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1128
          apply(unfold wq_def V, auto simp:Let_def V split:prod.splits, fold wq_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1129
          by (drule_tac ih, simp)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1130
      next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1131
        case True
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1132
        from h
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1133
        show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1134
        proof(unfold V wq_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1135
          assume th_in: "th \<in> set (wq_fun (schs (V th' cs' # s)) cs)" (is "th \<in> set ?l")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1136
          show "th \<in> threads (V th' cs' # s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1137
          proof(cases "cs = cs'")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1138
            case False
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1139
            hence "?l = wq_fun (schs s) cs" by (simp add:Let_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1140
            with th_in have " th \<in> set (wq s cs)" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1141
              by (fold wq_def, simp)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1142
            from ih [OF this] show ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1143
          next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1144
            case True
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1145
            show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1146
            proof(cases "wq_fun (schs s) cs'")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1147
              case Nil
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1148
              with h V show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1149
                apply (auto simp:wq_def Let_def split:if_splits)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1150
                by (fold wq_def, drule_tac ih, simp)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1151
            next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1152
              case (Cons a rest)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1153
              assume eq_wq: "wq_fun (schs s) cs' = a # rest"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1154
              with h V show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1155
                apply (auto simp:Let_def wq_def split:if_splits)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1156
              proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1157
                assume th_in: "th \<in> set (SOME q. distinct q \<and> set q = set rest)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1158
                have "set (SOME q. distinct q \<and> set q = set rest) = set rest" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1159
                proof(rule someI2)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1160
                  from wq_distinct[OF vt, of cs'] and eq_wq[folded wq_def]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1161
                  show "distinct rest \<and> set rest = set rest" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1162
                next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1163
                  show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1164
                    by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1165
                qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1166
                with eq_wq th_in have "th \<in> set (wq_fun (schs s) cs')" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1167
                from ih[OF this[folded wq_def]] show "th \<in> threads s" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1168
              next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1169
                assume th_in: "th \<in> set (wq_fun (schs s) cs)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1170
                from ih[OF this[folded wq_def]]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1171
                show "th \<in> threads s" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1172
              qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1173
            qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1174
          qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1175
        qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1176
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1177
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1178
      case (P th' cs')
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1179
      from h stp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1180
      show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1181
        apply (unfold P wq_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1182
        apply (auto simp:Let_def split:if_splits, fold wq_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1183
        apply (auto intro:ih)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1184
        apply(ind_cases "step s (P th' cs')")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1185
        by (unfold runing_def readys_def, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1186
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1187
      case (Set thread prio)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1188
      with ih h show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1189
        by (auto simp:wq_def Let_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1190
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1191
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1192
    case vt_nil
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1193
    thus ?case by (auto simp:wq_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1194
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1195
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1196
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1197
lemma range_in: "\<lbrakk>vt s; (Th th) \<in> Range (RAG (s::state))\<rbrakk> \<Longrightarrow> th \<in> threads s"
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1198
  apply(unfold s_RAG_def cs_waiting_def cs_holding_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1199
  by (auto intro:wq_threads)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1200
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1201
lemma readys_v_eq:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1202
  fixes th thread cs rest
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1203
  assumes vt: "vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1204
  and neq_th: "th \<noteq> thread"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1205
  and eq_wq: "wq s cs = thread#rest"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1206
  and not_in: "th \<notin>  set rest"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1207
  shows "(th \<in> readys (V thread cs#s)) = (th \<in> readys s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1208
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1209
  from assms show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1210
    apply (auto simp:readys_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1211
    apply(simp add:s_waiting_def[folded wq_def])
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1212
    apply (erule_tac x = csa in allE)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1213
    apply (simp add:s_waiting_def wq_def Let_def split:if_splits)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1214
    apply (case_tac "csa = cs", simp)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1215
    apply (erule_tac x = cs in allE)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1216
    apply(auto simp add: s_waiting_def[folded wq_def] Let_def split: list.splits)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1217
    apply(auto simp add: wq_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1218
    apply (auto simp:s_waiting_def wq_def Let_def split:list.splits)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1219
    proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1220
       assume th_nin: "th \<notin> set rest"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1221
        and th_in: "th \<in> set (SOME q. distinct q \<and> set q = set rest)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1222
        and eq_wq: "wq_fun (schs s) cs = thread # rest"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1223
      have "set (SOME q. distinct q \<and> set q = set rest) = set rest"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1224
      proof(rule someI2)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1225
        from wq_distinct[OF vt, of cs, unfolded wq_def] and eq_wq[unfolded wq_def]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1226
        show "distinct rest \<and> set rest = set rest" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1227
      next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1228
        show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1229
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1230
      with th_nin th_in show False by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1231
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1232
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1233
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1234
lemma chain_building:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1235
  assumes vt: "vt s"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1236
  shows "node \<in> Domain (RAG s) \<longrightarrow> (\<exists> th'. th' \<in> readys s \<and> (node, Th th') \<in> (RAG s)^+)"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1237
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1238
  from wf_dep_converse [OF vt]
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1239
  have h: "wf ((RAG s)\<inverse>)" .
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1240
  show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1241
  proof(induct rule:wf_induct [OF h])
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1242
    fix x
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1243
    assume ih [rule_format]: 
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1244
      "\<forall>y. (y, x) \<in> (RAG s)\<inverse> \<longrightarrow> 
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1245
           y \<in> Domain (RAG s) \<longrightarrow> (\<exists>th'. th' \<in> readys s \<and> (y, Th th') \<in> (RAG s)\<^sup>+)"
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1246
    show "x \<in> Domain (RAG s) \<longrightarrow> (\<exists>th'. th' \<in> readys s \<and> (x, Th th') \<in> (RAG s)\<^sup>+)"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1247
    proof
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1248
      assume x_d: "x \<in> Domain (RAG s)"
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1249
      show "\<exists>th'. th' \<in> readys s \<and> (x, Th th') \<in> (RAG s)\<^sup>+"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1250
      proof(cases x)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1251
        case (Th th)
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1252
        from x_d Th obtain cs where x_in: "(Th th, Cs cs) \<in> RAG s" by (auto simp:s_RAG_def)
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1253
        with Th have x_in_r: "(Cs cs, x) \<in> (RAG s)^-1" by simp
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1254
        from th_chasing [OF x_in] obtain th' where "(Cs cs, Th th') \<in> RAG s" by blast
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1255
        hence "Cs cs \<in> Domain (RAG s)" by auto
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1256
        from ih [OF x_in_r this] obtain th'
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1257
          where th'_ready: " th' \<in> readys s" and cs_in: "(Cs cs, Th th') \<in> (RAG s)\<^sup>+" by auto
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1258
        have "(x, Th th') \<in> (RAG s)\<^sup>+" using Th x_in cs_in by auto
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1259
        with th'_ready show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1260
      next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1261
        case (Cs cs)
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1262
        from x_d Cs obtain th' where th'_d: "(Th th', x) \<in> (RAG s)^-1" by (auto simp:s_RAG_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1263
        show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1264
        proof(cases "th' \<in> readys s")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1265
          case True
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1266
          from True and th'_d show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1267
        next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1268
          case False
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1269
          from th'_d and range_in [OF vt] have "th' \<in> threads s" by auto
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1270
          with False have "Th th' \<in> Domain (RAG s)" 
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1271
            by (auto simp:readys_def wq_def s_waiting_def s_RAG_def cs_waiting_def Domain_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1272
          from ih [OF th'_d this]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1273
          obtain th'' where 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1274
            th''_r: "th'' \<in> readys s" and 
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1275
            th''_in: "(Th th', Th th'') \<in> (RAG s)\<^sup>+" by auto
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1276
          from th'_d and th''_in 
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1277
          have "(x, Th th'') \<in> (RAG s)\<^sup>+" by auto
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1278
          with th''_r show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1279
        qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1280
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1281
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1282
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1283
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1284
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1285
lemma th_chain_to_ready:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1286
  fixes s th
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1287
  assumes vt: "vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1288
  and th_in: "th \<in> threads s"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1289
  shows "th \<in> readys s \<or> (\<exists> th'. th' \<in> readys s \<and> (Th th, Th th') \<in> (RAG s)^+)"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1290
proof(cases "th \<in> readys s")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1291
  case True
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1292
  thus ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1293
next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1294
  case False
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1295
  from False and th_in have "Th th \<in> Domain (RAG s)" 
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1296
    by (auto simp:readys_def s_waiting_def s_RAG_def wq_def cs_waiting_def Domain_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1297
  from chain_building [rule_format, OF vt this]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1298
  show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1299
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1300
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1301
lemma waiting_eq: "waiting s th cs = waiting (wq s) th cs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1302
  by  (unfold s_waiting_def cs_waiting_def wq_def, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1303
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1304
lemma holding_eq: "holding (s::state) th cs = holding (wq s) th cs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1305
  by (unfold s_holding_def wq_def cs_holding_def, simp)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1306
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1307
lemma holding_unique: "\<lbrakk>holding (s::state) th1 cs; holding s th2 cs\<rbrakk> \<Longrightarrow> th1 = th2"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1308
  by (unfold s_holding_def cs_holding_def, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1309
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1310
lemma unique_RAG: "\<lbrakk>vt s; (n, n1) \<in> RAG s; (n, n2) \<in> RAG s\<rbrakk> \<Longrightarrow> n1 = n2"
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1311
  apply(unfold s_RAG_def, auto, fold waiting_eq holding_eq)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1312
  by(auto elim:waiting_unique holding_unique)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1313
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1314
lemma trancl_split: "(a, b) \<in> r^+ \<Longrightarrow> \<exists> c. (a, c) \<in> r"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1315
by (induct rule:trancl_induct, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1316
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1317
lemma dchain_unique:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1318
  assumes vt: "vt s"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1319
  and th1_d: "(n, Th th1) \<in> (RAG s)^+"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1320
  and th1_r: "th1 \<in> readys s"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1321
  and th2_d: "(n, Th th2) \<in> (RAG s)^+"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1322
  and th2_r: "th2 \<in> readys s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1323
  shows "th1 = th2"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1324
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1325
  { assume neq: "th1 \<noteq> th2"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1326
    hence "Th th1 \<noteq> Th th2" by simp
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1327
    from unique_chain [OF _ th1_d th2_d this] and unique_RAG [OF vt]
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1328
    have "(Th th1, Th th2) \<in> (RAG s)\<^sup>+ \<or> (Th th2, Th th1) \<in> (RAG s)\<^sup>+" by auto
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1329
    hence "False"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1330
    proof
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1331
      assume "(Th th1, Th th2) \<in> (RAG s)\<^sup>+"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1332
      from trancl_split [OF this]
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1333
      obtain n where dd: "(Th th1, n) \<in> RAG s" by auto
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1334
      then obtain cs where eq_n: "n = Cs cs"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1335
        by (auto simp:s_RAG_def s_holding_def cs_holding_def cs_waiting_def wq_def dest:hd_np_in)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1336
      from dd eq_n have "th1 \<notin> readys s"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1337
        by (auto simp:readys_def s_RAG_def wq_def s_waiting_def cs_waiting_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1338
      with th1_r show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1339
    next
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1340
      assume "(Th th2, Th th1) \<in> (RAG s)\<^sup>+"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1341
      from trancl_split [OF this]
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1342
      obtain n where dd: "(Th th2, n) \<in> RAG s" by auto
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1343
      then obtain cs where eq_n: "n = Cs cs"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1344
        by (auto simp:s_RAG_def s_holding_def cs_holding_def cs_waiting_def wq_def dest:hd_np_in)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1345
      from dd eq_n have "th2 \<notin> readys s"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1346
        by (auto simp:readys_def wq_def s_RAG_def s_waiting_def cs_waiting_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1347
      with th2_r show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1348
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1349
  } thus ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1350
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1351
             
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1352
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1353
lemma step_holdents_p_add:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1354
  fixes th cs s
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1355
  assumes vt: "vt (P th cs#s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1356
  and "wq s cs = []"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1357
  shows "holdents (P th cs#s) th = holdents s th \<union> {cs}"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1358
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1359
  from assms show ?thesis
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1360
  unfolding  holdents_test step_RAG_p[OF vt] by (auto)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1361
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1362
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1363
lemma step_holdents_p_eq:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1364
  fixes th cs s
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1365
  assumes vt: "vt (P th cs#s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1366
  and "wq s cs \<noteq> []"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1367
  shows "holdents (P th cs#s) th = holdents s th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1368
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1369
  from assms show ?thesis
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1370
  unfolding  holdents_test step_RAG_p[OF vt] by auto
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1371
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1372
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1373
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1374
lemma finite_holding:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1375
  fixes s th cs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1376
  assumes vt: "vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1377
  shows "finite (holdents s th)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1378
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1379
  let ?F = "\<lambda> (x, y). the_cs x"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1380
  from finite_RAG [OF vt]
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1381
  have "finite (RAG s)" .
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1382
  hence "finite (?F `(RAG s))" by simp
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1383
  moreover have "{cs . (Cs cs, Th th) \<in> RAG s} \<subseteq> \<dots>" 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1384
  proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1385
    { have h: "\<And> a A f. a \<in> A \<Longrightarrow> f a \<in> f ` A" by auto
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1386
      fix x assume "(Cs x, Th th) \<in> RAG s"
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1387
      hence "?F (Cs x, Th th) \<in> ?F `(RAG s)" by (rule h)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1388
      moreover have "?F (Cs x, Th th) = x" by simp
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1389
      ultimately have "x \<in> (\<lambda>(x, y). the_cs x) ` RAG s" by simp 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1390
    } thus ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1391
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1392
  ultimately show ?thesis by (unfold holdents_test, auto intro:finite_subset)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1393
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1394
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1395
lemma cntCS_v_dec: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1396
  fixes s thread cs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1397
  assumes vtv: "vt (V thread cs#s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1398
  shows "(cntCS (V thread cs#s) thread + 1) = cntCS s thread"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1399
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1400
  from step_back_step[OF vtv]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1401
  have cs_in: "cs \<in> holdents s thread" 
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1402
    apply (cases, unfold holdents_test s_RAG_def, simp)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1403
    by (unfold cs_holding_def s_holding_def wq_def, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1404
  moreover have cs_not_in: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1405
    "(holdents (V thread cs#s) thread) = holdents s thread - {cs}"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1406
    apply (insert wq_distinct[OF step_back_vt[OF vtv], of cs])
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1407
    apply (unfold holdents_test, unfold step_RAG_v[OF vtv],
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1408
            auto simp:next_th_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1409
  proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1410
    fix rest
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1411
    assume dst: "distinct (rest::thread list)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1412
      and ne: "rest \<noteq> []"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1413
    and hd_ni: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1414
    moreover have "set (SOME q. distinct q \<and> set q = set rest) = set rest"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1415
    proof(rule someI2)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1416
      from dst show "distinct rest \<and> set rest = set rest" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1417
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1418
      show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1419
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1420
    ultimately have "hd (SOME q. distinct q \<and> set q = set rest) \<notin> 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1421
                     set (SOME q. distinct q \<and> set q = set rest)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1422
    moreover have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1423
    proof(rule someI2)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1424
      from dst show "distinct rest \<and> set rest = set rest" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1425
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1426
      fix x assume " distinct x \<and> set x = set rest" with ne
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1427
      show "x \<noteq> []" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1428
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1429
    ultimately 
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1430
    show "(Cs cs, Th (hd (SOME q. distinct q \<and> set q = set rest))) \<in> RAG s"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1431
      by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1432
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1433
    fix rest
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1434
    assume dst: "distinct (rest::thread list)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1435
      and ne: "rest \<noteq> []"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1436
    and hd_ni: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1437
    moreover have "set (SOME q. distinct q \<and> set q = set rest) = set rest"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1438
    proof(rule someI2)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1439
      from dst show "distinct rest \<and> set rest = set rest" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1440
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1441
      show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1442
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1443
    ultimately have "hd (SOME q. distinct q \<and> set q = set rest) \<notin> 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1444
                     set (SOME q. distinct q \<and> set q = set rest)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1445
    moreover have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1446
    proof(rule someI2)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1447
      from dst show "distinct rest \<and> set rest = set rest" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1448
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1449
      fix x assume " distinct x \<and> set x = set rest" with ne
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1450
      show "x \<noteq> []" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1451
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1452
    ultimately show "False" by auto 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1453
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1454
  ultimately 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1455
  have "holdents s thread = insert cs (holdents (V thread cs#s) thread)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1456
    by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1457
  moreover have "card \<dots> = 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1458
                    Suc (card ((holdents (V thread cs#s) thread) - {cs}))"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1459
  proof(rule card_insert)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1460
    from finite_holding [OF vtv]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1461
    show " finite (holdents (V thread cs # s) thread)" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1462
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1463
  moreover from cs_not_in 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1464
  have "cs \<notin> (holdents (V thread cs#s) thread)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1465
  ultimately show ?thesis by (simp add:cntCS_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1466
qed 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1467
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1468
lemma cnp_cnv_cncs:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1469
  fixes s th
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1470
  assumes vt: "vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1471
  shows "cntP s th = cntV s th + (if (th \<in> readys s \<or> th \<notin> threads s) 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1472
                                       then cntCS s th else cntCS s th + 1)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1473
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1474
  from vt show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1475
  proof(induct arbitrary:th)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1476
    case (vt_cons s e)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1477
    assume vt: "vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1478
    and ih: "\<And>th. cntP s th  = cntV s th +
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1479
               (if (th \<in> readys s \<or> th \<notin> threads s) then cntCS s th else cntCS s th + 1)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1480
    and stp: "step s e"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1481
    from stp show ?case
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1482
    proof(cases)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1483
      case (thread_create thread prio)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1484
      assume eq_e: "e = Create thread prio"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1485
        and not_in: "thread \<notin> threads s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1486
      show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1487
      proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1488
        { fix cs 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1489
          assume "thread \<in> set (wq s cs)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1490
          from wq_threads [OF vt this] have "thread \<in> threads s" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1491
          with not_in have "False" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1492
        } with eq_e have eq_readys: "readys (e#s) = readys s \<union> {thread}"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1493
          by (auto simp:readys_def threads.simps s_waiting_def 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1494
            wq_def cs_waiting_def Let_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1495
        from eq_e have eq_cnp: "cntP (e#s) th = cntP s th" by (simp add:cntP_def count_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1496
        from eq_e have eq_cnv: "cntV (e#s) th = cntV s th" by (simp add:cntV_def count_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1497
        have eq_cncs: "cntCS (e#s) th = cntCS s th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1498
          unfolding cntCS_def holdents_test
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1499
          by (simp add:RAG_create_unchanged eq_e)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1500
        { assume "th \<noteq> thread"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1501
          with eq_readys eq_e
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1502
          have "(th \<in> readys (e # s) \<or> th \<notin> threads (e # s)) = 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1503
                      (th \<in> readys (s) \<or> th \<notin> threads (s))" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1504
            by (simp add:threads.simps)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1505
          with eq_cnp eq_cnv eq_cncs ih not_in
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1506
          have ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1507
        } moreover {
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1508
          assume eq_th: "th = thread"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1509
          with not_in ih have " cntP s th  = cntV s th + cntCS s th" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1510
          moreover from eq_th and eq_readys have "th \<in> readys (e#s)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1511
          moreover note eq_cnp eq_cnv eq_cncs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1512
          ultimately have ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1513
        } ultimately show ?thesis by blast
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1514
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1515
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1516
      case (thread_exit thread)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1517
      assume eq_e: "e = Exit thread" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1518
      and is_runing: "thread \<in> runing s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1519
      and no_hold: "holdents s thread = {}"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1520
      from eq_e have eq_cnp: "cntP (e#s) th = cntP s th" by (simp add:cntP_def count_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1521
      from eq_e have eq_cnv: "cntV (e#s) th = cntV s th" by (simp add:cntV_def count_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1522
      have eq_cncs: "cntCS (e#s) th = cntCS s th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1523
        unfolding cntCS_def holdents_test
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1524
        by (simp add:RAG_exit_unchanged eq_e)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1525
      { assume "th \<noteq> thread"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1526
        with eq_e
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1527
        have "(th \<in> readys (e # s) \<or> th \<notin> threads (e # s)) = 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1528
          (th \<in> readys (s) \<or> th \<notin> threads (s))" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1529
          apply (simp add:threads.simps readys_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1530
          apply (subst s_waiting_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1531
          apply (simp add:Let_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1532
          apply (subst s_waiting_def, simp)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1533
          done
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1534
        with eq_cnp eq_cnv eq_cncs ih
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1535
        have ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1536
      } moreover {
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1537
        assume eq_th: "th = thread"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1538
        with ih is_runing have " cntP s th = cntV s th + cntCS s th" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1539
          by (simp add:runing_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1540
        moreover from eq_th eq_e have "th \<notin> threads (e#s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1541
          by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1542
        moreover note eq_cnp eq_cnv eq_cncs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1543
        ultimately have ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1544
      } ultimately show ?thesis by blast
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1545
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1546
      case (thread_P thread cs)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1547
      assume eq_e: "e = P thread cs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1548
        and is_runing: "thread \<in> runing s"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1549
        and no_dep: "(Cs cs, Th thread) \<notin> (RAG s)\<^sup>+"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1550
      from thread_P vt stp ih  have vtp: "vt (P thread cs#s)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1551
      show ?thesis 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1552
      proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1553
        { have hh: "\<And> A B C. (B = C) \<Longrightarrow> (A \<and> B) = (A \<and> C)" by blast
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1554
          assume neq_th: "th \<noteq> thread"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1555
          with eq_e
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1556
          have eq_readys: "(th \<in> readys (e#s)) = (th \<in> readys (s))"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1557
            apply (simp add:readys_def s_waiting_def wq_def Let_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1558
            apply (rule_tac hh, clarify)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1559
            apply (intro iffI allI, clarify)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1560
            apply (erule_tac x = csa in allE, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1561
            apply (subgoal_tac "wq_fun (schs s) cs \<noteq> []", auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1562
            apply (erule_tac x = cs in allE, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1563
            by (case_tac "(wq_fun (schs s) cs)", auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1564
          moreover from neq_th eq_e have "cntCS (e # s) th = cntCS s th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1565
            apply (simp add:cntCS_def holdents_test)
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1566
            by (unfold  step_RAG_p [OF vtp], auto)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1567
          moreover from eq_e neq_th have "cntP (e # s) th = cntP s th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1568
            by (simp add:cntP_def count_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1569
          moreover from eq_e neq_th have "cntV (e#s) th = cntV s th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1570
            by (simp add:cntV_def count_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1571
          moreover from eq_e neq_th have "threads (e#s) = threads s" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1572
          moreover note ih [of th] 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1573
          ultimately have ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1574
        } moreover {
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1575
          assume eq_th: "th = thread"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1576
          have ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1577
          proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1578
            from eq_e eq_th have eq_cnp: "cntP (e # s) th  = 1 + (cntP s th)" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1579
              by (simp add:cntP_def count_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1580
            from eq_e eq_th have eq_cnv: "cntV (e#s) th = cntV s th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1581
              by (simp add:cntV_def count_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1582
            show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1583
            proof (cases "wq s cs = []")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1584
              case True
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1585
              with is_runing
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1586
              have "th \<in> readys (e#s)"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1587
                apply (unfold eq_e wq_def, unfold readys_def s_RAG_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1588
                apply (simp add: wq_def[symmetric] runing_def eq_th s_waiting_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1589
                by (auto simp:readys_def wq_def Let_def s_waiting_def wq_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1590
              moreover have "cntCS (e # s) th = 1 + cntCS s th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1591
              proof -
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1592
                have "card {csa. csa = cs \<or> (Cs csa, Th thread) \<in> RAG s} =
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1593
                  Suc (card {cs. (Cs cs, Th thread) \<in> RAG s})" (is "card ?L = Suc (card ?R)")
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1594
                proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1595
                  have "?L = insert cs ?R" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1596
                  moreover have "card \<dots> = Suc (card (?R - {cs}))" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1597
                  proof(rule card_insert)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1598
                    from finite_holding [OF vt, of thread]
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1599
                    show " finite {cs. (Cs cs, Th thread) \<in> RAG s}"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1600
                      by (unfold holdents_test, simp)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1601
                  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1602
                  moreover have "?R - {cs} = ?R"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1603
                  proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1604
                    have "cs \<notin> ?R"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1605
                    proof
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1606
                      assume "cs \<in> {cs. (Cs cs, Th thread) \<in> RAG s}"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1607
                      with no_dep show False by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1608
                    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1609
                    thus ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1610
                  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1611
                  ultimately show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1612
                qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1613
                thus ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1614
                  apply (unfold eq_e eq_th cntCS_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1615
                  apply (simp add: holdents_test)
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1616
                  by (unfold step_RAG_p [OF vtp], auto simp:True)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1617
              qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1618
              moreover from is_runing have "th \<in> readys s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1619
                by (simp add:runing_def eq_th)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1620
              moreover note eq_cnp eq_cnv ih [of th]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1621
              ultimately show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1622
            next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1623
              case False
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1624
              have eq_wq: "wq (e#s) cs = wq s cs @ [th]"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1625
                    by (unfold eq_th eq_e wq_def, auto simp:Let_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1626
              have "th \<notin> readys (e#s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1627
              proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1628
                assume "th \<in> readys (e#s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1629
                hence "\<forall>cs. \<not> waiting (e # s) th cs" by (simp add:readys_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1630
                from this[rule_format, of cs] have " \<not> waiting (e # s) th cs" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1631
                hence "th \<in> set (wq (e#s) cs) \<Longrightarrow> th = hd (wq (e#s) cs)" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1632
                  by (simp add:s_waiting_def wq_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1633
                moreover from eq_wq have "th \<in> set (wq (e#s) cs)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1634
                ultimately have "th = hd (wq (e#s) cs)" by blast
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1635
                with eq_wq have "th = hd (wq s cs @ [th])" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1636
                hence "th = hd (wq s cs)" using False by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1637
                with False eq_wq wq_distinct [OF vtp, of cs]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1638
                show False by (fold eq_e, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1639
              qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1640
              moreover from is_runing have "th \<in> threads (e#s)" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1641
                by (unfold eq_e, auto simp:runing_def readys_def eq_th)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1642
              moreover have "cntCS (e # s) th = cntCS s th"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1643
                apply (unfold cntCS_def holdents_test eq_e step_RAG_p[OF vtp])
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1644
                by (auto simp:False)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1645
              moreover note eq_cnp eq_cnv ih[of th]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1646
              moreover from is_runing have "th \<in> readys s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1647
                by (simp add:runing_def eq_th)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1648
              ultimately show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1649
            qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1650
          qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1651
        } ultimately show ?thesis by blast
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1652
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1653
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1654
      case (thread_V thread cs)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1655
      from assms vt stp ih thread_V have vtv: "vt (V thread cs # s)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1656
      assume eq_e: "e = V thread cs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1657
        and is_runing: "thread \<in> runing s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1658
        and hold: "holding s thread cs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1659
      from hold obtain rest 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1660
        where eq_wq: "wq s cs = thread # rest"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1661
        by (case_tac "wq s cs", auto simp: wq_def s_holding_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1662
      have eq_threads: "threads (e#s) = threads s" by (simp add: eq_e)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1663
      have eq_set: "set (SOME q. distinct q \<and> set q = set rest) = set rest"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1664
      proof(rule someI2)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1665
        from wq_distinct[OF step_back_vt[OF vtv], of cs] and eq_wq
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1666
        show "distinct rest \<and> set rest = set rest" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1667
      next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1668
        show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1669
          by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1670
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1671
      show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1672
      proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1673
        { assume eq_th: "th = thread"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1674
          from eq_th have eq_cnp: "cntP (e # s) th = cntP s th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1675
            by (unfold eq_e, simp add:cntP_def count_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1676
          moreover from eq_th have eq_cnv: "cntV (e#s) th = 1 + cntV s th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1677
            by (unfold eq_e, simp add:cntV_def count_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1678
          moreover from cntCS_v_dec [OF vtv] 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1679
          have "cntCS (e # s) thread + 1 = cntCS s thread"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1680
            by (simp add:eq_e)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1681
          moreover from is_runing have rd_before: "thread \<in> readys s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1682
            by (unfold runing_def, simp)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1683
          moreover have "thread \<in> readys (e # s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1684
          proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1685
            from is_runing
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1686
            have "thread \<in> threads (e#s)" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1687
              by (unfold eq_e, auto simp:runing_def readys_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1688
            moreover have "\<forall> cs1. \<not> waiting (e#s) thread cs1"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1689
            proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1690
              fix cs1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1691
              { assume eq_cs: "cs1 = cs" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1692
                have "\<not> waiting (e # s) thread cs1"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1693
                proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1694
                  from eq_wq
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1695
                  have "thread \<notin> set (wq (e#s) cs1)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1696
                    apply(unfold eq_e wq_def eq_cs s_holding_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1697
                    apply (auto simp:Let_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1698
                  proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1699
                    assume "thread \<in> set (SOME q. distinct q \<and> set q = set rest)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1700
                    with eq_set have "thread \<in> set rest" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1701
                    with wq_distinct[OF step_back_vt[OF vtv], of cs]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1702
                    and eq_wq show False by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1703
                  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1704
                  thus ?thesis by (simp add:wq_def s_waiting_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1705
                qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1706
              } moreover {
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1707
                assume neq_cs: "cs1 \<noteq> cs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1708
                  have "\<not> waiting (e # s) thread cs1" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1709
                  proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1710
                    from wq_v_neq [OF neq_cs[symmetric]]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1711
                    have "wq (V thread cs # s) cs1 = wq s cs1" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1712
                    moreover have "\<not> waiting s thread cs1" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1713
                    proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1714
                      from runing_ready and is_runing
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1715
                      have "thread \<in> readys s" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1716
                      thus ?thesis by (simp add:readys_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1717
                    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1718
                    ultimately show ?thesis 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1719
                      by (auto simp:wq_def s_waiting_def eq_e)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1720
                  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1721
              } ultimately show "\<not> waiting (e # s) thread cs1" by blast
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1722
            qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1723
            ultimately show ?thesis by (simp add:readys_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1724
          qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1725
          moreover note eq_th ih
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1726
          ultimately have ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1727
        } moreover {
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1728
          assume neq_th: "th \<noteq> thread"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1729
          from neq_th eq_e have eq_cnp: "cntP (e # s) th = cntP s th" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1730
            by (simp add:cntP_def count_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1731
          from neq_th eq_e have eq_cnv: "cntV (e # s) th = cntV s th" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1732
            by (simp add:cntV_def count_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1733
          have ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1734
          proof(cases "th \<in> set rest")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1735
            case False
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1736
            have "(th \<in> readys (e # s)) = (th \<in> readys s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1737
              apply (insert step_back_vt[OF vtv])
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1738
              by (unfold eq_e, rule readys_v_eq [OF _ neq_th eq_wq False], auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1739
            moreover have "cntCS (e#s) th = cntCS s th"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1740
              apply (insert neq_th, unfold eq_e cntCS_def holdents_test step_RAG_v[OF vtv], auto)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1741
              proof -
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1742
                have "{csa. (Cs csa, Th th) \<in> RAG s \<or> csa = cs \<and> next_th s thread cs th} =
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1743
                      {cs. (Cs cs, Th th) \<in> RAG s}"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1744
                proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1745
                  from False eq_wq
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1746
                  have " next_th s thread cs th \<Longrightarrow> (Cs cs, Th th) \<in> RAG s"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1747
                    apply (unfold next_th_def, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1748
                  proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1749
                    assume ne: "rest \<noteq> []"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1750
                      and ni: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1751
                      and eq_wq: "wq s cs = thread # rest"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1752
                    from eq_set ni have "hd (SOME q. distinct q \<and> set q = set rest) \<notin> 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1753
                                  set (SOME q. distinct q \<and> set q = set rest)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1754
                                  " by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1755
                    moreover have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1756
                    proof(rule someI2)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1757
                      from wq_distinct[OF step_back_vt[OF vtv], of cs] and eq_wq
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1758
                      show "distinct rest \<and> set rest = set rest" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1759
                    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1760
                      fix x assume "distinct x \<and> set x = set rest"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1761
                      with ne show "x \<noteq> []" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1762
                    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1763
                    ultimately show 
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1764
                      "(Cs cs, Th (hd (SOME q. distinct q \<and> set q = set rest))) \<in> RAG s"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1765
                      by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1766
                  qed    
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1767
                  thus ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1768
                qed
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1769
                thus "card {csa. (Cs csa, Th th) \<in> RAG s \<or> csa = cs \<and> next_th s thread cs th} =
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1770
                             card {cs. (Cs cs, Th th) \<in> RAG s}" by simp 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1771
              qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1772
            moreover note ih eq_cnp eq_cnv eq_threads
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1773
            ultimately show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1774
          next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1775
            case True
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1776
            assume th_in: "th \<in> set rest"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1777
            show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1778
            proof(cases "next_th s thread cs th")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1779
              case False
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1780
              with eq_wq and th_in have 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1781
                neq_hd: "th \<noteq> hd (SOME q. distinct q \<and> set q = set rest)" (is "th \<noteq> hd ?rest")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1782
                by (auto simp:next_th_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1783
              have "(th \<in> readys (e # s)) = (th \<in> readys s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1784
              proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1785
                from eq_wq and th_in
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1786
                have "\<not> th \<in> readys s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1787
                  apply (auto simp:readys_def s_waiting_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1788
                  apply (rule_tac x = cs in exI, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1789
                  by (insert wq_distinct[OF step_back_vt[OF vtv], of cs], auto simp add: wq_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1790
                moreover 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1791
                from eq_wq and th_in and neq_hd
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1792
                have "\<not> (th \<in> readys (e # s))"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1793
                  apply (auto simp:readys_def s_waiting_def eq_e wq_def Let_def split:list.splits)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1794
                  by (rule_tac x = cs in exI, auto simp:eq_set)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1795
                ultimately show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1796
              qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1797
              moreover have "cntCS (e#s) th = cntCS s th" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1798
              proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1799
                from eq_wq and  th_in and neq_hd
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1800
                have "(holdents (e # s) th) = (holdents s th)"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1801
                  apply (unfold eq_e step_RAG_v[OF vtv], 
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1802
                         auto simp:next_th_def eq_set s_RAG_def holdents_test wq_def
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1803
                                   Let_def cs_holding_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1804
                  by (insert wq_distinct[OF step_back_vt[OF vtv], of cs], auto simp:wq_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1805
                thus ?thesis by (simp add:cntCS_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1806
              qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1807
              moreover note ih eq_cnp eq_cnv eq_threads
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1808
              ultimately show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1809
            next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1810
              case True
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1811
              let ?rest = " (SOME q. distinct q \<and> set q = set rest)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1812
              let ?t = "hd ?rest"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1813
              from True eq_wq th_in neq_th
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1814
              have "th \<in> readys (e # s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1815
                apply (auto simp:eq_e readys_def s_waiting_def wq_def
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1816
                        Let_def next_th_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1817
              proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1818
                assume eq_wq: "wq_fun (schs s) cs = thread # rest"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1819
                  and t_in: "?t \<in> set rest"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1820
                show "?t \<in> threads s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1821
                proof(rule wq_threads[OF step_back_vt[OF vtv]])
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1822
                  from eq_wq and t_in
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1823
                  show "?t \<in> set (wq s cs)" by (auto simp:wq_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1824
                qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1825
              next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1826
                fix csa
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1827
                assume eq_wq: "wq_fun (schs s) cs = thread # rest"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1828
                  and t_in: "?t \<in> set rest"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1829
                  and neq_cs: "csa \<noteq> cs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1830
                  and t_in': "?t \<in>  set (wq_fun (schs s) csa)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1831
                show "?t = hd (wq_fun (schs s) csa)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1832
                proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1833
                  { assume neq_hd': "?t \<noteq> hd (wq_fun (schs s) csa)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1834
                    from wq_distinct[OF step_back_vt[OF vtv], of cs] and 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1835
                    eq_wq[folded wq_def] and t_in eq_wq
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1836
                    have "?t \<noteq> thread" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1837
                    with eq_wq and t_in
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1838
                    have w1: "waiting s ?t cs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1839
                      by (auto simp:s_waiting_def wq_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1840
                    from t_in' neq_hd'
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1841
                    have w2: "waiting s ?t csa"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1842
                      by (auto simp:s_waiting_def wq_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1843
                    from waiting_unique[OF step_back_vt[OF vtv] w1 w2]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1844
                    and neq_cs have "False" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1845
                  } thus ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1846
                qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1847
              qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1848
              moreover have "cntP s th = cntV s th + cntCS s th + 1"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1849
              proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1850
                have "th \<notin> readys s" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1851
                proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1852
                  from True eq_wq neq_th th_in
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1853
                  show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1854
                    apply (unfold readys_def s_waiting_def, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1855
                    by (rule_tac x = cs in exI, auto simp add: wq_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1856
                qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1857
                moreover have "th \<in> threads s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1858
                proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1859
                  from th_in eq_wq
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1860
                  have "th \<in> set (wq s cs)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1861
                  from wq_threads [OF step_back_vt[OF vtv] this] 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1862
                  show ?thesis .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1863
                qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1864
                ultimately show ?thesis using ih by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1865
              qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1866
              moreover from True neq_th have "cntCS (e # s) th = 1 + cntCS s th"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1867
                apply (unfold cntCS_def holdents_test eq_e step_RAG_v[OF vtv], auto)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1868
              proof -
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1869
                show "card {csa. (Cs csa, Th th) \<in> RAG s \<or> csa = cs} =
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1870
                               Suc (card {cs. (Cs cs, Th th) \<in> RAG s})"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1871
                  (is "card ?A = Suc (card ?B)")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1872
                proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1873
                  have "?A = insert cs ?B" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1874
                  hence "card ?A = card (insert cs ?B)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1875
                  also have "\<dots> = Suc (card ?B)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1876
                  proof(rule card_insert_disjoint)
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1877
                    have "?B \<subseteq> ((\<lambda> (x, y). the_cs x) ` RAG s)" 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1878
                      apply (auto simp:image_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1879
                      by (rule_tac x = "(Cs x, Th th)" in bexI, auto)
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1880
                    with finite_RAG[OF step_back_vt[OF vtv]]
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1881
                    show "finite {cs. (Cs cs, Th th) \<in> RAG s}" by (auto intro:finite_subset)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1882
                  next
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1883
                    show "cs \<notin> {cs. (Cs cs, Th th) \<in> RAG s}"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1884
                    proof
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1885
                      assume "cs \<in> {cs. (Cs cs, Th th) \<in> RAG s}"
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1886
                      hence "(Cs cs, Th th) \<in> RAG s" by simp
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1887
                      with True neq_th eq_wq show False
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1888
                        by (auto simp:next_th_def s_RAG_def cs_holding_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1889
                    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1890
                  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1891
                  finally show ?thesis .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1892
                qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1893
              qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1894
              moreover note eq_cnp eq_cnv
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1895
              ultimately show ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1896
            qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1897
          qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1898
        } ultimately show ?thesis by blast
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1899
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1900
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1901
      case (thread_set thread prio)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1902
      assume eq_e: "e = Set thread prio"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1903
        and is_runing: "thread \<in> runing s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1904
      show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1905
      proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1906
        from eq_e have eq_cnp: "cntP (e#s) th = cntP s th" by (simp add:cntP_def count_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1907
        from eq_e have eq_cnv: "cntV (e#s) th = cntV s th" by (simp add:cntV_def count_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1908
        have eq_cncs: "cntCS (e#s) th = cntCS s th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1909
          unfolding cntCS_def holdents_test
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1910
          by (simp add:RAG_set_unchanged eq_e)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1911
        from eq_e have eq_readys: "readys (e#s) = readys s" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1912
          by (simp add:readys_def cs_waiting_def s_waiting_def wq_def,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1913
                  auto simp:Let_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1914
        { assume "th \<noteq> thread"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1915
          with eq_readys eq_e
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1916
          have "(th \<in> readys (e # s) \<or> th \<notin> threads (e # s)) = 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1917
                      (th \<in> readys (s) \<or> th \<notin> threads (s))" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1918
            by (simp add:threads.simps)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1919
          with eq_cnp eq_cnv eq_cncs ih is_runing
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1920
          have ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1921
        } moreover {
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1922
          assume eq_th: "th = thread"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1923
          with is_runing ih have " cntP s th  = cntV s th + cntCS s th" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1924
            by (unfold runing_def, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1925
          moreover from eq_th and eq_readys is_runing have "th \<in> readys (e#s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1926
            by (simp add:runing_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1927
          moreover note eq_cnp eq_cnv eq_cncs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1928
          ultimately have ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1929
        } ultimately show ?thesis by blast
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1930
      qed   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1931
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1932
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1933
    case vt_nil
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1934
    show ?case 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1935
      by (unfold cntP_def cntV_def cntCS_def, 
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1936
        auto simp:count_def holdents_test s_RAG_def wq_def cs_holding_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1937
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1938
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1939
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1940
lemma not_thread_cncs:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1941
  fixes th s
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1942
  assumes vt: "vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1943
  and not_in: "th \<notin> threads s" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1944
  shows "cntCS s th = 0"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1945
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1946
  from vt not_in show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1947
  proof(induct arbitrary:th)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1948
    case (vt_cons s e th)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1949
    assume vt: "vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1950
      and ih: "\<And>th. th \<notin> threads s \<Longrightarrow> cntCS s th = 0"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1951
      and stp: "step s e"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1952
      and not_in: "th \<notin> threads (e # s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1953
    from stp show ?case
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1954
    proof(cases)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1955
      case (thread_create thread prio)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1956
      assume eq_e: "e = Create thread prio"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1957
        and not_in': "thread \<notin> threads s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1958
      have "cntCS (e # s) th = cntCS s th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1959
        apply (unfold eq_e cntCS_def holdents_test)
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1960
        by (simp add:RAG_create_unchanged)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1961
      moreover have "th \<notin> threads s" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1962
      proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1963
        from not_in eq_e show ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1964
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1965
      moreover note ih ultimately show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1966
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1967
      case (thread_exit thread)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1968
      assume eq_e: "e = Exit thread"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1969
      and nh: "holdents s thread = {}"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1970
      have eq_cns: "cntCS (e # s) th = cntCS s th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1971
        apply (unfold eq_e cntCS_def holdents_test)
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1972
        by (simp add:RAG_exit_unchanged)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1973
      show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1974
      proof(cases "th = thread")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1975
        case True
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1976
        have "cntCS s th = 0" by (unfold cntCS_def, auto simp:nh True)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1977
        with eq_cns show ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1978
      next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1979
        case False
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1980
        with not_in and eq_e
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1981
        have "th \<notin> threads s" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1982
        from ih[OF this] and eq_cns show ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1983
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1984
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1985
      case (thread_P thread cs)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1986
      assume eq_e: "e = P thread cs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1987
      and is_runing: "thread \<in> runing s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1988
      from assms thread_P ih vt stp thread_P have vtp: "vt (P thread cs#s)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1989
      have neq_th: "th \<noteq> thread" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1990
      proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1991
        from not_in eq_e have "th \<notin> threads s" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1992
        moreover from is_runing have "thread \<in> threads s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1993
          by (simp add:runing_def readys_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1994
        ultimately show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1995
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1996
      hence "cntCS (e # s) th  = cntCS s th "
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1997
        apply (unfold cntCS_def holdents_test eq_e)
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  1998
        by (unfold step_RAG_p[OF vtp], auto)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1999
      moreover have "cntCS s th = 0"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2000
      proof(rule ih)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2001
        from not_in eq_e show "th \<notin> threads s" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2002
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2003
      ultimately show ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2004
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2005
      case (thread_V thread cs)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2006
      assume eq_e: "e = V thread cs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2007
        and is_runing: "thread \<in> runing s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2008
        and hold: "holding s thread cs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2009
      have neq_th: "th \<noteq> thread" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2010
      proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2011
        from not_in eq_e have "th \<notin> threads s" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2012
        moreover from is_runing have "thread \<in> threads s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2013
          by (simp add:runing_def readys_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2014
        ultimately show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2015
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2016
      from assms thread_V vt stp ih have vtv: "vt (V thread cs#s)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2017
      from hold obtain rest 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2018
        where eq_wq: "wq s cs = thread # rest"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2019
        by (case_tac "wq s cs", auto simp: wq_def s_holding_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2020
      from not_in eq_e eq_wq
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2021
      have "\<not> next_th s thread cs th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2022
        apply (auto simp:next_th_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2023
      proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2024
        assume ne: "rest \<noteq> []"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2025
          and ni: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> threads s" (is "?t \<notin> threads s")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2026
        have "?t \<in> set rest"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2027
        proof(rule someI2)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2028
          from wq_distinct[OF step_back_vt[OF vtv], of cs] and eq_wq
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2029
          show "distinct rest \<and> set rest = set rest" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2030
        next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2031
          fix x assume "distinct x \<and> set x = set rest" with ne
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2032
          show "hd x \<in> set rest" by (cases x, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2033
        qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2034
        with eq_wq have "?t \<in> set (wq s cs)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2035
        from wq_threads[OF step_back_vt[OF vtv], OF this] and ni
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2036
        show False by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2037
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2038
      moreover note neq_th eq_wq
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2039
      ultimately have "cntCS (e # s) th  = cntCS s th"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2040
        by (unfold eq_e cntCS_def holdents_test step_RAG_v[OF vtv], auto)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2041
      moreover have "cntCS s th = 0"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2042
      proof(rule ih)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2043
        from not_in eq_e show "th \<notin> threads s" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2044
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2045
      ultimately show ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2046
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2047
      case (thread_set thread prio)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2048
      print_facts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2049
      assume eq_e: "e = Set thread prio"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2050
        and is_runing: "thread \<in> runing s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2051
      from not_in and eq_e have "th \<notin> threads s" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2052
      from ih [OF this] and eq_e
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2053
      show ?thesis 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2054
        apply (unfold eq_e cntCS_def holdents_test)
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2055
        by (simp add:RAG_set_unchanged)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2056
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2057
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2058
      case vt_nil
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2059
      show ?case
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2060
      by (unfold cntCS_def, 
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2061
        auto simp:count_def holdents_test s_RAG_def wq_def cs_holding_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2062
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2063
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2064
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2065
lemma eq_waiting: "waiting (wq (s::state)) th cs = waiting s th cs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2066
  by (auto simp:s_waiting_def cs_waiting_def wq_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2067
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2068
lemma dm_RAG_threads:
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2069
  fixes th s
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2070
  assumes vt: "vt s"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2071
  and in_dom: "(Th th) \<in> Domain (RAG s)"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2072
  shows "th \<in> threads s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2073
proof -
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2074
  from in_dom obtain n where "(Th th, n) \<in> RAG s" by auto
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2075
  moreover from RAG_target_th[OF this] obtain cs where "n = Cs cs" by auto
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2076
  ultimately have "(Th th, Cs cs) \<in> RAG s" by simp
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2077
  hence "th \<in> set (wq s cs)"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2078
    by (unfold s_RAG_def, auto simp:cs_waiting_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2079
  from wq_threads [OF vt this] show ?thesis .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2080
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2081
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2082
lemma cp_eq_cpreced: "cp s th = cpreced (wq s) s th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2083
unfolding cp_def wq_def
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2084
apply(induct s rule: schs.induct)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2085
apply(simp add: Let_def cpreced_initial)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2086
apply(simp add: Let_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2087
apply(simp add: Let_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2088
apply(simp add: Let_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2089
apply(subst (2) schs.simps)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2090
apply(simp add: Let_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2091
apply(subst (2) schs.simps)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2092
apply(simp add: Let_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2093
done
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2094
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2095
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2096
lemma runing_unique:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2097
  fixes th1 th2 s
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2098
  assumes vt: "vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2099
  and runing_1: "th1 \<in> runing s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2100
  and runing_2: "th2 \<in> runing s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2101
  shows "th1 = th2"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2102
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2103
  from runing_1 and runing_2 have "cp s th1 = cp s th2"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2104
    by (unfold runing_def, simp)
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2105
  hence eq_max: "Max ((\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1)) =
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2106
                 Max ((\<lambda>th. preced th s) ` ({th2} \<union> dependants (wq s) th2))"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2107
    (is "Max (?f ` ?A) = Max (?f ` ?B)")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2108
    by (unfold cp_eq_cpreced cpreced_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2109
  obtain th1' where th1_in: "th1' \<in> ?A" and eq_f_th1: "?f th1' = Max (?f ` ?A)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2110
  proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2111
    have h1: "finite (?f ` ?A)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2112
    proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2113
      have "finite ?A" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2114
      proof -
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2115
        have "finite (dependants (wq s) th1)"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2116
        proof-
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2117
          have "finite {th'. (Th th', Th th1) \<in> (RAG (wq s))\<^sup>+}"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2118
          proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2119
            let ?F = "\<lambda> (x, y). the_th x"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2120
            have "{th'. (Th th', Th th1) \<in> (RAG (wq s))\<^sup>+} \<subseteq> ?F ` ((RAG (wq s))\<^sup>+)"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2121
              apply (auto simp:image_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2122
              by (rule_tac x = "(Th x, Th th1)" in bexI, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2123
            moreover have "finite \<dots>"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2124
            proof -
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2125
              from finite_RAG[OF vt] have "finite (RAG s)" .
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2126
              hence "finite ((RAG (wq s))\<^sup>+)"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2127
                apply (unfold finite_trancl)
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2128
                by (auto simp: s_RAG_def cs_RAG_def wq_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2129
              thus ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2130
            qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2131
            ultimately show ?thesis by (auto intro:finite_subset)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2132
          qed
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2133
          thus ?thesis by (simp add:cs_dependants_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2134
        qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2135
        thus ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2136
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2137
      thus ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2138
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2139
    moreover have h2: "(?f ` ?A) \<noteq> {}"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2140
    proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2141
      have "?A \<noteq> {}" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2142
      thus ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2143
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2144
    from Max_in [OF h1 h2]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2145
    have "Max (?f ` ?A) \<in> (?f ` ?A)" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2146
    thus ?thesis by (auto intro:that)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2147
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2148
  obtain th2' where th2_in: "th2' \<in> ?B" and eq_f_th2: "?f th2' = Max (?f ` ?B)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2149
  proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2150
    have h1: "finite (?f ` ?B)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2151
    proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2152
      have "finite ?B" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2153
      proof -
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2154
        have "finite (dependants (wq s) th2)"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2155
        proof-
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2156
          have "finite {th'. (Th th', Th th2) \<in> (RAG (wq s))\<^sup>+}"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2157
          proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2158
            let ?F = "\<lambda> (x, y). the_th x"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2159
            have "{th'. (Th th', Th th2) \<in> (RAG (wq s))\<^sup>+} \<subseteq> ?F ` ((RAG (wq s))\<^sup>+)"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2160
              apply (auto simp:image_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2161
              by (rule_tac x = "(Th x, Th th2)" in bexI, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2162
            moreover have "finite \<dots>"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2163
            proof -
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2164
              from finite_RAG[OF vt] have "finite (RAG s)" .
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2165
              hence "finite ((RAG (wq s))\<^sup>+)"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2166
                apply (unfold finite_trancl)
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2167
                by (auto simp: s_RAG_def cs_RAG_def wq_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2168
              thus ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2169
            qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2170
            ultimately show ?thesis by (auto intro:finite_subset)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2171
          qed
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2172
          thus ?thesis by (simp add:cs_dependants_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2173
        qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2174
        thus ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2175
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2176
      thus ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2177
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2178
    moreover have h2: "(?f ` ?B) \<noteq> {}"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2179
    proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2180
      have "?B \<noteq> {}" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2181
      thus ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2182
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2183
    from Max_in [OF h1 h2]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2184
    have "Max (?f ` ?B) \<in> (?f ` ?B)" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2185
    thus ?thesis by (auto intro:that)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2186
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2187
  from eq_f_th1 eq_f_th2 eq_max 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2188
  have eq_preced: "preced th1' s = preced th2' s" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2189
  hence eq_th12: "th1' = th2'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2190
  proof (rule preced_unique)
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2191
    from th1_in have "th1' = th1 \<or> (th1' \<in> dependants (wq s) th1)" by simp
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2192
    thus "th1' \<in> threads s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2193
    proof
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2194
      assume "th1' \<in> dependants (wq s) th1"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2195
      hence "(Th th1') \<in> Domain ((RAG s)^+)"
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2196
        apply (unfold cs_dependants_def cs_RAG_def s_RAG_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2197
        by (auto simp:Domain_def)
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2198
      hence "(Th th1') \<in> Domain (RAG s)" by (simp add:trancl_domain)
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2199
      from dm_RAG_threads[OF vt this] show ?thesis .
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2200
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2201
      assume "th1' = th1"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2202
      with runing_1 show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2203
        by (unfold runing_def readys_def, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2204
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2205
  next
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2206
    from th2_in have "th2' = th2 \<or> (th2' \<in> dependants (wq s) th2)" by simp
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2207
    thus "th2' \<in> threads s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2208
    proof
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2209
      assume "th2' \<in> dependants (wq s) th2"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2210
      hence "(Th th2') \<in> Domain ((RAG s)^+)"
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2211
        apply (unfold cs_dependants_def cs_RAG_def s_RAG_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2212
        by (auto simp:Domain_def)
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2213
      hence "(Th th2') \<in> Domain (RAG s)" by (simp add:trancl_domain)
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2214
      from dm_RAG_threads[OF vt this] show ?thesis .
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2215
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2216
      assume "th2' = th2"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2217
      with runing_2 show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2218
        by (unfold runing_def readys_def, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2219
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2220
  qed
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2221
  from th1_in have "th1' = th1 \<or> th1' \<in> dependants (wq s) th1" by simp
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2222
  thus ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2223
  proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2224
    assume eq_th': "th1' = th1"
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2225
    from th2_in have "th2' = th2 \<or> th2' \<in> dependants (wq s) th2" by simp
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2226
    thus ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2227
    proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2228
      assume "th2' = th2" thus ?thesis using eq_th' eq_th12 by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2229
    next
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2230
      assume "th2' \<in> dependants (wq s) th2"
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2231
      with eq_th12 eq_th' have "th1 \<in> dependants (wq s) th2" by simp
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2232
      hence "(Th th1, Th th2) \<in> (RAG s)^+"
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2233
        by (unfold cs_dependants_def s_RAG_def cs_RAG_def, simp)
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2234
      hence "Th th1 \<in> Domain ((RAG s)^+)" 
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2235
        apply (unfold cs_dependants_def cs_RAG_def s_RAG_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2236
        by (auto simp:Domain_def)
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2237
      hence "Th th1 \<in> Domain (RAG s)" by (simp add:trancl_domain)
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2238
      then obtain n where d: "(Th th1, n) \<in> RAG s" by (auto simp:Domain_def)
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2239
      from RAG_target_th [OF this]
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2240
      obtain cs' where "n = Cs cs'" by auto
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2241
      with d have "(Th th1, Cs cs') \<in> RAG s" by simp
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2242
      with runing_1 have "False"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2243
        apply (unfold runing_def readys_def s_RAG_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2244
        by (auto simp:eq_waiting)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2245
      thus ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2246
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2247
  next
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2248
    assume th1'_in: "th1' \<in> dependants (wq s) th1"
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2249
    from th2_in have "th2' = th2 \<or> th2' \<in> dependants (wq s) th2" by simp
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2250
    thus ?thesis 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2251
    proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2252
      assume "th2' = th2"
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2253
      with th1'_in eq_th12 have "th2 \<in> dependants (wq s) th1" by simp
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2254
      hence "(Th th2, Th th1) \<in> (RAG s)^+"
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2255
        by (unfold cs_dependants_def s_RAG_def cs_RAG_def, simp)
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2256
      hence "Th th2 \<in> Domain ((RAG s)^+)" 
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2257
        apply (unfold cs_dependants_def cs_RAG_def s_RAG_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2258
        by (auto simp:Domain_def)
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2259
      hence "Th th2 \<in> Domain (RAG s)" by (simp add:trancl_domain)
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2260
      then obtain n where d: "(Th th2, n) \<in> RAG s" by (auto simp:Domain_def)
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2261
      from RAG_target_th [OF this]
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2262
      obtain cs' where "n = Cs cs'" by auto
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2263
      with d have "(Th th2, Cs cs') \<in> RAG s" by simp
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2264
      with runing_2 have "False"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2265
        apply (unfold runing_def readys_def s_RAG_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2266
        by (auto simp:eq_waiting)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2267
      thus ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2268
    next
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2269
      assume "th2' \<in> dependants (wq s) th2"
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2270
      with eq_th12 have "th1' \<in> dependants (wq s) th2" by simp
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2271
      hence h1: "(Th th1', Th th2) \<in> (RAG s)^+"
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2272
        by (unfold cs_dependants_def s_RAG_def cs_RAG_def, simp)
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2273
      from th1'_in have h2: "(Th th1', Th th1) \<in> (RAG s)^+"
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2274
        by (unfold cs_dependants_def s_RAG_def cs_RAG_def, simp)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2275
      show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2276
      proof(rule dchain_unique[OF vt h1 _ h2, symmetric])
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2277
        from runing_1 show "th1 \<in> readys s" by (simp add:runing_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2278
        from runing_2 show "th2 \<in> readys s" by (simp add:runing_def) 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2279
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2280
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2281
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2282
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2283
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2284
lemma create_pre:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2285
  assumes stp: "step s e"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2286
  and not_in: "th \<notin> threads s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2287
  and is_in: "th \<in> threads (e#s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2288
  obtains prio where "e = Create th prio"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2289
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2290
  from assms  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2291
  show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2292
  proof(cases)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2293
    case (thread_create thread prio)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2294
    with is_in not_in have "e = Create th prio" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2295
    from that[OF this] show ?thesis .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2296
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2297
    case (thread_exit thread)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2298
    with assms show ?thesis by (auto intro!:that)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2299
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2300
    case (thread_P thread)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2301
    with assms show ?thesis by (auto intro!:that)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2302
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2303
    case (thread_V thread)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2304
    with assms show ?thesis by (auto intro!:that)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2305
  next 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2306
    case (thread_set thread)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2307
    with assms show ?thesis by (auto intro!:that)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2308
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2309
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2310
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2311
lemma length_down_to_in: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2312
  assumes le_ij: "i \<le> j"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2313
    and le_js: "j \<le> length s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2314
  shows "length (down_to j i s) = j - i"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2315
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2316
  have "length (down_to j i s) = length (from_to i j (rev s))"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2317
    by (unfold down_to_def, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2318
  also have "\<dots> = j - i"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2319
  proof(rule length_from_to_in[OF le_ij])
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2320
    from le_js show "j \<le> length (rev s)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2321
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2322
  finally show ?thesis .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2323
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2324
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2325
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2326
lemma moment_head: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2327
  assumes le_it: "Suc i \<le> length t"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2328
  obtains e where "moment (Suc i) t = e#moment i t"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2329
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2330
  have "i \<le> Suc i" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2331
  from length_down_to_in [OF this le_it]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2332
  have "length (down_to (Suc i) i t) = 1" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2333
  then obtain e where "down_to (Suc i) i t = [e]"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2334
    apply (cases "(down_to (Suc i) i t)") by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2335
  moreover have "down_to (Suc i) 0 t = down_to (Suc i) i t @ down_to i 0 t"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2336
    by (rule down_to_conc[symmetric], auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2337
  ultimately have eq_me: "moment (Suc i) t = e#(moment i t)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2338
    by (auto simp:down_to_moment)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2339
  from that [OF this] show ?thesis .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2340
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2341
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2342
lemma cnp_cnv_eq:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2343
  fixes th s
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2344
  assumes "vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2345
  and "th \<notin> threads s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2346
  shows "cntP s th = cntV s th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2347
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2348
  from assms show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2349
  proof(induct)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2350
    case (vt_cons s e)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2351
    have ih: "th \<notin> threads s \<Longrightarrow> cntP s th = cntV s th" by fact
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2352
    have not_in: "th \<notin> threads (e # s)" by fact
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2353
    have "step s e" by fact
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2354
    thus ?case proof(cases)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2355
      case (thread_create thread prio)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2356
      assume eq_e: "e = Create thread prio"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2357
      hence "thread \<in> threads (e#s)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2358
      with not_in and eq_e have "th \<notin> threads s" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2359
      from ih [OF this] show ?thesis using eq_e
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2360
        by (auto simp:cntP_def cntV_def count_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2361
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2362
      case (thread_exit thread)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2363
      assume eq_e: "e = Exit thread"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2364
        and not_holding: "holdents s thread = {}"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2365
      have vt_s: "vt s" by fact
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2366
      from finite_holding[OF vt_s] have "finite (holdents s thread)" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2367
      with not_holding have "cntCS s thread = 0" by (unfold cntCS_def, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2368
      moreover have "thread \<in> readys s" using thread_exit by (auto simp:runing_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2369
      moreover note cnp_cnv_cncs[OF vt_s, of thread]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2370
      ultimately have eq_thread: "cntP s thread = cntV s thread" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2371
      show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2372
      proof(cases "th = thread")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2373
        case True
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2374
        with eq_thread eq_e show ?thesis 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2375
          by (auto simp:cntP_def cntV_def count_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2376
      next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2377
        case False
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2378
        with not_in and eq_e have "th \<notin> threads s" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2379
        from ih[OF this] and eq_e show ?thesis 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2380
           by (auto simp:cntP_def cntV_def count_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2381
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2382
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2383
      case (thread_P thread cs)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2384
      assume eq_e: "e = P thread cs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2385
      have "thread \<in> runing s" by fact
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2386
      with not_in eq_e have neq_th: "thread \<noteq> th" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2387
        by (auto simp:runing_def readys_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2388
      from not_in eq_e have "th \<notin> threads s" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2389
      from ih[OF this] and neq_th and eq_e show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2390
        by (auto simp:cntP_def cntV_def count_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2391
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2392
      case (thread_V thread cs)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2393
      assume eq_e: "e = V thread cs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2394
      have "thread \<in> runing s" by fact
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2395
      with not_in eq_e have neq_th: "thread \<noteq> th" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2396
        by (auto simp:runing_def readys_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2397
      from not_in eq_e have "th \<notin> threads s" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2398
      from ih[OF this] and neq_th and eq_e show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2399
        by (auto simp:cntP_def cntV_def count_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2400
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2401
      case (thread_set thread prio)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2402
      assume eq_e: "e = Set thread prio"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2403
        and "thread \<in> runing s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2404
      hence "thread \<in> threads (e#s)" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2405
        by (simp add:runing_def readys_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2406
      with not_in and eq_e have "th \<notin> threads s" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2407
      from ih [OF this] show ?thesis using eq_e
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2408
        by (auto simp:cntP_def cntV_def count_def)  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2409
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2410
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2411
    case vt_nil
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2412
    show ?case by (auto simp:cntP_def cntV_def count_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2413
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2414
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2415
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2416
lemma eq_RAG: 
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2417
  "RAG (wq s) = RAG s"
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2418
by (unfold cs_RAG_def s_RAG_def, auto)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2419
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2420
lemma count_eq_dependants:
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2421
  assumes vt: "vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2422
  and eq_pv: "cntP s th = cntV s th"
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2423
  shows "dependants (wq s) th = {}"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2424
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2425
  from cnp_cnv_cncs[OF vt] and eq_pv
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2426
  have "cntCS s th = 0" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2427
    by (auto split:if_splits)
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2428
  moreover have "finite {cs. (Cs cs, Th th) \<in> RAG s}"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2429
  proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2430
    from finite_holding[OF vt, of th] show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2431
      by (simp add:holdents_test)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2432
  qed
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2433
  ultimately have h: "{cs. (Cs cs, Th th) \<in> RAG s} = {}"
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2434
    by (unfold cntCS_def holdents_test cs_dependants_def, auto)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2435
  show ?thesis
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2436
  proof(unfold cs_dependants_def)
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2437
    { assume "{th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+} \<noteq> {}"
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2438
      then obtain th' where "(Th th', Th th) \<in> (RAG (wq s))\<^sup>+" by auto
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2439
      hence "False"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2440
      proof(cases)
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2441
        assume "(Th th', Th th) \<in> RAG (wq s)"
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2442
        thus "False" by (auto simp:cs_RAG_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2443
      next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2444
        fix c
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2445
        assume "(c, Th th) \<in> RAG (wq s)"
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2446
        with h and eq_RAG show "False"
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2447
          by (cases c, auto simp:cs_RAG_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2448
      qed
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2449
    } thus "{th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+} = {}" by auto
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2450
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2451
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2452
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2453
lemma dependants_threads:
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2454
  fixes s th
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2455
  assumes vt: "vt s"
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2456
  shows "dependants (wq s) th \<subseteq> threads s"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2457
proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2458
  { fix th th'
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2459
    assume h: "th \<in> {th'a. (Th th'a, Th th') \<in> (RAG (wq s))\<^sup>+}"
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2460
    have "Th th \<in> Domain (RAG s)"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2461
    proof -
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2462
      from h obtain th' where "(Th th, Th th') \<in> (RAG (wq s))\<^sup>+" by auto
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2463
      hence "(Th th) \<in> Domain ( (RAG (wq s))\<^sup>+)" by (auto simp:Domain_def)
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2464
      with trancl_domain have "(Th th) \<in> Domain (RAG (wq s))" by simp
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2465
      thus ?thesis using eq_RAG by simp
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2466
    qed
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2467
    from dm_RAG_threads[OF vt this]
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2468
    have "th \<in> threads s" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2469
  } note hh = this
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2470
  fix th1 
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2471
  assume "th1 \<in> dependants (wq s) th"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2472
  hence "th1 \<in> {th'a. (Th th'a, Th th) \<in> (RAG (wq s))\<^sup>+}"
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2473
    by (unfold cs_dependants_def, simp)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2474
  from hh [OF this] show "th1 \<in> threads s" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2475
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2476
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2477
lemma finite_threads:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2478
  assumes vt: "vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2479
  shows "finite (threads s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2480
using vt
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2481
by (induct) (auto elim: step.cases)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2482
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2483
lemma Max_f_mono:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2484
  assumes seq: "A \<subseteq> B"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2485
  and np: "A \<noteq> {}"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2486
  and fnt: "finite B"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2487
  shows "Max (f ` A) \<le> Max (f ` B)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2488
proof(rule Max_mono)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2489
  from seq show "f ` A \<subseteq> f ` B" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2490
next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2491
  from np show "f ` A \<noteq> {}" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2492
next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2493
  from fnt and seq show "finite (f ` B)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2494
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2495
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2496
lemma cp_le:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2497
  assumes vt: "vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2498
  and th_in: "th \<in> threads s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2499
  shows "cp s th \<le> Max ((\<lambda> th. (preced th s)) ` threads s)"
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2500
proof(unfold cp_eq_cpreced cpreced_def cs_dependants_def)
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2501
  show "Max ((\<lambda>th. preced th s) ` ({th} \<union> {th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+}))
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2502
         \<le> Max ((\<lambda>th. preced th s) ` threads s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2503
    (is "Max (?f ` ?A) \<le> Max (?f ` ?B)")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2504
  proof(rule Max_f_mono)
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2505
    show "{th} \<union> {th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+} \<noteq> {}" by simp
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2506
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2507
    from finite_threads [OF vt]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2508
    show "finite (threads s)" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2509
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2510
    from th_in
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2511
    show "{th} \<union> {th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+} \<subseteq> threads s"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2512
      apply (auto simp:Domain_def)
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2513
      apply (rule_tac dm_RAG_threads[OF vt])
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2514
      apply (unfold trancl_domain [of "RAG s", symmetric])
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2515
      by (unfold cs_RAG_def s_RAG_def, auto simp:Domain_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2516
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2517
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2518
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2519
lemma le_cp:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2520
  assumes vt: "vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2521
  shows "preced th s \<le> cp s th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2522
proof(unfold cp_eq_cpreced preced_def cpreced_def, simp)
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2523
  show "Prc (priority th s) (last_set th s)
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2524
    \<le> Max (insert (Prc (priority th s) (last_set th s))
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2525
            ((\<lambda>th. Prc (priority th s) (last_set th s)) ` dependants (wq s) th))"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2526
    (is "?l \<le> Max (insert ?l ?A)")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2527
  proof(cases "?A = {}")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2528
    case False
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2529
    have "finite ?A" (is "finite (?f ` ?B)")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2530
    proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2531
      have "finite ?B" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2532
      proof-
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2533
        have "finite {th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+}"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2534
        proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2535
          let ?F = "\<lambda> (x, y). the_th x"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2536
          have "{th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+} \<subseteq> ?F ` ((RAG (wq s))\<^sup>+)"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2537
            apply (auto simp:image_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2538
            by (rule_tac x = "(Th x, Th th)" in bexI, auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2539
          moreover have "finite \<dots>"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2540
          proof -
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2541
            from finite_RAG[OF vt] have "finite (RAG s)" .
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2542
            hence "finite ((RAG (wq s))\<^sup>+)"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2543
              apply (unfold finite_trancl)
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2544
              by (auto simp: s_RAG_def cs_RAG_def wq_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2545
            thus ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2546
          qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2547
          ultimately show ?thesis by (auto intro:finite_subset)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2548
        qed
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2549
        thus ?thesis by (simp add:cs_dependants_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2550
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2551
      thus ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2552
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2553
    from Max_insert [OF this False, of ?l] show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2554
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2555
    case True
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2556
    thus ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2557
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2558
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2559
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2560
lemma max_cp_eq: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2561
  assumes vt: "vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2562
  shows "Max ((cp s) ` threads s) = Max ((\<lambda> th. (preced th s)) ` threads s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2563
  (is "?l = ?r")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2564
proof(cases "threads s = {}")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2565
  case True
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2566
  thus ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2567
next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2568
  case False
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2569
  have "?l \<in> ((cp s) ` threads s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2570
  proof(rule Max_in)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2571
    from finite_threads[OF vt] 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2572
    show "finite (cp s ` threads s)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2573
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2574
    from False show "cp s ` threads s \<noteq> {}" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2575
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2576
  then obtain th 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2577
    where th_in: "th \<in> threads s" and eq_l: "?l = cp s th" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2578
  have "\<dots> \<le> ?r" by (rule cp_le[OF vt th_in])
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2579
  moreover have "?r \<le> cp s th" (is "Max (?f ` ?A) \<le> cp s th")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2580
  proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2581
    have "?r \<in> (?f ` ?A)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2582
    proof(rule Max_in)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2583
      from finite_threads[OF vt]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2584
      show " finite ((\<lambda>th. preced th s) ` threads s)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2585
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2586
      from False show " (\<lambda>th. preced th s) ` threads s \<noteq> {}" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2587
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2588
    then obtain th' where 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2589
      th_in': "th' \<in> ?A " and eq_r: "?r = ?f th'" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2590
    from le_cp [OF vt, of th']  eq_r
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2591
    have "?r \<le> cp s th'" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2592
    moreover have "\<dots> \<le> cp s th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2593
    proof(fold eq_l)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2594
      show " cp s th' \<le> Max (cp s ` threads s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2595
      proof(rule Max_ge)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2596
        from th_in' show "cp s th' \<in> cp s ` threads s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2597
          by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2598
      next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2599
        from finite_threads[OF vt]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2600
        show "finite (cp s ` threads s)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2601
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2602
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2603
    ultimately show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2604
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2605
  ultimately show ?thesis using eq_l by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2606
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2607
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2608
lemma max_cp_readys_threads_pre:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2609
  assumes vt: "vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2610
  and np: "threads s \<noteq> {}"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2611
  shows "Max (cp s ` readys s) = Max (cp s ` threads s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2612
proof(unfold max_cp_eq[OF vt])
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2613
  show "Max (cp s ` readys s) = Max ((\<lambda>th. preced th s) ` threads s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2614
  proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2615
    let ?p = "Max ((\<lambda>th. preced th s) ` threads s)" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2616
    let ?f = "(\<lambda>th. preced th s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2617
    have "?p \<in> ((\<lambda>th. preced th s) ` threads s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2618
    proof(rule Max_in)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2619
      from finite_threads[OF vt] show "finite (?f ` threads s)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2620
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2621
      from np show "?f ` threads s \<noteq> {}" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2622
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2623
    then obtain tm where tm_max: "?f tm = ?p" and tm_in: "tm \<in> threads s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2624
      by (auto simp:Image_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2625
    from th_chain_to_ready [OF vt tm_in]
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2626
    have "tm \<in> readys s \<or> (\<exists>th'. th' \<in> readys s \<and> (Th tm, Th th') \<in> (RAG s)\<^sup>+)" .
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2627
    thus ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2628
    proof
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2629
      assume "\<exists>th'. th' \<in> readys s \<and> (Th tm, Th th') \<in> (RAG s)\<^sup>+ "
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2630
      then obtain th' where th'_in: "th' \<in> readys s" 
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2631
        and tm_chain:"(Th tm, Th th') \<in> (RAG s)\<^sup>+" by auto
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2632
      have "cp s th' = ?f tm"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2633
      proof(subst cp_eq_cpreced, subst cpreced_def, rule Max_eqI)
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2634
        from dependants_threads[OF vt] finite_threads[OF vt]
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2635
        show "finite ((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th'))" 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2636
          by (auto intro:finite_subset)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2637
      next
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2638
        fix p assume p_in: "p \<in> (\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2639
        from tm_max have " preced tm s = Max ((\<lambda>th. preced th s) ` threads s)" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2640
        moreover have "p \<le> \<dots>"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2641
        proof(rule Max_ge)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2642
          from finite_threads[OF vt]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2643
          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
  2644
        next
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2645
          from p_in and th'_in and dependants_threads[OF vt, of th']
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2646
          show "p \<in> (\<lambda>th. preced th s) ` threads s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2647
            by (auto simp:readys_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2648
        qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2649
        ultimately show "p \<le> preced tm s" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2650
      next
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2651
        show "preced tm s \<in> (\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2652
        proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2653
          from tm_chain
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2654
          have "tm \<in> dependants (wq s) th'"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2655
            by (unfold cs_dependants_def s_RAG_def cs_RAG_def, auto)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2656
          thus ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2657
        qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2658
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2659
      with tm_max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2660
      have h: "cp s th' = Max ((\<lambda>th. preced th s) ` threads s)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2661
      show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2662
      proof (fold h, rule Max_eqI)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2663
        fix q 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2664
        assume "q \<in> cp s ` readys s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2665
        then obtain th1 where th1_in: "th1 \<in> readys s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2666
          and eq_q: "q = cp s th1" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2667
        show "q \<le> cp s th'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2668
          apply (unfold h eq_q)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2669
          apply (unfold cp_eq_cpreced cpreced_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2670
          apply (rule Max_mono)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2671
        proof -
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2672
          from dependants_threads [OF vt, of th1] th1_in
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2673
          show "(\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1) \<subseteq> 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2674
                 (\<lambda>th. preced th s) ` threads s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2675
            by (auto simp:readys_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2676
        next
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2677
          show "(\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1) \<noteq> {}" by simp
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2678
        next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2679
          from finite_threads[OF vt] 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2680
          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
  2681
        qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2682
      next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2683
        from finite_threads[OF vt]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2684
        show "finite (cp s ` readys s)" by (auto simp:readys_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2685
      next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2686
        from th'_in
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2687
        show "cp s th' \<in> cp s ` readys s" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2688
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2689
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2690
      assume tm_ready: "tm \<in> readys s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2691
      show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2692
      proof(fold tm_max)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2693
        have cp_eq_p: "cp s tm = preced tm s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2694
        proof(unfold cp_eq_cpreced cpreced_def, rule Max_eqI)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2695
          fix y 
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2696
          assume hy: "y \<in> (\<lambda>th. preced th s) ` ({tm} \<union> dependants (wq s) tm)"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2697
          show "y \<le> preced tm s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2698
          proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2699
            { fix y'
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2700
              assume hy' : "y' \<in> ((\<lambda>th. preced th s) ` dependants (wq s) tm)"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2701
              have "y' \<le> preced tm s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2702
              proof(unfold tm_max, rule Max_ge)
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2703
                from hy' dependants_threads[OF vt, of tm]
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2704
                show "y' \<in> (\<lambda>th. preced th s) ` threads s" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2705
              next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2706
                from finite_threads[OF vt] 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2707
                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
  2708
              qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2709
            } with hy show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2710
          qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2711
        next
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2712
          from dependants_threads[OF vt, of tm] finite_threads[OF vt]
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2713
          show "finite ((\<lambda>th. preced th s) ` ({tm} \<union> dependants (wq s) tm))"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2714
            by (auto intro:finite_subset)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2715
        next
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2716
          show "preced tm s \<in> (\<lambda>th. preced th s) ` ({tm} \<union> dependants (wq s) tm)"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2717
            by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2718
        qed 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2719
        moreover have "Max (cp s ` readys s) = cp s tm"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2720
        proof(rule Max_eqI)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2721
          from tm_ready show "cp s tm \<in> cp s ` readys s" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2722
        next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2723
          from finite_threads[OF vt]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2724
          show "finite (cp s ` readys s)" by (auto simp:readys_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2725
        next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2726
          fix y assume "y \<in> cp s ` readys s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2727
          then obtain th1 where th1_readys: "th1 \<in> readys s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2728
            and h: "y = cp s th1" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2729
          show "y \<le> cp s tm"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2730
            apply(unfold cp_eq_p h)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2731
            apply(unfold cp_eq_cpreced cpreced_def tm_max, rule Max_mono)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2732
          proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2733
            from finite_threads[OF vt]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2734
            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
  2735
          next
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2736
            show "(\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1) \<noteq> {}"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2737
              by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2738
          next
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2739
            from dependants_threads[OF vt, of th1] th1_readys
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3
diff changeset
  2740
            show "(\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1) 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2741
                    \<subseteq> (\<lambda>th. preced th s) ` threads s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2742
              by (auto simp:readys_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2743
          qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2744
        qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2745
        ultimately show " Max (cp s ` readys s) = preced tm s" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2746
      qed 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2747
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2748
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2749
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2750
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2751
lemma max_cp_readys_threads:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2752
  assumes vt: "vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2753
  shows "Max (cp s ` readys s) = Max (cp s ` threads s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2754
proof(cases "threads s = {}")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2755
  case True
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2756
  thus ?thesis 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2757
    by (auto simp:readys_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2758
next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2759
  case False
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2760
  show ?thesis by (rule max_cp_readys_threads_pre[OF vt False])
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2761
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2762
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2763
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2764
lemma eq_holding: "holding (wq s) th cs = holding s th cs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2765
  apply (unfold s_holding_def cs_holding_def wq_def, simp)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2766
  done
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2767
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2768
lemma f_image_eq:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2769
  assumes h: "\<And> a. a \<in> A \<Longrightarrow> f a = g a"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2770
  shows "f ` A = g ` A"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2771
proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2772
  show "f ` A \<subseteq> g ` A"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2773
    by(rule image_subsetI, auto intro:h)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2774
next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2775
  show "g ` A \<subseteq> f ` A"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2776
   by (rule image_subsetI, auto intro:h[symmetric])
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2777
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2778
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2779
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2780
definition detached :: "state \<Rightarrow> thread \<Rightarrow> bool"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2781
  where "detached s th \<equiv> (\<not>(\<exists> cs. holding s th cs)) \<and> (\<not>(\<exists>cs. waiting s th cs))"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2782
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2783
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2784
lemma detached_test:
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2785
  shows "detached s th = (Th th \<notin> Field (RAG s))"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2786
apply(simp add: detached_def Field_def)
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2787
apply(simp add: s_RAG_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2788
apply(simp add: s_holding_abv s_waiting_abv)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2789
apply(simp add: Domain_iff Range_iff)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2790
apply(simp add: wq_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2791
apply(auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2792
done
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2793
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2794
lemma detached_intro:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2795
  fixes s th
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2796
  assumes vt: "vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2797
  and eq_pv: "cntP s th = cntV s th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2798
  shows "detached s th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2799
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2800
 from cnp_cnv_cncs[OF vt]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2801
  have eq_cnt: "cntP s th =
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2802
    cntV s th + (if th \<in> readys s \<or> th \<notin> threads s then cntCS s th else cntCS s th + 1)" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2803
  hence cncs_zero: "cntCS s th = 0"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2804
    by (auto simp:eq_pv split:if_splits)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2805
  with eq_cnt
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2806
  have "th \<in> readys s \<or> th \<notin> threads s" by (auto simp:eq_pv)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2807
  thus ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2808
  proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2809
    assume "th \<notin> threads s"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2810
    with range_in[OF vt] dm_RAG_threads[OF vt]
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2811
    show ?thesis
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2812
      by (auto simp add: detached_def s_RAG_def s_waiting_abv s_holding_abv wq_def Domain_iff Range_iff)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2813
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2814
    assume "th \<in> readys s"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2815
    moreover have "Th th \<notin> Range (RAG s)"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2816
    proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2817
      from card_0_eq [OF finite_holding [OF vt]] and cncs_zero
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2818
      have "holdents s th = {}"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2819
        by (simp add:cntCS_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2820
      thus ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2821
        apply(auto simp:holdents_test)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2822
        apply(case_tac a)
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2823
        apply(auto simp:holdents_test s_RAG_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2824
        done
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2825
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2826
    ultimately show ?thesis
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2827
      by (auto simp add: detached_def s_RAG_def s_waiting_abv s_holding_abv wq_def readys_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2828
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2829
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2830
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2831
lemma detached_elim:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2832
  fixes s th
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2833
  assumes vt: "vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2834
  and dtc: "detached s th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2835
  shows "cntP s th = cntV s th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2836
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2837
  from cnp_cnv_cncs[OF vt]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2838
  have eq_pv: " cntP s th =
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2839
    cntV s th + (if th \<in> readys s \<or> th \<notin> threads s then cntCS s th else cntCS s th + 1)" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2840
  have cncs_z: "cntCS s th = 0"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2841
  proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2842
    from dtc have "holdents s th = {}"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2843
      unfolding detached_def holdents_test s_RAG_def
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2844
      by (simp add: s_waiting_abv wq_def s_holding_abv Domain_iff Range_iff)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2845
    thus ?thesis by (auto simp:cntCS_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2846
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2847
  show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2848
  proof(cases "th \<in> threads s")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2849
    case True
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2850
    with dtc 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2851
    have "th \<in> readys s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2852
      by (unfold readys_def detached_def Field_def Domain_def Range_def, 
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2853
           auto simp:eq_waiting s_RAG_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2854
    with cncs_z and eq_pv show ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2855
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2856
    case False
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2857
    with cncs_z and eq_pv show ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2858
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2859
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2860
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2861
lemma detached_eq:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2862
  fixes s th
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2863
  assumes vt: "vt s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2864
  shows "(detached s th) = (cntP s th = cntV s th)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2865
  by (insert vt, auto intro:detached_intro detached_elim)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2866
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
  2867
end