src/HOL/Data_Structures/AA_Set.thy
author nipkow
Sun, 08 Apr 2018 12:31:08 +0200
changeset 67967 5a4280946a25
parent 67613 ce654b0e6d69
child 68023 75130777ece4
permissions -rw-r--r--
moved and renamed lemmas
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
61793
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
     1
(*
63411
e051eea34990 got rid of class cmp; added height-size proofs by Daniel Stuewe
nipkow
parents: 62526
diff changeset
     2
Author: Tobias Nipkow, Daniel Stüwe
61793
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
     3
*)
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
     4
62130
90a3016a6c12 added AA_Map; tuned titles
nipkow
parents: 61793
diff changeset
     5
section \<open>AA Tree Implementation of Sets\<close>
61793
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
     6
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
     7
theory AA_Set
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
     8
imports
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
     9
  Isin2
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    10
  Cmp
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    11
begin
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    12
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    13
type_synonym 'a aa_tree = "('a,nat) tree"
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    14
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    15
fun lvl :: "'a aa_tree \<Rightarrow> nat" where
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    16
"lvl Leaf = 0" |
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    17
"lvl (Node lv _ _ _) = lv"
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
    18
61793
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    19
fun invar :: "'a aa_tree \<Rightarrow> bool" where
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    20
"invar Leaf = True" |
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    21
"invar (Node h l a r) =
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    22
 (invar l \<and> invar r \<and>
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    23
  h = lvl l + 1 \<and> (h = lvl r + 1 \<or> (\<exists>lr b rr. r = Node h lr b rr \<and> h = lvl rr + 1)))"
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
    24
61793
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    25
fun skew :: "'a aa_tree \<Rightarrow> 'a aa_tree" where
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    26
"skew (Node lva (Node lvb t1 b t2) a t3) =
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    27
  (if lva = lvb then Node lva t1 b (Node lva t2 a t3) else Node lva (Node lvb t1 b t2) a t3)" |
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    28
"skew t = t"
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    29
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    30
fun split :: "'a aa_tree \<Rightarrow> 'a aa_tree" where
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    31
"split (Node lva t1 a (Node lvb t2 b (Node lvc t3 c t4))) =
67369
7360fe6bb423 prefer formal comments;
wenzelm
parents: 67040
diff changeset
    32
   (if lva = lvb \<and> lvb = lvc \<comment> \<open>\<open>lva = lvc\<close> suffices\<close>
61793
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    33
    then Node (lva+1) (Node lva t1 a t2) b (Node lva t3 c t4)
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    34
    else Node lva t1 a (Node lvb t2 b (Node lvc t3 c t4)))" |
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    35
"split t = t"
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    36
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    37
hide_const (open) insert
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    38
63411
e051eea34990 got rid of class cmp; added height-size proofs by Daniel Stuewe
nipkow
parents: 62526
diff changeset
    39
fun insert :: "'a::linorder \<Rightarrow> 'a aa_tree \<Rightarrow> 'a aa_tree" where
61793
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    40
"insert x Leaf = Node 1 Leaf x Leaf" |
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    41
"insert x (Node lv t1 a t2) =
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    42
  (case cmp x a of
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    43
     LT \<Rightarrow> split (skew (Node lv (insert x t1) a t2)) |
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    44
     GT \<Rightarrow> split (skew (Node lv t1 a (insert x t2))) |
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    45
     EQ \<Rightarrow> Node lv t1 x t2)"
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    46
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    47
fun sngl :: "'a aa_tree \<Rightarrow> bool" where
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    48
"sngl Leaf = False" |
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    49
"sngl (Node _ _ _ Leaf) = True" |
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    50
"sngl (Node lva _ _ (Node lvb _ _ _)) = (lva > lvb)"
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    51
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    52
definition adjust :: "'a aa_tree \<Rightarrow> 'a aa_tree" where
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    53
"adjust t =
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    54
 (case t of
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    55
  Node lv l x r \<Rightarrow>
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    56
   (if lvl l >= lv-1 \<and> lvl r >= lv-1 then t else
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    57
    if lvl r < lv-1 \<and> sngl l then skew (Node (lv-1) l x r) else
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    58
    if lvl r < lv-1
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    59
    then case l of
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    60
           Node lva t1 a (Node lvb t2 b t3)
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
    61
             \<Rightarrow> Node (lvb+1) (Node lva t1 a t2) b (Node (lv-1) t3 x r) 
61793
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    62
    else
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    63
    if lvl r < lv then split (Node (lv-1) l x r)
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    64
    else
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    65
      case r of
62160
ff20b44b2fc8 tuned layout
nipkow
parents: 62130
diff changeset
    66
        Node lvb t1 b t4 \<Rightarrow>
61793
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    67
          (case t1 of
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    68
             Node lva t2 a t3
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    69
               \<Rightarrow> Node (lva+1) (Node (lv-1) l x t2) a
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
    70
                    (split (Node (if sngl t1 then lva else lva+1) t3 b t4)))))"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
    71
67406
23307fd33906 isabelle update_cartouches -c;
wenzelm
parents: 67369
diff changeset
    72
text\<open>In the paper, the last case of @{const adjust} is expressed with the help of an
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
    73
incorrect auxiliary function \texttt{nlvl}.
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
    74
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
    75
Function @{text del_max} below is called \texttt{dellrg} in the paper.
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
    76
The latter is incorrect for two reasons: \texttt{dellrg} is meant to delete the largest
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
    77
element but recurses on the left instead of the right subtree; the invariant
67406
23307fd33906 isabelle update_cartouches -c;
wenzelm
parents: 67369
diff changeset
    78
is not restored.\<close>
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
    79
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
    80
fun del_max :: "'a aa_tree \<Rightarrow> 'a aa_tree * 'a" where
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
    81
"del_max (Node lv l a Leaf) = (l,a)" |
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
    82
"del_max (Node lv l a r) = (let (r',b) = del_max r in (adjust(Node lv l a r'), b))"
61793
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    83
63411
e051eea34990 got rid of class cmp; added height-size proofs by Daniel Stuewe
nipkow
parents: 62526
diff changeset
    84
fun delete :: "'a::linorder \<Rightarrow> 'a aa_tree \<Rightarrow> 'a aa_tree" where
61793
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    85
"delete _ Leaf = Leaf" |
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    86
"delete x (Node lv l a r) =
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    87
  (case cmp x a of
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    88
     LT \<Rightarrow> adjust (Node lv (delete x l) a r) |
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    89
     GT \<Rightarrow> adjust (Node lv l a (delete x r)) |
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    90
     EQ \<Rightarrow> (if l = Leaf then r
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    91
            else let (l',b) = del_max l in adjust (Node lv l' b r)))"
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
    92
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
    93
fun pre_adjust where
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
    94
"pre_adjust (Node lv l a r) = (invar l \<and> invar r \<and>
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
    95
    ((lv = lvl l + 1 \<and> (lv = lvl r + 1 \<or> lv = lvl r + 2 \<or> lv = lvl r \<and> sngl r)) \<or>
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
    96
     (lv = lvl l + 2 \<and> (lv = lvl r + 1 \<or> lv = lvl r \<and> sngl r))))"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
    97
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
    98
declare pre_adjust.simps [simp del]
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
    99
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   100
subsection "Auxiliary Proofs"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   101
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   102
lemma split_case: "split t = (case t of
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   103
  Node lvx a x (Node lvy b y (Node lvz c z d)) \<Rightarrow>
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   104
   (if lvx = lvy \<and> lvy = lvz
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   105
    then Node (lvx+1) (Node lvx a x b) y (Node lvx c z d)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   106
    else t)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   107
  | t \<Rightarrow> t)"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   108
by(auto split: tree.split)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   109
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   110
lemma skew_case: "skew t = (case t of
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   111
  Node lvx (Node lvy a y b) x c \<Rightarrow>
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   112
  (if lvx = lvy then Node lvx a y (Node lvx b x c) else t)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   113
 | t \<Rightarrow> t)"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   114
by(auto split: tree.split)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   115
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   116
lemma lvl_0_iff: "invar t \<Longrightarrow> lvl t = 0 \<longleftrightarrow> t = Leaf"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   117
by(cases t) auto
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   118
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   119
lemma lvl_Suc_iff: "lvl t = Suc n \<longleftrightarrow> (\<exists> l a r. t = Node (Suc n) l a r)"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   120
by(cases t) auto
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   121
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   122
lemma lvl_skew: "lvl (skew t) = lvl t"
62526
nipkow
parents: 62496
diff changeset
   123
by(cases t rule: skew.cases) auto
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   124
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   125
lemma lvl_split: "lvl (split t) = lvl t \<or> lvl (split t) = lvl t + 1 \<and> sngl (split t)"
62526
nipkow
parents: 62496
diff changeset
   126
by(cases t rule: split.cases) auto
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   127
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   128
lemma invar_2Nodes:"invar (Node lv l x (Node rlv rl rx rr)) =
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   129
     (invar l \<and> invar \<langle>rlv, rl, rx, rr\<rangle> \<and> lv = Suc (lvl l) \<and>
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   130
     (lv = Suc rlv \<or> rlv = lv \<and> lv = Suc (lvl rr)))"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   131
by simp
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   132
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   133
lemma invar_NodeLeaf[simp]:
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   134
  "invar (Node lv l x Leaf) = (invar l \<and> lv = Suc (lvl l) \<and> lv = Suc 0)"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   135
by simp
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   136
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   137
lemma sngl_if_invar: "invar (Node n l a r) \<Longrightarrow> n = lvl r \<Longrightarrow> sngl r"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   138
by(cases r rule: sngl.cases) clarsimp+
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   139
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   140
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   141
subsection "Invariance"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   142
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   143
subsubsection "Proofs for insert"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   144
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   145
lemma lvl_insert_aux:
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   146
  "lvl (insert x t) = lvl t \<or> lvl (insert x t) = lvl t + 1 \<and> sngl (insert x t)"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   147
apply(induction t)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   148
apply (auto simp: lvl_skew)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   149
apply (metis Suc_eq_plus1 lvl.simps(2) lvl_split lvl_skew)+
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   150
done
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   151
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   152
lemma lvl_insert: obtains
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   153
  (Same) "lvl (insert x t) = lvl t" |
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   154
  (Incr) "lvl (insert x t) = lvl t + 1" "sngl (insert x t)"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   155
using lvl_insert_aux by blast
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   156
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   157
lemma lvl_insert_sngl: "invar t \<Longrightarrow> sngl t \<Longrightarrow> lvl(insert x t) = lvl t"
62526
nipkow
parents: 62496
diff changeset
   158
proof (induction t rule: insert.induct)
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   159
  case (2 x lv t1 a t2)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   160
  consider (LT) "x < a" | (GT) "x > a" | (EQ) "x = a" 
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   161
    using less_linear by blast 
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   162
  thus ?case proof cases
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   163
    case LT
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   164
    thus ?thesis using 2 by (auto simp add: skew_case split_case split: tree.splits)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   165
  next
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   166
    case GT
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   167
    thus ?thesis using 2 proof (cases t1)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   168
      case Node
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   169
      thus ?thesis using 2 GT  
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   170
        apply (auto simp add: skew_case split_case split: tree.splits)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   171
        by (metis less_not_refl2 lvl.simps(2) lvl_insert_aux n_not_Suc_n sngl.simps(3))+ 
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   172
    qed (auto simp add: lvl_0_iff)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   173
  qed simp
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   174
qed simp
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   175
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   176
lemma skew_invar: "invar t \<Longrightarrow> skew t = t"
62526
nipkow
parents: 62496
diff changeset
   177
by(cases t rule: skew.cases) auto
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   178
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   179
lemma split_invar: "invar t \<Longrightarrow> split t = t"
62526
nipkow
parents: 62496
diff changeset
   180
by(cases t rule: split.cases) clarsimp+
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   181
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   182
lemma invar_NodeL:
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   183
  "\<lbrakk> invar(Node n l x r); invar l'; lvl l' = lvl l \<rbrakk> \<Longrightarrow> invar(Node n l' x r)"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   184
by(auto)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   185
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   186
lemma invar_NodeR:
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   187
  "\<lbrakk> invar(Node n l x r); n = lvl r + 1; invar r'; lvl r' = lvl r \<rbrakk> \<Longrightarrow> invar(Node n l x r')"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   188
by(auto)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   189
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   190
lemma invar_NodeR2:
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   191
  "\<lbrakk> invar(Node n l x r); sngl r'; n = lvl r + 1; invar r'; lvl r' = n \<rbrakk> \<Longrightarrow> invar(Node n l x r')"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   192
by(cases r' rule: sngl.cases) clarsimp+
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   193
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   194
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   195
lemma lvl_insert_incr_iff: "(lvl(insert a t) = lvl t + 1) \<longleftrightarrow>
67613
ce654b0e6d69 more symbols;
wenzelm
parents: 67406
diff changeset
   196
  (\<exists>l x r. insert a t = Node (lvl t + 1) l x r \<and> lvl l = lvl r)"
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   197
apply(cases t)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   198
apply(auto simp add: skew_case split_case split: if_splits)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   199
apply(auto split: tree.splits if_splits)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   200
done
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   201
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   202
lemma invar_insert: "invar t \<Longrightarrow> invar(insert a t)"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   203
proof(induction t)
67040
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   204
  case N: (Node n l x r)
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   205
  hence il: "invar l" and ir: "invar r" by auto
67040
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   206
  note iil = N.IH(1)[OF il]
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   207
  note iir = N.IH(2)[OF ir]
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   208
  let ?t = "Node n l x r"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   209
  have "a < x \<or> a = x \<or> x < a" by auto
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   210
  moreover
67040
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   211
  have ?case if "a < x"
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   212
  proof (cases rule: lvl_insert[of a l])
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   213
    case (Same) thus ?thesis
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   214
      using \<open>a<x\<close> invar_NodeL[OF N.prems iil Same]
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   215
      by (simp add: skew_invar split_invar del: invar.simps)
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   216
  next
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   217
    case (Incr)
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   218
    then obtain t1 w t2 where ial[simp]: "insert a l = Node n t1 w t2"
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   219
      using N.prems by (auto simp: lvl_Suc_iff)
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   220
    have l12: "lvl t1 = lvl t2"
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   221
      by (metis Incr(1) ial lvl_insert_incr_iff tree.inject)
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   222
    have "insert a ?t = split(skew(Node n (insert a l) x r))"
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   223
      by(simp add: \<open>a<x\<close>)
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   224
    also have "skew(Node n (insert a l) x r) = Node n t1 w (Node n t2 x r)"
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   225
      by(simp)
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   226
    also have "invar(split \<dots>)"
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   227
    proof (cases r)
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   228
      case Leaf
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   229
      hence "l = Leaf" using N.prems by(auto simp: lvl_0_iff)
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   230
      thus ?thesis using Leaf ial by simp
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   231
    next
67040
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   232
      case [simp]: (Node m t3 y t4)
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   233
      show ?thesis (*using N(3) iil l12 by(auto)*)
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   234
      proof cases
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   235
        assume "m = n" thus ?thesis using N(3) iil by(auto)
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   236
      next
67040
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   237
        assume "m \<noteq> n" thus ?thesis using N(3) iil l12 by(auto)
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   238
      qed
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   239
    qed
67040
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   240
    finally show ?thesis .
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   241
  qed
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   242
  moreover
67040
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   243
  have ?case if "x < a"
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   244
  proof -
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   245
    from \<open>invar ?t\<close> have "n = lvl r \<or> n = lvl r + 1" by auto
67040
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   246
    thus ?case
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   247
    proof
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   248
      assume 0: "n = lvl r"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   249
      have "insert a ?t = split(skew(Node n l x (insert a r)))"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   250
        using \<open>a>x\<close> by(auto)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   251
      also have "skew(Node n l x (insert a r)) = Node n l x (insert a r)"
67040
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   252
        using N.prems by(simp add: skew_case split: tree.split)
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   253
      also have "invar(split \<dots>)"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   254
      proof -
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   255
        from lvl_insert_sngl[OF ir sngl_if_invar[OF \<open>invar ?t\<close> 0], of a]
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   256
        obtain t1 y t2 where iar: "insert a r = Node n t1 y t2"
67040
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   257
          using N.prems 0 by (auto simp: lvl_Suc_iff)
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   258
        from N.prems iar 0 iir
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   259
        show ?thesis by (auto simp: split_case split: tree.splits)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   260
      qed
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   261
      finally show ?thesis .
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   262
    next
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   263
      assume 1: "n = lvl r + 1"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   264
      hence "sngl ?t" by(cases r) auto
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   265
      show ?thesis
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   266
      proof (cases rule: lvl_insert[of a r])
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   267
        case (Same)
67040
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   268
        show ?thesis using \<open>x<a\<close> il ir invar_NodeR[OF N.prems 1 iir Same]
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   269
          by (auto simp add: skew_invar split_invar)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   270
      next
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   271
        case (Incr)
67406
23307fd33906 isabelle update_cartouches -c;
wenzelm
parents: 67369
diff changeset
   272
        thus ?thesis using invar_NodeR2[OF \<open>invar ?t\<close> Incr(2) 1 iir] 1 \<open>x < a\<close>
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   273
          by (auto simp add: skew_invar split_invar split: if_splits)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   274
      qed
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   275
    qed
67040
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   276
  qed
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   277
  moreover
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63636
diff changeset
   278
  have "a = x \<Longrightarrow> ?case" using N.prems by auto
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   279
  ultimately show ?case by blast
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   280
qed simp
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   281
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   282
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   283
subsubsection "Proofs for delete"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   284
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   285
lemma invarL: "ASSUMPTION(invar \<langle>lv, l, a, r\<rangle>) \<Longrightarrow> invar l"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   286
by(simp add: ASSUMPTION_def)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   287
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   288
lemma invarR: "ASSUMPTION(invar \<langle>lv, l, a, r\<rangle>) \<Longrightarrow> invar r"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   289
by(simp add: ASSUMPTION_def)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   290
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   291
lemma sngl_NodeI:
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   292
  "sngl (Node lv l a r) \<Longrightarrow> sngl (Node lv l' a' r)"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   293
by(cases r) (simp_all)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   294
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   295
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   296
declare invarL[simp] invarR[simp]
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   297
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   298
lemma pre_cases:
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   299
assumes "pre_adjust (Node lv l x r)"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   300
obtains
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   301
 (tSngl) "invar l \<and> invar r \<and>
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   302
    lv = Suc (lvl r) \<and> lvl l = lvl r" |
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   303
 (tDouble) "invar l \<and> invar r \<and>
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   304
    lv = lvl r \<and> Suc (lvl l) = lvl r \<and> sngl r " |
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   305
 (rDown) "invar l \<and> invar r \<and>
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   306
    lv = Suc (Suc (lvl r)) \<and>  lv = Suc (lvl l)" |
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   307
 (lDown_tSngl) "invar l \<and> invar r \<and>
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   308
    lv = Suc (lvl r) \<and> lv = Suc (Suc (lvl l))" |
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   309
 (lDown_tDouble) "invar l \<and> invar r \<and>
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   310
    lv = lvl r \<and> lv = Suc (Suc (lvl l)) \<and> sngl r"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   311
using assms unfolding pre_adjust.simps
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   312
by auto
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   313
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   314
declare invar.simps(2)[simp del] invar_2Nodes[simp add]
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   315
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   316
lemma invar_adjust:
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   317
  assumes pre: "pre_adjust (Node lv l a r)"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   318
  shows  "invar(adjust (Node lv l a r))"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   319
using pre proof (cases rule: pre_cases)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   320
  case (tDouble) thus ?thesis unfolding adjust_def by (cases r) (auto simp: invar.simps(2)) 
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   321
next 
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   322
  case (rDown)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   323
  from rDown obtain llv ll la lr where l: "l = Node llv ll la lr" by (cases l) auto
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   324
  from rDown show ?thesis unfolding adjust_def by (auto simp: l invar.simps(2) split: tree.splits)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   325
next
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   326
  case (lDown_tDouble)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   327
  from lDown_tDouble obtain rlv rr ra rl where r: "r = Node rlv rl ra rr" by (cases r) auto
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   328
  from lDown_tDouble and r obtain rrlv rrr rra rrl where
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   329
    rr :"rr = Node rrlv rrr rra rrl" by (cases rr) auto
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   330
  from  lDown_tDouble show ?thesis unfolding adjust_def r rr
63636
6f38b7abb648 introduced aggressive splitter "split!"
nipkow
parents: 63411
diff changeset
   331
    apply (cases rl) apply (auto simp add: invar.simps(2) split!: if_split)
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   332
    using lDown_tDouble by (auto simp: split_case lvl_0_iff  elim:lvl.elims split: tree.split)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   333
qed (auto simp: split_case invar.simps(2) adjust_def split: tree.splits)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   334
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   335
lemma lvl_adjust:
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   336
  assumes "pre_adjust (Node lv l a r)"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   337
  shows "lv = lvl (adjust(Node lv l a r)) \<or> lv = lvl (adjust(Node lv l a r)) + 1"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   338
using assms(1) proof(cases rule: pre_cases)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   339
  case lDown_tSngl thus ?thesis
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   340
    using lvl_split[of "\<langle>lvl r, l, a, r\<rangle>"] by (auto simp: adjust_def)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   341
next
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   342
  case lDown_tDouble thus ?thesis
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   343
    by (auto simp: adjust_def invar.simps(2) split: tree.split)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   344
qed (auto simp: adjust_def split: tree.splits)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   345
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   346
lemma sngl_adjust: assumes "pre_adjust (Node lv l a r)"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   347
  "sngl \<langle>lv, l, a, r\<rangle>" "lv = lvl (adjust \<langle>lv, l, a, r\<rangle>)"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   348
  shows "sngl (adjust \<langle>lv, l, a, r\<rangle>)" 
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   349
using assms proof (cases rule: pre_cases)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   350
  case rDown
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   351
  thus ?thesis using assms(2,3) unfolding adjust_def
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   352
    by (auto simp add: skew_case) (auto split: tree.split)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   353
qed (auto simp: adjust_def skew_case split_case split: tree.split)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   354
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   355
definition "post_del t t' ==
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   356
  invar t' \<and>
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   357
  (lvl t' = lvl t \<or> lvl t' + 1 = lvl t) \<and>
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   358
  (lvl t' = lvl t \<and> sngl t \<longrightarrow> sngl t')"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   359
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   360
lemma pre_adj_if_postR:
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   361
  "invar\<langle>lv, l, a, r\<rangle> \<Longrightarrow> post_del r r' \<Longrightarrow> pre_adjust \<langle>lv, l, a, r'\<rangle>"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   362
by(cases "sngl r")
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   363
  (auto simp: pre_adjust.simps post_del_def invar.simps(2) elim: sngl.elims)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   364
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   365
lemma pre_adj_if_postL:
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   366
  "invar\<langle>lv, l, a, r\<rangle> \<Longrightarrow> post_del l l' \<Longrightarrow> pre_adjust \<langle>lv, l', b, r\<rangle>"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   367
by(cases "sngl r")
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   368
  (auto simp: pre_adjust.simps post_del_def invar.simps(2) elim: sngl.elims)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   369
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   370
lemma post_del_adjL:
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   371
  "\<lbrakk> invar\<langle>lv, l, a, r\<rangle>; pre_adjust \<langle>lv, l', b, r\<rangle> \<rbrakk>
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   372
  \<Longrightarrow> post_del \<langle>lv, l, a, r\<rangle> (adjust \<langle>lv, l', b, r\<rangle>)"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   373
unfolding post_del_def
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   374
by (metis invar_adjust lvl_adjust sngl_NodeI sngl_adjust lvl.simps(2))
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   375
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   376
lemma post_del_adjR:
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   377
assumes "invar\<langle>lv, l, a, r\<rangle>" "pre_adjust \<langle>lv, l, a, r'\<rangle>" "post_del r r'"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   378
shows "post_del \<langle>lv, l, a, r\<rangle> (adjust \<langle>lv, l, a, r'\<rangle>)"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   379
proof(unfold post_del_def, safe del: disjCI)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   380
  let ?t = "\<langle>lv, l, a, r\<rangle>"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   381
  let ?t' = "adjust \<langle>lv, l, a, r'\<rangle>"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   382
  show "invar ?t'" by(rule invar_adjust[OF assms(2)])
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   383
  show "lvl ?t' = lvl ?t \<or> lvl ?t' + 1 = lvl ?t"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   384
    using lvl_adjust[OF assms(2)] by auto
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   385
  show "sngl ?t'" if as: "lvl ?t' = lvl ?t" "sngl ?t"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   386
  proof -
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   387
    have s: "sngl \<langle>lv, l, a, r'\<rangle>"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   388
    proof(cases r')
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   389
      case Leaf thus ?thesis by simp
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   390
    next
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   391
      case Node thus ?thesis using as(2) assms(1,3)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   392
      by (cases r) (auto simp: post_del_def)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   393
    qed
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   394
    show ?thesis using as(1) sngl_adjust[OF assms(2) s] by simp
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   395
  qed
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   396
qed
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   397
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   398
declare prod.splits[split]
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   399
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   400
theorem post_del_max:
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   401
 "\<lbrakk> invar t; (t', x) = del_max t; t \<noteq> Leaf \<rbrakk> \<Longrightarrow> post_del t t'"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   402
proof (induction t arbitrary: t' rule: del_max.induct)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   403
  case (2 lv l a lvr rl ra rr)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   404
  let ?r =  "\<langle>lvr, rl, ra, rr\<rangle>"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   405
  let ?t = "\<langle>lv, l, a, ?r\<rangle>"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   406
  from "2.prems"(2) obtain r' where r': "(r', x) = del_max ?r"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   407
    and [simp]: "t' = adjust \<langle>lv, l, a, r'\<rangle>" by auto
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   408
  from  "2.IH"[OF _ r'] \<open>invar ?t\<close> have post: "post_del ?r r'" by simp
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   409
  note preR = pre_adj_if_postR[OF \<open>invar ?t\<close> post]
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   410
  show ?case by (simp add: post_del_adjR[OF "2.prems"(1) preR post])
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   411
qed (auto simp: post_del_def)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   412
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   413
theorem post_delete: "invar t \<Longrightarrow> post_del t (delete x t)"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   414
proof (induction t)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   415
  case (Node lv l a r)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   416
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   417
  let ?l' = "delete x l" and ?r' = "delete x r"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   418
  let ?t = "Node lv l a r" let ?t' = "delete x ?t"
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   419
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   420
  from Node.prems have inv_l: "invar l" and inv_r: "invar r" by (auto)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   421
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   422
  note post_l' = Node.IH(1)[OF inv_l]
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   423
  note preL = pre_adj_if_postL[OF Node.prems post_l']
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   424
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   425
  note post_r' = Node.IH(2)[OF inv_r]
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   426
  note preR = pre_adj_if_postR[OF Node.prems post_r']
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   427
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   428
  show ?case
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   429
  proof (cases rule: linorder_cases[of x a])
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   430
    case less
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   431
    thus ?thesis using Node.prems by (simp add: post_del_adjL preL)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   432
  next
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   433
    case greater
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   434
    thus ?thesis using Node.prems by (simp add: post_del_adjR preR post_r')
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   435
  next
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   436
    case equal
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   437
    show ?thesis
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   438
    proof cases
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   439
      assume "l = Leaf" thus ?thesis using equal Node.prems
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   440
        by(auto simp: post_del_def invar.simps(2))
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   441
    next
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   442
      assume "l \<noteq> Leaf" thus ?thesis using equal
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   443
        by simp (metis Node.prems inv_l post_del_adjL post_del_max pre_adj_if_postL)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   444
    qed
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   445
  qed
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   446
qed (simp add: post_del_def)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   447
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   448
declare invar_2Nodes[simp del]
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   449
61793
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
   450
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
   451
subsection "Functional Correctness"
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
   452
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   453
61793
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
   454
subsubsection "Proofs for insert"
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
   455
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
   456
lemma inorder_split: "inorder(split t) = inorder t"
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
   457
by(cases t rule: split.cases) (auto)
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
   458
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
   459
lemma inorder_skew: "inorder(skew t) = inorder t"
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
   460
by(cases t rule: skew.cases) (auto)
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
   461
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
   462
lemma inorder_insert:
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
   463
  "sorted(inorder t) \<Longrightarrow> inorder(insert x t) = ins_list x (inorder t)"
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
   464
by(induction t) (auto simp: ins_list_simps inorder_split inorder_skew)
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
   465
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   466
61793
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
   467
subsubsection "Proofs for delete"
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
   468
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   469
lemma inorder_adjust: "t \<noteq> Leaf \<Longrightarrow> pre_adjust t \<Longrightarrow> inorder(adjust t) = inorder t"
62526
nipkow
parents: 62496
diff changeset
   470
by(cases t)
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   471
  (auto simp: adjust_def inorder_skew inorder_split invar.simps(2) pre_adjust.simps
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   472
     split: tree.splits)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   473
61793
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
   474
lemma del_maxD:
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   475
  "\<lbrakk> del_max t = (t',x); t \<noteq> Leaf; invar t \<rbrakk> \<Longrightarrow> inorder t' @ [x] = inorder t"
61793
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
   476
by(induction t arbitrary: t' rule: del_max.induct)
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   477
  (auto simp: sorted_lems inorder_adjust pre_adj_if_postR post_del_max split: prod.splits)
61793
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
   478
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
   479
lemma inorder_delete:
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   480
  "invar t \<Longrightarrow> sorted(inorder t) \<Longrightarrow> inorder(delete x t) = del_list x (inorder t)"
61793
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
   481
by(induction t)
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   482
  (auto simp: del_list_simps inorder_adjust pre_adj_if_postL pre_adj_if_postR 
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   483
              post_del_max post_delete del_maxD split: prod.splits)
61793
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
   484
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   485
interpretation I: Set_by_Ordered
61793
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
   486
where empty = Leaf and isin = isin and insert = insert and delete = delete
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   487
and inorder = inorder and inv = invar
61793
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
   488
proof (standard, goal_cases)
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
   489
  case 1 show ?case by simp
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
   490
next
67967
5a4280946a25 moved and renamed lemmas
nipkow
parents: 67613
diff changeset
   491
  case 2 thus ?case by(simp add: isin_set_inorder)
61793
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
   492
next
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
   493
  case 3 thus ?case by(simp add: inorder_insert)
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
   494
next
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
   495
  case 4 thus ?case by(simp add: inorder_delete)
62496
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   496
next
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   497
  case 5 thus ?case by(simp)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   498
next
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   499
  case 6 thus ?case by(simp add: invar_insert)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   500
next
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   501
  case 7 thus ?case using post_delete by(auto simp: post_del_def)
f187aaf602c4 added invariant proofs to AA trees
nipkow
parents: 62390
diff changeset
   502
qed
61793
4c9e1e5a240e added AA trees
nipkow
parents:
diff changeset
   503
62390
842917225d56 more canonical names
nipkow
parents: 62160
diff changeset
   504
end