PIPBasics.thy~
author zhangx
Thu, 14 Jan 2016 00:55:54 +0800
changeset 74 83ba2d8c859a
parent 68 db196b066b97
child 77 d37703e0c5c4
child 95 8d2cc27f45f3
permissions -rw-r--r--
Moment.thy further simplified.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
     1
theory PIPBasics
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
     2
imports PIPDefs 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
     3
begin
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
     4
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
     5
locale valid_trace = 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
     6
  fixes s
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
     7
  assumes vt : "vt s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
     8
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
     9
locale valid_trace_e = valid_trace +
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    10
  fixes e
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    11
  assumes vt_e: "vt (e#s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    12
begin
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    13
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    14
lemma pip_e: "PIP s e"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    15
  using vt_e by (cases, simp)  
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    16
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    17
end
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    18
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    19
lemma runing_ready: 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    20
  shows "runing s \<subseteq> readys s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    21
  unfolding runing_def readys_def
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    22
  by auto 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    23
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    24
lemma readys_threads:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    25
  shows "readys s \<subseteq> threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    26
  unfolding readys_def
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    27
  by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    28
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    29
lemma wq_v_neq:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    30
   "cs \<noteq> cs' \<Longrightarrow> wq (V thread cs#s) cs' = wq s cs'"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    31
  by (auto simp:wq_def Let_def cp_def split:list.splits)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    32
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    33
context valid_trace
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    34
begin
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    35
68
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
    36
lemma actor_inv: 
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
    37
  assumes "PIP s e"
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
    38
  and "\<not> isCreate e"
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
    39
  shows "actor e \<in> runing s"
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
    40
  using assms
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
    41
  by (induct, auto)
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
    42
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    43
lemma ind [consumes 0, case_names Nil Cons, induct type]:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    44
  assumes "PP []"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    45
     and "(\<And>s e. valid_trace s \<Longrightarrow> valid_trace (e#s) \<Longrightarrow>
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    46
                   PP s \<Longrightarrow> PIP s e \<Longrightarrow> PP (e # s))"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    47
     shows "PP s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    48
proof(rule vt.induct[OF vt])
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    49
  from assms(1) show "PP []" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    50
next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    51
  fix s e
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    52
  assume h: "vt s" "PP s" "PIP s e"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    53
  show "PP (e # s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    54
  proof(cases rule:assms(2))
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    55
    from h(1) show v1: "valid_trace s" by (unfold_locales, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    56
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    57
    from h(1,3) have "vt (e#s)" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    58
    thus "valid_trace (e # s)" by (unfold_locales, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    59
  qed (insert h, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    60
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    61
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    62
lemma wq_distinct: "distinct (wq s cs)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    63
proof(rule ind, simp add:wq_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    64
  fix s e
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    65
  assume h1: "step s e"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    66
  and h2: "distinct (wq s cs)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    67
  thus "distinct (wq (e # s) cs)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    68
  proof(induct rule:step.induct, auto simp: wq_def Let_def split:list.splits)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    69
    fix thread s
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    70
    assume h1: "(Cs cs, Th thread) \<notin> (RAG s)\<^sup>+"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    71
      and h2: "thread \<in> set (wq_fun (schs s) cs)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    72
      and h3: "thread \<in> runing s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    73
    show "False" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    74
    proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    75
      from h3 have "\<And> cs. thread \<in>  set (wq_fun (schs s) cs) \<Longrightarrow> 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    76
                             thread = hd ((wq_fun (schs s) cs))" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    77
        by (simp add:runing_def readys_def s_waiting_def wq_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    78
      from this [OF h2] have "thread = hd (wq_fun (schs s) cs)" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    79
      with h2
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    80
      have "(Cs cs, Th thread) \<in> (RAG s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    81
        by (simp add:s_RAG_def s_holding_def wq_def cs_holding_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    82
      with h1 show False by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    83
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    84
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    85
    fix thread s a list
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    86
    assume dst: "distinct list"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    87
    show "distinct (SOME q. distinct q \<and> set q = set list)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    88
    proof(rule someI2)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    89
      from dst show  "distinct list \<and> set list = set list" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    90
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    91
      fix q assume "distinct q \<and> set q = set list"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    92
      thus "distinct q" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    93
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    94
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    95
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    96
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    97
end
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    98
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    99
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   100
context valid_trace_e
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   101
begin
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   102
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   103
text {*
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   104
  The following lemma shows that only the @{text "P"}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   105
  operation can add new thread into waiting queues. 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   106
  Such kind of lemmas are very obvious, but need to be checked formally.
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   107
  This is a kind of confirmation that our modelling is correct.
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   108
*}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   109
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   110
lemma block_pre: 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   111
  assumes s_ni: "thread \<notin>  set (wq s cs)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   112
  and s_i: "thread \<in> set (wq (e#s) cs)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   113
  shows "e = P thread cs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   114
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   115
  show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   116
  proof(cases e)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   117
    case (P th cs)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   118
    with assms
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   119
    show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   120
      by (auto simp:wq_def Let_def split:if_splits)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   121
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   122
    case (Create th prio)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   123
    with assms show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   124
      by (auto simp:wq_def Let_def split:if_splits)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   125
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   126
    case (Exit th)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   127
    with assms show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   128
      by (auto simp:wq_def Let_def split:if_splits)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   129
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   130
    case (Set th prio)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   131
    with assms show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   132
      by (auto simp:wq_def Let_def split:if_splits)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   133
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   134
    case (V th cs)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   135
    with vt_e assms show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   136
      apply (auto simp:wq_def Let_def split:if_splits)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   137
    proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   138
      fix q qs
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   139
      assume h1: "thread \<notin> set (wq_fun (schs s) cs)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   140
        and h2: "q # qs = wq_fun (schs s) cs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   141
        and h3: "thread \<in> set (SOME q. distinct q \<and> set q = set qs)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   142
        and vt: "vt (V th cs # s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   143
      from h1 and h2[symmetric] have "thread \<notin> set (q # qs)" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   144
      moreover have "thread \<in> set qs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   145
      proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   146
        have "set (SOME q. distinct q \<and> set q = set qs) = set qs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   147
        proof(rule someI2)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   148
          from wq_distinct [of cs]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   149
          and h2[symmetric, folded wq_def]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   150
          show "distinct qs \<and> set qs = set qs" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   151
        next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   152
          fix x assume "distinct x \<and> set x = set qs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   153
          thus "set x = set qs" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   154
        qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   155
        with h3 show ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   156
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   157
      ultimately show "False" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   158
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   159
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   160
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   161
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   162
end
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   163
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   164
text {*
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   165
  The following lemmas is also obvious and shallow. It says
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   166
  that only running thread can request for a critical resource 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   167
  and that the requested resource must be one which is
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   168
  not current held by the thread.
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   169
*}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   170
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   171
lemma p_pre: "\<lbrakk>vt ((P thread cs)#s)\<rbrakk> \<Longrightarrow> 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   172
  thread \<in> runing s \<and> (Cs cs, Th thread)  \<notin> (RAG s)^+"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   173
apply (ind_cases "vt ((P thread cs)#s)")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   174
apply (ind_cases "step s (P thread cs)")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   175
by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   176
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   177
lemma abs1:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   178
  assumes ein: "e \<in> set es"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   179
  and neq: "hd es \<noteq> hd (es @ [x])"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   180
  shows "False"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   181
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   182
  from ein have "es \<noteq> []" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   183
  then obtain e ess where "es = e # ess" by (cases es, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   184
  with neq show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   185
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   186
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   187
lemma q_head: "Q (hd es) \<Longrightarrow> hd es = hd [th\<leftarrow>es . Q th]"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   188
  by (cases es, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   189
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   190
inductive_cases evt_cons: "vt (a#s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   191
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   192
context valid_trace_e
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   193
begin
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   194
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   195
lemma abs2:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   196
  assumes inq: "thread \<in> set (wq s cs)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   197
  and nh: "thread = hd (wq s cs)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   198
  and qt: "thread \<noteq> hd (wq (e#s) cs)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   199
  and inq': "thread \<in> set (wq (e#s) cs)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   200
  shows "False"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   201
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   202
  from vt_e assms show "False"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   203
    apply (cases e)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   204
    apply ((simp split:if_splits add:Let_def wq_def)[1])+
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   205
    apply (insert abs1, fast)[1]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   206
    apply (auto simp:wq_def simp:Let_def split:if_splits list.splits)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   207
  proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   208
    fix th qs
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   209
    assume vt: "vt (V th cs # s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   210
      and th_in: "thread \<in> set (SOME q. distinct q \<and> set q = set qs)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   211
      and eq_wq: "wq_fun (schs s) cs = thread # qs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   212
    show "False"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   213
    proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   214
      from wq_distinct[of cs]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   215
        and eq_wq[folded wq_def] have "distinct (thread#qs)" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   216
      moreover have "thread \<in> set qs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   217
      proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   218
        have "set (SOME q. distinct q \<and> set q = set qs) = set qs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   219
        proof(rule someI2)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   220
          from wq_distinct [of cs]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   221
          and eq_wq [folded wq_def]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   222
          show "distinct qs \<and> set qs = set qs" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   223
        next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   224
          fix x assume "distinct x \<and> set x = set qs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   225
          thus "set x = set qs" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   226
        qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   227
        with th_in show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   228
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   229
      ultimately show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   230
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   231
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   232
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   233
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   234
end
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   235
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   236
context valid_trace
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   237
begin
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   238
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   239
lemma vt_moment: "\<And> t. vt (moment t s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   240
proof(induct rule:ind)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   241
  case Nil
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   242
  thus ?case by (simp add:vt_nil)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   243
next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   244
  case (Cons s e t)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   245
  show ?case
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   246
  proof(cases "t \<ge> length (e#s)")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   247
    case True
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   248
    from True have "moment t (e#s) = e#s" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   249
    thus ?thesis using Cons
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   250
      by (simp add:valid_trace_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   251
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   252
    case False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   253
    from Cons have "vt (moment t s)" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   254
    moreover have "moment t (e#s) = moment t s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   255
    proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   256
      from False have "t \<le> length s" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   257
      from moment_app [OF this, of "[e]"] 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   258
      show ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   259
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   260
    ultimately show ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   261
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   262
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   263
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   264
(* Wrong:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   265
    lemma \<lbrakk>thread \<in> set (wq_fun cs1 s); thread \<in> set (wq_fun cs2 s)\<rbrakk> \<Longrightarrow> cs1 = cs2"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   266
*)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   267
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   268
text {* (* ddd *)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   269
  The nature of the work is like this: since it starts from a very simple and basic 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   270
  model, even intuitively very `basic` and `obvious` properties need to derived from scratch.
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   271
  For instance, the fact 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   272
  that one thread can not be blocked by two critical resources at the same time
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   273
  is obvious, because only running threads can make new requests, if one is waiting for 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   274
  a critical resource and get blocked, it can not make another resource request and get 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   275
  blocked the second time (because it is not running). 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   276
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   277
  To derive this fact, one needs to prove by contraction and 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   278
  reason about time (or @{text "moement"}). The reasoning is based on a generic theorem
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   279
  named @{text "p_split"}, which is about status changing along the time axis. It says if 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   280
  a condition @{text "Q"} is @{text "True"} at a state @{text "s"},
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   281
  but it was @{text "False"} at the very beginning, then there must exits a moment @{text "t"} 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   282
  in the history of @{text "s"} (notice that @{text "s"} itself is essentially the history 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   283
  of events leading to it), such that @{text "Q"} switched 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   284
  from being @{text "False"} to @{text "True"} and kept being @{text "True"}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   285
  till the last moment of @{text "s"}.
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   286
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   287
  Suppose a thread @{text "th"} is blocked
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   288
  on @{text "cs1"} and @{text "cs2"} in some state @{text "s"}, 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   289
  since no thread is blocked at the very beginning, by applying 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   290
  @{text "p_split"} to these two blocking facts, there exist 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   291
  two moments @{text "t1"} and @{text "t2"}  in @{text "s"}, such that 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   292
  @{text "th"} got blocked on @{text "cs1"} and @{text "cs2"} 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   293
  and kept on blocked on them respectively ever since.
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   294
 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   295
  Without lose of generality, we assume @{text "t1"} is earlier than @{text "t2"}.
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   296
  However, since @{text "th"} was blocked ever since memonent @{text "t1"}, so it was still
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   297
  in blocked state at moment @{text "t2"} and could not
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   298
  make any request and get blocked the second time: Contradiction.
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   299
*}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   300
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   301
lemma waiting_unique_pre:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   302
  assumes h11: "thread \<in> set (wq s cs1)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   303
  and h12: "thread \<noteq> hd (wq s cs1)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   304
  assumes h21: "thread \<in> set (wq s cs2)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   305
  and h22: "thread \<noteq> hd (wq s cs2)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   306
  and neq12: "cs1 \<noteq> cs2"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   307
  shows "False"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   308
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   309
  let "?Q cs s" = "thread \<in> set (wq s cs) \<and> thread \<noteq> hd (wq s cs)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   310
  from h11 and h12 have q1: "?Q cs1 s" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   311
  from h21 and h22 have q2: "?Q cs2 s" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   312
  have nq1: "\<not> ?Q cs1 []" by (simp add:wq_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   313
  have nq2: "\<not> ?Q cs2 []" by (simp add:wq_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   314
  from p_split [of "?Q cs1", OF q1 nq1]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   315
  obtain t1 where lt1: "t1 < length s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   316
    and np1: "\<not>(thread \<in> set (wq (moment t1 s) cs1) \<and>
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   317
        thread \<noteq> hd (wq (moment t1 s) cs1))"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   318
    and nn1: "(\<forall>i'>t1. thread \<in> set (wq (moment i' s) cs1) \<and>
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   319
             thread \<noteq> hd (wq (moment i' s) cs1))" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   320
  from p_split [of "?Q cs2", OF q2 nq2]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   321
  obtain t2 where lt2: "t2 < length s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   322
    and np2: "\<not>(thread \<in> set (wq (moment t2 s) cs2) \<and>
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   323
        thread \<noteq> hd (wq (moment t2 s) cs2))"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   324
    and nn2: "(\<forall>i'>t2. thread \<in> set (wq (moment i' s) cs2) \<and>
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   325
             thread \<noteq> hd (wq (moment i' s) cs2))" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   326
  show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   327
  proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   328
    { 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   329
      assume lt12: "t1 < t2"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   330
      let ?t3 = "Suc t2"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   331
      from lt2 have le_t3: "?t3 \<le> length s" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   332
      from moment_plus [OF this] 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   333
      obtain e where eq_m: "moment ?t3 s = e#moment t2 s" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   334
      have "t2 < ?t3" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   335
      from nn2 [rule_format, OF this] and eq_m
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   336
      have h1: "thread \<in> set (wq (e#moment t2 s) cs2)" and
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   337
        h2: "thread \<noteq> hd (wq (e#moment t2 s) cs2)" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   338
      have "vt (e#moment t2 s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   339
      proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   340
        from vt_moment 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   341
        have "vt (moment ?t3 s)" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   342
        with eq_m show ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   343
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   344
      then interpret vt_e: valid_trace_e "moment t2 s" "e"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   345
        by (unfold_locales, auto, cases, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   346
      have ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   347
      proof(cases "thread \<in> set (wq (moment t2 s) cs2)")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   348
        case True
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   349
        from True and np2 have eq_th: "thread = hd (wq (moment t2 s) cs2)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   350
          by auto 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   351
        from vt_e.abs2 [OF True eq_th h2 h1]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   352
        show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   353
      next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   354
        case False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   355
        from vt_e.block_pre[OF False h1]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   356
        have "e = P thread cs2" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   357
        with vt_e.vt_e have "vt ((P thread cs2)# moment t2 s)" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   358
        from p_pre [OF this] have "thread \<in> runing (moment t2 s)" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   359
        with runing_ready have "thread \<in> readys (moment t2 s)" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   360
        with nn1 [rule_format, OF lt12]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   361
        show ?thesis  by (simp add:readys_def wq_def s_waiting_def, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   362
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   363
    } moreover {
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   364
      assume lt12: "t2 < t1"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   365
      let ?t3 = "Suc t1"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   366
      from lt1 have le_t3: "?t3 \<le> length s" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   367
      from moment_plus [OF this] 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   368
      obtain e where eq_m: "moment ?t3 s = e#moment t1 s" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   369
      have lt_t3: "t1 < ?t3" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   370
      from nn1 [rule_format, OF this] and eq_m
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   371
      have h1: "thread \<in> set (wq (e#moment t1 s) cs1)" and
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   372
        h2: "thread \<noteq> hd (wq (e#moment t1 s) cs1)" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   373
      have "vt  (e#moment t1 s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   374
      proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   375
        from vt_moment
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   376
        have "vt (moment ?t3 s)" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   377
        with eq_m show ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   378
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   379
      then interpret vt_e: valid_trace_e "moment t1 s" e
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   380
        by (unfold_locales, auto, cases, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   381
      have ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   382
      proof(cases "thread \<in> set (wq (moment t1 s) cs1)")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   383
        case True
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   384
        from True and np1 have eq_th: "thread = hd (wq (moment t1 s) cs1)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   385
          by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   386
        from vt_e.abs2 True eq_th h2 h1
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   387
        show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   388
      next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   389
        case False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   390
        from vt_e.block_pre [OF False h1]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   391
        have "e = P thread cs1" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   392
        with vt_e.vt_e have "vt ((P thread cs1)# moment t1 s)" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   393
        from p_pre [OF this] have "thread \<in> runing (moment t1 s)" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   394
        with runing_ready have "thread \<in> readys (moment t1 s)" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   395
        with nn2 [rule_format, OF lt12]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   396
        show ?thesis  by (simp add:readys_def wq_def s_waiting_def, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   397
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   398
    } moreover {
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   399
      assume eqt12: "t1 = t2"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   400
      let ?t3 = "Suc t1"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   401
      from lt1 have le_t3: "?t3 \<le> length s" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   402
      from moment_plus [OF this] 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   403
      obtain e where eq_m: "moment ?t3 s = e#moment t1 s" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   404
      have lt_t3: "t1 < ?t3" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   405
      from nn1 [rule_format, OF this] and eq_m
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   406
      have h1: "thread \<in> set (wq (e#moment t1 s) cs1)" and
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   407
        h2: "thread \<noteq> hd (wq (e#moment t1 s) cs1)" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   408
      have vt_e: "vt (e#moment t1 s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   409
      proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   410
        from vt_moment
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   411
        have "vt (moment ?t3 s)" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   412
        with eq_m show ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   413
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   414
      then interpret vt_e: valid_trace_e "moment t1 s" e
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   415
        by (unfold_locales, auto, cases, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   416
      have ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   417
      proof(cases "thread \<in> set (wq (moment t1 s) cs1)")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   418
        case True
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   419
        from True and np1 have eq_th: "thread = hd (wq (moment t1 s) cs1)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   420
          by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   421
        from vt_e.abs2 [OF True eq_th h2 h1]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   422
        show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   423
      next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   424
        case False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   425
        from vt_e.block_pre [OF False h1]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   426
        have eq_e1: "e = P thread cs1" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   427
        have lt_t3: "t1 < ?t3" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   428
        with eqt12 have "t2 < ?t3" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   429
        from nn2 [rule_format, OF this] and eq_m and eqt12
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   430
        have h1: "thread \<in> set (wq (e#moment t2 s) cs2)" and
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   431
          h2: "thread \<noteq> hd (wq (e#moment t2 s) cs2)" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   432
        show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   433
        proof(cases "thread \<in> set (wq (moment t2 s) cs2)")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   434
          case True
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   435
          from True and np2 have eq_th: "thread = hd (wq (moment t2 s) cs2)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   436
            by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   437
          from vt_e and eqt12 have "vt (e#moment t2 s)" by simp 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   438
          then interpret vt_e2: valid_trace_e "moment t2 s" e
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   439
            by (unfold_locales, auto, cases, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   440
          from vt_e2.abs2 [OF True eq_th h2 h1]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   441
          show ?thesis .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   442
        next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   443
          case False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   444
          have "vt (e#moment t2 s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   445
          proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   446
            from vt_moment eqt12
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   447
            have "vt (moment (Suc t2) s)" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   448
            with eq_m eqt12 show ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   449
          qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   450
          then interpret vt_e2: valid_trace_e "moment t2 s" e
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   451
            by (unfold_locales, auto, cases, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   452
          from vt_e2.block_pre [OF False h1]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   453
          have "e = P thread cs2" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   454
          with eq_e1 neq12 show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   455
        qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   456
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   457
    } ultimately show ?thesis by arith
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   458
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   459
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   460
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   461
text {*
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   462
  This lemma is a simple corrolary of @{text "waiting_unique_pre"}.
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   463
*}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   464
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   465
lemma waiting_unique:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   466
  assumes "waiting s th cs1"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   467
  and "waiting s th cs2"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   468
  shows "cs1 = cs2"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   469
using waiting_unique_pre assms
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   470
unfolding wq_def s_waiting_def
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   471
by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   472
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   473
end
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   474
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   475
(* not used *)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   476
text {*
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   477
  Every thread can only be blocked on one critical resource, 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   478
  symmetrically, every critical resource can only be held by one thread. 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   479
  This fact is much more easier according to our definition. 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   480
*}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   481
lemma held_unique:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   482
  assumes "holding (s::event list) th1 cs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   483
  and "holding s th2 cs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   484
  shows "th1 = th2"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   485
 by (insert assms, unfold s_holding_def, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   486
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   487
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   488
lemma last_set_lt: "th \<in> threads s \<Longrightarrow> last_set th s < length s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   489
  apply (induct s, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   490
  by (case_tac a, auto split:if_splits)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   491
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   492
lemma last_set_unique: 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   493
  "\<lbrakk>last_set th1 s = last_set th2 s; th1 \<in> threads s; th2 \<in> threads s\<rbrakk>
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   494
          \<Longrightarrow> th1 = th2"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   495
  apply (induct s, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   496
  by (case_tac a, auto split:if_splits dest:last_set_lt)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   497
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   498
lemma preced_unique : 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   499
  assumes pcd_eq: "preced th1 s = preced th2 s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   500
  and th_in1: "th1 \<in> threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   501
  and th_in2: " th2 \<in> threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   502
  shows "th1 = th2"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   503
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   504
  from pcd_eq have "last_set th1 s = last_set th2 s" by (simp add:preced_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   505
  from last_set_unique [OF this th_in1 th_in2]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   506
  show ?thesis .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   507
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   508
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   509
lemma preced_linorder: 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   510
  assumes neq_12: "th1 \<noteq> th2"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   511
  and th_in1: "th1 \<in> threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   512
  and th_in2: " th2 \<in> threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   513
  shows "preced th1 s < preced th2 s \<or> preced th1 s > preced th2 s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   514
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   515
  from preced_unique [OF _ th_in1 th_in2] and neq_12 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   516
  have "preced th1 s \<noteq> preced th2 s" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   517
  thus ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   518
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   519
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   520
(* An aux lemma used later *)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   521
lemma unique_minus:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   522
  fixes x y z r
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   523
  assumes unique: "\<And> a b c. \<lbrakk>(a, b) \<in> r; (a, c) \<in> r\<rbrakk> \<Longrightarrow> b = c"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   524
  and xy: "(x, y) \<in> r"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   525
  and xz: "(x, z) \<in> r^+"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   526
  and neq: "y \<noteq> z"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   527
  shows "(y, z) \<in> r^+"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   528
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   529
 from xz and neq show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   530
 proof(induct)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   531
   case (base ya)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   532
   have "(x, ya) \<in> r" by fact
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   533
   from unique [OF xy this] have "y = ya" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   534
   with base show ?case by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   535
 next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   536
   case (step ya z)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   537
   show ?case
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   538
   proof(cases "y = ya")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   539
     case True
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   540
     from step True show ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   541
   next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   542
     case False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   543
     from step False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   544
     show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   545
   qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   546
 qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   547
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   548
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   549
lemma unique_base:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   550
  fixes r x y z
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   551
  assumes unique: "\<And> a b c. \<lbrakk>(a, b) \<in> r; (a, c) \<in> r\<rbrakk> \<Longrightarrow> b = c"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   552
  and xy: "(x, y) \<in> r"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   553
  and xz: "(x, z) \<in> r^+"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   554
  and neq_yz: "y \<noteq> z"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   555
  shows "(y, z) \<in> r^+"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   556
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   557
  from xz neq_yz show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   558
  proof(induct)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   559
    case (base ya)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   560
    from xy unique base show ?case by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   561
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   562
    case (step ya z)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   563
    show ?case
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   564
    proof(cases "y = ya")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   565
      case True
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   566
      from True step show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   567
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   568
      case False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   569
      from False step 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   570
      have "(y, ya) \<in> r\<^sup>+" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   571
      with step show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   572
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   573
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   574
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   575
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   576
lemma unique_chain:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   577
  fixes r x y z
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   578
  assumes unique: "\<And> a b c. \<lbrakk>(a, b) \<in> r; (a, c) \<in> r\<rbrakk> \<Longrightarrow> b = c"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   579
  and xy: "(x, y) \<in> r^+"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   580
  and xz: "(x, z) \<in> r^+"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   581
  and neq_yz: "y \<noteq> z"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   582
  shows "(y, z) \<in> r^+ \<or> (z, y) \<in> r^+"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   583
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   584
  from xy xz neq_yz show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   585
  proof(induct)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   586
    case (base y)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   587
    have h1: "(x, y) \<in> r" and h2: "(x, z) \<in> r\<^sup>+" and h3: "y \<noteq> z" using base by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   588
    from unique_base [OF _ h1 h2 h3] and unique show ?case by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   589
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   590
    case (step y za)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   591
    show ?case
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   592
    proof(cases "y = z")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   593
      case True
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   594
      from True step show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   595
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   596
      case False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   597
      from False step have "(y, z) \<in> r\<^sup>+ \<or> (z, y) \<in> r\<^sup>+" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   598
      thus ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   599
      proof
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   600
        assume "(z, y) \<in> r\<^sup>+"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   601
        with step have "(z, za) \<in> r\<^sup>+" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   602
        thus ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   603
      next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   604
        assume h: "(y, z) \<in> r\<^sup>+"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   605
        from step have yza: "(y, za) \<in> r" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   606
        from step have "za \<noteq> z" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   607
        from unique_minus [OF _ yza h this] and unique
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   608
        have "(za, z) \<in> r\<^sup>+" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   609
        thus ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   610
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   611
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   612
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   613
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   614
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   615
text {*
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   616
  The following three lemmas show that @{text "RAG"} does not change
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   617
  by the happening of @{text "Set"}, @{text "Create"} and @{text "Exit"}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   618
  events, respectively.
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   619
*}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   620
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   621
lemma RAG_set_unchanged: "(RAG (Set th prio # s)) = RAG s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   622
apply (unfold s_RAG_def s_waiting_def wq_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   623
by (simp add:Let_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   624
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   625
lemma RAG_create_unchanged: "(RAG (Create th prio # s)) = RAG s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   626
apply (unfold s_RAG_def s_waiting_def wq_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   627
by (simp add:Let_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   628
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   629
lemma RAG_exit_unchanged: "(RAG (Exit th # s)) = RAG s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   630
apply (unfold s_RAG_def s_waiting_def wq_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   631
by (simp add:Let_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   632
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   633
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   634
text {* 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   635
  The following lemmas are used in the proof of 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   636
  lemma @{text "step_RAG_v"}, which characterizes how the @{text "RAG"} is changed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   637
  by @{text "V"}-events. 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   638
  However, since our model is very concise, such  seemingly obvious lemmas need to be derived from scratch,
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   639
  starting from the model definitions.
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   640
*}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   641
lemma step_v_hold_inv[elim_format]:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   642
  "\<And>c t. \<lbrakk>vt (V th cs # s); 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   643
          \<not> holding (wq s) t c; holding (wq (V th cs # s)) t c\<rbrakk> \<Longrightarrow> 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   644
            next_th s th cs t \<and> c = cs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   645
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   646
  fix c t
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   647
  assume vt: "vt (V th cs # s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   648
    and nhd: "\<not> holding (wq s) t c"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   649
    and hd: "holding (wq (V th cs # s)) t c"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   650
  show "next_th s th cs t \<and> c = cs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   651
  proof(cases "c = cs")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   652
    case False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   653
    with nhd hd show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   654
      by (unfold cs_holding_def wq_def, auto simp:Let_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   655
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   656
    case True
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   657
    with step_back_step [OF vt] 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   658
    have "step s (V th c)" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   659
    hence "next_th s th cs t"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   660
    proof(cases)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   661
      assume "holding s th c"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   662
      with nhd hd show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   663
        apply (unfold s_holding_def cs_holding_def wq_def next_th_def,
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   664
               auto simp:Let_def split:list.splits if_splits)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   665
        proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   666
          assume " hd (SOME q. distinct q \<and> q = []) \<in> set (SOME q. distinct q \<and> q = [])"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   667
          moreover have "\<dots> = set []"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   668
          proof(rule someI2)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   669
            show "distinct [] \<and> [] = []" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   670
          next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   671
            fix x assume "distinct x \<and> x = []"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   672
            thus "set x = set []" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   673
          qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   674
          ultimately show False by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   675
        next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   676
          assume " hd (SOME q. distinct q \<and> q = []) \<in> set (SOME q. distinct q \<and> q = [])"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   677
          moreover have "\<dots> = set []"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   678
          proof(rule someI2)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   679
            show "distinct [] \<and> [] = []" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   680
          next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   681
            fix x assume "distinct x \<and> x = []"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   682
            thus "set x = set []" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   683
          qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   684
          ultimately show False by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   685
        qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   686
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   687
    with True show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   688
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   689
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   690
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   691
text {* 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   692
  The following @{text "step_v_wait_inv"} is also an obvious lemma, which, however, needs to be
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   693
  derived from scratch, which confirms the correctness of the definition of @{text "next_th"}.
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   694
*}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   695
lemma step_v_wait_inv[elim_format]:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   696
    "\<And>t c. \<lbrakk>vt (V th cs # s); \<not> waiting (wq (V th cs # s)) t c; waiting (wq s) t c
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   697
           \<rbrakk>
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   698
          \<Longrightarrow> (next_th s th cs t \<and> cs = c)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   699
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   700
  fix t c 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   701
  assume vt: "vt (V th cs # s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   702
    and nw: "\<not> waiting (wq (V th cs # s)) t c"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   703
    and wt: "waiting (wq s) t c"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   704
  from vt interpret vt_v: valid_trace_e s "V th cs" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   705
    by  (cases, unfold_locales, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   706
  show "next_th s th cs t \<and> cs = c"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   707
  proof(cases "cs = c")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   708
    case False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   709
    with nw wt show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   710
      by (auto simp:cs_waiting_def wq_def Let_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   711
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   712
    case True
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   713
    from nw[folded True] wt[folded True]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   714
    have "next_th s th cs t"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   715
      apply (unfold next_th_def, auto simp:cs_waiting_def wq_def Let_def split:list.splits)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   716
    proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   717
      fix a list
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   718
      assume t_in: "t \<in> set list"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   719
        and t_ni: "t \<notin> set (SOME q. distinct q \<and> set q = set list)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   720
        and eq_wq: "wq_fun (schs s) cs = a # list"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   721
      have " set (SOME q. distinct q \<and> set q = set list) = set list"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   722
      proof(rule someI2)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   723
        from vt_v.wq_distinct[of cs] and eq_wq[folded wq_def]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   724
        show "distinct list \<and> set list = set list" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   725
      next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   726
        show "\<And>x. distinct x \<and> set x = set list \<Longrightarrow> set x = set list"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   727
          by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   728
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   729
      with t_ni and t_in show "a = th" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   730
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   731
      fix a list
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   732
      assume t_in: "t \<in> set list"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   733
        and t_ni: "t \<notin> set (SOME q. distinct q \<and> set q = set list)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   734
        and eq_wq: "wq_fun (schs s) cs = a # list"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   735
      have " set (SOME q. distinct q \<and> set q = set list) = set list"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   736
      proof(rule someI2)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   737
        from vt_v.wq_distinct[of cs] and eq_wq[folded wq_def]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   738
        show "distinct list \<and> set list = set list" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   739
      next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   740
        show "\<And>x. distinct x \<and> set x = set list \<Longrightarrow> set x = set list"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   741
          by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   742
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   743
      with t_ni and t_in show "t = hd (SOME q. distinct q \<and> set q = set list)" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   744
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   745
      fix a list
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   746
      assume eq_wq: "wq_fun (schs s) cs = a # list"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   747
      from step_back_step[OF vt]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   748
      show "a = th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   749
      proof(cases)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   750
        assume "holding s th cs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   751
        with eq_wq show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   752
          by (unfold s_holding_def wq_def, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   753
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   754
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   755
    with True show ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   756
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   757
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   758
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   759
lemma step_v_not_wait[consumes 3]:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   760
  "\<lbrakk>vt (V th cs # s); next_th s th cs t; waiting (wq (V th cs # s)) t cs\<rbrakk> \<Longrightarrow> False"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   761
  by (unfold next_th_def cs_waiting_def wq_def, auto simp:Let_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   762
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   763
lemma step_v_release:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   764
  "\<lbrakk>vt (V th cs # s); holding (wq (V th cs # s)) th cs\<rbrakk> \<Longrightarrow> False"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   765
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   766
  assume vt: "vt (V th cs # s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   767
    and hd: "holding (wq (V th cs # s)) th cs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   768
  from vt interpret vt_v: valid_trace_e s "V th cs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   769
    by (cases, unfold_locales, simp+)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   770
  from step_back_step [OF vt] and hd
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   771
  show "False"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   772
  proof(cases)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   773
    assume "holding (wq (V th cs # s)) th cs" and "holding s th cs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   774
    thus ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   775
      apply (unfold s_holding_def wq_def cs_holding_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   776
      apply (auto simp:Let_def split:list.splits)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   777
    proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   778
      fix list
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   779
      assume eq_wq[folded wq_def]: 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   780
        "wq_fun (schs s) cs = hd (SOME q. distinct q \<and> set q = set list) # list"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   781
      and hd_in: "hd (SOME q. distinct q \<and> set q = set list)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   782
            \<in> set (SOME q. distinct q \<and> set q = set list)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   783
      have "set (SOME q. distinct q \<and> set q = set list) = set list"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   784
      proof(rule someI2)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   785
        from vt_v.wq_distinct[of cs] and eq_wq
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   786
        show "distinct list \<and> set list = set list" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   787
      next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   788
        show "\<And>x. distinct x \<and> set x = set list \<Longrightarrow> set x = set list"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   789
          by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   790
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   791
      moreover have "distinct  (hd (SOME q. distinct q \<and> set q = set list) # list)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   792
      proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   793
        from vt_v.wq_distinct[of cs] and eq_wq
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   794
        show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   795
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   796
      moreover note eq_wq and hd_in
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   797
      ultimately show "False" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   798
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   799
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   800
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   801
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   802
lemma step_v_get_hold:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   803
  "\<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"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   804
  apply (unfold cs_holding_def next_th_def wq_def,
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   805
         auto simp:Let_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   806
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   807
  fix rest
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   808
  assume vt: "vt (V th cs # s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   809
    and eq_wq[folded wq_def]: " wq_fun (schs s) cs = th # rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   810
    and nrest: "rest \<noteq> []"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   811
    and ni: "hd (SOME q. distinct q \<and> set q = set rest)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   812
            \<notin> set (SOME q. distinct q \<and> set q = set rest)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   813
  from vt interpret vt_v: valid_trace_e s "V th cs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   814
    by (cases, unfold_locales, simp+)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   815
  have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   816
  proof(rule someI2)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   817
    from vt_v.wq_distinct[of cs] and eq_wq
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   818
    show "distinct rest \<and> set rest = set rest" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   819
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   820
    fix x assume "distinct x \<and> set x = set rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   821
    hence "set x = set rest" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   822
    with nrest
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   823
    show "x \<noteq> []" by (case_tac x, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   824
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   825
  with ni show "False" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   826
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   827
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   828
lemma step_v_release_inv[elim_format]:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   829
"\<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> 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   830
  c = cs \<and> t = th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   831
  apply (unfold cs_holding_def wq_def, auto simp:Let_def split:if_splits list.splits)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   832
  proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   833
    fix a list
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   834
    assume vt: "vt (V th cs # s)" and eq_wq: "wq_fun (schs s) cs = a # list"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   835
    from step_back_step [OF vt] show "a = th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   836
    proof(cases)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   837
      assume "holding s th cs" with eq_wq
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   838
      show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   839
        by (unfold s_holding_def wq_def, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   840
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   841
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   842
    fix a list
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   843
    assume vt: "vt (V th cs # s)" and eq_wq: "wq_fun (schs s) cs = a # list"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   844
    from step_back_step [OF vt] show "a = th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   845
    proof(cases)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   846
      assume "holding s th cs" with eq_wq
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   847
      show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   848
        by (unfold s_holding_def wq_def, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   849
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   850
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   851
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   852
lemma step_v_waiting_mono:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   853
  "\<And>t c. \<lbrakk>vt (V th cs # s); waiting (wq (V th cs # s)) t c\<rbrakk> \<Longrightarrow> waiting (wq s) t c"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   854
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   855
  fix t c
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   856
  let ?s' = "(V th cs # s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   857
  assume vt: "vt ?s'" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   858
    and wt: "waiting (wq ?s') t c"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   859
  from vt interpret vt_v: valid_trace_e s "V th cs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   860
    by (cases, unfold_locales, simp+)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   861
  show "waiting (wq s) t c"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   862
  proof(cases "c = cs")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   863
    case False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   864
    assume neq_cs: "c \<noteq> cs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   865
    hence "waiting (wq ?s') t c = waiting (wq s) t c"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   866
      by (unfold cs_waiting_def wq_def, auto simp:Let_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   867
    with wt show ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   868
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   869
    case True
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   870
    with wt show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   871
      apply (unfold cs_waiting_def wq_def, auto simp:Let_def split:list.splits)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   872
    proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   873
      fix a list
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   874
      assume not_in: "t \<notin> set list"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   875
        and is_in: "t \<in> set (SOME q. distinct q \<and> set q = set list)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   876
        and eq_wq: "wq_fun (schs s) cs = a # list"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   877
      have "set (SOME q. distinct q \<and> set q = set list) = set list"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   878
      proof(rule someI2)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   879
        from vt_v.wq_distinct [of cs]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   880
        and eq_wq[folded wq_def]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   881
        show "distinct list \<and> set list = set list" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   882
      next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   883
        fix x assume "distinct x \<and> set x = set list"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   884
        thus "set x = set list" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   885
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   886
      with not_in is_in show "t = a" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   887
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   888
      fix list
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   889
      assume is_waiting: "waiting (wq (V th cs # s)) t cs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   890
      and eq_wq: "wq_fun (schs s) cs = t # list"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   891
      hence "t \<in> set list"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   892
        apply (unfold wq_def, auto simp:Let_def cs_waiting_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   893
      proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   894
        assume " t \<in> set (SOME q. distinct q \<and> set q = set list)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   895
        moreover have "\<dots> = set list" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   896
        proof(rule someI2)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   897
          from vt_v.wq_distinct [of cs]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   898
            and eq_wq[folded wq_def]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   899
          show "distinct list \<and> set list = set list" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   900
        next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   901
          fix x assume "distinct x \<and> set x = set list" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   902
          thus "set x = set list" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   903
        qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   904
        ultimately show "t \<in> set list" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   905
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   906
      with eq_wq and vt_v.wq_distinct [of cs, unfolded wq_def]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   907
      show False by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   908
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   909
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   910
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   911
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   912
text {* (* ddd *) 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   913
  The following @{text "step_RAG_v"} lemma charaterizes how @{text "RAG"} is changed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   914
  with the happening of @{text "V"}-events:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   915
*}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   916
lemma step_RAG_v:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   917
fixes th::thread
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   918
assumes vt:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   919
  "vt (V th cs#s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   920
shows "
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   921
  RAG (V th cs # s) =
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   922
  RAG s - {(Cs cs, Th th)} -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   923
  {(Th th', Cs cs) |th'. next_th s th cs th'} \<union>
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   924
  {(Cs cs, Th th') |th'.  next_th s th cs th'}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   925
  apply (insert vt, unfold s_RAG_def) 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   926
  apply (auto split:if_splits list.splits simp:Let_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   927
  apply (auto elim: step_v_waiting_mono step_v_hold_inv 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   928
              step_v_release step_v_wait_inv
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   929
              step_v_get_hold step_v_release_inv)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   930
  apply (erule_tac step_v_not_wait, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   931
  done
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   932
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   933
text {* 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   934
  The following @{text "step_RAG_p"} lemma charaterizes how @{text "RAG"} is changed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   935
  with the happening of @{text "P"}-events:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   936
*}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   937
lemma step_RAG_p:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   938
  "vt (P th cs#s) \<Longrightarrow>
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   939
  RAG (P th cs # s) =  (if (wq s cs = []) then RAG s \<union> {(Cs cs, Th th)}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   940
                                             else RAG s \<union> {(Th th, Cs cs)})"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   941
  apply(simp only: s_RAG_def wq_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   942
  apply (auto split:list.splits prod.splits simp:Let_def wq_def cs_waiting_def cs_holding_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   943
  apply(case_tac "csa = cs", auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   944
  apply(fold wq_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   945
  apply(drule_tac step_back_step)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   946
  apply(ind_cases " step s (P (hd (wq s cs)) cs)")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   947
  apply(simp add:s_RAG_def wq_def cs_holding_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   948
  apply(auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   949
  done
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   950
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   951
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   952
lemma RAG_target_th: "(Th th, x) \<in> RAG (s::state) \<Longrightarrow> \<exists> cs. x = Cs cs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   953
  by (unfold s_RAG_def, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   954
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   955
context valid_trace
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   956
begin
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   957
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   958
text {*
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   959
  The following lemma shows that @{text "RAG"} is acyclic.
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   960
  The overall structure is by induction on the formation of @{text "vt s"}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   961
  and then case analysis on event @{text "e"}, where the non-trivial cases 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   962
  for those for @{text "V"} and @{text "P"} events.
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   963
*}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   964
lemma acyclic_RAG:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   965
  shows "acyclic (RAG s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   966
using vt
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   967
proof(induct)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   968
  case (vt_cons s e)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   969
  interpret vt_s: valid_trace s using vt_cons(1)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   970
    by (unfold_locales, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   971
  assume ih: "acyclic (RAG s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   972
    and stp: "step s e"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   973
    and vt: "vt s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   974
  show ?case
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   975
  proof(cases e)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   976
    case (Create th prio)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   977
    with ih
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   978
    show ?thesis by (simp add:RAG_create_unchanged)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   979
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   980
    case (Exit th)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   981
    with ih show ?thesis by (simp add:RAG_exit_unchanged)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   982
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   983
    case (V th cs)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   984
    from V vt stp have vtt: "vt (V th cs#s)" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   985
    from step_RAG_v [OF this]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   986
    have eq_de: 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   987
      "RAG (e # s) = 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   988
      RAG s - {(Cs cs, Th th)} - {(Th th', Cs cs) |th'. next_th s th cs th'} \<union>
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   989
      {(Cs cs, Th th') |th'. next_th s th cs th'}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   990
      (is "?L = (?A - ?B - ?C) \<union> ?D") by (simp add:V)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   991
    from ih have ac: "acyclic (?A - ?B - ?C)" by (auto elim:acyclic_subset)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   992
    from step_back_step [OF vtt]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   993
    have "step s (V th cs)" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   994
    thus ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   995
    proof(cases)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   996
      assume "holding s th cs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   997
      hence th_in: "th \<in> set (wq s cs)" and
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   998
        eq_hd: "th = hd (wq s cs)" unfolding s_holding_def wq_def by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   999
      then obtain rest where
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1000
        eq_wq: "wq s cs = th#rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1001
        by (cases "wq s cs", auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1002
      show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1003
      proof(cases "rest = []")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1004
        case False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1005
        let ?th' = "hd (SOME q. distinct q \<and> set q = set rest)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1006
        from eq_wq False have eq_D: "?D = {(Cs cs, Th ?th')}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1007
          by (unfold next_th_def, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1008
        let ?E = "(?A - ?B - ?C)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1009
        have "(Th ?th', Cs cs) \<notin> ?E\<^sup>*"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1010
        proof
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1011
          assume "(Th ?th', Cs cs) \<in> ?E\<^sup>*"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1012
          hence " (Th ?th', Cs cs) \<in> ?E\<^sup>+" by (simp add: rtrancl_eq_or_trancl)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1013
          from tranclD [OF this]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1014
          obtain x where th'_e: "(Th ?th', x) \<in> ?E" by blast
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1015
          hence th_d: "(Th ?th', x) \<in> ?A" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1016
          from RAG_target_th [OF this]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1017
          obtain cs' where eq_x: "x = Cs cs'" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1018
          with th_d have "(Th ?th', Cs cs') \<in> ?A" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1019
          hence wt_th': "waiting s ?th' cs'"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1020
            unfolding s_RAG_def s_waiting_def cs_waiting_def wq_def by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1021
          hence "cs' = cs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1022
          proof(rule vt_s.waiting_unique)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1023
            from eq_wq vt_s.wq_distinct[of cs]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1024
            show "waiting s ?th' cs" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1025
              apply (unfold s_waiting_def wq_def, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1026
            proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1027
              assume hd_in: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1028
                and eq_wq: "wq_fun (schs s) cs = th # rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1029
              have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1030
              proof(rule someI2)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1031
                from vt_s.wq_distinct[of cs] and eq_wq
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1032
                show "distinct rest \<and> set rest = set rest" unfolding wq_def by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1033
              next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1034
                fix x assume "distinct x \<and> set x = set rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1035
                with False show "x \<noteq> []" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1036
              qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1037
              hence "hd (SOME q. distinct q \<and> set q = set rest) \<in> 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1038
                set (SOME q. distinct q \<and> set q = set rest)" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1039
              moreover have "\<dots> = set rest" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1040
              proof(rule someI2)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1041
                from vt_s.wq_distinct[of cs] and eq_wq
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1042
                show "distinct rest \<and> set rest = set rest" unfolding wq_def by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1043
              next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1044
                show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1045
              qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1046
              moreover note hd_in
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1047
              ultimately show "hd (SOME q. distinct q \<and> set q = set rest) = th" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1048
            next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1049
              assume hd_in: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1050
                and eq_wq: "wq s cs = hd (SOME q. distinct q \<and> set q = set rest) # rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1051
              have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1052
              proof(rule someI2)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1053
                from vt_s.wq_distinct[of cs] and eq_wq
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1054
                show "distinct rest \<and> set rest = set rest" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1055
              next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1056
                fix x assume "distinct x \<and> set x = set rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1057
                with False show "x \<noteq> []" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1058
              qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1059
              hence "hd (SOME q. distinct q \<and> set q = set rest) \<in> 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1060
                set (SOME q. distinct q \<and> set q = set rest)" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1061
              moreover have "\<dots> = set rest" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1062
              proof(rule someI2)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1063
                from vt_s.wq_distinct[of cs] and eq_wq
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1064
                show "distinct rest \<and> set rest = set rest" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1065
              next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1066
                show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1067
              qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1068
              moreover note hd_in
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1069
              ultimately show False by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1070
            qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1071
          qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1072
          with th'_e eq_x have "(Th ?th', Cs cs) \<in> ?E" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1073
          with False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1074
          show "False" by (auto simp: next_th_def eq_wq)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1075
        qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1076
        with acyclic_insert[symmetric] and ac
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1077
          and eq_de eq_D show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1078
      next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1079
        case True
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1080
        with eq_wq
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1081
        have eq_D: "?D = {}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1082
          by (unfold next_th_def, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1083
        with eq_de ac
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1084
        show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1085
      qed 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1086
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1087
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1088
    case (P th cs)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1089
    from P vt stp have vtt: "vt (P th cs#s)" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1090
    from step_RAG_p [OF this] P
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1091
    have "RAG (e # s) = 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1092
      (if wq s cs = [] then RAG s \<union> {(Cs cs, Th th)} else 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1093
      RAG s \<union> {(Th th, Cs cs)})" (is "?L = ?R")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1094
      by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1095
    moreover have "acyclic ?R"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1096
    proof(cases "wq s cs = []")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1097
      case True
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1098
      hence eq_r: "?R =  RAG s \<union> {(Cs cs, Th th)}" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1099
      have "(Th th, Cs cs) \<notin> (RAG s)\<^sup>*"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1100
      proof
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1101
        assume "(Th th, Cs cs) \<in> (RAG s)\<^sup>*"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1102
        hence "(Th th, Cs cs) \<in> (RAG s)\<^sup>+" by (simp add: rtrancl_eq_or_trancl)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1103
        from tranclD2 [OF this]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1104
        obtain x where "(x, Cs cs) \<in> RAG s" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1105
        with True show False by (auto simp:s_RAG_def cs_waiting_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1106
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1107
      with acyclic_insert ih eq_r show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1108
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1109
      case False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1110
      hence eq_r: "?R =  RAG s \<union> {(Th th, Cs cs)}" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1111
      have "(Cs cs, Th th) \<notin> (RAG s)\<^sup>*"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1112
      proof
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1113
        assume "(Cs cs, Th th) \<in> (RAG s)\<^sup>*"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1114
        hence "(Cs cs, Th th) \<in> (RAG s)\<^sup>+" by (simp add: rtrancl_eq_or_trancl)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1115
        moreover from step_back_step [OF vtt] have "step s (P th cs)" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1116
        ultimately show False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1117
        proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1118
          show " \<lbrakk>(Cs cs, Th th) \<in> (RAG s)\<^sup>+; step s (P th cs)\<rbrakk> \<Longrightarrow> False"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1119
            by (ind_cases "step s (P th cs)", simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1120
        qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1121
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1122
      with acyclic_insert ih eq_r show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1123
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1124
      ultimately show ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1125
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1126
      case (Set thread prio)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1127
      with ih
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1128
      thm RAG_set_unchanged
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1129
      show ?thesis by (simp add:RAG_set_unchanged)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1130
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1131
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1132
    case vt_nil
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1133
    show "acyclic (RAG ([]::state))"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1134
      by (auto simp: s_RAG_def cs_waiting_def 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1135
        cs_holding_def wq_def acyclic_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1136
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1137
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1138
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1139
lemma finite_RAG:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1140
  shows "finite (RAG s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1141
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1142
  from vt show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1143
  proof(induct)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1144
    case (vt_cons s e)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1145
    interpret vt_s: valid_trace s using vt_cons(1)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1146
      by (unfold_locales, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1147
    assume ih: "finite (RAG s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1148
      and stp: "step s e"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1149
      and vt: "vt s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1150
    show ?case
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1151
    proof(cases e)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1152
      case (Create th prio)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1153
      with ih
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1154
      show ?thesis by (simp add:RAG_create_unchanged)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1155
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1156
      case (Exit th)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1157
      with ih show ?thesis by (simp add:RAG_exit_unchanged)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1158
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1159
      case (V th cs)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1160
      from V vt stp have vtt: "vt (V th cs#s)" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1161
      from step_RAG_v [OF this]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1162
      have eq_de: "RAG (e # s) = 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1163
                   RAG s - {(Cs cs, Th th)} - {(Th th', Cs cs) |th'. next_th s th cs th'} \<union>
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1164
                      {(Cs cs, Th th') |th'. next_th s th cs th'}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1165
"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1166
        (is "?L = (?A - ?B - ?C) \<union> ?D") by (simp add:V)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1167
      moreover from ih have ac: "finite (?A - ?B - ?C)" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1168
      moreover have "finite ?D"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1169
      proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1170
        have "?D = {} \<or> (\<exists> a. ?D = {a})" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1171
          by (unfold next_th_def, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1172
        thus ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1173
        proof
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1174
          assume h: "?D = {}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1175
          show ?thesis by (unfold h, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1176
        next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1177
          assume "\<exists> a. ?D = {a}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1178
          thus ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1179
            by (metis finite.simps)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1180
        qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1181
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1182
      ultimately show ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1183
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1184
      case (P th cs)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1185
      from P vt stp have vtt: "vt (P th cs#s)" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1186
      from step_RAG_p [OF this] P
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1187
      have "RAG (e # s) = 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1188
              (if wq s cs = [] then RAG s \<union> {(Cs cs, Th th)} else 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1189
                                    RAG s \<union> {(Th th, Cs cs)})" (is "?L = ?R")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1190
        by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1191
      moreover have "finite ?R"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1192
      proof(cases "wq s cs = []")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1193
        case True
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1194
        hence eq_r: "?R =  RAG s \<union> {(Cs cs, Th th)}" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1195
        with True and ih show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1196
      next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1197
        case False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1198
        hence "?R = RAG s \<union> {(Th th, Cs cs)}" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1199
        with False and ih show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1200
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1201
      ultimately show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1202
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1203
      case (Set thread prio)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1204
      with ih
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1205
      show ?thesis by (simp add:RAG_set_unchanged)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1206
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1207
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1208
    case vt_nil
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1209
    show "finite (RAG ([]::state))"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1210
      by (auto simp: s_RAG_def cs_waiting_def 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1211
                   cs_holding_def wq_def acyclic_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1212
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1213
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1214
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1215
text {* Several useful lemmas *}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1216
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1217
lemma wf_dep_converse: 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1218
  shows "wf ((RAG s)^-1)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1219
proof(rule finite_acyclic_wf_converse)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1220
  from finite_RAG 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1221
  show "finite (RAG s)" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1222
next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1223
  from acyclic_RAG
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1224
  show "acyclic (RAG s)" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1225
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1226
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1227
end
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1228
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1229
lemma hd_np_in: "x \<in> set l \<Longrightarrow> hd l \<in> set l"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1230
  by (induct l, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1231
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1232
lemma th_chasing: "(Th th, Cs cs) \<in> RAG (s::state) \<Longrightarrow> \<exists> th'. (Cs cs, Th th') \<in> RAG s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1233
  by (auto simp:s_RAG_def s_holding_def cs_holding_def cs_waiting_def wq_def dest:hd_np_in)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1234
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1235
context valid_trace
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1236
begin
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1237
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1238
lemma wq_threads: 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1239
  assumes h: "th \<in> set (wq s cs)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1240
  shows "th \<in> threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1241
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1242
 from vt and h show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1243
  proof(induct arbitrary: th cs)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1244
    case (vt_cons s e)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1245
    interpret vt_s: valid_trace s
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1246
      using vt_cons(1) by (unfold_locales, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1247
    assume ih: "\<And>th cs. th \<in> set (wq s cs) \<Longrightarrow> th \<in> threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1248
      and stp: "step s e"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1249
      and vt: "vt s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1250
      and h: "th \<in> set (wq (e # s) cs)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1251
    show ?case
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1252
    proof(cases e)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1253
      case (Create th' prio)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1254
      with ih h show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1255
        by (auto simp:wq_def Let_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1256
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1257
      case (Exit th')
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1258
      with stp ih h show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1259
        apply (auto simp:wq_def Let_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1260
        apply (ind_cases "step s (Exit th')")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1261
        apply (auto simp:runing_def readys_def s_holding_def s_waiting_def holdents_def
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1262
               s_RAG_def s_holding_def cs_holding_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1263
        done
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1264
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1265
      case (V th' cs')
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1266
      show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1267
      proof(cases "cs' = cs")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1268
        case False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1269
        with h
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1270
        show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1271
          apply(unfold wq_def V, auto simp:Let_def V split:prod.splits, fold wq_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1272
          by (drule_tac ih, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1273
      next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1274
        case True
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1275
        from h
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1276
        show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1277
        proof(unfold V wq_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1278
          assume th_in: "th \<in> set (wq_fun (schs (V th' cs' # s)) cs)" (is "th \<in> set ?l")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1279
          show "th \<in> threads (V th' cs' # s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1280
          proof(cases "cs = cs'")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1281
            case False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1282
            hence "?l = wq_fun (schs s) cs" by (simp add:Let_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1283
            with th_in have " th \<in> set (wq s cs)" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1284
              by (fold wq_def, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1285
            from ih [OF this] show ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1286
          next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1287
            case True
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1288
            show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1289
            proof(cases "wq_fun (schs s) cs'")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1290
              case Nil
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1291
              with h V show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1292
                apply (auto simp:wq_def Let_def split:if_splits)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1293
                by (fold wq_def, drule_tac ih, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1294
            next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1295
              case (Cons a rest)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1296
              assume eq_wq: "wq_fun (schs s) cs' = a # rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1297
              with h V show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1298
                apply (auto simp:Let_def wq_def split:if_splits)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1299
              proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1300
                assume th_in: "th \<in> set (SOME q. distinct q \<and> set q = set rest)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1301
                have "set (SOME q. distinct q \<and> set q = set rest) = set rest" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1302
                proof(rule someI2)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1303
                  from vt_s.wq_distinct[of cs'] and eq_wq[folded wq_def]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1304
                  show "distinct rest \<and> set rest = set rest" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1305
                next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1306
                  show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1307
                    by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1308
                qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1309
                with eq_wq th_in have "th \<in> set (wq_fun (schs s) cs')" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1310
                from ih[OF this[folded wq_def]] show "th \<in> threads s" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1311
              next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1312
                assume th_in: "th \<in> set (wq_fun (schs s) cs)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1313
                from ih[OF this[folded wq_def]]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1314
                show "th \<in> threads s" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1315
              qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1316
            qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1317
          qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1318
        qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1319
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1320
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1321
      case (P th' cs')
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1322
      from h stp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1323
      show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1324
        apply (unfold P wq_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1325
        apply (auto simp:Let_def split:if_splits, fold wq_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1326
        apply (auto intro:ih)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1327
        apply(ind_cases "step s (P th' cs')")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1328
        by (unfold runing_def readys_def, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1329
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1330
      case (Set thread prio)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1331
      with ih h show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1332
        by (auto simp:wq_def Let_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1333
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1334
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1335
    case vt_nil
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1336
    thus ?case by (auto simp:wq_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1337
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1338
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1339
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1340
lemma range_in: "\<lbrakk>(Th th) \<in> Range (RAG (s::state))\<rbrakk> \<Longrightarrow> th \<in> threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1341
  apply(unfold s_RAG_def cs_waiting_def cs_holding_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1342
  by (auto intro:wq_threads)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1343
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1344
lemma readys_v_eq:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1345
  fixes th thread cs rest
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1346
  assumes neq_th: "th \<noteq> thread"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1347
  and eq_wq: "wq s cs = thread#rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1348
  and not_in: "th \<notin>  set rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1349
  shows "(th \<in> readys (V thread cs#s)) = (th \<in> readys s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1350
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1351
  from assms show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1352
    apply (auto simp:readys_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1353
    apply(simp add:s_waiting_def[folded wq_def])
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1354
    apply (erule_tac x = csa in allE)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1355
    apply (simp add:s_waiting_def wq_def Let_def split:if_splits)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1356
    apply (case_tac "csa = cs", simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1357
    apply (erule_tac x = cs in allE)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1358
    apply(auto simp add: s_waiting_def[folded wq_def] Let_def split: list.splits)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1359
    apply(auto simp add: wq_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1360
    apply (auto simp:s_waiting_def wq_def Let_def split:list.splits)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1361
    proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1362
       assume th_nin: "th \<notin> set rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1363
        and th_in: "th \<in> set (SOME q. distinct q \<and> set q = set rest)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1364
        and eq_wq: "wq_fun (schs s) cs = thread # rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1365
      have "set (SOME q. distinct q \<and> set q = set rest) = set rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1366
      proof(rule someI2)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1367
        from wq_distinct[of cs, unfolded wq_def] and eq_wq[unfolded wq_def]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1368
        show "distinct rest \<and> set rest = set rest" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1369
      next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1370
        show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1371
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1372
      with th_nin th_in show False by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1373
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1374
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1375
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1376
text {* \noindent
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1377
  The following lemmas shows that: starting from any node in @{text "RAG"}, 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1378
  by chasing out-going edges, it is always possible to reach a node representing a ready
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1379
  thread. In this lemma, it is the @{text "th'"}.
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1380
*}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1381
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1382
lemma chain_building:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1383
  shows "node \<in> Domain (RAG s) \<longrightarrow> (\<exists> th'. th' \<in> readys s \<and> (node, Th th') \<in> (RAG s)^+)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1384
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1385
  from wf_dep_converse
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1386
  have h: "wf ((RAG s)\<inverse>)" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1387
  show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1388
  proof(induct rule:wf_induct [OF h])
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1389
    fix x
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1390
    assume ih [rule_format]: 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1391
      "\<forall>y. (y, x) \<in> (RAG s)\<inverse> \<longrightarrow> 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1392
           y \<in> Domain (RAG s) \<longrightarrow> (\<exists>th'. th' \<in> readys s \<and> (y, Th th') \<in> (RAG s)\<^sup>+)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1393
    show "x \<in> Domain (RAG s) \<longrightarrow> (\<exists>th'. th' \<in> readys s \<and> (x, Th th') \<in> (RAG s)\<^sup>+)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1394
    proof
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1395
      assume x_d: "x \<in> Domain (RAG s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1396
      show "\<exists>th'. th' \<in> readys s \<and> (x, Th th') \<in> (RAG s)\<^sup>+"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1397
      proof(cases x)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1398
        case (Th th)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1399
        from x_d Th obtain cs where x_in: "(Th th, Cs cs) \<in> RAG s" by (auto simp:s_RAG_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1400
        with Th have x_in_r: "(Cs cs, x) \<in> (RAG s)^-1" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1401
        from th_chasing [OF x_in] obtain th' where "(Cs cs, Th th') \<in> RAG s" by blast
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1402
        hence "Cs cs \<in> Domain (RAG s)" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1403
        from ih [OF x_in_r this] obtain th'
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1404
          where th'_ready: " th' \<in> readys s" and cs_in: "(Cs cs, Th th') \<in> (RAG s)\<^sup>+" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1405
        have "(x, Th th') \<in> (RAG s)\<^sup>+" using Th x_in cs_in by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1406
        with th'_ready show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1407
      next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1408
        case (Cs cs)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1409
        from x_d Cs obtain th' where th'_d: "(Th th', x) \<in> (RAG s)^-1" by (auto simp:s_RAG_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1410
        show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1411
        proof(cases "th' \<in> readys s")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1412
          case True
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1413
          from True and th'_d show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1414
        next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1415
          case False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1416
          from th'_d and range_in  have "th' \<in> threads s" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1417
          with False have "Th th' \<in> Domain (RAG s)" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1418
            by (auto simp:readys_def wq_def s_waiting_def s_RAG_def cs_waiting_def Domain_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1419
          from ih [OF th'_d this]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1420
          obtain th'' where 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1421
            th''_r: "th'' \<in> readys s" and 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1422
            th''_in: "(Th th', Th th'') \<in> (RAG s)\<^sup>+" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1423
          from th'_d and th''_in 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1424
          have "(x, Th th'') \<in> (RAG s)\<^sup>+" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1425
          with th''_r show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1426
        qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1427
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1428
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1429
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1430
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1431
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1432
text {* \noindent
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1433
  The following is just an instance of @{text "chain_building"}.
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1434
*}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1435
lemma th_chain_to_ready:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1436
  assumes th_in: "th \<in> threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1437
  shows "th \<in> readys s \<or> (\<exists> th'. th' \<in> readys s \<and> (Th th, Th th') \<in> (RAG s)^+)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1438
proof(cases "th \<in> readys s")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1439
  case True
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1440
  thus ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1441
next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1442
  case False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1443
  from False and th_in have "Th th \<in> Domain (RAG s)" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1444
    by (auto simp:readys_def s_waiting_def s_RAG_def wq_def cs_waiting_def Domain_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1445
  from chain_building [rule_format, OF this]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1446
  show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1447
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1448
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1449
end
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1450
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1451
lemma waiting_eq: "waiting s th cs = waiting (wq s) th cs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1452
  by  (unfold s_waiting_def cs_waiting_def wq_def, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1453
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1454
lemma holding_eq: "holding (s::state) th cs = holding (wq s) th cs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1455
  by (unfold s_holding_def wq_def cs_holding_def, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1456
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1457
lemma holding_unique: "\<lbrakk>holding (s::state) th1 cs; holding s th2 cs\<rbrakk> \<Longrightarrow> th1 = th2"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1458
  by (unfold s_holding_def cs_holding_def, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1459
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1460
context valid_trace
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1461
begin
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1462
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1463
lemma unique_RAG: "\<lbrakk>(n, n1) \<in> RAG s; (n, n2) \<in> RAG s\<rbrakk> \<Longrightarrow> n1 = n2"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1464
  apply(unfold s_RAG_def, auto, fold waiting_eq holding_eq)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1465
  by(auto elim:waiting_unique holding_unique)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1466
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1467
end
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1468
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1469
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1470
lemma trancl_split: "(a, b) \<in> r^+ \<Longrightarrow> \<exists> c. (a, c) \<in> r"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1471
by (induct rule:trancl_induct, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1472
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1473
context valid_trace
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1474
begin
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1475
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1476
lemma dchain_unique:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1477
  assumes th1_d: "(n, Th th1) \<in> (RAG s)^+"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1478
  and th1_r: "th1 \<in> readys s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1479
  and th2_d: "(n, Th th2) \<in> (RAG s)^+"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1480
  and th2_r: "th2 \<in> readys s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1481
  shows "th1 = th2"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1482
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1483
  { assume neq: "th1 \<noteq> th2"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1484
    hence "Th th1 \<noteq> Th th2" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1485
    from unique_chain [OF _ th1_d th2_d this] and unique_RAG 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1486
    have "(Th th1, Th th2) \<in> (RAG s)\<^sup>+ \<or> (Th th2, Th th1) \<in> (RAG s)\<^sup>+" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1487
    hence "False"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1488
    proof
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1489
      assume "(Th th1, Th th2) \<in> (RAG s)\<^sup>+"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1490
      from trancl_split [OF this]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1491
      obtain n where dd: "(Th th1, n) \<in> RAG s" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1492
      then obtain cs where eq_n: "n = Cs cs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1493
        by (auto simp:s_RAG_def s_holding_def cs_holding_def cs_waiting_def wq_def dest:hd_np_in)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1494
      from dd eq_n have "th1 \<notin> readys s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1495
        by (auto simp:readys_def s_RAG_def wq_def s_waiting_def cs_waiting_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1496
      with th1_r show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1497
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1498
      assume "(Th th2, Th th1) \<in> (RAG s)\<^sup>+"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1499
      from trancl_split [OF this]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1500
      obtain n where dd: "(Th th2, n) \<in> RAG s" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1501
      then obtain cs where eq_n: "n = Cs cs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1502
        by (auto simp:s_RAG_def s_holding_def cs_holding_def cs_waiting_def wq_def dest:hd_np_in)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1503
      from dd eq_n have "th2 \<notin> readys s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1504
        by (auto simp:readys_def wq_def s_RAG_def s_waiting_def cs_waiting_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1505
      with th2_r show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1506
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1507
  } thus ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1508
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1509
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1510
end
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1511
             
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1512
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1513
lemma step_holdents_p_add:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1514
  fixes th cs s
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1515
  assumes vt: "vt (P th cs#s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1516
  and "wq s cs = []"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1517
  shows "holdents (P th cs#s) th = holdents s th \<union> {cs}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1518
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1519
  from assms show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1520
  unfolding  holdents_test step_RAG_p[OF vt] by (auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1521
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1522
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1523
lemma step_holdents_p_eq:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1524
  fixes th cs s
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1525
  assumes vt: "vt (P th cs#s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1526
  and "wq s cs \<noteq> []"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1527
  shows "holdents (P th cs#s) th = holdents s th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1528
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1529
  from assms show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1530
  unfolding  holdents_test step_RAG_p[OF vt] by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1531
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1532
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1533
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1534
lemma (in valid_trace) finite_holding :
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1535
  shows "finite (holdents s th)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1536
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1537
  let ?F = "\<lambda> (x, y). the_cs x"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1538
  from finite_RAG 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1539
  have "finite (RAG s)" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1540
  hence "finite (?F `(RAG s))" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1541
  moreover have "{cs . (Cs cs, Th th) \<in> RAG s} \<subseteq> \<dots>" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1542
  proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1543
    { have h: "\<And> a A f. a \<in> A \<Longrightarrow> f a \<in> f ` A" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1544
      fix x assume "(Cs x, Th th) \<in> RAG s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1545
      hence "?F (Cs x, Th th) \<in> ?F `(RAG s)" by (rule h)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1546
      moreover have "?F (Cs x, Th th) = x" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1547
      ultimately have "x \<in> (\<lambda>(x, y). the_cs x) ` RAG s" by simp 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1548
    } thus ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1549
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1550
  ultimately show ?thesis by (unfold holdents_test, auto intro:finite_subset)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1551
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1552
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1553
lemma cntCS_v_dec: 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1554
  fixes s thread cs
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1555
  assumes vtv: "vt (V thread cs#s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1556
  shows "(cntCS (V thread cs#s) thread + 1) = cntCS s thread"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1557
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1558
  from vtv interpret vt_s: valid_trace s
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1559
    by (cases, unfold_locales, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1560
  from vtv interpret vt_v: valid_trace "V thread cs#s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1561
     by (unfold_locales, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1562
  from step_back_step[OF vtv]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1563
  have cs_in: "cs \<in> holdents s thread" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1564
    apply (cases, unfold holdents_test s_RAG_def, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1565
    by (unfold cs_holding_def s_holding_def wq_def, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1566
  moreover have cs_not_in: 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1567
    "(holdents (V thread cs#s) thread) = holdents s thread - {cs}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1568
    apply (insert vt_s.wq_distinct[of cs])
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1569
    apply (unfold holdents_test, unfold step_RAG_v[OF vtv],
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1570
            auto simp:next_th_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1571
  proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1572
    fix rest
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1573
    assume dst: "distinct (rest::thread list)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1574
      and ne: "rest \<noteq> []"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1575
    and hd_ni: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1576
    moreover have "set (SOME q. distinct q \<and> set q = set rest) = set rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1577
    proof(rule someI2)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1578
      from dst show "distinct rest \<and> set rest = set rest" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1579
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1580
      show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1581
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1582
    ultimately have "hd (SOME q. distinct q \<and> set q = set rest) \<notin> 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1583
                     set (SOME q. distinct q \<and> set q = set rest)" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1584
    moreover have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1585
    proof(rule someI2)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1586
      from dst show "distinct rest \<and> set rest = set rest" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1587
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1588
      fix x assume " distinct x \<and> set x = set rest" with ne
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1589
      show "x \<noteq> []" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1590
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1591
    ultimately 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1592
    show "(Cs cs, Th (hd (SOME q. distinct q \<and> set q = set rest))) \<in> RAG s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1593
      by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1594
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1595
    fix rest
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1596
    assume dst: "distinct (rest::thread list)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1597
      and ne: "rest \<noteq> []"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1598
    and hd_ni: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1599
    moreover have "set (SOME q. distinct q \<and> set q = set rest) = set rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1600
    proof(rule someI2)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1601
      from dst show "distinct rest \<and> set rest = set rest" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1602
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1603
      show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1604
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1605
    ultimately have "hd (SOME q. distinct q \<and> set q = set rest) \<notin> 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1606
                     set (SOME q. distinct q \<and> set q = set rest)" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1607
    moreover have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1608
    proof(rule someI2)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1609
      from dst show "distinct rest \<and> set rest = set rest" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1610
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1611
      fix x assume " distinct x \<and> set x = set rest" with ne
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1612
      show "x \<noteq> []" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1613
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1614
    ultimately show "False" by auto 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1615
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1616
  ultimately 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1617
  have "holdents s thread = insert cs (holdents (V thread cs#s) thread)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1618
    by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1619
  moreover have "card \<dots> = 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1620
                    Suc (card ((holdents (V thread cs#s) thread) - {cs}))"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1621
  proof(rule card_insert)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1622
    from vt_v.finite_holding
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1623
    show " finite (holdents (V thread cs # s) thread)" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1624
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1625
  moreover from cs_not_in 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1626
  have "cs \<notin> (holdents (V thread cs#s) thread)" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1627
  ultimately show ?thesis by (simp add:cntCS_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1628
qed 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1629
68
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1630
lemma count_rec1 [simp]: 
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1631
  assumes "Q e"
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1632
  shows "count Q (e#es) = Suc (count Q es)"
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1633
  using assms
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1634
  by (unfold count_def, auto)
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1635
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1636
lemma count_rec2 [simp]: 
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1637
  assumes "\<not>Q e"
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1638
  shows "count Q (e#es) = (count Q es)"
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1639
  using assms
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1640
  by (unfold count_def, auto)
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1641
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1642
lemma count_rec3 [simp]: 
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1643
  shows "count Q [] =  0"
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1644
  by (unfold count_def, auto)
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1645
  
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1646
lemma cntP_diff_inv:
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1647
  assumes "cntP (e#s) th \<noteq> cntP s th"
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1648
  shows "isP e \<and> actor e = th"
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1649
proof(cases e)
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1650
  case (P th' pty)
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1651
  show ?thesis
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1652
  by (cases "(\<lambda>e. \<exists>cs. e = P th cs) (P th' pty)", 
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1653
        insert assms P, auto simp:cntP_def)
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1654
qed (insert assms, auto simp:cntP_def)
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1655
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1656
lemma isP_E:
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1657
  assumes "isP e"
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1658
  obtains cs where "e = P (actor e) cs"
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1659
  using assms by (cases e, auto)
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1660
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1661
lemma isV_E:
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1662
  assumes "isV e"
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1663
  obtains cs where "e = V (actor e) cs"
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1664
  using assms by (cases e, auto) (* ccc *)
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1665
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1666
lemma cntV_diff_inv:
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1667
  assumes "cntV (e#s) th \<noteq> cntV s th"
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1668
  shows "isV e \<and> actor e = th"
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1669
proof(cases e)
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1670
  case (V th' pty)
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1671
  show ?thesis
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1672
  by (cases "(\<lambda>e. \<exists>cs. e = V th cs) (V th' pty)", 
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1673
        insert assms V, auto simp:cntV_def)
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1674
qed (insert assms, auto simp:cntV_def)
db196b066b97 Before retrofiting PIPBasics.thy
zhangx
parents: 67
diff changeset
  1675
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1676
context valid_trace
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1677
begin
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1678
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1679
text {* (* ddd *) \noindent
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1680
  The relationship between @{text "cntP"}, @{text "cntV"} and @{text "cntCS"} 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1681
  of one particular thread. 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1682
*} 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1683
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1684
lemma cnp_cnv_cncs:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1685
  shows "cntP s th = cntV s th + (if (th \<in> readys s \<or> th \<notin> threads s) 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1686
                                       then cntCS s th else cntCS s th + 1)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1687
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1688
  from vt show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1689
  proof(induct arbitrary:th)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1690
    case (vt_cons s e)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1691
    interpret vt_s: valid_trace s using vt_cons(1) by (unfold_locales, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1692
    assume vt: "vt s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1693
    and ih: "\<And>th. cntP s th  = cntV s th +
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1694
               (if (th \<in> readys s \<or> th \<notin> threads s) then cntCS s th else cntCS s th + 1)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1695
    and stp: "step s e"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1696
    from stp show ?case
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1697
    proof(cases)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1698
      case (thread_create thread prio)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1699
      assume eq_e: "e = Create thread prio"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1700
        and not_in: "thread \<notin> threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1701
      show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1702
      proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1703
        { fix cs 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1704
          assume "thread \<in> set (wq s cs)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1705
          from vt_s.wq_threads [OF this] have "thread \<in> threads s" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1706
          with not_in have "False" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1707
        } with eq_e have eq_readys: "readys (e#s) = readys s \<union> {thread}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1708
          by (auto simp:readys_def threads.simps s_waiting_def 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1709
            wq_def cs_waiting_def Let_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1710
        from eq_e have eq_cnp: "cntP (e#s) th = cntP s th" by (simp add:cntP_def count_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1711
        from eq_e have eq_cnv: "cntV (e#s) th = cntV s th" by (simp add:cntV_def count_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1712
        have eq_cncs: "cntCS (e#s) th = cntCS s th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1713
          unfolding cntCS_def holdents_test
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1714
          by (simp add:RAG_create_unchanged eq_e)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1715
        { assume "th \<noteq> thread"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1716
          with eq_readys eq_e
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1717
          have "(th \<in> readys (e # s) \<or> th \<notin> threads (e # s)) = 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1718
                      (th \<in> readys (s) \<or> th \<notin> threads (s))" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1719
            by (simp add:threads.simps)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1720
          with eq_cnp eq_cnv eq_cncs ih not_in
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1721
          have ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1722
        } moreover {
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1723
          assume eq_th: "th = thread"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1724
          with not_in ih have " cntP s th  = cntV s th + cntCS s th" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1725
          moreover from eq_th and eq_readys have "th \<in> readys (e#s)" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1726
          moreover note eq_cnp eq_cnv eq_cncs
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1727
          ultimately have ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1728
        } ultimately show ?thesis by blast
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1729
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1730
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1731
      case (thread_exit thread)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1732
      assume eq_e: "e = Exit thread" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1733
      and is_runing: "thread \<in> runing s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1734
      and no_hold: "holdents s thread = {}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1735
      from eq_e have eq_cnp: "cntP (e#s) th = cntP s th" by (simp add:cntP_def count_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1736
      from eq_e have eq_cnv: "cntV (e#s) th = cntV s th" by (simp add:cntV_def count_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1737
      have eq_cncs: "cntCS (e#s) th = cntCS s th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1738
        unfolding cntCS_def holdents_test
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1739
        by (simp add:RAG_exit_unchanged eq_e)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1740
      { assume "th \<noteq> thread"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1741
        with eq_e
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1742
        have "(th \<in> readys (e # s) \<or> th \<notin> threads (e # s)) = 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1743
          (th \<in> readys (s) \<or> th \<notin> threads (s))" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1744
          apply (simp add:threads.simps readys_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1745
          apply (subst s_waiting_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1746
          apply (simp add:Let_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1747
          apply (subst s_waiting_def, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1748
          done
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1749
        with eq_cnp eq_cnv eq_cncs ih
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1750
        have ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1751
      } moreover {
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1752
        assume eq_th: "th = thread"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1753
        with ih is_runing have " cntP s th = cntV s th + cntCS s th" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1754
          by (simp add:runing_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1755
        moreover from eq_th eq_e have "th \<notin> threads (e#s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1756
          by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1757
        moreover note eq_cnp eq_cnv eq_cncs
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1758
        ultimately have ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1759
      } ultimately show ?thesis by blast
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1760
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1761
      case (thread_P thread cs)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1762
      assume eq_e: "e = P thread cs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1763
        and is_runing: "thread \<in> runing s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1764
        and no_dep: "(Cs cs, Th thread) \<notin> (RAG s)\<^sup>+"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1765
      from thread_P vt stp ih  have vtp: "vt (P thread cs#s)" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1766
      then interpret vt_p: valid_trace "(P thread cs#s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1767
        by (unfold_locales, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1768
      show ?thesis 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1769
      proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1770
        { have hh: "\<And> A B C. (B = C) \<Longrightarrow> (A \<and> B) = (A \<and> C)" by blast
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1771
          assume neq_th: "th \<noteq> thread"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1772
          with eq_e
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1773
          have eq_readys: "(th \<in> readys (e#s)) = (th \<in> readys (s))"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1774
            apply (simp add:readys_def s_waiting_def wq_def Let_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1775
            apply (rule_tac hh)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1776
             apply (intro iffI allI, clarify)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1777
            apply (erule_tac x = csa in allE, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1778
            apply (subgoal_tac "wq_fun (schs s) cs \<noteq> []", auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1779
            apply (erule_tac x = cs in allE, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1780
            by (case_tac "(wq_fun (schs s) cs)", auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1781
          moreover from neq_th eq_e have "cntCS (e # s) th = cntCS s th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1782
            apply (simp add:cntCS_def holdents_test)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1783
            by (unfold  step_RAG_p [OF vtp], auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1784
          moreover from eq_e neq_th have "cntP (e # s) th = cntP s th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1785
            by (simp add:cntP_def count_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1786
          moreover from eq_e neq_th have "cntV (e#s) th = cntV s th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1787
            by (simp add:cntV_def count_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1788
          moreover from eq_e neq_th have "threads (e#s) = threads s" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1789
          moreover note ih [of th] 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1790
          ultimately have ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1791
        } moreover {
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1792
          assume eq_th: "th = thread"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1793
          have ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1794
          proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1795
            from eq_e eq_th have eq_cnp: "cntP (e # s) th  = 1 + (cntP s th)" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1796
              by (simp add:cntP_def count_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1797
            from eq_e eq_th have eq_cnv: "cntV (e#s) th = cntV s th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1798
              by (simp add:cntV_def count_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1799
            show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1800
            proof (cases "wq s cs = []")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1801
              case True
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1802
              with is_runing
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1803
              have "th \<in> readys (e#s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1804
                apply (unfold eq_e wq_def, unfold readys_def s_RAG_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1805
                apply (simp add: wq_def[symmetric] runing_def eq_th s_waiting_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1806
                by (auto simp:readys_def wq_def Let_def s_waiting_def wq_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1807
              moreover have "cntCS (e # s) th = 1 + cntCS s th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1808
              proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1809
                have "card {csa. csa = cs \<or> (Cs csa, Th thread) \<in> RAG s} =
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1810
                  Suc (card {cs. (Cs cs, Th thread) \<in> RAG s})" (is "card ?L = Suc (card ?R)")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1811
                proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1812
                  have "?L = insert cs ?R" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1813
                  moreover have "card \<dots> = Suc (card (?R - {cs}))" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1814
                  proof(rule card_insert)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1815
                    from vt_s.finite_holding [of thread]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1816
                    show " finite {cs. (Cs cs, Th thread) \<in> RAG s}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1817
                      by (unfold holdents_test, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1818
                  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1819
                  moreover have "?R - {cs} = ?R"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1820
                  proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1821
                    have "cs \<notin> ?R"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1822
                    proof
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1823
                      assume "cs \<in> {cs. (Cs cs, Th thread) \<in> RAG s}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1824
                      with no_dep show False by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1825
                    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1826
                    thus ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1827
                  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1828
                  ultimately show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1829
                qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1830
                thus ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1831
                  apply (unfold eq_e eq_th cntCS_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1832
                  apply (simp add: holdents_test)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1833
                  by (unfold step_RAG_p [OF vtp], auto simp:True)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1834
              qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1835
              moreover from is_runing have "th \<in> readys s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1836
                by (simp add:runing_def eq_th)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1837
              moreover note eq_cnp eq_cnv ih [of th]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1838
              ultimately show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1839
            next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1840
              case False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1841
              have eq_wq: "wq (e#s) cs = wq s cs @ [th]"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1842
                    by (unfold eq_th eq_e wq_def, auto simp:Let_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1843
              have "th \<notin> readys (e#s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1844
              proof
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1845
                assume "th \<in> readys (e#s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1846
                hence "\<forall>cs. \<not> waiting (e # s) th cs" by (simp add:readys_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1847
                from this[rule_format, of cs] have " \<not> waiting (e # s) th cs" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1848
                hence "th \<in> set (wq (e#s) cs) \<Longrightarrow> th = hd (wq (e#s) cs)" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1849
                  by (simp add:s_waiting_def wq_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1850
                moreover from eq_wq have "th \<in> set (wq (e#s) cs)" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1851
                ultimately have "th = hd (wq (e#s) cs)" by blast
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1852
                with eq_wq have "th = hd (wq s cs @ [th])" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1853
                hence "th = hd (wq s cs)" using False by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1854
                with False eq_wq vt_p.wq_distinct [of cs]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1855
                show False by (fold eq_e, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1856
              qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1857
              moreover from is_runing have "th \<in> threads (e#s)" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1858
                by (unfold eq_e, auto simp:runing_def readys_def eq_th)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1859
              moreover have "cntCS (e # s) th = cntCS s th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1860
                apply (unfold cntCS_def holdents_test eq_e step_RAG_p[OF vtp])
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1861
                by (auto simp:False)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1862
              moreover note eq_cnp eq_cnv ih[of th]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1863
              moreover from is_runing have "th \<in> readys s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1864
                by (simp add:runing_def eq_th)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1865
              ultimately show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1866
            qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1867
          qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1868
        } ultimately show ?thesis by blast
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1869
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1870
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1871
      case (thread_V thread cs)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1872
      from assms vt stp ih thread_V have vtv: "vt (V thread cs # s)" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1873
      then interpret vt_v: valid_trace "(V thread cs # s)" by (unfold_locales, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1874
      assume eq_e: "e = V thread cs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1875
        and is_runing: "thread \<in> runing s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1876
        and hold: "holding s thread cs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1877
      from hold obtain rest 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1878
        where eq_wq: "wq s cs = thread # rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1879
        by (case_tac "wq s cs", auto simp: wq_def s_holding_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1880
      have eq_threads: "threads (e#s) = threads s" by (simp add: eq_e)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1881
      have eq_set: "set (SOME q. distinct q \<and> set q = set rest) = set rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1882
      proof(rule someI2)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1883
        from vt_v.wq_distinct[of cs] and eq_wq
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1884
        show "distinct rest \<and> set rest = set rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1885
          by (metis distinct.simps(2) vt_s.wq_distinct)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1886
      next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1887
        show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1888
          by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1889
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1890
      show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1891
      proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1892
        { assume eq_th: "th = thread"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1893
          from eq_th have eq_cnp: "cntP (e # s) th = cntP s th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1894
            by (unfold eq_e, simp add:cntP_def count_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1895
          moreover from eq_th have eq_cnv: "cntV (e#s) th = 1 + cntV s th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1896
            by (unfold eq_e, simp add:cntV_def count_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1897
          moreover from cntCS_v_dec [OF vtv] 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1898
          have "cntCS (e # s) thread + 1 = cntCS s thread"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1899
            by (simp add:eq_e)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1900
          moreover from is_runing have rd_before: "thread \<in> readys s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1901
            by (unfold runing_def, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1902
          moreover have "thread \<in> readys (e # s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1903
          proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1904
            from is_runing
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1905
            have "thread \<in> threads (e#s)" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1906
              by (unfold eq_e, auto simp:runing_def readys_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1907
            moreover have "\<forall> cs1. \<not> waiting (e#s) thread cs1"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1908
            proof
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1909
              fix cs1
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1910
              { assume eq_cs: "cs1 = cs" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1911
                have "\<not> waiting (e # s) thread cs1"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1912
                proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1913
                  from eq_wq
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1914
                  have "thread \<notin> set (wq (e#s) cs1)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1915
                    apply(unfold eq_e wq_def eq_cs s_holding_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1916
                    apply (auto simp:Let_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1917
                  proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1918
                    assume "thread \<in> set (SOME q. distinct q \<and> set q = set rest)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1919
                    with eq_set have "thread \<in> set rest" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1920
                    with vt_v.wq_distinct[of cs]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1921
                    and eq_wq show False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1922
                        by (metis distinct.simps(2) vt_s.wq_distinct)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1923
                  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1924
                  thus ?thesis by (simp add:wq_def s_waiting_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1925
                qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1926
              } moreover {
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1927
                assume neq_cs: "cs1 \<noteq> cs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1928
                  have "\<not> waiting (e # s) thread cs1" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1929
                  proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1930
                    from wq_v_neq [OF neq_cs[symmetric]]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1931
                    have "wq (V thread cs # s) cs1 = wq s cs1" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1932
                    moreover have "\<not> waiting s thread cs1" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1933
                    proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1934
                      from runing_ready and is_runing
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1935
                      have "thread \<in> readys s" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1936
                      thus ?thesis by (simp add:readys_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1937
                    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1938
                    ultimately show ?thesis 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1939
                      by (auto simp:wq_def s_waiting_def eq_e)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1940
                  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1941
              } ultimately show "\<not> waiting (e # s) thread cs1" by blast
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1942
            qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1943
            ultimately show ?thesis by (simp add:readys_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1944
          qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1945
          moreover note eq_th ih
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1946
          ultimately have ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1947
        } moreover {
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1948
          assume neq_th: "th \<noteq> thread"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1949
          from neq_th eq_e have eq_cnp: "cntP (e # s) th = cntP s th" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1950
            by (simp add:cntP_def count_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1951
          from neq_th eq_e have eq_cnv: "cntV (e # s) th = cntV s th" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1952
            by (simp add:cntV_def count_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1953
          have ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1954
          proof(cases "th \<in> set rest")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1955
            case False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1956
            have "(th \<in> readys (e # s)) = (th \<in> readys s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1957
              apply (insert step_back_vt[OF vtv])
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1958
              by (simp add: False eq_e eq_wq neq_th vt_s.readys_v_eq)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1959
            moreover have "cntCS (e#s) th = cntCS s th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1960
              apply (insert neq_th, unfold eq_e cntCS_def holdents_test step_RAG_v[OF vtv], auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1961
              proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1962
                have "{csa. (Cs csa, Th th) \<in> RAG s \<or> csa = cs \<and> next_th s thread cs th} =
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1963
                      {cs. (Cs cs, Th th) \<in> RAG s}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1964
                proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1965
                  from False eq_wq
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1966
                  have " next_th s thread cs th \<Longrightarrow> (Cs cs, Th th) \<in> RAG s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1967
                    apply (unfold next_th_def, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1968
                  proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1969
                    assume ne: "rest \<noteq> []"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1970
                      and ni: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1971
                      and eq_wq: "wq s cs = thread # rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1972
                    from eq_set ni have "hd (SOME q. distinct q \<and> set q = set rest) \<notin> 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1973
                                  set (SOME q. distinct q \<and> set q = set rest)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1974
                                  " by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1975
                    moreover have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1976
                    proof(rule someI2)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1977
                      from vt_s.wq_distinct[ of cs] and eq_wq
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1978
                      show "distinct rest \<and> set rest = set rest" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1979
                    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1980
                      fix x assume "distinct x \<and> set x = set rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1981
                      with ne show "x \<noteq> []" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1982
                    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1983
                    ultimately show 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1984
                      "(Cs cs, Th (hd (SOME q. distinct q \<and> set q = set rest))) \<in> RAG s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1985
                      by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1986
                  qed    
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1987
                  thus ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1988
                qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1989
                thus "card {csa. (Cs csa, Th th) \<in> RAG s \<or> csa = cs \<and> next_th s thread cs th} =
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1990
                             card {cs. (Cs cs, Th th) \<in> RAG s}" by simp 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1991
              qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1992
            moreover note ih eq_cnp eq_cnv eq_threads
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1993
            ultimately show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1994
          next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1995
            case True
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1996
            assume th_in: "th \<in> set rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1997
            show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1998
            proof(cases "next_th s thread cs th")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  1999
              case False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2000
              with eq_wq and th_in have 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2001
                neq_hd: "th \<noteq> hd (SOME q. distinct q \<and> set q = set rest)" (is "th \<noteq> hd ?rest")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2002
                by (auto simp:next_th_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2003
              have "(th \<in> readys (e # s)) = (th \<in> readys s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2004
              proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2005
                from eq_wq and th_in
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2006
                have "\<not> th \<in> readys s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2007
                  apply (auto simp:readys_def s_waiting_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2008
                  apply (rule_tac x = cs in exI, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2009
                  by (insert vt_s.wq_distinct[of cs], auto simp add: wq_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2010
                moreover 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2011
                from eq_wq and th_in and neq_hd
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2012
                have "\<not> (th \<in> readys (e # s))"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2013
                  apply (auto simp:readys_def s_waiting_def eq_e wq_def Let_def split:list.splits)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2014
                  by (rule_tac x = cs in exI, auto simp:eq_set)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2015
                ultimately show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2016
              qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2017
              moreover have "cntCS (e#s) th = cntCS s th" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2018
              proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2019
                from eq_wq and  th_in and neq_hd
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2020
                have "(holdents (e # s) th) = (holdents s th)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2021
                  apply (unfold eq_e step_RAG_v[OF vtv], 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2022
                         auto simp:next_th_def eq_set s_RAG_def holdents_test wq_def
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2023
                                   Let_def cs_holding_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2024
                  by (insert vt_s.wq_distinct[of cs], auto simp:wq_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2025
                thus ?thesis by (simp add:cntCS_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2026
              qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2027
              moreover note ih eq_cnp eq_cnv eq_threads
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2028
              ultimately show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2029
            next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2030
              case True
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2031
              let ?rest = " (SOME q. distinct q \<and> set q = set rest)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2032
              let ?t = "hd ?rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2033
              from True eq_wq th_in neq_th
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2034
              have "th \<in> readys (e # s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2035
                apply (auto simp:eq_e readys_def s_waiting_def wq_def
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2036
                        Let_def next_th_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2037
              proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2038
                assume eq_wq: "wq_fun (schs s) cs = thread # rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2039
                  and t_in: "?t \<in> set rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2040
                show "?t \<in> threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2041
                proof(rule vt_s.wq_threads)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2042
                  from eq_wq and t_in
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2043
                  show "?t \<in> set (wq s cs)" by (auto simp:wq_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2044
                qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2045
              next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2046
                fix csa
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2047
                assume eq_wq: "wq_fun (schs s) cs = thread # rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2048
                  and t_in: "?t \<in> set rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2049
                  and neq_cs: "csa \<noteq> cs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2050
                  and t_in': "?t \<in>  set (wq_fun (schs s) csa)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2051
                show "?t = hd (wq_fun (schs s) csa)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2052
                proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2053
                  { assume neq_hd': "?t \<noteq> hd (wq_fun (schs s) csa)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2054
                    from vt_s.wq_distinct[of cs] and 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2055
                    eq_wq[folded wq_def] and t_in eq_wq
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2056
                    have "?t \<noteq> thread" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2057
                    with eq_wq and t_in
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2058
                    have w1: "waiting s ?t cs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2059
                      by (auto simp:s_waiting_def wq_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2060
                    from t_in' neq_hd'
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2061
                    have w2: "waiting s ?t csa"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2062
                      by (auto simp:s_waiting_def wq_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2063
                    from vt_s.waiting_unique[OF w1 w2]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2064
                    and neq_cs have "False" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2065
                  } thus ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2066
                qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2067
              qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2068
              moreover have "cntP s th = cntV s th + cntCS s th + 1"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2069
              proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2070
                have "th \<notin> readys s" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2071
                proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2072
                  from True eq_wq neq_th th_in
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2073
                  show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2074
                    apply (unfold readys_def s_waiting_def, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2075
                    by (rule_tac x = cs in exI, auto simp add: wq_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2076
                qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2077
                moreover have "th \<in> threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2078
                proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2079
                  from th_in eq_wq
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2080
                  have "th \<in> set (wq s cs)" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2081
                  from vt_s.wq_threads [OF this] 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2082
                  show ?thesis .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2083
                qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2084
                ultimately show ?thesis using ih by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2085
              qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2086
              moreover from True neq_th have "cntCS (e # s) th = 1 + cntCS s th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2087
                apply (unfold cntCS_def holdents_test eq_e step_RAG_v[OF vtv], auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2088
              proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2089
                show "card {csa. (Cs csa, Th th) \<in> RAG s \<or> csa = cs} =
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2090
                               Suc (card {cs. (Cs cs, Th th) \<in> RAG s})"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2091
                  (is "card ?A = Suc (card ?B)")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2092
                proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2093
                  have "?A = insert cs ?B" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2094
                  hence "card ?A = card (insert cs ?B)" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2095
                  also have "\<dots> = Suc (card ?B)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2096
                  proof(rule card_insert_disjoint)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2097
                    have "?B \<subseteq> ((\<lambda> (x, y). the_cs x) ` RAG s)" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2098
                      apply (auto simp:image_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2099
                      by (rule_tac x = "(Cs x, Th th)" in bexI, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2100
                    with vt_s.finite_RAG
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2101
                    show "finite {cs. (Cs cs, Th th) \<in> RAG s}" by (auto intro:finite_subset)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2102
                  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2103
                    show "cs \<notin> {cs. (Cs cs, Th th) \<in> RAG s}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2104
                    proof
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2105
                      assume "cs \<in> {cs. (Cs cs, Th th) \<in> RAG s}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2106
                      hence "(Cs cs, Th th) \<in> RAG s" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2107
                      with True neq_th eq_wq show False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2108
                        by (auto simp:next_th_def s_RAG_def cs_holding_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2109
                    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2110
                  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2111
                  finally show ?thesis .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2112
                qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2113
              qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2114
              moreover note eq_cnp eq_cnv
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2115
              ultimately show ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2116
            qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2117
          qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2118
        } ultimately show ?thesis by blast
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2119
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2120
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2121
      case (thread_set thread prio)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2122
      assume eq_e: "e = Set thread prio"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2123
        and is_runing: "thread \<in> runing s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2124
      show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2125
      proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2126
        from eq_e have eq_cnp: "cntP (e#s) th = cntP s th" by (simp add:cntP_def count_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2127
        from eq_e have eq_cnv: "cntV (e#s) th = cntV s th" by (simp add:cntV_def count_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2128
        have eq_cncs: "cntCS (e#s) th = cntCS s th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2129
          unfolding cntCS_def holdents_test
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2130
          by (simp add:RAG_set_unchanged eq_e)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2131
        from eq_e have eq_readys: "readys (e#s) = readys s" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2132
          by (simp add:readys_def cs_waiting_def s_waiting_def wq_def,
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2133
                  auto simp:Let_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2134
        { assume "th \<noteq> thread"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2135
          with eq_readys eq_e
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2136
          have "(th \<in> readys (e # s) \<or> th \<notin> threads (e # s)) = 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2137
                      (th \<in> readys (s) \<or> th \<notin> threads (s))" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2138
            by (simp add:threads.simps)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2139
          with eq_cnp eq_cnv eq_cncs ih is_runing
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2140
          have ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2141
        } moreover {
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2142
          assume eq_th: "th = thread"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2143
          with is_runing ih have " cntP s th  = cntV s th + cntCS s th" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2144
            by (unfold runing_def, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2145
          moreover from eq_th and eq_readys is_runing have "th \<in> readys (e#s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2146
            by (simp add:runing_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2147
          moreover note eq_cnp eq_cnv eq_cncs
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2148
          ultimately have ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2149
        } ultimately show ?thesis by blast
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2150
      qed   
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2151
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2152
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2153
    case vt_nil
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2154
    show ?case 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2155
      by (unfold cntP_def cntV_def cntCS_def, 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2156
        auto simp:count_def holdents_test s_RAG_def wq_def cs_holding_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2157
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2158
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2159
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2160
lemma not_thread_cncs:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2161
  assumes not_in: "th \<notin> threads s" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2162
  shows "cntCS s th = 0"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2163
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2164
  from vt not_in show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2165
  proof(induct arbitrary:th)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2166
    case (vt_cons s e th)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2167
    interpret vt_s: valid_trace s using vt_cons(1)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2168
       by (unfold_locales, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2169
    assume vt: "vt s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2170
      and ih: "\<And>th. th \<notin> threads s \<Longrightarrow> cntCS s th = 0"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2171
      and stp: "step s e"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2172
      and not_in: "th \<notin> threads (e # s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2173
    from stp show ?case
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2174
    proof(cases)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2175
      case (thread_create thread prio)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2176
      assume eq_e: "e = Create thread prio"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2177
        and not_in': "thread \<notin> threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2178
      have "cntCS (e # s) th = cntCS s th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2179
        apply (unfold eq_e cntCS_def holdents_test)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2180
        by (simp add:RAG_create_unchanged)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2181
      moreover have "th \<notin> threads s" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2182
      proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2183
        from not_in eq_e show ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2184
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2185
      moreover note ih ultimately show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2186
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2187
      case (thread_exit thread)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2188
      assume eq_e: "e = Exit thread"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2189
      and nh: "holdents s thread = {}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2190
      have eq_cns: "cntCS (e # s) th = cntCS s th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2191
        apply (unfold eq_e cntCS_def holdents_test)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2192
        by (simp add:RAG_exit_unchanged)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2193
      show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2194
      proof(cases "th = thread")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2195
        case True
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2196
        have "cntCS s th = 0" by (unfold cntCS_def, auto simp:nh True)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2197
        with eq_cns show ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2198
      next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2199
        case False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2200
        with not_in and eq_e
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2201
        have "th \<notin> threads s" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2202
        from ih[OF this] and eq_cns show ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2203
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2204
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2205
      case (thread_P thread cs)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2206
      assume eq_e: "e = P thread cs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2207
      and is_runing: "thread \<in> runing s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2208
      from assms thread_P ih vt stp thread_P have vtp: "vt (P thread cs#s)" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2209
      have neq_th: "th \<noteq> thread" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2210
      proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2211
        from not_in eq_e have "th \<notin> threads s" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2212
        moreover from is_runing have "thread \<in> threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2213
          by (simp add:runing_def readys_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2214
        ultimately show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2215
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2216
      hence "cntCS (e # s) th  = cntCS s th "
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2217
        apply (unfold cntCS_def holdents_test eq_e)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2218
        by (unfold step_RAG_p[OF vtp], auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2219
      moreover have "cntCS s th = 0"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2220
      proof(rule ih)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2221
        from not_in eq_e show "th \<notin> threads s" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2222
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2223
      ultimately show ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2224
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2225
      case (thread_V thread cs)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2226
      assume eq_e: "e = V thread cs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2227
        and is_runing: "thread \<in> runing s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2228
        and hold: "holding s thread cs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2229
      have neq_th: "th \<noteq> thread" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2230
      proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2231
        from not_in eq_e have "th \<notin> threads s" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2232
        moreover from is_runing have "thread \<in> threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2233
          by (simp add:runing_def readys_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2234
        ultimately show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2235
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2236
      from assms thread_V vt stp ih 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2237
      have vtv: "vt (V thread cs#s)" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2238
      then interpret vt_v: valid_trace "(V thread cs#s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2239
        by (unfold_locales, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2240
      from hold obtain rest 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2241
        where eq_wq: "wq s cs = thread # rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2242
        by (case_tac "wq s cs", auto simp: wq_def s_holding_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2243
      from not_in eq_e eq_wq
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2244
      have "\<not> next_th s thread cs th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2245
        apply (auto simp:next_th_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2246
      proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2247
        assume ne: "rest \<noteq> []"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2248
          and ni: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> threads s" (is "?t \<notin> threads s")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2249
        have "?t \<in> set rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2250
        proof(rule someI2)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2251
          from vt_v.wq_distinct[of cs] and eq_wq
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2252
          show "distinct rest \<and> set rest = set rest"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2253
            by (metis distinct.simps(2) vt_s.wq_distinct) 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2254
        next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2255
          fix x assume "distinct x \<and> set x = set rest" with ne
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2256
          show "hd x \<in> set rest" by (cases x, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2257
        qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2258
        with eq_wq have "?t \<in> set (wq s cs)" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2259
        from vt_s.wq_threads[OF this] and ni
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2260
        show False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2261
          using `hd (SOME q. distinct q \<and> set q = set rest) \<in> set (wq s cs)` 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2262
            ni vt_s.wq_threads by blast 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2263
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2264
      moreover note neq_th eq_wq
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2265
      ultimately have "cntCS (e # s) th  = cntCS s th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2266
        by (unfold eq_e cntCS_def holdents_test step_RAG_v[OF vtv], auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2267
      moreover have "cntCS s th = 0"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2268
      proof(rule ih)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2269
        from not_in eq_e show "th \<notin> threads s" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2270
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2271
      ultimately show ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2272
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2273
      case (thread_set thread prio)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2274
      print_facts
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2275
      assume eq_e: "e = Set thread prio"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2276
        and is_runing: "thread \<in> runing s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2277
      from not_in and eq_e have "th \<notin> threads s" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2278
      from ih [OF this] and eq_e
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2279
      show ?thesis 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2280
        apply (unfold eq_e cntCS_def holdents_test)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2281
        by (simp add:RAG_set_unchanged)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2282
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2283
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2284
      case vt_nil
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2285
      show ?case
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2286
      by (unfold cntCS_def, 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2287
        auto simp:count_def holdents_test s_RAG_def wq_def cs_holding_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2288
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2289
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2290
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2291
end
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2292
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2293
lemma eq_waiting: "waiting (wq (s::state)) th cs = waiting s th cs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2294
  by (auto simp:s_waiting_def cs_waiting_def wq_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2295
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2296
context valid_trace
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2297
begin
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2298
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2299
lemma dm_RAG_threads:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2300
  assumes in_dom: "(Th th) \<in> Domain (RAG s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2301
  shows "th \<in> threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2302
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2303
  from in_dom obtain n where "(Th th, n) \<in> RAG s" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2304
  moreover from RAG_target_th[OF this] obtain cs where "n = Cs cs" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2305
  ultimately have "(Th th, Cs cs) \<in> RAG s" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2306
  hence "th \<in> set (wq s cs)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2307
    by (unfold s_RAG_def, auto simp:cs_waiting_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2308
  from wq_threads [OF this] show ?thesis .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2309
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2310
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2311
end
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2312
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2313
lemma cp_eq_cpreced: "cp s th = cpreced (wq s) s th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2314
unfolding cp_def wq_def
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2315
apply(induct s rule: schs.induct)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2316
thm cpreced_initial
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2317
apply(simp add: Let_def cpreced_initial)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2318
apply(simp add: Let_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2319
apply(simp add: Let_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2320
apply(simp add: Let_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2321
apply(subst (2) schs.simps)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2322
apply(simp add: Let_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2323
apply(subst (2) schs.simps)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2324
apply(simp add: Let_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2325
done
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2326
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2327
context valid_trace
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2328
begin
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2329
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2330
lemma runing_unique:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2331
  assumes runing_1: "th1 \<in> runing s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2332
  and runing_2: "th2 \<in> runing s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2333
  shows "th1 = th2"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2334
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2335
  from runing_1 and runing_2 have "cp s th1 = cp s th2"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2336
    unfolding runing_def
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2337
    apply(simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2338
    done
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2339
  hence eq_max: "Max ((\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1)) =
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2340
                 Max ((\<lambda>th. preced th s) ` ({th2} \<union> dependants (wq s) th2))"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2341
    (is "Max (?f ` ?A) = Max (?f ` ?B)")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2342
    unfolding cp_eq_cpreced 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2343
    unfolding cpreced_def .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2344
  obtain th1' where th1_in: "th1' \<in> ?A" and eq_f_th1: "?f th1' = Max (?f ` ?A)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2345
  proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2346
    have h1: "finite (?f ` ?A)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2347
    proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2348
      have "finite ?A" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2349
      proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2350
        have "finite (dependants (wq s) th1)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2351
        proof-
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2352
          have "finite {th'. (Th th', Th th1) \<in> (RAG (wq s))\<^sup>+}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2353
          proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2354
            let ?F = "\<lambda> (x, y). the_th x"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2355
            have "{th'. (Th th', Th th1) \<in> (RAG (wq s))\<^sup>+} \<subseteq> ?F ` ((RAG (wq s))\<^sup>+)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2356
              apply (auto simp:image_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2357
              by (rule_tac x = "(Th x, Th th1)" in bexI, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2358
            moreover have "finite \<dots>"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2359
            proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2360
              from finite_RAG have "finite (RAG s)" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2361
              hence "finite ((RAG (wq s))\<^sup>+)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2362
                apply (unfold finite_trancl)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2363
                by (auto simp: s_RAG_def cs_RAG_def wq_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2364
              thus ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2365
            qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2366
            ultimately show ?thesis by (auto intro:finite_subset)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2367
          qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2368
          thus ?thesis by (simp add:cs_dependants_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2369
        qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2370
        thus ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2371
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2372
      thus ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2373
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2374
    moreover have h2: "(?f ` ?A) \<noteq> {}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2375
    proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2376
      have "?A \<noteq> {}" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2377
      thus ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2378
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2379
    from Max_in [OF h1 h2]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2380
    have "Max (?f ` ?A) \<in> (?f ` ?A)" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2381
    thus ?thesis 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2382
      thm cpreced_def
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2383
      unfolding cpreced_def[symmetric] 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2384
      unfolding cp_eq_cpreced[symmetric] 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2385
      unfolding cpreced_def 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2386
      using that[intro] by (auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2387
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2388
  obtain th2' where th2_in: "th2' \<in> ?B" and eq_f_th2: "?f th2' = Max (?f ` ?B)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2389
  proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2390
    have h1: "finite (?f ` ?B)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2391
    proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2392
      have "finite ?B" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2393
      proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2394
        have "finite (dependants (wq s) th2)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2395
        proof-
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2396
          have "finite {th'. (Th th', Th th2) \<in> (RAG (wq s))\<^sup>+}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2397
          proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2398
            let ?F = "\<lambda> (x, y). the_th x"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2399
            have "{th'. (Th th', Th th2) \<in> (RAG (wq s))\<^sup>+} \<subseteq> ?F ` ((RAG (wq s))\<^sup>+)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2400
              apply (auto simp:image_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2401
              by (rule_tac x = "(Th x, Th th2)" in bexI, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2402
            moreover have "finite \<dots>"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2403
            proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2404
              from finite_RAG have "finite (RAG s)" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2405
              hence "finite ((RAG (wq s))\<^sup>+)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2406
                apply (unfold finite_trancl)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2407
                by (auto simp: s_RAG_def cs_RAG_def wq_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2408
              thus ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2409
            qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2410
            ultimately show ?thesis by (auto intro:finite_subset)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2411
          qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2412
          thus ?thesis by (simp add:cs_dependants_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2413
        qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2414
        thus ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2415
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2416
      thus ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2417
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2418
    moreover have h2: "(?f ` ?B) \<noteq> {}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2419
    proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2420
      have "?B \<noteq> {}" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2421
      thus ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2422
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2423
    from Max_in [OF h1 h2]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2424
    have "Max (?f ` ?B) \<in> (?f ` ?B)" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2425
    thus ?thesis by (auto intro:that)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2426
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2427
  from eq_f_th1 eq_f_th2 eq_max 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2428
  have eq_preced: "preced th1' s = preced th2' s" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2429
  hence eq_th12: "th1' = th2'"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2430
  proof (rule preced_unique)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2431
    from th1_in have "th1' = th1 \<or> (th1' \<in> dependants (wq s) th1)" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2432
    thus "th1' \<in> threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2433
    proof
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2434
      assume "th1' \<in> dependants (wq s) th1"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2435
      hence "(Th th1') \<in> Domain ((RAG s)^+)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2436
        apply (unfold cs_dependants_def cs_RAG_def s_RAG_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2437
        by (auto simp:Domain_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2438
      hence "(Th th1') \<in> Domain (RAG s)" by (simp add:trancl_domain)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2439
      from dm_RAG_threads[OF this] show ?thesis .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2440
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2441
      assume "th1' = th1"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2442
      with runing_1 show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2443
        by (unfold runing_def readys_def, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2444
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2445
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2446
    from th2_in have "th2' = th2 \<or> (th2' \<in> dependants (wq s) th2)" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2447
    thus "th2' \<in> threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2448
    proof
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2449
      assume "th2' \<in> dependants (wq s) th2"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2450
      hence "(Th th2') \<in> Domain ((RAG s)^+)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2451
        apply (unfold cs_dependants_def cs_RAG_def s_RAG_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2452
        by (auto simp:Domain_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2453
      hence "(Th th2') \<in> Domain (RAG s)" by (simp add:trancl_domain)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2454
      from dm_RAG_threads[OF this] show ?thesis .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2455
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2456
      assume "th2' = th2"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2457
      with runing_2 show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2458
        by (unfold runing_def readys_def, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2459
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2460
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2461
  from th1_in have "th1' = th1 \<or> th1' \<in> dependants (wq s) th1" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2462
  thus ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2463
  proof
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2464
    assume eq_th': "th1' = th1"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2465
    from th2_in have "th2' = th2 \<or> th2' \<in> dependants (wq s) th2" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2466
    thus ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2467
    proof
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2468
      assume "th2' = th2" thus ?thesis using eq_th' eq_th12 by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2469
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2470
      assume "th2' \<in> dependants (wq s) th2"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2471
      with eq_th12 eq_th' have "th1 \<in> dependants (wq s) th2" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2472
      hence "(Th th1, Th th2) \<in> (RAG s)^+"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2473
        by (unfold cs_dependants_def s_RAG_def cs_RAG_def, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2474
      hence "Th th1 \<in> Domain ((RAG s)^+)" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2475
        apply (unfold cs_dependants_def cs_RAG_def s_RAG_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2476
        by (auto simp:Domain_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2477
      hence "Th th1 \<in> Domain (RAG s)" by (simp add:trancl_domain)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2478
      then obtain n where d: "(Th th1, n) \<in> RAG s" by (auto simp:Domain_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2479
      from RAG_target_th [OF this]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2480
      obtain cs' where "n = Cs cs'" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2481
      with d have "(Th th1, Cs cs') \<in> RAG s" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2482
      with runing_1 have "False"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2483
        apply (unfold runing_def readys_def s_RAG_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2484
        by (auto simp:eq_waiting)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2485
      thus ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2486
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2487
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2488
    assume th1'_in: "th1' \<in> dependants (wq s) th1"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2489
    from th2_in have "th2' = th2 \<or> th2' \<in> dependants (wq s) th2" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2490
    thus ?thesis 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2491
    proof
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2492
      assume "th2' = th2"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2493
      with th1'_in eq_th12 have "th2 \<in> dependants (wq s) th1" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2494
      hence "(Th th2, Th th1) \<in> (RAG s)^+"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2495
        by (unfold cs_dependants_def s_RAG_def cs_RAG_def, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2496
      hence "Th th2 \<in> Domain ((RAG s)^+)" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2497
        apply (unfold cs_dependants_def cs_RAG_def s_RAG_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2498
        by (auto simp:Domain_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2499
      hence "Th th2 \<in> Domain (RAG s)" by (simp add:trancl_domain)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2500
      then obtain n where d: "(Th th2, n) \<in> RAG s" by (auto simp:Domain_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2501
      from RAG_target_th [OF this]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2502
      obtain cs' where "n = Cs cs'" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2503
      with d have "(Th th2, Cs cs') \<in> RAG s" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2504
      with runing_2 have "False"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2505
        apply (unfold runing_def readys_def s_RAG_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2506
        by (auto simp:eq_waiting)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2507
      thus ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2508
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2509
      assume "th2' \<in> dependants (wq s) th2"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2510
      with eq_th12 have "th1' \<in> dependants (wq s) th2" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2511
      hence h1: "(Th th1', Th th2) \<in> (RAG s)^+"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2512
        by (unfold cs_dependants_def s_RAG_def cs_RAG_def, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2513
      from th1'_in have h2: "(Th th1', Th th1) \<in> (RAG s)^+"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2514
        by (unfold cs_dependants_def s_RAG_def cs_RAG_def, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2515
      show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2516
      proof(rule dchain_unique[OF h1 _ h2, symmetric])
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2517
        from runing_1 show "th1 \<in> readys s" by (simp add:runing_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2518
        from runing_2 show "th2 \<in> readys s" by (simp add:runing_def) 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2519
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2520
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2521
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2522
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2523
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2524
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2525
lemma "card (runing s) \<le> 1"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2526
apply(subgoal_tac "finite (runing s)")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2527
prefer 2
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2528
apply (metis finite_nat_set_iff_bounded lessI runing_unique)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2529
apply(rule ccontr)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2530
apply(simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2531
apply(case_tac "Suc (Suc 0) \<le> card (runing s)")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2532
apply(subst (asm) card_le_Suc_iff)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2533
apply(simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2534
apply(auto)[1]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2535
apply (metis insertCI runing_unique)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2536
apply(auto) 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2537
done
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2538
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2539
end
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2540
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2541
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2542
lemma create_pre:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2543
  assumes stp: "step s e"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2544
  and not_in: "th \<notin> threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2545
  and is_in: "th \<in> threads (e#s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2546
  obtains prio where "e = Create th prio"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2547
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2548
  from assms  
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2549
  show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2550
  proof(cases)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2551
    case (thread_create thread prio)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2552
    with is_in not_in have "e = Create th prio" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2553
    from that[OF this] show ?thesis .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2554
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2555
    case (thread_exit thread)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2556
    with assms show ?thesis by (auto intro!:that)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2557
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2558
    case (thread_P thread)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2559
    with assms show ?thesis by (auto intro!:that)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2560
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2561
    case (thread_V thread)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2562
    with assms show ?thesis by (auto intro!:that)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2563
  next 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2564
    case (thread_set thread)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2565
    with assms show ?thesis by (auto intro!:that)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2566
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2567
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2568
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2569
lemma length_down_to_in: 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2570
  assumes le_ij: "i \<le> j"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2571
    and le_js: "j \<le> length s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2572
  shows "length (down_to j i s) = j - i"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2573
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2574
  have "length (down_to j i s) = length (from_to i j (rev s))"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2575
    by (unfold down_to_def, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2576
  also have "\<dots> = j - i"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2577
  proof(rule length_from_to_in[OF le_ij])
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2578
    from le_js show "j \<le> length (rev s)" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2579
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2580
  finally show ?thesis .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2581
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2582
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2583
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2584
lemma moment_head: 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2585
  assumes le_it: "Suc i \<le> length t"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2586
  obtains e where "moment (Suc i) t = e#moment i t"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2587
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2588
  have "i \<le> Suc i" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2589
  from length_down_to_in [OF this le_it]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2590
  have "length (down_to (Suc i) i t) = 1" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2591
  then obtain e where "down_to (Suc i) i t = [e]"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2592
    apply (cases "(down_to (Suc i) i t)") by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2593
  moreover have "down_to (Suc i) 0 t = down_to (Suc i) i t @ down_to i 0 t"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2594
    by (rule down_to_conc[symmetric], auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2595
  ultimately have eq_me: "moment (Suc i) t = e#(moment i t)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2596
    by (auto simp:down_to_moment)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2597
  from that [OF this] show ?thesis .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2598
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2599
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2600
context valid_trace
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2601
begin
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2602
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2603
lemma cnp_cnv_eq:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2604
  assumes "th \<notin> threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2605
  shows "cntP s th = cntV s th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2606
  using assms
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2607
  using cnp_cnv_cncs not_thread_cncs by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2608
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2609
end
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2610
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2611
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2612
lemma eq_RAG: 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2613
  "RAG (wq s) = RAG s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2614
by (unfold cs_RAG_def s_RAG_def, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2615
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2616
context valid_trace
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2617
begin
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2618
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2619
lemma count_eq_dependants:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2620
  assumes eq_pv: "cntP s th = cntV s th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2621
  shows "dependants (wq s) th = {}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2622
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2623
  from cnp_cnv_cncs and eq_pv
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2624
  have "cntCS s th = 0" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2625
    by (auto split:if_splits)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2626
  moreover have "finite {cs. (Cs cs, Th th) \<in> RAG s}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2627
  proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2628
    from finite_holding[of th] show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2629
      by (simp add:holdents_test)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2630
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2631
  ultimately have h: "{cs. (Cs cs, Th th) \<in> RAG s} = {}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2632
    by (unfold cntCS_def holdents_test cs_dependants_def, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2633
  show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2634
  proof(unfold cs_dependants_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2635
    { assume "{th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+} \<noteq> {}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2636
      then obtain th' where "(Th th', Th th) \<in> (RAG (wq s))\<^sup>+" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2637
      hence "False"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2638
      proof(cases)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2639
        assume "(Th th', Th th) \<in> RAG (wq s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2640
        thus "False" by (auto simp:cs_RAG_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2641
      next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2642
        fix c
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2643
        assume "(c, Th th) \<in> RAG (wq s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2644
        with h and eq_RAG show "False"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2645
          by (cases c, auto simp:cs_RAG_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2646
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2647
    } thus "{th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+} = {}" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2648
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2649
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2650
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2651
lemma dependants_threads:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2652
  shows "dependants (wq s) th \<subseteq> threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2653
proof
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2654
  { fix th th'
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2655
    assume h: "th \<in> {th'a. (Th th'a, Th th') \<in> (RAG (wq s))\<^sup>+}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2656
    have "Th th \<in> Domain (RAG s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2657
    proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2658
      from h obtain th' where "(Th th, Th th') \<in> (RAG (wq s))\<^sup>+" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2659
      hence "(Th th) \<in> Domain ( (RAG (wq s))\<^sup>+)" by (auto simp:Domain_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2660
      with trancl_domain have "(Th th) \<in> Domain (RAG (wq s))" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2661
      thus ?thesis using eq_RAG by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2662
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2663
    from dm_RAG_threads[OF this]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2664
    have "th \<in> threads s" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2665
  } note hh = this
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2666
  fix th1 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2667
  assume "th1 \<in> dependants (wq s) th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2668
  hence "th1 \<in> {th'a. (Th th'a, Th th) \<in> (RAG (wq s))\<^sup>+}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2669
    by (unfold cs_dependants_def, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2670
  from hh [OF this] show "th1 \<in> threads s" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2671
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2672
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2673
lemma finite_threads:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2674
  shows "finite (threads s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2675
using vt by (induct) (auto elim: step.cases)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2676
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2677
end
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2678
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2679
lemma Max_f_mono:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2680
  assumes seq: "A \<subseteq> B"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2681
  and np: "A \<noteq> {}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2682
  and fnt: "finite B"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2683
  shows "Max (f ` A) \<le> Max (f ` B)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2684
proof(rule Max_mono)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2685
  from seq show "f ` A \<subseteq> f ` B" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2686
next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2687
  from np show "f ` A \<noteq> {}" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2688
next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2689
  from fnt and seq show "finite (f ` B)" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2690
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2691
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2692
context valid_trace
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2693
begin
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2694
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2695
lemma cp_le:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2696
  assumes th_in: "th \<in> threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2697
  shows "cp s th \<le> Max ((\<lambda> th. (preced th s)) ` threads s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2698
proof(unfold cp_eq_cpreced cpreced_def cs_dependants_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2699
  show "Max ((\<lambda>th. preced th s) ` ({th} \<union> {th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+}))
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2700
         \<le> Max ((\<lambda>th. preced th s) ` threads s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2701
    (is "Max (?f ` ?A) \<le> Max (?f ` ?B)")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2702
  proof(rule Max_f_mono)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2703
    show "{th} \<union> {th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+} \<noteq> {}" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2704
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2705
    from finite_threads
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2706
    show "finite (threads s)" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2707
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2708
    from th_in
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2709
    show "{th} \<union> {th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+} \<subseteq> threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2710
      apply (auto simp:Domain_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2711
      apply (rule_tac dm_RAG_threads)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2712
      apply (unfold trancl_domain [of "RAG s", symmetric])
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2713
      by (unfold cs_RAG_def s_RAG_def, auto simp:Domain_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2714
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2715
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2716
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2717
lemma le_cp:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2718
  shows "preced th s \<le> cp s th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2719
proof(unfold cp_eq_cpreced preced_def cpreced_def, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2720
  show "Prc (priority th s) (last_set th s)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2721
    \<le> Max (insert (Prc (priority th s) (last_set th s))
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2722
            ((\<lambda>th. Prc (priority th s) (last_set th s)) ` dependants (wq s) th))"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2723
    (is "?l \<le> Max (insert ?l ?A)")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2724
  proof(cases "?A = {}")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2725
    case False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2726
    have "finite ?A" (is "finite (?f ` ?B)")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2727
    proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2728
      have "finite ?B" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2729
      proof-
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2730
        have "finite {th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2731
        proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2732
          let ?F = "\<lambda> (x, y). the_th x"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2733
          have "{th'. (Th th', Th th) \<in> (RAG (wq s))\<^sup>+} \<subseteq> ?F ` ((RAG (wq s))\<^sup>+)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2734
            apply (auto simp:image_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2735
            by (rule_tac x = "(Th x, Th th)" in bexI, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2736
          moreover have "finite \<dots>"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2737
          proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2738
            from finite_RAG have "finite (RAG s)" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2739
            hence "finite ((RAG (wq s))\<^sup>+)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2740
              apply (unfold finite_trancl)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2741
              by (auto simp: s_RAG_def cs_RAG_def wq_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2742
            thus ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2743
          qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2744
          ultimately show ?thesis by (auto intro:finite_subset)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2745
        qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2746
        thus ?thesis by (simp add:cs_dependants_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2747
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2748
      thus ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2749
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2750
    from Max_insert [OF this False, of ?l] show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2751
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2752
    case True
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2753
    thus ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2754
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2755
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2756
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2757
lemma max_cp_eq: 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2758
  shows "Max ((cp s) ` threads s) = Max ((\<lambda> th. (preced th s)) ` threads s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2759
  (is "?l = ?r")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2760
proof(cases "threads s = {}")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2761
  case True
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2762
  thus ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2763
next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2764
  case False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2765
  have "?l \<in> ((cp s) ` threads s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2766
  proof(rule Max_in)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2767
    from finite_threads
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2768
    show "finite (cp s ` threads s)" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2769
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2770
    from False show "cp s ` threads s \<noteq> {}" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2771
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2772
  then obtain th 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2773
    where th_in: "th \<in> threads s" and eq_l: "?l = cp s th" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2774
  have "\<dots> \<le> ?r" by (rule cp_le[OF th_in])
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2775
  moreover have "?r \<le> cp s th" (is "Max (?f ` ?A) \<le> cp s th")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2776
  proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2777
    have "?r \<in> (?f ` ?A)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2778
    proof(rule Max_in)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2779
      from finite_threads
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2780
      show " finite ((\<lambda>th. preced th s) ` threads s)" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2781
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2782
      from False show " (\<lambda>th. preced th s) ` threads s \<noteq> {}" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2783
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2784
    then obtain th' where 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2785
      th_in': "th' \<in> ?A " and eq_r: "?r = ?f th'" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2786
    from le_cp [of th']  eq_r
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2787
    have "?r \<le> cp s th'" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2788
    moreover have "\<dots> \<le> cp s th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2789
    proof(fold eq_l)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2790
      show " cp s th' \<le> Max (cp s ` threads s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2791
      proof(rule Max_ge)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2792
        from th_in' show "cp s th' \<in> cp s ` threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2793
          by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2794
      next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2795
        from finite_threads
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2796
        show "finite (cp s ` threads s)" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2797
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2798
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2799
    ultimately show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2800
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2801
  ultimately show ?thesis using eq_l by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2802
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2803
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2804
lemma max_cp_readys_threads_pre:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2805
  assumes np: "threads s \<noteq> {}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2806
  shows "Max (cp s ` readys s) = Max (cp s ` threads s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2807
proof(unfold max_cp_eq)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2808
  show "Max (cp s ` readys s) = Max ((\<lambda>th. preced th s) ` threads s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2809
  proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2810
    let ?p = "Max ((\<lambda>th. preced th s) ` threads s)" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2811
    let ?f = "(\<lambda>th. preced th s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2812
    have "?p \<in> ((\<lambda>th. preced th s) ` threads s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2813
    proof(rule Max_in)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2814
      from finite_threads show "finite (?f ` threads s)" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2815
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2816
      from np show "?f ` threads s \<noteq> {}" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2817
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2818
    then obtain tm where tm_max: "?f tm = ?p" and tm_in: "tm \<in> threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2819
      by (auto simp:Image_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2820
    from th_chain_to_ready [OF tm_in]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2821
    have "tm \<in> readys s \<or> (\<exists>th'. th' \<in> readys s \<and> (Th tm, Th th') \<in> (RAG s)\<^sup>+)" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2822
    thus ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2823
    proof
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2824
      assume "\<exists>th'. th' \<in> readys s \<and> (Th tm, Th th') \<in> (RAG s)\<^sup>+ "
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2825
      then obtain th' where th'_in: "th' \<in> readys s" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2826
        and tm_chain:"(Th tm, Th th') \<in> (RAG s)\<^sup>+" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2827
      have "cp s th' = ?f tm"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2828
      proof(subst cp_eq_cpreced, subst cpreced_def, rule Max_eqI)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2829
        from dependants_threads finite_threads
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2830
        show "finite ((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th'))" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2831
          by (auto intro:finite_subset)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2832
      next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2833
        fix p assume p_in: "p \<in> (\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2834
        from tm_max have " preced tm s = Max ((\<lambda>th. preced th s) ` threads s)" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2835
        moreover have "p \<le> \<dots>"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2836
        proof(rule Max_ge)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2837
          from finite_threads
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2838
          show "finite ((\<lambda>th. preced th s) ` threads s)" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2839
        next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2840
          from p_in and th'_in and dependants_threads[of th']
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2841
          show "p \<in> (\<lambda>th. preced th s) ` threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2842
            by (auto simp:readys_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2843
        qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2844
        ultimately show "p \<le> preced tm s" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2845
      next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2846
        show "preced tm s \<in> (\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2847
        proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2848
          from tm_chain
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2849
          have "tm \<in> dependants (wq s) th'"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2850
            by (unfold cs_dependants_def s_RAG_def cs_RAG_def, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2851
          thus ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2852
        qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2853
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2854
      with tm_max
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2855
      have h: "cp s th' = Max ((\<lambda>th. preced th s) ` threads s)" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2856
      show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2857
      proof (fold h, rule Max_eqI)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2858
        fix q 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2859
        assume "q \<in> cp s ` readys s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2860
        then obtain th1 where th1_in: "th1 \<in> readys s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2861
          and eq_q: "q = cp s th1" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2862
        show "q \<le> cp s th'"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2863
          apply (unfold h eq_q)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2864
          apply (unfold cp_eq_cpreced cpreced_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2865
          apply (rule Max_mono)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2866
        proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2867
          from dependants_threads [of th1] th1_in
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2868
          show "(\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1) \<subseteq> 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2869
                 (\<lambda>th. preced th s) ` threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2870
            by (auto simp:readys_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2871
        next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2872
          show "(\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1) \<noteq> {}" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2873
        next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2874
          from finite_threads 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2875
          show " finite ((\<lambda>th. preced th s) ` threads s)" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2876
        qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2877
      next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2878
        from finite_threads
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2879
        show "finite (cp s ` readys s)" by (auto simp:readys_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2880
      next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2881
        from th'_in
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2882
        show "cp s th' \<in> cp s ` readys s" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2883
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2884
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2885
      assume tm_ready: "tm \<in> readys s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2886
      show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2887
      proof(fold tm_max)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2888
        have cp_eq_p: "cp s tm = preced tm s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2889
        proof(unfold cp_eq_cpreced cpreced_def, rule Max_eqI)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2890
          fix y 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2891
          assume hy: "y \<in> (\<lambda>th. preced th s) ` ({tm} \<union> dependants (wq s) tm)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2892
          show "y \<le> preced tm s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2893
          proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2894
            { fix y'
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2895
              assume hy' : "y' \<in> ((\<lambda>th. preced th s) ` dependants (wq s) tm)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2896
              have "y' \<le> preced tm s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2897
              proof(unfold tm_max, rule Max_ge)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2898
                from hy' dependants_threads[of tm]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2899
                show "y' \<in> (\<lambda>th. preced th s) ` threads s" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2900
              next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2901
                from finite_threads
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2902
                show "finite ((\<lambda>th. preced th s) ` threads s)" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2903
              qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2904
            } with hy show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2905
          qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2906
        next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2907
          from dependants_threads[of tm] finite_threads
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2908
          show "finite ((\<lambda>th. preced th s) ` ({tm} \<union> dependants (wq s) tm))"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2909
            by (auto intro:finite_subset)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2910
        next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2911
          show "preced tm s \<in> (\<lambda>th. preced th s) ` ({tm} \<union> dependants (wq s) tm)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2912
            by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2913
        qed 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2914
        moreover have "Max (cp s ` readys s) = cp s tm"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2915
        proof(rule Max_eqI)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2916
          from tm_ready show "cp s tm \<in> cp s ` readys s" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2917
        next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2918
          from finite_threads
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2919
          show "finite (cp s ` readys s)" by (auto simp:readys_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2920
        next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2921
          fix y assume "y \<in> cp s ` readys s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2922
          then obtain th1 where th1_readys: "th1 \<in> readys s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2923
            and h: "y = cp s th1" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2924
          show "y \<le> cp s tm"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2925
            apply(unfold cp_eq_p h)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2926
            apply(unfold cp_eq_cpreced cpreced_def tm_max, rule Max_mono)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2927
          proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2928
            from finite_threads
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2929
            show "finite ((\<lambda>th. preced th s) ` threads s)" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2930
          next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2931
            show "(\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1) \<noteq> {}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2932
              by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2933
          next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2934
            from dependants_threads[of th1] th1_readys
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2935
            show "(\<lambda>th. preced th s) ` ({th1} \<union> dependants (wq s) th1) 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2936
                    \<subseteq> (\<lambda>th. preced th s) ` threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2937
              by (auto simp:readys_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2938
          qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2939
        qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2940
        ultimately show " Max (cp s ` readys s) = preced tm s" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2941
      qed 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2942
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2943
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2944
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2945
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2946
text {* (* ccc *) \noindent
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2947
  Since the current precedence of the threads in ready queue will always be boosted,
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2948
  there must be one inside it has the maximum precedence of the whole system. 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2949
*}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2950
lemma max_cp_readys_threads:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2951
  shows "Max (cp s ` readys s) = Max (cp s ` threads s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2952
proof(cases "threads s = {}")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2953
  case True
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2954
  thus ?thesis 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2955
    by (auto simp:readys_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2956
next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2957
  case False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2958
  show ?thesis by (rule max_cp_readys_threads_pre[OF False])
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2959
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2960
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2961
end
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2962
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2963
lemma eq_holding: "holding (wq s) th cs = holding s th cs"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2964
  apply (unfold s_holding_def cs_holding_def wq_def, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2965
  done
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2966
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2967
lemma f_image_eq:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2968
  assumes h: "\<And> a. a \<in> A \<Longrightarrow> f a = g a"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2969
  shows "f ` A = g ` A"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2970
proof
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2971
  show "f ` A \<subseteq> g ` A"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2972
    by(rule image_subsetI, auto intro:h)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2973
next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2974
  show "g ` A \<subseteq> f ` A"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2975
   by (rule image_subsetI, auto intro:h[symmetric])
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2976
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2977
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2978
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2979
definition detached :: "state \<Rightarrow> thread \<Rightarrow> bool"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2980
  where "detached s th \<equiv> (\<not>(\<exists> cs. holding s th cs)) \<and> (\<not>(\<exists>cs. waiting s th cs))"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2981
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2982
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2983
lemma detached_test:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2984
  shows "detached s th = (Th th \<notin> Field (RAG s))"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2985
apply(simp add: detached_def Field_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2986
apply(simp add: s_RAG_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2987
apply(simp add: s_holding_abv s_waiting_abv)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2988
apply(simp add: Domain_iff Range_iff)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2989
apply(simp add: wq_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2990
apply(auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2991
done
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2992
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2993
context valid_trace
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2994
begin
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2995
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2996
lemma detached_intro:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2997
  assumes eq_pv: "cntP s th = cntV s th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2998
  shows "detached s th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  2999
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3000
 from cnp_cnv_cncs
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3001
  have eq_cnt: "cntP s th =
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3002
    cntV s th + (if th \<in> readys s \<or> th \<notin> threads s then cntCS s th else cntCS s th + 1)" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3003
  hence cncs_zero: "cntCS s th = 0"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3004
    by (auto simp:eq_pv split:if_splits)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3005
  with eq_cnt
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3006
  have "th \<in> readys s \<or> th \<notin> threads s" by (auto simp:eq_pv)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3007
  thus ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3008
  proof
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3009
    assume "th \<notin> threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3010
    with range_in dm_RAG_threads
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3011
    show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3012
      by (auto simp add: detached_def s_RAG_def s_waiting_abv s_holding_abv wq_def Domain_iff Range_iff)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3013
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3014
    assume "th \<in> readys s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3015
    moreover have "Th th \<notin> Range (RAG s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3016
    proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3017
      from card_0_eq [OF finite_holding] and cncs_zero
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3018
      have "holdents s th = {}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3019
        by (simp add:cntCS_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3020
      thus ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3021
        apply(auto simp:holdents_test)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3022
        apply(case_tac a)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3023
        apply(auto simp:holdents_test s_RAG_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3024
        done
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3025
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3026
    ultimately show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3027
      by (auto simp add: detached_def s_RAG_def s_waiting_abv s_holding_abv wq_def readys_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3028
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3029
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3030
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3031
lemma detached_elim:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3032
  assumes dtc: "detached s th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3033
  shows "cntP s th = cntV s th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3034
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3035
  from cnp_cnv_cncs
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3036
  have eq_pv: " cntP s th =
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3037
    cntV s th + (if th \<in> readys s \<or> th \<notin> threads s then cntCS s th else cntCS s th + 1)" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3038
  have cncs_z: "cntCS s th = 0"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3039
  proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3040
    from dtc have "holdents s th = {}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3041
      unfolding detached_def holdents_test s_RAG_def
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3042
      by (simp add: s_waiting_abv wq_def s_holding_abv Domain_iff Range_iff)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3043
    thus ?thesis by (auto simp:cntCS_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3044
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3045
  show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3046
  proof(cases "th \<in> threads s")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3047
    case True
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3048
    with dtc 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3049
    have "th \<in> readys s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3050
      by (unfold readys_def detached_def Field_def Domain_def Range_def, 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3051
           auto simp:eq_waiting s_RAG_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3052
    with cncs_z and eq_pv show ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3053
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3054
    case False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3055
    with cncs_z and eq_pv show ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3056
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3057
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3058
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3059
lemma detached_eq:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3060
  shows "(detached s th) = (cntP s th = cntV s th)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3061
  by (insert vt, auto intro:detached_intro detached_elim)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3062
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3063
end
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3064
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3065
text {* 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3066
  The lemmas in this .thy file are all obvious lemmas, however, they still needs to be derived
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3067
  from the concise and miniature model of PIP given in PrioGDef.thy.
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3068
*}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3069
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3070
lemma eq_dependants: "dependants (wq s) = dependants s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3071
  by (simp add: s_dependants_abv wq_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3072
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3073
lemma next_th_unique: 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3074
  assumes nt1: "next_th s th cs th1"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3075
  and nt2: "next_th s th cs th2"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3076
  shows "th1 = th2"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3077
using assms by (unfold next_th_def, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3078
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3079
lemma birth_time_lt:  "s \<noteq> [] \<Longrightarrow> last_set th s < length s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3080
  apply (induct s, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3081
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3082
  fix a s
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3083
  assume ih: "s \<noteq> [] \<Longrightarrow> last_set th s < length s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3084
    and eq_as: "a # s \<noteq> []"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3085
  show "last_set th (a # s) < length (a # s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3086
  proof(cases "s \<noteq> []")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3087
    case False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3088
    from False show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3089
      by (cases a, auto simp:last_set.simps)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3090
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3091
    case True
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3092
    from ih [OF True] show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3093
      by (cases a, auto simp:last_set.simps)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3094
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3095
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3096
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3097
lemma th_in_ne: "th \<in> threads s \<Longrightarrow> s \<noteq> []"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3098
  by (induct s, auto simp:threads.simps)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3099
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3100
lemma preced_tm_lt: "th \<in> threads s \<Longrightarrow> preced th s = Prc x y \<Longrightarrow> y < length s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3101
  apply (drule_tac th_in_ne)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3102
  by (unfold preced_def, auto intro: birth_time_lt)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3103
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3104
lemma inj_the_preced: 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3105
  "inj_on (the_preced s) (threads s)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3106
  by (metis inj_onI preced_unique the_preced_def)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3107
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3108
lemma tRAG_alt_def: 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3109
  "tRAG s = {(Th th1, Th th2) | th1 th2. 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3110
                  \<exists> cs. (Th th1, Cs cs) \<in> RAG s \<and> (Cs cs, Th th2) \<in> RAG s}"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3111
 by (auto simp:tRAG_def RAG_split wRAG_def hRAG_def)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3112
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3113
lemma tRAG_Field:
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3114
  "Field (tRAG s) \<subseteq> Field (RAG s)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3115
  by (unfold tRAG_alt_def Field_def, auto)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3116
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3117
lemma tRAG_ancestorsE:
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3118
  assumes "x \<in> ancestors (tRAG s) u"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3119
  obtains th where "x = Th th"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3120
proof -
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3121
  from assms have "(u, x) \<in> (tRAG s)^+" 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3122
      by (unfold ancestors_def, auto)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3123
  from tranclE[OF this] obtain c where "(c, x) \<in> tRAG s" by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3124
  then obtain th where "x = Th th"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3125
    by (unfold tRAG_alt_def, auto)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3126
  from that[OF this] show ?thesis .
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3127
qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3128
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3129
lemma tRAG_mono:
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3130
  assumes "RAG s' \<subseteq> RAG s"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3131
  shows "tRAG s' \<subseteq> tRAG s"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3132
  using assms 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3133
  by (unfold tRAG_alt_def, auto)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3134
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3135
lemma holding_next_thI:
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3136
  assumes "holding s th cs"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3137
  and "length (wq s cs) > 1"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3138
  obtains th' where "next_th s th cs th'"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3139
proof -
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3140
  from assms(1)[folded eq_holding, unfolded cs_holding_def]
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3141
  have " th \<in> set (wq s cs) \<and> th = hd (wq s cs)" .
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3142
  then obtain rest where h1: "wq s cs = th#rest" 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3143
    by (cases "wq s cs", auto)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3144
  with assms(2) have h2: "rest \<noteq> []" by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3145
  let ?th' = "hd (SOME q. distinct q \<and> set q = set rest)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3146
  have "next_th s th cs ?th'" using  h1(1) h2 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3147
    by (unfold next_th_def, auto)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3148
  from that[OF this] show ?thesis .
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3149
qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3150
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3151
lemma RAG_tRAG_transfer:
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3152
  assumes "vt s'"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3153
  assumes "RAG s = RAG s' \<union> {(Th th, Cs cs)}"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3154
  and "(Cs cs, Th th'') \<in> RAG s'"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3155
  shows "tRAG s = tRAG s' \<union> {(Th th, Th th'')}" (is "?L = ?R")
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3156
proof -
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3157
  interpret vt_s': valid_trace "s'" using assms(1)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3158
    by (unfold_locales, simp)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3159
  interpret rtree: rtree "RAG s'"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3160
  proof
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3161
  show "single_valued (RAG s')"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3162
  apply (intro_locales)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3163
    by (unfold single_valued_def, 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3164
        auto intro:vt_s'.unique_RAG)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3165
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3166
  show "acyclic (RAG s')"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3167
     by (rule vt_s'.acyclic_RAG)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3168
  qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3169
  { fix n1 n2
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3170
    assume "(n1, n2) \<in> ?L"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3171
    from this[unfolded tRAG_alt_def]
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3172
    obtain th1 th2 cs' where 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3173
      h: "n1 = Th th1" "n2 = Th th2" 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3174
         "(Th th1, Cs cs') \<in> RAG s"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3175
         "(Cs cs', Th th2) \<in> RAG s" by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3176
    from h(4) and assms(2) have cs_in: "(Cs cs', Th th2) \<in> RAG s'" by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3177
    from h(3) and assms(2) 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3178
    have "(Th th1, Cs cs') = (Th th, Cs cs) \<or> 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3179
          (Th th1, Cs cs') \<in> RAG s'" by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3180
    hence "(n1, n2) \<in> ?R"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3181
    proof
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3182
      assume h1: "(Th th1, Cs cs') = (Th th, Cs cs)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3183
      hence eq_th1: "th1 = th" by simp
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3184
      moreover have "th2 = th''"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3185
      proof -
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3186
        from h1 have "cs' = cs" by simp
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3187
        from assms(3) cs_in[unfolded this] rtree.sgv
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3188
        show ?thesis
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3189
          by (unfold single_valued_def, auto)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3190
      qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3191
      ultimately show ?thesis using h(1,2) by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3192
    next
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3193
      assume "(Th th1, Cs cs') \<in> RAG s'"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3194
      with cs_in have "(Th th1, Th th2) \<in> tRAG s'"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3195
        by (unfold tRAG_alt_def, auto)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3196
      from this[folded h(1, 2)] show ?thesis by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3197
    qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3198
  } moreover {
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3199
    fix n1 n2
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3200
    assume "(n1, n2) \<in> ?R"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3201
    hence "(n1, n2) \<in>tRAG s' \<or> (n1, n2) = (Th th, Th th'')" by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3202
    hence "(n1, n2) \<in> ?L" 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3203
    proof
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3204
      assume "(n1, n2) \<in> tRAG s'"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3205
      moreover have "... \<subseteq> ?L"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3206
      proof(rule tRAG_mono)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3207
        show "RAG s' \<subseteq> RAG s" by (unfold assms(2), auto)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3208
      qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3209
      ultimately show ?thesis by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3210
    next
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3211
      assume eq_n: "(n1, n2) = (Th th, Th th'')"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3212
      from assms(2, 3) have "(Cs cs, Th th'') \<in> RAG s" by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3213
      moreover have "(Th th, Cs cs) \<in> RAG s" using assms(2) by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3214
      ultimately show ?thesis 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3215
        by (unfold eq_n tRAG_alt_def, auto)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3216
    qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3217
  } ultimately show ?thesis by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3218
qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3219
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3220
context valid_trace
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3221
begin
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3222
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3223
lemmas RAG_tRAG_transfer = RAG_tRAG_transfer[OF vt]
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3224
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
  3225
end
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3226
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3227
lemma cp_alt_def:
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3228
  "cp s th =  
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3229
           Max ((the_preced s) ` {th'. Th th' \<in> (subtree (RAG s) (Th th))})"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3230
proof -
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3231
  have "Max (the_preced s ` ({th} \<union> dependants (wq s) th)) =
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3232
        Max (the_preced s ` {th'. Th th' \<in> subtree (RAG s) (Th th)})" 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3233
          (is "Max (_ ` ?L) = Max (_ ` ?R)")
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3234
  proof -
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3235
    have "?L = ?R" 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3236
    by (auto dest:rtranclD simp:cs_dependants_def cs_RAG_def s_RAG_def subtree_def)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3237
    thus ?thesis by simp
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3238
  qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3239
  thus ?thesis by (unfold cp_eq_cpreced cpreced_def, fold the_preced_def, simp)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3240
qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3241
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3242
lemma cp_gen_alt_def:
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3243
  "cp_gen s = (Max \<circ> (\<lambda>x. (the_preced s \<circ> the_thread) ` subtree (tRAG s) x))"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3244
    by (auto simp:cp_gen_def)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3245
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3246
lemma tRAG_nodeE:
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3247
  assumes "(n1, n2) \<in> tRAG s"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3248
  obtains th1 th2 where "n1 = Th th1" "n2 = Th th2"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3249
  using assms
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3250
  by (auto simp: tRAG_def wRAG_def hRAG_def tRAG_def)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3251
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3252
lemma subtree_nodeE:
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3253
  assumes "n \<in> subtree (tRAG s) (Th th)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3254
  obtains th1 where "n = Th th1"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3255
proof -
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3256
  show ?thesis
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3257
  proof(rule subtreeE[OF assms])
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3258
    assume "n = Th th"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3259
    from that[OF this] show ?thesis .
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3260
  next
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3261
    assume "Th th \<in> ancestors (tRAG s) n"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3262
    hence "(n, Th th) \<in> (tRAG s)^+" by (auto simp:ancestors_def)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3263
    hence "\<exists> th1. n = Th th1"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3264
    proof(induct)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3265
      case (base y)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3266
      from tRAG_nodeE[OF this] show ?case by metis
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3267
    next
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3268
      case (step y z)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3269
      thus ?case by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3270
    qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3271
    with that show ?thesis by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3272
  qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3273
qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3274
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3275
lemma tRAG_star_RAG: "(tRAG s)^* \<subseteq> (RAG s)^*"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3276
proof -
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3277
  have "(wRAG s O hRAG s)^* \<subseteq> (RAG s O RAG s)^*" 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3278
    by (rule rtrancl_mono, auto simp:RAG_split)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3279
  also have "... \<subseteq> ((RAG s)^*)^*"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3280
    by (rule rtrancl_mono, auto)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3281
  also have "... = (RAG s)^*" by simp
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3282
  finally show ?thesis by (unfold tRAG_def, simp)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3283
qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3284
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3285
lemma tRAG_subtree_RAG: "subtree (tRAG s) x \<subseteq> subtree (RAG s) x"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3286
proof -
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3287
  { fix a
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3288
    assume "a \<in> subtree (tRAG s) x"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3289
    hence "(a, x) \<in> (tRAG s)^*" by (auto simp:subtree_def)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3290
    with tRAG_star_RAG[of s]
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3291
    have "(a, x) \<in> (RAG s)^*" by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3292
    hence "a \<in> subtree (RAG s) x" by (auto simp:subtree_def)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3293
  } thus ?thesis by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3294
qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3295
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3296
lemma tRAG_trancl_eq:
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3297
   "{th'. (Th th', Th th)  \<in> (tRAG s)^+} = 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3298
    {th'. (Th th', Th th)  \<in> (RAG s)^+}"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3299
   (is "?L = ?R")
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3300
proof -
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3301
  { fix th'
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3302
    assume "th' \<in> ?L"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3303
    hence "(Th th', Th th) \<in> (tRAG s)^+" by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3304
    from tranclD[OF this]
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3305
    obtain z where h: "(Th th', z) \<in> tRAG s" "(z, Th th) \<in> (tRAG s)\<^sup>*" by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3306
    from tRAG_subtree_RAG[of s] and this(2)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3307
    have "(z, Th th) \<in> (RAG s)^*" by (meson subsetCE tRAG_star_RAG) 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3308
    moreover from h(1) have "(Th th', z) \<in> (RAG s)^+" using tRAG_alt_def by auto 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3309
    ultimately have "th' \<in> ?R"  by auto 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3310
  } moreover 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3311
  { fix th'
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3312
    assume "th' \<in> ?R"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3313
    hence "(Th th', Th th) \<in> (RAG s)^+" by (auto)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3314
    from plus_rpath[OF this]
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3315
    obtain xs where rp: "rpath (RAG s) (Th th') xs (Th th)" "xs \<noteq> []" by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3316
    hence "(Th th', Th th) \<in> (tRAG s)^+"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3317
    proof(induct xs arbitrary:th' th rule:length_induct)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3318
      case (1 xs th' th)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3319
      then obtain x1 xs1 where Cons1: "xs = x1#xs1" by (cases xs, auto)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3320
      show ?case
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3321
      proof(cases "xs1")
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3322
        case Nil
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3323
        from 1(2)[unfolded Cons1 Nil]
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3324
        have rp: "rpath (RAG s) (Th th') [x1] (Th th)" .
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3325
        hence "(Th th', x1) \<in> (RAG s)" by (cases, simp)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3326
        then obtain cs where "x1 = Cs cs" 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3327
              by (unfold s_RAG_def, auto)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3328
        from rpath_nnl_lastE[OF rp[unfolded this]]
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3329
        show ?thesis by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3330
      next
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3331
        case (Cons x2 xs2)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3332
        from 1(2)[unfolded Cons1[unfolded this]]
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3333
        have rp: "rpath (RAG s) (Th th') (x1 # x2 # xs2) (Th th)" .
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3334
        from rpath_edges_on[OF this]
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3335
        have eds: "edges_on (Th th' # x1 # x2 # xs2) \<subseteq> RAG s" .
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3336
        have "(Th th', x1) \<in> edges_on (Th th' # x1 # x2 # xs2)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3337
            by (simp add: edges_on_unfold)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3338
        with eds have rg1: "(Th th', x1) \<in> RAG s" by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3339
        then obtain cs1 where eq_x1: "x1 = Cs cs1" by (unfold s_RAG_def, auto)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3340
        have "(x1, x2) \<in> edges_on (Th th' # x1 # x2 # xs2)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3341
            by (simp add: edges_on_unfold)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3342
        from this eds
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3343
        have rg2: "(x1, x2) \<in> RAG s" by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3344
        from this[unfolded eq_x1] 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3345
        obtain th1 where eq_x2: "x2 = Th th1" by (unfold s_RAG_def, auto)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3346
        from rg1[unfolded eq_x1] rg2[unfolded eq_x1 eq_x2]
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3347
        have rt1: "(Th th', Th th1) \<in> tRAG s" by (unfold tRAG_alt_def, auto)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3348
        from rp have "rpath (RAG s) x2 xs2 (Th th)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3349
           by  (elim rpath_ConsE, simp)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3350
        from this[unfolded eq_x2] have rp': "rpath (RAG s) (Th th1) xs2 (Th th)" .
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3351
        show ?thesis
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3352
        proof(cases "xs2 = []")
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3353
          case True
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3354
          from rpath_nilE[OF rp'[unfolded this]]
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3355
          have "th1 = th" by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3356
          from rt1[unfolded this] show ?thesis by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3357
        next
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3358
          case False
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3359
          from 1(1)[rule_format, OF _ rp' this, unfolded Cons1 Cons]
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3360
          have "(Th th1, Th th) \<in> (tRAG s)\<^sup>+" by simp
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3361
          with rt1 show ?thesis by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3362
        qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3363
      qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3364
    qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3365
    hence "th' \<in> ?L" by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3366
  } ultimately show ?thesis by blast
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3367
qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3368
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3369
lemma tRAG_trancl_eq_Th:
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3370
   "{Th th' | th'. (Th th', Th th)  \<in> (tRAG s)^+} = 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3371
    {Th th' | th'. (Th th', Th th)  \<in> (RAG s)^+}"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3372
    using tRAG_trancl_eq by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3373
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3374
lemma dependants_alt_def:
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3375
  "dependants s th = {th'. (Th th', Th th) \<in> (tRAG s)^+}"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3376
  by (metis eq_RAG s_dependants_def tRAG_trancl_eq)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3377
  
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3378
context valid_trace
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3379
begin
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3380
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3381
lemma count_eq_tRAG_plus:
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3382
  assumes "cntP s th = cntV s th"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3383
  shows "{th'. (Th th', Th th) \<in> (tRAG s)^+} = {}"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3384
  using assms count_eq_dependants dependants_alt_def eq_dependants by auto 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3385
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3386
lemma count_eq_RAG_plus:
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3387
  assumes "cntP s th = cntV s th"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3388
  shows "{th'. (Th th', Th th) \<in> (RAG s)^+} = {}"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3389
  using assms count_eq_dependants cs_dependants_def eq_RAG by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3390
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3391
lemma count_eq_RAG_plus_Th:
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3392
  assumes "cntP s th = cntV s th"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3393
  shows "{Th th' | th'. (Th th', Th th) \<in> (RAG s)^+} = {}"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3394
  using count_eq_RAG_plus[OF assms] by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3395
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3396
lemma count_eq_tRAG_plus_Th:
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3397
  assumes "cntP s th = cntV s th"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3398
  shows "{Th th' | th'. (Th th', Th th) \<in> (tRAG s)^+} = {}"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3399
   using count_eq_tRAG_plus[OF assms] by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3400
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3401
end
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3402
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3403
lemma tRAG_subtree_eq: 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3404
   "(subtree (tRAG s) (Th th)) = {Th th' | th'. Th th'  \<in> (subtree (RAG s) (Th th))}"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3405
   (is "?L = ?R")
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3406
proof -
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3407
  { fix n 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3408
    assume h: "n \<in> ?L"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3409
    hence "n \<in> ?R"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3410
    by (smt mem_Collect_eq subsetCE subtree_def subtree_nodeE tRAG_subtree_RAG) 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3411
  } moreover {
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3412
    fix n
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3413
    assume "n \<in> ?R"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3414
    then obtain th' where h: "n = Th th'" "(Th th', Th th) \<in> (RAG s)^*"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3415
      by (auto simp:subtree_def)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3416
    from rtranclD[OF this(2)]
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3417
    have "n \<in> ?L"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3418
    proof
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3419
      assume "Th th' \<noteq> Th th \<and> (Th th', Th th) \<in> (RAG s)\<^sup>+"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3420
      with h have "n \<in> {Th th' | th'. (Th th', Th th)  \<in> (RAG s)^+}" by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3421
      thus ?thesis using subtree_def tRAG_trancl_eq by fastforce
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3422
    qed (insert h, auto simp:subtree_def)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3423
  } ultimately show ?thesis by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3424
qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3425
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3426
lemma threads_set_eq: 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3427
   "the_thread ` (subtree (tRAG s) (Th th)) = 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3428
                  {th'. Th th' \<in> (subtree (RAG s) (Th th))}" (is "?L = ?R")
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3429
   by (auto intro:rev_image_eqI simp:tRAG_subtree_eq)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3430
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3431
lemma cp_alt_def1: 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3432
  "cp s th = Max ((the_preced s o the_thread) ` (subtree (tRAG s) (Th th)))"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3433
proof -
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3434
  have "(the_preced s ` the_thread ` subtree (tRAG s) (Th th)) =
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3435
       ((the_preced s \<circ> the_thread) ` subtree (tRAG s) (Th th))"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3436
       by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3437
  thus ?thesis by (unfold cp_alt_def, fold threads_set_eq, auto)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3438
qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3439
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3440
lemma cp_gen_def_cond: 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3441
  assumes "x = Th th"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3442
  shows "cp s th = cp_gen s (Th th)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3443
by (unfold cp_alt_def1 cp_gen_def, simp)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3444
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3445
lemma cp_gen_over_set:
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3446
  assumes "\<forall> x \<in> A. \<exists> th. x = Th th"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3447
  shows "cp_gen s ` A = (cp s \<circ> the_thread) ` A"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3448
proof(rule f_image_eq)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3449
  fix a
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3450
  assume "a \<in> A"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3451
  from assms[rule_format, OF this]
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3452
  obtain th where eq_a: "a = Th th" by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3453
  show "cp_gen s a = (cp s \<circ> the_thread) a"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3454
    by  (unfold eq_a, simp, unfold cp_gen_def_cond[OF refl[of "Th th"]], simp)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3455
qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3456
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3457
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3458
context valid_trace
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3459
begin
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3460
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3461
lemma RAG_threads:
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3462
  assumes "(Th th) \<in> Field (RAG s)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3463
  shows "th \<in> threads s"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3464
  using assms
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3465
  by (metis Field_def UnE dm_RAG_threads range_in vt)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3466
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3467
lemma subtree_tRAG_thread:
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3468
  assumes "th \<in> threads s"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3469
  shows "subtree (tRAG s) (Th th) \<subseteq> Th ` threads s" (is "?L \<subseteq> ?R")
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3470
proof -
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3471
  have "?L = {Th th' |th'. Th th' \<in> subtree (RAG s) (Th th)}"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3472
    by (unfold tRAG_subtree_eq, simp)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3473
  also have "... \<subseteq> ?R"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3474
  proof
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3475
    fix x
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3476
    assume "x \<in> {Th th' |th'. Th th' \<in> subtree (RAG s) (Th th)}"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3477
    then obtain th' where h: "x = Th th'" "Th th' \<in> subtree (RAG s) (Th th)" by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3478
    from this(2)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3479
    show "x \<in> ?R"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3480
    proof(cases rule:subtreeE)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3481
      case 1
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3482
      thus ?thesis by (simp add: assms h(1)) 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3483
    next
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3484
      case 2
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3485
      thus ?thesis by (metis ancestors_Field dm_RAG_threads h(1) image_eqI) 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3486
    qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3487
  qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3488
  finally show ?thesis .
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3489
qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3490
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3491
lemma readys_root:
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3492
  assumes "th \<in> readys s"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3493
  shows "root (RAG s) (Th th)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3494
proof -
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3495
  { fix x
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3496
    assume "x \<in> ancestors (RAG s) (Th th)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3497
    hence h: "(Th th, x) \<in> (RAG s)^+" by (auto simp:ancestors_def)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3498
    from tranclD[OF this]
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3499
    obtain z where "(Th th, z) \<in> RAG s" by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3500
    with assms(1) have False
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3501
         apply (case_tac z, auto simp:readys_def s_RAG_def s_waiting_def cs_waiting_def)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3502
         by (fold wq_def, blast)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3503
  } thus ?thesis by (unfold root_def, auto)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3504
qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3505
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3506
lemma readys_in_no_subtree:
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3507
  assumes "th \<in> readys s"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3508
  and "th' \<noteq> th"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3509
  shows "Th th \<notin> subtree (RAG s) (Th th')" 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3510
proof
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3511
   assume "Th th \<in> subtree (RAG s) (Th th')"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3512
   thus False
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3513
   proof(cases rule:subtreeE)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3514
      case 1
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3515
      with assms show ?thesis by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3516
   next
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3517
      case 2
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3518
      with readys_root[OF assms(1)]
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3519
      show ?thesis by (auto simp:root_def)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3520
   qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3521
qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3522
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3523
lemma not_in_thread_isolated:
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3524
  assumes "th \<notin> threads s"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3525
  shows "(Th th) \<notin> Field (RAG s)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3526
proof
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3527
  assume "(Th th) \<in> Field (RAG s)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3528
  with dm_RAG_threads and range_in assms
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3529
  show False by (unfold Field_def, blast)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3530
qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3531
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3532
lemma wf_RAG: "wf (RAG s)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3533
proof(rule finite_acyclic_wf)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3534
  from finite_RAG show "finite (RAG s)" .
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3535
next
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3536
  from acyclic_RAG show "acyclic (RAG s)" .
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3537
qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3538
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3539
lemma sgv_wRAG: "single_valued (wRAG s)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3540
  using waiting_unique
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3541
  by (unfold single_valued_def wRAG_def, auto)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3542
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3543
lemma sgv_hRAG: "single_valued (hRAG s)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3544
  using holding_unique 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3545
  by (unfold single_valued_def hRAG_def, auto)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3546
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3547
lemma sgv_tRAG: "single_valued (tRAG s)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3548
  by (unfold tRAG_def, rule single_valued_relcomp, 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3549
              insert sgv_wRAG sgv_hRAG, auto)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3550
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3551
lemma acyclic_tRAG: "acyclic (tRAG s)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3552
proof(unfold tRAG_def, rule acyclic_compose)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3553
  show "acyclic (RAG s)" using acyclic_RAG .
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3554
next
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3555
  show "wRAG s \<subseteq> RAG s" unfolding RAG_split by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3556
next
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3557
  show "hRAG s \<subseteq> RAG s" unfolding RAG_split by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3558
qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3559
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3560
lemma sgv_RAG: "single_valued (RAG s)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3561
  using unique_RAG by (auto simp:single_valued_def)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3562
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3563
lemma rtree_RAG: "rtree (RAG s)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3564
  using sgv_RAG acyclic_RAG
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3565
  by (unfold rtree_def rtree_axioms_def sgv_def, auto)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3566
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3567
end
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3568
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3569
sublocale valid_trace < rtree_RAG: rtree "RAG s"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3570
proof
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3571
  show "single_valued (RAG s)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3572
  apply (intro_locales)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3573
    by (unfold single_valued_def, 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3574
        auto intro:unique_RAG)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3575
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3576
  show "acyclic (RAG s)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3577
     by (rule acyclic_RAG)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3578
qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3579
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3580
sublocale valid_trace < rtree_s: rtree "tRAG s"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3581
proof(unfold_locales)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3582
  from sgv_tRAG show "single_valued (tRAG s)" .
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3583
next
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3584
  from acyclic_tRAG show "acyclic (tRAG s)" .
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3585
qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3586
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3587
sublocale valid_trace < fsbtRAGs : fsubtree "RAG s"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3588
proof -
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3589
  show "fsubtree (RAG s)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3590
  proof(intro_locales)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3591
    show "fbranch (RAG s)" using finite_fbranchI[OF finite_RAG] .
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3592
  next
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3593
    show "fsubtree_axioms (RAG s)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3594
    proof(unfold fsubtree_axioms_def)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3595
      from wf_RAG show "wf (RAG s)" .
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3596
    qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3597
  qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3598
qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3599
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3600
sublocale valid_trace < fsbttRAGs: fsubtree "tRAG s"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3601
proof -
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3602
  have "fsubtree (tRAG s)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3603
  proof -
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3604
    have "fbranch (tRAG s)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3605
    proof(unfold tRAG_def, rule fbranch_compose)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3606
        show "fbranch (wRAG s)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3607
        proof(rule finite_fbranchI)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3608
           from finite_RAG show "finite (wRAG s)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3609
           by (unfold RAG_split, auto)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3610
        qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3611
    next
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3612
        show "fbranch (hRAG s)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3613
        proof(rule finite_fbranchI)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3614
           from finite_RAG 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3615
           show "finite (hRAG s)" by (unfold RAG_split, auto)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3616
        qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3617
    qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3618
    moreover have "wf (tRAG s)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3619
    proof(rule wf_subset)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3620
      show "wf (RAG s O RAG s)" using wf_RAG
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3621
        by (fold wf_comp_self, simp)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3622
    next
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3623
      show "tRAG s \<subseteq> (RAG s O RAG s)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3624
        by (unfold tRAG_alt_def, auto)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3625
    qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3626
    ultimately show ?thesis
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3627
      by (unfold fsubtree_def fsubtree_axioms_def,auto)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3628
  qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3629
  from this[folded tRAG_def] show "fsubtree (tRAG s)" .
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3630
qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3631
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3632
lemma Max_UNION: 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3633
  assumes "finite A"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3634
  and "A \<noteq> {}"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3635
  and "\<forall> M \<in> f ` A. finite M"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3636
  and "\<forall> M \<in> f ` A. M \<noteq> {}"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3637
  shows "Max (\<Union>x\<in> A. f x) = Max (Max ` f ` A)" (is "?L = ?R")
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3638
  using assms[simp]
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3639
proof -
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3640
  have "?L = Max (\<Union>(f ` A))"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3641
    by (fold Union_image_eq, simp)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3642
  also have "... = ?R"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3643
    by (subst Max_Union, simp+)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3644
  finally show ?thesis .
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3645
qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3646
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3647
lemma max_Max_eq:
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3648
  assumes "finite A"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3649
    and "A \<noteq> {}"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3650
    and "x = y"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3651
  shows "max x (Max A) = Max ({y} \<union> A)" (is "?L = ?R")
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3652
proof -
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3653
  have "?R = Max (insert y A)" by simp
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3654
  also from assms have "... = ?L"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3655
      by (subst Max.insert, simp+)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3656
  finally show ?thesis by simp
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3657
qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3658
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3659
context valid_trace
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3660
begin
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3661
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3662
(* ddd *)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3663
lemma cp_gen_rec:
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3664
  assumes "x = Th th"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3665
  shows "cp_gen s x = Max ({the_preced s th} \<union> (cp_gen s) ` children (tRAG s) x)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3666
proof(cases "children (tRAG s) x = {}")
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3667
  case True
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3668
  show ?thesis
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3669
    by (unfold True cp_gen_def subtree_children, simp add:assms)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3670
next
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3671
  case False
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3672
  hence [simp]: "children (tRAG s) x \<noteq> {}" by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3673
  note fsbttRAGs.finite_subtree[simp]
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3674
  have [simp]: "finite (children (tRAG s) x)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3675
     by (intro rev_finite_subset[OF fsbttRAGs.finite_subtree], 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3676
            rule children_subtree)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3677
  { fix r x
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3678
    have "subtree r x \<noteq> {}" by (auto simp:subtree_def)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3679
  } note this[simp]
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3680
  have [simp]: "\<exists>x\<in>children (tRAG s) x. subtree (tRAG s) x \<noteq> {}"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3681
  proof -
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3682
    from False obtain q where "q \<in> children (tRAG s) x" by blast
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3683
    moreover have "subtree (tRAG s) q \<noteq> {}" by simp
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3684
    ultimately show ?thesis by blast
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3685
  qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3686
  have h: "Max ((the_preced s \<circ> the_thread) `
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3687
                ({x} \<union> \<Union>(subtree (tRAG s) ` children (tRAG s) x))) =
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3688
        Max ({the_preced s th} \<union> cp_gen s ` children (tRAG s) x)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3689
                     (is "?L = ?R")
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3690
  proof -
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3691
    let "Max (?f ` (?A \<union> \<Union> (?g ` ?B)))" = ?L
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3692
    let "Max (_ \<union> (?h ` ?B))" = ?R
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3693
    let ?L1 = "?f ` \<Union>(?g ` ?B)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3694
    have eq_Max_L1: "Max ?L1 = Max (?h ` ?B)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3695
    proof -
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3696
      have "?L1 = ?f ` (\<Union> x \<in> ?B.(?g x))" by simp
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3697
      also have "... =  (\<Union> x \<in> ?B. ?f ` (?g x))" by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3698
      finally have "Max ?L1 = Max ..." by simp
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3699
      also have "... = Max (Max ` (\<lambda>x. ?f ` subtree (tRAG s) x) ` ?B)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3700
        by (subst Max_UNION, simp+)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3701
      also have "... = Max (cp_gen s ` children (tRAG s) x)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3702
          by (unfold image_comp cp_gen_alt_def, simp)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3703
      finally show ?thesis .
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3704
    qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3705
    show ?thesis
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3706
    proof -
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3707
      have "?L = Max (?f ` ?A \<union> ?L1)" by simp
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3708
      also have "... = max (the_preced s (the_thread x)) (Max ?L1)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3709
            by (subst Max_Un, simp+)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3710
      also have "... = max (?f x) (Max (?h ` ?B))"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3711
        by (unfold eq_Max_L1, simp)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3712
      also have "... =?R"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3713
        by (rule max_Max_eq, (simp)+, unfold assms, simp)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3714
      finally show ?thesis .
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3715
    qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3716
  qed  thus ?thesis 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3717
          by (fold h subtree_children, unfold cp_gen_def, simp) 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3718
qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3719
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3720
lemma cp_rec:
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3721
  "cp s th = Max ({the_preced s th} \<union> 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3722
                     (cp s o the_thread) ` children (tRAG s) (Th th))"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3723
proof -
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3724
  have "Th th = Th th" by simp
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3725
  note h =  cp_gen_def_cond[OF this] cp_gen_rec[OF this]
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3726
  show ?thesis 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3727
  proof -
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3728
    have "cp_gen s ` children (tRAG s) (Th th) = 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3729
                (cp s \<circ> the_thread) ` children (tRAG s) (Th th)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3730
    proof(rule cp_gen_over_set)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3731
      show " \<forall>x\<in>children (tRAG s) (Th th). \<exists>th. x = Th th"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3732
        by (unfold tRAG_alt_def, auto simp:children_def)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3733
    qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3734
    thus ?thesis by (subst (1) h(1), unfold h(2), simp)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3735
  qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3736
qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3737
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3738
end
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3739
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3740
(* keep *)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3741
lemma next_th_holding:
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3742
  assumes vt: "vt s"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3743
  and nxt: "next_th s th cs th'"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3744
  shows "holding (wq s) th cs"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3745
proof -
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3746
  from nxt[unfolded next_th_def]
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3747
  obtain rest where h: "wq s cs = th # rest"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3748
                       "rest \<noteq> []" 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3749
                       "th' = hd (SOME q. distinct q \<and> set q = set rest)" by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3750
  thus ?thesis
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3751
    by (unfold cs_holding_def, auto)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3752
qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3753
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3754
context valid_trace
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3755
begin
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3756
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3757
lemma next_th_waiting:
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3758
  assumes nxt: "next_th s th cs th'"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3759
  shows "waiting (wq s) th' cs"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3760
proof -
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3761
  from nxt[unfolded next_th_def]
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3762
  obtain rest where h: "wq s cs = th # rest"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3763
                       "rest \<noteq> []" 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3764
                       "th' = hd (SOME q. distinct q \<and> set q = set rest)" by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3765
  from wq_distinct[of cs, unfolded h]
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3766
  have dst: "distinct (th # rest)" .
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3767
  have in_rest: "th' \<in> set rest"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3768
  proof(unfold h, rule someI2)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3769
    show "distinct rest \<and> set rest = set rest" using dst by auto
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3770
  next
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3771
    fix x assume "distinct x \<and> set x = set rest"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3772
    with h(2)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3773
    show "hd x \<in> set (rest)" by (cases x, auto)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3774
  qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3775
  hence "th' \<in> set (wq s cs)" by (unfold h(1), auto)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3776
  moreover have "th' \<noteq> hd (wq s cs)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3777
    by (unfold h(1), insert in_rest dst, auto)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3778
  ultimately show ?thesis by (auto simp:cs_waiting_def)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3779
qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3780
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3781
lemma next_th_RAG:
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3782
  assumes nxt: "next_th (s::event list) th cs th'"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3783
  shows "{(Cs cs, Th th), (Th th', Cs cs)} \<subseteq> RAG s"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3784
  using vt assms next_th_holding next_th_waiting
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3785
  by (unfold s_RAG_def, simp)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3786
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3787
end
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3788
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3789
-- {* A useless definition *}
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3790
definition cps:: "state \<Rightarrow> (thread \<times> precedence) set"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3791
where "cps s = {(th, cp s th) | th . th \<in> threads s}"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3792
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
  3793
end