src/HOL/Data_Structures/AA_Set.thy
changeset 67040 c1b87d15774a
parent 63636 6f38b7abb648
child 67369 7360fe6bb423
     1.1 --- a/src/HOL/Data_Structures/AA_Set.thy	Thu Nov 09 10:24:00 2017 +0100
     1.2 +++ b/src/HOL/Data_Structures/AA_Set.thy	Fri Nov 10 22:05:30 2017 +0100
     1.3 @@ -201,63 +201,61 @@
     1.4  
     1.5  lemma invar_insert: "invar t \<Longrightarrow> invar(insert a t)"
     1.6  proof(induction t)
     1.7 -  case (Node n l x r)
     1.8 +  case N: (Node n l x r)
     1.9    hence il: "invar l" and ir: "invar r" by auto
    1.10 -  note N = Node
    1.11 +  note iil = N.IH(1)[OF il]
    1.12 +  note iir = N.IH(2)[OF ir]
    1.13    let ?t = "Node n l x r"
    1.14    have "a < x \<or> a = x \<or> x < a" by auto
    1.15    moreover
    1.16 -  { assume "a < x"
    1.17 -    note iil = Node.IH(1)[OF il]
    1.18 -    have ?case
    1.19 -    proof (cases rule: lvl_insert[of a l])
    1.20 -      case (Same) thus ?thesis
    1.21 -        using \<open>a<x\<close> invar_NodeL[OF Node.prems iil Same]
    1.22 -        by (simp add: skew_invar split_invar del: invar.simps)
    1.23 +  have ?case if "a < x"
    1.24 +  proof (cases rule: lvl_insert[of a l])
    1.25 +    case (Same) thus ?thesis
    1.26 +      using \<open>a<x\<close> invar_NodeL[OF N.prems iil Same]
    1.27 +      by (simp add: skew_invar split_invar del: invar.simps)
    1.28 +  next
    1.29 +    case (Incr)
    1.30 +    then obtain t1 w t2 where ial[simp]: "insert a l = Node n t1 w t2"
    1.31 +      using N.prems by (auto simp: lvl_Suc_iff)
    1.32 +    have l12: "lvl t1 = lvl t2"
    1.33 +      by (metis Incr(1) ial lvl_insert_incr_iff tree.inject)
    1.34 +    have "insert a ?t = split(skew(Node n (insert a l) x r))"
    1.35 +      by(simp add: \<open>a<x\<close>)
    1.36 +    also have "skew(Node n (insert a l) x r) = Node n t1 w (Node n t2 x r)"
    1.37 +      by(simp)
    1.38 +    also have "invar(split \<dots>)"
    1.39 +    proof (cases r)
    1.40 +      case Leaf
    1.41 +      hence "l = Leaf" using N.prems by(auto simp: lvl_0_iff)
    1.42 +      thus ?thesis using Leaf ial by simp
    1.43      next
    1.44 -      case (Incr)
    1.45 -      then obtain t1 w t2 where ial[simp]: "insert a l = Node n t1 w t2"
    1.46 -        using Node.prems by (auto simp: lvl_Suc_iff)
    1.47 -      have l12: "lvl t1 = lvl t2"
    1.48 -        by (metis Incr(1) ial lvl_insert_incr_iff tree.inject)
    1.49 -      have "insert a ?t = split(skew(Node n (insert a l) x r))"
    1.50 -        by(simp add: \<open>a<x\<close>)
    1.51 -      also have "skew(Node n (insert a l) x r) = Node n t1 w (Node n t2 x r)"
    1.52 -        by(simp)
    1.53 -      also have "invar(split \<dots>)"
    1.54 -      proof (cases r)
    1.55 -        case Leaf
    1.56 -        hence "l = Leaf" using Node.prems by(auto simp: lvl_0_iff)
    1.57 -        thus ?thesis using Leaf ial by simp
    1.58 +      case [simp]: (Node m t3 y t4)
    1.59 +      show ?thesis (*using N(3) iil l12 by(auto)*)
    1.60 +      proof cases
    1.61 +        assume "m = n" thus ?thesis using N(3) iil by(auto)
    1.62        next
    1.63 -        case [simp]: (Node m t3 y t4)
    1.64 -        show ?thesis (*using N(3) iil l12 by(auto)*)
    1.65 -        proof cases
    1.66 -          assume "m = n" thus ?thesis using N(3) iil by(auto)
    1.67 -        next
    1.68 -          assume "m \<noteq> n" thus ?thesis using N(3) iil l12 by(auto)
    1.69 -        qed
    1.70 +        assume "m \<noteq> n" thus ?thesis using N(3) iil l12 by(auto)
    1.71        qed
    1.72 -      finally show ?thesis .
    1.73      qed
    1.74 -  }
    1.75 +    finally show ?thesis .
    1.76 +  qed
    1.77    moreover
    1.78 -  { assume "x < a"
    1.79 -    note iir = Node.IH(2)[OF ir]
    1.80 +  have ?case if "x < a"
    1.81 +  proof -
    1.82      from \<open>invar ?t\<close> have "n = lvl r \<or> n = lvl r + 1" by auto
    1.83 -    hence ?case
    1.84 +    thus ?case
    1.85      proof
    1.86        assume 0: "n = lvl r"
    1.87        have "insert a ?t = split(skew(Node n l x (insert a r)))"
    1.88          using \<open>a>x\<close> by(auto)
    1.89        also have "skew(Node n l x (insert a r)) = Node n l x (insert a r)"
    1.90 -        using Node.prems by(simp add: skew_case split: tree.split)
    1.91 +        using N.prems by(simp add: skew_case split: tree.split)
    1.92        also have "invar(split \<dots>)"
    1.93        proof -
    1.94          from lvl_insert_sngl[OF ir sngl_if_invar[OF \<open>invar ?t\<close> 0], of a]
    1.95          obtain t1 y t2 where iar: "insert a r = Node n t1 y t2"
    1.96 -          using Node.prems 0 by (auto simp: lvl_Suc_iff)
    1.97 -        from Node.prems iar 0 iir
    1.98 +          using N.prems 0 by (auto simp: lvl_Suc_iff)
    1.99 +        from N.prems iar 0 iir
   1.100          show ?thesis by (auto simp: split_case split: tree.splits)
   1.101        qed
   1.102        finally show ?thesis .
   1.103 @@ -267,7 +265,7 @@
   1.104        show ?thesis
   1.105        proof (cases rule: lvl_insert[of a r])
   1.106          case (Same)
   1.107 -        show ?thesis using \<open>x<a\<close> il ir invar_NodeR[OF Node.prems 1 iir Same]
   1.108 +        show ?thesis using \<open>x<a\<close> il ir invar_NodeR[OF N.prems 1 iir Same]
   1.109            by (auto simp add: skew_invar split_invar)
   1.110        next
   1.111          case (Incr)
   1.112 @@ -275,8 +273,9 @@
   1.113            by (auto simp add: skew_invar split_invar split: if_splits)
   1.114        qed
   1.115      qed
   1.116 -  }
   1.117 -  moreover { assume "a = x" hence ?case using Node.prems by auto }
   1.118 +  qed
   1.119 +  moreover
   1.120 +  have "a = x \<Longrightarrow> ?case" using N.prems by auto
   1.121    ultimately show ?case by blast
   1.122  qed simp
   1.123