author nipkow Mon Apr 23 08:09:50 2018 +0200 (13 months ago) changeset 68023 75130777ece4 parent 68022 c8a506be83bd child 68024 b5e29bf0aeab
del_max -> split_max
 src/HOL/Data_Structures/AA_Map.thy file | annotate | diff | revisions src/HOL/Data_Structures/AA_Set.thy file | annotate | diff | revisions src/HOL/Data_Structures/AVL_Map.thy file | annotate | diff | revisions src/HOL/Data_Structures/AVL_Set.thy file | annotate | diff | revisions
```     1.1 --- a/src/HOL/Data_Structures/AA_Map.thy	Sun Apr 22 21:05:14 2018 +0100
1.2 +++ b/src/HOL/Data_Structures/AA_Map.thy	Mon Apr 23 08:09:50 2018 +0200
1.3 @@ -23,7 +23,7 @@
1.4       LT \<Rightarrow> adjust (Node lv (delete x l) (a,b) r) |
1.5       GT \<Rightarrow> adjust (Node lv l (a,b) (delete x r)) |
1.6       EQ \<Rightarrow> (if l = Leaf then r
1.7 -            else let (l',ab') = del_max l in adjust (Node lv l' ab' r)))"
1.8 +            else let (l',ab') = split_max l in adjust (Node lv l' ab' r)))"
1.9
1.10
1.11  subsection "Invariance"
1.12 @@ -187,7 +187,7 @@
1.13          by(auto simp: post_del_def invar.simps(2))
1.14      next
1.15        assume "l \<noteq> Leaf" thus ?thesis using equal Node.prems
1.18      qed
1.19    qed
1.21 @@ -204,7 +204,7 @@
1.22    inorder (delete x t) = del_list x (inorder t)"
1.23  by(induction t)
1.25 -              post_del_max post_delete del_maxD split: prod.splits)
1.26 +              post_split_max post_delete split_maxD split: prod.splits)
1.27
1.28  interpretation I: Map_by_Ordered
1.29  where empty = Leaf and lookup = lookup and update = update and delete = delete
```
```     2.1 --- a/src/HOL/Data_Structures/AA_Set.thy	Sun Apr 22 21:05:14 2018 +0100
2.2 +++ b/src/HOL/Data_Structures/AA_Set.thy	Mon Apr 23 08:09:50 2018 +0200
2.3 @@ -72,14 +72,14 @@
2.4  text\<open>In the paper, the last case of @{const adjust} is expressed with the help of an
2.5  incorrect auxiliary function \texttt{nlvl}.
2.6
2.7 -Function @{text del_max} below is called \texttt{dellrg} in the paper.
2.8 +Function @{text split_max} below is called \texttt{dellrg} in the paper.
2.9  The latter is incorrect for two reasons: \texttt{dellrg} is meant to delete the largest
2.10  element but recurses on the left instead of the right subtree; the invariant
2.11  is not restored.\<close>
2.12
2.13 -fun del_max :: "'a aa_tree \<Rightarrow> 'a aa_tree * 'a" where
2.14 -"del_max (Node lv l a Leaf) = (l,a)" |
2.15 -"del_max (Node lv l a r) = (let (r',b) = del_max r in (adjust(Node lv l a r'), b))"
2.16 +fun split_max :: "'a aa_tree \<Rightarrow> 'a aa_tree * 'a" where
2.17 +"split_max (Node lv l a Leaf) = (l,a)" |
2.18 +"split_max (Node lv l a r) = (let (r',b) = split_max r in (adjust(Node lv l a r'), b))"
2.19
2.20  fun delete :: "'a::linorder \<Rightarrow> 'a aa_tree \<Rightarrow> 'a aa_tree" where
2.21  "delete _ Leaf = Leaf" |
2.22 @@ -88,7 +88,7 @@
2.23       LT \<Rightarrow> adjust (Node lv (delete x l) a r) |
2.24       GT \<Rightarrow> adjust (Node lv l a (delete x r)) |
2.25       EQ \<Rightarrow> (if l = Leaf then r
2.26 -            else let (l',b) = del_max l in adjust (Node lv l' b r)))"
2.27 +            else let (l',b) = split_max l in adjust (Node lv l' b r)))"
2.28
2.30  "pre_adjust (Node lv l a r) = (invar l \<and> invar r \<and>
2.31 @@ -397,13 +397,13 @@
2.32
2.33  declare prod.splits[split]
2.34
2.35 -theorem post_del_max:
2.36 - "\<lbrakk> invar t; (t', x) = del_max t; t \<noteq> Leaf \<rbrakk> \<Longrightarrow> post_del t t'"
2.37 -proof (induction t arbitrary: t' rule: del_max.induct)
2.38 +theorem post_split_max:
2.39 + "\<lbrakk> invar t; (t', x) = split_max t; t \<noteq> Leaf \<rbrakk> \<Longrightarrow> post_del t t'"
2.40 +proof (induction t arbitrary: t' rule: split_max.induct)
2.41    case (2 lv l a lvr rl ra rr)
2.42    let ?r =  "\<langle>lvr, rl, ra, rr\<rangle>"
2.43    let ?t = "\<langle>lv, l, a, ?r\<rangle>"
2.44 -  from "2.prems"(2) obtain r' where r': "(r', x) = del_max ?r"
2.45 +  from "2.prems"(2) obtain r' where r': "(r', x) = split_max ?r"
2.46      and [simp]: "t' = adjust \<langle>lv, l, a, r'\<rangle>" by auto
2.47    from  "2.IH"[OF _ r'] \<open>invar ?t\<close> have post: "post_del ?r r'" by simp
2.48    note preR = pre_adj_if_postR[OF \<open>invar ?t\<close> post]
2.49 @@ -440,7 +440,7 @@
2.50          by(auto simp: post_del_def invar.simps(2))
2.51      next
2.52        assume "l \<noteq> Leaf" thus ?thesis using equal
2.55      qed
2.56    qed
2.58 @@ -471,16 +471,16 @@
2.60       split: tree.splits)
2.61
2.62 -lemma del_maxD:
2.63 -  "\<lbrakk> del_max t = (t',x); t \<noteq> Leaf; invar t \<rbrakk> \<Longrightarrow> inorder t' @ [x] = inorder t"
2.64 -by(induction t arbitrary: t' rule: del_max.induct)
2.66 +lemma split_maxD:
2.67 +  "\<lbrakk> split_max t = (t',x); t \<noteq> Leaf; invar t \<rbrakk> \<Longrightarrow> inorder t' @ [x] = inorder t"
2.68 +by(induction t arbitrary: t' rule: split_max.induct)
2.70
2.71  lemma inorder_delete:
2.72    "invar t \<Longrightarrow> sorted(inorder t) \<Longrightarrow> inorder(delete x t) = del_list x (inorder t)"
2.73  by(induction t)
2.75 -              post_del_max post_delete del_maxD split: prod.splits)
2.76 +              post_split_max post_delete split_maxD split: prod.splits)
2.77
2.78  interpretation I: Set_by_Ordered
2.79  where empty = Leaf and isin = isin and insert = insert and delete = delete
```
```     3.1 --- a/src/HOL/Data_Structures/AVL_Map.thy	Sun Apr 22 21:05:14 2018 +0100
3.2 +++ b/src/HOL/Data_Structures/AVL_Map.thy	Mon Apr 23 08:09:50 2018 +0200
3.3 @@ -34,7 +34,7 @@
3.4    "sorted1(inorder t) \<Longrightarrow> inorder (delete x t) = del_list x (inorder t)"
3.5  by(induction t)
3.6    (auto simp: del_list_simps inorder_balL inorder_balR
3.7 -     inorder_del_root inorder_del_maxD split: prod.splits)
3.8 +     inorder_del_root inorder_split_maxD split: prod.splits)
3.9
3.10  interpretation Map_by_Ordered
3.11  where empty = Leaf and lookup = lookup and update = update and delete = delete
```
```     4.1 --- a/src/HOL/Data_Structures/AVL_Set.thy	Sun Apr 22 21:05:14 2018 +0100
4.2 +++ b/src/HOL/Data_Structures/AVL_Set.thy	Mon Apr 23 08:09:50 2018 +0200
4.3 @@ -58,16 +58,16 @@
4.4     LT \<Rightarrow> balL (insert x l) a r |
4.5     GT \<Rightarrow> balR l a (insert x r))"
4.6
4.7 -fun del_max :: "'a avl_tree \<Rightarrow> 'a avl_tree * 'a" where
4.8 -"del_max (Node _ l a r) =
4.9 -  (if r = Leaf then (l,a) else let (r',a') = del_max r in (balL l a r', a'))"
4.10 +fun split_max :: "'a avl_tree \<Rightarrow> 'a avl_tree * 'a" where
4.11 +"split_max (Node _ l a r) =
4.12 +  (if r = Leaf then (l,a) else let (r',a') = split_max r in (balL l a r', a'))"
4.13
4.14 -lemmas del_max_induct = del_max.induct[case_names Node Leaf]
4.15 +lemmas split_max_induct = split_max.induct[case_names Node Leaf]
4.16
4.17  fun del_root :: "'a avl_tree \<Rightarrow> 'a avl_tree" where
4.18  "del_root (Node h Leaf a r) = r" |
4.19  "del_root (Node h l a Leaf) = l" |
4.20 -"del_root (Node h l a r) = (let (l', a') = del_max l in balR l' a' r)"
4.21 +"del_root (Node h l a r) = (let (l', a') = split_max l in balR l' a' r)"
4.22
4.23  lemmas del_root_cases = del_root.cases[case_names Leaf_t Node_Leaf Node_Node]
4.24
4.25 @@ -103,22 +103,22 @@
4.26
4.27  subsubsection "Proofs for delete"
4.28
4.29 -lemma inorder_del_maxD:
4.30 -  "\<lbrakk> del_max t = (t',a); t \<noteq> Leaf \<rbrakk> \<Longrightarrow>
4.31 +lemma inorder_split_maxD:
4.32 +  "\<lbrakk> split_max t = (t',a); t \<noteq> Leaf \<rbrakk> \<Longrightarrow>
4.33     inorder t' @ [a] = inorder t"
4.34 -by(induction t arbitrary: t' rule: del_max.induct)
4.35 +by(induction t arbitrary: t' rule: split_max.induct)
4.36    (auto simp: inorder_balL split: if_splits prod.splits tree.split)
4.37
4.38  lemma inorder_del_root:
4.39    "inorder (del_root (Node h l a r)) = inorder l @ inorder r"
4.40  by(cases "Node h l a r" rule: del_root.cases)
4.41 -  (auto simp: inorder_balL inorder_balR inorder_del_maxD split: if_splits prod.splits)
4.42 +  (auto simp: inorder_balL inorder_balR inorder_split_maxD split: if_splits prod.splits)
4.43
4.44  theorem inorder_delete:
4.45    "sorted(inorder t) \<Longrightarrow> inorder (delete x t) = del_list x (inorder t)"
4.46  by(induction t)
4.47    (auto simp: del_list_simps inorder_balL inorder_balR
4.48 -    inorder_del_root inorder_del_maxD split: prod.splits)
4.49 +    inorder_del_root inorder_split_maxD split: prod.splits)
4.50
4.51
4.52  subsubsection "Overall functional correctness"
4.53 @@ -301,12 +301,12 @@
4.54
4.55  subsubsection \<open>Deletion maintains AVL balance\<close>
4.56
4.57 -lemma avl_del_max:
4.58 +lemma avl_split_max:
4.59    assumes "avl x" and "x \<noteq> Leaf"
4.60 -  shows "avl (fst (del_max x))" "height x = height(fst (del_max x)) \<or>
4.61 -         height x = height(fst (del_max x)) + 1"
4.62 +  shows "avl (fst (split_max x))" "height x = height(fst (split_max x)) \<or>
4.63 +         height x = height(fst (split_max x)) + 1"
4.64  using assms
4.65 -proof (induct x rule: del_max_induct)
4.66 +proof (induct x rule: split_max_induct)
4.67    case (Node h l a r)
4.68    case 1
4.69    thus ?case using Node
4.70 @@ -316,7 +316,7 @@
4.71  next
4.72    case (Node h l a r)
4.73    case 2
4.74 -  let ?r' = "fst (del_max r)"
4.75 +  let ?r' = "fst (split_max r)"
4.76    from \<open>avl x\<close> Node 2 have "avl l" and "avl r" by simp_all
4.77    thus ?case using Node 2 height_balL[of l ?r' a] height_balL2[of l ?r' a]
4.78      apply (auto split:prod.splits simp del:avl.simps) by arith+
4.79 @@ -330,14 +330,14 @@
4.80    case (Node_Node h lh ll ln lr n rh rl rn rr)
4.81    let ?l = "Node lh ll ln lr"
4.82    let ?r = "Node rh rl rn rr"
4.83 -  let ?l' = "fst (del_max ?l)"
4.84 +  let ?l' = "fst (split_max ?l)"
4.85    from \<open>avl t\<close> and Node_Node have "avl ?r" by simp
4.86    from \<open>avl t\<close> and Node_Node have "avl ?l" by simp
4.87    hence "avl(?l')" "height ?l = height(?l') \<or>
4.88 -         height ?l = height(?l') + 1" by (rule avl_del_max,simp)+
4.89 +         height ?l = height(?l') + 1" by (rule avl_split_max,simp)+
4.90    with \<open>avl t\<close> Node_Node have "height ?l' = height ?r \<or> height ?l' = height ?r + 1
4.91              \<or> height ?r = height ?l' + 1 \<or> height ?r = height ?l' + 2" by fastforce
4.92 -  with \<open>avl ?l'\<close> \<open>avl ?r\<close> have "avl(balR ?l' (snd(del_max ?l)) ?r)"
4.93 +  with \<open>avl ?l'\<close> \<open>avl ?r\<close> have "avl(balR ?l' (snd(split_max ?l)) ?r)"
4.94      by (rule avl_balR)
4.95    with Node_Node show ?thesis by (auto split:prod.splits)
4.96  qed simp_all
4.97 @@ -350,12 +350,12 @@
4.98    case (Node_Node h lh ll ln lr n rh rl rn rr)
4.99    let ?l = "Node lh ll ln lr"
4.100    let ?r = "Node rh rl rn rr"
4.101 -  let ?l' = "fst (del_max ?l)"
4.102 -  let ?t' = "balR ?l' (snd(del_max ?l)) ?r"
4.103 +  let ?l' = "fst (split_max ?l)"
4.104 +  let ?t' = "balR ?l' (snd(split_max ?l)) ?r"
4.105    from \<open>avl t\<close> and Node_Node have "avl ?r" by simp
4.106    from \<open>avl t\<close> and Node_Node have "avl ?l" by simp
4.107 -  hence "avl(?l')"  by (rule avl_del_max,simp)
4.108 -  have l'_height: "height ?l = height ?l' \<or> height ?l = height ?l' + 1" using \<open>avl ?l\<close> by (intro avl_del_max) auto
4.109 +  hence "avl(?l')"  by (rule avl_split_max,simp)
4.110 +  have l'_height: "height ?l = height ?l' \<or> height ?l = height ?l' + 1" using \<open>avl ?l\<close> by (intro avl_split_max) auto
4.111    have t_height: "height t = 1 + max (height ?l) (height ?r)" using \<open>avl t\<close> Node_Node by simp
4.112    have "height t = height ?t' \<or> height t = height ?t' + 1" using  \<open>avl t\<close> Node_Node
4.113    proof(cases "height ?r = height ?l' + 2")
4.114 @@ -364,7 +364,7 @@
4.115    next
4.116      case True
4.117      show ?thesis
4.118 -    proof(cases rule: disjE[OF height_balR[OF True \<open>avl ?l'\<close> \<open>avl ?r\<close>, of "snd (del_max ?l)"]])
4.119 +    proof(cases rule: disjE[OF height_balR[OF True \<open>avl ?l'\<close> \<open>avl ?r\<close>, of "snd (split_max ?l)"]])
4.120        case 1
4.121        thus ?thesis using l'_height t_height True by arith
4.122      next
```