CpsG.thy~
author zhangx
Sat, 16 Jan 2016 10:59:03 +0800
changeset 77 d37703e0c5c4
parent 73 b0054fb0d1ce
child 79 8067efcb43da
permissions -rw-r--r--
CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
     1
theory CpsG
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
     2
imports PIPDefs 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
     3
begin
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
     4
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
     5
lemma Max_f_mono:
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
     6
  assumes seq: "A \<subseteq> B"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
     7
  and np: "A \<noteq> {}"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
     8
  and fnt: "finite B"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
     9
  shows "Max (f ` A) \<le> Max (f ` B)"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
    10
proof(rule Max_mono)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
    11
  from seq show "f ` A \<subseteq> f ` B" by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
    12
next
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
    13
  from np show "f ` A \<noteq> {}" by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
    14
next
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
    15
  from fnt and seq show "finite (f ` B)" by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
    16
qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
    17
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    18
(* I am going to use this file as a start point to retrofiting 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    19
   PIPBasics.thy, which is originally called CpsG.ghy *)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    20
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    21
locale valid_trace = 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    22
  fixes s
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    23
  assumes vt : "vt s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    24
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
    25
lemma waiting_eq: "waiting s th cs = waiting (wq s) th cs"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
    26
  by  (unfold s_waiting_def cs_waiting_def wq_def, auto)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
    27
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
    28
lemma holding_eq: "holding (s::state) th cs = holding (wq s) th cs"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
    29
  by (unfold s_holding_def wq_def cs_holding_def, simp)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
    30
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
    31
thm s_waiting_def cs_waiting_def wq_def
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
    32
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    33
locale valid_trace_e = valid_trace +
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    34
  fixes e
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    35
  assumes vt_e: "vt (e#s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    36
begin
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    37
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    38
lemma pip_e: "PIP s e"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    39
  using vt_e by (cases, simp)  
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    40
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    41
end
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    42
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    43
lemma runing_ready: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    44
  shows "runing s \<subseteq> readys s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    45
  unfolding runing_def readys_def
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    46
  by auto 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    47
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    48
lemma readys_threads:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    49
  shows "readys s \<subseteq> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    50
  unfolding readys_def
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    51
  by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    52
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    53
lemma wq_v_neq [simp]:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    54
   "cs \<noteq> cs' \<Longrightarrow> wq (V thread cs#s) cs' = wq s cs'"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    55
  by (auto simp:wq_def Let_def cp_def split:list.splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    56
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    57
lemma runing_head:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    58
  assumes "th \<in> runing s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    59
  and "th \<in> set (wq_fun (schs s) cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    60
  shows "th = hd (wq_fun (schs s) cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    61
  using assms
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    62
  by (simp add:runing_def readys_def s_waiting_def wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    63
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    64
context valid_trace
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    65
begin
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    66
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    67
lemma actor_inv: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    68
  assumes "PIP s e"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    69
  and "\<not> isCreate e"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    70
  shows "actor e \<in> runing s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    71
  using assms
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    72
  by (induct, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    74
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    75
lemma isP_E:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    76
  assumes "isP e"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    77
  obtains cs where "e = P (actor e) cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    78
  using assms by (cases e, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    79
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    80
lemma isV_E:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    81
  assumes "isV e"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    82
  obtains cs where "e = V (actor e) cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    83
  using assms by (cases e, auto) 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    84
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    85
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    86
lemma ind [consumes 0, case_names Nil Cons, induct type]:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    87
  assumes "PP []"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    88
     and "(\<And>s e. valid_trace s \<Longrightarrow> valid_trace (e#s) \<Longrightarrow>
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    89
                   PP s \<Longrightarrow> PIP s e \<Longrightarrow> PP (e # s))"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    90
     shows "PP s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    91
proof(rule vt.induct[OF vt])
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    92
  from assms(1) show "PP []" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    93
next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    94
  fix s e
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    95
  assume h: "vt s" "PP s" "PIP s e"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    96
  show "PP (e # s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    97
  proof(cases rule:assms(2))
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    98
    from h(1) show v1: "valid_trace s" by (unfold_locales, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    99
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   100
    from h(1,3) have "vt (e#s)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   101
    thus "valid_trace (e # s)" by (unfold_locales, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   102
  qed (insert h, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   103
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   104
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   105
lemma wq_distinct: "distinct (wq s cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   106
proof(induct rule:ind)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   107
  case (Cons s e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   108
  from Cons(4,3)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   109
  show ?case 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   110
  proof(induct)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   111
    case (thread_P th s cs1)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   112
    show ?case 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   113
    proof(cases "cs = cs1")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   114
      case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   115
      thus ?thesis (is "distinct ?L")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   116
      proof - 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   117
        have "?L = wq_fun (schs s) cs1 @ [th]" using True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   118
          by (simp add:wq_def wf_def Let_def split:list.splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   119
        moreover have "distinct ..."
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   120
        proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   121
          have "th \<notin> set (wq_fun (schs s) cs1)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   122
          proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   123
            assume otherwise: "th \<in> set (wq_fun (schs s) cs1)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   124
            from runing_head[OF thread_P(1) this]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   125
            have "th = hd (wq_fun (schs s) cs1)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   126
            hence "(Cs cs1, Th th) \<in> (RAG s)" using otherwise
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   127
              by (simp add:s_RAG_def s_holding_def wq_def cs_holding_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   128
            with thread_P(2) show False by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   129
          qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   130
          moreover have "distinct (wq_fun (schs s) cs1)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   131
              using True thread_P wq_def by auto 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   132
          ultimately show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   133
        qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   134
        ultimately show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   135
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   136
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   137
      case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   138
      with thread_P(3)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   139
      show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   140
        by (auto simp:wq_def wf_def Let_def split:list.splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   141
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   142
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   143
    case (thread_V th s cs1)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   144
    thus ?case
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   145
    proof(cases "cs = cs1")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   146
      case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   147
      show ?thesis (is "distinct ?L")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   148
      proof(cases "(wq s cs)")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   149
        case Nil
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   150
        thus ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   151
          by (auto simp:wq_def wf_def Let_def split:list.splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   152
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   153
        case (Cons w_hd w_tl)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   154
        moreover have "distinct (SOME q. distinct q \<and> set q = set w_tl)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   155
        proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   156
          from thread_V(3)[unfolded Cons]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   157
          show  "distinct w_tl \<and> set w_tl = set w_tl" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   158
        qed auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   159
        ultimately show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   160
          by (auto simp:wq_def wf_def Let_def True split:list.splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   161
      qed 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   162
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   163
      case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   164
      with thread_V(3)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   165
      show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   166
        by (auto simp:wq_def wf_def Let_def split:list.splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   167
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   168
  qed (insert Cons, auto simp: wq_def Let_def split:list.splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   169
qed (unfold wq_def Let_def, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   170
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   171
end
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   172
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   173
context valid_trace_e
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   174
begin
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   175
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   176
text {*
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   177
  The following lemma shows that only the @{text "P"}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   178
  operation can add new thread into waiting queues. 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   179
  Such kind of lemmas are very obvious, but need to be checked formally.
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   180
  This is a kind of confirmation that our modelling is correct.
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   181
*}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   182
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   183
lemma wq_in_inv: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   184
  assumes s_ni: "thread \<notin> set (wq s cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   185
  and s_i: "thread \<in> set (wq (e#s) cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   186
  shows "e = P thread cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   187
proof(cases e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   188
  -- {* This is the only non-trivial case: *}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   189
  case (V th cs1)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   190
  have False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   191
  proof(cases "cs1 = cs")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   192
    case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   193
    show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   194
    proof(cases "(wq s cs1)")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   195
      case (Cons w_hd w_tl)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   196
      have "set (wq (e#s) cs) \<subseteq> set (wq s cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   197
      proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   198
        have "(wq (e#s) cs) = (SOME q. distinct q \<and> set q = set w_tl)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   199
          using  Cons V by (auto simp:wq_def Let_def True split:if_splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   200
        moreover have "set ... \<subseteq> set (wq s cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   201
        proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   202
          show "distinct w_tl \<and> set w_tl = set w_tl"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   203
            by (metis distinct.simps(2) local.Cons wq_distinct)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   204
        qed (insert Cons True, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   205
        ultimately show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   206
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   207
      with assms show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   208
    qed (insert assms V True, auto simp:wq_def Let_def split:if_splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   209
  qed (insert assms V, auto simp:wq_def Let_def split:if_splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   210
  thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   211
qed (insert assms, auto simp:wq_def Let_def split:if_splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   212
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   213
lemma wq_out_inv: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   214
  assumes s_in: "thread \<in> set (wq s cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   215
  and s_hd: "thread = hd (wq s cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   216
  and s_i: "thread \<noteq> hd (wq (e#s) cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   217
  shows "e = V thread cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   218
proof(cases e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   219
-- {* There are only two non-trivial cases: *}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   220
  case (V th cs1)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   221
  show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   222
  proof(cases "cs1 = cs")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   223
    case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   224
    have "PIP s (V th cs)" using pip_e[unfolded V[unfolded True]] .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   225
    thus ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   226
    proof(cases)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   227
      case (thread_V)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   228
      moreover have "th = thread" using thread_V(2) s_hd
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   229
          by (unfold s_holding_def wq_def, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   230
      ultimately show ?thesis using V True by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   231
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   232
  qed (insert assms V, auto simp:wq_def Let_def split:if_splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   233
next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   234
  case (P th cs1)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   235
  show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   236
  proof(cases "cs1 = cs")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   237
    case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   238
    with P have "wq (e#s) cs = wq_fun (schs s) cs @ [th]"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   239
      by (auto simp:wq_def Let_def split:if_splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   240
    with s_i s_hd s_in have False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   241
      by (metis empty_iff hd_append2 list.set(1) wq_def) 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   242
    thus ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   243
  qed (insert assms P, auto simp:wq_def Let_def split:if_splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   244
qed (insert assms, auto simp:wq_def Let_def split:if_splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   245
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   246
end
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   247
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   248
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   249
context valid_trace
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   250
begin
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   251
lemma  vt_moment: "\<And> t. vt (moment t s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   252
proof(induct rule:ind)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   253
  case Nil
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   254
  thus ?case by (simp add:vt_nil)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   255
next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   256
  case (Cons s e t)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   257
  show ?case
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   258
  proof(cases "t \<ge> length (e#s)")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   259
    case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   260
    from True have "moment t (e#s) = e#s" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   261
    thus ?thesis using Cons
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   262
      by (simp add:valid_trace_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   263
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   264
    case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   265
    from Cons have "vt (moment t s)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   266
    moreover have "moment t (e#s) = moment t s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   267
    proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   268
      from False have "t \<le> length s" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   269
      from moment_app [OF this, of "[e]"] 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   270
      show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   271
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   272
    ultimately show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   273
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   274
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   275
end
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   276
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   277
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   278
locale valid_moment = valid_trace + 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   279
  fixes i :: nat
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   280
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   281
sublocale valid_moment < vat_moment: valid_trace "(moment i s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   282
  by (unfold_locales, insert vt_moment, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   283
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   284
context valid_trace
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   285
begin
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   286
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   287
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   288
text {* (* ddd *)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   289
  The nature of the work is like this: since it starts from a very simple and basic 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   290
  model, even intuitively very `basic` and `obvious` properties need to derived from scratch.
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   291
  For instance, the fact 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   292
  that one thread can not be blocked by two critical resources at the same time
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   293
  is obvious, because only running threads can make new requests, if one is waiting for 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   294
  a critical resource and get blocked, it can not make another resource request and get 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   295
  blocked the second time (because it is not running). 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   296
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   297
  To derive this fact, one needs to prove by contraction and 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   298
  reason about time (or @{text "moement"}). The reasoning is based on a generic theorem
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   299
  named @{text "p_split"}, which is about status changing along the time axis. It says if 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   300
  a condition @{text "Q"} is @{text "True"} at a state @{text "s"},
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   301
  but it was @{text "False"} at the very beginning, then there must exits a moment @{text "t"} 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   302
  in the history of @{text "s"} (notice that @{text "s"} itself is essentially the history 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   303
  of events leading to it), such that @{text "Q"} switched 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   304
  from being @{text "False"} to @{text "True"} and kept being @{text "True"}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   305
  till the last moment of @{text "s"}.
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   306
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   307
  Suppose a thread @{text "th"} is blocked
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   308
  on @{text "cs1"} and @{text "cs2"} in some state @{text "s"}, 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   309
  since no thread is blocked at the very beginning, by applying 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   310
  @{text "p_split"} to these two blocking facts, there exist 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   311
  two moments @{text "t1"} and @{text "t2"}  in @{text "s"}, such that 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   312
  @{text "th"} got blocked on @{text "cs1"} and @{text "cs2"} 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   313
  and kept on blocked on them respectively ever since.
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   314
 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   315
  Without lost of generality, we assume @{text "t1"} is earlier than @{text "t2"}.
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   316
  However, since @{text "th"} was blocked ever since memonent @{text "t1"}, so it was still
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   317
  in blocked state at moment @{text "t2"} and could not
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   318
  make any request and get blocked the second time: Contradiction.
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   319
*}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   320
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   321
lemma waiting_unique_pre: (* ddd *)
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   322
  assumes h11: "thread \<in> set (wq s cs1)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   323
  and h12: "thread \<noteq> hd (wq s cs1)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   324
  assumes h21: "thread \<in> set (wq s cs2)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   325
  and h22: "thread \<noteq> hd (wq s cs2)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   326
  and neq12: "cs1 \<noteq> cs2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   327
  shows "False"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   328
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   329
  let "?Q" = "\<lambda> cs s. thread \<in> set (wq s cs) \<and> thread \<noteq> hd (wq s cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   330
  from h11 and h12 have q1: "?Q cs1 s" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   331
  from h21 and h22 have q2: "?Q cs2 s" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   332
  have nq1: "\<not> ?Q cs1 []" by (simp add:wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   333
  have nq2: "\<not> ?Q cs2 []" by (simp add:wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   334
  from p_split [of "?Q cs1", OF q1 nq1]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   335
  obtain t1 where lt1: "t1 < length s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   336
    and np1: "\<not> ?Q cs1 (moment t1 s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   337
    and nn1: "(\<forall>i'>t1. ?Q cs1 (moment i' s))" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   338
  from p_split [of "?Q cs2", OF q2 nq2]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   339
  obtain t2 where lt2: "t2 < length s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   340
    and np2: "\<not> ?Q cs2 (moment t2 s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   341
    and nn2: "(\<forall>i'>t2. ?Q cs2 (moment i' s))" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   342
  { fix s cs
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   343
    assume q: "?Q cs s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   344
    have "thread \<notin> runing s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   345
    proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   346
      assume "thread \<in> runing s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   347
      hence " \<forall>cs. \<not> (thread \<in> set (wq_fun (schs s) cs) \<and> 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   348
                 thread \<noteq> hd (wq_fun (schs s) cs))"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   349
        by (unfold runing_def s_waiting_def readys_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   350
      from this[rule_format, of cs] q 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   351
      show False by (simp add: wq_def) 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   352
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   353
  } note q_not_runing = this
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   354
  { fix t1 t2 cs1 cs2
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   355
    assume  lt1: "t1 < length s"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   356
    and np1: "\<not> ?Q cs1 (moment t1 s)"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   357
    and nn1: "(\<forall>i'>t1. ?Q cs1 (moment i' s))"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   358
    and lt2: "t2 < length s"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   359
    and np2: "\<not> ?Q cs2 (moment t2 s)"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   360
    and nn2: "(\<forall>i'>t2. ?Q cs2 (moment i' s))"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   361
    and lt12: "t1 < t2"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   362
    let ?t3 = "Suc t2"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   363
    from lt2 have le_t3: "?t3 \<le> length s" by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   364
    from moment_plus [OF this] 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   365
    obtain e where eq_m: "moment ?t3 s = e#moment t2 s" by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   366
    have "t2 < ?t3" by simp
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   367
    from nn2 [rule_format, OF this] and eq_m
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   368
    have h1: "thread \<in> set (wq (e#moment t2 s) cs2)" and
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   369
         h2: "thread \<noteq> hd (wq (e#moment t2 s) cs2)" by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   370
    have "vt (e#moment t2 s)"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   371
    proof -
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   372
      from vt_moment 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   373
      have "vt (moment ?t3 s)" .
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   374
      with eq_m show ?thesis by simp
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   375
    qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   376
    then interpret vt_e: valid_trace_e "moment t2 s" "e"
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   377
        by (unfold_locales, auto, cases, simp)
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   378
    have ?thesis
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   379
    proof -
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   380
      have "thread \<in> runing (moment t2 s)"
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   381
      proof(cases "thread \<in> set (wq (moment t2 s) cs2)")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   382
        case True
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   383
        have "e = V thread cs2"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   384
        proof -
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   385
          have eq_th: "thread = hd (wq (moment t2 s) cs2)" 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   386
              using True and np2  by auto 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   387
          from vt_e.wq_out_inv[OF True this h2]
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   388
          show ?thesis .
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   389
        qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   390
        thus ?thesis using vt_e.actor_inv[OF vt_e.pip_e] by auto
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   391
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   392
        case False
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   393
        have "e = P thread cs2" using vt_e.wq_in_inv[OF False h1] .
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   394
        with vt_e.actor_inv[OF vt_e.pip_e]
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   395
        show ?thesis by auto
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   396
      qed
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   397
      moreover have "thread \<notin> runing (moment t2 s)"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   398
        by (rule q_not_runing[OF nn1[rule_format, OF lt12]])
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   399
      ultimately show ?thesis by simp
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   400
    qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   401
  } note lt_case = this
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   402
  show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   403
  proof -
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   404
    { assume "t1 < t2"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   405
      from lt_case[OF lt1 np1 nn1 lt2 np2 nn2 this]
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   406
      have ?thesis .
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   407
    } moreover {
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   408
      assume "t2 < t1"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   409
      from lt_case[OF lt2 np2 nn2 lt1 np1 nn1 this]
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   410
      have ?thesis .
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   411
    } moreover {
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   412
      assume eq_12: "t1 = t2"
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   413
      let ?t3 = "Suc t2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   414
      from lt2 have le_t3: "?t3 \<le> length s" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   415
      from moment_plus [OF this] 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   416
      obtain e where eq_m: "moment ?t3 s = e#moment t2 s" by auto
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   417
      have lt_2: "t2 < ?t3" by simp
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   418
      from nn2 [rule_format, OF this] and eq_m
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   419
      have h1: "thread \<in> set (wq (e#moment t2 s) cs2)" and
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   420
           h2: "thread \<noteq> hd (wq (e#moment t2 s) cs2)" by auto
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   421
      from nn1[rule_format, OF lt_2[folded eq_12]] eq_m[folded eq_12]
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   422
      have g1: "thread \<in> set (wq (e#moment t1 s) cs1)" and
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   423
           g2: "thread \<noteq> hd (wq (e#moment t1 s) cs1)" by auto
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   424
      have "vt (e#moment t2 s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   425
      proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   426
        from vt_moment 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   427
        have "vt (moment ?t3 s)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   428
        with eq_m show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   429
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   430
      then interpret vt_e: valid_trace_e "moment t2 s" "e"
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   431
          by (unfold_locales, auto, cases, simp)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   432
      have "e = V thread cs2 \<or> e = P thread cs2"
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   433
      proof(cases "thread \<in> set (wq (moment t2 s) cs2)")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   434
        case True
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   435
        have "e = V thread cs2"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   436
        proof -
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   437
          have eq_th: "thread = hd (wq (moment t2 s) cs2)" 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   438
              using True and np2  by auto 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   439
          from vt_e.wq_out_inv[OF True this h2]
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   440
          show ?thesis .
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   441
        qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   442
        thus ?thesis by auto
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   443
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   444
        case False
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   445
        have "e = P thread cs2" using vt_e.wq_in_inv[OF False h1] .
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   446
        thus ?thesis by auto
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   447
      qed
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   448
      moreover have "e = V thread cs1 \<or> e = P thread cs1"
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   449
      proof(cases "thread \<in> set (wq (moment t1 s) cs1)")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   450
        case True
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   451
        have eq_th: "thread = hd (wq (moment t1 s) cs1)" 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   452
              using True and np1  by auto 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   453
        from vt_e.wq_out_inv[folded eq_12, OF True this g2]
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   454
        have "e = V thread cs1" .
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   455
        thus ?thesis by auto
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   456
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   457
        case False
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   458
        have "e = P thread cs1" using vt_e.wq_in_inv[folded eq_12, OF False g1] .
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   459
        thus ?thesis by auto
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   460
      qed
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   461
      ultimately have ?thesis using neq12 by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   462
    } ultimately show ?thesis using nat_neq_iff by blast 
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   463
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   464
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   465
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   466
text {*
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   467
  This lemma is a simple corrolary of @{text "waiting_unique_pre"}.
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   468
*}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   469
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   470
lemma waiting_unique:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   471
  assumes "waiting s th cs1"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   472
  and "waiting s th cs2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   473
  shows "cs1 = cs2"
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   474
  using waiting_unique_pre assms
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   475
  unfolding wq_def s_waiting_def
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   476
  by auto
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   477
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   478
end
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   479
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   480
(* not used *)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   481
text {*
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   482
  Every thread can only be blocked on one critical resource, 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   483
  symmetrically, every critical resource can only be held by one thread. 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   484
  This fact is much more easier according to our definition. 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   485
*}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   486
lemma held_unique:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   487
  assumes "holding (s::event list) th1 cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   488
  and "holding s th2 cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   489
  shows "th1 = th2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   490
 by (insert assms, unfold s_holding_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   491
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   492
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   493
lemma last_set_lt: "th \<in> threads s \<Longrightarrow> last_set th s < length s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   494
  apply (induct s, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   495
  by (case_tac a, auto split:if_splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   496
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   497
lemma last_set_unique: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   498
  "\<lbrakk>last_set th1 s = last_set th2 s; th1 \<in> threads s; th2 \<in> threads s\<rbrakk>
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   499
          \<Longrightarrow> th1 = th2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   500
  apply (induct s, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   501
  by (case_tac a, auto split:if_splits dest:last_set_lt)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   502
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   503
lemma preced_unique : 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   504
  assumes pcd_eq: "preced th1 s = preced th2 s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   505
  and th_in1: "th1 \<in> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   506
  and th_in2: " th2 \<in> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   507
  shows "th1 = th2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   508
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   509
  from pcd_eq have "last_set th1 s = last_set th2 s" by (simp add:preced_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   510
  from last_set_unique [OF this th_in1 th_in2]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   511
  show ?thesis .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   512
qed
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   513
                      
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   514
lemma preced_linorder: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   515
  assumes neq_12: "th1 \<noteq> th2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   516
  and th_in1: "th1 \<in> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   517
  and th_in2: " th2 \<in> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   518
  shows "preced th1 s < preced th2 s \<or> preced th1 s > preced th2 s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   519
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   520
  from preced_unique [OF _ th_in1 th_in2] and neq_12 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   521
  have "preced th1 s \<noteq> preced th2 s" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   522
  thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   523
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   524
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   525
(* An aux lemma used later *) 
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   526
lemma unique_minus:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   527
  assumes unique: "\<And> a b c. \<lbrakk>(a, b) \<in> r; (a, c) \<in> r\<rbrakk> \<Longrightarrow> b = c"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   528
  and xy: "(x, y) \<in> r"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   529
  and xz: "(x, z) \<in> r^+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   530
  and neq: "y \<noteq> z"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   531
  shows "(y, z) \<in> r^+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   532
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   533
 from xz and neq show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   534
 proof(induct)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   535
   case (base ya)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   536
   have "(x, ya) \<in> r" by fact
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   537
   from unique [OF xy this] have "y = ya" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   538
   with base show ?case by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   539
 next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   540
   case (step ya z)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   541
   show ?case
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   542
   proof(cases "y = ya")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   543
     case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   544
     from step True show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   545
   next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   546
     case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   547
     from step False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   548
     show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   549
   qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   550
 qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   551
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   552
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   553
lemma unique_base:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   554
  assumes unique: "\<And> a b c. \<lbrakk>(a, b) \<in> r; (a, c) \<in> r\<rbrakk> \<Longrightarrow> b = c"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   555
  and xy: "(x, y) \<in> r"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   556
  and xz: "(x, z) \<in> r^+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   557
  and neq_yz: "y \<noteq> z"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   558
  shows "(y, z) \<in> r^+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   559
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   560
  from xz neq_yz show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   561
  proof(induct)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   562
    case (base ya)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   563
    from xy unique base show ?case by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   564
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   565
    case (step ya z)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   566
    show ?case
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   567
    proof(cases "y = ya")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   568
      case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   569
      from True step show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   570
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   571
      case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   572
      from False step 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   573
      have "(y, ya) \<in> r\<^sup>+" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   574
      with step show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   575
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   576
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   577
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   578
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   579
lemma unique_chain:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   580
  assumes unique: "\<And> a b c. \<lbrakk>(a, b) \<in> r; (a, c) \<in> r\<rbrakk> \<Longrightarrow> b = c"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   581
  and xy: "(x, y) \<in> r^+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   582
  and xz: "(x, z) \<in> r^+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   583
  and neq_yz: "y \<noteq> z"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   584
  shows "(y, z) \<in> r^+ \<or> (z, y) \<in> r^+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   585
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   586
  from xy xz neq_yz show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   587
  proof(induct)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   588
    case (base y)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   589
    have h1: "(x, y) \<in> r" and h2: "(x, z) \<in> r\<^sup>+" and h3: "y \<noteq> z" using base by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   590
    from unique_base [OF _ h1 h2 h3] and unique show ?case by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   591
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   592
    case (step y za)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   593
    show ?case
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   594
    proof(cases "y = z")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   595
      case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   596
      from True step show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   597
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   598
      case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   599
      from False step have "(y, z) \<in> r\<^sup>+ \<or> (z, y) \<in> r\<^sup>+" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   600
      thus ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   601
      proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   602
        assume "(z, y) \<in> r\<^sup>+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   603
        with step have "(z, za) \<in> r\<^sup>+" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   604
        thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   605
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   606
        assume h: "(y, z) \<in> r\<^sup>+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   607
        from step have yza: "(y, za) \<in> r" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   608
        from step have "za \<noteq> z" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   609
        from unique_minus [OF _ yza h this] and unique
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   610
        have "(za, z) \<in> r\<^sup>+" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   611
        thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   612
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   613
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   614
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   615
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   616
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   617
text {*
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   618
  The following three lemmas show that @{text "RAG"} does not change
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   619
  by the happening of @{text "Set"}, @{text "Create"} and @{text "Exit"}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   620
  events, respectively.
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   621
*}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   622
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   623
lemma RAG_set_unchanged: "(RAG (Set th prio # s)) = RAG s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   624
apply (unfold s_RAG_def s_waiting_def wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   625
by (simp add:Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   626
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   627
lemma RAG_create_unchanged: "(RAG (Create th prio # s)) = RAG s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   628
apply (unfold s_RAG_def s_waiting_def wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   629
by (simp add:Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   630
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   631
lemma RAG_exit_unchanged: "(RAG (Exit th # s)) = RAG s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   632
apply (unfold s_RAG_def s_waiting_def wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   633
by (simp add:Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   634
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   635
context valid_trace
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   636
begin
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   637
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   638
lemma finite_threads:
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   639
  shows "finite (threads s)"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   640
using vt by (induct) (auto elim: step.cases)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   641
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   642
lemma cp_eq_cpreced: "cp s th = cpreced (wq s) s th"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   643
unfolding cp_def wq_def
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   644
apply(induct s rule: schs.induct)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   645
thm cpreced_initial
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   646
apply(simp add: Let_def cpreced_initial)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   647
apply(simp add: Let_def)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   648
apply(simp add: Let_def)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   649
apply(simp add: Let_def)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   650
apply(subst (2) schs.simps)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   651
apply(simp add: Let_def)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   652
apply(subst (2) schs.simps)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   653
apply(simp add: Let_def)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   654
done
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   655
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   656
lemma RAG_target_th: "(Th th, x) \<in> RAG (s::state) \<Longrightarrow> \<exists> cs. x = Cs cs"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   657
  by (unfold s_RAG_def, auto)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   658
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   659
lemma wq_threads: 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   660
  assumes h: "th \<in> set (wq s cs)"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   661
  shows "th \<in> threads s"
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   662
proof -
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   663
 from vt and h show ?thesis
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   664
  proof(induct arbitrary: th cs)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   665
    case (vt_cons s e)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   666
    interpret vt_s: valid_trace s
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   667
      using vt_cons(1) by (unfold_locales, auto)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   668
    assume ih: "\<And>th cs. th \<in> set (wq s cs) \<Longrightarrow> th \<in> threads s"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   669
      and stp: "step s e"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   670
      and vt: "vt s"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   671
      and h: "th \<in> set (wq (e # s) cs)"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   672
    show ?case
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   673
    proof(cases e)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   674
      case (Create th' prio)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   675
      with ih h show ?thesis
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   676
        by (auto simp:wq_def Let_def)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   677
    next
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   678
      case (Exit th')
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   679
      with stp ih h show ?thesis
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   680
        apply (auto simp:wq_def Let_def)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   681
        apply (ind_cases "step s (Exit th')")
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   682
        apply (auto simp:runing_def readys_def s_holding_def s_waiting_def holdents_def
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   683
               s_RAG_def s_holding_def cs_holding_def)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   684
        done
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   685
    next
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   686
      case (V th' cs')
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   687
      show ?thesis
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   688
      proof(cases "cs' = cs")
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   689
        case False
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   690
        with h
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   691
        show ?thesis
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   692
          apply(unfold wq_def V, auto simp:Let_def V split:prod.splits, fold wq_def)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   693
          by (drule_tac ih, simp)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   694
      next
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   695
        case True
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   696
        from h
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   697
        show ?thesis
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   698
        proof(unfold V wq_def)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   699
          assume th_in: "th \<in> set (wq_fun (schs (V th' cs' # s)) cs)" (is "th \<in> set ?l")
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   700
          show "th \<in> threads (V th' cs' # s)"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   701
          proof(cases "cs = cs'")
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   702
            case False
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   703
            hence "?l = wq_fun (schs s) cs" by (simp add:Let_def)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   704
            with th_in have " th \<in> set (wq s cs)" 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   705
              by (fold wq_def, simp)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   706
            from ih [OF this] show ?thesis by simp
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   707
          next
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   708
            case True
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   709
            show ?thesis
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   710
            proof(cases "wq_fun (schs s) cs'")
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   711
              case Nil
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   712
              with h V show ?thesis
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   713
                apply (auto simp:wq_def Let_def split:if_splits)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   714
                by (fold wq_def, drule_tac ih, simp)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   715
            next
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   716
              case (Cons a rest)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   717
              assume eq_wq: "wq_fun (schs s) cs' = a # rest"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   718
              with h V show ?thesis
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   719
                apply (auto simp:Let_def wq_def split:if_splits)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   720
              proof -
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   721
                assume th_in: "th \<in> set (SOME q. distinct q \<and> set q = set rest)"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   722
                have "set (SOME q. distinct q \<and> set q = set rest) = set rest" 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   723
                proof(rule someI2)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   724
                  from vt_s.wq_distinct[of cs'] and eq_wq[folded wq_def]
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   725
                  show "distinct rest \<and> set rest = set rest" by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   726
                next
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   727
                  show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   728
                    by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   729
                qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   730
                with eq_wq th_in have "th \<in> set (wq_fun (schs s) cs')" by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   731
                from ih[OF this[folded wq_def]] show "th \<in> threads s" .
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   732
              next
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   733
                assume th_in: "th \<in> set (wq_fun (schs s) cs)"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   734
                from ih[OF this[folded wq_def]]
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   735
                show "th \<in> threads s" .
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   736
              qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   737
            qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   738
          qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   739
        qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   740
      qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   741
    next
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   742
      case (P th' cs')
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   743
      from h stp
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   744
      show ?thesis
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   745
        apply (unfold P wq_def)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   746
        apply (auto simp:Let_def split:if_splits, fold wq_def)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   747
        apply (auto intro:ih)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   748
        apply(ind_cases "step s (P th' cs')")
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   749
        by (unfold runing_def readys_def, auto)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   750
    next
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   751
      case (Set thread prio)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   752
      with ih h show ?thesis
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   753
        by (auto simp:wq_def Let_def)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   754
    qed
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   755
  next
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   756
    case vt_nil
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   757
    thus ?case by (auto simp:wq_def)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   758
  qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   759
qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   760
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   761
lemma dm_RAG_threads:
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   762
  assumes in_dom: "(Th th) \<in> Domain (RAG s)"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   763
  shows "th \<in> threads s"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   764
proof -
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   765
  from in_dom obtain n where "(Th th, n) \<in> RAG s" by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   766
  moreover from RAG_target_th[OF this] obtain cs where "n = Cs cs" by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   767
  ultimately have "(Th th, Cs cs) \<in> RAG s" by simp
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   768
  hence "th \<in> set (wq s cs)"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   769
    by (unfold s_RAG_def, auto simp:cs_waiting_def)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   770
  from wq_threads [OF this] show ?thesis .
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   771
qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   772
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   773
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   774
lemma cp_le:
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   775
  assumes th_in: "th \<in> threads s"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   776
  shows "cp s th \<le> Max ((\<lambda> th. (preced th s)) ` threads s)"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   777
proof(unfold cp_eq_cpreced cpreced_def cs_dependants_def)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   778
  show "Max ((\<lambda>th. preced th s) ` ({th} \<union> {th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+}))
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   779
         \<le> Max ((\<lambda>th. preced th s) ` threads s)"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   780
    (is "Max (?f ` ?A) \<le> Max (?f ` ?B)")
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   781
  proof(rule Max_f_mono)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   782
    show "{th} \<union> {th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+} \<noteq> {}" by simp
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   783
  next
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   784
    from finite_threads
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   785
    show "finite (threads s)" .
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   786
  next
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   787
    from th_in
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   788
    show "{th} \<union> {th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+} \<subseteq> threads s"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   789
      apply (auto simp:Domain_def)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   790
      apply (rule_tac dm_RAG_threads)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   791
      apply (unfold trancl_domain [of "RAG s", symmetric])
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   792
      by (unfold cs_RAG_def s_RAG_def, auto simp:Domain_def)
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   793
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   794
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   795
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   796
lemma le_cp:
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   797
  shows "preced th s \<le> cp s th"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   798
proof(unfold cp_eq_cpreced preced_def cpreced_def, simp)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   799
  show "Prc (priority th s) (last_set th s)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   800
    \<le> Max (insert (Prc (priority th s) (last_set th s))
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   801
            ((\<lambda>th. Prc (priority th s) (last_set th s)) ` dependants (wq s) th))"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   802
    (is "?l \<le> Max (insert ?l ?A)")
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   803
  proof(cases "?A = {}")
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   804
    case False
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   805
    have "finite ?A" (is "finite (?f ` ?B)")
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   806
    proof -
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   807
      have "finite ?B" 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   808
      proof-
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   809
        have "finite {th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+}"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   810
        proof -
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   811
          let ?F = "\<lambda> (x, y). the_th x"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   812
          have "{th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+} \<subseteq> ?F ` ((RAG (wq s))\<^sup>+)"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   813
            apply (auto simp:image_def)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   814
            by (rule_tac x = "(Th x, Th th)" in bexI, auto)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   815
          moreover have "finite \<dots>"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   816
          proof -
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   817
            from finite_RAG have "finite (RAG s)" .
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   818
            hence "finite ((RAG (wq s))\<^sup>+)"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   819
              apply (unfold finite_trancl)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   820
              by (auto simp: s_RAG_def cs_RAG_def wq_def)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   821
            thus ?thesis by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   822
          qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   823
          ultimately show ?thesis by (auto intro:finite_subset)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   824
        qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   825
        thus ?thesis by (simp add:cs_dependants_def)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   826
      qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   827
      thus ?thesis by simp
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   828
    qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   829
    from Max_insert [OF this False, of ?l] show ?thesis by auto
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   830
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   831
    case True
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   832
    thus ?thesis by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   833
  qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   834
qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   835
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   836
lemma max_cp_eq: 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   837
  shows "Max ((cp s) ` threads s) = Max ((\<lambda> th. (preced th s)) ` threads s)"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   838
  (is "?l = ?r")
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   839
proof(cases "threads s = {}")
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   840
  case True
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   841
  thus ?thesis by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   842
next
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   843
  case False
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   844
  have "?l \<in> ((cp s) ` threads s)"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   845
  proof(rule Max_in)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   846
    from finite_threads
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   847
    show "finite (cp s ` threads s)" by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   848
  next
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   849
    from False show "cp s ` threads s \<noteq> {}" by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   850
  qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   851
  then obtain th 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   852
    where th_in: "th \<in> threads s" and eq_l: "?l = cp s th" by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   853
  have "\<dots> \<le> ?r" by (rule cp_le[OF th_in])
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   854
  moreover have "?r \<le> cp s th" (is "Max (?f ` ?A) \<le> cp s th")
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   855
  proof -
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   856
    have "?r \<in> (?f ` ?A)"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   857
    proof(rule Max_in)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   858
      from finite_threads
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   859
      show " finite ((\<lambda>th. preced th s) ` threads s)" by auto
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   860
    next
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   861
      from False show " (\<lambda>th. preced th s) ` threads s \<noteq> {}" by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   862
    qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   863
    then obtain th' where 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   864
      th_in': "th' \<in> ?A " and eq_r: "?r = ?f th'" by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   865
    from le_cp [of th']  eq_r
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   866
    have "?r \<le> cp s th'" by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   867
    moreover have "\<dots> \<le> cp s th"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   868
    proof(fold eq_l)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   869
      show " cp s th' \<le> Max (cp s ` threads s)"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   870
      proof(rule Max_ge)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   871
        from th_in' show "cp s th' \<in> cp s ` threads s"
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   872
          by auto
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   873
      next
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   874
        from finite_threads
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   875
        show "finite (cp s ` threads s)" by auto
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   876
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   877
    qed
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   878
    ultimately show ?thesis by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   879
  qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   880
  ultimately show ?thesis using eq_l by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   881
qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   882
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   883
lemma max_cp_eq_the_preced:
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   884
  shows "Max ((cp s) ` threads s) = Max (the_preced s ` threads s)"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   885
  using max_cp_eq using the_preced_def by presburger 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   886
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   887
end
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   888
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   889
lemma preced_v [simp]: "preced th' (V th cs#s) = preced th' s"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   890
  by (unfold preced_def, simp)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   891
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   892
lemma the_preced_v[simp]: "the_preced (V th cs#s) = the_preced s"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   893
proof
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   894
  fix th'
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   895
  show "the_preced (V th cs # s) th' = the_preced s th'"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   896
    by (unfold the_preced_def preced_def, simp)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   897
qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   898
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   899
locale valid_trace_v = valid_trace_e + 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   900
  fixes th cs
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   901
  assumes is_v: "e = V th cs"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   902
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   903
context valid_trace_v
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   904
begin
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   905
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   906
definition "rest = tl (wq s cs)"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   907
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   908
definition "wq' = (SOME q. distinct q \<and> set q = set rest)"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   909
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   910
lemma distinct_rest: "distinct rest"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   911
  by (simp add: distinct_tl rest_def wq_distinct)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   912
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   913
lemma runing_th_s:
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   914
  shows "th \<in> runing s"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   915
proof -
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   916
  from pip_e[unfolded is_v]
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   917
  show ?thesis by (cases, simp)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   918
qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   919
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   920
lemma holding_cs_eq_th:
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   921
  assumes "holding s t cs"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   922
  shows "t = th"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   923
proof -
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   924
  from pip_e[unfolded is_v]
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   925
  show ?thesis
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   926
  proof(cases)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   927
    case (thread_V)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   928
    from held_unique[OF this(2) assms]
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   929
    show ?thesis by simp
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   930
  qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   931
qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   932
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   933
lemma th_not_waiting: 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   934
  "\<not> waiting s th c"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   935
proof -
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   936
  have "th \<in> readys s"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   937
    using runing_ready runing_th_s by blast 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   938
  thus ?thesis
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   939
    by (unfold readys_def, auto)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   940
qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   941
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   942
lemma waiting_neq_th: 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   943
  assumes "waiting s t c"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   944
  shows "t \<noteq> th"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   945
  using assms using th_not_waiting by blast 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   946
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   947
lemma wq_s_cs:
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   948
  "wq s cs = th#rest"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   949
proof -
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   950
  from pip_e[unfolded is_v]
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   951
  show ?thesis
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   952
  proof(cases)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   953
    case (thread_V)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   954
    from this(2) show ?thesis
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   955
      by (unfold rest_def s_holding_def, fold wq_def,
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   956
                 metis empty_iff list.collapse list.set(1))
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   957
  qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   958
qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   959
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   960
lemma wq_es_cs:
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   961
  "wq (e#s) cs = wq'"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   962
 using wq_s_cs[unfolded wq_def]
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   963
 by (auto simp:Let_def wq_def rest_def wq'_def is_v, simp) 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   964
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   965
lemma distinct_wq': "distinct wq'"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   966
  by (metis (mono_tags, lifting) distinct_rest  some_eq_ex wq'_def)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   967
  
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   968
lemma th'_in_inv:
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   969
  assumes "th' \<in> set wq'"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   970
  shows "th' \<in> set rest"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   971
  using assms
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   972
  by (metis (mono_tags, lifting) distinct.simps(2) 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   973
        rest_def some_eq_ex wq'_def wq_distinct wq_s_cs) 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   974
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   975
lemma neq_t_th: 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   976
  assumes "waiting (e#s) t c"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   977
  shows "t \<noteq> th"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   978
proof
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   979
  assume otherwise: "t = th"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   980
  show False
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   981
  proof(cases "c = cs")
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   982
    case True
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   983
    have "t \<in> set wq'" 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   984
     using assms[unfolded True s_waiting_def, folded wq_def, unfolded wq_es_cs]
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   985
     by simp 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   986
    from th'_in_inv[OF this] have "t \<in> set rest" .
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   987
    with wq_s_cs[folded otherwise] wq_distinct[of cs]
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   988
    show ?thesis by simp
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   989
  next
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   990
    case False
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   991
    have "wq (e#s) c = wq s c" using False
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   992
        by (unfold is_v, simp)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   993
    hence "waiting s t c" using assms 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   994
        by (simp add: cs_waiting_def waiting_eq)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   995
    hence "t \<notin> readys s" by (unfold readys_def, auto)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   996
    hence "t \<notin> runing s" using runing_ready by auto 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
   997
    with runing_th_s[folded otherwise] show ?thesis by auto
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   998
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   999
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1000
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1001
lemma waiting_esI1:
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1002
  assumes "waiting s t c"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1003
      and "c \<noteq> cs" 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1004
  shows "waiting (e#s) t c" 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1005
proof -
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1006
  have "wq (e#s) c = wq s c" 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1007
    using assms(2) is_v by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1008
  with assms(1) show ?thesis 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1009
    using cs_waiting_def waiting_eq by auto 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1010
qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1011
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1012
lemma holding_esI2:
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1013
  assumes "c \<noteq> cs" 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1014
  and "holding s t c"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1015
  shows "holding (e#s) t c"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1016
proof -
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1017
  from assms(1) have "wq (e#s) c = wq s c" using is_v by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1018
  from assms(2)[unfolded s_holding_def, folded wq_def, 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1019
                folded this, unfolded wq_def, folded s_holding_def]
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1020
  show ?thesis .
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1021
qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1022
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1023
end
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1024
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1025
locale valid_trace_v_n = valid_trace_v +
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1026
  assumes rest_nnl: "rest \<noteq> []"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1027
begin
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1028
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1029
lemma neq_wq': "wq' \<noteq> []" 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1030
proof (unfold wq'_def, rule someI2)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1031
  show "distinct rest \<and> set rest = set rest"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1032
    by (simp add: distinct_rest) 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1033
next
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1034
  fix x
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1035
  assume " distinct x \<and> set x = set rest" 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1036
  thus "x \<noteq> []" using rest_nnl by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1037
qed 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1038
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1039
definition "taker = hd wq'"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1040
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1041
definition "rest' = tl wq'"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1042
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1043
lemma eq_wq': "wq' = taker # rest'"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1044
  by (simp add: neq_wq' rest'_def taker_def)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1045
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1046
lemma next_th_taker: 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1047
  shows "next_th s th cs taker"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1048
  using rest_nnl taker_def wq'_def wq_s_cs 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1049
  by (auto simp:next_th_def)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1050
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1051
lemma taker_unique: 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1052
  assumes "next_th s th cs taker'"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1053
  shows "taker' = taker"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1054
proof -
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1055
  from assms
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1056
  obtain rest' where 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1057
    h: "wq s cs = th # rest'" 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1058
       "taker' = hd (SOME q. distinct q \<and> set q = set rest')"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1059
          by (unfold next_th_def, auto)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1060
  with wq_s_cs have "rest' = rest" by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1061
  thus ?thesis using h(2) taker_def wq'_def by auto 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1062
qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1063
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1064
lemma waiting_set_eq:
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1065
  "{(Th th', Cs cs) |th'. next_th s th cs th'} = {(Th taker, Cs cs)}"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1066
  by (smt all_not_in_conv bot.extremum insertI1 insert_subset 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1067
      mem_Collect_eq next_th_taker subsetI subset_antisym taker_def taker_unique)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1068
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1069
lemma holding_set_eq:
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1070
  "{(Cs cs, Th th') |th'.  next_th s th cs th'} = {(Cs cs, Th taker)}"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1071
  using next_th_taker taker_def waiting_set_eq 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1072
  by fastforce
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1073
   
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1074
lemma holding_taker:
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1075
  shows "holding (e#s) taker cs"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1076
    by (unfold s_holding_def, fold wq_def, unfold wq_es_cs, 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1077
        auto simp:neq_wq' taker_def)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1078
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1079
lemma waiting_esI2:
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1080
  assumes "waiting s t cs"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1081
      and "t \<noteq> taker"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1082
  shows "waiting (e#s) t cs" 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1083
proof -
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1084
  have "t \<in> set wq'" 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1085
  proof(unfold wq'_def, rule someI2)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1086
    show "distinct rest \<and> set rest = set rest"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1087
          by (simp add: distinct_rest)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1088
  next
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1089
    fix x
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1090
    assume "distinct x \<and> set x = set rest"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1091
    moreover have "t \<in> set rest"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1092
        using assms(1) cs_waiting_def waiting_eq wq_s_cs by auto 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1093
    ultimately show "t \<in> set x" by simp
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1094
  qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1095
  moreover have "t \<noteq> hd wq'"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1096
    using assms(2) taker_def by auto 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1097
  ultimately show ?thesis
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1098
    by (unfold s_waiting_def, fold wq_def, unfold wq_es_cs, simp)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1099
qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1100
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1101
lemma waiting_esE:
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1102
  assumes "waiting (e#s) t c" 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1103
  obtains "c \<noteq> cs" "waiting s t c"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1104
     |    "c = cs" "t \<noteq> taker" "waiting s t cs" "t \<in> set rest'"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1105
proof(cases "c = cs")
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1106
  case False
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1107
  hence "wq (e#s) c = wq s c" using is_v by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1108
  with assms have "waiting s t c" using cs_waiting_def waiting_eq by auto 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1109
  from that(1)[OF False this] show ?thesis .
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1110
next
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1111
  case True
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1112
  from assms[unfolded s_waiting_def True, folded wq_def, unfolded wq_es_cs]
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1113
  have "t \<noteq> hd wq'" "t \<in> set wq'" by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1114
  hence "t \<noteq> taker" by (simp add: taker_def) 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1115
  moreover hence "t \<noteq> th" using assms neq_t_th by blast 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1116
  moreover have "t \<in> set rest" by (simp add: `t \<in> set wq'` th'_in_inv) 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1117
  ultimately have "waiting s t cs"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1118
    by (metis cs_waiting_def list.distinct(2) list.sel(1) 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1119
                list.set_sel(2) rest_def waiting_eq wq_s_cs)  
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1120
  show ?thesis using that(2)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1121
  using True `t \<in> set wq'` `t \<noteq> taker` `waiting s t cs` eq_wq' by auto   
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1122
qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1123
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1124
lemma holding_esI1:
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1125
  assumes "c = cs"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1126
  and "t = taker"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1127
  shows "holding (e#s) t c"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1128
  by (unfold assms, simp add: holding_taker)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1129
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1130
lemma holding_esE:
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1131
  assumes "holding (e#s) t c" 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1132
  obtains "c = cs" "t = taker"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1133
      | "c \<noteq> cs" "holding s t c"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1134
proof(cases "c = cs")
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1135
  case True
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1136
  from assms[unfolded True, unfolded s_holding_def, 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1137
             folded wq_def, unfolded wq_es_cs]
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1138
  have "t = taker" by (simp add: taker_def) 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1139
  from that(1)[OF True this] show ?thesis .
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1140
next
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1141
  case False
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1142
  hence "wq (e#s) c = wq s c" using is_v by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1143
  from assms[unfolded s_holding_def, folded wq_def, 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1144
             unfolded this, unfolded wq_def, folded s_holding_def]
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1145
  have "holding s t c"  .
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1146
  from that(2)[OF False this] show ?thesis .
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1147
qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1148
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1149
end 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1150
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1151
locale valid_trace_v_e = valid_trace_v +
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1152
  assumes rest_nil: "rest = []"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1153
begin
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1154
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1155
lemma nil_wq': "wq' = []" 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1156
proof (unfold wq'_def, rule someI2)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1157
  show "distinct rest \<and> set rest = set rest"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1158
    by (simp add: distinct_rest) 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1159
next
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1160
  fix x
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1161
  assume " distinct x \<and> set x = set rest" 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1162
  thus "x = []" using rest_nil by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1163
qed 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1164
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1165
lemma no_taker: 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1166
  assumes "next_th s th cs taker"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1167
  shows "False"
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1168
proof -
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1169
  from assms[unfolded next_th_def]
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1170
  obtain rest' where "wq s cs = th # rest'" "rest' \<noteq> []"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1171
    by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1172
  thus ?thesis using rest_def rest_nil by auto 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1173
qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1174
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1175
lemma waiting_set_eq:
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1176
  "{(Th th', Cs cs) |th'. next_th s th cs th'} = {}"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1177
  using no_taker by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1178
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1179
lemma holding_set_eq:
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1180
  "{(Cs cs, Th th') |th'.  next_th s th cs th'} = {}"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1181
  using no_taker by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1182
   
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1183
lemma no_holding:
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1184
  assumes "holding (e#s) taker cs"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1185
  shows False
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1186
proof -
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1187
  from wq_es_cs[unfolded nil_wq']
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1188
  have " wq (e # s) cs = []" .
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1189
  from assms[unfolded s_holding_def, folded wq_def, unfolded this]
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1190
  show ?thesis by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1191
qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1192
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1193
lemma no_waiting:
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1194
  assumes "waiting (e#s) t cs"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1195
  shows False
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1196
proof -
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1197
  from wq_es_cs[unfolded nil_wq']
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1198
  have " wq (e # s) cs = []" .
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1199
  from assms[unfolded s_waiting_def, folded wq_def, unfolded this]
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1200
  show ?thesis by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1201
qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1202
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1203
lemma waiting_esE:
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1204
  assumes "waiting (e#s) t c" 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1205
  obtains "c \<noteq> cs" "waiting s t c"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1206
proof(cases "c = cs")
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1207
  case False
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1208
  hence "wq (e#s) c = wq s c" using is_v by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1209
  with assms have "waiting s t c" using cs_waiting_def waiting_eq by auto 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1210
  from that(1)[OF False this] show ?thesis .
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1211
next
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1212
  case True
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1213
  from no_waiting[OF assms[unfolded True]]
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1214
  show ?thesis by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1215
qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1216
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1217
lemma holding_esE:
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1218
  assumes "holding (e#s) t c" 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1219
  obtains "c \<noteq> cs" "holding s t c"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1220
proof(cases "c = cs")
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1221
  case True
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1222
  from no_holding[OF assms[unfolded True]] 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1223
  show ?thesis by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1224
next
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1225
  case False
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1226
  hence "wq (e#s) c = wq s c" using is_v by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1227
  from assms[unfolded s_holding_def, folded wq_def, 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1228
             unfolded this, unfolded wq_def, folded s_holding_def]
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1229
  have "holding s t c"  .
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1230
  from that[OF False this] show ?thesis .
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1231
qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1232
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1233
end (* ccc *)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1234
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1235
lemma rel_eqI:
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1236
  assumes "\<And> x y. (x,y) \<in> A \<Longrightarrow> (x,y) \<in> B"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1237
  and "\<And> x y. (x,y) \<in> B \<Longrightarrow> (x, y) \<in> A"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1238
  shows "A = B"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1239
  using assms by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1240
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1241
lemma in_RAG_E:
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1242
  assumes "(n1, n2) \<in> RAG (s::state)"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1243
  obtains (waiting) th cs where "n1 = Th th" "n2 = Cs cs" "waiting s th cs"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1244
      | (holding) th cs where "n1 = Cs cs" "n2 = Th th" "holding s th cs"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1245
  using assms[unfolded s_RAG_def, folded waiting_eq holding_eq]
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1246
  by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1247
  
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1248
context valid_trace_v
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1249
begin
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1250
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1251
lemma
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1252
  "RAG (e # s) =
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1253
   RAG s - {(Cs cs, Th th)} -
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1254
     {(Th th', Cs cs) |th'. next_th s th cs th'} \<union>
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1255
     {(Cs cs, Th th') |th'.  next_th s th cs th'}" (is "?L = ?R")
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1256
proof(rule rel_eqI)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1257
  fix n1 n2
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1258
  assume "(n1, n2) \<in> ?L"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1259
  thus "(n1, n2) \<in> ?R"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1260
  proof(cases rule:in_RAG_E)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1261
    case (waiting th' cs')
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1262
    show ?thesis
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1263
    proof(cases "rest = []")
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1264
      case False
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1265
      interpret h_n: valid_trace_v_n s e th cs
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1266
        by (unfold_locales, insert False, simp)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1267
      from waiting(3)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1268
      show ?thesis
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1269
      proof(cases rule:h_n.waiting_esE)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1270
        case 1
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1271
        with waiting(1,2)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1272
        show ?thesis
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1273
        by (unfold h_n.waiting_set_eq h_n.holding_set_eq s_RAG_def, 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1274
             fold waiting_eq, auto)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1275
      next
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1276
        case 2
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1277
        with waiting(1,2)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1278
        show ?thesis
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1279
         by (unfold h_n.waiting_set_eq h_n.holding_set_eq s_RAG_def, 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1280
             fold waiting_eq, auto)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1281
      qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1282
    next
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1283
      case True
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1284
      interpret h_e: valid_trace_v_e s e th cs
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1285
        by (unfold_locales, insert True, simp)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1286
      from waiting(3)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1287
      show ?thesis
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1288
      proof(cases rule:h_e.waiting_esE)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1289
        case 1
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1290
        with waiting(1,2)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1291
        show ?thesis
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1292
        by (unfold h_e.waiting_set_eq h_e.holding_set_eq s_RAG_def, 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1293
             fold waiting_eq, auto)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1294
      qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1295
    qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1296
  next
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1297
    case (holding th' cs')
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1298
    show ?thesis
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1299
    proof(cases "rest = []")
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1300
      case False
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1301
      interpret h_n: valid_trace_v_n s e th cs
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1302
        by (unfold_locales, insert False, simp)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1303
      from holding(3)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1304
      show ?thesis
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1305
      proof(cases rule:h_n.holding_esE)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1306
        case 1
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1307
        with holding(1,2)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1308
        show ?thesis
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1309
        by (unfold h_n.waiting_set_eq h_n.holding_set_eq s_RAG_def, 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1310
             fold waiting_eq, auto)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1311
      next
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1312
        case 2
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1313
        with holding(1,2)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1314
        show ?thesis
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1315
         by (unfold h_n.waiting_set_eq h_n.holding_set_eq s_RAG_def, 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1316
             fold holding_eq, auto)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1317
      qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1318
    next
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1319
      case True
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1320
      interpret h_e: valid_trace_v_e s e th cs
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1321
        by (unfold_locales, insert True, simp)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1322
      from holding(3)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1323
      show ?thesis
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1324
      proof(cases rule:h_e.holding_esE)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1325
        case 1
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1326
        with holding(1,2)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1327
        show ?thesis
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1328
        by (unfold h_e.waiting_set_eq h_e.holding_set_eq s_RAG_def, 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1329
             fold holding_eq, auto)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1330
      qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1331
    qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1332
  qed
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1333
next
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1334
  fix n1 n2
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1335
  assume h: "(n1, n2) \<in> ?R"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1336
  show "(n1, n2) \<in> ?L"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1337
  proof(cases "rest = []")
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1338
    case False
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1339
    interpret h_n: valid_trace_v_n s e th cs
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1340
        by (unfold_locales, insert False, simp)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1341
    from h[unfolded h_n.waiting_set_eq h_n.holding_set_eq]
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1342
    have "((n1, n2) \<in> RAG s \<and> (n1 \<noteq> Cs cs \<or> n2 \<noteq> Th th)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1343
                            \<and> (n1 \<noteq> Th h_n.taker \<or> n2 \<noteq> Cs cs)) \<or> 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1344
          (n2 = Th h_n.taker \<and> n1 = Cs cs)" 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1345
      by auto
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1346
   thus ?thesis
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1347
   proof
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1348
      assume "n2 = Th h_n.taker \<and> n1 = Cs cs"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1349
      with h_n.holding_taker
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1350
      show ?thesis 
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1351
        by (unfold s_RAG_def, fold holding_eq, auto)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1352
   next
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1353
    assume h: "(n1, n2) \<in> RAG s \<and>
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1354
        (n1 \<noteq> Cs cs \<or> n2 \<noteq> Th th) \<and> (n1 \<noteq> Th h_n.taker \<or> n2 \<noteq> Cs cs)"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1355
    hence "(n1, n2) \<in> RAG s" by simp
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1356
    thus ?thesis
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1357
    proof(cases rule:in_RAG_E)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1358
      case (waiting th' cs')
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1359
      thus ?thesis
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1360
    qed
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1361
   qed
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1362
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1363
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1364
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1365
end
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1366
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1367
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1368
lemma step_RAG_v: (* ccc *)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1369
assumes vt:
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1370
  "vt (V th cs#s)"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1371
shows "
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1372
  RAG (V th cs # s) =
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1373
  RAG s - {(Cs cs, Th th)} -
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1374
  {(Th th', Cs cs) |th'. next_th s th cs th'} \<union>
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1375
  {(Cs cs, Th th') |th'.  next_th s th cs th'}" (is "?L = ?R")
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1376
proof(rule rel_eqI)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1377
  fix n1 n2
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1378
  assume "(n1, n2) \<in> ?L"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1379
  show "(n1, n2) \<in> ?R" sorry
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1380
next
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1381
  fix n1 n2
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1382
  assume "(n1, n2) \<in> ?R"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1383
  show "(n1, n2) \<in> ?L" sorry
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1384
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1385
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1386
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1387
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1388
text {* (* ddd *) 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1389
  The following @{text "step_RAG_v"} lemma charaterizes how @{text "RAG"} is changed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1390
  with the happening of @{text "V"}-events:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1391
*}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1392
lemma step_RAG_v:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1393
assumes vt:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1394
  "vt (V th cs#s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1395
shows "
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1396
  RAG (V th cs # s) =
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1397
  RAG s - {(Cs cs, Th th)} -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1398
  {(Th th', Cs cs) |th'. next_th s th cs th'} \<union>
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1399
  {(Cs cs, Th th') |th'.  next_th s th cs th'}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1400
  apply (insert vt, unfold s_RAG_def) 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1401
  apply (auto split:if_splits list.splits simp:Let_def)
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1402
  apply (auto elim: step_v_waiting_mono step_v_hold_inv
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1403
              step_v_release step_v_wait_inv
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1404
              step_v_get_hold step_v_release_inv)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1405
  apply (erule_tac step_v_not_wait, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1406
  done
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1407
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1408
text {* 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1409
  The following @{text "step_RAG_p"} lemma charaterizes how @{text "RAG"} is changed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1410
  with the happening of @{text "P"}-events:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1411
*}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1412
lemma step_RAG_p:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1413
  "vt (P th cs#s) \<Longrightarrow>
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1414
  RAG (P th cs # s) =  (if (wq s cs = []) then RAG s \<union> {(Cs cs, Th th)}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1415
                                             else RAG s \<union> {(Th th, Cs cs)})"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1416
  apply(simp only: s_RAG_def wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1417
  apply (auto split:list.splits prod.splits simp:Let_def wq_def cs_waiting_def cs_holding_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1418
  apply(case_tac "csa = cs", auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1419
  apply(fold wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1420
  apply(drule_tac step_back_step)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1421
  apply(ind_cases " step s (P (hd (wq s cs)) cs)")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1422
  apply(simp add:s_RAG_def wq_def cs_holding_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1423
  apply(auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1424
  done
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1425
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1426
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1427
lemma RAG_target_th: "(Th th, x) \<in> RAG (s::state) \<Longrightarrow> \<exists> cs. x = Cs cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1428
  by (unfold s_RAG_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1429
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1430
context valid_trace
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1431
begin
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1432
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1433
text {*
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1434
  The following lemma shows that @{text "RAG"} is acyclic.
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1435
  The overall structure is by induction on the formation of @{text "vt s"}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1436
  and then case analysis on event @{text "e"}, where the non-trivial cases 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1437
  for those for @{text "V"} and @{text "P"} events.
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1438
*}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1439
lemma acyclic_RAG:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1440
  shows "acyclic (RAG s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1441
using vt
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1442
proof(induct)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1443
  case (vt_cons s e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1444
  interpret vt_s: valid_trace s using vt_cons(1)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1445
    by (unfold_locales, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1446
  assume ih: "acyclic (RAG s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1447
    and stp: "step s e"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1448
    and vt: "vt s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1449
  show ?case
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1450
  proof(cases e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1451
    case (Create th prio)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1452
    with ih
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1453
    show ?thesis by (simp add:RAG_create_unchanged)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1454
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1455
    case (Exit th)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1456
    with ih show ?thesis by (simp add:RAG_exit_unchanged)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1457
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1458
    case (V th cs)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1459
    from V vt stp have vtt: "vt (V th cs#s)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1460
    from step_RAG_v [OF this]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1461
    have eq_de: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1462
      "RAG (e # s) = 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1463
      RAG s - {(Cs cs, Th th)} - {(Th th', Cs cs) |th'. next_th s th cs th'} \<union>
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1464
      {(Cs cs, Th th') |th'. next_th s th cs th'}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1465
      (is "?L = (?A - ?B - ?C) \<union> ?D") by (simp add:V)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1466
    from ih have ac: "acyclic (?A - ?B - ?C)" by (auto elim:acyclic_subset)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1467
    from step_back_step [OF vtt]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1468
    have "step s (V th cs)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1469
    thus ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1470
    proof(cases)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1471
      assume "holding s th cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1472
      hence th_in: "th \<in> set (wq s cs)" and
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1473
        eq_hd: "th = hd (wq s cs)" unfolding s_holding_def wq_def by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1474
      then obtain rest where
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1475
        eq_wq: "wq s cs = th#rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1476
        by (cases "wq s cs", auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1477
      show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1478
      proof(cases "rest = []")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1479
        case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1480
        let ?th' = "hd (SOME q. distinct q \<and> set q = set rest)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1481
        from eq_wq False have eq_D: "?D = {(Cs cs, Th ?th')}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1482
          by (unfold next_th_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1483
        let ?E = "(?A - ?B - ?C)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1484
        have "(Th ?th', Cs cs) \<notin> ?E\<^sup>*"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1485
        proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1486
          assume "(Th ?th', Cs cs) \<in> ?E\<^sup>*"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1487
          hence " (Th ?th', Cs cs) \<in> ?E\<^sup>+" by (simp add: rtrancl_eq_or_trancl)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1488
          from tranclD [OF this]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1489
          obtain x where th'_e: "(Th ?th', x) \<in> ?E" by blast
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1490
          hence th_d: "(Th ?th', x) \<in> ?A" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1491
          from RAG_target_th [OF this]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1492
          obtain cs' where eq_x: "x = Cs cs'" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1493
          with th_d have "(Th ?th', Cs cs') \<in> ?A" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1494
          hence wt_th': "waiting s ?th' cs'"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1495
            unfolding s_RAG_def s_waiting_def cs_waiting_def wq_def by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1496
          hence "cs' = cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1497
          proof(rule vt_s.waiting_unique)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1498
            from eq_wq vt_s.wq_distinct[of cs]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1499
            show "waiting s ?th' cs" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1500
              apply (unfold s_waiting_def wq_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1501
            proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1502
              assume hd_in: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1503
                and eq_wq: "wq_fun (schs s) cs = th # rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1504
              have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1505
              proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1506
                from vt_s.wq_distinct[of cs] and eq_wq
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1507
                show "distinct rest \<and> set rest = set rest" unfolding wq_def by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1508
              next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1509
                fix x assume "distinct x \<and> set x = set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1510
                with False show "x \<noteq> []" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1511
              qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1512
              hence "hd (SOME q. distinct q \<and> set q = set rest) \<in> 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1513
                set (SOME q. distinct q \<and> set q = set rest)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1514
              moreover have "\<dots> = set rest" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1515
              proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1516
                from vt_s.wq_distinct[of cs] and eq_wq
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1517
                show "distinct rest \<and> set rest = set rest" unfolding wq_def by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1518
              next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1519
                show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1520
              qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1521
              moreover note hd_in
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1522
              ultimately show "hd (SOME q. distinct q \<and> set q = set rest) = th" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1523
            next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1524
              assume hd_in: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1525
                and eq_wq: "wq s cs = hd (SOME q. distinct q \<and> set q = set rest) # rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1526
              have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1527
              proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1528
                from vt_s.wq_distinct[of cs] and eq_wq
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1529
                show "distinct rest \<and> set rest = set rest" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1530
              next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1531
                fix x assume "distinct x \<and> set x = set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1532
                with False show "x \<noteq> []" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1533
              qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1534
              hence "hd (SOME q. distinct q \<and> set q = set rest) \<in> 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1535
                set (SOME q. distinct q \<and> set q = set rest)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1536
              moreover have "\<dots> = set rest" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1537
              proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1538
                from vt_s.wq_distinct[of cs] and eq_wq
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1539
                show "distinct rest \<and> set rest = set rest" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1540
              next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1541
                show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1542
              qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1543
              moreover note hd_in
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1544
              ultimately show False by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1545
            qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1546
          qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1547
          with th'_e eq_x have "(Th ?th', Cs cs) \<in> ?E" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1548
          with False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1549
          show "False" by (auto simp: next_th_def eq_wq)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1550
        qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1551
        with acyclic_insert[symmetric] and ac
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1552
          and eq_de eq_D show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1553
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1554
        case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1555
        with eq_wq
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1556
        have eq_D: "?D = {}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1557
          by (unfold next_th_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1558
        with eq_de ac
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1559
        show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1560
      qed 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1561
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1562
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1563
    case (P th cs)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1564
    from P vt stp have vtt: "vt (P th cs#s)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1565
    from step_RAG_p [OF this] P
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1566
    have "RAG (e # s) = 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1567
      (if wq s cs = [] then RAG s \<union> {(Cs cs, Th th)} else 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1568
      RAG s \<union> {(Th th, Cs cs)})" (is "?L = ?R")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1569
      by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1570
    moreover have "acyclic ?R"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1571
    proof(cases "wq s cs = []")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1572
      case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1573
      hence eq_r: "?R =  RAG s \<union> {(Cs cs, Th th)}" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1574
      have "(Th th, Cs cs) \<notin> (RAG s)\<^sup>*"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1575
      proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1576
        assume "(Th th, Cs cs) \<in> (RAG s)\<^sup>*"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1577
        hence "(Th th, Cs cs) \<in> (RAG s)\<^sup>+" by (simp add: rtrancl_eq_or_trancl)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1578
        from tranclD2 [OF this]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1579
        obtain x where "(x, Cs cs) \<in> RAG s" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1580
        with True show False by (auto simp:s_RAG_def cs_waiting_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1581
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1582
      with acyclic_insert ih eq_r show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1583
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1584
      case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1585
      hence eq_r: "?R =  RAG s \<union> {(Th th, Cs cs)}" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1586
      have "(Cs cs, Th th) \<notin> (RAG s)\<^sup>*"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1587
      proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1588
        assume "(Cs cs, Th th) \<in> (RAG s)\<^sup>*"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1589
        hence "(Cs cs, Th th) \<in> (RAG s)\<^sup>+" by (simp add: rtrancl_eq_or_trancl)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1590
        moreover from step_back_step [OF vtt] have "step s (P th cs)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1591
        ultimately show False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1592
        proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1593
          show " \<lbrakk>(Cs cs, Th th) \<in> (RAG s)\<^sup>+; step s (P th cs)\<rbrakk> \<Longrightarrow> False"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1594
            by (ind_cases "step s (P th cs)", simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1595
        qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1596
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1597
      with acyclic_insert ih eq_r show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1598
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1599
      ultimately show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1600
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1601
      case (Set thread prio)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1602
      with ih
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1603
      thm RAG_set_unchanged
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1604
      show ?thesis by (simp add:RAG_set_unchanged)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1605
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1606
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1607
    case vt_nil
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1608
    show "acyclic (RAG ([]::state))"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1609
      by (auto simp: s_RAG_def cs_waiting_def 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1610
        cs_holding_def wq_def acyclic_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1611
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1612
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1613
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1614
lemma finite_RAG:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1615
  shows "finite (RAG s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1616
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1617
  from vt show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1618
  proof(induct)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1619
    case (vt_cons s e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1620
    interpret vt_s: valid_trace s using vt_cons(1)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1621
      by (unfold_locales, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1622
    assume ih: "finite (RAG s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1623
      and stp: "step s e"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1624
      and vt: "vt s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1625
    show ?case
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1626
    proof(cases e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1627
      case (Create th prio)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1628
      with ih
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1629
      show ?thesis by (simp add:RAG_create_unchanged)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1630
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1631
      case (Exit th)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1632
      with ih show ?thesis by (simp add:RAG_exit_unchanged)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1633
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1634
      case (V th cs)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1635
      from V vt stp have vtt: "vt (V th cs#s)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1636
      from step_RAG_v [OF this]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1637
      have eq_de: "RAG (e # s) = 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1638
                   RAG s - {(Cs cs, Th th)} - {(Th th', Cs cs) |th'. next_th s th cs th'} \<union>
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1639
                      {(Cs cs, Th th') |th'. next_th s th cs th'}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1640
"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1641
        (is "?L = (?A - ?B - ?C) \<union> ?D") by (simp add:V)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1642
      moreover from ih have ac: "finite (?A - ?B - ?C)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1643
      moreover have "finite ?D"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1644
      proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1645
        have "?D = {} \<or> (\<exists> a. ?D = {a})" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1646
          by (unfold next_th_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1647
        thus ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1648
        proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1649
          assume h: "?D = {}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1650
          show ?thesis by (unfold h, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1651
        next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1652
          assume "\<exists> a. ?D = {a}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1653
          thus ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1654
            by (metis finite.simps)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1655
        qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1656
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1657
      ultimately show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1658
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1659
      case (P th cs)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1660
      from P vt stp have vtt: "vt (P th cs#s)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1661
      from step_RAG_p [OF this] P
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1662
      have "RAG (e # s) = 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1663
              (if wq s cs = [] then RAG s \<union> {(Cs cs, Th th)} else 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1664
                                    RAG s \<union> {(Th th, Cs cs)})" (is "?L = ?R")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1665
        by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1666
      moreover have "finite ?R"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1667
      proof(cases "wq s cs = []")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1668
        case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1669
        hence eq_r: "?R =  RAG s \<union> {(Cs cs, Th th)}" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1670
        with True and ih show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1671
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1672
        case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1673
        hence "?R = RAG s \<union> {(Th th, Cs cs)}" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1674
        with False and ih show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1675
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1676
      ultimately show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1677
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1678
      case (Set thread prio)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1679
      with ih
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1680
      show ?thesis by (simp add:RAG_set_unchanged)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1681
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1682
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1683
    case vt_nil
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1684
    show "finite (RAG ([]::state))"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1685
      by (auto simp: s_RAG_def cs_waiting_def 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1686
                   cs_holding_def wq_def acyclic_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1687
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1688
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1689
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1690
text {* Several useful lemmas *}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1691
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1692
lemma wf_dep_converse: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1693
  shows "wf ((RAG s)^-1)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1694
proof(rule finite_acyclic_wf_converse)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1695
  from finite_RAG 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1696
  show "finite (RAG s)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1697
next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1698
  from acyclic_RAG
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1699
  show "acyclic (RAG s)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1700
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1701
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1702
end
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1703
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1704
lemma hd_np_in: "x \<in> set l \<Longrightarrow> hd l \<in> set l"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1705
  by (induct l, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1706
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1707
lemma th_chasing: "(Th th, Cs cs) \<in> RAG (s::state) \<Longrightarrow> \<exists> th'. (Cs cs, Th th') \<in> RAG s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1708
  by (auto simp:s_RAG_def s_holding_def cs_holding_def cs_waiting_def wq_def dest:hd_np_in)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1709
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1710
context valid_trace
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1711
begin
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1712
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1713
lemma wq_threads: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1714
  assumes h: "th \<in> set (wq s cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1715
  shows "th \<in> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1716
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1717
 from vt and h show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1718
  proof(induct arbitrary: th cs)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1719
    case (vt_cons s e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1720
    interpret vt_s: valid_trace s
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1721
      using vt_cons(1) by (unfold_locales, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1722
    assume ih: "\<And>th cs. th \<in> set (wq s cs) \<Longrightarrow> th \<in> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1723
      and stp: "step s e"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1724
      and vt: "vt s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1725
      and h: "th \<in> set (wq (e # s) cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1726
    show ?case
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1727
    proof(cases e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1728
      case (Create th' prio)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1729
      with ih h show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1730
        by (auto simp:wq_def Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1731
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1732
      case (Exit th')
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1733
      with stp ih h show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1734
        apply (auto simp:wq_def Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1735
        apply (ind_cases "step s (Exit th')")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1736
        apply (auto simp:runing_def readys_def s_holding_def s_waiting_def holdents_def
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1737
               s_RAG_def s_holding_def cs_holding_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1738
        done
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1739
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1740
      case (V th' cs')
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1741
      show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1742
      proof(cases "cs' = cs")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1743
        case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1744
        with h
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1745
        show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1746
          apply(unfold wq_def V, auto simp:Let_def V split:prod.splits, fold wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1747
          by (drule_tac ih, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1748
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1749
        case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1750
        from h
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1751
        show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1752
        proof(unfold V wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1753
          assume th_in: "th \<in> set (wq_fun (schs (V th' cs' # s)) cs)" (is "th \<in> set ?l")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1754
          show "th \<in> threads (V th' cs' # s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1755
          proof(cases "cs = cs'")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1756
            case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1757
            hence "?l = wq_fun (schs s) cs" by (simp add:Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1758
            with th_in have " th \<in> set (wq s cs)" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1759
              by (fold wq_def, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1760
            from ih [OF this] show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1761
          next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1762
            case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1763
            show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1764
            proof(cases "wq_fun (schs s) cs'")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1765
              case Nil
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1766
              with h V show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1767
                apply (auto simp:wq_def Let_def split:if_splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1768
                by (fold wq_def, drule_tac ih, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1769
            next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1770
              case (Cons a rest)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1771
              assume eq_wq: "wq_fun (schs s) cs' = a # rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1772
              with h V show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1773
                apply (auto simp:Let_def wq_def split:if_splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1774
              proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1775
                assume th_in: "th \<in> set (SOME q. distinct q \<and> set q = set rest)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1776
                have "set (SOME q. distinct q \<and> set q = set rest) = set rest" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1777
                proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1778
                  from vt_s.wq_distinct[of cs'] and eq_wq[folded wq_def]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1779
                  show "distinct rest \<and> set rest = set rest" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1780
                next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1781
                  show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1782
                    by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1783
                qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1784
                with eq_wq th_in have "th \<in> set (wq_fun (schs s) cs')" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1785
                from ih[OF this[folded wq_def]] show "th \<in> threads s" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1786
              next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1787
                assume th_in: "th \<in> set (wq_fun (schs s) cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1788
                from ih[OF this[folded wq_def]]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1789
                show "th \<in> threads s" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1790
              qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1791
            qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1792
          qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1793
        qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1794
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1795
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1796
      case (P th' cs')
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1797
      from h stp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1798
      show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1799
        apply (unfold P wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1800
        apply (auto simp:Let_def split:if_splits, fold wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1801
        apply (auto intro:ih)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1802
        apply(ind_cases "step s (P th' cs')")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1803
        by (unfold runing_def readys_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1804
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1805
      case (Set thread prio)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1806
      with ih h show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1807
        by (auto simp:wq_def Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1808
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1809
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1810
    case vt_nil
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1811
    thus ?case by (auto simp:wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1812
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1813
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1814
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1815
lemma range_in: "\<lbrakk>(Th th) \<in> Range (RAG (s::state))\<rbrakk> \<Longrightarrow> th \<in> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1816
  apply(unfold s_RAG_def cs_waiting_def cs_holding_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1817
  by (auto intro:wq_threads)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1818
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1819
lemma readys_v_eq:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1820
  assumes neq_th: "th \<noteq> thread"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1821
  and eq_wq: "wq s cs = thread#rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1822
  and not_in: "th \<notin>  set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1823
  shows "(th \<in> readys (V thread cs#s)) = (th \<in> readys s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1824
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1825
  from assms show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1826
    apply (auto simp:readys_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1827
    apply(simp add:s_waiting_def[folded wq_def])
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1828
    apply (erule_tac x = csa in allE)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1829
    apply (simp add:s_waiting_def wq_def Let_def split:if_splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1830
    apply (case_tac "csa = cs", simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1831
    apply (erule_tac x = cs in allE)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1832
    apply(auto simp add: s_waiting_def[folded wq_def] Let_def split: list.splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1833
    apply(auto simp add: wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1834
    apply (auto simp:s_waiting_def wq_def Let_def split:list.splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1835
    proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1836
       assume th_nin: "th \<notin> set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1837
        and th_in: "th \<in> set (SOME q. distinct q \<and> set q = set rest)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1838
        and eq_wq: "wq_fun (schs s) cs = thread # rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1839
      have "set (SOME q. distinct q \<and> set q = set rest) = set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1840
      proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1841
        from wq_distinct[of cs, unfolded wq_def] and eq_wq[unfolded wq_def]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1842
        show "distinct rest \<and> set rest = set rest" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1843
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1844
        show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1845
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1846
      with th_nin th_in show False by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1847
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1848
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1849
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1850
text {* \noindent
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1851
  The following lemmas shows that: starting from any node in @{text "RAG"}, 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1852
  by chasing out-going edges, it is always possible to reach a node representing a ready
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1853
  thread. In this lemma, it is the @{text "th'"}.
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1854
*}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1855
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1856
lemma chain_building:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1857
  shows "node \<in> Domain (RAG s) \<longrightarrow> (\<exists> th'. th' \<in> readys s \<and> (node, Th th') \<in> (RAG s)^+)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1858
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1859
  from wf_dep_converse
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1860
  have h: "wf ((RAG s)\<inverse>)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1861
  show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1862
  proof(induct rule:wf_induct [OF h])
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1863
    fix x
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1864
    assume ih [rule_format]: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1865
      "\<forall>y. (y, x) \<in> (RAG s)\<inverse> \<longrightarrow> 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1866
           y \<in> Domain (RAG s) \<longrightarrow> (\<exists>th'. th' \<in> readys s \<and> (y, Th th') \<in> (RAG s)\<^sup>+)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1867
    show "x \<in> Domain (RAG s) \<longrightarrow> (\<exists>th'. th' \<in> readys s \<and> (x, Th th') \<in> (RAG s)\<^sup>+)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1868
    proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1869
      assume x_d: "x \<in> Domain (RAG s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1870
      show "\<exists>th'. th' \<in> readys s \<and> (x, Th th') \<in> (RAG s)\<^sup>+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1871
      proof(cases x)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1872
        case (Th th)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1873
        from x_d Th obtain cs where x_in: "(Th th, Cs cs) \<in> RAG s" by (auto simp:s_RAG_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1874
        with Th have x_in_r: "(Cs cs, x) \<in> (RAG s)^-1" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1875
        from th_chasing [OF x_in] obtain th' where "(Cs cs, Th th') \<in> RAG s" by blast
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1876
        hence "Cs cs \<in> Domain (RAG s)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1877
        from ih [OF x_in_r this] obtain th'
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1878
          where th'_ready: " th' \<in> readys s" and cs_in: "(Cs cs, Th th') \<in> (RAG s)\<^sup>+" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1879
        have "(x, Th th') \<in> (RAG s)\<^sup>+" using Th x_in cs_in by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1880
        with th'_ready show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1881
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1882
        case (Cs cs)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1883
        from x_d Cs obtain th' where th'_d: "(Th th', x) \<in> (RAG s)^-1" by (auto simp:s_RAG_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1884
        show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1885
        proof(cases "th' \<in> readys s")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1886
          case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1887
          from True and th'_d show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1888
        next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1889
          case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1890
          from th'_d and range_in  have "th' \<in> threads s" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1891
          with False have "Th th' \<in> Domain (RAG s)" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1892
            by (auto simp:readys_def wq_def s_waiting_def s_RAG_def cs_waiting_def Domain_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1893
          from ih [OF th'_d this]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1894
          obtain th'' where 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1895
            th''_r: "th'' \<in> readys s" and 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1896
            th''_in: "(Th th', Th th'') \<in> (RAG s)\<^sup>+" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1897
          from th'_d and th''_in 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1898
          have "(x, Th th'') \<in> (RAG s)\<^sup>+" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1899
          with th''_r show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1900
        qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1901
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1902
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1903
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1904
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1905
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1906
text {* \noindent
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1907
  The following is just an instance of @{text "chain_building"}.
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1908
*}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1909
lemma th_chain_to_ready:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1910
  assumes th_in: "th \<in> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1911
  shows "th \<in> readys s \<or> (\<exists> th'. th' \<in> readys s \<and> (Th th, Th th') \<in> (RAG s)^+)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1912
proof(cases "th \<in> readys s")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1913
  case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1914
  thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1915
next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1916
  case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1917
  from False and th_in have "Th th \<in> Domain (RAG s)" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1918
    by (auto simp:readys_def s_waiting_def s_RAG_def wq_def cs_waiting_def Domain_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1919
  from chain_building [rule_format, OF this]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1920
  show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1921
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1922
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1923
end
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1924
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  1925
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1926
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1927
lemma holding_unique: "\<lbrakk>holding (s::state) th1 cs; holding s th2 cs\<rbrakk> \<Longrightarrow> th1 = th2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1928
  by (unfold s_holding_def cs_holding_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1929
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1930
context valid_trace
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1931
begin
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1932
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1933
lemma unique_RAG: "\<lbrakk>(n, n1) \<in> RAG s; (n, n2) \<in> RAG s\<rbrakk> \<Longrightarrow> n1 = n2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1934
  apply(unfold s_RAG_def, auto, fold waiting_eq holding_eq)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1935
  by(auto elim:waiting_unique holding_unique)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1936
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1937
end
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1938
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1939
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1940
lemma trancl_split: "(a, b) \<in> r^+ \<Longrightarrow> \<exists> c. (a, c) \<in> r"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1941
by (induct rule:trancl_induct, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1942
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1943
context valid_trace
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1944
begin
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1945
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1946
lemma dchain_unique:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1947
  assumes th1_d: "(n, Th th1) \<in> (RAG s)^+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1948
  and th1_r: "th1 \<in> readys s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1949
  and th2_d: "(n, Th th2) \<in> (RAG s)^+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1950
  and th2_r: "th2 \<in> readys s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1951
  shows "th1 = th2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1952
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1953
  { assume neq: "th1 \<noteq> th2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1954
    hence "Th th1 \<noteq> Th th2" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1955
    from unique_chain [OF _ th1_d th2_d this] and unique_RAG 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1956
    have "(Th th1, Th th2) \<in> (RAG s)\<^sup>+ \<or> (Th th2, Th th1) \<in> (RAG s)\<^sup>+" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1957
    hence "False"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1958
    proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1959
      assume "(Th th1, Th th2) \<in> (RAG s)\<^sup>+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1960
      from trancl_split [OF this]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1961
      obtain n where dd: "(Th th1, n) \<in> RAG s" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1962
      then obtain cs where eq_n: "n = Cs cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1963
        by (auto simp:s_RAG_def s_holding_def cs_holding_def cs_waiting_def wq_def dest:hd_np_in)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1964
      from dd eq_n have "th1 \<notin> readys s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1965
        by (auto simp:readys_def s_RAG_def wq_def s_waiting_def cs_waiting_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1966
      with th1_r show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1967
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1968
      assume "(Th th2, Th th1) \<in> (RAG s)\<^sup>+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1969
      from trancl_split [OF this]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1970
      obtain n where dd: "(Th th2, n) \<in> RAG s" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1971
      then obtain cs where eq_n: "n = Cs cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1972
        by (auto simp:s_RAG_def s_holding_def cs_holding_def cs_waiting_def wq_def dest:hd_np_in)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1973
      from dd eq_n have "th2 \<notin> readys s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1974
        by (auto simp:readys_def wq_def s_RAG_def s_waiting_def cs_waiting_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1975
      with th2_r show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1976
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1977
  } thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1978
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1979
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1980
end
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1981
             
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1982
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1983
lemma step_holdents_p_add:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1984
  assumes vt: "vt (P th cs#s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1985
  and "wq s cs = []"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1986
  shows "holdents (P th cs#s) th = holdents s th \<union> {cs}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1987
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1988
  from assms show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1989
  unfolding  holdents_test step_RAG_p[OF vt] by (auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1990
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1991
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1992
lemma step_holdents_p_eq:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1993
  assumes vt: "vt (P th cs#s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1994
  and "wq s cs \<noteq> []"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1995
  shows "holdents (P th cs#s) th = holdents s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1996
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1997
  from assms show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1998
  unfolding  holdents_test step_RAG_p[OF vt] by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1999
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2000
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2001
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2002
lemma (in valid_trace) finite_holding :
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2003
  shows "finite (holdents s th)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2004
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2005
  let ?F = "\<lambda> (x, y). the_cs x"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2006
  from finite_RAG 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2007
  have "finite (RAG s)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2008
  hence "finite (?F `(RAG s))" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2009
  moreover have "{cs . (Cs cs, Th th) \<in> RAG s} \<subseteq> \<dots>" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2010
  proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2011
    { have h: "\<And> a A f. a \<in> A \<Longrightarrow> f a \<in> f ` A" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2012
      fix x assume "(Cs x, Th th) \<in> RAG s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2013
      hence "?F (Cs x, Th th) \<in> ?F `(RAG s)" by (rule h)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2014
      moreover have "?F (Cs x, Th th) = x" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2015
      ultimately have "x \<in> (\<lambda>(x, y). the_cs x) ` RAG s" by simp 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2016
    } thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2017
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2018
  ultimately show ?thesis by (unfold holdents_test, auto intro:finite_subset)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2019
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2020
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2021
lemma cntCS_v_dec: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2022
  assumes vtv: "vt (V thread cs#s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2023
  shows "(cntCS (V thread cs#s) thread + 1) = cntCS s thread"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2024
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2025
  from vtv interpret vt_s: valid_trace s
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2026
    by (cases, unfold_locales, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2027
  from vtv interpret vt_v: valid_trace "V thread cs#s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2028
     by (unfold_locales, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2029
  from step_back_step[OF vtv]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2030
  have cs_in: "cs \<in> holdents s thread" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2031
    apply (cases, unfold holdents_test s_RAG_def, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2032
    by (unfold cs_holding_def s_holding_def wq_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2033
  moreover have cs_not_in: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2034
    "(holdents (V thread cs#s) thread) = holdents s thread - {cs}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2035
    apply (insert vt_s.wq_distinct[of cs])
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2036
    apply (unfold holdents_test, unfold step_RAG_v[OF vtv],
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2037
            auto simp:next_th_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2038
  proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2039
    fix rest
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2040
    assume dst: "distinct (rest::thread list)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2041
      and ne: "rest \<noteq> []"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2042
    and hd_ni: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2043
    moreover have "set (SOME q. distinct q \<and> set q = set rest) = set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2044
    proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2045
      from dst show "distinct rest \<and> set rest = set rest" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2046
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2047
      show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2048
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2049
    ultimately have "hd (SOME q. distinct q \<and> set q = set rest) \<notin> 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2050
                     set (SOME q. distinct q \<and> set q = set rest)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2051
    moreover have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2052
    proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2053
      from dst show "distinct rest \<and> set rest = set rest" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2054
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2055
      fix x assume " distinct x \<and> set x = set rest" with ne
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2056
      show "x \<noteq> []" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2057
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2058
    ultimately 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2059
    show "(Cs cs, Th (hd (SOME q. distinct q \<and> set q = set rest))) \<in> RAG s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2060
      by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2061
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2062
    fix rest
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2063
    assume dst: "distinct (rest::thread list)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2064
      and ne: "rest \<noteq> []"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2065
    and hd_ni: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2066
    moreover have "set (SOME q. distinct q \<and> set q = set rest) = set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2067
    proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2068
      from dst show "distinct rest \<and> set rest = set rest" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2069
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2070
      show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2071
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2072
    ultimately have "hd (SOME q. distinct q \<and> set q = set rest) \<notin> 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2073
                     set (SOME q. distinct q \<and> set q = set rest)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2074
    moreover have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2075
    proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2076
      from dst show "distinct rest \<and> set rest = set rest" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2077
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2078
      fix x assume " distinct x \<and> set x = set rest" with ne
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2079
      show "x \<noteq> []" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2080
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2081
    ultimately show "False" by auto 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2082
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2083
  ultimately 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2084
  have "holdents s thread = insert cs (holdents (V thread cs#s) thread)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2085
    by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2086
  moreover have "card \<dots> = 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2087
                    Suc (card ((holdents (V thread cs#s) thread) - {cs}))"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2088
  proof(rule card_insert)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2089
    from vt_v.finite_holding
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2090
    show " finite (holdents (V thread cs # s) thread)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2091
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2092
  moreover from cs_not_in 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2093
  have "cs \<notin> (holdents (V thread cs#s) thread)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2094
  ultimately show ?thesis by (simp add:cntCS_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2095
qed 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2096
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2097
lemma count_rec1 [simp]: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2098
  assumes "Q e"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2099
  shows "count Q (e#es) = Suc (count Q es)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2100
  using assms
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2101
  by (unfold count_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2102
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2103
lemma count_rec2 [simp]: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2104
  assumes "\<not>Q e"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2105
  shows "count Q (e#es) = (count Q es)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2106
  using assms
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2107
  by (unfold count_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2108
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2109
lemma count_rec3 [simp]: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2110
  shows "count Q [] =  0"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2111
  by (unfold count_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2112
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2113
lemma cntP_diff_inv:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2114
  assumes "cntP (e#s) th \<noteq> cntP s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2115
  shows "isP e \<and> actor e = th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2116
proof(cases e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2117
  case (P th' pty)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2118
  show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2119
  by (cases "(\<lambda>e. \<exists>cs. e = P th cs) (P th' pty)", 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2120
        insert assms P, auto simp:cntP_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2121
qed (insert assms, auto simp:cntP_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2122
  
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2123
lemma cntV_diff_inv:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2124
  assumes "cntV (e#s) th \<noteq> cntV s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2125
  shows "isV e \<and> actor e = th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2126
proof(cases e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2127
  case (V th' pty)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2128
  show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2129
  by (cases "(\<lambda>e. \<exists>cs. e = V th cs) (V th' pty)", 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2130
        insert assms V, auto simp:cntV_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2131
qed (insert assms, auto simp:cntV_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2132
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2133
context valid_trace
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2134
begin
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2135
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2136
text {* (* ddd *) \noindent
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2137
  The relationship between @{text "cntP"}, @{text "cntV"} and @{text "cntCS"} 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2138
  of one particular thread. 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2139
*} 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2140
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2141
lemma cnp_cnv_cncs:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2142
  shows "cntP s th = cntV s th + (if (th \<in> readys s \<or> th \<notin> threads s) 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2143
                                       then cntCS s th else cntCS s th + 1)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2144
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2145
  from vt show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2146
  proof(induct arbitrary:th)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2147
    case (vt_cons s e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2148
    interpret vt_s: valid_trace s using vt_cons(1) by (unfold_locales, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2149
    assume vt: "vt s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2150
    and ih: "\<And>th. cntP s th  = cntV s th +
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2151
               (if (th \<in> readys s \<or> th \<notin> threads s) then cntCS s th else cntCS s th + 1)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2152
    and stp: "step s e"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2153
    from stp show ?case
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2154
    proof(cases)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2155
      case (thread_create thread prio)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2156
      assume eq_e: "e = Create thread prio"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2157
        and not_in: "thread \<notin> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2158
      show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2159
      proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2160
        { fix cs 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2161
          assume "thread \<in> set (wq s cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2162
          from vt_s.wq_threads [OF this] have "thread \<in> threads s" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2163
          with not_in have "False" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2164
        } with eq_e have eq_readys: "readys (e#s) = readys s \<union> {thread}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2165
          by (auto simp:readys_def threads.simps s_waiting_def 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2166
            wq_def cs_waiting_def Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2167
        from eq_e have eq_cnp: "cntP (e#s) th = cntP s th" by (simp add:cntP_def count_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2168
        from eq_e have eq_cnv: "cntV (e#s) th = cntV s th" by (simp add:cntV_def count_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2169
        have eq_cncs: "cntCS (e#s) th = cntCS s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2170
          unfolding cntCS_def holdents_test
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2171
          by (simp add:RAG_create_unchanged eq_e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2172
        { assume "th \<noteq> thread"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2173
          with eq_readys eq_e
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2174
          have "(th \<in> readys (e # s) \<or> th \<notin> threads (e # s)) = 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2175
                      (th \<in> readys (s) \<or> th \<notin> threads (s))" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2176
            by (simp add:threads.simps)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2177
          with eq_cnp eq_cnv eq_cncs ih not_in
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2178
          have ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2179
        } moreover {
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2180
          assume eq_th: "th = thread"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2181
          with not_in ih have " cntP s th  = cntV s th + cntCS s th" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2182
          moreover from eq_th and eq_readys have "th \<in> readys (e#s)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2183
          moreover note eq_cnp eq_cnv eq_cncs
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2184
          ultimately have ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2185
        } ultimately show ?thesis by blast
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2186
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2187
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2188
      case (thread_exit thread)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2189
      assume eq_e: "e = Exit thread" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2190
      and is_runing: "thread \<in> runing s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2191
      and no_hold: "holdents s thread = {}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2192
      from eq_e have eq_cnp: "cntP (e#s) th = cntP s th" by (simp add:cntP_def count_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2193
      from eq_e have eq_cnv: "cntV (e#s) th = cntV s th" by (simp add:cntV_def count_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2194
      have eq_cncs: "cntCS (e#s) th = cntCS s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2195
        unfolding cntCS_def holdents_test
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2196
        by (simp add:RAG_exit_unchanged eq_e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2197
      { assume "th \<noteq> thread"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2198
        with eq_e
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2199
        have "(th \<in> readys (e # s) \<or> th \<notin> threads (e # s)) = 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2200
          (th \<in> readys (s) \<or> th \<notin> threads (s))" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2201
          apply (simp add:threads.simps readys_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2202
          apply (subst s_waiting_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2203
          apply (simp add:Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2204
          apply (subst s_waiting_def, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2205
          done
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2206
        with eq_cnp eq_cnv eq_cncs ih
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2207
        have ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2208
      } moreover {
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2209
        assume eq_th: "th = thread"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2210
        with ih is_runing have " cntP s th = cntV s th + cntCS s th" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2211
          by (simp add:runing_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2212
        moreover from eq_th eq_e have "th \<notin> threads (e#s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2213
          by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2214
        moreover note eq_cnp eq_cnv eq_cncs
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2215
        ultimately have ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2216
      } ultimately show ?thesis by blast
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2217
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2218
      case (thread_P thread cs)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2219
      assume eq_e: "e = P thread cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2220
        and is_runing: "thread \<in> runing s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2221
        and no_dep: "(Cs cs, Th thread) \<notin> (RAG s)\<^sup>+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2222
      from thread_P vt stp ih  have vtp: "vt (P thread cs#s)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2223
      then interpret vt_p: valid_trace "(P thread cs#s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2224
        by (unfold_locales, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2225
      show ?thesis 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2226
      proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2227
        { have hh: "\<And> A B C. (B = C) \<Longrightarrow> (A \<and> B) = (A \<and> C)" by blast
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2228
          assume neq_th: "th \<noteq> thread"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2229
          with eq_e
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2230
          have eq_readys: "(th \<in> readys (e#s)) = (th \<in> readys (s))"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2231
            apply (simp add:readys_def s_waiting_def wq_def Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2232
            apply (rule_tac hh)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2233
             apply (intro iffI allI, clarify)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2234
            apply (erule_tac x = csa in allE, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2235
            apply (subgoal_tac "wq_fun (schs s) cs \<noteq> []", auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2236
            apply (erule_tac x = cs in allE, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2237
            by (case_tac "(wq_fun (schs s) cs)", auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2238
          moreover from neq_th eq_e have "cntCS (e # s) th = cntCS s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2239
            apply (simp add:cntCS_def holdents_test)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2240
            by (unfold  step_RAG_p [OF vtp], auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2241
          moreover from eq_e neq_th have "cntP (e # s) th = cntP s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2242
            by (simp add:cntP_def count_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2243
          moreover from eq_e neq_th have "cntV (e#s) th = cntV s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2244
            by (simp add:cntV_def count_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2245
          moreover from eq_e neq_th have "threads (e#s) = threads s" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2246
          moreover note ih [of th] 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2247
          ultimately have ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2248
        } moreover {
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2249
          assume eq_th: "th = thread"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2250
          have ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2251
          proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2252
            from eq_e eq_th have eq_cnp: "cntP (e # s) th  = 1 + (cntP s th)" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2253
              by (simp add:cntP_def count_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2254
            from eq_e eq_th have eq_cnv: "cntV (e#s) th = cntV s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2255
              by (simp add:cntV_def count_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2256
            show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2257
            proof (cases "wq s cs = []")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2258
              case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2259
              with is_runing
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2260
              have "th \<in> readys (e#s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2261
                apply (unfold eq_e wq_def, unfold readys_def s_RAG_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2262
                apply (simp add: wq_def[symmetric] runing_def eq_th s_waiting_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2263
                by (auto simp:readys_def wq_def Let_def s_waiting_def wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2264
              moreover have "cntCS (e # s) th = 1 + cntCS s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2265
              proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2266
                have "card {csa. csa = cs \<or> (Cs csa, Th thread) \<in> RAG s} =
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2267
                  Suc (card {cs. (Cs cs, Th thread) \<in> RAG s})" (is "card ?L = Suc (card ?R)")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2268
                proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2269
                  have "?L = insert cs ?R" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2270
                  moreover have "card \<dots> = Suc (card (?R - {cs}))" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2271
                  proof(rule card_insert)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2272
                    from vt_s.finite_holding [of thread]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2273
                    show " finite {cs. (Cs cs, Th thread) \<in> RAG s}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2274
                      by (unfold holdents_test, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2275
                  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2276
                  moreover have "?R - {cs} = ?R"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2277
                  proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2278
                    have "cs \<notin> ?R"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2279
                    proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2280
                      assume "cs \<in> {cs. (Cs cs, Th thread) \<in> RAG s}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2281
                      with no_dep show False by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2282
                    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2283
                    thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2284
                  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2285
                  ultimately show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2286
                qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2287
                thus ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2288
                  apply (unfold eq_e eq_th cntCS_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2289
                  apply (simp add: holdents_test)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2290
                  by (unfold step_RAG_p [OF vtp], auto simp:True)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2291
              qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2292
              moreover from is_runing have "th \<in> readys s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2293
                by (simp add:runing_def eq_th)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2294
              moreover note eq_cnp eq_cnv ih [of th]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2295
              ultimately show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2296
            next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2297
              case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2298
              have eq_wq: "wq (e#s) cs = wq s cs @ [th]"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2299
                    by (unfold eq_th eq_e wq_def, auto simp:Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2300
              have "th \<notin> readys (e#s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2301
              proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2302
                assume "th \<in> readys (e#s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2303
                hence "\<forall>cs. \<not> waiting (e # s) th cs" by (simp add:readys_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2304
                from this[rule_format, of cs] have " \<not> waiting (e # s) th cs" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2305
                hence "th \<in> set (wq (e#s) cs) \<Longrightarrow> th = hd (wq (e#s) cs)" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2306
                  by (simp add:s_waiting_def wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2307
                moreover from eq_wq have "th \<in> set (wq (e#s) cs)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2308
                ultimately have "th = hd (wq (e#s) cs)" by blast
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2309
                with eq_wq have "th = hd (wq s cs @ [th])" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2310
                hence "th = hd (wq s cs)" using False by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2311
                with False eq_wq vt_p.wq_distinct [of cs]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2312
                show False by (fold eq_e, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2313
              qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2314
              moreover from is_runing have "th \<in> threads (e#s)" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2315
                by (unfold eq_e, auto simp:runing_def readys_def eq_th)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2316
              moreover have "cntCS (e # s) th = cntCS s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2317
                apply (unfold cntCS_def holdents_test eq_e step_RAG_p[OF vtp])
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2318
                by (auto simp:False)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2319
              moreover note eq_cnp eq_cnv ih[of th]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2320
              moreover from is_runing have "th \<in> readys s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2321
                by (simp add:runing_def eq_th)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2322
              ultimately show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2323
            qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2324
          qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2325
        } ultimately show ?thesis by blast
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2326
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2327
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2328
      case (thread_V thread cs)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2329
      from assms vt stp ih thread_V have vtv: "vt (V thread cs # s)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2330
      then interpret vt_v: valid_trace "(V thread cs # s)" by (unfold_locales, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2331
      assume eq_e: "e = V thread cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2332
        and is_runing: "thread \<in> runing s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2333
        and hold: "holding s thread cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2334
      from hold obtain rest 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2335
        where eq_wq: "wq s cs = thread # rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2336
        by (case_tac "wq s cs", auto simp: wq_def s_holding_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2337
      have eq_threads: "threads (e#s) = threads s" by (simp add: eq_e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2338
      have eq_set: "set (SOME q. distinct q \<and> set q = set rest) = set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2339
      proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2340
        from vt_v.wq_distinct[of cs] and eq_wq
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2341
        show "distinct rest \<and> set rest = set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2342
          by (metis distinct.simps(2) vt_s.wq_distinct)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2343
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2344
        show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2345
          by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2346
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2347
      show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2348
      proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2349
        { assume eq_th: "th = thread"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2350
          from eq_th have eq_cnp: "cntP (e # s) th = cntP s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2351
            by (unfold eq_e, simp add:cntP_def count_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2352
          moreover from eq_th have eq_cnv: "cntV (e#s) th = 1 + cntV s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2353
            by (unfold eq_e, simp add:cntV_def count_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2354
          moreover from cntCS_v_dec [OF vtv] 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2355
          have "cntCS (e # s) thread + 1 = cntCS s thread"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2356
            by (simp add:eq_e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2357
          moreover from is_runing have rd_before: "thread \<in> readys s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2358
            by (unfold runing_def, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2359
          moreover have "thread \<in> readys (e # s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2360
          proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2361
            from is_runing
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2362
            have "thread \<in> threads (e#s)" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2363
              by (unfold eq_e, auto simp:runing_def readys_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2364
            moreover have "\<forall> cs1. \<not> waiting (e#s) thread cs1"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2365
            proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2366
              fix cs1
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2367
              { assume eq_cs: "cs1 = cs" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2368
                have "\<not> waiting (e # s) thread cs1"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2369
                proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2370
                  from eq_wq
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2371
                  have "thread \<notin> set (wq (e#s) cs1)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2372
                    apply(unfold eq_e wq_def eq_cs s_holding_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2373
                    apply (auto simp:Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2374
                  proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2375
                    assume "thread \<in> set (SOME q. distinct q \<and> set q = set rest)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2376
                    with eq_set have "thread \<in> set rest" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2377
                    with vt_v.wq_distinct[of cs]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2378
                    and eq_wq show False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2379
                        by (metis distinct.simps(2) vt_s.wq_distinct)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2380
                  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2381
                  thus ?thesis by (simp add:wq_def s_waiting_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2382
                qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2383
              } moreover {
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2384
                assume neq_cs: "cs1 \<noteq> cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2385
                  have "\<not> waiting (e # s) thread cs1" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2386
                  proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2387
                    from wq_v_neq [OF neq_cs[symmetric]]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2388
                    have "wq (V thread cs # s) cs1 = wq s cs1" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2389
                    moreover have "\<not> waiting s thread cs1" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2390
                    proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2391
                      from runing_ready and is_runing
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2392
                      have "thread \<in> readys s" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2393
                      thus ?thesis by (simp add:readys_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2394
                    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2395
                    ultimately show ?thesis 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2396
                      by (auto simp:wq_def s_waiting_def eq_e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2397
                  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2398
              } ultimately show "\<not> waiting (e # s) thread cs1" by blast
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2399
            qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2400
            ultimately show ?thesis by (simp add:readys_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2401
          qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2402
          moreover note eq_th ih
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2403
          ultimately have ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2404
        } moreover {
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2405
          assume neq_th: "th \<noteq> thread"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2406
          from neq_th eq_e have eq_cnp: "cntP (e # s) th = cntP s th" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2407
            by (simp add:cntP_def count_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2408
          from neq_th eq_e have eq_cnv: "cntV (e # s) th = cntV s th" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2409
            by (simp add:cntV_def count_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2410
          have ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2411
          proof(cases "th \<in> set rest")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2412
            case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2413
            have "(th \<in> readys (e # s)) = (th \<in> readys s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2414
              apply (insert step_back_vt[OF vtv])
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2415
              by (simp add: False eq_e eq_wq neq_th vt_s.readys_v_eq)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2416
            moreover have "cntCS (e#s) th = cntCS s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2417
              apply (insert neq_th, unfold eq_e cntCS_def holdents_test step_RAG_v[OF vtv], auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2418
              proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2419
                have "{csa. (Cs csa, Th th) \<in> RAG s \<or> csa = cs \<and> next_th s thread cs th} =
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2420
                      {cs. (Cs cs, Th th) \<in> RAG s}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2421
                proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2422
                  from False eq_wq
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2423
                  have " next_th s thread cs th \<Longrightarrow> (Cs cs, Th th) \<in> RAG s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2424
                    apply (unfold next_th_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2425
                  proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2426
                    assume ne: "rest \<noteq> []"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2427
                      and ni: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2428
                      and eq_wq: "wq s cs = thread # rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2429
                    from eq_set ni have "hd (SOME q. distinct q \<and> set q = set rest) \<notin> 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2430
                                  set (SOME q. distinct q \<and> set q = set rest)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2431
                                  " by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2432
                    moreover have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2433
                    proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2434
                      from vt_s.wq_distinct[ of cs] and eq_wq
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2435
                      show "distinct rest \<and> set rest = set rest" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2436
                    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2437
                      fix x assume "distinct x \<and> set x = set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2438
                      with ne show "x \<noteq> []" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2439
                    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2440
                    ultimately show 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2441
                      "(Cs cs, Th (hd (SOME q. distinct q \<and> set q = set rest))) \<in> RAG s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2442
                      by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2443
                  qed    
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2444
                  thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2445
                qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2446
                thus "card {csa. (Cs csa, Th th) \<in> RAG s \<or> csa = cs \<and> next_th s thread cs th} =
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2447
                             card {cs. (Cs cs, Th th) \<in> RAG s}" by simp 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2448
              qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2449
            moreover note ih eq_cnp eq_cnv eq_threads
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2450
            ultimately show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2451
          next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2452
            case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2453
            assume th_in: "th \<in> set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2454
            show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2455
            proof(cases "next_th s thread cs th")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2456
              case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2457
              with eq_wq and th_in have 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2458
                neq_hd: "th \<noteq> hd (SOME q. distinct q \<and> set q = set rest)" (is "th \<noteq> hd ?rest")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2459
                by (auto simp:next_th_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2460
              have "(th \<in> readys (e # s)) = (th \<in> readys s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2461
              proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2462
                from eq_wq and th_in
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2463
                have "\<not> th \<in> readys s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2464
                  apply (auto simp:readys_def s_waiting_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2465
                  apply (rule_tac x = cs in exI, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2466
                  by (insert vt_s.wq_distinct[of cs], auto simp add: wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2467
                moreover 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2468
                from eq_wq and th_in and neq_hd
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2469
                have "\<not> (th \<in> readys (e # s))"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2470
                  apply (auto simp:readys_def s_waiting_def eq_e wq_def Let_def split:list.splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2471
                  by (rule_tac x = cs in exI, auto simp:eq_set)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2472
                ultimately show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2473
              qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2474
              moreover have "cntCS (e#s) th = cntCS s th" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2475
              proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2476
                from eq_wq and  th_in and neq_hd
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2477
                have "(holdents (e # s) th) = (holdents s th)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2478
                  apply (unfold eq_e step_RAG_v[OF vtv], 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2479
                         auto simp:next_th_def eq_set s_RAG_def holdents_test wq_def
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2480
                                   Let_def cs_holding_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2481
                  by (insert vt_s.wq_distinct[of cs], auto simp:wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2482
                thus ?thesis by (simp add:cntCS_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2483
              qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2484
              moreover note ih eq_cnp eq_cnv eq_threads
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2485
              ultimately show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2486
            next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2487
              case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2488
              let ?rest = " (SOME q. distinct q \<and> set q = set rest)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2489
              let ?t = "hd ?rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2490
              from True eq_wq th_in neq_th
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2491
              have "th \<in> readys (e # s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2492
                apply (auto simp:eq_e readys_def s_waiting_def wq_def
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2493
                        Let_def next_th_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2494
              proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2495
                assume eq_wq: "wq_fun (schs s) cs = thread # rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2496
                  and t_in: "?t \<in> set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2497
                show "?t \<in> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2498
                proof(rule vt_s.wq_threads)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2499
                  from eq_wq and t_in
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2500
                  show "?t \<in> set (wq s cs)" by (auto simp:wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2501
                qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2502
              next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2503
                fix csa
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2504
                assume eq_wq: "wq_fun (schs s) cs = thread # rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2505
                  and t_in: "?t \<in> set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2506
                  and neq_cs: "csa \<noteq> cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2507
                  and t_in': "?t \<in>  set (wq_fun (schs s) csa)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2508
                show "?t = hd (wq_fun (schs s) csa)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2509
                proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2510
                  { assume neq_hd': "?t \<noteq> hd (wq_fun (schs s) csa)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2511
                    from vt_s.wq_distinct[of cs] and 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2512
                    eq_wq[folded wq_def] and t_in eq_wq
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2513
                    have "?t \<noteq> thread" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2514
                    with eq_wq and t_in
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2515
                    have w1: "waiting s ?t cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2516
                      by (auto simp:s_waiting_def wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2517
                    from t_in' neq_hd'
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2518
                    have w2: "waiting s ?t csa"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2519
                      by (auto simp:s_waiting_def wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2520
                    from vt_s.waiting_unique[OF w1 w2]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2521
                    and neq_cs have "False" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2522
                  } thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2523
                qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2524
              qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2525
              moreover have "cntP s th = cntV s th + cntCS s th + 1"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2526
              proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2527
                have "th \<notin> readys s" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2528
                proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2529
                  from True eq_wq neq_th th_in
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2530
                  show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2531
                    apply (unfold readys_def s_waiting_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2532
                    by (rule_tac x = cs in exI, auto simp add: wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2533
                qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2534
                moreover have "th \<in> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2535
                proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2536
                  from th_in eq_wq
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2537
                  have "th \<in> set (wq s cs)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2538
                  from vt_s.wq_threads [OF this] 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2539
                  show ?thesis .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2540
                qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2541
                ultimately show ?thesis using ih by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2542
              qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2543
              moreover from True neq_th have "cntCS (e # s) th = 1 + cntCS s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2544
                apply (unfold cntCS_def holdents_test eq_e step_RAG_v[OF vtv], auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2545
              proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2546
                show "card {csa. (Cs csa, Th th) \<in> RAG s \<or> csa = cs} =
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2547
                               Suc (card {cs. (Cs cs, Th th) \<in> RAG s})"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2548
                  (is "card ?A = Suc (card ?B)")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2549
                proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2550
                  have "?A = insert cs ?B" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2551
                  hence "card ?A = card (insert cs ?B)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2552
                  also have "\<dots> = Suc (card ?B)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2553
                  proof(rule card_insert_disjoint)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2554
                    have "?B \<subseteq> ((\<lambda> (x, y). the_cs x) ` RAG s)" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2555
                      apply (auto simp:image_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2556
                      by (rule_tac x = "(Cs x, Th th)" in bexI, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2557
                    with vt_s.finite_RAG
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2558
                    show "finite {cs. (Cs cs, Th th) \<in> RAG s}" by (auto intro:finite_subset)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2559
                  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2560
                    show "cs \<notin> {cs. (Cs cs, Th th) \<in> RAG s}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2561
                    proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2562
                      assume "cs \<in> {cs. (Cs cs, Th th) \<in> RAG s}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2563
                      hence "(Cs cs, Th th) \<in> RAG s" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2564
                      with True neq_th eq_wq show False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2565
                        by (auto simp:next_th_def s_RAG_def cs_holding_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2566
                    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2567
                  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2568
                  finally show ?thesis .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2569
                qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2570
              qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2571
              moreover note eq_cnp eq_cnv
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2572
              ultimately show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2573
            qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2574
          qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2575
        } ultimately show ?thesis by blast
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2576
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2577
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2578
      case (thread_set thread prio)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2579
      assume eq_e: "e = Set thread prio"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2580
        and is_runing: "thread \<in> runing s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2581
      show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2582
      proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2583
        from eq_e have eq_cnp: "cntP (e#s) th = cntP s th" by (simp add:cntP_def count_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2584
        from eq_e have eq_cnv: "cntV (e#s) th = cntV s th" by (simp add:cntV_def count_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2585
        have eq_cncs: "cntCS (e#s) th = cntCS s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2586
          unfolding cntCS_def holdents_test
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2587
          by (simp add:RAG_set_unchanged eq_e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2588
        from eq_e have eq_readys: "readys (e#s) = readys s" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2589
          by (simp add:readys_def cs_waiting_def s_waiting_def wq_def,
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2590
                  auto simp:Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2591
        { assume "th \<noteq> thread"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2592
          with eq_readys eq_e
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2593
          have "(th \<in> readys (e # s) \<or> th \<notin> threads (e # s)) = 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2594
                      (th \<in> readys (s) \<or> th \<notin> threads (s))" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2595
            by (simp add:threads.simps)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2596
          with eq_cnp eq_cnv eq_cncs ih is_runing
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2597
          have ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2598
        } moreover {
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2599
          assume eq_th: "th = thread"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2600
          with is_runing ih have " cntP s th  = cntV s th + cntCS s th" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2601
            by (unfold runing_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2602
          moreover from eq_th and eq_readys is_runing have "th \<in> readys (e#s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2603
            by (simp add:runing_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2604
          moreover note eq_cnp eq_cnv eq_cncs
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2605
          ultimately have ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2606
        } ultimately show ?thesis by blast
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2607
      qed   
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2608
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2609
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2610
    case vt_nil
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2611
    show ?case 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2612
      by (unfold cntP_def cntV_def cntCS_def, 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2613
        auto simp:count_def holdents_test s_RAG_def wq_def cs_holding_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2614
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2615
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2616
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2617
lemma not_thread_cncs:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2618
  assumes not_in: "th \<notin> threads s" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2619
  shows "cntCS s th = 0"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2620
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2621
  from vt not_in show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2622
  proof(induct arbitrary:th)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2623
    case (vt_cons s e th)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2624
    interpret vt_s: valid_trace s using vt_cons(1)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2625
       by (unfold_locales, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2626
    assume vt: "vt s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2627
      and ih: "\<And>th. th \<notin> threads s \<Longrightarrow> cntCS s th = 0"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2628
      and stp: "step s e"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2629
      and not_in: "th \<notin> threads (e # s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2630
    from stp show ?case
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2631
    proof(cases)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2632
      case (thread_create thread prio)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2633
      assume eq_e: "e = Create thread prio"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2634
        and not_in': "thread \<notin> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2635
      have "cntCS (e # s) th = cntCS s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2636
        apply (unfold eq_e cntCS_def holdents_test)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2637
        by (simp add:RAG_create_unchanged)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2638
      moreover have "th \<notin> threads s" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2639
      proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2640
        from not_in eq_e show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2641
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2642
      moreover note ih ultimately show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2643
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2644
      case (thread_exit thread)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2645
      assume eq_e: "e = Exit thread"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2646
      and nh: "holdents s thread = {}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2647
      have eq_cns: "cntCS (e # s) th = cntCS s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2648
        apply (unfold eq_e cntCS_def holdents_test)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2649
        by (simp add:RAG_exit_unchanged)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2650
      show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2651
      proof(cases "th = thread")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2652
        case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2653
        have "cntCS s th = 0" by (unfold cntCS_def, auto simp:nh True)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2654
        with eq_cns show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2655
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2656
        case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2657
        with not_in and eq_e
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2658
        have "th \<notin> threads s" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2659
        from ih[OF this] and eq_cns show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2660
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2661
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2662
      case (thread_P thread cs)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2663
      assume eq_e: "e = P thread cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2664
      and is_runing: "thread \<in> runing s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2665
      from assms thread_P ih vt stp thread_P have vtp: "vt (P thread cs#s)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2666
      have neq_th: "th \<noteq> thread" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2667
      proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2668
        from not_in eq_e have "th \<notin> threads s" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2669
        moreover from is_runing have "thread \<in> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2670
          by (simp add:runing_def readys_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2671
        ultimately show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2672
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2673
      hence "cntCS (e # s) th  = cntCS s th "
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2674
        apply (unfold cntCS_def holdents_test eq_e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2675
        by (unfold step_RAG_p[OF vtp], auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2676
      moreover have "cntCS s th = 0"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2677
      proof(rule ih)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2678
        from not_in eq_e show "th \<notin> threads s" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2679
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2680
      ultimately show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2681
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2682
      case (thread_V thread cs)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2683
      assume eq_e: "e = V thread cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2684
        and is_runing: "thread \<in> runing s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2685
        and hold: "holding s thread cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2686
      have neq_th: "th \<noteq> thread" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2687
      proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2688
        from not_in eq_e have "th \<notin> threads s" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2689
        moreover from is_runing have "thread \<in> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2690
          by (simp add:runing_def readys_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2691
        ultimately show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2692
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2693
      from assms thread_V vt stp ih 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2694
      have vtv: "vt (V thread cs#s)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2695
      then interpret vt_v: valid_trace "(V thread cs#s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2696
        by (unfold_locales, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2697
      from hold obtain rest 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2698
        where eq_wq: "wq s cs = thread # rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2699
        by (case_tac "wq s cs", auto simp: wq_def s_holding_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2700
      from not_in eq_e eq_wq
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2701
      have "\<not> next_th s thread cs th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2702
        apply (auto simp:next_th_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2703
      proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2704
        assume ne: "rest \<noteq> []"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2705
          and ni: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> threads s" (is "?t \<notin> threads s")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2706
        have "?t \<in> set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2707
        proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2708
          from vt_v.wq_distinct[of cs] and eq_wq
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2709
          show "distinct rest \<and> set rest = set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2710
            by (metis distinct.simps(2) vt_s.wq_distinct) 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2711
        next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2712
          fix x assume "distinct x \<and> set x = set rest" with ne
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2713
          show "hd x \<in> set rest" by (cases x, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2714
        qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2715
        with eq_wq have "?t \<in> set (wq s cs)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2716
        from vt_s.wq_threads[OF this] and ni
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2717
        show False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2718
          using `hd (SOME q. distinct q \<and> set q = set rest) \<in> set (wq s cs)` 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2719
            ni vt_s.wq_threads by blast 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2720
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2721
      moreover note neq_th eq_wq
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2722
      ultimately have "cntCS (e # s) th  = cntCS s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2723
        by (unfold eq_e cntCS_def holdents_test step_RAG_v[OF vtv], auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2724
      moreover have "cntCS s th = 0"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2725
      proof(rule ih)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2726
        from not_in eq_e show "th \<notin> threads s" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2727
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2728
      ultimately show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2729
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2730
      case (thread_set thread prio)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2731
      print_facts
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2732
      assume eq_e: "e = Set thread prio"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2733
        and is_runing: "thread \<in> runing s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2734
      from not_in and eq_e have "th \<notin> threads s" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2735
      from ih [OF this] and eq_e
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2736
      show ?thesis 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2737
        apply (unfold eq_e cntCS_def holdents_test)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2738
        by (simp add:RAG_set_unchanged)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2739
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2740
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2741
      case vt_nil
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2742
      show ?case
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2743
      by (unfold cntCS_def, 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2744
        auto simp:count_def holdents_test s_RAG_def wq_def cs_holding_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2745
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2746
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2747
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2748
end
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2749
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2750
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2751
context valid_trace
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2752
begin
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2753
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2754
lemma dm_RAG_threads:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2755
  assumes in_dom: "(Th th) \<in> Domain (RAG s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2756
  shows "th \<in> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2757
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2758
  from in_dom obtain n where "(Th th, n) \<in> RAG s" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2759
  moreover from RAG_target_th[OF this] obtain cs where "n = Cs cs" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2760
  ultimately have "(Th th, Cs cs) \<in> RAG s" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2761
  hence "th \<in> set (wq s cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2762
    by (unfold s_RAG_def, auto simp:cs_waiting_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2763
  from wq_threads [OF this] show ?thesis .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2764
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2765
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2766
end
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2767
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2768
lemma cp_eq_cpreced: "cp s th = cpreced (wq s) s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2769
unfolding cp_def wq_def
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2770
apply(induct s rule: schs.induct)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2771
thm cpreced_initial
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2772
apply(simp add: Let_def cpreced_initial)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2773
apply(simp add: Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2774
apply(simp add: Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2775
apply(simp add: Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2776
apply(subst (2) schs.simps)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2777
apply(simp add: Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2778
apply(subst (2) schs.simps)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2779
apply(simp add: Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2780
done
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2781
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2782
context valid_trace
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2783
begin
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2784
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2785
lemma runing_unique:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2786
  assumes runing_1: "th1 \<in> runing s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2787
  and runing_2: "th2 \<in> runing s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2788
  shows "th1 = th2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2789
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2790
  from runing_1 and runing_2 have "cp s th1 = cp s th2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2791
    unfolding runing_def
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2792
    apply(simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2793
    done
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2794
  hence eq_max: "Max ((\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1)) =
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2795
                 Max ((\<lambda>th. preced th s) ` ({th2} \<union> dependants (wq s) th2))"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2796
    (is "Max (?f ` ?A) = Max (?f ` ?B)")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2797
    unfolding cp_eq_cpreced 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2798
    unfolding cpreced_def .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2799
  obtain th1' where th1_in: "th1' \<in> ?A" and eq_f_th1: "?f th1' = Max (?f ` ?A)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2800
  proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2801
    have h1: "finite (?f ` ?A)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2802
    proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2803
      have "finite ?A" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2804
      proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2805
        have "finite (dependants (wq s) th1)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2806
        proof-
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2807
          have "finite {th'. (Th th', Th th1) \<in> (RAG (wq s))\<^sup>+}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2808
          proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2809
            let ?F = "\<lambda> (x, y). the_th x"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2810
            have "{th'. (Th th', Th th1) \<in> (RAG (wq s))\<^sup>+} \<subseteq> ?F ` ((RAG (wq s))\<^sup>+)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2811
              apply (auto simp:image_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2812
              by (rule_tac x = "(Th x, Th th1)" in bexI, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2813
            moreover have "finite \<dots>"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2814
            proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2815
              from finite_RAG have "finite (RAG s)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2816
              hence "finite ((RAG (wq s))\<^sup>+)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2817
                apply (unfold finite_trancl)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2818
                by (auto simp: s_RAG_def cs_RAG_def wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2819
              thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2820
            qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2821
            ultimately show ?thesis by (auto intro:finite_subset)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2822
          qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2823
          thus ?thesis by (simp add:cs_dependants_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2824
        qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2825
        thus ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2826
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2827
      thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2828
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2829
    moreover have h2: "(?f ` ?A) \<noteq> {}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2830
    proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2831
      have "?A \<noteq> {}" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2832
      thus ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2833
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2834
    from Max_in [OF h1 h2]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2835
    have "Max (?f ` ?A) \<in> (?f ` ?A)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2836
    thus ?thesis 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2837
      thm cpreced_def
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2838
      unfolding cpreced_def[symmetric] 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2839
      unfolding cp_eq_cpreced[symmetric] 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2840
      unfolding cpreced_def 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2841
      using that[intro] by (auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2842
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2843
  obtain th2' where th2_in: "th2' \<in> ?B" and eq_f_th2: "?f th2' = Max (?f ` ?B)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2844
  proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2845
    have h1: "finite (?f ` ?B)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2846
    proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2847
      have "finite ?B" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2848
      proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2849
        have "finite (dependants (wq s) th2)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2850
        proof-
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2851
          have "finite {th'. (Th th', Th th2) \<in> (RAG (wq s))\<^sup>+}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2852
          proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2853
            let ?F = "\<lambda> (x, y). the_th x"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2854
            have "{th'. (Th th', Th th2) \<in> (RAG (wq s))\<^sup>+} \<subseteq> ?F ` ((RAG (wq s))\<^sup>+)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2855
              apply (auto simp:image_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2856
              by (rule_tac x = "(Th x, Th th2)" in bexI, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2857
            moreover have "finite \<dots>"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2858
            proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2859
              from finite_RAG have "finite (RAG s)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2860
              hence "finite ((RAG (wq s))\<^sup>+)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2861
                apply (unfold finite_trancl)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2862
                by (auto simp: s_RAG_def cs_RAG_def wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2863
              thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2864
            qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2865
            ultimately show ?thesis by (auto intro:finite_subset)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2866
          qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2867
          thus ?thesis by (simp add:cs_dependants_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2868
        qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2869
        thus ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2870
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2871
      thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2872
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2873
    moreover have h2: "(?f ` ?B) \<noteq> {}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2874
    proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2875
      have "?B \<noteq> {}" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2876
      thus ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2877
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2878
    from Max_in [OF h1 h2]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2879
    have "Max (?f ` ?B) \<in> (?f ` ?B)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2880
    thus ?thesis by (auto intro:that)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2881
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2882
  from eq_f_th1 eq_f_th2 eq_max 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2883
  have eq_preced: "preced th1' s = preced th2' s" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2884
  hence eq_th12: "th1' = th2'"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2885
  proof (rule preced_unique)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2886
    from th1_in have "th1' = th1 \<or> (th1' \<in> dependants (wq s) th1)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2887
    thus "th1' \<in> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2888
    proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2889
      assume "th1' \<in> dependants (wq s) th1"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2890
      hence "(Th th1') \<in> Domain ((RAG s)^+)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2891
        apply (unfold cs_dependants_def cs_RAG_def s_RAG_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2892
        by (auto simp:Domain_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2893
      hence "(Th th1') \<in> Domain (RAG s)" by (simp add:trancl_domain)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2894
      from dm_RAG_threads[OF this] show ?thesis .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2895
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2896
      assume "th1' = th1"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2897
      with runing_1 show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2898
        by (unfold runing_def readys_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2899
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2900
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2901
    from th2_in have "th2' = th2 \<or> (th2' \<in> dependants (wq s) th2)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2902
    thus "th2' \<in> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2903
    proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2904
      assume "th2' \<in> dependants (wq s) th2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2905
      hence "(Th th2') \<in> Domain ((RAG s)^+)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2906
        apply (unfold cs_dependants_def cs_RAG_def s_RAG_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2907
        by (auto simp:Domain_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2908
      hence "(Th th2') \<in> Domain (RAG s)" by (simp add:trancl_domain)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2909
      from dm_RAG_threads[OF this] show ?thesis .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2910
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2911
      assume "th2' = th2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2912
      with runing_2 show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2913
        by (unfold runing_def readys_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2914
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2915
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2916
  from th1_in have "th1' = th1 \<or> th1' \<in> dependants (wq s) th1" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2917
  thus ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2918
  proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2919
    assume eq_th': "th1' = th1"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2920
    from th2_in have "th2' = th2 \<or> th2' \<in> dependants (wq s) th2" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2921
    thus ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2922
    proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2923
      assume "th2' = th2" thus ?thesis using eq_th' eq_th12 by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2924
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2925
      assume "th2' \<in> dependants (wq s) th2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2926
      with eq_th12 eq_th' have "th1 \<in> dependants (wq s) th2" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2927
      hence "(Th th1, Th th2) \<in> (RAG s)^+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2928
        by (unfold cs_dependants_def s_RAG_def cs_RAG_def, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2929
      hence "Th th1 \<in> Domain ((RAG s)^+)" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2930
        apply (unfold cs_dependants_def cs_RAG_def s_RAG_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2931
        by (auto simp:Domain_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2932
      hence "Th th1 \<in> Domain (RAG s)" by (simp add:trancl_domain)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2933
      then obtain n where d: "(Th th1, n) \<in> RAG s" by (auto simp:Domain_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2934
      from RAG_target_th [OF this]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2935
      obtain cs' where "n = Cs cs'" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2936
      with d have "(Th th1, Cs cs') \<in> RAG s" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2937
      with runing_1 have "False"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2938
        apply (unfold runing_def readys_def s_RAG_def)
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  2939
        by (auto simp:waiting_eq)
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2940
      thus ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2941
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2942
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2943
    assume th1'_in: "th1' \<in> dependants (wq s) th1"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2944
    from th2_in have "th2' = th2 \<or> th2' \<in> dependants (wq s) th2" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2945
    thus ?thesis 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2946
    proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2947
      assume "th2' = th2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2948
      with th1'_in eq_th12 have "th2 \<in> dependants (wq s) th1" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2949
      hence "(Th th2, Th th1) \<in> (RAG s)^+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2950
        by (unfold cs_dependants_def s_RAG_def cs_RAG_def, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2951
      hence "Th th2 \<in> Domain ((RAG s)^+)" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2952
        apply (unfold cs_dependants_def cs_RAG_def s_RAG_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2953
        by (auto simp:Domain_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2954
      hence "Th th2 \<in> Domain (RAG s)" by (simp add:trancl_domain)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2955
      then obtain n where d: "(Th th2, n) \<in> RAG s" by (auto simp:Domain_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2956
      from RAG_target_th [OF this]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2957
      obtain cs' where "n = Cs cs'" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2958
      with d have "(Th th2, Cs cs') \<in> RAG s" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2959
      with runing_2 have "False"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2960
        apply (unfold runing_def readys_def s_RAG_def)
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  2961
        by (auto simp:waiting_eq)
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2962
      thus ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2963
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2964
      assume "th2' \<in> dependants (wq s) th2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2965
      with eq_th12 have "th1' \<in> dependants (wq s) th2" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2966
      hence h1: "(Th th1', Th th2) \<in> (RAG s)^+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2967
        by (unfold cs_dependants_def s_RAG_def cs_RAG_def, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2968
      from th1'_in have h2: "(Th th1', Th th1) \<in> (RAG s)^+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2969
        by (unfold cs_dependants_def s_RAG_def cs_RAG_def, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2970
      show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2971
      proof(rule dchain_unique[OF h1 _ h2, symmetric])
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2972
        from runing_1 show "th1 \<in> readys s" by (simp add:runing_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2973
        from runing_2 show "th2 \<in> readys s" by (simp add:runing_def) 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2974
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2975
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2976
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2977
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2978
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2979
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2980
lemma "card (runing s) \<le> 1"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2981
apply(subgoal_tac "finite (runing s)")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2982
prefer 2
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2983
apply (metis finite_nat_set_iff_bounded lessI runing_unique)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2984
apply(rule ccontr)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2985
apply(simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2986
apply(case_tac "Suc (Suc 0) \<le> card (runing s)")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2987
apply(subst (asm) card_le_Suc_iff)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2988
apply(simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2989
apply(auto)[1]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2990
apply (metis insertCI runing_unique)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2991
apply(auto) 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2992
done
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2993
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2994
end
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2995
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2996
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2997
lemma create_pre:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2998
  assumes stp: "step s e"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2999
  and not_in: "th \<notin> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3000
  and is_in: "th \<in> threads (e#s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3001
  obtains prio where "e = Create th prio"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3002
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3003
  from assms  
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3004
  show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3005
  proof(cases)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3006
    case (thread_create thread prio)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3007
    with is_in not_in have "e = Create th prio" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3008
    from that[OF this] show ?thesis .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3009
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3010
    case (thread_exit thread)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3011
    with assms show ?thesis by (auto intro!:that)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3012
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3013
    case (thread_P thread)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3014
    with assms show ?thesis by (auto intro!:that)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3015
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3016
    case (thread_V thread)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3017
    with assms show ?thesis by (auto intro!:that)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3018
  next 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3019
    case (thread_set thread)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3020
    with assms show ?thesis by (auto intro!:that)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3021
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3022
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3023
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3024
context valid_trace
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3025
begin
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3026
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3027
lemma cnp_cnv_eq:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3028
  assumes "th \<notin> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3029
  shows "cntP s th = cntV s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3030
  using assms
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3031
  using cnp_cnv_cncs not_thread_cncs by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3032
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3033
end
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3034
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3035
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3036
lemma eq_RAG: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3037
  "RAG (wq s) = RAG s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3038
by (unfold cs_RAG_def s_RAG_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3039
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3040
context valid_trace
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3041
begin
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3042
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3043
lemma count_eq_dependants:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3044
  assumes eq_pv: "cntP s th = cntV s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3045
  shows "dependants (wq s) th = {}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3046
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3047
  from cnp_cnv_cncs and eq_pv
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3048
  have "cntCS s th = 0" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3049
    by (auto split:if_splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3050
  moreover have "finite {cs. (Cs cs, Th th) \<in> RAG s}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3051
  proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3052
    from finite_holding[of th] show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3053
      by (simp add:holdents_test)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3054
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3055
  ultimately have h: "{cs. (Cs cs, Th th) \<in> RAG s} = {}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3056
    by (unfold cntCS_def holdents_test cs_dependants_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3057
  show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3058
  proof(unfold cs_dependants_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3059
    { assume "{th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+} \<noteq> {}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3060
      then obtain th' where "(Th th', Th th) \<in> (RAG (wq s))\<^sup>+" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3061
      hence "False"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3062
      proof(cases)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3063
        assume "(Th th', Th th) \<in> RAG (wq s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3064
        thus "False" by (auto simp:cs_RAG_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3065
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3066
        fix c
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3067
        assume "(c, Th th) \<in> RAG (wq s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3068
        with h and eq_RAG show "False"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3069
          by (cases c, auto simp:cs_RAG_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3070
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3071
    } thus "{th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+} = {}" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3072
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3073
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3074
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3075
lemma dependants_threads:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3076
  shows "dependants (wq s) th \<subseteq> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3077
proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3078
  { fix th th'
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3079
    assume h: "th \<in> {th'a. (Th th'a, Th th') \<in> (RAG (wq s))\<^sup>+}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3080
    have "Th th \<in> Domain (RAG s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3081
    proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3082
      from h obtain th' where "(Th th, Th th') \<in> (RAG (wq s))\<^sup>+" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3083
      hence "(Th th) \<in> Domain ( (RAG (wq s))\<^sup>+)" by (auto simp:Domain_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3084
      with trancl_domain have "(Th th) \<in> Domain (RAG (wq s))" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3085
      thus ?thesis using eq_RAG by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3086
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3087
    from dm_RAG_threads[OF this]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3088
    have "th \<in> threads s" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3089
  } note hh = this
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3090
  fix th1 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3091
  assume "th1 \<in> dependants (wq s) th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3092
  hence "th1 \<in> {th'a. (Th th'a, Th th) \<in> (RAG (wq s))\<^sup>+}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3093
    by (unfold cs_dependants_def, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3094
  from hh [OF this] show "th1 \<in> threads s" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3095
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3096
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3097
lemma finite_threads:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3098
  shows "finite (threads s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3099
using vt by (induct) (auto elim: step.cases)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3100
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3101
end
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3102
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3103
lemma Max_f_mono:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3104
  assumes seq: "A \<subseteq> B"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3105
  and np: "A \<noteq> {}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3106
  and fnt: "finite B"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3107
  shows "Max (f ` A) \<le> Max (f ` B)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3108
proof(rule Max_mono)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3109
  from seq show "f ` A \<subseteq> f ` B" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3110
next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3111
  from np show "f ` A \<noteq> {}" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3112
next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3113
  from fnt and seq show "finite (f ` B)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3114
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3115
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3116
context valid_trace
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3117
begin
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3118
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3119
lemma cp_le:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3120
  assumes th_in: "th \<in> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3121
  shows "cp s th \<le> Max ((\<lambda> th. (preced th s)) ` threads s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3122
proof(unfold cp_eq_cpreced cpreced_def cs_dependants_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3123
  show "Max ((\<lambda>th. preced th s) ` ({th} \<union> {th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+}))
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3124
         \<le> Max ((\<lambda>th. preced th s) ` threads s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3125
    (is "Max (?f ` ?A) \<le> Max (?f ` ?B)")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3126
  proof(rule Max_f_mono)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3127
    show "{th} \<union> {th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+} \<noteq> {}" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3128
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3129
    from finite_threads
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3130
    show "finite (threads s)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3131
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3132
    from th_in
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3133
    show "{th} \<union> {th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+} \<subseteq> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3134
      apply (auto simp:Domain_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3135
      apply (rule_tac dm_RAG_threads)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3136
      apply (unfold trancl_domain [of "RAG s", symmetric])
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3137
      by (unfold cs_RAG_def s_RAG_def, auto simp:Domain_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3138
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3139
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3140
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3141
lemma le_cp:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3142
  shows "preced th s \<le> cp s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3143
proof(unfold cp_eq_cpreced preced_def cpreced_def, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3144
  show "Prc (priority th s) (last_set th s)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3145
    \<le> Max (insert (Prc (priority th s) (last_set th s))
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3146
            ((\<lambda>th. Prc (priority th s) (last_set th s)) ` dependants (wq s) th))"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3147
    (is "?l \<le> Max (insert ?l ?A)")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3148
  proof(cases "?A = {}")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3149
    case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3150
    have "finite ?A" (is "finite (?f ` ?B)")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3151
    proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3152
      have "finite ?B" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3153
      proof-
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3154
        have "finite {th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3155
        proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3156
          let ?F = "\<lambda> (x, y). the_th x"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3157
          have "{th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+} \<subseteq> ?F ` ((RAG (wq s))\<^sup>+)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3158
            apply (auto simp:image_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3159
            by (rule_tac x = "(Th x, Th th)" in bexI, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3160
          moreover have "finite \<dots>"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3161
          proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3162
            from finite_RAG have "finite (RAG s)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3163
            hence "finite ((RAG (wq s))\<^sup>+)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3164
              apply (unfold finite_trancl)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3165
              by (auto simp: s_RAG_def cs_RAG_def wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3166
            thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3167
          qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3168
          ultimately show ?thesis by (auto intro:finite_subset)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3169
        qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3170
        thus ?thesis by (simp add:cs_dependants_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3171
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3172
      thus ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3173
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3174
    from Max_insert [OF this False, of ?l] show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3175
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3176
    case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3177
    thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3178
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3179
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3180
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3181
lemma max_cp_eq: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3182
  shows "Max ((cp s) ` threads s) = Max ((\<lambda> th. (preced th s)) ` threads s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3183
  (is "?l = ?r")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3184
proof(cases "threads s = {}")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3185
  case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3186
  thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3187
next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3188
  case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3189
  have "?l \<in> ((cp s) ` threads s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3190
  proof(rule Max_in)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3191
    from finite_threads
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3192
    show "finite (cp s ` threads s)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3193
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3194
    from False show "cp s ` threads s \<noteq> {}" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3195
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3196
  then obtain th 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3197
    where th_in: "th \<in> threads s" and eq_l: "?l = cp s th" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3198
  have "\<dots> \<le> ?r" by (rule cp_le[OF th_in])
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3199
  moreover have "?r \<le> cp s th" (is "Max (?f ` ?A) \<le> cp s th")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3200
  proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3201
    have "?r \<in> (?f ` ?A)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3202
    proof(rule Max_in)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3203
      from finite_threads
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3204
      show " finite ((\<lambda>th. preced th s) ` threads s)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3205
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3206
      from False show " (\<lambda>th. preced th s) ` threads s \<noteq> {}" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3207
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3208
    then obtain th' where 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3209
      th_in': "th' \<in> ?A " and eq_r: "?r = ?f th'" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3210
    from le_cp [of th']  eq_r
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3211
    have "?r \<le> cp s th'" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3212
    moreover have "\<dots> \<le> cp s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3213
    proof(fold eq_l)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3214
      show " cp s th' \<le> Max (cp s ` threads s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3215
      proof(rule Max_ge)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3216
        from th_in' show "cp s th' \<in> cp s ` threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3217
          by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3218
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3219
        from finite_threads
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3220
        show "finite (cp s ` threads s)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3221
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3222
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3223
    ultimately show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3224
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3225
  ultimately show ?thesis using eq_l by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3226
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3227
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3228
lemma max_cp_readys_threads_pre:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3229
  assumes np: "threads s \<noteq> {}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3230
  shows "Max (cp s ` readys s) = Max (cp s ` threads s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3231
proof(unfold max_cp_eq)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3232
  show "Max (cp s ` readys s) = Max ((\<lambda>th. preced th s) ` threads s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3233
  proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3234
    let ?p = "Max ((\<lambda>th. preced th s) ` threads s)" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3235
    let ?f = "(\<lambda>th. preced th s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3236
    have "?p \<in> ((\<lambda>th. preced th s) ` threads s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3237
    proof(rule Max_in)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3238
      from finite_threads show "finite (?f ` threads s)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3239
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3240
      from np show "?f ` threads s \<noteq> {}" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3241
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3242
    then obtain tm where tm_max: "?f tm = ?p" and tm_in: "tm \<in> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3243
      by (auto simp:Image_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3244
    from th_chain_to_ready [OF tm_in]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3245
    have "tm \<in> readys s \<or> (\<exists>th'. th' \<in> readys s \<and> (Th tm, Th th') \<in> (RAG s)\<^sup>+)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3246
    thus ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3247
    proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3248
      assume "\<exists>th'. th' \<in> readys s \<and> (Th tm, Th th') \<in> (RAG s)\<^sup>+ "
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3249
      then obtain th' where th'_in: "th' \<in> readys s" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3250
        and tm_chain:"(Th tm, Th th') \<in> (RAG s)\<^sup>+" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3251
      have "cp s th' = ?f tm"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3252
      proof(subst cp_eq_cpreced, subst cpreced_def, rule Max_eqI)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3253
        from dependants_threads finite_threads
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3254
        show "finite ((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th'))" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3255
          by (auto intro:finite_subset)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3256
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3257
        fix p assume p_in: "p \<in> (\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3258
        from tm_max have " preced tm s = Max ((\<lambda>th. preced th s) ` threads s)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3259
        moreover have "p \<le> \<dots>"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3260
        proof(rule Max_ge)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3261
          from finite_threads
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3262
          show "finite ((\<lambda>th. preced th s) ` threads s)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3263
        next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3264
          from p_in and th'_in and dependants_threads[of th']
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3265
          show "p \<in> (\<lambda>th. preced th s) ` threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3266
            by (auto simp:readys_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3267
        qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3268
        ultimately show "p \<le> preced tm s" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3269
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3270
        show "preced tm s \<in> (\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3271
        proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3272
          from tm_chain
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3273
          have "tm \<in> dependants (wq s) th'"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3274
            by (unfold cs_dependants_def s_RAG_def cs_RAG_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3275
          thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3276
        qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3277
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3278
      with tm_max
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3279
      have h: "cp s th' = Max ((\<lambda>th. preced th s) ` threads s)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3280
      show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3281
      proof (fold h, rule Max_eqI)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3282
        fix q 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3283
        assume "q \<in> cp s ` readys s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3284
        then obtain th1 where th1_in: "th1 \<in> readys s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3285
          and eq_q: "q = cp s th1" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3286
        show "q \<le> cp s th'"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3287
          apply (unfold h eq_q)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3288
          apply (unfold cp_eq_cpreced cpreced_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3289
          apply (rule Max_mono)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3290
        proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3291
          from dependants_threads [of th1] th1_in
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3292
          show "(\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1) \<subseteq> 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3293
                 (\<lambda>th. preced th s) ` threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3294
            by (auto simp:readys_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3295
        next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3296
          show "(\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1) \<noteq> {}" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3297
        next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3298
          from finite_threads 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3299
          show " finite ((\<lambda>th. preced th s) ` threads s)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3300
        qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3301
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3302
        from finite_threads
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3303
        show "finite (cp s ` readys s)" by (auto simp:readys_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3304
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3305
        from th'_in
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3306
        show "cp s th' \<in> cp s ` readys s" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3307
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3308
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3309
      assume tm_ready: "tm \<in> readys s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3310
      show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3311
      proof(fold tm_max)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3312
        have cp_eq_p: "cp s tm = preced tm s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3313
        proof(unfold cp_eq_cpreced cpreced_def, rule Max_eqI)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3314
          fix y 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3315
          assume hy: "y \<in> (\<lambda>th. preced th s) ` ({tm} \<union> dependants (wq s) tm)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3316
          show "y \<le> preced tm s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3317
          proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3318
            { fix y'
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3319
              assume hy' : "y' \<in> ((\<lambda>th. preced th s) ` dependants (wq s) tm)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3320
              have "y' \<le> preced tm s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3321
              proof(unfold tm_max, rule Max_ge)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3322
                from hy' dependants_threads[of tm]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3323
                show "y' \<in> (\<lambda>th. preced th s) ` threads s" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3324
              next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3325
                from finite_threads
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3326
                show "finite ((\<lambda>th. preced th s) ` threads s)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3327
              qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3328
            } with hy show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3329
          qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3330
        next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3331
          from dependants_threads[of tm] finite_threads
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3332
          show "finite ((\<lambda>th. preced th s) ` ({tm} \<union> dependants (wq s) tm))"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3333
            by (auto intro:finite_subset)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3334
        next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3335
          show "preced tm s \<in> (\<lambda>th. preced th s) ` ({tm} \<union> dependants (wq s) tm)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3336
            by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3337
        qed 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3338
        moreover have "Max (cp s ` readys s) = cp s tm"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3339
        proof(rule Max_eqI)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3340
          from tm_ready show "cp s tm \<in> cp s ` readys s" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3341
        next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3342
          from finite_threads
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3343
          show "finite (cp s ` readys s)" by (auto simp:readys_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3344
        next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3345
          fix y assume "y \<in> cp s ` readys s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3346
          then obtain th1 where th1_readys: "th1 \<in> readys s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3347
            and h: "y = cp s th1" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3348
          show "y \<le> cp s tm"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3349
            apply(unfold cp_eq_p h)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3350
            apply(unfold cp_eq_cpreced cpreced_def tm_max, rule Max_mono)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3351
          proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3352
            from finite_threads
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3353
            show "finite ((\<lambda>th. preced th s) ` threads s)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3354
          next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3355
            show "(\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1) \<noteq> {}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3356
              by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3357
          next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3358
            from dependants_threads[of th1] th1_readys
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3359
            show "(\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1) 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3360
                    \<subseteq> (\<lambda>th. preced th s) ` threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3361
              by (auto simp:readys_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3362
          qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3363
        qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3364
        ultimately show " Max (cp s ` readys s) = preced tm s" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3365
      qed 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3366
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3367
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3368
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3369
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3370
text {* (* ccc *) \noindent
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3371
  Since the current precedence of the threads in ready queue will always be boosted,
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3372
  there must be one inside it has the maximum precedence of the whole system. 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3373
*}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3374
lemma max_cp_readys_threads:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3375
  shows "Max (cp s ` readys s) = Max (cp s ` threads s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3376
proof(cases "threads s = {}")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3377
  case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3378
  thus ?thesis 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3379
    by (auto simp:readys_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3380
next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3381
  case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3382
  show ?thesis by (rule max_cp_readys_threads_pre[OF False])
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3383
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3384
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3385
end
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3386
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3387
lemma eq_holding: "holding (wq s) th cs = holding s th cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3388
  apply (unfold s_holding_def cs_holding_def wq_def, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3389
  done
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3390
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3391
lemma f_image_eq:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3392
  assumes h: "\<And> a. a \<in> A \<Longrightarrow> f a = g a"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3393
  shows "f ` A = g ` A"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3394
proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3395
  show "f ` A \<subseteq> g ` A"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3396
    by(rule image_subsetI, auto intro:h)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3397
next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3398
  show "g ` A \<subseteq> f ` A"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3399
   by (rule image_subsetI, auto intro:h[symmetric])
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3400
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3401
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3402
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3403
definition detached :: "state \<Rightarrow> thread \<Rightarrow> bool"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3404
  where "detached s th \<equiv> (\<not>(\<exists> cs. holding s th cs)) \<and> (\<not>(\<exists>cs. waiting s th cs))"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3405
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3406
lemma detached_test:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3407
  shows "detached s th = (Th th \<notin> Field (RAG s))"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3408
apply(simp add: detached_def Field_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3409
apply(simp add: s_RAG_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3410
apply(simp add: s_holding_abv s_waiting_abv)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3411
apply(simp add: Domain_iff Range_iff)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3412
apply(simp add: wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3413
apply(auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3414
done
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3415
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3416
context valid_trace
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3417
begin
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3418
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3419
lemma detached_intro:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3420
  assumes eq_pv: "cntP s th = cntV s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3421
  shows "detached s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3422
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3423
 from cnp_cnv_cncs
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3424
  have eq_cnt: "cntP s th =
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3425
    cntV s th + (if th \<in> readys s \<or> th \<notin> threads s then cntCS s th else cntCS s th + 1)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3426
  hence cncs_zero: "cntCS s th = 0"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3427
    by (auto simp:eq_pv split:if_splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3428
  with eq_cnt
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3429
  have "th \<in> readys s \<or> th \<notin> threads s" by (auto simp:eq_pv)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3430
  thus ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3431
  proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3432
    assume "th \<notin> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3433
    with range_in dm_RAG_threads
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3434
    show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3435
      by (auto simp add: detached_def s_RAG_def s_waiting_abv s_holding_abv wq_def Domain_iff Range_iff)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3436
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3437
    assume "th \<in> readys s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3438
    moreover have "Th th \<notin> Range (RAG s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3439
    proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3440
      from card_0_eq [OF finite_holding] and cncs_zero
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3441
      have "holdents s th = {}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3442
        by (simp add:cntCS_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3443
      thus ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3444
        apply(auto simp:holdents_test)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3445
        apply(case_tac a)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3446
        apply(auto simp:holdents_test s_RAG_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3447
        done
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3448
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3449
    ultimately show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3450
      by (auto simp add: detached_def s_RAG_def s_waiting_abv s_holding_abv wq_def readys_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3451
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3452
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3453
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3454
lemma detached_elim:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3455
  assumes dtc: "detached s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3456
  shows "cntP s th = cntV s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3457
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3458
  from cnp_cnv_cncs
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3459
  have eq_pv: " cntP s th =
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3460
    cntV s th + (if th \<in> readys s \<or> th \<notin> threads s then cntCS s th else cntCS s th + 1)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3461
  have cncs_z: "cntCS s th = 0"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3462
  proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3463
    from dtc have "holdents s th = {}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3464
      unfolding detached_def holdents_test s_RAG_def
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3465
      by (simp add: s_waiting_abv wq_def s_holding_abv Domain_iff Range_iff)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3466
    thus ?thesis by (auto simp:cntCS_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3467
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3468
  show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3469
  proof(cases "th \<in> threads s")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3470
    case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3471
    with dtc 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3472
    have "th \<in> readys s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3473
      by (unfold readys_def detached_def Field_def Domain_def Range_def, 
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  3474
           auto simp:waiting_eq s_RAG_def)
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3475
    with cncs_z and eq_pv show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3476
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3477
    case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3478
    with cncs_z and eq_pv show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3479
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3480
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3481
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3482
lemma detached_eq:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3483
  shows "(detached s th) = (cntP s th = cntV s th)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3484
  by (insert vt, auto intro:detached_intro detached_elim)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3485
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3486
end
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3487
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3488
text {* 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3489
  The lemmas in this .thy file are all obvious lemmas, however, they still needs to be derived
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3490
  from the concise and miniature model of PIP given in PrioGDef.thy.
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3491
*}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3492
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3493
lemma eq_dependants: "dependants (wq s) = dependants s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3494
  by (simp add: s_dependants_abv wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3495
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3496
lemma next_th_unique: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3497
  assumes nt1: "next_th s th cs th1"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3498
  and nt2: "next_th s th cs th2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3499
  shows "th1 = th2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3500
using assms by (unfold next_th_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3501
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3502
lemma birth_time_lt:  "s \<noteq> [] \<Longrightarrow> last_set th s < length s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3503
  apply (induct s, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3504
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3505
  fix a s
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3506
  assume ih: "s \<noteq> [] \<Longrightarrow> last_set th s < length s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3507
    and eq_as: "a # s \<noteq> []"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3508
  show "last_set th (a # s) < length (a # s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3509
  proof(cases "s \<noteq> []")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3510
    case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3511
    from False show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3512
      by (cases a, auto simp:last_set.simps)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3513
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3514
    case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3515
    from ih [OF True] show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3516
      by (cases a, auto simp:last_set.simps)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3517
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3518
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3519
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3520
lemma th_in_ne: "th \<in> threads s \<Longrightarrow> s \<noteq> []"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3521
  by (induct s, auto simp:threads.simps)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3522
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3523
lemma preced_tm_lt: "th \<in> threads s \<Longrightarrow> preced th s = Prc x y \<Longrightarrow> y < length s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3524
  apply (drule_tac th_in_ne)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3525
  by (unfold preced_def, auto intro: birth_time_lt)
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3526
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3527
lemma inj_the_preced: 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3528
  "inj_on (the_preced s) (threads s)"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3529
  by (metis inj_onI preced_unique the_preced_def)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3530
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3531
lemma tRAG_alt_def: 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3532
  "tRAG s = {(Th th1, Th th2) | th1 th2. 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3533
                  \<exists> cs. (Th th1, Cs cs) \<in> RAG s \<and> (Cs cs, Th th2) \<in> RAG s}"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3534
 by (auto simp:tRAG_def RAG_split wRAG_def hRAG_def)
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3535
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3536
lemma tRAG_Field:
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3537
  "Field (tRAG s) \<subseteq> Field (RAG s)"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3538
  by (unfold tRAG_alt_def Field_def, auto)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3539
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3540
lemma tRAG_ancestorsE:
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3541
  assumes "x \<in> ancestors (tRAG s) u"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3542
  obtains th where "x = Th th"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3543
proof -
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3544
  from assms have "(u, x) \<in> (tRAG s)^+" 
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3545
      by (unfold ancestors_def, auto)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3546
  from tranclE[OF this] obtain c where "(c, x) \<in> tRAG s" by auto
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3547
  then obtain th where "x = Th th"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3548
    by (unfold tRAG_alt_def, auto)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3549
  from that[OF this] show ?thesis .
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3550
qed
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3551
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3552
lemma tRAG_mono:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3553
  assumes "RAG s' \<subseteq> RAG s"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3554
  shows "tRAG s' \<subseteq> tRAG s"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3555
  using assms 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3556
  by (unfold tRAG_alt_def, auto)
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3557
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3558
lemma holding_next_thI:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3559
  assumes "holding s th cs"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3560
  and "length (wq s cs) > 1"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3561
  obtains th' where "next_th s th cs th'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3562
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3563
  from assms(1)[folded eq_holding, unfolded cs_holding_def]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3564
  have " th \<in> set (wq s cs) \<and> th = hd (wq s cs)" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3565
  then obtain rest where h1: "wq s cs = th#rest" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3566
    by (cases "wq s cs", auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3567
  with assms(2) have h2: "rest \<noteq> []" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3568
  let ?th' = "hd (SOME q. distinct q \<and> set q = set rest)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3569
  have "next_th s th cs ?th'" using  h1(1) h2 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3570
    by (unfold next_th_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3571
  from that[OF this] show ?thesis .
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3572
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3573
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3574
lemma RAG_tRAG_transfer:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3575
  assumes "vt s'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3576
  assumes "RAG s = RAG s' \<union> {(Th th, Cs cs)}"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3577
  and "(Cs cs, Th th'') \<in> RAG s'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3578
  shows "tRAG s = tRAG s' \<union> {(Th th, Th th'')}" (is "?L = ?R")
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3579
proof -
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3580
  interpret vt_s': valid_trace "s'" using assms(1)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3581
    by (unfold_locales, simp)
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3582
  interpret rtree: rtree "RAG s'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3583
  proof
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3584
  show "single_valued (RAG s')"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3585
  apply (intro_locales)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3586
    by (unfold single_valued_def, 
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3587
        auto intro:vt_s'.unique_RAG)
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3588
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3589
  show "acyclic (RAG s')"
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3590
     by (rule vt_s'.acyclic_RAG)
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3591
  qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3592
  { fix n1 n2
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3593
    assume "(n1, n2) \<in> ?L"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3594
    from this[unfolded tRAG_alt_def]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3595
    obtain th1 th2 cs' where 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3596
      h: "n1 = Th th1" "n2 = Th th2" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3597
         "(Th th1, Cs cs') \<in> RAG s"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3598
         "(Cs cs', Th th2) \<in> RAG s" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3599
    from h(4) and assms(2) have cs_in: "(Cs cs', Th th2) \<in> RAG s'" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3600
    from h(3) and assms(2) 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3601
    have "(Th th1, Cs cs') = (Th th, Cs cs) \<or> 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3602
          (Th th1, Cs cs') \<in> RAG s'" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3603
    hence "(n1, n2) \<in> ?R"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3604
    proof
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3605
      assume h1: "(Th th1, Cs cs') = (Th th, Cs cs)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3606
      hence eq_th1: "th1 = th" by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3607
      moreover have "th2 = th''"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3608
      proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3609
        from h1 have "cs' = cs" by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3610
        from assms(3) cs_in[unfolded this] rtree.sgv
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3611
        show ?thesis
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3612
          by (unfold single_valued_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3613
      qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3614
      ultimately show ?thesis using h(1,2) by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3615
    next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3616
      assume "(Th th1, Cs cs') \<in> RAG s'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3617
      with cs_in have "(Th th1, Th th2) \<in> tRAG s'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3618
        by (unfold tRAG_alt_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3619
      from this[folded h(1, 2)] show ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3620
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3621
  } moreover {
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3622
    fix n1 n2
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3623
    assume "(n1, n2) \<in> ?R"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3624
    hence "(n1, n2) \<in>tRAG s' \<or> (n1, n2) = (Th th, Th th'')" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3625
    hence "(n1, n2) \<in> ?L" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3626
    proof
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3627
      assume "(n1, n2) \<in> tRAG s'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3628
      moreover have "... \<subseteq> ?L"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3629
      proof(rule tRAG_mono)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3630
        show "RAG s' \<subseteq> RAG s" by (unfold assms(2), auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3631
      qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3632
      ultimately show ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3633
    next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3634
      assume eq_n: "(n1, n2) = (Th th, Th th'')"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3635
      from assms(2, 3) have "(Cs cs, Th th'') \<in> RAG s" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3636
      moreover have "(Th th, Cs cs) \<in> RAG s" using assms(2) by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3637
      ultimately show ?thesis 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3638
        by (unfold eq_n tRAG_alt_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3639
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3640
  } ultimately show ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3641
qed
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3642
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3643
context valid_trace
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3644
begin
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3645
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3646
lemmas RAG_tRAG_transfer = RAG_tRAG_transfer[OF vt]
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3647
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3648
end
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3649
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3650
lemma cp_alt_def:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3651
  "cp s th =  
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3652
           Max ((the_preced s) ` {th'. Th th' \<in> (subtree (RAG s) (Th th))})"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3653
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3654
  have "Max (the_preced s ` ({th} \<union> dependants (wq s) th)) =
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3655
        Max (the_preced s ` {th'. Th th' \<in> subtree (RAG s) (Th th)})" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3656
          (is "Max (_ ` ?L) = Max (_ ` ?R)")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3657
  proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3658
    have "?L = ?R" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3659
    by (auto dest:rtranclD simp:cs_dependants_def cs_RAG_def s_RAG_def subtree_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3660
    thus ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3661
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3662
  thus ?thesis by (unfold cp_eq_cpreced cpreced_def, fold the_preced_def, simp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3663
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3664
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3665
lemma cp_gen_alt_def:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3666
  "cp_gen s = (Max \<circ> (\<lambda>x. (the_preced s \<circ> the_thread) ` subtree (tRAG s) x))"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3667
    by (auto simp:cp_gen_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3668
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3669
lemma tRAG_nodeE:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3670
  assumes "(n1, n2) \<in> tRAG s"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3671
  obtains th1 th2 where "n1 = Th th1" "n2 = Th th2"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3672
  using assms
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3673
  by (auto simp: tRAG_def wRAG_def hRAG_def tRAG_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3674
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3675
lemma subtree_nodeE:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3676
  assumes "n \<in> subtree (tRAG s) (Th th)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3677
  obtains th1 where "n = Th th1"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3678
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3679
  show ?thesis
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3680
  proof(rule subtreeE[OF assms])
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3681
    assume "n = Th th"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3682
    from that[OF this] show ?thesis .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3683
  next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3684
    assume "Th th \<in> ancestors (tRAG s) n"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3685
    hence "(n, Th th) \<in> (tRAG s)^+" by (auto simp:ancestors_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3686
    hence "\<exists> th1. n = Th th1"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3687
    proof(induct)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3688
      case (base y)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3689
      from tRAG_nodeE[OF this] show ?case by metis
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3690
    next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3691
      case (step y z)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3692
      thus ?case by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3693
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3694
    with that show ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3695
  qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3696
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3697
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3698
lemma tRAG_star_RAG: "(tRAG s)^* \<subseteq> (RAG s)^*"
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3699
proof -
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3700
  have "(wRAG s O hRAG s)^* \<subseteq> (RAG s O RAG s)^*" 
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3701
    by (rule rtrancl_mono, auto simp:RAG_split)
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3702
  also have "... \<subseteq> ((RAG s)^*)^*"
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3703
    by (rule rtrancl_mono, auto)
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3704
  also have "... = (RAG s)^*" by simp
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3705
  finally show ?thesis by (unfold tRAG_def, simp)
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3706
qed
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3707
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3708
lemma tRAG_subtree_RAG: "subtree (tRAG s) x \<subseteq> subtree (RAG s) x"
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3709
proof -
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3710
  { fix a
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3711
    assume "a \<in> subtree (tRAG s) x"
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3712
    hence "(a, x) \<in> (tRAG s)^*" by (auto simp:subtree_def)
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3713
    with tRAG_star_RAG[of s]
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3714
    have "(a, x) \<in> (RAG s)^*" by auto
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3715
    hence "a \<in> subtree (RAG s) x" by (auto simp:subtree_def)
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3716
  } thus ?thesis by auto
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3717
qed
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3718
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3719
lemma tRAG_trancl_eq:
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3720
   "{th'. (Th th', Th th)  \<in> (tRAG s)^+} = 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3721
    {th'. (Th th', Th th)  \<in> (RAG s)^+}"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3722
   (is "?L = ?R")
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3723
proof -
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3724
  { fix th'
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3725
    assume "th' \<in> ?L"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3726
    hence "(Th th', Th th) \<in> (tRAG s)^+" by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3727
    from tranclD[OF this]
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3728
    obtain z where h: "(Th th', z) \<in> tRAG s" "(z, Th th) \<in> (tRAG s)\<^sup>*" by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3729
    from tRAG_subtree_RAG[of s] and this(2)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3730
    have "(z, Th th) \<in> (RAG s)^*" by (meson subsetCE tRAG_star_RAG) 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3731
    moreover from h(1) have "(Th th', z) \<in> (RAG s)^+" using tRAG_alt_def by auto 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3732
    ultimately have "th' \<in> ?R"  by auto 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3733
  } moreover 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3734
  { fix th'
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3735
    assume "th' \<in> ?R"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3736
    hence "(Th th', Th th) \<in> (RAG s)^+" by (auto)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3737
    from plus_rpath[OF this]
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3738
    obtain xs where rp: "rpath (RAG s) (Th th') xs (Th th)" "xs \<noteq> []" by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3739
    hence "(Th th', Th th) \<in> (tRAG s)^+"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3740
    proof(induct xs arbitrary:th' th rule:length_induct)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3741
      case (1 xs th' th)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3742
      then obtain x1 xs1 where Cons1: "xs = x1#xs1" by (cases xs, auto)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3743
      show ?case
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3744
      proof(cases "xs1")
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3745
        case Nil
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3746
        from 1(2)[unfolded Cons1 Nil]
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3747
        have rp: "rpath (RAG s) (Th th') [x1] (Th th)" .
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3748
        hence "(Th th', x1) \<in> (RAG s)" by (cases, simp)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3749
        then obtain cs where "x1 = Cs cs" 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3750
              by (unfold s_RAG_def, auto)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3751
        from rpath_nnl_lastE[OF rp[unfolded this]]
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3752
        show ?thesis by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3753
      next
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3754
        case (Cons x2 xs2)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3755
        from 1(2)[unfolded Cons1[unfolded this]]
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3756
        have rp: "rpath (RAG s) (Th th') (x1 # x2 # xs2) (Th th)" .
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3757
        from rpath_edges_on[OF this]
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3758
        have eds: "edges_on (Th th' # x1 # x2 # xs2) \<subseteq> RAG s" .
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3759
        have "(Th th', x1) \<in> edges_on (Th th' # x1 # x2 # xs2)"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3760
            by (simp add: edges_on_unfold)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3761
        with eds have rg1: "(Th th', x1) \<in> RAG s" by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3762
        then obtain cs1 where eq_x1: "x1 = Cs cs1" by (unfold s_RAG_def, auto)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3763
        have "(x1, x2) \<in> edges_on (Th th' # x1 # x2 # xs2)"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3764
            by (simp add: edges_on_unfold)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3765
        from this eds
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3766
        have rg2: "(x1, x2) \<in> RAG s" by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3767
        from this[unfolded eq_x1] 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3768
        obtain th1 where eq_x2: "x2 = Th th1" by (unfold s_RAG_def, auto)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3769
        from rg1[unfolded eq_x1] rg2[unfolded eq_x1 eq_x2]
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3770
        have rt1: "(Th th', Th th1) \<in> tRAG s" by (unfold tRAG_alt_def, auto)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3771
        from rp have "rpath (RAG s) x2 xs2 (Th th)"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3772
           by  (elim rpath_ConsE, simp)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3773
        from this[unfolded eq_x2] have rp': "rpath (RAG s) (Th th1) xs2 (Th th)" .
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3774
        show ?thesis
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3775
        proof(cases "xs2 = []")
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3776
          case True
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3777
          from rpath_nilE[OF rp'[unfolded this]]
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3778
          have "th1 = th" by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3779
          from rt1[unfolded this] show ?thesis by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3780
        next
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3781
          case False
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3782
          from 1(1)[rule_format, OF _ rp' this, unfolded Cons1 Cons]
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3783
          have "(Th th1, Th th) \<in> (tRAG s)\<^sup>+" by simp
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3784
          with rt1 show ?thesis by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3785
        qed
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3786
      qed
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3787
    qed
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3788
    hence "th' \<in> ?L" by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3789
  } ultimately show ?thesis by blast
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3790
qed
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3791
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3792
lemma tRAG_trancl_eq_Th:
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3793
   "{Th th' | th'. (Th th', Th th)  \<in> (tRAG s)^+} = 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3794
    {Th th' | th'. (Th th', Th th)  \<in> (RAG s)^+}"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3795
    using tRAG_trancl_eq by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3796
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3797
lemma dependants_alt_def:
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3798
  "dependants s th = {th'. (Th th', Th th) \<in> (tRAG s)^+}"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3799
  by (metis eq_RAG s_dependants_def tRAG_trancl_eq)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3800
  
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3801
context valid_trace
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3802
begin
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3803
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3804
lemma count_eq_tRAG_plus:
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3805
  assumes "cntP s th = cntV s th"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3806
  shows "{th'. (Th th', Th th) \<in> (tRAG s)^+} = {}"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3807
  using assms count_eq_dependants dependants_alt_def eq_dependants by auto 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3808
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3809
lemma count_eq_RAG_plus:
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3810
  assumes "cntP s th = cntV s th"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3811
  shows "{th'. (Th th', Th th) \<in> (RAG s)^+} = {}"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3812
  using assms count_eq_dependants cs_dependants_def eq_RAG by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3813
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3814
lemma count_eq_RAG_plus_Th:
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3815
  assumes "cntP s th = cntV s th"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3816
  shows "{Th th' | th'. (Th th', Th th) \<in> (RAG s)^+} = {}"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3817
  using count_eq_RAG_plus[OF assms] by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3818
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3819
lemma count_eq_tRAG_plus_Th:
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3820
  assumes "cntP s th = cntV s th"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3821
  shows "{Th th' | th'. (Th th', Th th) \<in> (tRAG s)^+} = {}"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3822
   using count_eq_tRAG_plus[OF assms] by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3823
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3824
end
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3825
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3826
lemma tRAG_subtree_eq: 
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3827
   "(subtree (tRAG s) (Th th)) = {Th th' | th'. Th th'  \<in> (subtree (RAG s) (Th th))}"
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3828
   (is "?L = ?R")
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3829
proof -
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3830
  { fix n 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3831
    assume h: "n \<in> ?L"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3832
    hence "n \<in> ?R"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3833
    by (smt mem_Collect_eq subsetCE subtree_def subtree_nodeE tRAG_subtree_RAG) 
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3834
  } moreover {
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3835
    fix n
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3836
    assume "n \<in> ?R"
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3837
    then obtain th' where h: "n = Th th'" "(Th th', Th th) \<in> (RAG s)^*"
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3838
      by (auto simp:subtree_def)
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3839
    from rtranclD[OF this(2)]
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3840
    have "n \<in> ?L"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3841
    proof
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3842
      assume "Th th' \<noteq> Th th \<and> (Th th', Th th) \<in> (RAG s)\<^sup>+"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3843
      with h have "n \<in> {Th th' | th'. (Th th', Th th)  \<in> (RAG s)^+}" by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3844
      thus ?thesis using subtree_def tRAG_trancl_eq by fastforce
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3845
    qed (insert h, auto simp:subtree_def)
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3846
  } ultimately show ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3847
qed
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3848
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3849
lemma threads_set_eq: 
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3850
   "the_thread ` (subtree (tRAG s) (Th th)) = 
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3851
                  {th'. Th th' \<in> (subtree (RAG s) (Th th))}" (is "?L = ?R")
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3852
   by (auto intro:rev_image_eqI simp:tRAG_subtree_eq)
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3853
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3854
lemma cp_alt_def1: 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3855
  "cp s th = Max ((the_preced s o the_thread) ` (subtree (tRAG s) (Th th)))"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3856
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3857
  have "(the_preced s ` the_thread ` subtree (tRAG s) (Th th)) =
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3858
       ((the_preced s \<circ> the_thread) ` subtree (tRAG s) (Th th))"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3859
       by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3860
  thus ?thesis by (unfold cp_alt_def, fold threads_set_eq, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3861
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3862
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3863
lemma cp_gen_def_cond: 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3864
  assumes "x = Th th"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3865
  shows "cp s th = cp_gen s (Th th)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3866
by (unfold cp_alt_def1 cp_gen_def, simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3867
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3868
lemma cp_gen_over_set:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3869
  assumes "\<forall> x \<in> A. \<exists> th. x = Th th"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3870
  shows "cp_gen s ` A = (cp s \<circ> the_thread) ` A"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3871
proof(rule f_image_eq)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3872
  fix a
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3873
  assume "a \<in> A"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3874
  from assms[rule_format, OF this]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3875
  obtain th where eq_a: "a = Th th" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3876
  show "cp_gen s a = (cp s \<circ> the_thread) a"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3877
    by  (unfold eq_a, simp, unfold cp_gen_def_cond[OF refl[of "Th th"]], simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3878
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3879
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3880
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3881
context valid_trace
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3882
begin
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3883
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3884
lemma RAG_threads:
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3885
  assumes "(Th th) \<in> Field (RAG s)"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3886
  shows "th \<in> threads s"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3887
  using assms
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3888
  by (metis Field_def UnE dm_RAG_threads range_in vt)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3889
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3890
lemma subtree_tRAG_thread:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3891
  assumes "th \<in> threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3892
  shows "subtree (tRAG s) (Th th) \<subseteq> Th ` threads s" (is "?L \<subseteq> ?R")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3893
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3894
  have "?L = {Th th' |th'. Th th' \<in> subtree (RAG s) (Th th)}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3895
    by (unfold tRAG_subtree_eq, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3896
  also have "... \<subseteq> ?R"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3897
  proof
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3898
    fix x
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3899
    assume "x \<in> {Th th' |th'. Th th' \<in> subtree (RAG s) (Th th)}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3900
    then obtain th' where h: "x = Th th'" "Th th' \<in> subtree (RAG s) (Th th)" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3901
    from this(2)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3902
    show "x \<in> ?R"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3903
    proof(cases rule:subtreeE)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3904
      case 1
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3905
      thus ?thesis by (simp add: assms h(1)) 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3906
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3907
      case 2
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3908
      thus ?thesis by (metis ancestors_Field dm_RAG_threads h(1) image_eqI) 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3909
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3910
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3911
  finally show ?thesis .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3912
qed
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3913
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3914
lemma readys_root:
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3915
  assumes "th \<in> readys s"
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3916
  shows "root (RAG s) (Th th)"
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3917
proof -
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3918
  { fix x
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3919
    assume "x \<in> ancestors (RAG s) (Th th)"
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3920
    hence h: "(Th th, x) \<in> (RAG s)^+" by (auto simp:ancestors_def)
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3921
    from tranclD[OF this]
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3922
    obtain z where "(Th th, z) \<in> RAG s" by auto
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3923
    with assms(1) have False
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3924
         apply (case_tac z, auto simp:readys_def s_RAG_def s_waiting_def cs_waiting_def)
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3925
         by (fold wq_def, blast)
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3926
  } thus ?thesis by (unfold root_def, auto)
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3927
qed
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3928
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3929
lemma readys_in_no_subtree:
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3930
  assumes "th \<in> readys s"
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3931
  and "th' \<noteq> th"
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3932
  shows "Th th \<notin> subtree (RAG s) (Th th')" 
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3933
proof
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3934
   assume "Th th \<in> subtree (RAG s) (Th th')"
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3935
   thus False
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3936
   proof(cases rule:subtreeE)
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3937
      case 1
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3938
      with assms show ?thesis by auto
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3939
   next
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3940
      case 2
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3941
      with readys_root[OF assms(1)]
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3942
      show ?thesis by (auto simp:root_def)
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3943
   qed
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3944
qed
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3945
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3946
lemma not_in_thread_isolated:
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3947
  assumes "th \<notin> threads s"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3948
  shows "(Th th) \<notin> Field (RAG s)"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3949
proof
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3950
  assume "(Th th) \<in> Field (RAG s)"
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3951
  with dm_RAG_threads and range_in assms
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3952
  show False by (unfold Field_def, blast)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3953
qed
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3954
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3955
lemma wf_RAG: "wf (RAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3956
proof(rule finite_acyclic_wf)
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3957
  from finite_RAG show "finite (RAG s)" .
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3958
next
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3959
  from acyclic_RAG show "acyclic (RAG s)" .
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3960
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3961
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3962
lemma sgv_wRAG: "single_valued (wRAG s)"
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3963
  using waiting_unique
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3964
  by (unfold single_valued_def wRAG_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3965
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3966
lemma sgv_hRAG: "single_valued (hRAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3967
  using holding_unique 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3968
  by (unfold single_valued_def hRAG_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3969
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3970
lemma sgv_tRAG: "single_valued (tRAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3971
  by (unfold tRAG_def, rule single_valued_relcomp, 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3972
              insert sgv_wRAG sgv_hRAG, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3973
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3974
lemma acyclic_tRAG: "acyclic (tRAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3975
proof(unfold tRAG_def, rule acyclic_compose)
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3976
  show "acyclic (RAG s)" using acyclic_RAG .
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3977
next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3978
  show "wRAG s \<subseteq> RAG s" unfolding RAG_split by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3979
next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3980
  show "hRAG s \<subseteq> RAG s" unfolding RAG_split by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3981
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3982
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3983
lemma sgv_RAG: "single_valued (RAG s)"
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3984
  using unique_RAG by (auto simp:single_valued_def)
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3985
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3986
lemma rtree_RAG: "rtree (RAG s)"
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3987
  using sgv_RAG acyclic_RAG
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3988
  by (unfold rtree_def rtree_axioms_def sgv_def, auto)
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3989
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 61
diff changeset
  3990
end
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3991
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 61
diff changeset
  3992
sublocale valid_trace < rtree_RAG: rtree "RAG s"
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 61
diff changeset
  3993
proof
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 61
diff changeset
  3994
  show "single_valued (RAG s)"
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 61
diff changeset
  3995
  apply (intro_locales)
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 61
diff changeset
  3996
    by (unfold single_valued_def, 
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3997
        auto intro:unique_RAG)
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 61
diff changeset
  3998
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 61
diff changeset
  3999
  show "acyclic (RAG s)"
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  4000
     by (rule acyclic_RAG)
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 61
diff changeset
  4001
qed
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4002
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4003
sublocale valid_trace < rtree_s: rtree "tRAG s"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4004
proof(unfold_locales)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4005
  from sgv_tRAG show "single_valued (tRAG s)" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4006
next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4007
  from acyclic_tRAG show "acyclic (tRAG s)" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4008
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4009
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4010
sublocale valid_trace < fsbtRAGs : fsubtree "RAG s"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4011
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4012
  show "fsubtree (RAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4013
  proof(intro_locales)
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  4014
    show "fbranch (RAG s)" using finite_fbranchI[OF finite_RAG] .
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4015
  next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4016
    show "fsubtree_axioms (RAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4017
    proof(unfold fsubtree_axioms_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4018
      from wf_RAG show "wf (RAG s)" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4019
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4020
  qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4021
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4022
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4023
sublocale valid_trace < fsbttRAGs: fsubtree "tRAG s"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4024
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4025
  have "fsubtree (tRAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4026
  proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4027
    have "fbranch (tRAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4028
    proof(unfold tRAG_def, rule fbranch_compose)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4029
        show "fbranch (wRAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4030
        proof(rule finite_fbranchI)
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  4031
           from finite_RAG show "finite (wRAG s)"
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4032
           by (unfold RAG_split, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4033
        qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4034
    next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4035
        show "fbranch (hRAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4036
        proof(rule finite_fbranchI)
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  4037
           from finite_RAG 
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4038
           show "finite (hRAG s)" by (unfold RAG_split, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4039
        qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4040
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4041
    moreover have "wf (tRAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4042
    proof(rule wf_subset)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4043
      show "wf (RAG s O RAG s)" using wf_RAG
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4044
        by (fold wf_comp_self, simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4045
    next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4046
      show "tRAG s \<subseteq> (RAG s O RAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4047
        by (unfold tRAG_alt_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4048
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4049
    ultimately show ?thesis
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4050
      by (unfold fsubtree_def fsubtree_axioms_def,auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4051
  qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4052
  from this[folded tRAG_def] show "fsubtree (tRAG s)" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4053
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4054
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4055
lemma Max_UNION: 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4056
  assumes "finite A"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4057
  and "A \<noteq> {}"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4058
  and "\<forall> M \<in> f ` A. finite M"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4059
  and "\<forall> M \<in> f ` A. M \<noteq> {}"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4060
  shows "Max (\<Union>x\<in> A. f x) = Max (Max ` f ` A)" (is "?L = ?R")
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4061
  using assms[simp]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4062
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4063
  have "?L = Max (\<Union>(f ` A))"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4064
    by (fold Union_image_eq, simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4065
  also have "... = ?R"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4066
    by (subst Max_Union, simp+)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4067
  finally show ?thesis .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4068
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4069
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4070
lemma max_Max_eq:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4071
  assumes "finite A"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4072
    and "A \<noteq> {}"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4073
    and "x = y"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4074
  shows "max x (Max A) = Max ({y} \<union> A)" (is "?L = ?R")
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4075
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4076
  have "?R = Max (insert y A)" by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4077
  also from assms have "... = ?L"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4078
      by (subst Max.insert, simp+)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4079
  finally show ?thesis by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4080
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4081
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4082
context valid_trace
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4083
begin
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4084
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4085
(* ddd *)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4086
lemma cp_gen_rec:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4087
  assumes "x = Th th"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4088
  shows "cp_gen s x = Max ({the_preced s th} \<union> (cp_gen s) ` children (tRAG s) x)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4089
proof(cases "children (tRAG s) x = {}")
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4090
  case True
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4091
  show ?thesis
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4092
    by (unfold True cp_gen_def subtree_children, simp add:assms)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4093
next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4094
  case False
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4095
  hence [simp]: "children (tRAG s) x \<noteq> {}" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4096
  note fsbttRAGs.finite_subtree[simp]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4097
  have [simp]: "finite (children (tRAG s) x)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4098
     by (intro rev_finite_subset[OF fsbttRAGs.finite_subtree], 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4099
            rule children_subtree)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4100
  { fix r x
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4101
    have "subtree r x \<noteq> {}" by (auto simp:subtree_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4102
  } note this[simp]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4103
  have [simp]: "\<exists>x\<in>children (tRAG s) x. subtree (tRAG s) x \<noteq> {}"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4104
  proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4105
    from False obtain q where "q \<in> children (tRAG s) x" by blast
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4106
    moreover have "subtree (tRAG s) q \<noteq> {}" by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4107
    ultimately show ?thesis by blast
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4108
  qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4109
  have h: "Max ((the_preced s \<circ> the_thread) `
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4110
                ({x} \<union> \<Union>(subtree (tRAG s) ` children (tRAG s) x))) =
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4111
        Max ({the_preced s th} \<union> cp_gen s ` children (tRAG s) x)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4112
                     (is "?L = ?R")
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4113
  proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4114
    let "Max (?f ` (?A \<union> \<Union> (?g ` ?B)))" = ?L
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4115
    let "Max (_ \<union> (?h ` ?B))" = ?R
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4116
    let ?L1 = "?f ` \<Union>(?g ` ?B)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4117
    have eq_Max_L1: "Max ?L1 = Max (?h ` ?B)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4118
    proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4119
      have "?L1 = ?f ` (\<Union> x \<in> ?B.(?g x))" by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4120
      also have "... =  (\<Union> x \<in> ?B. ?f ` (?g x))" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4121
      finally have "Max ?L1 = Max ..." by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4122
      also have "... = Max (Max ` (\<lambda>x. ?f ` subtree (tRAG s) x) ` ?B)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4123
        by (subst Max_UNION, simp+)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4124
      also have "... = Max (cp_gen s ` children (tRAG s) x)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4125
          by (unfold image_comp cp_gen_alt_def, simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4126
      finally show ?thesis .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4127
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4128
    show ?thesis
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4129
    proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4130
      have "?L = Max (?f ` ?A \<union> ?L1)" by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4131
      also have "... = max (the_preced s (the_thread x)) (Max ?L1)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4132
            by (subst Max_Un, simp+)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4133
      also have "... = max (?f x) (Max (?h ` ?B))"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4134
        by (unfold eq_Max_L1, simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4135
      also have "... =?R"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4136
        by (rule max_Max_eq, (simp)+, unfold assms, simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4137
      finally show ?thesis .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4138
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4139
  qed  thus ?thesis 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4140
          by (fold h subtree_children, unfold cp_gen_def, simp) 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4141
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4142
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4143
lemma cp_rec:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4144
  "cp s th = Max ({the_preced s th} \<union> 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4145
                     (cp s o the_thread) ` children (tRAG s) (Th th))"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4146
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4147
  have "Th th = Th th" by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4148
  note h =  cp_gen_def_cond[OF this] cp_gen_rec[OF this]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4149
  show ?thesis 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4150
  proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4151
    have "cp_gen s ` children (tRAG s) (Th th) = 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4152
                (cp s \<circ> the_thread) ` children (tRAG s) (Th th)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4153
    proof(rule cp_gen_over_set)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4154
      show " \<forall>x\<in>children (tRAG s) (Th th). \<exists>th. x = Th th"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4155
        by (unfold tRAG_alt_def, auto simp:children_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4156
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4157
    thus ?thesis by (subst (1) h(1), unfold h(2), simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4158
  qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4159
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4160
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4161
end
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4162
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 61
diff changeset
  4163
(* keep *)
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4164
lemma next_th_holding:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4165
  assumes vt: "vt s"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4166
  and nxt: "next_th s th cs th'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4167
  shows "holding (wq s) th cs"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4168
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4169
  from nxt[unfolded next_th_def]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4170
  obtain rest where h: "wq s cs = th # rest"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4171
                       "rest \<noteq> []" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4172
                       "th' = hd (SOME q. distinct q \<and> set q = set rest)" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4173
  thus ?thesis
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4174
    by (unfold cs_holding_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4175
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4176
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  4177
context valid_trace
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  4178
begin
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  4179
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4180
lemma next_th_waiting:
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  4181
  assumes nxt: "next_th s th cs th'"
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4182
  shows "waiting (wq s) th' cs"
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  4183
proof -
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4184
  from nxt[unfolded next_th_def]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4185
  obtain rest where h: "wq s cs = th # rest"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4186
                       "rest \<noteq> []" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4187
                       "th' = hd (SOME q. distinct q \<and> set q = set rest)" by auto
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  4188
  from wq_distinct[of cs, unfolded h]
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4189
  have dst: "distinct (th # rest)" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4190
  have in_rest: "th' \<in> set rest"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4191
  proof(unfold h, rule someI2)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4192
    show "distinct rest \<and> set rest = set rest" using dst by auto
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  4193
  next
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4194
    fix x assume "distinct x \<and> set x = set rest"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4195
    with h(2)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4196
    show "hd x \<in> set (rest)" by (cases x, auto)
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  4197
  qed
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4198
  hence "th' \<in> set (wq s cs)" by (unfold h(1), auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4199
  moreover have "th' \<noteq> hd (wq s cs)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4200
    by (unfold h(1), insert in_rest dst, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4201
  ultimately show ?thesis by (auto simp:cs_waiting_def)
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  4202
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  4203
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4204
lemma next_th_RAG:
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  4205
  assumes nxt: "next_th (s::event list) th cs th'"
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4206
  shows "{(Cs cs, Th th), (Th th', Cs cs)} \<subseteq> RAG s"
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  4207
  using vt assms next_th_holding next_th_waiting
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  4208
  by (unfold s_RAG_def, simp)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  4209
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  4210
end
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  4211
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  4212
-- {* A useless definition *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  4213
definition cps:: "state \<Rightarrow> (thread \<times> precedence) set"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  4214
where "cps s = {(th, cp s th) | th . th \<in> threads s}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  4215
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  4216
find_theorems release
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  4217
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  4218
lemma "wq (V th cs # s) cs1 = ttt"
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  4219
  apply (unfold wq_def, auto simp:Let_def)
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  4220
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  4221
end
77
d37703e0c5c4 CpsG.thy updated. It is a copy of PIPBasics.thy under drastic improvement.
zhangx
parents: 73
diff changeset
  4222