src/HOL/Data_Structures/AVL_Set.thy
changeset 68023 75130777ece4
parent 67967 5a4280946a25
child 68313 56c57e91edf9
     1.1 --- a/src/HOL/Data_Structures/AVL_Set.thy	Sun Apr 22 21:05:14 2018 +0100
     1.2 +++ b/src/HOL/Data_Structures/AVL_Set.thy	Mon Apr 23 08:09:50 2018 +0200
     1.3 @@ -58,16 +58,16 @@
     1.4     LT \<Rightarrow> balL (insert x l) a r |
     1.5     GT \<Rightarrow> balR l a (insert x r))"
     1.6  
     1.7 -fun del_max :: "'a avl_tree \<Rightarrow> 'a avl_tree * 'a" where
     1.8 -"del_max (Node _ l a r) =
     1.9 -  (if r = Leaf then (l,a) else let (r',a') = del_max r in (balL l a r', a'))"
    1.10 +fun split_max :: "'a avl_tree \<Rightarrow> 'a avl_tree * 'a" where
    1.11 +"split_max (Node _ l a r) =
    1.12 +  (if r = Leaf then (l,a) else let (r',a') = split_max r in (balL l a r', a'))"
    1.13  
    1.14 -lemmas del_max_induct = del_max.induct[case_names Node Leaf]
    1.15 +lemmas split_max_induct = split_max.induct[case_names Node Leaf]
    1.16  
    1.17  fun del_root :: "'a avl_tree \<Rightarrow> 'a avl_tree" where
    1.18  "del_root (Node h Leaf a r) = r" |
    1.19  "del_root (Node h l a Leaf) = l" |
    1.20 -"del_root (Node h l a r) = (let (l', a') = del_max l in balR l' a' r)"
    1.21 +"del_root (Node h l a r) = (let (l', a') = split_max l in balR l' a' r)"
    1.22  
    1.23  lemmas del_root_cases = del_root.cases[case_names Leaf_t Node_Leaf Node_Node]
    1.24  
    1.25 @@ -103,22 +103,22 @@
    1.26  
    1.27  subsubsection "Proofs for delete"
    1.28  
    1.29 -lemma inorder_del_maxD:
    1.30 -  "\<lbrakk> del_max t = (t',a); t \<noteq> Leaf \<rbrakk> \<Longrightarrow>
    1.31 +lemma inorder_split_maxD:
    1.32 +  "\<lbrakk> split_max t = (t',a); t \<noteq> Leaf \<rbrakk> \<Longrightarrow>
    1.33     inorder t' @ [a] = inorder t"
    1.34 -by(induction t arbitrary: t' rule: del_max.induct)
    1.35 +by(induction t arbitrary: t' rule: split_max.induct)
    1.36    (auto simp: inorder_balL split: if_splits prod.splits tree.split)
    1.37  
    1.38  lemma inorder_del_root:
    1.39    "inorder (del_root (Node h l a r)) = inorder l @ inorder r"
    1.40  by(cases "Node h l a r" rule: del_root.cases)
    1.41 -  (auto simp: inorder_balL inorder_balR inorder_del_maxD split: if_splits prod.splits)
    1.42 +  (auto simp: inorder_balL inorder_balR inorder_split_maxD split: if_splits prod.splits)
    1.43  
    1.44  theorem inorder_delete:
    1.45    "sorted(inorder t) \<Longrightarrow> inorder (delete x t) = del_list x (inorder t)"
    1.46  by(induction t)
    1.47    (auto simp: del_list_simps inorder_balL inorder_balR
    1.48 -    inorder_del_root inorder_del_maxD split: prod.splits)
    1.49 +    inorder_del_root inorder_split_maxD split: prod.splits)
    1.50  
    1.51  
    1.52  subsubsection "Overall functional correctness"
    1.53 @@ -301,12 +301,12 @@
    1.54  
    1.55  subsubsection \<open>Deletion maintains AVL balance\<close>
    1.56  
    1.57 -lemma avl_del_max:
    1.58 +lemma avl_split_max:
    1.59    assumes "avl x" and "x \<noteq> Leaf"
    1.60 -  shows "avl (fst (del_max x))" "height x = height(fst (del_max x)) \<or>
    1.61 -         height x = height(fst (del_max x)) + 1"
    1.62 +  shows "avl (fst (split_max x))" "height x = height(fst (split_max x)) \<or>
    1.63 +         height x = height(fst (split_max x)) + 1"
    1.64  using assms
    1.65 -proof (induct x rule: del_max_induct)
    1.66 +proof (induct x rule: split_max_induct)
    1.67    case (Node h l a r)
    1.68    case 1
    1.69    thus ?case using Node
    1.70 @@ -316,7 +316,7 @@
    1.71  next
    1.72    case (Node h l a r)
    1.73    case 2
    1.74 -  let ?r' = "fst (del_max r)"
    1.75 +  let ?r' = "fst (split_max r)"
    1.76    from \<open>avl x\<close> Node 2 have "avl l" and "avl r" by simp_all
    1.77    thus ?case using Node 2 height_balL[of l ?r' a] height_balL2[of l ?r' a]
    1.78      apply (auto split:prod.splits simp del:avl.simps) by arith+
    1.79 @@ -330,14 +330,14 @@
    1.80    case (Node_Node h lh ll ln lr n rh rl rn rr)
    1.81    let ?l = "Node lh ll ln lr"
    1.82    let ?r = "Node rh rl rn rr"
    1.83 -  let ?l' = "fst (del_max ?l)"
    1.84 +  let ?l' = "fst (split_max ?l)"
    1.85    from \<open>avl t\<close> and Node_Node have "avl ?r" by simp
    1.86    from \<open>avl t\<close> and Node_Node have "avl ?l" by simp
    1.87    hence "avl(?l')" "height ?l = height(?l') \<or>
    1.88 -         height ?l = height(?l') + 1" by (rule avl_del_max,simp)+
    1.89 +         height ?l = height(?l') + 1" by (rule avl_split_max,simp)+
    1.90    with \<open>avl t\<close> Node_Node have "height ?l' = height ?r \<or> height ?l' = height ?r + 1
    1.91              \<or> height ?r = height ?l' + 1 \<or> height ?r = height ?l' + 2" by fastforce
    1.92 -  with \<open>avl ?l'\<close> \<open>avl ?r\<close> have "avl(balR ?l' (snd(del_max ?l)) ?r)"
    1.93 +  with \<open>avl ?l'\<close> \<open>avl ?r\<close> have "avl(balR ?l' (snd(split_max ?l)) ?r)"
    1.94      by (rule avl_balR)
    1.95    with Node_Node show ?thesis by (auto split:prod.splits)
    1.96  qed simp_all
    1.97 @@ -350,12 +350,12 @@
    1.98    case (Node_Node h lh ll ln lr n rh rl rn rr)
    1.99    let ?l = "Node lh ll ln lr"
   1.100    let ?r = "Node rh rl rn rr"
   1.101 -  let ?l' = "fst (del_max ?l)"
   1.102 -  let ?t' = "balR ?l' (snd(del_max ?l)) ?r"
   1.103 +  let ?l' = "fst (split_max ?l)"
   1.104 +  let ?t' = "balR ?l' (snd(split_max ?l)) ?r"
   1.105    from \<open>avl t\<close> and Node_Node have "avl ?r" by simp
   1.106    from \<open>avl t\<close> and Node_Node have "avl ?l" by simp
   1.107 -  hence "avl(?l')"  by (rule avl_del_max,simp)
   1.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
   1.109 +  hence "avl(?l')"  by (rule avl_split_max,simp)
   1.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
   1.111    have t_height: "height t = 1 + max (height ?l) (height ?r)" using \<open>avl t\<close> Node_Node by simp
   1.112    have "height t = height ?t' \<or> height t = height ?t' + 1" using  \<open>avl t\<close> Node_Node
   1.113    proof(cases "height ?r = height ?l' + 2")
   1.114 @@ -364,7 +364,7 @@
   1.115    next
   1.116      case True
   1.117      show ?thesis
   1.118 -    proof(cases rule: disjE[OF height_balR[OF True \<open>avl ?l'\<close> \<open>avl ?r\<close>, of "snd (del_max ?l)"]])
   1.119 +    proof(cases rule: disjE[OF height_balR[OF True \<open>avl ?l'\<close> \<open>avl ?r\<close>, of "snd (split_max ?l)"]])
   1.120        case 1
   1.121        thus ?thesis using l'_height t_height True by arith
   1.122      next