src/HOL/MicroJava/BV/Kildall.thy
author kleing
Sun, 03 Mar 2002 16:59:08 +0100
changeset 13006 51c5f3f11d16
parent 12911 704713ca07ea
child 13062 4b1edf2f6bd2
permissions -rw-r--r--
symbolized
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
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    11
theory Kildall = Typing_Framework + While_Combinator + Product:
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    12
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    13
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    14
syntax "@lesubstep_type" :: "(nat \<times> 's) list \<Rightarrow> 's ord \<Rightarrow> (nat \<times> 's) list \<Rightarrow> bool"
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    15
       ("(_ /<=|_| _)" [50, 0, 51] 50)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    16
translations
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    17
 "x <=|r| y" == "x <=[(Product.le (op =) r)] y"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    18
 
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    19
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    20
constdefs
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    21
 pres_type :: "'s step_type \<Rightarrow> nat \<Rightarrow> 's set \<Rightarrow> bool"
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    22
"pres_type step n A == \<forall>s\<in>A. \<forall>p<n. \<forall>(q,s')\<in>set (step p s). s' \<in> A"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    23
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    24
 mono :: "'s ord \<Rightarrow> 's step_type \<Rightarrow> nat \<Rightarrow> 's set \<Rightarrow> bool"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    25
"mono r step n A ==
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    26
 \<forall>s p t. s \<in> A \<and> p < n \<and> s <=_r t \<longrightarrow> step p s <=|r| step p t"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    27
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    28
consts
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    29
 iter :: "'s binop \<Rightarrow> 's step_type \<Rightarrow>
11298
acd83fa66e92 simplified defs and proofs a little
nipkow
parents: 11229
diff changeset
    30
          's list \<Rightarrow> nat set \<Rightarrow> 's list \<times> nat set"
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    31
 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
    32
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    33
primrec
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    34
"propa f []      ss w = (ss,w)"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    35
"propa f (q'#qs) ss w = (let (q,t) = q';
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    36
                             u = t +_f ss!q;
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    37
                             w' = (if u = ss!q then w else insert q w)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    38
                         in propa f qs (ss[q := u]) w')"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    39
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
    40
defs iter_def:
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    41
"iter f step ss w ==
11298
acd83fa66e92 simplified defs and proofs a little
nipkow
parents: 11229
diff changeset
    42
 while (%(ss,w). w \<noteq> {})
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    43
       (%(ss,w). let p = SOME p. p \<in> w
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    44
                 in propa f (step p (ss!p)) ss (w-{p}))
11298
acd83fa66e92 simplified defs and proofs a little
nipkow
parents: 11229
diff changeset
    45
       (ss,w)"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    46
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    47
constdefs
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    48
 unstables :: "'s ord \<Rightarrow> 's step_type \<Rightarrow> 's list \<Rightarrow> nat set"
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    49
"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
    50
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    51
 kildall :: "'s ord \<Rightarrow> 's binop \<Rightarrow> 's step_type \<Rightarrow> 's list \<Rightarrow> 's list"
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    52
"kildall r f step ss == fst(iter f step ss (unstables r step ss))"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    53
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    54
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
    55
primrec
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    56
"merges f []      ss = ss"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    57
"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
    58
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    59
10774
4de3a0d3ae28 recdef_tc;
wenzelm
parents: 10661
diff changeset
    60
lemmas [simp] = Let_def le_iff_plus_unchanged [symmetric]
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    61
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    62
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    63
consts
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    64
 "@plusplussub" :: "'a list \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> 'a \<Rightarrow> 'a" ("(_ /++'__ _)" [65, 1000, 66] 65)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    65
primrec
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    66
  "[] ++_f y = y"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    67
  "(x#xs) ++_f y = xs ++_f (x +_f y)"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    68
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    69
lemma nth_merges:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    70
  "\<And>ss. \<lbrakk> semilat (A, r, f); p < length ss; ss \<in> list n A; 
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    71
            \<forall>(p,t)\<in>set ps. p<n \<and> t\<in>A \<rbrakk> \<Longrightarrow>
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    72
  (merges f ps ss)!p = map snd [(p',t') \<in> ps. p'=p] ++_f ss!p"
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    73
  (is "\<And>ss. _ \<Longrightarrow> _ \<Longrightarrow> _ \<Longrightarrow> ?steptype ps \<Longrightarrow> ?P ss ps")
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    74
proof (induct ps)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    75
  show "\<And>ss. ?P ss []" by simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    76
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    77
  fix ss p' ps'
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    78
  assume sl: "semilat (A, r, f)"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    79
  assume ss: "ss \<in> list n A"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    80
  assume l:  "p < length ss"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    81
  assume "?steptype (p'#ps')"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    82
  then obtain a b where
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    83
    p': "p'=(a,b)" and ab: "a<n" "b\<in>A" and "?steptype ps'"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    84
    by (cases p', auto)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    85
  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
    86
  hence IH: "\<And>ss. ss \<in> list n A \<Longrightarrow> p < length ss \<Longrightarrow> ?P ss ps'" .
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    87
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    88
  from sl ss ab
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    89
  have "ss[a := b +_f ss!a] \<in> list n A" by (simp add: closedD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    90
  moreover
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    91
  from calculation
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    92
  have "p < length (ss[a := b +_f ss!a])" by simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    93
  ultimately
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    94
  have "?P (ss[a := b +_f ss!a]) ps'" by (rule IH)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    95
  with p' l 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    96
  show "?P ss (p'#ps')" by simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    97
qed
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    98
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
    99
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   100
lemma pres_typeD:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   101
  "\<lbrakk> pres_type step n A; s\<in>A; p<n; (q,s')\<in>set (step p s) \<rbrakk> \<Longrightarrow> s' \<in> A"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   102
  by (unfold pres_type_def, blast)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   103
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   104
lemma boundedD: 
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   105
  "\<lbrakk> bounded step n; p < n; (q,t) : set (step p xs) \<rbrakk> \<Longrightarrow> q < n" 
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   106
  by (unfold bounded_def, blast)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   107
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   108
lemma monoD:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   109
  "\<lbrakk> mono r step n A; p < n; s\<in>A; s <=_r t \<rbrakk> \<Longrightarrow> step p s <=|r| step p t"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   110
  by (unfold mono_def, blast)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   111
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   112
(** merges **)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   113
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   114
lemma length_merges [rule_format, simp]:
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   115
  "\<forall>ss. size(merges f ps ss) = size ss"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   116
  by (induct_tac ps, auto)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   117
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   118
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   119
lemma merges_preserves_type_lemma: 
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   120
  "semilat(A,r,f) \<Longrightarrow>
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   121
     \<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
   122
          \<longrightarrow> merges f ps xs \<in> list n A" 
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   123
  apply (frule semilatDclosedI) 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   124
  apply (unfold closed_def) 
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   125
  apply (induct_tac ps)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   126
   apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   127
  apply clarsimp
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   128
  done
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   129
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   130
lemma merges_preserves_type [simp]:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   131
  "\<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
   132
  \<Longrightarrow> merges f ps xs \<in> list n A"
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   133
  by (simp add: merges_preserves_type_lemma)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   134
  
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   135
lemma merges_incr_lemma:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   136
  "semilat(A,r,f) \<Longrightarrow> 
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   137
     \<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
   138
  apply (induct_tac ps)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   139
   apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   140
  apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   141
  apply clarify
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   142
  apply (rule order_trans)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   143
    apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   144
   apply (erule list_update_incr)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   145
     apply assumption
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   146
    apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   147
   apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   148
  apply (blast intro!: listE_set intro: closedD listE_length [THEN nth_in])
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   149
  done
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   150
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   151
lemma merges_incr:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   152
  "\<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
   153
  \<Longrightarrow> xs <=[r] merges f ps xs"
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   154
  by (simp add: merges_incr_lemma)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   155
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   156
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   157
lemma merges_same_conv [rule_format]:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   158
  "semilat(A,r,f) \<Longrightarrow> 
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   159
     (\<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
   160
     (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
   161
  apply (induct_tac ps)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   162
   apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   163
  apply clarsimp
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   164
  apply (rename_tac p x ps xs)
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   165
  apply (rule iffI)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   166
   apply (rule context_conjI)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   167
    apply (subgoal_tac "xs[p := x +_f xs!p] <=[r] xs")
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   168
     apply (force dest!: le_listD simp add: nth_list_update)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   169
    apply (erule subst, rule merges_incr)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   170
        apply assumption
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   171
       apply (blast intro!: listE_set intro: closedD listE_length [THEN nth_in])
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   172
      apply clarify
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   173
      apply (rule conjI)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   174
       apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   175
       apply (blast dest: boundedD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   176
      apply blast
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   177
   apply clarify
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   178
   apply (rotate_tac -2)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   179
   apply (erule allE)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   180
   apply (erule impE)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   181
    apply assumption
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   182
   apply (erule impE)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   183
    apply assumption
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   184
   apply (drule bspec)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   185
    apply assumption
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   186
   apply (simp add: le_iff_plus_unchanged [THEN iffD1] list_update_same_conv [THEN iffD2])
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   187
   apply blast
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   188
  apply clarify 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   189
  apply (simp add: le_iff_plus_unchanged [THEN iffD1] list_update_same_conv [THEN iffD2])
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   190
  done
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   191
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   192
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   193
lemma list_update_le_listI [rule_format]:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   194
  "set xs <= A \<longrightarrow> set ys <= A \<longrightarrow> xs <=[r] ys \<longrightarrow> p < size xs \<longrightarrow>  
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   195
   x <=_r ys!p \<longrightarrow> semilat(A,r,f) \<longrightarrow> x\<in>A \<longrightarrow> 
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   196
   xs[p := x +_f xs!p] <=[r] ys"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   197
  apply (unfold Listn.le_def lesub_def semilat_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   198
  apply (simp add: list_all2_conv_all_nth nth_list_update)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   199
  done
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   200
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   201
lemma merges_pres_le_ub:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   202
  "\<lbrakk> semilat(A,r,f); set ts <= A; set ss <= A; 
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   203
     \<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
   204
     ss <=[r] ts \<rbrakk> 
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   205
  \<Longrightarrow> merges f ps ss <=[r] ts"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   206
proof -
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   207
  { fix A r f t ts ps
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   208
    have
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   209
    "\<And>qs. \<lbrakk> semilat(A,r,f); set ts <= A; 
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   210
              \<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
   211
    set qs <= set ps  \<longrightarrow> 
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   212
    (\<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
   213
    apply (induct_tac qs)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   214
     apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   215
    apply (simp (no_asm_simp))
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   216
    apply clarify
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   217
    apply (rotate_tac -2)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   218
    apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   219
    apply (erule allE, erule impE, erule_tac [2] mp)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   220
     apply (drule bspec, assumption)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   221
     apply (simp add: closedD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   222
    apply (drule bspec, assumption)
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   223
    apply (simp add: list_update_le_listI)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   224
    done 
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   225
  } note this [dest]
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   226
  
11549
e7265e70fd7c renamed "antecedent" case to "rule_context";
wenzelm
parents: 11299
diff changeset
   227
  case rule_context
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   228
  thus ?thesis by blast
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   229
qed
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   230
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   231
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   232
(** propa **)
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   233
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   234
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   235
lemma decomp_propa:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   236
  "\<And>ss w. (\<forall>(q,t)\<in>set qs. q < size ss) \<Longrightarrow> 
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   237
   propa f qs ss w = 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   238
   (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
   239
  apply (induct qs)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   240
   apply simp   
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   241
  apply (simp (no_asm))
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   242
  apply clarify  
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   243
  apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   244
  apply (rule conjI) 
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   245
   apply (simp add: nth_list_update)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   246
   apply blast
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   247
  apply (simp add: nth_list_update)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   248
  apply blast
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   249
  done 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   250
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   251
(** iter **)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   252
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   253
lemma plusplus_closed: 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   254
  "\<And>y. \<lbrakk>semilat (A, r, f); set x \<subseteq> A; y \<in> A\<rbrakk> \<Longrightarrow> x ++_f y \<in> A"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   255
proof (induct x)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   256
  show "\<And>y. y \<in> A \<Longrightarrow> [] ++_f y \<in> A" by simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   257
  fix y x xs
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   258
  assume sl: "semilat (A, r, f)" and y: "y \<in> A" and xs: "set (x#xs) \<subseteq> A"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   259
  assume IH: "\<And>y. \<lbrakk>semilat (A, r, f); set xs \<subseteq> A; y \<in> A\<rbrakk> \<Longrightarrow> xs ++_f y \<in> A"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   260
  from xs obtain x: "x \<in> A" and "set xs \<subseteq> A" by simp  
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   261
  from sl x y have "(x +_f y) \<in> A" by (simp add: closedD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   262
  with sl xs have "xs ++_f (x +_f y) \<in> A" by - (rule IH)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   263
  thus "(x#xs) ++_f y \<in> A" by simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   264
qed
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   265
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   266
lemma ub2: "\<And>y. \<lbrakk>semilat (A, r, f); set x \<subseteq> A; y \<in> A\<rbrakk> \<Longrightarrow> y <=_r x ++_f y"
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   267
proof (induct x)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   268
  show "\<And>y. semilat(A, r, f) \<Longrightarrow> y <=_r [] ++_f y" by simp 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   269
  
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   270
  fix y a l
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   271
  assume sl: "semilat (A, r, f)"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   272
  assume y:  "y \<in> A"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   273
  assume "set (a#l) \<subseteq> A"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   274
  then obtain a: "a \<in> A" and x: "set l \<subseteq> A" by simp 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   275
  assume "\<And>y. \<lbrakk>semilat (A, r, f); set l \<subseteq> A; y \<in> A\<rbrakk> \<Longrightarrow> y <=_r l ++_f y"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   276
  hence IH: "\<And>y. y \<in> A \<Longrightarrow> y <=_r l ++_f y" .
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   277
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   278
  from sl have "order r" .. note order_trans [OF this, trans]  
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   279
  
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   280
  from sl a y have "y <=_r a +_f y" by (rule semilat_ub2)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   281
  also
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   282
  from sl a y have "a +_f y \<in> A" by (simp add: closedD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   283
  hence "(a +_f y) <=_r l ++_f (a +_f y)" by (rule IH)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   284
  finally
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   285
  have "y <=_r l ++_f (a +_f y)" .
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   286
  thus "y <=_r (a#l) ++_f y" by simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   287
qed
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   288
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   289
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   290
lemma ub1: 
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   291
  "\<And>y. \<lbrakk>semilat (A, r, f); set ls \<subseteq> A; y \<in> A; x \<in> set ls\<rbrakk> \<Longrightarrow> x <=_r ls ++_f y"
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   292
proof (induct ls)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   293
  show "\<And>y. x \<in> set [] \<Longrightarrow> x <=_r [] ++_f y" by simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   294
  
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   295
  fix y s ls
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   296
  assume sl: "semilat (A, r, f)" 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   297
  hence "order r" .. note order_trans [OF this, trans]
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   298
  assume "set (s#ls) \<subseteq> A"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   299
  then obtain s: "s \<in> A" and ls: "set ls \<subseteq> A" by simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   300
  assume y: "y \<in> A" 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   301
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   302
  assume 
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   303
    "\<And>y. \<lbrakk>semilat (A, r, f); set ls \<subseteq> A; y \<in> A; x \<in> set ls\<rbrakk> \<Longrightarrow> x <=_r ls ++_f y"
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   304
  hence IH: "\<And>y. x \<in> set ls \<Longrightarrow> y \<in> A \<Longrightarrow> x <=_r ls ++_f y" .
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   305
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   306
  assume "x \<in> set (s#ls)"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   307
  then obtain xls: "x = s \<or> x \<in> set ls" by simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   308
  moreover {
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   309
    assume xs: "x = s"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   310
    from sl s y have "s <=_r s +_f y" by (rule semilat_ub1)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   311
    also
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   312
    from sl s y have "s +_f y \<in> A" by (simp add: closedD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   313
    with sl ls have "(s +_f y) <=_r ls ++_f (s +_f y)" by (rule ub2)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   314
    finally 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   315
    have "s <=_r ls ++_f (s +_f y)" .
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   316
    with xs have "x <=_r ls ++_f (s +_f y)" by simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   317
  } 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   318
  moreover {
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   319
    assume "x \<in> set ls"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   320
    hence "\<And>y. y \<in> A \<Longrightarrow> x <=_r ls ++_f y" by (rule IH)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   321
    moreover
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   322
    from sl s y
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   323
    have "s +_f y \<in> A" by (simp add: closedD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   324
    ultimately 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   325
    have "x <=_r ls ++_f (s +_f y)" .
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   326
  }
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   327
  ultimately 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   328
  have "x <=_r ls ++_f (s +_f y)" by blast
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   329
  thus "x <=_r (s#ls) ++_f y" by simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   330
qed
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   331
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   332
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   333
lemma ub1': 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   334
  "\<lbrakk>semilat (A, r, f); \<forall>(p,s) \<in> set S. s \<in> A; y \<in> A; (a,b) \<in> set S\<rbrakk> 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   335
  \<Longrightarrow> b <=_r map snd [(p', t')\<in>S. p' = a] ++_f y" 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   336
proof -
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   337
  let "b <=_r ?map ++_f y" = ?thesis
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   338
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   339
  assume "semilat (A, r, f)" "y \<in> A"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   340
  moreover
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   341
  assume "\<forall>(p,s) \<in> set S. s \<in> A"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   342
  hence "set ?map \<subseteq> A" by auto
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   343
  moreover
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   344
  assume "(a,b) \<in> set S"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   345
  hence "b \<in> set ?map" by (induct S, auto)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   346
  ultimately
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   347
  show ?thesis by - (rule ub1)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   348
qed
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   349
    
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   350
 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   351
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   352
lemma plusplus_empty:  
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   353
  "\<forall>s'. (q, s') \<in> set S \<longrightarrow> s' +_f ss ! q = ss ! q \<Longrightarrow>
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   354
   (map snd [(p', t')\<in> S. p' = q] ++_f ss ! q) = ss ! q"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   355
apply (induct S)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   356
apply auto 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   357
done
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   358
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   359
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   360
lemma stable_pres_lemma:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   361
  "\<lbrakk> semilat (A,r,f); pres_type step n A; bounded step n; 
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   362
     ss \<in> list n A; p \<in> w; \<forall>q\<in>w. q < n; 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   363
     \<forall>q. q < n \<longrightarrow> q \<notin> w \<longrightarrow> stable r step ss q; q < n; 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   364
     \<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
   365
     q \<notin> w \<or> q = p \<rbrakk> 
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   366
  \<Longrightarrow> stable r step (merges f (step p (ss!p)) ss) q"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   367
  apply (unfold stable_def)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   368
  apply (subgoal_tac "\<forall>s'. (q,s') \<in> set (step p (ss!p)) \<longrightarrow> s' : A")
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   369
   prefer 2
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   370
   apply clarify
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   371
   apply (erule pres_typeD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   372
    prefer 3 apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   373
    apply (rule listE_nth_in)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   374
     apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   375
    apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   376
   apply simp
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   377
  apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   378
  apply clarify
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   379
  apply (subst nth_merges) 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   380
        apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   381
       apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   382
       apply (blast dest: boundedD)
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   383
      apply assumption
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   384
     apply clarify
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   385
     apply (rule conjI)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   386
      apply (blast dest: boundedD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   387
     apply (erule pres_typeD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   388
       prefer 3 apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   389
      apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   390
     apply simp 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   391
  apply (frule nth_merges [of _ _ _ q _ _ "step p (ss!p)"]) (* fixme: why does method subst not work?? *)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   392
    prefer 2 apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   393
   apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   394
  apply clarify
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   395
  apply (rule conjI)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   396
   apply (blast dest: boundedD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   397
  apply (erule pres_typeD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   398
     prefer 3 apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   399
    apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   400
   apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   401
  apply (drule_tac P = "\<lambda>x. (a, b) \<in> set (step q x)" in subst)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   402
   apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   403
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   404
 apply (simp add: plusplus_empty)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   405
 apply (cases "q \<in> w")
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   406
  apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   407
  apply (rule ub1')
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   408
     apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   409
    apply clarify
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   410
    apply (rule pres_typeD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   411
       apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   412
      prefer 3 apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   413
     apply (blast intro: listE_nth_in dest: boundedD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   414
    apply (blast intro: pres_typeD dest: boundedD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   415
   apply (blast intro: listE_nth_in dest: boundedD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   416
  apply assumption
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   417
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   418
 apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   419
 apply (erule allE, erule impE, assumption, erule impE, assumption)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   420
 apply (rule order_trans)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   421
   apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   422
  defer
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   423
 apply (rule ub2)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   424
    apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   425
   apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   426
   apply clarify
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   427
   apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   428
   apply (rule pres_typeD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   429
      apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   430
     prefer 3 apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   431
    apply (blast intro: listE_nth_in dest: boundedD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   432
   apply (blast intro: pres_typeD dest: boundedD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   433
  apply (blast intro: listE_nth_in dest: boundedD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   434
 apply blast
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   435
 done
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   436
 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   437
  
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   438
lemma lesub_step_type:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   439
  "\<And>b x y. a <=|r| b \<Longrightarrow> (x,y) \<in> set a \<Longrightarrow> \<exists>y'. (x, y') \<in> set b \<and> y <=_r y'"
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   440
apply (induct a)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   441
 apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   442
apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   443
apply (case_tac b)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   444
 apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   445
apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   446
apply (erule disjE)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   447
 apply clarify
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   448
 apply (simp add: lesub_def)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   449
 apply blast   
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   450
apply clarify
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   451
apply blast
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   452
done
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   453
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   454
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   455
lemma merges_bounded_lemma:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   456
  "\<lbrakk> semilat (A,r,f); mono r step n A; bounded step n; 
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   457
     \<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
   458
     ss <=[r] ts; ! p. p < n \<longrightarrow> stable r step ts p \<rbrakk> 
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   459
  \<Longrightarrow> merges f (step p (ss!p)) ss <=[r] ts"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   460
  apply (unfold stable_def)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   461
  apply (rule merges_pres_le_ub)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   462
      apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   463
     apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   464
    apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   465
   prefer 2 apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   466
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   467
  apply clarsimp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   468
  apply (drule boundedD, assumption+)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   469
  apply (erule allE, erule impE, assumption)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   470
  apply (drule bspec, assumption)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   471
  apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   472
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   473
  apply (drule monoD [of _ _ _ _ p "ss!p"  "ts!p"])
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   474
     apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   475
    apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   476
   apply (simp add: le_listD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   477
  
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   478
  apply (drule lesub_step_type, assumption) 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   479
  apply clarify
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   480
  apply (drule bspec, assumption)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   481
  apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   482
  apply (blast intro: order_trans)
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   483
  done
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   484
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   485
lemma termination_lemma:  
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   486
  "\<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
   487
      ss <[r] merges f qs ss \<or> 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   488
  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
   489
  apply (unfold lesssub_def)
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   490
  apply (simp (no_asm_simp) add: merges_incr)
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   491
  apply (rule impI)
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   492
  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
   493
  apply assumption+
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   494
    defer
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   495
    apply (rule sym, assumption)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   496
   defer apply simp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   497
   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
   498
   apply (blast intro!: psubsetI elim: equalityE)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   499
   apply clarsimp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   500
   apply (drule bspec, assumption) 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   501
   apply (drule bspec, assumption)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   502
   apply clarsimp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   503
  done 
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   504
11298
acd83fa66e92 simplified defs and proofs a little
nipkow
parents: 11229
diff changeset
   505
lemma iter_properties[rule_format]:
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   506
  "\<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
   507
     bounded step n; \<forall>p\<in>w0. p < n; ss0 \<in> list n A;
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   508
     \<forall>p<n. p \<notin> w0 \<longrightarrow> stable r step ss0 p \<rbrakk> \<Longrightarrow>
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   509
   iter f step ss0 w0 = (ss',w')
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   510
   \<longrightarrow>
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   511
   ss' \<in> list n A \<and> stables r step ss' \<and> ss0 <=[r] ss' \<and>
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   512
   (\<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
   513
apply (unfold iter_def stables_def)
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   514
apply (rule_tac P = "%(ss,w).
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   515
 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
   516
 (\<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
   517
 (\<forall>p\<in>w. p < n)" and
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   518
 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
   519
       in while_rule)
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   520
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   521
-- "Invariant holds initially:"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   522
apply (simp add:stables_def) 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   523
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   524
-- "Invariant is preserved:"
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   525
apply(simp add: stables_def split_paired_all)
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   526
apply(rename_tac ss w)
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   527
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
   528
 prefer 2; apply (fast intro: someI)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   529
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
   530
 prefer 2
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   531
 apply clarify
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   532
 apply (rule conjI)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   533
  apply(clarsimp, blast dest!: boundedD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   534
 apply (erule pres_typeD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   535
  prefer 3
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   536
  apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   537
  apply (erule listE_nth_in)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   538
  apply blast
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   539
 apply blast
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   540
apply (subst decomp_propa)
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   541
 apply blast
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   542
apply simp
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   543
apply (rule conjI)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   544
 apply (erule merges_preserves_type)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   545
 apply blast 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   546
 apply clarify
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   547
 apply (rule conjI)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   548
  apply(clarsimp, blast dest!: boundedD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   549
 apply (erule pres_typeD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   550
  prefer 3
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   551
  apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   552
  apply (erule listE_nth_in)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   553
  apply blast
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   554
 apply blast
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   555
apply (rule conjI) 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   556
 apply clarify 
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   557
 apply (blast intro!: stable_pres_lemma)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   558
apply (rule conjI) 
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   559
 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
   560
apply (rule conjI)
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   561
 apply clarsimp
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   562
 apply (blast intro!: merges_bounded_lemma)
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   563
apply (blast dest!: boundedD)
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   564
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   565
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   566
-- "Postcondition holds upon termination:"
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   567
apply(clarsimp simp add: stables_def split_paired_all) 
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   568
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   569
-- "Well-foundedness of the termination relation:"
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   570
apply (rule wf_lex_prod)
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   571
 apply (drule (1) semilatDorderI [THEN acc_le_listI])
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   572
 apply (simp only: acc_def lesssub_def)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   573
apply (rule wf_finite_psubset) 
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   574
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   575
-- "Loop decreases along termination relation:"
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   576
apply(simp add: stables_def split_paired_all)
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   577
apply(rename_tac ss w)
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   578
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
   579
 prefer 2; apply (fast intro: someI)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   580
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
   581
 prefer 2
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   582
 apply clarify
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   583
 apply (rule conjI)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   584
  apply(clarsimp, blast dest!: boundedD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   585
 apply (erule pres_typeD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   586
  prefer 3
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   587
  apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   588
  apply (erule listE_nth_in)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   589
  apply blast
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   590
 apply blast
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   591
apply (subst decomp_propa)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   592
 apply blast
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   593
apply clarify 
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   594
apply (simp del: listE_length
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   595
    add: lex_prod_def finite_psubset_def 
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   596
         bounded_nat_set_is_finite)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   597
apply (rule termination_lemma)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   598
apply assumption+
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   599
defer
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   600
apply assumption
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   601
apply clarsimp
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   602
apply (blast dest!: boundedD)
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   603
done   
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   604
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 10774
diff changeset
   605
11229
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   606
lemma kildall_properties:
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   607
  "\<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
   608
     bounded step n; ss0 \<in> list n A \<rbrakk> \<Longrightarrow>
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   609
  kildall r f step ss0 \<in> list n A \<and>
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   610
  stables r step (kildall r f step ss0) \<and>
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   611
  ss0 <=[r] kildall r f step ss0 \<and>
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   612
  (\<forall>ts\<in>list n A. ss0 <=[r] ts \<and> stables r step ts \<longrightarrow>
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   613
                 kildall r f step ss0 <=[r] ts)"
11229
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   614
apply (unfold kildall_def)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   615
apply(case_tac "iter f step ss0 (unstables r step ss0)")
11298
acd83fa66e92 simplified defs and proofs a little
nipkow
parents: 11229
diff changeset
   616
apply(simp)
11229
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   617
apply (rule iter_properties)
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   618
apply (simp_all add: unstables_def stable_def)
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   619
done
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   620
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   621
lemma is_bcv_kildall:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   622
  "\<lbrakk> semilat(A,r,f); acc r; top r T; 
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   623
      pres_type step n A; bounded step n; 
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   624
      mono r step n A \<rbrakk>
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   625
  \<Longrightarrow> is_bcv r T step n A (kildall r f step)"
11299
1d3d110c456e welltyping -> wt_step
nipkow
parents: 11298
diff changeset
   626
apply(unfold is_bcv_def wt_step_def)
11229
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   627
apply(insert kildall_properties[of A])
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   628
apply(simp add:stables_def)
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   629
apply clarify
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   630
apply(subgoal_tac "kildall r f step ss \<in> list n A")
11229
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   631
 prefer 2 apply (simp(no_asm_simp))
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   632
apply (rule iffI)
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   633
 apply (rule_tac x = "kildall r f step ss" in bexI) 
11229
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   634
  apply (rule conjI)
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   635
   apply blast
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   636
  apply (simp  (no_asm_simp))
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   637
 apply assumption
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   638
apply clarify
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   639
apply(subgoal_tac "kildall r f step ss!p <=_r ts!p")
11229
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   640
 apply simp
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   641
apply (blast intro!: le_listD less_lengthI)
f417841385b7 Got rid of is_dfa
nipkow
parents: 11184
diff changeset
   642
done
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   643
12516
d09d0f160888 exceptions
kleing
parents: 11549
diff changeset
   644
end