(* ========================================================================= *)
(*                FLYSPECK - BOOK FORMALIZATION                              *)
(*                                                                           *)
(*      Authour   : VU KHAC KY                                               *)
(*      Book lemma: GRUTOTI                                                  *)
(*      Chaper    : Packing                                                  *)
(*                                                                           *)
(* ========================================================================= *)
(*                                                                           *)
(* flyspeck_needs "packing/marchal_cells_3.hl";;                             *)
(*                                                                           *)
(* ========================================================================= *)

let GRUTOTI1_concl = 
`!V u0 u1 e.
     saturated V /\
     packing V /\
     u0 IN V /\
     u1 IN V /\
     ~(u0 = u1) /\
     hl [u0;u1] < sqrt (&2) /\
     e = {u0, u1}
     ==> sum {X | mcell_set V X /\ e IN edgeX V X } (\t. dihX V t (u0,u1)) =
         &2 * pi`;;

let GRUTOTI = prove_by_refinement (GRUTOTI1_concl,
[(REPEAT STRIP_TAC);
 (NEW_GOAL `barV V 1 [u0;u1:real^3]`);
 (MATCH_MP_TAC HL_LE_SQRT2_IMP_BARV_1);
 (ASM_REWRITE_TAC[]);
 (NEW_GOAL 
  `{k | k IN 1..3 /\
        voronoi_list V [u0;u1:real^3] =
        UNIONS
          {convex hull
          ({omega_list_n V vl i | i IN 1..k - 1} UNION
            voronoi_list V vl) | vl | barV V k vl /\
                                      truncate_simplex 1 vl = [u0;u1]}} =
             1..3`);
 (MATCH_MP_TAC Rogers.GLTVHUM_lemma1);
 (ASM_REWRITE_TAC[] THEN ARITH_TAC);
 (NEW_GOAL 
 `3 IN {k | k IN 1..3 /\
          voronoi_list V [u0; u1] =
          UNIONS
          {convex hull
         ({omega_list_n V vl i | i IN 1..k - 1} UNION voronoi_list V vl) | vl | 
          barV V k vl /\
          truncate_simplex 1 vl = [u0; u1]}}`);
 (ASM_REWRITE_TAC[IN_NUMSEG] THEN ARITH_TAC);
 (UP_ASM_TAC THEN ONCE_REWRITE_TAC[IN] THEN REWRITE_TAC[IN_ELIM_THM]);
 (REWRITE_WITH 
   `UNIONS
   {convex hull ({omega_list_n V vl i | i IN 1..3 - 1} UNION voronoi_list V vl)      | vl | barV V 3 vl /\
           truncate_simplex 1 vl = [u0; u1]} = 
   UNIONS {convex hull {omega_list_n V vl 1, omega_list_n V vl 2, 
           omega_list_n V vl 3} | vl | barV V 3 vl /\
                                       truncate_simplex 1 vl = [u0; u1]}`);
 (ONCE_REWRITE_TAC[SET_EQ_LEMMA]);
 (REWRITE_TAC[IN_UNIONS] THEN ONCE_REWRITE_TAC[IN] THEN 
   REWRITE_TAC[IN_ELIM_THM]);
 (REPEAT STRIP_TAC);
 (EXISTS_TAC `t:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (EXISTS_TAC `vl:(real^3)list`);
 (ASM_REWRITE_TAC[]);
 (NEW_GOAL `?a. voronoi_list V vl = {a} /\
                    a = circumcenter (set_of_list vl) /\
                    hl vl = dist (HD vl,a)`);
 (MATCH_MP_TAC Marchal_cells_2_new.VORONOI_LIST_3_SINGLETON_EXPLICIT);
 (ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);

 (NEW_GOAL `omega_list_n V vl 3 IN voronoi_list V vl`);
 (REWRITE_WITH `omega_list_n V vl 3 = omega_list V vl`);
 (REWRITE_TAC[OMEGA_LIST]);
 (REWRITE_WITH `LENGTH (vl:(real^3)list) = 3 + 1 /\ 
                 CARD (set_of_list vl) = 3 + 1`);
 (MATCH_MP_TAC Rogers.BARV_IMP_LENGTH_EQ_CARD);
 (EXISTS_TAC `V:real^3->bool`);
 (ASM_REWRITE_TAC[]);
 (REWRITE_TAC[ARITH_RULE `(3 + 1) - 1 = 3`]);
 (MATCH_MP_TAC Packing3.OMEGA_LIST_IN_VORONOI_LIST);
 (EXISTS_TAC `3` THEN ASM_REWRITE_TAC[]);
 (NEW_GOAL `omega_list_n V vl 3 = a`);
 (ASM_SET_TAC[]);
 (ASM_REWRITE_TAC[]);
 (REWRITE_TAC[ARITH_RULE `3 - 1 = 2`; IN_NUMSEG; 
   ARITH_RULE `1 <= i /\ i <= 2 <=> i = 1 \/ i = 2`]);
 (REWRITE_WITH `{omega_list_n V vl i | i = 1 \/ i = 2} = 
                 {omega_list_n V vl 1,omega_list_n V vl 2}`);
 (SET_TAC[]);
 (REWRITE_WITH `{omega_list_n V vl 1, omega_list_n V vl 2} UNION
   {circumcenter (set_of_list vl)} = {omega_list_n V vl 1, omega_list_n V vl 2,      circumcenter (set_of_list vl)}`);
 (SET_TAC[]);

 (EXISTS_TAC `t:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (EXISTS_TAC `vl:(real^3)list`);
 (ASM_REWRITE_TAC[]);
 (NEW_GOAL `?a. voronoi_list V vl = {a} /\
                    a = circumcenter (set_of_list vl) /\
                    hl vl = dist (HD vl,a)`);
 (MATCH_MP_TAC Marchal_cells_2_new.VORONOI_LIST_3_SINGLETON_EXPLICIT);
 (ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);

 (NEW_GOAL `omega_list_n V vl 3 IN voronoi_list V vl`);
 (REWRITE_WITH `omega_list_n V vl 3 = omega_list V vl`);
 (REWRITE_TAC[OMEGA_LIST]);
 (REWRITE_WITH `LENGTH (vl:(real^3)list) = 3 + 1 /\ 
                 CARD (set_of_list vl) = 3 + 1`);
 (MATCH_MP_TAC Rogers.BARV_IMP_LENGTH_EQ_CARD);
 (EXISTS_TAC `V:real^3->bool`);
 (ASM_REWRITE_TAC[]);
 (REWRITE_TAC[ARITH_RULE `(3 + 1) - 1 = 3`]);
 (MATCH_MP_TAC Packing3.OMEGA_LIST_IN_VORONOI_LIST);
 (EXISTS_TAC `3` THEN ASM_REWRITE_TAC[]);
 (NEW_GOAL `omega_list_n V vl 3 = a`);
 (ASM_SET_TAC[]);
 (ASM_REWRITE_TAC[]);
 (REWRITE_TAC[ARITH_RULE `3 - 1 = 2`; IN_NUMSEG; 
   ARITH_RULE `1 <= i /\ i <= 2 <=> i = 1 \/ i = 2`]);
 (REWRITE_WITH `{omega_list_n V vl i | i = 1 \/ i = 2} = 
                 {omega_list_n V vl 1,omega_list_n V vl 2}`);
 (SET_TAC[]);
 (REWRITE_WITH `{omega_list_n V vl 1, omega_list_n V vl 2} UNION
   {circumcenter (set_of_list vl)} = {omega_list_n V vl 1, omega_list_n V vl 2,
    circumcenter (set_of_list vl)}`);
 (SET_TAC[]);
 (STRIP_TAC);

(* ======================================================================= *)

 (ABBREV_TAC `p = circumcenter {u0, u1:real^3}`);
 (NEW_GOAL `aff_dim (u0 INSERT voronoi_list V [u0;u1]) = &3`);
 (REWRITE_TAC[AFF_DIM_INSERT]);
 (COND_CASES_TAC);
 (NEW_GOAL `F`);

 (NEW_GOAL `affine hull voronoi_list V [u0; u1] SUBSET 
   affine hull {x | &2 % (u0 - u1) dot x = norm u0 pow 2 - norm u1 pow 2}`);
 (MATCH_MP_TAC Marchal_cells_2_new.AFFINE_SUBSET_KY_LEMMA);
 (REWRITE_TAC[VORONOI_LIST; set_of_list; Packing3.VORONOI_SET_2]);
 (ONCE_REWRITE_TAC[SET_RULE `a INTER b = b INTER a`]);
 (ASM_SIMP_TAC[Pack2.INTER_VORONOI_SUBSET_BISECTOR]);
 (NEW_GOAL 
  `affine hull {x | &2 % (u0 - u1) dot x = norm u0 pow 2 - norm u1 pow 2} = 
   {x:real^3 | &2 % (u0 - u1) dot x = norm u0 pow 2 - norm u1 pow 2}`);
 (REWRITE_TAC[AFFINE_HULL_EQ]);
 (REWRITE_TAC[AFFINE_HYPERPLANE]);
 (NEW_GOAL 
 `~(u0 IN {x:real^3 | &2 % (u0 - u1) dot x = norm u0 pow 2 - norm u1 pow 2})`);
 (REWRITE_TAC[IN; IN_ELIM_THM; NORM_POW_2]);
 (ONCE_REWRITE_TAC [REAL_ARITH `a = b <=> a - b = &0`]);
 (REWRITE_TAC[VECTOR_ARITH `&2 % (u0 - u1) dot u0 - (u0 dot u0 - u1 dot u1) = 
                (u0 - u1) dot (u0 - u1)`]);
 (REWRITE_TAC[DOT_EQ_0] THEN ASM_NORM_ARITH_TAC);
 (ASM_SET_TAC[]);
 (ASM_MESON_TAC[]);
 (REWRITE_TAC[ARITH_RULE `a + &1 = b:int <=> a = b - &1`]);
 (MATCH_MP_TAC Packing3.AFF_DIM_VORONOI_LIST);
 (ASM_REWRITE_TAC[]);

 (NEW_GOAL `aff_dim (u0 INSERT voronoi_list V [u0; u1]) = &(dimindex (:3))`);
 (ASM_REWRITE_TAC[DIMINDEX_3]);
 (UP_ASM_TAC THEN REWRITE_TAC[AFF_DIM_EQ_FULL]);
 (STRIP_TAC);

 (ABBREV_TAC `S = voronoi_list V [u0;u1]`);
 (NEW_GOAL `!x. x IN S ==> (x - u0) dot (u1 - u0) = 
                            dist (p, u0) * dist (u1, u0:real^3)`);
 (REPEAT STRIP_TAC);
 (NEW_GOAL `p = inv (&2) % (u0 + (u1:real^3))`);
 (EXPAND_TAC "p" THEN REWRITE_TAC[Rogers.CIRCUMCENTER_2; midpoint]);
 (REWRITE_TAC[dist]);
 (REWRITE_WITH `u1 - u0 = &2 % (p - u0:real^3)`);
 (ASM_REWRITE_TAC[]);
 (VECTOR_ARITH_TAC);
 (REWRITE_TAC[NORM_MUL; REAL_ARITH `abs (&2) = &2`;
   REAL_ARITH `a * b * a = b * a pow 2`; NORM_POW_2; DOT_RMUL]);
 (REWRITE_WITH `(x - u0) dot (p - u0:real^3) = 
                 (p - u0) dot (p - u0) - (x - p) dot (u0 - p)`);
 (VECTOR_ARITH_TAC);
 (REWRITE_WITH `(x - p) dot (u0 - p:real^3) = &0`);
 (EXPAND_TAC "p");
 (REWRITE_WITH `{u0, u1} = set_of_list [u0; u1:real^3]`);
 (REWRITE_TAC[set_of_list]);
 (MATCH_MP_TAC Rogers.MHFTTZN4);
 (EXISTS_TAC `V:real^3->bool` THEN EXISTS_TAC `1`);
 (REPEAT STRIP_TAC);
 (ASM_REWRITE_TAC[]);
 (ASM_REWRITE_TAC[]);
 (NEW_GOAL `S SUBSET affine hull voronoi_list V [u0; u1]`);
 (EXPAND_TAC "S");
 (REWRITE_TAC[Qzksykg.SET_SUBSET_AFFINE_HULL]);
 (ASM_SET_TAC[]);
 (REWRITE_TAC[set_of_list]);
 (NEW_GOAL `{u0,u1} SUBSET affine hull {u0,u1:real^3}`);
 (REWRITE_TAC[Qzksykg.SET_SUBSET_AFFINE_HULL]);
 (ASM_SET_TAC[]);
 (REAL_ARITH_TAC);

(* ========================================================================= *)

 (ABBREV_TAC `S1 = {x:real^3 | &2 % (u0 - u1) dot x = 
                                norm u0 pow 2 - norm u1 pow 2}`);
 (ABBREV_TAC `S2:real^3->bool = (S1 DIFF (relative_interior S))`);
 (NEW_GOAL `closed_in (subtopology euclidean (S1:real^3->bool)) S2`);
 (EXPAND_TAC "S2");
 (MATCH_MP_TAC CLOSED_IN_DIFF);
 (STRIP_TAC);
 (NEW_GOAL `closed (S1:real^3->bool)`);
 (EXPAND_TAC "S1" THEN REWRITE_TAC[CLOSED_HYPERPLANE]);
 (MATCH_MP_TAC CLOSED_SUBSET);
 (ASM_REWRITE_TAC[] THEN SET_TAC[]);

 (REWRITE_WITH `S1 = affine hull (S:real^3->bool)`);
 (EXPAND_TAC "S");
 (NEW_GOAL `affine hull S1 = S1:real^3->bool`);
 (REWRITE_TAC[AFFINE_HULL_EQ]);
 (EXPAND_TAC "S1" THEN REWRITE_TAC[AFFINE_HYPERPLANE]);
 (ONCE_REWRITE_TAC[GSYM (ASSUME `affine hull S1 = S1:real^3->bool`)]);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC AFF_DIM_EQ_AFFINE_HULL);
 (STRIP_TAC);
 (REWRITE_TAC[VORONOI_LIST; VORONOI_SET; set_of_list; 
   SET_RULE `INTERS {f x | x IN {a, b}} = f a INTER f b`]);
 (DEL_TAC THEN EXPAND_TAC "S1");
 (MATCH_MP_TAC Pack2.INTER_VORONOI_SUBSET_BISECTOR);
 (ASM_REWRITE_TAC[]);
 (REWRITE_WITH `aff_dim (S1:(real^3->bool)) = &(dimindex (:3)) - &1`);
 (DEL_TAC THEN EXPAND_TAC "S1");
 (MATCH_MP_TAC AFF_DIM_HYPERPLANE);
 (REWRITE_TAC[VECTOR_ARITH `&2 % (s - t) = vec 0 <=> s = t`]);
 (ASM_REWRITE_TAC[]);
 (REWRITE_TAC[DIMINDEX_3]);
 (REWRITE_WITH `aff_dim (voronoi_list V [u0;u1:real^3]) = &3 - &1`);
 (MATCH_MP_TAC Packing3.AFF_DIM_VORONOI_LIST);
 (ASM_REWRITE_TAC[]);
 (ARITH_TAC);

 (REWRITE_TAC[OPEN_IN_RELATIVE_INTERIOR]);

 (NEW_GOAL `closed (S2:real^3->bool)`);
 (MATCH_MP_TAC CLOSED_IN_CLOSED_TRANS);
 (EXISTS_TAC `S1:real^3->bool`);
 (ASM_REWRITE_TAC[]);
 (EXPAND_TAC "S1");
 (REWRITE_TAC[CLOSED_HYPERPLANE]);


 (NEW_GOAL `~(S2:real^3->bool = {})`);
 (EXPAND_TAC "S2");
 (REWRITE_TAC [SET_RULE `A DIFF B = {} <=> A SUBSET B`]);
 (REPEAT STRIP_TAC);
 (NEW_GOAL `S1 SUBSET S:real^3->bool`);
 (NEW_GOAL `relative_interior S SUBSET S:real^3->bool`);
 (REWRITE_TAC[RELATIVE_INTERIOR_SUBSET]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN SET_TAC[]);

 (NEW_GOAL `S1 = S:real^3->bool`);
 (NEW_GOAL `S SUBSET S1:real^3->bool`);
 (EXPAND_TAC "S");
 (REWRITE_TAC[VORONOI_LIST; VORONOI_SET; set_of_list; 
   SET_RULE `INTERS {f x | x IN {a, b}} = f a INTER f b`]);
 (EXPAND_TAC "S1");
 (MATCH_MP_TAC Pack2.INTER_VORONOI_SUBSET_BISECTOR);
 (ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN SET_TAC[]);

 (NEW_GOAL `bounded (S1:real^3->bool)`);
 (REWRITE_TAC[ASSUME `S1 = S:real^3->bool`]);
 (DEL_TAC THEN EXPAND_TAC "S");
 (MATCH_MP_TAC Packing3.BOUNDED_VORONOI_LIST);
 (EXISTS_TAC `1`);
 (ASM_REWRITE_TAC[]);
 
 (NEW_GOAL `~bounded (S1:real^3->bool)`);
 (EXPAND_TAC "S1");
 (MATCH_MP_TAC UNBOUNDED_HYPERPLANE);
 (REWRITE_TAC[VECTOR_ARITH `&2 % (u0 - u1) = vec 0 <=> u0 = u1`]);
 (ASM_REWRITE_TAC[]);
 (ASM_MESON_TAC[]);

 (NEW_GOAL `?z:real^3. z IN S2 /\ 
                (!w. w IN S2 ==> dist (u0,z) <= dist (u0,w))`);
 (MATCH_MP_TAC DISTANCE_ATTAINS_INF);
 (ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);

(* ======================================================================== *)

 (ABBREV_TAC `a = dist (p, u0:real^3) / dist (z, u0)`);
 (NEW_GOAL `&0 < a /\ a < &1`);
 (EXPAND_TAC "a");
 (NEW_GOAL `~(u0:real^3 IN S1)`);
 (EXPAND_TAC "S1" THEN REWRITE_TAC[IN; IN_ELIM_THM; NORM_POW_2]);
 (REWRITE_TAC[REAL_ARITH `a = b - c <=> a + c - b = &0`]);
 (REWRITE_TAC[VECTOR_ARITH `&2 % (u0 - u1) dot u0 + u1 dot u1 - u0 dot u0 = 
  (u0 - u1) dot (u0 - u1)`]);
 (REWRITE_TAC[DOT_EQ_0; VECTOR_ARITH `a - b = vec 0 <=> a = b`]);
 (ASM_REWRITE_TAC[]);
 (NEW_GOAL `&0 < dist (p,u0:real^3)`);
 (MATCH_MP_TAC DIST_POS_LT);
 (EXPAND_TAC "p" THEN REWRITE_TAC[Rogers.CIRCUMCENTER_2; midpoint]);
 (REWRITE_TAC[VECTOR_ARITH `inv (&2) % (u0 + u1) = u0 <=> u0 = u1`]);
 (ASM_REWRITE_TAC[]);
 (NEW_GOAL `&0 < dist (z,u0:real^3)`);
 (MATCH_MP_TAC DIST_POS_LT);
 (STRIP_TAC);
 (NEW_GOAL `z:real^3 IN S1`);
 (ASM_SET_TAC[]);
 (ASM_MESON_TAC[]);
 (STRIP_TAC);
 (MATCH_MP_TAC REAL_LT_DIV);
 (ASM_REWRITE_TAC[]);
 (REWRITE_WITH 
  `dist (p,u0) / dist (z,u0:real^3) < &1 <=> dist (p,u0) < &1 * dist (z,u0)`);
 (ASM_SIMP_TAC[REAL_LT_LDIV_EQ]);
 (REWRITE_TAC[REAL_MUL_LID]);
 (MATCH_MP_TAC Tactics_jordan.REAL_POW_2_LT);
 (REPEAT STRIP_TAC);
 (ASM_REAL_ARITH_TAC);
 (ASM_REAL_ARITH_TAC);
 (REWRITE_TAC[dist]);
 (REWRITE_WITH `norm (z - u0:real^3) pow 2 = 
                 norm (p - u0) pow 2 + norm (z - p) pow 2`);
 (MATCH_MP_TAC PYTHAGORAS);
 (REWRITE_TAC[orthogonal]);
 (REWRITE_WITH `p = circumcenter (set_of_list [u0;u1:real^3])`);
 (ASM_REWRITE_TAC[set_of_list]);
 (ONCE_REWRITE_TAC[DOT_SYM]);
 (MATCH_MP_TAC Rogers.MHFTTZN4);
 (EXISTS_TAC `V:real^3->bool` THEN EXISTS_TAC `1`);
 (REPEAT STRIP_TAC);
 (ASM_REWRITE_TAC[]);
 (ASM_REWRITE_TAC[]);

 (REWRITE_TAC[ASSUME `voronoi_list V [u0; u1] = S`]);
 (REWRITE_WITH `affine hull (S:real^3->bool) = S1`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (EXPAND_TAC "S");
 (NEW_GOAL `affine hull S1 = S1:real^3->bool`);
 (REWRITE_TAC[AFFINE_HULL_EQ]);
 (EXPAND_TAC "S1" THEN REWRITE_TAC[AFFINE_HYPERPLANE]);
 (ONCE_REWRITE_TAC[GSYM (ASSUME `affine hull S1 = S1:real^3->bool`)]);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC AFF_DIM_EQ_AFFINE_HULL);
 (STRIP_TAC);
 (REWRITE_TAC[VORONOI_LIST; VORONOI_SET; set_of_list; 
   SET_RULE `INTERS {f x | x IN {a, b}} = f a INTER f b`]);
 (DEL_TAC THEN EXPAND_TAC "S1");
 (MATCH_MP_TAC Pack2.INTER_VORONOI_SUBSET_BISECTOR);
 (ASM_REWRITE_TAC[]);
 (REWRITE_WITH `aff_dim (S1:(real^3->bool)) = &(dimindex (:3)) - &1`);
 (DEL_TAC THEN EXPAND_TAC "S1");
 (MATCH_MP_TAC AFF_DIM_HYPERPLANE);
 (REWRITE_TAC[VECTOR_ARITH `&2 % (s - t) = vec 0 <=> s = t`]);
 (ASM_REWRITE_TAC[]);
 (REWRITE_TAC[DIMINDEX_3]);
 (REWRITE_WITH `aff_dim (voronoi_list V [u0;u1:real^3]) = &3 - &1`);
 (MATCH_MP_TAC Packing3.AFF_DIM_VORONOI_LIST);
 (ASM_REWRITE_TAC[]);
 (ARITH_TAC);
 (ASM_SET_TAC[]);
 (REWRITE_TAC[set_of_list]);
 (NEW_GOAL `{u0, u1:real^3} SUBSET affine hull {u0, u1}`);
 (REWRITE_TAC[Qzksykg.SET_SUBSET_AFFINE_HULL]);
 (ASM_SET_TAC[]);
 (REWRITE_TAC[REAL_ARITH `a < a + b <=> &0 < b`; NORM_POW_2; DOT_POS_LT]);
 (REWRITE_TAC[VECTOR_ARITH `a - b = vec 0 <=> a = b`]);
 (STRIP_TAC);
 (NEW_GOAL `~(z:real^3 IN S2)`);
 (REWRITE_TAC[ASSUME `z = p:real^3`]);
 (EXPAND_TAC "S2");
 (NEW_GOAL `p:real^3 IN relative_interior S`);



 (ABBREV_TAC `B = V INTER ball (p:real^3, &8)`);
 (ABBREV_TAC `A = B DIFF {u0, u1:real^3}`);
 (NEW_GOAL `FINITE (A:real^3->bool)`);
 (EXPAND_TAC "A");
 (MATCH_MP_TAC FINITE_DIFF);
 (EXPAND_TAC "B");
 (MATCH_MP_TAC Packing3.KIUMVTC THEN ASM_REWRITE_TAC[]);
 (NEW_GOAL `?y. dist (p,y:real^3) = &4`);
 (MATCH_MP_TAC VECTOR_CHOOSE_DIST);
 (REAL_ARITH_TAC);
 (UP_ASM_TAC THEN STRIP_TAC);
 (UNDISCH_TAC `saturated (V:real^3->bool)`);
 (REWRITE_TAC[saturated] THEN STRIP_TAC);
 (NEW_GOAL `?z. z IN V /\ dist (y:real^3, z) < &2`);
 (ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);

 (NEW_GOAL `z':real^3 IN A`);
 (EXPAND_TAC "A" THEN EXPAND_TAC "B");
 (REWRITE_TAC[IN_DIFF; IN_INTER; IN_BALL]);
 (REPEAT STRIP_TAC);
 (ASM_REWRITE_TAC[]);

 (NEW_GOAL `dist (p,z') <= dist (p, y) + dist (y, z':real^3)`);
 (REWRITE_TAC[DIST_TRIANGLE]);
 (ASM_REAL_ARITH_TAC);
 (NEW_GOAL `dist (p, y) <= dist (p, z') + dist (z', y:real^3)`);
 (REWRITE_TAC[DIST_TRIANGLE]);
 (UP_ASM_TAC THEN ASM_REWRITE_TAC[] THEN ONCE_REWRITE_TAC[DIST_SYM]);
 (STRIP_TAC);
 (NEW_GOAL `&2 < dist (z', p:real^3)`);
 (ASM_REAL_ARITH_TAC);
 (UP_ASM_TAC THEN REWRITE_TAC[] THEN ONCE_REWRITE_TAC[DIST_SYM]);
 (REWRITE_WITH `p = circumcenter (set_of_list [u0;u1:real^3])`);
 (ASM_MESON_TAC[set_of_list]);
 (NEW_GOAL `(!w. w IN set_of_list [u0;u1:real^3]
               ==> dist (circumcenter (set_of_list [u0;u1]),w) = hl [u0;u1])`);
 (MATCH_MP_TAC Rogers.HL_PROPERTIES);
 (EXISTS_TAC `V:real^3->bool` THEN EXISTS_TAC `1`);
 (ASM_REWRITE_TAC[]);

 (REWRITE_WITH `dist (circumcenter (set_of_list [u0; u1:real^3]),z') = 
   hl [u0; u1]`);
 (FIRST_ASSUM MATCH_MP_TAC);
 (ASM_REWRITE_TAC[set_of_list]);
 (NEW_GOAL `sqrt (&2) <= &2`);
 (MATCH_MP_TAC Tactics_jordan.REAL_POW_2_LE);
 (SIMP_TAC[REAL_ARITH `&0 <= &2`; SQRT_POS_LE; SQRT_POW_2]);
 (REAL_ARITH_TAC);
 (ASM_REAL_ARITH_TAC);

 (NEW_GOAL `?a:real^3. a IN A /\ (!x. x IN A ==> dist (p,a) <= dist (p,x))`);
 (MATCH_MP_TAC Packing3.REAL_FINITE_ARGMIN);
 (ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN SET_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);


 (ABBREV_TAC `d = inv (&4) * (dist (p, a') - dist (p, u0:real^3))`);
 (NEW_GOAL `&0 < d`);
 (EXPAND_TAC "d");
 (MATCH_MP_TAC REAL_LT_MUL);
 (STRIP_TAC);
 (REAL_ARITH_TAC);
 (REWRITE_TAC[REAL_ARITH `&0 < a - b <=> a > b`]);
 (ONCE_REWRITE_TAC[DIST_SYM]);
 (NEW_GOAL `!u v. u IN {u0,u1} /\ v IN V DIFF {u0,u1} ==> 
                   dist (v,p) > dist (u,p:real^3)`);
 (MATCH_MP_TAC Rogers.XYOFCGX);
 (REPEAT STRIP_TAC);
 (ASM_REWRITE_TAC[]);
 (ASM_SET_TAC[]);
 (UP_ASM_TAC THEN REWRITE_TAC[AFFINE_INDEPENDENT_2]);
 (ASM_MESON_TAC[set_of_list]);
 (REWRITE_WITH `radV {u0, u1:real^3} = hl [u0;u1]`);
 (REWRITE_TAC[HL;set_of_list]);
 (ASM_REWRITE_TAC[]);
 (FIRST_ASSUM MATCH_MP_TAC);
 (ASM_SET_TAC[]);

 (REWRITE_TAC[relative_interior; IN; IN_ELIM_THM]);
 (ABBREV_TAC `St = S INTER ball (p:real^3, d)`);
 (EXISTS_TAC `St:real^3->bool`);
 (REPEAT STRIP_TAC);

 (REWRITE_TAC[open_in]);
 (REPEAT STRIP_TAC);
 (NEW_GOAL `S SUBSET affine hull (S:real^3->bool)`);
 (REWRITE_TAC[Qzksykg.SET_SUBSET_AFFINE_HULL]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN SET_TAC[]);
 (EXISTS_TAC `d - dist (p:real^3, x)`);
 (REPEAT STRIP_TAC);
 (REWRITE_TAC[REAL_ARITH `&0 < a - b <=> b < a`]);
 (REWRITE_TAC[GSYM IN_BALL]);
 (ASM_SET_TAC[]);
 (EXPAND_TAC "St");
 (REWRITE_TAC[IN_INTER]);
 (STRIP_TAC);


 (NEW_GOAL `dist (x',x:real^3) < d`);
 (NEW_GOAL `&0 <= dist (p,x:real^3)`);
 (REWRITE_TAC[DIST_POS_LE]);
 (ASM_REAL_ARITH_TAC);

 (NEW_GOAL `x' IN voronoi_closed V (u0:real^3)`);
 (REWRITE_TAC[voronoi_closed; IN; IN_ELIM_THM]);
 (REPEAT STRIP_TAC);

 (ASM_CASES_TAC `w IN {u0, u1:real^3}`);
 (ASM_CASES_TAC `w = u0:real^3`);
 (REWRITE_TAC[ASSUME `w = u0:real^3`]);
 (REAL_ARITH_TAC);
 (NEW_GOAL `w = u1:real^3`);
 (ASM_SET_TAC[]);
 (REWRITE_TAC[ASSUME `w = u1:real^3`]);
 (MATCH_MP_TAC (REAL_ARITH `a = b ==> a <= b`));

 (NEW_GOAL `x':real^3 IN S1`);
 (NEW_GOAL `affine hull S SUBSET affine hull (S1:real^3->bool)`);
 (MATCH_MP_TAC Marchal_cells_2_new.AFFINE_SUBSET_KY_LEMMA);
 (EXPAND_TAC "S1" THEN REWRITE_TAC[GSYM 
  (ASSUME `voronoi_list V [u0; u1] = S`); VORONOI_LIST; VORONOI_SET; 
  set_of_list; SET_RULE `INTERS {f v | v IN {a, b}} = f a INTER f b`]);
 (MATCH_MP_TAC Pack2.INTER_VORONOI_SUBSET_BISECTOR);
 (ASM_REWRITE_TAC[]);
 (REWRITE_WITH `x' IN S1 <=> x':real^3 IN affine hull S1`);
 (REWRITE_WITH `affine hull S1 = S1:real^3->bool`);
 (REWRITE_TAC[AFFINE_HULL_EQ]);
 (EXPAND_TAC "S1" THEN REWRITE_TAC[AFFINE_HYPERPLANE]);
 (ASM_SET_TAC[]);

 (UP_ASM_TAC THEN EXPAND_TAC "S1" THEN REWRITE_TAC[IN_ELIM_THM; NORM_POW_2]);
 (ONCE_REWRITE_TAC[REAL_ARITH `a = b <=> a - b = &0`]);
 (REWRITE_TAC[
   VECTOR_ARITH `&2 % (u0 - u1) dot x - (u0 dot u0 - u1 dot u1) = 
                (u1 - x) dot (u1 - x) - (u0 - x) dot (u0 - x)`]);
 (REWRITE_TAC[REAL_ARITH `a - b = &0 <=> a = b`; GSYM NORM_POW_2; GSYM dist]);
 (STRIP_TAC);
 (REWRITE_TAC[DIST_EQ]);
 (ONCE_REWRITE_TAC[DIST_SYM]);
 (ASM_REWRITE_TAC[]);

 (NEW_GOAL `dist (x', u0:real^3) <= dist (x', x) + dist (x, u0)`);
 (REWRITE_TAC[DIST_TRIANGLE]);
 (NEW_GOAL `dist (x, u0:real^3) <= dist (x, p:real^3) + dist (p, u0)`);
 (REWRITE_TAC[DIST_TRIANGLE]);
 (NEW_GOAL `dist (x,p:real^3) < d`);
 (NEW_GOAL `x IN ball (p:real^3, d)`);
 (ASM_SET_TAC[]);
 (UP_ASM_TAC THEN REWRITE_TAC[IN_BALL]);
 (REWRITE_TAC[DIST_SYM]);
 (NEW_GOAL `dist (x',u0) < &2 * d + dist (p:real^3,u0)`);
 (ASM_REAL_ARITH_TAC);

 (NEW_GOAL `dist (p, w:real^3)- &2 * d <= dist (x',w)`);
 (NEW_GOAL `dist (x, w:real^3) <= dist (x, x') + dist (x', w)`);
 (REWRITE_TAC[DIST_TRIANGLE]);
 (NEW_GOAL `dist (p, w:real^3) <= dist (p, x) + dist (x, w)`);
 (REWRITE_TAC[DIST_TRIANGLE]);
 (NEW_GOAL `dist (x, x':real^3) < d /\ dist (p, x:real^3) < d`);
 (ONCE_REWRITE_TAC[DIST_SYM] THEN ASM_REWRITE_TAC[]);
 (ASM_REAL_ARITH_TAC);
 (NEW_GOAL `dist (p, u0) + &4 * d <= dist (p, w:real^3)`);
 (EXPAND_TAC "d");
 (REWRITE_TAC[REAL_ARITH `&4 * inv (&4) * a = a`]);
 (REWRITE_TAC[REAL_ARITH `a + b - a = b`]);

 (ASM_CASES_TAC `w:real^3 IN B`);
 (FIRST_ASSUM MATCH_MP_TAC);
 (ASM_SET_TAC[]);
 (NEW_GOAL `~(dist (p,w:real^3) < &8)`);
 (REWRITE_TAC[GSYM IN_BALL]);
 (ASM_SET_TAC[]);
 (NEW_GOAL `dist (p,a':real^3) < &8`);
 (REWRITE_TAC[GSYM IN_BALL]);
 (ASM_SET_TAC[]);
 (ASM_REAL_ARITH_TAC);
 (ASM_REAL_ARITH_TAC);


 (NEW_GOAL `x' IN voronoi_closed V (u1:real^3)`);
 (NEW_GOAL `x':real^3 IN S1`);
 (NEW_GOAL `affine hull S SUBSET affine hull (S1:real^3->bool)`);
 (MATCH_MP_TAC Marchal_cells_2_new.AFFINE_SUBSET_KY_LEMMA);
 (EXPAND_TAC "S1" THEN REWRITE_TAC[GSYM 
  (ASSUME `voronoi_list V [u0; u1] = S`); VORONOI_LIST; VORONOI_SET; 
  set_of_list; SET_RULE `INTERS {f v | v IN {a, b}} = f a INTER f b`]);
 (MATCH_MP_TAC Pack2.INTER_VORONOI_SUBSET_BISECTOR);
 (ASM_REWRITE_TAC[]);
 (REWRITE_WITH `x' IN S1 <=> x':real^3 IN affine hull S1`);
 (REWRITE_WITH `affine hull S1 = S1:real^3->bool`);
 (REWRITE_TAC[AFFINE_HULL_EQ]);
 (EXPAND_TAC "S1" THEN REWRITE_TAC[AFFINE_HYPERPLANE]);
 (ASM_SET_TAC[]);

 (UP_ASM_TAC THEN EXPAND_TAC "S1" THEN REWRITE_TAC[IN_ELIM_THM; NORM_POW_2]);
 (ONCE_REWRITE_TAC[REAL_ARITH `a = b <=> a - b = &0`]);
 (REWRITE_TAC[
   VECTOR_ARITH `&2 % (u0 - u1) dot x - (u0 dot u0 - u1 dot u1) = 
                (u1 - x) dot (u1 - x) - (u0 - x) dot (u0 - x)`]);
 (REWRITE_TAC[REAL_ARITH `a - b = &0 <=> a = b`; GSYM NORM_POW_2; GSYM dist]);
 (STRIP_TAC);
 (UNDISCH_TAC `x' IN voronoi_closed V (u0:real^3)`);
 (REWRITE_TAC[voronoi_closed; IN_ELIM_THM; IN]);
 (REPEAT STRIP_TAC);
 (REWRITE_WITH `dist (x', u1)= dist (x', u0:real^3)`);
 (ONCE_REWRITE_TAC[DIST_SYM]);
 (ASM_REWRITE_TAC[DIST_EQ]);
 (ASM_SIMP_TAC[]);

 (REWRITE_TAC[GSYM 
  (ASSUME `voronoi_list V [u0; u1] = S`); VORONOI_LIST; VORONOI_SET; 
  set_of_list; SET_RULE `INTERS {f v | v IN {a, b}} = f a INTER f b`]);
 (ASM_REWRITE_TAC[IN_INTER]);

 (REWRITE_TAC[IN_BALL]);
 (NEW_GOAL `dist (p,x':real^3) <= dist (p,x) + dist (x, x':real^3)`);
 (REWRITE_TAC[DIST_TRIANGLE]);
 (NEW_GOAL `dist (x,x':real^3) = dist (x',x)`);
 (REWRITE_TAC[DIST_SYM]);
 (ASM_REAL_ARITH_TAC);
 (REWRITE_WITH `St p <=> p:real^3 IN St`);
 (REWRITE_TAC[IN]);
 (EXPAND_TAC "St" THEN REWRITE_TAC[IN_INTER; IN_BALL; DIST_REFL]);
 (STRIP_TAC);
 (REWRITE_WITH `p = omega_list V [u0; u1]`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (REWRITE_WITH `p = circumcenter (set_of_list [u0;u1:real^3])`);
 (ASM_MESON_TAC[set_of_list]);
 (MATCH_MP_TAC Rogers.XNHPWAB1);
 (EXISTS_TAC `1`);
 (ASM_REWRITE_TAC[IN]);
 (REWRITE_TAC[GSYM (ASSUME `voronoi_list V [u0;u1] = S`)]);
 (MATCH_MP_TAC Packing3.OMEGA_LIST_IN_VORONOI_LIST);
 (EXISTS_TAC `1` THEN ASM_REWRITE_TAC[]);
 (ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN SET_TAC[]);
 (UP_ASM_TAC THEN SET_TAC[]);
 (ASM_MESON_TAC[]);

(* ======================================================================== *)

 (NEW_GOAL `?b. &0 < b /\ b < &1 /\ 
                  rcone_gt u0 u1 b SUBSET aff_ge_alt {u0:real^3} S`);

 (EXISTS_TAC `a:real`);
 (REPEAT STRIP_TAC);
 (ASM_REWRITE_TAC[]);
 (ASM_REWRITE_TAC[]);
 (REWRITE_TAC[SET_RULE `A SUBSET B <=> (!x. ~(x IN B) ==> ~(x IN A))`]);
 (REPEAT STRIP_TAC);
 (NEW_GOAL `x:real^3 IN affine hull (u0 INSERT S)`);
 (ASM_SET_TAC[]);
 (UP_ASM_TAC THEN REWRITE_TAC[AFFINE_HULL_EXPLICIT_ALT; IN; IN_ELIM_THM]);
 (REPEAT STRIP_TAC);

 (ABBREV_TAC `h = sum (s DELETE u0:real^3) u`);
 (NEW_GOAL `(x - u0) dot (u1 - u0:real^3) = 
              h * dist (p, u0) * dist (u1, u0:real^3)`);
 (EXPAND_TAC "x");
 (NEW_GOAL `u0 = vsum s (\v:real^3. (u:real^3->real) v % (u0:real^3))`);
 (ASM_SIMP_TAC[VSUM_RMUL]);
 (VECTOR_ARITH_TAC);
 (REWRITE_WITH `vsum (s:real^3->bool) (\v. u v % v) - u0:real^3 = 
                 vsum s (\v. u v % v) - vsum s (\v:real^3. u v % u0)`);
 (ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (REWRITE_WITH `vsum s (\v. u v % v) - vsum s (\v:real^3. u v % u0:real^3) = 
                 vsum s (\x. (\v. u v % v) x - (\v. u v % u0) x)`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC VSUM_SUB);
 (ASM_REWRITE_TAC[]);
 (REWRITE_TAC[VECTOR_ARITH `a % x - a % y = a % (x - y)`]);
 (REWRITE_WITH `vsum s (\x:real^3. u x % (x - u0)) dot (u1 - u0) = 
                 sum s (\x. (\x. u x % (x - u0)) x dot (u1 - u0:real^3))`);
 (ASM_SIMP_TAC[DOT_LSUM]);
 (REWRITE_TAC[DOT_LMUL]);
 (REWRITE_WITH `sum s (\x:real^3. u x * ((x - u0) dot (u1 - u0:real^3))) = 
   sum (s DELETE u0) (\x. u x * (dist (p,u0) * dist (u1,u0)))`);
 (ASM_CASES_TAC `u0:real^3 IN s`);
 (NEW_GOAL `s = u0 INSERT (s DELETE u0:real^3)`);
 (ASM_SET_TAC[]);
 (NEW_GOAL `FINITE (s DELETE u0:real^3)`);
 (MATCH_MP_TAC FINITE_SUBSET);
 (EXISTS_TAC `s:real^3->bool` THEN ASM_REWRITE_TAC[] THEN SET_TAC[]);

 (REWRITE_WITH `sum s (\x:real^3. u x * ((x - u0) dot (u1 - u0:real^3))) = 
   sum (u0 INSERT (s DELETE u0))  (\x. u x * ((x - u0) dot (u1 - u0)))`);
 (ASM_MESON_TAC[]);
 (ABBREV_TAC `f = (\x:real^3. u x * ((x - u0) dot (u1 - u0:real^3)))`);
 (REWRITE_WITH `sum (u0:real^3 INSERT (s DELETE u0)) f = 
         (if u0 IN (s DELETE u0) then sum (s DELETE u0) f 
          else f u0 + sum (s DELETE u0) f)`);
 (MATCH_MP_TAC Marchal_cells_2_new.SUM_CLAUSES_alt);
 (ASM_REWRITE_TAC[]);
 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (ASM_SET_TAC[]);
 (ASM_MESON_TAC[]);
 (REWRITE_WITH `f (u0:real^3) = &0`);
 (EXPAND_TAC "f");
 (REWRITE_TAC[VECTOR_ARITH `(u0 - u0) dot (u1 - u0) = &0`]);
 (REAL_ARITH_TAC);
 (REWRITE_TAC[REAL_ARITH `&0 + a = a`]);
 (MATCH_MP_TAC SUM_EQ);
 (EXPAND_TAC "f");
 (REPEAT STRIP_TAC);
 (REWRITE_TAC[REAL_ARITH `a * x = a * y * z <=> a * (x - y * z) = &0`]);
 (NEW_GOAL `(x' - u0) dot (u1 - u0) - dist (p,u0) * dist (u1,u0:real^3) = &0`);
 (REWRITE_TAC[REAL_ARITH `a - b = &0 <=> a = b`]);
 (FIRST_ASSUM MATCH_MP_TAC);
 (ASM_SET_TAC[]);
 (ASM_REWRITE_TAC[]);
 (REAL_ARITH_TAC);
 (REWRITE_WITH `s DELETE u0:real^3 = s`);
 (ASM_SET_TAC[]);
 (MATCH_MP_TAC SUM_EQ);
 (REPEAT STRIP_TAC);
 (REWRITE_TAC[]);
 (REWRITE_TAC[REAL_ARITH `a * x = a * y * z <=> a * (x - y * z) = &0`]);
 (NEW_GOAL `(x' - u0) dot (u1 - u0) - dist (p,u0) * dist (u1,u0:real^3) = &0`);
 (REWRITE_TAC[REAL_ARITH `a - b = &0 <=> a = b`]);
 (FIRST_ASSUM MATCH_MP_TAC);
 (ASM_SET_TAC[]);
 (ASM_REWRITE_TAC[]);
 (REAL_ARITH_TAC);
 (NEW_GOAL `FINITE (s DELETE u0:real^3)`);
 (MATCH_MP_TAC FINITE_SUBSET);
 (EXISTS_TAC `s:real^3->bool` THEN ASM_REWRITE_TAC[] THEN SET_TAC[]);
 (ASM_SIMP_TAC[SUM_RMUL]);

 (ASM_CASES_TAC `h <= &0`);
 (NEW_GOAL `~(x IN rcone_gt u0 (u1:real^3) a)`);
 (REWRITE_TAC[rcone_gt; rconesgn; IN; IN_ELIM_THM]);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC (REAL_ARITH `&0 <= x /\ y <= &0 ==> ~(y > x)`));
 (STRIP_TAC);
 (MATCH_MP_TAC REAL_LE_MUL);
 (REWRITE_TAC[DIST_POS_LE]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (REWRITE_TAC[DIST_POS_LE]);
 (ASM_REAL_ARITH_TAC);

 (REWRITE_TAC[REAL_ARITH `a * b * c <= &0 <=> &0 <= b * c * (--a)`]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (REWRITE_TAC[DIST_POS_LE]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (REWRITE_TAC[DIST_POS_LE]);
 (ASM_REAL_ARITH_TAC);
 (NEW_GOAL `F`);
 (ASM_MESON_TAC[]);
 (ASM_MESON_TAC[]);

 (ABBREV_TAC `y = inv (h) % vsum (s DELETE u0) (\v:real^3. u v % v)`);
 (NEW_GOAL `?t. t + h = &1 /\ x = t % u0 + h % (y:real^3)`);
 (EXISTS_TAC `&1 - h`);
 (STRIP_TAC);
 (REAL_ARITH_TAC);
 (ASM_CASES_TAC `u0:real^3 IN s`);
 (REWRITE_TAC[GSYM (ASSUME `sum s (u:real^3->real) = &1`)]);

 (EXPAND_TAC "h");
 (REWRITE_WITH `sum s u = sum (u0 INSERT (s DELETE u0)) (u:real^3->real)`);
 (REWRITE_WITH `(u0 INSERT (s DELETE u0:real^3)) = s`);
 (ASM_SET_TAC[]);
 (NEW_GOAL `FINITE (s DELETE u0:real^3)`);
 (MATCH_MP_TAC FINITE_SUBSET);
 (EXISTS_TAC `s:real^3->bool` THEN ASM_REWRITE_TAC[] THEN SET_TAC[]);

 (SIMP_TAC[Marchal_cells_2_new.SUM_CLAUSES_alt; 
   ASSUME `FINITE (s DELETE u0:real^3)`]);
 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (ASM_MESON_TAC[]);
 (REWRITE_TAC[REAL_ARITH `(a + b:real) - b = a`]);
 (ASM_REWRITE_TAC[]);
 (EXPAND_TAC "y");
 (REWRITE_TAC[VECTOR_MUL_ASSOC]);
 (REWRITE_WITH `h * inv h = &1`);
 (NEW_GOAL `~(h = &0)`);
 (ASM_REAL_ARITH_TAC);
 (ASM_SIMP_TAC[Trigonometry2.REAL_MUL_LRINV]);
 (REWRITE_TAC[VECTOR_MUL_LID]);
 (EXPAND_TAC "x");

 (REWRITE_WITH `vsum s (\v. u v % v) = 
   vsum (u0 INSERT (s DELETE u0)) (\v:real^3. u v % v)`);
 (REWRITE_WITH `(u0 INSERT (s DELETE u0:real^3)) = s`);
 (ASM_SET_TAC[]);
 (SIMP_TAC[Marchal_cells_2_new.VSUM_CLAUSES_alt; 
   ASSUME `FINITE (s DELETE u0:real^3)`]);
 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (ASM_MESON_TAC[]);
 (REFL_TAC);

 (NEW_GOAL `h = &1`);
 (EXPAND_TAC "h" THEN REWRITE_WITH `s DELETE u0:real^3 = s`);
 (ASM_SET_TAC[]);
 (ASM_REWRITE_TAC[]);
 (EXPAND_TAC "y" THEN REWRITE_TAC[ASSUME `h = &1`]);
 (REWRITE_WITH `s DELETE u0:real^3 = s`);
 (ASM_SET_TAC[]);
 (ASM_REWRITE_TAC[REAL_ARITH `inv (&1) = &1 /\ &1 - &1 = &0`]);
 (VECTOR_ARITH_TAC);
 (UP_ASM_TAC THEN STRIP_TAC);

 (NEW_GOAL `~(y:real^3 IN S)`);
 (STRIP_TAC);
 (NEW_GOAL `x IN aff_ge_alt {u0:real^3} S`);
 (REWRITE_TAC[IN; aff_ge_alt; lin_combo]);

 (ABBREV_TAC `f = (\v:real^3. if v = u0 then t 
                                else if v = y then h else &0)`);
 (EXISTS_TAC `f:real^3->real`);
 (EXISTS_TAC `{y:real^3}`);

 (REPEAT STRIP_TAC);
 (REWRITE_TAC[FINITE_SING]);
 (ASM_SET_TAC[]);

 (REWRITE_TAC[SET_RULE `{a} UNION {b} = {a, b}`]);
 (REWRITE_WITH `vsum {u0:real^3, y} (\v. f v % v) = 
                (\v. f v % v) u0 + (\v. f v % v) y`);
 (MATCH_MP_TAC Geomdetail.VSUM_DIS2);
 (STRIP_TAC);
 (NEW_GOAL `~(u0:real^3 IN S)`);
 (EXPAND_TAC "S");
 (REWRITE_TAC[VORONOI_LIST; VORONOI_SET; set_of_list; 
   SET_RULE `v IN {a,b} <=> v = a \/ v = b`]);
 (STRIP_TAC);
 (NEW_GOAL `u0 IN voronoi_closed V (u1:real^3)`);
 (ASM_SET_TAC[]);
 (UP_ASM_TAC THEN REWRITE_TAC[voronoi_closed; IN; IN_ELIM_THM]);
 (REPEAT STRIP_TAC);
 (NEW_GOAL `dist (u0,u1) <= dist (u0,u0:real^3)`);
 (FIRST_ASSUM MATCH_MP_TAC);
 (ASM_SET_TAC[]);
 (UP_ASM_TAC THEN REWRITE_TAC[DIST_REFL; REAL_ARITH `~(a <= b) <=> b < a`]);
 (MATCH_MP_TAC DIST_POS_LT);
 (ASM_REWRITE_TAC[]);
 (ASM_MESON_TAC[]);

 (REWRITE_WITH `(f:real^3->real) u0 = t`);
 (EXPAND_TAC "f");
 (COND_CASES_TAC);
 (REFL_TAC);
 (NEW_GOAL `F`);
 (ASM_MESON_TAC[]);
 (ASM_MESON_TAC[]);

 (REWRITE_WITH `(f:real^3->real) y = h`);
 (EXPAND_TAC "f");
 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (NEW_GOAL `~(u0:real^3 IN S)`);
 (EXPAND_TAC "S");
 (REWRITE_TAC[VORONOI_LIST; VORONOI_SET; set_of_list; 
   SET_RULE `v IN {a,b} <=> v = a \/ v = b`]);
 (STRIP_TAC);
 (NEW_GOAL `u0 IN voronoi_closed V (u1:real^3)`);
 (ASM_SET_TAC[]);
 (UP_ASM_TAC THEN REWRITE_TAC[voronoi_closed; IN; IN_ELIM_THM]);
 (REPEAT STRIP_TAC);
 (NEW_GOAL `dist (u0,u1) <= dist (u0,u0:real^3)`);
 (FIRST_ASSUM MATCH_MP_TAC);
 (ASM_SET_TAC[]);
 (UP_ASM_TAC THEN REWRITE_TAC[DIST_REFL; REAL_ARITH `~(a <= b) <=> b < a`]);
 (MATCH_MP_TAC DIST_POS_LT);
 (ASM_REWRITE_TAC[]);
 (ASM_MESON_TAC[]);
 (ASM_MESON_TAC[]);
 (COND_CASES_TAC);
 (REFL_TAC);
 (NEW_GOAL `F`);
 (ASM_MESON_TAC[]);
 (ASM_MESON_TAC[]);
 (ASM_REWRITE_TAC[]);

 (EXPAND_TAC "f");
 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (NEW_GOAL `~({y:real^3} u0)`);
 (REWRITE_WITH `~({y} u0) <=> ~(u0:real^3 IN {y})`);
 (MESON_TAC[IN]);
 (REWRITE_TAC[IN_SING]);
 (STRIP_TAC);

 (NEW_GOAL `~(u0:real^3 IN S)`);
 (EXPAND_TAC "S");
 (REWRITE_TAC[VORONOI_LIST; VORONOI_SET; set_of_list; 
   SET_RULE `v IN {a,b} <=> v = a \/ v = b`]);
 (STRIP_TAC);

 (NEW_GOAL `u0 IN voronoi_closed V (u1:real^3)`);
 (ASM_SET_TAC[]);
 (UP_ASM_TAC THEN REWRITE_TAC[voronoi_closed; IN; IN_ELIM_THM]);
 (REPEAT STRIP_TAC);
 (NEW_GOAL `dist (u0,u1) <= dist (u0,u0:real^3)`);
 (FIRST_ASSUM MATCH_MP_TAC);
 (ASM_SET_TAC[]);
 (UP_ASM_TAC THEN REWRITE_TAC[DIST_REFL; REAL_ARITH `~(a <= b) <=> b < a`]);
 (MATCH_MP_TAC DIST_POS_LT);
 (ASM_REWRITE_TAC[]);
 (ASM_MESON_TAC[]);
 (ASM_MESON_TAC[]);
 (ASM_MESON_TAC[]);

 (COND_CASES_TAC);
 (ASM_REAL_ARITH_TAC);
 (REAL_ARITH_TAC);

 (REWRITE_TAC[SET_RULE `{a} UNION {b} = {a,b}`]);
 (REWRITE_WITH `sum {u0:real^3, y} f = f u0 + f y`);
 (MATCH_MP_TAC Geomdetail.SUM_DIS2);
 (STRIP_TAC);
 (NEW_GOAL `~(u0:real^3 IN S)`);
 (EXPAND_TAC "S");
 (REWRITE_TAC[VORONOI_LIST; VORONOI_SET; set_of_list; 
   SET_RULE `v IN {a,b} <=> v = a \/ v = b`]);
 (STRIP_TAC);
 (NEW_GOAL `u0 IN voronoi_closed V (u1:real^3)`);
 (ASM_SET_TAC[]);
 (UP_ASM_TAC THEN REWRITE_TAC[voronoi_closed; IN; IN_ELIM_THM]);
 (REPEAT STRIP_TAC);
 (NEW_GOAL `dist (u0,u1) <= dist (u0,u0:real^3)`);
 (FIRST_ASSUM MATCH_MP_TAC);
 (ASM_SET_TAC[]);
 (UP_ASM_TAC THEN REWRITE_TAC[DIST_REFL; REAL_ARITH `~(a <= b) <=> b < a`]);
 (MATCH_MP_TAC DIST_POS_LT);
 (ASM_REWRITE_TAC[]);
 (ASM_MESON_TAC[]);

 (REWRITE_WITH `(f:real^3->real) u0 = t`);
 (EXPAND_TAC "f");
 (COND_CASES_TAC);
 (REFL_TAC);
 (NEW_GOAL `F`);
 (ASM_MESON_TAC[]);
 (ASM_MESON_TAC[]);

 (REWRITE_WITH `(f:real^3->real) y = h`);
 (EXPAND_TAC "f");
 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (NEW_GOAL `~(u0:real^3 IN S)`);
 (EXPAND_TAC "S");
 (REWRITE_TAC[VORONOI_LIST; VORONOI_SET; set_of_list; 
   SET_RULE `v IN {a,b} <=> v = a \/ v = b`]);
 (STRIP_TAC);
 (NEW_GOAL `u0 IN voronoi_closed V (u1:real^3)`);
 (ASM_SET_TAC[]);
 (UP_ASM_TAC THEN REWRITE_TAC[voronoi_closed; IN; IN_ELIM_THM]);
 (REPEAT STRIP_TAC);
 (NEW_GOAL `dist (u0,u1) <= dist (u0,u0:real^3)`);
 (FIRST_ASSUM MATCH_MP_TAC);
 (ASM_SET_TAC[]);
 (UP_ASM_TAC THEN REWRITE_TAC[DIST_REFL; REAL_ARITH `~(a <= b) <=> b < a`]);
 (MATCH_MP_TAC DIST_POS_LT);
 (ASM_REWRITE_TAC[]);
 (ASM_MESON_TAC[]);
 (ASM_MESON_TAC[]);

 (COND_CASES_TAC);
 (REFL_TAC);
 (NEW_GOAL `F`);
 (ASM_MESON_TAC[]);
 (ASM_MESON_TAC[]);
 (ASM_REWRITE_TAC[]);
 (ASM_MESON_TAC[]);

 (NEW_GOAL `y:real^3 IN S2`);
 (EXPAND_TAC "S2");
 (NEW_GOAL `y:real^3 IN S1`);
 (NEW_GOAL `y:real^3 IN affine hull S`);
 (REWRITE_TAC[AFFINE_HULL_EXPLICIT_ALT]);
 (REWRITE_TAC[IN; IN_ELIM_THM]);
 (EXISTS_TAC `s DELETE u0:real^3`);
 (EXISTS_TAC `(\v:real^3. inv h * u v)`);
 (REPEAT STRIP_TAC);
 (ASM_REWRITE_TAC[FINITE_DELETE]);
 (ASM_SET_TAC[]);
 (REWRITE_TAC[SUM_LMUL]);
 (ASM_REWRITE_TAC[]);
 (ASM_SIMP_TAC[Trigonometry2.REAL_MUL_LRINV; 
   REAL_ARITH `~(h <= &0) ==> ~(h = &0)`]);
 (REWRITE_TAC[GSYM VECTOR_MUL_ASSOC]);
 (ASM_SIMP_TAC[VSUM_LMUL; FINITE_DELETE]);
 (NEW_GOAL `affine hull S1 = S1:real^3->bool`);
 (REWRITE_TAC[AFFINE_HULL_EQ]);
 (EXPAND_TAC "S1" THEN REWRITE_TAC[AFFINE_HYPERPLANE]);

 (NEW_GOAL `affine hull S SUBSET affine hull (S1:real^3->bool)`);
 (MATCH_MP_TAC Marchal_cells_2_new.AFFINE_SUBSET_KY_LEMMA);
 (EXPAND_TAC "S");
 (REWRITE_TAC[VORONOI_LIST; VORONOI_SET; set_of_list; 
   SET_RULE `INTERS {f x | x IN {a, b}} = f a INTER f b`]);
 (DEL_TAC THEN EXPAND_TAC "S1");
 (MATCH_MP_TAC Pack2.INTER_VORONOI_SUBSET_BISECTOR);
 (ASM_REWRITE_TAC[]);
 (ASM_SET_TAC[]);

 (NEW_GOAL `relative_interior S SUBSET S:real^3->bool`);
 (REWRITE_TAC[RELATIVE_INTERIOR_SUBSET]);
 (ASM_SET_TAC[]);

(* OK until here *)
(* ========================================================================= *)

 (NEW_GOAL `dist (z,u0) <= dist (y,u0:real^3)`);
 (ONCE_REWRITE_TAC[DIST_SYM]);
 (ASM_SIMP_TAC[]);
 (UNDISCH_TAC `x:real^3 IN rcone_gt u0 u1 a`);
 (REWRITE_TAC[rcone_gt; rconesgn; IN; IN_ELIM_THM]);
 (ASM_REWRITE_TAC[]);
 (REWRITE_WITH `dist (t % u0 + h % y,u0) = h * dist (y, u0:real^3)`);
 (REWRITE_TAC[dist]);
 (REWRITE_WITH `(t % u0 + h % y:real^3) - u0 = (t % u0 + h % y) - (t + h) % u0`);
 (ASM_REWRITE_TAC[] THEN VECTOR_ARITH_TAC);
 (REWRITE_TAC[VECTOR_ARITH `(t % u0 + h % y) - (t + h) % u0 = h % (y - u0)`]);
 (REWRITE_TAC[NORM_MUL]);
 (REWRITE_WITH `abs h = h`);
 (REWRITE_TAC[REAL_ABS_REFL]);
 (ASM_REAL_ARITH_TAC);

 (REWRITE_TAC[REAL_ARITH `~(a > b) <=> a <= b`]);
 (REWRITE_WITH `h * dist (p,u0:real^3) * dist (u1,u0) = 
            (h * dist (z,u0)) * dist (u1,u0) * a`);
 (EXPAND_TAC "a");
 (REWRITE_TAC[REAL_ARITH `(a * b) * c * d / b = (a * d * c) * (b / b)`]);
 (REWRITE_WITH `dist (z,u0) / dist (z,u0:real^3) = &1`);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (REWRITE_TAC[DIST_EQ_0]);
 (STRIP_TAC);

 (NEW_GOAL `~(u0:real^3 IN S1)`);
 (EXPAND_TAC "S1" THEN REWRITE_TAC[IN; IN_ELIM_THM; NORM_POW_2]);
 (REWRITE_TAC[REAL_ARITH `a = b - c <=> a + c - b = &0`]);
 (REWRITE_TAC[VECTOR_ARITH `&2 % (u0 - u1) dot u0 + u1 dot u1 - u0 dot u0 = 
  (u0 - u1) dot (u0 - u1)`]);
 (REWRITE_TAC[DOT_EQ_0; VECTOR_ARITH `a - b = vec 0 <=> a = b`]);
 (ASM_REWRITE_TAC[]);
 (NEW_GOAL `z:real^3 IN S1`);
 (ASM_SET_TAC[]);
 (ASM_MESON_TAC[]);

 (REAL_ARITH_TAC);
 (REWRITE_TAC[REAL_ARITH 
  `(a * x) * b * c <= (a * y) * b * c <=> &0 <= a * b * c *(y - x)`]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (STRIP_TAC);
 (ASM_REAL_ARITH_TAC);
 (MATCH_MP_TAC REAL_LE_MUL);
 (REWRITE_TAC[DIST_POS_LE]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (STRIP_TAC);
 (ASM_REAL_ARITH_TAC);
 (ASM_REAL_ARITH_TAC);

 (UP_ASM_TAC THEN STRIP_TAC);

 (ABBREV_TAC `W = aff_ge_alt {u0:real^3} S`);
 (ABBREV_TAC `c = max b (hl[u0;u1:real^3] / sqrt (&2))`);
 (NEW_GOAL `&0 < c /\ c < &1`);
 (EXPAND_TAC "c" THEN REWRITE_TAC[REAL_LT_MAX]);
 (ASM_REWRITE_TAC[]);
 (EXPAND_TAC "c" THEN REWRITE_TAC[REAL_MAX_LT]);
 (STRIP_TAC);
 (ASM_REWRITE_TAC[]);
 (REWRITE_WITH `hl [u0; u1:real^3] / sqrt (&2) < &1 <=> 
                 hl [u0; u1] < &1 * sqrt (&2)`);
 (MATCH_MP_TAC REAL_LT_LDIV_EQ);
 (ASM_SIMP_TAC[SQRT_POS_LT; REAL_ARITH `&0 < &2`]);
 (ASM_REAL_ARITH_TAC);

 (NEW_GOAL `rcone_gt u0 u1 c SUBSET 
             W INTER (rcone_gt u0 u1 (hl [u0; u1:real^3] / sqrt (&2)))`);
 (REWRITE_TAC[SUBSET_INTER]);
 (STRIP_TAC);
 (NEW_GOAL `rcone_gt (u0:real^3) u1 c SUBSET rcone_gt u0 u1 b`);
 (MATCH_MP_TAC RCONE_GT_SUBSET);
 (EXPAND_TAC "c" THEN REAL_ARITH_TAC);
 (ASM_SET_TAC[]);
 (MATCH_MP_TAC RCONE_GT_SUBSET);
 (EXPAND_TAC "c" THEN REAL_ARITH_TAC);

 (ABBREV_TAC `C = ball (u0:real^3,&1) INTER rcone_gt u0 u1 c`);
 (NEW_GOAL `C SUBSET 
      UNIONS
      {rogers V vl | vl | barV V 3 vl /\ truncate_simplex 1 vl = [u0; u1]}`);
 (REWRITE_TAC[SUBSET]);
 (REPEAT STRIP_TAC);
 (NEW_GOAL `x IN ball (u0:real^3,&1)  /\ x IN aff_ge_alt {u0} S`);
 (ASM_SET_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);

(* OK until here *)
(* ===========================================================================*)

 (NEW_GOAL `(x:real^3) IN convex hull (u0 INSERT S)`);
 (REWRITE_TAC[CONVEX_HULL_EXPLICIT; IN; IN_ELIM_THM]);

 (UP_ASM_TAC THEN REWRITE_TAC[IN; aff_ge_alt; lin_combo]);
 (REPEAT STRIP_TAC);
 (EXISTS_TAC `{u0:real^3} UNION q`);
 (EXISTS_TAC `f:real^3->real`);
 (REPEAT STRIP_TAC);
 (REWRITE_TAC[SET_RULE `{a} UNION b = a INSERT b`; FINITE_INSERT]);
 (ASM_REWRITE_TAC[]);
 (ASM_SET_TAC[]);
 (ASM_CASES_TAC `x':real^3 IN q`);
 (FIRST_ASSUM MATCH_MP_TAC);
 (UP_ASM_TAC THEN MESON_TAC[IN]);
 (REWRITE_WITH `x' = u0:real^3`);
 (NEW_GOAL `x' IN ({u0:real^3} UNION q)`);
 (ASM_REWRITE_TAC[IN]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_TAC[REAL_ARITH `&0 <= x <=> ~(x < &0)`]);
 (STRIP_TAC);
 (UNDISCH_TAC `x IN ball (u0:real^3,&1)`);
 (ASM_REWRITE_TAC[IN_BALL; SET_RULE `{u} UNION q = u INSERT (q DELETE u)`]);
 (REWRITE_WITH `vsum (u0 INSERT (q DELETE u0:real^3)) (\v. f v % v) = 
  (if u0 IN (q DELETE u0) then vsum (q DELETE u0) (\v. f v % v)
   else (\v. f v % v) u0 + vsum (q DELETE u0) (\v. f v % v))`);
 (MATCH_MP_TAC Marchal_cells_2_new.VSUM_CLAUSES_alt);
 (ASM_REWRITE_TAC[FINITE_DELETE]);
 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (ASM_MESON_TAC[]);
 (ONCE_REWRITE_TAC[DIST_SYM]);
 (REWRITE_TAC[dist]);
 (REWRITE_WITH `!a. a - u0 = a - (sum ({u0:real^3} UNION q) f) % u0`);
 (ASM_REWRITE_TAC[]);
 (VECTOR_ARITH_TAC);


 (NEW_GOAL `sum ({u0} UNION q) f = f u0 + sum (q DELETE u0:real^3) f`);
 (REWRITE_TAC[SET_RULE `{u} UNION q = u INSERT (q DELETE u)`]);
 (REWRITE_WITH `sum (u0 INSERT (q DELETE u0:real^3)) f = 
  (if u0 IN (q DELETE u0) then sum (q DELETE u0) f
   else f u0 + sum (q DELETE u0) f)`);
 (MATCH_MP_TAC Marchal_cells_2_new.SUM_CLAUSES_alt);
 (ASM_REWRITE_TAC[FINITE_DELETE]);
 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (ASM_MESON_TAC[]);
 (ASM_REWRITE_TAC[]);
 (REWRITE_TAC[VECTOR_ADD_RDISTRIB;
   VECTOR_ARITH `(a + b) - (a + c:real^3) = b - c`;
   ASSUME `sum ({u0} UNION q) f = f u0 + sum (q DELETE u0:real^3) f`; ]);
 (ABBREV_TAC `h = sum (q DELETE u0:real^3) f`);
 (ABBREV_TAC `y = inv (h) % vsum (q DELETE u0) (\v:real^3. f v % v)`);
 (NEW_GOAL `h > &1`);
 (ASM_REAL_ARITH_TAC);
 (REWRITE_WITH `vsum (q DELETE u0) (\v. f v % v) = h % y:real^3`);
 (EXPAND_TAC "y");
 (REWRITE_TAC[VECTOR_MUL_ASSOC]);
 (REWRITE_WITH `h * inv h = &1`);
 (ASM_SIMP_TAC [Trigonometry2.REAL_MUL_LRINV; REAL_ARITH `h > &1 ==> ~(h = &0)`]);
 (VECTOR_ARITH_TAC);
 (REWRITE_TAC[VECTOR_ARITH `h % a - h % b = h % (a - b)`; NORM_MUL]);
 (REWRITE_TAC[REAL_ARITH `~(a < b) <=> b <= a`]);

 (NEW_GOAL `norm (p - u0) <= norm (y - u0:real^3)`);
 (MATCH_MP_TAC Tactics_jordan.REAL_POW_2_LE);
 (REWRITE_TAC[NORM_POS_LE]);
 (REWRITE_WITH 
  `norm (y - u0) pow 2 = norm (p - u0) pow 2 + norm (y - p:real^3) pow 2`);
 (MATCH_MP_TAC PYTHAGORAS);
 (REWRITE_TAC[orthogonal]);
 (REWRITE_WITH `p = circumcenter (set_of_list [u0;u1:real^3])`);
 (ASM_REWRITE_TAC[set_of_list]);
 (ONCE_REWRITE_TAC[DOT_SYM]);
 (MATCH_MP_TAC Rogers.MHFTTZN4);
 (EXISTS_TAC `V:real^3->bool` THEN EXISTS_TAC `1`);
 (REPEAT STRIP_TAC);
 (ASM_REWRITE_TAC[]);
 (ASM_REWRITE_TAC[]);

 (REWRITE_TAC[ASSUME `voronoi_list V [u0; u1] = S`]);
 (REWRITE_TAC[AFFINE_HULL_EXPLICIT_ALT; IN; IN_ELIM_THM]);
 (EXISTS_TAC `q DELETE u0:real^3`);
 (EXISTS_TAC `(\v:real^3. inv h * f v)`);
 (REPEAT STRIP_TAC);
 (ASM_REWRITE_TAC[FINITE_DELETE]);
 (ASM_SET_TAC[]);
 (ASM_REWRITE_TAC[SUM_LMUL]);
 (ASM_SIMP_TAC [Trigonometry2.REAL_MUL_LRINV; REAL_ARITH `h > &1 ==> ~(h = &0)`]);
 (REWRITE_TAC[GSYM VECTOR_MUL_ASSOC]);
 (ASM_REWRITE_TAC[VSUM_LMUL]);

 (REWRITE_TAC[set_of_list]);
 (NEW_GOAL `{u0, u1:real^3} SUBSET affine hull {u0, u1}`);
 (REWRITE_TAC[Qzksykg.SET_SUBSET_AFFINE_HULL]);
 (ASM_SET_TAC[]);
 (REWRITE_TAC[REAL_ARITH `a <= a + b <=> &0 <= b`; NORM_POW_2; DOT_POS_LE]);

 (NEW_GOAL `&1 <= norm (p - u0:real^3)`);
 (EXPAND_TAC "p");
 (REWRITE_TAC[CIRCUMCENTER_2; midpoint; 
   VECTOR_ARITH `inv (&2) % (u0 + u1) - u0 = inv (&2) % (u1 - u0)`; 
   NORM_MUL; REAL_ARITH `abs (inv(&2)) = inv (&2)`]);
 (REWRITE_TAC[GSYM dist]);
 (REWRITE_WITH `&1 = inv (&2) * &2`);
 (REAL_ARITH_TAC);
 (REWRITE_TAC[REAL_ARITH `inv (&2) * &2 <= inv (&2) * a <=> &2 <= a`]);
 (MP_TAC (ASSUME `packing (V:real^3->bool)`));
 (REWRITE_TAC[packing] THEN STRIP_TAC);
 (FIRST_ASSUM MATCH_MP_TAC);
 (ASM_REWRITE_TAC[] THEN ASM_SET_TAC[]);
 (REWRITE_WITH `abs h = h`);
 (ASM_REAL_ARITH_TAC);

 (NEW_GOAL `h <= h * norm (y - u0:real^3)`);
 (REWRITE_TAC[REAL_ARITH `h <= h * a <=> &0 <= h * (a - &1)`]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (ASM_REAL_ARITH_TAC);
 (ASM_REAL_ARITH_TAC);

 (ASM_REWRITE_TAC[]);
 (ASM_REWRITE_TAC[]);

(* ========================================================================== *)
 (NEW_GOAL `~(S:real^3->bool = {})`);
 (STRIP_TAC);
 (NEW_GOAL `~(aff_dim (u0:real^3 INSERT S) = &3)`);
 (REWRITE_TAC[ASSUME `S:real^3->bool = {}`; AFF_DIM_SING]);
 (ARITH_TAC);
 (ASM_MESON_TAC[]);
 (SWITCH_TAC);
 (UP_ASM_TAC THEN SIMP_TAC[CONVEX_HULL_INSERT; 
   ASSUME `~(S:real^3->bool = {})`]);
 (REWRITE_WITH `convex hull S = S:real^3->bool`);
 (REWRITE_TAC[CONVEX_HULL_EQ]);
 (EXPAND_TAC "S" THEN REWRITE_TAC[Packing3.CONVEX_VORONOI_LIST]);
 (ASM_REWRITE_TAC[]);
 (REWRITE_TAC[IN_UNIONS; IN; IN_ELIM_THM]);
 (REPEAT STRIP_TAC);

 (EXISTS_TAC `rogers V vl`);
 (REPEAT STRIP_TAC);
 (EXISTS_TAC `vl:(real^3)list`);
 (ASM_REWRITE_TAC[]);

 (ASM_SIMP_TAC[Marchal_cells_2.ROGERS_EXPLICIT]);
 (REWRITE_TAC[CONVEX_HULL_4; IN_ELIM_THM]);

 (UNDISCH_TAC `(t:real^3->bool) b'`);
 (ASM_REWRITE_TAC[CONVEX_HULL_3; IN_ELIM_THM]);
 (REPEAT STRIP_TAC);

 (EXISTS_TAC `u:real`);
 (EXISTS_TAC `v * u'`);
 (EXISTS_TAC `v * v'`);
 (EXISTS_TAC `v * w`);
 (ASM_SIMP_TAC[REAL_LE_MUL]);
 (STRIP_TAC);

 (REWRITE_TAC[REAL_ARITH `u + v * u' + v * v' + v * w = u + v * (u' + v' +w)`]);
 (ASM_REWRITE_TAC[]);
 (ASM_REAL_ARITH_TAC);

 (REWRITE_WITH `(HD vl):real^3 = HD (truncate_simplex 1 vl)`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC Packing3.HD_TRUNCATE_SIMPLEX);
 (REWRITE_WITH `LENGTH (vl:(real^3)list) = 3 + 1 /\ CARD (set_of_list vl) = 3 + 1`);
 (MATCH_MP_TAC Rogers.BARV_IMP_LENGTH_EQ_CARD);
 (EXISTS_TAC `V:real^3->bool`);
 (ASM_REWRITE_TAC[]);
 (ARITH_TAC);

 (ASM_REWRITE_TAC[HD]);
 (VECTOR_ARITH_TAC);

(* ========================================================================= *)
(* ========================================================================== *)

 (NEW_GOAL 
 `!X. mcell_set V X /\ ~NULLSET (X INTER C)
     ==> (?k vl.
              2 <= k /\
              barV V 3 vl /\
              X = mcell k V vl /\
              truncate_simplex 1 vl = [u0; u1])`);

 (REWRITE_TAC[mcell_set_2; IN_ELIM_THM]);
 (REPEAT STRIP_TAC);

 (NEW_GOAL `~NULLSET (X INTER UNIONS
      {rogers V vl | vl | barV V 3 vl /\ truncate_simplex 1 vl = [u0; u1]})`);
 (STRIP_TAC);
 (UNDISCH_TAC `~NULLSET (X INTER C)`);
 (REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X INTER
       UNIONS
       {rogers V vl | vl | barV V 3 vl /\ truncate_simplex 1 vl = [u0; u1]}`);
 (STRIP_TAC);
 (ASM_REWRITE_TAC[]);
 (ASM_SET_TAC[]);
 (UP_ASM_TAC THEN REWRITE_TAC[INTER_UNIONS]);
 (STRIP_TAC);

 (NEW_GOAL 
  `!s. ~NULLSET (UNIONS s) /\ FINITE s ==> (?t. t IN s /\ ~NULLSET t)`);
 (MESON_TAC[NEGLIGIBLE_UNIONS]);
 (ABBREV_TAC `St = {X INTER x | x IN
                    {rogers V vl | vl | barV V 3 vl /\
                                        truncate_simplex 1 vl = [u0; u1]}}`);
 (NEW_GOAL `?t. t IN St /\ ~NULLSET t`);
 (FIRST_ASSUM MATCH_MP_TAC);
 (ASM_REWRITE_TAC[]);
 (EXPAND_TAC "St");
 (ABBREV_TAC `Sr = {rogers V vl | vl | barV V 3 vl /\
                                  truncate_simplex 1 vl = [u0; u1]}`);
 (ABBREV_TAC `f = (\x:real^3->bool. X INTER x)`);
 (MATCH_MP_TAC FINITE_SUBSET);
 (EXISTS_TAC `{y:real^3->bool | ?x:real^3->bool. x IN Sr /\ y = f x }`);
 (STRIP_TAC);



 (MATCH_MP_TAC FINITE_IMAGE_EXPAND);
 (ABBREV_TAC `Ss = {vl | barV V 3 vl /\ truncate_simplex 1 vl = [u0; u1]}`);
 (MATCH_MP_TAC FINITE_SUBSET);
 (EXISTS_TAC `{y | ?vl. vl IN Ss /\ y = rogers V vl}`);
 (STRIP_TAC);
 (MATCH_MP_TAC FINITE_IMAGE_EXPAND);
 (ABBREV_TAC `Sx = V INTER ball (u0:real^3, &4)`);
 (MATCH_MP_TAC FINITE_SUBSET);
 (EXISTS_TAC `{y | ?u0 u1 u2 u3:real^3.
                      u0 IN Sx /\
                      u1 IN Sx /\
                      u2 IN Sx /\
                      u3 IN Sx /\
                      y = [u0; u1; u2; u3]}`);
 (STRIP_TAC);
 (MATCH_MP_TAC Ajripqn.FINITE_SET_LIST_LEMMA);
 (EXPAND_TAC "Sx");
 (MATCH_MP_TAC Pack2.KIUMVTC);
 (ASM_REWRITE_TAC[]);
 (EXPAND_TAC "Ss");
 (REWRITE_TAC[SUBSET; IN; IN_ELIM_THM]);
 (REPEAT STRIP_TAC);

 (NEW_GOAL `?v0 v1 v2 v3. x = [v0;v1;v2;v3:real^3]`);
 (MATCH_MP_TAC Marchal_cells.BARV_3_EXPLICIT);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (EXISTS_TAC `v0:real^3`);
 (EXISTS_TAC `v1:real^3`);
 (EXISTS_TAC `v2:real^3`);
 (EXISTS_TAC `v3:real^3`);
 (ASM_REWRITE_TAC[]);

 (NEW_GOAL `{v0, v1, v2, v3:real^3} SUBSET Sx`);
 (EXPAND_TAC "Sx");
 (REWRITE_TAC[SUBSET_INTER]);
 (REWRITE_WITH `{v0, v1, v2, v3:real^3} = set_of_list x`);
 (ASM_REWRITE_TAC[set_of_list]);
 (STRIP_TAC);
 (MATCH_MP_TAC Packing3.BARV_SUBSET);
 (EXISTS_TAC `3` THEN ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC Qzyzmjc.BARV_3_IMP_FINITE_lemma2);
 (EXISTS_TAC `V:real^3->bool`);
 (ASM_REWRITE_TAC[]);
 (NEW_GOAL `HD (truncate_simplex 1 x) = u0:real^3`);
 (ASM_REWRITE_TAC[HD]);
 (NEW_GOAL `HD (truncate_simplex 1 x) = v0:real^3`);
 (REWRITE_TAC[ASSUME `x = [v0; v1; v2; v3:real^3]`;  
   TRUNCATE_SIMPLEX_EXPLICIT_1; HD]);
 (REWRITE_WITH `u0 = v0:real^3`);
 (ASM_MESON_TAC[]);
 (REWRITE_TAC[set_of_list] THEN SET_TAC[]);
 (UP_ASM_TAC THEN SET_TAC[]);

 (EXPAND_TAC "Sr" THEN EXPAND_TAC "Ss");
 (SET_TAC[]);
 (REWRITE_WITH `{X INTER x:real^3->bool | x IN Sr} = {f x | x IN Sr}`);
 (EXPAND_TAC "f");
 (REFL_TAC);
 (SET_TAC[]);
 (UP_ASM_TAC THEN EXPAND_TAC "St" THEN REWRITE_TAC[IN; IN_ELIM_THM]);
 (REPEAT STRIP_TAC);

 (NEW_GOAL `x SUBSET UNIONS {mcell i V vl | i <= 4}`);
 (ASM_REWRITE_TAC[SUBSET; IN_UNIONS; IN; IN_ELIM_THM]);
 (REPEAT STRIP_TAC);
 (NEW_GOAL `?i. i <= 4 /\ x' IN mcell i V vl`);
 (MATCH_MP_TAC Sltstlo.SLTSTLO1);
 (ASM_REWRITE_TAC[IN]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (EXISTS_TAC `mcell i' V vl`);
 (STRIP_TAC);
 (EXISTS_TAC `i':num` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN REWRITE_TAC[IN]);

 (NEW_GOAL `~NULLSET (X INTER UNIONS {mcell i V vl | i <= 4})`);
 (STRIP_TAC);
 (UNDISCH_TAC `~NULLSET (t)`);
 (REWRITE_TAC[ASSUME `t:real^3->bool = X INTER x`]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X INTER UNIONS {mcell i V vl | i <= 4}`);
 (STRIP_TAC);
 (ASM_REWRITE_TAC[]);
 (ASM_SET_TAC[]);
 (UP_ASM_TAC THEN REWRITE_TAC[INTER_UNIONS]);
 (STRIP_TAC);

 (NEW_GOAL 
  `!s. ~NULLSET (UNIONS s) /\ FINITE s ==> (?t. t IN s /\ ~NULLSET t)`);
 (MESON_TAC[NEGLIGIBLE_UNIONS]);
 (ABBREV_TAC `Sx = {X INTER x | x IN {mcell i V vl | i <= 4}}`);
 (NEW_GOAL `?t. t IN Sx /\ ~NULLSET t`);
 (FIRST_ASSUM MATCH_MP_TAC);
 (ASM_REWRITE_TAC[]);
 (EXPAND_TAC "Sx");
 (ABBREV_TAC `Sy = {mcell i V vl | i <= 4}`);
 (ABBREV_TAC `f = (\x:real^3->bool. X INTER x)`);
 (MATCH_MP_TAC FINITE_SUBSET);
 (EXISTS_TAC `{y:real^3->bool | ?x:real^3->bool. x IN Sy /\ y = f x }`);
 (STRIP_TAC);
 (MATCH_MP_TAC FINITE_IMAGE_EXPAND);
 (EXPAND_TAC "Sy");
 (REWRITE_TAC[GSYM IN_NUMSEG_0]);
 (ABBREV_TAC `g = (\i:num. mcell i V vl)`);
 (REWRITE_WITH `{mcell i V vl | i IN 0..4} = {g i | i IN 0..4}`);
 (EXPAND_TAC "g" THEN REWRITE_TAC[]);
 (MATCH_MP_TAC FINITE_SUBSET);
 (EXISTS_TAC `{y:real^3->bool | ?i. i IN 0..4 /\ y = g i}`);
 (STRIP_TAC);
 (MATCH_MP_TAC FINITE_IMAGE_EXPAND);
 (REWRITE_TAC[FINITE_NUMSEG]);
 (SET_TAC[]);
 (REWRITE_WITH `{X INTER x:real^3->bool | x IN Sy} = {f x | x IN Sy}`);
 (EXPAND_TAC "f" THEN REWRITE_TAC[]);
 (SET_TAC[]);
 (UP_ASM_TAC THEN EXPAND_TAC "Sx" THEN REWRITE_TAC[IN; IN_ELIM_THM]);
 (REPEAT STRIP_TAC);

(* ========================================================================= *)

 (NEW_GOAL `i = i' /\ mcell i V ul = mcell i' V vl`);
 (MATCH_MP_TAC Ajripqn.AJRIPQN);
 (ASM_REWRITE_TAC[GSYM Ajripqn.UP_TO_4_KY_LEMMA]);
 (REPEAT STRIP_TAC);
 (UNDISCH_TAC `ul IN barV V 3` THEN REWRITE_TAC[IN]);
 (UNDISCH_TAC `~NULLSET t'`);
 (ASM_REWRITE_TAC[]);
 (EXISTS_TAC `i:num` THEN EXISTS_TAC `vl:(real^3)list`);
 (ASM_REWRITE_TAC[]);

(* ========================================================================= *)

 (ASM_CASES_TAC `i' = 0`);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~NULLSET (X INTER C)`);
 (REWRITE_TAC[]);
 (REWRITE_WITH `X INTER C = {}:real^3->bool`);
 (ASM_REWRITE_TAC[MCELL_EXPLICIT; mcell0]);
 (REWRITE_WITH `(HD vl):real^3 = HD (truncate_simplex 1 vl)`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC Packing3.HD_TRUNCATE_SIMPLEX);
 (REWRITE_WITH `LENGTH (vl:(real^3)list) = 3 + 1 /\ CARD (set_of_list vl) = 3 + 1`);
 (MATCH_MP_TAC Rogers.BARV_IMP_LENGTH_EQ_CARD);
 (EXISTS_TAC `V:real^3->bool`);
 (ASM_REWRITE_TAC[]);
 (ARITH_TAC);
 (ASM_REWRITE_TAC[HD]);
 (NEW_GOAL `C SUBSET ball (u0:real^3, sqrt (&2))`);
 (NEW_GOAL `ball (u0:real^3, &1) SUBSET ball (u0, sqrt (&2))`);
 (MATCH_MP_TAC SUBSET_BALL);
 (MATCH_MP_TAC (REAL_ARITH `a < b ==> a <= b`));
 (REWRITE_TAC[Marchal_cells_2_new.ZERO_LT_SQRT_2]);
 (ASM_SET_TAC[]);
 (UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);
 (ASM_MESON_TAC[]);

 (ASM_CASES_TAC `i' = 1`);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~NULLSET (X INTER C)`);
 (REWRITE_TAC[]);
 (REWRITE_WITH `X INTER C = {}:real^3->bool`);
 (ASM_REWRITE_TAC[MCELL_EXPLICIT; mcell1]);
 (COND_CASES_TAC);
 (NEW_GOAL `?v0 v1 v2 v3. vl = [v0;v1;v2;v3:real^3]`);
 (MATCH_MP_TAC Marchal_cells.BARV_3_EXPLICIT);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (ASM_REWRITE_TAC[HD; TL]);

 (REWRITE_WITH `v0 = u0:real^3`);
 (NEW_GOAL `HD (truncate_simplex 1 vl) = u0:real^3`);
 (ASM_REWRITE_TAC[HD]);
 (NEW_GOAL `HD (truncate_simplex 1 vl) = v0:real^3`);
 (REWRITE_TAC[ASSUME `vl = [v0; v1; v2; v3:real^3]`;  
   TRUNCATE_SIMPLEX_EXPLICIT_1; HD]);
 (ASM_MESON_TAC[]);

 (REWRITE_WITH `v1 = u1:real^3`);
 (NEW_GOAL `HD (TL(truncate_simplex 1 vl)) = u1:real^3`);
 (ASM_REWRITE_TAC[HD; TL]);
 (NEW_GOAL `HD (TL(truncate_simplex 1 vl)) = v1:real^3`);
 (REWRITE_TAC[ASSUME `vl = [v0; v1; v2; v3:real^3]`;  
   TRUNCATE_SIMPLEX_EXPLICIT_1; HD; TL]);
 (ASM_MESON_TAC[]);

 (NEW_GOAL `C SUBSET (rcone_gt u0 u1 (hl [u0:real^3; u1] / sqrt (&2)))`);
 (EXPAND_TAC "C");
 (SET_TAC[ASSUME `rcone_gt u0 u1 c SUBSET
                   W INTER rcone_gt u0 u1 (hl [u0:real^3; u1] / sqrt (&2))`]);
 (UP_ASM_TAC THEN SET_TAC[]);
 (SET_TAC[]);
 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (ASM_ARITH_TAC);

(* ========================================================================= *)

 (ABBREV_TAC `f1 = 
  (\ul. dist (u0:real^3, 
              closest_point (affine hull {u1, EL 2 ul, mxi V ul}) u0))`);

 (ABBREV_TAC `P1 = { (f1:(real^3)list->real) ul |ul | barV V 3 ul /\
                                 ~NULLSET (mcell 3 V ul INTER C) /\
                                  truncate_simplex 1 ul = [u0; u1]}`);

 (NEW_GOAL `~(P1 = {}) ==> (?b:real. b IN P1 /\ (!x. x IN P1 ==> b <= x))`);
 (STRIP_TAC);
 (MATCH_MP_TAC INF_FINITE_LEMMA);
 (ASM_REWRITE_TAC[]);
 (EXPAND_TAC "P1");
 (ONCE_REWRITE_TAC [SET_RULE `{f x| x | P x} = {f x | x IN {y | P y}}`]);
 (ONCE_REWRITE_TAC [SET_RULE `{f x| x IN s} = {y | ?x. x IN s /\ y = f x}`]);
 (MATCH_MP_TAC FINITE_IMAGE_EXPAND);
 (MATCH_MP_TAC FINITE_SUBSET);
 (EXISTS_TAC `{y | ?v0:real^3 v1 u2 u3.
                      v0 IN (V INTER ball (u0:real^3, &4)) /\
                      v1 IN (V INTER ball (u0, &4)) /\
                      u2 IN (V INTER ball (u0, &4)) /\
                      u3 IN (V INTER ball (u0, &4)) /\
                      y = [v0; v1; u2; u3]}`);
 (STRIP_TAC);
 (MATCH_MP_TAC FINITE_SET_LIST_LEMMA);
 (ASM_SIMP_TAC[FINITE_PACK_LEMMA]);
 (REWRITE_TAC[SUBSET] THEN ONCE_REWRITE_TAC[IN] THEN REWRITE_TAC[IN_ELIM_THM]);
 (REPEAT STRIP_TAC);
 (NEW_GOAL `?v0 v1 u2 u3. x = [v0; v1; u2; u3:real^3]`);
 (MATCH_MP_TAC BARV_3_EXPLICIT);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (EXISTS_TAC `v0:real^3` THEN EXISTS_TAC `v1:real^3` THEN     
   EXISTS_TAC `u2:real^3` THEN EXISTS_TAC `u3:real^3`);
 (ASM_REWRITE_TAC[]);
 (NEW_GOAL `v0 = u0:real^3`);
 (REWRITE_WITH `v0 = HD (x:(real^3)list)`);
 (ASM_REWRITE_TAC[HD]);
 (REWRITE_WITH `u0 = HD (truncate_simplex 1 (x:(real^3)list))`);
 (ASM_REWRITE_TAC[HD]);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ] THEN MATCH_MP_TAC Packing3.HD_TRUNCATE_SIMPLEX);
 (ASM_REWRITE_TAC[LENGTH] THEN ARITH_TAC);
 (NEW_GOAL `set_of_list x SUBSET ball (u0:real^3,&4)`);
 (MATCH_MP_TAC Qzyzmjc.BARV_3_IMP_FINITE_lemma2);
 (EXISTS_TAC `V:real^3->bool`);
 (ASM_REWRITE_TAC[set_of_list]);
 (SET_TAC[]);
 (NEW_GOAL `set_of_list x SUBSET V:real^3->bool`);
 (MATCH_MP_TAC Packing3.BARV_SUBSET);
 (EXISTS_TAC `3` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN ASM_REWRITE_TAC[set_of_list]);
 (SET_TAC[]);

 (ABBREV_TAC `r1 = (if (P1 = {}:real->bool) then &1 
                    else (@b. b IN P1 /\ (!x. x IN P1 ==> b <= x)))`);
 (NEW_GOAL `&0 < r1`);
 (EXPAND_TAC "r1");
 (COND_CASES_TAC);
 (REAL_ARITH_TAC);
 (NEW_GOAL `?b:real. b IN P1 /\ (!x. x IN P1 ==> b <= x)`);
 (ASM_SIMP_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (ABBREV_TAC `P  = (\b:real. b IN P1 /\ (!x. x IN P1 ==> b <= x))`);
 (ABBREV_TAC `zz = (@) (P:real->bool)`);
 (NEW_GOAL `(P:real->bool) zz`);
 (EXPAND_TAC "zz");
 (MATCH_MP_TAC SELECT_AX);
 (EXISTS_TAC `b':real`);
 (EXPAND_TAC "P" THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN EXPAND_TAC "P" THEN REWRITE_TAC[]);
 (EXPAND_TAC "P1" THEN REWRITE_TAC[IN; IN_ELIM_THM]);
 (REPEAT STRIP_TAC);
 (ASM_REWRITE_TAC[]);
 (EXPAND_TAC "f1");
 (MATCH_MP_TAC DIST_POS_LT);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (REWRITE_WITH `closest_point (affine hull {u1, EL 2 ul, mxi V ul}) u0 = u0
  <=> u0 IN (affine hull {u1:real^3, EL 2 ul, mxi V ul})`);
 (MATCH_MP_TAC CLOSEST_POINT_REFL);
 (REWRITE_TAC[CLOSED_AFFINE_HULL]);
 (REWRITE_TAC[AFFINE_HULL_EQ_EMPTY] THEN SET_TAC[]);
 (STRIP_TAC);
 (UNDISCH_TAC `~NULLSET (mcell 3 V ul INTER C)`);
 (REWRITE_TAC[] THEN MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `mcell 3 V ul`);
 (REWRITE_TAC[SET_RULE `A INTER B SUBSET A`]);
 (REWRITE_TAC[MCELL_EXPLICIT; mcell3]);
 (COND_CASES_TAC);

 (NEW_GOAL `?v0 v1 v2 v3. ul = [v0;v1;v2;v3:real^3]`);
 (MATCH_MP_TAC Marchal_cells.BARV_3_EXPLICIT);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (ASM_REWRITE_TAC[TRUNCATE_SIMPLEX_EXPLICIT_2; set_of_list]);

 (REWRITE_WITH `v0 = u0:real^3`);
 (NEW_GOAL `HD (truncate_simplex 1 ul) = u0:real^3`);
 (ASM_REWRITE_TAC[HD]);
 (NEW_GOAL `HD (truncate_simplex 1 ul) = v0:real^3`);
 (REWRITE_TAC[ASSUME `ul = [v0; v1; v2; v3:real^3]`;  
   TRUNCATE_SIMPLEX_EXPLICIT_1; HD]);
 (ASM_MESON_TAC[]);

 (REWRITE_WITH `v1 = u1:real^3`);
 (NEW_GOAL `HD (TL(truncate_simplex 1 ul)) = u1:real^3`);
 (ASM_REWRITE_TAC[HD; TL]);
 (NEW_GOAL `HD (TL(truncate_simplex 1 ul)) = v1:real^3`);
 (REWRITE_TAC[ASSUME `ul = [v0; v1; v2; v3:real^3]`;  
   TRUNCATE_SIMPLEX_EXPLICIT_1; HD; TL]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN MESON_TAC[]);
 (REWRITE_TAC[SET_RULE `{a,b,c} UNION {d} = {a,b,c,d}`]);

 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1, v2, mxi V [u0; u1; v2; v3]}`);
 (REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (REWRITE_WITH `affine hull {u0, u1, v2, mxi V [u0; u1; v2; v3]} = 
                 affine hull {u1, v2, mxi V [u0; u1; v2; v3]}`);
 (MATCH_MP_TAC AFFINE_HULL_3_INSERT);
 (REWRITE_WITH `affine hull {u1, v2, mxi V [u0; u1; v2; v3]} = 
                 affine hull {u1, EL 2 ul, mxi V ul}`);
 (ASM_REWRITE_TAC[EL; ARITH_RULE `2 = SUC 1 /\ 1 = SUC 0`; HD; TL]);

 (REWRITE_WITH `v0 = u0:real^3`);
 (NEW_GOAL `HD (truncate_simplex 1 ul) = u0:real^3`);
 (ASM_REWRITE_TAC[HD]);
 (NEW_GOAL `HD (truncate_simplex 1 ul) = v0:real^3`);
 (REWRITE_TAC[ASSUME `ul = [v0; v1; v2; v3:real^3]`;  
   TRUNCATE_SIMPLEX_EXPLICIT_1; HD]);
 (ASM_MESON_TAC[]);

 (REWRITE_WITH `v1 = u1:real^3`);
 (NEW_GOAL `HD (TL(truncate_simplex 1 ul)) = u1:real^3`);
 (ASM_REWRITE_TAC[HD; TL]);
 (NEW_GOAL `HD (TL(truncate_simplex 1 ul)) = v1:real^3`);
 (REWRITE_TAC[ASSUME `ul = [v0; v1; v2; v3:real^3]`;  
   TRUNCATE_SIMPLEX_EXPLICIT_1; HD; TL]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN MESON_TAC[]);
 (ASM_REWRITE_TAC[]);
 (REWRITE_TAC[NEGLIGIBLE_AFFINE_HULL_3]);
 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);

(* ========================================================================= *)

 (ABBREV_TAC `f2 = 
  (\ul. dist (u0:real^3, 
              closest_point (affine hull {u1, EL 2 ul, EL 3 ul}) u0))`);

 (ABBREV_TAC `P2 = { (f2:(real^3)list->real) ul |ul | barV V 3 ul /\
                                 ~NULLSET (mcell 4 V ul INTER C) /\
                                  truncate_simplex 1 ul = [u0; u1]}`);

 (NEW_GOAL `~(P2 = {}) ==> (?b:real. b IN P2 /\ (!x. x IN P2 ==> b <= x))`);
 (STRIP_TAC);
 (MATCH_MP_TAC INF_FINITE_LEMMA);
 (ASM_REWRITE_TAC[]);
 (EXPAND_TAC "P2");
 (ONCE_REWRITE_TAC [SET_RULE `{f x| x | P x} = {f x | x IN {y | P y}}`]);
 (ONCE_REWRITE_TAC [SET_RULE `{f x| x IN s} = {y | ?x. x IN s /\ y = f x}`]);
 (MATCH_MP_TAC FINITE_IMAGE_EXPAND);
 (MATCH_MP_TAC FINITE_SUBSET);
 (EXISTS_TAC `{y | ?v0:real^3 v1 u2 u3.
                      v0 IN (V INTER ball (u0:real^3, &4)) /\
                      v1 IN (V INTER ball (u0, &4)) /\
                      u2 IN (V INTER ball (u0, &4)) /\
                      u3 IN (V INTER ball (u0, &4)) /\
                      y = [v0; v1; u2; u3]}`);
 (STRIP_TAC);
 (MATCH_MP_TAC FINITE_SET_LIST_LEMMA);
 (ASM_SIMP_TAC[FINITE_PACK_LEMMA]);
 (REWRITE_TAC[SUBSET] THEN ONCE_REWRITE_TAC[IN] THEN REWRITE_TAC[IN_ELIM_THM]);
 (REPEAT STRIP_TAC);
 (NEW_GOAL `?v0 v1 u2 u3. x = [v0; v1; u2; u3:real^3]`);
 (MATCH_MP_TAC BARV_3_EXPLICIT);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (EXISTS_TAC `v0:real^3` THEN EXISTS_TAC `v1:real^3` THEN     
   EXISTS_TAC `u2:real^3` THEN EXISTS_TAC `u3:real^3`);
 (ASM_REWRITE_TAC[]);
 (NEW_GOAL `v0 = u0:real^3`);
 (REWRITE_WITH `v0 = HD (x:(real^3)list)`);
 (ASM_REWRITE_TAC[HD]);
 (REWRITE_WITH `u0 = HD (truncate_simplex 1 (x:(real^3)list))`);
 (ASM_REWRITE_TAC[HD]);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ] THEN MATCH_MP_TAC Packing3.HD_TRUNCATE_SIMPLEX);
 (ASM_REWRITE_TAC[LENGTH] THEN ARITH_TAC);
 (NEW_GOAL `set_of_list x SUBSET ball (u0:real^3,&4)`);
 (MATCH_MP_TAC Qzyzmjc.BARV_3_IMP_FINITE_lemma2);
 (EXISTS_TAC `V:real^3->bool`);
 (ASM_REWRITE_TAC[set_of_list]);
 (SET_TAC[]);
 (NEW_GOAL `set_of_list x SUBSET V:real^3->bool`);
 (MATCH_MP_TAC Packing3.BARV_SUBSET);
 (EXISTS_TAC `3` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN ASM_REWRITE_TAC[set_of_list]);
 (SET_TAC[]);

 (ABBREV_TAC `r2 = (if (P2 = {}:real->bool) then &1 
                    else (@b. b IN P2 /\ (!x. x IN P2 ==> b <= x)))`);

 (NEW_GOAL `&0 < r2`);
 (EXPAND_TAC "r2");
 (COND_CASES_TAC);
 (REAL_ARITH_TAC);
 (NEW_GOAL `?b:real. b IN P2 /\ (!x. x IN P2 ==> b <= x)`);
 (ASM_SIMP_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (ABBREV_TAC `P  = (\b:real. b IN P2 /\ (!x. x IN P2 ==> b <= x))`);
 (ABBREV_TAC `zz = (@) (P:real->bool)`);
 (NEW_GOAL `(P:real->bool) zz`);
 (EXPAND_TAC "zz");
 (MATCH_MP_TAC SELECT_AX);
 (EXISTS_TAC `b':real`);
 (EXPAND_TAC "P" THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN EXPAND_TAC "P" THEN REWRITE_TAC[]);
 (EXPAND_TAC "P2" THEN REWRITE_TAC[IN; IN_ELIM_THM]);
 (REPEAT STRIP_TAC);
 (ASM_REWRITE_TAC[]);
 (EXPAND_TAC "f2");
 (MATCH_MP_TAC DIST_POS_LT);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (REWRITE_WITH `closest_point (affine hull {u1, EL 2 ul, EL 3 ul}) u0 = u0
  <=> u0 IN (affine hull {u1:real^3, EL 2 ul, EL 3 ul})`);
 (MATCH_MP_TAC CLOSEST_POINT_REFL);
 (REWRITE_TAC[CLOSED_AFFINE_HULL]);
 (REWRITE_TAC[AFFINE_HULL_EQ_EMPTY] THEN SET_TAC[]);
 (STRIP_TAC);
 (UNDISCH_TAC `~NULLSET (mcell 4 V ul INTER C)`);
 (REWRITE_TAC[] THEN MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `mcell 4 V ul`);
 (REWRITE_TAC[SET_RULE `A INTER B SUBSET A`]);
 (SIMP_TAC[MCELL_EXPLICIT; ARITH_RULE `4 >= 4`; mcell4]);
 (COND_CASES_TAC);

 (NEW_GOAL `?v0 v1 v2 v3. ul = [v0;v1;v2;v3:real^3]`);
 (MATCH_MP_TAC Marchal_cells.BARV_3_EXPLICIT);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (ASM_REWRITE_TAC[set_of_list]);

 (REWRITE_WITH `v0 = u0:real^3`);
 (NEW_GOAL `HD (truncate_simplex 1 ul) = u0:real^3`);
 (ASM_REWRITE_TAC[HD]);
 (NEW_GOAL `HD (truncate_simplex 1 ul) = v0:real^3`);
 (REWRITE_TAC[ASSUME `ul = [v0; v1; v2; v3:real^3]`;  
   TRUNCATE_SIMPLEX_EXPLICIT_1; HD]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN MESON_TAC[]);

 (REWRITE_WITH `v1 = u1:real^3`);
 (NEW_GOAL `HD (TL(truncate_simplex 1 ul)) = u1:real^3`);
 (ASM_REWRITE_TAC[HD; TL]);
 (NEW_GOAL `HD (TL(truncate_simplex 1 ul)) = v1:real^3`);
 (REWRITE_TAC[ASSUME `ul = [v0; v1; v2; v3:real^3]`;  
   TRUNCATE_SIMPLEX_EXPLICIT_1; HD; TL]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN MESON_TAC[]);

 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1, v2, v3:real^3}`);
 (REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (REWRITE_WITH `affine hull {u0, u1, v2, v3:real^3} = 
                 affine hull {u1, v2, v3}`);
 (MATCH_MP_TAC AFFINE_HULL_3_INSERT);
 (REWRITE_WITH `affine hull {u1, v2, v3:real^3} = 
                 affine hull {u1, EL 2 ul, EL 3 ul}`);
 (ASM_REWRITE_TAC[EL; ARITH_RULE `3 = SUC 2 /\ 2 = SUC 1 /\ 1 = SUC 0`; HD; TL]);
 (ASM_REWRITE_TAC[]);

 (REWRITE_TAC[NEGLIGIBLE_AFFINE_HULL_3]);
 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);

(* ========================================================================= *)

 (ABBREV_TAC `r = min (&1) (min r1 r2)`);
 (NEW_GOAL `&0 < r`);
 (EXPAND_TAC "r");
 (UNDISCH_TAC `&0 < r1` THEN UNDISCH_TAC `&0  < r2` THEN REAL_ARITH_TAC);

(* ========================================================================= *)

 (ABBREV_TAC `f3 = 
  (\ul. (((smallest_angle_line (EL 2 ul)  (mxi V ul) u0 u1) - u0)
   dot (u1 - u0)) / 
   (norm ((smallest_angle_line (EL 2 ul)  (mxi V ul) u0 u1) - u0)
   * norm (u1 - u0)))`);

 (ABBREV_TAC `P3 = {(f3:(real^3)list->real) ul |ul | barV V 3 ul /\
                                 ~NULLSET (mcell 3 V ul INTER C) /\
                                  truncate_simplex 1 ul = [u0; u1]}`);

 (NEW_GOAL `~(P3 = {}) ==> (?b:real. b IN P3 /\ (!x. x IN P3 ==> x <= b))`);
 (STRIP_TAC);
 (MATCH_MP_TAC SUP_FINITE_LEMMA);
 (ASM_REWRITE_TAC[]);
 (EXPAND_TAC "P3");
 (ONCE_REWRITE_TAC [SET_RULE `{f x| x | P x} = {f x | x IN {y | P y}}`]);
 (ONCE_REWRITE_TAC [SET_RULE `{f x| x IN s} = {y | ?x. x IN s /\ y = f x}`]);
 (MATCH_MP_TAC FINITE_IMAGE_EXPAND);
 (MATCH_MP_TAC FINITE_SUBSET);
 (EXISTS_TAC `{y | ?v0:real^3 v1 u2 u3.
                      v0 IN (V INTER ball (u0:real^3, &4)) /\
                      v1 IN (V INTER ball (u0, &4)) /\
                      u2 IN (V INTER ball (u0, &4)) /\
                      u3 IN (V INTER ball (u0, &4)) /\
                      y = [v0; v1; u2; u3]}`);
 (STRIP_TAC);
 (MATCH_MP_TAC FINITE_SET_LIST_LEMMA);
 (ASM_SIMP_TAC[FINITE_PACK_LEMMA]);
 (REWRITE_TAC[SUBSET] THEN ONCE_REWRITE_TAC[IN] THEN REWRITE_TAC[IN_ELIM_THM]);
 (REPEAT STRIP_TAC);
 (NEW_GOAL `?v0 v1 u2 u3. x = [v0; v1; u2; u3:real^3]`);
 (MATCH_MP_TAC BARV_3_EXPLICIT);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (EXISTS_TAC `v0:real^3` THEN EXISTS_TAC `v1:real^3` THEN     
   EXISTS_TAC `u2:real^3` THEN EXISTS_TAC `u3:real^3`);
 (ASM_REWRITE_TAC[]);
 (NEW_GOAL `v0 = u0:real^3`);
 (REWRITE_WITH `v0 = HD (x:(real^3)list)`);
 (ASM_REWRITE_TAC[HD]);
 (REWRITE_WITH `u0 = HD (truncate_simplex 1 (x:(real^3)list))`);
 (ASM_REWRITE_TAC[HD]);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ] THEN MATCH_MP_TAC Packing3.HD_TRUNCATE_SIMPLEX);
 (ASM_REWRITE_TAC[LENGTH] THEN ARITH_TAC);
 (NEW_GOAL `set_of_list x SUBSET ball (u0:real^3,&4)`);
 (MATCH_MP_TAC Qzyzmjc.BARV_3_IMP_FINITE_lemma2);
 (EXISTS_TAC `V:real^3->bool`);
 (ASM_REWRITE_TAC[set_of_list]);
 (SET_TAC[]);
 (NEW_GOAL `set_of_list x SUBSET V:real^3->bool`);
 (MATCH_MP_TAC Packing3.BARV_SUBSET);
 (EXISTS_TAC `3` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN ASM_REWRITE_TAC[set_of_list]);
 (SET_TAC[]);

 (ABBREV_TAC `d1 = (if (P3 = {}:real->bool) then c 
                    else (@b. b IN P3 /\ (!x. x IN P3 ==> x <= b)))`);

 (NEW_GOAL `d1 < &1`);
 (EXPAND_TAC "d1");
 (COND_CASES_TAC);
 (ASM_REWRITE_TAC[]);
 (NEW_GOAL `?b:real. b IN P3 /\ (!x. x IN P3 ==> x <= b)`);
 (ASM_SIMP_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (ABBREV_TAC `P  = (\b:real. b IN P3 /\ (!x. x IN P3 ==> x <= b))`);
 (ABBREV_TAC `zz = (@) (P:real->bool)`);
 (NEW_GOAL `(P:real->bool) zz`);
 (EXPAND_TAC "zz");
 (MATCH_MP_TAC SELECT_AX);
 (EXISTS_TAC `b':real`);
 (EXPAND_TAC "P" THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN EXPAND_TAC "P" THEN REWRITE_TAC[]);
 (EXPAND_TAC "P3" THEN REWRITE_TAC[IN; IN_ELIM_THM]);
 (REPEAT STRIP_TAC);
 (ASM_REWRITE_TAC[]);
 (EXPAND_TAC "f3");

 (ABBREV_TAC `xx = smallest_angle_line (EL 2 ul) (mxi V ul) u0 u1`);
 (MATCH_MP_TAC REAL_DIV_LT_1_TACTICS);
 (STRIP_TAC);
 (MATCH_MP_TAC (REAL_ARITH `&0 <= a /\ ~(a = &0) ==> &0 < a`));
 (STRIP_TAC);
 (SIMP_TAC[REAL_LE_MUL; NORM_POS_LE]);
 (REWRITE_TAC[REAL_ENTIRE; NORM_EQ_0; VECTOR_ARITH `a - b = vec 0 <=> a = b`]);
 (ASM_REWRITE_TAC[]);
 (EXPAND_TAC "xx");
 (ONCE_REWRITE_TAC[EQ_SYM_EQ] THEN 
   REWRITE_TAC[smallest_angle_line; smallest_angle_set]);
 (STRIP_TAC);
 (ABBREV_TAC `Q = (\x:real^3. x IN convex hull {EL 2 ul, mxi V ul} /\
           (!y. y IN convex hull {EL 2 ul, mxi V ul}
                ==> ((y - u0) dot (u1 - u0)) /
                    (norm (y - u0) * norm (u1 - u0)) <=
                    ((x - u0) dot (u1 - u0)) /
                    (norm (x - u0) * norm (u1 - u0))))`);
 (NEW_GOAL `(Q:real^3->bool) u0`);
 (REWRITE_TAC[ASSUME `u0 = (@) (Q:real^3->bool)`]);
 (MATCH_MP_TAC SELECT_AX);
 (EXPAND_TAC "Q");
 (MATCH_MP_TAC SMALLEST_ANGLE_LINE_EXISTS);
 (STRIP_TAC);
 (ASM_REWRITE_TAC[]);

 (NEW_GOAL `?v1 v2 v3. ul = [u0; v1; v2; v3:real^3]`);
 (NEW_GOAL `?v0 v1 v2 v3. ul = [v0; v1; v2; v3:real^3]`);
 (MATCH_MP_TAC BARV_3_EXPLICIT);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (EXISTS_TAC `v1:real^3` THEN     
   EXISTS_TAC `v2:real^3` THEN EXISTS_TAC `v3:real^3`);
 (REWRITE_TAC[ASSUME `ul = [v0; v1; v2; v3:real^3]`]);

 (NEW_GOAL `v0 = u0:real^3`);
 (REWRITE_WITH `v0 = HD (ul:(real^3)list)`);
 (ASM_REWRITE_TAC[HD]);
 (REWRITE_WITH `u0 = HD (truncate_simplex 1 (ul:(real^3)list))`);
 (ASM_REWRITE_TAC[HD]);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ] THEN MATCH_MP_TAC Packing3.HD_TRUNCATE_SIMPLEX);
 (ASM_REWRITE_TAC[LENGTH] THEN ARITH_TAC);
 (REWRITE_TAC[ASSUME `v0 = u0:real^3`]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (REWRITE_WITH `EL 2 ul = v2:real^3`);
 (ASM_REWRITE_TAC[EL;HD;TL; ARITH_RULE `2 = SUC 1 /\ 1 = SUC 0`]);
 (STRIP_TAC);

 (UNDISCH_TAC `~NULLSET (mcell 3 V ul INTER C)`);
 (REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `mcell 3 V ul` THEN STRIP_TAC);
 (REWRITE_TAC[MCELL_EXPLICIT; mcell3; set_of_list;
   TRUNCATE_SIMPLEX_EXPLICIT_2; ASSUME `ul = [u0; v1; v2; v3:real^3]`;
   SET_RULE `{a,b,c} UNION {d} = {a,b, c,d}`]);
 (COND_CASES_TAC);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, v1, v2, mxi V ul}`);
 (STRIP_TAC);
 (MATCH_MP_TAC COPLANAR_IMP_NEGLIGIBLE);
 (REWRITE_TAC[COPLANAR_AFFINE_HULL_COPLANAR]);
 (REWRITE_TAC[coplanar]);
 (UNDISCH_TAC `u0 IN convex hull {v2, mxi V ul}`);
 (REWRITE_TAC[CONVEX_HULL_2; IN; IN_ELIM_THM] THEN STRIP_TAC);
 (EXISTS_TAC `v1:real^3` THEN EXISTS_TAC `v2:real^3` THEN 
   EXISTS_TAC `mxi V ul`);
 (MATCH_MP_TAC (SET_RULE `a IN s /\ b SUBSET s ==> (a INSERT b) SUBSET s`));
 (REWRITE_TAC[SET_SUBSET_AFFINE_HULL]);
 (REWRITE_TAC[AFFINE_HULL_3; IN; IN_ELIM_THM]);
 (EXISTS_TAC `&0` THEN EXISTS_TAC `u:real` THEN EXISTS_TAC `v:real`);
 (STRIP_TAC);
 (UNDISCH_TAC `u + v = &1` THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN VECTOR_ARITH_TAC);
 (ASM_REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);
 (SET_TAC[]);

 (UP_ASM_TAC THEN EXPAND_TAC "Q");
 (STRIP_TAC);
 (UNDISCH_TAC `~NULLSET (mcell 3 V ul INTER C)` THEN REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `mcell 3 V ul`);
 (REWRITE_TAC[SET_RULE `A INTER B SUBSET A`]);
 (REWRITE_TAC[MCELL_EXPLICIT; mcell3]);
 (COND_CASES_TAC);
 (NEW_GOAL `?v2 v3. ul = [u0;u1;v2;v3:real^3]`);
 (NEW_GOAL `?v0 v1 v2 v3. ul = [v0;v1;v2;v3:real^3]`);
 (MATCH_MP_TAC BARV_3_EXPLICIT);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (EXISTS_TAC `v2:real^3` THEN EXISTS_TAC `v3:real^3`);
 (REWRITE_TAC[ASSUME `ul = [v0;v1;v2;v3:real^3]`]);

 (REWRITE_WITH `v0 = u0:real^3`);
 (NEW_GOAL `HD (truncate_simplex 1 ul) = u0:real^3`);
 (ASM_REWRITE_TAC[HD]);
 (NEW_GOAL `HD (truncate_simplex 1 ul) = v0:real^3`);
 (REWRITE_TAC[ASSUME `ul = [v0; v1; v2; v3:real^3]`;  
   TRUNCATE_SIMPLEX_EXPLICIT_1; HD]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN MESON_TAC[]);

 (REWRITE_WITH `v1 = u1:real^3`);
 (NEW_GOAL `HD (TL(truncate_simplex 1 ul)) = u1:real^3`);
 (ASM_REWRITE_TAC[HD; TL]);
 (NEW_GOAL `HD (TL(truncate_simplex 1 ul)) = v1:real^3`);
 (REWRITE_TAC[ASSUME `ul = [v0; v1; v2; v3:real^3]`;  
   TRUNCATE_SIMPLEX_EXPLICIT_1; HD; TL]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN MESON_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (ASM_REWRITE_TAC[TRUNCATE_SIMPLEX_EXPLICIT_2; set_of_list; 
   SET_RULE `{a,b,c} UNION {d} = {a,b,c,d}`]);
 (REWRITE_TAC[GSYM (ASSUME `u0 = (@) (Q:real^3->bool)`)]);

 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1, v2, mxi V ul}`);
 (REWRITE_TAC[ASSUME `ul = [u0; u1; v2; v3:real^3]`;   
               CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (REWRITE_WITH `affine hull {u0, u1, v2, mxi V [u0; u1; v2; v3]} = 
                 affine hull {u1, v2, mxi V [u0; u1; v2; v3]}`);
 (MATCH_MP_TAC AFFINE_HULL_3_INSERT);

 (NEW_GOAL `convex hull {EL 2 ul, mxi V ul} SUBSET 
             affine hull {EL 2 ul, mxi V ul}`);
 (REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (NEW_GOAL `affine hull {EL 2 ul, mxi V ul} SUBSET 
             affine hull {u1, v2, mxi V [u0; u1; v2; v3]}`);
 (MATCH_MP_TAC AFFINE_SUBSET_KY_LEMMA);
 (ASM_REWRITE_TAC[EL; HD; TL; ARITH_RULE `2 = SUC 1 /\ 1 = SUC 0`]);
 (SET_TAC[]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN 
   UNDISCH_TAC `u0 IN convex hull {EL 2 ul, mxi V ul}` THEN SET_TAC[]);
 (REWRITE_TAC[NEGLIGIBLE_AFFINE_HULL_3]);
 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);

 (MATCH_MP_TAC (REAL_ARITH `(a <= b) /\ ~(a = b) ==> a < b`));
 (REWRITE_TAC[NORM_CAUCHY_SCHWARZ; NORM_CAUCHY_SCHWARZ_EQ]);
 (NEW_GOAL `xx IN convex hull {(EL 2 ul) ,(mxi V ul)}`);
 (MATCH_MP_TAC SMALLEST_ANGLE_IN_CONVEX_HULL);
 (EXISTS_TAC `u0:real^3` THEN EXISTS_TAC `u1:real^3`);
 (ASM_REWRITE_TAC[]);

 (NEW_GOAL `?v1 v2 v3. ul = [u0; v1; v2; v3:real^3]`);
 (NEW_GOAL `?v0 v1 v2 v3. ul = [v0; v1; v2; v3:real^3]`);
 (MATCH_MP_TAC BARV_3_EXPLICIT);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (EXISTS_TAC `v1:real^3` THEN     
   EXISTS_TAC `v2:real^3` THEN EXISTS_TAC `v3:real^3`);
 (REWRITE_TAC[ASSUME `ul = [v0; v1; v2; v3:real^3]`]);

 (NEW_GOAL `v0 = u0:real^3`);
 (REWRITE_WITH `v0 = HD (ul:(real^3)list)`);
 (ASM_REWRITE_TAC[HD]);
 (REWRITE_WITH `u0 = HD (truncate_simplex 1 (ul:(real^3)list))`);
 (ASM_REWRITE_TAC[HD]);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ] THEN MATCH_MP_TAC Packing3.HD_TRUNCATE_SIMPLEX);
 (ASM_REWRITE_TAC[LENGTH] THEN ARITH_TAC);
 (REWRITE_TAC[ASSUME `v0 = u0:real^3`]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (REWRITE_WITH `EL 2 ul = v2:real^3`);
 (ASM_REWRITE_TAC[EL;HD;TL; ARITH_RULE `2 = SUC 1 /\ 1 = SUC 0`]);
 (STRIP_TAC);

 (UNDISCH_TAC `~NULLSET (mcell 3 V ul INTER C)`);
 (REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `mcell 3 V ul` THEN STRIP_TAC);
 (REWRITE_TAC[MCELL_EXPLICIT; mcell3; set_of_list;
   TRUNCATE_SIMPLEX_EXPLICIT_2; ASSUME `ul = [u0; v1; v2; v3:real^3]`;
   SET_RULE `{a,b,c} UNION {d} = {a,b, c,d}`]);
 (COND_CASES_TAC);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, v1, v2, mxi V ul}`);
 (STRIP_TAC);
 (MATCH_MP_TAC COPLANAR_IMP_NEGLIGIBLE);
 (REWRITE_TAC[COPLANAR_AFFINE_HULL_COPLANAR]);
 (REWRITE_TAC[coplanar]);
 (UNDISCH_TAC `u0 IN convex hull {v2, mxi V ul}`);
 (REWRITE_TAC[CONVEX_HULL_2; IN; IN_ELIM_THM] THEN STRIP_TAC);
 (EXISTS_TAC `v1:real^3` THEN EXISTS_TAC `v2:real^3` THEN 
   EXISTS_TAC `mxi V ul`);
 (MATCH_MP_TAC (SET_RULE `a IN s /\ b SUBSET s ==> (a INSERT b) SUBSET s`));
 (REWRITE_TAC[SET_SUBSET_AFFINE_HULL]);
 (REWRITE_TAC[AFFINE_HULL_3; IN; IN_ELIM_THM]);
 (EXISTS_TAC `&0` THEN EXISTS_TAC `u:real` THEN EXISTS_TAC `v:real`);
 (STRIP_TAC);
 (UNDISCH_TAC `u + v = &1` THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN VECTOR_ARITH_TAC);
 (ASM_REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);
 (SET_TAC[]);

 (STRIP_TAC);

 (UNDISCH_TAC `~NULLSET (mcell 3 V ul INTER C)` THEN REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `mcell 3 V ul`);
 (REWRITE_TAC[SET_RULE `A INTER B SUBSET A`]);
 (REWRITE_TAC[MCELL_EXPLICIT; mcell3]);
 (COND_CASES_TAC);
 (NEW_GOAL `?v2 v3. ul = [u0;u1;v2;v3:real^3]`);
 (NEW_GOAL `?v0 v1 v2 v3. ul = [v0;v1;v2;v3:real^3]`);
 (MATCH_MP_TAC BARV_3_EXPLICIT);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (EXISTS_TAC `v2:real^3` THEN EXISTS_TAC `v3:real^3`);
 (ASM_REWRITE_TAC[]);

 (REWRITE_WITH `v0 = u0:real^3`);
 (NEW_GOAL `HD (truncate_simplex 1 ul) = u0:real^3`);
 (ASM_REWRITE_TAC[HD]);
 (NEW_GOAL `HD (truncate_simplex 1 ul) = v0:real^3`);
 (REWRITE_TAC[ASSUME `ul = [v0; v1; v2; v3:real^3]`;  
   TRUNCATE_SIMPLEX_EXPLICIT_1; HD]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN MESON_TAC[]);

 (REWRITE_WITH `v1 = u1:real^3`);
 (NEW_GOAL `HD (TL(truncate_simplex 1 ul)) = u1:real^3`);
 (ASM_REWRITE_TAC[HD; TL]);
 (NEW_GOAL `HD (TL(truncate_simplex 1 ul)) = v1:real^3`);
 (REWRITE_TAC[ASSUME `ul = [v0; v1; v2; v3:real^3]`;  
   TRUNCATE_SIMPLEX_EXPLICIT_1; HD; TL]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN MESON_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (ASM_REWRITE_TAC[TRUNCATE_SIMPLEX_EXPLICIT_2; set_of_list; 
   SET_RULE `{a,b,c} UNION {d} = {a,b,c,d}`]);

 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1, v2, mxi V ul}`);
 (ASM_REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (MATCH_MP_TAC COPLANAR_IMP_NEGLIGIBLE);
 (ABBREV_TAC `m = mxi V ul`);
 (NEW_GOAL `mxi V [u0; u1;v2;v3] = m`);
 (EXPAND_TAC "m" THEN AP_TERM_TAC THEN ASM_REWRITE_TAC[]);
 (ASM_REWRITE_TAC[]);
 (REWRITE_TAC[COPLANAR_AFFINE_HULL_COPLANAR]);
 (ABBREV_TAC `k1 = norm (xx - u0:real^3)`);
 (ABBREV_TAC `k2 = norm (u1 - u0:real^3)`);
 (UNDISCH_TAC `xx IN convex hull {EL 2 ul, m:real^3}`);
 (ASM_REWRITE_TAC[EL; HD; TL; ARITH_RULE `2 = SUC 1/\ 1 = SUC 0`; 
   CONVEX_HULL_2; IN; IN_ELIM_THM] THEN STRIP_TAC);
 (UNDISCH_TAC `k1 % (u1 - u0) = k2 % (xx - u0:real^3)`);
 (ASM_REWRITE_TAC[]);

 (STRIP_TAC); 

 (REWRITE_TAC[coplanar]);
 (NEW_GOAL `~(k2 = &0)`);
 (EXPAND_TAC "k2");
 (REWRITE_TAC[NORM_EQ_0; VECTOR_ARITH `a - b = vec 0 <=> b = a`]);
 (ASM_REWRITE_TAC[]);

 (ASM_CASES_TAC `~(v = &0)`);
 (EXISTS_TAC `u0:real^3` THEN EXISTS_TAC `u1:real^3` THEN 
   EXISTS_TAC `v2:real^3`);
 (MATCH_MP_TAC (SET_RULE `{a,b,c} SUBSET X /\ d IN X ==> {a,b,c,d} SUBSET X`));
 (STRIP_TAC);
 (REWRITE_TAC[Qzksykg.SET_SUBSET_AFFINE_HULL]);
 (REWRITE_TAC[AFFINE_HULL_3; IN; IN_ELIM_THM]);
 (EXISTS_TAC `(k2 - k1:real) / (k2 * v)`);
 (EXISTS_TAC `k1 / (k2 * v)`);
 (EXISTS_TAC `(--k2 * u) / (k2 * v)`);
 (STRIP_TAC);
 (REWRITE_TAC[REAL_ARITH `a / x + b / x + c / x = (a+b+c)/ x`]);
 (REWRITE_WITH `k2 - k1 + k1 + --k2 * u = k2 * (u + v) - k1 + k1 + --k2 * u`);
 (ASM_REWRITE_TAC[ARITH_RULE `SUC 0 = 1`] THEN REAL_ARITH_TAC);
 (REWRITE_TAC[REAL_ARITH `k2 * (u + v) - k1 + k1 + --k2 * u = k2 * v`]);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (REWRITE_TAC[REAL_ENTIRE] THEN ASM_REWRITE_TAC[]);

 (REWRITE_TAC[VECTOR_ARITH `a / x % u0 + b / x % u1 + d / x % u2 = 
                            (&1 / x) % (a % u0 + b % u1 + d % u2)`]);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (REWRITE_WITH
  `&1 / (k2 * v) % ((k2 - k1) % u0 + k1 % u1 + (--k2 * u) % v2) = m:real^3  <=> 
   ((k2 - k1) % u0 + k1 % u1 + (--k2 * u) % v2) = (k2 * v) % m`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC Collect_geom.CHANGE_SIDE);
 (REWRITE_TAC[REAL_ENTIRE] THEN ASM_REWRITE_TAC[]);
 (ASM_REWRITE_TAC[VECTOR_ARITH 
  `(k2 - k1) % u0 + k1 % u1 + (--k2 * u) % v2 = (k2 * v) % m <=> 
    k1 % (u1 - u0) = k2 % ((u % v2 + v % m) - u0)`]);

 (NEW_GOAL `~(u = &0)`);
 (UP_ASM_TAC THEN UNDISCH_TAC `u + v = &(SUC 0):real` THEN  
   REWRITE_TAC[ARITH_RULE `SUC 0 = 1`]);
 (REAL_ARITH_TAC);

 (EXISTS_TAC `u0:real^3` THEN EXISTS_TAC `u1:real^3` THEN 
   EXISTS_TAC `m:real^3`);
 (MATCH_MP_TAC (SET_RULE `{a,b,c} SUBSET X /\ d IN X ==> {a,b,d,c} SUBSET X`));
 (STRIP_TAC);
 (REWRITE_TAC[Qzksykg.SET_SUBSET_AFFINE_HULL]);
 (REWRITE_TAC[AFFINE_HULL_3; IN; IN_ELIM_THM]);

 (EXISTS_TAC `(k2 - k1:real) / (k2 * u)`);
 (EXISTS_TAC `k1 / (k2 * u)`);
 (EXISTS_TAC `(--k2 * v) / (k2 * u)`);
 (STRIP_TAC);
 (REWRITE_TAC[REAL_ARITH `a / x + b / x + c / x = (a+b+c)/ x`]);
 (REWRITE_WITH `k2 - k1 + k1 + --k2 * v = k2 * (u + v) - k1 + k1 + --k2 * v`);
 (ASM_REWRITE_TAC[ARITH_RULE `SUC 0 = 1`] THEN REAL_ARITH_TAC);
 (REWRITE_TAC[REAL_ARITH `k2 * (u + v) - k1 + k1 + --k2 * v = k2 * u`]);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (REWRITE_TAC[REAL_ENTIRE] THEN ASM_REWRITE_TAC[]);

 (REWRITE_TAC[VECTOR_ARITH `a / x % u0 + b / x % u1 + d / x % u2 = 
                            (&1 / x) % (a % u0 + b % u1 + d % u2)`]);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (REWRITE_WITH
  `&1 / (k2 * u) % ((k2 - k1) % u0 + k1 % u1 + (--k2 * v) % m) = v2:real^3  <=> 
   ((k2 - k1) % u0 + k1 % u1 + (--k2 * v) % m) = (k2 * u) % v2`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC Collect_geom.CHANGE_SIDE);
 (REWRITE_TAC[REAL_ENTIRE] THEN ASM_REWRITE_TAC[]);
 (ASM_REWRITE_TAC[VECTOR_ARITH 
  `(k2 - k1) % u0 + k1 % u1 + (--k2 * v) % m = (k2 * u) % v2 <=> 
    k1 % (u1 - u0) = k2 % ((u % v2 + v % m) - u0)`]);

 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);

(* ========================================================================== *)

 (ABBREV_TAC `f4 = 
  (\ul. (((smallest_angle_line (EL 2 ul)  (EL 3 ul) u0 u1) - u0)
   dot (u1 - u0)) / 
   (norm ((smallest_angle_line (EL 2 ul)  (EL 3 ul) u0 u1) - u0)
   * norm (u1 - u0)))`);

 (ABBREV_TAC `P4 = {(f4:(real^3)list->real) ul |ul | barV V 3 ul /\
                                 ~NULLSET (mcell 4 V ul INTER C) /\
                                  truncate_simplex 1 ul = [u0; u1]}`);

 (NEW_GOAL `~(P4 = {}) ==> (?b:real. b IN P4 /\ (!x. x IN P4 ==> x <= b))`);
 (STRIP_TAC);
 (MATCH_MP_TAC SUP_FINITE_LEMMA);
 (ASM_REWRITE_TAC[]);
 (EXPAND_TAC "P4");
 (ONCE_REWRITE_TAC [SET_RULE `{f x| x | P x} = {f x | x IN {y | P y}}`]);
 (ONCE_REWRITE_TAC [SET_RULE `{f x| x IN s} = {y | ?x. x IN s /\ y = f x}`]);
 (MATCH_MP_TAC FINITE_IMAGE_EXPAND);
 (MATCH_MP_TAC FINITE_SUBSET);
 (EXISTS_TAC `{y | ?v0:real^3 v1 u2 u3.
                      v0 IN (V INTER ball (u0:real^3, &4)) /\
                      v1 IN (V INTER ball (u0, &4)) /\
                      u2 IN (V INTER ball (u0, &4)) /\
                      u3 IN (V INTER ball (u0, &4)) /\
                      y = [v0; v1; u2; u3]}`);
 (STRIP_TAC);
 (MATCH_MP_TAC FINITE_SET_LIST_LEMMA);
 (ASM_SIMP_TAC[FINITE_PACK_LEMMA]);
 (REWRITE_TAC[SUBSET] THEN ONCE_REWRITE_TAC[IN] THEN REWRITE_TAC[IN_ELIM_THM]);
 (REPEAT STRIP_TAC);
 (NEW_GOAL `?v0 v1 u2 u3. x = [v0; v1; u2; u3:real^3]`);
 (MATCH_MP_TAC BARV_3_EXPLICIT);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (EXISTS_TAC `v0:real^3` THEN EXISTS_TAC `v1:real^3` THEN     
   EXISTS_TAC `u2:real^3` THEN EXISTS_TAC `u3:real^3`);
 (ASM_REWRITE_TAC[]);
 (NEW_GOAL `v0 = u0:real^3`);
 (REWRITE_WITH `v0 = HD (x:(real^3)list)`);
 (ASM_REWRITE_TAC[HD]);
 (REWRITE_WITH `u0 = HD (truncate_simplex 1 (x:(real^3)list))`);
 (ASM_REWRITE_TAC[HD]);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ] THEN MATCH_MP_TAC Packing3.HD_TRUNCATE_SIMPLEX);
 (ASM_REWRITE_TAC[LENGTH] THEN ARITH_TAC);
 (NEW_GOAL `set_of_list x SUBSET ball (u0:real^3,&4)`);
 (MATCH_MP_TAC Qzyzmjc.BARV_3_IMP_FINITE_lemma2);
 (EXISTS_TAC `V:real^3->bool`);
 (ASM_REWRITE_TAC[set_of_list]);
 (SET_TAC[]);
 (NEW_GOAL `set_of_list x SUBSET V:real^3->bool`);
 (MATCH_MP_TAC Packing3.BARV_SUBSET);
 (EXISTS_TAC `3` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN ASM_REWRITE_TAC[set_of_list]);
 (SET_TAC[]);

 (ABBREV_TAC `d2 = (if (P4 = {}:real->bool) then c 
                    else (@b. b IN P4 /\ (!x. x IN P4 ==> x <= b)))`);
 (NEW_GOAL `d2 < &1`);
 (EXPAND_TAC "d2");
 (COND_CASES_TAC);
 (ASM_REWRITE_TAC[]);
 (NEW_GOAL `?b:real. b IN P4 /\ (!x. x IN P4 ==> x <= b)`);
 (ASM_SIMP_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (ABBREV_TAC `P  = (\b:real. b IN P4 /\ (!x. x IN P4 ==> x <= b))`);
 (ABBREV_TAC `zz = (@) (P:real->bool)`);
 (NEW_GOAL `(P:real->bool) zz`);
 (EXPAND_TAC "zz");
 (MATCH_MP_TAC SELECT_AX);
 (EXISTS_TAC `b':real`);
 (EXPAND_TAC "P" THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN EXPAND_TAC "P" THEN REWRITE_TAC[]);
 (EXPAND_TAC "P4" THEN REWRITE_TAC[IN; IN_ELIM_THM]);
 (REPEAT STRIP_TAC);
 (ASM_REWRITE_TAC[]);
 (EXPAND_TAC "f4");

 (ABBREV_TAC `xx = smallest_angle_line (EL 2 ul) (EL 3 ul) u0 u1`);
 (MATCH_MP_TAC REAL_DIV_LT_1_TACTICS);
 (STRIP_TAC);
 (MATCH_MP_TAC (REAL_ARITH `&0 <= a /\ ~(a = &0) ==> &0 < a`));
 (STRIP_TAC);
 (SIMP_TAC[REAL_LE_MUL; NORM_POS_LE]);
 (REWRITE_TAC[REAL_ENTIRE; NORM_EQ_0; VECTOR_ARITH `a - b = vec 0 <=> a = b`]);
 (ASM_REWRITE_TAC[]);
 (EXPAND_TAC "xx");
 (ONCE_REWRITE_TAC[EQ_SYM_EQ] THEN 
   REWRITE_TAC[smallest_angle_line; smallest_angle_set]);
 (STRIP_TAC);
 (ABBREV_TAC `Q = (\x:real^3. x IN convex hull {EL 2 ul, EL 3 ul} /\
           (!y. y IN convex hull {EL 2 ul, EL 3 ul}
                ==> ((y - u0) dot (u1 - u0)) /
                    (norm (y - u0) * norm (u1 - u0)) <=
                    ((x - u0) dot (u1 - u0)) /
                    (norm (x - u0) * norm (u1 - u0))))`);
 (NEW_GOAL `(Q:real^3->bool) u0`);
 (ONCE_ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC SELECT_AX);
 (EXPAND_TAC "Q");

 (MATCH_MP_TAC SMALLEST_ANGLE_LINE_EXISTS);
 (STRIP_TAC);
 (ASM_REWRITE_TAC[]);

 (NEW_GOAL `?v1 v2 v3. ul = [u0; v1; v2; v3:real^3]`);
 (NEW_GOAL `?v0 v1 v2 v3. ul = [v0; v1; v2; v3:real^3]`);
 (MATCH_MP_TAC BARV_3_EXPLICIT);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (EXISTS_TAC `v1:real^3` THEN     
   EXISTS_TAC `v2:real^3` THEN EXISTS_TAC `v3:real^3`);
 (REWRITE_TAC[ASSUME `ul = [v0; v1; v2; v3:real^3]`]);

 (NEW_GOAL `v0 = u0:real^3`);
 (REWRITE_WITH `v0 = HD (ul:(real^3)list)`);
 (ASM_REWRITE_TAC[HD]);
 (REWRITE_WITH `u0 = HD (truncate_simplex 1 (ul:(real^3)list))`);
 (ASM_REWRITE_TAC[HD]);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ] THEN MATCH_MP_TAC Packing3.HD_TRUNCATE_SIMPLEX);
 (ASM_REWRITE_TAC[LENGTH] THEN ARITH_TAC);
 (REWRITE_TAC[ASSUME `v0 = u0:real^3`]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (REWRITE_WITH `EL 2 ul = v2:real^3 /\ EL 3 ul = v3`);
 (ASM_REWRITE_TAC[EL;HD;TL; ARITH_RULE `3 = SUC 2 /\2 = SUC 1 /\ 1 = SUC 0`]);
 (STRIP_TAC);

 (UNDISCH_TAC `~NULLSET (mcell 4 V ul INTER C)`);
 (REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `mcell 4 V ul` THEN STRIP_TAC);
 (SIMP_TAC[MCELL_EXPLICIT; mcell4; set_of_list;ARITH_RULE `4 >= 4`; 
   ASSUME `ul = [u0; v1; v2; v3:real^3]`]);
 (COND_CASES_TAC);

 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, v1, v2, v3:real^3}`);
 (STRIP_TAC);
 (MATCH_MP_TAC COPLANAR_IMP_NEGLIGIBLE);
 (REWRITE_TAC[COPLANAR_AFFINE_HULL_COPLANAR]);
 (REWRITE_TAC[coplanar]);
 (UNDISCH_TAC `u0 IN convex hull {v2, v3:real^3}`);
 (REWRITE_TAC[CONVEX_HULL_2; IN; IN_ELIM_THM] THEN STRIP_TAC);
 (EXISTS_TAC `v1:real^3` THEN EXISTS_TAC `v2:real^3` THEN 
   EXISTS_TAC `v3:real^3`);
 (MATCH_MP_TAC (SET_RULE `a IN s /\ b SUBSET s ==> (a INSERT b) SUBSET s`));
 (REWRITE_TAC[SET_SUBSET_AFFINE_HULL]);
 (REWRITE_TAC[AFFINE_HULL_3; IN; IN_ELIM_THM]);
 (EXISTS_TAC `&0` THEN EXISTS_TAC `u:real` THEN EXISTS_TAC `v:real`);
 (STRIP_TAC);
 (UNDISCH_TAC `u + v = &1` THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN VECTOR_ARITH_TAC);
 (ASM_REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);
 (SET_TAC[]);

 (UP_ASM_TAC THEN EXPAND_TAC "Q");
 (STRIP_TAC);
 (UNDISCH_TAC `~NULLSET (mcell 4 V ul INTER C)` THEN REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `mcell 4 V ul`);
 (REWRITE_TAC[SET_RULE `A INTER B SUBSET A`]);
 (SIMP_TAC[MCELL_EXPLICIT; mcell4; ARITH_RULE `4 >= 4`]);
 (COND_CASES_TAC);
 (NEW_GOAL `?v2 v3. ul = [u0;u1;v2;v3:real^3]`);
 (NEW_GOAL `?v0 v1 v2 v3. ul = [v0;v1;v2;v3:real^3]`);
 (MATCH_MP_TAC BARV_3_EXPLICIT);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (EXISTS_TAC `v2:real^3` THEN EXISTS_TAC `v3:real^3`);
 (ASM_REWRITE_TAC[]);

 (REWRITE_WITH `v0 = u0:real^3`);
 (NEW_GOAL `HD (truncate_simplex 1 ul) = u0:real^3`);
 (ASM_REWRITE_TAC[HD]);
 (NEW_GOAL `HD (truncate_simplex 1 ul) = v0:real^3`);
 (REWRITE_TAC[ASSUME `ul = [v0; v1; v2; v3:real^3]`;  
   TRUNCATE_SIMPLEX_EXPLICIT_1; HD]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN MESON_TAC[]);

 (REWRITE_WITH `v1 = u1:real^3`);
 (NEW_GOAL `HD (TL(truncate_simplex 1 ul)) = u1:real^3`);
 (ASM_REWRITE_TAC[HD; TL]);
 (NEW_GOAL `HD (TL(truncate_simplex 1 ul)) = v1:real^3`);
 (REWRITE_TAC[ASSUME `ul = [v0; v1; v2; v3:real^3]`;  
   TRUNCATE_SIMPLEX_EXPLICIT_1; HD; TL]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN MESON_TAC[]);
 (ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);

 (ASM_REWRITE_TAC[set_of_list]);
 (REWRITE_TAC[GSYM (ASSUME `u0 = (@) (Q:real^3->bool)`)]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1, v2, v3:real^3}`);
 (REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (REWRITE_WITH `affine hull {u0, u1, v2, v3} = 
                 affine hull {u1, v2, v3:real^3}`);
 (MATCH_MP_TAC AFFINE_HULL_3_INSERT);

 (NEW_GOAL `convex hull {EL 2 ul, (EL 3 ul):real^3} SUBSET 
             affine hull {EL 2 ul, EL 3 ul}`);
 (REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (NEW_GOAL `affine hull {EL 2 ul, (EL 3 ul):real^3} SUBSET 
             affine hull {u1, v2, v3}`);
 (MATCH_MP_TAC AFFINE_SUBSET_KY_LEMMA);
 (ASM_REWRITE_TAC[EL; HD; TL; 
   ARITH_RULE `3 = SUC 2 /\ 2 = SUC 1 /\ 1 = SUC 0`]);
 (SET_TAC[]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN 
   UNDISCH_TAC `u0 IN convex hull {EL 2 ul, (EL 3 ul):real^3}` THEN SET_TAC[]);
 (REWRITE_TAC[NEGLIGIBLE_AFFINE_HULL_3]);
 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);

 (MATCH_MP_TAC (REAL_ARITH `(a <= b) /\ ~(a = b) ==> a < b`));
 (REWRITE_TAC[NORM_CAUCHY_SCHWARZ; NORM_CAUCHY_SCHWARZ_EQ]);
 (NEW_GOAL `xx IN convex hull {(EL 2 ul) ,(EL 3 ul):real^3}`);
 (MATCH_MP_TAC SMALLEST_ANGLE_IN_CONVEX_HULL);
 (EXISTS_TAC `u0:real^3` THEN EXISTS_TAC `u1:real^3`);
 (ASM_REWRITE_TAC[]);

 (NEW_GOAL `?v1 v2 v3. ul = [u0; v1; v2; v3:real^3]`);
 (NEW_GOAL `?v0 v1 v2 v3. ul = [v0; v1; v2; v3:real^3]`);
 (MATCH_MP_TAC BARV_3_EXPLICIT);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (EXISTS_TAC `v1:real^3` THEN     
   EXISTS_TAC `v2:real^3` THEN EXISTS_TAC `v3:real^3`);
 (REWRITE_TAC[ASSUME `ul = [v0; v1; v2; v3:real^3]`]);

 (NEW_GOAL `v0 = u0:real^3`);
 (REWRITE_WITH `v0 = HD (ul:(real^3)list)`);
 (ASM_REWRITE_TAC[HD]);
 (REWRITE_WITH `u0 = HD (truncate_simplex 1 (ul:(real^3)list))`);
 (ASM_REWRITE_TAC[HD]);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ] THEN MATCH_MP_TAC Packing3.HD_TRUNCATE_SIMPLEX);
 (ASM_REWRITE_TAC[LENGTH] THEN ARITH_TAC);
 (REWRITE_TAC[ASSUME `v0 = u0:real^3`]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (REWRITE_WITH `EL 2 ul = v2:real^3 /\ EL 3 ul = v3`);
 (ASM_REWRITE_TAC[EL;HD;TL; ARITH_RULE `3 = SUC 2 /\2 = SUC 1 /\ 1 = SUC 0`]);
 (STRIP_TAC);

 (UNDISCH_TAC `~NULLSET (mcell 4 V ul INTER C)`);
 (REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `mcell 4 V ul` THEN STRIP_TAC);
 (SIMP_TAC[MCELL_EXPLICIT; mcell4; set_of_list;ARITH_RULE `4 >= 4`; 
   ASSUME `ul = [u0; v1; v2; v3:real^3]`]);
 (COND_CASES_TAC);

 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, v1, v2, v3:real^3}`);
 (STRIP_TAC);
 (MATCH_MP_TAC COPLANAR_IMP_NEGLIGIBLE);
 (REWRITE_TAC[COPLANAR_AFFINE_HULL_COPLANAR]);
 (REWRITE_TAC[coplanar]);
 (UNDISCH_TAC `u0 IN convex hull {v2, v3:real^3}`);
 (REWRITE_TAC[CONVEX_HULL_2; IN; IN_ELIM_THM] THEN STRIP_TAC);
 (EXISTS_TAC `v1:real^3` THEN EXISTS_TAC `v2:real^3` THEN 
   EXISTS_TAC `v3:real^3`);
 (MATCH_MP_TAC (SET_RULE `a IN s /\ b SUBSET s ==> (a INSERT b) SUBSET s`));
 (REWRITE_TAC[SET_SUBSET_AFFINE_HULL]);
 (REWRITE_TAC[AFFINE_HULL_3; IN; IN_ELIM_THM]);
 (EXISTS_TAC `&0` THEN EXISTS_TAC `u:real` THEN EXISTS_TAC `v:real`);
 (STRIP_TAC);
 (UNDISCH_TAC `u + v = &1` THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN VECTOR_ARITH_TAC);
 (ASM_REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);
 (SET_TAC[]);

 (STRIP_TAC);

 (UNDISCH_TAC `~NULLSET (mcell 4 V ul INTER C)` THEN REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `mcell 4 V ul`);
 (REWRITE_TAC[SET_RULE `A INTER B SUBSET A`]);
 (SIMP_TAC[MCELL_EXPLICIT; mcell4; ARITH_RULE `4 >= 4`]);
 (COND_CASES_TAC);
 (NEW_GOAL `?v2 v3. ul = [u0;u1;v2;v3:real^3]`);
 (NEW_GOAL `?v0 v1 v2 v3. ul = [v0;v1;v2;v3:real^3]`);
 (MATCH_MP_TAC BARV_3_EXPLICIT);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (EXISTS_TAC `v2:real^3` THEN EXISTS_TAC `v3:real^3`);
 (ASM_REWRITE_TAC[]);

 (REWRITE_WITH `v0 = u0:real^3`);
 (NEW_GOAL `HD (truncate_simplex 1 ul) = u0:real^3`);
 (ASM_REWRITE_TAC[HD]);
 (NEW_GOAL `HD (truncate_simplex 1 ul) = v0:real^3`);
 (REWRITE_TAC[ASSUME `ul = [v0; v1; v2; v3:real^3]`;  
   TRUNCATE_SIMPLEX_EXPLICIT_1; HD]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN MESON_TAC[]);

 (REWRITE_WITH `v1 = u1:real^3`);
 (NEW_GOAL `HD (TL(truncate_simplex 1 ul)) = u1:real^3`);
 (ASM_REWRITE_TAC[HD; TL]);
 (NEW_GOAL `HD (TL(truncate_simplex 1 ul)) = v1:real^3`);
 (REWRITE_TAC[ASSUME `ul = [v0; v1; v2; v3:real^3]`;  
   TRUNCATE_SIMPLEX_EXPLICIT_1; HD; TL]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN MESON_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (ASM_REWRITE_TAC[set_of_list]);

 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1, v2, v3:real^3}`);
 (ASM_REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (MATCH_MP_TAC COPLANAR_IMP_NEGLIGIBLE);
 (REWRITE_TAC[COPLANAR_AFFINE_HULL_COPLANAR]);
 (ABBREV_TAC `k1 = norm (xx - u0:real^3)`);
 (ABBREV_TAC `k2 = norm (u1 - u0:real^3)`);
 (UNDISCH_TAC `xx IN convex hull {EL 2 ul,(EL 3 ul):real^3}`);
 (ASM_REWRITE_TAC[EL; HD; TL; ARITH_RULE `3 = SUC 2 /\ 2 = SUC 1/\ 1 = SUC 0`; 
   CONVEX_HULL_2; IN; IN_ELIM_THM] THEN STRIP_TAC);
 (UNDISCH_TAC `k1 % (u1 - u0) = k2 % (xx - u0:real^3)`);
 (ASM_REWRITE_TAC[]);

 (STRIP_TAC); 

 (REWRITE_TAC[coplanar]);
 (NEW_GOAL `~(k2 = &0)`);
 (EXPAND_TAC "k2");
 (REWRITE_TAC[NORM_EQ_0; VECTOR_ARITH `a - b = vec 0 <=> b = a`]);
 (ASM_REWRITE_TAC[]);

 (ASM_CASES_TAC `~(v = &0)`);
 (EXISTS_TAC `u0:real^3` THEN EXISTS_TAC `u1:real^3` THEN 
   EXISTS_TAC `v2:real^3`);
 (MATCH_MP_TAC (SET_RULE `{a,b,c} SUBSET X /\ d IN X ==> {a,b,c,d} SUBSET X`));
 (STRIP_TAC);
 (REWRITE_TAC[Qzksykg.SET_SUBSET_AFFINE_HULL]);
 (REWRITE_TAC[AFFINE_HULL_3; IN; IN_ELIM_THM]);
 (EXISTS_TAC `(k2 - k1:real) / (k2 * v)`);
 (EXISTS_TAC `k1 / (k2 * v)`);
 (EXISTS_TAC `(--k2 * u) / (k2 * v)`);
 (STRIP_TAC);
 (REWRITE_TAC[REAL_ARITH `a / x + b / x + c / x = (a+b+c)/ x`]);
 (REWRITE_WITH `k2 - k1 + k1 + --k2 * u = k2 * (u + v) - k1 + k1 + --k2 * u`);
 (ASM_REWRITE_TAC[ARITH_RULE `SUC 0 = 1`] THEN REAL_ARITH_TAC);
 (REWRITE_TAC[REAL_ARITH `k2 * (u + v) - k1 + k1 + --k2 * u = k2 * v`]);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (REWRITE_TAC[REAL_ENTIRE] THEN ASM_REWRITE_TAC[]);

 (REWRITE_TAC[VECTOR_ARITH `a / x % u0 + b / x % u1 + d / x % u2 = 
                            (&1 / x) % (a % u0 + b % u1 + d % u2)`]);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (REWRITE_WITH
  `&1 / (k2 * v) % ((k2 - k1) % u0 + k1 % u1 + (--k2 * u) % v2) = v3:real^3  <=> 
   ((k2 - k1) % u0 + k1 % u1 + (--k2 * u) % v2) = (k2 * v) % v3`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC Collect_geom.CHANGE_SIDE);
 (REWRITE_TAC[REAL_ENTIRE] THEN ASM_REWRITE_TAC[]);
 (ASM_REWRITE_TAC[VECTOR_ARITH 
  `(k2 - k1) % u0 + k1 % u1 + (--k2 * u) % v2 = (k2 * v) % v3 <=> 
    k1 % (u1 - u0) = k2 % ((u % v2 + v % v3) - u0)`]);

 (NEW_GOAL `~(u = &0)`);
 (UP_ASM_TAC THEN UNDISCH_TAC `u + v = &(SUC 0):real` THEN  
   REWRITE_TAC[ARITH_RULE `SUC 0 = 1`]);
 (REAL_ARITH_TAC);

 (EXISTS_TAC `u0:real^3` THEN EXISTS_TAC `u1:real^3` THEN 
   EXISTS_TAC `v3:real^3`);
 (MATCH_MP_TAC (SET_RULE `{a,b,c} SUBSET X /\ d IN X ==> {a,b,d,c} SUBSET X`));
 (STRIP_TAC);
 (REWRITE_TAC[Qzksykg.SET_SUBSET_AFFINE_HULL]);
 (REWRITE_TAC[AFFINE_HULL_3; IN; IN_ELIM_THM]);

 (EXISTS_TAC `(k2 - k1:real) / (k2 * u)`);
 (EXISTS_TAC `k1 / (k2 * u)`);
 (EXISTS_TAC `(--k2 * v) / (k2 * u)`);
 (STRIP_TAC);
 (REWRITE_TAC[REAL_ARITH `a / x + b / x + c / x = (a+b+c)/ x`]);
 (REWRITE_WITH `k2 - k1 + k1 + --k2 * v = k2 * (u + v) - k1 + k1 + --k2 * v`);
 (ASM_REWRITE_TAC[ARITH_RULE `SUC 0 = 1`] THEN REAL_ARITH_TAC);
 (REWRITE_TAC[REAL_ARITH `k2 * (u + v) - k1 + k1 + --k2 * v = k2 * u`]);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (REWRITE_TAC[REAL_ENTIRE] THEN ASM_REWRITE_TAC[]);

 (REWRITE_TAC[VECTOR_ARITH `a / x % u0 + b / x % u1 + d / x % u2 = 
                            (&1 / x) % (a % u0 + b % u1 + d % u2)`]);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (REWRITE_WITH
  `&1 / (k2 * u) % ((k2 - k1) % u0 + k1 % u1 + (--k2 * v) % v3) = v2:real^3  <=> 
   ((k2 - k1) % u0 + k1 % u1 + (--k2 * v) % v3) = (k2 * u) % v2`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC Collect_geom.CHANGE_SIDE);
 (REWRITE_TAC[REAL_ENTIRE] THEN ASM_REWRITE_TAC[]);
 (ASM_REWRITE_TAC[VECTOR_ARITH 
  `(k2 - k1) % u0 + k1 % u1 + (--k2 * v) % m = (k2 * u) % v2 <=> 
    k1 % (u1 - u0) = k2 % ((u % v2 + v % m) - u0)`]);
 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);

(* ========================================================================== *)

 (ABBREV_TAC `d = max c (max d1 d2)`);
 (NEW_GOAL `d < &1`);
 (UNDISCH_TAC `d2 < &1` THEN UNDISCH_TAC `d1 < &1` THEN 
   UNDISCH_TAC `&0 < c /\ c < &1`);
 (EXPAND_TAC "d" THEN REAL_ARITH_TAC);

(* ========================================================================== *)

 (ABBREV_TAC `D = ball (u0:real^3,r) INTER rcone_gt u0 u1 d`);
 (NEW_GOAL `D SUBSET C:real^3->bool`);
 (EXPAND_TAC "D" THEN EXPAND_TAC "C");
 (MATCH_MP_TAC (SET_RULE 
  `A SUBSET B /\ C SUBSET D ==> A INTER C SUBSET B INTER D`));
 (STRIP_TAC);
 (MATCH_MP_TAC SUBSET_BALL);
 (EXPAND_TAC "r" THEN REAL_ARITH_TAC);
 (MATCH_MP_TAC RCONE_GT_SUBSET);
 (EXPAND_TAC "d" THEN REAL_ARITH_TAC);

 (NEW_GOAL `!X. mcell_set V X /\ ~NULLSET (X INTER D)
          ==> (?k vl.
                   2 <= k /\
                   barV V 3 vl /\
                   X = mcell k V vl /\
                   truncate_simplex 1 vl = [u0; u1])`);
 (REPEAT STRIP_TAC);
 (FIRST_ASSUM MATCH_MP_TAC);
 (ASM_REWRITE_TAC[]);
 (STRIP_TAC);
 (UNDISCH_TAC `~NULLSET (X INTER D)`);
 (REWRITE_TAC[] THEN MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X INTER C:real^3->bool`);
 (ASM_REWRITE_TAC[] THEN UNDISCH_TAC `D SUBSET C:real^3->bool`);
 (SET_TAC[]);

(* ========================================================================= *)

 (NEW_GOAL `D = conic_cap (u0:real^3) u1 r d`);
 (EXPAND_TAC "D" THEN REWRITE_TAC[conic_cap; NORMBALL_BALL]);

 (NEW_GOAL `!X. mcell_set V X /\ ~NULLSET (X INTER D) ==>
   vol (X INTER D) = vol (D) * (dihX V X (u0,u1)) / (&2 * pi)`);
 (REPEAT STRIP_TAC);
 (NEW_GOAL `?k vl.
                   2 <= k /\
                   barV V 3 vl /\
                   X = mcell k V vl /\
                   truncate_simplex 1 vl = [u0; u1]`);
 (FIRST_ASSUM MATCH_MP_TAC);
 (ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN REPEAT STRIP_TAC);

(* ========================================================================= *)
(*  Case k = 2                                                               *)
(* ========================================================================= *)

 (ASM_CASES_TAC `k = 2`);
 (ABBREV_TAC `m = mxi V vl`);
 (ABBREV_TAC `s3 = omega_list_n V vl 3`);
 (ABBREV_TAC `L = aff_ge{u0, u1} {m, s3:real^3}`);

 (REWRITE_WITH `vol (X INTER D) = vol (L INTER D)`);
 (AP_TERM_TAC);
 (ASM_REWRITE_TAC[MCELL_EXPLICIT; mcell2]);
 (LET_TAC);
 (COND_CASES_TAC);
 (NEW_GOAL `?v0 v1 v2 v3. vl = [v0;v1;v2;v3:real^3]`);
 (MATCH_MP_TAC Marchal_cells.BARV_3_EXPLICIT);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);

 (REWRITE_WITH `HD vl = u0 /\ HD (TL vl) = u1:real^3`);
 (REWRITE_WITH `(HD vl):real^3 = HD (truncate_simplex 1 vl)`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC Packing3.HD_TRUNCATE_SIMPLEX);
 (ASM_REWRITE_TAC[LENGTH] THEN ARITH_TAC);
 (ASM_REWRITE_TAC[HD; TL]);
 (NEW_GOAL `HD (TL(truncate_simplex 1 vl)) = u1:real^3`);
 (ASM_REWRITE_TAC[HD; TL]);
 (NEW_GOAL `HD (TL(truncate_simplex 1 vl)) = v1:real^3`);
 (REWRITE_TAC[ASSUME `vl = [v0; v1; v2; v3:real^3]`;  
   TRUNCATE_SIMPLEX_EXPLICIT_1; HD; TL]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN MESON_TAC[]);

 (EXPAND_TAC "L");
 (REWRITE_TAC [SET_RULE `(A INTER B INTER C) INTER D = C INTER D 
                       <=> (!x. x IN C INTER D ==> x IN A /\ x IN B)`]);

 (REPEAT GEN_TAC THEN STRIP_TAC);
 (NEW_GOAL `x:real^3 IN D`);
 (UP_ASM_TAC THEN UNDISCH_TAC `D = conic_cap (u0:real^3) u1 r d`);
 (SET_TAC[]);
 (UP_ASM_TAC THEN EXPAND_TAC "D" THEN STRIP_TAC);
 (NEW_GOAL `x:real^3 IN rcone_gt u0 u1 a'`);
 (NEW_GOAL `rcone_gt (u0:real^3) u1 d SUBSET rcone_gt u0 u1 c`);
 (MATCH_MP_TAC RCONE_GT_SUBSET);
 (EXPAND_TAC "d" THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN UNDISCH_TAC 
   `rcone_gt (u0:real^3) u1 c SUBSET W INTER rcone_gt u0 u1 a'`);
 (SET_TAC[]);
 (STRIP_TAC);
 (UP_ASM_TAC THEN SET_TAC[RCONE_GT_SUBSET_RCONE_GE]);

(* ========================================================================== *)
 (UP_ASM_TAC THEN REWRITE_TAC[rcone_ge; rconesgn; rcone_gt; IN; IN_ELIM_THM]);
 (STRIP_TAC);

 (ABBREV_TAC `y = u0 + proj_point (u1 - u0:real^3) (x - u0)`);
 (NEW_GOAL `orthogonal (x - y) (u1 - u0:real^3)`);
 (REWRITE_WITH `x - y = (x - u0) - proj_point (u1 - u0) (x - u0:real^3)`);
 (EXPAND_TAC "y" THEN VECTOR_ARITH_TAC);
 (REWRITE_TAC[GSYM Marchal_cells_2_new.projection_proj_point]);
 (REWRITE_TAC[orthogonal; Packing3.PROJECTION_ORTHOGONAL]);

 (NEW_GOAL `norm (x - u0) pow 2 = norm (y - u0) pow 2 + norm (x - y:real^3) pow 2`);
 (MATCH_MP_TAC PYTHAGORAS);
 (REWRITE_TAC[orthogonal]);
 (ONCE_REWRITE_TAC[VECTOR_ARITH `(a - b) dot c = --(c dot (b - a))`]);
 (REWRITE_WITH `y - u0 = proj_point (u1 - u0) (x - u0:real^3)`);
 (EXPAND_TAC "y" THEN REWRITE_TAC[VECTOR_ARITH `(a + b) - a:real^3 = b`]);
 (REWRITE_TAC[PRO_EXP; DOT_RMUL]);
 (UP_ASM_TAC THEN REWRITE_TAC[orthogonal] THEN STRIP_TAC);
 (ASM_REWRITE_TAC[]);
 (REAL_ARITH_TAC);

 (NEW_GOAL `norm (x - u1) pow 2 = norm (y - u1) pow 2 + norm (x - y:real^3) pow 2`);
 (MATCH_MP_TAC PYTHAGORAS);
 (REWRITE_TAC[orthogonal]);
 (ONCE_REWRITE_TAC[VECTOR_ARITH `(a - b) dot c = c dot (a - b)`]);
 (REWRITE_WITH `u1 - y = (u1 - u0) - proj_point (u1 - u0) (x - u0:real^3)`);
 (EXPAND_TAC "y" THEN VECTOR_ARITH_TAC);
 (REWRITE_TAC[PRO_EXP; VECTOR_ARITH `x - a % x = (&1 - a) % x`]);
 (REWRITE_TAC[DOT_RMUL] THEN DEL_TAC);
 (UP_ASM_TAC THEN REWRITE_TAC[orthogonal] THEN STRIP_TAC);
 (ASM_REWRITE_TAC[]);
 (REAL_ARITH_TAC);

 (MP_TAC (ASSUME `(x - u0:real^3) dot (u1 - u0) > 
                dist (x,u0) * dist (u1,u0) * a'`));
 (REWRITE_WITH `(x - u0) dot (u1 - u0) = 
                 (x - y) dot (u1 - u0) + (y - u0) dot (u1 - u0:real^3)`);
 (VECTOR_ARITH_TAC);
 (REWRITE_WITH `(x - u1) dot (u0 - u1) = 
                 (x - y) dot (u0 - u1) + (y - u1) dot (u0 - u1:real^3)`);
 (VECTOR_ARITH_TAC);
 (REWRITE_WITH `(x - y) dot (u1 - u0:real^3) = &0`);
 (ASM_REWRITE_TAC[GSYM orthogonal]);
 (REWRITE_WITH `(x - y) dot (u0 - u1:real^3) = &0`);
 (ONCE_REWRITE_TAC[VECTOR_ARITH `a dot (u0 - u1) = --(a dot (u1 - u0))`]);
 (REWRITE_TAC[REAL_ARITH `--a = &0 <=> a = &0`]);
 (ASM_REWRITE_TAC[GSYM orthogonal]);
 (REWRITE_TAC[REAL_ARITH `&0 + a = a`]);

 (STRIP_TAC);
 (NEW_GOAL `(y - u0) dot (u1 - u0) = norm (y - u0) * norm (u1 - u0:real^3)`);
 (REWRITE_TAC[NORM_CAUCHY_SCHWARZ_EQ]);
 (REWRITE_WITH `y - u0 = proj_point (u1 - u0) (x - u0:real^3)`);
 (EXPAND_TAC "y" THEN REWRITE_TAC[VECTOR_ARITH `(a + b) - a:real^3 = b`]);
 (REWRITE_TAC[PRO_EXP; NORM_MUL; VECTOR_MUL_ASSOC]);
 (MATCH_MP_TAC (MESON[] `a = b ==> a % x = b % x`));
 (REWRITE_TAC[REAL_ARITH `a * norm b = norm b * a`]);
 (MATCH_MP_TAC (MESON[] `a = b ==> x * a = x * b`));
 (REWRITE_TAC[REAL_ABS_REFL]);
 (MATCH_MP_TAC REAL_LE_DIV);
 (REWRITE_TAC[DOT_POS_LE]);

 (REWRITE_WITH `(x - u0) dot (u1 - u0) = 
                 (x - y) dot (u1 - u0) + (y - u0) dot (u1 - u0:real^3)`);
 (VECTOR_ARITH_TAC);
 (REWRITE_WITH `(x - y) dot (u1 - u0:real^3) = &0`);
 (ASM_REWRITE_TAC[GSYM orthogonal]);
 (REWRITE_TAC[REAL_ARITH `&0 + a = a`]);

 (NEW_GOAL `y IN convex hull {u0, u1:real^3}`);
 (NEW_GOAL `y IN affine hull {u0, u1:real^3}`);
 (REWRITE_TAC[AFFINE_HULL_2; IN; IN_ELIM_THM]);
 (EXPAND_TAC "y" THEN REWRITE_TAC[PRO_EXP]);
 (ABBREV_TAC `rtemp = ((x - u0) dot (u1 - u0)) / ((u1 - u0) dot (u1 - 
                u0:real^3))`);
 (EXISTS_TAC `&1 - rtemp` THEN EXISTS_TAC `rtemp:real`);
 (STRIP_TAC);
 (REAL_ARITH_TAC);
 (VECTOR_ARITH_TAC);
 (UP_ASM_TAC THEN REWRITE_TAC[IN; AFFINE_HULL_2; CONVEX_HULL_2; IN_ELIM_THM]);
 (REPEAT STRIP_TAC);
 (EXISTS_TAC `u:real` THEN EXISTS_TAC `v:real`);
 (ASM_REWRITE_TAC[]);

 (NEW_GOAL `y - u0 = v % (u1 - u0:real^3)`);
 (NEW_GOAL `y - u0 = y - (u + v) % u0:real^3`);
 (REWRITE_TAC[ASSUME `u + v = &1`; VECTOR_MUL_LID]);
 (UP_ASM_TAC THEN REWRITE_WITH `y - (u + v) % u0 = v % (u1 - u0:real^3)`);
 (REWRITE_TAC[ASSUME `y = u % u0 + v % u1:real^3`] THEN VECTOR_ARITH_TAC);

 (ASM_CASES_TAC `u < &0`);
 (NEW_GOAL `F`);
 (NEW_GOAL `norm (y - u0) <= norm (x - u0:real^3)`);
 (MATCH_MP_TAC Tactics_jordan.REAL_POW_2_LE);
 (REWRITE_TAC[NORM_POS_LE; ASSUME 
  `norm (x - u0:real^3) pow 2 = norm (y - u0) pow 2 + norm (x - y) pow 2`; 
   REAL_ARITH `a <= a + b <=> &0 <= b`; REAL_LE_POW_2]);
 (NEW_GOAL `norm (x - u0:real^3) < &1`);
 (REWRITE_TAC[GSYM dist] THEN ONCE_REWRITE_TAC[DIST_SYM] THEN 
   REWRITE_TAC[GSYM IN_BALL]);
 (NEW_GOAL `ball (u0:real^3, r) SUBSET ball (u0, &1)`);
 (MATCH_MP_TAC SUBSET_BALL);
 (EXPAND_TAC "r" THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN UNDISCH_TAC 
  `x IN ball (u0:real^3,r) INTER rcone_gt u0 u1 d` THEN SET_TAC[]);

 (NEW_GOAL `norm (y - u0) = v * norm (u1:real^3 - u0)`);
 (ASM_REWRITE_TAC[NORM_MUL]);

 (REWRITE_WITH `abs v = v`);
 (REWRITE_TAC[REAL_ABS_REFL]);
 (UNDISCH_TAC `u + v = &1` THEN UNDISCH_TAC `u < &0` THEN REAL_ARITH_TAC);
 (NEW_GOAL `&2 <= norm (u1 - u0:real^3)`);
 (REWRITE_TAC[GSYM dist]);
 (UNDISCH_TAC `packing (V:real^3->bool)` THEN REWRITE_TAC[packing]);
 (REPEAT STRIP_TAC);
 (FIRST_ASSUM MATCH_MP_TAC);
 (ASM_REWRITE_TAC[]);
 (ONCE_REWRITE_TAC[MESON[IN] `V x <=> x IN (V:real^3->bool)`]);
 (ASM_REWRITE_TAC[]);

 (NEW_GOAL `v * &2 <= v * norm (u1 - u0:real^3)`);
 (REWRITE_TAC[REAL_ARITH `a * b <= a * c <=> &0 <= a * (c - b)`]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (UNDISCH_TAC `u + v = &1` THEN UNDISCH_TAC `u < &0` THEN UP_ASM_TAC);
 (REAL_ARITH_TAC);

 (NEW_GOAL `&1 < v`);
 (UNDISCH_TAC `u + v = &1` THEN UNDISCH_TAC `u < &0` THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN UP_ASM_TAC THEN UP_ASM_TAC THEN 
   UP_ASM_TAC THEN UP_ASM_TAC THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (ASM_CASES_TAC `v < &0`);
 (NEW_GOAL `F`);
 (NEW_GOAL `(y - u0) dot (u1 - u0:real^3) <= &0`);
 (ASM_REWRITE_TAC[DOT_LMUL; REAL_ARITH `a * b <= &0 <=> &0 <= (--a) * b`]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (REWRITE_TAC[DOT_POS_LE]);
 (UP_ASM_TAC THEN REAL_ARITH_TAC);

 (NEW_GOAL `&0 <= dist (x,u0) * dist (u1,u0:real^3) * a'`);
 (MATCH_MP_TAC REAL_LE_MUL);
 (REWRITE_TAC[DIST_POS_LE]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (REWRITE_TAC[DIST_POS_LE]);
 (EXPAND_TAC "a'" THEN MATCH_MP_TAC REAL_LE_DIV);
 (STRIP_TAC);
 (REWRITE_TAC[HL_2]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (REWRITE_TAC[DIST_POS_LE] THEN REAL_ARITH_TAC);
 (MATCH_MP_TAC SQRT_POS_LE THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN UNDISCH_TAC 
 `(y - u0:real^3) dot (u1 - u0) > dist (x,u0) * dist (u1,u0) * a'`);
 (REAL_ARITH_TAC);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN REAL_ARITH_TAC);

 (NEW_GOAL `&0 <= dist (x,u0) * dist (u1,u0:real^3) * a'`);
 (MATCH_MP_TAC REAL_LE_MUL);
 (REWRITE_TAC[DIST_POS_LE]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (REWRITE_TAC[DIST_POS_LE]);
 (EXPAND_TAC "a'" THEN MATCH_MP_TAC REAL_LE_DIV);
 (STRIP_TAC);
 (REWRITE_TAC[HL_2]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (REWRITE_TAC[DIST_POS_LE] THEN REAL_ARITH_TAC);
 (MATCH_MP_TAC SQRT_POS_LE THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN UP_ASM_TAC THEN REAL_ARITH_TAC);

 (NEW_GOAL `(y - u1) dot (u0 - u1) = norm (y - u1) * norm (u0 - u1:real^3)`);
 (REWRITE_TAC[NORM_CAUCHY_SCHWARZ_EQ]);
 (REWRITE_WITH `y - u1 = proj_point (u1 - u0) (x - u0:real^3) - (u1 - u0)`);
 (EXPAND_TAC "y" THEN VECTOR_ARITH_TAC);
 (REWRITE_TAC[PRO_EXP; VECTOR_ARITH `x % a - a = (x - &1) % a`; NORM_MUL;
               VECTOR_MUL_ASSOC]);
 (REWRITE_WITH ` 
   (norm (u0 - u1) *
   (((x - u0) dot (u1 - u0)) / ((u1 - u0) dot (u1 - u0)) - &1)) % (u1 - u0) =  
   (norm (u0 - u1:real^3) *
   (&1 - ((x - u0) dot (u1 - u0)) / ((u1 - u0) dot (u1 - u0)))) % (u0 - u1)`);
 (VECTOR_ARITH_TAC);
 (MATCH_MP_TAC (MESON[] `a = b ==> a % x = b % x`));
 (REWRITE_TAC[REAL_ARITH `a * norm b = norm b * a`]);
 (REWRITE_TAC[NORM_ARITH `norm (a - b) = norm (b - a)`]);
 (MATCH_MP_TAC (MESON[] `a = b ==> x * a = x * b`));
 (REWRITE_TAC[REAL_ARITH `abs (x - &1) = abs (&1 - x)`]);
 (REWRITE_TAC[REAL_ABS_REFL; REAL_ARITH `&0 <= a - b <=> b <= a`]);
 (REWRITE_WITH `((x - u0) dot (u1 - u0)) / ((u1 - u0) dot (u1 - u0)) <= &1
  <=> ((x - u0) dot (u1 - u0)) <= &1 * ((u1 - u0) dot (u1 - u0:real^3))`);
 (MATCH_MP_TAC REAL_LE_LDIV_EQ);
 (REWRITE_TAC[DOT_POS_LT; VECTOR_ARITH `a - b = vec 0 <=> b = a`]);
 (ASM_REWRITE_TAC[]);
 (NEW_GOAL `(x - u0) dot (u1 - u0) <= norm (x - u0) * norm (u1 - u0:real^3)`);
 (REWRITE_TAC[NORM_CAUCHY_SCHWARZ]);

 (NEW_GOAL `norm (x - u0) * norm (u1 - u0) <= &1 * norm (u1 - u0:real^3)`);
 (REWRITE_TAC[REAL_ARITH `a * x <= b * x <=> &0 <= (b - a) * x`]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (REWRITE_TAC[NORM_POS_LE; REAL_ARITH `&0 <= a - b <=> b <= a`; GSYM dist]);
 (MATCH_MP_TAC (REAL_ARITH `a < x ==> a <= x`));
 (ONCE_REWRITE_TAC[DIST_SYM] THEN REWRITE_TAC[GSYM IN_BALL]);
 (NEW_GOAL `ball (u0:real^3, r) SUBSET ball (u0, &1)`);
 (MATCH_MP_TAC SUBSET_BALL);
 (EXPAND_TAC "r" THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN UNDISCH_TAC 
  `x IN ball (u0:real^3,r) INTER rcone_gt u0 u1 d` THEN SET_TAC[]);
 (REWRITE_TAC[GSYM NORM_POW_2; REAL_ARITH `&1 * a pow 2 = a * a`]);
 (NEW_GOAL `&1 * norm (u1 - u0) <= norm (u1 - u0) * norm (u1 - u0:real^3)`);
 (REWRITE_TAC[REAL_ARITH `a * x <= b * x <=> &0 <= (b - a) * x`]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (REWRITE_TAC[NORM_POS_LE; REAL_ARITH `&0 <= a - b <=> b <= a`; GSYM dist]);
 (MATCH_MP_TAC (REAL_ARITH `&2 <= x ==> &1 <= x`));
 (UNDISCH_TAC `packing (V:real^3->bool)` THEN REWRITE_TAC[packing]);
 (STRIP_TAC);
 (FIRST_ASSUM MATCH_MP_TAC);
 (ASM_REWRITE_TAC[]);
 (ONCE_REWRITE_TAC[MESON[IN] `V x <=> x IN (V:real^3->bool)`]);
 (ASM_REWRITE_TAC[]);
 (UNDISCH_TAC `(x - u0:real^3) dot (u1 - u0) <= 
                norm (x - u0) * norm (u1 - u0)` THEN 
   UP_ASM_TAC THEN UP_ASM_TAC THEN REAL_ARITH_TAC);
 (ASM_REWRITE_TAC[dist]);
 (REWRITE_TAC[REAL_ARITH `a * b >= x * b * c <=> &0 <= b * (a - x * c)`]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (REWRITE_TAC[NORM_POS_LE; REAL_ARITH `&0 <= a - b <=> b <= a`]);
 (MATCH_MP_TAC Tactics_jordan.REAL_POW_2_LE);
 (STRIP_TAC);

 (MATCH_MP_TAC REAL_LE_MUL);
 (REWRITE_TAC[NORM_POS_LE]);
 (EXPAND_TAC "a'" THEN MATCH_MP_TAC REAL_LE_DIV);
 (STRIP_TAC);
 (REWRITE_TAC[HL_2]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (REWRITE_TAC[DIST_POS_LE] THEN REAL_ARITH_TAC);
 (MATCH_MP_TAC SQRT_POS_LE THEN REAL_ARITH_TAC);
 (REWRITE_TAC[NORM_POS_LE; REAL_ARITH `(a * b) pow 2 = a pow 2 * b pow 2`]);
 (ASM_REWRITE_TAC[]);
 (REWRITE_TAC[REAL_ARITH `(a + b) * x <= a <=> b * x <= (&1 - x) * a`]);

 (UNDISCH_TAC `(y - u0) dot (u1 - u0) > dist (x,u0) * dist (u1,u0:real^3) * a'`);
 (ASM_REWRITE_TAC[dist]);
 (REWRITE_TAC[REAL_ARITH `a * b > x * b * c <=> &0 < b * (a - x * c)`]);
 (REWRITE_TAC[REAL_MUL_POS_LT]);
 (REWRITE_WITH `~(norm (u1 - u0:real^3) < &0 /\ 
                   norm (y - u0) - norm (x - u0) * a' < &0)`);
 (NEW_GOAL `&0 <= norm (u1 - u0:real^3)`);
 (REWRITE_TAC[NORM_POS_LE]);
 (UP_ASM_TAC THEN REAL_ARITH_TAC);
 (REWRITE_TAC[REAL_ARITH `&0 < a - b <=> b < a`]);
 (REWRITE_WITH `norm (x - u0) * a' < norm (y - u0:real^3) <=> 
                (norm (x - u0) * a') pow 2 < norm (y - u0) pow 2`);
 (MATCH_MP_TAC Pack1.bp_bdt);
 (STRIP_TAC);
 (MATCH_MP_TAC REAL_LE_MUL);
 (REWRITE_TAC[NORM_POS_LE]);
 (EXPAND_TAC "a'" THEN MATCH_MP_TAC REAL_LE_DIV);
 (STRIP_TAC);
 (REWRITE_TAC[HL_2]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (REWRITE_TAC[DIST_POS_LE] THEN REAL_ARITH_TAC);
 (MATCH_MP_TAC SQRT_POS_LE THEN REAL_ARITH_TAC);
 (REWRITE_TAC[NORM_POS_LE]);

 (ASM_REWRITE_TAC[REAL_ARITH `(a * b) pow 2 = a pow 2 * b pow 2`]);
 (REWRITE_TAC[REAL_ARITH `(a + b) * x < a <=> b * x < (&1 - x) * a`]);
 (STRIP_TAC);
 
 (NEW_GOAL `(&1 - a' pow 2) * norm (y - u0) pow 2 <= 
             (&1 - a' pow 2) * norm (y - u1:real^3) pow 2`);
 (REWRITE_TAC[REAL_ARITH `a * x <= a * y <=> &0 <= a * (y - x)`]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (STRIP_TAC);
 (REWRITE_TAC[REAL_ARITH `&0 <= &1 - b <=> b <= &1 pow 2`]);
 (REWRITE_WITH `a' pow 2 <= &1 pow 2 <=> a' <= &1`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC Collect_geom.POW2_COND);
 (REWRITE_TAC[REAL_ARITH `&0 <= &1`]);
 (EXPAND_TAC "a'" THEN MATCH_MP_TAC REAL_LE_DIV);
 (STRIP_TAC);
 (REWRITE_TAC[HL_2]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (REWRITE_TAC[DIST_POS_LE] THEN REAL_ARITH_TAC);
 (MATCH_MP_TAC SQRT_POS_LE THEN REAL_ARITH_TAC);

 (EXPAND_TAC "a'");
 (MATCH_MP_TAC REAL_DIV_LE_1_TACTICS);
 (ASM_SIMP_TAC[SQRT_POS_LT; REAL_ARITH `&0 < &2`]);
 (UNDISCH_TAC `hl [u0; u1:real^3] < sqrt (&2)` THEN REAL_ARITH_TAC);
 (NEW_GOAL `norm (x - u0) pow 2 <= norm (x - u1:real^3) pow 2`);
 (REWRITE_WITH `norm (x - u0) pow 2 <= norm (x - u1:real^3) pow 2 <=>
                 norm (x - u0)  <= norm (x - u1:real^3)`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC Collect_geom.POW2_COND);
 (REWRITE_TAC[NORM_POS_LE]);
 (MATCH_MP_TAC (REAL_ARITH `&2 * x <= x + y ==> x <= y`));
 (REWRITE_TAC[GSYM dist]);

 (NEW_GOAL `dist (x, u0:real^3) < &1`);
 (ONCE_REWRITE_TAC[DIST_SYM] THEN REWRITE_TAC[GSYM IN_BALL]);
 (NEW_GOAL `ball (u0:real^3, r) SUBSET ball (u0, &1)`);
 (MATCH_MP_TAC SUBSET_BALL);
 (EXPAND_TAC "r" THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN UNDISCH_TAC 
  `x IN ball (u0:real^3,r) INTER rcone_gt u0 u1 d` THEN SET_TAC[]);
 (NEW_GOAL `&2 * dist (x, u0:real^3) < &2`);
 (UP_ASM_TAC THEN REAL_ARITH_TAC);
 (NEW_GOAL `&2 <= dist (x, u0) + dist (x, u1:real^3)`);
 (NEW_GOAL `&2 <= dist (u0, u1:real^3)`);
 (UNDISCH_TAC `packing (V:real^3->bool)` THEN REWRITE_TAC[packing]);
 (STRIP_TAC);
 (FIRST_ASSUM MATCH_MP_TAC);
 (ASM_REWRITE_TAC[]);
 (ONCE_REWRITE_TAC[MESON[IN] `V a <=> a:real^3 IN V`]);
 (ASM_REWRITE_TAC[]);

 (NEW_GOAL `dist (u0, u1:real^3) <= dist (u0, x) + dist (x, u1)`);
 (REWRITE_TAC[DIST_TRIANGLE]);
 (UP_ASM_TAC THEN REWRITE_TAC[DIST_SYM]);
 (UP_ASM_TAC THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN ASM_REWRITE_TAC[]);
 (REAL_ARITH_TAC);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN REAL_ARITH_TAC);

 (NEW_GOAL `F`);
 (UNDISCH_TAC `~NULLSET (X INTER D)`);
 (REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X INTER C:real^3->bool`);
 (ASM_SIMP_TAC [SET_RULE `A SUBSET B ==> X INTER A SUBSET X INTER B`]);
 (ASM_REWRITE_TAC[MCELL_EXPLICIT; mcell2; SET_RULE `{} INTER s = {}`]);
 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (NEW_GOAL `~coplanar {u0, u1:real^3, m, s3}`);
 (ONCE_REWRITE_TAC[GSYM COPLANAR_AFFINE_HULL_COPLANAR]);
 (STRIP_TAC);
 (NEW_GOAL `NULLSET X`);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1, m, s3:real^3}`);
 (STRIP_TAC);
 (MATCH_MP_TAC COPLANAR_IMP_NEGLIGIBLE);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (ASM_REWRITE_TAC[MCELL_EXPLICIT; mcell2]);
 (COND_CASES_TAC);
 (LET_TAC);
 (MATCH_MP_TAC (SET_RULE `A SUBSET B ==> M INTER N INTER A SUBSET B`));

 (NEW_GOAL `?v0 v1 v2 v3. vl = [v0;v1;v2;v3:real^3]`);
 (MATCH_MP_TAC Marchal_cells.BARV_3_EXPLICIT);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (REWRITE_WITH `HD vl = u0 /\ HD (TL vl) = u1:real^3`);
 (REWRITE_WITH `(HD vl):real^3 = HD (truncate_simplex 1 vl)`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC Packing3.HD_TRUNCATE_SIMPLEX);
 (ASM_REWRITE_TAC[LENGTH] THEN ARITH_TAC);
 (ASM_REWRITE_TAC[HD; TL]);
 (NEW_GOAL `HD (TL(truncate_simplex 1 vl)) = u1:real^3`);
 (ASM_REWRITE_TAC[HD; TL]);
 (NEW_GOAL `HD (TL(truncate_simplex 1 vl)) = v1:real^3`);
 (REWRITE_TAC[ASSUME `vl = [v0; v1; v2; v3:real^3]`;  
   TRUNCATE_SIMPLEX_EXPLICIT_1; HD; TL]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN MESON_TAC[]);
 (REWRITE_WITH `{u0, u1, m, s3} = {u0, u1} UNION {m:real^3, s3}`);
 (SET_TAC[]);
 (REWRITE_TAC[AFF_GE_SUBSET_AFFINE_HULL]);
 (SET_TAC[]);
 (UNDISCH_TAC `~NULLSET (X INTER D)`);
 (REWRITE_TAC[] THEN MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X:real^3->bool`);
 (ASM_REWRITE_TAC[] THEN SET_TAC[]);

(* ========================================================================= *)
 (ASM_CASES_TAC `azim u0 u1 m (s3:real^3) < pi`);
 (REWRITE_WITH `vol (L INTER D) = vol (D INTER wedge u0 u1 m s3)`);
 (ASM_SIMP_TAC[WEDGE_LUNE]);
 (REWRITE_WITH `L INTER conic_cap (u0:real^3) u1 r d = 
                 conic_cap u0 u1 r d INTER L`);
 (SET_TAC[]);
 (MATCH_MP_TAC MEASURE_NEGLIGIBLE_SYMDIFF);
 (REWRITE_WITH `conic_cap (u0:real^3) u1 r d INTER 
   aff_gt {u0, u1} {m, s3} DIFF conic_cap u0 u1 r d INTER L = {}`);
 (EXPAND_TAC "L");
 (MATCH_MP_TAC (SET_RULE `A SUBSET B ==> C INTER A DIFF C INTER B = {}`));
 (REWRITE_TAC[AFF_GT_SUBSET_AFF_GE]);
 (REWRITE_TAC[SET_RULE `A UNION {} = A`]);
 (EXPAND_TAC "L");

 (REWRITE_WITH `aff_ge {u0, u1:real^3} {m, s3} =
                 aff_gt {u0, u1} {m, s3} UNION 
   UNIONS {aff_ge {u0, u1} ({m, s3} DELETE a) | a | a IN  {m, s3}}`);
 (MATCH_MP_TAC AFF_GE_AFF_GT_DECOMP);
 (REWRITE_TAC[Geomdetail.FINITE6]);
 (REWRITE_TAC[DISJOINT]);

 (ASM_CASES_TAC `m IN {u0, u1:real^3}`);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~coplanar {u0, u1, m, s3:real^3}`);
 (REWRITE_WITH `{u0, u1, m, s3} = {u0, u1, s3:real^3}`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_TAC[COPLANAR_3]);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (ASM_CASES_TAC `s3 IN {u0, u1:real^3}`);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~coplanar {u0, u1, m, s3:real^3}`);
 (REWRITE_WITH `{u0, u1, m, s3} = {u0, u1, m:real^3}`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_TAC[COPLANAR_3]);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN SET_TAC[]);

 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC 
  `UNIONS {aff_ge {u0, u1:real^3} ({m, s3} DELETE a) | a | a IN {m, s3}}`);
 (STRIP_TAC);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC 
  `aff_ge {u0, u1:real^3} {m} UNION aff_ge {u0, u1:real^3} {s3}`);
 (STRIP_TAC);
 (MATCH_MP_TAC NEGLIGIBLE_UNION);
 (STRIP_TAC);

 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1:real^3, m}`);
 (STRIP_TAC);
 (REWRITE_TAC[NEGLIGIBLE_AFFINE_HULL_3]);
 (REWRITE_WITH `{u0,u1,m:real^3} = {u0,u1} UNION {m}`);
 (SET_TAC[]);
 (REWRITE_TAC[AFF_GE_SUBSET_AFFINE_HULL]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1:real^3, s3}`);
 (STRIP_TAC);
 (REWRITE_TAC[NEGLIGIBLE_AFFINE_HULL_3]);
 (REWRITE_WITH `{u0,u1,s3:real^3} = {u0,u1} UNION {s3}`);
 (SET_TAC[]);
 (REWRITE_TAC[AFF_GE_SUBSET_AFFINE_HULL]);
 (REWRITE_TAC[SET_RULE 
  `UNIONS {aff_ge {u0, u1} ({m, s3} DELETE a) | a | a IN {m, s3}} = 
         aff_ge {u0, u1} ({m, s3} DELETE s3) 
   UNION aff_ge {u0, u1} ({m, s3} DELETE m)`]);
 (MATCH_MP_TAC (SET_RULE 
  `A SUBSET B /\ C SUBSET D ==> A UNION C SUBSET B UNION D`));
 (STRIP_TAC);
 (MATCH_MP_TAC AFF_GE_MONO_RIGHT);
 (STRIP_TAC);
 (SET_TAC[]);

 (REWRITE_TAC[DISJOINT]);
 (ASM_CASES_TAC `m IN {u0, u1:real^3}`);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~coplanar {u0, u1, m, s3:real^3}`);
 (REWRITE_WITH `{u0, u1, m, s3} = {u0, u1, s3:real^3}`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_TAC[COPLANAR_3]);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (UP_ASM_TAC THEN SET_TAC[]);

 (MATCH_MP_TAC AFF_GE_MONO_RIGHT);
 (STRIP_TAC);
 (SET_TAC[]);
 (REWRITE_TAC[DISJOINT]);
 (ASM_CASES_TAC `s3 IN {u0, u1:real^3}`);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~coplanar {u0, u1, m, s3:real^3}`);
 (REWRITE_WITH `{u0, u1, m, s3} = {u0, u1, m:real^3}`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_TAC[COPLANAR_3]);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (UP_ASM_TAC THEN SET_TAC[]);

 (SET_TAC[]);

 (REWRITE_TAC[ASSUME `D = conic_cap (u0:real^3) u1 r d`]);
 (REWRITE_WITH `vol (conic_cap u0 u1 r d INTER wedge u0 u1 m s3) =
             (if &1 < d \/ r < &0
              then &0
              else azim u0 u1 m s3 / &3 * (&1 - max d (-- &1)) * r pow 3)`);
 (NEW_GOAL `~collinear {u0:real^3, u1, m} /\ ~collinear {u0, u1, s3}`);
 (STRIP_TAC);
 (MATCH_MP_TAC NOT_COPLANAR_NOT_COLLINEAR);
 (EXISTS_TAC `s3:real^3`);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC NOT_COPLANAR_NOT_COLLINEAR);
 (EXISTS_TAC `m:real^3`);
 (ONCE_REWRITE_TAC[SET_RULE `{a,b,c,d} = {a,b,d,c}`]);
 (ASM_REWRITE_TAC[]);

 (ASM_SIMP_TAC[VOLUME_CONIC_CAP_WEDGE]);
 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `&0 < r` THEN UNDISCH_TAC `d < &1` THEN 
   UP_ASM_TAC THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (REWRITE_WITH `azim (u0:real^3) u1 m s3 = dihV u0 u1 m s3`);
 (MATCH_MP_TAC AZIM_DIHV_SAME);
 (ASM_REWRITE_TAC[]);
 (STRIP_TAC);
 (MATCH_MP_TAC NOT_COPLANAR_NOT_COLLINEAR);
 (EXISTS_TAC `s3:real^3`);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC NOT_COPLANAR_NOT_COLLINEAR);
 (EXISTS_TAC `m:real^3`);
 (ONCE_REWRITE_TAC[SET_RULE `{a,b,c,d} = {a,b,d,c}`]);
 (ASM_REWRITE_TAC[]);

 (REWRITE_TAC[dihX]);
 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~NULLSET (X INTER D)`);
 (REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X:real^3->bool`);
 (ASM_REWRITE_TAC[] THEN SET_TAC[]);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (LET_TAC);

 (UP_ASM_TAC THEN REWRITE_TAC[cell_params_d]);
 (ABBREV_TAC `P = (\(k, ul). k <= 4 /\
           ul IN barV V 3 /\
           X = mcell k V ul /\
           initial_sublist [u0; u1] ul)`);
 (STRIP_TAC);
 (NEW_GOAL `(P:num#(real^3)list->bool) ((@) P)`);
 (MATCH_MP_TAC SELECT_AX);
 (EXISTS_TAC `(2, vl:(real^3)list)`);
 (EXPAND_TAC "P");
 (REWRITE_TAC[BETA_THM]);
 (REWRITE_TAC[IN; ARITH_RULE `2 <= 4`] THEN ASM_REWRITE_TAC[]);
 (REWRITE_WITH `initial_sublist [u0;u1:real^3] vl /\ LENGTH [u0;u1] = 1 + 1`);
 (REWRITE_TAC[GSYM Packing3.TRUNCATE_SIMPLEX_INITIAL_SUBLIST]);
 (ASM_REWRITE_TAC[]);

 (NEW_GOAL `?v0 v1 v2 v3. vl = [v0;v1;v2;v3:real^3]`);
 (MATCH_MP_TAC Marchal_cells.BARV_3_EXPLICIT);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (ASM_REWRITE_TAC[LENGTH] THEN ARITH_TAC);
 (UP_ASM_TAC THEN ASM_REWRITE_TAC[]);
 (EXPAND_TAC "P" THEN REWRITE_TAC[IN] THEN REPEAT STRIP_TAC);

 (NEW_GOAL `k' = 2 /\ mcell k' V ul = mcell 2 V vl`);
 (MATCH_MP_TAC Ajripqn.AJRIPQN);
 (ASM_REWRITE_TAC[]);
 (REWRITE_WITH `mcell k' V ul INTER mcell 2 V vl = X`);
 (SET_TAC[ASSUME `X = mcell k' V ul`; 
               ASSUME `X = mcell k V vl`; ASSUME `k = 2`]);
 (REPEAT STRIP_TAC);
 (UNDISCH_TAC `k' <= 4` THEN REWRITE_TAC[ARITH_RULE 
   `a <= 4 <=> a = 0 \/a = 1 \/ a = 2 \/ a = 3 \/ a = 4`] THEN SET_TAC[]);
 (SET_TAC[]);
 (UP_ASM_TAC THEN UNDISCH_TAC `~NULLSET X` THEN MESON_TAC[]);

 (COND_CASES_TAC);
 (REWRITE_TAC[dihu2]);

 (REWRITE_WITH `omega_list_n V ul 3 = s3`);
 (EXPAND_TAC "s3");
 (NEW_GOAL `2  = 2 /\
             (!k. 2 - 1 <= k /\ k <= 3
                  ==> omega_list_n V ul k = omega_list_n V vl k)`);
 (MATCH_MP_TAC MCELL_ID_OMEGA_LIST_N);
 (ASM_REWRITE_TAC[SET_RULE `2 IN {2,3,4}`]);
 (REWRITE_TAC[GSYM (ASSUME `X = mcell k' V ul`); GSYM (ASSUME `k' = 2`)]);
 (ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);

 (FIRST_ASSUM MATCH_MP_TAC);
 (ARITH_TAC);

 (REWRITE_WITH `mxi V ul = m`);
 (EXPAND_TAC "m");
 (MATCH_MP_TAC MCELL_ID_MXI);
 (EXISTS_TAC `2` THEN EXISTS_TAC `2`);
 (ASM_REWRITE_TAC[SET_RULE `2 IN {2,3}`]);
 (STRIP_TAC);

 (REWRITE_WITH `(HD vl):real^3 = HD (truncate_simplex 1 vl)`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC Packing3.HD_TRUNCATE_SIMPLEX);
 (REWRITE_WITH `LENGTH (vl:(real^3)list) = 3 + 1 /\ 
                 CARD (set_of_list vl) = 3 + 1`);
 (MATCH_MP_TAC Rogers.BARV_IMP_LENGTH_EQ_CARD);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (ARITH_TAC);
 (ASM_REWRITE_TAC[HD]);

 (REWRITE_WITH `(HD ul):real^3 = HD (truncate_simplex 1 ul)`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC Packing3.HD_TRUNCATE_SIMPLEX);
 (REWRITE_WITH `LENGTH (ul:(real^3)list) = 3 + 1 /\ 
                 CARD (set_of_list ul) = 3 + 1`);
 (MATCH_MP_TAC Rogers.BARV_IMP_LENGTH_EQ_CARD);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (ARITH_TAC);

 (REWRITE_WITH `truncate_simplex 1 ul = [u0;u1:real^3] /\ 1 + 1 <= LENGTH ul`);
 (REWRITE_TAC[Packing3.TRUNCATE_SIMPLEX_INITIAL_SUBLIST]);
 (ASM_REWRITE_TAC[LENGTH] THEN ARITH_TAC);
 (REWRITE_TAC[HD]);
 (REWRITE_TAC[GSYM (ASSUME `X = mcell k' V ul`); GSYM (ASSUME `k' = 2`)]);
 (ASM_REWRITE_TAC[]);

 (NEW_GOAL `initial_sublist [u0; u1:real^3] ul /\ LENGTH [u0; u1] = 1 + 1`);
 (ASM_REWRITE_TAC[LENGTH] THEN ARITH_TAC);
 (NEW_GOAL `truncate_simplex 1 ul = [u0;u1:real^3] /\ 1 + 1 <= LENGTH ul`);
 (REWRITE_TAC[Packing3.TRUNCATE_SIMPLEX_INITIAL_SUBLIST]);
 (ASM_REWRITE_TAC[]);

 (REWRITE_WITH `EL 0 (ul:(real^3)list) = EL 0 (truncate_simplex 1 ul)`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC Packing3.EL_TRUNCATE_SIMPLEX);
 (REWRITE_WITH `LENGTH (ul:(real^3)list) = 3 + 1 /\ 
                 CARD (set_of_list ul) = 3 + 1`);
 (MATCH_MP_TAC Rogers.BARV_IMP_LENGTH_EQ_CARD);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (ARITH_TAC);

 (REWRITE_WITH `EL 1 (ul:(real^3)list) = EL 1 (truncate_simplex 1 ul)`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC Packing3.EL_TRUNCATE_SIMPLEX);
 (REWRITE_WITH `LENGTH (ul:(real^3)list) = 3 + 1 /\ 
                 CARD (set_of_list ul) = 3 + 1`);
 (MATCH_MP_TAC Rogers.BARV_IMP_LENGTH_EQ_CARD);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (ARITH_TAC);
 (ASM_REWRITE_TAC[EL; HD; ARITH_RULE `1 = SUC 0`; TL]);
 (REWRITE_TAC[REAL_ARITH `a / b * c * d pow 3 = (c/ b * d pow 3) * a`]);
 (REWRITE_TAC[REAL_ARITH `a * b / (&2 * c) = (a / (&2 * c)) * b`]);
 (AP_THM_TAC THEN AP_TERM_TAC);

 (REWRITE_WITH 
  `measurable (conic_cap u0 u1 r d) /\
             vol (conic_cap u0 u1 r d) =
             (if u1 = u0 \/ &1 <= d \/ r < &0
              then &0
              else &2 / &3 * pi * (&1 - d) * r pow 3)`);
 (MATCH_MP_TAC VOLUME_CONIC_CAP);
 (EXPAND_TAC "d");
 (UNDISCH_TAC `&0 < c /\ c < &1` THEN REAL_ARITH_TAC);
 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (UP_ASM_TAC THEN STRIP_TAC);
 (UP_ASM_TAC THEN UNDISCH_TAC `~(u0 = u1:real^3)` THEN MESON_TAC[]);
 (UNDISCH_TAC `d < &1` THEN UP_ASM_TAC THEN REAL_ARITH_TAC);
 (UNDISCH_TAC `&0 < r` THEN UP_ASM_TAC THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (REWRITE_TAC[ARITH_RULE `SUC 0 = 1`]);


 (REWRITE_WITH `max d (--(&1)) = d`);
 (MATCH_MP_TAC (REAL_ARITH `&0 < d /\ --(&1) < &0 ==> max d (--(&1)) = d`));
 (REWRITE_TAC[REAL_NEG_LT0]);
 (STRIP_TAC);
 (EXPAND_TAC "d");
 (UNDISCH_TAC `&0 < c /\ c < &1` THEN REAL_ARITH_TAC);
 (REAL_ARITH_TAC);

 (REWRITE_WITH `
  (&2 / &3 * pi * (&1 - d) * r pow 3) / (&2 * pi) = (&1 - d) / &3 * r pow 3 *   
  ((&2 * pi) / (&2 * pi))`);
 (REAL_ARITH_TAC);
 (REWRITE_WITH `(&2 * pi) / (&2 * pi) = &1`);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (REWRITE_TAC[REAL_ENTIRE; PI_NZ; REAL_ARITH `~(&2 = &0)`]);
 (REAL_ARITH_TAC);
 (NEW_GOAL `F`);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN MESON_TAC[]);
 (UP_ASM_TAC THEN MESON_TAC[]);

(* ========================================================================= *)
(* OK here *)

 (ASM_CASES_TAC `azim u0 u1 s3 (m:real^3) < pi`);
 (UNDISCH_TAC `~coplanar {u0, u1, m, s3:real^3}`);
 (ONCE_REWRITE_TAC[SET_RULE `{a,b,c,d} = {a,b,d,c}`]);
 (STRIP_TAC);
 (REWRITE_WITH `vol (L INTER D) = vol (D INTER wedge u0 u1 s3 m)`);
 (ASM_SIMP_TAC[WEDGE_LUNE]);
 (REWRITE_WITH `L INTER conic_cap (u0:real^3) u1 r d = 
                 conic_cap u0 u1 r d INTER L`);
 (SET_TAC[]);
 (MATCH_MP_TAC MEASURE_NEGLIGIBLE_SYMDIFF);

 (REWRITE_WITH `conic_cap (u0:real^3) u1 r d INTER 
   aff_gt {u0, u1} {s3, m} DIFF conic_cap u0 u1 r d INTER L = {}`);
 (EXPAND_TAC "L");
 (REWRITE_TAC[SET_RULE `{a,b} = {b, a}`]);
 (MATCH_MP_TAC (SET_RULE `A SUBSET B ==> C INTER A DIFF C INTER B = {}`));
 (REWRITE_TAC[AFF_GT_SUBSET_AFF_GE]);
 (REWRITE_TAC[SET_RULE `A UNION {} = A`]);
 (EXPAND_TAC "L");
 (REWRITE_TAC[SET_RULE `{a,b} = {b, a}`]);

 (REWRITE_WITH `aff_ge {u0, u1:real^3} {m, s3} =
                 aff_gt {u0, u1} {m, s3} UNION 
   UNIONS {aff_ge {u0, u1} ({m, s3} DELETE a) | a | a IN  {m, s3}}`);
 (MATCH_MP_TAC AFF_GE_AFF_GT_DECOMP);
 (REWRITE_TAC[Geomdetail.FINITE6]);
 (REWRITE_TAC[DISJOINT]);

 (ASM_CASES_TAC `m IN {u0, u1:real^3}`);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~coplanar {u0, u1, s3, m:real^3}`);
 (REWRITE_WITH `{u0, u1, s3, m} = {u0, u1, s3:real^3}`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_TAC[COPLANAR_3]);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (ASM_CASES_TAC `s3 IN {u0, u1:real^3}`);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~coplanar {u0, u1, s3, m:real^3}`);
 (REWRITE_WITH `{u0, u1, s3, m} = {u0, u1, m:real^3}`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_TAC[COPLANAR_3]);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN SET_TAC[]);

 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC 
  `UNIONS {aff_ge {u0, u1:real^3} ({m, s3} DELETE a) | a | a IN {m, s3}}`);
 (STRIP_TAC);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC 
  `aff_ge {u0, u1:real^3} {m} UNION aff_ge {u0, u1:real^3} {s3}`);
 (STRIP_TAC);
 (MATCH_MP_TAC NEGLIGIBLE_UNION);
 (STRIP_TAC);

 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1:real^3, m}`);
 (STRIP_TAC);
 (REWRITE_TAC[NEGLIGIBLE_AFFINE_HULL_3]);
 (REWRITE_WITH `{u0,u1,m:real^3} = {u0,u1} UNION {m}`);
 (SET_TAC[]);
 (REWRITE_TAC[AFF_GE_SUBSET_AFFINE_HULL]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1:real^3, s3}`);
 (STRIP_TAC);
 (REWRITE_TAC[NEGLIGIBLE_AFFINE_HULL_3]);
 (REWRITE_WITH `{u0,u1,s3:real^3} = {u0,u1} UNION {s3}`);
 (SET_TAC[]);
 (REWRITE_TAC[AFF_GE_SUBSET_AFFINE_HULL]);
 (REWRITE_TAC[SET_RULE 
  `UNIONS {aff_ge {u0, u1} ({m, s3} DELETE a) | a | a IN {m, s3}} = 
         aff_ge {u0, u1} ({m, s3} DELETE s3) 
   UNION aff_ge {u0, u1} ({m, s3} DELETE m)`]);
 (MATCH_MP_TAC (SET_RULE 
  `A SUBSET B /\ C SUBSET D ==> A UNION C SUBSET B UNION D`));
 (STRIP_TAC);
 (MATCH_MP_TAC AFF_GE_MONO_RIGHT);
 (STRIP_TAC);
 (SET_TAC[]);

 (REWRITE_TAC[DISJOINT]);
 (ASM_CASES_TAC `m IN {u0, u1:real^3}`);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~coplanar {u0, u1, s3, m:real^3}`);
 (REWRITE_WITH `{u0, u1, s3, m} = {u0, u1, s3:real^3}`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_TAC[COPLANAR_3]);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (UP_ASM_TAC THEN SET_TAC[]);

 (MATCH_MP_TAC AFF_GE_MONO_RIGHT);
 (STRIP_TAC);
 (SET_TAC[]);
 (REWRITE_TAC[DISJOINT]);
 (ASM_CASES_TAC `s3 IN {u0, u1:real^3}`);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~coplanar {u0, u1, s3, m:real^3}`);
 (REWRITE_WITH `{u0, u1, s3, m} = {u0, u1, m:real^3}`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_TAC[COPLANAR_3]);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (UP_ASM_TAC THEN SET_TAC[]);

 (SET_TAC[]);

 (REWRITE_TAC[ASSUME `D = conic_cap (u0:real^3) u1 r d`]);
 (REWRITE_WITH `vol (conic_cap u0 u1 r d INTER wedge u0 u1 s3 m) =
             (if &1 < d \/ r < &0
              then &0
              else azim u0 u1 s3 m / &3 * (&1 - max d (-- &1)) * r pow 3)`);
 (NEW_GOAL `~collinear {u0:real^3, u1, m} /\ ~collinear {u0, u1, s3}`);
 (STRIP_TAC);
 (MATCH_MP_TAC NOT_COPLANAR_NOT_COLLINEAR);
 (EXISTS_TAC `s3:real^3`);
 (ONCE_REWRITE_TAC[SET_RULE `{a,b,c,d} = {a,b,d,c}`]);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC NOT_COPLANAR_NOT_COLLINEAR);
 (EXISTS_TAC `m:real^3`);
 (ASM_REWRITE_TAC[]);

 (ASM_SIMP_TAC[VOLUME_CONIC_CAP_WEDGE]);
 (COND_CASES_TAC);
 (NEW_GOAL `F`);

 (UNDISCH_TAC `&0 < r` THEN UNDISCH_TAC `d < &1` THEN 
   UP_ASM_TAC THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (REWRITE_WITH `azim (u0:real^3) u1 s3 m = dihV u0 u1 s3 m`);
 (MATCH_MP_TAC AZIM_DIHV_SAME);
 (ASM_REWRITE_TAC[]);
 (STRIP_TAC);

 (MATCH_MP_TAC NOT_COPLANAR_NOT_COLLINEAR);
 (EXISTS_TAC `m:real^3`);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC NOT_COPLANAR_NOT_COLLINEAR);
 (EXISTS_TAC `s3:real^3`);
 (ONCE_REWRITE_TAC[SET_RULE `{a,b,c,d} = {a,b,d,c}`]);
 (ASM_REWRITE_TAC[]);

 (REWRITE_TAC[dihX]);
 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~NULLSET (X INTER D)`);
 (REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X:real^3->bool`);
 (ASM_REWRITE_TAC[] THEN SET_TAC[]);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (LET_TAC);

 (UP_ASM_TAC THEN REWRITE_TAC[cell_params_d]);
 (ABBREV_TAC `P = (\(k, ul). k <= 4 /\
           ul IN barV V 3 /\
           X = mcell k V ul /\
           initial_sublist [u0; u1] ul)`);
 (STRIP_TAC);
 (NEW_GOAL `(P:num#(real^3)list->bool) ((@) P)`);
 (MATCH_MP_TAC SELECT_AX);
 (EXISTS_TAC `(2, vl:(real^3)list)`);
 (EXPAND_TAC "P");
 (REWRITE_TAC[BETA_THM]);
 (REWRITE_TAC[IN; ARITH_RULE `2 <= 4`] THEN ASM_REWRITE_TAC[]);
 (REWRITE_WITH `initial_sublist [u0;u1:real^3] vl /\ LENGTH [u0;u1] = 1 + 1`);
 (REWRITE_TAC[GSYM Packing3.TRUNCATE_SIMPLEX_INITIAL_SUBLIST]);
 (ASM_REWRITE_TAC[]);

 (NEW_GOAL `?v0 v1 v2 v3. vl = [v0;v1;v2;v3:real^3]`);
 (MATCH_MP_TAC Marchal_cells.BARV_3_EXPLICIT);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (ASM_REWRITE_TAC[LENGTH] THEN ARITH_TAC);
 (UP_ASM_TAC THEN ASM_REWRITE_TAC[]);
 (EXPAND_TAC "P" THEN REWRITE_TAC[IN] THEN REPEAT STRIP_TAC);

 (NEW_GOAL `k' = 2 /\ mcell k' V ul = mcell 2 V vl`);
 (MATCH_MP_TAC Ajripqn.AJRIPQN);
 (ASM_REWRITE_TAC[]);
 (REWRITE_WITH `mcell k' V ul INTER mcell 2 V vl = X`);
 (REWRITE_TAC[ASSUME `X = mcell k V vl`; GSYM (ASSUME `X = mcell k' V ul`);
   ASSUME `k = 2`]);
 (SET_TAC[]);
 (REPEAT STRIP_TAC);
 (UNDISCH_TAC `k' <= 4` THEN REWRITE_TAC[ARITH_RULE 
   `a <= 4 <=> a = 0 \/a = 1 \/ a = 2 \/ a = 3 \/ a = 4`] THEN SET_TAC[]);
 (SET_TAC[]);
 (UNDISCH_TAC `~NULLSET X` THEN UP_ASM_TAC THEN MESON_TAC[]);

 (COND_CASES_TAC);
 (REWRITE_TAC[dihu2]);
 (REWRITE_WITH `omega_list_n V ul 3 = s3`);
 (EXPAND_TAC "s3");
 (NEW_GOAL `2  = 2 /\
             (!k. 2 - 1 <= k /\ k <= 3
                  ==> omega_list_n V ul k = omega_list_n V vl k)`);
 (MATCH_MP_TAC MCELL_ID_OMEGA_LIST_N);
 (ASM_REWRITE_TAC[SET_RULE `2 IN {2,3,4}`]);
 (STRIP_TAC);
 (MESON_TAC[ASSUME `X = mcell k V vl`; ASSUME `X = mcell k' V ul`;
   ASSUME `k = 2`; ASSUME `k' = 2`]);
 (REWRITE_WITH `mcell 2 V ul = X`);
 (MESON_TAC[ASSUME `X = mcell k' V ul`; ASSUME `k' = 2`]);
 (ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (FIRST_ASSUM MATCH_MP_TAC);
 (ARITH_TAC);

 (REWRITE_WITH `mxi V ul = m`);
 (EXPAND_TAC "m");
 (MATCH_MP_TAC MCELL_ID_MXI);
 (EXISTS_TAC `2` THEN EXISTS_TAC `2`);
 (ASM_REWRITE_TAC[SET_RULE `2 IN {2,3}`]);
 (STRIP_TAC);

 (REWRITE_WITH `(HD vl):real^3 = HD (truncate_simplex 1 vl)`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC Packing3.HD_TRUNCATE_SIMPLEX);
 (REWRITE_WITH `LENGTH (vl:(real^3)list) = 3 + 1 /\ 
                 CARD (set_of_list vl) = 3 + 1`);
 (MATCH_MP_TAC Rogers.BARV_IMP_LENGTH_EQ_CARD);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (ARITH_TAC);
 (ASM_REWRITE_TAC[HD]);

 (REWRITE_WITH `(HD ul):real^3 = HD (truncate_simplex 1 ul)`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC Packing3.HD_TRUNCATE_SIMPLEX);
 (REWRITE_WITH `LENGTH (ul:(real^3)list) = 3 + 1 /\ 
                 CARD (set_of_list ul) = 3 + 1`);
 (MATCH_MP_TAC Rogers.BARV_IMP_LENGTH_EQ_CARD);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (ARITH_TAC);

 (REWRITE_WITH `truncate_simplex 1 ul = [u0;u1:real^3] /\ 1 + 1 <= LENGTH ul`);
 (REWRITE_TAC[Packing3.TRUNCATE_SIMPLEX_INITIAL_SUBLIST]);
 (ASM_REWRITE_TAC[LENGTH] THEN ARITH_TAC);
 (REWRITE_TAC[HD]);

 (STRIP_TAC);
 (MESON_TAC[ASSUME `X = mcell k V vl`; ASSUME `X = mcell k' V ul`;
   ASSUME `k = 2`; ASSUME `k' = 2`]);
 (REWRITE_WITH `mcell 2 V ul = X`);
 (MESON_TAC[ASSUME `X = mcell k' V ul`; ASSUME `k' = 2`]);
 (ASM_REWRITE_TAC[]);

 (NEW_GOAL `initial_sublist [u0; u1:real^3] ul /\ LENGTH [u0; u1] = 1 + 1`);
 (ASM_REWRITE_TAC[LENGTH] THEN ARITH_TAC);
 (NEW_GOAL `truncate_simplex 1 ul = [u0;u1:real^3] /\ 1 + 1 <= LENGTH ul`);
 (REWRITE_TAC[Packing3.TRUNCATE_SIMPLEX_INITIAL_SUBLIST]);
 (ASM_REWRITE_TAC[]);

 (REWRITE_WITH `EL 0 (ul:(real^3)list) = EL 0 (truncate_simplex 1 ul)`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC Packing3.EL_TRUNCATE_SIMPLEX);
 (REWRITE_WITH `LENGTH (ul:(real^3)list) = 3 + 1 /\ 
                 CARD (set_of_list ul) = 3 + 1`);
 (MATCH_MP_TAC Rogers.BARV_IMP_LENGTH_EQ_CARD);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (ARITH_TAC);

 (REWRITE_WITH `EL 1 (ul:(real^3)list) = EL 1 (truncate_simplex 1 ul)`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC Packing3.EL_TRUNCATE_SIMPLEX);
 (REWRITE_WITH `LENGTH (ul:(real^3)list) = 3 + 1 /\ 
                 CARD (set_of_list ul) = 3 + 1`);
 (MATCH_MP_TAC Rogers.BARV_IMP_LENGTH_EQ_CARD);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (ARITH_TAC);
 (ASM_REWRITE_TAC[EL; HD; ARITH_RULE `1 = SUC 0`; TL]);
 (REWRITE_TAC[DIHV_SYM_2]);
 (REWRITE_TAC[ARITH_RULE `SUC 0 = 1`]);

 (REWRITE_TAC[REAL_ARITH `a / b * c * d pow 3 = (c/ b * d pow 3) * a`]);
 (REWRITE_TAC[REAL_ARITH `a * b / (&2 * c) = (a / (&2 * c)) * b`]);
 (AP_THM_TAC THEN AP_TERM_TAC);
 (REWRITE_WITH 
  `measurable (conic_cap u0 u1 r d) /\
             vol (conic_cap u0 u1 r d) =
             (if u1 = u0 \/ &1 <= d \/ r < &0
              then &0
              else &2 / &3 * pi * (&1 - d) * r pow 3)`);
 (MATCH_MP_TAC VOLUME_CONIC_CAP);
 (EXPAND_TAC "d");
 (UNDISCH_TAC `&0 < c /\ c < &1` THEN REAL_ARITH_TAC);
 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (UP_ASM_TAC THEN STRIP_TAC);
 (UP_ASM_TAC THEN ASM_REWRITE_TAC[]);

 (UP_ASM_TAC THEN UNDISCH_TAC `d < &1` THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN UNDISCH_TAC `&0 < r` THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (REWRITE_WITH `max d (--(&1)) = d`);
 (MATCH_MP_TAC (REAL_ARITH `&0 < d ==> max d (--(&1)) = d`));
 (EXPAND_TAC "d");
 (UNDISCH_TAC `&0 < c /\ c < &1` THEN REAL_ARITH_TAC);
 (REWRITE_WITH `
  (&2 / &3 * pi * (&1 - d) * r pow 3) / (&2 * pi) = (&1 - d) / &3 * r pow 3 *   
  ((&2 * pi) / (&2 * pi))`);
 (REAL_ARITH_TAC);
 (REWRITE_WITH `(&2 * pi) / (&2 * pi) = &1`);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (REWRITE_TAC[REAL_ENTIRE; PI_NZ; REAL_ARITH `~(&2 = &0)`]);
 (REAL_ARITH_TAC);
 (NEW_GOAL `F`);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN MESON_TAC[]);
 (UP_ASM_TAC THEN MESON_TAC[]);

(* ========================================================================== *)

 (NEW_GOAL `F`);
 (NEW_GOAL `azim (u0:real^3) u1 s3 m = 
  (if azim u0 u1 m s3 = &0 then &0 else &2 * pi - azim u0 u1 m s3)`);
 (MATCH_MP_TAC AZIM_COMPL);
 (STRIP_TAC);

 (MATCH_MP_TAC NOT_COPLANAR_NOT_COLLINEAR);
 (EXISTS_TAC `s3:real^3`);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC NOT_COPLANAR_NOT_COLLINEAR);
 (EXISTS_TAC `m:real^3`);
 (ONCE_REWRITE_TAC[SET_RULE `{a,b,c,d} = {a,b, d, c}`]);
 (ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN COND_CASES_TAC);
 (NEW_GOAL `F`);
 (NEW_GOAL `(&0 < pi)`);
 (REWRITE_TAC[PI_POS]);
 (UNDISCH_TAC `~(azim (u0:real^3) u1 m s3 < pi)`);
 (ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (STRIP_TAC);

 (NEW_GOAL `azim (u0:real^3) u1 m s3 = pi`);
 (UP_ASM_TAC THEN DEL_TAC THEN UP_ASM_TAC THEN UP_ASM_TAC THEN REAL_ARITH_TAC);
 (UNDISCH_TAC `~coplanar {u0, u1, m, s3:real^3}`);
 (REWRITE_TAC[] THEN MATCH_MP_TAC AZIM_EQ_0_PI_IMP_COPLANAR);
 (ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN MESON_TAC[]);


(* ========================================================================= *)
(*  Case k >= 4                                                              *)
(* ========================================================================= *)

 (ASM_CASES_TAC `k >= 4`);
 (NEW_GOAL `?u2 u3. vl = [u0; u1;u2;u3:real^3]`);
 (NEW_GOAL `?v0 v1 u2 u3. vl = [v0; v1;u2;u3:real^3]`);
 (MATCH_MP_TAC BARV_3_EXPLICIT);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (EXISTS_TAC `u2:real^3` THEN EXISTS_TAC `u3:real^3`);

 (REWRITE_WITH `u0 = v0:real^3`);
 (REWRITE_WITH `v0:real^3 = HD (truncate_simplex 1 vl)`);
 (REWRITE_TAC[ASSUME `vl = [v0;v1;u2;u3:real^3]`; 
   TRUNCATE_SIMPLEX_EXPLICIT_1; HD]);
 (ASM_REWRITE_TAC[TRUNCATE_SIMPLEX_EXPLICIT_1; HD]);

 (REWRITE_WITH `u1 = v1:real^3`);
 (REWRITE_WITH `v1:real^3 = HD (TL (truncate_simplex 1 vl))`);
 (REWRITE_TAC[ASSUME `vl = [v0;v1;u2;u3:real^3]`; 
   TRUNCATE_SIMPLEX_EXPLICIT_1; HD; TL]);
 (ASM_REWRITE_TAC[TRUNCATE_SIMPLEX_EXPLICIT_1; HD; TL]);
 (ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);

 (ABBREV_TAC `L = aff_ge{u0, u1} {u2, u3:real^3}`);

 (REWRITE_WITH `vol (X INTER D) = vol (L INTER D)`);
 (AP_TERM_TAC);
 (ASM_SIMP_TAC[MCELL_EXPLICIT; mcell4; ARITH_RULE `4 >= 4`;set_of_list]);
 (COND_CASES_TAC);

 (EXPAND_TAC "L");
 (REWRITE_TAC[SET_RULE `A = B <=> A SUBSET B /\ B SUBSET A`]);
 (STRIP_TAC);
 (MATCH_MP_TAC (SET_RULE `A SUBSET B ==> A INTER X SUBSET B INTER X`));
 (REWRITE_TAC[Marchal_cells_2.CONVEX_HULL_4_SUBSET_AFF_GE_2_2]);
 (MATCH_MP_TAC (SET_RULE `(!x. x IN A /\ x IN B ==> x IN C) ==>
                            A INTER B SUBSET C INTER B`));
 (NEW_GOAL `DISJOINT {u0,u1:real^3} {u2, u3}`);
 (REWRITE_TAC[DISJOINT]);
 (MATCH_MP_TAC (MESON[] `(~A:bool ==> F) ==> A`));
 (STRIP_TAC);
 (UNDISCH_TAC `~NULLSET (X INTER D)` THEN REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X:real^3->bool` THEN REWRITE_TAC[SET_RULE `A INTER X SUBSET A`]);
 (ASM_SIMP_TAC[MCELL_EXPLICIT; mcell4; set_of_list]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1, u2, u3:real^3}`);
 (REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (MATCH_MP_TAC COPLANAR_IMP_NEGLIGIBLE);
 (REWRITE_TAC[COPLANAR_AFFINE_HULL_COPLANAR]);
 (ASM_CASES_TAC `u2 IN {u0, u1:real^3}`);
 (REWRITE_WITH `{u0, u1, u2, u3} = {u0, u1, u3:real^3}`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_TAC[COPLANAR_3]);
 (NEW_GOAL `u3 IN {u0, u1:real^3}`);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_WITH `{u0, u1, u2, u3} = {u0, u1, u2:real^3}`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_TAC[COPLANAR_3]);

 (SIMP_TAC[ASSUME `DISJOINT {u0, u1} {u2, u3:real^3}`; AFF_GE_2_2]);
 (REWRITE_TAC[CONVEX_HULL_4; IN; IN_ELIM_THM]);
 (REPEAT STRIP_TAC);
 (EXISTS_TAC `t1:real` THEN EXISTS_TAC `t2:real` THEN 
   EXISTS_TAC `t3:real` THEN EXISTS_TAC `t4:real`);
 (ASM_REWRITE_TAC[]);
 (STRIP_TAC);

 (REWRITE_TAC[REAL_ARITH `&0 <= a <=> (a < &0 ==> F)`]);
 (STRIP_TAC);
 (UNDISCH_TAC `conic_cap (u0:real^3) u1 r d x`);
 (REWRITE_TAC[MESON[IN] `conic_cap u0 u1 r d x <=> x IN conic_cap u0 u1 r d`;
   GSYM (ASSUME `D = conic_cap (u0:real^3) u1 r d`)]);
 (EXPAND_TAC "D");
 (REWRITE_TAC[IN_INTER; MESON[] `~(x:bool /\ y) <=> (~x \/ ~y)`]);
 (DISJ1_TAC);
 (REWRITE_TAC[IN_BALL] THEN STRIP_TAC);

 (NEW_GOAL `(?b1:real. b1 IN P2 /\ (!x. x IN P2 ==> b1 <= x))`);
 (FIRST_ASSUM MATCH_MP_TAC);
 (REWRITE_TAC[SET_RULE `~(X = {}) <=> (?x. x IN X)`]);
 (EXISTS_TAC `(f2:(real^3)list -> real) vl`);
 (EXPAND_TAC "P2" THEN REWRITE_TAC[IN; IN_ELIM_THM]);
 (EXISTS_TAC `vl:(real^3)list`);
 (ASM_REWRITE_TAC[]);
 (REWRITE_WITH `mcell 4 V [u0; u1; u2; u3] = X`);
 (ASM_SIMP_TAC[MCELL_EXPLICIT; ARITH_RULE `4 >= 4`]);
 (STRIP_TAC);
 (UNDISCH_TAC `~NULLSET (X INTER D)` THEN REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X INTER (C:real^3->bool)`);
 (STRIP_TAC);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC (SET_RULE `D SUBSET C ==> X INTER D SUBSET X INTER C`));
 (EXPAND_TAC "D" THEN EXPAND_TAC "C");
 (MATCH_MP_TAC (SET_RULE 
  `A SUBSET B /\ C SUBSET D ==> A INTER C SUBSET B INTER D`));
 (STRIP_TAC);
 (MATCH_MP_TAC SUBSET_BALL);
 (EXPAND_TAC "r" THEN REAL_ARITH_TAC);
 (MATCH_MP_TAC RCONE_GT_SUBSET);
 (EXPAND_TAC "d" THEN REAL_ARITH_TAC);
 (FIRST_X_ASSUM CHOOSE_TAC);

 (NEW_GOAL `r2 = (@b. b IN P2 /\ (!x. x IN P2 ==> b <= x:real))`);
 (EXPAND_TAC "r2");
 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (UP_ASM_TAC THEN REWRITE_TAC[]);
 (REWRITE_TAC[SET_RULE `~(X = {}) <=> (?x. x IN X)`]);
 (EXISTS_TAC `(f2:(real^3)list -> real) vl`);
 (EXPAND_TAC "P2" THEN REWRITE_TAC[IN; IN_ELIM_THM]);
 (EXISTS_TAC `vl:(real^3)list`);
 (ASM_REWRITE_TAC[]);
 (REWRITE_WITH `mcell 4 V [u0; u1; u2; u3] = X`);
 (ASM_SIMP_TAC[MCELL_EXPLICIT; ARITH_RULE `4 >= 4`]);
 (STRIP_TAC);
 (UNDISCH_TAC `~NULLSET (X INTER D)` THEN REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X INTER (C:real^3->bool)`);
 (STRIP_TAC);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC (SET_RULE `D SUBSET C ==> X INTER D SUBSET X INTER C`));
 (EXPAND_TAC "D" THEN EXPAND_TAC "C");
 (MATCH_MP_TAC (SET_RULE 
  `A SUBSET B /\ C SUBSET D ==> A INTER C SUBSET B INTER D`));
 (STRIP_TAC);
 (MATCH_MP_TAC SUBSET_BALL);
 (EXPAND_TAC "r" THEN REAL_ARITH_TAC);
 (MATCH_MP_TAC RCONE_GT_SUBSET);
 (EXPAND_TAC "d" THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (REWRITE_TAC[]);

 (ABBREV_TAC `Q1 = (\b:real. b IN P2 /\ (!x. x IN P2 ==> b <= x))`);
 (NEW_GOAL `(Q1:real->bool) r2`);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC SELECT_AX);
 (EXISTS_TAC `b1:real` THEN EXPAND_TAC "Q1");
 (ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN EXPAND_TAC "Q1" THEN REPEAT STRIP_TAC);
 (NEW_GOAL `r2 <= f2 (vl:(real^3)list)`);
 (FIRST_ASSUM MATCH_MP_TAC);
 (EXPAND_TAC "P2" THEN REWRITE_TAC[IN; IN_ELIM_THM]);
 (EXISTS_TAC `vl:(real^3)list`);
 (ASM_REWRITE_TAC[]);
 (REWRITE_WITH `mcell 4 V [u0; u1; u2; u3] = X`);
 (ASM_SIMP_TAC[MCELL_EXPLICIT; ARITH_RULE `4 >= 4`]);
 (STRIP_TAC);
 (UNDISCH_TAC `~NULLSET (X INTER D)` THEN REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X INTER (C:real^3->bool)`);
 (STRIP_TAC);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC (SET_RULE `D SUBSET C ==> X INTER D SUBSET X INTER C`));
 (EXPAND_TAC "D" THEN EXPAND_TAC "C");
 (MATCH_MP_TAC (SET_RULE 
  `A SUBSET B /\ C SUBSET D ==> A INTER C SUBSET B INTER D`));
 (STRIP_TAC);
 (MATCH_MP_TAC SUBSET_BALL);
 (EXPAND_TAC "r" THEN REAL_ARITH_TAC);
 (MATCH_MP_TAC RCONE_GT_SUBSET);
 (EXPAND_TAC "d" THEN REAL_ARITH_TAC);

 (UP_ASM_TAC THEN EXPAND_TAC "f2" THEN REWRITE_TAC[EL; HD; TL; 
   ARITH_RULE `3 = SUC 2 /\ 2 = SUC 1 /\ 1 = SUC 0`; 
   ASSUME `vl= [u0; u1; u2; u3:real^3]`] THEN STRIP_TAC);
 (NEW_GOAL `!v. v IN affine hull {u1, u2, u3:real^3} ==> r2 <= dist (u0, v)`);
 (REPEAT STRIP_TAC);
 (NEW_GOAL `dist (u0,closest_point (affine hull {u1, u2, u3}) u0) <= 
             dist (u0, v:real^3)`);
 (MATCH_MP_TAC CLOSEST_POINT_LE);
 (ASM_REWRITE_TAC[CLOSED_AFFINE_HULL]);
 (UP_ASM_TAC THEN DEL_TAC THEN UP_ASM_TAC THEN REAL_ARITH_TAC);

 (NEW_GOAL `r <= dist (u0:real^3, x)`);
 (REWRITE_TAC[dist]);
 (REWRITE_WITH `u0:real^3 - x = (t1 + t2 + t3 + t4) % u0 - x`);
 (ASM_REWRITE_TAC[] THEN VECTOR_ARITH_TAC);
 (REWRITE_TAC[VECTOR_ADD_RDISTRIB]);
 (ASM_REWRITE_TAC[VECTOR_ARITH `(t1 % u0 + t2 % u0 + t3 % u0 + t4 % u0) -
  (t1 % u0 + t2 % u1 + t3 % u2 + t4 % u3) = 
  (t2 + t3 + t4) % u0 - (t2 % u1 + t3 % u2 + t4 % u3)`]);
 (ABBREV_TAC `y:real^3 = t2 /(t2 + t3 + t4) % u1 + 
                          t3 /(t2 + t3 + t4) % u2 + 
                          t4 /(t2 + t3 + t4) % u3`);
 (REWRITE_WITH `(t2 % u1 + t3 % u2 + t4 % u3) = (t2 + t3 + t4) % (y:real^3)`);
 (EXPAND_TAC "y");
 (REWRITE_TAC[VECTOR_ARITH `x % (t2 / x % u1 +  t3 / x % u2 + t4 / x % u3) = 
   (x / x) % (t2 % u1 + t3 % u2 + t4 % u3)`]);
 (REWRITE_WITH `(t2 + t3 + t4) / (t2 + t3 + t4) = &1`);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (UNDISCH_TAC `t1 < &0` THEN UNDISCH_TAC `t1 + t2 + t3 + t4 = &1`);
 (REAL_ARITH_TAC);
 (VECTOR_ARITH_TAC);
 (REWRITE_TAC[VECTOR_ARITH `a % x - a % y = a % (x - y)`; NORM_MUL]);

 (NEW_GOAL `&1 < t2 + t3 + t4`);
 (UNDISCH_TAC `t1 < &0` THEN UNDISCH_TAC `t1 + t2 + t3 + t4 = &1`);
 (REAL_ARITH_TAC);
 (REWRITE_WITH `abs (t2 + t3 + t4) = t2 + t3 + t4`); 
 (REWRITE_TAC[REAL_ABS_REFL] THEN UP_ASM_TAC THEN REAL_ARITH_TAC);
 (REWRITE_TAC[GSYM dist]);
 (NEW_GOAL `r2 <= dist (u0, y:real^3)`);
 (FIRST_ASSUM MATCH_MP_TAC);
 (REWRITE_TAC[AFFINE_HULL_3; IN; IN_ELIM_THM]);
 (EXISTS_TAC `t2 / (t2 + t3 + t4)` THEN EXISTS_TAC `t3 / (t2 + t3 + t4)` THEN
   EXISTS_TAC `t4 / (t2 + t3 + t4)`);
 (STRIP_TAC);
 (REWRITE_TAC[REAL_ARITH `a / x + b / x + c / x = (a+b+c)/ x`]);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (UP_ASM_TAC THEN REAL_ARITH_TAC);
 (ASM_REWRITE_TAC[]);

 (NEW_GOAL `r2 <= (t2 + t3 + t4) * dist (u0,y:real^3)`);
 (NEW_GOAL `dist (u0,y) <= (t2 + t3 + t4) * dist (u0,y:real^3)`);
 (REWRITE_TAC[REAL_ARITH `a <= b * a <=> &0 <= (b - &1) * a`]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (REWRITE_TAC[DIST_POS_LE]);
 (DEL_TAC THEN UP_ASM_TAC THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN REAL_ARITH_TAC);
 (EXPAND_TAC "r" THEN UP_ASM_TAC THEN REAL_ARITH_TAC);
 (UNDISCH_TAC `dist (u0, x:real^3) < r` THEN UP_ASM_TAC THEN REAL_ARITH_TAC);

(* ========================================================================== *)


 (REWRITE_TAC[REAL_ARITH `&0 <= a <=> (a < &0 ==> F)`]);
 (STRIP_TAC);
 (UNDISCH_TAC `conic_cap (u0:real^3) u1 r d x`);
 (REWRITE_TAC[MESON[IN] `conic_cap u0 u1 r d x <=> x IN conic_cap u0 u1 r d`;
   GSYM (ASSUME `D = conic_cap (u0:real^3) u1 r d`)]);
 (EXPAND_TAC "D");
 (REWRITE_TAC[IN_INTER; MESON[] `~(x:bool /\ y) <=> (~x \/ ~y)`]);
 (DISJ2_TAC);
 (REWRITE_TAC[IN; IN_ELIM_THM; rcone_gt; rconesgn] THEN STRIP_TAC);

 (NEW_GOAL `(?b1:real. b1 IN P4 /\ (!x. x IN P4 ==> x <= b1))`);
 (FIRST_ASSUM MATCH_MP_TAC);
 (REWRITE_TAC[SET_RULE `~(X = {}) <=> (?x. x IN X)`]);
 (EXISTS_TAC `(f4:(real^3)list -> real) vl`);
 (EXPAND_TAC "P4" THEN REWRITE_TAC[IN; IN_ELIM_THM]);
 (EXISTS_TAC `vl:(real^3)list`);
 (ASM_REWRITE_TAC[]);
 (REWRITE_WITH `mcell 4 V [u0; u1; u2; u3] = X`);
 (ASM_SIMP_TAC[MCELL_EXPLICIT; ARITH_RULE `4 >= 4`]);
 (STRIP_TAC);
 (UNDISCH_TAC `~NULLSET (X INTER D)` THEN REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X INTER (C:real^3->bool)`);
 (STRIP_TAC);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC (SET_RULE `D SUBSET C ==> X INTER D SUBSET X INTER C`));
 (EXPAND_TAC "D" THEN EXPAND_TAC "C");
 (MATCH_MP_TAC (SET_RULE 
  `A SUBSET B /\ C SUBSET D ==> A INTER C SUBSET B INTER D`));
 (STRIP_TAC);
 (MATCH_MP_TAC SUBSET_BALL);
 (EXPAND_TAC "r" THEN REAL_ARITH_TAC);
 (MATCH_MP_TAC RCONE_GT_SUBSET);
 (EXPAND_TAC "d" THEN REAL_ARITH_TAC);
 (FIRST_X_ASSUM CHOOSE_TAC);

 (NEW_GOAL `d2 = (@b. b IN P4 /\ (!x. x IN P4 ==> x <= b:real))`);
 (EXPAND_TAC "d2");
 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (UP_ASM_TAC THEN REWRITE_TAC[]);
 (REWRITE_TAC[SET_RULE `~(X = {}) <=> (?x. x IN X)`]);
 (EXISTS_TAC `(f4:(real^3)list -> real) vl`);
 (EXPAND_TAC "P4" THEN REWRITE_TAC[IN; IN_ELIM_THM]);
 (EXISTS_TAC `vl:(real^3)list`);
 (ASM_REWRITE_TAC[]);
 (REWRITE_WITH `mcell 4 V [u0; u1; u2; u3] = X`);
 (ASM_SIMP_TAC[MCELL_EXPLICIT; ARITH_RULE `4 >= 4`]);
 (STRIP_TAC);
 (UNDISCH_TAC `~NULLSET (X INTER D)` THEN REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X INTER (C:real^3->bool)`);
 (STRIP_TAC);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC (SET_RULE `D SUBSET C ==> X INTER D SUBSET X INTER C`));
 (EXPAND_TAC "D" THEN EXPAND_TAC "C");
 (MATCH_MP_TAC (SET_RULE 
  `A SUBSET B /\ C SUBSET D ==> A INTER C SUBSET B INTER D`));
 (STRIP_TAC);
 (MATCH_MP_TAC SUBSET_BALL);
 (EXPAND_TAC "r" THEN REAL_ARITH_TAC);
 (MATCH_MP_TAC RCONE_GT_SUBSET);
 (EXPAND_TAC "d" THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (REWRITE_TAC[]);

 (ABBREV_TAC `Q1 = (\b:real. b IN P4 /\ (!x. x IN P4 ==> x <= b))`);
 (NEW_GOAL `(Q1:real->bool) d2`);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC SELECT_AX);
 (EXISTS_TAC `b1:real` THEN EXPAND_TAC "Q1");
 (ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN EXPAND_TAC "Q1" THEN REPEAT STRIP_TAC);

 (NEW_GOAL `f4 (vl:(real^3)list) <= d2`);
 (FIRST_ASSUM MATCH_MP_TAC);
 (EXPAND_TAC "P4" THEN REWRITE_TAC[IN; IN_ELIM_THM]);
 (EXISTS_TAC `vl:(real^3)list`);
 (ASM_REWRITE_TAC[]);
 (REWRITE_WITH `mcell 4 V [u0; u1; u2; u3] = X`);
 (ASM_SIMP_TAC[MCELL_EXPLICIT; ARITH_RULE `4 >= 4`]);
 (STRIP_TAC);
 (UNDISCH_TAC `~NULLSET (X INTER D)` THEN REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X INTER (C:real^3->bool)`);
 (STRIP_TAC);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC (SET_RULE `D SUBSET C ==> X INTER D SUBSET X INTER C`));
 (EXPAND_TAC "D" THEN EXPAND_TAC "C");
 (MATCH_MP_TAC (SET_RULE 
  `A SUBSET B /\ C SUBSET D ==> A INTER C SUBSET B INTER D`));
 (STRIP_TAC);
 (MATCH_MP_TAC SUBSET_BALL);
 (EXPAND_TAC "r" THEN REAL_ARITH_TAC);
 (MATCH_MP_TAC RCONE_GT_SUBSET);
 (EXPAND_TAC "d" THEN REAL_ARITH_TAC);

 (UP_ASM_TAC THEN EXPAND_TAC "f4");
 (REWRITE_TAC[EL; HD; TL; 
   ARITH_RULE `3 = SUC 2 /\ 2 = SUC 1 /\ 1 = SUC 0`; 
   ASSUME `vl= [u0; u1; u2; u3:real^3]`] THEN STRIP_TAC);
 (ABBREV_TAC `xx = smallest_angle_line u2 u3 u0 u1`);

 (MP_TAC (ASSUME `smallest_angle_line u2 u3 u0 u1 = xx`));
 (REWRITE_TAC[smallest_angle_line; smallest_angle_set]);
 (ABBREV_TAC `Q2 = 
 (\x:real^3. x IN convex hull {u2, u3} /\
             (!y. y IN convex hull {u2, u3}
                  ==> ((y - u0) dot (u1 - u0)) /
                      (norm (y - u0) * norm (u1 - u0)) <=
                      ((x - u0) dot (u1 - u0)) /
                      (norm (x - u0) * norm (u1 - u0))))`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ] THEN STRIP_TAC);
 (NEW_GOAL `(Q2:real^3->bool) xx`);
 (ONCE_ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC SELECT_AX);
 (EXPAND_TAC "Q2");

 (MATCH_MP_TAC SMALLEST_ANGLE_LINE_EXISTS);
 (STRIP_TAC);
 (ASM_REWRITE_TAC[]);
 (STRIP_TAC);

 (UNDISCH_TAC `~NULLSET (X INTER D)`);
 (REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X:real^3->bool` THEN STRIP_TAC);
 (ASM_SIMP_TAC[MCELL_EXPLICIT; mcell4; set_of_list;ARITH_RULE `4 >= 4`]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);

 (EXISTS_TAC `affine hull {u0, u1, u2, u3:real^3}`);
 (STRIP_TAC);
 (MATCH_MP_TAC COPLANAR_IMP_NEGLIGIBLE);
 (REWRITE_TAC[COPLANAR_AFFINE_HULL_COPLANAR]);
 (REWRITE_TAC[coplanar]);
 (UNDISCH_TAC `u0 IN convex hull {u2, u3:real^3}`);
 (REWRITE_TAC[CONVEX_HULL_2; IN; IN_ELIM_THM] THEN STRIP_TAC);
 (EXISTS_TAC `u1:real^3` THEN EXISTS_TAC `u2:real^3` THEN 
   EXISTS_TAC `u3:real^3`);
 (MATCH_MP_TAC (SET_RULE `a IN s /\ b SUBSET s ==> (a INSERT b) SUBSET s`));
 (REWRITE_TAC[SET_SUBSET_AFFINE_HULL]);
 (REWRITE_TAC[AFFINE_HULL_3; IN; IN_ELIM_THM]);
 (EXISTS_TAC `&0` THEN EXISTS_TAC `u:real` THEN EXISTS_TAC `v:real`);
 (STRIP_TAC);
 (UNDISCH_TAC `u + v = &1` THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN VECTOR_ARITH_TAC);
 (ASM_REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);
 (SET_TAC[]);

 (UP_ASM_TAC THEN EXPAND_TAC "Q2");
 (STRIP_TAC);
 (ABBREV_TAC `g = (\y:real^3. ((y - u0) dot (u1 - u0)) / 
                               (norm (y - u0) * norm (u1 - u0)))`);

 (NEW_GOAL `d < (g:real^3->real) x`);
 (EXPAND_TAC "g");
 (REWRITE_WITH 
  `d < ((x - u0) dot (u1 - u0)) / (norm (x - u0) * norm (u1 - u0:real^3)) <=>
   d * (norm (x - u0) * norm (u1 - u0)) < (x - u0) dot (u1 - u0)`);
 (MATCH_MP_TAC REAL_LT_RDIV_EQ);
 (MATCH_MP_TAC (REAL_ARITH `&0 <= a /\ ~(a = &0) ==> &0 < a`));
 (STRIP_TAC);
 (MATCH_MP_TAC REAL_LE_MUL);
 (ASM_REWRITE_TAC[NORM_POS_LE]);
 (REWRITE_TAC[REAL_ENTIRE; NORM_EQ_0; VECTOR_ARITH `x - y = vec 0 <=> x = y`]);
 (ASM_REWRITE_TAC[]);
 (REWRITE_WITH `t1 % u0 + t2 % u1 + t3 % u2 + t4 % u3 = u0:real^3 <=>
  t1 % u0 + t2 % u1 + t3 % u2 + t4 % u3 = (t1 + t2 + t3 + t4) % u0`);
 (ASM_REWRITE_TAC[] THEN VECTOR_ARITH_TAC);
 (REWRITE_TAC[VECTOR_ARITH `t1 % u0 + u = (t1 + t2) % u0 <=> u = t2 % u0`]);
 (STRIP_TAC);

 (MP_TAC (ASSUME `~NULLSET (X INTER D)`) THEN REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X:real^3->bool` THEN STRIP_TAC);
 (ASM_SIMP_TAC[MCELL_EXPLICIT; mcell4;set_of_list]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1, u2, u3:real^3}`);
 (REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (MATCH_MP_TAC COPLANAR_IMP_NEGLIGIBLE);
 (REWRITE_TAC[COPLANAR_AFFINE_HULL_COPLANAR]);
 (MATCH_MP_TAC Rogers.AFF_DIM_LE_2_IMP_COPLANAR);
 (MATCH_MP_TAC Njiutiu.AFF_DEPENDENT_AFF_DIM_4);
 (REWRITE_TAC[affine_dependent]);
 (EXISTS_TAC `u1:real^3`);
 (STRIP_TAC);
 (SET_TAC[]);

 (NEW_GOAL `~(u1 IN {u0, u2, u3:real^3})`);
 (STRIP_TAC);
 (MP_TAC (ASSUME `~NULLSET (X INTER D)`) THEN REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X:real^3->bool` THEN STRIP_TAC);
 (ASM_SIMP_TAC[MCELL_EXPLICIT; mcell4;set_of_list]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1, u2, u3:real^3}`);
 (REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (MATCH_MP_TAC COPLANAR_IMP_NEGLIGIBLE);
 (REWRITE_TAC[COPLANAR_AFFINE_HULL_COPLANAR]);
 (REWRITE_WITH `{u0, u1, u2, u3} = {u0:real^3,u2, u3}`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_TAC[COPLANAR_3]);
 (SET_TAC[]);
 (REWRITE_WITH `{u0, u1, u2, u3} DELETE u1 = {u0, u2, u3:real^3}`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_TAC[AFFINE_HULL_3; IN; IN_ELIM_THM]);
 (EXISTS_TAC `(t2 + t3 + t4) / t2`);
 (EXISTS_TAC `(-- t3) / t2`);
 (EXISTS_TAC `(-- t4) / t2`);

 (STRIP_TAC);
 (REWRITE_WITH `(t2 + t3 + t4) / t2 + --t3 / t2 + --t4 / t2 = t2 / t2`);
 (REAL_ARITH_TAC);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (UNDISCH_TAC `t2 < &0` THEN REAL_ARITH_TAC);
 (REWRITE_WITH 
  `u1 = (t2 + t3 + t4) / t2 % u0 + --t3 / t2 % u2 + --t4 / t2 % u3:real^3 <=> 
   u1 = (&1 / t2) % ((t2 + t3 + t4) % u0 - t3 % u2 - t4 % u3)`);
 (VECTOR_ARITH_TAC);
 (REWRITE_TAC[GSYM (ASSUME `t2 % u1 + t3 % u2 + t4 % u3 = 
                             (t2 + t3 + t4) % u0:real^3`)]);
 (REWRITE_TAC[VECTOR_ARITH 
  `(t2 % u1 + t3 % u2 + t4 % u3) - t3 % u2 - t4 % u3 = t2 % u1`]);
 (REWRITE_TAC[VECTOR_MUL_ASSOC]);
 (REWRITE_WITH `&1 / t2 * t2 = &1`);
 (REWRITE_TAC[REAL_ARITH `&1 / t2 * t2 = t2 / t2`]);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (UNDISCH_TAC `t2 < &0` THEN REAL_ARITH_TAC);
 (VECTOR_ARITH_TAC);
 (SET_TAC[]);
 (REWRITE_TAC[REAL_ARITH `a * b * c < d <=> d > b * c * a`; GSYM dist]);
 (ASM_REWRITE_TAC[]);

 (NEW_GOAL `g x <= (g:real^3->real) xx`);
 (NEW_GOAL `!y. y IN convex hull {u2 , u3:real^3} ==> g y <= g xx`);
 (EXPAND_TAC "g" THEN ASM_REWRITE_TAC[]);
 (NEW_GOAL `&0 < (t3 + t4)`);
 (MATCH_MP_TAC (REAL_ARITH `(&0 <= x) /\ ~(x = &0)  ==> &0 < x`));
 (STRIP_TAC);
 (MATCH_MP_TAC REAL_LE_ADD);
 (ASM_REWRITE_TAC[]);
 (STRIP_TAC);
 (NEW_GOAL `t3 = &0 /\ t4 = &0`);
 (UNDISCH_TAC `&0 <= t3` THEN UNDISCH_TAC `&0 <= t4` THEN 
   UP_ASM_TAC THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN STRIP_TAC);

 (NEW_GOAL `F`);
 (UNDISCH_TAC `(x - u0) dot (u1 - u0:real^3) > dist (x,u0) * dist (u1,u0) * d`);
 (REWRITE_WITH `x = t1 % u0 + t2 % u1:real^3`);
 (ASM_REWRITE_TAC[] THEN VECTOR_ARITH_TAC);
 (MATCH_MP_TAC (REAL_ARITH `a <= &0 /\ &0 <= b ==> ~(a > b)`));
 (STRIP_TAC);
 (REWRITE_WITH `(t1 % u0 + t2 % u1) - u0 = (t1 % u0 + t2 % u1) - 
                 (t1 + t2 + t3 + t4) % u0:real^3`);
 (ASM_REWRITE_TAC[] THEN VECTOR_ARITH_TAC);
 (REWRITE_TAC[ASSUME `t3 = &0`; ASSUME `t4 = &0`; VECTOR_ARITH 
  `(t1 % u0 + t2 % u1) - (t1 + t2 + &0 + &0) % u0 = t2 % (u1 - u0)`; 
   DOT_LMUL; REAL_ARITH `a * b <= &0 <=> &0 <= (--a) * b`]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (REWRITE_TAC[DOT_POS_LE]);
 (UNDISCH_TAC `t2 < &0` THEN REAL_ARITH_TAC);
 (MATCH_MP_TAC REAL_LE_MUL);
 (REWRITE_TAC[DIST_POS_LE]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (REWRITE_TAC[DIST_POS_LE]);
 (EXPAND_TAC "d" THEN UNDISCH_TAC `&0 < c/\ c < &1`);
 (REAL_ARITH_TAC);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (ABBREV_TAC `y = t3 / (t3 + t4) % u2 + t4 / (t3 + t4) % u3:real^3`);
 (NEW_GOAL `(g:real^3->real) y <= g xx`);
 (FIRST_ASSUM MATCH_MP_TAC);
 (REWRITE_TAC[CONVEX_HULL_2; IN; IN_ELIM_THM]);
 (EXISTS_TAC `t3 / (t3 + t4)` THEN EXISTS_TAC `t4 / (t3 + t4)`);
 (REPEAT STRIP_TAC);
 (MATCH_MP_TAC REAL_LE_DIV);
 (ASM_SIMP_TAC[REAL_LE_ADD]);
 (ASM_SIMP_TAC[REAL_LE_ADD; REAL_LE_DIV]);
 (REWRITE_TAC[REAL_ARITH `a / x + b / x = (a + b) / x`]);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (UNDISCH_TAC `&0 < t3 + t4` THEN REAL_ARITH_TAC);
 (ASM_REWRITE_TAC[]);

 (ABBREV_TAC `w = t1 / (t1 + t3 + t4) % u0 + t3 / (t1 + t3 + t4) % u2 + 
                   t4 / (t1 + t3 + t4) % u3:real^3`);
 (NEW_GOAL `(g:real^3->real) y = g w`);
 (EXPAND_TAC "g");

 (REWRITE_WITH `y:real^3 - u0 = 
                &1 / (t3 + t4) % (t3 % u2 + t4 % u3 - (t3 + t4) % u0)`);
 (EXPAND_TAC "y");
 (REWRITE_TAC[VECTOR_ARITH 
  `(t3 / (t3 + t4) % u2 + t4 / (t3 + t4) % u3) - u0 =
   &1 / (t3 + t4) % (t3 % u2 + t4 % u3 - (t3 + t4) % u0) <=> 
   (t3 + t4) / (t3 + t4) % u0 = u0`]);
 (REWRITE_WITH `(t3 + t4) / (t3 + t4) = &1`);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (UNDISCH_TAC `&0 < t3 + t4` THEN REAL_ARITH_TAC);
 (VECTOR_ARITH_TAC);
 (REWRITE_TAC[NORM_MUL; DOT_LMUL]);

 (REWRITE_WITH `w:real^3 - u0 = 
                &1 / (t1 + t3 + t4) % (t3 % u2 + t4 % u3 - (t3 + t4) % u0)`);
 (EXPAND_TAC "w");
 (REWRITE_TAC[VECTOR_ARITH 
   `(t1 / (t1 + t3 + t4) % u0 +
    t3 / (t1 + t3 + t4) % u2 + t4 / (t1 + t3 + t4) % u3) - u0 =
    &1 / (t1 + t3 + t4) % (t3 % u2 + t4 % u3 - (t3 + t4) % u0) <=> 
    (t1 + t3 + t4) / (t1 + t3 + t4) % u0 = u0`]);
 (REWRITE_WITH `(t1 + t3 + t4) / (t1 + t3 + t4) = &1`);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (UNDISCH_TAC `t2 < &0` THEN UNDISCH_TAC `t1 + t2 + t3 + t4 = &1` 
   THEN REAL_ARITH_TAC);
 (VECTOR_ARITH_TAC);
 (REWRITE_TAC[NORM_MUL; DOT_LMUL]);
 (REWRITE_WITH `abs (&1 / (t3 + t4)) = &1 / (t3 + t4)`);
 (REWRITE_TAC[REAL_ABS_REFL]);
 (ASM_SIMP_TAC[REAL_LE_DIV;REAL_LE_ADD; REAL_ARITH `&0 <= &1`]);
 (REWRITE_WITH `abs (&1 / (t1 + t3 + t4)) = &1 / (t1 + t3 + t4)`);
 (REWRITE_TAC[REAL_ABS_REFL]);
 (MATCH_MP_TAC REAL_LE_DIV THEN REWRITE_TAC[REAL_ARITH `&0 <= &1`]);
 (UNDISCH_TAC `t2 < &0` THEN UNDISCH_TAC `t1 + t2 + t3 + t4 = &1` 
   THEN REAL_ARITH_TAC);
 (REWRITE_TAC[REAL_ARITH `(a * x) / ((a * y) * z) = 
                           (a * x) / (a * (y * z))`]);
 (ABBREV_TAC 
  `a1 = norm (t3 % u2 + t4 % u3 - (t3 + t4) % u0) * norm (u1 - u0:real^3)`);
 (NEW_GOAL `~(a1 = &0)`);
 (EXPAND_TAC "a1" THEN ASM_REWRITE_TAC[REAL_ENTIRE; NORM_EQ_0; 
   VECTOR_ARITH `(a - b = vec 0 <=> a = b)/\(a + b-c = vec 0 <=> a + b = c)`]);
 (STRIP_TAC);

 (UNDISCH_TAC `~NULLSET (X INTER D)` THEN REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `(X:real^3->bool)`);
 (STRIP_TAC);
 (ASM_SIMP_TAC[mcell4; MCELL_EXPLICIT; set_of_list]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1, u2, u3:real^3}`);
 (REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (MATCH_MP_TAC COPLANAR_IMP_NEGLIGIBLE);
 (REWRITE_TAC[COPLANAR_AFFINE_HULL_COPLANAR]);
 (REWRITE_TAC[coplanar]);
 (EXISTS_TAC `u1:real^3` THEN EXISTS_TAC `u2:real^3` THEN 
   EXISTS_TAC `u3:real^3`);
 (MATCH_MP_TAC (SET_RULE `u0 IN S /\ b SUBSET S ==> (u0 INSERT b) SUBSET S`));
 (REWRITE_TAC[SET_SUBSET_AFFINE_HULL]);
 (REWRITE_TAC[AFFINE_HULL_3; IN; IN_ELIM_THM]);
 (EXISTS_TAC `&0` THEN EXISTS_TAC `t3 / (t3 + t4)` 
   THEN EXISTS_TAC `t4 / (t3 + t4)`);
 (REPEAT STRIP_TAC);
 (REWRITE_TAC[REAL_ARITH `&0 + t3 / (t3 + t4) + t4 / (t3 + t4) = 
                          (t3 + t4) / (t3 + t4)`]);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (UNDISCH_TAC `&0 < t3 + t4` THEN REAL_ARITH_TAC);
 (ASM_REWRITE_TAC[VECTOR_ARITH 
   `&0 % u1 + t3 / (t3 + t4) % u2 + t4 / (t3 + t4) % u3 = 
    (&1 / (t3 + t4)) % (t3 % u2 + t4 % u3)`]);
 (REWRITE_TAC[VECTOR_MUL_ASSOC; REAL_ARITH `&1 / a * a = a / a`]);
 (REWRITE_WITH `(t3 + t4) / (t3 + t4) = &1`);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (UNDISCH_TAC `&0 < t3 + t4` THEN REAL_ARITH_TAC);
 (VECTOR_ARITH_TAC);
 (SET_TAC[]);

 (NEW_GOAL `~(&1 / (t3 + t4) = &0)`);
 (NEW_GOAL `&0 < &1 / (t3 + t4)`);
 (MATCH_MP_TAC REAL_LT_DIV);
 (ASM_REWRITE_TAC[REAL_ARITH `&0 < &1`]);
 (UP_ASM_TAC THEN REAL_ARITH_TAC);

 (REWRITE_WITH 
 `(&1 / (t3 + t4) * ((t3 % u2 + t4 % u3 - (t3 + t4) % u0) dot (u1 - u0))) /
  (&1 / (t3 + t4) * a1) = 
  ((t3 % u2 + t4 % u3 - (t3 + t4) % u0) dot (u1 - u0:real^3)) / a1`);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN MESON_TAC[Trigonometry1.REAL_DIV_MUL2]);

 (NEW_GOAL `~(&1 / (t1 + t3 + t4) = &0)`);
 (NEW_GOAL `&0 < &1 / (t1 + t3 + t4)`);
 (MATCH_MP_TAC REAL_LT_DIV);
 (ASM_REWRITE_TAC[REAL_ARITH `&0 < &1`]);
 (UNDISCH_TAC `t2 < &0` THEN UNDISCH_TAC `t1 + t2 + t3 + t4 = &1` THEN
   REAL_ARITH_TAC);
 (UP_ASM_TAC THEN REAL_ARITH_TAC);

 (REWRITE_WITH 
 `(&1 / (t1 + t3 + t4) * ((t3 % u2 + t4 % u3 - (t3 + t4) % u0) dot (u1 - u0))) /
  (&1 / (t1 + t3 + t4) * a1) = 
  ((t3 % u2 + t4 % u3 - (t3 + t4) % u0) dot (u1 - u0:real^3)) / a1`);
 (UP_ASM_TAC THEN UNDISCH_TAC `~(a1 = &0)` THEN
   MESON_TAC[Trigonometry1.REAL_DIV_MUL2]);

 (NEW_GOAL `(g:real^3->real) x <= g w`);
 (EXPAND_TAC "g");

 (REWRITE_WITH 
  `((x - u0) dot (u1 - u0:real^3)) / (norm (x - u0) * norm (u1 - u0)) <=
  ((w - u0) dot (u1 - u0)) / (norm (w - u0) * norm (u1 - u0)) <=>
  ((x - u0) dot (u1 - u0)) * (norm (w - u0) * norm (u1 - u0)) <= 
  ((w - u0) dot (u1 - u0)) * (norm (x - u0) * norm (u1 - u0))`);
 (MATCH_MP_TAC RAT_LEMMA4);
 (STRIP_TAC);
 (MATCH_MP_TAC REAL_LT_MUL);
 (ASM_REWRITE_TAC[NORM_POS_LT; VECTOR_ARITH `x - b = vec 0 <=> x = b`]);
 (STRIP_TAC);
 (UNDISCH_TAC `~NULLSET (X INTER D)`);
 (REWRITE_TAC[]);

 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `(X:real^3->bool)`);
 (STRIP_TAC);
 (ASM_SIMP_TAC[mcell4; MCELL_EXPLICIT; set_of_list]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1, u2, u3:real^3}`);
 (REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (MATCH_MP_TAC COPLANAR_IMP_NEGLIGIBLE);
 (REWRITE_TAC[COPLANAR_AFFINE_HULL_COPLANAR]);
 (REWRITE_TAC[coplanar]);
 (EXISTS_TAC `u0:real^3` THEN EXISTS_TAC `u2:real^3` THEN 
   EXISTS_TAC `u3:real^3`);
 (ONCE_REWRITE_TAC[SET_RULE `{u0, u1, u2, u3} = {u1, u0, u2, u3}`]);
 (MATCH_MP_TAC (SET_RULE `u0 IN S /\ b SUBSET S ==> (u0 INSERT b) SUBSET S`));
 (REWRITE_TAC[SET_SUBSET_AFFINE_HULL]);
 (REWRITE_TAC[AFFINE_HULL_3; IN; IN_ELIM_THM]);
 (EXISTS_TAC `(t2 + t3 + t4) / t2` THEN EXISTS_TAC `(--t3) / t2` 
   THEN EXISTS_TAC `(--t4) / t2`);
 (REPEAT STRIP_TAC);
 (REWRITE_TAC[REAL_ARITH 
   `(t2 + t3 + t4) / t2 + --t3 / t2 + --t4 / t2 = t2 / t2`]);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (UNDISCH_TAC `t2 < &0` THEN REAL_ARITH_TAC);
 (REWRITE_WITH `(t2 + t3 + t4) = &1 - t1`);
 (UNDISCH_TAC `t1 + t2 + t3 + t4 = &1` THEN REAL_ARITH_TAC);
 (NEW_GOAL `u0 - t1 % u0 - t3 % u2 - t4 % u3:real^3 = t2 % u1`);
 (UP_ASM_TAC THEN VECTOR_ARITH_TAC);
 (ASM_REWRITE_TAC[VECTOR_ARITH 
   `(&1 - t1) / t2 % u0 + --t3 / t2 % u2 + --t4 / t2 % u3 = 
    (&1 / t2) % (u0 - t1 % u0 - t3 % u2 - t4 % u3)`]);
 (REWRITE_TAC[VECTOR_MUL_ASSOC; REAL_ARITH `&1 / a * a = a / a`]);
 (REWRITE_WITH `t2 / t2 = &1`);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (UNDISCH_TAC `t2 < &0` THEN REAL_ARITH_TAC);
 (VECTOR_ARITH_TAC);
 (SET_TAC[]);

 (MATCH_MP_TAC REAL_LT_MUL);
 (ASM_REWRITE_TAC[NORM_POS_LT; VECTOR_ARITH `x - b = vec 0 <=> x = b`]);
 (EXPAND_TAC "w" THEN STRIP_TAC);
 (UNDISCH_TAC `~NULLSET (X INTER D)`);
 (REWRITE_TAC[]);

 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `(X:real^3->bool)`);
 (STRIP_TAC);
 (ASM_SIMP_TAC[mcell4; MCELL_EXPLICIT; set_of_list]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1, u2, u3:real^3}`);
 (REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (MATCH_MP_TAC COPLANAR_IMP_NEGLIGIBLE);
 (REWRITE_TAC[COPLANAR_AFFINE_HULL_COPLANAR]);
 (REWRITE_TAC[coplanar]);
 (EXISTS_TAC `u1:real^3` THEN EXISTS_TAC `u2:real^3` THEN 
   EXISTS_TAC `u3:real^3`);
 (MATCH_MP_TAC (SET_RULE `u0 IN S /\ b SUBSET S ==> (u0 INSERT b) SUBSET S`));
 (REWRITE_TAC[SET_SUBSET_AFFINE_HULL]);
 (REWRITE_TAC[AFFINE_HULL_3; IN; IN_ELIM_THM]);

 (EXISTS_TAC `&0` THEN EXISTS_TAC `t3 / (t3 + t4)` 
   THEN EXISTS_TAC `t4 / (t3 + t4)`);
 (REPEAT STRIP_TAC);
 (REWRITE_TAC[REAL_ARITH `&0 + t3 / (t3 + t4) + t4 / (t3 + t4) = 
                          (t3 + t4) / (t3 + t4)`]);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (UNDISCH_TAC `&0 < t3 + t4` THEN REAL_ARITH_TAC);
 (ASM_REWRITE_TAC[VECTOR_ARITH 
   `&0 % u1 + t3 / (t3 + t4) % u2 + t4 / (t3 + t4) % u3 = 
    (&1 / (t3 + t4)) % (t3 % u2 + t4 % u3)`]);
 (UP_ASM_TAC THEN REWRITE_TAC[VECTOR_ARITH 
   `t1 / x % u0 + t3 / x % u2 + t4 / x % u3 = 
    (&1 / x) % (t1 % u0 + t3 % u2 + t4 % u3)`]);
 (REWRITE_WITH `&1 / (t1 + t3 + t4) % (t1 % u0 + t3 % u2 + t4 % u3) = u0 <=> 
                 t1 % u0 + t3 % u2 + t4 % u3 = (t1 + t3 + t4) % u0:real^3`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC Collect_geom.CHANGE_SIDE);
 (UNDISCH_TAC `t2 < &0` THEN UNDISCH_TAC `t1 + t2 +t3 + t4 = &1` THEN 
   REAL_ARITH_TAC);

 (REWRITE_TAC[VECTOR_ARITH `t1 % u0 + t3 % u2 + t4 % u3 = (t1 + t3 + t4) % u0
   <=> t3 % u2 + t4 % u3 = (t3 + t4) % u0`]);
 (STRIP_TAC THEN ASM_REWRITE_TAC[]);
 (REWRITE_TAC[VECTOR_MUL_ASSOC; REAL_ARITH `&1 / a * a = a / a`]);
 (REWRITE_WITH `(t3 + t4) / (t3 + t4) = &1`);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (UNDISCH_TAC `&0 < t3 + t4` THEN REAL_ARITH_TAC);
 (VECTOR_ARITH_TAC);
 (SET_TAC[]);

 (REWRITE_WITH `x = t2 % u1 + (t1 + t3 + t4) % w:real^3`);
 (ASM_REWRITE_TAC[] THEN EXPAND_TAC "w");
 (REWRITE_TAC[VECTOR_ARITH 
  `x % (t1 /x % u0 + t3 / x % u2 + t4 /x  % u3) = 
   (x / x) % (t1 % u0 + t3 % u2 + t4 % u3)`]);
 (REWRITE_WITH `(t1 + t3 + t4) / (t1 + t3 + t4) = &1`);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (UNDISCH_TAC `t2 < &0` THEN UNDISCH_TAC `t1 + t2 + t3 + t4 = &1` THEN
   REAL_ARITH_TAC);
 (VECTOR_ARITH_TAC);
 (ABBREV_TAC `t = t1 + t3 + t4`);
 (REWRITE_WITH `(t2 % u1 + t % w) - u0:real^3 = 
                (t2 % u1 + t % w) - (t1 + t2 + t3 + t4) % u0`);
 (ASM_REWRITE_TAC[] THEN VECTOR_ARITH_TAC);
 (REWRITE_WITH `t1 + t2 + t3 + t4 = t2 + t:real`);
 (EXPAND_TAC "t" THEN REAL_ARITH_TAC);
 (REWRITE_TAC[VECTOR_ARITH 
  `(t2 % u1 + t % w) - (t2 + t) % u0 = t2 % (u1 - u0) + t % (w - u0)`]);
 (ABBREV_TAC `x1 = u1 - u0:real^3`);
 (ABBREV_TAC `x2 = w - u0:real^3`);

 (REWRITE_WITH `(t2 % x1 + t % x2) dot x1 = 
   t2 * norm x1 pow 2 + t * x2 dot (x1:real^3)`);
 (REWRITE_TAC[NORM_POW_2]);
 (VECTOR_ARITH_TAC);

 (NEW_GOAL `t2 * norm x1 pow 2 * norm x2 * norm x1 <= 
             t2 * (x2 dot x1) * norm x1 * norm (x1:real^3)`);
 (REWRITE_TAC[REAL_POW_2; REAL_ARITH `t2 * (x1 * x1) * x2 * x1 <=
   t2 * x3 * x1 * x1 <=> &0 <= (x1 pow 2) * (--t2) * (x2 * x1 - x3)`]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (ASM_SIMP_TAC[REAL_LE_MUL; NORM_POS_LE]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (REWRITE_TAC[REAL_ARITH `&0 <= a - b <=> b <= a`]);
 (STRIP_TAC);
 (UNDISCH_TAC `t2 < &0` THEN REAL_ARITH_TAC);
 (REWRITE_TAC[NORM_CAUCHY_SCHWARZ]);

 (NEW_GOAL 
 `t2 * (x2 dot x1) * norm x1 * norm x1 + t * (x2 dot x1) * norm x2 * norm x1 <= 
  (x2 dot x1) * norm (t2 % x1 + t % x2) * norm (x1:real^3)`);

 (REWRITE_TAC[REAL_ARITH `t2 * x3 * x1 * x1 + t * x3 * x2 * x1 <=
 x3 * x4 * x1 <=> &0 <= (x1 * x3) * (x4 - t2 * x1 - t * x2)`]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (STRIP_TAC);
 (MATCH_MP_TAC REAL_LE_MUL);
 (REWRITE_TAC[NORM_POS_LE]);
 (ASM_CASES_TAC `x2 dot (x1:real^3) < &0`);
 (NEW_GOAL `F`);
 (NEW_GOAL `(g:real^3->real) x <= &0`);
 (EXPAND_TAC "g");
 (REWRITE_TAC[REAL_ARITH `a / b <= &0 <=> &0 <= (--a) / b`]);
 (MATCH_MP_TAC REAL_LE_DIV);
 (SIMP_TAC[NORM_POS_LE; REAL_LE_MUL]);

 (REWRITE_WITH `x = t2 % u1 + (t1 + t3 + t4) % w:real^3`);
 (ASM_REWRITE_TAC[] THEN EXPAND_TAC "w");
 (REWRITE_TAC[VECTOR_ARITH 
  `x % (t1 /x % u0 + t3 / x % u2 + t4 /x  % u3) = 
   (x / x) % (t1 % u0 + t3 % u2 + t4 % u3)`]);
 (EXPAND_TAC "t");
 (REWRITE_WITH `(t1 + t3 + t4) / (t1 + t3 + t4) = &1`);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (UNDISCH_TAC `t2 < &0` THEN UNDISCH_TAC `t1 + t2 + t3 + t4 = &1` THEN
   REAL_ARITH_TAC);
 (VECTOR_ARITH_TAC);

 (REWRITE_TAC[REAL_ARITH `&0 <= --a <=> a <= &0`]);
 (REWRITE_WITH `(t2 % u1 + (t1 + t3 + t4) % w) - u0:real^3 = 
                 (t2 % u1 + (t1 + t3 + t4) % w) - (t1 + t2 + t3 + t4) % u0`);
 (ASM_REWRITE_TAC[] THEN VECTOR_ARITH_TAC);
 (REWRITE_WITH `(t2 % u1 + (t1 + t3 + t4) % w) - (t1 + t2 + t3 + t4) % u0 = 
   t2 % x1 + t % x2:real^3`);
 (EXPAND_TAC "x1" THEN EXPAND_TAC "x2" THEN EXPAND_TAC "t"
   THEN VECTOR_ARITH_TAC);
 (NEW_GOAL `t % x2 dot (x1:real^3) <= &0`);
 (REWRITE_TAC[DOT_LMUL; REAL_ARITH `a * b <= &0 <=> &0 <= a * (--b)`]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (STRIP_TAC);
 (EXPAND_TAC "t" THEN UNDISCH_TAC `t2 < &0` THEN 
   UNDISCH_TAC `t1 + t2 + t3 + t4 = &1` THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN REAL_ARITH_TAC);
 (NEW_GOAL `t2 % x1 dot (x1:real^3) <= &0`);
 (REWRITE_TAC[DOT_LMUL; REAL_ARITH `a * b <= &0 <=> &0 <= (--a) * b`]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (STRIP_TAC);
 (EXPAND_TAC "t" THEN UNDISCH_TAC `t2 < &0` THEN 
   UNDISCH_TAC `t1 + t2 + t3 + t4 = &1` THEN REAL_ARITH_TAC);
 (REWRITE_TAC[DOT_POS_LE]);
 (REWRITE_TAC[DOT_LADD]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN UNDISCH_TAC `d < (g:real^3->real) x`);
 (EXPAND_TAC "d" THEN UNDISCH_TAC `&0 < c /\ c < &1`);
 (REAL_ARITH_TAC);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (UP_ASM_TAC THEN REAL_ARITH_TAC);

 (REWRITE_TAC [REAL_ARITH `&0 <= a - b * d - c <=> c <= a + (--b) * d`]);
 (REWRITE_WITH `t * norm (x2:real^3) = abs t * norm x2`);
 (AP_THM_TAC THEN AP_TERM_TAC);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (REWRITE_TAC[REAL_ABS_REFL]);
 (EXPAND_TAC "t" THEN UNDISCH_TAC `t2 < &0` THEN 
   UNDISCH_TAC `t1 + t2 + t3 + t4 = &1` THEN REAL_ARITH_TAC);
 (REWRITE_WITH `(--t2) * norm (x1:real^3) = abs (--t2) * norm x1`);
 (AP_THM_TAC THEN AP_TERM_TAC);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (REWRITE_TAC[REAL_ABS_REFL]);
 (UNDISCH_TAC `t2 < &0` THEN REAL_ARITH_TAC);
 (REWRITE_TAC[GSYM NORM_MUL]);
 (REWRITE_WITH 
  `norm (t % x2:real^3) = norm ((t2 % x1 + t % x2) + (--t2 % x1))`);
 (AP_TERM_TAC THEN VECTOR_ARITH_TAC);
 (REWRITE_TAC[NORM_TRIANGLE]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN REAL_ARITH_TAC);
 (UNDISCH_TAC `(g:real^3->real) y <= g xx`);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN REAL_ARITH_TAC);

 (NEW_GOAL `(g:real^3->real) xx <= d2`);
 (FIRST_ASSUM MATCH_MP_TAC);
 (EXPAND_TAC "P4");
 (EXPAND_TAC "g" THEN EXPAND_TAC "f4");
 (REWRITE_TAC[IN_ELIM_THM; IN]);
 (EXISTS_TAC `vl:(real^3)list`);
 (REWRITE_TAC[ASSUME `barV V 3 vl`; ASSUME `vl = [u0;u1;u2;u3:real^3]`; 
               TRUNCATE_SIMPLEX_EXPLICIT_1]);
 (SIMP_TAC[EL; HD; TL; ARITH_RULE `3 = SUC 2 /\ 2 = SUC 1 /\ 1 = SUC 0`]);
 (EXPAND_TAC "xx");
 (SIMP_TAC[GSYM (ASSUME `vl = [u0; u1; u2; u3:real^3]`)]);
 (REWRITE_WITH `mcell 4 V vl = mcell k V vl`);
 (ASM_SIMP_TAC[MCELL_EXPLICIT; ARITH_RULE `4 >= 4`]);
 (REWRITE_TAC[GSYM (ASSUME `X = mcell k V vl`)]);
 (STRIP_TAC);

 (UNDISCH_TAC `~NULLSET (X INTER D)` THEN REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X INTER (C:real^3->bool)`);
 (STRIP_TAC);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC (SET_RULE `D SUBSET C ==> X INTER D SUBSET X INTER C`));
 (EXPAND_TAC "D" THEN EXPAND_TAC "C");
 (MATCH_MP_TAC (SET_RULE 
  `A SUBSET B /\ C SUBSET D ==> A INTER C SUBSET B INTER D`));
 (STRIP_TAC);
 (MATCH_MP_TAC SUBSET_BALL);
 (EXPAND_TAC "r" THEN REAL_ARITH_TAC);
 (MATCH_MP_TAC RCONE_GT_SUBSET);
 (EXPAND_TAC "d" THEN REAL_ARITH_TAC);

 (UP_ASM_TAC THEN UP_ASM_TAC THEN UP_ASM_TAC THEN EXPAND_TAC "d");
 (REAL_ARITH_TAC);

 (NEW_GOAL `F`);
 (UNDISCH_TAC `~NULLSET (X INTER D)` THEN REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `(X:real^3->bool)`);
 (STRIP_TAC);
 (ASM_SIMP_TAC[mcell4; MCELL_EXPLICIT; set_of_list]);
 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);
 (SET_TAC[]);
 (UP_ASM_TAC THEN MESON_TAC[]);


(* ========================================================================= *)

 (NEW_GOAL `~coplanar {u0, u1, u2, u3:real^3}`);
 (STRIP_TAC);
 (UNDISCH_TAC `~NULLSET (X INTER D)` THEN REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X:real^3->bool`);
 (STRIP_TAC);
 (ASM_SIMP_TAC[mcell4; MCELL_EXPLICIT; set_of_list]);
 (COND_CASES_TAC);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1, u2, u3:real^3}`);
 (REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (MATCH_MP_TAC COPLANAR_IMP_NEGLIGIBLE);
 (ASM_REWRITE_TAC[COPLANAR_AFFINE_HULL_COPLANAR]);
 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);
 (SET_TAC[]);

 (ASM_CASES_TAC `azim u0 u1 u2 (u3:real^3) < pi`);
 (REWRITE_WITH `vol (L INTER D) = vol (D INTER wedge u0 u1 u2 u3)`);
 (ASM_SIMP_TAC[WEDGE_LUNE]);
 (REWRITE_WITH `L INTER conic_cap (u0:real^3) u1 r d = 
                 conic_cap u0 u1 r d INTER L`);
 (SET_TAC[]);
 (MATCH_MP_TAC MEASURE_NEGLIGIBLE_SYMDIFF);
 (REWRITE_WITH `conic_cap (u0:real^3) u1 r d INTER 
   aff_gt {u0, u1} {u2, u3} DIFF conic_cap u0 u1 r d INTER L = {}`);
 (EXPAND_TAC "L");
 (MATCH_MP_TAC (SET_RULE `A SUBSET B ==> C INTER A DIFF C INTER B = {}`));
 (REWRITE_TAC[AFF_GT_SUBSET_AFF_GE]);
 (REWRITE_TAC[SET_RULE `A UNION {} = A`]);
 (EXPAND_TAC "L");

 (REWRITE_WITH `aff_ge {u0, u1:real^3} {u2, u3} =
                 aff_gt {u0, u1} {u2, u3} UNION 
   UNIONS {aff_ge {u0, u1} ({u2, u3} DELETE a) | a | a IN  {u2, u3}}`);
 (MATCH_MP_TAC AFF_GE_AFF_GT_DECOMP);
 (REWRITE_TAC[Geomdetail.FINITE6]);
 (REWRITE_TAC[DISJOINT]);

 (ASM_CASES_TAC `u2 IN {u0, u1:real^3}`);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~coplanar {u0, u1, u2, u3:real^3}`);
 (REWRITE_WITH `{u0, u1, u2, u3} = {u0, u1, u3:real^3}`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_TAC[COPLANAR_3]);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (ASM_CASES_TAC `u3 IN {u0, u1:real^3}`);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~coplanar {u0, u1, u2, u3:real^3}`);
 (REWRITE_WITH `{u0, u1, u2, u3} = {u0, u1, u2:real^3}`);
 (UP_ASM_TAC THEN SET_TAC[]); 
 (REWRITE_TAC[COPLANAR_3]);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN SET_TAC[]);

 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC 
  `UNIONS {aff_ge {u0, u1:real^3} ({u2, u3} DELETE a) | a | a IN {u2, u3}}`);
 (STRIP_TAC);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC 
  `aff_ge {u0, u1:real^3} {u2} UNION aff_ge {u0, u1:real^3} {u3}`);
 (STRIP_TAC);
 (MATCH_MP_TAC NEGLIGIBLE_UNION);
 (STRIP_TAC);

 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1:real^3, u2}`);
 (STRIP_TAC);
 (REWRITE_TAC[NEGLIGIBLE_AFFINE_HULL_3]);
 (REWRITE_WITH `{u0,u1,u2:real^3} = {u0,u1} UNION {u2}`);
 (SET_TAC[]);
 (REWRITE_TAC[AFF_GE_SUBSET_AFFINE_HULL]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1:real^3, u3}`);
 (STRIP_TAC);
 (REWRITE_TAC[NEGLIGIBLE_AFFINE_HULL_3]);
 (REWRITE_WITH `{u0,u1,u3:real^3} = {u0,u1} UNION {u3}`);
 (SET_TAC[]);
 (REWRITE_TAC[AFF_GE_SUBSET_AFFINE_HULL]);
 (REWRITE_TAC[SET_RULE 
  `UNIONS {aff_ge {u0, u1} ({m, s3} DELETE a) | a | a IN {m, s3}} = 
         aff_ge {u0, u1} ({m, s3} DELETE s3) 
   UNION aff_ge {u0, u1} ({m, s3} DELETE m)`]);
 (MATCH_MP_TAC (SET_RULE 
  `A SUBSET B /\ C SUBSET D ==> A UNION C SUBSET B UNION D`));
 (STRIP_TAC);
 (MATCH_MP_TAC AFF_GE_MONO_RIGHT);
 (STRIP_TAC);
 (SET_TAC[]);

 (REWRITE_TAC[DISJOINT]);
 (ASM_CASES_TAC `u2 IN {u0, u1:real^3}`);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~coplanar {u0, u1, u2, u3:real^3}`);
 (REWRITE_WITH `{u0, u1, u2, u3} = {u0, u1, u3:real^3}`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_TAC[COPLANAR_3]);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (UP_ASM_TAC THEN SET_TAC[]);

 (MATCH_MP_TAC AFF_GE_MONO_RIGHT);
 (STRIP_TAC);
 (SET_TAC[]);
 (REWRITE_TAC[DISJOINT]);
 (ASM_CASES_TAC `u3 IN {u0, u1:real^3}`);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~coplanar {u0, u1, u2, u3:real^3}`);
 (REWRITE_WITH `{u0, u1, u2, u3} = {u0, u1, u2:real^3}`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_TAC[COPLANAR_3]);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (UP_ASM_TAC THEN SET_TAC[]);

 (SET_TAC[]);

(* begin the computation *)

 (REWRITE_TAC[ASSUME `D = conic_cap (u0:real^3) u1 r d`]);
 (REWRITE_WITH `vol (conic_cap u0 u1 r d INTER wedge u0 u1 u2 u3) =
             (if &1 < d \/ r < &0
              then &0
              else azim u0 u1 u2 u3 / &3 * (&1 - max d (-- &1)) * r pow 3)`);
 (NEW_GOAL `~collinear {u0:real^3, u1, u2} /\ ~collinear {u0, u1, u3}`);
 (STRIP_TAC);
 (MATCH_MP_TAC NOT_COPLANAR_NOT_COLLINEAR);
 (EXISTS_TAC `u3:real^3`);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC NOT_COPLANAR_NOT_COLLINEAR);
 (EXISTS_TAC `u2:real^3`);
 (ONCE_REWRITE_TAC[SET_RULE `{a,b,c,d} = {a,b,d,c}`]);
 (ASM_REWRITE_TAC[]);

 (ASM_SIMP_TAC[VOLUME_CONIC_CAP_WEDGE]);
 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `&0 < r` THEN UNDISCH_TAC `d < &1` THEN 
   UP_ASM_TAC THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (REWRITE_WITH `azim (u0:real^3) u1 u2 u3 = dihV u0 u1 u2 u3`);
 (MATCH_MP_TAC AZIM_DIHV_SAME);
 (ASM_REWRITE_TAC[]);
 (STRIP_TAC);
 (MATCH_MP_TAC NOT_COPLANAR_NOT_COLLINEAR);
 (EXISTS_TAC `u3:real^3`);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC NOT_COPLANAR_NOT_COLLINEAR);
 (EXISTS_TAC `u2:real^3`);
 (ONCE_REWRITE_TAC[SET_RULE `{a,b,c,d} = {a,b,d,c}`]);
 (ASM_REWRITE_TAC[]);

 (REWRITE_TAC[dihX]);
 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~NULLSET (X INTER D)`);
 (REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X:real^3->bool`);
 (ASM_REWRITE_TAC[] THEN SET_TAC[]);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (LET_TAC);

 (UP_ASM_TAC THEN REWRITE_TAC[cell_params_d]);
 (ABBREV_TAC `P = (\(k, ul). k <= 4 /\
           ul IN barV V 3 /\
           X = mcell k V ul /\
           initial_sublist [u0; u1] ul)`);
 (STRIP_TAC);
 (NEW_GOAL `(P:num#(real^3)list->bool) ((@) P)`);
 (MATCH_MP_TAC SELECT_AX);
 (EXISTS_TAC `(4, vl:(real^3)list)`);
 (EXPAND_TAC "P");
 (REWRITE_TAC[BETA_THM]);
 (REWRITE_TAC[IN; ARITH_RULE `4 <= 4`] THEN ASM_REWRITE_TAC[]);
 (STRIP_TAC);
 (ASM_SIMP_TAC[MCELL_EXPLICIT; ARITH_RULE `4 >= 4`]);

 (REWRITE_WITH `initial_sublist [u0;u1:real^3] [u0; u1; u2; u3] /\ 
                 LENGTH [u0;u1] = 1 + 1`);
 (REWRITE_TAC[GSYM Packing3.TRUNCATE_SIMPLEX_INITIAL_SUBLIST]);
 (REWRITE_TAC[GSYM (ASSUME `vl = [u0; u1; u2; u3:real^3]`)]);
 (ASM_REWRITE_TAC[]);
 (REWRITE_TAC[LENGTH] THEN ARITH_TAC);
 (UP_ASM_TAC THEN ASM_REWRITE_TAC[]);
 (EXPAND_TAC "P" THEN REWRITE_TAC[IN] THEN REPEAT STRIP_TAC);

 (NEW_GOAL `k' = 4 /\ mcell k' V ul = mcell 4 V vl`);
 (MATCH_MP_TAC Ajripqn.AJRIPQN);
 (ASM_REWRITE_TAC[]);
 (REWRITE_TAC[GSYM (ASSUME `vl = [u0; u1; u2; u3:real^3]`)]);
 (REWRITE_WITH `mcell k' V ul INTER mcell 4 V vl = X`);
 (REWRITE_WITH `mcell 4 V vl = X`);
 (ASM_SIMP_TAC[MCELL_EXPLICIT; ARITH_RULE `4 >= 4`]);
 (SET_TAC[ASSUME `X = mcell k' V ul`]);

 (REPEAT STRIP_TAC);
 (UNDISCH_TAC `k' <= 4` THEN REWRITE_TAC[ARITH_RULE 
   `a <= 4 <=> a = 0 \/a = 1 \/ a = 2 \/ a = 3 \/ a = 4`] THEN SET_TAC[]);
 (SET_TAC[]);
 (UP_ASM_TAC THEN UNDISCH_TAC `~NULLSET X` THEN MESON_TAC[]);

 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN ARITH_TAC);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (UP_ASM_TAC THEN DEL_TAC THEN UP_ASM_TAC THEN ARITH_TAC);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (COND_CASES_TAC);

 (REWRITE_TAC[dihu4]);

 (REWRITE_WITH `dihV (EL 0 (ul:(real^3)list)) (EL 1 ul) (EL 2 ul) (EL 3 ul) = 
   dihV u0 u1 u2 (u3:real^3)`);

 (NEW_GOAL `truncate_simplex 1 ul = [u0;u1:real^3] /\ 1 + 1 <= LENGTH ul`);
 (REWRITE_TAC[Packing3.TRUNCATE_SIMPLEX_INITIAL_SUBLIST]);
 (ASM_REWRITE_TAC[LENGTH] THEN ARITH_TAC);

 (NEW_GOAL `EL 0 (ul:(real^3)list) = EL 0 (truncate_simplex 1 ul)`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC Packing3.EL_TRUNCATE_SIMPLEX);
 (REWRITE_WITH `LENGTH (ul:(real^3)list) = 3 + 1 /\ 
                 CARD (set_of_list ul) = 3 + 1`);
 (MATCH_MP_TAC Rogers.BARV_IMP_LENGTH_EQ_CARD);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (ARITH_TAC);

 (NEW_GOAL `EL 1 (ul:(real^3)list) = EL 1 (truncate_simplex 1 ul)`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC Packing3.EL_TRUNCATE_SIMPLEX);
 (REWRITE_WITH `LENGTH (ul:(real^3)list) = 3 + 1 /\ 
                 CARD (set_of_list ul) = 3 + 1`);
 (MATCH_MP_TAC Rogers.BARV_IMP_LENGTH_EQ_CARD);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (ARITH_TAC);

 (NEW_GOAL `{EL 0 ul, EL 1 ul, EL 2 ul, EL 3 ul} = {u0, u1,u2,u3:real^3}`);
 (REWRITE_WITH `
    {EL 0 ul, EL 1 ul, EL 2 ul, EL 3 ul} = {u0, u1,u2,u3:real^3} <=>
    convex hull {EL 0 ul, EL 1 ul, EL 2 ul, EL 3 ul} = 
    convex hull {u0, u1,u2,u3:real^3}`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC Packing3.CONVEX_HULL_EQ_EQ_SET_EQ);
 (REPEAT STRIP_TAC);

 (UNDISCH_TAC `~NULLSET X`);
 (REWRITE_TAC[]);
 (SIMP_TAC[MCELL_EXPLICIT; ARITH_RULE `4 >= 4`; mcell4; 
   ASSUME `X = mcell k' V ul`; ASSUME `k' = 4`]);
 (COND_CASES_TAC);
 (NEW_GOAL `?v0 v1 v2 v3. ul = [v0; v1; v2; v3:real^3]`);
 (MATCH_MP_TAC BARV_3_EXPLICIT);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (ASM_REWRITE_TAC[set_of_list]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {v0, v1, v2, v3:real^3}`);
 (REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (MATCH_MP_TAC COPLANAR_IMP_NEGLIGIBLE);
 (REWRITE_TAC[COPLANAR_AFFINE_HULL_COPLANAR]);
 (MATCH_MP_TAC Rogers.AFF_DIM_LE_2_IMP_COPLANAR);
 (MATCH_MP_TAC Njiutiu.AFF_DEPENDENT_AFF_DIM_4);
 (UNDISCH_TAC 
   `affine_dependent {EL 0 ul, EL 1 ul, EL 2 ul, (EL 3 ul):real^3}`);
 (REWRITE_TAC[EL; HD; TL; ARITH_RULE `3 = SUC 2 /\ 2 = SUC 1 /\ 1 = SUC 0`; 
               ASSUME `ul = [v0; v1; v2; v3:real^3]`]);

 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);

 (UNDISCH_TAC `~NULLSET X`);
 (REWRITE_TAC[]);
 (ASM_SIMP_TAC[MCELL_EXPLICIT; ARITH_RULE `4 >= 4`; mcell4; set_of_list]);
 (COND_CASES_TAC);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1, u2, u3:real^3}`);
 (REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (MATCH_MP_TAC COPLANAR_IMP_NEGLIGIBLE);
 (REWRITE_TAC[COPLANAR_AFFINE_HULL_COPLANAR]);
 (MATCH_MP_TAC Rogers.AFF_DIM_LE_2_IMP_COPLANAR);
 (MATCH_MP_TAC Njiutiu.AFF_DEPENDENT_AFF_DIM_4);
 (ASM_REWRITE_TAC[]);
 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);

 (REWRITE_WITH `convex hull {u0, u1, u2, u3:real^3} = X`);
 (ASM_SIMP_TAC[MCELL_EXPLICIT; ARITH_RULE `4 >= 4`; mcell4; set_of_list]);
 (COND_CASES_TAC);
 (MESON_TAC[]);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~NULLSET X`);
 (REWRITE_TAC[]);
 (ASM_SIMP_TAC[MCELL_EXPLICIT; ARITH_RULE `4 >= 4`; mcell4; set_of_list]);
 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (SIMP_TAC[MCELL_EXPLICIT; ARITH_RULE `4 >= 4`; mcell4; 
   ASSUME `X = mcell k' V ul`; ASSUME `k' = 4`]);
 (COND_CASES_TAC);
 (NEW_GOAL `?v0 v1 v2 v3. ul = [v0; v1; v2; v3:real^3]`);
 (MATCH_MP_TAC BARV_3_EXPLICIT);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (REWRITE_TAC[set_of_list; ASSUME `ul = [v0; v1; v2; v3:real^3]`]);
 (REWRITE_TAC[EL; HD; TL; ARITH_RULE `3 = SUC 2 /\ 2 = SUC 1 /\ 1 = SUC 0`]);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~NULLSET X`);
 (REWRITE_TAC[]);
 (SIMP_TAC[MCELL_EXPLICIT; ARITH_RULE `4 >= 4`; mcell4; 
   ASSUME `X = mcell k' V ul`; ASSUME `k' = 4`]);
 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN REWRITE_TAC[]);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (UP_ASM_TAC THEN ASM_REWRITE_TAC[EL; HD; TL; ARITH_RULE `1 = SUC 0`]);
 (STRIP_TAC);

 (ASM_CASES_TAC `EL 2 ul = u2:real^3`);
 (NEW_GOAL `EL 3 ul = u3:real^3`);
 (MATCH_MP_TAC (MESON[] `(~A ==> F) ==> A`));
 (STRIP_TAC);
 (NEW_GOAL `{u0, u1, EL 2 ul, EL 3 ul} = {u0, u1, u2:real^3}`);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN UP_ASM_TAC THEN SET_TAC[]);
 (UNDISCH_TAC `~coplanar {u0,u1,u2,u3:real^3}` THEN REWRITE_TAC[
   GSYM (ASSUME `{u0, u1, EL 2 ul, EL 3 ul} = {u0, u1, u2, u3:real^3}`);
   ASSUME `{u0, u1, EL 2 ul, EL 3 ul} = {u0, u1, u2:real^3}`; COPLANAR_3]);
 (ASM_REWRITE_TAC[]);

 (NEW_GOAL `EL 2 ul = u3:real^3`);
 (MATCH_MP_TAC (MESON[] `(~A ==> F) ==> A`));
 (STRIP_TAC); 
 (NEW_GOAL `{u0:real^3, u1, EL 2 ul, EL 3 ul} = {u0, u1, EL 3 ul}`);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN UP_ASM_TAC THEN SET_TAC[]);
 (UNDISCH_TAC `~coplanar {u0,u1,u2,u3:real^3}` THEN REWRITE_TAC[
   GSYM (ASSUME `{u0, u1, EL 2 ul, EL 3 ul} = {u0, u1, u2, u3:real^3}`);
   ASSUME `{u0, u1, EL 2 ul, EL 3 ul} = {u0,u1:real^3, EL 3 ul}`; COPLANAR_3]);

 (NEW_GOAL `EL 3 ul = u2:real^3`);
 (MATCH_MP_TAC (MESON[] `(~A ==> F) ==> A`));
 (STRIP_TAC);
 (NEW_GOAL `{u0, u1, EL 2 ul, EL 3 ul} = {u0, u1, u3:real^3}`);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN UP_ASM_TAC THEN UP_ASM_TAC THEN SET_TAC[]);
 (UNDISCH_TAC `~coplanar {u0,u1,u2,u3:real^3}` THEN REWRITE_TAC[
   GSYM (ASSUME `{u0, u1, EL 2 ul, EL 3 ul} = {u0, u1, u2, u3:real^3}`);
   ASSUME `{u0, u1, EL 2 ul, EL 3 ul} = {u0, u1, u3:real^3}`; COPLANAR_3]);
 (ASM_REWRITE_TAC[]);
 (REWRITE_TAC[DIHV_SYM_2]);

 (REWRITE_TAC[REAL_ARITH `a / b * c * d pow 3 = (c/ b * d pow 3) * a`]);
 (REWRITE_TAC[REAL_ARITH `a * b / (&2 * c) = (a / (&2 * c)) * b`]);
 (AP_THM_TAC THEN AP_TERM_TAC);

 (REWRITE_WITH 
  `measurable (conic_cap u0 u1 r d) /\
             vol (conic_cap u0 u1 r d) =
             (if u1 = u0 \/ &1 <= d \/ r < &0
              then &0
              else &2 / &3 * pi * (&1 - d) * r pow 3)`);
 (MATCH_MP_TAC VOLUME_CONIC_CAP);
 (EXPAND_TAC "d");
 (UNDISCH_TAC `&0 < c /\ c < &1` THEN REAL_ARITH_TAC);
 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (UP_ASM_TAC THEN STRIP_TAC);
 (UP_ASM_TAC THEN UNDISCH_TAC `~(u0 = u1:real^3)` THEN MESON_TAC[]);
 (UNDISCH_TAC `d < &1` THEN UP_ASM_TAC THEN REAL_ARITH_TAC);
 (UNDISCH_TAC `&0 < r` THEN UP_ASM_TAC THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (REWRITE_TAC[ARITH_RULE `SUC 0 = 1`]);

 (REWRITE_WITH `max d (--(&1)) = d`);
 (MATCH_MP_TAC (REAL_ARITH `&0 < d /\ --(&1) < &0 ==> max d (--(&1)) = d`));
 (REWRITE_TAC[REAL_NEG_LT0]);
 (STRIP_TAC);
 (EXPAND_TAC "d");
 (UNDISCH_TAC `&0 < c /\ c < &1` THEN REAL_ARITH_TAC);
 (REAL_ARITH_TAC);

 (REWRITE_WITH `
  (&2 / &3 * pi * (&1 - d) * r pow 3) / (&2 * pi) = (&1 - d) / &3 * r pow 3 *   
  ((&2 * pi) / (&2 * pi))`);
 (REAL_ARITH_TAC);
 (REWRITE_WITH `(&2 * pi) / (&2 * pi) = &1`);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (REWRITE_TAC[REAL_ENTIRE; PI_NZ; REAL_ARITH `~(&2 = &0)`]);
 (REAL_ARITH_TAC);
 (NEW_GOAL `F`);
 (UP_ASM_TAC THEN UNDISCH_TAC `k' = 4 /\ mcell k' V ul = mcell 4 V vl`
   THEN MESON_TAC[]);
 (UP_ASM_TAC THEN MESON_TAC[]);

(* ========================================================================= *)
(* OK here *)

 (ASM_CASES_TAC `azim u0 u1 u3 (u2:real^3) < pi`);
 (UNDISCH_TAC `~coplanar {u0, u1, u2, u3:real^3}`);
 (ONCE_REWRITE_TAC[SET_RULE `{a,b,c,d} = {a,b,d,c}`]);
 (STRIP_TAC);
 (REWRITE_WITH `vol (L INTER D) = vol (D INTER wedge u0 u1 u3 u2)`);
 (ASM_SIMP_TAC[WEDGE_LUNE]);
 (REWRITE_WITH `L INTER conic_cap (u0:real^3) u1 r d = 
                 conic_cap u0 u1 r d INTER L`);
 (SET_TAC[]);
 (MATCH_MP_TAC MEASURE_NEGLIGIBLE_SYMDIFF);

 (REWRITE_WITH `conic_cap (u0:real^3) u1 r d INTER 
   aff_gt {u0, u1} {u3, u2} DIFF conic_cap u0 u1 r d INTER L = {}`);
 (EXPAND_TAC "L");
 (REWRITE_TAC[SET_RULE `{a,b} = {b, a}`]);
 (MATCH_MP_TAC (SET_RULE `A SUBSET B ==> C INTER A DIFF C INTER B = {}`));
 (REWRITE_TAC[AFF_GT_SUBSET_AFF_GE]);
 (REWRITE_TAC[SET_RULE `A UNION {} = A`]);
 (EXPAND_TAC "L");
 (REWRITE_TAC[SET_RULE `{a,b} = {b, a}`]);

 (REWRITE_WITH `aff_ge {u0, u1:real^3} {u2, u3} =
                 aff_gt {u0, u1} {u2, u3} UNION 
   UNIONS {aff_ge {u0, u1} ({u2, u3} DELETE a) | a | a IN  {u2, u3}}`);
 (MATCH_MP_TAC AFF_GE_AFF_GT_DECOMP);
 (REWRITE_TAC[Geomdetail.FINITE6]);
 (REWRITE_TAC[DISJOINT]);

 (ASM_CASES_TAC `u2 IN {u0, u1:real^3}`);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~coplanar {u0, u1, u3, u2:real^3}`);
 (REWRITE_WITH `{u0, u1, u3, u2} = {u0, u1, u3:real^3}`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_TAC[COPLANAR_3]);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (ASM_CASES_TAC `u3 IN {u0, u1:real^3}`);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~coplanar {u0, u1, u3, u2:real^3}`);
 (REWRITE_WITH `{u0, u1, u3, u2} = {u0, u1, u2:real^3}`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_TAC[COPLANAR_3]);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN SET_TAC[]);

 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC 
  `UNIONS {aff_ge {u0, u1:real^3} ({u2, u3} DELETE a) | a | a IN {u2, u3}}`);
 (STRIP_TAC);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC 
  `aff_ge {u0, u1:real^3} {u2} UNION aff_ge {u0, u1:real^3} {u3}`);
 (STRIP_TAC);
 (MATCH_MP_TAC NEGLIGIBLE_UNION);
 (STRIP_TAC);

 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1:real^3, u2}`);
 (STRIP_TAC);
 (REWRITE_TAC[NEGLIGIBLE_AFFINE_HULL_3]);
 (REWRITE_WITH `{u0,u1,u2:real^3} = {u0,u1} UNION {u2}`);
 (SET_TAC[]);
 (REWRITE_TAC[AFF_GE_SUBSET_AFFINE_HULL]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1:real^3, u3}`);
 (STRIP_TAC);
 (REWRITE_TAC[NEGLIGIBLE_AFFINE_HULL_3]);
 (REWRITE_WITH `{u0,u1,u3:real^3} = {u0,u1} UNION {u3}`);
 (SET_TAC[]);
 (REWRITE_TAC[AFF_GE_SUBSET_AFFINE_HULL]);
 (REWRITE_TAC[SET_RULE 
  `UNIONS {aff_ge {u0, u1} ({m, s3} DELETE a) | a | a IN {m, s3}} = 
         aff_ge {u0, u1} ({m, s3} DELETE s3) 
   UNION aff_ge {u0, u1} ({m, s3} DELETE m)`]);
 (MATCH_MP_TAC (SET_RULE 
  `A SUBSET B /\ C SUBSET D ==> A UNION C SUBSET B UNION D`));
 (STRIP_TAC);
 (MATCH_MP_TAC AFF_GE_MONO_RIGHT);
 (STRIP_TAC);
 (SET_TAC[]);

 (REWRITE_TAC[DISJOINT]);
 (ASM_CASES_TAC `u2 IN {u0, u1:real^3}`);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~coplanar {u0, u1, u3, u2:real^3}`);
 (REWRITE_WITH `{u0, u1, u3, u2} = {u0, u1, u3:real^3}`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_TAC[COPLANAR_3]);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (UP_ASM_TAC THEN SET_TAC[]);

 (MATCH_MP_TAC AFF_GE_MONO_RIGHT);
 (STRIP_TAC);
 (SET_TAC[]);
 (REWRITE_TAC[DISJOINT]);
 (ASM_CASES_TAC `u3 IN {u0, u1:real^3}`);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~coplanar {u0, u1, u3, u2:real^3}`);
 (REWRITE_WITH `{u0, u1, u3, u2} = {u0, u1, u2:real^3}`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_TAC[COPLANAR_3]);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (UP_ASM_TAC THEN SET_TAC[]);

 (SET_TAC[]);

 (REWRITE_TAC[ASSUME `D = conic_cap (u0:real^3) u1 r d`]);
 (REWRITE_WITH `vol (conic_cap u0 u1 r d INTER wedge u0 u1 u3 u2) =
             (if &1 < d \/ r < &0
              then &0
              else azim u0 u1 u3 u2 / &3 * (&1 - max d (-- &1)) * r pow 3)`);
 (NEW_GOAL `~collinear {u0:real^3, u1, u2} /\ ~collinear {u0, u1, u3}`);
 (STRIP_TAC);
 (MATCH_MP_TAC NOT_COPLANAR_NOT_COLLINEAR);
 (EXISTS_TAC `u3:real^3`);
 (ONCE_REWRITE_TAC[SET_RULE `{a,b,c,d} = {a,b,d,c}`]);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC NOT_COPLANAR_NOT_COLLINEAR);
 (EXISTS_TAC `u2:real^3`);
 (ASM_REWRITE_TAC[]);

 (ASM_SIMP_TAC[VOLUME_CONIC_CAP_WEDGE]);
 (COND_CASES_TAC);
 (NEW_GOAL `F`);

 (UNDISCH_TAC `&0 < r` THEN UNDISCH_TAC `d < &1` THEN 
   UP_ASM_TAC THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (REWRITE_WITH `azim (u0:real^3) u1 u3 u2 = dihV u0 u1 u3 u2`);
 (MATCH_MP_TAC AZIM_DIHV_SAME);
 (ASM_REWRITE_TAC[]);
 (STRIP_TAC);

 (MATCH_MP_TAC NOT_COPLANAR_NOT_COLLINEAR);
 (EXISTS_TAC `u2:real^3`);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC NOT_COPLANAR_NOT_COLLINEAR);
 (EXISTS_TAC `u3:real^3`);
 (ONCE_REWRITE_TAC[SET_RULE `{a,b,c,d} = {a,b,d,c}`]);
 (ASM_REWRITE_TAC[]);

 (REWRITE_TAC[dihX]);
 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~NULLSET (X INTER D)`);
 (REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X:real^3->bool`);
 (ASM_REWRITE_TAC[] THEN SET_TAC[]);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (LET_TAC);

 (UP_ASM_TAC THEN REWRITE_TAC[cell_params_d]);
 (ABBREV_TAC `P = (\(k, ul). k <= 4 /\
           ul IN barV V 3 /\
           X = mcell k V ul /\
           initial_sublist [u0; u1] ul)`);
 (STRIP_TAC);
 (NEW_GOAL `(P:num#(real^3)list->bool) ((@) P)`);
 (MATCH_MP_TAC SELECT_AX);
 (EXISTS_TAC `(4, vl:(real^3)list)`);
 (EXPAND_TAC "P");
 (REWRITE_TAC[BETA_THM]);
 (REWRITE_TAC[IN; ARITH_RULE `4 <= 4`] THEN ASM_REWRITE_TAC[]);
 (STRIP_TAC);
 (ASM_SIMP_TAC[MCELL_EXPLICIT; ARITH_RULE `4 >= 4`]);

 (REWRITE_WITH `initial_sublist [u0;u1:real^3] [u0; u1; u2; u3] /\ 
                 LENGTH [u0;u1] = 1 + 1`);
 (REWRITE_TAC[GSYM Packing3.TRUNCATE_SIMPLEX_INITIAL_SUBLIST]);
 (REWRITE_TAC[GSYM (ASSUME `vl = [u0; u1; u2; u3:real^3]`)]);
 (ASM_REWRITE_TAC[]);
 (REWRITE_TAC[LENGTH] THEN ARITH_TAC);
 (UP_ASM_TAC THEN ASM_REWRITE_TAC[]);
 (EXPAND_TAC "P" THEN REWRITE_TAC[IN] THEN REPEAT STRIP_TAC);

 (NEW_GOAL `k' = 4 /\ mcell k' V ul = mcell 4 V vl`);
 (MATCH_MP_TAC Ajripqn.AJRIPQN);
 (ASM_REWRITE_TAC[]);
 (REWRITE_TAC[GSYM (ASSUME `vl = [u0; u1; u2; u3:real^3]`)]);
 (REWRITE_WITH `mcell k' V ul INTER mcell 4 V vl = X`);
 (REWRITE_WITH `mcell 4 V vl = X`);
 (ASM_SIMP_TAC[MCELL_EXPLICIT; ARITH_RULE `4 >= 4`]);
 (SET_TAC[ASSUME `X = mcell k' V ul`]);

 (REPEAT STRIP_TAC);
 (UNDISCH_TAC `k' <= 4` THEN REWRITE_TAC[ARITH_RULE 
   `a <= 4 <=> a = 0 \/a = 1 \/ a = 2 \/ a = 3 \/ a = 4`] THEN SET_TAC[]);
 (SET_TAC[]);
 (UP_ASM_TAC THEN UNDISCH_TAC `~NULLSET X` THEN MESON_TAC[]);

 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN ARITH_TAC);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (UP_ASM_TAC THEN DEL_TAC THEN UP_ASM_TAC THEN ARITH_TAC);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (COND_CASES_TAC);

 (REWRITE_TAC[dihu4]);

 (REWRITE_WITH `dihV (EL 0 (ul:(real^3)list)) (EL 1 ul) (EL 2 ul) (EL 3 ul) = 
   dihV u0 u1 u2 (u3:real^3)`);

 (NEW_GOAL `truncate_simplex 1 ul = [u0;u1:real^3] /\ 1 + 1 <= LENGTH ul`);
 (REWRITE_TAC[Packing3.TRUNCATE_SIMPLEX_INITIAL_SUBLIST]);
 (ASM_REWRITE_TAC[LENGTH] THEN ARITH_TAC);

 (NEW_GOAL `EL 0 (ul:(real^3)list) = EL 0 (truncate_simplex 1 ul)`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC Packing3.EL_TRUNCATE_SIMPLEX);
 (REWRITE_WITH `LENGTH (ul:(real^3)list) = 3 + 1 /\ 
                 CARD (set_of_list ul) = 3 + 1`);
 (MATCH_MP_TAC Rogers.BARV_IMP_LENGTH_EQ_CARD);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (ARITH_TAC);

 (NEW_GOAL `EL 1 (ul:(real^3)list) = EL 1 (truncate_simplex 1 ul)`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC Packing3.EL_TRUNCATE_SIMPLEX);
 (REWRITE_WITH `LENGTH (ul:(real^3)list) = 3 + 1 /\ 
                 CARD (set_of_list ul) = 3 + 1`);
 (MATCH_MP_TAC Rogers.BARV_IMP_LENGTH_EQ_CARD);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (ARITH_TAC);

 (NEW_GOAL `{EL 0 ul, EL 1 ul, EL 2 ul, EL 3 ul} = {u0, u1,u2,u3:real^3}`);
 (REWRITE_WITH `
    {EL 0 ul, EL 1 ul, EL 2 ul, EL 3 ul} = {u0, u1,u2,u3:real^3} <=>
    convex hull {EL 0 ul, EL 1 ul, EL 2 ul, EL 3 ul} = 
    convex hull {u0, u1,u2,u3:real^3}`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC Packing3.CONVEX_HULL_EQ_EQ_SET_EQ);
 (REPEAT STRIP_TAC);

 (UNDISCH_TAC `~NULLSET X`);
 (REWRITE_TAC[]);
 (SIMP_TAC[MCELL_EXPLICIT; ARITH_RULE `4 >= 4`; mcell4; 
   ASSUME `X = mcell k' V ul`; ASSUME `k' = 4`]);
 (COND_CASES_TAC);
 (NEW_GOAL `?v0 v1 v2 v3. ul = [v0; v1; v2; v3:real^3]`);
 (MATCH_MP_TAC BARV_3_EXPLICIT);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (ASM_REWRITE_TAC[set_of_list]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {v0, v1, v2, v3:real^3}`);
 (REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (MATCH_MP_TAC COPLANAR_IMP_NEGLIGIBLE);
 (REWRITE_TAC[COPLANAR_AFFINE_HULL_COPLANAR]);
 (MATCH_MP_TAC Rogers.AFF_DIM_LE_2_IMP_COPLANAR);
 (MATCH_MP_TAC Njiutiu.AFF_DEPENDENT_AFF_DIM_4);
 (UNDISCH_TAC 
   `affine_dependent {EL 0 ul, EL 1 ul, EL 2 ul, (EL 3 ul):real^3}`);
 (REWRITE_TAC[EL; HD; TL; ARITH_RULE `3 = SUC 2 /\ 2 = SUC 1 /\ 1 = SUC 0`; 
               ASSUME `ul = [v0; v1; v2; v3:real^3]`]);

 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);

 (UNDISCH_TAC `~NULLSET X`);
 (REWRITE_TAC[]);
 (ASM_SIMP_TAC[MCELL_EXPLICIT; ARITH_RULE `4 >= 4`; mcell4; set_of_list]);
 (COND_CASES_TAC);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1, u2, u3:real^3}`);
 (REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (MATCH_MP_TAC COPLANAR_IMP_NEGLIGIBLE);
 (REWRITE_TAC[COPLANAR_AFFINE_HULL_COPLANAR]);
 (MATCH_MP_TAC Rogers.AFF_DIM_LE_2_IMP_COPLANAR);
 (MATCH_MP_TAC Njiutiu.AFF_DEPENDENT_AFF_DIM_4);
 (ASM_REWRITE_TAC[]);
 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);

 (REWRITE_WITH `convex hull {u0, u1, u2, u3:real^3} = X`);
 (ASM_SIMP_TAC[MCELL_EXPLICIT; ARITH_RULE `4 >= 4`; mcell4; set_of_list]);
 (COND_CASES_TAC);
 (MESON_TAC[]);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~NULLSET X`);
 (REWRITE_TAC[]);
 (ASM_SIMP_TAC[MCELL_EXPLICIT; ARITH_RULE `4 >= 4`; mcell4; set_of_list]);
 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (SIMP_TAC[MCELL_EXPLICIT; ARITH_RULE `4 >= 4`; mcell4; 
   ASSUME `X = mcell k' V ul`; ASSUME `k' = 4`]);
 (COND_CASES_TAC);
 (NEW_GOAL `?v0 v1 v2 v3. ul = [v0; v1; v2; v3:real^3]`);
 (MATCH_MP_TAC BARV_3_EXPLICIT);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (REWRITE_TAC[set_of_list; ASSUME `ul = [v0; v1; v2; v3:real^3]`]);
 (REWRITE_TAC[EL; HD; TL; ARITH_RULE `3 = SUC 2 /\ 2 = SUC 1 /\ 1 = SUC 0`]);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~NULLSET X`);
 (REWRITE_TAC[]);
 (SIMP_TAC[MCELL_EXPLICIT; ARITH_RULE `4 >= 4`; mcell4; 
   ASSUME `X = mcell k' V ul`; ASSUME `k' = 4`]);
 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN REWRITE_TAC[]);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (UP_ASM_TAC THEN ASM_REWRITE_TAC[EL; HD; TL; ARITH_RULE `1 = SUC 0`]);
 (STRIP_TAC);

 (ASM_CASES_TAC `EL 2 ul = u2:real^3`);
 (NEW_GOAL `EL 3 ul = u3:real^3`);
 (MATCH_MP_TAC (MESON[] `(~A ==> F) ==> A`));
 (STRIP_TAC);
 (NEW_GOAL `{u0, u1, EL 2 ul, EL 3 ul} = {u0, u1, u2:real^3}`);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN UP_ASM_TAC THEN SET_TAC[]);
 (UNDISCH_TAC `~coplanar {u0,u1,u3,u2:real^3}`);
 (REWRITE_TAC[]);
 (ONCE_REWRITE_TAC[SET_RULE `{a,b,c,d} = {a,b,d,c}`]);
 (REWRITE_TAC[
   GSYM (ASSUME `{u0, u1, EL 2 ul, EL 3 ul} = {u0, u1, u2, u3:real^3}`);
   ASSUME `{u0, u1, EL 2 ul, EL 3 ul} = {u0, u1, u2:real^3}`; COPLANAR_3]);
 (ASM_REWRITE_TAC[]);

 (NEW_GOAL `EL 2 ul = u3:real^3`);
 (MATCH_MP_TAC (MESON[] `(~A ==> F) ==> A`));
 (STRIP_TAC); 
 (NEW_GOAL `{u0:real^3, u1, EL 2 ul, EL 3 ul} = {u0, u1, EL 3 ul}`);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN UP_ASM_TAC THEN SET_TAC[]);
 (UNDISCH_TAC `~coplanar {u0,u1,u3,u2:real^3}`);
 (REWRITE_TAC[]);
 (ONCE_REWRITE_TAC[SET_RULE `{a,b,c,d} = {a,b,d,c}`]);


 (REWRITE_TAC[
   GSYM (ASSUME `{u0, u1, EL 2 ul, EL 3 ul} = {u0, u1, u2, u3:real^3}`);
   ASSUME `{u0, u1, EL 2 ul, EL 3 ul} = {u0,u1:real^3, EL 3 ul}`; COPLANAR_3]);
 (NEW_GOAL `EL 3 ul = u2:real^3`);
 (MATCH_MP_TAC (MESON[] `(~A ==> F) ==> A`));
 (STRIP_TAC);
 (NEW_GOAL `{u0, u1, EL 2 ul, EL 3 ul} = {u0, u1, u3:real^3}`);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN UP_ASM_TAC THEN UP_ASM_TAC THEN SET_TAC[]);
 (UNDISCH_TAC `~coplanar {u0,u1,u3,u2:real^3}`);
 (REWRITE_TAC[]);
 (ONCE_REWRITE_TAC[SET_RULE `{a,b,c,d} = {a,b,d,c}`]);

 (REWRITE_TAC[
   GSYM (ASSUME `{u0, u1, EL 2 ul, EL 3 ul} = {u0, u1, u2, u3:real^3}`);
   ASSUME `{u0, u1, EL 2 ul, EL 3 ul} = {u0, u1, u3:real^3}`; COPLANAR_3]);
 (ASM_REWRITE_TAC[]);
 (REWRITE_TAC[DIHV_SYM_2]);

 (REWRITE_TAC[DIHV_SYM_2]);
 (REWRITE_TAC[REAL_ARITH `a / b * c * d pow 3 = (c/ b * d pow 3) * a`]);
 (REWRITE_TAC[REAL_ARITH `a * b / (&2 * c) = (a / (&2 * c)) * b`]);
 (AP_THM_TAC THEN AP_TERM_TAC);

 (REWRITE_WITH 
  `measurable (conic_cap u0 u1 r d) /\
             vol (conic_cap u0 u1 r d) =
             (if u1 = u0 \/ &1 <= d \/ r < &0
              then &0
              else &2 / &3 * pi * (&1 - d) * r pow 3)`);
 (MATCH_MP_TAC VOLUME_CONIC_CAP);
 (EXPAND_TAC "d");
 (UNDISCH_TAC `&0 < c /\ c < &1` THEN REAL_ARITH_TAC);
 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (UP_ASM_TAC THEN STRIP_TAC);
 (UP_ASM_TAC THEN UNDISCH_TAC `~(u0 = u1:real^3)` THEN MESON_TAC[]);
 (UNDISCH_TAC `d < &1` THEN UP_ASM_TAC THEN REAL_ARITH_TAC);
 (UNDISCH_TAC `&0 < r` THEN UP_ASM_TAC THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (REWRITE_WITH `max d (--(&1)) = d`);
 (MATCH_MP_TAC (REAL_ARITH `&0 < d /\ --(&1) < &0 ==> max d (--(&1)) = d`));
 (REWRITE_TAC[REAL_NEG_LT0]);
 (STRIP_TAC);
 (EXPAND_TAC "d");
 (UNDISCH_TAC `&0 < c /\ c < &1` THEN REAL_ARITH_TAC);
 (REAL_ARITH_TAC);

 (REWRITE_WITH `
  (&2 / &3 * pi * (&1 - d) * r pow 3) / (&2 * pi) = (&1 - d) / &3 * r pow 3 *   
  ((&2 * pi) / (&2 * pi))`);
 (REAL_ARITH_TAC);
 (REWRITE_WITH `(&2 * pi) / (&2 * pi) = &1`);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (REWRITE_TAC[REAL_ENTIRE; PI_NZ; REAL_ARITH `~(&2 = &0)`]);
 (REAL_ARITH_TAC);
 (NEW_GOAL `F`);
 (UP_ASM_TAC THEN UNDISCH_TAC `k' = 4 /\ mcell k' V ul = mcell 4 V vl`
   THEN MESON_TAC[]);
 (UP_ASM_TAC THEN MESON_TAC[]);

(* ========================================================================== *)

 (NEW_GOAL `F`);
 (NEW_GOAL `azim (u0:real^3) u1 u3 u2 = 
  (if azim u0 u1 u2 u3 = &0 then &0 else &2 * pi - azim u0 u1 u2 u3)`);
 (MATCH_MP_TAC AZIM_COMPL);
 (STRIP_TAC);

 (MATCH_MP_TAC NOT_COPLANAR_NOT_COLLINEAR);
 (EXISTS_TAC `u3:real^3`);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC NOT_COPLANAR_NOT_COLLINEAR);
 (EXISTS_TAC `u2:real^3`);
 (ONCE_REWRITE_TAC[SET_RULE `{a,b,c,d} = {a,b, d, c}`]);
 (ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN COND_CASES_TAC);
 (NEW_GOAL `F`);
 (NEW_GOAL `(&0 < pi)`);
 (REWRITE_TAC[PI_POS]);
 (UNDISCH_TAC `~(azim (u0:real^3) u1 u2 u3 < pi)`);
 (ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (STRIP_TAC);

 (NEW_GOAL `azim (u0:real^3) u1 u2 u3 = pi`);
 (UP_ASM_TAC THEN DEL_TAC THEN UP_ASM_TAC THEN UP_ASM_TAC THEN REAL_ARITH_TAC);
 (UNDISCH_TAC `~coplanar {u0, u1, u2, u3:real^3}`);
 (REWRITE_TAC[] THEN MATCH_MP_TAC AZIM_EQ_0_PI_IMP_COPLANAR);
 (ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN MESON_TAC[]);

(* ========================================================================= *)
(*  Case k = 3                                                               *)
(* ========================================================================= *)

 (NEW_GOAL `k = 3`);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN UNDISCH_TAC `2 <= k` THEN ARITH_TAC);
 (NEW_GOAL `?u2 u3. vl = [u0; u1;u2;u3:real^3]`);
 (NEW_GOAL `?v0 v1 u2 u3. vl = [v0; v1;u2;u3:real^3]`);
 (MATCH_MP_TAC BARV_3_EXPLICIT);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (EXISTS_TAC `u2:real^3` THEN EXISTS_TAC `u3:real^3`);

 (REWRITE_WITH `u0 = v0:real^3`);
 (REWRITE_WITH `v0:real^3 = HD (truncate_simplex 1 vl)`);
 (REWRITE_TAC[ASSUME `vl = [v0;v1;u2;u3:real^3]`; 
   TRUNCATE_SIMPLEX_EXPLICIT_1; HD]);
 (ASM_REWRITE_TAC[TRUNCATE_SIMPLEX_EXPLICIT_1; HD]);

 (REWRITE_WITH `u1 = v1:real^3`);
 (REWRITE_WITH `v1:real^3 = HD (TL (truncate_simplex 1 vl))`);
 (REWRITE_TAC[ASSUME `vl = [v0;v1;u2;u3:real^3]`; 
   TRUNCATE_SIMPLEX_EXPLICIT_1; HD; TL]);
 (ASM_REWRITE_TAC[TRUNCATE_SIMPLEX_EXPLICIT_1; HD; TL]);
 (ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);

 (ABBREV_TAC `L = aff_ge{u0, u1} {u2, mxi V vl}`);

 (REWRITE_WITH `vol (X INTER D) = vol (L INTER D)`);
 (AP_TERM_TAC);
 (ASM_SIMP_TAC[MCELL_EXPLICIT; TRUNCATE_SIMPLEX_EXPLICIT_2; 
   mcell3; set_of_list; SET_RULE `{a,b,c} UNION {d} = {a,b,c,d}`]);
 (COND_CASES_TAC);
 (ABBREV_TAC `m = mxi V vl`);
 (REWRITE_WITH `mxi V [u0; u1; u2; u3] = m`);
 (EXPAND_TAC "m" THEN DEL_TAC THEN ASM_REWRITE_TAC[]);

 (EXPAND_TAC "L");
 (REWRITE_TAC[SET_RULE `A = B <=> A SUBSET B /\ B SUBSET A`]);
 (STRIP_TAC);
 (MATCH_MP_TAC (SET_RULE `A SUBSET B ==> A INTER X SUBSET B INTER X`));
 (REWRITE_TAC[Marchal_cells_2.CONVEX_HULL_4_SUBSET_AFF_GE_2_2]);
 (MATCH_MP_TAC (SET_RULE `(!x. x IN A /\ x IN B ==> x IN C) ==>
                            A INTER B SUBSET C INTER B`));
 (NEW_GOAL `DISJOINT {u0,u1:real^3} {u2, m}`);
 (REWRITE_TAC[DISJOINT]);
 (MATCH_MP_TAC (MESON[] `(~A:bool ==> F) ==> A`));
 (STRIP_TAC);
 (UNDISCH_TAC `~NULLSET (X INTER D)` THEN REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X:real^3->bool` THEN REWRITE_TAC[SET_RULE `A INTER X SUBSET A`]);


 (ASM_SIMP_TAC[MCELL_EXPLICIT; TRUNCATE_SIMPLEX_EXPLICIT_2; 
   mcell3; set_of_list; SET_RULE `{a,b,c} UNION {d} = {a,b,c,d}`]);
 (REWRITE_WITH `mxi V [u0; u1; u2; u3] = m`);
 (EXPAND_TAC "m" THEN REWRITE_TAC[ASSUME `vl = [u0; u1; u2; u3:real^3]`]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1, u2, m:real^3}`);
 (REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (MATCH_MP_TAC COPLANAR_IMP_NEGLIGIBLE);
 (REWRITE_TAC[COPLANAR_AFFINE_HULL_COPLANAR]);

 (ASM_CASES_TAC `u2 IN {u0, u1:real^3}`);
 (REWRITE_WITH `{u0, u1, u2, m} = {u0, u1, m:real^3}`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_TAC[COPLANAR_3]);
 (NEW_GOAL `m IN {u0, u1:real^3}`);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_WITH `{u0, u1, u2, m} = {u0, u1, u2:real^3}`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_TAC[COPLANAR_3]);

 (SIMP_TAC[ASSUME `DISJOINT {u0, u1} {u2, m:real^3}`; AFF_GE_2_2]);
 (REWRITE_TAC[CONVEX_HULL_4; IN; IN_ELIM_THM]);
 (REPEAT STRIP_TAC);
 (EXISTS_TAC `t1:real` THEN EXISTS_TAC `t2:real` THEN 
   EXISTS_TAC `t3:real` THEN EXISTS_TAC `t4:real`);
 (ASM_REWRITE_TAC[]);
 (STRIP_TAC);

 (REWRITE_TAC[REAL_ARITH `&0 <= a <=> (a < &0 ==> F)`]);
 (STRIP_TAC);
 (UNDISCH_TAC `conic_cap (u0:real^3) u1 r d x`);
 (REWRITE_TAC[MESON[IN] `conic_cap u0 u1 r d x <=> x IN conic_cap u0 u1 r d`;
   GSYM (ASSUME `D = conic_cap (u0:real^3) u1 r d`)]);
 (EXPAND_TAC "D");
 (REWRITE_TAC[IN_INTER; MESON[] `~(x:bool /\ y) <=> (~x \/ ~y)`]);
 (DISJ1_TAC);
 (REWRITE_TAC[IN_BALL] THEN STRIP_TAC);

 (NEW_GOAL `(?b1:real. b1 IN P1 /\ (!x. x IN P1 ==> b1 <= x))`);
 (FIRST_ASSUM MATCH_MP_TAC);
 (REWRITE_TAC[SET_RULE `~(X = {}) <=> (?x. x IN X)`]);
 (EXISTS_TAC `(f1:(real^3)list -> real) vl`);
 (EXPAND_TAC "P1" THEN REWRITE_TAC[IN; IN_ELIM_THM]);
 (EXISTS_TAC `vl:(real^3)list`);
 (ASM_REWRITE_TAC[]);
 (REWRITE_WITH `mcell 3 V [u0; u1; u2; u3] = X`);
 (ASM_REWRITE_TAC[]);
 (STRIP_TAC);
 (UNDISCH_TAC `~NULLSET (X INTER D)` THEN REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X INTER (C:real^3->bool)`);
 (STRIP_TAC);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC (SET_RULE `D SUBSET C ==> X INTER D SUBSET X INTER C`));
 (EXPAND_TAC "D" THEN EXPAND_TAC "C");
 (MATCH_MP_TAC (SET_RULE 
  `A SUBSET B /\ C SUBSET D ==> A INTER C SUBSET B INTER D`));
 (STRIP_TAC);
 (MATCH_MP_TAC SUBSET_BALL);
 (EXPAND_TAC "r" THEN REAL_ARITH_TAC);
 (MATCH_MP_TAC RCONE_GT_SUBSET);
 (EXPAND_TAC "d" THEN REAL_ARITH_TAC);
 (FIRST_X_ASSUM CHOOSE_TAC);

 (NEW_GOAL `r1 = (@b. b IN P1 /\ (!x. x IN P1 ==> b <= x:real))`);
 (EXPAND_TAC "r1");
 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (UP_ASM_TAC THEN REWRITE_TAC[]);
 (REWRITE_TAC[SET_RULE `~(X = {}) <=> (?x. x IN X)`]);
 (EXISTS_TAC `(f1:(real^3)list -> real) vl`);
 (EXPAND_TAC "P1" THEN REWRITE_TAC[IN; IN_ELIM_THM]);
 (EXISTS_TAC `vl:(real^3)list`);
 (ASM_REWRITE_TAC[]);
 (REWRITE_WITH `mcell 3 V [u0; u1; u2; u3] = X`);
 (ASM_SIMP_TAC[]);
 (STRIP_TAC);
 (UNDISCH_TAC `~NULLSET (X INTER D)` THEN REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X INTER (C:real^3->bool)`);
 (STRIP_TAC);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC (SET_RULE `D SUBSET C ==> X INTER D SUBSET X INTER C`));
 (EXPAND_TAC "D" THEN EXPAND_TAC "C");
 (MATCH_MP_TAC (SET_RULE 
  `A SUBSET B /\ C SUBSET D ==> A INTER C SUBSET B INTER D`));
 (STRIP_TAC);
 (MATCH_MP_TAC SUBSET_BALL);
 (EXPAND_TAC "r" THEN REAL_ARITH_TAC);
 (MATCH_MP_TAC RCONE_GT_SUBSET);
 (EXPAND_TAC "d" THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (REWRITE_TAC[]);

 (ABBREV_TAC `Q1 = (\b:real. b IN P1 /\ (!x. x IN P1 ==> b <= x))`);
 (NEW_GOAL `(Q1:real->bool) r1`);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC SELECT_AX);
 (EXISTS_TAC `b1:real` THEN EXPAND_TAC "Q1");
 (ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN EXPAND_TAC "Q1" THEN REPEAT STRIP_TAC);
 (NEW_GOAL `r1 <= f1 (vl:(real^3)list)`);
 (FIRST_ASSUM MATCH_MP_TAC);
 (EXPAND_TAC "P1" THEN REWRITE_TAC[IN; IN_ELIM_THM]);
 (EXISTS_TAC `vl:(real^3)list`);
 (ASM_REWRITE_TAC[]);
 (REWRITE_WITH `mcell 3 V [u0; u1; u2; u3] = X`);
 (ASM_SIMP_TAC[MCELL_EXPLICIT; ARITH_RULE `4 >= 4`]);
 (STRIP_TAC);
 (UNDISCH_TAC `~NULLSET (X INTER D)` THEN REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X INTER (C:real^3->bool)`);
 (STRIP_TAC);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC (SET_RULE `D SUBSET C ==> X INTER D SUBSET X INTER C`));
 (EXPAND_TAC "D" THEN EXPAND_TAC "C");
 (MATCH_MP_TAC (SET_RULE 
  `A SUBSET B /\ C SUBSET D ==> A INTER C SUBSET B INTER D`));
 (STRIP_TAC);
 (MATCH_MP_TAC SUBSET_BALL);
 (EXPAND_TAC "r" THEN REAL_ARITH_TAC);
 (MATCH_MP_TAC RCONE_GT_SUBSET);
 (EXPAND_TAC "d" THEN REAL_ARITH_TAC);

 (UP_ASM_TAC THEN EXPAND_TAC "f1" THEN REWRITE_TAC[EL; HD; TL; 
   ARITH_RULE `3 = SUC 2 /\ 2 = SUC 1 /\ 1 = SUC 0`; 
   ASSUME `vl= [u0; u1; u2; u3:real^3]`]);
 (REWRITE_WITH `mxi V [u0;u1;u2;u3] = m`);
 (EXPAND_TAC "m");
 (REWRITE_TAC[ASSUME `vl = [u0;u1;u2;u3:real^3]`]);
 (STRIP_TAC);

 (NEW_GOAL `!v. v IN affine hull {u1, u2, m:real^3} ==> r1 <= dist (u0, v)`);
 (REPEAT STRIP_TAC);
 (NEW_GOAL `dist (u0,closest_point (affine hull {u1, u2, m}) u0) <= 
             dist (u0, v:real^3)`);
 (MATCH_MP_TAC CLOSEST_POINT_LE);
 (ASM_REWRITE_TAC[CLOSED_AFFINE_HULL]);
 (UP_ASM_TAC THEN DEL_TAC THEN UP_ASM_TAC THEN REAL_ARITH_TAC);

 (NEW_GOAL `r <= dist (u0:real^3, x)`);
 (REWRITE_TAC[dist]);
 (REWRITE_WITH `u0:real^3 - x = (t1 + t2 + t3 + t4) % u0 - x`);
 (ASM_REWRITE_TAC[] THEN VECTOR_ARITH_TAC);
 (REWRITE_TAC[VECTOR_ADD_RDISTRIB]);
 (ASM_REWRITE_TAC[VECTOR_ARITH `(t1 % u0 + t2 % u0 + t3 % u0 + t4 % u0) -
  (t1 % u0 + t2 % u1 + t3 % u2 + t4 % u3) = 
  (t2 + t3 + t4) % u0 - (t2 % u1 + t3 % u2 + t4 % u3)`]);
 (ABBREV_TAC `y:real^3 = t2 /(t2 + t3 + t4) % u1 + 
                          t3 /(t2 + t3 + t4) % u2 + 
                          t4 /(t2 + t3 + t4) % m`);
 (REWRITE_WITH `(t2 % u1 + t3 % u2 + t4 % m) = (t2 + t3 + t4) % (y:real^3)`);
 (EXPAND_TAC "y");
 (REWRITE_TAC[VECTOR_ARITH `x % (t2 / x % u1 +  t3 / x % u2 + t4 / x % u3) = 
   (x / x) % (t2 % u1 + t3 % u2 + t4 % u3)`]);
 (REWRITE_WITH `(t2 + t3 + t4) / (t2 + t3 + t4) = &1`);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (UNDISCH_TAC `t1 < &0` THEN UNDISCH_TAC `t1 + t2 + t3 + t4 = &1`);
 (REAL_ARITH_TAC);
 (VECTOR_ARITH_TAC);
 (REWRITE_TAC[VECTOR_ARITH `a % x - a % y = a % (x - y)`; NORM_MUL]);

 (NEW_GOAL `&1 < t2 + t3 + t4`);
 (UNDISCH_TAC `t1 < &0` THEN UNDISCH_TAC `t1 + t2 + t3 + t4 = &1`);
 (REAL_ARITH_TAC);
 (REWRITE_WITH `abs (t2 + t3 + t4) = t2 + t3 + t4`); 
 (REWRITE_TAC[REAL_ABS_REFL] THEN UP_ASM_TAC THEN REAL_ARITH_TAC);
 (REWRITE_TAC[GSYM dist]);
 (NEW_GOAL `r1 <= dist (u0, y:real^3)`);
 (FIRST_ASSUM MATCH_MP_TAC);
 (REWRITE_TAC[AFFINE_HULL_3; IN; IN_ELIM_THM]);
 (EXISTS_TAC `t2 / (t2 + t3 + t4)` THEN EXISTS_TAC `t3 / (t2 + t3 + t4)` THEN
   EXISTS_TAC `t4 / (t2 + t3 + t4)`);
 (STRIP_TAC);
 (REWRITE_TAC[REAL_ARITH `a / x + b / x + c / x = (a+b+c)/ x`]);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (UP_ASM_TAC THEN REAL_ARITH_TAC);
 (ASM_REWRITE_TAC[]);

 (NEW_GOAL `r1 <= (t2 + t3 + t4) * dist (u0,y:real^3)`);
 (NEW_GOAL `dist (u0,y) <= (t2 + t3 + t4) * dist (u0,y:real^3)`);
 (REWRITE_TAC[REAL_ARITH `a <= b * a <=> &0 <= (b - &1) * a`]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (REWRITE_TAC[DIST_POS_LE]);
 (DEL_TAC THEN UP_ASM_TAC THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN REAL_ARITH_TAC);
 (EXPAND_TAC "r" THEN UP_ASM_TAC THEN REAL_ARITH_TAC);
 (UNDISCH_TAC `dist (u0, x:real^3) < r` THEN UP_ASM_TAC THEN REAL_ARITH_TAC);

(* ========================================================================== *)

 (REWRITE_TAC[REAL_ARITH `&0 <= a <=> (a < &0 ==> F)`]);
 (STRIP_TAC);
 (UNDISCH_TAC `conic_cap (u0:real^3) u1 r d x`);
 (REWRITE_TAC[MESON[IN] `conic_cap u0 u1 r d x <=> x IN conic_cap u0 u1 r d`;
   GSYM (ASSUME `D = conic_cap (u0:real^3) u1 r d`)]);
 (EXPAND_TAC "D");
 (REWRITE_TAC[IN_INTER; MESON[] `~(x:bool /\ y) <=> (~x \/ ~y)`]);
 (DISJ2_TAC);
 (REWRITE_TAC[IN; IN_ELIM_THM; rcone_gt; rconesgn] THEN STRIP_TAC);

 (NEW_GOAL `(?b1:real. b1 IN P3 /\ (!x. x IN P3 ==> x <= b1))`);
 (FIRST_ASSUM MATCH_MP_TAC);
 (REWRITE_TAC[SET_RULE `~(X = {}) <=> (?x. x IN X)`]);
 (EXISTS_TAC `(f3:(real^3)list -> real) vl`);
 (EXPAND_TAC "P3" THEN REWRITE_TAC[IN; IN_ELIM_THM]);
 (EXISTS_TAC `vl:(real^3)list`);
 (ASM_REWRITE_TAC[]);
 (REWRITE_WITH `mcell 3 V [u0; u1; u2; u3] = X`);
 (ASM_SIMP_TAC[MCELL_EXPLICIT]);
 (STRIP_TAC);
 (UNDISCH_TAC `~NULLSET (X INTER D)` THEN REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X INTER (C:real^3->bool)`);
 (STRIP_TAC);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC (SET_RULE `D SUBSET C ==> X INTER D SUBSET X INTER C`));
 (EXPAND_TAC "D" THEN EXPAND_TAC "C");
 (MATCH_MP_TAC (SET_RULE 
  `A SUBSET B /\ C SUBSET D ==> A INTER C SUBSET B INTER D`));
 (STRIP_TAC);
 (MATCH_MP_TAC SUBSET_BALL);
 (EXPAND_TAC "r" THEN REAL_ARITH_TAC);
 (MATCH_MP_TAC RCONE_GT_SUBSET);
 (EXPAND_TAC "d" THEN REAL_ARITH_TAC);
 (FIRST_X_ASSUM CHOOSE_TAC);

 (NEW_GOAL `d1 = (@b. b IN P3 /\ (!x. x IN P3 ==> x <= b:real))`);
 (EXPAND_TAC "d1");
 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (UP_ASM_TAC THEN REWRITE_TAC[]);
 (REWRITE_TAC[SET_RULE `~(X = {}) <=> (?x. x IN X)`]);
 (EXISTS_TAC `(f3:(real^3)list -> real) vl`);
 (EXPAND_TAC "P3" THEN REWRITE_TAC[IN; IN_ELIM_THM]);
 (EXISTS_TAC `vl:(real^3)list`);
 (ASM_REWRITE_TAC[]);
 (REWRITE_WITH `mcell 3 V [u0; u1; u2; u3] = X`);
 (ASM_SIMP_TAC[MCELL_EXPLICIT]);
 (STRIP_TAC);
 (UNDISCH_TAC `~NULLSET (X INTER D)` THEN REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X INTER (C:real^3->bool)`);
 (STRIP_TAC);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC (SET_RULE `D SUBSET C ==> X INTER D SUBSET X INTER C`));
 (EXPAND_TAC "D" THEN EXPAND_TAC "C");
 (MATCH_MP_TAC (SET_RULE 
  `A SUBSET B /\ C SUBSET D ==> A INTER C SUBSET B INTER D`));
 (STRIP_TAC);
 (MATCH_MP_TAC SUBSET_BALL);
 (EXPAND_TAC "r" THEN REAL_ARITH_TAC);
 (MATCH_MP_TAC RCONE_GT_SUBSET);
 (EXPAND_TAC "d" THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (REWRITE_TAC[]);

 (ABBREV_TAC `Q1 = (\b:real. b IN P3 /\ (!x. x IN P3 ==> x <= b))`);
 (NEW_GOAL `(Q1:real->bool) d1`);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC SELECT_AX);
 (EXISTS_TAC `b1:real` THEN EXPAND_TAC "Q1");
 (ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN EXPAND_TAC "Q1" THEN REPEAT STRIP_TAC);

 (NEW_GOAL `f3 (vl:(real^3)list) <= d1`);
 (FIRST_ASSUM MATCH_MP_TAC);
 (EXPAND_TAC "P3" THEN REWRITE_TAC[IN; IN_ELIM_THM]);
 (EXISTS_TAC `vl:(real^3)list`);
 (ASM_REWRITE_TAC[]);
 (REWRITE_WITH `mcell 3 V [u0; u1; u2; u3] = X`);
 (ASM_SIMP_TAC[MCELL_EXPLICIT]);
 (STRIP_TAC);
 (UNDISCH_TAC `~NULLSET (X INTER D)` THEN REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X INTER (C:real^3->bool)`);
 (STRIP_TAC);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC (SET_RULE `D SUBSET C ==> X INTER D SUBSET X INTER C`));
 (EXPAND_TAC "D" THEN EXPAND_TAC "C");
 (MATCH_MP_TAC (SET_RULE 
  `A SUBSET B /\ C SUBSET D ==> A INTER C SUBSET B INTER D`));
 (STRIP_TAC);
 (MATCH_MP_TAC SUBSET_BALL);
 (EXPAND_TAC "r" THEN REAL_ARITH_TAC);
 (MATCH_MP_TAC RCONE_GT_SUBSET);
 (EXPAND_TAC "d" THEN REAL_ARITH_TAC);

 (UP_ASM_TAC THEN EXPAND_TAC "f3");
 (REWRITE_TAC[EL; HD; TL; 
   ARITH_RULE `3 = SUC 2 /\ 2 = SUC 1 /\ 1 = SUC 0`; ASSUME `mxi V vl = m`; 
   ASSUME `vl= [u0; u1; u2; u3:real^3]`] THEN STRIP_TAC);

 (ABBREV_TAC `xx = smallest_angle_line u2 m u0 u1`);

 (MP_TAC (ASSUME `smallest_angle_line u2 m u0 u1 = xx`));
 (REWRITE_TAC[smallest_angle_line; smallest_angle_set]);
 (ABBREV_TAC `Q2 = 
 (\x:real^3. x IN convex hull {u2, m} /\
             (!y. y IN convex hull {u2, m}
                  ==> ((y - u0) dot (u1 - u0)) /
                      (norm (y - u0) * norm (u1 - u0)) <=
                      ((x - u0) dot (u1 - u0)) /
                      (norm (x - u0) * norm (u1 - u0))))`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ] THEN STRIP_TAC);
 (NEW_GOAL `(Q2:real^3->bool) xx`);
 (ONCE_ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC SELECT_AX);
 (EXPAND_TAC "Q2");

 (MATCH_MP_TAC SMALLEST_ANGLE_LINE_EXISTS);
 (STRIP_TAC);
 (ASM_REWRITE_TAC[]);
 (STRIP_TAC);

 (UNDISCH_TAC `~NULLSET (X INTER D)`);
 (REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X:real^3->bool` THEN STRIP_TAC);
 (ASM_SIMP_TAC[MCELL_EXPLICIT; mcell3; set_of_list;TRUNCATE_SIMPLEX_EXPLICIT_2;
    SET_RULE `{a,b,c} UNION {d} = {a,b,c,d}`]);
 (REWRITE_WITH `mxi V [u0;u1;u2;u3] = m`);
 (EXPAND_TAC "m");
 (REWRITE_TAC[ASSUME `vl = [u0; u1; u2; u3:real^3]`]);

 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);

 (EXISTS_TAC `affine hull {u0, u1, u2, m:real^3}`);
 (STRIP_TAC);
 (MATCH_MP_TAC COPLANAR_IMP_NEGLIGIBLE);
 (REWRITE_TAC[COPLANAR_AFFINE_HULL_COPLANAR]);
 (REWRITE_TAC[coplanar]);
 (UNDISCH_TAC `u0 IN convex hull {u2, m:real^3}`);
 (REWRITE_TAC[CONVEX_HULL_2; IN; IN_ELIM_THM] THEN STRIP_TAC);
 (EXISTS_TAC `u1:real^3` THEN EXISTS_TAC `u2:real^3` THEN 
   EXISTS_TAC `m:real^3`);
 (MATCH_MP_TAC (SET_RULE `a IN s /\ b SUBSET s ==> (a INSERT b) SUBSET s`));
 (REWRITE_TAC[SET_SUBSET_AFFINE_HULL]);
 (REWRITE_TAC[AFFINE_HULL_3; IN; IN_ELIM_THM]);
 (EXISTS_TAC `&0` THEN EXISTS_TAC `u:real` THEN EXISTS_TAC `v:real`);
 (STRIP_TAC);
 (UNDISCH_TAC `u + v = &1` THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN VECTOR_ARITH_TAC);
 (ASM_REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);
 (SET_TAC[]);

 (UP_ASM_TAC THEN EXPAND_TAC "Q2");
 (STRIP_TAC);
 (ABBREV_TAC `g = (\y:real^3. ((y - u0) dot (u1 - u0)) / 
                               (norm (y - u0) * norm (u1 - u0)))`);

 (NEW_GOAL `d < (g:real^3->real) x`);
 (EXPAND_TAC "g");
 (REWRITE_WITH 
  `d < ((x - u0) dot (u1 - u0)) / (norm (x - u0) * norm (u1 - u0:real^3)) <=>
   d * (norm (x - u0) * norm (u1 - u0)) < (x - u0) dot (u1 - u0)`);
 (MATCH_MP_TAC REAL_LT_RDIV_EQ);
 (MATCH_MP_TAC (REAL_ARITH `&0 <= a /\ ~(a = &0) ==> &0 < a`));
 (STRIP_TAC);
 (MATCH_MP_TAC REAL_LE_MUL);
 (ASM_REWRITE_TAC[NORM_POS_LE]);
 (REWRITE_TAC[REAL_ENTIRE; NORM_EQ_0; VECTOR_ARITH `x - y = vec 0 <=> x = y`]);
 (ASM_REWRITE_TAC[]);
 (REWRITE_WITH `t1 % u0 + t2 % u1 + t3 % u2 + t4 % m = u0:real^3 <=>
  t1 % u0 + t2 % u1 + t3 % u2 + t4 % m = (t1 + t2 + t3 + t4) % u0`);
 (ASM_REWRITE_TAC[] THEN VECTOR_ARITH_TAC);
 (REWRITE_TAC[VECTOR_ARITH `t1 % u0 + u = (t1 + t2) % u0 <=> u = t2 % u0`]);
 (STRIP_TAC);

 (MP_TAC (ASSUME `~NULLSET (X INTER D)`) THEN REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X:real^3->bool` THEN STRIP_TAC);
 (ASM_SIMP_TAC[MCELL_EXPLICIT; mcell3;set_of_list; 
   TRUNCATE_SIMPLEX_EXPLICIT_2; SET_RULE `{a,b,c} UNION {d} = {a,b,c,d}`]);
 (REWRITE_WITH `mxi V [u0;u1;u2;u3] = m`);
 (EXPAND_TAC "m");
 (REWRITE_TAC[ASSUME `vl = [u0; u1; u2; u3:real^3]`]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);

 (EXISTS_TAC `affine hull {u0, u1, u2, m:real^3}`);
 (REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (MATCH_MP_TAC COPLANAR_IMP_NEGLIGIBLE);
 (REWRITE_TAC[COPLANAR_AFFINE_HULL_COPLANAR]);
 (MATCH_MP_TAC Rogers.AFF_DIM_LE_2_IMP_COPLANAR);
 (MATCH_MP_TAC Njiutiu.AFF_DEPENDENT_AFF_DIM_4);
 (REWRITE_TAC[affine_dependent]);
 (EXISTS_TAC `u1:real^3`);
 (STRIP_TAC);
 (SET_TAC[]);

 (NEW_GOAL `~(u1 IN {u0, u2, m:real^3})`);
 (STRIP_TAC);
 (MP_TAC (ASSUME `~NULLSET (X INTER D)`) THEN REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X:real^3->bool` THEN STRIP_TAC);
 (ASM_SIMP_TAC[MCELL_EXPLICIT; mcell3;set_of_list; 
   TRUNCATE_SIMPLEX_EXPLICIT_2; SET_RULE `{a,b,c} UNION {d} = {a,b,c,d}`]);
 (REWRITE_WITH `mxi V [u0;u1;u2;u3] = m`);
 (EXPAND_TAC "m");
 (REWRITE_TAC[ASSUME `vl = [u0; u1; u2; u3:real^3]`]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1, u2, m:real^3}`);
 (REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (MATCH_MP_TAC COPLANAR_IMP_NEGLIGIBLE);
 (REWRITE_TAC[COPLANAR_AFFINE_HULL_COPLANAR]);
 (REWRITE_WITH `{u0, u1, u2, m} = {u0:real^3,u2, m}`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_TAC[COPLANAR_3]);
 (SET_TAC[]);
 (REWRITE_WITH `{u0, u1, u2, m} DELETE u1 = {u0, u2, m:real^3}`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_TAC[AFFINE_HULL_3; IN; IN_ELIM_THM]);
 (EXISTS_TAC `(t2 + t3 + t4) / t2`);
 (EXISTS_TAC `(-- t3) / t2`);
 (EXISTS_TAC `(-- t4) / t2`);

 (STRIP_TAC);
 (REWRITE_WITH `(t2 + t3 + t4) / t2 + --t3 / t2 + --t4 / t2 = t2 / t2`);
 (REAL_ARITH_TAC);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (UNDISCH_TAC `t2 < &0` THEN REAL_ARITH_TAC);
 (REWRITE_WITH 
  `u1 = (t2 + t3 + t4) / t2 % u0 + --t3 / t2 % u2 + --t4 / t2 % m:real^3 <=> 
   u1 = (&1 / t2) % ((t2 + t3 + t4) % u0 - t3 % u2 - t4 % m)`);
 (VECTOR_ARITH_TAC);
 (REWRITE_TAC[GSYM (ASSUME `t2 % u1 + t3 % u2 + t4 % m = 
                             (t2 + t3 + t4) % u0:real^3`)]);
 (REWRITE_TAC[VECTOR_ARITH 
  `(t2 % u1 + t3 % u2 + t4 % u3) - t3 % u2 - t4 % u3 = t2 % u1`]);
 (REWRITE_TAC[VECTOR_MUL_ASSOC]);
 (REWRITE_WITH `&1 / t2 * t2 = &1`);
 (REWRITE_TAC[REAL_ARITH `&1 / t2 * t2 = t2 / t2`]);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (UNDISCH_TAC `t2 < &0` THEN REAL_ARITH_TAC);
 (VECTOR_ARITH_TAC);
 (SET_TAC[]);
 (REWRITE_TAC[REAL_ARITH `a * b * c < d <=> d > b * c * a`; GSYM dist]);
 (ASM_REWRITE_TAC[]);

 (NEW_GOAL `g x <= (g:real^3->real) xx`);
 (NEW_GOAL `!y. y IN convex hull {u2 , m:real^3} ==> g y <= g xx`);
 (EXPAND_TAC "g" THEN ASM_REWRITE_TAC[]);
 (NEW_GOAL `&0 < (t3 + t4)`);
 (MATCH_MP_TAC (REAL_ARITH `(&0 <= x) /\ ~(x = &0)  ==> &0 < x`));
 (STRIP_TAC);
 (MATCH_MP_TAC REAL_LE_ADD);
 (ASM_REWRITE_TAC[]);
 (STRIP_TAC);
 (NEW_GOAL `t3 = &0 /\ t4 = &0`);
 (UNDISCH_TAC `&0 <= t3` THEN UNDISCH_TAC `&0 <= t4` THEN 
   UP_ASM_TAC THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN STRIP_TAC);

 (NEW_GOAL `F`);
 (UNDISCH_TAC `(x - u0) dot (u1 - u0:real^3) > dist (x,u0) * dist (u1,u0) * d`);
 (REWRITE_WITH `x = t1 % u0 + t2 % u1:real^3`);
 (ASM_REWRITE_TAC[] THEN VECTOR_ARITH_TAC);
 (MATCH_MP_TAC (REAL_ARITH `a <= &0 /\ &0 <= b ==> ~(a > b)`));
 (STRIP_TAC);
 (REWRITE_WITH `(t1 % u0 + t2 % u1) - u0 = (t1 % u0 + t2 % u1) - 
                 (t1 + t2 + t3 + t4) % u0:real^3`);
 (ASM_REWRITE_TAC[] THEN VECTOR_ARITH_TAC);
 (REWRITE_TAC[ASSUME `t3 = &0`; ASSUME `t4 = &0`; VECTOR_ARITH 
  `(t1 % u0 + t2 % u1) - (t1 + t2 + &0 + &0) % u0 = t2 % (u1 - u0)`; 
   DOT_LMUL; REAL_ARITH `a * b <= &0 <=> &0 <= (--a) * b`]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (REWRITE_TAC[DOT_POS_LE]);
 (UNDISCH_TAC `t2 < &0` THEN REAL_ARITH_TAC);
 (MATCH_MP_TAC REAL_LE_MUL);
 (REWRITE_TAC[DIST_POS_LE]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (REWRITE_TAC[DIST_POS_LE]);
 (EXPAND_TAC "d" THEN UNDISCH_TAC `&0 < c/\ c < &1`);
 (REAL_ARITH_TAC);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (ABBREV_TAC `y = t3 / (t3 + t4) % u2 + t4 / (t3 + t4) % m:real^3`);
 (NEW_GOAL `(g:real^3->real) y <= g xx`);
 (FIRST_ASSUM MATCH_MP_TAC);
 (REWRITE_TAC[CONVEX_HULL_2; IN; IN_ELIM_THM]);
 (EXISTS_TAC `t3 / (t3 + t4)` THEN EXISTS_TAC `t4 / (t3 + t4)`);
 (REPEAT STRIP_TAC);
 (MATCH_MP_TAC REAL_LE_DIV);
 (ASM_SIMP_TAC[REAL_LE_ADD]);
 (ASM_SIMP_TAC[REAL_LE_ADD; REAL_LE_DIV]);
 (REWRITE_TAC[REAL_ARITH `a / x + b / x = (a + b) / x`]);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (UNDISCH_TAC `&0 < t3 + t4` THEN REAL_ARITH_TAC);
 (ASM_REWRITE_TAC[]);

 (ABBREV_TAC `w = t1 / (t1 + t3 + t4) % u0 + t3 / (t1 + t3 + t4) % u2 + 
                   t4 / (t1 + t3 + t4) % m:real^3`);
 (NEW_GOAL `(g:real^3->real) y = g w`);
 (EXPAND_TAC "g");

 (REWRITE_WITH `y:real^3 - u0 = 
                &1 / (t3 + t4) % (t3 % u2 + t4 % m - (t3 + t4) % u0)`);
 (EXPAND_TAC "y");
 (REWRITE_TAC[VECTOR_ARITH 
  `(t3 / (t3 + t4) % u2 + t4 / (t3 + t4) % u3) - u0 =
   &1 / (t3 + t4) % (t3 % u2 + t4 % u3 - (t3 + t4) % u0) <=> 
   (t3 + t4) / (t3 + t4) % u0 = u0`]);
 (REWRITE_WITH `(t3 + t4) / (t3 + t4) = &1`);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (UNDISCH_TAC `&0 < t3 + t4` THEN REAL_ARITH_TAC);
 (VECTOR_ARITH_TAC);
 (REWRITE_TAC[NORM_MUL; DOT_LMUL]);

 (REWRITE_WITH `w:real^3 - u0 = 
                &1 / (t1 + t3 + t4) % (t3 % u2 + t4 % m - (t3 + t4) % u0)`);
 (EXPAND_TAC "w");
 (REWRITE_TAC[VECTOR_ARITH 
   `(t1 / (t1 + t3 + t4) % u0 +
    t3 / (t1 + t3 + t4) % u2 + t4 / (t1 + t3 + t4) % u3) - u0 =
    &1 / (t1 + t3 + t4) % (t3 % u2 + t4 % u3 - (t3 + t4) % u0) <=> 
    (t1 + t3 + t4) / (t1 + t3 + t4) % u0 = u0`]);
 (REWRITE_WITH `(t1 + t3 + t4) / (t1 + t3 + t4) = &1`);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (UNDISCH_TAC `t2 < &0` THEN UNDISCH_TAC `t1 + t2 + t3 + t4 = &1` 
   THEN REAL_ARITH_TAC);
 (VECTOR_ARITH_TAC);
 (REWRITE_TAC[NORM_MUL; DOT_LMUL]);
 (REWRITE_WITH `abs (&1 / (t3 + t4)) = &1 / (t3 + t4)`);
 (REWRITE_TAC[REAL_ABS_REFL]);
 (ASM_SIMP_TAC[REAL_LE_DIV;REAL_LE_ADD; REAL_ARITH `&0 <= &1`]);
 (REWRITE_WITH `abs (&1 / (t1 + t3 + t4)) = &1 / (t1 + t3 + t4)`);
 (REWRITE_TAC[REAL_ABS_REFL]);
 (MATCH_MP_TAC REAL_LE_DIV THEN REWRITE_TAC[REAL_ARITH `&0 <= &1`]);
 (UNDISCH_TAC `t2 < &0` THEN UNDISCH_TAC `t1 + t2 + t3 + t4 = &1` 
   THEN REAL_ARITH_TAC);
 (REWRITE_TAC[REAL_ARITH `(a * x) / ((a * y) * z) = 
                           (a * x) / (a * (y * z))`]);
 (ABBREV_TAC 
  `a1 = norm (t3 % u2 + t4 % m - (t3 + t4) % u0) * norm (u1 - u0:real^3)`);
 (NEW_GOAL `~(a1 = &0)`);
 (EXPAND_TAC "a1" THEN ASM_REWRITE_TAC[REAL_ENTIRE; NORM_EQ_0; 
   VECTOR_ARITH `(a - b = vec 0 <=> a = b)/\(a + b-c = vec 0 <=> a + b = c)`]);
 (STRIP_TAC);

 (UNDISCH_TAC `~NULLSET (X INTER D)` THEN REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `(X:real^3->bool)`);
 (STRIP_TAC);

 (ASM_SIMP_TAC[mcell3; MCELL_EXPLICIT; TRUNCATE_SIMPLEX_EXPLICIT_2; 
                set_of_list; SET_RULE `{a,b,c} UNION {d} = {a,b,c,d}`]);
 (REWRITE_WITH `mxi V [u0;u1;u2;u3] = m`);
 (EXPAND_TAC "m");
 (REWRITE_TAC[ASSUME `vl = [u0; u1; u2; u3:real^3]`]);

 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1, u2, m:real^3}`);
 (REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (MATCH_MP_TAC COPLANAR_IMP_NEGLIGIBLE);
 (REWRITE_TAC[COPLANAR_AFFINE_HULL_COPLANAR]);
 (REWRITE_TAC[coplanar]);
 (EXISTS_TAC `u1:real^3` THEN EXISTS_TAC `u2:real^3` THEN 
   EXISTS_TAC `m:real^3`);
 (MATCH_MP_TAC (SET_RULE `u0 IN S /\ b SUBSET S ==> (u0 INSERT b) SUBSET S`));
 (REWRITE_TAC[SET_SUBSET_AFFINE_HULL]);
 (REWRITE_TAC[AFFINE_HULL_3; IN; IN_ELIM_THM]);
 (EXISTS_TAC `&0` THEN EXISTS_TAC `t3 / (t3 + t4)` 
   THEN EXISTS_TAC `t4 / (t3 + t4)`);
 (REPEAT STRIP_TAC);
 (REWRITE_TAC[REAL_ARITH `&0 + t3 / (t3 + t4) + t4 / (t3 + t4) = 
                          (t3 + t4) / (t3 + t4)`]);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (UNDISCH_TAC `&0 < t3 + t4` THEN REAL_ARITH_TAC);
 (ASM_REWRITE_TAC[VECTOR_ARITH 
   `&0 % u1 + t3 / (t3 + t4) % u2 + t4 / (t3 + t4) % u3 = 
    (&1 / (t3 + t4)) % (t3 % u2 + t4 % u3)`]);
 (REWRITE_TAC[VECTOR_MUL_ASSOC; REAL_ARITH `&1 / a * a = a / a`]);
 (REWRITE_WITH `(t3 + t4) / (t3 + t4) = &1`);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (UNDISCH_TAC `&0 < t3 + t4` THEN REAL_ARITH_TAC);
 (VECTOR_ARITH_TAC);
 (SET_TAC[]);

 (NEW_GOAL `~(&1 / (t3 + t4) = &0)`);
 (NEW_GOAL `&0 < &1 / (t3 + t4)`);
 (MATCH_MP_TAC REAL_LT_DIV);
 (ASM_REWRITE_TAC[REAL_ARITH `&0 < &1`]);
 (UP_ASM_TAC THEN REAL_ARITH_TAC);

 (REWRITE_WITH 
 `(&1 / (t3 + t4) * ((t3 % u2 + t4 % m - (t3 + t4) % u0) dot (u1 - u0))) /
  (&1 / (t3 + t4) * a1) = 
  ((t3 % u2 + t4 % m - (t3 + t4) % u0) dot (u1 - u0:real^3)) / a1`);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN MESON_TAC[Trigonometry1.REAL_DIV_MUL2]);

 (NEW_GOAL `~(&1 / (t1 + t3 + t4) = &0)`);
 (NEW_GOAL `&0 < &1 / (t1 + t3 + t4)`);
 (MATCH_MP_TAC REAL_LT_DIV);
 (ASM_REWRITE_TAC[REAL_ARITH `&0 < &1`]);
 (UNDISCH_TAC `t2 < &0` THEN UNDISCH_TAC `t1 + t2 + t3 + t4 = &1` THEN
   REAL_ARITH_TAC);
 (UP_ASM_TAC THEN REAL_ARITH_TAC);

 (REWRITE_WITH 
 `(&1 / (t1 + t3 + t4) * ((t3 % u2 + t4 % m - (t3 + t4) % u0) dot (u1 - u0))) /
  (&1 / (t1 + t3 + t4) * a1) = 
  ((t3 % u2 + t4 % m - (t3 + t4) % u0) dot (u1 - u0:real^3)) / a1`);
 (UP_ASM_TAC THEN UNDISCH_TAC `~(a1 = &0)` THEN
   MESON_TAC[Trigonometry1.REAL_DIV_MUL2]);

 (NEW_GOAL `(g:real^3->real) x <= g w`);
 (EXPAND_TAC "g");

 (REWRITE_WITH 
  `((x - u0) dot (u1 - u0:real^3)) / (norm (x - u0) * norm (u1 - u0)) <=
  ((w - u0) dot (u1 - u0)) / (norm (w - u0) * norm (u1 - u0)) <=>
  ((x - u0) dot (u1 - u0)) * (norm (w - u0) * norm (u1 - u0)) <= 
  ((w - u0) dot (u1 - u0)) * (norm (x - u0) * norm (u1 - u0))`);
 (MATCH_MP_TAC RAT_LEMMA4);
 (STRIP_TAC);
 (MATCH_MP_TAC REAL_LT_MUL);
 (ASM_REWRITE_TAC[NORM_POS_LT; VECTOR_ARITH `x - b = vec 0 <=> x = b`]);
 (STRIP_TAC);
 (UNDISCH_TAC `~NULLSET (X INTER D)`);
 (REWRITE_TAC[]);

 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `(X:real^3->bool)`);
 (STRIP_TAC);
 (ASM_SIMP_TAC[mcell3; MCELL_EXPLICIT; TRUNCATE_SIMPLEX_EXPLICIT_2; set_of_list;
   SET_RULE `{a,b,c} UNION {d} = {a,b,c,d}`]);
 (REWRITE_WITH `mxi V [u0;u1;u2;u3] = m`);
 (EXPAND_TAC "m");
 (REWRITE_TAC[ASSUME `vl = [u0; u1; u2; u3:real^3]`]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1, u2, m:real^3}`);
 (REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (MATCH_MP_TAC COPLANAR_IMP_NEGLIGIBLE);
 (REWRITE_TAC[COPLANAR_AFFINE_HULL_COPLANAR]);
 (REWRITE_TAC[coplanar]);
 (EXISTS_TAC `u0:real^3` THEN EXISTS_TAC `u2:real^3` THEN 
   EXISTS_TAC `m:real^3`);
 (ONCE_REWRITE_TAC[SET_RULE `{u0, u1, u2, u3} = {u1, u0, u2, u3}`]);
 (MATCH_MP_TAC (SET_RULE `u0 IN S /\ b SUBSET S ==> (u0 INSERT b) SUBSET S`));
 (REWRITE_TAC[SET_SUBSET_AFFINE_HULL]);
 (REWRITE_TAC[AFFINE_HULL_3; IN; IN_ELIM_THM]);
 (EXISTS_TAC `(t2 + t3 + t4) / t2` THEN EXISTS_TAC `(--t3) / t2` 
   THEN EXISTS_TAC `(--t4) / t2`);
 (REPEAT STRIP_TAC);
 (REWRITE_TAC[REAL_ARITH 
   `(t2 + t3 + t4) / t2 + --t3 / t2 + --t4 / t2 = t2 / t2`]);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (UNDISCH_TAC `t2 < &0` THEN REAL_ARITH_TAC);
 (REWRITE_WITH `(t2 + t3 + t4) = &1 - t1`);
 (UNDISCH_TAC `t1 + t2 + t3 + t4 = &1` THEN REAL_ARITH_TAC);
 (NEW_GOAL `u0 - t1 % u0 - t3 % u2 - t4 % m:real^3 = t2 % u1`);
 (UP_ASM_TAC THEN VECTOR_ARITH_TAC);
 (ASM_REWRITE_TAC[VECTOR_ARITH 
   `(&1 - t1) / t2 % u0 + --t3 / t2 % u2 + --t4 / t2 % u3 = 
    (&1 / t2) % (u0 - t1 % u0 - t3 % u2 - t4 % u3)`]);
 (REWRITE_TAC[VECTOR_MUL_ASSOC; REAL_ARITH `&1 / a * a = a / a`]);
 (REWRITE_WITH `t2 / t2 = &1`);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (UNDISCH_TAC `t2 < &0` THEN REAL_ARITH_TAC);
 (VECTOR_ARITH_TAC);
 (SET_TAC[]);

 (MATCH_MP_TAC REAL_LT_MUL);
 (ASM_REWRITE_TAC[NORM_POS_LT; VECTOR_ARITH `x - b = vec 0 <=> x = b`]);
 (EXPAND_TAC "w" THEN STRIP_TAC);
 (UNDISCH_TAC `~NULLSET (X INTER D)`);
 (REWRITE_TAC[]);

 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `(X:real^3->bool)`);
 (STRIP_TAC);
 (ASM_SIMP_TAC[mcell3; MCELL_EXPLICIT; TRUNCATE_SIMPLEX_EXPLICIT_2; set_of_list;
   SET_RULE `{a,b,c} UNION {d} = {a,b,c,d}`]);
 (REWRITE_WITH `mxi V [u0;u1;u2;u3] = m`);
 (EXPAND_TAC "m");
 (REWRITE_TAC[ASSUME `vl = [u0; u1; u2; u3:real^3]`]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1, u2, m:real^3}`);
 (REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (MATCH_MP_TAC COPLANAR_IMP_NEGLIGIBLE);
 (REWRITE_TAC[COPLANAR_AFFINE_HULL_COPLANAR]);
 (REWRITE_TAC[coplanar]);
 (EXISTS_TAC `u1:real^3` THEN EXISTS_TAC `u2:real^3` THEN 
   EXISTS_TAC `m:real^3`);
 (MATCH_MP_TAC (SET_RULE `u0 IN S /\ b SUBSET S ==> (u0 INSERT b) SUBSET S`));
 (REWRITE_TAC[SET_SUBSET_AFFINE_HULL]);
 (REWRITE_TAC[AFFINE_HULL_3; IN; IN_ELIM_THM]);

 (EXISTS_TAC `&0` THEN EXISTS_TAC `t3 / (t3 + t4)` 
   THEN EXISTS_TAC `t4 / (t3 + t4)`);
 (REPEAT STRIP_TAC);
 (REWRITE_TAC[REAL_ARITH `&0 + t3 / (t3 + t4) + t4 / (t3 + t4) = 
                          (t3 + t4) / (t3 + t4)`]);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (UNDISCH_TAC `&0 < t3 + t4` THEN REAL_ARITH_TAC);
 (ASM_REWRITE_TAC[VECTOR_ARITH 
   `&0 % u1 + t3 / (t3 + t4) % u2 + t4 / (t3 + t4) % u3 = 
    (&1 / (t3 + t4)) % (t3 % u2 + t4 % u3)`]);
 (UP_ASM_TAC THEN REWRITE_TAC[VECTOR_ARITH 
   `t1 / x % u0 + t3 / x % u2 + t4 / x % u3 = 
    (&1 / x) % (t1 % u0 + t3 % u2 + t4 % u3)`]);
 (REWRITE_WITH `&1 / (t1 + t3 + t4) % (t1 % u0 + t3 % u2 + t4 % m) = u0 <=> 
                 t1 % u0 + t3 % u2 + t4 % m = (t1 + t3 + t4) % u0:real^3`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC Collect_geom.CHANGE_SIDE);
 (UNDISCH_TAC `t2 < &0` THEN UNDISCH_TAC `t1 + t2 +t3 + t4 = &1` THEN 
   REAL_ARITH_TAC);

 (REWRITE_TAC[VECTOR_ARITH `t1 % u0 + t3 % u2 + t4 % u3 = (t1 + t3 + t4) % u0
   <=> t3 % u2 + t4 % u3 = (t3 + t4) % u0`]);
 (STRIP_TAC THEN ASM_REWRITE_TAC[]);
 (REWRITE_TAC[VECTOR_MUL_ASSOC; REAL_ARITH `&1 / a * a = a / a`]);
 (REWRITE_WITH `(t3 + t4) / (t3 + t4) = &1`);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (UNDISCH_TAC `&0 < t3 + t4` THEN REAL_ARITH_TAC);
 (VECTOR_ARITH_TAC);
 (SET_TAC[]);

 (REWRITE_WITH `x = t2 % u1 + (t1 + t3 + t4) % w:real^3`);
 (ASM_REWRITE_TAC[] THEN EXPAND_TAC "w");
 (REWRITE_TAC[VECTOR_ARITH 
  `x % (t1 /x % u0 + t3 / x % u2 + t4 /x  % u3) = 
   (x / x) % (t1 % u0 + t3 % u2 + t4 % u3)`]);
 (REWRITE_WITH `(t1 + t3 + t4) / (t1 + t3 + t4) = &1`);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (UNDISCH_TAC `t2 < &0` THEN UNDISCH_TAC `t1 + t2 + t3 + t4 = &1` THEN
   REAL_ARITH_TAC);
 (VECTOR_ARITH_TAC);
 (ABBREV_TAC `t = t1 + t3 + t4`);
 (REWRITE_WITH `(t2 % u1 + t % w) - u0:real^3 = 
                (t2 % u1 + t % w) - (t1 + t2 + t3 + t4) % u0`);
 (ASM_REWRITE_TAC[] THEN VECTOR_ARITH_TAC);
 (REWRITE_WITH `t1 + t2 + t3 + t4 = t2 + t:real`);
 (EXPAND_TAC "t" THEN REAL_ARITH_TAC);
 (REWRITE_TAC[VECTOR_ARITH 
  `(t2 % u1 + t % w) - (t2 + t) % u0 = t2 % (u1 - u0) + t % (w - u0)`]);
 (ABBREV_TAC `x1 = u1 - u0:real^3`);
 (ABBREV_TAC `x2 = w - u0:real^3`);

 (REWRITE_WITH `(t2 % x1 + t % x2) dot x1 = 
   t2 * norm x1 pow 2 + t * x2 dot (x1:real^3)`);
 (REWRITE_TAC[NORM_POW_2]);
 (VECTOR_ARITH_TAC);

 (NEW_GOAL `t2 * norm x1 pow 2 * norm x2 * norm x1 <= 
             t2 * (x2 dot x1) * norm x1 * norm (x1:real^3)`);
 (REWRITE_TAC[REAL_POW_2; REAL_ARITH `t2 * (x1 * x1) * x2 * x1 <=
   t2 * x3 * x1 * x1 <=> &0 <= (x1 pow 2) * (--t2) * (x2 * x1 - x3)`]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (ASM_SIMP_TAC[REAL_LE_MUL; NORM_POS_LE]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (REWRITE_TAC[REAL_ARITH `&0 <= a - b <=> b <= a`]);
 (STRIP_TAC);
 (UNDISCH_TAC `t2 < &0` THEN REAL_ARITH_TAC);
 (REWRITE_TAC[NORM_CAUCHY_SCHWARZ]);

 (NEW_GOAL 
 `t2 * (x2 dot x1) * norm x1 * norm x1 + t * (x2 dot x1) * norm x2 * norm x1 <=    (x2 dot x1) * norm (t2 % x1 + t % x2) * norm (x1:real^3)`);

 (REWRITE_TAC[REAL_ARITH `t2 * x3 * x1 * x1 + t * x3 * x2 * x1 <=
 x3 * x4 * x1 <=> &0 <= (x1 * x3) * (x4 - t2 * x1 - t * x2)`]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (STRIP_TAC);
 (MATCH_MP_TAC REAL_LE_MUL);
 (REWRITE_TAC[NORM_POS_LE]);
 (ASM_CASES_TAC `x2 dot (x1:real^3) < &0`);
 (NEW_GOAL `F`);
 (NEW_GOAL `(g:real^3->real) x <= &0`);
 (EXPAND_TAC "g");
 (REWRITE_TAC[REAL_ARITH `a / b <= &0 <=> &0 <= (--a) / b`]);
 (MATCH_MP_TAC REAL_LE_DIV);
 (SIMP_TAC[NORM_POS_LE; REAL_LE_MUL]);

 (REWRITE_WITH `x = t2 % u1 + (t1 + t3 + t4) % w:real^3`);
 (ASM_REWRITE_TAC[] THEN EXPAND_TAC "w");
 (REWRITE_TAC[VECTOR_ARITH 
  `x % (t1 /x % u0 + t3 / x % u2 + t4 /x  % u3) = 
   (x / x) % (t1 % u0 + t3 % u2 + t4 % u3)`]);
 (EXPAND_TAC "t");
 (REWRITE_WITH `(t1 + t3 + t4) / (t1 + t3 + t4) = &1`);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (UNDISCH_TAC `t2 < &0` THEN UNDISCH_TAC `t1 + t2 + t3 + t4 = &1` THEN
   REAL_ARITH_TAC);
 (VECTOR_ARITH_TAC);

 (REWRITE_TAC[REAL_ARITH `&0 <= --a <=> a <= &0`]);
 (REWRITE_WITH `(t2 % u1 + (t1 + t3 + t4) % w) - u0:real^3 = 
                 (t2 % u1 + (t1 + t3 + t4) % w) - (t1 + t2 + t3 + t4) % u0`);
 (ASM_REWRITE_TAC[] THEN VECTOR_ARITH_TAC);
 (REWRITE_WITH `(t2 % u1 + (t1 + t3 + t4) % w) - (t1 + t2 + t3 + t4) % u0 = 
   t2 % x1 + t % x2:real^3`);
 (EXPAND_TAC "x1" THEN EXPAND_TAC "x2" THEN EXPAND_TAC "t"
   THEN VECTOR_ARITH_TAC);
 (NEW_GOAL `t % x2 dot (x1:real^3) <= &0`);
 (REWRITE_TAC[DOT_LMUL; REAL_ARITH `a * b <= &0 <=> &0 <= a * (--b)`]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (STRIP_TAC);
 (EXPAND_TAC "t" THEN UNDISCH_TAC `t2 < &0` THEN 
   UNDISCH_TAC `t1 + t2 + t3 + t4 = &1` THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN REAL_ARITH_TAC);
 (NEW_GOAL `t2 % x1 dot (x1:real^3) <= &0`);
 (REWRITE_TAC[DOT_LMUL; REAL_ARITH `a * b <= &0 <=> &0 <= (--a) * b`]);
 (MATCH_MP_TAC REAL_LE_MUL);
 (STRIP_TAC);
 (EXPAND_TAC "t" THEN UNDISCH_TAC `t2 < &0` THEN 
   UNDISCH_TAC `t1 + t2 + t3 + t4 = &1` THEN REAL_ARITH_TAC);
 (REWRITE_TAC[DOT_POS_LE]);
 (REWRITE_TAC[DOT_LADD]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN UNDISCH_TAC `d < (g:real^3->real) x`);
 (EXPAND_TAC "d" THEN UNDISCH_TAC `&0 < c /\ c < &1`);
 (REAL_ARITH_TAC);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (UP_ASM_TAC THEN REAL_ARITH_TAC);

 (REWRITE_TAC [REAL_ARITH `&0 <= a - b * d - c <=> c <= a + (--b) * d`]);
 (REWRITE_WITH `t * norm (x2:real^3) = abs t * norm x2`);
 (AP_THM_TAC THEN AP_TERM_TAC);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (REWRITE_TAC[REAL_ABS_REFL]);
 (EXPAND_TAC "t" THEN UNDISCH_TAC `t2 < &0` THEN 
   UNDISCH_TAC `t1 + t2 + t3 + t4 = &1` THEN REAL_ARITH_TAC);
 (REWRITE_WITH `(--t2) * norm (x1:real^3) = abs (--t2) * norm x1`);
 (AP_THM_TAC THEN AP_TERM_TAC);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (REWRITE_TAC[REAL_ABS_REFL]);
 (UNDISCH_TAC `t2 < &0` THEN REAL_ARITH_TAC);
 (REWRITE_TAC[GSYM NORM_MUL]);
 (REWRITE_WITH 
  `norm (t % x2:real^3) = norm ((t2 % x1 + t % x2) + (--t2 % x1))`);
 (AP_TERM_TAC THEN VECTOR_ARITH_TAC);
 (REWRITE_TAC[NORM_TRIANGLE]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN REAL_ARITH_TAC);
 (UNDISCH_TAC `(g:real^3->real) y <= g xx`);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN REAL_ARITH_TAC);

 (NEW_GOAL `(g:real^3->real) xx <= d1`);
 (FIRST_ASSUM MATCH_MP_TAC);
 (EXPAND_TAC "P3");
 (EXPAND_TAC "g" THEN EXPAND_TAC "f3");
 (REWRITE_TAC[IN_ELIM_THM; IN]);
 (EXISTS_TAC `vl:(real^3)list`);
 (REWRITE_TAC[ASSUME `barV V 3 vl`; ASSUME `vl = [u0;u1;u2;u3:real^3]`; 
               TRUNCATE_SIMPLEX_EXPLICIT_1]);
 (STRIP_TAC);
 (SIMP_TAC[GSYM (ASSUME `vl = [u0; u1; u2; u3:real^3]`)]);
 (REWRITE_WITH `mcell 3 V vl = mcell k V vl`);
 (ASM_SIMP_TAC[]);
 (REWRITE_TAC[GSYM (ASSUME `X = mcell k V vl`)]);
 (STRIP_TAC);

 (UNDISCH_TAC `~NULLSET (X INTER D)` THEN REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X INTER (C:real^3->bool)`);
 (STRIP_TAC);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC (SET_RULE `D SUBSET C ==> X INTER D SUBSET X INTER C`));
 (EXPAND_TAC "D" THEN EXPAND_TAC "C");
 (MATCH_MP_TAC (SET_RULE 
  `A SUBSET B /\ C SUBSET D ==> A INTER C SUBSET B INTER D`));
 (STRIP_TAC);
 (MATCH_MP_TAC SUBSET_BALL);
 (EXPAND_TAC "r" THEN REAL_ARITH_TAC);
 (MATCH_MP_TAC RCONE_GT_SUBSET);
 (EXPAND_TAC "d" THEN REAL_ARITH_TAC);


 (EXPAND_TAC "xx");
 (SIMP_TAC[EL; HD; TL; ARITH_RULE `3 = SUC 2 /\ 2 = SUC 1 /\ 1 = SUC 0`]);
 (REWRITE_WITH `mxi V [u0;u1;u2;u3] = m`);
 (EXPAND_TAC "m");
 (REWRITE_TAC[ASSUME `vl = [u0; u1; u2; u3:real^3]`]);

 (UP_ASM_TAC THEN UP_ASM_TAC THEN UP_ASM_TAC THEN EXPAND_TAC "d");
 (REAL_ARITH_TAC);

 (NEW_GOAL `F`);
 (UNDISCH_TAC `~NULLSET (X INTER D)` THEN REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `(X:real^3->bool)`);
 (STRIP_TAC);
 (ASM_SIMP_TAC[mcell3; MCELL_EXPLICIT; TRUNCATE_SIMPLEX_EXPLICIT_2; 
               set_of_list; SET_RULE `{a,b,c} UNION {d} = {a,b,c,d}`]);
 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);
 (SET_TAC[]);
 (UP_ASM_TAC THEN MESON_TAC[]);

(* ========================================================================= *)

 (ABBREV_TAC `m = mxi V vl`);
 (NEW_GOAL `~coplanar {u0, u1, u2, m:real^3}`);
 (STRIP_TAC);
 (UNDISCH_TAC `~NULLSET (X INTER D)` THEN REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X:real^3->bool`);
 (STRIP_TAC);
 (ASM_SIMP_TAC[mcell3; MCELL_EXPLICIT; set_of_list]);
 (COND_CASES_TAC);
 (REWRITE_TAC[TRUNCATE_SIMPLEX_EXPLICIT_2; set_of_list;
   SET_RULE `{a,b,c} UNION {d} = {a,b,c,d}`]);
 (REWRITE_WITH `mxi V [u0;u1;u2;u3] = m`);
 (EXPAND_TAC "m");
 (REWRITE_TAC[ASSUME `vl = [u0; u1; u2; u3:real^3]`]);

 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1, u2, m:real^3}`);
 (REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (MATCH_MP_TAC COPLANAR_IMP_NEGLIGIBLE);
 (ASM_REWRITE_TAC[COPLANAR_AFFINE_HULL_COPLANAR]);
 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);
 (SET_TAC[]);

 (ASM_CASES_TAC `azim u0 u1 u2 (m:real^3) < pi`);
 (REWRITE_WITH `vol (L INTER D) = vol (D INTER wedge u0 u1 u2 m)`);
 (ASM_SIMP_TAC[WEDGE_LUNE]);
 (REWRITE_WITH `L INTER conic_cap (u0:real^3) u1 r d = 
                 conic_cap u0 u1 r d INTER L`);
 (SET_TAC[]);
 (MATCH_MP_TAC MEASURE_NEGLIGIBLE_SYMDIFF);
 (REWRITE_WITH `conic_cap (u0:real^3) u1 r d INTER 
   aff_gt {u0, u1} {u2, m} DIFF conic_cap u0 u1 r d INTER L = {}`);
 (EXPAND_TAC "L");
 (MATCH_MP_TAC (SET_RULE `A SUBSET B ==> C INTER A DIFF C INTER B = {}`));
 (REWRITE_TAC[AFF_GT_SUBSET_AFF_GE]);
 (REWRITE_TAC[SET_RULE `A UNION {} = A`]);
 (EXPAND_TAC "L");

 (REWRITE_WITH `aff_ge {u0, u1:real^3} {u2, m} =
                 aff_gt {u0, u1} {u2, m} UNION 
   UNIONS {aff_ge {u0, u1} ({u2, m} DELETE a) | a | a IN  {u2, m}}`);
 (MATCH_MP_TAC AFF_GE_AFF_GT_DECOMP);
 (REWRITE_TAC[Geomdetail.FINITE6]);
 (REWRITE_TAC[DISJOINT]);

 (ASM_CASES_TAC `u2 IN {u0, u1:real^3}`);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~coplanar {u0, u1, u2, m:real^3}`);
 (REWRITE_WITH `{u0, u1, u2, m} = {u0, u1, m:real^3}`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_TAC[COPLANAR_3]);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (ASM_CASES_TAC `m IN {u0, u1:real^3}`);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~coplanar {u0, u1, u2, m:real^3}`);
 (REWRITE_WITH `{u0, u1, u2, m} = {u0, u1, u2:real^3}`);
 (UP_ASM_TAC THEN SET_TAC[]); 
 (REWRITE_TAC[COPLANAR_3]);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN SET_TAC[]);

 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC 
  `UNIONS {aff_ge {u0, u1:real^3} ({u2, m} DELETE a) | a | a IN {u2, m}}`);
 (STRIP_TAC);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC 
  `aff_ge {u0, u1:real^3} {u2} UNION aff_ge {u0, u1:real^3} {m}`);
 (STRIP_TAC);
 (MATCH_MP_TAC NEGLIGIBLE_UNION);
 (STRIP_TAC);

 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1:real^3, u2}`);
 (STRIP_TAC);
 (REWRITE_TAC[NEGLIGIBLE_AFFINE_HULL_3]);
 (REWRITE_WITH `{u0,u1,u2:real^3} = {u0,u1} UNION {u2}`);
 (SET_TAC[]);
 (REWRITE_TAC[AFF_GE_SUBSET_AFFINE_HULL]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1:real^3, m}`);
 (STRIP_TAC);
 (REWRITE_TAC[NEGLIGIBLE_AFFINE_HULL_3]);
 (REWRITE_WITH `{u0,u1,m:real^3} = {u0,u1} UNION {m}`);
 (SET_TAC[]);
 (REWRITE_TAC[AFF_GE_SUBSET_AFFINE_HULL]);
 (REWRITE_TAC[SET_RULE 
  `UNIONS {aff_ge {u0, u1} ({m, s3} DELETE a) | a | a IN {m, s3}} = 
         aff_ge {u0, u1} ({m, s3} DELETE s3) 
   UNION aff_ge {u0, u1} ({m, s3} DELETE m)`]);
 (MATCH_MP_TAC (SET_RULE 
  `A SUBSET B /\ C SUBSET D ==> A UNION C SUBSET B UNION D`));
 (STRIP_TAC);
 (MATCH_MP_TAC AFF_GE_MONO_RIGHT);
 (STRIP_TAC);
 (SET_TAC[]);

 (REWRITE_TAC[DISJOINT]);
 (ASM_CASES_TAC `u2 IN {u0, u1:real^3}`);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~coplanar {u0, u1, u2, m:real^3}`);
 (REWRITE_WITH `{u0, u1, u2, m} = {u0, u1, m:real^3}`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_TAC[COPLANAR_3]);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (UP_ASM_TAC THEN SET_TAC[]);

 (MATCH_MP_TAC AFF_GE_MONO_RIGHT);
 (STRIP_TAC);
 (SET_TAC[]);
 (REWRITE_TAC[DISJOINT]);
 (ASM_CASES_TAC `m IN {u0, u1:real^3}`);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~coplanar {u0, u1, u2, m:real^3}`);
 (REWRITE_WITH `{u0, u1, u2, m} = {u0, u1, u2:real^3}`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_TAC[COPLANAR_3]);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (UP_ASM_TAC THEN SET_TAC[]);

 (SET_TAC[]);

(* begin the computation *)

 (REWRITE_TAC[ASSUME `D = conic_cap (u0:real^3) u1 r d`]);
 (REWRITE_WITH `vol (conic_cap u0 u1 r d INTER wedge u0 u1 u2 m) =
             (if &1 < d \/ r < &0
              then &0
              else azim u0 u1 u2 m / &3 * (&1 - max d (-- &1)) * r pow 3)`);
 (NEW_GOAL `~collinear {u0:real^3, u1, u2} /\ ~collinear {u0, u1, m}`);
 (STRIP_TAC);
 (MATCH_MP_TAC NOT_COPLANAR_NOT_COLLINEAR);
 (EXISTS_TAC `m:real^3`);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC NOT_COPLANAR_NOT_COLLINEAR);
 (EXISTS_TAC `u2:real^3`);
 (ONCE_REWRITE_TAC[SET_RULE `{a,b,c,d} = {a,b,d,c}`]);
 (ASM_REWRITE_TAC[]);
 (ASM_SIMP_TAC[VOLUME_CONIC_CAP_WEDGE]);

 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `&0 < r` THEN UNDISCH_TAC `d < &1` THEN 
   UP_ASM_TAC THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (REWRITE_WITH `azim (u0:real^3) u1 u2 m = dihV u0 u1 u2 m`);
 (MATCH_MP_TAC AZIM_DIHV_SAME);
 (ASM_REWRITE_TAC[]);
 (STRIP_TAC);
 (MATCH_MP_TAC NOT_COPLANAR_NOT_COLLINEAR);
 (EXISTS_TAC `m:real^3`);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC NOT_COPLANAR_NOT_COLLINEAR);
 (EXISTS_TAC `u2:real^3`);
 (ONCE_REWRITE_TAC[SET_RULE `{a,b,c,d} = {a,b,d,c}`]);
 (ASM_REWRITE_TAC[]);

 (REWRITE_TAC[dihX]);
 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~NULLSET (X INTER D)`);
 (REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X:real^3->bool`);
 (ASM_REWRITE_TAC[] THEN SET_TAC[]);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (LET_TAC);

 (UP_ASM_TAC THEN REWRITE_TAC[cell_params_d]);
 (ABBREV_TAC `P = (\(k, ul). k <= 4 /\
           ul IN barV V 3 /\
           X = mcell k V ul /\
           initial_sublist [u0; u1] ul)`);
 (STRIP_TAC);
 (NEW_GOAL `(P:num#(real^3)list->bool) ((@) P)`);
 (MATCH_MP_TAC SELECT_AX);
 (EXISTS_TAC `(3, vl:(real^3)list)`);
 (EXPAND_TAC "P");
 (REWRITE_TAC[BETA_THM]);
 (REWRITE_TAC[IN; ARITH_RULE `3 <= 4`] THEN ASM_REWRITE_TAC[]);
 (REWRITE_WITH `initial_sublist [u0;u1:real^3] [u0; u1; u2; u3] /\ 
                 LENGTH [u0;u1] = 1 + 1`);
 (REWRITE_TAC[GSYM Packing3.TRUNCATE_SIMPLEX_INITIAL_SUBLIST]);
 (REWRITE_TAC[GSYM (ASSUME `vl = [u0; u1; u2; u3:real^3]`)]);
 (ASM_REWRITE_TAC[]);
 (REWRITE_TAC[LENGTH] THEN ARITH_TAC);
 (UP_ASM_TAC THEN ASM_REWRITE_TAC[]);
 (EXPAND_TAC "P" THEN REWRITE_TAC[IN] THEN REPEAT STRIP_TAC);

 (NEW_GOAL `k' = 3 /\ mcell k' V ul = mcell 3 V vl`);
 (MATCH_MP_TAC Ajripqn.AJRIPQN);
 (ASM_REWRITE_TAC[]);
 (REWRITE_TAC[GSYM (ASSUME `vl = [u0; u1; u2; u3:real^3]`)]);
 (REWRITE_WITH `mcell k' V ul INTER mcell 3 V vl = X`);
 (REWRITE_WITH `mcell 3 V vl = X`);
 (ASM_SIMP_TAC[]);
 (SET_TAC[ASSUME `X = mcell k' V ul`]);

 (REPEAT STRIP_TAC);
 (UNDISCH_TAC `k' <= 4` THEN REWRITE_TAC[ARITH_RULE 
   `a <= 4 <=> a = 0 \/a = 1 \/ a = 2 \/ a = 3 \/ a = 4`] THEN SET_TAC[]);
 (SET_TAC[]);
 (UP_ASM_TAC THEN UNDISCH_TAC `~NULLSET X` THEN MESON_TAC[]);

 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN ARITH_TAC);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (COND_CASES_TAC);

 (REWRITE_TAC[dihu3]);

 (REWRITE_WITH `dihV (EL 0 ul) (EL 1 ul) (EL 2 ul) (mxi V ul) = 
   dihV u0 u1 u2 (m:real^3)`);

 (NEW_GOAL `truncate_simplex 1 ul = [u0;u1:real^3] /\ 1 + 1 <= LENGTH ul`);
 (REWRITE_TAC[Packing3.TRUNCATE_SIMPLEX_INITIAL_SUBLIST]);
 (ASM_REWRITE_TAC[LENGTH] THEN ARITH_TAC);

 (NEW_GOAL `EL 0 (ul:(real^3)list) = EL 0 (truncate_simplex 1 ul)`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC Packing3.EL_TRUNCATE_SIMPLEX);
 (REWRITE_WITH `LENGTH (ul:(real^3)list) = 3 + 1 /\ 
                 CARD (set_of_list ul) = 3 + 1`);
 (MATCH_MP_TAC Rogers.BARV_IMP_LENGTH_EQ_CARD);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (ARITH_TAC);

 (NEW_GOAL `EL 1 (ul:(real^3)list) = EL 1 (truncate_simplex 1 ul)`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC Packing3.EL_TRUNCATE_SIMPLEX);
 (REWRITE_WITH `LENGTH (ul:(real^3)list) = 3 + 1 /\ 
                 CARD (set_of_list ul) = 3 + 1`);
 (MATCH_MP_TAC Rogers.BARV_IMP_LENGTH_EQ_CARD);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (ARITH_TAC);

 (NEW_GOAL `{EL 0 ul, EL 1 ul, EL 2 ul, mxi V ul} = {u0, u1,u2,m:real^3}`);
 (REWRITE_WITH `
    {EL 0 ul, EL 1 ul, EL 2 ul, mxi V ul} = {u0, u1,u2,m:real^3} <=>
    convex hull {EL 0 ul, EL 1 ul, EL 2 ul, mxi V ul} = 
    convex hull {u0, u1,u2,m:real^3}`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC Packing3.CONVEX_HULL_EQ_EQ_SET_EQ);
 (REPEAT STRIP_TAC);

 (UNDISCH_TAC `~NULLSET X`);
 (REWRITE_TAC[]);
 (SIMP_TAC[MCELL_EXPLICIT; mcell3; ASSUME `X = mcell k' V ul`; ASSUME `k' = 3`]);
 (COND_CASES_TAC);
 (NEW_GOAL `?v0 v1 v2 v3. ul = [v0; v1; v2; v3:real^3]`);
 (MATCH_MP_TAC BARV_3_EXPLICIT);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (ASM_REWRITE_TAC[set_of_list; TRUNCATE_SIMPLEX_EXPLICIT_2; 
                   SET_RULE `{a,b,c} UNION {d} = {a,b,c,d}`]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {v0, v1, v2, mxi V [v0; v1; v2; v3]}`);
 (REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (MATCH_MP_TAC COPLANAR_IMP_NEGLIGIBLE);
 (REWRITE_TAC[COPLANAR_AFFINE_HULL_COPLANAR]);
 (MATCH_MP_TAC Rogers.AFF_DIM_LE_2_IMP_COPLANAR);
 (MATCH_MP_TAC Njiutiu.AFF_DEPENDENT_AFF_DIM_4);
 (UNDISCH_TAC `affine_dependent {EL 0 ul, EL 1 ul, EL 2 ul, mxi V ul}`);
 (REWRITE_TAC[EL; HD; TL; ARITH_RULE `3 = SUC 2 /\ 2 = SUC 1 /\ 1 = SUC 0`; 
               ASSUME `ul = [v0; v1; v2; v3:real^3]`]);

 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);

 (UNDISCH_TAC `~NULLSET X`);
 (REWRITE_TAC[]);
 (ASM_SIMP_TAC[MCELL_EXPLICIT; mcell3; set_of_list;
   TRUNCATE_SIMPLEX_EXPLICIT_2; SET_RULE `{a,b,c} UNION {d} = {a,b,c,d}`]);
 (COND_CASES_TAC);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1, u2, mxi V [u0; u1; u2; u3]}`);
 (REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (MATCH_MP_TAC COPLANAR_IMP_NEGLIGIBLE);
 (REWRITE_TAC[COPLANAR_AFFINE_HULL_COPLANAR]);
 (MATCH_MP_TAC Rogers.AFF_DIM_LE_2_IMP_COPLANAR);
 (MATCH_MP_TAC Njiutiu.AFF_DEPENDENT_AFF_DIM_4);
 (REWRITE_WITH `mxi V [u0;u1;u2;u3] = m`);
 (EXPAND_TAC "m");
 (REWRITE_TAC[ASSUME `vl = [u0; u1; u2; u3:real^3]`]);
 (ASM_REWRITE_TAC[]);

 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);

 (REWRITE_WITH `convex hull {u0, u1, u2, m:real^3} = X`);
 (ASM_SIMP_TAC[mcell3; MCELL_EXPLICIT; set_of_list]);
 (COND_CASES_TAC);
 (REWRITE_TAC[TRUNCATE_SIMPLEX_EXPLICIT_2; set_of_list;
   SET_RULE `{a,b,c} UNION {d} = {a,b,c,d}`]);
 (REWRITE_WITH `mxi V [u0;u1;u2;u3] = m`);
 (EXPAND_TAC "m");
 (REWRITE_TAC[ASSUME `vl = [u0; u1; u2; u3:real^3]`]);

 (NEW_GOAL `F`);
 (UNDISCH_TAC `~NULLSET X`);
 (REWRITE_TAC[]);
 (ASM_SIMP_TAC[mcell3; MCELL_EXPLICIT; set_of_list]);
 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (SIMP_TAC[MCELL_EXPLICIT; mcell3; ASSUME `X = mcell k' V ul`; ASSUME `k' = 3`]);
 (COND_CASES_TAC);
 (NEW_GOAL `?v0 v1 v2 v3. ul = [v0; v1; v2; v3:real^3]`);
 (MATCH_MP_TAC BARV_3_EXPLICIT);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (REWRITE_TAC[set_of_list; ASSUME `ul = [v0; v1; v2; v3:real^3]`;
               TRUNCATE_SIMPLEX_EXPLICIT_2; set_of_list;
               SET_RULE `{a,b,c} UNION {d} = {a,b,c,d}`]);
 (REWRITE_TAC[EL; HD; TL; ARITH_RULE `3 = SUC 2 /\ 2 = SUC 1 /\ 1 = SUC 0`]);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~NULLSET X`);
 (REWRITE_TAC[]);
 (SIMP_TAC[MCELL_EXPLICIT; mcell3; ASSUME `X = mcell k' V ul`; ASSUME `k' = 3`]);
 (ASM_REWRITE_TAC[]);
 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (UP_ASM_TAC THEN ASM_REWRITE_TAC[EL; HD; TL; ARITH_RULE `1 = SUC 0`]);

 (NEW_GOAL `mxi V ul = m`);
 (EXPAND_TAC "m");
 (MATCH_MP_TAC MCELL_ID_MXI);
 (EXISTS_TAC `k':num` THEN EXISTS_TAC `k:num`);
 (ASM_REWRITE_TAC[SET_RULE `3 IN {2, 3}`]);
 (REWRITE_WITH `mcell 3 V [u0; u1; u2; u3] = X`);
 (ASM_REWRITE_TAC[]);
 (ASM_REWRITE_TAC[HD]);
 (REWRITE_WITH `HD (ul) = (HD (truncate_simplex 1 ul)):real^3`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC Packing3.HD_TRUNCATE_SIMPLEX);
 (REWRITE_WITH `LENGTH (ul:(real^3)list) = 3 + 1 /\ 
                 CARD (set_of_list ul) = 3 + 1`);
 (MATCH_MP_TAC Rogers.BARV_IMP_LENGTH_EQ_CARD);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (ARITH_TAC);
 (ASM_REWRITE_TAC[HD]);
 (ASM_REWRITE_TAC[]);

 (STRIP_TAC);
 (NEW_GOAL `EL 2 ul = u2:real^3`);
 (MATCH_MP_TAC (MESON[] `(~A ==> F) ==> A`));
 (STRIP_TAC);
 (NEW_GOAL `{u0, u1, EL 2 ul, m} = {u0, u1, m:real^3}`);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN SET_TAC[]);
 (UNDISCH_TAC `~coplanar {u0,u1,u2,m:real^3}` THEN REWRITE_TAC[
   GSYM (ASSUME `{u0, u1, EL 2 ul, m} = {u0, u1, u2, m:real^3}`);
   ASSUME `{u0, u1, EL 2 ul, m} = {u0, u1, m:real^3}`; COPLANAR_3]);
 (ASM_REWRITE_TAC[]);

 (REWRITE_TAC[REAL_ARITH `a / b * c * d pow 3 = (c/ b * d pow 3) * a`]);
 (REWRITE_TAC[REAL_ARITH `a * b / (&2 * c) = (a / (&2 * c)) * b`]);
 (AP_THM_TAC THEN AP_TERM_TAC);

 (REWRITE_WITH 
  `measurable (conic_cap u0 u1 r d) /\
             vol (conic_cap u0 u1 r d) =
             (if u1 = u0 \/ &1 <= d \/ r < &0
              then &0
              else &2 / &3 * pi * (&1 - d) * r pow 3)`);
 (MATCH_MP_TAC VOLUME_CONIC_CAP);
 (EXPAND_TAC "d");
 (UNDISCH_TAC `&0 < c /\ c < &1` THEN REAL_ARITH_TAC);
 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (UP_ASM_TAC THEN STRIP_TAC);
 (UP_ASM_TAC THEN UNDISCH_TAC `~(u0 = u1:real^3)` THEN MESON_TAC[]);
 (UNDISCH_TAC `d < &1` THEN UP_ASM_TAC THEN REAL_ARITH_TAC);
 (UNDISCH_TAC `&0 < r` THEN UP_ASM_TAC THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (REWRITE_TAC[ARITH_RULE `SUC 0 = 1`]);

 (REWRITE_WITH `max d (--(&1)) = d`);
 (MATCH_MP_TAC (REAL_ARITH `&0 < d /\ --(&1) < &0 ==> max d (--(&1)) = d`));
 (REWRITE_TAC[REAL_NEG_LT0]);
 (STRIP_TAC);
 (EXPAND_TAC "d");
 (UNDISCH_TAC `&0 < c /\ c < &1` THEN REAL_ARITH_TAC);
 (REAL_ARITH_TAC);

 (REWRITE_WITH `
  (&2 / &3 * pi * (&1 - d) * r pow 3) / (&2 * pi) = (&1 - d) / &3 * r pow 3 *   
  ((&2 * pi) / (&2 * pi))`);
 (REAL_ARITH_TAC);
 (REWRITE_WITH `(&2 * pi) / (&2 * pi) = &1`);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (REWRITE_TAC[REAL_ENTIRE; PI_NZ; REAL_ARITH `~(&2 = &0)`]);
 (REAL_ARITH_TAC);
 (NEW_GOAL `F`);
 (UP_ASM_TAC THEN UNDISCH_TAC `k' = 3 /\ mcell k' V ul = mcell 3 V vl`
   THEN MESON_TAC[]);
 (UP_ASM_TAC THEN MESON_TAC[]);

(* ========================================================================= *)

 (ASM_CASES_TAC `azim u0 u1 m (u2:real^3) < pi`);
 (UNDISCH_TAC `~coplanar {u0, u1, u2, m:real^3}`);
 (ONCE_REWRITE_TAC[SET_RULE `{a,b,c,d} = {a,b,d,c}`]);
 (STRIP_TAC);
 (REWRITE_WITH `vol (L INTER D) = vol (D INTER wedge u0 u1 m u2)`);
 (ASM_SIMP_TAC[WEDGE_LUNE]);
 (REWRITE_WITH `L INTER conic_cap (u0:real^3) u1 r d = 
                 conic_cap u0 u1 r d INTER L`);
 (SET_TAC[]);
 (MATCH_MP_TAC MEASURE_NEGLIGIBLE_SYMDIFF);

 (REWRITE_WITH `conic_cap (u0:real^3) u1 r d INTER 
   aff_gt {u0, u1} {m, u2} DIFF conic_cap u0 u1 r d INTER L = {}`);
 (EXPAND_TAC "L");
 (REWRITE_TAC[SET_RULE `{a,b} = {b, a}`]);
 (MATCH_MP_TAC (SET_RULE `A SUBSET B ==> C INTER A DIFF C INTER B = {}`));
 (REWRITE_TAC[AFF_GT_SUBSET_AFF_GE]);
 (REWRITE_TAC[SET_RULE `A UNION {} = A`]);
 (EXPAND_TAC "L");
 (REWRITE_TAC[SET_RULE `{a,b} = {b, a}`]);

 (REWRITE_WITH `aff_ge {u0, u1:real^3} {m, u2} =
                 aff_gt {u0, u1} {m, u2} UNION 
   UNIONS {aff_ge {u0, u1} ({m, u2} DELETE a) | a | a IN  {m, u2}}`);
 (MATCH_MP_TAC AFF_GE_AFF_GT_DECOMP);
 (REWRITE_TAC[Geomdetail.FINITE6]);
 (REWRITE_TAC[DISJOINT]);

 (ASM_CASES_TAC `u2 IN {u0, u1:real^3}`);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~coplanar {u0, u1, m, u2:real^3}`);
 (REWRITE_WITH `{u0, u1, m, u2} = {u0, u1, m:real^3}`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_TAC[COPLANAR_3]);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (ASM_CASES_TAC `m IN {u0, u1:real^3}`);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~coplanar {u0, u1, m, u2:real^3}`);
 (REWRITE_WITH `{u0, u1, m, u2} = {u0, u1, u2:real^3}`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_TAC[COPLANAR_3]);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN SET_TAC[]);

 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC 
  `UNIONS {aff_ge {u0, u1:real^3} ({m, u2} DELETE a) | a | a IN {m, u2}}`);
 (STRIP_TAC);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC 
  `aff_ge {u0, u1:real^3} {u2} UNION aff_ge {u0, u1:real^3} {m}`);
 (STRIP_TAC);
 (MATCH_MP_TAC NEGLIGIBLE_UNION);
 (STRIP_TAC);

 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1:real^3, u2}`);
 (STRIP_TAC);
 (REWRITE_TAC[NEGLIGIBLE_AFFINE_HULL_3]);
 (REWRITE_WITH `{u0,u1,u2:real^3} = {u0,u1} UNION {u2}`);
 (SET_TAC[]);
 (REWRITE_TAC[AFF_GE_SUBSET_AFFINE_HULL]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1:real^3, m}`);
 (STRIP_TAC);
 (REWRITE_TAC[NEGLIGIBLE_AFFINE_HULL_3]);
 (REWRITE_WITH `{u0,u1,m:real^3} = {u0,u1} UNION {m}`);
 (SET_TAC[]);
 (REWRITE_TAC[AFF_GE_SUBSET_AFFINE_HULL]);
 (REWRITE_TAC[SET_RULE 
  `UNIONS {aff_ge {u0, u1} ({m, s3} DELETE a) | a | a IN {m, s3}} = 
         aff_ge {u0, u1} ({m, s3} DELETE s3) 
   UNION aff_ge {u0, u1} ({m, s3} DELETE m)`]);
 (MATCH_MP_TAC (SET_RULE 
  `A SUBSET D /\ C SUBSET B ==> A UNION C SUBSET B UNION D`));
 (STRIP_TAC);
 (MATCH_MP_TAC AFF_GE_MONO_RIGHT);
 (STRIP_TAC);
 (SET_TAC[]);

 (REWRITE_TAC[DISJOINT]);
 (ASM_CASES_TAC `m IN {u0, u1:real^3}`);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~coplanar {u0, u1, m, u2:real^3}`);
 (REWRITE_WITH `{u0, u1, m, u2} = {u0, u1, u2:real^3}`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_TAC[COPLANAR_3]);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (UP_ASM_TAC THEN SET_TAC[]);

 (MATCH_MP_TAC AFF_GE_MONO_RIGHT);
 (STRIP_TAC);
 (SET_TAC[]);
 (REWRITE_TAC[DISJOINT]);
 (ASM_CASES_TAC `u2 IN {u0, u1:real^3}`);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~coplanar {u0, u1, m, u2:real^3}`);
 (REWRITE_WITH `{u0, u1, m, u2} = {u0, u1, m:real^3}`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_TAC[COPLANAR_3]);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (UP_ASM_TAC THEN SET_TAC[]);

 (SET_TAC[]);

 (REWRITE_TAC[ASSUME `D = conic_cap (u0:real^3) u1 r d`]);
 (REWRITE_WITH `vol (conic_cap u0 u1 r d INTER wedge u0 u1 m u2) =
             (if &1 < d \/ r < &0
              then &0
              else azim u0 u1 m u2 / &3 * (&1 - max d (-- &1)) * r pow 3)`);
 (NEW_GOAL `~collinear {u0:real^3, u1, u2} /\ ~collinear {u0, u1, m}`);
 (STRIP_TAC);
 (MATCH_MP_TAC NOT_COPLANAR_NOT_COLLINEAR);
 (EXISTS_TAC `m:real^3`);
 (ONCE_REWRITE_TAC[SET_RULE `{a,b,c,d} = {a,b,d,c}`]);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC NOT_COPLANAR_NOT_COLLINEAR);
 (EXISTS_TAC `u2:real^3`);
 (ASM_REWRITE_TAC[]);

 (ASM_SIMP_TAC[VOLUME_CONIC_CAP_WEDGE]);
 (COND_CASES_TAC);
 (NEW_GOAL `F`);

 (UNDISCH_TAC `&0 < r` THEN UNDISCH_TAC `d < &1` THEN 
   UP_ASM_TAC THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (REWRITE_WITH `azim (u0:real^3) u1 m u2 = dihV u0 u1 m u2`);
 (MATCH_MP_TAC AZIM_DIHV_SAME);
 (ASM_REWRITE_TAC[]);
 (STRIP_TAC);

 (MATCH_MP_TAC NOT_COPLANAR_NOT_COLLINEAR);
 (EXISTS_TAC `u2:real^3`);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC NOT_COPLANAR_NOT_COLLINEAR);
 (EXISTS_TAC `m:real^3`);
 (ONCE_REWRITE_TAC[SET_RULE `{a,b,c,d} = {a,b,d,c}`]);
 (ASM_REWRITE_TAC[]);

 (REWRITE_TAC[dihX]);
 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~NULLSET (X INTER D)`);
 (REWRITE_TAC[]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `X:real^3->bool`);
 (ASM_REWRITE_TAC[] THEN SET_TAC[]);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (LET_TAC);

 (UP_ASM_TAC THEN REWRITE_TAC[cell_params_d]);
 (ABBREV_TAC `P = (\(k, ul). k <= 4 /\
           ul IN barV V 3 /\
           X = mcell k V ul /\
           initial_sublist [u0; u1] ul)`);
 (STRIP_TAC);
 (NEW_GOAL `(P:num#(real^3)list->bool) ((@) P)`);
 (MATCH_MP_TAC SELECT_AX);
 (EXISTS_TAC `(3, vl:(real^3)list)`);
 (EXPAND_TAC "P");
 (REWRITE_TAC[BETA_THM]);
 (REWRITE_TAC[IN; ARITH_RULE `3 <= 4`] THEN ASM_REWRITE_TAC[]);

 (REWRITE_WITH `initial_sublist [u0;u1:real^3] [u0; u1; u2; u3] /\ 
                 LENGTH [u0;u1] = 1 + 1`);
 (REWRITE_TAC[GSYM Packing3.TRUNCATE_SIMPLEX_INITIAL_SUBLIST]);
 (REWRITE_TAC[GSYM (ASSUME `vl = [u0; u1; u2; u3:real^3]`)]);
 (ASM_REWRITE_TAC[]);
 (REWRITE_TAC[LENGTH] THEN ARITH_TAC);
 (UP_ASM_TAC THEN ASM_REWRITE_TAC[]);
 (EXPAND_TAC "P" THEN REWRITE_TAC[IN] THEN REPEAT STRIP_TAC);

 (NEW_GOAL `k' = 3 /\ mcell k' V ul = mcell 3 V vl`);
 (MATCH_MP_TAC Ajripqn.AJRIPQN);
 (ASM_REWRITE_TAC[]);
 (REWRITE_TAC[GSYM (ASSUME `vl = [u0; u1; u2; u3:real^3]`)]);
 (REWRITE_WITH `mcell k' V ul INTER mcell 3 V vl = X`);
 (REWRITE_WITH `mcell 3 V vl = X`);
 (ASM_SIMP_TAC[]);
 (SET_TAC[ASSUME `X = mcell k' V ul`]);

 (REPEAT STRIP_TAC);
 (UNDISCH_TAC `k' <= 4` THEN REWRITE_TAC[ARITH_RULE 
   `a <= 4 <=> a = 0 \/a = 1 \/ a = 2 \/ a = 3 \/ a = 4`] THEN SET_TAC[]);
 (SET_TAC[]);
 (UP_ASM_TAC THEN UNDISCH_TAC `~NULLSET X` THEN MESON_TAC[]);

 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN ARITH_TAC);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (COND_CASES_TAC);

 (REWRITE_TAC[dihu3]);

 (REWRITE_WITH `dihV (EL 0 ul) (EL 1 ul) (EL 2 ul) (mxi V ul) = 
   dihV u0 u1 u2 (m:real^3)`);

 (NEW_GOAL `truncate_simplex 1 ul = [u0;u1:real^3] /\ 1 + 1 <= LENGTH ul`);
 (REWRITE_TAC[Packing3.TRUNCATE_SIMPLEX_INITIAL_SUBLIST]);
 (ASM_REWRITE_TAC[LENGTH] THEN ARITH_TAC);

 (NEW_GOAL `EL 0 (ul:(real^3)list) = EL 0 (truncate_simplex 1 ul)`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC Packing3.EL_TRUNCATE_SIMPLEX);
 (REWRITE_WITH `LENGTH (ul:(real^3)list) = 3 + 1 /\ 
                 CARD (set_of_list ul) = 3 + 1`);
 (MATCH_MP_TAC Rogers.BARV_IMP_LENGTH_EQ_CARD);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (ARITH_TAC);

 (NEW_GOAL `EL 1 (ul:(real^3)list) = EL 1 (truncate_simplex 1 ul)`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC Packing3.EL_TRUNCATE_SIMPLEX);
 (REWRITE_WITH `LENGTH (ul:(real^3)list) = 3 + 1 /\ 
                 CARD (set_of_list ul) = 3 + 1`);
 (MATCH_MP_TAC Rogers.BARV_IMP_LENGTH_EQ_CARD);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (ARITH_TAC);

 (NEW_GOAL `{EL 0 ul, EL 1 ul, EL 2 ul, mxi V ul} = {u0, u1,u2,m:real^3}`);
 (REWRITE_WITH `
    {EL 0 ul, EL 1 ul, EL 2 ul, mxi V ul} = {u0, u1,u2,m:real^3} <=>
    convex hull {EL 0 ul, EL 1 ul, EL 2 ul, mxi V ul} = 
    convex hull {u0, u1,u2,m:real^3}`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC Packing3.CONVEX_HULL_EQ_EQ_SET_EQ);
 (REPEAT STRIP_TAC);

 (UNDISCH_TAC `~NULLSET X`);
 (REWRITE_TAC[]);
 (SIMP_TAC[MCELL_EXPLICIT; mcell3; ASSUME `X = mcell k' V ul`; ASSUME `k' = 3`]);
 (COND_CASES_TAC);
 (NEW_GOAL `?v0 v1 v2 v3. ul = [v0; v1; v2; v3:real^3]`);
 (MATCH_MP_TAC BARV_3_EXPLICIT);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (ASM_REWRITE_TAC[set_of_list; TRUNCATE_SIMPLEX_EXPLICIT_2; 
                   SET_RULE `{a,b,c} UNION {d} = {a,b,c,d}`]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {v0, v1, v2, mxi V [v0; v1; v2; v3]}`);
 (REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (MATCH_MP_TAC COPLANAR_IMP_NEGLIGIBLE);
 (REWRITE_TAC[COPLANAR_AFFINE_HULL_COPLANAR]);
 (MATCH_MP_TAC Rogers.AFF_DIM_LE_2_IMP_COPLANAR);
 (MATCH_MP_TAC Njiutiu.AFF_DEPENDENT_AFF_DIM_4);
 (UNDISCH_TAC `affine_dependent {EL 0 ul, EL 1 ul, EL 2 ul, mxi V ul}`);
 (REWRITE_TAC[EL; HD; TL; ARITH_RULE `3 = SUC 2 /\ 2 = SUC 1 /\ 1 = SUC 0`; 
               ASSUME `ul = [v0; v1; v2; v3:real^3]`]);

 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);

 (UNDISCH_TAC `~NULLSET X`);
 (REWRITE_TAC[]);
 (ASM_SIMP_TAC[MCELL_EXPLICIT; mcell3; set_of_list;
   TRUNCATE_SIMPLEX_EXPLICIT_2; SET_RULE `{a,b,c} UNION {d} = {a,b,c,d}`]);
 (COND_CASES_TAC);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {u0, u1, u2, mxi V [u0; u1; u2; u3]}`);
 (REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (MATCH_MP_TAC COPLANAR_IMP_NEGLIGIBLE);
 (REWRITE_TAC[COPLANAR_AFFINE_HULL_COPLANAR]);
 (MATCH_MP_TAC Rogers.AFF_DIM_LE_2_IMP_COPLANAR);
 (MATCH_MP_TAC Njiutiu.AFF_DEPENDENT_AFF_DIM_4);
 (REWRITE_WITH `mxi V [u0;u1;u2;u3] = m`);
 (EXPAND_TAC "m");
 (REWRITE_TAC[ASSUME `vl = [u0; u1; u2; u3:real^3]`]);
 (ASM_REWRITE_TAC[]);

 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);

 (REWRITE_WITH `convex hull {u0, u1, u2, m:real^3} = X`);
 (ASM_SIMP_TAC[mcell3; MCELL_EXPLICIT; set_of_list]);
 (COND_CASES_TAC);
 (REWRITE_TAC[TRUNCATE_SIMPLEX_EXPLICIT_2; set_of_list;
   SET_RULE `{a,b,c} UNION {d} = {a,b,c,d}`]);
 (REWRITE_WITH `mxi V [u0;u1;u2;u3] = m`);
 (EXPAND_TAC "m");
 (REWRITE_TAC[ASSUME `vl = [u0; u1; u2; u3:real^3]`]);

 (NEW_GOAL `F`);
 (UNDISCH_TAC `~NULLSET X`);
 (REWRITE_TAC[]);
 (ASM_SIMP_TAC[mcell3; MCELL_EXPLICIT; set_of_list]);
 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (SIMP_TAC[MCELL_EXPLICIT; mcell3; ASSUME `X = mcell k' V ul`; ASSUME `k' = 3`]);
 (COND_CASES_TAC);
 (NEW_GOAL `?v0 v1 v2 v3. ul = [v0; v1; v2; v3:real^3]`);
 (MATCH_MP_TAC BARV_3_EXPLICIT);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (REWRITE_TAC[set_of_list; ASSUME `ul = [v0; v1; v2; v3:real^3]`;
               TRUNCATE_SIMPLEX_EXPLICIT_2; set_of_list;
               SET_RULE `{a,b,c} UNION {d} = {a,b,c,d}`]);
 (REWRITE_TAC[EL; HD; TL; ARITH_RULE `3 = SUC 2 /\ 2 = SUC 1 /\ 1 = SUC 0`]);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `~NULLSET X`);
 (REWRITE_TAC[]);
 (SIMP_TAC[MCELL_EXPLICIT; mcell3; ASSUME `X = mcell k' V ul`; ASSUME `k' = 3`]);
 (ASM_REWRITE_TAC[]);
 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (UP_ASM_TAC THEN ASM_REWRITE_TAC[EL; HD; TL; ARITH_RULE `1 = SUC 0`]);

 (NEW_GOAL `mxi V ul = m`);
 (EXPAND_TAC "m");
 (MATCH_MP_TAC MCELL_ID_MXI);
 (EXISTS_TAC `k':num` THEN EXISTS_TAC `k:num`);
 (ASM_REWRITE_TAC[SET_RULE `3 IN {2, 3}`]);
 (REWRITE_WITH `mcell 3 V [u0; u1; u2; u3] = X`);
 (ASM_REWRITE_TAC[]);
 (ASM_REWRITE_TAC[HD]);
 (REWRITE_WITH `HD (ul) = (HD (truncate_simplex 1 ul)):real^3`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC Packing3.HD_TRUNCATE_SIMPLEX);
 (REWRITE_WITH `LENGTH (ul:(real^3)list) = 3 + 1 /\ 
                 CARD (set_of_list ul) = 3 + 1`);
 (MATCH_MP_TAC Rogers.BARV_IMP_LENGTH_EQ_CARD);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (ARITH_TAC);
 (ASM_REWRITE_TAC[HD]);
 (ASM_REWRITE_TAC[]);

 (STRIP_TAC);
 (NEW_GOAL `EL 2 ul = u2:real^3`);
 (MATCH_MP_TAC (MESON[] `(~A ==> F) ==> A`));
 (STRIP_TAC);
 (NEW_GOAL `{u0, u1, EL 2 ul, m} = {u0, u1, m:real^3}`);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN SET_TAC[]);
 (UNDISCH_TAC `~coplanar {u0,u1,m,u2:real^3}`);
 (REWRITE_TAC[]);
 (ONCE_REWRITE_TAC[SET_RULE `{a,b,c,d} = {a,b,d,c}`]);
 (REWRITE_TAC[GSYM (ASSUME `{u0, u1, EL 2 ul, m} = {u0, u1, u2, m:real^3}`);
              ASSUME `{u0, u1, EL 2 ul, m} = {u0, u1, m:real^3}`; COPLANAR_3]);
 (ASM_REWRITE_TAC[]);
 (REWRITE_TAC[DIHV_SYM_2]);

 (REWRITE_TAC[REAL_ARITH `a / b * c * d pow 3 = (c/ b * d pow 3) * a`]);
 (REWRITE_TAC[REAL_ARITH `a * b / (&2 * c) = (a / (&2 * c)) * b`]);
 (AP_THM_TAC THEN AP_TERM_TAC);

 (REWRITE_WITH 
  `measurable (conic_cap u0 u1 r d) /\
             vol (conic_cap u0 u1 r d) =
             (if u1 = u0 \/ &1 <= d \/ r < &0
              then &0
              else &2 / &3 * pi * (&1 - d) * r pow 3)`);
 (MATCH_MP_TAC VOLUME_CONIC_CAP);
 (EXPAND_TAC "d");
 (UNDISCH_TAC `&0 < c /\ c < &1` THEN REAL_ARITH_TAC);
 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (UP_ASM_TAC THEN STRIP_TAC);
 (UP_ASM_TAC THEN UNDISCH_TAC `~(u0 = u1:real^3)` THEN MESON_TAC[]);
 (UNDISCH_TAC `d < &1` THEN UP_ASM_TAC THEN REAL_ARITH_TAC);
 (UNDISCH_TAC `&0 < r` THEN UP_ASM_TAC THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (REWRITE_TAC[ARITH_RULE `SUC 0 = 1`]);

 (REWRITE_WITH `max d (--(&1)) = d`);
 (MATCH_MP_TAC (REAL_ARITH `&0 < d /\ --(&1) < &0 ==> max d (--(&1)) = d`));
 (REWRITE_TAC[REAL_NEG_LT0]);
 (STRIP_TAC);
 (EXPAND_TAC "d");
 (UNDISCH_TAC `&0 < c /\ c < &1` THEN REAL_ARITH_TAC);
 (REAL_ARITH_TAC);

 (REWRITE_WITH `
  (&2 / &3 * pi * (&1 - d) * r pow 3) / (&2 * pi) = (&1 - d) / &3 * r pow 3 *   
  ((&2 * pi) / (&2 * pi))`);
 (REAL_ARITH_TAC);
 (REWRITE_WITH `(&2 * pi) / (&2 * pi) = &1`);
 (MATCH_MP_TAC REAL_DIV_REFL);
 (REWRITE_TAC[REAL_ENTIRE; PI_NZ; REAL_ARITH `~(&2 = &0)`]);
 (REAL_ARITH_TAC);
 (NEW_GOAL `F`);
 (UP_ASM_TAC THEN UNDISCH_TAC `k' = 3 /\ mcell k' V ul = mcell 3 V vl`
   THEN MESON_TAC[]);
 (UP_ASM_TAC THEN MESON_TAC[]);

(* ========================================================================= *)

 (NEW_GOAL `F`);
 (NEW_GOAL `azim (u0:real^3) u1 m u2 = 
  (if azim u0 u1 u2 m = &0 then &0 else &2 * pi - azim u0 u1 u2 m)`);
 (MATCH_MP_TAC AZIM_COMPL);
 (STRIP_TAC);

 (MATCH_MP_TAC NOT_COPLANAR_NOT_COLLINEAR);
 (EXISTS_TAC `m:real^3`);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC NOT_COPLANAR_NOT_COLLINEAR);
 (EXISTS_TAC `u2:real^3`);
 (ONCE_REWRITE_TAC[SET_RULE `{a,b,c,d} = {a,b, d, c}`]);
 (ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN COND_CASES_TAC);
 (NEW_GOAL `F`);
 (NEW_GOAL `(&0 < pi)`);
 (REWRITE_TAC[PI_POS]);
 (UNDISCH_TAC `~(azim (u0:real^3) u1 u2 m < pi)`);
 (ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (STRIP_TAC);

 (NEW_GOAL `azim (u0:real^3) u1 u2 m = pi`);
 (UP_ASM_TAC THEN DEL_TAC THEN UP_ASM_TAC THEN UP_ASM_TAC THEN REAL_ARITH_TAC);
 (UNDISCH_TAC `~coplanar {u0, u1, u2, m:real^3}`);
 (REWRITE_TAC[] THEN MATCH_MP_TAC AZIM_EQ_0_PI_IMP_COPLANAR);
 (ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN MESON_TAC[]);

(* ========================================================================= *)
(* ========================================================================= *)
 (ABBREV_TAC `s = {X | mcell_set V X /\ edgeX V X e}`);
 (NEW_GOAL `sum s (\t. vol (t INTER D)) = vol (D)`);
 (ABBREV_TAC `f = (\t:real^3->bool. t INTER D)`);
 (REWRITE_WITH `(\t. vol (t INTER D)) = (\x:real^3->bool. vol (f x))`);
 (EXPAND_TAC "f");
 (REWRITE_TAC[]);
 (REWRITE_WITH `sum s (\x:real^3->bool. vol (f x)) = vol (UNIONS (IMAGE f s))`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC MEASURE_NEGLIGIBLE_UNIONS_IMAGE);
 (REPEAT STRIP_TAC); 

 (EXPAND_TAC "s");
 (MATCH_MP_TAC FINITE_EDGE_X2);
 (EXISTS_TAC `u0:real^3` THEN EXISTS_TAC `u1:real^3`);
 (ASM_REWRITE_TAC[]);

 (EXPAND_TAC "f");
 (MATCH_MP_TAC MEASURABLE_INTER);
 (STRIP_TAC);
 (UP_ASM_TAC THEN EXPAND_TAC "s");
 (REWRITE_TAC[mcell_set; IN; IN_ELIM_THM]);
 (REPEAT STRIP_TAC);
 (ASM_SIMP_TAC[MEASURABLE_MCELL]);
 (ASM_REWRITE_TAC[MEASURABLE_CONIC_CAP]);

 (EXPAND_TAC "f");
 (UNDISCH_TAC `(x:real^3->bool) IN s` THEN 
   UNDISCH_TAC `(y:real^3->bool) IN s` THEN EXPAND_TAC "s");
 (REWRITE_TAC[mcell_set_2; IN; IN_ELIM_THM]);
 (REPEAT STRIP_TAC);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `x INTER (y:real^3->bool)`);
 (ASM_REWRITE_TAC[SET_RULE `(x INTER D) INTER y INTER D SUBSET x INTER y`]);
 (MATCH_MP_TAC (MESON[] `(~A ==> F) ==> A`));
 (STRIP_TAC);

 (NEW_GOAL `i' = i /\ mcell i' V ul' = mcell i V ul`);
 (MATCH_MP_TAC Ajripqn.AJRIPQN);
 (ASM_REWRITE_TAC[SET_RULE `i IN {0, 1, 2, 3, 4} <=>
                             i = 0 \/ i = 1 \/ i = 2 \/ i = 3 \/ i = 4`]);
 (UNDISCH_TAC `i <= 4` THEN UNDISCH_TAC `i' <= 4` THEN ARITH_TAC);
 (UNDISCH_TAC `~(x = y:real^3->bool)` THEN ASM_REWRITE_TAC[]);


 (EXPAND_TAC "s");
 (EXPAND_TAC "f" THEN REWRITE_TAC[IMAGE]);

(* OK here *)



 (MATCH_MP_TAC MEASURE_NEGLIGIBLE_SYMDIFF);
 (REWRITE_WITH 
   `UNIONS {y | ?x. x IN {X | mcell_set V X /\ edgeX V X e} /\ y = x INTER D}
    DIFF D = {}`);
 (REWRITE_TAC[SET_RULE `A DIFF B = {} <=> A SUBSET B`]);
 (REWRITE_TAC[UNIONS_SUBSET; IN; IN_ELIM_THM]);
 (SET_TAC[]);
 (REWRITE_TAC[SET_RULE `{} UNION A = A`]);

 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `UNIONS {y | ?x. x IN {X | mcell_set V X /\ NULLSET (X INTER D) /\ 
            ~(X INTER D = {})} /\  y = x INTER D}`);
 (STRIP_TAC);
 (MATCH_MP_TAC NEGLIGIBLE_UNIONS);
 (STRIP_TAC);
 (REWRITE_WITH 
  `{y | ?x. x IN {X | mcell_set V X /\ NULLSET (X INTER D) /\ 
                ~(X INTER D = {})} /\ 
            y = x INTER D} = 
   {y | ?x. x IN {X | mcell_set V X /\ NULLSET (X INTER D) /\ 
                ~(X INTER D = {})} /\ 
            y = f x }`);
 (EXPAND_TAC "f" THEN REWRITE_TAC[]);
 (MATCH_MP_TAC FINITE_IMAGE_EXPAND);

(* ========================================================================= *)
(* ========================================================================= *)
(* ========================================================================= *)

 (MATCH_MP_TAC FINITE_SUBSET);
 (EXISTS_TAC `{X | X SUBSET ball (u0, &10) /\ mcell_set V X}`);
 (STRIP_TAC);
 (ASM_SIMP_TAC[FINITE_MCELL_SET_LEMMA_2]);
 (REWRITE_TAC[SUBSET; IN_BALL; IN; IN_ELIM_THM; mcell_set] THEN 
   REPEAT STRIP_TAC);

 (NEW_GOAL `?v1:real^3. v1 IN x /\ v1 IN D`);
 (REWRITE_TAC[GSYM IN_INTER]);
 (UNDISCH_TAC `~(x:real^3->bool INTER D = {})` THEN SET_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (NEW_GOAL `dist (u0, x') <= dist (u0, v1:real^3) + dist (v1, x')`);
 (NORM_ARITH_TAC);
 (NEW_GOAL `dist (u0, v1:real^3) < &1`);
 (REWRITE_TAC[GSYM IN_BALL]);
 (NEW_GOAL `D SUBSET ball (u0:real^3, &1)`);
 (EXPAND_TAC "D");
 (NEW_GOAL `ball (u0, r) SUBSET ball (u0:real^3, &1)`);
 (MATCH_MP_TAC SUBSET_BALL);
 (EXPAND_TAC "r" THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN SET_TAC[]);
 (UP_ASM_TAC THEN UNDISCH_TAC `v1:real^3 IN D` THEN SET_TAC[]);
 (NEW_GOAL `dist (v1,x':real^3) < &8`);
 (REWRITE_TAC[GSYM IN_BALL]);

 (NEW_GOAL `x SUBSET ball (v1:real^3, &8)`);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC MCELL_SUBSET_BALL8);
 (REWRITE_TAC[GSYM (ASSUME `x = mcell i V ul`)] THEN ASM_REWRITE_TAC[]);
 (UNDISCH_TAC `(x:real^3->bool) x'` THEN UP_ASM_TAC THEN SET_TAC[]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN UP_ASM_TAC THEN REAL_ARITH_TAC);
 (EXISTS_TAC `i:num` THEN EXISTS_TAC `ul:(real^3)list`);
 (ASM_REWRITE_TAC[]);

(* ========================================================================= *)

 (REWRITE_TAC[IN; IN_ELIM_THM]);
 (REPEAT STRIP_TAC);
 (REWRITE_TAC[ASSUME `t:real^3->bool = x INTER D`]);
 (ASM_REWRITE_TAC[]);

 (REWRITE_TAC[SUBSET; IN_UNIONS]);
 (REPEAT STRIP_TAC);

 (NEW_GOAL `?v:real^3. v IN V /\ x IN voronoi_closed V v`);
 (ASM_SIMP_TAC[TIWWFYQ]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (UP_ASM_TAC THEN REWRITE_WITH 
   `x IN voronoi_closed V v <=>  (?vl. vl IN barV V 3 /\ x IN rogers V vl /\
                                       truncate_simplex 0 vl = [v])`);
 (ASM_SIMP_TAC[GLTVHUM]);
 (REWRITE_TAC[IN] THEN STRIP_TAC);
 (NEW_GOAL `?i. i <= 4 /\ x IN mcell i V vl`);
 (ASM_SIMP_TAC[IN;SLTSTLO1]);
 (UP_ASM_TAC THEN STRIP_TAC);

 (ABBREV_TAC `X = mcell i V vl`);
 (NEW_GOAL `~NULLSET (X INTER D) ==> F`);
 (STRIP_TAC);

 (NEW_GOAL `?k ul.
                   2 <= k /\
                   barV V 3 ul /\
                   X = mcell k V ul /\
                   truncate_simplex 1 ul = [u0; u1]`);
 (FIRST_ASSUM MATCH_MP_TAC);
 (STRIP_TAC);
 (REWRITE_TAC[mcell_set; IN_ELIM_THM; IN]);
 (EXISTS_TAC `i:num` THEN EXISTS_TAC `vl:(real^3)list`);
 (ASM_REWRITE_TAC[]);
 (ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);

 (MP_TAC (ASSUME `x IN
      D DIFF
      UNIONS
      {y | ?x. x IN {X | mcell_set V X /\ edgeX V X e} /\ y = x INTER D}`));
 (REWRITE_TAC[IN_DIFF; MESON[] `~(A /\ ~B) <=> ~A \/ B`]);
 (DISJ2_TAC);
 (REWRITE_TAC[IN_UNIONS; IN; IN_ELIM_THM]);
 (EXISTS_TAC `X INTER (D:real^3->bool)`);
 (STRIP_TAC);

 (EXISTS_TAC `(X:real^3->bool)`);
 (REWRITE_TAC[mcell_set; IN; IN_ELIM_THM] THEN STRIP_TAC);
 (EXISTS_TAC `i:num` THEN EXISTS_TAC `vl:(real^3)list`);
 (ASM_REWRITE_TAC[]);

 (REWRITE_TAC[edgeX; IN_ELIM_THM]);
 (EXISTS_TAC `u0:real^3` THEN EXISTS_TAC `u1:real^3`);
 (STRIP_TAC);

 (NEW_GOAL `VX V X = V INTER X`);
 (MATCH_MP_TAC Hdtfnfz.HDTFNFZ);
 (EXISTS_TAC `ul:(real^3)list` THEN EXISTS_TAC `(if k < 4 then k else 4)`);
 (ASM_REWRITE_TAC[]);
 (STRIP_TAC);
 (COND_CASES_TAC);
 (MESON_TAC[]);
 (NEW_GOAL `k >= 4`);
 (UP_ASM_TAC THEN ARITH_TAC);
 (ASM_SIMP_TAC[MCELL_EXPLICIT; ARITH_RULE `4 >= 4`; ]);
 (UNDISCH_TAC `~NULLSET (X INTER D)` THEN ASM_REWRITE_TAC[]);
 (MESON_TAC[NEGLIGIBLE_SUBSET; SET_RULE `A INTER B SUBSET A`]);

 (NEW_GOAL `(V:real^3->bool) INTER X = 
            set_of_list (truncate_simplex ((if k < 4 then k else 4) - 1) ul)`);
 (REWRITE_WITH `X = mcell (if k < 4 then k else 4) V ul`);
 (ASM_REWRITE_TAC[]);
 (COND_CASES_TAC);
 (REFL_TAC);
 (NEW_GOAL `k >= 4`);
 (UP_ASM_TAC THEN ARITH_TAC);
 (ASM_SIMP_TAC[MCELL_EXPLICIT; ARITH_RULE `4 >= 4`; ]);

 (MATCH_MP_TAC Lepjbdj.LEPJBDJ);
 (ASM_REWRITE_TAC[]);
 (STRIP_TAC);
 (UNDISCH_TAC `2 <= k` THEN ARITH_TAC);
 (STRIP_TAC);
 (UNDISCH_TAC `2 <= k` THEN ARITH_TAC);
 (REWRITE_WITH `mcell (if k < 4 then k else 4) V ul = X`);
 (ASM_REWRITE_TAC[]);
 (COND_CASES_TAC);
 (REFL_TAC);
 (NEW_GOAL `k >= 4`);
 (UP_ASM_TAC THEN ARITH_TAC);
 (ASM_SIMP_TAC[MCELL_EXPLICIT; ARITH_RULE `4 >= 4`; ]);
 (STRIP_TAC);
 (UNDISCH_TAC `~NULLSET (X INTER D)` THEN 
   REWRITE_TAC[ASSUME `X = {}:real^3->bool`; SET_RULE `{} INTER x = {}`;
   NEGLIGIBLE_EMPTY]);
 (ASM_REWRITE_TAC[]);
 (NEW_GOAL `set_of_list (truncate_simplex 1 (ul:(real^3)list)) SUBSET 
           set_of_list (truncate_simplex ((if k < 4 then k else 4) - 1) ul)`);
 (MATCH_MP_TAC Rogers.TRUNCATE_SIMPLEX_SUBSET);
 (REWRITE_WITH `LENGTH ul = 3 + 1 /\ 
                 CARD (set_of_list (ul:(real^3)list)) = 3 + 1`);
 (MATCH_MP_TAC Rogers.BARV_IMP_LENGTH_EQ_CARD);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UNDISCH_TAC `2 <= k` THEN ARITH_TAC);
 (REWRITE_TAC[MESON[IN] `(s:real^3->bool) u <=> u IN s`]);

 (UP_ASM_TAC THEN REWRITE_TAC[ASSUME `truncate_simplex 1 ul = [u0; u1:real^3]`;
    set_of_list]);
 (SET_TAC[]);
 (ASM_REWRITE_TAC[]);
 (REWRITE_TAC[MESON[IN] `(s:real^3->bool) u <=> u IN s`; IN_INTER]);
 (STRIP_TAC);
 (ASM_REWRITE_TAC[]);
 (UNDISCH_TAC `x IN
      D DIFF
      UNIONS
      {y | ?x. x IN {X | mcell_set V X /\ edgeX V X e} /\ y = x INTER D}`);
 (SET_TAC[]);
 (UP_ASM_TAC THEN REWRITE_TAC[] THEN STRIP_TAC);
 (EXISTS_TAC `X INTER (D:real^3 ->bool)`);
 (STRIP_TAC);
 (REWRITE_TAC[IN_ELIM_THM]);
 (EXISTS_TAC `(X:real^3 ->bool)`);
 (STRIP_TAC);
 (STRIP_TAC);

 (REWRITE_TAC[mcell_set; IN; IN_ELIM_THM]);
 (EXISTS_TAC `i:num` THEN EXISTS_TAC `vl:(real^3)list`);
 (ASM_REWRITE_TAC[]);
 (STRIP_TAC);
 (ASM_REWRITE_TAC[]);

 (REWRITE_TAC[SET_RULE `~(a = {}) <=> (?x. x IN a)`]);
 (EXISTS_TAC `x:real^3`);

 (REWRITE_TAC[IN_INTER]);
 (STRIP_TAC);
 (ASM_REWRITE_TAC[]);
 (UNDISCH_TAC `x IN
      D DIFF
      UNIONS
      {y | ?x. x IN {X | mcell_set V X /\ edgeX V X e} /\ y = x INTER D}`);
 (SET_TAC[]);
 (REWRITE_TAC[]);

 (REWRITE_TAC[MESON[IN] `(s:real^3->bool) u <=> u IN s`; IN_INTER]);
 (STRIP_TAC);
 (ASM_REWRITE_TAC[]);
 (UNDISCH_TAC `x IN
      D DIFF
      UNIONS
      {y | ?x. x IN {X | mcell_set V X /\ edgeX V X e} /\ y = x INTER D}`);
 (SET_TAC[]);

(* ========================================================================= *)
(* ========================================================================= *)
(* ========================================================================= *)

 (UP_ASM_TAC);
 (ABBREV_TAC `t ={X | mcell_set V X /\ edgeX V X e /\ ~NULLSET (X INTER D)}`);

 (REWRITE_WITH `sum s (\t. vol (t INTER D)) = 
                 sum t (\t. vol (t INTER D))`);
 (MATCH_MP_TAC SUM_SUPERSET);
 (EXPAND_TAC "s" THEN EXPAND_TAC "t" THEN REPEAT STRIP_TAC);
 (SET_TAC[]);
 (MATCH_MP_TAC MEASURE_EQ_0);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN REWRITE_TAC[IN; IN_ELIM_THM] );
 (MESON_TAC[]);


 (REWRITE_WITH `sum s (\t. dihX V t (u0,u1)) = 
                 sum t (\t. dihX V t (u0,u1))`);
 (MATCH_MP_TAC SUM_SUPERSET);
 (EXPAND_TAC "s" THEN EXPAND_TAC "t" THEN REPEAT STRIP_TAC);
 (SET_TAC[]);

 (NEW_GOAL `NULLSET (x INTER D)`);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN REWRITE_TAC[IN; IN_ELIM_THM] );
 (MESON_TAC[]);

 (NEW_GOAL `mcell_set V x /\ edgeX V x e`);
 (UNDISCH_TAC `x IN {X | mcell_set V X /\ edgeX V X e}`);
 (REWRITE_TAC[IN; IN_ELIM_THM]);
 (UP_ASM_TAC THEN REWRITE_TAC[mcell_set_2; IN_ELIM_THM;IN] THEN STRIP_TAC);

 (NEW_GOAL `~NULLSET x`);
 (UP_ASM_TAC THEN REWRITE_TAC[edgeX; VX; IN_ELIM_THM]);
 (COND_CASES_TAC THEN REPEAT STRIP_TAC);
 (UNDISCH_TAC `{} (u:real^3)` THEN REWRITE_TAC[MESON[IN] `{} x <=> x IN {}`]);
 (SET_TAC[]);

 (NEW_GOAL `VX V x = V INTER (x:real^3->bool)`);
 (MATCH_MP_TAC Hdtfnfz.HDTFNFZ);
 (EXISTS_TAC `ul:(real^3)list` THEN EXISTS_TAC `i:num`);
 (ASM_REWRITE_TAC[]);

 (NEW_GOAL `V INTER (x:real^3->bool) = 
             set_of_list (truncate_simplex (i - 1) ul)`);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC Lepjbdj.LEPJBDJ);
 (ASM_REWRITE_TAC[]);
 (STRIP_TAC);
 (ASM_CASES_TAC `i = 0`);
 (NEW_GOAL `V INTER (x:real^3->bool) = {}`);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC Lepjbdj.LEPJBDJ_0);
 (ASM_REWRITE_TAC[]);
 (NEW_GOAL `F`);
 (UNDISCH_TAC `edgeX V x e` THEN REWRITE_TAC[edgeX; IN_ELIM_THM]);
 (STRIP_TAC);
 (UNDISCH_TAC `VX V x u` THEN ASM_REWRITE_TAC[MESON[IN] `{} x <=> x IN {}`]);
 (SET_TAC[]);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (UP_ASM_TAC THEN ARITH_TAC);
 (REWRITE_TAC[GSYM (ASSUME `x = mcell i V ul`)] THEN STRIP_TAC);
 (UNDISCH_TAC `~NULLSET x` THEN REWRITE_TAC[ASSUME `x:real^3->bool = {}`;
   NEGLIGIBLE_EMPTY]);

 (NEW_GOAL `(u0:real^3) IN VX V x /\ u1 IN VX V x`);
 (UNDISCH_TAC `edgeX V x e` THEN REWRITE_TAC[edgeX; IN_ELIM_THM; 
   ASSUME `e = {u0, u1:real^3}`]);
 (STRIP_TAC);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN UP_ASM_TAC THEN UP_ASM_TAC THEN SET_TAC[]);

(* ========================================================================== *)
 (NEW_GOAL `F`);

 (ASM_CASES_TAC `i <= 1`);
 (NEW_GOAL `?v0 v1 v2 v3. ul = [v0; v1; v2 ;v3:real^3]`);
 (MATCH_MP_TAC BARV_3_EXPLICIT);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (NEW_GOAL `i - 1 = 0`);
 (UNDISCH_TAC `i <= 1` THEN ARITH_TAC);
 (UNDISCH_TAC `u0 IN VX V x /\ u1 IN VX V x`);
 (ASM_REWRITE_TAC[TRUNCATE_SIMPLEX_EXPLICIT_0; set_of_list]);
 (UNDISCH_TAC `~(u0 = u1:real^3)` THEN SET_TAC[]);

 (ASM_CASES_TAC `i = 3`);
 (NEW_GOAL `vol (x INTER D) > &0`);
 (ONCE_REWRITE_TAC[SET_RULE `a INTER b = b INTER a`]);
 (NEW_GOAL `?v0 v1 v2 v3. ul = [v0; v1; v2 ;v3:real^3]`);
 (MATCH_MP_TAC BARV_3_EXPLICIT);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (ASM_REWRITE_TAC[MCELL_EXPLICIT; mcell3; TRUNCATE_SIMPLEX_EXPLICIT_2; 
   set_of_list; SET_RULE `{a,c,d} UNION {x} = {a,c,d,x}`]);
 (COND_CASES_TAC);
 (NEW_GOAL `i - 1 = 2`);
 (UNDISCH_TAC `i = 3` THEN ARITH_TAC);
 (UNDISCH_TAC `u0 IN VX V x /\ u1 IN VX V x`);
 (ASM_REWRITE_TAC[TRUNCATE_SIMPLEX_EXPLICIT_2; set_of_list]);
 (STRIP_TAC);
 (NEW_GOAL `?v:real^3. {u0, u1, v} = {v0, v1, v2}`);
 (NEW_GOAL `?v:real^3. v IN {v0, v1, v2} DIFF {u0, u1}`);
 (REWRITE_TAC[SET_RULE `(?x. x IN s) <=> ~(s = {})`]);
 (REWRITE_WITH `{v0, v1, v2} DIFF {u0, u1:real^3} = {} <=> 
                  CARD ({v0, v1, v2} DIFF {u0, u1}) = 0`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC CARD_EQ_0);
 (MATCH_MP_TAC FINITE_SUBSET);
 (EXISTS_TAC `{v0, v1, v2:real^3}`);
 (REWRITE_TAC[Geomdetail.FINITE6] THEN SET_TAC[]);
 (REWRITE_TAC[ARITH_RULE `~(a = 0) <=> 1 <= a`]);

 (NEW_GOAL `CARD {v0, v1, v2} = CARD ({v0, v1, v2} DIFF {u0, u1:real^3}) +
                                 CARD {u0, u1}`);
 (MATCH_MP_TAC Hypermap.CARD_MINUS_DIFF_TWO_SET);
 (ASM_REWRITE_TAC[Geomdetail.FINITE6]);
 (UP_ASM_TAC THEN REWRITE_WITH `CARD ({v0, v1, v2:real^3}) = 3`);
 (REWRITE_WITH `{v0, v1, v2:real^3} = set_of_list (truncate_simplex 2 ul)`);
 (ASM_REWRITE_TAC[TRUNCATE_SIMPLEX_EXPLICIT_2; set_of_list]);
 (ABBREV_TAC `xl = truncate_simplex 2 (ul:(real^3)list)`);
 (REWRITE_WITH `LENGTH (xl:(real^3)list) = 2 + 1 /\ 
                 CARD (set_of_list xl) = 2 + 1`);
 (MATCH_MP_TAC Rogers.BARV_IMP_LENGTH_EQ_CARD);
 (EXISTS_TAC `V:real^3->bool` THEN STRIP_TAC);
 (ASM_REWRITE_TAC[]);
 (EXPAND_TAC "xl" THEN MATCH_MP_TAC Packing3.TRUNCATE_SIMPLEX_BARV);
 (EXISTS_TAC `3` THEN ASM_REWRITE_TAC[ARITH_RULE `2 <= 3`]);
 (ARITH_TAC);

 (NEW_GOAL `CARD {u0, u1:real^3} <= 2`);
 (REWRITE_TAC[Geomdetail.CARD2]);
 (UP_ASM_TAC THEN ARITH_TAC);
 (UP_ASM_TAC THEN STRIP_TAC);
 (EXISTS_TAC `v:real^3`);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN UP_ASM_TAC THEN 
   UNDISCH_TAC `~(u0 = u1:real^3)` THEN SET_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (NEW_GOAL `{v0, v1, v2, mxi V [v0; v1; v2; v3]} = 
             {u0, u1, v, mxi V [v0; v1; v2; v3]}`);
 (UP_ASM_TAC THEN SET_TAC[]);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC CONIC_CAP_INTER_CONVEX_HULL_4_GT_0);
 (ASM_REWRITE_TAC[]);
 (STRIP_TAC);
 (EXPAND_TAC "d" THEN UNDISCH_TAC `&0 < c /\ c < &1` THEN REAL_ARITH_TAC);
 (REWRITE_TAC[GSYM (ASSUME `{v0, v1, v2, mxi V [v0; v1; v2; v3]} =
               {u0, u1, v, mxi V [v0; v1; v2; v3]}`)] THEN STRIP_TAC);
 (UNDISCH_TAC `~NULLSET x`);
 (ASM_REWRITE_TAC[MCELL_EXPLICIT; mcell3; set_of_list;
   TRUNCATE_SIMPLEX_EXPLICIT_2]);
 (REWRITE_TAC[SET_RULE `{a,b,c} UNION {d} = {a,b,c,d}`]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {v0, v1, v2, mxi V [v0; v1; v2; v3]}`);
 (REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (MATCH_MP_TAC COPLANAR_IMP_NEGLIGIBLE);
 (REWRITE_TAC[COPLANAR_AFFINE_HULL_COPLANAR]);
 (ASM_REWRITE_TAC[]);

 (NEW_GOAL `F`);
 (UNDISCH_TAC `~NULLSET x`);
 (ASM_REWRITE_TAC[MCELL_EXPLICIT; mcell3; set_of_list;
   TRUNCATE_SIMPLEX_EXPLICIT_2]);
 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (NEW_GOAL `vol (x INTER D) = &0`);
 (MATCH_MP_TAC MEASURE_EQ_0);
 (ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN REAL_ARITH_TAC);


(* ========================================== *)

 (ASM_CASES_TAC `i = 4`);
 (NEW_GOAL `vol (x INTER D) > &0`);
 (ONCE_REWRITE_TAC[SET_RULE `a INTER b = b INTER a`]);
 (NEW_GOAL `?v0 v1 v2 v3. ul = [v0; v1; v2 ;v3:real^3]`);
 (MATCH_MP_TAC BARV_3_EXPLICIT);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (ASM_SIMP_TAC[MCELL_EXPLICIT; mcell4; ARITH_RULE `4 >= 4`; 
   set_of_list]);
 (COND_CASES_TAC);
 (NEW_GOAL `i - 1 = 3`);
 (UNDISCH_TAC `i = 4` THEN ARITH_TAC);
 (UNDISCH_TAC `u0 IN VX V x /\ u1 IN VX V x`);
 (ASM_REWRITE_TAC[TRUNCATE_SIMPLEX_EXPLICIT_3; set_of_list]);
 (STRIP_TAC);

 (NEW_GOAL `?v w:real^3. {u0, u1, v, w} = {v0, v1, v2, v3}`);

 (NEW_GOAL `?v:real^3. v IN {v0, v1, v2, v3} DIFF {u0, u1}`);
 (REWRITE_TAC[SET_RULE `(?x. x IN s) <=> ~(s = {})`]);
 (REWRITE_WITH `{v0, v1, v2, v3} DIFF {u0, u1:real^3} = {} <=> 
                  CARD ({v0, v1, v2, v3} DIFF {u0, u1}) = 0`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC CARD_EQ_0);
 (MATCH_MP_TAC FINITE_SUBSET);
 (EXISTS_TAC `{v0, v1, v2, v3:real^3}`);
 (REWRITE_TAC[Geomdetail.FINITE6] THEN SET_TAC[]);
 (REWRITE_TAC[ARITH_RULE `~(a = 0) <=> 1 <= a`]);

 (NEW_GOAL `CARD {v0, v1, v2, v3} = 
             CARD ({v0, v1, v2, v3} DIFF {u0, u1:real^3}) + CARD {u0, u1}`);
 (MATCH_MP_TAC Hypermap.CARD_MINUS_DIFF_TWO_SET);
 (ASM_REWRITE_TAC[Geomdetail.FINITE6]);

 (UP_ASM_TAC THEN REWRITE_WITH `CARD ({v0, v1, v2, v3:real^3}) = 3 + 1`);
 (REWRITE_WITH `{v0, v1, v2, v3:real^3} = set_of_list ul`);
 (ASM_REWRITE_TAC[set_of_list]);
 (REWRITE_WITH `LENGTH (ul:(real^3)list) = 3 + 1 /\ 
                 CARD (set_of_list ul) = 3 + 1`);
 (MATCH_MP_TAC Rogers.BARV_IMP_LENGTH_EQ_CARD);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (NEW_GOAL `CARD {u0, u1:real^3} <= 2`);
 (REWRITE_TAC[Geomdetail.CARD2]);
 (UP_ASM_TAC THEN ARITH_TAC);
 (UP_ASM_TAC THEN STRIP_TAC);

 (NEW_GOAL `?w:real^3. w IN {v0, v1, v2, v3} DIFF {u0, u1, v}`);
 (REWRITE_TAC[SET_RULE `(?x. x IN s) <=> ~(s = {})`]);
 (REWRITE_WITH `{v0, v1, v2, v3} DIFF {u0, u1, v:real^3} = {} <=> 
                  CARD ({v0, v1, v2, v3} DIFF {u0, u1, v}) = 0`);
 (ONCE_REWRITE_TAC[EQ_SYM_EQ]);
 (MATCH_MP_TAC CARD_EQ_0);
 (MATCH_MP_TAC FINITE_SUBSET);
 (EXISTS_TAC `{v0, v1, v2, v3:real^3}`);
 (REWRITE_TAC[Geomdetail.FINITE6] THEN SET_TAC[]);
 (REWRITE_TAC[ARITH_RULE `~(a = 0) <=> 1 <= a`]);

 (NEW_GOAL `CARD ({v0, v1, v2, v3} DIFF {u0, u1,v:real^3}) = 
             CARD {v0, v1, v2, v3} - CARD {u0,u1,v}`);
 (MATCH_MP_TAC CARD_DIFF);
 (ASM_REWRITE_TAC[Geomdetail.FINITE6]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN UP_ASM_TAC THEN SET_TAC[]);
 (UP_ASM_TAC THEN REWRITE_WITH `CARD ({v0, v1, v2, v3:real^3}) = 3 + 1`);
 (REWRITE_WITH `{v0, v1, v2, v3:real^3} = set_of_list ul`);
 (ASM_REWRITE_TAC[set_of_list]);
 (REWRITE_WITH `LENGTH (ul:(real^3)list) = 3 + 1 /\ 
                 CARD (set_of_list ul) = 3 + 1`);
 (MATCH_MP_TAC Rogers.BARV_IMP_LENGTH_EQ_CARD);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (NEW_GOAL `CARD {u0, u1, v:real^3} <= 3`);
 (REWRITE_TAC[Geomdetail.CARD3]);
 (UP_ASM_TAC THEN ARITH_TAC);
 (UP_ASM_TAC THEN STRIP_TAC);

 (EXISTS_TAC `v:real^3` THEN EXISTS_TAC `w:real^3`);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN UP_ASM_TAC THEN UP_ASM_TAC THEN 
   UNDISCH_TAC `~(u0 = u1:real^3)` THEN SET_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (REWRITE_TAC[GSYM (ASSUME `{u0:real^3, u1, v, w} = {v0, v1, v2, v3}`)]);
 (MATCH_MP_TAC CONIC_CAP_INTER_CONVEX_HULL_4_GT_0);
 (ASM_REWRITE_TAC[]);
 (STRIP_TAC);
 (EXPAND_TAC "d" THEN UNDISCH_TAC `&0 < c /\ c < &1` THEN REAL_ARITH_TAC);
 (STRIP_TAC);
 (UNDISCH_TAC `~NULLSET x`);
 (SIMP_TAC[MCELL_EXPLICIT; mcell4; set_of_list; ARITH_RULE `4 >= 4`; 
   ASSUME `x  = mcell i V ul`; ASSUME `i = 4`; 
   ASSUME `ul = [v0; v1; v2; v3:real^3]`]);
 (COND_CASES_TAC);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull {v0, v1, v2, v3:real^3}`);
 (REWRITE_TAC[CONVEX_HULL_SUBSET_AFFINE_HULL]);
 (MATCH_MP_TAC COPLANAR_IMP_NEGLIGIBLE);
 (REWRITE_TAC[COPLANAR_AFFINE_HULL_COPLANAR]);
 (ASM_REWRITE_TAC[]);
 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);

 (NEW_GOAL `F`);
 (UNDISCH_TAC `~NULLSET x`);
 (SIMP_TAC[MCELL_EXPLICIT; mcell4; set_of_list; ARITH_RULE `4 >= 4`; 
   ASSUME `x  = mcell i V ul`; ASSUME `i = 4`; 
   ASSUME `ul = [v0; v1; v2; v3:real^3]`]);
 (COND_CASES_TAC);
 (NEW_GOAL `F`);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (NEW_GOAL `vol (x INTER D) = &0`);
 (MATCH_MP_TAC MEASURE_EQ_0);
 (ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN REAL_ARITH_TAC);

(* ========================================== *)

 (NEW_GOAL `i = 2`);
 (UNDISCH_TAC `i <= 4` THEN UP_ASM_TAC THEN UP_ASM_TAC THEN UP_ASM_TAC 
   THEN ARITH_TAC);


 (NEW_GOAL `vol (x INTER D) > &0`);
 (ONCE_REWRITE_TAC[SET_RULE `a INTER b = b INTER a`]);
 (NEW_GOAL `?v0 v1 v2 v3. ul = [v0; v1; v2 ;v3:real^3]`);
 (MATCH_MP_TAC BARV_3_EXPLICIT);
 (EXISTS_TAC `V:real^3->bool` THEN ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN STRIP_TAC);
 (ASM_REWRITE_TAC[MCELL_EXPLICIT; mcell2; TRUNCATE_SIMPLEX_EXPLICIT_1; 
   set_of_list; HD; TL]);
 (LET_TAC);
 (COND_CASES_TAC);

 (NEW_GOAL `i - 1 = 1`);
 (UNDISCH_TAC `i = 2` THEN ARITH_TAC);
 (UNDISCH_TAC `u0 IN VX V x /\ u1 IN VX V x`);
 (ASM_REWRITE_TAC[TRUNCATE_SIMPLEX_EXPLICIT_1; set_of_list]);
 (STRIP_TAC);
 (NEW_GOAL `{u0, u1} = {v0, v1:real^3}`);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN UNDISCH_TAC `~(u0 = u1:real^3)` THEN
   SET_TAC[]);
 (REWRITE_TAC[SET_RULE `A INTER B INTER C INTER D = 
                        (A INTER (B INTER C)) INTER D`]);
 (REWRITE_WITH `rcone_ge v0 v1 a' INTER rcone_ge v1 v0 a' = 
                 rcone_ge u0 u1 a' INTER rcone_ge u1 (u0:real^3) a'`);
 (ASM_CASES_TAC `u0:real^3 = v0`);
 (NEW_GOAL `u1 = v1:real^3`);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN SET_TAC[]);
 (ASM_REWRITE_TAC[]);
 (NEW_GOAL `u0 = v1:real^3`);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN SET_TAC[]);
 (NEW_GOAL `u1 = v0:real^3`);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN UP_ASM_TAC THEN SET_TAC[]);
 (ASM_REWRITE_TAC[]);
 (SET_TAC[]);

 (REWRITE_WITH 
  `conic_cap u0 u1 r d INTER rcone_ge u0 u1 a' INTER rcone_ge u1 u0 a' =
   conic_cap (u0:real^3) u1 r d`);
 (MATCH_MP_TAC (SET_RULE `A SUBSET B ==> A INTER B = A`));

 (NEW_GOAL `conic_cap (u0:real^3) u1 r d SUBSET rcone_ge u0 u1 a'`);
 (REWRITE_TAC[conic_cap]);
 (MATCH_MP_TAC (SET_RULE `A SUBSET B ==> C INTER A SUBSET B`));
 (NEW_GOAL `rcone_gt u0 u1 d SUBSET rcone_gt (u0:real^3) u1 a'`);
 (MATCH_MP_TAC RCONE_GT_SUBSET);
 (EXPAND_TAC "d" THEN EXPAND_TAC "c");
 (MATCH_MP_TAC (REAL_ARITH `a = x ==> a <= max (max y x) (max z t)`));
 (EXPAND_TAC "a'" THEN REWRITE_TAC[HL; set_of_list] THEN ASM_REWRITE_TAC[]);
 (NEW_GOAL `rcone_gt u0 u1 a' SUBSET rcone_ge (u0:real^3) u1 a'`);
 (REWRITE_TAC[RCONE_GT_SUBSET_RCONE_GE]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN SET_TAC[]);
 (REWRITE_TAC[SUBSET_INTER] THEN STRIP_TAC);
 (ASM_REWRITE_TAC[]);

 (REWRITE_TAC[SUBSET]);
 (REPEAT STRIP_TAC);
 (MATCH_MP_TAC Marchal_cells_2_new.RCONEGE_INTER_VORONOI_CLOSED_IMP_RCONEGE);
 (EXISTS_TAC `V:real^3->bool`);
 (ASM_REWRITE_TAC[]);
 (REPEAT STRIP_TAC);

 (REWRITE_WITH `a' = hl [u0; u1:real^3] / sqrt (&2)`);
 (EXPAND_TAC "a'");
 (REWRITE_TAC[HL; set_of_list] THEN ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC REAL_LT_DIV);
 (REWRITE_TAC[HL_2]);
 (STRIP_TAC);
 (MATCH_MP_TAC REAL_LT_MUL);
 (REWRITE_TAC[REAL_ARITH `&0 < inv (&2)`]);
 (MATCH_MP_TAC DIST_POS_LT);
 (ASM_REWRITE_TAC[]);
 (MATCH_MP_TAC SQRT_POS_LT);
 (REAL_ARITH_TAC);
 (EXPAND_TAC "a'");
 (MATCH_MP_TAC REAL_DIV_LE_1_TACTICS);
 (STRIP_TAC);
 (MATCH_MP_TAC SQRT_POS_LT);
 (REAL_ARITH_TAC);
 (MATCH_MP_TAC (REAL_ARITH `a < b ==> a <= b`));
 (ASM_REWRITE_TAC[]);

 (UP_ASM_TAC THEN UP_ASM_TAC THEN SET_TAC[]);
 (NEW_GOAL `x':real^3 IN ball (u0, (&1))`);
 (UP_ASM_TAC THEN REWRITE_TAC[conic_cap;NORMBALL_BALL] THEN STRIP_TAC);
 (NEW_GOAL `ball (u0, r) SUBSET ball (u0:real^3, &1)`);
 (MATCH_MP_TAC SUBSET_BALL);
 (EXPAND_TAC "r");
 (REAL_ARITH_TAC);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN SET_TAC[]);
 (UP_ASM_TAC THEN REWRITE_TAC[IN_BALL] THEN ONCE_REWRITE_TAC[DIST_SYM] 
   THEN STRIP_TAC);
 (REWRITE_TAC[voronoi_closed; IN; IN_ELIM_THM]);
 (REPEAT STRIP_TAC);
 (ASM_CASES_TAC `u0 = w:real^3`);
 (ASM_REWRITE_TAC[] THEN REAL_ARITH_TAC);
 (NEW_GOAL `&2 <= dist (u0, w:real^3)`);
 (UNDISCH_TAC `packing (V:real^3->bool)` THEN REWRITE_TAC[packing]);
 (STRIP_TAC);
 (FIRST_ASSUM MATCH_MP_TAC);
 (ASM_REWRITE_TAC[]);
 (UNDISCH_TAC `u0:real^3 IN V` THEN REWRITE_TAC[IN]);
 (NEW_GOAL `dist (x', u0) >= dist (u0, w) - dist (x', w:real^3)`);
 (NORM_ARITH_TAC);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN DEL_TAC THEN DEL_TAC THEN UP_ASM_TAC
   THEN REAL_ARITH_TAC);
 (ABBREV_TAC `M = mxi V [v0; v1; v2; v3]`);
 (ABBREV_TAC `R = omega_list_n V [v0; v1; v2; v3] 3`);

 (NEW_GOAL `vol (conic_cap u0 u1 r d INTER convex hull {v0:real^3,v1,M,R}) 
         <=  vol (conic_cap u0 u1 r d INTER aff_ge {v0, v1} {M, R})`);
 (MATCH_MP_TAC MEASURE_SUBSET);
 (REPEAT STRIP_TAC);
 (MATCH_MP_TAC MEASURABLE_INTER);
 (REWRITE_TAC[MEASURABLE_CONIC_CAP]);
 (MATCH_MP_TAC MEASURABLE_CONVEX_HULL);
 (MATCH_MP_TAC FINITE_IMP_BOUNDED);
 (REWRITE_TAC[Geomdetail.FINITE6]);

 (REWRITE_TAC[conic_cap; NORMBALL_BALL]);
 (ONCE_REWRITE_TAC[SET_RULE `(a INTER b) INTER c = 
                              (a INTER b) INTER (a INTER c)`]);
 (MATCH_MP_TAC MEASURABLE_INTER);
 (REWRITE_TAC[MEASURABLE_BALL_AFF_GE]);
 (REWRITE_TAC[GSYM conic_cap; GSYM NORMBALL_BALL; MEASURABLE_CONIC_CAP]);

 (MATCH_MP_TAC (SET_RULE `A SUBSET B ==> C INTER A SUBSET C INTER B`));
 (REWRITE_TAC[Marchal_cells_2_new.CONVEX_HULL_4_SUBSET_AFF_GE_2_2]);



 (NEW_GOAL `vol (conic_cap u0 u1 r d INTER convex hull {v0, v1, M, R}) > &0`);
 (REWRITE_WITH `{v0, v1, M, R} = {u0, u1, M, R:real^3}`);
 (UNDISCH_TAC `{u0, u1} = {v0, v1:real^3}` THEN SET_TAC[]);
 (MATCH_MP_TAC CONIC_CAP_INTER_CONVEX_HULL_4_GT_0);
 (ASM_REWRITE_TAC[]);
 (REPEAT STRIP_TAC);
 (EXPAND_TAC "d" THEN UNDISCH_TAC `&0 < c /\ c < &1` THEN REAL_ARITH_TAC);

 (UNDISCH_TAC `~NULLSET x`);
 (ASM_REWRITE_TAC[MCELL_EXPLICIT; mcell2; set_of_list;
   TRUNCATE_SIMPLEX_EXPLICIT_1; HD; TL]);
 (LET_TAC);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `aff_ge {v0, v1} {M, R:real^3}`);
 (REWRITE_TAC[SET_RULE `a INTER B INTER c SUBSET c`]);
 (MATCH_MP_TAC NEGLIGIBLE_SUBSET);
 (EXISTS_TAC `affine hull ({v0, v1} UNION {M, R:real^3})`);
 (REWRITE_TAC[AFF_GE_SUBSET_AFFINE_HULL; SET_RULE 
  `{a, b} UNION {c, d} = {a,b,c,d}`]);
 (MATCH_MP_TAC COPLANAR_IMP_NEGLIGIBLE);
 (REWRITE_TAC[COPLANAR_AFFINE_HULL_COPLANAR]);
 (REWRITE_WITH `{v0, v1, M, R} = {u0, u1, M, R:real^3}`);
 (UNDISCH_TAC `{u0, u1} = {v0, v1:real^3}` THEN SET_TAC[]);
 (ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN REAL_ARITH_TAC);

 (NEW_GOAL `F`);
 (UNDISCH_TAC `~NULLSET x`);
 (ASM_REWRITE_TAC[MCELL_EXPLICIT; mcell2; set_of_list;
   TRUNCATE_SIMPLEX_EXPLICIT_1; HD; TL]);
 (REWRITE_TAC[NEGLIGIBLE_EMPTY]);
 (UP_ASM_TAC THEN MESON_TAC[]);

 (NEW_GOAL `vol (x INTER D) = &0`);
 (MATCH_MP_TAC MEASURE_EQ_0);
 (ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN UP_ASM_TAC THEN REAL_ARITH_TAC);
 (UP_ASM_TAC THEN MESON_TAC[]);

(* ========================================== *)

 (REWRITE_WITH `sum t (\t. vol (t INTER D)) = 
                 sum t (\t. vol D * dihX V t (u0,u1) / (&2 * pi))`);
 (MATCH_MP_TAC SUM_EQ);
 (EXPAND_TAC "t" THEN REWRITE_TAC[IN_ELIM_THM; IN] THEN REPEAT STRIP_TAC);
 (ASM_SIMP_TAC[]);
 (REWRITE_TAC[REAL_ARITH `a * b / c = (a / c) * b`]);
 (REWRITE_TAC[SUM_LMUL]);
 (ABBREV_TAC `R = sum t (\t. dihX V t (u0,u1))`);
 (REWRITE_TAC[REAL_ARITH `a / b * c = (a * c) / b`]);
 (REWRITE_WITH `(vol D * R) / (&2 * pi) = vol D <=> 
                 (vol D * R) = vol D * (&2 * pi)`);
 (MATCH_MP_TAC REAL_EQ_LDIV_EQ);
 (MATCH_MP_TAC REAL_LT_MUL);
 (REWRITE_TAC[PI_POS]);
 (REAL_ARITH_TAC);
 (REWRITE_TAC[REAL_ARITH `a * b = a * c <=> a * (b - c) = &0`]);
 (REWRITE_TAC[REAL_ENTIRE]);
 (STRIP_TAC);
 (NEW_GOAL `F`);
 (UP_ASM_TAC THEN ASM_REWRITE_TAC[]);

 (NEW_GOAL `&0 < d`);
 (EXPAND_TAC "d" THEN UNDISCH_TAC `&0 < c /\ c < &1` THEN REAL_ARITH_TAC);
 (ASM_SIMP_TAC[VOLUME_CONIC_CAP]);
 (COND_CASES_TAC);
 (REWRITE_TAC[]);
 (UNDISCH_TAC `d < &1` THEN UNDISCH_TAC `&0 < r` THEN UP_ASM_TAC 
   THEN REAL_ARITH_TAC);
 (REWRITE_TAC[REAL_ARITH `&2 / &3 * a = &0 <=> a = &0`]);
 (REWRITE_TAC[REAL_ENTIRE]);
 (NEW_GOAL `~(pi = &0)`);
 (MP_TAC PI_POS THEN REAL_ARITH_TAC);
 (NEW_GOAL `~(&1 - d = &0)`);
 (UNDISCH_TAC `d < &1` THEN REAL_ARITH_TAC);
 (NEW_GOAL `~(r pow 3 = &0)`);
 (MATCH_MP_TAC REAL_POW_NZ);
 (UNDISCH_TAC `&0 < r` THEN REAL_ARITH_TAC);
 (ASM_REWRITE_TAC[]);
 (UP_ASM_TAC THEN MESON_TAC[]);
 (UP_ASM_TAC THEN REAL_ARITH_TAC)]);;