CpsG.thy~
author xingyuan zhang <xingyuanzhang@126.com>
Thu, 03 Dec 2015 14:34:29 +0800
changeset 57 f1b39d77db00
child 58 ad57323fd4d6
permissions -rw-r--r--
Added generic theory "RTree.thy"
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
     1
section {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
     2
  This file contains lemmas used to guide the recalculation of current precedence 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
     3
  after every system call (or system operation)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
     4
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
     5
theory CpsG
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
     6
imports PrioG Max RTree
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
     7
begin
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
     8
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
     9
locale pip = 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    10
  fixes s
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    11
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    12
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    13
context pip
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    14
begin
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    15
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    16
interpretation rtree_RAG: rtree "RAG s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    17
proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    18
  show "single_valued (RAG s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    19
    by (unfold single_valued_def, auto intro: unique_RAG[OF vt])
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    20
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    21
  show "acyclic (RAG s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    22
     by (rule acyclic_RAG[OF vt])
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    23
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    24
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    25
thm rtree_RAG.rpath_overlap_oneside
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    26
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    27
end
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    28
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    29
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    30
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    31
definition "the_preced s th = preced th s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    32
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    33
lemma cp_alt_def:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    34
  "cp s th =  
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    35
           Max ((the_preced s) ` {th'. Th th' \<in> (subtree (RAG s) (Th th))})"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    36
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    37
  have "Max (the_preced s ` ({th} \<union> dependants (wq s) th)) =
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    38
        Max (the_preced s ` {th'. Th th' \<in> subtree (RAG s) (Th th)})" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    39
          (is "Max (_ ` ?L) = Max (_ ` ?R)")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    40
  proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    41
    have "?L = ?R" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    42
    by (auto dest:rtranclD simp:cs_dependants_def cs_RAG_def s_RAG_def subtree_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    43
    thus ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    44
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    45
  thus ?thesis by (unfold cp_eq_cpreced cpreced_def, fold the_preced_def, simp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    46
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    47
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    48
lemma eq_dependants: "dependants (wq s) = dependants s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    49
  by (simp add: s_dependants_abv wq_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    50
  
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    51
(* obvious lemma *)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    52
lemma not_thread_holdents:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    53
  fixes th s
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    54
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    55
  and not_in: "th \<notin> threads s" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    56
  shows "holdents s th = {}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    57
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    58
  from vt not_in show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    59
  proof(induct arbitrary:th)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    60
    case (vt_cons s e th)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    61
    assume vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    62
      and ih: "\<And>th. th \<notin> threads s \<Longrightarrow> holdents s th = {}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    63
      and stp: "step s e"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    64
      and not_in: "th \<notin> threads (e # s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    65
    from stp show ?case
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    66
    proof(cases)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    67
      case (thread_create thread prio)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    68
      assume eq_e: "e = Create thread prio"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    69
        and not_in': "thread \<notin> threads s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    70
      have "holdents (e # s) th = holdents s th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    71
        apply (unfold eq_e holdents_test)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    72
        by (simp add:RAG_create_unchanged)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    73
      moreover have "th \<notin> threads s" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    74
      proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    75
        from not_in eq_e show ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    76
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    77
      moreover note ih ultimately show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    78
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    79
      case (thread_exit thread)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    80
      assume eq_e: "e = Exit thread"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    81
      and nh: "holdents s thread = {}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    82
      show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    83
      proof(cases "th = thread")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    84
        case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    85
        with nh eq_e
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    86
        show ?thesis 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    87
          by (auto simp:holdents_test RAG_exit_unchanged)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    88
      next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    89
        case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    90
        with not_in and eq_e
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    91
        have "th \<notin> threads s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    92
        from ih[OF this] False eq_e show ?thesis 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    93
          by (auto simp:holdents_test RAG_exit_unchanged)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    94
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    95
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    96
      case (thread_P thread cs)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    97
      assume eq_e: "e = P thread cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    98
      and is_runing: "thread \<in> runing s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
    99
      from assms thread_exit ih stp not_in vt eq_e have vtp: "vt (P thread cs#s)" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   100
      have neq_th: "th \<noteq> thread" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   101
      proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   102
        from not_in eq_e have "th \<notin> threads s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   103
        moreover from is_runing have "thread \<in> threads s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   104
          by (simp add:runing_def readys_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   105
        ultimately show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   106
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   107
      hence "holdents (e # s) th  = holdents s th "
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   108
        apply (unfold cntCS_def holdents_test eq_e)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   109
        by (unfold step_RAG_p[OF vtp], auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   110
      moreover have "holdents s th = {}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   111
      proof(rule ih)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   112
        from not_in eq_e show "th \<notin> threads s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   113
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   114
      ultimately show ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   115
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   116
      case (thread_V thread cs)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   117
      assume eq_e: "e = V thread cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   118
        and is_runing: "thread \<in> runing s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   119
        and hold: "holding s thread cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   120
      have neq_th: "th \<noteq> thread" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   121
      proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   122
        from not_in eq_e have "th \<notin> threads s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   123
        moreover from is_runing have "thread \<in> threads s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   124
          by (simp add:runing_def readys_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   125
        ultimately show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   126
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   127
      from assms thread_V eq_e ih stp not_in vt have vtv: "vt (V thread cs#s)" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   128
      from hold obtain rest 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   129
        where eq_wq: "wq s cs = thread # rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   130
        by (case_tac "wq s cs", auto simp: wq_def s_holding_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   131
      from not_in eq_e eq_wq
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   132
      have "\<not> next_th s thread cs th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   133
        apply (auto simp:next_th_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   134
      proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   135
        assume ne: "rest \<noteq> []"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   136
          and ni: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> threads s" (is "?t \<notin> threads s")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   137
        have "?t \<in> set rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   138
        proof(rule someI2)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   139
          from wq_distinct[OF step_back_vt[OF vtv], of cs] and eq_wq
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   140
          show "distinct rest \<and> set rest = set rest" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   141
        next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   142
          fix x assume "distinct x \<and> set x = set rest" with ne
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   143
          show "hd x \<in> set rest" by (cases x, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   144
        qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   145
        with eq_wq have "?t \<in> set (wq s cs)" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   146
        from wq_threads[OF step_back_vt[OF vtv], OF this] and ni
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   147
        show False by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   148
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   149
      moreover note neq_th eq_wq
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   150
      ultimately have "holdents (e # s) th  = holdents s th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   151
        by (unfold eq_e cntCS_def holdents_test step_RAG_v[OF vtv], auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   152
      moreover have "holdents s th = {}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   153
      proof(rule ih)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   154
        from not_in eq_e show "th \<notin> threads s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   155
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   156
      ultimately show ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   157
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   158
      case (thread_set thread prio)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   159
      print_facts
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   160
      assume eq_e: "e = Set thread prio"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   161
        and is_runing: "thread \<in> runing s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   162
      from not_in and eq_e have "th \<notin> threads s" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   163
      from ih [OF this] and eq_e
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   164
      show ?thesis 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   165
        apply (unfold eq_e cntCS_def holdents_test)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   166
        by (simp add:RAG_set_unchanged)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   167
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   168
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   169
      case vt_nil
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   170
      show ?case
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   171
      by (auto simp:count_def holdents_test s_RAG_def wq_def cs_holding_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   172
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   173
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   174
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   175
(* obvious lemma *)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   176
lemma next_th_neq: 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   177
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   178
  and nt: "next_th s th cs th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   179
  shows "th' \<noteq> th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   180
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   181
  from nt show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   182
    apply (auto simp:next_th_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   183
  proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   184
    fix rest
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   185
    assume eq_wq: "wq s cs = hd (SOME q. distinct q \<and> set q = set rest) # rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   186
      and ne: "rest \<noteq> []"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   187
    have "hd (SOME q. distinct q \<and> set q = set rest) \<in> set rest" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   188
    proof(rule someI2)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   189
      from wq_distinct[OF vt, of cs] eq_wq
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   190
      show "distinct rest \<and> set rest = set rest" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   191
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   192
      fix x
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   193
      assume "distinct x \<and> set x = set rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   194
      hence eq_set: "set x = set rest" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   195
      with ne have "x \<noteq> []" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   196
      hence "hd x \<in> set x" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   197
      with eq_set show "hd x \<in> set rest" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   198
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   199
    with wq_distinct[OF vt, of cs] eq_wq show False by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   200
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   201
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   202
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   203
(* obvious lemma *)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   204
lemma next_th_unique: 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   205
  assumes nt1: "next_th s th cs th1"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   206
  and nt2: "next_th s th cs th2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   207
  shows "th1 = th2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   208
using assms by (unfold next_th_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   209
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   210
lemma wf_RAG:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   211
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   212
  shows "wf (RAG s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   213
proof(rule finite_acyclic_wf)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   214
  from finite_RAG[OF vt] show "finite (RAG s)" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   215
next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   216
  from acyclic_RAG[OF vt] show "acyclic (RAG s)" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   217
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   218
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   219
definition child :: "state \<Rightarrow> (node \<times> node) set"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   220
  where "child s \<equiv>
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   221
            {(Th th', Th th) | th th'. \<exists>cs. (Th th', Cs cs) \<in> RAG s \<and> (Cs cs, Th th) \<in> RAG s}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   222
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   223
definition children :: "state \<Rightarrow> thread \<Rightarrow> thread set"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   224
  where "children s th \<equiv> {th'. (Th th', Th th) \<in> child s}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   225
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   226
lemma children_def2:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   227
  "children s th \<equiv> {th'. \<exists> cs. (Th th', Cs cs) \<in> RAG s \<and> (Cs cs, Th th) \<in> RAG s}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   228
unfolding child_def children_def by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   229
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   230
lemma children_dependants: 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   231
  "children s th \<subseteq> dependants (wq s) th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   232
  unfolding children_def2
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   233
  unfolding cs_dependants_def
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   234
  by (auto simp add: eq_RAG)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   235
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   236
lemma child_unique:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   237
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   238
  and ch1: "(Th th, Th th1) \<in> child s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   239
  and ch2: "(Th th, Th th2) \<in> child s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   240
  shows "th1 = th2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   241
using ch1 ch2 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   242
proof(unfold child_def, clarsimp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   243
  fix cs csa
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   244
  assume h1: "(Th th, Cs cs) \<in> RAG s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   245
    and h2: "(Cs cs, Th th1) \<in> RAG s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   246
    and h3: "(Th th, Cs csa) \<in> RAG s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   247
    and h4: "(Cs csa, Th th2) \<in> RAG s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   248
  from unique_RAG[OF vt h1 h3] have "cs = csa" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   249
  with h4 have "(Cs cs, Th th2) \<in> RAG s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   250
  from unique_RAG[OF vt h2 this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   251
  show "th1 = th2" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   252
qed 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   253
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   254
lemma RAG_children:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   255
  assumes h: "(Th th1, Th th2) \<in> (RAG s)^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   256
  shows "th1 \<in> children s th2 \<or> (\<exists> th3. th3 \<in> children s th2 \<and> (Th th1, Th th3) \<in> (RAG s)^+)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   257
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   258
  from h show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   259
  proof(induct rule: tranclE)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   260
    fix c th2
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   261
    assume h1: "(Th th1, c) \<in> (RAG s)\<^sup>+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   262
    and h2: "(c, Th th2) \<in> RAG s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   263
    from h2 obtain cs where eq_c: "c = Cs cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   264
      by (case_tac c, auto simp:s_RAG_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   265
    show "th1 \<in> children s th2 \<or> (\<exists>th3. th3 \<in> children s th2 \<and> (Th th1, Th th3) \<in> (RAG s)\<^sup>+)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   266
    proof(rule tranclE[OF h1])
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   267
      fix ca
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   268
      assume h3: "(Th th1, ca) \<in> (RAG s)\<^sup>+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   269
        and h4: "(ca, c) \<in> RAG s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   270
      show "th1 \<in> children s th2 \<or> (\<exists>th3. th3 \<in> children s th2 \<and> (Th th1, Th th3) \<in> (RAG s)\<^sup>+)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   271
      proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   272
        from eq_c and h4 obtain th3 where eq_ca: "ca = Th th3"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   273
          by (case_tac ca, auto simp:s_RAG_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   274
        from eq_ca h4 h2 eq_c
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   275
        have "th3 \<in> children s th2" by (auto simp:children_def child_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   276
        moreover from h3 eq_ca have "(Th th1, Th th3) \<in> (RAG s)\<^sup>+" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   277
        ultimately show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   278
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   279
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   280
      assume "(Th th1, c) \<in> RAG s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   281
      with h2 eq_c
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   282
      have "th1 \<in> children s th2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   283
        by (auto simp:children_def child_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   284
      thus ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   285
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   286
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   287
    assume "(Th th1, Th th2) \<in> RAG s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   288
    thus ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   289
      by (auto simp:s_RAG_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   290
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   291
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   292
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   293
lemma sub_child: "child s \<subseteq> (RAG s)^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   294
  by (unfold child_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   295
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   296
lemma wf_child: 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   297
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   298
  shows "wf (child s)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   299
apply(rule wf_subset)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   300
apply(rule wf_trancl[OF wf_RAG[OF vt]])
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   301
apply(rule sub_child)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   302
done
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   303
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   304
lemma RAG_child_pre:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   305
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   306
  shows
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   307
  "(Th th, n) \<in> (RAG s)^+ \<longrightarrow> (\<forall> th'. n = (Th th') \<longrightarrow> (Th th, Th th') \<in> (child s)^+)" (is "?P n")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   308
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   309
  from wf_trancl[OF wf_RAG[OF vt]]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   310
  have wf: "wf ((RAG s)^+)" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   311
  show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   312
  proof(rule wf_induct[OF wf, of ?P], clarsimp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   313
    fix th'
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   314
    assume ih[rule_format]: "\<forall>y. (y, Th th') \<in> (RAG s)\<^sup>+ \<longrightarrow>
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   315
               (Th th, y) \<in> (RAG s)\<^sup>+ \<longrightarrow> (\<forall>th'. y = Th th' \<longrightarrow> (Th th, Th th') \<in> (child s)\<^sup>+)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   316
    and h: "(Th th, Th th') \<in> (RAG s)\<^sup>+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   317
    show "(Th th, Th th') \<in> (child s)\<^sup>+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   318
    proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   319
      from RAG_children[OF h]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   320
      have "th \<in> children s th' \<or> (\<exists>th3. th3 \<in> children s th' \<and> (Th th, Th th3) \<in> (RAG s)\<^sup>+)" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   321
      thus ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   322
      proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   323
        assume "th \<in> children s th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   324
        thus "(Th th, Th th') \<in> (child s)\<^sup>+" by (auto simp:children_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   325
      next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   326
        assume "\<exists>th3. th3 \<in> children s th' \<and> (Th th, Th th3) \<in> (RAG s)\<^sup>+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   327
        then obtain th3 where th3_in: "th3 \<in> children s th'" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   328
          and th_dp: "(Th th, Th th3) \<in> (RAG s)\<^sup>+" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   329
        from th3_in have "(Th th3, Th th') \<in> (RAG s)^+" by (auto simp:children_def child_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   330
        from ih[OF this th_dp, of th3] have "(Th th, Th th3) \<in> (child s)\<^sup>+" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   331
        with th3_in show "(Th th, Th th') \<in> (child s)\<^sup>+" by (auto simp:children_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   332
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   333
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   334
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   335
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   336
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   337
lemma RAG_child: "\<lbrakk>vt s; (Th th, Th th') \<in> (RAG s)^+\<rbrakk> \<Longrightarrow> (Th th, Th th') \<in> (child s)^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   338
  by (insert RAG_child_pre, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   339
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   340
lemma child_RAG_p:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   341
  assumes "(n1, n2) \<in> (child s)^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   342
  shows "(n1, n2) \<in> (RAG s)^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   343
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   344
  from assms show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   345
  proof(induct)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   346
    case (base y)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   347
    with sub_child show ?case by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   348
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   349
    case (step y z)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   350
    assume "(y, z) \<in> child s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   351
    with sub_child have "(y, z) \<in> (RAG s)^+" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   352
    moreover have "(n1, y) \<in> (RAG s)^+" by fact
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   353
    ultimately show ?case by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   354
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   355
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   356
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   357
text {* (* ddd *)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   358
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   359
lemma child_RAG_eq: 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   360
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   361
  shows "(Th th1, Th th2) \<in> (child s)^+  \<longleftrightarrow> (Th th1, Th th2) \<in> (RAG s)^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   362
  by (auto intro: RAG_child[OF vt] child_RAG_p)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   363
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   364
text {* (* ddd *)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   365
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   366
lemma children_no_dep:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   367
  fixes s th th1 th2 th3
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   368
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   369
  and ch1: "(Th th1, Th th) \<in> child s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   370
  and ch2: "(Th th2, Th th) \<in> child s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   371
  and ch3: "(Th th1, Th th2) \<in> (RAG s)^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   372
  shows "False"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   373
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   374
  from RAG_child[OF vt ch3]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   375
  have "(Th th1, Th th2) \<in> (child s)\<^sup>+" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   376
  thus ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   377
  proof(rule converse_tranclE)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   378
    assume "(Th th1, Th th2) \<in> child s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   379
    from child_unique[OF vt ch1 this] have "th = th2" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   380
    with ch2 have "(Th th2, Th th2) \<in> child s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   381
    with wf_child[OF vt] show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   382
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   383
    fix c
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   384
    assume h1: "(Th th1, c) \<in> child s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   385
      and h2: "(c, Th th2) \<in> (child s)\<^sup>+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   386
    from h1 obtain th3 where eq_c: "c = Th th3" by (unfold child_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   387
    with h1 have "(Th th1, Th th3) \<in> child s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   388
    from child_unique[OF vt ch1 this] have eq_th3: "th3 = th" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   389
    with eq_c and h2 have "(Th th, Th th2) \<in> (child s)\<^sup>+" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   390
    with ch2 have "(Th th, Th th) \<in> (child s)\<^sup>+" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   391
    moreover have "wf ((child s)\<^sup>+)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   392
    proof(rule wf_trancl)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   393
      from wf_child[OF vt] show "wf (child s)" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   394
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   395
    ultimately show False by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   396
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   397
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   398
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   399
text {* (* ddd *)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   400
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   401
lemma unique_RAG_p:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   402
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   403
  and dp1: "(n, n1) \<in> (RAG s)^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   404
  and dp2: "(n, n2) \<in> (RAG s)^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   405
  and neq: "n1 \<noteq> n2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   406
  shows "(n1, n2) \<in> (RAG s)^+ \<or> (n2, n1) \<in> (RAG s)^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   407
proof(rule unique_chain [OF _ dp1 dp2 neq])
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   408
  from unique_RAG[OF vt]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   409
  show "\<And>a b c. \<lbrakk>(a, b) \<in> RAG s; (a, c) \<in> RAG s\<rbrakk> \<Longrightarrow> b = c" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   410
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   411
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   412
text {* (* ddd *)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   413
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   414
lemma dependants_child_unique:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   415
  fixes s th th1 th2 th3
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   416
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   417
  and ch1: "(Th th1, Th th) \<in> child s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   418
  and ch2: "(Th th2, Th th) \<in> child s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   419
  and dp1: "th3 \<in> dependants s th1"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   420
  and dp2: "th3 \<in> dependants s th2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   421
shows "th1 = th2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   422
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   423
  { assume neq: "th1 \<noteq> th2"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   424
    from dp1 have dp1: "(Th th3, Th th1) \<in> (RAG s)^+" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   425
      by (simp add:s_dependants_def eq_RAG)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   426
    from dp2 have dp2: "(Th th3, Th th2) \<in> (RAG s)^+" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   427
      by (simp add:s_dependants_def eq_RAG)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   428
    from unique_RAG_p[OF vt dp1 dp2] and neq
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   429
    have "(Th th1, Th th2) \<in> (RAG s)\<^sup>+ \<or> (Th th2, Th th1) \<in> (RAG s)\<^sup>+" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   430
    hence False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   431
    proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   432
      assume "(Th th1, Th th2) \<in> (RAG s)\<^sup>+ "
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   433
      from children_no_dep[OF vt ch1 ch2 this] show ?thesis .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   434
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   435
      assume " (Th th2, Th th1) \<in> (RAG s)\<^sup>+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   436
      from children_no_dep[OF vt ch2 ch1 this] show ?thesis .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   437
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   438
  } thus ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   439
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   440
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   441
lemma RAG_plus_elim:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   442
  assumes "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   443
  fixes x
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   444
  assumes "(Th x, Th th) \<in> (RAG (wq s))\<^sup>+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   445
  shows "\<exists>th'\<in>children s th. x = th' \<or> (Th x, Th th') \<in> (RAG (wq s))\<^sup>+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   446
  using assms(2)[unfolded eq_RAG, folded child_RAG_eq[OF `vt s`]]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   447
  apply (unfold children_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   448
  by (metis assms(2) children_def RAG_children eq_RAG)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   449
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   450
text {* (* ddd *)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   451
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   452
lemma dependants_expand:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   453
  assumes "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   454
  shows "dependants (wq s) th = (children s th) \<union> (\<Union>((dependants (wq s)) ` children s th))"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   455
apply(simp add: image_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   456
unfolding cs_dependants_def
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   457
apply(auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   458
apply (metis assms RAG_plus_elim mem_Collect_eq)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   459
apply (metis child_RAG_p children_def eq_RAG mem_Collect_eq r_into_trancl')
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   460
by (metis assms child_RAG_eq children_def eq_RAG mem_Collect_eq trancl.trancl_into_trancl)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   461
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   462
lemma finite_children:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   463
  assumes "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   464
  shows "finite (children s th)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   465
  using children_dependants dependants_threads[OF assms] finite_threads[OF assms]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   466
  by (metis rev_finite_subset)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   467
  
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   468
lemma finite_dependants:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   469
  assumes "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   470
  shows "finite (dependants (wq s) th')"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   471
  using dependants_threads[OF assms] finite_threads[OF assms]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   472
  by (metis rev_finite_subset)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   473
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   474
abbreviation
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   475
  "preceds s ths \<equiv> {preced th s| th. th \<in> ths}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   476
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   477
abbreviation
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   478
  "cpreceds s ths \<equiv> (cp s) ` ths"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   479
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   480
lemma Un_compr:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   481
  "{f th | th. R th \<or> Q th} = ({f th | th. R th} \<union> {f th' | th'. Q th'})"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   482
by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   483
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   484
lemma in_disj:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   485
  shows "x \<in> A \<or> (\<exists>y \<in> A. x \<in> Q y) \<longleftrightarrow> (\<exists>y \<in> A. x = y \<or> x \<in> Q y)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   486
by metis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   487
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   488
lemma UN_exists:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   489
  shows "(\<Union>x \<in> A. {f y | y. Q y x}) = ({f y | y. (\<exists>x \<in> A. Q y x)})"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   490
by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   491
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   492
text {* (* ddd *)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   493
  This is the recursive equation used to compute the current precedence of 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   494
  a thread (the @{text "th"}) here. 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   495
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   496
lemma cp_rec:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   497
  fixes s th
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   498
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   499
  shows "cp s th = Max ({preced th s} \<union> (cp s ` children s th))"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   500
proof(cases "children s th = {}")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   501
  case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   502
  show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   503
    unfolding cp_eq_cpreced cpreced_def 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   504
    by (subst dependants_expand[OF `vt s`]) (simp add: True)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   505
next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   506
  case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   507
  show ?thesis (is "?LHS = ?RHS")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   508
  proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   509
    have eq_cp: "cp s = (\<lambda>th. Max (preceds s ({th} \<union> dependants (wq s) th)))"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   510
      by (simp add: fun_eq_iff cp_eq_cpreced cpreced_def Un_compr image_Collect[symmetric])
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   511
  
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   512
    have not_emptyness_facts[simp]: 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   513
      "dependants (wq s) th \<noteq> {}" "children s th \<noteq> {}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   514
      using False dependants_expand[OF assms] by(auto simp only: Un_empty)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   515
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   516
    have finiteness_facts[simp]:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   517
      "\<And>th. finite (dependants (wq s) th)" "\<And>th. finite (children s th)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   518
      by (simp_all add: finite_dependants[OF `vt s`] finite_children[OF `vt s`])
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   519
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   520
    (* expanding definition *)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   521
    have "?LHS = Max ({preced th s} \<union> preceds s (dependants (wq s) th))"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   522
      unfolding eq_cp by (simp add: Un_compr)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   523
    
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   524
    (* moving Max in *)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   525
    also have "\<dots> = max (Max {preced th s}) (Max (preceds s (dependants (wq s) th)))"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   526
      by (simp add: Max_Un)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   527
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   528
    (* expanding dependants *)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   529
    also have "\<dots> = max (Max {preced th s}) 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   530
      (Max (preceds s (children s th \<union> \<Union>(dependants (wq s) ` children s th))))"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   531
      by (subst dependants_expand[OF `vt s`]) (simp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   532
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   533
    (* moving out big Union *)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   534
    also have "\<dots> = max (Max {preced th s})
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   535
      (Max (preceds s (\<Union> ({children s th} \<union> (dependants (wq s) ` children s th)))))"  
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   536
      by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   537
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   538
    (* moving in small union *)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   539
    also have "\<dots> = max (Max {preced th s})
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   540
      (Max (preceds s (\<Union> ((\<lambda>th. {th} \<union> (dependants (wq s) th)) ` children s th))))"  
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   541
      by (simp add: in_disj)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   542
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   543
    (* moving in preceds *)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   544
    also have "\<dots> = max (Max {preced th s})  
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   545
      (Max (\<Union> ((\<lambda>th. preceds s ({th} \<union> (dependants (wq s) th))) ` children s th)))" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   546
      by (simp add: UN_exists)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   547
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   548
    (* moving in Max *)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   549
    also have "\<dots> = max (Max {preced th s})  
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   550
      (Max ((\<lambda>th. Max (preceds s ({th} \<union> (dependants (wq s) th)))) ` children s th))" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   551
      by (subst Max_Union) (auto simp add: image_image)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   552
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   553
    (* folding cp + moving out Max *)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   554
    also have "\<dots> = ?RHS" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   555
      unfolding eq_cp by (simp add: Max_insert)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   556
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   557
    finally show "?LHS = ?RHS" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   558
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   559
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   560
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   561
lemma next_waiting:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   562
  assumes vt: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   563
  and nxt: "next_th s th cs th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   564
  shows "waiting s th' cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   565
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   566
  from assms show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   567
    apply (auto simp:next_th_def s_waiting_def[folded wq_def])
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   568
  proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   569
    fix rest
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   570
    assume ni: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   571
      and eq_wq: "wq s cs = th # rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   572
      and ne: "rest \<noteq> []"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   573
    have "set (SOME q. distinct q \<and> set q = set rest) = set rest" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   574
    proof(rule someI2)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   575
      from wq_distinct[OF vt, of cs] eq_wq
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   576
      show "distinct rest \<and> set rest = set rest" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   577
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   578
      show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   579
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   580
    with ni
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   581
    have "hd (SOME q. distinct q \<and> set q = set rest) \<notin>  set (SOME q. distinct q \<and> set q = set rest)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   582
      by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   583
    moreover have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   584
    proof(rule someI2)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   585
      from wq_distinct[OF vt, of cs] eq_wq
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   586
      show "distinct rest \<and> set rest = set rest" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   587
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   588
      from ne show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> x \<noteq> []" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   589
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   590
    ultimately show "hd (SOME q. distinct q \<and> set q = set rest) = th" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   591
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   592
    fix rest
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   593
    assume eq_wq: "wq s cs = hd (SOME q. distinct q \<and> set q = set rest) # rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   594
      and ne: "rest \<noteq> []"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   595
    have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   596
    proof(rule someI2)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   597
      from wq_distinct[OF vt, of cs] eq_wq
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   598
      show "distinct rest \<and> set rest = set rest" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   599
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   600
      from ne show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> x \<noteq> []" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   601
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   602
    hence "hd (SOME q. distinct q \<and> set q = set rest) \<in> set (SOME q. distinct q \<and> set q = set rest)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   603
      by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   604
    moreover have "set (SOME q. distinct q \<and> set q = set rest) = set rest" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   605
    proof(rule someI2)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   606
      from wq_distinct[OF vt, of cs] eq_wq
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   607
      show "distinct rest \<and> set rest = set rest" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   608
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   609
      show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   610
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   611
    ultimately have "hd (SOME q. distinct q \<and> set q = set rest) \<in> set rest" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   612
    with eq_wq and wq_distinct[OF vt, of cs]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   613
    show False by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   614
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   615
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   616
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   617
-- {* A useless definition *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   618
definition cps:: "state \<Rightarrow> (thread \<times> precedence) set"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   619
where "cps s = {(th, cp s th) | th . th \<in> threads s}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   620
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   621
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   622
text {* (* ddd *)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   623
  One beauty of our modelling is that we follow the definitional extension tradition of HOL.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   624
  The benefit of such a concise and miniature model is that  large number of intuitively 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   625
  obvious facts are derived as lemmas, rather than asserted as axioms.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   626
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   627
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   628
text {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   629
  However, the lemmas in the forthcoming several locales are no longer 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   630
  obvious. These lemmas show how the current precedences should be recalculated 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   631
  after every execution step (in our model, every step is represented by an event, 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   632
  which in turn, represents a system call, or operation). Each operation is 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   633
  treated in a separate locale.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   634
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   635
  The complication of current precedence recalculation comes 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   636
  because the changing of RAG needs to be taken into account, 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   637
  in addition to the changing of precedence. 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   638
  The reason RAG changing affects current precedence is that,
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   639
  according to the definition, current precedence 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   640
  of a thread is the maximum of the precedences of its dependants, 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   641
  where the dependants are defined in terms of RAG.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   642
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   643
  Therefore, each operation, lemmas concerning the change of the precedences 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   644
  and RAG are derived first, so that the lemmas about
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   645
  current precedence recalculation can be based on.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   646
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   647
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   648
text {* (* ddd *)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   649
  The following locale @{text "step_set_cps"} investigates the recalculation 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   650
  after the @{text "Set"} operation.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   651
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   652
locale step_set_cps =
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   653
  fixes s' th prio s 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   654
  -- {* @{text "s'"} is the system state before the operation *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   655
  -- {* @{text "s"} is the system state after the operation *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   656
  defines s_def : "s \<equiv> (Set th prio#s')" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   657
  -- {* @{text "s"} is assumed to be a legitimate state, from which
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   658
         the legitimacy of @{text "s"} can be derived. *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   659
  assumes vt_s: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   660
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   661
context step_set_cps 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   662
begin
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   663
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   664
interpretation h: pip "s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   665
  by (unfold pip_def, insert vt_s, simp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   666
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   667
find_theorems 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   668
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   669
(* *)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   670
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   671
text {* (* ddd *)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   672
  The following lemma confirms that @{text "Set"}-operating only changes the precedence 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   673
  of initiating thread.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   674
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   675
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   676
lemma eq_preced:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   677
  fixes th'
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   678
  assumes "th' \<noteq> th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   679
  shows "preced th' s = preced th' s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   680
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   681
  from assms show ?thesis 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   682
    by (unfold s_def, auto simp:preced_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   683
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   684
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   685
text {* (* ddd *)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   686
  The following lemma assures that the resetting of priority does not change the RAG. 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   687
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   688
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   689
lemma eq_dep: "RAG s = RAG s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   690
  by (unfold s_def RAG_set_unchanged, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   691
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   692
text {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   693
  Th following lemma @{text "eq_cp_pre"} circumscribe a rough range of recalculation.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   694
  It says, thread other than the initiating thread @{text "th"} does not need recalculation
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   695
  unless it lies upstream of @{text "th"} in the RAG. 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   696
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   697
  The reason behind this lemma is that: 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   698
  the change of precedence of one thread can only affect it's upstream threads, according to 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   699
  lemma @{text "eq_preced"}. Since the only thread which might change precedence is
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   700
  @{text "th"}, so only @{text "th"} and its upstream threads need recalculation.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   701
  (* ccc *)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   702
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   703
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   704
lemma eq_cp_pre:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   705
  fixes th' 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   706
  assumes neq_th: "th' \<noteq> th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   707
  and nd: "th \<notin> dependants s th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   708
  shows "cp s th' = cp s' th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   709
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   710
  -- {* This is what we need to prove after expanding the definition of @{text "cp"} *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   711
  have "Max ((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')) =
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   712
        Max ((\<lambda>th. preced th s') ` ({th'} \<union> dependants (wq s') th'))"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   713
   (is "Max (?f1 ` ({th'} \<union> ?A)) = Max (?f2 ` ({th'} \<union> ?B))") 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   714
  proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   715
      -- {* Since RAG is not changed by @{text "Set"}-operation, the dependants of 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   716
            any threads are not changed, this is one of key facts underpinning this 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   717
            lemma *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   718
      have eq_ab: "?A = ?B" by (unfold cs_dependants_def, auto simp:eq_dep eq_RAG)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   719
      have "(?f1 ` ({th'} \<union> ?A)) =  (?f2 ` ({th'} \<union> ?B))"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   720
      proof(rule image_cong)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   721
        show "{th'} \<union> ?A = {th'} \<union> ?B" by (simp only:eq_ab)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   722
      next  
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   723
        fix x
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   724
        assume x_in: "x \<in> {th'} \<union> ?B"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   725
        show "?f1 x = ?f2 x"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   726
        proof(rule eq_preced) -- {* The other key fact underpinning this lemma is @{text "eq_preced"} *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   727
          from x_in[folded eq_ab, unfolded eq_dependants]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   728
          have "x \<in> {th'} \<union> dependants s th'" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   729
          thus "x \<noteq> th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   730
          proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   731
            assume "x \<in> {th'}" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   732
            with `th' \<noteq> th` show ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   733
          next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   734
            assume "x \<in> dependants s th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   735
            with `th \<notin> dependants s th'` show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   736
          qed 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   737
        qed 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   738
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   739
      thus ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   740
  qed 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   741
  thus ?thesis by (unfold cp_eq_cpreced cpreced_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   742
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   743
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   744
text {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   745
  The following lemma shows that no thread lies upstream of the initiating thread @{text "th"}. 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   746
  The reason for this is that only no-blocked thread can initiate 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   747
  a system call. Since thread @{text "th"} is non-blocked, it is not waiting for any 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   748
  critical resource. Therefore, there is edge leading out of @{text "th"} in the RAG.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   749
  Consequently, there is no node (neither resource nor thread) upstream of @{text "th"}.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   750
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   751
lemma no_dependants:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   752
  shows "th \<notin> dependants s th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   753
proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   754
  assume "th \<in> dependants s th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   755
  from `th \<in> dependants s th'` have "(Th th, Th th') \<in> (RAG s')\<^sup>+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   756
    by (unfold s_dependants_def, unfold eq_RAG, unfold eq_dep, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   757
  from tranclD[OF this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   758
  obtain z where "(Th th, z) \<in> RAG s'" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   759
  moreover have "th \<in> readys s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   760
  proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   761
    from step_back_step [OF vt_s[unfolded s_def]]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   762
    have "step s' (Set th prio)" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   763
    hence "th \<in> runing s'" by (cases, simp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   764
    thus ?thesis by (simp add:readys_def runing_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   765
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   766
  ultimately show "False"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   767
    apply (case_tac z, auto simp:readys_def s_RAG_def s_waiting_def cs_waiting_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   768
    by (fold wq_def, blast)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   769
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   770
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   771
(* Result improved *)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   772
text {* 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   773
  A simple combination of @{text "eq_cp_pre"} and @{text "no_dependants"}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   774
  gives the main lemma of this locale, which shows that
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   775
  only the initiating thread needs a recalculation of current precedence.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   776
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   777
lemma eq_cp:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   778
  fixes th' 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   779
  assumes "th' \<noteq> th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   780
  shows "cp s th' = cp s' th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   781
  by (rule eq_cp_pre[OF assms no_dependants])
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   782
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   783
end
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   784
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   785
text {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   786
  The following @{text "step_v_cps"} is the locale for @{text "V"}-operation.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   787
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   788
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   789
locale step_v_cps =
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   790
  -- {* @{text "th"} is the initiating thread *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   791
  -- {* @{text "cs"} is the critical resource release by the @{text "V"}-operation *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   792
  fixes s' th cs s    -- {* @{text "s'"} is the state before operation*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   793
  defines s_def : "s \<equiv> (V th cs#s')" -- {* @{text "s"} is the state after operation*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   794
  -- {* @{text "s"} is assumed to be valid, which implies the validity of @{text "s'"} *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   795
  assumes vt_s: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   796
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   797
text {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   798
  The following @{text "step_v_cps_nt"} is the sub-locale for @{text "V"}-operation, 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   799
  which represents the case when there is another thread @{text "th'"}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   800
  to take over the critical resource released by the initiating thread @{text "th"}.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   801
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   802
locale step_v_cps_nt = step_v_cps +
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   803
  fixes th'
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   804
  -- {* @{text "th'"} is assumed to take over @{text "cs"} *}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   805
  assumes nt: "next_th s' th cs th'" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   806
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   807
context step_v_cps_nt
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   808
begin
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   809
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   810
text {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   811
  Lemma @{text "RAG_s"} confirms the change of RAG:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   812
  two edges removed and one added, as shown by the following diagram.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   813
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   814
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   815
(*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   816
  RAG before the V-operation
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   817
    th1 ----|
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   818
            |
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   819
    th' ----|
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   820
            |----> cs -----|
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   821
    th2 ----|              |
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   822
            |              |
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   823
    th3 ----|              |
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   824
                           |------> th
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   825
    th4 ----|              |
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   826
            |              |
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   827
    th5 ----|              |
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   828
            |----> cs'-----|
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   829
    th6 ----|
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   830
            |
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   831
    th7 ----|
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   832
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   833
 RAG after the V-operation
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   834
    th1 ----|
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   835
            |
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   836
            |----> cs ----> th'
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   837
    th2 ----|              
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   838
            |              
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   839
    th3 ----|              
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   840
                           
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   841
    th4 ----|              
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   842
            |              
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   843
    th5 ----|              
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   844
            |----> cs'----> th
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   845
    th6 ----|
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   846
            |
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   847
    th7 ----|
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   848
*)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   849
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   850
lemma RAG_s:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   851
  "RAG s = (RAG s' - {(Cs cs, Th th), (Th th', Cs cs)}) \<union>
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   852
                                         {(Cs cs, Th th')}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   853
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   854
  from step_RAG_v[OF vt_s[unfolded s_def], folded s_def]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   855
    and nt show ?thesis  by (auto intro:next_th_unique)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   856
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   857
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   858
text {*
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   859
  Lemma @{text "dependants_kept"} shows only @{text "th"} and @{text "th'"}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   860
  have their dependants changed.
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   861
*}
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   862
lemma dependants_kept:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   863
  fixes th''
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   864
  assumes neq1: "th'' \<noteq> th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   865
  and neq2: "th'' \<noteq> th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   866
  shows "dependants (wq s) th'' = dependants (wq s') th''"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   867
proof(auto) (* ccc *)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   868
  fix x
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   869
  assume "x \<in> dependants (wq s) th''"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   870
  hence dp: "(Th x, Th th'') \<in> (RAG s)^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   871
    by (auto simp:cs_dependants_def eq_RAG)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   872
  { fix n
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   873
    have "(n, Th th'') \<in> (RAG s)^+ \<Longrightarrow>  (n, Th th'') \<in> (RAG s')^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   874
    proof(induct rule:converse_trancl_induct)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   875
      fix y 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   876
      assume "(y, Th th'') \<in> RAG s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   877
      with RAG_s neq1 neq2
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   878
      have "(y, Th th'') \<in> RAG s'" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   879
      thus "(y, Th th'') \<in> (RAG s')\<^sup>+" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   880
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   881
      fix y z 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   882
      assume yz: "(y, z) \<in> RAG s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   883
        and ztp: "(z, Th th'') \<in> (RAG s)\<^sup>+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   884
        and ztp': "(z, Th th'') \<in> (RAG s')\<^sup>+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   885
      have "y \<noteq> Cs cs \<and> y \<noteq> Th th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   886
      proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   887
        show "y \<noteq> Cs cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   888
        proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   889
          assume eq_y: "y = Cs cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   890
          with yz have dp_yz: "(Cs cs, z) \<in> RAG s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   891
          from RAG_s
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   892
          have cst': "(Cs cs, Th th') \<in> RAG s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   893
          from unique_RAG[OF vt_s this dp_yz] 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   894
          have eq_z: "z = Th th'" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   895
          with ztp have "(Th th', Th th'') \<in> (RAG s)^+" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   896
          from converse_tranclE[OF this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   897
          obtain cs' where dp'': "(Th th', Cs cs') \<in> RAG s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   898
            by (auto simp:s_RAG_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   899
          with RAG_s have dp': "(Th th', Cs cs') \<in> RAG s'" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   900
          from dp'' eq_y yz eq_z have "(Cs cs, Cs cs') \<in> (RAG s)^+" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   901
          moreover have "cs' = cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   902
          proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   903
            from next_waiting[OF step_back_vt[OF vt_s[unfolded s_def]] nt]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   904
            have "(Th th', Cs cs) \<in> RAG s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   905
              by (auto simp:s_waiting_def wq_def s_RAG_def cs_waiting_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   906
            from unique_RAG[OF step_back_vt[OF vt_s[unfolded s_def]] this dp']
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   907
            show ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   908
          qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   909
          ultimately have "(Cs cs, Cs cs) \<in> (RAG s)^+" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   910
          moreover note wf_trancl[OF wf_RAG[OF vt_s]]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   911
          ultimately show False by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   912
        qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   913
      next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   914
        show "y \<noteq> Th th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   915
        proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   916
          assume eq_y: "y = Th th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   917
          with yz have dps: "(Th th', z) \<in> RAG s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   918
          with RAG_s have dps': "(Th th', z) \<in> RAG s'" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   919
          have "z = Cs cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   920
          proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   921
            from next_waiting[OF step_back_vt[OF vt_s[unfolded s_def]] nt]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   922
            have "(Th th', Cs cs) \<in> RAG s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   923
              by (auto simp:s_waiting_def wq_def s_RAG_def cs_waiting_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   924
            from unique_RAG[OF step_back_vt[OF vt_s[unfolded s_def]] dps' this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   925
            show ?thesis .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   926
          qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   927
          with dps RAG_s show False by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   928
        qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   929
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   930
      with RAG_s yz have "(y, z) \<in> RAG s'" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   931
      with ztp'
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   932
      show "(y, Th th'') \<in> (RAG s')\<^sup>+" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   933
    qed    
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   934
  }
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   935
  from this[OF dp]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   936
  show "x \<in> dependants (wq s') th''" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   937
    by (auto simp:cs_dependants_def eq_RAG)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   938
next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   939
  fix x
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   940
  assume "x \<in> dependants (wq s') th''"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   941
  hence dp: "(Th x, Th th'') \<in> (RAG s')^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   942
    by (auto simp:cs_dependants_def eq_RAG)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   943
  { fix n
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   944
    have "(n, Th th'') \<in> (RAG s')^+ \<Longrightarrow>  (n, Th th'') \<in> (RAG s)^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   945
    proof(induct rule:converse_trancl_induct)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   946
      fix y 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   947
      assume "(y, Th th'') \<in> RAG s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   948
      with RAG_s neq1 neq2
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   949
      have "(y, Th th'') \<in> RAG s" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   950
      thus "(y, Th th'') \<in> (RAG s)\<^sup>+" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   951
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   952
      fix y z 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   953
      assume yz: "(y, z) \<in> RAG s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   954
        and ztp: "(z, Th th'') \<in> (RAG s')\<^sup>+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   955
        and ztp': "(z, Th th'') \<in> (RAG s)\<^sup>+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   956
      have "y \<noteq> Cs cs \<and> y \<noteq> Th th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   957
      proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   958
        show "y \<noteq> Cs cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   959
        proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   960
          assume eq_y: "y = Cs cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   961
          with yz have dp_yz: "(Cs cs, z) \<in> RAG s'" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   962
          from this have eq_z: "z = Th th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   963
          proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   964
            from step_back_step[OF vt_s[unfolded s_def]]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   965
            have "(Cs cs, Th th) \<in> RAG s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   966
              by(cases, auto simp: wq_def s_RAG_def cs_holding_def s_holding_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   967
            from unique_RAG[OF step_back_vt[OF vt_s[unfolded s_def]] this dp_yz]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   968
            show ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   969
          qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   970
          from converse_tranclE[OF ztp]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   971
          obtain u where "(z, u) \<in> RAG s'" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   972
          moreover 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   973
          from step_back_step[OF vt_s[unfolded s_def]]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   974
          have "th \<in> readys s'" by (cases, simp add:runing_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   975
          moreover note eq_z
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   976
          ultimately show False 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   977
            by (auto simp:readys_def wq_def s_RAG_def s_waiting_def cs_waiting_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   978
        qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   979
      next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   980
        show "y \<noteq> Th th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   981
        proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   982
          assume eq_y: "y = Th th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   983
          with yz have dps: "(Th th', z) \<in> RAG s'" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   984
          have "z = Cs cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   985
          proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   986
            from next_waiting[OF step_back_vt[OF vt_s[unfolded s_def]] nt]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   987
            have "(Th th', Cs cs) \<in> RAG s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   988
              by (auto simp:s_waiting_def wq_def s_RAG_def cs_waiting_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   989
            from unique_RAG[OF step_back_vt[OF vt_s[unfolded s_def]] dps this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   990
            show ?thesis .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   991
          qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   992
          with ztp have cs_i: "(Cs cs, Th th'') \<in>  (RAG s')\<^sup>+" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   993
          from step_back_step[OF vt_s[unfolded s_def]]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   994
          have cs_th: "(Cs cs, Th th) \<in> RAG s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   995
            by(cases, auto simp: s_RAG_def wq_def cs_holding_def s_holding_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   996
          have "(Cs cs, Th th'') \<notin>  RAG s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   997
          proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   998
            assume "(Cs cs, Th th'') \<in> RAG s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
   999
            from unique_RAG[OF step_back_vt[OF vt_s[unfolded s_def]] this cs_th]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1000
            and neq1 show "False" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1001
          qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1002
          with converse_tranclE[OF cs_i]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1003
          obtain u where cu: "(Cs cs, u) \<in> RAG s'"  
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1004
            and u_t: "(u, Th th'') \<in> (RAG s')\<^sup>+" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1005
          have "u = Th th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1006
          proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1007
            from unique_RAG[OF step_back_vt[OF vt_s[unfolded s_def]] cu cs_th]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1008
            show ?thesis .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1009
          qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1010
          with u_t have "(Th th, Th th'') \<in> (RAG s')\<^sup>+" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1011
          from converse_tranclE[OF this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1012
          obtain v where "(Th th, v) \<in> (RAG s')" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1013
          moreover from step_back_step[OF vt_s[unfolded s_def]]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1014
          have "th \<in> readys s'" by (cases, simp add:runing_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1015
          ultimately show False 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1016
            by (auto simp:readys_def wq_def s_RAG_def s_waiting_def cs_waiting_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1017
        qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1018
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1019
      with RAG_s yz have "(y, z) \<in> RAG s" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1020
      with ztp'
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1021
      show "(y, Th th'') \<in> (RAG s)\<^sup>+" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1022
    qed    
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1023
  }
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1024
  from this[OF dp]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1025
  show "x \<in> dependants (wq s) th''"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1026
    by (auto simp:cs_dependants_def eq_RAG)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1027
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1028
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1029
lemma cp_kept:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1030
  fixes th''
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1031
  assumes neq1: "th'' \<noteq> th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1032
  and neq2: "th'' \<noteq> th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1033
  shows "cp s th'' = cp s' th''"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1034
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1035
  from dependants_kept[OF neq1 neq2]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1036
  have "dependants (wq s) th'' = dependants (wq s') th''" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1037
  moreover {
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1038
    fix th1
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1039
    assume "th1 \<in> dependants (wq s) th''"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1040
    have "preced th1 s = preced th1 s'" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1041
      by (unfold s_def, auto simp:preced_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1042
  }
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1043
  moreover have "preced th'' s = preced th'' s'" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1044
    by (unfold s_def, auto simp:preced_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1045
  ultimately have "((\<lambda>th. preced th s) ` ({th''} \<union> dependants (wq s) th'')) = 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1046
    ((\<lambda>th. preced th s') ` ({th''} \<union> dependants (wq s') th''))"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1047
    by (auto simp:image_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1048
  thus ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1049
    by (unfold cp_eq_cpreced cpreced_def, simp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1050
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1051
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1052
end
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1053
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1054
locale step_v_cps_nnt = step_v_cps +
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1055
  assumes nnt: "\<And> th'. (\<not> next_th s' th cs th')"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1056
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1057
context step_v_cps_nnt
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1058
begin
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1059
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1060
lemma nw_cs: "(Th th1, Cs cs) \<notin> RAG s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1061
proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1062
  assume "(Th th1, Cs cs) \<in> RAG s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1063
  thus "False"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1064
    apply (auto simp:s_RAG_def cs_waiting_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1065
  proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1066
    assume h1: "th1 \<in> set (wq s' cs)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1067
      and h2: "th1 \<noteq> hd (wq s' cs)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1068
    from step_back_step[OF vt_s[unfolded s_def]]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1069
    show "False"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1070
    proof(cases)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1071
      assume "holding s' th cs" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1072
      then obtain rest where
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1073
        eq_wq: "wq s' cs = th#rest"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1074
        apply (unfold s_holding_def wq_def[symmetric])
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1075
        by (case_tac "(wq s' cs)", auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1076
      with h1 h2 have ne: "rest \<noteq> []" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1077
      with eq_wq
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1078
      have "next_th s' th cs (hd (SOME q. distinct q \<and> set q = set rest))"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1079
        by(unfold next_th_def, rule_tac x = "rest" in exI, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1080
      with nnt show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1081
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1082
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1083
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1084
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1085
lemma RAG_s: "RAG s = RAG s' - {(Cs cs, Th th)}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1086
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1087
  from nnt and  step_RAG_v[OF vt_s[unfolded s_def], folded s_def]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1088
  show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1089
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1090
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1091
lemma child_kept_left:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1092
  assumes 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1093
  "(n1, n2) \<in> (child s')^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1094
  shows "(n1, n2) \<in> (child s)^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1095
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1096
  from assms show ?thesis 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1097
  proof(induct rule: converse_trancl_induct)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1098
    case (base y)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1099
    from base obtain th1 cs1 th2
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1100
      where h1: "(Th th1, Cs cs1) \<in> RAG s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1101
      and h2: "(Cs cs1, Th th2) \<in> RAG s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1102
      and eq_y: "y = Th th1" and eq_n2: "n2 = Th th2"  by (auto simp:child_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1103
    have "cs1 \<noteq> cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1104
    proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1105
      assume eq_cs: "cs1 = cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1106
      with h1 have "(Th th1, Cs cs1) \<in> RAG s'" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1107
      with nw_cs eq_cs show False by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1108
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1109
    with h1 h2 RAG_s have 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1110
      h1': "(Th th1, Cs cs1) \<in> RAG s" and
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1111
      h2': "(Cs cs1, Th th2) \<in> RAG s" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1112
    hence "(Th th1, Th th2) \<in> child s" by (auto simp:child_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1113
    with eq_y eq_n2 have "(y, n2) \<in> child s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1114
    thus ?case by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1115
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1116
    case (step y z)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1117
    have "(y, z) \<in> child s'" by fact
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1118
    then obtain th1 cs1 th2
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1119
      where h1: "(Th th1, Cs cs1) \<in> RAG s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1120
      and h2: "(Cs cs1, Th th2) \<in> RAG s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1121
      and eq_y: "y = Th th1" and eq_z: "z = Th th2"  by (auto simp:child_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1122
    have "cs1 \<noteq> cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1123
    proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1124
      assume eq_cs: "cs1 = cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1125
      with h1 have "(Th th1, Cs cs1) \<in> RAG s'" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1126
      with nw_cs eq_cs show False by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1127
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1128
    with h1 h2 RAG_s have 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1129
      h1': "(Th th1, Cs cs1) \<in> RAG s" and
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1130
      h2': "(Cs cs1, Th th2) \<in> RAG s" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1131
    hence "(Th th1, Th th2) \<in> child s" by (auto simp:child_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1132
    with eq_y eq_z have "(y, z) \<in> child s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1133
    moreover have "(z, n2) \<in> (child s)^+" by fact
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1134
    ultimately show ?case by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1135
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1136
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1137
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1138
lemma  child_kept_right:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1139
  assumes
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1140
  "(n1, n2) \<in> (child s)^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1141
  shows "(n1, n2) \<in> (child s')^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1142
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1143
  from assms show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1144
  proof(induct)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1145
    case (base y)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1146
    from base and RAG_s 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1147
    have "(n1, y) \<in> child s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1148
      by (auto simp:child_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1149
    thus ?case by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1150
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1151
    case (step y z)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1152
    have "(y, z) \<in> child s" by fact
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1153
    with RAG_s have "(y, z) \<in> child s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1154
      by (auto simp:child_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1155
    moreover have "(n1, y) \<in> (child s')\<^sup>+" by fact
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1156
    ultimately show ?case by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1157
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1158
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1159
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1160
lemma eq_child: "(child s)^+ = (child s')^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1161
  by (insert child_kept_left child_kept_right, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1162
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1163
lemma eq_cp:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1164
  fixes th' 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1165
  shows "cp s th' = cp s' th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1166
  apply (unfold cp_eq_cpreced cpreced_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1167
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1168
  have eq_dp: "\<And> th. dependants (wq s) th = dependants (wq s') th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1169
    apply (unfold cs_dependants_def, unfold eq_RAG)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1170
  proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1171
    from eq_child
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1172
    have "\<And>th. {th'. (Th th', Th th) \<in> (child s)\<^sup>+} = {th'. (Th th', Th th) \<in> (child s')\<^sup>+}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1173
      by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1174
    with child_RAG_eq[OF vt_s] child_RAG_eq[OF step_back_vt[OF vt_s[unfolded s_def]]]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1175
    show "\<And>th. {th'. (Th th', Th th) \<in> (RAG s)\<^sup>+} = {th'. (Th th', Th th) \<in> (RAG s')\<^sup>+}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1176
      by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1177
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1178
  moreover {
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1179
    fix th1 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1180
    assume "th1 \<in> {th'} \<union> dependants (wq s') th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1181
    hence "th1 = th' \<or> th1 \<in> dependants (wq s') th'" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1182
    hence "preced th1 s = preced th1 s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1183
    proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1184
      assume "th1 = th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1185
      show "preced th1 s = preced th1 s'" by (simp add:s_def preced_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1186
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1187
      assume "th1 \<in> dependants (wq s') th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1188
      show "preced th1 s = preced th1 s'" by (simp add:s_def preced_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1189
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1190
  } ultimately have "((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')) = 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1191
                     ((\<lambda>th. preced th s') ` ({th'} \<union> dependants (wq s') th'))" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1192
    by (auto simp:image_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1193
  thus "Max ((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')) =
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1194
        Max ((\<lambda>th. preced th s') ` ({th'} \<union> dependants (wq s') th'))" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1195
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1196
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1197
end
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1198
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1199
locale step_P_cps =
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1200
  fixes s' th cs s 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1201
  defines s_def : "s \<equiv> (P th cs#s')"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1202
  assumes vt_s: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1203
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1204
locale step_P_cps_ne =step_P_cps +
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1205
  assumes ne: "wq s' cs \<noteq> []"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1206
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1207
locale step_P_cps_e =step_P_cps +
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1208
  assumes ee: "wq s' cs = []"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1209
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1210
context step_P_cps_e
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1211
begin
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1212
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1213
lemma RAG_s: "RAG s = RAG s' \<union> {(Cs cs, Th th)}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1214
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1215
  from ee and  step_RAG_p[OF vt_s[unfolded s_def], folded s_def]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1216
  show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1217
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1218
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1219
lemma child_kept_left:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1220
  assumes 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1221
  "(n1, n2) \<in> (child s')^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1222
  shows "(n1, n2) \<in> (child s)^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1223
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1224
  from assms show ?thesis 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1225
  proof(induct rule: converse_trancl_induct)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1226
    case (base y)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1227
    from base obtain th1 cs1 th2
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1228
      where h1: "(Th th1, Cs cs1) \<in> RAG s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1229
      and h2: "(Cs cs1, Th th2) \<in> RAG s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1230
      and eq_y: "y = Th th1" and eq_n2: "n2 = Th th2"  by (auto simp:child_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1231
    have "cs1 \<noteq> cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1232
    proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1233
      assume eq_cs: "cs1 = cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1234
      with h1 have "(Th th1, Cs cs) \<in> RAG s'" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1235
      with ee show False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1236
        by (auto simp:s_RAG_def cs_waiting_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1237
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1238
    with h1 h2 RAG_s have 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1239
      h1': "(Th th1, Cs cs1) \<in> RAG s" and
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1240
      h2': "(Cs cs1, Th th2) \<in> RAG s" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1241
    hence "(Th th1, Th th2) \<in> child s" by (auto simp:child_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1242
    with eq_y eq_n2 have "(y, n2) \<in> child s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1243
    thus ?case by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1244
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1245
    case (step y z)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1246
    have "(y, z) \<in> child s'" by fact
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1247
    then obtain th1 cs1 th2
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1248
      where h1: "(Th th1, Cs cs1) \<in> RAG s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1249
      and h2: "(Cs cs1, Th th2) \<in> RAG s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1250
      and eq_y: "y = Th th1" and eq_z: "z = Th th2"  by (auto simp:child_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1251
    have "cs1 \<noteq> cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1252
    proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1253
      assume eq_cs: "cs1 = cs"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1254
      with h1 have "(Th th1, Cs cs) \<in> RAG s'" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1255
      with ee show False 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1256
        by (auto simp:s_RAG_def cs_waiting_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1257
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1258
    with h1 h2 RAG_s have 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1259
      h1': "(Th th1, Cs cs1) \<in> RAG s" and
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1260
      h2': "(Cs cs1, Th th2) \<in> RAG s" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1261
    hence "(Th th1, Th th2) \<in> child s" by (auto simp:child_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1262
    with eq_y eq_z have "(y, z) \<in> child s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1263
    moreover have "(z, n2) \<in> (child s)^+" by fact
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1264
    ultimately show ?case by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1265
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1266
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1267
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1268
lemma  child_kept_right:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1269
  assumes
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1270
  "(n1, n2) \<in> (child s)^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1271
  shows "(n1, n2) \<in> (child s')^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1272
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1273
  from assms show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1274
  proof(induct)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1275
    case (base y)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1276
    from base and RAG_s
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1277
    have "(n1, y) \<in> child s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1278
      apply (auto simp:child_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1279
      proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1280
        fix th'
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1281
        assume "(Th th', Cs cs) \<in> RAG s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1282
        with ee have "False"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1283
          by (auto simp:s_RAG_def cs_waiting_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1284
        thus "\<exists>cs. (Th th', Cs cs) \<in> RAG s' \<and> (Cs cs, Th th) \<in> RAG s'" by auto 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1285
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1286
    thus ?case by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1287
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1288
    case (step y z)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1289
    have "(y, z) \<in> child s" by fact
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1290
    with RAG_s have "(y, z) \<in> child s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1291
      apply (auto simp:child_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1292
      proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1293
        fix th'
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1294
        assume "(Th th', Cs cs) \<in> RAG s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1295
        with ee have "False"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1296
          by (auto simp:s_RAG_def cs_waiting_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1297
        thus "\<exists>cs. (Th th', Cs cs) \<in> RAG s' \<and> (Cs cs, Th th) \<in> RAG s'" by auto 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1298
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1299
    moreover have "(n1, y) \<in> (child s')\<^sup>+" by fact
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1300
    ultimately show ?case by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1301
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1302
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1303
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1304
lemma eq_child: "(child s)^+ = (child s')^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1305
  by (insert child_kept_left child_kept_right, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1306
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1307
lemma eq_cp:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1308
  fixes th' 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1309
  shows "cp s th' = cp s' th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1310
  apply (unfold cp_eq_cpreced cpreced_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1311
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1312
  have eq_dp: "\<And> th. dependants (wq s) th = dependants (wq s') th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1313
    apply (unfold cs_dependants_def, unfold eq_RAG)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1314
  proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1315
    from eq_child
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1316
    have "\<And>th. {th'. (Th th', Th th) \<in> (child s)\<^sup>+} = {th'. (Th th', Th th) \<in> (child s')\<^sup>+}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1317
      by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1318
    with child_RAG_eq[OF vt_s] child_RAG_eq[OF step_back_vt[OF vt_s[unfolded s_def]]]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1319
    show "\<And>th. {th'. (Th th', Th th) \<in> (RAG s)\<^sup>+} = {th'. (Th th', Th th) \<in> (RAG s')\<^sup>+}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1320
      by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1321
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1322
  moreover {
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1323
    fix th1 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1324
    assume "th1 \<in> {th'} \<union> dependants (wq s') th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1325
    hence "th1 = th' \<or> th1 \<in> dependants (wq s') th'" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1326
    hence "preced th1 s = preced th1 s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1327
    proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1328
      assume "th1 = th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1329
      show "preced th1 s = preced th1 s'" by (simp add:s_def preced_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1330
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1331
      assume "th1 \<in> dependants (wq s') th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1332
      show "preced th1 s = preced th1 s'" by (simp add:s_def preced_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1333
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1334
  } ultimately have "((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')) = 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1335
                     ((\<lambda>th. preced th s') ` ({th'} \<union> dependants (wq s') th'))" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1336
    by (auto simp:image_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1337
  thus "Max ((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')) =
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1338
        Max ((\<lambda>th. preced th s') ` ({th'} \<union> dependants (wq s') th'))" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1339
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1340
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1341
end
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1342
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1343
context step_P_cps_ne
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1344
begin
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1345
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1346
lemma RAG_s: "RAG s = RAG s' \<union> {(Th th, Cs cs)}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1347
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1348
  from step_RAG_p[OF vt_s[unfolded s_def]] and ne
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1349
  show ?thesis by (simp add:s_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1350
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1351
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1352
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1353
lemma eq_child_left:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1354
  assumes nd: "(Th th, Th th') \<notin> (child s)^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1355
  shows "(n1, Th th') \<in> (child s)^+ \<Longrightarrow> (n1, Th th') \<in> (child s')^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1356
proof(induct rule:converse_trancl_induct)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1357
  case (base y)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1358
  from base obtain th1 cs1
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1359
    where h1: "(Th th1, Cs cs1) \<in> RAG s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1360
    and h2: "(Cs cs1, Th th') \<in> RAG s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1361
    and eq_y: "y = Th th1"   by (auto simp:child_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1362
  have "th1 \<noteq> th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1363
  proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1364
    assume "th1 = th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1365
    with base eq_y have "(Th th, Th th') \<in> child s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1366
    with nd show False by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1367
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1368
  with h1 h2 RAG_s 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1369
  have h1': "(Th th1, Cs cs1) \<in> RAG s'" and 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1370
       h2': "(Cs cs1, Th th') \<in> RAG s'" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1371
  with eq_y show ?case by (auto simp:child_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1372
next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1373
  case (step y z)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1374
  have yz: "(y, z) \<in> child s" by fact
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1375
  then obtain th1 cs1 th2
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1376
    where h1: "(Th th1, Cs cs1) \<in> RAG s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1377
    and h2: "(Cs cs1, Th th2) \<in> RAG s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1378
    and eq_y: "y = Th th1" and eq_z: "z = Th th2"  by (auto simp:child_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1379
  have "th1 \<noteq> th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1380
  proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1381
    assume "th1 = th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1382
    with yz eq_y have "(Th th, z) \<in> child s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1383
    moreover have "(z, Th th') \<in> (child s)^+" by fact
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1384
    ultimately have "(Th th, Th th') \<in> (child s)^+" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1385
    with nd show False by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1386
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1387
  with h1 h2 RAG_s have h1': "(Th th1, Cs cs1) \<in> RAG s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1388
                       and h2': "(Cs cs1, Th th2) \<in> RAG s'" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1389
  with eq_y eq_z have "(y, z) \<in> child s'" by (auto simp:child_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1390
  moreover have "(z, Th th') \<in> (child s')^+" by fact
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1391
  ultimately show ?case by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1392
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1393
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1394
lemma eq_child_right:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1395
  shows "(n1, Th th') \<in> (child s')^+ \<Longrightarrow> (n1, Th th') \<in> (child s)^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1396
proof(induct rule:converse_trancl_induct)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1397
  case (base y)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1398
  with RAG_s show ?case by (auto simp:child_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1399
next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1400
  case (step y z)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1401
  have "(y, z) \<in> child s'" by fact
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1402
  with RAG_s have "(y, z) \<in> child s" by (auto simp:child_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1403
  moreover have "(z, Th th') \<in> (child s)^+" by fact
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1404
  ultimately show ?case by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1405
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1406
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1407
lemma eq_child:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1408
  assumes nd: "(Th th, Th th') \<notin> (child s)^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1409
  shows "((n1, Th th') \<in> (child s)^+) = ((n1, Th th') \<in> (child s')^+)"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1410
  by (insert eq_child_left[OF nd] eq_child_right, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1411
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1412
lemma eq_cp:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1413
  fixes th' 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1414
  assumes nd: "th \<notin> dependants s th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1415
  shows "cp s th' = cp s' th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1416
  apply (unfold cp_eq_cpreced cpreced_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1417
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1418
  have nd': "(Th th, Th th') \<notin> (child s)^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1419
  proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1420
    assume "(Th th, Th th') \<in> (child s)\<^sup>+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1421
    with child_RAG_eq[OF vt_s]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1422
    have "(Th th, Th th') \<in> (RAG s)\<^sup>+" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1423
    with nd show False 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1424
      by (simp add:s_dependants_def eq_RAG)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1425
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1426
  have eq_dp: "dependants (wq s) th' = dependants (wq s') th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1427
  proof(auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1428
    fix x assume " x \<in> dependants (wq s) th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1429
    thus "x \<in> dependants (wq s') th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1430
      apply (auto simp:cs_dependants_def eq_RAG)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1431
    proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1432
      assume "(Th x, Th th') \<in> (RAG s)\<^sup>+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1433
      with  child_RAG_eq[OF vt_s] have "(Th x, Th th') \<in> (child s)\<^sup>+" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1434
      with eq_child[OF nd'] have "(Th x, Th th') \<in> (child s')^+" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1435
      with child_RAG_eq[OF step_back_vt[OF vt_s[unfolded s_def]]]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1436
      show "(Th x, Th th') \<in> (RAG s')\<^sup>+" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1437
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1438
  next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1439
    fix x assume "x \<in> dependants (wq s') th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1440
    thus "x \<in> dependants (wq s) th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1441
      apply (auto simp:cs_dependants_def eq_RAG)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1442
    proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1443
      assume "(Th x, Th th') \<in> (RAG s')\<^sup>+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1444
      with child_RAG_eq[OF step_back_vt[OF vt_s[unfolded s_def]]] 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1445
      have "(Th x, Th th') \<in> (child s')\<^sup>+" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1446
      with eq_child[OF nd'] have "(Th x, Th th') \<in> (child s)^+" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1447
      with  child_RAG_eq[OF vt_s]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1448
      show "(Th x, Th th') \<in> (RAG s)\<^sup>+" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1449
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1450
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1451
  moreover {
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1452
    fix th1 have "preced th1 s = preced th1 s'" by (simp add:s_def preced_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1453
  } ultimately have "((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')) = 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1454
                     ((\<lambda>th. preced th s') ` ({th'} \<union> dependants (wq s') th'))" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1455
    by (auto simp:image_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1456
  thus "Max ((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')) =
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1457
        Max ((\<lambda>th. preced th s') ` ({th'} \<union> dependants (wq s') th'))" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1458
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1459
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1460
lemma eq_up:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1461
  fixes th' th''
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1462
  assumes dp1: "th \<in> dependants s th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1463
  and dp2: "th' \<in> dependants s th''"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1464
  and eq_cps: "cp s th' = cp s' th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1465
  shows "cp s th'' = cp s' th''"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1466
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1467
  from dp2
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1468
  have "(Th th', Th th'') \<in> (RAG (wq s))\<^sup>+" by (simp add:s_dependants_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1469
  from RAG_child[OF vt_s this[unfolded eq_RAG]]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1470
  have ch_th': "(Th th', Th th'') \<in> (child s)\<^sup>+" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1471
  moreover {
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1472
    fix n th''
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1473
    have "\<lbrakk>(Th th', n) \<in> (child s)^+\<rbrakk> \<Longrightarrow>
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1474
                   (\<forall> th'' . n = Th th'' \<longrightarrow> cp s th'' = cp s' th'')"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1475
    proof(erule trancl_induct, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1476
      fix y th''
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1477
      assume y_ch: "(y, Th th'') \<in> child s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1478
        and ih: "\<forall>th''. y = Th th'' \<longrightarrow> cp s th'' = cp s' th''"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1479
        and ch': "(Th th', y) \<in> (child s)\<^sup>+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1480
      from y_ch obtain thy where eq_y: "y = Th thy" by (auto simp:child_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1481
      with ih have eq_cpy:"cp s thy = cp s' thy" by blast
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1482
      from dp1 have "(Th th, Th th') \<in> (RAG s)^+" by (auto simp:s_dependants_def eq_RAG)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1483
      moreover from child_RAG_p[OF ch'] and eq_y
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1484
      have "(Th th', Th thy) \<in> (RAG s)^+" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1485
      ultimately have dp_thy: "(Th th, Th thy) \<in> (RAG s)^+" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1486
      show "cp s th'' = cp s' th''"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1487
        apply (subst cp_rec[OF vt_s])
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1488
      proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1489
        have "preced th'' s = preced th'' s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1490
          by (simp add:s_def preced_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1491
        moreover { 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1492
          fix th1
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1493
          assume th1_in: "th1 \<in> children s th''"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1494
          have "cp s th1 = cp s' th1"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1495
          proof(cases "th1 = thy")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1496
            case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1497
            with eq_cpy show ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1498
          next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1499
            case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1500
            have neq_th1: "th1 \<noteq> th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1501
            proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1502
              assume eq_th1: "th1 = th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1503
              with dp_thy have "(Th th1, Th thy) \<in> (RAG s)^+" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1504
              from children_no_dep[OF vt_s _ _ this] and 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1505
              th1_in y_ch eq_y show False by (auto simp:children_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1506
            qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1507
            have "th \<notin> dependants s th1"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1508
            proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1509
              assume h:"th \<in> dependants s th1"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1510
              from eq_y dp_thy have "th \<in> dependants s thy" by (auto simp:s_dependants_def eq_RAG)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1511
              from dependants_child_unique[OF vt_s _ _ h this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1512
              th1_in y_ch eq_y have "th1 = thy" by (auto simp:children_def child_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1513
              with False show False by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1514
            qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1515
            from eq_cp[OF this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1516
            show ?thesis .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1517
          qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1518
        }
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1519
        ultimately have "{preced th'' s} \<union> (cp s ` children s th'') = 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1520
          {preced th'' s'} \<union> (cp s' ` children s th'')" by (auto simp:image_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1521
        moreover have "children s th'' = children s' th''"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1522
          apply (unfold children_def child_def s_def RAG_set_unchanged, simp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1523
          apply (fold s_def, auto simp:RAG_s)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1524
          proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1525
            assume "(Cs cs, Th th'') \<in> RAG s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1526
            with RAG_s have cs_th': "(Cs cs, Th th'') \<in> RAG s" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1527
            from dp1 have "(Th th, Th th') \<in> (RAG s)^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1528
              by (auto simp:s_dependants_def eq_RAG)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1529
            from converse_tranclE[OF this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1530
            obtain cs1 where h1: "(Th th, Cs cs1) \<in> RAG s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1531
              and h2: "(Cs cs1 , Th th') \<in> (RAG s)\<^sup>+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1532
              by (auto simp:s_RAG_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1533
            have eq_cs: "cs1 = cs" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1534
            proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1535
              from RAG_s have "(Th th, Cs cs) \<in> RAG s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1536
              from unique_RAG[OF vt_s this h1]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1537
              show ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1538
            qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1539
            have False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1540
            proof(rule converse_tranclE[OF h2])
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1541
              assume "(Cs cs1, Th th') \<in> RAG s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1542
              with eq_cs have "(Cs cs, Th th') \<in> RAG s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1543
              from unique_RAG[OF vt_s this cs_th']
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1544
              have "th' = th''" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1545
              with ch' y_ch have "(Th th'', Th th'') \<in> (child s)^+" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1546
              with wf_trancl[OF wf_child[OF vt_s]] 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1547
              show False by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1548
            next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1549
              fix y
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1550
              assume "(Cs cs1, y) \<in> RAG s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1551
                and ytd: " (y, Th th') \<in> (RAG s)\<^sup>+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1552
              with eq_cs have csy: "(Cs cs, y) \<in> RAG s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1553
              from unique_RAG[OF vt_s this cs_th']
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1554
              have "y = Th th''" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1555
              with ytd have "(Th th'', Th th') \<in> (RAG s)^+" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1556
              from RAG_child[OF vt_s this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1557
              have "(Th th'', Th th') \<in> (child s)\<^sup>+" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1558
              moreover from ch' y_ch have ch'': "(Th th', Th th'') \<in> (child s)^+" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1559
              ultimately have "(Th th'', Th th'') \<in> (child s)^+" by auto 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1560
              with wf_trancl[OF wf_child[OF vt_s]] 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1561
              show False by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1562
            qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1563
            thus "\<exists>cs. (Th th, Cs cs) \<in> RAG s' \<and> (Cs cs, Th th'') \<in> RAG s'" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1564
          qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1565
          ultimately show "Max ({preced th'' s} \<union> cp s ` children s th'') = cp s' th''"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1566
          by (simp add:cp_rec[OF step_back_vt[OF vt_s[unfolded s_def]]])
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1567
      qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1568
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1569
      fix th''
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1570
      assume dp': "(Th th', Th th'') \<in> child s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1571
      show "cp s th'' = cp s' th''"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1572
        apply (subst cp_rec[OF vt_s])
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1573
      proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1574
        have "preced th'' s = preced th'' s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1575
          by (simp add:s_def preced_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1576
        moreover { 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1577
          fix th1
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1578
          assume th1_in: "th1 \<in> children s th''"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1579
          have "cp s th1 = cp s' th1"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1580
          proof(cases "th1 = th'")
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1581
            case True
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1582
            with eq_cps show ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1583
          next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1584
            case False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1585
            have neq_th1: "th1 \<noteq> th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1586
            proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1587
              assume eq_th1: "th1 = th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1588
              with dp1 have "(Th th1, Th th') \<in> (RAG s)^+" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1589
                by (auto simp:s_dependants_def eq_RAG)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1590
              from children_no_dep[OF vt_s _ _ this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1591
              th1_in dp'
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1592
              show False by (auto simp:children_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1593
            qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1594
            show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1595
            proof(rule eq_cp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1596
              show "th \<notin> dependants s th1"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1597
              proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1598
                assume "th \<in> dependants s th1"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1599
                from dependants_child_unique[OF vt_s _ _ this dp1]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1600
                th1_in dp' have "th1 = th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1601
                  by (auto simp:children_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1602
                with False show False by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1603
              qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1604
            qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1605
          qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1606
        }
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1607
        ultimately have "{preced th'' s} \<union> (cp s ` children s th'') = 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1608
          {preced th'' s'} \<union> (cp s' ` children s th'')" by (auto simp:image_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1609
        moreover have "children s th'' = children s' th''"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1610
          apply (unfold children_def child_def s_def RAG_set_unchanged, simp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1611
          apply (fold s_def, auto simp:RAG_s)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1612
          proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1613
            assume "(Cs cs, Th th'') \<in> RAG s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1614
            with RAG_s have cs_th': "(Cs cs, Th th'') \<in> RAG s" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1615
            from dp1 have "(Th th, Th th') \<in> (RAG s)^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1616
              by (auto simp:s_dependants_def eq_RAG)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1617
            from converse_tranclE[OF this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1618
            obtain cs1 where h1: "(Th th, Cs cs1) \<in> RAG s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1619
              and h2: "(Cs cs1 , Th th') \<in> (RAG s)\<^sup>+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1620
              by (auto simp:s_RAG_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1621
            have eq_cs: "cs1 = cs" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1622
            proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1623
              from RAG_s have "(Th th, Cs cs) \<in> RAG s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1624
              from unique_RAG[OF vt_s this h1]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1625
              show ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1626
            qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1627
            have False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1628
            proof(rule converse_tranclE[OF h2])
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1629
              assume "(Cs cs1, Th th') \<in> RAG s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1630
              with eq_cs have "(Cs cs, Th th') \<in> RAG s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1631
              from unique_RAG[OF vt_s this cs_th']
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1632
              have "th' = th''" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1633
              with dp' have "(Th th'', Th th'') \<in> (child s)^+" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1634
              with wf_trancl[OF wf_child[OF vt_s]] 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1635
              show False by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1636
            next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1637
              fix y
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1638
              assume "(Cs cs1, y) \<in> RAG s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1639
                and ytd: " (y, Th th') \<in> (RAG s)\<^sup>+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1640
              with eq_cs have csy: "(Cs cs, y) \<in> RAG s" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1641
              from unique_RAG[OF vt_s this cs_th']
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1642
              have "y = Th th''" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1643
              with ytd have "(Th th'', Th th') \<in> (RAG s)^+" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1644
              from RAG_child[OF vt_s this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1645
              have "(Th th'', Th th') \<in> (child s)\<^sup>+" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1646
              moreover from dp' have ch'': "(Th th', Th th'') \<in> (child s)^+" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1647
              ultimately have "(Th th'', Th th'') \<in> (child s)^+" by auto 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1648
              with wf_trancl[OF wf_child[OF vt_s]] 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1649
              show False by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1650
            qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1651
            thus "\<exists>cs. (Th th, Cs cs) \<in> RAG s' \<and> (Cs cs, Th th'') \<in> RAG s'" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1652
          qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1653
        ultimately show "Max ({preced th'' s} \<union> cp s ` children s th'') = cp s' th''"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1654
          by (simp add:cp_rec[OF step_back_vt[OF vt_s[unfolded s_def]]])
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1655
      qed     
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1656
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1657
  }
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1658
  ultimately show ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1659
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1660
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1661
end
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1662
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1663
locale step_create_cps =
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1664
  fixes s' th prio s 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1665
  defines s_def : "s \<equiv> (Create th prio#s')"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1666
  assumes vt_s: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1667
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1668
context step_create_cps
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1669
begin
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1670
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1671
lemma eq_dep: "RAG s = RAG s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1672
  by (unfold s_def RAG_create_unchanged, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1673
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1674
lemma eq_cp:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1675
  fixes th' 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1676
  assumes neq_th: "th' \<noteq> th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1677
  shows "cp s th' = cp s' th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1678
  apply (unfold cp_eq_cpreced cpreced_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1679
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1680
  have nd: "th \<notin> dependants s th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1681
  proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1682
    assume "th \<in> dependants s th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1683
    hence "(Th th, Th th') \<in> (RAG s)^+" by (simp add:s_dependants_def eq_RAG)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1684
    with eq_dep have "(Th th, Th th') \<in> (RAG s')^+" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1685
    from converse_tranclE[OF this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1686
    obtain y where "(Th th, y) \<in> RAG s'" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1687
    with dm_RAG_threads[OF step_back_vt[OF vt_s[unfolded s_def]]]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1688
    have in_th: "th \<in> threads s'" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1689
    from step_back_step[OF vt_s[unfolded s_def]]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1690
    show False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1691
    proof(cases)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1692
      assume "th \<notin> threads s'" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1693
      with in_th show ?thesis by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1694
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1695
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1696
  have eq_dp: "\<And> th. dependants (wq s) th = dependants (wq s') th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1697
    by (unfold cs_dependants_def, auto simp:eq_dep eq_RAG)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1698
  moreover {
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1699
    fix th1 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1700
    assume "th1 \<in> {th'} \<union> dependants (wq s') th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1701
    hence "th1 = th' \<or> th1 \<in> dependants (wq s') th'" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1702
    hence "preced th1 s = preced th1 s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1703
    proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1704
      assume "th1 = th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1705
      with neq_th
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1706
      show "preced th1 s = preced th1 s'" by (auto simp:s_def preced_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1707
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1708
      assume "th1 \<in> dependants (wq s') th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1709
      with nd and eq_dp have "th1 \<noteq> th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1710
        by (auto simp:eq_RAG cs_dependants_def s_dependants_def eq_dep)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1711
      thus "preced th1 s = preced th1 s'" by (auto simp:s_def preced_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1712
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1713
  } ultimately have "((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')) = 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1714
                     ((\<lambda>th. preced th s') ` ({th'} \<union> dependants (wq s') th'))" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1715
    by (auto simp:image_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1716
  thus "Max ((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')) =
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1717
        Max ((\<lambda>th. preced th s') ` ({th'} \<union> dependants (wq s') th'))" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1718
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1719
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1720
lemma nil_dependants: "dependants s th = {}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1721
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1722
  from step_back_step[OF vt_s[unfolded s_def]]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1723
  show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1724
  proof(cases)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1725
    assume "th \<notin> threads s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1726
    from not_thread_holdents[OF step_back_vt[OF vt_s[unfolded s_def]] this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1727
    have hdn: " holdents s' th = {}" .
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1728
    have "dependants s' th = {}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1729
    proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1730
      { assume "dependants s' th \<noteq> {}"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1731
        then obtain th' where dp: "(Th th', Th th) \<in> (RAG s')^+"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1732
          by (auto simp:s_dependants_def eq_RAG)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1733
        from tranclE[OF this] obtain cs' where 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1734
          "(Cs cs', Th th) \<in> RAG s'" by (auto simp:s_RAG_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1735
        with hdn
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1736
        have False by (auto simp:holdents_test)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1737
      } thus ?thesis by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1738
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1739
    thus ?thesis 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1740
      by (unfold s_def s_dependants_def eq_RAG RAG_create_unchanged, simp)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1741
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1742
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1743
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1744
lemma eq_cp_th: "cp s th = preced th s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1745
  apply (unfold cp_eq_cpreced cpreced_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1746
  by (insert nil_dependants, unfold s_dependants_def cs_dependants_def, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1747
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1748
end
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1749
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1750
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1751
locale step_exit_cps =
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1752
  fixes s' th prio s 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1753
  defines s_def : "s \<equiv> Exit th # s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1754
  assumes vt_s: "vt s"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1755
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1756
context step_exit_cps
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1757
begin
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1758
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1759
lemma eq_dep: "RAG s = RAG s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1760
  by (unfold s_def RAG_exit_unchanged, auto)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1761
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1762
lemma eq_cp:
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1763
  fixes th' 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1764
  assumes neq_th: "th' \<noteq> th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1765
  shows "cp s th' = cp s' th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1766
  apply (unfold cp_eq_cpreced cpreced_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1767
proof -
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1768
  have nd: "th \<notin> dependants s th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1769
  proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1770
    assume "th \<in> dependants s th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1771
    hence "(Th th, Th th') \<in> (RAG s)^+" by (simp add:s_dependants_def eq_RAG)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1772
    with eq_dep have "(Th th, Th th') \<in> (RAG s')^+" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1773
    from converse_tranclE[OF this]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1774
    obtain cs' where bk: "(Th th, Cs cs') \<in> RAG s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1775
      by (auto simp:s_RAG_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1776
    from step_back_step[OF vt_s[unfolded s_def]]
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1777
    show False
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1778
    proof(cases)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1779
      assume "th \<in> runing s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1780
      with bk show ?thesis
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1781
        apply (unfold runing_def readys_def s_waiting_def s_RAG_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1782
        by (auto simp:cs_waiting_def wq_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1783
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1784
  qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1785
  have eq_dp: "\<And> th. dependants (wq s) th = dependants (wq s') th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1786
    by (unfold cs_dependants_def, auto simp:eq_dep eq_RAG)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1787
  moreover {
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1788
    fix th1 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1789
    assume "th1 \<in> {th'} \<union> dependants (wq s') th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1790
    hence "th1 = th' \<or> th1 \<in> dependants (wq s') th'" by auto
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1791
    hence "preced th1 s = preced th1 s'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1792
    proof
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1793
      assume "th1 = th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1794
      with neq_th
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1795
      show "preced th1 s = preced th1 s'" by (auto simp:s_def preced_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1796
    next
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1797
      assume "th1 \<in> dependants (wq s') th'"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1798
      with nd and eq_dp have "th1 \<noteq> th"
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1799
        by (auto simp:eq_RAG cs_dependants_def s_dependants_def eq_dep)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1800
      thus "preced th1 s = preced th1 s'" by (auto simp:s_def preced_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1801
    qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1802
  } ultimately have "((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')) = 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1803
                     ((\<lambda>th. preced th s') ` ({th'} \<union> dependants (wq s') th'))" 
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1804
    by (auto simp:image_def)
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1805
  thus "Max ((\<lambda>th. preced th s) ` ({th'} \<union> dependants (wq s) th')) =
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1806
        Max ((\<lambda>th. preced th s') ` ({th'} \<union> dependants (wq s') th'))" by simp
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1807
qed
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1808
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1809
end
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1810
end
f1b39d77db00 Added generic theory "RTree.thy"
xingyuan zhang <xingyuanzhang@126.com>
parents:
diff changeset
  1811