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