Correctness.thy~
author zhangx
Sat, 09 Jan 2016 22:19:27 +0800
changeset 67 25fd656667a7
parent 66 2af87bb52fca
child 68 db196b066b97
permissions -rw-r--r--
Correctness simplified a great deal.
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 Correctness
66
2af87bb52fca Some small improvements in Correctness.thy.
zhangx
parents: 65
diff changeset
     2
imports PIPBasics
65
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
text {* 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
     6
  The following two auxiliary lemmas are used to reason about @{term Max}.
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
     7
*}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
     8
lemma image_Max_eqI: 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
     9
  assumes "finite B"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    10
  and "b \<in> B"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    11
  and "\<forall> x \<in> B. f x \<le> f b"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    12
  shows "Max (f ` B) = f b"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    13
  using assms
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    14
  using Max_eqI by blast 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    15
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    16
lemma image_Max_subset:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    17
  assumes "finite A"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    18
  and "B \<subseteq> A"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    19
  and "a \<in> B"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    20
  and "Max (f ` A) = f a"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    21
  shows "Max (f ` B) = f a"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    22
proof(rule image_Max_eqI)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    23
  show "finite B"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    24
    using assms(1) assms(2) finite_subset by auto 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    25
next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    26
  show "a \<in> B" using assms by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    27
next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    28
  show "\<forall>x\<in>B. f x \<le> f a"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    29
    by (metis Max_ge assms(1) assms(2) assms(4) 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    30
            finite_imageI image_eqI subsetCE) 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    31
qed
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
text {*
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    34
  The following locale @{text "highest_gen"} sets the basic context for our
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    35
  investigation: supposing thread @{text th} holds the highest @{term cp}-value
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    36
  in state @{text s}, which means the task for @{text th} is the 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    37
  most urgent. We want to show that  
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    38
  @{text th} is treated correctly by PIP, which means
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    39
  @{text th} will not be blocked unreasonably by other less urgent
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    40
  threads. 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    41
*}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    42
locale highest_gen =
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    43
  fixes s th prio tm
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    44
  assumes vt_s: "vt s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    45
  and threads_s: "th \<in> threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    46
  and highest: "preced th s = Max ((cp s)`threads s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    47
  -- {* The internal structure of @{term th}'s precedence is exposed:*}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    48
  and preced_th: "preced th s = Prc prio tm" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    49
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    50
-- {* @{term s} is a valid trace, so it will inherit all results derived for
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    51
      a valid trace: *}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    52
sublocale highest_gen < vat_s: valid_trace "s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    53
  by (unfold_locales, insert vt_s, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    54
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    55
context highest_gen
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    56
begin
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    57
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    58
text {*
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    59
  @{term tm} is the time when the precedence of @{term th} is set, so 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    60
  @{term tm} must be a valid moment index into @{term s}.
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 lt_tm: "tm < length s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    63
  by (insert preced_tm_lt[OF threads_s preced_th], simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    64
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    65
text {*
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    66
  Since @{term th} holds the highest precedence and @{text "cp"}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    67
  is the highest precedence of all threads in the sub-tree of 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    68
  @{text "th"} and @{text th} is among these threads, 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    69
  its @{term cp} must equal to its precedence:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    70
*}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    71
lemma eq_cp_s_th: "cp s th = preced th s" (is "?L = ?R")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    72
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    73
  have "?L \<le> ?R"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    74
  by (unfold highest, rule Max_ge, 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    75
        auto simp:threads_s finite_threads)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    76
  moreover have "?R \<le> ?L"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    77
    by (unfold vat_s.cp_rec, rule Max_ge, 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    78
        auto simp:the_preced_def vat_s.fsbttRAGs.finite_children)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    79
  ultimately show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    80
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    81
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    82
lemma highest_cp_preced: "cp s th = Max ((\<lambda> th'. preced th' s) ` threads s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    83
  by (fold max_cp_eq, unfold eq_cp_s_th, insert highest, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    84
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    85
lemma highest_preced_thread: "preced th s = Max ((\<lambda> th'. preced th' s) ` threads s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    86
  by (fold eq_cp_s_th, unfold highest_cp_preced, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    87
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    88
lemma highest': "cp s th = Max (cp s ` threads s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    89
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    90
  from highest_cp_preced max_cp_eq[symmetric]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    91
  show ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    92
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    93
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    94
end
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    95
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    96
locale extend_highest_gen = highest_gen + 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    97
  fixes t 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    98
  assumes vt_t: "vt (t@s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
    99
  and create_low: "Create th' prio' \<in> set t \<Longrightarrow> prio' \<le> prio"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   100
  and set_diff_low: "Set th' prio' \<in> set t \<Longrightarrow> th' \<noteq> th \<and> prio' \<le> prio"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   101
  and exit_diff: "Exit th' \<in> set t \<Longrightarrow> th' \<noteq> th"
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
sublocale extend_highest_gen < vat_t: valid_trace "t@s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   104
  by (unfold_locales, insert vt_t, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   105
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   106
lemma step_back_vt_app: 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   107
  assumes vt_ts: "vt (t@s)" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   108
  shows "vt s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   109
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   110
  from vt_ts show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   111
  proof(induct t)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   112
    case Nil
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   113
    from Nil show ?case by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   114
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   115
    case (Cons e t)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   116
    assume ih: " vt (t @ s) \<Longrightarrow> vt s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   117
      and vt_et: "vt ((e # t) @ s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   118
    show ?case
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   119
    proof(rule ih)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   120
      show "vt (t @ s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   121
      proof(rule step_back_vt)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   122
        from vt_et show "vt (e # t @ s)" by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   123
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   124
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   125
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   126
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   127
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   128
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   129
locale red_extend_highest_gen = extend_highest_gen +
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   130
   fixes i::nat
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   131
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   132
sublocale red_extend_highest_gen <   red_moment: extend_highest_gen "s" "th" "prio" "tm" "(moment i t)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   133
  apply (insert extend_highest_gen_axioms, subst (asm) (1) moment_restm_s [of i t, symmetric])
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   134
  apply (unfold extend_highest_gen_def extend_highest_gen_axioms_def, clarsimp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   135
  by (unfold highest_gen_def, auto dest:step_back_vt_app)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   136
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   137
context extend_highest_gen
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   138
begin
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   139
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   140
 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
   141
  assumes 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   142
    h0: "R []"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   143
  and h2: "\<And> e t. \<lbrakk>vt (t@s); step (t@s) e; 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   144
                    extend_highest_gen s th prio tm t; 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   145
                    extend_highest_gen s th prio tm (e#t); R t\<rbrakk> \<Longrightarrow> R (e#t)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   146
  shows "R t"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   147
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   148
  from vt_t extend_highest_gen_axioms show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   149
  proof(induct t)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   150
    from h0 show "R []" .
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
    case (Cons e t')
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   153
    assume ih: "\<lbrakk>vt (t' @ s); extend_highest_gen s th prio tm t'\<rbrakk> \<Longrightarrow> R t'"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   154
      and vt_e: "vt ((e # t') @ s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   155
      and et: "extend_highest_gen s th prio tm (e # t')"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   156
    from vt_e and step_back_step have stp: "step (t'@s) e" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   157
    from vt_e and step_back_vt have vt_ts: "vt (t'@s)" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   158
    show ?case
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   159
    proof(rule h2 [OF vt_ts stp _ _ _ ])
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   160
      show "R t'"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   161
      proof(rule ih)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   162
        from et show ext': "extend_highest_gen s th prio tm t'"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   163
          by (unfold extend_highest_gen_def extend_highest_gen_axioms_def, auto dest:step_back_vt)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   164
      next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   165
        from vt_ts show "vt (t' @ s)" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   166
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   167
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   168
      from et show "extend_highest_gen s th prio tm (e # t')" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   169
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   170
      from et show ext': "extend_highest_gen s th prio tm t'"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   171
          by (unfold extend_highest_gen_def extend_highest_gen_axioms_def, auto dest:step_back_vt)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   172
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   173
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   174
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   175
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 th_kept: "th \<in> threads (t @ s) \<and> 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   178
                 preced th (t@s) = preced th s" (is "?Q t") 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   179
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   180
  show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   181
  proof(induct rule:ind)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   182
    case Nil
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   183
    from threads_s
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   184
    show ?case
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   185
      by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   186
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   187
    case (Cons e t)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   188
    interpret h_e: extend_highest_gen _ _ _ _ "(e # t)" using Cons by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   189
    interpret h_t: extend_highest_gen _ _ _ _ t using Cons by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   190
    show ?case
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   191
    proof(cases e)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   192
      case (Create thread prio)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   193
      show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   194
      proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   195
        from Cons and Create have "step (t@s) (Create thread prio)" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   196
        hence "th \<noteq> thread"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   197
        proof(cases)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   198
          case thread_create
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   199
          with Cons show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   200
        qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   201
        hence "preced th ((e # t) @ s)  = preced th (t @ s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   202
          by (unfold Create, auto simp:preced_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   203
        moreover note Cons
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   204
        ultimately show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   205
          by (auto simp:Create)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   206
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   207
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   208
      case (Exit thread)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   209
      from h_e.exit_diff and Exit
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   210
      have neq_th: "thread \<noteq> th" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   211
      with Cons
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   212
      show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   213
        by (unfold Exit, auto simp:preced_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   214
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   215
      case (P thread cs)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   216
      with Cons
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   217
      show ?thesis 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   218
        by (auto simp:P preced_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   219
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   220
      case (V thread cs)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   221
      with Cons
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   222
      show ?thesis 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   223
        by (auto simp:V preced_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   224
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   225
      case (Set thread prio')
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   226
      show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   227
      proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   228
        from h_e.set_diff_low and Set
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   229
        have "th \<noteq> thread" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   230
        hence "preced th ((e # t) @ s)  = preced th (t @ s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   231
          by (unfold Set, auto simp:preced_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   232
        moreover note Cons
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   233
        ultimately show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   234
          by (auto simp:Set)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   235
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   236
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   237
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   238
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   239
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   240
text {*
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   241
  According to @{thm th_kept}, thread @{text "th"} has its living status
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   242
  and precedence kept along the way of @{text "t"}. The following lemma
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   243
  shows that this preserved precedence of @{text "th"} remains as the highest
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   244
  along the way of @{text "t"}.
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   245
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   246
  The proof goes by induction over @{text "t"} using the specialized
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   247
  induction rule @{thm ind}, followed by case analysis of each possible 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   248
  operations of PIP. All cases follow the same pattern rendered by the 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   249
  generalized introduction rule @{thm "image_Max_eqI"}. 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   250
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   251
  The very essence is to show that precedences, no matter whether they are newly introduced 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   252
  or modified, are always lower than the one held by @{term "th"},
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   253
  which by @{thm th_kept} is preserved along the way.
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   254
*}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   255
lemma max_kept: "Max (the_preced (t @ s) ` (threads (t@s))) = preced th s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   256
proof(induct rule:ind)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   257
  case Nil
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   258
  from highest_preced_thread
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   259
  show ?case
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   260
    by (unfold the_preced_def, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   261
next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   262
  case (Cons e t)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   263
    interpret h_e: extend_highest_gen _ _ _ _ "(e # t)" using Cons by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   264
    interpret h_t: extend_highest_gen _ _ _ _ t using Cons by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   265
  show ?case
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   266
  proof(cases e)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   267
    case (Create thread prio')
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   268
    show ?thesis (is "Max (?f ` ?A) = ?t")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   269
    proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   270
      -- {* The following is the common pattern of each branch of the case analysis. *}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   271
      -- {* The major part is to show that @{text "th"} holds the highest precedence: *}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   272
      have "Max (?f ` ?A) = ?f th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   273
      proof(rule image_Max_eqI)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   274
        show "finite ?A" using h_e.finite_threads by auto 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   275
      next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   276
        show "th \<in> ?A" using h_e.th_kept by auto 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   277
      next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   278
        show "\<forall>x\<in>?A. ?f x \<le> ?f th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   279
        proof 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   280
          fix x
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   281
          assume "x \<in> ?A"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   282
          hence "x = thread \<or> x \<in> threads (t@s)" by (auto simp:Create)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   283
          thus "?f x \<le> ?f th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   284
          proof
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   285
            assume "x = thread"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   286
            thus ?thesis 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   287
              apply (simp add:Create the_preced_def preced_def, fold preced_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   288
              using Create h_e.create_low h_t.th_kept lt_tm preced_leI2 preced_th by force
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   289
          next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   290
            assume h: "x \<in> threads (t @ s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   291
            from Cons(2)[unfolded Create] 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   292
            have "x \<noteq> thread" using h by (cases, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   293
            hence "?f x = the_preced (t@s) x" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   294
              by (simp add:Create the_preced_def preced_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   295
            hence "?f x \<le> Max (the_preced (t@s) ` threads (t@s))"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   296
              by (simp add: h_t.finite_threads h)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   297
            also have "... = ?f th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   298
              by (metis Cons.hyps(5) h_e.th_kept the_preced_def) 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   299
            finally show ?thesis .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   300
          qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   301
        qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   302
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   303
     -- {* The minor part is to show that the precedence of @{text "th"} 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   304
           equals to preserved one, given by the foregoing lemma @{thm th_kept} *}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   305
      also have "... = ?t" using h_e.th_kept the_preced_def by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   306
      -- {* Then it follows trivially that the precedence preserved
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   307
            for @{term "th"} remains the maximum of all living threads along the way. *}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   308
      finally show ?thesis .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   309
    qed 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   310
  next 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   311
    case (Exit thread)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   312
    show ?thesis (is "Max (?f ` ?A) = ?t")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   313
    proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   314
      have "Max (?f ` ?A) = ?f th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   315
      proof(rule image_Max_eqI)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   316
        show "finite ?A" using h_e.finite_threads by auto 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   317
      next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   318
        show "th \<in> ?A" using h_e.th_kept by auto 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   319
      next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   320
        show "\<forall>x\<in>?A. ?f x \<le> ?f th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   321
        proof 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   322
          fix x
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   323
          assume "x \<in> ?A"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   324
          hence "x \<in> threads (t@s)" by (simp add: Exit) 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   325
          hence "?f x \<le> Max (?f ` threads (t@s))" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   326
            by (simp add: h_t.finite_threads) 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   327
          also have "... \<le> ?f th" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   328
            apply (simp add:Exit the_preced_def preced_def, fold preced_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   329
            using Cons.hyps(5) h_t.th_kept the_preced_def by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   330
          finally show "?f x \<le> ?f th" .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   331
        qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   332
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   333
      also have "... = ?t" using h_e.th_kept the_preced_def by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   334
      finally show ?thesis .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   335
    qed 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   336
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   337
    case (P thread cs)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   338
    with Cons
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   339
    show ?thesis by (auto simp:preced_def the_preced_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   340
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   341
    case (V thread cs)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   342
    with Cons
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   343
    show ?thesis by (auto simp:preced_def the_preced_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   344
  next 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   345
    case (Set thread prio')
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   346
    show ?thesis (is "Max (?f ` ?A) = ?t")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   347
    proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   348
      have "Max (?f ` ?A) = ?f th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   349
      proof(rule image_Max_eqI)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   350
        show "finite ?A" using h_e.finite_threads by auto 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   351
      next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   352
        show "th \<in> ?A" using h_e.th_kept 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
        show "\<forall>x\<in>?A. ?f x \<le> ?f th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   355
        proof 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   356
          fix x
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   357
          assume h: "x \<in> ?A"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   358
          show "?f x \<le> ?f th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   359
          proof(cases "x = thread")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   360
            case True
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   361
            moreover have "the_preced (Set thread prio' # t @ s) thread \<le> the_preced (t @ s) th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   362
            proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   363
              have "the_preced (t @ s) th = Prc prio tm"  
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   364
                using h_t.th_kept preced_th by (simp add:the_preced_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   365
              moreover have "prio' \<le> prio" using Set h_e.set_diff_low by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   366
              ultimately show ?thesis by (insert lt_tm, auto simp:the_preced_def preced_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   367
            qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   368
            ultimately show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   369
              by (unfold Set, simp add:the_preced_def preced_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   370
          next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   371
            case False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   372
            then have "?f x  = the_preced (t@s) x"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   373
              by (simp add:the_preced_def preced_def Set)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   374
            also have "... \<le> Max (the_preced (t@s) ` threads (t@s))"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   375
              using Set h h_t.finite_threads by auto 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   376
            also have "... = ?f th" by (metis Cons.hyps(5) h_e.th_kept the_preced_def) 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   377
            finally show ?thesis .
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
        qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   380
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   381
      also have "... = ?t" using h_e.th_kept the_preced_def by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   382
      finally show ?thesis .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   383
    qed 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   384
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   385
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   386
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   387
lemma max_preced: "preced th (t@s) = Max (the_preced (t@s) ` (threads (t@s)))"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   388
  by (insert th_kept max_kept, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   389
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   390
text {*
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   391
  The reason behind the following lemma is that:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   392
  Since @{term "cp"} is defined as the maximum precedence 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   393
  of those threads contained in the sub-tree of node @{term "Th th"} 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   394
  in @{term "RAG (t@s)"}, and all these threads are living threads, and 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   395
  @{term "th"} is also among them, the maximum precedence of 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   396
  them all must be the one for @{text "th"}.
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   397
*}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   398
lemma th_cp_max_preced: 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   399
  "cp (t@s) th = Max (the_preced (t@s) ` (threads (t@s)))" (is "?L = ?R") 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   400
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   401
  let ?f = "the_preced (t@s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   402
  have "?L = ?f th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   403
  proof(unfold cp_alt_def, rule image_Max_eqI)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   404
    show "finite {th'. Th th' \<in> subtree (RAG (t @ s)) (Th th)}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   405
    proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   406
      have "{th'. Th th' \<in> subtree (RAG (t @ s)) (Th th)} = 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   407
            the_thread ` {n . n \<in> subtree (RAG (t @ s)) (Th th) \<and>
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   408
                            (\<exists> th'. n = Th th')}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   409
      by (smt Collect_cong Setcompr_eq_image mem_Collect_eq the_thread.simps)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   410
      moreover have "finite ..." by (simp add: vat_t.fsbtRAGs.finite_subtree) 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   411
      ultimately show ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   412
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   413
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   414
    show "th \<in> {th'. Th th' \<in> subtree (RAG (t @ s)) (Th th)}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   415
      by (auto simp:subtree_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   416
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   417
    show "\<forall>x\<in>{th'. Th th' \<in> subtree (RAG (t @ s)) (Th th)}.
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   418
               the_preced (t @ s) x \<le> the_preced (t @ s) th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   419
    proof
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   420
      fix th'
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   421
      assume "th' \<in> {th'. Th th' \<in> subtree (RAG (t @ s)) (Th th)}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   422
      hence "Th th' \<in> subtree (RAG (t @ s)) (Th th)" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   423
      moreover have "... \<subseteq> Field (RAG (t @ s)) \<union> {Th th}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   424
        by (meson subtree_Field)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   425
      ultimately have "Th th' \<in> ..." by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   426
      hence "th' \<in> threads (t@s)" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   427
      proof
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   428
        assume "Th th' \<in> {Th th}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   429
        thus ?thesis using th_kept by auto 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   430
      next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   431
        assume "Th th' \<in> Field (RAG (t @ s))"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   432
        thus ?thesis using vat_t.not_in_thread_isolated by blast 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   433
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   434
      thus "the_preced (t @ s) th' \<le> the_preced (t @ s) th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   435
        by (metis Max_ge finite_imageI finite_threads image_eqI 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   436
               max_kept th_kept the_preced_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   437
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   438
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   439
  also have "... = ?R" by (simp add: max_preced the_preced_def) 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   440
  finally show ?thesis .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   441
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   442
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   443
lemma th_cp_max: "cp (t@s) th = Max (cp (t@s) ` threads (t@s))"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   444
  using max_cp_eq th_cp_max_preced the_preced_def vt_t by presburger
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   445
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   446
lemma th_cp_preced: "cp (t@s) th = preced th s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   447
  by (fold max_kept, unfold th_cp_max_preced, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   448
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   449
lemma preced_less:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   450
  assumes th'_in: "th' \<in> threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   451
  and neq_th': "th' \<noteq> th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   452
  shows "preced th' s < preced th s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   453
  using assms
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   454
by (metis Max.coboundedI finite_imageI highest not_le order.trans 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   455
    preced_linorder rev_image_eqI threads_s vat_s.finite_threads 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   456
    vat_s.le_cp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   457
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   458
text {*
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   459
  The following lemmas shows that the @{term cp}-value 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   460
  of the blocking thread @{text th'} equals to the highest
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   461
  precedence in the whole system.
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   462
*}
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   463
lemma runing_preced_inversion:
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   464
  assumes runing': "th' \<in> runing (t@s)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   465
  shows "cp (t@s) th' = preced th s" (is "?L = ?R")
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   466
proof -
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   467
  have "?L = Max (cp (t @ s) ` readys (t @ s))" using assms
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   468
      by (unfold runing_def, auto)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   469
  also have "\<dots> = ?R"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   470
      by (metis th_cp_max th_cp_preced vat_t.max_cp_readys_threads) 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   471
  finally show ?thesis .
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   472
qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   473
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   474
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   475
text {*
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   476
  Counting of the number of @{term "P"} and @{term "V"} operations 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   477
  is the cornerstone of a large number of the following proofs. 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   478
  The reason is that this counting is quite easy to calculate and 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   479
  convenient to use in the reasoning. 
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
  The following lemma shows that the counting controls whether 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   482
  a thread is running or not.
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   483
*} (* ccc *)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   484
                      
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   485
lemma eq_pv_blocked: (* ddd *)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   486
  assumes neq_th': "th' \<noteq> th"
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   487
  and eq_pv: "cntP (t@s) th' = cntV (t@s) th'"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   488
  shows "th' \<notin> runing (t@s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   489
proof
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   490
  assume otherwise: "th' \<in> runing (t@s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   491
  show False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   492
  proof -
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   493
    have th'_in: "th' \<in> threads (t@s)"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   494
        using otherwise readys_threads runing_def by auto 
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   495
    have "th' = th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   496
    proof(rule preced_unique)
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   497
      -- {* The proof goes like this: 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   498
            it is first shown that the @{term preced}-value of @{term th'} 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   499
            equals to that of @{term th}, then by uniqueness 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   500
            of @{term preced}-values (given by lemma @{thm preced_unique}), 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   501
            @{term th'} equals to @{term th}: *}
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   502
      show "preced th' (t @ s) = preced th (t @ s)" (is "?L = ?R")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   503
      proof -
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   504
        -- {* Since the counts of @{term th'} are balanced, the subtree
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   505
              of it contains only itself, so, its @{term cp}-value
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   506
              equals its @{term preced}-value: *}
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   507
        have "?L = cp (t@s) th'"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   508
          by (unfold cp_eq_cpreced cpreced_def count_eq_dependants[OF eq_pv], simp)
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   509
        -- {* Since @{term "th'"} is running by @{thm otherwise},
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   510
              it has the highest @{term cp}-value, by definition, 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   511
              which in turn equals to the @{term cp}-value of @{term th}. *}
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   512
        also have "... = ?R" 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   513
            using runing_preced_inversion[OF otherwise] th_kept by simp
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   514
        finally show ?thesis .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   515
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   516
    qed (auto simp: th'_in th_kept)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   517
    moreover have "th' \<noteq> th" using neq_th' .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   518
    ultimately show ?thesis by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   519
 qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   520
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   521
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   522
lemmas eq_pv_blocked_dtc = eq_pv_blocked[folded detached_eq]
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   523
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   524
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   525
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   526
lemma eq_pv_kept: (* ddd *)
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   527
  assumes th'_in: "th' \<in> threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   528
  and eq_pv: "cntP s th' = cntV s th'"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   529
  and neq_th': "th' \<noteq> th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   530
  shows "th' \<in> threads (t@s) \<and>
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   531
         cntP (t@s) th' = cntV (t@s) th'"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   532
proof(induct rule:ind)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   533
  case (Cons e t)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   534
    interpret vat_t: extend_highest_gen s th prio tm t using Cons by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   535
    interpret vat_e: extend_highest_gen s th prio tm "(e # t)" using Cons by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   536
    show ?case
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   537
    proof(cases e)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   538
      case (P thread cs)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   539
      show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   540
      proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   541
        have "cntP ((e # t) @ s) th' = cntV ((e # t) @ s) th'"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   542
        proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   543
          have "thread \<noteq> th'"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   544
          proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   545
            have "step (t@s) (P thread cs)" using Cons P by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   546
            thus ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   547
            proof(cases)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   548
              assume "thread \<in> runing (t@s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   549
              moreover have "th' \<notin> runing (t@s)" using Cons(5)
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   550
                by (metis neq_th' vat_t.eq_pv_blocked) 
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   551
              ultimately show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   552
            qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   553
          qed with Cons show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   554
            by (unfold P, simp add:cntP_def cntV_def count_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   555
        qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   556
        moreover have "th' \<in> threads ((e # t) @ s)" using Cons by (unfold P, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   557
        ultimately show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   558
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   559
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   560
      case (V thread cs)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   561
      show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   562
      proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   563
        have "cntP ((e # t) @ s) th' = cntV ((e # t) @ s) th'"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   564
        proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   565
          have "thread \<noteq> th'"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   566
          proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   567
            have "step (t@s) (V thread cs)" using Cons V by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   568
            thus ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   569
            proof(cases)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   570
              assume "thread \<in> runing (t@s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   571
              moreover have "th' \<notin> runing (t@s)" using Cons(5)
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   572
                by (metis neq_th' vat_t.eq_pv_blocked) 
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   573
              ultimately show ?thesis by auto
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
          qed with Cons show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   576
            by (unfold V, simp add:cntP_def cntV_def count_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   577
        qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   578
        moreover have "th' \<in> threads ((e # t) @ s)" using Cons by (unfold V, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   579
        ultimately show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   580
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   581
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   582
      case (Create thread prio')
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   583
      show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   584
      proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   585
        have "cntP ((e # t) @ s) th' = cntV ((e # t) @ s) th'"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   586
        proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   587
          have "thread \<noteq> th'"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   588
          proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   589
            have "step (t@s) (Create thread prio')" using Cons Create by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   590
            thus ?thesis using Cons(5) by (cases, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   591
          qed with Cons show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   592
            by (unfold Create, simp add:cntP_def cntV_def count_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   593
        qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   594
        moreover have "th' \<in> threads ((e # t) @ s)" using Cons by (unfold Create, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   595
        ultimately show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   596
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   597
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   598
      case (Exit thread)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   599
      show ?thesis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   600
      proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   601
        have neq_thread: "thread \<noteq> th'"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   602
        proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   603
          have "step (t@s) (Exit thread)" using Cons Exit by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   604
          thus ?thesis apply (cases) using Cons(5)
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   605
                by (metis neq_th' vat_t.eq_pv_blocked) 
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   606
        qed 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   607
        hence "cntP ((e # t) @ s) th' = cntV ((e # t) @ s) th'" using Cons
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   608
            by (unfold Exit, simp add:cntP_def cntV_def count_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   609
        moreover have "th' \<in> threads ((e # t) @ s)" using Cons neq_thread 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   610
          by (unfold Exit, simp) 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   611
        ultimately show ?thesis by auto
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
    next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   614
      case (Set thread prio')
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   615
      with Cons
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   616
      show ?thesis 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   617
        by (auto simp:cntP_def cntV_def count_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   618
    qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   619
next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   620
  case Nil
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   621
  with assms
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   622
  show ?case by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   623
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   624
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   625
(* runing_precond has changed to eq_pv_kept *)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   626
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   627
text {* Changing counting balance to detachedness *}
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   628
lemmas eq_pv_kept_dtc = eq_pv_kept
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   629
         [folded vat_t.detached_eq vat_s.detached_eq]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   630
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   631
section {* The blocking thread *}
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   632
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   633
text {* 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   634
  The purpose of PIP is to ensure that the most 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   635
  urgent thread @{term th} is not blocked unreasonably. 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   636
  Therefore, a clear picture of the blocking thread is essential 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   637
  to assure people that the purpose is fulfilled. 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   638
  
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   639
  The following lemmas will give us such a picture: 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   640
*}
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   641
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   642
(* ccc *)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   643
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   644
text {*
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   645
  The following lemma shows the blocking thread @{term th'}
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   646
  must hold some resource in the very beginning. 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   647
*}
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   648
lemma runing_cntP_cntV_inv: (* ddd *)
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   649
  assumes th'_in: "th' \<in> threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   650
  and neq_th': "th' \<noteq> th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   651
  and is_runing: "th' \<in> runing (t@s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   652
  shows "cntP s th' > cntV s th'"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   653
  using assms
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   654
proof - (* ccc *)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   655
  -- {* First, it can be shown that the number of @{term P} and
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   656
        @{term V} operations can not be equal for thred @{term th'} *}
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   657
  have "cntP s th' \<noteq> cntV s th'"
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   658
  proof
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   659
    assume otherwise: "cntP s th' = cntV s th'"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   660
    -- {* The proof goes by contradiction. *}
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   661
    -- {* We can show that @{term th'} can not be running at moment @{term "t@s"}: *}
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   662
    have "th' \<notin> runing (t@s)" 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   663
    proof(rule eq_pv_blocked)
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   664
      show "th' \<noteq> th" using neq_th' by simp
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   665
    next
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   666
      show "cntP (t @ s) th' = cntV (t @ s) th'"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   667
        using eq_pv_kept[OF th'_in otherwise neq_th'] by simp
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   668
    qed
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   669
    -- {* This is obvious in contradiction with assumption @{thm is_runing}  *}
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   670
    thus False using is_runing by simp
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   671
  qed
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   672
  moreover have "cntV s th' \<le> cntP s th'" using vat_s.cnp_cnv_cncs by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   673
  ultimately show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   674
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   675
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   676
lemma moment_blocked_pre:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   677
  assumes neq_th': "th' \<noteq> th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   678
  and th'_in: "th' \<in> threads ((moment i t)@s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   679
  and eq_pv: "cntP ((moment i t)@s) th' = cntV ((moment i t)@s) th'"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   680
  shows "cntP ((moment (i+j) t)@s) th' = cntV ((moment (i+j) t)@s) th' \<and>
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   681
         th' \<in> threads ((moment (i+j) t)@s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   682
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   683
  interpret h_i: red_extend_highest_gen _ _ _ _ _ i
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   684
      by (unfold_locales)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   685
  interpret h_j: red_extend_highest_gen _ _ _ _ _ "i+j"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   686
      by (unfold_locales)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   687
  interpret h:  extend_highest_gen "((moment i t)@s)" th prio tm "moment j (restm i t)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   688
  proof(unfold_locales)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   689
    show "vt (moment i t @ s)" by (metis h_i.vt_t) 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   690
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   691
    show "th \<in> threads (moment i t @ s)" by (metis h_i.th_kept)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   692
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   693
    show "preced th (moment i t @ s) = 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   694
            Max (cp (moment i t @ s) ` threads (moment i t @ s))"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   695
              by (metis h_i.th_cp_max h_i.th_cp_preced h_i.th_kept)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   696
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   697
    show "preced th (moment i t @ s) = Prc prio tm" by (metis h_i.th_kept preced_th) 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   698
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   699
    show "vt (moment j (restm i t) @ moment i t @ s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   700
      using moment_plus_split by (metis add.commute append_assoc h_j.vt_t)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   701
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   702
    fix th' prio'
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   703
    assume "Create th' prio' \<in> set (moment j (restm i t))"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   704
    thus "prio' \<le> prio" using assms
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   705
       by (metis Un_iff add.commute h_j.create_low moment_plus_split set_append)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   706
  next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   707
    fix th' prio'
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   708
    assume "Set th' prio' \<in> set (moment j (restm i t))"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   709
    thus "th' \<noteq> th \<and> prio' \<le> prio"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   710
    by (metis Un_iff add.commute h_j.set_diff_low moment_plus_split set_append)
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
    fix th'
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   713
    assume "Exit th' \<in> set (moment j (restm i t))"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   714
    thus "th' \<noteq> th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   715
      by (metis Un_iff add.commute h_j.exit_diff moment_plus_split set_append)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   716
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   717
  show ?thesis 
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   718
    by (metis add.commute append_assoc eq_pv h.eq_pv_kept
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   719
          moment_plus_split neq_th' th'_in)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   720
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   721
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   722
lemma moment_blocked_eqpv: (* ddd *)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   723
  assumes neq_th': "th' \<noteq> th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   724
  and th'_in: "th' \<in> threads ((moment i t)@s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   725
  and eq_pv: "cntP ((moment i t)@s) th' = cntV ((moment i t)@s) th'"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   726
  and le_ij: "i \<le> j"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   727
  shows "cntP ((moment j t)@s) th' = cntV ((moment j t)@s) th' \<and>
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   728
         th' \<in> threads ((moment j t)@s) \<and>
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   729
         th' \<notin> runing ((moment j t)@s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   730
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   731
  from moment_blocked_pre [OF neq_th' th'_in eq_pv, of "j-i"] and le_ij
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   732
  have h1: "cntP ((moment j t)@s) th' = cntV ((moment j t)@s) th'"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   733
   and h2: "th' \<in> threads ((moment j t)@s)" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   734
  moreover have "th' \<notin> runing ((moment j t)@s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   735
  proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   736
    interpret h: red_extend_highest_gen _ _ _ _ _ j by (unfold_locales)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   737
    show ?thesis
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   738
      using h.eq_pv_blocked h1 h2 neq_th' by auto 
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   739
  qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   740
  ultimately show ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   741
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   742
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   743
(* The foregoing two lemmas are preparation for this one, but
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   744
   in long run can be combined. Maybe I am wrong.
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   745
   This one is useless (* XY *)
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   746
*)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   747
lemma moment_blocked:
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   748
  assumes neq_th': "th' \<noteq> th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   749
  and th'_in: "th' \<in> threads ((moment i t)@s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   750
  and dtc: "detached (moment i t @ s) th'"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   751
  and le_ij: "i \<le> j"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   752
  shows "detached (moment j t @ s) th' \<and>
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   753
         th' \<in> threads ((moment j t)@s) \<and>
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   754
         th' \<notin> runing ((moment j t)@s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   755
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   756
  interpret h_i: red_extend_highest_gen _ _ _ _ _ i by (unfold_locales)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   757
  interpret h_j: red_extend_highest_gen _ _ _ _ _ j by (unfold_locales) 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   758
  have cnt_i: "cntP (moment i t @ s) th' = cntV (moment i t @ s) th'"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   759
                by (metis dtc h_i.detached_elim)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   760
  from moment_blocked_eqpv[OF neq_th' th'_in cnt_i le_ij]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   761
  show ?thesis by (metis h_j.detached_intro) 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   762
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   763
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   764
text {*
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   765
  The following lemmas shows the blocking thread @{text th'} must be live 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   766
  at the very beginning, i.e. the moment (or state) @{term s}. 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   767
*}
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   768
lemma runing_threads_inv: (* ddd *) (* ccc *)
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   769
  assumes runing': "th' \<in> runing (t@s)"
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   770
  and neq_th': "th' \<noteq> th"
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   771
  shows "th' \<in> threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   772
proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   773
    -- {* The proof is by contradiction: *}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   774
    { assume otherwise: "\<not> ?thesis"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   775
      have "th' \<notin> runing (t @ s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   776
      proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   777
        -- {* Since @{term "th'"} is running at time @{term "t@s"}, so it exists that time. *}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   778
        have th'_in: "th' \<in> threads (t@s)" using runing' by (simp add:runing_def readys_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   779
        -- {* However, @{text "th'"} does not exist at very beginning. *}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   780
        have th'_notin: "th' \<notin> threads (moment 0 t @ s)" using otherwise
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   781
          by (metis append.simps(1) moment_zero)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   782
        -- {* Therefore, there must be a moment during @{text "t"}, when 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   783
              @{text "th'"} came into being. *}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   784
        -- {* Let us suppose the moment being @{text "i"}: *}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   785
        from p_split_gen[OF th'_in th'_notin]
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   786
        obtain i where lt_its: "i < length t"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   787
                 and le_i: "0 \<le> i"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   788
                 and pre: " th' \<notin> threads (moment i t @ s)" (is "th' \<notin> threads ?pre")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   789
                 and post: "(\<forall>i'>i. th' \<in> threads (moment i' t @ s))" by (auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   790
        interpret h_i: red_extend_highest_gen _ _ _ _ _ i by (unfold_locales)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   791
        interpret h_i': red_extend_highest_gen _ _ _ _ _ "(Suc i)" by (unfold_locales)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   792
        from lt_its have "Suc i \<le> length t" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   793
        -- {* Let us also suppose the event which makes this change is @{text e}: *}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   794
        from moment_head[OF this] obtain e where 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   795
          eq_me: "moment (Suc i) t = e # moment i t" by blast
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   796
        hence "vt (e # (moment i t @ s))" by (metis append_Cons h_i'.vt_t) 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   797
        hence "PIP (moment i t @ s) e" by (cases, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   798
        -- {* It can be derived that this event @{text "e"}, which 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   799
              gives birth to @{term "th'"} must be a @{term "Create"}: *}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   800
        from create_pre[OF this, of th']
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   801
        obtain prio where eq_e: "e = Create th' prio"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   802
            by (metis append_Cons eq_me lessI post pre) 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   803
        have h1: "th' \<in> threads (moment (Suc i) t @ s)" using post by auto 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   804
        have h2: "cntP (moment (Suc i) t @ s) th' = cntV (moment (Suc i) t@ s) th'"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   805
        proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   806
          have "cntP (moment i t@s) th' = cntV (moment i t@s) th'"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   807
            by (metis h_i.cnp_cnv_eq pre)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   808
          thus ?thesis by (simp add:eq_me eq_e cntP_def cntV_def count_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   809
        qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   810
        show ?thesis 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   811
          using moment_blocked_eqpv [OF neq_th' h1 h2, of "length t"] lt_its moment_ge
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   812
            by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   813
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   814
      with `th' \<in> runing (t@s)`
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   815
      have False by simp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   816
    } thus ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   817
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   818
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   819
text {*
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   820
  The following lemma summarizes several foregoing 
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   821
  lemmas to give an overall picture of the blocking thread @{text "th'"}:
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   822
*}
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   823
lemma runing_inversion:
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   824
  assumes runing': "th' \<in> runing (t@s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   825
  and neq_th: "th' \<noteq> th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   826
  shows "th' \<in> threads s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   827
  and    "\<not>detached s th'"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   828
  and    "cp (t@s) th' = preced th s"
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   829
proof -
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   830
  from runing_threads_inv[OF assms]
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   831
  show "th' \<in> threads s" .
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   832
next
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   833
  from runing_cntP_cntV_inv[OF runing_threads_inv[OF assms] neq_th runing']
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   834
  show "\<not>detached s th'" using vat_s.detached_eq by simp
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   835
next
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   836
  from runing_preced_inversion[OF runing']
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   837
  show "cp (t@s) th' = preced th s" .
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 66
diff changeset
   838
qed
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   839
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   840
text {* 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   841
  Suppose @{term th} is not running, it is first shown that
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   842
  there is a path in RAG leading from node @{term th} to another thread @{text "th'"} 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   843
  in the @{term readys}-set (So @{text "th'"} is an ancestor of @{term th}}).
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   844
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   845
  Now, since @{term readys}-set is non-empty, there must be
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   846
  one in it which holds the highest @{term cp}-value, which, by definition, 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   847
  is the @{term runing}-thread. However, we are going to show more: this running thread
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   848
  is exactly @{term "th'"}.
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   849
     *}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   850
lemma th_blockedE: (* ddd *)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   851
  assumes "th \<notin> runing (t@s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   852
  obtains th' where "Th th' \<in> ancestors (RAG (t @ s)) (Th th)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   853
                    "th' \<in> runing (t@s)"
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
  -- {* According to @{thm vat_t.th_chain_to_ready}, either 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   856
        @{term "th"} is in @{term "readys"} or there is path leading from it to 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   857
        one thread in @{term "readys"}. *}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   858
  have "th \<in> readys (t @ s) \<or> (\<exists>th'. th' \<in> readys (t @ s) \<and> (Th th, Th th') \<in> (RAG (t @ s))\<^sup>+)" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   859
    using th_kept vat_t.th_chain_to_ready by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   860
  -- {* However, @{term th} can not be in @{term readys}, because otherwise, since 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   861
       @{term th} holds the highest @{term cp}-value, it must be @{term "runing"}. *}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   862
  moreover have "th \<notin> readys (t@s)" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   863
    using assms runing_def th_cp_max vat_t.max_cp_readys_threads by auto 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   864
  -- {* So, there must be a path from @{term th} to another thread @{text "th'"} in 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   865
        term @{term readys}: *}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   866
  ultimately obtain th' where th'_in: "th' \<in> readys (t@s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   867
                          and dp: "(Th th, Th th') \<in> (RAG (t @ s))\<^sup>+" by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   868
  -- {* We are going to show that this @{term th'} is running. *}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   869
  have "th' \<in> runing (t@s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   870
  proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   871
    -- {* We only need to show that this @{term th'} holds the highest @{term cp}-value: *}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   872
    have "cp (t@s) th' = Max (cp (t@s) ` readys (t@s))" (is "?L = ?R")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   873
    proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   874
      have "?L =  Max ((the_preced (t @ s) \<circ> the_thread) ` subtree (tRAG (t @ s)) (Th th'))"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   875
        by (unfold cp_alt_def1, simp)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   876
      also have "... = (the_preced (t @ s) \<circ> the_thread) (Th th)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   877
      proof(rule image_Max_subset)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   878
        show "finite (Th ` (threads (t@s)))" by (simp add: vat_t.finite_threads)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   879
      next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   880
        show "subtree (tRAG (t @ s)) (Th th') \<subseteq> Th ` threads (t @ s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   881
          by (metis Range.intros dp trancl_range vat_t.range_in vat_t.subtree_tRAG_thread) 
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
        show "Th th \<in> subtree (tRAG (t @ s)) (Th th')" using dp
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   884
                    by (unfold tRAG_subtree_eq, auto simp:subtree_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   885
      next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   886
        show "Max ((the_preced (t @ s) \<circ> the_thread) ` Th ` threads (t @ s)) =
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   887
                      (the_preced (t @ s) \<circ> the_thread) (Th th)" (is "Max ?L = _")
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   888
        proof -
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   889
          have "?L = the_preced (t @ s) `  threads (t @ s)" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   890
                     by (unfold image_comp, rule image_cong, auto)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   891
          thus ?thesis using max_preced the_preced_def by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   892
        qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   893
      qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   894
      also have "... = ?R"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   895
        using th_cp_max th_cp_preced th_kept 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   896
              the_preced_def vat_t.max_cp_readys_threads by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   897
      finally show ?thesis .
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   898
    qed 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   899
    -- {* Now, since @{term th'} holds the highest @{term cp} 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   900
          and we have already show it is in @{term readys},
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   901
          it is @{term runing} by definition. *}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   902
    with `th' \<in> readys (t@s)` show ?thesis by (simp add: runing_def) 
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
  -- {* It is easy to show @{term th'} is an ancestor of @{term th}: *}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   905
  moreover have "Th th' \<in> ancestors (RAG (t @ s)) (Th th)" 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   906
    using `(Th th, Th th') \<in> (RAG (t @ s))\<^sup>+` by (auto simp:ancestors_def)
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   907
  ultimately show ?thesis using that by metis
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
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   910
text {*
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   911
  Now it is easy to see there is always a thread to run by case analysis
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   912
  on whether thread @{term th} is running: if the answer is Yes, the 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   913
  the running thread is obviously @{term th} itself; otherwise, the running
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   914
  thread is the @{text th'} given by lemma @{thm th_blockedE}.
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 live: "runing (t@s) \<noteq> {}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   917
proof(cases "th \<in> runing (t@s)") 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   918
  case True thus ?thesis by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   919
next
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   920
  case False
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   921
  thus ?thesis using th_blockedE by auto
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   922
qed
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   923
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   924
end
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   925
end
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   926
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   927
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents:
diff changeset
   928