src/HOL/MicroJava/BV/Kildall.thy
author kleing
Sun, 24 Mar 2002 14:05:53 +0100
changeset 13065 d6585b32412b
parent 13062 4b1edf2f6bd2
child 13066 b57d926d1de2
permissions -rw-r--r--
more about match_exception_table
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
     1
(*  Title:      HOL/MicroJava/BV/Kildall.thy
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
     2
    ID:         $Id$
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
     3
    Author:     Tobias Nipkow, Gerwin Klein
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
     4
    Copyright   2000 TUM
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
     5
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
     6
Kildall's algorithm
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
     7
*)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
     8
12911
704713ca07ea new document
kleing
parents: 12516
diff changeset
     9
header {* \isaheader{Kildall's Algorithm}\label{sec:Kildall} *}
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    10
13062
4b1edf2f6bd2 small refactoring for lbv with semilattices
kleing
parents: 13006
diff changeset
    11
theory Kildall = SemilatAlg + While_Combinator:
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    12
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    13
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    14
consts
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    15
 iter :: "'s binop \<Rightarrow> 's step_type \<Rightarrow>
11298
acd83fa66e92 simplified defs and proofs a little
nipkow
parents: 11229
diff changeset
    16
          's list \<Rightarrow> nat set \<Rightarrow> 's list \<times> nat set"
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    17
 propa :: "'s binop \<Rightarrow> (nat \<times> 's) list \<Rightarrow> 's list \<Rightarrow> nat set \<Rightarrow> 's list * nat set"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    18
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    19
primrec
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    20
"propa f []      ss w = (ss,w)"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    21
"propa f (q'#qs) ss w = (let (q,t) = q';
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    22
                             u = t +_f ss!q;
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    23
                             w' = (if u = ss!q then w else insert q w)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    24
                         in propa f qs (ss[q := u]) w')"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    25
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
    26
defs iter_def:
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    27
"iter f step ss w ==
11298
acd83fa66e92 simplified defs and proofs a little
nipkow
parents: 11229
diff changeset
    28
 while (%(ss,w). w \<noteq> {})
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    29
       (%(ss,w). let p = SOME p. p \<in> w
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    30
                 in propa f (step p (ss!p)) ss (w-{p}))
11298
acd83fa66e92 simplified defs and proofs a little
nipkow
parents: 11229
diff changeset
    31
       (ss,w)"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    32
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    33
constdefs
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    34
 unstables :: "'s ord \<Rightarrow> 's step_type \<Rightarrow> 's list \<Rightarrow> nat set"
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    35
"unstables r step ss == {p. p < size ss \<and> \<not>stable r step ss p}"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    36
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    37
 kildall :: "'s ord \<Rightarrow> 's binop \<Rightarrow> 's step_type \<Rightarrow> 's list \<Rightarrow> 's list"
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    38
"kildall r f step ss == fst(iter f step ss (unstables r step ss))"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    39
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    40
consts merges :: "'s binop \<Rightarrow> (nat \<times> 's) list \<Rightarrow> 's list \<Rightarrow> 's list"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    41
primrec
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    42
"merges f []      ss = ss"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    43
"merges f (p'#ps) ss = (let (p,s) = p' in merges f ps (ss[p := s +_f ss!p]))"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    44
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    45
10774
4de3a0d3ae28 recdef_tc;
wenzelm
parents: 10661
diff changeset
    46
lemmas [simp] = Let_def le_iff_plus_unchanged [symmetric]
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    47
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    48
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    49
lemma nth_merges:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    50
  "\<And>ss. \<lbrakk> semilat (A, r, f); p < length ss; ss \<in> list n A; 
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    51
            \<forall>(p,t)\<in>set ps. p<n \<and> t\<in>A \<rbrakk> \<Longrightarrow>
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    52
  (merges f ps ss)!p = map snd [(p',t') \<in> ps. p'=p] ++_f ss!p"
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    53
  (is "\<And>ss. _ \<Longrightarrow> _ \<Longrightarrow> _ \<Longrightarrow> ?steptype ps \<Longrightarrow> ?P ss ps")
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    54
proof (induct ps)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    55
  show "\<And>ss. ?P ss []" by simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    56
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    57
  fix ss p' ps'
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    58
  assume sl: "semilat (A, r, f)"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    59
  assume ss: "ss \<in> list n A"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    60
  assume l:  "p < length ss"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    61
  assume "?steptype (p'#ps')"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    62
  then obtain a b where
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    63
    p': "p'=(a,b)" and ab: "a<n" "b\<in>A" and "?steptype ps'"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    64
    by (cases p', auto)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    65
  assume "\<And>ss. semilat (A,r,f) \<Longrightarrow> p < length ss \<Longrightarrow> ss \<in> list n A \<Longrightarrow> ?steptype ps' \<Longrightarrow> ?P ss ps'"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    66
  hence IH: "\<And>ss. ss \<in> list n A \<Longrightarrow> p < length ss \<Longrightarrow> ?P ss ps'" .
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    67
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    68
  from sl ss ab
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    69
  have "ss[a := b +_f ss!a] \<in> list n A" by (simp add: closedD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    70
  moreover
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    71
  from calculation
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    72
  have "p < length (ss[a := b +_f ss!a])" by simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    73
  ultimately
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    74
  have "?P (ss[a := b +_f ss!a]) ps'" by (rule IH)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    75
  with p' l 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    76
  show "?P ss (p'#ps')" by simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    77
qed
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    78
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    79
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    80
(** merges **)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    81
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    82
lemma length_merges [rule_format, simp]:
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    83
  "\<forall>ss. size(merges f ps ss) = size ss"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    84
  by (induct_tac ps, auto)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    85
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    86
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    87
lemma merges_preserves_type_lemma: 
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    88
  "semilat(A,r,f) \<Longrightarrow>
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    89
     \<forall>xs. xs \<in> list n A \<longrightarrow> (\<forall>(p,x) \<in> set ps. p<n \<and> x\<in>A)
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    90
          \<longrightarrow> merges f ps xs \<in> list n A" 
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    91
  apply (frule semilatDclosedI) 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    92
  apply (unfold closed_def) 
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    93
  apply (induct_tac ps)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    94
   apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    95
  apply clarsimp
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    96
  done
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    97
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    98
lemma merges_preserves_type [simp]:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    99
  "\<lbrakk> semilat(A,r,f); xs \<in> list n A; \<forall>(p,x) \<in> set ps. p<n \<and> x\<in>A \<rbrakk>
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   100
  \<Longrightarrow> merges f ps xs \<in> list n A"
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   101
  by (simp add: merges_preserves_type_lemma)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   102
  
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   103
lemma merges_incr_lemma:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   104
  "semilat(A,r,f) \<Longrightarrow> 
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   105
     \<forall>xs. xs \<in> list n A \<longrightarrow> (\<forall>(p,x)\<in>set ps. p<size xs \<and> x \<in> A) \<longrightarrow> xs <=[r] merges f ps xs"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   106
  apply (induct_tac ps)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   107
   apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   108
  apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   109
  apply clarify
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   110
  apply (rule order_trans)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   111
    apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   112
   apply (erule list_update_incr)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   113
     apply assumption
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   114
    apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   115
   apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   116
  apply (blast intro!: listE_set intro: closedD listE_length [THEN nth_in])
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   117
  done
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   118
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   119
lemma merges_incr:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   120
  "\<lbrakk> semilat(A,r,f); xs \<in> list n A; \<forall>(p,x)\<in>set ps. p<size xs \<and> x \<in> A \<rbrakk> 
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   121
  \<Longrightarrow> xs <=[r] merges f ps xs"
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   122
  by (simp add: merges_incr_lemma)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   123
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   124
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   125
lemma merges_same_conv [rule_format]:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   126
  "semilat(A,r,f) \<Longrightarrow> 
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   127
     (\<forall>xs. xs \<in> list n A \<longrightarrow> (\<forall>(p,x)\<in>set ps. p<size xs \<and> x\<in>A) \<longrightarrow> 
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   128
     (merges f ps xs = xs) = (\<forall>(p,x)\<in>set ps. x <=_r xs!p))"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   129
  apply (induct_tac ps)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   130
   apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   131
  apply clarsimp
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   132
  apply (rename_tac p x ps xs)
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   133
  apply (rule iffI)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   134
   apply (rule context_conjI)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   135
    apply (subgoal_tac "xs[p := x +_f xs!p] <=[r] xs")
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   136
     apply (force dest!: le_listD simp add: nth_list_update)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   137
    apply (erule subst, rule merges_incr)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   138
        apply assumption
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   139
       apply (blast intro!: listE_set intro: closedD listE_length [THEN nth_in])
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   140
      apply clarify
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   141
      apply (rule conjI)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   142
       apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   143
       apply (blast dest: boundedD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   144
      apply blast
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   145
   apply clarify
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   146
   apply (rotate_tac -2)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   147
   apply (erule allE)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   148
   apply (erule impE)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   149
    apply assumption
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   150
   apply (erule impE)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   151
    apply assumption
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   152
   apply (drule bspec)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   153
    apply assumption
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   154
   apply (simp add: le_iff_plus_unchanged [THEN iffD1] list_update_same_conv [THEN iffD2])
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   155
   apply blast
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   156
  apply clarify 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   157
  apply (simp add: le_iff_plus_unchanged [THEN iffD1] list_update_same_conv [THEN iffD2])
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   158
  done
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   159
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   160
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   161
lemma list_update_le_listI [rule_format]:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   162
  "set xs <= A \<longrightarrow> set ys <= A \<longrightarrow> xs <=[r] ys \<longrightarrow> p < size xs \<longrightarrow>  
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   163
   x <=_r ys!p \<longrightarrow> semilat(A,r,f) \<longrightarrow> x\<in>A \<longrightarrow> 
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   164
   xs[p := x +_f xs!p] <=[r] ys"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   165
  apply (unfold Listn.le_def lesub_def semilat_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   166
  apply (simp add: list_all2_conv_all_nth nth_list_update)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   167
  done
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   168
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   169
lemma merges_pres_le_ub:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   170
  "\<lbrakk> semilat(A,r,f); set ts <= A; set ss <= A; 
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   171
     \<forall>(p,t)\<in>set ps. t <=_r ts!p \<and> t \<in> A \<and> p < size ts; 
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   172
     ss <=[r] ts \<rbrakk> 
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   173
  \<Longrightarrow> merges f ps ss <=[r] ts"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   174
proof -
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   175
  { fix A r f t ts ps
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   176
    have
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   177
    "\<And>qs. \<lbrakk> semilat(A,r,f); set ts <= A; 
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   178
              \<forall>(p,t)\<in>set ps. t <=_r ts!p \<and> t \<in> A \<and> p < size ts \<rbrakk> \<Longrightarrow> 
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   179
    set qs <= set ps  \<longrightarrow> 
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   180
    (\<forall>ss. set ss <= A \<longrightarrow> ss <=[r] ts \<longrightarrow> merges f qs ss <=[r] ts)"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   181
    apply (induct_tac qs)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   182
     apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   183
    apply (simp (no_asm_simp))
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   184
    apply clarify
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   185
    apply (rotate_tac -2)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   186
    apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   187
    apply (erule allE, erule impE, erule_tac [2] mp)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   188
     apply (drule bspec, assumption)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   189
     apply (simp add: closedD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   190
    apply (drule bspec, assumption)
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   191
    apply (simp add: list_update_le_listI)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   192
    done 
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   193
  } note this [dest]
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   194
  
11549
e7265e70fd7c renamed "antecedent" case to "rule_context";
wenzelm
parents: 11299
diff changeset
   195
  case rule_context
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   196
  thus ?thesis by blast
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   197
qed
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   198
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   199
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   200
(** propa **)
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   201
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   202
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   203
lemma decomp_propa:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   204
  "\<And>ss w. (\<forall>(q,t)\<in>set qs. q < size ss) \<Longrightarrow> 
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   205
   propa f qs ss w = 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   206
   (merges f qs ss, {q. \<exists>t. (q,t)\<in>set qs \<and> t +_f ss!q \<noteq> ss!q} Un w)"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   207
  apply (induct qs)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   208
   apply simp   
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   209
  apply (simp (no_asm))
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   210
  apply clarify  
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   211
  apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   212
  apply (rule conjI) 
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   213
   apply (simp add: nth_list_update)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   214
   apply blast
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   215
  apply (simp add: nth_list_update)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   216
  apply blast
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   217
  done 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   218
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   219
(** iter **)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   220
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   221
lemma stable_pres_lemma:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   222
  "\<lbrakk> semilat (A,r,f); pres_type step n A; bounded step n; 
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   223
     ss \<in> list n A; p \<in> w; \<forall>q\<in>w. q < n; 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   224
     \<forall>q. q < n \<longrightarrow> q \<notin> w \<longrightarrow> stable r step ss q; q < n; 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   225
     \<forall>s'. (q,s') \<in> set (step p (ss ! p)) \<longrightarrow> s' +_f ss ! q = ss ! q; 
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   226
     q \<notin> w \<or> q = p \<rbrakk> 
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   227
  \<Longrightarrow> stable r step (merges f (step p (ss!p)) ss) q"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   228
  apply (unfold stable_def)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   229
  apply (subgoal_tac "\<forall>s'. (q,s') \<in> set (step p (ss!p)) \<longrightarrow> s' : A")
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   230
   prefer 2
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   231
   apply clarify
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   232
   apply (erule pres_typeD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   233
    prefer 3 apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   234
    apply (rule listE_nth_in)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   235
     apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   236
    apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   237
   apply simp
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   238
  apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   239
  apply clarify
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   240
  apply (subst nth_merges) 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   241
        apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   242
       apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   243
       apply (blast dest: boundedD)
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   244
      apply assumption
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   245
     apply clarify
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   246
     apply (rule conjI)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   247
      apply (blast dest: boundedD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   248
     apply (erule pres_typeD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   249
       prefer 3 apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   250
      apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   251
     apply simp 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   252
  apply (frule nth_merges [of _ _ _ q _ _ "step p (ss!p)"]) (* fixme: why does method subst not work?? *)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   253
    prefer 2 apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   254
   apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   255
  apply clarify
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   256
  apply (rule conjI)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   257
   apply (blast dest: boundedD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   258
  apply (erule pres_typeD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   259
     prefer 3 apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   260
    apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   261
   apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   262
  apply (drule_tac P = "\<lambda>x. (a, b) \<in> set (step q x)" in subst)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   263
   apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   264
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   265
 apply (simp add: plusplus_empty)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   266
 apply (cases "q \<in> w")
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   267
  apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   268
  apply (rule ub1')
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   269
     apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   270
    apply clarify
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   271
    apply (rule pres_typeD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   272
       apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   273
      prefer 3 apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   274
     apply (blast intro: listE_nth_in dest: boundedD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   275
    apply (blast intro: pres_typeD dest: boundedD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   276
   apply (blast intro: listE_nth_in dest: boundedD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   277
  apply assumption
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   278
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   279
 apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   280
 apply (erule allE, erule impE, assumption, erule impE, assumption)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   281
 apply (rule order_trans)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   282
   apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   283
  defer
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   284
 apply (rule ub2)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   285
    apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   286
   apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   287
   apply clarify
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   288
   apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   289
   apply (rule pres_typeD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   290
      apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   291
     prefer 3 apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   292
    apply (blast intro: listE_nth_in dest: boundedD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   293
   apply (blast intro: pres_typeD dest: boundedD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   294
  apply (blast intro: listE_nth_in dest: boundedD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   295
 apply blast
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   296
 done
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   297
 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   298
  
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   299
lemma merges_bounded_lemma:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   300
  "\<lbrakk> semilat (A,r,f); mono r step n A; bounded step n; 
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   301
     \<forall>(p',s') \<in> set (step p (ss!p)). s' \<in> A; ss \<in> list n A; ts \<in> list n A; p < n; 
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   302
     ss <=[r] ts; ! p. p < n \<longrightarrow> stable r step ts p \<rbrakk> 
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   303
  \<Longrightarrow> merges f (step p (ss!p)) ss <=[r] ts"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   304
  apply (unfold stable_def)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   305
  apply (rule merges_pres_le_ub)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   306
      apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   307
     apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   308
    apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   309
   prefer 2 apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   310
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   311
  apply clarsimp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   312
  apply (drule boundedD, assumption+)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   313
  apply (erule allE, erule impE, assumption)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   314
  apply (drule bspec, assumption)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   315
  apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   316
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   317
  apply (drule monoD [of _ _ _ _ p "ss!p"  "ts!p"])
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   318
     apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   319
    apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   320
   apply (simp add: le_listD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   321
  
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   322
  apply (drule lesub_step_type, assumption) 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   323
  apply clarify
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   324
  apply (drule bspec, assumption)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   325
  apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   326
  apply (blast intro: order_trans)
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   327
  done
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   328
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   329
lemma termination_lemma:  
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   330
  "\<lbrakk> semilat(A,r,f); ss \<in> list n A; \<forall>(q,t)\<in>set qs. q<n \<and> t\<in>A; p\<in>w \<rbrakk> \<Longrightarrow> 
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   331
      ss <[r] merges f qs ss \<or> 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   332
  merges f qs ss = ss \<and> {q. \<exists>t. (q,t)\<in>set qs \<and> t +_f ss!q \<noteq> ss!q} Un (w-{p}) < w"
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   333
  apply (unfold lesssub_def)
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   334
  apply (simp (no_asm_simp) add: merges_incr)
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   335
  apply (rule impI)
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   336
  apply (rule merges_same_conv [THEN iffD1, elim_format]) 
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   337
  apply assumption+
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   338
    defer
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   339
    apply (rule sym, assumption)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   340
   defer apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   341
   apply (subgoal_tac "\<forall>q t. \<not>((q, t) \<in> set qs \<and> t +_f ss ! q \<noteq> ss ! q)")
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   342
   apply (blast intro!: psubsetI elim: equalityE)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   343
   apply clarsimp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   344
   apply (drule bspec, assumption) 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   345
   apply (drule bspec, assumption)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   346
   apply clarsimp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   347
  done 
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   348
11298
acd83fa66e92 simplified defs and proofs a little
nipkow
parents: 11229
diff changeset
   349
lemma iter_properties[rule_format]:
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   350
  "\<lbrakk> semilat(A,r,f); acc r ; pres_type step n A; mono r step n A;
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   351
     bounded step n; \<forall>p\<in>w0. p < n; ss0 \<in> list n A;
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   352
     \<forall>p<n. p \<notin> w0 \<longrightarrow> stable r step ss0 p \<rbrakk> \<Longrightarrow>
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   353
   iter f step ss0 w0 = (ss',w')
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   354
   \<longrightarrow>
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   355
   ss' \<in> list n A \<and> stables r step ss' \<and> ss0 <=[r] ss' \<and>
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   356
   (\<forall>ts\<in>list n A. ss0 <=[r] ts \<and> stables r step ts \<longrightarrow> ss' <=[r] ts)"
11298
acd83fa66e92 simplified defs and proofs a little
nipkow
parents: 11229
diff changeset
   357
apply (unfold iter_def stables_def)
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   358
apply (rule_tac P = "%(ss,w).
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   359
 ss \<in> list n A \<and> (\<forall>p<n. p \<notin> w \<longrightarrow> stable r step ss p) \<and> ss0 <=[r] ss \<and>
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   360
 (\<forall>ts\<in>list n A. ss0 <=[r] ts \<and> stables r step ts \<longrightarrow> ss <=[r] ts) \<and>
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   361
 (\<forall>p\<in>w. p < n)" and
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   362
 r = "{(ss',ss) . ss <[r] ss'} <*lex*> finite_psubset"
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   363
       in while_rule)
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   364
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   365
-- "Invariant holds initially:"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   366
apply (simp add:stables_def) 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   367
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   368
-- "Invariant is preserved:"
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   369
apply(simp add: stables_def split_paired_all)
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   370
apply(rename_tac ss w)
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   371
apply(subgoal_tac "(SOME p. p \<in> w) \<in> w")
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   372
 prefer 2; apply (fast intro: someI)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   373
apply(subgoal_tac "\<forall>(q,t) \<in> set (step (SOME p. p \<in> w) (ss ! (SOME p. p \<in> w))). q < length ss \<and> t \<in> A")
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   374
 prefer 2
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   375
 apply clarify
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   376
 apply (rule conjI)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   377
  apply(clarsimp, blast dest!: boundedD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   378
 apply (erule pres_typeD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   379
  prefer 3
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   380
  apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   381
  apply (erule listE_nth_in)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   382
  apply blast
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   383
 apply blast
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   384
apply (subst decomp_propa)
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   385
 apply blast
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   386
apply simp
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   387
apply (rule conjI)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   388
 apply (erule merges_preserves_type)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   389
 apply blast 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   390
 apply clarify
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   391
 apply (rule conjI)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   392
  apply(clarsimp, blast dest!: boundedD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   393
 apply (erule pres_typeD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   394
  prefer 3
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   395
  apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   396
  apply (erule listE_nth_in)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   397
  apply blast
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   398
 apply blast
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   399
apply (rule conjI) 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   400
 apply clarify 
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   401
 apply (blast intro!: stable_pres_lemma)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   402
apply (rule conjI) 
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   403
 apply (blast intro!: merges_incr intro: le_list_trans)
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   404
apply (rule conjI)
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   405
 apply clarsimp
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   406
 apply (blast intro!: merges_bounded_lemma)
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   407
apply (blast dest!: boundedD)
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   408
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   409
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   410
-- "Postcondition holds upon termination:"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   411
apply(clarsimp simp add: stables_def split_paired_all) 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   412
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   413
-- "Well-foundedness of the termination relation:"
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   414
apply (rule wf_lex_prod)
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   415
 apply (drule (1) semilatDorderI [THEN acc_le_listI])
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   416
 apply (simp only: acc_def lesssub_def)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   417
apply (rule wf_finite_psubset) 
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   418
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   419
-- "Loop decreases along termination relation:"
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   420
apply(simp add: stables_def split_paired_all)
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   421
apply(rename_tac ss w)
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   422
apply(subgoal_tac "(SOME p. p \<in> w) \<in> w")
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   423
 prefer 2; apply (fast intro: someI)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   424
apply(subgoal_tac "\<forall>(q,t) \<in> set (step (SOME p. p \<in> w) (ss ! (SOME p. p \<in> w))). q < length ss \<and> t \<in> A")
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   425
 prefer 2
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   426
 apply clarify
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   427
 apply (rule conjI)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   428
  apply(clarsimp, blast dest!: boundedD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   429
 apply (erule pres_typeD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   430
  prefer 3
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   431
  apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   432
  apply (erule listE_nth_in)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   433
  apply blast
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   434
 apply blast
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   435
apply (subst decomp_propa)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   436
 apply blast
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   437
apply clarify 
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   438
apply (simp del: listE_length
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   439
    add: lex_prod_def finite_psubset_def 
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   440
         bounded_nat_set_is_finite)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   441
apply (rule termination_lemma)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   442
apply assumption+
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   443
defer
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   444
apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   445
apply clarsimp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   446
apply (blast dest!: boundedD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   447
done   
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   448
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   449
11229
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   450
lemma kildall_properties:
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   451
  "\<lbrakk> semilat(A,r,f); acc r; pres_type step n A; mono r step n A;
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   452
     bounded step n; ss0 \<in> list n A \<rbrakk> \<Longrightarrow>
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   453
  kildall r f step ss0 \<in> list n A \<and>
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   454
  stables r step (kildall r f step ss0) \<and>
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   455
  ss0 <=[r] kildall r f step ss0 \<and>
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   456
  (\<forall>ts\<in>list n A. ss0 <=[r] ts \<and> stables r step ts \<longrightarrow>
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   457
                 kildall r f step ss0 <=[r] ts)"
11229
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   458
apply (unfold kildall_def)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   459
apply(case_tac "iter f step ss0 (unstables r step ss0)")
11298
acd83fa66e92 simplified defs and proofs a little
nipkow
parents: 11229
diff changeset
   460
apply(simp)
11229
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   461
apply (rule iter_properties)
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   462
apply (simp_all add: unstables_def stable_def)
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   463
done
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   464
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   465
lemma is_bcv_kildall:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   466
  "\<lbrakk> semilat(A,r,f); acc r; top r T; 
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   467
      pres_type step n A; bounded step n; 
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   468
      mono r step n A \<rbrakk>
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   469
  \<Longrightarrow> is_bcv r T step n A (kildall r f step)"
11299
1d3d110c456e welltyping -> wt_step
nipkow
parents: 11298
diff changeset
   470
apply(unfold is_bcv_def wt_step_def)
11229
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   471
apply(insert kildall_properties[of A])
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   472
apply(simp add:stables_def)
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   473
apply clarify
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   474
apply(subgoal_tac "kildall r f step ss \<in> list n A")
11229
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   475
 prefer 2 apply (simp(no_asm_simp))
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   476
apply (rule iffI)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   477
 apply (rule_tac x = "kildall r f step ss" in bexI) 
11229
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   478
  apply (rule conjI)
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   479
   apply blast
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   480
  apply (simp  (no_asm_simp))
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   481
 apply assumption
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   482
apply clarify
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   483
apply(subgoal_tac "kildall r f step ss!p <=_r ts!p")
11229
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   484
 apply simp
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   485
apply (blast intro!: le_listD less_lengthI)
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   486
done
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   487
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   488
end