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