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