CpsG.thy~
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Wed, 27 Jan 2016 13:47:08 +0000
changeset 82 c0a4e840aefe
parent 73 b0054fb0d1ce
child 77 d37703e0c5c4
child 95 8d2cc27f45f3
permissions -rw-r--r--
some small changes to Correctness and Paper
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
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
     5
(* I am going to use this file as a start point to retrofiting 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
     6
   PIPBasics.thy, which is originally called CpsG.ghy *)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
     7
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
     8
locale valid_trace = 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
     9
  fixes s
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    10
  assumes vt : "vt s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    11
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    12
locale valid_trace_e = valid_trace +
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    13
  fixes e
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    14
  assumes vt_e: "vt (e#s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    15
begin
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    16
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    17
lemma pip_e: "PIP s e"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    18
  using vt_e by (cases, simp)  
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    19
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    20
end
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    21
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    22
lemma runing_ready: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    23
  shows "runing s \<subseteq> readys s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    24
  unfolding runing_def readys_def
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    25
  by auto 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    26
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    27
lemma readys_threads:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    28
  shows "readys s \<subseteq> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    29
  unfolding readys_def
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    30
  by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    31
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    32
lemma wq_v_neq [simp]:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    33
   "cs \<noteq> cs' \<Longrightarrow> wq (V thread cs#s) cs' = wq s cs'"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    34
  by (auto simp:wq_def Let_def cp_def split:list.splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    35
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    36
lemma runing_head:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    37
  assumes "th \<in> runing s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    38
  and "th \<in> set (wq_fun (schs s) cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    39
  shows "th = hd (wq_fun (schs s) cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    40
  using assms
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    41
  by (simp add:runing_def readys_def s_waiting_def wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    42
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    43
context valid_trace
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    44
begin
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    45
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    46
lemma actor_inv: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    47
  assumes "PIP s e"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    48
  and "\<not> isCreate e"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    49
  shows "actor e \<in> runing s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    50
  using assms
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    51
  by (induct, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    52
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    53
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    54
lemma isP_E:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    55
  assumes "isP e"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    56
  obtains cs where "e = P (actor e) cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    57
  using assms by (cases e, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    58
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    59
lemma isV_E:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    60
  assumes "isV e"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    61
  obtains cs where "e = V (actor e) cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    62
  using assms by (cases e, auto) 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    63
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    64
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    65
lemma ind [consumes 0, case_names Nil Cons, induct type]:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    66
  assumes "PP []"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    67
     and "(\<And>s e. valid_trace s \<Longrightarrow> valid_trace (e#s) \<Longrightarrow>
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    68
                   PP s \<Longrightarrow> PIP s e \<Longrightarrow> PP (e # s))"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    69
     shows "PP s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    70
proof(rule vt.induct[OF vt])
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    71
  from assms(1) show "PP []" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    72
next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    73
  fix s e
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    74
  assume h: "vt s" "PP s" "PIP s e"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    75
  show "PP (e # s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    76
  proof(cases rule:assms(2))
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    77
    from h(1) show v1: "valid_trace s" by (unfold_locales, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    78
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    79
    from h(1,3) have "vt (e#s)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    80
    thus "valid_trace (e # s)" by (unfold_locales, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    81
  qed (insert h, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    82
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    83
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    84
lemma wq_distinct: "distinct (wq s cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    85
proof(induct rule:ind)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    86
  case (Cons s e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    87
  from Cons(4,3)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    88
  show ?case 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    89
  proof(induct)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    90
    case (thread_P th s cs1)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    91
    show ?case 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    92
    proof(cases "cs = cs1")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    93
      case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    94
      thus ?thesis (is "distinct ?L")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    95
      proof - 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    96
        have "?L = wq_fun (schs s) cs1 @ [th]" using True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    97
          by (simp add:wq_def wf_def Let_def split:list.splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    98
        moreover have "distinct ..."
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
    99
        proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   100
          have "th \<notin> set (wq_fun (schs s) cs1)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   101
          proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   102
            assume otherwise: "th \<in> set (wq_fun (schs s) cs1)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   103
            from runing_head[OF thread_P(1) this]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   104
            have "th = hd (wq_fun (schs s) cs1)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   105
            hence "(Cs cs1, Th th) \<in> (RAG s)" using otherwise
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   106
              by (simp add:s_RAG_def s_holding_def wq_def cs_holding_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   107
            with thread_P(2) show False by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   108
          qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   109
          moreover have "distinct (wq_fun (schs s) cs1)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   110
              using True thread_P wq_def by auto 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   111
          ultimately show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   112
        qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   113
        ultimately show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   114
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   115
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   116
      case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   117
      with thread_P(3)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   118
      show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   119
        by (auto simp:wq_def wf_def Let_def split:list.splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   120
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   121
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   122
    case (thread_V th s cs1)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   123
    thus ?case
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   124
    proof(cases "cs = cs1")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   125
      case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   126
      show ?thesis (is "distinct ?L")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   127
      proof(cases "(wq s cs)")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   128
        case Nil
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   129
        thus ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   130
          by (auto simp:wq_def wf_def Let_def split:list.splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   131
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   132
        case (Cons w_hd w_tl)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   133
        moreover have "distinct (SOME q. distinct q \<and> set q = set w_tl)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   134
        proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   135
          from thread_V(3)[unfolded Cons]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   136
          show  "distinct w_tl \<and> set w_tl = set w_tl" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   137
        qed auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   138
        ultimately show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   139
          by (auto simp:wq_def wf_def Let_def True split:list.splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   140
      qed 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   141
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   142
      case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   143
      with thread_V(3)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   144
      show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   145
        by (auto simp:wq_def wf_def Let_def split:list.splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   146
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   147
  qed (insert Cons, auto simp: wq_def Let_def split:list.splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   148
qed (unfold wq_def Let_def, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   149
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   150
end
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   151
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   152
context valid_trace_e
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   153
begin
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   154
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   155
text {*
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   156
  The following lemma shows that only the @{text "P"}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   157
  operation can add new thread into waiting queues. 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   158
  Such kind of lemmas are very obvious, but need to be checked formally.
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   159
  This is a kind of confirmation that our modelling is correct.
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   160
*}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   161
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   162
lemma wq_in_inv: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   163
  assumes s_ni: "thread \<notin> set (wq s cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   164
  and s_i: "thread \<in> set (wq (e#s) cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   165
  shows "e = P thread cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   166
proof(cases e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   167
  -- {* This is the only non-trivial case: *}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   168
  case (V th cs1)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   169
  have False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   170
  proof(cases "cs1 = cs")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   171
    case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   172
    show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   173
    proof(cases "(wq s cs1)")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   174
      case (Cons w_hd w_tl)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   175
      have "set (wq (e#s) cs) \<subseteq> set (wq s cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   176
      proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   177
        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
   178
          using  Cons V by (auto simp:wq_def Let_def True split:if_splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   179
        moreover have "set ... \<subseteq> set (wq s cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   180
        proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   181
          show "distinct w_tl \<and> set w_tl = set w_tl"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   182
            by (metis distinct.simps(2) local.Cons wq_distinct)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   183
        qed (insert Cons True, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   184
        ultimately show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   185
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   186
      with assms show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   187
    qed (insert assms V True, auto simp:wq_def Let_def split:if_splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   188
  qed (insert assms V, auto simp:wq_def Let_def split:if_splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   189
  thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   190
qed (insert assms, auto simp:wq_def Let_def split:if_splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   191
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   192
lemma wq_out_inv: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   193
  assumes s_in: "thread \<in> set (wq s cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   194
  and s_hd: "thread = hd (wq s cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   195
  and s_i: "thread \<noteq> hd (wq (e#s) cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   196
  shows "e = V thread cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   197
proof(cases e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   198
-- {* There are only two non-trivial cases: *}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   199
  case (V th cs1)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   200
  show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   201
  proof(cases "cs1 = cs")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   202
    case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   203
    have "PIP s (V th cs)" using pip_e[unfolded V[unfolded True]] .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   204
    thus ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   205
    proof(cases)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   206
      case (thread_V)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   207
      moreover have "th = thread" using thread_V(2) s_hd
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   208
          by (unfold s_holding_def wq_def, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   209
      ultimately show ?thesis using V True by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   210
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   211
  qed (insert assms V, auto simp:wq_def Let_def split:if_splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   212
next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   213
  case (P th cs1)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   214
  show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   215
  proof(cases "cs1 = cs")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   216
    case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   217
    with P have "wq (e#s) cs = wq_fun (schs s) cs @ [th]"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   218
      by (auto simp:wq_def Let_def split:if_splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   219
    with s_i s_hd s_in have False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   220
      by (metis empty_iff hd_append2 list.set(1) wq_def) 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   221
    thus ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   222
  qed (insert assms P, auto simp:wq_def Let_def split:if_splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   223
qed (insert assms, auto simp:wq_def Let_def split:if_splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   224
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   225
end
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   226
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   227
text {*
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   228
  The following lemmas is also obvious and shallow. It says
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   229
  that only running thread can request for a critical resource 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   230
  and that the requested resource must be one which is
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   231
  not current held by the thread.
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   232
*}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   233
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   234
lemma p_pre: "\<lbrakk>vt ((P thread cs)#s)\<rbrakk> \<Longrightarrow> 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   235
  thread \<in> runing s \<and> (Cs cs, Th thread)  \<notin> (RAG s)^+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   236
apply (ind_cases "vt ((P thread cs)#s)")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   237
apply (ind_cases "step s (P thread cs)")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   238
by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   239
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   240
lemma abs1:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   241
  assumes ein: "e \<in> set es"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   242
  and neq: "hd es \<noteq> hd (es @ [x])"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   243
  shows "False"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   244
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   245
  from ein have "es \<noteq> []" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   246
  then obtain e ess where "es = e # ess" by (cases es, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   247
  with neq show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   248
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   249
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   250
lemma q_head: "Q (hd es) \<Longrightarrow> hd es = hd [th\<leftarrow>es . Q th]"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   251
  by (cases es, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   252
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   253
inductive_cases evt_cons: "vt (a#s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   254
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   255
context valid_trace_e
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   256
begin
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   257
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   258
lemma abs2:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   259
  assumes inq: "thread \<in> set (wq s cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   260
  and nh: "thread = hd (wq s cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   261
  and qt: "thread \<noteq> hd (wq (e#s) cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   262
  and inq': "thread \<in> set (wq (e#s) cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   263
  shows "False"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   264
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   265
  from vt_e assms show "False"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   266
    apply (cases e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   267
    apply ((simp split:if_splits add:Let_def wq_def)[1])+
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   268
    apply (insert abs1, fast)[1]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   269
    apply (auto simp:wq_def simp:Let_def split:if_splits list.splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   270
  proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   271
    fix th qs
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   272
    assume vt: "vt (V th cs # s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   273
      and th_in: "thread \<in> set (SOME q. distinct q \<and> set q = set qs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   274
      and eq_wq: "wq_fun (schs s) cs = thread # qs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   275
    show "False"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   276
    proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   277
      from wq_distinct[of cs]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   278
        and eq_wq[folded wq_def] have "distinct (thread#qs)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   279
      moreover have "thread \<in> set qs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   280
      proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   281
        have "set (SOME q. distinct q \<and> set q = set qs) = set qs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   282
        proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   283
          from wq_distinct [of cs]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   284
          and eq_wq [folded wq_def]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   285
          show "distinct qs \<and> set qs = set qs" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   286
        next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   287
          fix x assume "distinct x \<and> set x = set qs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   288
          thus "set x = set qs" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   289
        qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   290
        with th_in show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   291
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   292
      ultimately show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   293
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   294
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   295
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   296
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   297
end
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   298
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   299
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   300
context valid_trace
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   301
begin
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   302
lemma  vt_moment: "\<And> t. vt (moment t s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   303
proof(induct rule:ind)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   304
  case Nil
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   305
  thus ?case by (simp add:vt_nil)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   306
next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   307
  case (Cons s e t)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   308
  show ?case
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   309
  proof(cases "t \<ge> length (e#s)")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   310
    case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   311
    from True have "moment t (e#s) = e#s" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   312
    thus ?thesis using Cons
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   313
      by (simp add:valid_trace_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   314
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   315
    case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   316
    from Cons have "vt (moment t s)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   317
    moreover have "moment t (e#s) = moment t s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   318
    proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   319
      from False have "t \<le> length s" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   320
      from moment_app [OF this, of "[e]"] 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   321
      show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   322
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   323
    ultimately show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   324
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   325
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   326
end
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   327
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   328
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   329
locale valid_moment = valid_trace + 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   330
  fixes i :: nat
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   331
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   332
sublocale valid_moment < vat_moment: valid_trace "(moment i s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   333
  by (unfold_locales, insert vt_moment, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   334
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   335
context valid_trace
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   336
begin
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   337
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   338
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   339
text {* (* ddd *)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   340
  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
   341
  model, even intuitively very `basic` and `obvious` properties need to derived from scratch.
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   342
  For instance, the fact 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   343
  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
   344
  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
   345
  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
   346
  blocked the second time (because it is not running). 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   347
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   348
  To derive this fact, one needs to prove by contraction and 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   349
  reason about time (or @{text "moement"}). The reasoning is based on a generic theorem
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   350
  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
   351
  a condition @{text "Q"} is @{text "True"} at a state @{text "s"},
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   352
  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
   353
  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
   354
  of events leading to it), such that @{text "Q"} switched 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   355
  from being @{text "False"} to @{text "True"} and kept being @{text "True"}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   356
  till the last moment of @{text "s"}.
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   357
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   358
  Suppose a thread @{text "th"} is blocked
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   359
  on @{text "cs1"} and @{text "cs2"} in some state @{text "s"}, 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   360
  since no thread is blocked at the very beginning, by applying 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   361
  @{text "p_split"} to these two blocking facts, there exist 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   362
  two moments @{text "t1"} and @{text "t2"}  in @{text "s"}, such that 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   363
  @{text "th"} got blocked on @{text "cs1"} and @{text "cs2"} 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   364
  and kept on blocked on them respectively ever since.
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   365
 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   366
  Without lost of generality, we assume @{text "t1"} is earlier than @{text "t2"}.
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   367
  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
   368
  in blocked state at moment @{text "t2"} and could not
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   369
  make any request and get blocked the second time: Contradiction.
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   370
*}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   371
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   372
lemma waiting_unique_pre: (* ccc *)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   373
  assumes h11: "thread \<in> set (wq s cs1)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   374
  and h12: "thread \<noteq> hd (wq s cs1)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   375
  assumes h21: "thread \<in> set (wq s cs2)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   376
  and h22: "thread \<noteq> hd (wq s cs2)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   377
  and neq12: "cs1 \<noteq> cs2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   378
  shows "False"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   379
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   380
  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
   381
  from h11 and h12 have q1: "?Q cs1 s" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   382
  from h21 and h22 have q2: "?Q cs2 s" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   383
  have nq1: "\<not> ?Q cs1 []" by (simp add:wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   384
  have nq2: "\<not> ?Q cs2 []" by (simp add:wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   385
  from p_split [of "?Q cs1", OF q1 nq1]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   386
  obtain t1 where lt1: "t1 < length s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   387
    and np1: "\<not> ?Q cs1 (moment t1 s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   388
    and nn1: "(\<forall>i'>t1. ?Q cs1 (moment i' s))" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   389
  from p_split [of "?Q cs2", OF q2 nq2]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   390
  obtain t2 where lt2: "t2 < length s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   391
    and np2: "\<not> ?Q cs2 (moment t2 s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   392
    and nn2: "(\<forall>i'>t2. ?Q cs2 (moment i' s))" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   393
  { fix s cs
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   394
    assume q: "?Q cs s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   395
    have "thread \<notin> runing s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   396
    proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   397
      assume "thread \<in> runing s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   398
      hence " \<forall>cs. \<not> (thread \<in> set (wq_fun (schs s) cs) \<and> 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   399
                 thread \<noteq> hd (wq_fun (schs s) cs))"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   400
        by (unfold runing_def s_waiting_def readys_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   401
      from this[rule_format, of cs] q 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   402
      show False by (simp add: wq_def) 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   403
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   404
  } note q_not_runing = this
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   405
  { fix i1 i2
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   406
    let ?i3 = "Suc i2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   407
    assume lt12: "i1 < i2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   408
    and "i1 < length s" "i2 < length s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   409
    hence le_i3: "?i3 \<le> length s" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   410
    from moment_plus [OF this]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   411
    obtain e where eq_m: "moment ?i3 s = e#moment i2 s" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   412
    have "i2 < ?i3" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   413
    from nn2 [rule_format, OF this] and eq_m
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   414
      have h1: "thread \<in> set (wq (e#moment t2 s) cs2)" and
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   415
           h2: "thread \<noteq> hd (wq (e#moment t2 s) cs2)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   416
      have "vt (e#moment t2 s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   417
      proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   418
        from vt_moment 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   419
        have "vt (moment ?t3 s)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   420
        with eq_m show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   421
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   422
      then interpret vt_e: valid_trace_e "moment t2 s" "e"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   423
        by (unfold_locales, auto, cases, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   424
      have ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   425
      proof(cases "thread \<in> set (wq (moment t2 s) cs2)")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   426
        case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   427
        from True and np2 have eq_th: "thread = hd (wq (moment t2 s) cs2)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   428
          by auto 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   429
        from vt_e.abs2 [OF True eq_th h2 h1]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   430
        show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   431
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   432
        case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   433
        from vt_e.block_pre[OF False h1]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   434
        have "e = P thread cs2" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   435
        with vt_e.vt_e have "vt ((P thread cs2)# moment t2 s)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   436
        from p_pre [OF this] have "thread \<in> runing (moment t2 s)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   437
        with runing_ready have "thread \<in> readys (moment t2 s)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   438
        with nn1 [rule_format, OF lt12]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   439
        show ?thesis  by (simp add:readys_def wq_def s_waiting_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   440
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   441
  }
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   442
  show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   443
  proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   444
    { 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   445
      assume lt12: "t1 < t2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   446
      let ?t3 = "Suc t2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   447
      from lt2 have le_t3: "?t3 \<le> length s" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   448
      from moment_plus [OF this] 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   449
      obtain e where eq_m: "moment ?t3 s = e#moment t2 s" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   450
      have "t2 < ?t3" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   451
      from nn2 [rule_format, OF this] and eq_m
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   452
      have h1: "thread \<in> set (wq (e#moment t2 s) cs2)" and
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   453
           h2: "thread \<noteq> hd (wq (e#moment t2 s) cs2)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   454
      have "vt (e#moment t2 s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   455
      proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   456
        from vt_moment 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   457
        have "vt (moment ?t3 s)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   458
        with eq_m show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   459
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   460
      then interpret vt_e: valid_trace_e "moment t2 s" "e"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   461
        by (unfold_locales, auto, cases, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   462
      have ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   463
      proof(cases "thread \<in> set (wq (moment t2 s) cs2)")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   464
        case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   465
        from True and np2 have eq_th: "thread = hd (wq (moment t2 s) cs2)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   466
          by auto 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   467
        from vt_e.abs2 [OF True eq_th h2 h1]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   468
        show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   469
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   470
        case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   471
        from vt_e.block_pre[OF False h1]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   472
        have "e = P thread cs2" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   473
        with vt_e.vt_e have "vt ((P thread cs2)# moment t2 s)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   474
        from p_pre [OF this] have "thread \<in> runing (moment t2 s)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   475
        with runing_ready have "thread \<in> readys (moment t2 s)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   476
        with nn1 [rule_format, OF lt12]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   477
        show ?thesis  by (simp add:readys_def wq_def s_waiting_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   478
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   479
    } moreover {
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   480
      assume lt12: "t2 < t1"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   481
      let ?t3 = "Suc t1"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   482
      from lt1 have le_t3: "?t3 \<le> length s" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   483
      from moment_plus [OF this] 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   484
      obtain e where eq_m: "moment ?t3 s = e#moment t1 s" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   485
      have lt_t3: "t1 < ?t3" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   486
      from nn1 [rule_format, OF this] and eq_m
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   487
      have h1: "thread \<in> set (wq (e#moment t1 s) cs1)" and
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   488
        h2: "thread \<noteq> hd (wq (e#moment t1 s) cs1)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   489
      have "vt  (e#moment t1 s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   490
      proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   491
        from vt_moment
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   492
        have "vt (moment ?t3 s)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   493
        with eq_m show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   494
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   495
      then interpret vt_e: valid_trace_e "moment t1 s" e
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   496
        by (unfold_locales, auto, cases, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   497
      have ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   498
      proof(cases "thread \<in> set (wq (moment t1 s) cs1)")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   499
        case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   500
        from True and np1 have eq_th: "thread = hd (wq (moment t1 s) cs1)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   501
          by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   502
        from vt_e.abs2 True eq_th h2 h1
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   503
        show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   504
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   505
        case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   506
        from vt_e.block_pre [OF False h1]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   507
        have "e = P thread cs1" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   508
        with vt_e.vt_e have "vt ((P thread cs1)# moment t1 s)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   509
        from p_pre [OF this] have "thread \<in> runing (moment t1 s)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   510
        with runing_ready have "thread \<in> readys (moment t1 s)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   511
        with nn2 [rule_format, OF lt12]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   512
        show ?thesis  by (simp add:readys_def wq_def s_waiting_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   513
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   514
    } moreover {
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   515
      assume eqt12: "t1 = t2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   516
      let ?t3 = "Suc t1"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   517
      from lt1 have le_t3: "?t3 \<le> length s" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   518
      from moment_plus [OF this] 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   519
      obtain e where eq_m: "moment ?t3 s = e#moment t1 s" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   520
      have lt_t3: "t1 < ?t3" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   521
      from nn1 [rule_format, OF this] and eq_m
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   522
      have h1: "thread \<in> set (wq (e#moment t1 s) cs1)" and
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   523
        h2: "thread \<noteq> hd (wq (e#moment t1 s) cs1)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   524
      have vt_e: "vt (e#moment t1 s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   525
      proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   526
        from vt_moment
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   527
        have "vt (moment ?t3 s)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   528
        with eq_m show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   529
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   530
      then interpret vt_e: valid_trace_e "moment t1 s" e
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   531
        by (unfold_locales, auto, cases, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   532
      have ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   533
      proof(cases "thread \<in> set (wq (moment t1 s) cs1)")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   534
        case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   535
        from True and np1 have eq_th: "thread = hd (wq (moment t1 s) cs1)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   536
          by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   537
        from vt_e.abs2 [OF True eq_th h2 h1]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   538
        show ?thesis 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 False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   541
        from vt_e.block_pre [OF False h1]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   542
        have eq_e1: "e = P thread cs1" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   543
        have lt_t3: "t1 < ?t3" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   544
        with eqt12 have "t2 < ?t3" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   545
        from nn2 [rule_format, OF this] and eq_m and eqt12
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   546
        have h1: "thread \<in> set (wq (e#moment t2 s) cs2)" and
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   547
          h2: "thread \<noteq> hd (wq (e#moment t2 s) cs2)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   548
        show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   549
        proof(cases "thread \<in> set (wq (moment t2 s) cs2)")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   550
          case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   551
          from True and np2 have eq_th: "thread = hd (wq (moment t2 s) cs2)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   552
            by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   553
          from vt_e and eqt12 have "vt (e#moment t2 s)" by simp 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   554
          then interpret vt_e2: valid_trace_e "moment t2 s" e
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   555
            by (unfold_locales, auto, cases, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   556
          from vt_e2.abs2 [OF True eq_th h2 h1]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   557
          show ?thesis .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   558
        next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   559
          case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   560
          have "vt (e#moment t2 s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   561
          proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   562
            from vt_moment eqt12
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   563
            have "vt (moment (Suc t2) s)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   564
            with eq_m eqt12 show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   565
          qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   566
          then interpret vt_e2: valid_trace_e "moment t2 s" e
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   567
            by (unfold_locales, auto, cases, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   568
          from vt_e2.block_pre [OF False h1]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   569
          have "e = P thread cs2" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   570
          with eq_e1 neq12 show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   571
        qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   572
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   573
    } ultimately show ?thesis by arith
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   574
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   575
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   576
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   577
text {*
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   578
  This lemma is a simple corrolary of @{text "waiting_unique_pre"}.
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   579
*}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   580
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   581
lemma waiting_unique:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   582
  assumes "waiting s th cs1"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   583
  and "waiting s th cs2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   584
  shows "cs1 = cs2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   585
using waiting_unique_pre assms
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   586
unfolding wq_def s_waiting_def
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   587
by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   588
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   589
end
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   590
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   591
(* not used *)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   592
text {*
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   593
  Every thread can only be blocked on one critical resource, 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   594
  symmetrically, every critical resource can only be held by one thread. 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   595
  This fact is much more easier according to our definition. 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   596
*}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   597
lemma held_unique:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   598
  assumes "holding (s::event list) th1 cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   599
  and "holding s th2 cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   600
  shows "th1 = th2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   601
 by (insert assms, unfold s_holding_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   602
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   603
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   604
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
   605
  apply (induct s, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   606
  by (case_tac a, auto split:if_splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   607
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   608
lemma last_set_unique: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   609
  "\<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
   610
          \<Longrightarrow> th1 = th2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   611
  apply (induct s, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   612
  by (case_tac a, auto split:if_splits dest:last_set_lt)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   613
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   614
lemma preced_unique : 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   615
  assumes pcd_eq: "preced th1 s = preced th2 s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   616
  and th_in1: "th1 \<in> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   617
  and th_in2: " th2 \<in> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   618
  shows "th1 = th2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   619
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   620
  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
   621
  from last_set_unique [OF this th_in1 th_in2]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   622
  show ?thesis .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   623
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   624
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   625
lemma preced_linorder: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   626
  assumes neq_12: "th1 \<noteq> th2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   627
  and th_in1: "th1 \<in> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   628
  and th_in2: " th2 \<in> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   629
  shows "preced th1 s < preced th2 s \<or> preced th1 s > preced th2 s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   630
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   631
  from preced_unique [OF _ th_in1 th_in2] and neq_12 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   632
  have "preced th1 s \<noteq> preced th2 s" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   633
  thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   634
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   635
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   636
(* An aux lemma used later *)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   637
lemma unique_minus:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   638
  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
   639
  and xy: "(x, y) \<in> r"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   640
  and xz: "(x, z) \<in> r^+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   641
  and neq: "y \<noteq> z"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   642
  shows "(y, z) \<in> r^+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   643
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   644
 from xz and neq show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   645
 proof(induct)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   646
   case (base ya)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   647
   have "(x, ya) \<in> r" by fact
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   648
   from unique [OF xy this] have "y = ya" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   649
   with base show ?case by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   650
 next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   651
   case (step ya z)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   652
   show ?case
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   653
   proof(cases "y = ya")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   654
     case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   655
     from step True show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   656
   next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   657
     case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   658
     from step False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   659
     show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   660
   qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   661
 qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   662
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   663
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   664
lemma unique_base:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   665
  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
   666
  and xy: "(x, y) \<in> r"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   667
  and xz: "(x, z) \<in> r^+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   668
  and neq_yz: "y \<noteq> z"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   669
  shows "(y, z) \<in> r^+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   670
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   671
  from xz neq_yz show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   672
  proof(induct)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   673
    case (base ya)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   674
    from xy unique base show ?case by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   675
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   676
    case (step ya z)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   677
    show ?case
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   678
    proof(cases "y = ya")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   679
      case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   680
      from True step show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   681
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   682
      case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   683
      from False step 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   684
      have "(y, ya) \<in> r\<^sup>+" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   685
      with step show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   686
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   687
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   688
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   689
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   690
lemma unique_chain:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   691
  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
   692
  and xy: "(x, y) \<in> r^+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   693
  and xz: "(x, z) \<in> r^+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   694
  and neq_yz: "y \<noteq> z"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   695
  shows "(y, z) \<in> r^+ \<or> (z, y) \<in> r^+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   696
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   697
  from xy xz neq_yz show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   698
  proof(induct)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   699
    case (base y)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   700
    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
   701
    from unique_base [OF _ h1 h2 h3] and unique show ?case by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   702
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   703
    case (step y za)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   704
    show ?case
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   705
    proof(cases "y = z")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   706
      case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   707
      from True step show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   708
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   709
      case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   710
      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
   711
      thus ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   712
      proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   713
        assume "(z, y) \<in> r\<^sup>+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   714
        with step have "(z, za) \<in> r\<^sup>+" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   715
        thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   716
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   717
        assume h: "(y, z) \<in> r\<^sup>+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   718
        from step have yza: "(y, za) \<in> r" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   719
        from step have "za \<noteq> z" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   720
        from unique_minus [OF _ yza h this] and unique
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   721
        have "(za, z) \<in> r\<^sup>+" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   722
        thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   723
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   724
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   725
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   726
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   727
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   728
text {*
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   729
  The following three lemmas show that @{text "RAG"} does not change
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   730
  by the happening of @{text "Set"}, @{text "Create"} and @{text "Exit"}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   731
  events, respectively.
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   732
*}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   733
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   734
lemma RAG_set_unchanged: "(RAG (Set th prio # s)) = RAG s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   735
apply (unfold s_RAG_def s_waiting_def wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   736
by (simp add:Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   737
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   738
lemma RAG_create_unchanged: "(RAG (Create th prio # s)) = RAG s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   739
apply (unfold s_RAG_def s_waiting_def wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   740
by (simp add:Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   741
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   742
lemma RAG_exit_unchanged: "(RAG (Exit th # s)) = RAG s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   743
apply (unfold s_RAG_def s_waiting_def wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   744
by (simp add:Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   745
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   746
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   747
text {* 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   748
  The following lemmas are used in the proof of 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   749
  lemma @{text "step_RAG_v"}, which characterizes how the @{text "RAG"} is changed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   750
  by @{text "V"}-events. 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   751
  However, since our model is very concise, such  seemingly obvious lemmas need to be derived from scratch,
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   752
  starting from the model definitions.
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   753
*}
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   754
lemma step_v_hold_inv[elim_format]:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   755
  "\<And>c t. \<lbrakk>vt (V th cs # s); 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   756
          \<not> holding (wq s) t c; holding (wq (V th cs # s)) t c\<rbrakk> \<Longrightarrow> 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   757
            next_th s th cs t \<and> c = cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   758
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   759
  fix c t
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   760
  assume vt: "vt (V th cs # s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   761
    and nhd: "\<not> holding (wq s) t c"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   762
    and hd: "holding (wq (V th cs # s)) t c"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   763
  show "next_th s th cs t \<and> c = cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   764
  proof(cases "c = cs")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   765
    case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   766
    with nhd hd show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   767
      by (unfold cs_holding_def wq_def, auto simp:Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   768
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   769
    case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   770
    with step_back_step [OF vt] 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   771
    have "step s (V th c)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   772
    hence "next_th s th cs t"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   773
    proof(cases)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   774
      assume "holding s th c"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   775
      with nhd hd show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   776
        apply (unfold s_holding_def cs_holding_def wq_def next_th_def,
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   777
               auto simp:Let_def split:list.splits if_splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   778
        proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   779
          assume " hd (SOME q. distinct q \<and> q = []) \<in> set (SOME q. distinct q \<and> q = [])"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   780
          moreover have "\<dots> = set []"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   781
          proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   782
            show "distinct [] \<and> [] = []" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   783
          next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   784
            fix x assume "distinct x \<and> x = []"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   785
            thus "set x = set []" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   786
          qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   787
          ultimately show False by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   788
        next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   789
          assume " hd (SOME q. distinct q \<and> q = []) \<in> set (SOME q. distinct q \<and> q = [])"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   790
          moreover have "\<dots> = set []"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   791
          proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   792
            show "distinct [] \<and> [] = []" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   793
          next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   794
            fix x assume "distinct x \<and> x = []"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   795
            thus "set x = set []" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   796
          qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   797
          ultimately show False by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   798
        qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   799
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   800
    with True show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   801
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   802
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   803
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   804
text {* 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   805
  The following @{text "step_v_wait_inv"} is also an obvious lemma, which, however, needs to be
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   806
  derived from scratch, which confirms the correctness of the definition of @{text "next_th"}.
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   807
*}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   808
lemma step_v_wait_inv[elim_format]:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   809
    "\<And>t c. \<lbrakk>vt (V th cs # s); \<not> waiting (wq (V th cs # s)) t c; waiting (wq s) t c
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   810
           \<rbrakk>
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   811
          \<Longrightarrow> (next_th s th cs t \<and> cs = c)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   812
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   813
  fix t c 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   814
  assume vt: "vt (V th cs # s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   815
    and nw: "\<not> waiting (wq (V th cs # s)) t c"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   816
    and wt: "waiting (wq s) t c"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   817
  from vt interpret vt_v: valid_trace_e s "V th cs" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   818
    by  (cases, unfold_locales, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   819
  show "next_th s th cs t \<and> cs = c"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   820
  proof(cases "cs = c")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   821
    case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   822
    with nw wt show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   823
      by (auto simp:cs_waiting_def wq_def Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   824
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   825
    case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   826
    from nw[folded True] wt[folded True]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   827
    have "next_th s th cs t"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   828
      apply (unfold next_th_def, auto simp:cs_waiting_def wq_def Let_def split:list.splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   829
    proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   830
      fix a list
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   831
      assume t_in: "t \<in> set list"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   832
        and t_ni: "t \<notin> set (SOME q. distinct q \<and> set q = set list)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   833
        and eq_wq: "wq_fun (schs s) cs = a # list"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   834
      have " set (SOME q. distinct q \<and> set q = set list) = set list"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   835
      proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   836
        from vt_v.wq_distinct[of cs] and eq_wq[folded wq_def]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   837
        show "distinct list \<and> set list = set list" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   838
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   839
        show "\<And>x. distinct x \<and> set x = set list \<Longrightarrow> set x = set list"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   840
          by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   841
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   842
      with t_ni and t_in show "a = th" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   843
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   844
      fix a list
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   845
      assume t_in: "t \<in> set list"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   846
        and t_ni: "t \<notin> set (SOME q. distinct q \<and> set q = set list)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   847
        and eq_wq: "wq_fun (schs s) cs = a # list"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   848
      have " set (SOME q. distinct q \<and> set q = set list) = set list"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   849
      proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   850
        from vt_v.wq_distinct[of cs] and eq_wq[folded wq_def]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   851
        show "distinct list \<and> set list = set list" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   852
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   853
        show "\<And>x. distinct x \<and> set x = set list \<Longrightarrow> set x = set list"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   854
          by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   855
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   856
      with t_ni and t_in show "t = hd (SOME q. distinct q \<and> set q = set list)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   857
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   858
      fix a list
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   859
      assume eq_wq: "wq_fun (schs s) cs = a # list"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   860
      from step_back_step[OF vt]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   861
      show "a = th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   862
      proof(cases)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   863
        assume "holding s th cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   864
        with eq_wq show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   865
          by (unfold s_holding_def wq_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   866
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   867
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   868
    with True show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   869
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   870
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   871
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   872
lemma step_v_not_wait[consumes 3]:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   873
  "\<lbrakk>vt (V th cs # s); next_th s th cs t; waiting (wq (V th cs # s)) t cs\<rbrakk> \<Longrightarrow> False"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   874
  by (unfold next_th_def cs_waiting_def wq_def, auto simp:Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   875
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   876
lemma step_v_release:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   877
  "\<lbrakk>vt (V th cs # s); holding (wq (V th cs # s)) th cs\<rbrakk> \<Longrightarrow> False"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   878
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   879
  assume vt: "vt (V th cs # s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   880
    and hd: "holding (wq (V th cs # s)) th cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   881
  from vt interpret vt_v: valid_trace_e s "V th cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   882
    by (cases, unfold_locales, simp+)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   883
  from step_back_step [OF vt] and hd
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   884
  show "False"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   885
  proof(cases)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   886
    assume "holding (wq (V th cs # s)) th cs" and "holding s th cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   887
    thus ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   888
      apply (unfold s_holding_def wq_def cs_holding_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   889
      apply (auto simp:Let_def split:list.splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   890
    proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   891
      fix list
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   892
      assume eq_wq[folded wq_def]: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   893
        "wq_fun (schs s) cs = hd (SOME q. distinct q \<and> set q = set list) # list"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   894
      and hd_in: "hd (SOME q. distinct q \<and> set q = set list)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   895
            \<in> set (SOME q. distinct q \<and> set q = set list)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   896
      have "set (SOME q. distinct q \<and> set q = set list) = set list"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   897
      proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   898
        from vt_v.wq_distinct[of cs] and eq_wq
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   899
        show "distinct list \<and> set list = set list" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   900
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   901
        show "\<And>x. distinct x \<and> set x = set list \<Longrightarrow> set x = set list"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   902
          by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   903
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   904
      moreover have "distinct  (hd (SOME q. distinct q \<and> set q = set list) # list)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   905
      proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   906
        from vt_v.wq_distinct[of cs] and eq_wq
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   907
        show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   908
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   909
      moreover note eq_wq and hd_in
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   910
      ultimately show "False" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   911
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   912
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   913
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   914
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   915
lemma step_v_get_hold:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   916
  "\<And>th'. \<lbrakk>vt (V th cs # s); \<not> holding (wq (V th cs # s)) th' cs; next_th s th cs th'\<rbrakk> \<Longrightarrow> False"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   917
  apply (unfold cs_holding_def next_th_def wq_def,
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   918
         auto simp:Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   919
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   920
  fix rest
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   921
  assume vt: "vt (V th cs # s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   922
    and eq_wq[folded wq_def]: " wq_fun (schs s) cs = th # rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   923
    and nrest: "rest \<noteq> []"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   924
    and ni: "hd (SOME q. distinct q \<and> set q = set rest)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   925
            \<notin> set (SOME q. distinct q \<and> set q = set rest)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   926
  from vt interpret vt_v: valid_trace_e s "V th cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   927
    by (cases, unfold_locales, simp+)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   928
  have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   929
  proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   930
    from vt_v.wq_distinct[of cs] and eq_wq
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   931
    show "distinct rest \<and> set rest = set rest" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   932
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   933
    fix x assume "distinct x \<and> set x = set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   934
    hence "set x = set rest" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   935
    with nrest
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   936
    show "x \<noteq> []" by (case_tac x, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   937
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   938
  with ni show "False" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   939
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   940
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   941
lemma step_v_release_inv[elim_format]:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   942
"\<And>c t. \<lbrakk>vt (V th cs # s); \<not> holding (wq (V th cs # s)) t c; holding (wq s) t c\<rbrakk> \<Longrightarrow> 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   943
  c = cs \<and> t = th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   944
  apply (unfold cs_holding_def wq_def, auto simp:Let_def split:if_splits list.splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   945
  proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   946
    fix a list
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   947
    assume vt: "vt (V th cs # s)" and eq_wq: "wq_fun (schs s) cs = a # list"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   948
    from step_back_step [OF vt] show "a = th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   949
    proof(cases)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   950
      assume "holding s th cs" with eq_wq
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   951
      show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   952
        by (unfold s_holding_def wq_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   953
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   954
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   955
    fix a list
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   956
    assume vt: "vt (V th cs # s)" and eq_wq: "wq_fun (schs s) cs = a # list"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   957
    from step_back_step [OF vt] show "a = th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   958
    proof(cases)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   959
      assume "holding s th cs" with eq_wq
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   960
      show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   961
        by (unfold s_holding_def wq_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   962
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   963
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   964
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   965
lemma step_v_waiting_mono:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   966
  "\<And>t c. \<lbrakk>vt (V th cs # s); waiting (wq (V th cs # s)) t c\<rbrakk> \<Longrightarrow> waiting (wq s) t c"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   967
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   968
  fix t c
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   969
  let ?s' = "(V th cs # s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   970
  assume vt: "vt ?s'" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   971
    and wt: "waiting (wq ?s') t c"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   972
  from vt interpret vt_v: valid_trace_e s "V th cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   973
    by (cases, unfold_locales, simp+)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   974
  show "waiting (wq s) t c"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   975
  proof(cases "c = cs")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   976
    case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   977
    assume neq_cs: "c \<noteq> cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   978
    hence "waiting (wq ?s') t c = waiting (wq s) t c"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   979
      by (unfold cs_waiting_def wq_def, auto simp:Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   980
    with wt show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   981
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   982
    case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   983
    with wt show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   984
      apply (unfold cs_waiting_def wq_def, auto simp:Let_def split:list.splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   985
    proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   986
      fix a list
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   987
      assume not_in: "t \<notin> set list"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   988
        and is_in: "t \<in> set (SOME q. distinct q \<and> set q = set list)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   989
        and eq_wq: "wq_fun (schs s) cs = a # list"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   990
      have "set (SOME q. distinct q \<and> set q = set list) = set list"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   991
      proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   992
        from vt_v.wq_distinct [of cs]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   993
        and eq_wq[folded wq_def]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   994
        show "distinct list \<and> set list = set list" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   995
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   996
        fix x assume "distinct x \<and> set x = set list"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   997
        thus "set x = set list" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   998
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
   999
      with not_in is_in show "t = a" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1000
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1001
      fix list
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1002
      assume is_waiting: "waiting (wq (V th cs # s)) t cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1003
      and eq_wq: "wq_fun (schs s) cs = t # list"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1004
      hence "t \<in> set list"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1005
        apply (unfold wq_def, auto simp:Let_def cs_waiting_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1006
      proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1007
        assume " t \<in> set (SOME q. distinct q \<and> set q = set list)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1008
        moreover have "\<dots> = set list" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1009
        proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1010
          from vt_v.wq_distinct [of cs]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1011
            and eq_wq[folded wq_def]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1012
          show "distinct list \<and> set list = set list" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1013
        next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1014
          fix x assume "distinct x \<and> set x = set list" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1015
          thus "set x = set list" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1016
        qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1017
        ultimately show "t \<in> set list" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1018
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1019
      with eq_wq and vt_v.wq_distinct [of cs, unfolded wq_def]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1020
      show False by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1021
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1022
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1023
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1024
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1025
text {* (* ddd *) 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1026
  The following @{text "step_RAG_v"} lemma charaterizes how @{text "RAG"} is changed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1027
  with the happening of @{text "V"}-events:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1028
*}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1029
lemma step_RAG_v:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1030
assumes vt:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1031
  "vt (V th cs#s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1032
shows "
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1033
  RAG (V th cs # s) =
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1034
  RAG s - {(Cs cs, Th th)} -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1035
  {(Th th', Cs cs) |th'. next_th s th cs th'} \<union>
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1036
  {(Cs cs, Th th') |th'.  next_th s th cs th'}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1037
  apply (insert vt, unfold s_RAG_def) 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1038
  apply (auto split:if_splits list.splits simp:Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1039
  apply (auto elim: step_v_waiting_mono step_v_hold_inv 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1040
              step_v_release step_v_wait_inv
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1041
              step_v_get_hold step_v_release_inv)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1042
  apply (erule_tac step_v_not_wait, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1043
  done
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1044
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1045
text {* 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1046
  The following @{text "step_RAG_p"} lemma charaterizes how @{text "RAG"} is changed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1047
  with the happening of @{text "P"}-events:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1048
*}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1049
lemma step_RAG_p:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1050
  "vt (P th cs#s) \<Longrightarrow>
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1051
  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
  1052
                                             else RAG s \<union> {(Th th, Cs cs)})"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1053
  apply(simp only: s_RAG_def wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1054
  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
  1055
  apply(case_tac "csa = cs", auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1056
  apply(fold wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1057
  apply(drule_tac step_back_step)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1058
  apply(ind_cases " step s (P (hd (wq s cs)) cs)")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1059
  apply(simp add:s_RAG_def wq_def cs_holding_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1060
  apply(auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1061
  done
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1062
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1063
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1064
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
  1065
  by (unfold s_RAG_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1066
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1067
context valid_trace
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1068
begin
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1069
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1070
text {*
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1071
  The following lemma shows that @{text "RAG"} is acyclic.
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1072
  The overall structure is by induction on the formation of @{text "vt s"}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1073
  and then case analysis on event @{text "e"}, where the non-trivial cases 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1074
  for those for @{text "V"} and @{text "P"} events.
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1075
*}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1076
lemma acyclic_RAG:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1077
  shows "acyclic (RAG s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1078
using vt
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1079
proof(induct)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1080
  case (vt_cons s e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1081
  interpret vt_s: valid_trace s using vt_cons(1)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1082
    by (unfold_locales, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1083
  assume ih: "acyclic (RAG s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1084
    and stp: "step s e"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1085
    and vt: "vt s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1086
  show ?case
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1087
  proof(cases e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1088
    case (Create th prio)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1089
    with ih
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1090
    show ?thesis by (simp add:RAG_create_unchanged)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1091
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1092
    case (Exit th)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1093
    with ih show ?thesis by (simp add:RAG_exit_unchanged)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1094
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1095
    case (V th cs)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1096
    from V vt stp have vtt: "vt (V th cs#s)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1097
    from step_RAG_v [OF this]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1098
    have eq_de: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1099
      "RAG (e # s) = 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1100
      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
  1101
      {(Cs cs, Th th') |th'. next_th s th cs th'}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1102
      (is "?L = (?A - ?B - ?C) \<union> ?D") by (simp add:V)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1103
    from ih have ac: "acyclic (?A - ?B - ?C)" by (auto elim:acyclic_subset)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1104
    from step_back_step [OF vtt]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1105
    have "step s (V th cs)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1106
    thus ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1107
    proof(cases)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1108
      assume "holding s th cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1109
      hence th_in: "th \<in> set (wq s cs)" and
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1110
        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
  1111
      then obtain rest where
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1112
        eq_wq: "wq s cs = th#rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1113
        by (cases "wq s cs", auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1114
      show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1115
      proof(cases "rest = []")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1116
        case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1117
        let ?th' = "hd (SOME q. distinct q \<and> set q = set rest)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1118
        from eq_wq False have eq_D: "?D = {(Cs cs, Th ?th')}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1119
          by (unfold next_th_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1120
        let ?E = "(?A - ?B - ?C)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1121
        have "(Th ?th', Cs cs) \<notin> ?E\<^sup>*"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1122
        proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1123
          assume "(Th ?th', Cs cs) \<in> ?E\<^sup>*"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1124
          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
  1125
          from tranclD [OF this]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1126
          obtain x where th'_e: "(Th ?th', x) \<in> ?E" by blast
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1127
          hence th_d: "(Th ?th', x) \<in> ?A" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1128
          from RAG_target_th [OF this]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1129
          obtain cs' where eq_x: "x = Cs cs'" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1130
          with th_d have "(Th ?th', Cs cs') \<in> ?A" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1131
          hence wt_th': "waiting s ?th' cs'"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1132
            unfolding s_RAG_def s_waiting_def cs_waiting_def wq_def by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1133
          hence "cs' = cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1134
          proof(rule vt_s.waiting_unique)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1135
            from eq_wq vt_s.wq_distinct[of cs]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1136
            show "waiting s ?th' cs" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1137
              apply (unfold s_waiting_def wq_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1138
            proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1139
              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
  1140
                and eq_wq: "wq_fun (schs s) cs = th # rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1141
              have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1142
              proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1143
                from vt_s.wq_distinct[of cs] and eq_wq
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1144
                show "distinct rest \<and> set rest = set rest" unfolding wq_def by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1145
              next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1146
                fix x assume "distinct x \<and> set x = set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1147
                with False show "x \<noteq> []" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1148
              qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1149
              hence "hd (SOME q. distinct q \<and> set q = set rest) \<in> 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1150
                set (SOME q. distinct q \<and> set q = set rest)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1151
              moreover have "\<dots> = set rest" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1152
              proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1153
                from vt_s.wq_distinct[of cs] and eq_wq
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1154
                show "distinct rest \<and> set rest = set rest" unfolding wq_def by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1155
              next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1156
                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
  1157
              qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1158
              moreover note hd_in
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1159
              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
  1160
            next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1161
              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
  1162
                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
  1163
              have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1164
              proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1165
                from vt_s.wq_distinct[of cs] and eq_wq
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1166
                show "distinct rest \<and> set rest = set rest" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1167
              next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1168
                fix x assume "distinct x \<and> set x = set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1169
                with False show "x \<noteq> []" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1170
              qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1171
              hence "hd (SOME q. distinct q \<and> set q = set rest) \<in> 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1172
                set (SOME q. distinct q \<and> set q = set rest)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1173
              moreover have "\<dots> = set rest" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1174
              proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1175
                from vt_s.wq_distinct[of cs] and eq_wq
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1176
                show "distinct rest \<and> set rest = set rest" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1177
              next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1178
                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
  1179
              qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1180
              moreover note hd_in
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1181
              ultimately show False by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1182
            qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1183
          qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1184
          with th'_e eq_x have "(Th ?th', Cs cs) \<in> ?E" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1185
          with False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1186
          show "False" by (auto simp: next_th_def eq_wq)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1187
        qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1188
        with acyclic_insert[symmetric] and ac
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1189
          and eq_de eq_D show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1190
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1191
        case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1192
        with eq_wq
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1193
        have eq_D: "?D = {}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1194
          by (unfold next_th_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1195
        with eq_de ac
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1196
        show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1197
      qed 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1198
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1199
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1200
    case (P th cs)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1201
    from P vt stp have vtt: "vt (P th cs#s)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1202
    from step_RAG_p [OF this] P
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1203
    have "RAG (e # s) = 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1204
      (if wq s cs = [] then RAG s \<union> {(Cs cs, Th th)} else 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1205
      RAG s \<union> {(Th th, Cs cs)})" (is "?L = ?R")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1206
      by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1207
    moreover have "acyclic ?R"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1208
    proof(cases "wq s cs = []")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1209
      case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1210
      hence eq_r: "?R =  RAG s \<union> {(Cs cs, Th th)}" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1211
      have "(Th th, Cs cs) \<notin> (RAG s)\<^sup>*"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1212
      proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1213
        assume "(Th th, Cs cs) \<in> (RAG s)\<^sup>*"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1214
        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
  1215
        from tranclD2 [OF this]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1216
        obtain x where "(x, Cs cs) \<in> RAG s" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1217
        with True show False by (auto simp:s_RAG_def cs_waiting_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1218
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1219
      with acyclic_insert ih eq_r show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1220
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1221
      case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1222
      hence eq_r: "?R =  RAG s \<union> {(Th th, Cs cs)}" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1223
      have "(Cs cs, Th th) \<notin> (RAG s)\<^sup>*"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1224
      proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1225
        assume "(Cs cs, Th th) \<in> (RAG s)\<^sup>*"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1226
        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
  1227
        moreover from step_back_step [OF vtt] have "step s (P th cs)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1228
        ultimately show False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1229
        proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1230
          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
  1231
            by (ind_cases "step s (P th cs)", simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1232
        qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1233
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1234
      with acyclic_insert ih eq_r show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1235
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1236
      ultimately show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1237
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1238
      case (Set thread prio)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1239
      with ih
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1240
      thm RAG_set_unchanged
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1241
      show ?thesis by (simp add:RAG_set_unchanged)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1242
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1243
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1244
    case vt_nil
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1245
    show "acyclic (RAG ([]::state))"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1246
      by (auto simp: s_RAG_def cs_waiting_def 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1247
        cs_holding_def wq_def acyclic_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1248
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1249
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1250
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1251
lemma finite_RAG:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1252
  shows "finite (RAG s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1253
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1254
  from vt show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1255
  proof(induct)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1256
    case (vt_cons s e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1257
    interpret vt_s: valid_trace s using vt_cons(1)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1258
      by (unfold_locales, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1259
    assume ih: "finite (RAG s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1260
      and stp: "step s e"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1261
      and vt: "vt s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1262
    show ?case
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1263
    proof(cases e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1264
      case (Create th prio)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1265
      with ih
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1266
      show ?thesis by (simp add:RAG_create_unchanged)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1267
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1268
      case (Exit th)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1269
      with ih show ?thesis by (simp add:RAG_exit_unchanged)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1270
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1271
      case (V th cs)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1272
      from V vt stp have vtt: "vt (V th cs#s)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1273
      from step_RAG_v [OF this]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1274
      have eq_de: "RAG (e # s) = 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1275
                   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
  1276
                      {(Cs cs, Th th') |th'. next_th s th cs th'}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1277
"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1278
        (is "?L = (?A - ?B - ?C) \<union> ?D") by (simp add:V)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1279
      moreover from ih have ac: "finite (?A - ?B - ?C)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1280
      moreover have "finite ?D"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1281
      proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1282
        have "?D = {} \<or> (\<exists> a. ?D = {a})" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1283
          by (unfold next_th_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1284
        thus ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1285
        proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1286
          assume h: "?D = {}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1287
          show ?thesis by (unfold h, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1288
        next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1289
          assume "\<exists> a. ?D = {a}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1290
          thus ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1291
            by (metis finite.simps)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1292
        qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1293
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1294
      ultimately show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1295
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1296
      case (P th cs)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1297
      from P vt stp have vtt: "vt (P th cs#s)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1298
      from step_RAG_p [OF this] P
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1299
      have "RAG (e # s) = 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1300
              (if wq s cs = [] then RAG s \<union> {(Cs cs, Th th)} else 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1301
                                    RAG s \<union> {(Th th, Cs cs)})" (is "?L = ?R")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1302
        by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1303
      moreover have "finite ?R"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1304
      proof(cases "wq s cs = []")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1305
        case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1306
        hence eq_r: "?R =  RAG s \<union> {(Cs cs, Th th)}" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1307
        with True and ih show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1308
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1309
        case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1310
        hence "?R = RAG s \<union> {(Th th, Cs cs)}" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1311
        with False and ih show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1312
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1313
      ultimately show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1314
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1315
      case (Set thread prio)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1316
      with ih
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1317
      show ?thesis by (simp add:RAG_set_unchanged)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1318
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1319
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1320
    case vt_nil
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1321
    show "finite (RAG ([]::state))"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1322
      by (auto simp: s_RAG_def cs_waiting_def 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1323
                   cs_holding_def wq_def acyclic_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1324
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1325
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1326
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1327
text {* Several useful lemmas *}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1328
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1329
lemma wf_dep_converse: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1330
  shows "wf ((RAG s)^-1)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1331
proof(rule finite_acyclic_wf_converse)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1332
  from finite_RAG 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1333
  show "finite (RAG s)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1334
next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1335
  from acyclic_RAG
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1336
  show "acyclic (RAG s)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1337
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1338
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1339
end
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1340
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1341
lemma hd_np_in: "x \<in> set l \<Longrightarrow> hd l \<in> set l"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1342
  by (induct l, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1343
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1344
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
  1345
  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
  1346
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1347
context valid_trace
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1348
begin
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1349
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1350
lemma wq_threads: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1351
  assumes h: "th \<in> set (wq s cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1352
  shows "th \<in> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1353
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1354
 from vt and h show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1355
  proof(induct arbitrary: th cs)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1356
    case (vt_cons s e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1357
    interpret vt_s: valid_trace s
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1358
      using vt_cons(1) by (unfold_locales, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1359
    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
  1360
      and stp: "step s e"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1361
      and vt: "vt s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1362
      and h: "th \<in> set (wq (e # s) cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1363
    show ?case
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1364
    proof(cases e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1365
      case (Create th' prio)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1366
      with ih h show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1367
        by (auto simp:wq_def Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1368
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1369
      case (Exit th')
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1370
      with stp ih h show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1371
        apply (auto simp:wq_def Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1372
        apply (ind_cases "step s (Exit th')")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1373
        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
  1374
               s_RAG_def s_holding_def cs_holding_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1375
        done
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1376
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1377
      case (V th' cs')
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1378
      show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1379
      proof(cases "cs' = cs")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1380
        case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1381
        with h
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1382
        show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1383
          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
  1384
          by (drule_tac ih, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1385
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1386
        case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1387
        from h
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1388
        show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1389
        proof(unfold V wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1390
          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
  1391
          show "th \<in> threads (V th' cs' # s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1392
          proof(cases "cs = cs'")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1393
            case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1394
            hence "?l = wq_fun (schs s) cs" by (simp add:Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1395
            with th_in have " th \<in> set (wq s cs)" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1396
              by (fold wq_def, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1397
            from ih [OF this] show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1398
          next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1399
            case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1400
            show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1401
            proof(cases "wq_fun (schs s) cs'")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1402
              case Nil
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1403
              with h V show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1404
                apply (auto simp:wq_def Let_def split:if_splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1405
                by (fold wq_def, drule_tac ih, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1406
            next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1407
              case (Cons a rest)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1408
              assume eq_wq: "wq_fun (schs s) cs' = a # rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1409
              with h V show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1410
                apply (auto simp:Let_def wq_def split:if_splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1411
              proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1412
                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
  1413
                have "set (SOME q. distinct q \<and> set q = set rest) = set rest" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1414
                proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1415
                  from vt_s.wq_distinct[of cs'] and eq_wq[folded wq_def]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1416
                  show "distinct rest \<and> set rest = set rest" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1417
                next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1418
                  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
  1419
                    by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1420
                qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1421
                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
  1422
                from ih[OF this[folded wq_def]] show "th \<in> threads s" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1423
              next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1424
                assume th_in: "th \<in> set (wq_fun (schs s) cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1425
                from ih[OF this[folded wq_def]]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1426
                show "th \<in> threads s" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1427
              qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1428
            qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1429
          qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1430
        qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1431
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1432
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1433
      case (P th' cs')
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1434
      from h stp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1435
      show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1436
        apply (unfold P wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1437
        apply (auto simp:Let_def split:if_splits, fold wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1438
        apply (auto intro:ih)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1439
        apply(ind_cases "step s (P th' cs')")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1440
        by (unfold runing_def readys_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1441
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1442
      case (Set thread prio)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1443
      with ih h show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1444
        by (auto simp:wq_def Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1445
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1446
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1447
    case vt_nil
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1448
    thus ?case by (auto simp:wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1449
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1450
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1451
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1452
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
  1453
  apply(unfold s_RAG_def cs_waiting_def cs_holding_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1454
  by (auto intro:wq_threads)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1455
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1456
lemma readys_v_eq:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1457
  assumes neq_th: "th \<noteq> thread"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1458
  and eq_wq: "wq s cs = thread#rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1459
  and not_in: "th \<notin>  set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1460
  shows "(th \<in> readys (V thread cs#s)) = (th \<in> readys s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1461
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1462
  from assms show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1463
    apply (auto simp:readys_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1464
    apply(simp add:s_waiting_def[folded wq_def])
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1465
    apply (erule_tac x = csa in allE)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1466
    apply (simp add:s_waiting_def wq_def Let_def split:if_splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1467
    apply (case_tac "csa = cs", simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1468
    apply (erule_tac x = cs in allE)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1469
    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
  1470
    apply(auto simp add: wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1471
    apply (auto simp:s_waiting_def wq_def Let_def split:list.splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1472
    proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1473
       assume th_nin: "th \<notin> set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1474
        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
  1475
        and eq_wq: "wq_fun (schs s) cs = thread # rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1476
      have "set (SOME q. distinct q \<and> set q = set rest) = set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1477
      proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1478
        from wq_distinct[of cs, unfolded wq_def] and eq_wq[unfolded wq_def]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1479
        show "distinct rest \<and> set rest = set rest" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1480
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1481
        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
  1482
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1483
      with th_nin th_in show False by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1484
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1485
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1486
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1487
text {* \noindent
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1488
  The following lemmas shows that: starting from any node in @{text "RAG"}, 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1489
  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
  1490
  thread. In this lemma, it is the @{text "th'"}.
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1491
*}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1492
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1493
lemma chain_building:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1494
  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
  1495
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1496
  from wf_dep_converse
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1497
  have h: "wf ((RAG s)\<inverse>)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1498
  show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1499
  proof(induct rule:wf_induct [OF h])
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1500
    fix x
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1501
    assume ih [rule_format]: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1502
      "\<forall>y. (y, x) \<in> (RAG s)\<inverse> \<longrightarrow> 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1503
           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
  1504
    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
  1505
    proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1506
      assume x_d: "x \<in> Domain (RAG s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1507
      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
  1508
      proof(cases x)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1509
        case (Th th)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1510
        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
  1511
        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
  1512
        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
  1513
        hence "Cs cs \<in> Domain (RAG s)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1514
        from ih [OF x_in_r this] obtain th'
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1515
          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
  1516
        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
  1517
        with th'_ready show ?thesis 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
        case (Cs cs)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1520
        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
  1521
        show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1522
        proof(cases "th' \<in> readys s")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1523
          case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1524
          from True and th'_d show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1525
        next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1526
          case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1527
          from th'_d and range_in  have "th' \<in> threads s" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1528
          with False have "Th th' \<in> Domain (RAG s)" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1529
            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
  1530
          from ih [OF th'_d this]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1531
          obtain th'' where 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1532
            th''_r: "th'' \<in> readys s" and 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1533
            th''_in: "(Th th', Th th'') \<in> (RAG s)\<^sup>+" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1534
          from th'_d and th''_in 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1535
          have "(x, Th th'') \<in> (RAG s)\<^sup>+" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1536
          with th''_r show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1537
        qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1538
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1539
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1540
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1541
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1542
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1543
text {* \noindent
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1544
  The following is just an instance of @{text "chain_building"}.
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1545
*}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1546
lemma th_chain_to_ready:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1547
  assumes th_in: "th \<in> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1548
  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
  1549
proof(cases "th \<in> readys s")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1550
  case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1551
  thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1552
next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1553
  case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1554
  from False and th_in have "Th th \<in> Domain (RAG s)" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1555
    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
  1556
  from chain_building [rule_format, OF this]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1557
  show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1558
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1559
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1560
end
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1561
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1562
lemma waiting_eq: "waiting s th cs = waiting (wq s) th cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1563
  by  (unfold s_waiting_def cs_waiting_def wq_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1564
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1565
lemma holding_eq: "holding (s::state) th cs = holding (wq s) th cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1566
  by (unfold s_holding_def wq_def cs_holding_def, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1567
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1568
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
  1569
  by (unfold s_holding_def cs_holding_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1570
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1571
context valid_trace
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1572
begin
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1573
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1574
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
  1575
  apply(unfold s_RAG_def, auto, fold waiting_eq holding_eq)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1576
  by(auto elim:waiting_unique holding_unique)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1577
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1578
end
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1579
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1580
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1581
lemma trancl_split: "(a, b) \<in> r^+ \<Longrightarrow> \<exists> c. (a, c) \<in> r"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1582
by (induct rule:trancl_induct, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1583
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1584
context valid_trace
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1585
begin
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1586
73
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1587
lemma dchain_unique:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1588
  assumes th1_d: "(n, Th th1) \<in> (RAG s)^+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1589
  and th1_r: "th1 \<in> readys s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1590
  and th2_d: "(n, Th th2) \<in> (RAG s)^+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1591
  and th2_r: "th2 \<in> readys s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1592
  shows "th1 = th2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1593
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1594
  { assume neq: "th1 \<noteq> th2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1595
    hence "Th th1 \<noteq> Th th2" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1596
    from unique_chain [OF _ th1_d th2_d this] and unique_RAG 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1597
    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
  1598
    hence "False"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1599
    proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1600
      assume "(Th th1, Th th2) \<in> (RAG s)\<^sup>+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1601
      from trancl_split [OF this]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1602
      obtain n where dd: "(Th th1, n) \<in> RAG s" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1603
      then obtain cs where eq_n: "n = Cs cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1604
        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
  1605
      from dd eq_n have "th1 \<notin> readys s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1606
        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
  1607
      with th1_r show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1608
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1609
      assume "(Th th2, Th th1) \<in> (RAG s)\<^sup>+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1610
      from trancl_split [OF this]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1611
      obtain n where dd: "(Th th2, n) \<in> RAG s" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1612
      then obtain cs where eq_n: "n = Cs cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1613
        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
  1614
      from dd eq_n have "th2 \<notin> readys s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1615
        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
  1616
      with th2_r show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1617
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1618
  } thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1619
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1620
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1621
end
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1622
             
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1623
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1624
lemma step_holdents_p_add:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1625
  assumes vt: "vt (P th cs#s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1626
  and "wq s cs = []"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1627
  shows "holdents (P th cs#s) th = holdents s th \<union> {cs}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1628
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1629
  from assms show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1630
  unfolding  holdents_test step_RAG_p[OF vt] by (auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1631
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1632
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1633
lemma step_holdents_p_eq:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1634
  assumes vt: "vt (P th cs#s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1635
  and "wq s cs \<noteq> []"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1636
  shows "holdents (P th cs#s) th = holdents s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1637
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1638
  from assms show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1639
  unfolding  holdents_test step_RAG_p[OF vt] by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1640
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1641
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1642
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1643
lemma (in valid_trace) finite_holding :
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1644
  shows "finite (holdents s th)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1645
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1646
  let ?F = "\<lambda> (x, y). the_cs x"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1647
  from finite_RAG 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1648
  have "finite (RAG s)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1649
  hence "finite (?F `(RAG s))" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1650
  moreover have "{cs . (Cs cs, Th th) \<in> RAG s} \<subseteq> \<dots>" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1651
  proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1652
    { 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
  1653
      fix x assume "(Cs x, Th th) \<in> RAG s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1654
      hence "?F (Cs x, Th th) \<in> ?F `(RAG s)" by (rule h)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1655
      moreover have "?F (Cs x, Th th) = x" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1656
      ultimately have "x \<in> (\<lambda>(x, y). the_cs x) ` RAG s" by simp 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1657
    } thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1658
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1659
  ultimately show ?thesis by (unfold holdents_test, auto intro:finite_subset)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1660
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1661
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1662
lemma cntCS_v_dec: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1663
  assumes vtv: "vt (V thread cs#s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1664
  shows "(cntCS (V thread cs#s) thread + 1) = cntCS s thread"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1665
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1666
  from vtv interpret vt_s: valid_trace s
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1667
    by (cases, unfold_locales, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1668
  from vtv interpret vt_v: valid_trace "V thread cs#s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1669
     by (unfold_locales, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1670
  from step_back_step[OF vtv]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1671
  have cs_in: "cs \<in> holdents s thread" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1672
    apply (cases, unfold holdents_test s_RAG_def, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1673
    by (unfold cs_holding_def s_holding_def wq_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1674
  moreover have cs_not_in: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1675
    "(holdents (V thread cs#s) thread) = holdents s thread - {cs}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1676
    apply (insert vt_s.wq_distinct[of cs])
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1677
    apply (unfold holdents_test, unfold step_RAG_v[OF vtv],
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1678
            auto simp:next_th_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1679
  proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1680
    fix rest
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1681
    assume dst: "distinct (rest::thread list)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1682
      and ne: "rest \<noteq> []"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1683
    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
  1684
    moreover have "set (SOME q. distinct q \<and> set q = set rest) = set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1685
    proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1686
      from dst show "distinct rest \<and> set rest = set rest" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1687
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1688
      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
  1689
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1690
    ultimately have "hd (SOME q. distinct q \<and> set q = set rest) \<notin> 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1691
                     set (SOME q. distinct q \<and> set q = set rest)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1692
    moreover have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1693
    proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1694
      from dst show "distinct rest \<and> set rest = set rest" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1695
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1696
      fix x assume " distinct x \<and> set x = set rest" with ne
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1697
      show "x \<noteq> []" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1698
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1699
    ultimately 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1700
    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
  1701
      by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1702
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1703
    fix rest
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1704
    assume dst: "distinct (rest::thread list)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1705
      and ne: "rest \<noteq> []"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1706
    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
  1707
    moreover have "set (SOME q. distinct q \<and> set q = set rest) = set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1708
    proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1709
      from dst show "distinct rest \<and> set rest = set rest" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1710
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1711
      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
  1712
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1713
    ultimately have "hd (SOME q. distinct q \<and> set q = set rest) \<notin> 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1714
                     set (SOME q. distinct q \<and> set q = set rest)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1715
    moreover have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1716
    proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1717
      from dst show "distinct rest \<and> set rest = set rest" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1718
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1719
      fix x assume " distinct x \<and> set x = set rest" with ne
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1720
      show "x \<noteq> []" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1721
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1722
    ultimately show "False" by auto 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1723
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1724
  ultimately 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1725
  have "holdents s thread = insert cs (holdents (V thread cs#s) thread)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1726
    by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1727
  moreover have "card \<dots> = 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1728
                    Suc (card ((holdents (V thread cs#s) thread) - {cs}))"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1729
  proof(rule card_insert)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1730
    from vt_v.finite_holding
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1731
    show " finite (holdents (V thread cs # s) thread)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1732
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1733
  moreover from cs_not_in 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1734
  have "cs \<notin> (holdents (V thread cs#s) thread)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1735
  ultimately show ?thesis by (simp add:cntCS_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1736
qed 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1737
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1738
lemma count_rec1 [simp]: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1739
  assumes "Q e"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1740
  shows "count Q (e#es) = Suc (count Q es)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1741
  using assms
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1742
  by (unfold count_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1743
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1744
lemma count_rec2 [simp]: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1745
  assumes "\<not>Q e"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1746
  shows "count Q (e#es) = (count Q es)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1747
  using assms
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1748
  by (unfold count_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1749
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1750
lemma count_rec3 [simp]: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1751
  shows "count Q [] =  0"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1752
  by (unfold count_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1753
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1754
lemma cntP_diff_inv:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1755
  assumes "cntP (e#s) th \<noteq> cntP s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1756
  shows "isP e \<and> actor e = th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1757
proof(cases e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1758
  case (P th' pty)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1759
  show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1760
  by (cases "(\<lambda>e. \<exists>cs. e = P th cs) (P th' pty)", 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1761
        insert assms P, auto simp:cntP_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1762
qed (insert assms, auto simp:cntP_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1763
  
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1764
lemma cntV_diff_inv:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1765
  assumes "cntV (e#s) th \<noteq> cntV s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1766
  shows "isV e \<and> actor e = th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1767
proof(cases e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1768
  case (V th' pty)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1769
  show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1770
  by (cases "(\<lambda>e. \<exists>cs. e = V th cs) (V th' pty)", 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1771
        insert assms V, auto simp:cntV_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1772
qed (insert assms, auto simp:cntV_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1773
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1774
context valid_trace
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1775
begin
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1776
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1777
text {* (* ddd *) \noindent
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1778
  The relationship between @{text "cntP"}, @{text "cntV"} and @{text "cntCS"} 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1779
  of one particular thread. 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1780
*} 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1781
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1782
lemma cnp_cnv_cncs:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1783
  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
  1784
                                       then cntCS s th else cntCS s th + 1)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1785
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1786
  from vt show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1787
  proof(induct arbitrary:th)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1788
    case (vt_cons s e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1789
    interpret vt_s: valid_trace s using vt_cons(1) by (unfold_locales, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1790
    assume vt: "vt s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1791
    and ih: "\<And>th. cntP s th  = cntV s th +
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1792
               (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
  1793
    and stp: "step s e"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1794
    from stp show ?case
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1795
    proof(cases)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1796
      case (thread_create thread prio)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1797
      assume eq_e: "e = Create thread prio"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1798
        and not_in: "thread \<notin> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1799
      show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1800
      proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1801
        { fix cs 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1802
          assume "thread \<in> set (wq s cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1803
          from vt_s.wq_threads [OF this] have "thread \<in> threads s" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1804
          with not_in have "False" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1805
        } with eq_e have eq_readys: "readys (e#s) = readys s \<union> {thread}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1806
          by (auto simp:readys_def threads.simps s_waiting_def 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1807
            wq_def cs_waiting_def Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1808
        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
  1809
        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
  1810
        have eq_cncs: "cntCS (e#s) th = cntCS s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1811
          unfolding cntCS_def holdents_test
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1812
          by (simp add:RAG_create_unchanged eq_e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1813
        { assume "th \<noteq> thread"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1814
          with eq_readys eq_e
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1815
          have "(th \<in> readys (e # s) \<or> th \<notin> threads (e # s)) = 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1816
                      (th \<in> readys (s) \<or> th \<notin> threads (s))" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1817
            by (simp add:threads.simps)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1818
          with eq_cnp eq_cnv eq_cncs ih not_in
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1819
          have ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1820
        } moreover {
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1821
          assume eq_th: "th = thread"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1822
          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
  1823
          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
  1824
          moreover note eq_cnp eq_cnv eq_cncs
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1825
          ultimately have ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1826
        } ultimately show ?thesis by blast
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1827
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1828
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1829
      case (thread_exit thread)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1830
      assume eq_e: "e = Exit thread" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1831
      and is_runing: "thread \<in> runing s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1832
      and no_hold: "holdents s thread = {}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1833
      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
  1834
      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
  1835
      have eq_cncs: "cntCS (e#s) th = cntCS s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1836
        unfolding cntCS_def holdents_test
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1837
        by (simp add:RAG_exit_unchanged eq_e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1838
      { assume "th \<noteq> thread"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1839
        with eq_e
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1840
        have "(th \<in> readys (e # s) \<or> th \<notin> threads (e # s)) = 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1841
          (th \<in> readys (s) \<or> th \<notin> threads (s))" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1842
          apply (simp add:threads.simps readys_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1843
          apply (subst s_waiting_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1844
          apply (simp add:Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1845
          apply (subst s_waiting_def, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1846
          done
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1847
        with eq_cnp eq_cnv eq_cncs ih
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1848
        have ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1849
      } moreover {
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1850
        assume eq_th: "th = thread"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1851
        with ih is_runing have " cntP s th = cntV s th + cntCS s th" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1852
          by (simp add:runing_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1853
        moreover from eq_th eq_e have "th \<notin> threads (e#s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1854
          by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1855
        moreover note eq_cnp eq_cnv eq_cncs
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1856
        ultimately have ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1857
      } ultimately show ?thesis by blast
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1858
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1859
      case (thread_P thread cs)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1860
      assume eq_e: "e = P thread cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1861
        and is_runing: "thread \<in> runing s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1862
        and no_dep: "(Cs cs, Th thread) \<notin> (RAG s)\<^sup>+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1863
      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
  1864
      then interpret vt_p: valid_trace "(P thread cs#s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1865
        by (unfold_locales, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1866
      show ?thesis 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1867
      proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1868
        { 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
  1869
          assume neq_th: "th \<noteq> thread"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1870
          with eq_e
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1871
          have eq_readys: "(th \<in> readys (e#s)) = (th \<in> readys (s))"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1872
            apply (simp add:readys_def s_waiting_def wq_def Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1873
            apply (rule_tac hh)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1874
             apply (intro iffI allI, clarify)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1875
            apply (erule_tac x = csa in allE, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1876
            apply (subgoal_tac "wq_fun (schs s) cs \<noteq> []", auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1877
            apply (erule_tac x = cs in allE, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1878
            by (case_tac "(wq_fun (schs s) cs)", auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1879
          moreover from neq_th eq_e have "cntCS (e # s) th = cntCS s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1880
            apply (simp add:cntCS_def holdents_test)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1881
            by (unfold  step_RAG_p [OF vtp], auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1882
          moreover from eq_e neq_th have "cntP (e # s) th = cntP s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1883
            by (simp add:cntP_def count_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1884
          moreover from eq_e neq_th have "cntV (e#s) th = cntV s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1885
            by (simp add:cntV_def count_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1886
          moreover from eq_e neq_th have "threads (e#s) = threads s" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1887
          moreover note ih [of th] 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1888
          ultimately have ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1889
        } moreover {
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1890
          assume eq_th: "th = thread"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1891
          have ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1892
          proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1893
            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
  1894
              by (simp add:cntP_def count_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1895
            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
  1896
              by (simp add:cntV_def count_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1897
            show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1898
            proof (cases "wq s cs = []")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1899
              case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1900
              with is_runing
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1901
              have "th \<in> readys (e#s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1902
                apply (unfold eq_e wq_def, unfold readys_def s_RAG_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1903
                apply (simp add: wq_def[symmetric] runing_def eq_th s_waiting_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1904
                by (auto simp:readys_def wq_def Let_def s_waiting_def wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1905
              moreover have "cntCS (e # s) th = 1 + cntCS s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1906
              proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1907
                have "card {csa. csa = cs \<or> (Cs csa, Th thread) \<in> RAG s} =
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1908
                  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
  1909
                proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1910
                  have "?L = insert cs ?R" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1911
                  moreover have "card \<dots> = Suc (card (?R - {cs}))" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1912
                  proof(rule card_insert)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1913
                    from vt_s.finite_holding [of thread]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1914
                    show " finite {cs. (Cs cs, Th thread) \<in> RAG s}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1915
                      by (unfold holdents_test, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1916
                  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1917
                  moreover have "?R - {cs} = ?R"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1918
                  proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1919
                    have "cs \<notin> ?R"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1920
                    proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1921
                      assume "cs \<in> {cs. (Cs cs, Th thread) \<in> RAG s}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1922
                      with no_dep show False by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1923
                    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1924
                    thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1925
                  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1926
                  ultimately show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1927
                qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1928
                thus ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1929
                  apply (unfold eq_e eq_th cntCS_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1930
                  apply (simp add: holdents_test)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1931
                  by (unfold step_RAG_p [OF vtp], auto simp:True)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1932
              qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1933
              moreover from is_runing have "th \<in> readys s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1934
                by (simp add:runing_def eq_th)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1935
              moreover note eq_cnp eq_cnv ih [of th]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1936
              ultimately show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1937
            next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1938
              case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1939
              have eq_wq: "wq (e#s) cs = wq s cs @ [th]"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1940
                    by (unfold eq_th eq_e wq_def, auto simp:Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1941
              have "th \<notin> readys (e#s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1942
              proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1943
                assume "th \<in> readys (e#s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1944
                hence "\<forall>cs. \<not> waiting (e # s) th cs" by (simp add:readys_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1945
                from this[rule_format, of cs] have " \<not> waiting (e # s) th cs" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1946
                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
  1947
                  by (simp add:s_waiting_def wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1948
                moreover from eq_wq have "th \<in> set (wq (e#s) cs)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1949
                ultimately have "th = hd (wq (e#s) cs)" by blast
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1950
                with eq_wq have "th = hd (wq s cs @ [th])" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1951
                hence "th = hd (wq s cs)" using False by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1952
                with False eq_wq vt_p.wq_distinct [of cs]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1953
                show False by (fold eq_e, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1954
              qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1955
              moreover from is_runing have "th \<in> threads (e#s)" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1956
                by (unfold eq_e, auto simp:runing_def readys_def eq_th)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1957
              moreover have "cntCS (e # s) th = cntCS s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1958
                apply (unfold cntCS_def holdents_test eq_e step_RAG_p[OF vtp])
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1959
                by (auto simp:False)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1960
              moreover note eq_cnp eq_cnv ih[of th]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1961
              moreover from is_runing have "th \<in> readys s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1962
                by (simp add:runing_def eq_th)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1963
              ultimately show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1964
            qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1965
          qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1966
        } ultimately show ?thesis by blast
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1967
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1968
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1969
      case (thread_V thread cs)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1970
      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
  1971
      then interpret vt_v: valid_trace "(V thread cs # s)" by (unfold_locales, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1972
      assume eq_e: "e = V thread cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1973
        and is_runing: "thread \<in> runing s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1974
        and hold: "holding s thread cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1975
      from hold obtain rest 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1976
        where eq_wq: "wq s cs = thread # rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1977
        by (case_tac "wq s cs", auto simp: wq_def s_holding_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1978
      have eq_threads: "threads (e#s) = threads s" by (simp add: eq_e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1979
      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
  1980
      proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1981
        from vt_v.wq_distinct[of cs] and eq_wq
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1982
        show "distinct rest \<and> set rest = set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1983
          by (metis distinct.simps(2) vt_s.wq_distinct)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1984
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1985
        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
  1986
          by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1987
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1988
      show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1989
      proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1990
        { assume eq_th: "th = thread"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1991
          from eq_th have eq_cnp: "cntP (e # s) th = cntP s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1992
            by (unfold eq_e, simp add:cntP_def count_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1993
          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
  1994
            by (unfold eq_e, simp add:cntV_def count_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1995
          moreover from cntCS_v_dec [OF vtv] 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1996
          have "cntCS (e # s) thread + 1 = cntCS s thread"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1997
            by (simp add:eq_e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1998
          moreover from is_runing have rd_before: "thread \<in> readys s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  1999
            by (unfold runing_def, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2000
          moreover have "thread \<in> readys (e # s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2001
          proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2002
            from is_runing
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2003
            have "thread \<in> threads (e#s)" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2004
              by (unfold eq_e, auto simp:runing_def readys_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2005
            moreover have "\<forall> cs1. \<not> waiting (e#s) thread cs1"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2006
            proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2007
              fix cs1
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2008
              { assume eq_cs: "cs1 = cs" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2009
                have "\<not> waiting (e # s) thread cs1"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2010
                proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2011
                  from eq_wq
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2012
                  have "thread \<notin> set (wq (e#s) cs1)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2013
                    apply(unfold eq_e wq_def eq_cs s_holding_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2014
                    apply (auto simp:Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2015
                  proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2016
                    assume "thread \<in> set (SOME q. distinct q \<and> set q = set rest)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2017
                    with eq_set have "thread \<in> set rest" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2018
                    with vt_v.wq_distinct[of cs]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2019
                    and eq_wq show False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2020
                        by (metis distinct.simps(2) vt_s.wq_distinct)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2021
                  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2022
                  thus ?thesis by (simp add:wq_def s_waiting_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2023
                qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2024
              } moreover {
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2025
                assume neq_cs: "cs1 \<noteq> cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2026
                  have "\<not> waiting (e # s) thread cs1" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2027
                  proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2028
                    from wq_v_neq [OF neq_cs[symmetric]]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2029
                    have "wq (V thread cs # s) cs1 = wq s cs1" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2030
                    moreover have "\<not> waiting s thread cs1" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2031
                    proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2032
                      from runing_ready and is_runing
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2033
                      have "thread \<in> readys s" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2034
                      thus ?thesis by (simp add:readys_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2035
                    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2036
                    ultimately show ?thesis 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2037
                      by (auto simp:wq_def s_waiting_def eq_e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2038
                  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2039
              } ultimately show "\<not> waiting (e # s) thread cs1" by blast
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2040
            qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2041
            ultimately show ?thesis by (simp add:readys_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2042
          qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2043
          moreover note eq_th ih
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2044
          ultimately have ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2045
        } moreover {
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2046
          assume neq_th: "th \<noteq> thread"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2047
          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
  2048
            by (simp add:cntP_def count_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2049
          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
  2050
            by (simp add:cntV_def count_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2051
          have ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2052
          proof(cases "th \<in> set rest")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2053
            case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2054
            have "(th \<in> readys (e # s)) = (th \<in> readys s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2055
              apply (insert step_back_vt[OF vtv])
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2056
              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
  2057
            moreover have "cntCS (e#s) th = cntCS s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2058
              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
  2059
              proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2060
                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
  2061
                      {cs. (Cs cs, Th th) \<in> RAG s}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2062
                proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2063
                  from False eq_wq
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2064
                  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
  2065
                    apply (unfold next_th_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2066
                  proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2067
                    assume ne: "rest \<noteq> []"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2068
                      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
  2069
                      and eq_wq: "wq s cs = thread # rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2070
                    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
  2071
                                  set (SOME q. distinct q \<and> set q = set rest)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2072
                                  " by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2073
                    moreover have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2074
                    proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2075
                      from vt_s.wq_distinct[ of cs] and eq_wq
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2076
                      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"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2079
                      with ne 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 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2082
                      "(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
  2083
                      by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2084
                  qed    
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2085
                  thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2086
                qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2087
                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
  2088
                             card {cs. (Cs cs, Th th) \<in> RAG s}" by simp 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2089
              qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2090
            moreover note ih eq_cnp eq_cnv eq_threads
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2091
            ultimately show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2092
          next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2093
            case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2094
            assume th_in: "th \<in> set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2095
            show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2096
            proof(cases "next_th s thread cs th")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2097
              case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2098
              with eq_wq and th_in have 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2099
                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
  2100
                by (auto simp:next_th_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2101
              have "(th \<in> readys (e # s)) = (th \<in> readys s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2102
              proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2103
                from eq_wq and th_in
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2104
                have "\<not> th \<in> readys s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2105
                  apply (auto simp:readys_def s_waiting_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2106
                  apply (rule_tac x = cs in exI, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2107
                  by (insert vt_s.wq_distinct[of cs], auto simp add: wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2108
                moreover 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2109
                from eq_wq and th_in and neq_hd
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2110
                have "\<not> (th \<in> readys (e # s))"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2111
                  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
  2112
                  by (rule_tac x = cs in exI, auto simp:eq_set)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2113
                ultimately show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2114
              qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2115
              moreover have "cntCS (e#s) th = cntCS s th" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2116
              proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2117
                from eq_wq and  th_in and neq_hd
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2118
                have "(holdents (e # s) th) = (holdents s th)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2119
                  apply (unfold eq_e step_RAG_v[OF vtv], 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2120
                         auto simp:next_th_def eq_set s_RAG_def holdents_test wq_def
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2121
                                   Let_def cs_holding_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2122
                  by (insert vt_s.wq_distinct[of cs], auto simp:wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2123
                thus ?thesis by (simp add:cntCS_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2124
              qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2125
              moreover note ih eq_cnp eq_cnv eq_threads
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2126
              ultimately show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2127
            next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2128
              case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2129
              let ?rest = " (SOME q. distinct q \<and> set q = set rest)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2130
              let ?t = "hd ?rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2131
              from True eq_wq th_in neq_th
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2132
              have "th \<in> readys (e # s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2133
                apply (auto simp:eq_e readys_def s_waiting_def wq_def
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2134
                        Let_def next_th_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2135
              proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2136
                assume eq_wq: "wq_fun (schs s) cs = thread # rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2137
                  and t_in: "?t \<in> set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2138
                show "?t \<in> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2139
                proof(rule vt_s.wq_threads)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2140
                  from eq_wq and t_in
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2141
                  show "?t \<in> set (wq s cs)" by (auto simp:wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2142
                qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2143
              next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2144
                fix csa
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2145
                assume eq_wq: "wq_fun (schs s) cs = thread # rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2146
                  and t_in: "?t \<in> set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2147
                  and neq_cs: "csa \<noteq> cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2148
                  and t_in': "?t \<in>  set (wq_fun (schs s) csa)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2149
                show "?t = hd (wq_fun (schs s) csa)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2150
                proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2151
                  { assume neq_hd': "?t \<noteq> hd (wq_fun (schs s) csa)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2152
                    from vt_s.wq_distinct[of cs] and 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2153
                    eq_wq[folded wq_def] and t_in eq_wq
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2154
                    have "?t \<noteq> thread" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2155
                    with eq_wq and t_in
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2156
                    have w1: "waiting s ?t cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2157
                      by (auto simp:s_waiting_def wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2158
                    from t_in' neq_hd'
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2159
                    have w2: "waiting s ?t csa"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2160
                      by (auto simp:s_waiting_def wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2161
                    from vt_s.waiting_unique[OF w1 w2]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2162
                    and neq_cs have "False" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2163
                  } thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2164
                qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2165
              qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2166
              moreover have "cntP s th = cntV s th + cntCS s th + 1"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2167
              proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2168
                have "th \<notin> readys s" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2169
                proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2170
                  from True eq_wq neq_th th_in
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2171
                  show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2172
                    apply (unfold readys_def s_waiting_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2173
                    by (rule_tac x = cs in exI, auto simp add: wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2174
                qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2175
                moreover have "th \<in> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2176
                proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2177
                  from th_in eq_wq
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2178
                  have "th \<in> set (wq s cs)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2179
                  from vt_s.wq_threads [OF this] 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2180
                  show ?thesis .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2181
                qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2182
                ultimately show ?thesis using ih by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2183
              qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2184
              moreover from True neq_th have "cntCS (e # s) th = 1 + cntCS s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2185
                apply (unfold cntCS_def holdents_test eq_e step_RAG_v[OF vtv], auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2186
              proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2187
                show "card {csa. (Cs csa, Th th) \<in> RAG s \<or> csa = cs} =
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2188
                               Suc (card {cs. (Cs cs, Th th) \<in> RAG s})"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2189
                  (is "card ?A = Suc (card ?B)")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2190
                proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2191
                  have "?A = insert cs ?B" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2192
                  hence "card ?A = card (insert cs ?B)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2193
                  also have "\<dots> = Suc (card ?B)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2194
                  proof(rule card_insert_disjoint)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2195
                    have "?B \<subseteq> ((\<lambda> (x, y). the_cs x) ` RAG s)" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2196
                      apply (auto simp:image_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2197
                      by (rule_tac x = "(Cs x, Th th)" in bexI, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2198
                    with vt_s.finite_RAG
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2199
                    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
  2200
                  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2201
                    show "cs \<notin> {cs. (Cs cs, Th th) \<in> RAG s}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2202
                    proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2203
                      assume "cs \<in> {cs. (Cs cs, Th th) \<in> RAG s}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2204
                      hence "(Cs cs, Th th) \<in> RAG s" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2205
                      with True neq_th eq_wq show False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2206
                        by (auto simp:next_th_def s_RAG_def cs_holding_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2207
                    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2208
                  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2209
                  finally show ?thesis .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2210
                qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2211
              qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2212
              moreover note eq_cnp eq_cnv
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2213
              ultimately show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2214
            qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2215
          qed
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
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2218
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2219
      case (thread_set thread prio)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2220
      assume eq_e: "e = Set thread prio"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2221
        and is_runing: "thread \<in> runing s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2222
      show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2223
      proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2224
        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
  2225
        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
  2226
        have eq_cncs: "cntCS (e#s) th = cntCS s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2227
          unfolding cntCS_def holdents_test
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2228
          by (simp add:RAG_set_unchanged eq_e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2229
        from eq_e have eq_readys: "readys (e#s) = readys s" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2230
          by (simp add:readys_def cs_waiting_def s_waiting_def wq_def,
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2231
                  auto simp:Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2232
        { assume "th \<noteq> thread"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2233
          with eq_readys eq_e
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2234
          have "(th \<in> readys (e # s) \<or> th \<notin> threads (e # s)) = 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2235
                      (th \<in> readys (s) \<or> th \<notin> threads (s))" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2236
            by (simp add:threads.simps)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2237
          with eq_cnp eq_cnv eq_cncs ih is_runing
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2238
          have ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2239
        } moreover {
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2240
          assume eq_th: "th = thread"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2241
          with is_runing ih have " cntP s th  = cntV s th + cntCS s th" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2242
            by (unfold runing_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2243
          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
  2244
            by (simp add:runing_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2245
          moreover note eq_cnp eq_cnv eq_cncs
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2246
          ultimately have ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2247
        } ultimately show ?thesis by blast
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2248
      qed   
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2249
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2250
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2251
    case vt_nil
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2252
    show ?case 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2253
      by (unfold cntP_def cntV_def cntCS_def, 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2254
        auto simp:count_def holdents_test s_RAG_def wq_def cs_holding_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2255
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2256
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2257
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2258
lemma not_thread_cncs:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2259
  assumes not_in: "th \<notin> threads s" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2260
  shows "cntCS s th = 0"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2261
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2262
  from vt not_in show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2263
  proof(induct arbitrary:th)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2264
    case (vt_cons s e th)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2265
    interpret vt_s: valid_trace s using vt_cons(1)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2266
       by (unfold_locales, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2267
    assume vt: "vt s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2268
      and ih: "\<And>th. th \<notin> threads s \<Longrightarrow> cntCS s th = 0"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2269
      and stp: "step s e"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2270
      and not_in: "th \<notin> threads (e # s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2271
    from stp show ?case
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2272
    proof(cases)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2273
      case (thread_create thread prio)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2274
      assume eq_e: "e = Create thread prio"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2275
        and not_in': "thread \<notin> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2276
      have "cntCS (e # s) th = cntCS s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2277
        apply (unfold eq_e cntCS_def holdents_test)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2278
        by (simp add:RAG_create_unchanged)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2279
      moreover have "th \<notin> threads s" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2280
      proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2281
        from not_in eq_e show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2282
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2283
      moreover note ih ultimately show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2284
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2285
      case (thread_exit thread)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2286
      assume eq_e: "e = Exit thread"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2287
      and nh: "holdents s thread = {}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2288
      have eq_cns: "cntCS (e # s) th = cntCS s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2289
        apply (unfold eq_e cntCS_def holdents_test)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2290
        by (simp add:RAG_exit_unchanged)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2291
      show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2292
      proof(cases "th = thread")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2293
        case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2294
        have "cntCS s th = 0" by (unfold cntCS_def, auto simp:nh True)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2295
        with eq_cns show ?thesis by simp
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
        with not_in and eq_e
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2299
        have "th \<notin> threads s" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2300
        from ih[OF this] and eq_cns show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2301
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2302
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2303
      case (thread_P thread cs)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2304
      assume eq_e: "e = P thread cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2305
      and is_runing: "thread \<in> runing s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2306
      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
  2307
      have neq_th: "th \<noteq> thread" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2308
      proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2309
        from not_in eq_e have "th \<notin> threads s" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2310
        moreover from is_runing have "thread \<in> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2311
          by (simp add:runing_def readys_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2312
        ultimately show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2313
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2314
      hence "cntCS (e # s) th  = cntCS s th "
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2315
        apply (unfold cntCS_def holdents_test eq_e)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2316
        by (unfold step_RAG_p[OF vtp], auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2317
      moreover have "cntCS s th = 0"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2318
      proof(rule ih)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2319
        from not_in eq_e show "th \<notin> threads s" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2320
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2321
      ultimately show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2322
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2323
      case (thread_V thread cs)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2324
      assume eq_e: "e = V thread cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2325
        and is_runing: "thread \<in> runing s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2326
        and hold: "holding s thread cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2327
      have neq_th: "th \<noteq> thread" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2328
      proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2329
        from not_in eq_e have "th \<notin> threads s" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2330
        moreover from is_runing have "thread \<in> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2331
          by (simp add:runing_def readys_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2332
        ultimately show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2333
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2334
      from assms thread_V vt stp ih 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2335
      have vtv: "vt (V thread cs#s)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2336
      then interpret vt_v: valid_trace "(V thread cs#s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2337
        by (unfold_locales, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2338
      from hold obtain rest 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2339
        where eq_wq: "wq s cs = thread # rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2340
        by (case_tac "wq s cs", auto simp: wq_def s_holding_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2341
      from not_in eq_e eq_wq
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2342
      have "\<not> next_th s thread cs th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2343
        apply (auto simp:next_th_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2344
      proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2345
        assume ne: "rest \<noteq> []"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2346
          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
  2347
        have "?t \<in> set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2348
        proof(rule someI2)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2349
          from vt_v.wq_distinct[of cs] and eq_wq
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2350
          show "distinct rest \<and> set rest = set rest"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2351
            by (metis distinct.simps(2) vt_s.wq_distinct) 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2352
        next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2353
          fix x assume "distinct x \<and> set x = set rest" with ne
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2354
          show "hd x \<in> set rest" by (cases x, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2355
        qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2356
        with eq_wq have "?t \<in> set (wq s cs)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2357
        from vt_s.wq_threads[OF this] and ni
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2358
        show False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2359
          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
  2360
            ni vt_s.wq_threads by blast 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2361
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2362
      moreover note neq_th eq_wq
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2363
      ultimately have "cntCS (e # s) th  = cntCS s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2364
        by (unfold eq_e cntCS_def holdents_test step_RAG_v[OF vtv], auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2365
      moreover have "cntCS s th = 0"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2366
      proof(rule ih)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2367
        from not_in eq_e show "th \<notin> threads s" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2368
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2369
      ultimately show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2370
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2371
      case (thread_set thread prio)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2372
      print_facts
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2373
      assume eq_e: "e = Set thread prio"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2374
        and is_runing: "thread \<in> runing s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2375
      from not_in and eq_e have "th \<notin> threads s" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2376
      from ih [OF this] and eq_e
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2377
      show ?thesis 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2378
        apply (unfold eq_e cntCS_def holdents_test)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2379
        by (simp add:RAG_set_unchanged)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2380
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2381
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2382
      case vt_nil
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2383
      show ?case
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2384
      by (unfold cntCS_def, 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2385
        auto simp:count_def holdents_test s_RAG_def wq_def cs_holding_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2386
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2387
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2388
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2389
end
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2390
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2391
lemma eq_waiting: "waiting (wq (s::state)) th cs = waiting s th cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2392
  by (auto simp:s_waiting_def cs_waiting_def wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2393
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2394
context valid_trace
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2395
begin
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2396
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2397
lemma dm_RAG_threads:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2398
  assumes in_dom: "(Th th) \<in> Domain (RAG s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2399
  shows "th \<in> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2400
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2401
  from in_dom obtain n where "(Th th, n) \<in> RAG s" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2402
  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
  2403
  ultimately have "(Th th, Cs cs) \<in> RAG s" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2404
  hence "th \<in> set (wq s cs)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2405
    by (unfold s_RAG_def, auto simp:cs_waiting_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2406
  from wq_threads [OF this] show ?thesis .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2407
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2408
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2409
end
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2410
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2411
lemma cp_eq_cpreced: "cp s th = cpreced (wq s) s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2412
unfolding cp_def wq_def
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2413
apply(induct s rule: schs.induct)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2414
thm cpreced_initial
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2415
apply(simp add: Let_def cpreced_initial)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2416
apply(simp add: Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2417
apply(simp add: Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2418
apply(simp add: Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2419
apply(subst (2) schs.simps)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2420
apply(simp add: Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2421
apply(subst (2) schs.simps)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2422
apply(simp add: Let_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2423
done
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2424
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2425
context valid_trace
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2426
begin
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2427
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2428
lemma runing_unique:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2429
  assumes runing_1: "th1 \<in> runing s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2430
  and runing_2: "th2 \<in> runing s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2431
  shows "th1 = th2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2432
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2433
  from runing_1 and runing_2 have "cp s th1 = cp s th2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2434
    unfolding runing_def
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2435
    apply(simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2436
    done
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2437
  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
  2438
                 Max ((\<lambda>th. preced th s) ` ({th2} \<union> dependants (wq s) th2))"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2439
    (is "Max (?f ` ?A) = Max (?f ` ?B)")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2440
    unfolding cp_eq_cpreced 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2441
    unfolding cpreced_def .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2442
  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
  2443
  proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2444
    have h1: "finite (?f ` ?A)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2445
    proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2446
      have "finite ?A" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2447
      proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2448
        have "finite (dependants (wq s) th1)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2449
        proof-
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2450
          have "finite {th'. (Th th', Th th1) \<in> (RAG (wq s))\<^sup>+}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2451
          proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2452
            let ?F = "\<lambda> (x, y). the_th x"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2453
            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
  2454
              apply (auto simp:image_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2455
              by (rule_tac x = "(Th x, Th th1)" in bexI, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2456
            moreover have "finite \<dots>"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2457
            proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2458
              from finite_RAG have "finite (RAG s)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2459
              hence "finite ((RAG (wq s))\<^sup>+)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2460
                apply (unfold finite_trancl)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2461
                by (auto simp: s_RAG_def cs_RAG_def wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2462
              thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2463
            qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2464
            ultimately show ?thesis by (auto intro:finite_subset)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2465
          qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2466
          thus ?thesis by (simp add:cs_dependants_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2467
        qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2468
        thus ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2469
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2470
      thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2471
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2472
    moreover have h2: "(?f ` ?A) \<noteq> {}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2473
    proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2474
      have "?A \<noteq> {}" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2475
      thus ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2476
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2477
    from Max_in [OF h1 h2]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2478
    have "Max (?f ` ?A) \<in> (?f ` ?A)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2479
    thus ?thesis 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2480
      thm cpreced_def
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2481
      unfolding cpreced_def[symmetric] 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2482
      unfolding cp_eq_cpreced[symmetric] 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2483
      unfolding cpreced_def 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2484
      using that[intro] by (auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2485
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2486
  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
  2487
  proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2488
    have h1: "finite (?f ` ?B)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2489
    proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2490
      have "finite ?B" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2491
      proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2492
        have "finite (dependants (wq s) th2)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2493
        proof-
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2494
          have "finite {th'. (Th th', Th th2) \<in> (RAG (wq s))\<^sup>+}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2495
          proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2496
            let ?F = "\<lambda> (x, y). the_th x"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2497
            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
  2498
              apply (auto simp:image_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2499
              by (rule_tac x = "(Th x, Th th2)" in bexI, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2500
            moreover have "finite \<dots>"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2501
            proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2502
              from finite_RAG have "finite (RAG s)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2503
              hence "finite ((RAG (wq s))\<^sup>+)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2504
                apply (unfold finite_trancl)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2505
                by (auto simp: s_RAG_def cs_RAG_def wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2506
              thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2507
            qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2508
            ultimately show ?thesis by (auto intro:finite_subset)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2509
          qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2510
          thus ?thesis by (simp add:cs_dependants_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2511
        qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2512
        thus ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2513
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2514
      thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2515
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2516
    moreover have h2: "(?f ` ?B) \<noteq> {}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2517
    proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2518
      have "?B \<noteq> {}" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2519
      thus ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2520
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2521
    from Max_in [OF h1 h2]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2522
    have "Max (?f ` ?B) \<in> (?f ` ?B)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2523
    thus ?thesis by (auto intro:that)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2524
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2525
  from eq_f_th1 eq_f_th2 eq_max 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2526
  have eq_preced: "preced th1' s = preced th2' s" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2527
  hence eq_th12: "th1' = th2'"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2528
  proof (rule preced_unique)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2529
    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
  2530
    thus "th1' \<in> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2531
    proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2532
      assume "th1' \<in> dependants (wq s) th1"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2533
      hence "(Th th1') \<in> Domain ((RAG s)^+)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2534
        apply (unfold cs_dependants_def cs_RAG_def s_RAG_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2535
        by (auto simp:Domain_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2536
      hence "(Th th1') \<in> Domain (RAG s)" by (simp add:trancl_domain)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2537
      from dm_RAG_threads[OF this] show ?thesis .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2538
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2539
      assume "th1' = th1"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2540
      with runing_1 show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2541
        by (unfold runing_def readys_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2542
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2543
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2544
    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
  2545
    thus "th2' \<in> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2546
    proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2547
      assume "th2' \<in> dependants (wq s) th2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2548
      hence "(Th th2') \<in> Domain ((RAG s)^+)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2549
        apply (unfold cs_dependants_def cs_RAG_def s_RAG_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2550
        by (auto simp:Domain_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2551
      hence "(Th th2') \<in> Domain (RAG s)" by (simp add:trancl_domain)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2552
      from dm_RAG_threads[OF this] show ?thesis .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2553
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2554
      assume "th2' = th2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2555
      with runing_2 show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2556
        by (unfold runing_def readys_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2557
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2558
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2559
  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
  2560
  thus ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2561
  proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2562
    assume eq_th': "th1' = th1"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2563
    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
  2564
    thus ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2565
    proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2566
      assume "th2' = th2" thus ?thesis using eq_th' eq_th12 by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2567
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2568
      assume "th2' \<in> dependants (wq s) th2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2569
      with eq_th12 eq_th' have "th1 \<in> dependants (wq s) th2" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2570
      hence "(Th th1, Th th2) \<in> (RAG s)^+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2571
        by (unfold cs_dependants_def s_RAG_def cs_RAG_def, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2572
      hence "Th th1 \<in> Domain ((RAG s)^+)" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2573
        apply (unfold cs_dependants_def cs_RAG_def s_RAG_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2574
        by (auto simp:Domain_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2575
      hence "Th th1 \<in> Domain (RAG s)" by (simp add:trancl_domain)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2576
      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
  2577
      from RAG_target_th [OF this]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2578
      obtain cs' where "n = Cs cs'" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2579
      with d have "(Th th1, Cs cs') \<in> RAG s" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2580
      with runing_1 have "False"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2581
        apply (unfold runing_def readys_def s_RAG_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2582
        by (auto simp:eq_waiting)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2583
      thus ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2584
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2585
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2586
    assume th1'_in: "th1' \<in> dependants (wq s) th1"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2587
    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
  2588
    thus ?thesis 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2589
    proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2590
      assume "th2' = th2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2591
      with th1'_in eq_th12 have "th2 \<in> dependants (wq s) th1" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2592
      hence "(Th th2, Th th1) \<in> (RAG s)^+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2593
        by (unfold cs_dependants_def s_RAG_def cs_RAG_def, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2594
      hence "Th th2 \<in> Domain ((RAG s)^+)" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2595
        apply (unfold cs_dependants_def cs_RAG_def s_RAG_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2596
        by (auto simp:Domain_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2597
      hence "Th th2 \<in> Domain (RAG s)" by (simp add:trancl_domain)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2598
      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
  2599
      from RAG_target_th [OF this]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2600
      obtain cs' where "n = Cs cs'" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2601
      with d have "(Th th2, Cs cs') \<in> RAG s" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2602
      with runing_2 have "False"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2603
        apply (unfold runing_def readys_def s_RAG_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2604
        by (auto simp:eq_waiting)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2605
      thus ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2606
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2607
      assume "th2' \<in> dependants (wq s) th2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2608
      with eq_th12 have "th1' \<in> dependants (wq s) th2" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2609
      hence h1: "(Th th1', Th th2) \<in> (RAG s)^+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2610
        by (unfold cs_dependants_def s_RAG_def cs_RAG_def, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2611
      from th1'_in have h2: "(Th th1', Th th1) \<in> (RAG s)^+"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2612
        by (unfold cs_dependants_def s_RAG_def cs_RAG_def, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2613
      show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2614
      proof(rule dchain_unique[OF h1 _ h2, symmetric])
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2615
        from runing_1 show "th1 \<in> readys s" by (simp add:runing_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2616
        from runing_2 show "th2 \<in> readys s" by (simp add:runing_def) 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2617
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2618
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2619
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2620
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2621
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2622
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2623
lemma "card (runing s) \<le> 1"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2624
apply(subgoal_tac "finite (runing s)")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2625
prefer 2
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2626
apply (metis finite_nat_set_iff_bounded lessI runing_unique)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2627
apply(rule ccontr)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2628
apply(simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2629
apply(case_tac "Suc (Suc 0) \<le> card (runing s)")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2630
apply(subst (asm) card_le_Suc_iff)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2631
apply(simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2632
apply(auto)[1]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2633
apply (metis insertCI runing_unique)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2634
apply(auto) 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2635
done
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2636
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2637
end
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2638
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2639
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2640
lemma create_pre:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2641
  assumes stp: "step s e"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2642
  and not_in: "th \<notin> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2643
  and is_in: "th \<in> threads (e#s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2644
  obtains prio where "e = Create th prio"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2645
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2646
  from assms  
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2647
  show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2648
  proof(cases)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2649
    case (thread_create thread prio)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2650
    with is_in not_in have "e = Create th prio" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2651
    from that[OF this] show ?thesis .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2652
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2653
    case (thread_exit thread)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2654
    with assms show ?thesis by (auto intro!:that)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2655
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2656
    case (thread_P thread)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2657
    with assms show ?thesis by (auto intro!:that)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2658
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2659
    case (thread_V thread)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2660
    with assms show ?thesis by (auto intro!:that)
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_set thread)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2663
    with assms show ?thesis by (auto intro!:that)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2664
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2665
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2666
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2667
lemma length_down_to_in: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2668
  assumes le_ij: "i \<le> j"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2669
    and le_js: "j \<le> length s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2670
  shows "length (down_to j i s) = j - i"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2671
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2672
  have "length (down_to j i s) = length (from_to i j (rev s))"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2673
    by (unfold down_to_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2674
  also have "\<dots> = j - i"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2675
  proof(rule length_from_to_in[OF le_ij])
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2676
    from le_js show "j \<le> length (rev s)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2677
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2678
  finally show ?thesis .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2679
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2680
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2681
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2682
lemma moment_head: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2683
  assumes le_it: "Suc i \<le> length t"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2684
  obtains e where "moment (Suc i) t = e#moment i t"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2685
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2686
  have "i \<le> Suc i" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2687
  from length_down_to_in [OF this le_it]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2688
  have "length (down_to (Suc i) i t) = 1" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2689
  then obtain e where "down_to (Suc i) i t = [e]"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2690
    apply (cases "(down_to (Suc i) i t)") by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2691
  moreover have "down_to (Suc i) 0 t = down_to (Suc i) i t @ down_to i 0 t"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2692
    by (rule down_to_conc[symmetric], auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2693
  ultimately have eq_me: "moment (Suc i) t = e#(moment i t)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2694
    by (auto simp:down_to_moment)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2695
  from that [OF this] show ?thesis .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2696
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2697
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2698
context valid_trace
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2699
begin
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2700
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2701
lemma cnp_cnv_eq:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2702
  assumes "th \<notin> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2703
  shows "cntP s th = cntV s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2704
  using assms
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2705
  using cnp_cnv_cncs not_thread_cncs by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2706
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2707
end
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2708
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2709
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2710
lemma eq_RAG: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2711
  "RAG (wq s) = RAG s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2712
by (unfold cs_RAG_def s_RAG_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2713
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2714
context valid_trace
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2715
begin
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2716
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2717
lemma count_eq_dependants:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2718
  assumes eq_pv: "cntP s th = cntV s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2719
  shows "dependants (wq s) th = {}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2720
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2721
  from cnp_cnv_cncs and eq_pv
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2722
  have "cntCS s th = 0" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2723
    by (auto split:if_splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2724
  moreover have "finite {cs. (Cs cs, Th th) \<in> RAG s}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2725
  proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2726
    from finite_holding[of th] show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2727
      by (simp add:holdents_test)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2728
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2729
  ultimately have h: "{cs. (Cs cs, Th th) \<in> RAG s} = {}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2730
    by (unfold cntCS_def holdents_test cs_dependants_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2731
  show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2732
  proof(unfold cs_dependants_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2733
    { assume "{th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+} \<noteq> {}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2734
      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
  2735
      hence "False"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2736
      proof(cases)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2737
        assume "(Th th', Th th) \<in> RAG (wq s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2738
        thus "False" by (auto simp:cs_RAG_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2739
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2740
        fix c
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2741
        assume "(c, Th th) \<in> RAG (wq s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2742
        with h and eq_RAG show "False"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2743
          by (cases c, auto simp:cs_RAG_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2744
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2745
    } thus "{th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+} = {}" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2746
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2747
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2748
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2749
lemma dependants_threads:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2750
  shows "dependants (wq s) th \<subseteq> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2751
proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2752
  { fix th th'
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2753
    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
  2754
    have "Th th \<in> Domain (RAG s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2755
    proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2756
      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
  2757
      hence "(Th th) \<in> Domain ( (RAG (wq s))\<^sup>+)" by (auto simp:Domain_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2758
      with trancl_domain have "(Th th) \<in> Domain (RAG (wq s))" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2759
      thus ?thesis using eq_RAG by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2760
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2761
    from dm_RAG_threads[OF this]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2762
    have "th \<in> threads s" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2763
  } note hh = this
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2764
  fix th1 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2765
  assume "th1 \<in> dependants (wq s) th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2766
  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
  2767
    by (unfold cs_dependants_def, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2768
  from hh [OF this] show "th1 \<in> threads s" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2769
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2770
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2771
lemma finite_threads:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2772
  shows "finite (threads s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2773
using vt by (induct) (auto elim: step.cases)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2774
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2775
end
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2776
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2777
lemma Max_f_mono:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2778
  assumes seq: "A \<subseteq> B"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2779
  and np: "A \<noteq> {}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2780
  and fnt: "finite B"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2781
  shows "Max (f ` A) \<le> Max (f ` B)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2782
proof(rule Max_mono)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2783
  from seq show "f ` A \<subseteq> f ` B" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2784
next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2785
  from np show "f ` A \<noteq> {}" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2786
next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2787
  from fnt and seq show "finite (f ` B)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2788
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2789
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2790
context valid_trace
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2791
begin
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2792
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2793
lemma cp_le:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2794
  assumes th_in: "th \<in> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2795
  shows "cp s th \<le> Max ((\<lambda> th. (preced th s)) ` threads s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2796
proof(unfold cp_eq_cpreced cpreced_def cs_dependants_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2797
  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
  2798
         \<le> Max ((\<lambda>th. preced th s) ` threads s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2799
    (is "Max (?f ` ?A) \<le> Max (?f ` ?B)")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2800
  proof(rule Max_f_mono)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2801
    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
  2802
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2803
    from finite_threads
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2804
    show "finite (threads s)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2805
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2806
    from th_in
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2807
    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
  2808
      apply (auto simp:Domain_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2809
      apply (rule_tac dm_RAG_threads)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2810
      apply (unfold trancl_domain [of "RAG s", symmetric])
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2811
      by (unfold cs_RAG_def s_RAG_def, auto simp:Domain_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2812
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2813
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2814
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2815
lemma le_cp:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2816
  shows "preced th s \<le> cp s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2817
proof(unfold cp_eq_cpreced preced_def cpreced_def, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2818
  show "Prc (priority th s) (last_set th s)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2819
    \<le> Max (insert (Prc (priority th s) (last_set th s))
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2820
            ((\<lambda>th. Prc (priority th s) (last_set th s)) ` dependants (wq s) th))"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2821
    (is "?l \<le> Max (insert ?l ?A)")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2822
  proof(cases "?A = {}")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2823
    case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2824
    have "finite ?A" (is "finite (?f ` ?B)")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2825
    proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2826
      have "finite ?B" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2827
      proof-
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2828
        have "finite {th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2829
        proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2830
          let ?F = "\<lambda> (x, y). the_th x"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2831
          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
  2832
            apply (auto simp:image_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2833
            by (rule_tac x = "(Th x, Th th)" in bexI, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2834
          moreover have "finite \<dots>"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2835
          proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2836
            from finite_RAG have "finite (RAG s)" .
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2837
            hence "finite ((RAG (wq s))\<^sup>+)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2838
              apply (unfold finite_trancl)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2839
              by (auto simp: s_RAG_def cs_RAG_def wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2840
            thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2841
          qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2842
          ultimately show ?thesis by (auto intro:finite_subset)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2843
        qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2844
        thus ?thesis by (simp add:cs_dependants_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2845
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2846
      thus ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2847
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2848
    from Max_insert [OF this False, of ?l] show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2849
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2850
    case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2851
    thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2852
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2853
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2854
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2855
lemma max_cp_eq: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2856
  shows "Max ((cp s) ` threads s) = Max ((\<lambda> th. (preced th s)) ` threads s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2857
  (is "?l = ?r")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2858
proof(cases "threads s = {}")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2859
  case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2860
  thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2861
next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2862
  case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2863
  have "?l \<in> ((cp s) ` threads s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2864
  proof(rule Max_in)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2865
    from finite_threads
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2866
    show "finite (cp s ` threads s)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2867
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2868
    from False show "cp s ` threads s \<noteq> {}" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2869
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2870
  then obtain th 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2871
    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
  2872
  have "\<dots> \<le> ?r" by (rule cp_le[OF th_in])
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2873
  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
  2874
  proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2875
    have "?r \<in> (?f ` ?A)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2876
    proof(rule Max_in)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2877
      from finite_threads
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2878
      show " finite ((\<lambda>th. preced th s) ` threads s)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2879
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2880
      from False show " (\<lambda>th. preced th s) ` threads s \<noteq> {}" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2881
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2882
    then obtain th' where 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2883
      th_in': "th' \<in> ?A " and eq_r: "?r = ?f th'" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2884
    from le_cp [of th']  eq_r
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2885
    have "?r \<le> cp s th'" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2886
    moreover have "\<dots> \<le> cp s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2887
    proof(fold eq_l)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2888
      show " cp s th' \<le> Max (cp s ` threads s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2889
      proof(rule Max_ge)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2890
        from th_in' show "cp s th' \<in> cp s ` threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2891
          by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2892
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2893
        from finite_threads
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2894
        show "finite (cp s ` threads s)" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2895
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2896
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2897
    ultimately show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2898
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2899
  ultimately show ?thesis using eq_l by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2900
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2901
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2902
lemma max_cp_readys_threads_pre:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2903
  assumes np: "threads s \<noteq> {}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2904
  shows "Max (cp s ` readys s) = Max (cp s ` threads s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2905
proof(unfold max_cp_eq)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2906
  show "Max (cp s ` readys s) = Max ((\<lambda>th. preced th s) ` threads s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2907
  proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2908
    let ?p = "Max ((\<lambda>th. preced th s) ` threads s)" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2909
    let ?f = "(\<lambda>th. preced th s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2910
    have "?p \<in> ((\<lambda>th. preced th s) ` threads s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2911
    proof(rule Max_in)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2912
      from finite_threads show "finite (?f ` threads s)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2913
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2914
      from np show "?f ` threads s \<noteq> {}" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2915
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2916
    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
  2917
      by (auto simp:Image_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2918
    from th_chain_to_ready [OF tm_in]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2919
    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
  2920
    thus ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2921
    proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2922
      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
  2923
      then obtain th' where th'_in: "th' \<in> readys s" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2924
        and tm_chain:"(Th tm, Th th') \<in> (RAG s)\<^sup>+" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2925
      have "cp s th' = ?f tm"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2926
      proof(subst cp_eq_cpreced, subst cpreced_def, rule Max_eqI)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2927
        from dependants_threads finite_threads
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2928
        show "finite ((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th'))" 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2929
          by (auto intro:finite_subset)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2930
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2931
        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
  2932
        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
  2933
        moreover have "p \<le> \<dots>"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2934
        proof(rule Max_ge)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2935
          from finite_threads
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2936
          show "finite ((\<lambda>th. preced th s) ` threads s)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2937
        next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2938
          from p_in and th'_in and dependants_threads[of th']
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2939
          show "p \<in> (\<lambda>th. preced th s) ` threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2940
            by (auto simp:readys_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2941
        qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2942
        ultimately show "p \<le> preced tm s" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2943
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2944
        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
  2945
        proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2946
          from tm_chain
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2947
          have "tm \<in> dependants (wq s) th'"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2948
            by (unfold cs_dependants_def s_RAG_def cs_RAG_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2949
          thus ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2950
        qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2951
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2952
      with tm_max
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2953
      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
  2954
      show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2955
      proof (fold h, rule Max_eqI)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2956
        fix q 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2957
        assume "q \<in> cp s ` readys s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2958
        then obtain th1 where th1_in: "th1 \<in> readys s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2959
          and eq_q: "q = cp s th1" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2960
        show "q \<le> cp s th'"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2961
          apply (unfold h eq_q)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2962
          apply (unfold cp_eq_cpreced cpreced_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2963
          apply (rule Max_mono)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2964
        proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2965
          from dependants_threads [of th1] th1_in
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2966
          show "(\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1) \<subseteq> 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2967
                 (\<lambda>th. preced th s) ` threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2968
            by (auto simp:readys_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2969
        next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2970
          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
  2971
        next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2972
          from finite_threads 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2973
          show " finite ((\<lambda>th. preced th s) ` threads s)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2974
        qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2975
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2976
        from finite_threads
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2977
        show "finite (cp s ` readys s)" by (auto simp:readys_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2978
      next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2979
        from th'_in
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2980
        show "cp s th' \<in> cp s ` readys s" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2981
      qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2982
    next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2983
      assume tm_ready: "tm \<in> readys s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2984
      show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2985
      proof(fold tm_max)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2986
        have cp_eq_p: "cp s tm = preced tm s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2987
        proof(unfold cp_eq_cpreced cpreced_def, rule Max_eqI)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2988
          fix y 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2989
          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
  2990
          show "y \<le> preced tm s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2991
          proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2992
            { fix y'
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2993
              assume hy' : "y' \<in> ((\<lambda>th. preced th s) ` dependants (wq s) tm)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2994
              have "y' \<le> preced tm s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2995
              proof(unfold tm_max, rule Max_ge)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2996
                from hy' dependants_threads[of tm]
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2997
                show "y' \<in> (\<lambda>th. preced th s) ` threads s" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2998
              next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  2999
                from finite_threads
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3000
                show "finite ((\<lambda>th. preced th s) ` threads s)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3001
              qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3002
            } with hy show ?thesis by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3003
          qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3004
        next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3005
          from dependants_threads[of tm] finite_threads
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3006
          show "finite ((\<lambda>th. preced th s) ` ({tm} \<union> dependants (wq s) tm))"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3007
            by (auto intro:finite_subset)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3008
        next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3009
          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
  3010
            by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3011
        qed 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3012
        moreover have "Max (cp s ` readys s) = cp s tm"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3013
        proof(rule Max_eqI)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3014
          from tm_ready show "cp s tm \<in> cp s ` readys s" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3015
        next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3016
          from finite_threads
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3017
          show "finite (cp s ` readys s)" by (auto simp:readys_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3018
        next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3019
          fix y assume "y \<in> cp s ` readys s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3020
          then obtain th1 where th1_readys: "th1 \<in> readys s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3021
            and h: "y = cp s th1" by auto
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3022
          show "y \<le> cp s tm"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3023
            apply(unfold cp_eq_p h)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3024
            apply(unfold cp_eq_cpreced cpreced_def tm_max, rule Max_mono)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3025
          proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3026
            from finite_threads
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3027
            show "finite ((\<lambda>th. preced th s) ` threads s)" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3028
          next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3029
            show "(\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1) \<noteq> {}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3030
              by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3031
          next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3032
            from dependants_threads[of th1] th1_readys
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3033
            show "(\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1) 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3034
                    \<subseteq> (\<lambda>th. preced th s) ` threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3035
              by (auto simp:readys_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3036
          qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3037
        qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3038
        ultimately show " Max (cp s ` readys s) = preced tm s" by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3039
      qed 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3040
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3041
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3042
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3043
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3044
text {* (* ccc *) \noindent
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3045
  Since the current precedence of the threads in ready queue will always be boosted,
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3046
  there must be one inside it has the maximum precedence of the whole system. 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3047
*}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3048
lemma max_cp_readys_threads:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3049
  shows "Max (cp s ` readys s) = Max (cp s ` threads s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3050
proof(cases "threads s = {}")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3051
  case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3052
  thus ?thesis 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3053
    by (auto simp:readys_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3054
next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3055
  case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3056
  show ?thesis by (rule max_cp_readys_threads_pre[OF False])
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3057
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3058
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3059
end
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3060
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3061
lemma eq_holding: "holding (wq s) th cs = holding s th cs"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3062
  apply (unfold s_holding_def cs_holding_def wq_def, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3063
  done
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3064
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3065
lemma f_image_eq:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3066
  assumes h: "\<And> a. a \<in> A \<Longrightarrow> f a = g a"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3067
  shows "f ` A = g ` A"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3068
proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3069
  show "f ` A \<subseteq> g ` A"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3070
    by(rule image_subsetI, auto intro:h)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3071
next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3072
  show "g ` A \<subseteq> f ` A"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3073
   by (rule image_subsetI, auto intro:h[symmetric])
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3074
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3075
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3076
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3077
definition detached :: "state \<Rightarrow> thread \<Rightarrow> bool"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3078
  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
  3079
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3080
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3081
lemma detached_test:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3082
  shows "detached s th = (Th th \<notin> Field (RAG s))"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3083
apply(simp add: detached_def Field_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3084
apply(simp add: s_RAG_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3085
apply(simp add: s_holding_abv s_waiting_abv)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3086
apply(simp add: Domain_iff Range_iff)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3087
apply(simp add: wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3088
apply(auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3089
done
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3090
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3091
context valid_trace
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3092
begin
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3093
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3094
lemma detached_intro:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3095
  assumes eq_pv: "cntP s th = cntV s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3096
  shows "detached s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3097
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3098
 from cnp_cnv_cncs
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3099
  have eq_cnt: "cntP s th =
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3100
    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
  3101
  hence cncs_zero: "cntCS s th = 0"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3102
    by (auto simp:eq_pv split:if_splits)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3103
  with eq_cnt
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3104
  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
  3105
  thus ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3106
  proof
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3107
    assume "th \<notin> threads s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3108
    with range_in dm_RAG_threads
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3109
    show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3110
      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
  3111
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3112
    assume "th \<in> readys s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3113
    moreover have "Th th \<notin> Range (RAG s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3114
    proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3115
      from card_0_eq [OF finite_holding] and cncs_zero
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3116
      have "holdents s th = {}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3117
        by (simp add:cntCS_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3118
      thus ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3119
        apply(auto simp:holdents_test)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3120
        apply(case_tac a)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3121
        apply(auto simp:holdents_test s_RAG_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3122
        done
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3123
    qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3124
    ultimately show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3125
      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
  3126
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3127
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3128
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3129
lemma detached_elim:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3130
  assumes dtc: "detached s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3131
  shows "cntP s th = cntV s th"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3132
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3133
  from cnp_cnv_cncs
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3134
  have eq_pv: " cntP s th =
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3135
    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
  3136
  have cncs_z: "cntCS s th = 0"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3137
  proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3138
    from dtc have "holdents s th = {}"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3139
      unfolding detached_def holdents_test s_RAG_def
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3140
      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
  3141
    thus ?thesis by (auto simp:cntCS_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3142
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3143
  show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3144
  proof(cases "th \<in> threads s")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3145
    case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3146
    with dtc 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3147
    have "th \<in> readys s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3148
      by (unfold readys_def detached_def Field_def Domain_def Range_def, 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3149
           auto simp:eq_waiting s_RAG_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3150
    with cncs_z and eq_pv show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3151
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3152
    case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3153
    with cncs_z and eq_pv show ?thesis by simp
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3154
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3155
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3156
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3157
lemma detached_eq:
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3158
  shows "(detached s th) = (cntP s th = cntV s th)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3159
  by (insert vt, auto intro:detached_intro detached_elim)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3160
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3161
end
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3162
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3163
text {* 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3164
  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
  3165
  from the concise and miniature model of PIP given in PrioGDef.thy.
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3166
*}
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3167
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3168
lemma eq_dependants: "dependants (wq s) = dependants s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3169
  by (simp add: s_dependants_abv wq_def)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3170
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3171
lemma next_th_unique: 
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3172
  assumes nt1: "next_th s th cs th1"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3173
  and nt2: "next_th s th cs th2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3174
  shows "th1 = th2"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3175
using assms by (unfold next_th_def, auto)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3176
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3177
lemma birth_time_lt:  "s \<noteq> [] \<Longrightarrow> last_set th s < length s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3178
  apply (induct s, simp)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3179
proof -
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3180
  fix a s
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3181
  assume ih: "s \<noteq> [] \<Longrightarrow> last_set th s < length s"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3182
    and eq_as: "a # s \<noteq> []"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3183
  show "last_set th (a # s) < length (a # s)"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3184
  proof(cases "s \<noteq> []")
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3185
    case False
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3186
    from False show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3187
      by (cases a, auto simp:last_set.simps)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3188
  next
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3189
    case True
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3190
    from ih [OF True] show ?thesis
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3191
      by (cases a, auto simp:last_set.simps)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3192
  qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3193
qed
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3194
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3195
lemma th_in_ne: "th \<in> threads s \<Longrightarrow> s \<noteq> []"
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3196
  by (induct s, auto simp:threads.simps)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3197
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3198
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
  3199
  apply (drule_tac th_in_ne)
b0054fb0d1ce Moment.thy further improved.
zhangx
parents: 65
diff changeset
  3200
  by (unfold preced_def, auto intro: birth_time_lt)
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3201
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3202
lemma inj_the_preced: 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3203
  "inj_on (the_preced s) (threads s)"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3204
  by (metis inj_onI preced_unique the_preced_def)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3205
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3206
lemma tRAG_alt_def: 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3207
  "tRAG s = {(Th th1, Th th2) | th1 th2. 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3208
                  \<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
  3209
 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
  3210
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3211
lemma tRAG_Field:
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3212
  "Field (tRAG s) \<subseteq> Field (RAG s)"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3213
  by (unfold tRAG_alt_def Field_def, auto)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3214
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3215
lemma tRAG_ancestorsE:
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3216
  assumes "x \<in> ancestors (tRAG s) u"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3217
  obtains th where "x = Th th"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3218
proof -
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3219
  from assms have "(u, x) \<in> (tRAG s)^+" 
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3220
      by (unfold ancestors_def, auto)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3221
  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
  3222
  then obtain th where "x = Th th"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3223
    by (unfold tRAG_alt_def, auto)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3224
  from that[OF this] show ?thesis .
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3225
qed
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3226
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3227
lemma tRAG_mono:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3228
  assumes "RAG s' \<subseteq> RAG s"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3229
  shows "tRAG s' \<subseteq> tRAG s"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3230
  using assms 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3231
  by (unfold tRAG_alt_def, auto)
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3232
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3233
lemma holding_next_thI:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3234
  assumes "holding s th cs"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3235
  and "length (wq s cs) > 1"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3236
  obtains th' where "next_th s th cs th'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3237
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3238
  from assms(1)[folded eq_holding, unfolded cs_holding_def]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3239
  have " th \<in> set (wq s cs) \<and> th = hd (wq s cs)" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3240
  then obtain rest where h1: "wq s cs = th#rest" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3241
    by (cases "wq s cs", auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3242
  with assms(2) have h2: "rest \<noteq> []" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3243
  let ?th' = "hd (SOME q. distinct q \<and> set q = set rest)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3244
  have "next_th s th cs ?th'" using  h1(1) h2 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3245
    by (unfold next_th_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3246
  from that[OF this] show ?thesis .
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3247
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3248
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3249
lemma RAG_tRAG_transfer:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3250
  assumes "vt s'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3251
  assumes "RAG s = RAG s' \<union> {(Th th, Cs cs)}"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3252
  and "(Cs cs, Th th'') \<in> RAG s'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3253
  shows "tRAG s = tRAG s' \<union> {(Th th, Th th'')}" (is "?L = ?R")
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3254
proof -
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3255
  interpret vt_s': valid_trace "s'" using assms(1)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3256
    by (unfold_locales, simp)
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3257
  interpret rtree: rtree "RAG s'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3258
  proof
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3259
  show "single_valued (RAG s')"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3260
  apply (intro_locales)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3261
    by (unfold single_valued_def, 
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3262
        auto intro:vt_s'.unique_RAG)
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3263
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3264
  show "acyclic (RAG s')"
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3265
     by (rule vt_s'.acyclic_RAG)
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3266
  qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3267
  { fix n1 n2
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3268
    assume "(n1, n2) \<in> ?L"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3269
    from this[unfolded tRAG_alt_def]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3270
    obtain th1 th2 cs' where 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3271
      h: "n1 = Th th1" "n2 = Th th2" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3272
         "(Th th1, Cs cs') \<in> RAG s"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3273
         "(Cs cs', Th th2) \<in> RAG s" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3274
    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
  3275
    from h(3) and assms(2) 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3276
    have "(Th th1, Cs cs') = (Th th, Cs cs) \<or> 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3277
          (Th th1, Cs cs') \<in> RAG s'" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3278
    hence "(n1, n2) \<in> ?R"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3279
    proof
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3280
      assume h1: "(Th th1, Cs cs') = (Th th, Cs cs)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3281
      hence eq_th1: "th1 = th" by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3282
      moreover have "th2 = th''"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3283
      proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3284
        from h1 have "cs' = cs" by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3285
        from assms(3) cs_in[unfolded this] rtree.sgv
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3286
        show ?thesis
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3287
          by (unfold single_valued_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3288
      qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3289
      ultimately show ?thesis using h(1,2) by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3290
    next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3291
      assume "(Th th1, Cs cs') \<in> RAG s'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3292
      with cs_in have "(Th th1, Th th2) \<in> tRAG s'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3293
        by (unfold tRAG_alt_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3294
      from this[folded h(1, 2)] show ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3295
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3296
  } moreover {
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3297
    fix n1 n2
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3298
    assume "(n1, n2) \<in> ?R"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3299
    hence "(n1, n2) \<in>tRAG s' \<or> (n1, n2) = (Th th, Th th'')" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3300
    hence "(n1, n2) \<in> ?L" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3301
    proof
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3302
      assume "(n1, n2) \<in> tRAG s'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3303
      moreover have "... \<subseteq> ?L"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3304
      proof(rule tRAG_mono)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3305
        show "RAG s' \<subseteq> RAG s" by (unfold assms(2), auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3306
      qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3307
      ultimately show ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3308
    next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3309
      assume eq_n: "(n1, n2) = (Th th, Th th'')"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3310
      from assms(2, 3) have "(Cs cs, Th th'') \<in> RAG s" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3311
      moreover have "(Th th, Cs cs) \<in> RAG s" using assms(2) by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3312
      ultimately show ?thesis 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3313
        by (unfold eq_n tRAG_alt_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3314
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3315
  } ultimately show ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3316
qed
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3317
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3318
context valid_trace
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3319
begin
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3320
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3321
lemmas RAG_tRAG_transfer = RAG_tRAG_transfer[OF vt]
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3322
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3323
end
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3324
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3325
lemma cp_alt_def:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3326
  "cp s th =  
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3327
           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
  3328
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3329
  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
  3330
        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
  3331
          (is "Max (_ ` ?L) = Max (_ ` ?R)")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3332
  proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3333
    have "?L = ?R" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3334
    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
  3335
    thus ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3336
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3337
  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
  3338
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3339
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3340
lemma cp_gen_alt_def:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3341
  "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
  3342
    by (auto simp:cp_gen_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3343
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3344
lemma tRAG_nodeE:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3345
  assumes "(n1, n2) \<in> tRAG s"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3346
  obtains th1 th2 where "n1 = Th th1" "n2 = Th th2"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3347
  using assms
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3348
  by (auto simp: tRAG_def wRAG_def hRAG_def tRAG_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3349
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3350
lemma subtree_nodeE:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3351
  assumes "n \<in> subtree (tRAG s) (Th th)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3352
  obtains th1 where "n = Th th1"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3353
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3354
  show ?thesis
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3355
  proof(rule subtreeE[OF assms])
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3356
    assume "n = Th th"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3357
    from that[OF this] show ?thesis .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3358
  next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3359
    assume "Th th \<in> ancestors (tRAG s) n"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3360
    hence "(n, Th th) \<in> (tRAG s)^+" by (auto simp:ancestors_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3361
    hence "\<exists> th1. n = Th th1"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3362
    proof(induct)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3363
      case (base y)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3364
      from tRAG_nodeE[OF this] show ?case by metis
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3365
    next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3366
      case (step y z)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3367
      thus ?case by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3368
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3369
    with that show ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3370
  qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3371
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3372
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3373
lemma tRAG_star_RAG: "(tRAG s)^* \<subseteq> (RAG s)^*"
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3374
proof -
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3375
  have "(wRAG s O hRAG s)^* \<subseteq> (RAG s O RAG s)^*" 
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3376
    by (rule rtrancl_mono, auto simp:RAG_split)
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3377
  also have "... \<subseteq> ((RAG s)^*)^*"
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3378
    by (rule rtrancl_mono, auto)
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3379
  also have "... = (RAG s)^*" by simp
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3380
  finally show ?thesis by (unfold tRAG_def, simp)
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3381
qed
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3382
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3383
lemma tRAG_subtree_RAG: "subtree (tRAG s) x \<subseteq> subtree (RAG s) x"
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3384
proof -
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3385
  { fix a
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3386
    assume "a \<in> subtree (tRAG s) x"
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3387
    hence "(a, x) \<in> (tRAG s)^*" by (auto simp:subtree_def)
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3388
    with tRAG_star_RAG[of s]
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3389
    have "(a, x) \<in> (RAG s)^*" by auto
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3390
    hence "a \<in> subtree (RAG s) x" by (auto simp:subtree_def)
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3391
  } thus ?thesis by auto
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3392
qed
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3393
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3394
lemma tRAG_trancl_eq:
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3395
   "{th'. (Th th', Th th)  \<in> (tRAG s)^+} = 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3396
    {th'. (Th th', Th th)  \<in> (RAG s)^+}"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3397
   (is "?L = ?R")
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3398
proof -
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3399
  { fix th'
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3400
    assume "th' \<in> ?L"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3401
    hence "(Th th', Th th) \<in> (tRAG s)^+" by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3402
    from tranclD[OF this]
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3403
    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
  3404
    from tRAG_subtree_RAG[of s] and this(2)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3405
    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
  3406
    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
  3407
    ultimately have "th' \<in> ?R"  by auto 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3408
  } moreover 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3409
  { fix th'
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3410
    assume "th' \<in> ?R"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3411
    hence "(Th th', Th th) \<in> (RAG s)^+" by (auto)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3412
    from plus_rpath[OF this]
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3413
    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
  3414
    hence "(Th th', Th th) \<in> (tRAG s)^+"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3415
    proof(induct xs arbitrary:th' th rule:length_induct)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3416
      case (1 xs th' th)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3417
      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
  3418
      show ?case
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3419
      proof(cases "xs1")
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3420
        case Nil
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3421
        from 1(2)[unfolded Cons1 Nil]
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3422
        have rp: "rpath (RAG s) (Th th') [x1] (Th th)" .
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3423
        hence "(Th th', x1) \<in> (RAG s)" by (cases, simp)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3424
        then obtain cs where "x1 = Cs cs" 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3425
              by (unfold s_RAG_def, auto)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3426
        from rpath_nnl_lastE[OF rp[unfolded this]]
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3427
        show ?thesis by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3428
      next
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3429
        case (Cons x2 xs2)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3430
        from 1(2)[unfolded Cons1[unfolded this]]
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3431
        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
  3432
        from rpath_edges_on[OF this]
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3433
        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
  3434
        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
  3435
            by (simp add: edges_on_unfold)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3436
        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
  3437
        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
  3438
        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
  3439
            by (simp add: edges_on_unfold)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3440
        from this eds
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3441
        have rg2: "(x1, x2) \<in> RAG s" by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3442
        from this[unfolded eq_x1] 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3443
        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
  3444
        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
  3445
        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
  3446
        from rp have "rpath (RAG s) x2 xs2 (Th th)"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3447
           by  (elim rpath_ConsE, simp)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3448
        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
  3449
        show ?thesis
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3450
        proof(cases "xs2 = []")
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3451
          case True
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3452
          from rpath_nilE[OF rp'[unfolded this]]
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3453
          have "th1 = th" by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3454
          from rt1[unfolded this] show ?thesis by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3455
        next
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3456
          case False
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3457
          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
  3458
          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
  3459
          with rt1 show ?thesis by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3460
        qed
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3461
      qed
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3462
    qed
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3463
    hence "th' \<in> ?L" by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3464
  } ultimately show ?thesis by blast
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3465
qed
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3466
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3467
lemma tRAG_trancl_eq_Th:
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3468
   "{Th th' | th'. (Th th', Th th)  \<in> (tRAG s)^+} = 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3469
    {Th th' | th'. (Th th', Th th)  \<in> (RAG s)^+}"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3470
    using tRAG_trancl_eq by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3471
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3472
lemma dependants_alt_def:
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3473
  "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
  3474
  by (metis eq_RAG s_dependants_def tRAG_trancl_eq)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3475
  
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3476
context valid_trace
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3477
begin
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3478
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3479
lemma count_eq_tRAG_plus:
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3480
  assumes "cntP s th = cntV s th"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3481
  shows "{th'. (Th th', Th th) \<in> (tRAG s)^+} = {}"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3482
  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
  3483
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3484
lemma count_eq_RAG_plus:
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3485
  assumes "cntP s th = cntV s th"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3486
  shows "{th'. (Th th', Th th) \<in> (RAG s)^+} = {}"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3487
  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
  3488
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3489
lemma count_eq_RAG_plus_Th:
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3490
  assumes "cntP s th = cntV s th"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3491
  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
  3492
  using count_eq_RAG_plus[OF assms] by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3493
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3494
lemma count_eq_tRAG_plus_Th:
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3495
  assumes "cntP s th = cntV s th"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3496
  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
  3497
   using count_eq_tRAG_plus[OF assms] by auto
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3498
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3499
end
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3500
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3501
lemma tRAG_subtree_eq: 
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3502
   "(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
  3503
   (is "?L = ?R")
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3504
proof -
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3505
  { fix n 
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3506
    assume h: "n \<in> ?L"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3507
    hence "n \<in> ?R"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3508
    by (smt mem_Collect_eq subsetCE subtree_def subtree_nodeE tRAG_subtree_RAG) 
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3509
  } moreover {
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3510
    fix n
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3511
    assume "n \<in> ?R"
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3512
    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
  3513
      by (auto simp:subtree_def)
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3514
    from rtranclD[OF this(2)]
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3515
    have "n \<in> ?L"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3516
    proof
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3517
      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
  3518
      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
  3519
      thus ?thesis using subtree_def tRAG_trancl_eq by fastforce
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3520
    qed (insert h, auto simp:subtree_def)
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3521
  } ultimately show ?thesis by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3522
qed
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3523
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3524
lemma threads_set_eq: 
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3525
   "the_thread ` (subtree (tRAG s) (Th th)) = 
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3526
                  {th'. Th th' \<in> (subtree (RAG s) (Th th))}" (is "?L = ?R")
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3527
   by (auto intro:rev_image_eqI simp:tRAG_subtree_eq)
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3528
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3529
lemma cp_alt_def1: 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3530
  "cp s th = Max ((the_preced s o the_thread) ` (subtree (tRAG s) (Th th)))"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3531
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3532
  have "(the_preced s ` the_thread ` subtree (tRAG s) (Th th)) =
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3533
       ((the_preced s \<circ> the_thread) ` subtree (tRAG s) (Th th))"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3534
       by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3535
  thus ?thesis by (unfold cp_alt_def, fold threads_set_eq, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3536
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3537
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3538
lemma cp_gen_def_cond: 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3539
  assumes "x = Th th"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3540
  shows "cp s th = cp_gen s (Th th)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3541
by (unfold cp_alt_def1 cp_gen_def, simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3542
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3543
lemma cp_gen_over_set:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3544
  assumes "\<forall> x \<in> A. \<exists> th. x = Th th"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3545
  shows "cp_gen s ` A = (cp s \<circ> the_thread) ` A"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3546
proof(rule f_image_eq)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3547
  fix a
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3548
  assume "a \<in> A"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3549
  from assms[rule_format, OF this]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3550
  obtain th where eq_a: "a = Th th" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3551
  show "cp_gen s a = (cp s \<circ> the_thread) a"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3552
    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
  3553
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3554
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3555
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3556
context valid_trace
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3557
begin
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3558
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3559
lemma RAG_threads:
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3560
  assumes "(Th th) \<in> Field (RAG s)"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3561
  shows "th \<in> threads s"
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3562
  using assms
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3563
  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
  3564
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3565
lemma subtree_tRAG_thread:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3566
  assumes "th \<in> threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3567
  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
  3568
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3569
  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
  3570
    by (unfold tRAG_subtree_eq, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3571
  also have "... \<subseteq> ?R"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3572
  proof
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3573
    fix x
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3574
    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
  3575
    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
  3576
    from this(2)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3577
    show "x \<in> ?R"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3578
    proof(cases rule:subtreeE)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3579
      case 1
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3580
      thus ?thesis by (simp add: assms h(1)) 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3581
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3582
      case 2
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3583
      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
  3584
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3585
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3586
  finally show ?thesis .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 63
diff changeset
  3587
qed
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3588
61
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3589
lemma readys_root:
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3590
  assumes "th \<in> readys s"
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3591
  shows "root (RAG s) (Th th)"
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3592
proof -
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3593
  { fix x
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3594
    assume "x \<in> ancestors (RAG s) (Th th)"
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3595
    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
  3596
    from tranclD[OF this]
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3597
    obtain z where "(Th th, z) \<in> RAG s" by auto
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3598
    with assms(1) have False
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3599
         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
  3600
         by (fold wq_def, blast)
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3601
  } thus ?thesis by (unfold root_def, auto)
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3602
qed
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3603
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3604
lemma readys_in_no_subtree:
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3605
  assumes "th \<in> readys s"
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3606
  and "th' \<noteq> th"
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3607
  shows "Th th \<notin> subtree (RAG s) (Th th')" 
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3608
proof
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3609
   assume "Th th \<in> subtree (RAG s) (Th th')"
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3610
   thus False
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3611
   proof(cases rule:subtreeE)
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3612
      case 1
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3613
      with assms show ?thesis by auto
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3614
   next
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3615
      case 2
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3616
      with readys_root[OF assms(1)]
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3617
      show ?thesis by (auto simp:root_def)
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3618
   qed
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3619
qed
f8194fd6214f CpsG.thy has been cleaned up.
zhangx
parents: 60
diff changeset
  3620
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3621
lemma not_in_thread_isolated:
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3622
  assumes "th \<notin> threads s"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3623
  shows "(Th th) \<notin> Field (RAG s)"
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3624
proof
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3625
  assume "(Th th) \<in> Field (RAG s)"
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3626
  with dm_RAG_threads and range_in assms
60
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3627
  show False by (unfold Field_def, blast)
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3628
qed
f98a95f3deae Main proofs in CpsG.thy completed.
zhangx
parents: 59
diff changeset
  3629
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3630
lemma wf_RAG: "wf (RAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3631
proof(rule finite_acyclic_wf)
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3632
  from finite_RAG show "finite (RAG s)" .
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3633
next
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3634
  from acyclic_RAG show "acyclic (RAG s)" .
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3635
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3636
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3637
lemma sgv_wRAG: "single_valued (wRAG s)"
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3638
  using waiting_unique
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3639
  by (unfold single_valued_def wRAG_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3640
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3641
lemma sgv_hRAG: "single_valued (hRAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3642
  using holding_unique 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3643
  by (unfold single_valued_def hRAG_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3644
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3645
lemma sgv_tRAG: "single_valued (tRAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3646
  by (unfold tRAG_def, rule single_valued_relcomp, 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3647
              insert sgv_wRAG sgv_hRAG, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3648
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3649
lemma acyclic_tRAG: "acyclic (tRAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3650
proof(unfold tRAG_def, rule acyclic_compose)
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3651
  show "acyclic (RAG s)" using acyclic_RAG .
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3652
next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3653
  show "wRAG s \<subseteq> RAG s" unfolding RAG_split by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3654
next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3655
  show "hRAG s \<subseteq> RAG s" unfolding RAG_split by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3656
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3657
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3658
lemma sgv_RAG: "single_valued (RAG s)"
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3659
  using unique_RAG by (auto simp:single_valued_def)
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3660
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3661
lemma rtree_RAG: "rtree (RAG s)"
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3662
  using sgv_RAG acyclic_RAG
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3663
  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
  3664
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 61
diff changeset
  3665
end
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3666
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 61
diff changeset
  3667
sublocale valid_trace < rtree_RAG: rtree "RAG s"
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 61
diff changeset
  3668
proof
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 61
diff changeset
  3669
  show "single_valued (RAG s)"
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 61
diff changeset
  3670
  apply (intro_locales)
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 61
diff changeset
  3671
    by (unfold single_valued_def, 
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3672
        auto intro:unique_RAG)
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 61
diff changeset
  3673
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 61
diff changeset
  3674
  show "acyclic (RAG s)"
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3675
     by (rule acyclic_RAG)
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 61
diff changeset
  3676
qed
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3677
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3678
sublocale valid_trace < rtree_s: rtree "tRAG s"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3679
proof(unfold_locales)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3680
  from sgv_tRAG show "single_valued (tRAG s)" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3681
next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3682
  from acyclic_tRAG show "acyclic (tRAG s)" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3683
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3684
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3685
sublocale valid_trace < fsbtRAGs : fsubtree "RAG s"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3686
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3687
  show "fsubtree (RAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3688
  proof(intro_locales)
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3689
    show "fbranch (RAG s)" using finite_fbranchI[OF finite_RAG] .
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3690
  next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3691
    show "fsubtree_axioms (RAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3692
    proof(unfold fsubtree_axioms_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3693
      from wf_RAG show "wf (RAG s)" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3694
    qed
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
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3698
sublocale valid_trace < fsbttRAGs: fsubtree "tRAG s"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3699
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3700
  have "fsubtree (tRAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3701
  proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3702
    have "fbranch (tRAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3703
    proof(unfold tRAG_def, rule fbranch_compose)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3704
        show "fbranch (wRAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3705
        proof(rule finite_fbranchI)
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3706
           from finite_RAG show "finite (wRAG s)"
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3707
           by (unfold RAG_split, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3708
        qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3709
    next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3710
        show "fbranch (hRAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3711
        proof(rule finite_fbranchI)
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3712
           from finite_RAG 
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3713
           show "finite (hRAG s)" by (unfold RAG_split, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3714
        qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3715
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3716
    moreover have "wf (tRAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3717
    proof(rule wf_subset)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3718
      show "wf (RAG s O RAG s)" using wf_RAG
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3719
        by (fold wf_comp_self, simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3720
    next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3721
      show "tRAG s \<subseteq> (RAG s O RAG s)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3722
        by (unfold tRAG_alt_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3723
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3724
    ultimately show ?thesis
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3725
      by (unfold fsubtree_def fsubtree_axioms_def,auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3726
  qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3727
  from this[folded tRAG_def] show "fsubtree (tRAG s)" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3728
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3729
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3730
lemma Max_UNION: 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3731
  assumes "finite A"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3732
  and "A \<noteq> {}"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3733
  and "\<forall> M \<in> f ` A. finite M"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3734
  and "\<forall> M \<in> f ` A. M \<noteq> {}"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3735
  shows "Max (\<Union>x\<in> A. f x) = Max (Max ` f ` A)" (is "?L = ?R")
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3736
  using assms[simp]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3737
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3738
  have "?L = Max (\<Union>(f ` A))"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3739
    by (fold Union_image_eq, simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3740
  also have "... = ?R"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3741
    by (subst Max_Union, simp+)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3742
  finally show ?thesis .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3743
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3744
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3745
lemma max_Max_eq:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3746
  assumes "finite A"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3747
    and "A \<noteq> {}"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3748
    and "x = y"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3749
  shows "max x (Max A) = Max ({y} \<union> A)" (is "?L = ?R")
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3750
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3751
  have "?R = Max (insert y A)" by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3752
  also from assms have "... = ?L"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3753
      by (subst Max.insert, simp+)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3754
  finally show ?thesis by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3755
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3756
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3757
context valid_trace
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3758
begin
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3759
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3760
(* ddd *)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3761
lemma cp_gen_rec:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3762
  assumes "x = Th th"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3763
  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
  3764
proof(cases "children (tRAG s) x = {}")
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3765
  case True
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3766
  show ?thesis
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3767
    by (unfold True cp_gen_def subtree_children, simp add:assms)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3768
next
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3769
  case False
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3770
  hence [simp]: "children (tRAG s) x \<noteq> {}" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3771
  note fsbttRAGs.finite_subtree[simp]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3772
  have [simp]: "finite (children (tRAG s) x)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3773
     by (intro rev_finite_subset[OF fsbttRAGs.finite_subtree], 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3774
            rule children_subtree)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3775
  { fix r x
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3776
    have "subtree r x \<noteq> {}" by (auto simp:subtree_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3777
  } note this[simp]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3778
  have [simp]: "\<exists>x\<in>children (tRAG s) x. subtree (tRAG s) x \<noteq> {}"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3779
  proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3780
    from False obtain q where "q \<in> children (tRAG s) x" by blast
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3781
    moreover have "subtree (tRAG s) q \<noteq> {}" by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3782
    ultimately show ?thesis by blast
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3783
  qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3784
  have h: "Max ((the_preced s \<circ> the_thread) `
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3785
                ({x} \<union> \<Union>(subtree (tRAG s) ` children (tRAG s) x))) =
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3786
        Max ({the_preced s th} \<union> cp_gen s ` children (tRAG s) x)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3787
                     (is "?L = ?R")
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3788
  proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3789
    let "Max (?f ` (?A \<union> \<Union> (?g ` ?B)))" = ?L
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3790
    let "Max (_ \<union> (?h ` ?B))" = ?R
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3791
    let ?L1 = "?f ` \<Union>(?g ` ?B)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3792
    have eq_Max_L1: "Max ?L1 = Max (?h ` ?B)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3793
    proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3794
      have "?L1 = ?f ` (\<Union> x \<in> ?B.(?g x))" by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3795
      also have "... =  (\<Union> x \<in> ?B. ?f ` (?g x))" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3796
      finally have "Max ?L1 = Max ..." by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3797
      also have "... = Max (Max ` (\<lambda>x. ?f ` subtree (tRAG s) x) ` ?B)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3798
        by (subst Max_UNION, simp+)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3799
      also have "... = Max (cp_gen s ` children (tRAG s) x)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3800
          by (unfold image_comp cp_gen_alt_def, simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3801
      finally show ?thesis .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3802
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3803
    show ?thesis
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3804
    proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3805
      have "?L = Max (?f ` ?A \<union> ?L1)" by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3806
      also have "... = max (the_preced s (the_thread x)) (Max ?L1)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3807
            by (subst Max_Un, simp+)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3808
      also have "... = max (?f x) (Max (?h ` ?B))"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3809
        by (unfold eq_Max_L1, simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3810
      also have "... =?R"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3811
        by (rule max_Max_eq, (simp)+, unfold assms, simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3812
      finally show ?thesis .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3813
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3814
  qed  thus ?thesis 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3815
          by (fold h subtree_children, unfold cp_gen_def, simp) 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3816
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3817
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3818
lemma cp_rec:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3819
  "cp s th = Max ({the_preced s th} \<union> 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3820
                     (cp s o the_thread) ` children (tRAG s) (Th th))"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3821
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3822
  have "Th th = Th th" by simp
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3823
  note h =  cp_gen_def_cond[OF this] cp_gen_rec[OF this]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3824
  show ?thesis 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3825
  proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3826
    have "cp_gen s ` children (tRAG s) (Th th) = 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3827
                (cp s \<circ> the_thread) ` children (tRAG s) (Th th)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3828
    proof(rule cp_gen_over_set)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3829
      show " \<forall>x\<in>children (tRAG s) (Th th). \<exists>th. x = Th th"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3830
        by (unfold tRAG_alt_def, auto simp:children_def)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3831
    qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3832
    thus ?thesis by (subst (1) h(1), unfold h(2), simp)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3833
  qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3834
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3835
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3836
end
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3837
62
031d2ae9c9b8 In the middle of retrofiting ExtGG.thy.
zhangx
parents: 61
diff changeset
  3838
(* keep *)
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3839
lemma next_th_holding:
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3840
  assumes vt: "vt s"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3841
  and nxt: "next_th s th cs th'"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3842
  shows "holding (wq s) th cs"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3843
proof -
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3844
  from nxt[unfolded next_th_def]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3845
  obtain rest where h: "wq s cs = th # rest"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3846
                       "rest \<noteq> []" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3847
                       "th' = hd (SOME q. distinct q \<and> set q = set rest)" by auto
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3848
  thus ?thesis
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3849
    by (unfold cs_holding_def, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3850
qed
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3851
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3852
context valid_trace
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3853
begin
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3854
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3855
lemma next_th_waiting:
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3856
  assumes nxt: "next_th s th cs th'"
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3857
  shows "waiting (wq s) th' cs"
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3858
proof -
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3859
  from nxt[unfolded next_th_def]
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3860
  obtain rest where h: "wq s cs = th # rest"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3861
                       "rest \<noteq> []" 
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3862
                       "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
  3863
  from wq_distinct[of cs, unfolded h]
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3864
  have dst: "distinct (th # rest)" .
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3865
  have in_rest: "th' \<in> set rest"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3866
  proof(unfold h, rule someI2)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3867
    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
  3868
  next
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3869
    fix x assume "distinct x \<and> set x = set rest"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3870
    with h(2)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3871
    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
  3872
  qed
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3873
  hence "th' \<in> set (wq s cs)" by (unfold h(1), auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3874
  moreover have "th' \<noteq> hd (wq s cs)"
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3875
    by (unfold h(1), insert in_rest dst, auto)
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3876
  ultimately show ?thesis by (auto simp:cs_waiting_def)
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3877
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3878
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3879
lemma next_th_RAG:
63
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3880
  assumes nxt: "next_th (s::event list) th cs th'"
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3881
  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
  3882
  using vt assms next_th_holding next_th_waiting
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3883
  by (unfold s_RAG_def, simp)
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3884
b620a2a0806a ExtGG.thy finished, but more comments are needed.
zhangx
parents: 62
diff changeset
  3885
end
58
ad57323fd4d6 Extended RTree.thy
zhangx
parents: 57
diff changeset
  3886
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3887
-- {* A useless definition *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3888
definition cps:: "state \<Rightarrow> (thread \<times> precedence) set"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3889
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
  3890
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  3891
end