(* ========================================================================== *)
(* FLYSPECK - BOOK FORMALIZATION *)
(* *)
(* Chapter: Packing *)
(* Author: John Harrison *)
(* Date: 2010-03-16 *)
(* *)
(* This proves theorems about closed Voronoi cells and transfers the main *)
(* results proved in Pack1 by Nguyen Tat Thang from open to closed cells. *)
(* ========================================================================== *)
module type Pack2_type = sig
end;;
flyspeck_needs "packing/pack1.hl";;
module Pack2 (* : Pack1_type *) = struct
(* ------------------------------------------------------------------------- *)
(* Slight variants of definitions, mainly to use IN. *)
(* ------------------------------------------------------------------------- *)
(* ------------------------------------------------------------------------- *)
(* Minor variant of KIUMVTC without 0 <= r condition. *)
(* ------------------------------------------------------------------------- *)
(* ------------------------------------------------------------------------- *)
(* The basic lemmas about closed Voronoi cells. *)
(* ------------------------------------------------------------------------- *)
let VORONOI_CLOSED_SUBSET_BALL = prove
(`!s v:real^N. saturated s ==>
voronoi_closed s v
SUBSET ball(v,&2)`,
REPEAT STRIP_TAC THEN REWRITE_TAC[
VORONOI_CLOSED;
SUBSET] THEN
REWRITE_TAC[
IN_ELIM_THM;
IN_BALL] THEN
X_GEN_TAC `x:real^N` THEN DISCH_TAC THEN
FIRST_X_ASSUM(MP_TAC o SPEC `x:real^N` o GEN_REWRITE_RULE I
[Pack1.saturated]) THEN
DISCH_THEN(X_CHOOSE_THEN `y:real^N` (CONJUNCTS_THEN2 ASSUME_TAC MP_TAC)) THEN
FIRST_X_ASSUM(MP_TAC o SPEC `y:real^N`) THEN
ASM_REWRITE_TAC[] THEN NORM_ARITH_TAC);;
let VORONOI_CLOSED_AS_FINITE_INTERSECTION = prove
(`!s v. packing s /\ saturated s /\ v
IN s
==>
voronoi_closed s v =
INTERS (
IMAGE (
bis_le v) ((s
INTER ball(v,&4))
DELETE v))`,
REPEAT STRIP_TAC THEN MATCH_MP_TAC
SUBSET_ANTISYM THEN CONJ_TAC THENL
[REWRITE_TAC[
VORONOI_CLOSED_AS_INTERSECTION] THEN SET_TAC[]; ALL_TAC] THEN
REWRITE_TAC[
SUBSET] THEN X_GEN_TAC `p:real^3` THEN
DISCH_TAC THEN
SUBGOAL_THEN
`?p':real^3. aff_ge {v} {p}
INTER voronoi_closed s v =
segment[v,p']`
STRIP_ASSUME_TAC THENL
[MATCH_MP_TAC
HALFLINE_INTER_COMPACT_SEGMENT THEN
ASM_SIMP_TAC[
COMPACT_VORONOI_CLOSED;
CONVEX_VORONOI_CLOSED;
BASE_IN_VORONOI_CLOSED];
ALL_TAC] THEN
MATCH_MP_TAC(TAUT `(~p ==> F) ==> p`) THEN DISCH_TAC THEN
SUBGOAL_THEN
`(v:real^3)
IN voronoi_closed s v /\ p'
IN voronoi_closed s v /\
p'
IN aff_ge {v} {p}`
STRIP_ASSUME_TAC THENL
[ASM_MESON_TAC[
ENDS_IN_SEGMENT;
IN_INTER]; ALL_TAC] THEN
SUBGOAL_THEN `p'
IN ball(v:real^3,&2)` ASSUME_TAC THENL
[ASM_MESON_TAC[
VORONOI_CLOSED_SUBSET_BALL;
SUBSET]; ALL_TAC] THEN
SUBGOAL_THEN
`?q:real^3.
q
IN ball(v,&2) /\
q
IN INTERS(
IMAGE (
bis_le v) ((s
INTER ball (v,&4))
DELETE v)) /\
~(q
IN voronoi_closed s v)`
STRIP_ASSUME_TAC THENL
[ASM_CASES_TAC `p
IN ball(v:real^3,&2)` THENL
[ASM_MESON_TAC[]; ALL_TAC] THEN
ASM_CASES_TAC `p:real^3 = v` THENL [ASM_MESON_TAC[]; ALL_TAC] THEN
SUBGOAL_THEN
`?t. &0 <= t /\ t < &1 /\ p':real^3 = (&1 - t) % v + t % p`
STRIP_ASSUME_TAC THENL
[UNDISCH_TAC `(p':real^3)
IN aff_ge {v} {p}` THEN
ASM_REWRITE_TAC[
HALFLINE;
IN_SEGMENT;
IN_ELIM_THM] THEN
MATCH_MP_TAC
MONO_EXISTS THEN X_GEN_TAC `t:real` THEN STRIP_TAC THEN
SUBGOAL_THEN `
dist(v:real^3,p') <
dist(v,p)` MP_TAC THENL
[ASM_MESON_TAC[
IN_BALL; REAL_ARITH `x < &2 /\ ~(y < &2) ==> x < y`];
ASM_REWRITE_TAC[]] THEN
REWRITE_TAC[VECTOR_ARITH
`(&1 - t) % x + t % y:real^N = x + t % (y - x)`] THEN
REWRITE_TAC[NORM_ARITH `
dist(v:real^N,v + x) =
norm x`;
NORM_MUL] THEN
REWRITE_TAC[
dist;
NORM_SUB] THEN
ONCE_REWRITE_TAC[REAL_ARITH `x * y < y <=> x * y < &1 * y`] THEN
ASM_SIMP_TAC[
REAL_LT_RMUL_EQ;
NORM_POS_LT;
VECTOR_SUB_EQ] THEN
ASM_REAL_ARITH_TAC;
ALL_TAC] THEN
MP_TAC(ISPECL [`v:real^3`; `&2`]
OPEN_BALL) THEN
REWRITE_TAC[
open_def] THEN DISCH_THEN(MP_TAC o SPEC `p':real^3`) THEN
ASM_REWRITE_TAC[
LEFT_IMP_EXISTS_THM;
dist] THEN
X_GEN_TAC `e:real` THEN STRIP_TAC THEN
ABBREV_TAC `u = t + min (e / &2 /
norm(p - v:real^3)) ((&1 - t) / &2)` THEN
SUBGOAL_THEN `&0 < u /\ t < u /\ u < &1` STRIP_ASSUME_TAC THENL
[EXPAND_TAC "u" THEN MATCH_MP_TAC(REAL_ARITH
`&0 < x /\ &0 <= t /\ t < &1
==> &0 < t + min x ((&1 - t) / &2) /\ t < t + min x ((&1 - t) / &2) /\
t + min x ((&1 - t) / &2) < &1`) THEN
ASM_SIMP_TAC[
REAL_HALF;
REAL_LT_DIV;
NORM_POS_LT;
VECTOR_SUB_EQ];
ALL_TAC] THEN
EXISTS_TAC `(&1 - u) % v + u % p:real^3` THEN REPEAT CONJ_TAC THENL
[FIRST_X_ASSUM MATCH_MP_TAC THEN
ASM_SIMP_TAC[
NORM_MUL; GSYM
REAL_LT_RDIV_EQ;
NORM_POS_LT;
VECTOR_SUB_EQ;
VECTOR_ARITH
`((&1 - u) % v + u % p) - ((&1 - t) % v + t % p):real^N =
(u - t) % (p - v)`] THEN
EXPAND_TAC "u" THEN REWRITE_TAC[
REAL_ADD_SUB] THEN
MATCH_MP_TAC(REAL_ARITH
`&0 < z /\ &0 < y /\ x = z / &2 ==> abs(min x y) < z`) THEN
ASM_SIMP_TAC[
REAL_HALF;
REAL_LT_DIV;
NORM_POS_LT;
VECTOR_SUB_EQ] THEN
REWRITE_TAC[
real_div;
REAL_MUL_AC] THEN ASM_REAL_ARITH_TAC;
MATCH_MP_TAC
IN_CONVEX_SET THEN ASM_SIMP_TAC[
REAL_LT_IMP_LE] THEN
CONJ_TAC THENL
[MATCH_MP_TAC
CONVEX_INTERS THEN
REWRITE_TAC[
FORALL_IN_IMAGE;
BIS_LE;
CONVEX_HALFSPACE_LE];
UNDISCH_TAC `(v:real^3)
IN voronoi_closed s v` THEN
REWRITE_TAC[
VORONOI_CLOSED_AS_INTERSECTION] THEN SET_TAC[]];
DISCH_TAC THEN
SUBGOAL_THEN `((&1 - u) % v + u % p:real^3)
IN
(aff_ge {v} {p}
INTER voronoi_closed s v)`
MP_TAC THENL
[ASM_REWRITE_TAC[
IN_INTER;
HALFLINE;
IN_ELIM_THM] THEN
ASM_MESON_TAC[
REAL_LT_IMP_LE];
ASM_REWRITE_TAC[GSYM
BETWEEN_IN_SEGMENT] THEN
REWRITE_TAC[
between; VECTOR_ARITH
`(&1 - u) % x + u % y:real^N = x + u % (y - x)`] THEN
REWRITE_TAC[NORM_ARITH `
dist(v:real^N,v + x) =
norm x`;
NORM_ARITH `
dist(v + x:real^N,v + y) =
norm(x - y)`] THEN
REWRITE_TAC[GSYM
VECTOR_SUB_RDISTRIB;
NORM_MUL] THEN
ASM_REWRITE_TAC[
REAL_ENTIRE;
NORM_EQ_0;
VECTOR_SUB_EQ; REAL_ARITH
`x * a:real = y * a + z * a <=> a * (x - y - z) = &0`] THEN
ASM_REAL_ARITH_TAC]];
MP_TAC(ISPEC `s:real^3->bool`
VORONOI_CLOSED_PARTITION) THEN
ASM_REWRITE_TAC[
EXTENSION;
IN_UNIV] THEN
DISCH_THEN(MP_TAC o SPEC `q:real^3`) THEN REWRITE_TAC[] THEN
ONCE_REWRITE_TAC[
SIMPLE_IMAGE] THEN
REWRITE_TAC[
UNIONS_IMAGE;
IN_ELIM_THM] THEN
DISCH_THEN(X_CHOOSE_THEN `w:real^3` STRIP_ASSUME_TAC) THEN
UNDISCH_TAC
`(q:real^3)
IN INTERS(
IMAGE (
bis_le v)
((s
INTER ball(v,&4))
DELETE v))` THEN
REWRITE_TAC[
IN_INTERS;
FORALL_IN_IMAGE] THEN
DISCH_THEN(MP_TAC o SPEC `w:real^3`) THEN
ASM_REWRITE_TAC[NOT_IMP;
IN_DELETE;
IN_INTER;
IN_BALL] THEN
ASM_CASES_TAC `w:real^3 = v` THENL [ASM_MESON_TAC[]; ALL_TAC] THEN
ASM_REWRITE_TAC[] THEN CONJ_TAC THENL
[MATCH_MP_TAC(NORM_ARITH
`!q.
dist(q,w) <=
dist(q,v) /\
dist(v,q) < &2 ==>
dist(v,w) < &4`) THEN
EXISTS_TAC `q:real^3` THEN
RULE_ASSUM_TAC(REWRITE_RULE[
VORONOI_CLOSED;
IN_ELIM_THM;
IN_BALL]) THEN
ASM_SIMP_TAC[];
REWRITE_TAC[Sphere.bis_le;
IN_ELIM_THM] THEN
RULE_ASSUM_TAC(REWRITE_RULE[
VORONOI_CLOSED;
IN_ELIM_THM]) THEN
ASM_MESON_TAC[
REAL_LE_TRANS]]]);;
(* ------------------------------------------------------------------------- *)
(* Relate closed and open Voronoi cells. *)
(* ------------------------------------------------------------------------- *)
(* ------------------------------------------------------------------------- *)
(* And so. *)
(* ------------------------------------------------------------------------- *)
(* ------------------------------------------------------------------------- *)
(* Transfer theorems from Pack1 to closed cells where applicable. *)
(* ------------------------------------------------------------------------- *)
end;;