(* ========================================================================== *)
(* FLYSPECK - BOOK FORMALIZATION                                              *)
(*                                                                            *)
(* Chapter: Fan                                              *)
(* Author: Hoang Le Truong                                        *)
(* Date: 2010-02-09                                                           *)
(* ========================================================================== *)



flyspeck_needs "general/sphere.hl";;
flyspeck_needs "fan/introduction.hl";;


module Topology  = struct


(*
# use "/home/truong/Desktop/googlecode/hol_light/hol.ml";;
needs "/home/truong/Desktop/googlecode/hol_light/Multivariate/flyspeck.ml";;
needs "/home/truong/Desktop/googlecode/flyspeck/text_formalization/general/sphere.hl";;
*)


open Sphere;;
open Fan_defs;;
open Fan;;



let CARD_SIGMA_FAN=
prove(`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3). FAN(x,V,E) ==> CARD( IMAGE (sigma_fan x V E v) (set_of_edge v V E))= CARD(set_of_edge v V E) `,
REPEAT GEN_TAC THEN STRIP_TAC THEN MATCH_MP_TAC CARD_IMAGE_INJ THEN STRIP_TAC THENL[ REPEAT GEN_TAC THEN STRIP_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;`x':real^3`]properties_of_set_of_edge_fan) THEN ASM_REWRITE_TAC[] THEN STRIP_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;`y:real^3`]properties_of_set_of_edge_fan) THEN ASM_REWRITE_TAC[] THEN STRIP_TAC THEN ASM_MESON_TAC[MONO_SIGMA_FAN]; POP_ASSUM MP_TAC THEN REWRITE_TAC[FAN;fan1] THEN MESON_TAC[remark_finite_fan1]]);;
let MONO_AZIM_SIGMA_FAN=
prove(`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (w:real^3). FAN(x,V,E) /\ ({v,u} IN E) /\ ({v,w} IN E) /\ ~(sigma_fan x V E v w =u) ==> (azim x v u w <= azim x v u (sigma_fan x V E v w))`,
REPEAT GEN_TAC THEN STRIP_TAC THEN REPEAT(POP_ASSUM MP_TAC) THEN DISCH_THEN (LABEL_TAC"1") THEN USE_THEN "1" MP_TAC THEN REWRITE_TAC[FAN;fan6] THEN REPEAT STRIP_TAC THEN REPEAT(POP_ASSUM MP_TAC) THEN DISCH_THEN (LABEL_TAC"1") THEN DISCH_THEN (LABEL_TAC"a") THEN DISCH_TAC THEN DISCH_TAC THEN DISCH_TAC THEN DISCH_THEN(LABEL_TAC "b") THEN REPEAT STRIP_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (u:real^3)`;` (v:real^3)`]properties_of_graph) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN DISJ_CASES_TAC(SET_RULE`({(w:real^3)}=set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)) \/ ~({(w:real^3)}=set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))`) THENL(*1*)[ ASM_REWRITE_TAC[sigma_fan] THEN REAL_ARITH_TAC;(*1*) DISJ_CASES_TAC(SET_RULE`((u:real^3)=(w:real^3))\/ ~(u=w)`) THENL (*2*)[ ASM_REWRITE_TAC[AZIM_REFL] THEN MESON_TAC[azim];(*2*) DISJ_CASES_TAC(SET_RULE`(azim (x:real^3) (v:real^3) (u:real^3) (w:real^3) <= azim (x:real^3) (v:real^3) (u:real^3) (sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3)) ) \/ ~(azim (x:real^3) (v:real^3) (u:real^3) (w:real^3) <= azim (x:real^3) (v:real^3) (u:real^3) (sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3)) )`) THENL (*3*)[ ASM_REWRITE_TAC[];(*3*) SUBGOAL_THEN`azim (x:real^3) (v:real^3) (u:real^3) (sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3)) <= azim (x:real^3) (v:real^3) (u:real^3) (w:real^3) ` ASSUME_TAC THENL(*4*)[ POP_ASSUM MP_TAC THEN REAL_ARITH_TAC;(*4*) MP_TAC(ISPECL[`(v:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (u:real^3)`]properties_of_set_of_edge) THEN ASM_REWRITE_TAC[] THEN STRIP_TAC THEN MP_TAC(ISPECL[`(v:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (w:real^3)`]properties_of_set_of_edge) THEN ASM_REWRITE_TAC[] THEN STRIP_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (w:real^3)`]SIGMA_FAN) THEN ASM_REWRITE_TAC[] THEN STRIP_TAC THEN POP_ASSUM MP_TAC THEN DISCH_THEN (LABEL_TAC "c") THEN SUBGOAL_THEN `{(u:real^3),(sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3)),(w:real^3)}SUBSET set_of_edge v V E` ASSUME_TAC THENL(*5*)[ ASM_TAC THEN SET_TAC[];(*5*) MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`]CYCLIC_SET_EDGE_FAN) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;` (v:real^3)`;`{(u:real^3), (sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3)),(w:real^3)}`;`set_of_edge(v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)` ]subset_cyclic_set_fan) THEN ASM_REWRITE_TAC[] THEN STRIP_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;` (v:real^3)`;` (u:real^3)`;`(sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3))`;` (w:real^3)`]sum2_azim_fan) THEN ASM_REWRITE_TAC[] THEN STRIP_TAC THEN SUBGOAL_THEN `azim (x:real^3) (v:real^3) (sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3)) (w:real^3)<= azim x v u w` ASSUME_TAC THENL(*6*)[ MP_TAC(ISPECL[`x:real^3`; `v:real^3`; `u:real^3`; `sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3)`]azim) THEN REPEAT(POP_ASSUM MP_TAC) THEN REAL_ARITH_TAC;(*6*) POP_ASSUM MP_TAC THEN POP_ASSUM (fun th-> REWRITE_TAC[])THEN ASM_REWRITE_TAC[] THEN MP_TAC (ISPECL[`(v:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;`(sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3))`]properties_of_set_of_edge) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN REMOVE_THEN "b" (fun th->MP_TAC (ISPEC`{(v:real^3),(w:real^3)}`th) THEN ASSUME_TAC(th)) THEN POP_ASSUM (fun th->MP_TAC (ISPEC`{(v:real^3),(u:real^3)}`th) THEN ASSUME_TAC(th)) THEN POP_ASSUM (fun th->MP_TAC (ISPEC`{(v:real^3),(sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3))}`th) THEN ASSUME_TAC(th)) THEN REWRITE_TAC[SET_RULE`{a} UNION {b,c}={a,b,c}`] THEN ASM_REWRITE_TAC[] THEN REPEAT STRIP_TAC THEN POP_ASSUM MP_TAC THEN ASM_REWRITE_TAC[] THEN DISJ_CASES_TAC(REAL_ARITH `(azim (x:real^3) (v:real^3) (w:real^3) (sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3))= &0) \/ ~(azim (x:real^3) (v:real^3) (w:real^3) (sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3)) = &0)`) THENL(*7*)[ MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (w:real^3)`;`(sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3))`]UNIQUE_AZIM_0_POINT_FAN) THEN ASM_TAC THEN SET_TAC[];(*7*) DISJ_CASES_TAC(REAL_ARITH `(azim (x:real^3) (v:real^3) (w:real^3) (u:real^3)= &0) \/ ~(azim (x:real^3) (v:real^3) (w:real^3) (u:real^3) = &0)`) THENL(*8*)[ MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (w:real^3)`;`(u:real^3)`]UNIQUE_AZIM_0_POINT_FAN) THEN ASM_TAC THEN SET_TAC[];(*8*) MP_TAC(ISPECL[`(x:real^3)`;` (v:real^3)`;`w:real^3`;`(sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3))`]AZIM_COMPL) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;` (v:real^3)`;` (w:real^3)`;` (u:real^3)`]AZIM_COMPL) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN ASM_REWRITE_TAC[REAL_ARITH`&2 * pi - a<= &2 * pi - (b:real) <=> b<= (a:real)`] THEN REMOVE_THEN "c" (fun th -> MP_TAC(ISPEC `u:real^3` th) ) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN STRIP_TAC THEN SUBGOAL_THEN `azim (x:real^3) (v:real^3) (w:real^3) (sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3)) = azim x v w u` ASSUME_TAC THENL(*9*)[ POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN REAL_ARITH_TAC;(*9*) MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (w:real^3)`;`(sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3))`;`u:real^3`]UNIQUE_AZIM_POINT_FAN) THEN ASM_REWRITE_TAC[]]]]]]]]]]);;
let MONO_POWER_SIGMA_FAN=
prove(`!(i:num) (j:num) (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3). FAN(x,V,E) /\ ({v,u} IN E)/\(j<i)/\ (power_map_points sigma_fan x V E v u i)= (power_map_points sigma_fan x V E v u j) ==> u=power_map_points sigma_fan x V E v u (i-j)`,
INDUCT_TAC THENL [ARITH_TAC; INDUCT_TAC THENL [REWRITE_TAC[ARITH_RULE `SUC i- 0 =SUC (i:num)`;power_map_points] THEN ASM_TAC THEN SET_TAC[]; REWRITE_TAC[ARITH_RULE `SUC (i:num)-SUC (j:num)= i - j`; ARITH_RULE `SUC(j:num) < SUC (i) <=> j < i`;power_map_points] THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN DISCH_THEN(LABEL_TAC "a") THEN DISCH_TAC THEN REPEAT GEN_TAC THEN STRIP_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;`v:real^3`;` (u:real^3)`]properties_of_set_of_edge_fan) THEN ASM_REWRITE_TAC[] THEN STRIP_TAC THEN MP_TAC(ISPECL[`(i:num)`;` (x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`]image_power_map_points) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(j:num)`;` (x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`]image_power_map_points) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;`v:real^3`;`power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num)`]properties_of_set_of_edge_fan) THEN ASM_REWRITE_TAC[] THEN STRIP_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;`v:real^3`;`power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (j:num)`]properties_of_set_of_edge_fan) THEN ASM_REWRITE_TAC[] THEN STRIP_TAC THEN MP_TAC(ISPECL[` (x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;`power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num)`;`power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (j:num)`]MONO_SIGMA_FAN) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN REMOVE_THEN "a"(fun th-> MP_TAC(ISPECL[`(j:num) `;`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`]th)) THEN ASM_REWRITE_TAC[]]]);;
let MONO_POWER_MAP_POINTS1_FAN=
prove(`!(i:num) (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) . FAN(x,V,E) /\ (u IN set_of_edge v V E) /\ ~(set_of_edge v V E={u}) ==> ~(power_map_points (sigma_fan) x V E v u i=power_map_points (sigma_fan) x V E v u (SUC i)) `,
INDUCT_TAC THENL[ REWRITE_TAC[power_map_points] THEN REPEAT GEN_TAC THEN STRIP_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`]SIGMA_FAN) THEN ASM_MESON_TAC[]; REPEAT GEN_TAC THEN POP_ASSUM (fun th-> MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`]th))THEN REWRITE_TAC[power_map_points] THEN STRIP_TAC THEN STRIP_TAC THEN REPEAT(POP_ASSUM MP_TAC) THEN DISCH_THEN (LABEL_TAC "a") THEN DISCH_THEN (LABEL_TAC "b") THEN USE_THEN "b" MP_TAC THEN REWRITE_TAC[FAN] THEN STRIP_TAC THEN DISCH_TAC THEN DISCH_TAC THEN REMOVE_THEN "a" MP_TAC THEN MP_TAC(ARITH_RULE `SUC (i:num)< CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))==> i < CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN ASM_REWRITE_TAC[] THEN MATCH_MP_TAC MONO_NOT THEN DISCH_TAC THEN MP_TAC(ISPECL[`(i:num)`;` (x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`]image_power_map_points) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`SUC (i:num)`;` (x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`]image_power_map_points) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[` (v:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num))`] properties_of_set_of_edge) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[` (v:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (SUC (i:num)))`] properties_of_set_of_edge) THEN ASM_REWRITE_TAC[power_map_points] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;`v:real^3`;`power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num)`;`sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num))`]MONO_SIGMA_FAN) THEN ASM_MESON_TAC[]]);;
let MONO_AZIM_POWER_SIGMA_FAN=
prove(`! (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num). FAN(x,V,E) /\ ({v,u} IN E) /\ ~(power_map_points (sigma_fan) x V E v u (SUC i) = u) ==> azim x v u (power_map_points (sigma_fan) x V E v u i)<= azim x v u (power_map_points (sigma_fan) x V E v u (SUC i)) `,
REPEAT GEN_TAC THEN STRIP_TAC THEN REPEAT(POP_ASSUM MP_TAC) THEN DISCH_THEN (LABEL_TAC"1") THEN USE_THEN "1" MP_TAC THEN REWRITE_TAC[FAN;fan6; power_map_points] THEN REPEAT STRIP_TAC THEN REPEAT(POP_ASSUM MP_TAC) THEN DISCH_THEN (LABEL_TAC"1") THEN REPEAT STRIP_TAC THEN MP_TAC (ISPECL[`(v:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (u:real^3)`]properties_of_set_of_edge) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(i:num)`;` (x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`]image_power_map_points) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC (ISPECL[`(v:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;`power_map_points (sigma_fan)(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num)`]properties_of_set_of_edge) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`;`power_map_points (sigma_fan)(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num)`]MONO_AZIM_SIGMA_FAN) THEN ASM_REWRITE_TAC[]);;
(* Proof of Lemma [VBTIKLP] *) (*let lemma62=prove(`!x:real^3 (V:real^3->bool) (E:(real^3->bool)->bool) v:real^3 w:real^3 w1:real^3. a IN a_node_fan x V E (x,v,w,w1)==>(?n. a=(x,v,(power_map_points sigma_fan x V E v w n),(power_map_points sigma_fan x V E v w (SUC n))))`, REWRITE_TAC[a_node_fan; IN_ELIM_THM; ] THEN REWRITE_TAC[node_fan] THEN REWRITE_TAC[power_n_fan]);;*) (* local definitions *)
let complement_set= new_definition`complement_set {x:real^3, v:real^3} = {y:real^3| ~(y IN aff {x,v})} `;;
let subset_aff=
prove(`!x:real^3 v:real^3. (aff{x, v} SUBSET (UNIV:real^3->bool))`,
REPEAT GEN_TAC THEN SET_TAC[]);;
let union_aff=
prove(`!x v:real^3. (UNIV:real^3->bool) = aff{x, v} UNION complement_set {x, v} `,
REPEAT GEN_TAC THEN REWRITE_TAC[complement_set] THEN SET_TAC[]);;
(*---------------------------------------------------------------*) (* the properties of if_azims_fan *) (*---------------------------------------------------------------*) (* azim pf powers of node map *)
let if_azims_fan= new_definition`
if_azims_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num)
    = if i = CARD(set_of_edge v V E) 
        then &2 * pi 
         else azim x v u (power_map_points sigma_fan x V E v u i)`;;
let if_azims_works_fan=
prove( `!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num). ( &0 <= if_azims_fan x V E v u i) /\ if_azims_fan x V E v u i <= &2 * pi`,
REPEAT GEN_TAC THEN REWRITE_TAC[REAL_ARITH `(a:real) <= (b:real) <=> (b >= a)`; if_azims_fan; azim;COND_ELIM_THM] THEN MP_TAC(ISPECL [`x:real^3`; `v:real^3`; `u:real^3`; `power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num)`]azim) THEN STRIP_TAC THEN ASSUME_TAC(PI_WORKS) THEN ASM_REWRITE_TAC[] THEN REPEAT (POP_ASSUM MP_TAC) THEN REAL_ARITH_TAC);;
let set_of_orbits_points_fan = new_definition `set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) = {power_map_points sigma_fan x V E v u i| 0<=i }`;;
let number_of_orbits_fan = new_definition `number_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) = CARD(set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3))`;;
let addition_sigma_fan = 
prove(`!(m:num) (n:num) (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3). power_map_points sigma_fan x V E v u (m + n) = (power_map_points sigma_fan x V E v (power_map_points sigma_fan x V E v u n) m) `,
INDUCT_TAC THENL [ REWRITE_TAC[power_map_points; ARITH_RULE`0 + n:num =n`]; REWRITE_TAC[ARITH_RULE` SUC (m:num) + n= SUC(m+n)`; power_map_points] THEN REPEAT GEN_TAC THEN POP_ASSUM(ASSUME_TAC o GSYM o (ISPECL[`(n:num) `;`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`])) THEN ASM_TAC THEN SET_TAC[]]);;
let fix_point_sigma_fan=
prove(`! (q:num) (i:num) (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3). (power_map_points (sigma_fan) x V E v u i=u) ==>power_map_points sigma_fan x V E v u (q * i)=u `,
INDUCT_TAC THENL[ ASM_REWRITE_TAC[ARITH_RULE`0 * i:num = 0`;power_map_points]; REWRITE_TAC[ARITH_RULE`SUC q * i:num= q * i + i`] THEN REPEAT GEN_TAC THEN POP_ASSUM(MP_TAC o (ISPECL[`(i:num) `;`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`])) THEN DISCH_THEN(LABEL_TAC "a") THEN DISCH_TAC THEN REMOVE_THEN "a" MP_TAC THEN ASM_REWRITE_TAC[addition_sigma_fan]]);;
let i_IN_ORBITS_FAN=
prove(`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num). power_map_points (sigma_fan) x V E v u i IN set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3)`,
REWRITE_TAC[set_of_orbits_points_fan; IN_ELIM_THM] THEN REPEAT GEN_TAC THEN EXISTS_TAC`i:num` THEN REWRITE_TAC[power_map_points] THEN SIMP_TAC[] THEN ARITH_TAC);;
let u_IN_ORBITS_FAN=
prove(`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) . u IN set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3)`,
REWRITE_TAC[set_of_orbits_points_fan; IN_ELIM_THM] THEN REPEAT GEN_TAC THEN EXISTS_TAC`0` THEN REWRITE_TAC[power_map_points] THEN SIMP_TAC[] THEN ARITH_TAC);;
let IN_ORBITS_FAN=
prove(`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (w:real^3). w IN set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) ==> sigma_fan x V E v w IN set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3)`,
REPEAT GEN_TAC THEN REWRITE_TAC[set_of_orbits_points_fan; IN_ELIM_THM] THEN STRIP_TAC THEN EXISTS_TAC`SUC i` THEN ASM_REWRITE_TAC[power_map_points] THEN ARITH_TAC);;
let ORBITS_SUBSET_EDGE_FAN=
prove(`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) . FAN(x,V,E) /\ ({v,u} IN E) ==> set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) SUBSET set_of_edge v V E`,
REPEAT GEN_TAC THEN STRIP_TAC THEN MP_TAC (ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;`v:real^3`;` (u:real^3)`]properties_of_set_of_edge_fan) THEN ASM_REWRITE_TAC[set_of_orbits_points_fan;SUBSET; IN_ELIM_THM] THEN DISCH_TAC THEN GEN_TAC THEN STRIP_TAC THEN MP_TAC(ISPECL[`(i:num)`;` (x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`]image_power_map_points) THEN ASM_REWRITE_TAC[]);;
let CARD_ORBITS_EDGE_FAN_LE=
prove(`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) . FAN(x,V,E) /\ ({v,u} IN E) ==> CARD(set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) ) <=CARD( set_of_edge v V E)`,
REPEAT GEN_TAC THEN STRIP_TAC THEN MP_TAC (ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;`v:real^3`;` (u:real^3)`]ORBITS_SUBSET_EDGE_FAN) THEN ASM_REWRITE_TAC[] THEN REPEAT (POP_ASSUM MP_TAC) THEN REWRITE_TAC[FAN;fan1] THEN REPEAT STRIP_TAC THEN MP_TAC(ISPECL[`(v:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`] remark_finite_fan1) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3)`;`set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)`]CARD_SUBSET) THEN ASM_REWRITE_TAC[]);;
let FINITE_ORBITS_SIGMA_FAN=
prove( `!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) . FAN(x,V,E) /\ ({v,u} IN E) ==> FINITE(set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3)) `,
REPEAT GEN_TAC THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;`v:real^3`;` (u:real^3)`] ORBITS_SUBSET_EDGE_FAN)THEN ASM_REWRITE_TAC[] THEN POP_ASSUM MP_TAC THEN REWRITE_TAC[FAN;fan1] THEN STRIP_TAC THEN MP_TAC(ISPECL[`(v:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`] remark_finite_fan1) THEN ASM_REWRITE_TAC[] THEN MESON_TAC[FINITE_SUBSET]);;
let ORBITS_SIGMA_FAN=
prove(`!(i:num) (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) . FAN(x,V,E) /\ ({v,u} IN E)/\ (power_map_points (sigma_fan) x V E v u i=u) /\ ~(i=0) ==> set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) = {power_map_points sigma_fan x V E v u j| j < i } `,
REPEAT STRIP_TAC THEN REWRITE_TAC[set_of_orbits_points_fan; EXTENSION; IN_ELIM_THM] THEN GEN_TAC THEN EQ_TAC THENL [ STRIP_TAC THEN ASM_REWRITE_TAC[] THEN FIND_ASSUM (MP_TAC o (SPEC `i':num`) o MATCH_MP DIVMOD_EXIST) `~(i:num = 0)` THEN REPEAT STRIP_TAC THEN EXISTS_TAC`r:num` THEN ASM_REWRITE_TAC[ARITH_RULE`q * (i:num) + r = r+ q * i`;addition_sigma_fan] THEN MP_TAC (SPECL [`(q:num)`;` (i:num)`;` (x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3) `;`(u:real^3)`]fix_point_sigma_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN ASM_REWRITE_TAC[]; STRIP_TAC THEN EXISTS_TAC `j:num` THEN ASM_REWRITE_TAC[] THEN ARITH_TAC]);;
(***********lemmas in hypermap.ml***************)
let IMAGE_SEG = 
prove(`!(n:num) (f:num->A). IMAGE f {i:num | i < n:num} = {f (i:num) | i < n}`,
REPEAT STRIP_TAC THEN REWRITE_TAC[IMAGE; IN_ELIM_THM] THEN ASM_SET_TAC[]);;
let FINITE_SERIES = 
prove(`!(n:num) (f:num->A). FINITE {f(i) | i < n}`,
REPEAT GEN_TAC THEN ONCE_REWRITE_TAC[SYM(SPECL[`n:num`; `f:num->A`] IMAGE_SEG)] THEN MATCH_MP_TAC FINITE_IMAGE THEN REWRITE_TAC[FINITE_NUMSEG_LT]);;
let CARD_FINITE_SERIES_LE  = 
prove(`!(n:num) (f:num->A). CARD {f(i) | i < n} <= n`,
REPEAT GEN_TAC THEN ONCE_REWRITE_TAC[SYM(SPECL[`n:num`; `f:num->A`] IMAGE_SEG)] THEN MP_TAC(ISPEC `f:num ->A` (MATCH_MP CARD_IMAGE_LE (SPEC `n:num` FINITE_NUMSEG_LT))) THEN REWRITE_TAC[CARD_NUMSEG_LT]);;
let LEMMA_INJ = 
prove(`!(n:num) (f:num->A).(!i:num j:num. i < n /\ j < i ==> ~(f i = f j)) ==> (!i:num j:num. i < n /\ j < n /\ f i = f j ==> i = j)`,
REPEAT GEN_TAC THEN DISCH_TAC THEN MATCH_MP_TAC WLOG_LT THEN STRIP_TAC THENL[ARITH_TAC; ALL_TAC] THEN STRIP_TAC THENL[MESON_TAC[]; ALL_TAC] THEN ASM_MESON_TAC[]);;
let CARD_FINITE_SERIES_EQ  = 
prove(`!(n:num) (f:num->A). (!i:num j:num. i < n /\ j < i ==> ~(f i = f j)) ==> CARD {f(i) | i < n} = n`,
REPEAT GEN_TAC THEN DISCH_THEN (LABEL_TAC "F1" o MATCH_MP LEMMA_INJ) THEN ONCE_REWRITE_TAC[GSYM IMAGE_SEG] THEN GEN_REWRITE_TAC(RAND_CONV o ONCE_DEPTH_CONV) [GSYM (SPEC `n:num` CARD_NUMSEG_LT)] THEN MATCH_MP_TAC CARD_IMAGE_INJ THEN REWRITE_TAC[FINITE_NUMSEG_LT] THEN REWRITE_TAC[IN_ELIM_THM] THEN ASM_REWRITE_TAC[]);;
(**************************************)
let CARD_ORBITS_SIGMA_FAN_LE=
prove(`!(i:num) (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) . FAN(x,V,E) /\ ({v,u} IN E)/\ (power_map_points (sigma_fan) x V E v u i=u) /\ ~(i=0) ==> CARD(set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3))<=i`,
REPEAT GEN_TAC THEN STRIP_TAC THEN MP_TAC(ISPECL[`(i:num)`;` (x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`]ORBITS_SIGMA_FAN) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN ASM_REWRITE_TAC[] THEN MP_TAC(ISPECL[`i:num`;`power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3)`]CARD_FINITE_SERIES_LE) THEN ASM_TAC THEN SET_TAC[]);;
let exists_inverse_in_orbits_sigma_fan=
prove(` !(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (y:real^3). FAN(x,V,E) /\({v,u} IN E)/\ ~(y IN set_of_orbits_points_fan x V E v u) ==> (?(w:real^3). (w IN (set_of_orbits_points_fan x V E v u)) /\ ~(w=y) /\ (!(w1:real^3). (w1 IN (set_of_orbits_points_fan x V E v u))/\ ~(w1=y) ==> azim1 x v y w <= azim1 x v y w1)) `,
(
let lemma = prove
   (`!X:real->bool. 
          FINITE X /\ ~(X = {}) 
          ==> ?a. a IN X /\ !x. x IN X ==> a <= x`,
    MESON_TAC[INF_FINITE]) in

MP_TAC(lemma) THEN DISCH_THEN(LABEL_TAC "a") THEN REPEAT GEN_TAC
THEN STRIP_TAC THEN POP_ASSUM MP_TAC THEN DISCH_THEN(LABEL_TAC "ba") 
THEN MP_TAC (ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;`(v:real^3)`;` (u:real^3)`]properties_of_set_of_edge_fan)
THEN  ASM_REWRITE_TAC[] THEN DISCH_TAC
THEN MP_TAC (ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;`v:real^3`;` (u:real^3)`]FINITE_ORBITS_SIGMA_FAN) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC 
THEN
SUBGOAL_THEN `FINITE ((set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)) (v:real^3) (u:real^3) DELETE  (y:real^3))` ASSUME_TAC
THENL[(*1*)

ASM_MESON_TAC[FINITE_DELETE_IMP];(*1*)
DISJ_CASES_TAC(SET_RULE`(set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) DELETE  (y:real^3)={})\/
 ~(set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) DELETE  (y:real^3)={})`)
THENL(*2*)[
MP_TAC (ISPECL[`y:real^3`;`set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3)`]DELETE_NON_ELEMENT) 
  THEN ASM_REWRITE_TAC[] THEN DISCH_TAC 
  THEN MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;`v:real^3`;` (u:real^3)`]u_IN_ORBITS_FAN)
  THEN ASM_TAC THEN SET_TAC[];(*2*)
SUBGOAL_THEN`~(IMAGE ( azim1 x v y) (set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) DELETE  (y:real^3))={})` ASSUME_TAC
THENL(*3*)[
REWRITE_TAC[IMAGE_EQ_EMPTY] THEN ASM_MESON_TAC[];(*3*)

SUBGOAL_THEN` FINITE (IMAGE (azim1 x v y) (set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) DELETE  (y:real^3)))` ASSUME_TAC
THENL(*4*)[
ASM_MESON_TAC[FINITE_IMAGE];(*4*)

REMOVE_THEN "a" (fun th ->MP_TAC(ISPEC `(IMAGE (azim1 x v y) (set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) DELETE  (y:real^3)))` th))
 THEN ASM_REWRITE_TAC[IMAGE;DELETE;IN_ELIM_THM]THEN STRIP_TAC
THEN EXISTS_TAC`x':real^3`
  THEN ASM_REWRITE_TAC[] THEN ASM_MESON_TAC[]]]]]));;
let key_lemma_cyclic_fan=
prove(`!(i:num) (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3). FAN(x,V,E) /\ (0 < i) /\(i< CARD(set_of_edge v V E)) /\ ({v,u} IN E) ==> ~(power_map_points (sigma_fan) x V E v u i=u) `,
INDUCT_TAC THENL(*1*)[ARITH_TAC;(*1*) REPEAT GEN_TAC THEN STRIP_TAC THEN REWRITE_TAC[power_map_points] THEN MP_TAC(ISPECL[` (x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`]ORBITS_SUBSET_EDGE_FAN) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN DISJ_CASES_TAC(SET_RULE`(sigma_fan x V E v (power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num))= u)\/ ~(sigma_fan x V E v (power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num))= u)`) THENL(*2*)[ ASM_REWRITE_TAC[] THEN MP_TAC(ISPECL[`SUC (i:num)`;` (x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`]CARD_ORBITS_SIGMA_FAN_LE) THEN ASM_REWRITE_TAC[power_map_points; ARITH_RULE`~(SUC i = 0)`] THEN STRIP_TAC THEN SUBGOAL_THEN `CARD(set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3)) <CARD(set_of_edge v V E)` ASSUME_TAC THENL(*3*)[ REPEAT (POP_ASSUM MP_TAC) THEN ARITH_TAC;(*3*) SUBGOAL_THEN `set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) PSUBSET set_of_edge v V E` ASSUME_TAC THENL(*4*)[ ASM_REWRITE_TAC[PSUBSET] THEN DISJ_CASES_TAC(SET_RULE`(set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) = set_of_edge v V E)\/ ~(set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) = set_of_edge v V E)`) THENL(*5*)[ SUBGOAL_THEN`CARD(set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3)) =CARD( set_of_edge v V E)`ASSUME_TAC THENL(*6*)[ POP_ASSUM(fun th->REWRITE_TAC[th]);(*6*) POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN ARITH_TAC](*6*);(*5*) POP_ASSUM(fun th->REWRITE_TAC[th])](*5*);(*4*) POP_ASSUM MP_TAC THEN ASM_REWRITE_TAC[PSUBSET_MEMBER] THEN STRIP_TAC THEN MP_TAC(ISPECL[` (x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`;`y:real^3`] exists_inverse_in_orbits_sigma_fan) THEN ASM_REWRITE_TAC[] THEN DISJ_CASES_TAC(SET_RULE`(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)={(u:real^3)})\/ ~(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)={(u:real^3)})`) THENL(*5*)[ POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN DISCH_THEN(LABEL_TAC"a") THEN DISCH_THEN(LABEL_TAC "b") THEN DISCH_TAC THEN REMOVE_THEN "a" MP_TAC THEN ASM_REWRITE_TAC[IN_SING] THEN DISCH_TAC THEN REMOVE_THEN "b" MP_TAC THEN ASM_REWRITE_TAC[u_IN_ORBITS_FAN];(*5*) ASM_REWRITE_TAC[] THEN STRIP_TAC THEN POP_ASSUM MP_TAC THEN ASM_REWRITE_TAC[] THEN DISJ_CASES_TAC(SET_RULE`(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)={(w:real^3)})\/ ~(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)={(w:real^3)})`) THENL(*6*)[ POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN DISCH_THEN(LABEL_TAC"a") THEN DISCH_THEN(LABEL_TAC "b") THEN DISCH_TAC THEN DISCH_TAC THEN DISCH_TAC THEN DISCH_TAC THEN REMOVE_THEN "a" MP_TAC THEN ASM_REWRITE_TAC[IN_SING] THEN DISCH_TAC THEN REMOVE_THEN "b" MP_TAC THEN ASM_REWRITE_TAC[];(*6*) MP_TAC(ISPECL[` (x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;`u:real^3`;` (w:real^3)`]IN_ORBITS_FAN) THEN ASM_REWRITE_TAC[] THEN STRIP_TAC THEN STRIP_TAC THEN POP_ASSUM(fun th->MP_TAC(ISPEC `sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3)` th)) THEN ASM_REWRITE_TAC[] THEN DISJ_CASES_TAC(SET_RULE`sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3)=(y:real^3) \/ ~(sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3)=(y:real^3))`) THENL(*7*)[ POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN DISCH_THEN(LABEL_TAC"a") THEN DISCH_TAC THEN REMOVE_THEN "a" MP_TAC THEN ASM_REWRITE_TAC[];(*7*) ASM_REWRITE_TAC[azim1;REAL_ARITH` (a:real) - b <= a - c <=> c<=b`] THEN STRIP_TAC THEN SUBGOAL_THEN `sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3) IN set_of_edge v V E` ASSUME_TAC THENL(*8*)[ ASM_TAC THEN SET_TAC[];(*8*) SUBGOAL_THEN `(w:real^3) IN set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)` ASSUME_TAC THENL(*9*)[ ASM_TAC THEN SET_TAC[];(*9*) SUBGOAL_THEN `{(y:real^3),sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3),(w:real^3)} SUBSET set_of_edge v V E` ASSUME_TAC THENL(*10*)[ ASM_TAC THEN SET_TAC[];(*10*) FIND_ASSUM(MP_TAC)`FAN((x:real^3),V,E)` THEN REWRITE_TAC[FAN;fan6] THEN STRIP_TAC THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN DISCH_THEN (LABEL_TAC "b") THEN STRIP_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (u:real^3)`;` (v:real^3)`]properties_of_graph) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`]CYCLIC_SET_EDGE_FAN) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;` (v:real^3)`;`{(y:real^3),sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3),(w:real^3)}`;`set_of_edge(v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)` ]subset_cyclic_set_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`y:real^3`;`sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3)`;`w:real^3`]sum2_azim_fan) THEN ASM_REWRITE_TAC[] THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`y:real^3`;`sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3)`]azim) THEN STRIP_TAC THEN STRIP_TAC THEN SUBGOAL_THEN `azim (x:real^3) (v:real^3) (sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3)) (w:real^3) <= azim (x:real^3) (v:real^3) (y:real^3) (w:real^3)` ASSUME_TAC THENL(*11*)[ REPEAT(POP_ASSUM MP_TAC) THEN REAL_ARITH_TAC;(*11*) POP_ASSUM MP_TAC THEN POP_ASSUM(fun th ->REWRITE_TAC[]) THEN ASM_REWRITE_TAC[] THEN MP_TAC (ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;`(v:real^3)`;` (y:real^3)`]properties_of_set_of_edge_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC (ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;`(v:real^3)`;` (w:real^3)`]properties_of_set_of_edge_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC (ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;`(v:real^3)`;` (sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3))`]properties_of_set_of_edge_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN DISJ_CASES_TAC(REAL_ARITH `(azim (x:real^3) (v:real^3) (w:real^3) (y:real^3)= &0) \/ ~(azim (x:real^3) (v:real^3) (w:real^3) (y:real^3) = &0)`) THENL(*12*)[ MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (w:real^3)`;`(y:real^3)`]UNIQUE_AZIM_0_POINT_FAN) THEN ASM_REWRITE_TAC[];(*12*) DISJ_CASES_TAC(REAL_ARITH `(azim (x:real^3) (v:real^3) (w:real^3) (sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3))= &0) \/ ~(azim (x:real^3) (v:real^3) (w:real^3) (sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3)) = &0)`) THENL(*13*)[ MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (w:real^3)`; ` (sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3))` ]UNIQUE_AZIM_0_POINT_FAN) THEN ASM_REWRITE_TAC[] THEN MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (w:real^3)`] SIGMA_FAN) THEN ASM_REWRITE_TAC[] THEN ASM_TAC THEN SET_TAC[];(*13*) REMOVE_THEN "b" (fun th->MP_TAC (ISPEC`{(v:real^3),(w:real^3)}`th) THEN ASSUME_TAC(th)) THEN POP_ASSUM (fun th->MP_TAC (ISPEC`{(v:real^3),(y:real^3)}`th) THEN ASSUME_TAC(th)) THEN POP_ASSUM (fun th->MP_TAC (ISPEC`{(v:real^3),(sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3))}`th) THEN ASSUME_TAC(th)) THEN REWRITE_TAC[SET_RULE`{(a:real^3)} UNION {b,c}={a,b,c}`] THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN DISCH_TAC THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;` (v:real^3)`;`(w:real^3)`;`(sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3))`]AZIM_COMPL) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;` (v:real^3)`;` (w:real^3)`;` (y:real^3)`]AZIM_COMPL) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN ASM_REWRITE_TAC[] THEN REWRITE_TAC[REAL_ARITH`(a - (b:real) <= (a:real)- (c:real))<=> c <= b`] THEN STRIP_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`;`(E:(real^3->bool)->bool)`;`v:real^3`; `(w:real^3)`] SIGMA_FAN) THEN ASM_REWRITE_TAC[] THEN STRIP_TAC THEN POP_ASSUM(fun th-> MP_TAC(ISPEC`(y:real^3)`th)) THEN ASM_REWRITE_TAC[] THEN STRIP_TAC THEN SUBGOAL_THEN`azim (x:real^3) (v:real^3) (w:real^3) (y:real^3) = azim x v w (sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3))` ASSUME_TAC THENL(*14*)[ POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN REAL_ARITH_TAC;(*14*) MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;`(w:real^3)`;` (y:real^3)`; ` (sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3))` ]UNIQUE_AZIM_POINT_FAN) THEN ASM_REWRITE_TAC[] ]]]]]]]]]]]]; ASM_REWRITE_TAC[]]]);;
let cyclic_power_sigma_fan=
prove(`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num) (j:num). FAN(x,V,E) /\ (i< CARD(set_of_edge v V E)) /\ (j<i) /\ ({v,u} IN E) ==> ~(power_map_points (sigma_fan) x V E v u i= power_map_points (sigma_fan) x V E v u j) `,
REPEAT GEN_TAC THEN STRIP_TAC THEN STRIP_TAC THEN MP_TAC(ISPECL[`(i:num)`;` (j:num)`;` (x:real^3)`;` (V:real^3->bool)`; ` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`]MONO_POWER_SIGMA_FAN) THEN ASM_REWRITE_TAC[] THEN MP_TAC(ARITH_RULE` j < i ==> 0 < (i:num)-(j:num)`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ARITH_RULE` (j:num) <(i:num)==> i-j <= i`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ARITH_RULE` (i :num )-(j:num) <= i /\ i< CARD(set_of_edge (v:real^3)(V:real^3->bool) (E:(real^3->bool)->bool))==> i-j <CARD(set_of_edge (v:real^3)(V:real^3->bool) (E:(real^3->bool)->bool))`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(i:num)-(j:num)`;` (x:real^3)`;` (V:real^3->bool)`; ` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`]key_lemma_cyclic_fan) THEN ASM_REWRITE_TAC[] THEN MESON_TAC[]);;
let CARD_SET_OF_ORBITS_POINTS_FAN=
prove(`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3). FAN(x,V,E) /\ ({v,u} IN E) ==> CARD(set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3))= CARD(set_of_edge v V E)`,
REPEAT GEN_TAC THEN STRIP_TAC THEN SUBGOAL_THEN`{power_map_points (sigma_fan) (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num) |i| (i< CARD(set_of_edge v V E))} SUBSET set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) `ASSUME_TAC THENL[ REWRITE_TAC[set_of_orbits_points_fan;SUBSET;IN_ELIM_THM] THEN GEN_TAC THEN STRIP_TAC THEN EXISTS_TAC`i:num` THEN ASM_REWRITE_TAC[] THEN ARITH_TAC; SUBGOAL_THEN`CARD {power_map_points (sigma_fan) (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num) |i| (i< CARD(set_of_edge v V E))} <= CARD (set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3))` ASSUME_TAC THENL[ MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`; ` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`] FINITE_ORBITS_SIGMA_FAN) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`{power_map_points (sigma_fan) (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num) |i| (i< CARD(set_of_edge v V E))}`;`set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3)`]CARD_SUBSET) THEN ASM_REWRITE_TAC[]; MP_TAC(SPECL[`(x:real^3)`;` (V:real^3->bool)`; ` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`]cyclic_power_sigma_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))`;`power_map_points (sigma_fan) (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3)`]CARD_FINITE_SERIES_EQ) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`; ` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`]CARD_ORBITS_EDGE_FAN_LE) THEN ASM_REWRITE_TAC[] THEN REPEAT (POP_ASSUM MP_TAC) THEN ARITH_TAC]]);;
let ORBITS_EQ_SET_EDGE_FAN=
prove(`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3). FAN(x,V,E) /\ ({v,u} IN E) ==> set_of_edge v V E = set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3)`,
REWRITE_TAC[SET_RULE`(set_of_edge v V E = set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3))<=> (set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3)= set_of_edge v V E) `] THEN REPEAT STRIP_TAC THEN MATCH_MP_TAC CARD_SUBSET_EQ THEN STRIP_TAC THENL[REPEAT (POP_ASSUM MP_TAC) THEN REWRITE_TAC[FAN;fan1] THEN MESON_TAC[remark_finite_fan1]; ASM_MESON_TAC[ORBITS_SUBSET_EDGE_FAN;CARD_SET_OF_ORBITS_POINTS_FAN]]);;
let SIMP_ORBITS_POINTS_FAN=
prove(`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3). FAN(x,V,E) /\ ({v,u} IN E) ==> {power_map_points (sigma_fan) (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num) |i| (i< CARD(set_of_edge v V E))} = set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) `,
REPEAT GEN_TAC THEN STRIP_TAC THEN SUBGOAL_THEN`{power_map_points (sigma_fan) (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num) |i| (i< CARD(set_of_edge v V E))} SUBSET set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) `ASSUME_TAC THENL[ REWRITE_TAC[set_of_orbits_points_fan;SUBSET;IN_ELIM_THM] THEN GEN_TAC THEN STRIP_TAC THEN EXISTS_TAC`i:num` THEN ASM_REWRITE_TAC[] THEN ARITH_TAC; POP_ASSUM MP_TAC THEN MP_TAC(SPECL[`(x:real^3)`;` (V:real^3->bool)`; ` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`]cyclic_power_sigma_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))`;`power_map_points (sigma_fan) (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3)`]CARD_FINITE_SERIES_EQ) THEN ASM_REWRITE_TAC[] THEN DISCH_THEN(LABEL_TAC"a") THEN MP_TAC(SPECL[`(x:real^3)`;` (V:real^3->bool)`; ` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`]CARD_SET_OF_ORBITS_POINTS_FAN) THEN ASM_REWRITE_TAC[SET_RULE`a=b<=> b=a`] THEN DISCH_TAC THEN REMOVE_THEN "a" MP_TAC THEN ASM_REWRITE_TAC[] THEN MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`; ` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`] FINITE_ORBITS_SIGMA_FAN) THEN ASM_REWRITE_TAC[] THEN MESON_TAC[CARD_SUBSET_EQ]]);;
let ORDER_POWER_SIGMA_FAN=
prove(`!(i:num) (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) . FAN(x,V,E) /\ (i=CARD(set_of_edge v V E)) /\ ({v,u} IN E) ==> power_map_points (sigma_fan) x V E v u i= u `,
REPEAT GEN_TAC THEN STRIP_TAC THEN SUBGOAL_THEN `power_map_points (sigma_fan) (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num) IN set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3)` ASSUME_TAC THENL[ REWRITE_TAC[ set_of_orbits_points_fan; IN_ELIM_THM] THEN EXISTS_TAC`i:num` THEN ASM_REWRITE_TAC[] THEN ARITH_TAC; POP_ASSUM MP_TAC THEN MP_TAC(SPECL[`(x:real^3)`;` (V:real^3->bool)`; ` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`]SIMP_ORBITS_POINTS_FAN) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN POP_ASSUM(fun th->REWRITE_TAC[SYM(th);]) THEN REWRITE_TAC[IN_ELIM_THM] THEN STRIP_TAC THEN ASM_REWRITE_TAC[] THEN MP_TAC(ISPECL[`CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))`;`i':num`;`(x:real^3)`;` (V:real^3->bool)`; ` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`]MONO_POWER_SIGMA_FAN) THEN ASM_REWRITE_TAC[] THEN DISJ_CASES_TAC(ARITH_RULE`(0<(i':num))\/ i'=0`) THENL[ DISCH_TAC THEN MP_TAC(ARITH_RULE`0 < (i':num)/\ i'< CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)) ==> (CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))- (i':num) < CARD (set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)))`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ARITH_RULE`(i':num)< CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))==> 0< CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))-i'`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))-(i':num)`; `(x:real^3)`;` (V:real^3->bool)`; ` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`]key_lemma_cyclic_fan) THEN ASM_REWRITE_TAC[] THEN ASM_SET_TAC[]; ASM_REWRITE_TAC[power_map_points]]]);;
let SUM_IF_AZIMS_FAN=
prove(`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num). FAN(x,V,E) /\ ({v,u} IN E) /\(0<i) /\ (i< CARD(set_of_edge v V E)) ==> if_azims_fan x V E v u (SUC i)= if_azims_fan x V E v u i + azim x v ((power_map_points sigma_fan x V E v u i)) (power_map_points sigma_fan x V E v u (SUC i))`,
REPEAT GEN_TAC THEN STRIP_TAC THEN REPEAT (POP_ASSUM MP_TAC) THEN DISCH_THEN (LABEL_TAC"a") THEN USE_THEN "a" MP_TAC THEN REWRITE_TAC[FAN;fan6] THEN STRIP_TAC THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN DISCH_THEN (LABEL_TAC "b") THEN REPEAT STRIP_TAC THEN MP_TAC (ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;`(v:real^3)`;` (u:real^3)`]properties_of_set_of_edge_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(i:num)`; `(x:real^3)`;` (V:real^3->bool)`; ` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`] image_power_map_points) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`SUC(i:num)`; `(x:real^3)`;` (V:real^3->bool)`; ` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`] image_power_map_points) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC (ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;`(v:real^3)`;` power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num)`]properties_of_set_of_edge_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC (ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;`(v:real^3)`;` power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (SUC(i:num))`]properties_of_set_of_edge_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN SUBGOAL_THEN `~((i:num)=CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)))` ASSUME_TAC THENL(*1*)[ REPEAT(POP_ASSUM MP_TAC) THEN ARITH_TAC;(*1*) DISJ_CASES_TAC(ARITH_RULE ` SUC (i:num)= CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)) \/ ~(SUC i=CARD(set_of_edge v V E))`) THENL(*2*)[ MP_TAC(ISPECL[`SUC (i:num)`; `(x:real^3)`;` (V:real^3->bool)`; ` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`]ORDER_POWER_SIGMA_FAN) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN REWRITE_TAC[if_azims_fan] THEN ASM_REWRITE_TAC[] THEN POP_ASSUM (fun th-> REWRITE_TAC[SYM(th)] THEN ASSUME_TAC(th)) THEN REMOVE_THEN "b" (fun th->MP_TAC (ISPEC`{(v:real^3),(u:real^3)}`th) THEN ASSUME_TAC(th)) THEN POP_ASSUM (fun th->MP_TAC (ISPEC`{(v:real^3),(power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num))}`th) THEN ASSUME_TAC(th)) THEN REWRITE_TAC[SET_RULE`{(a:real^3)} UNION {b,c}={a,b,c}`] THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN DISCH_TAC THEN DISJ_CASES_TAC(REAL_ARITH `(azim (x:real^3) (v:real^3) (u:real^3) (power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num))= &0) \/ ~(azim (x:real^3) (v:real^3) (u:real^3) (power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num)) = &0)`) THENL(*3*)[ MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`; ` (power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num))` ]UNIQUE_AZIM_0_POINT_FAN) THEN ASM_REWRITE_TAC[] THEN MP_TAC(ISPECL[`i:num`;`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`] key_lemma_cyclic_fan) THEN ASM_REWRITE_TAC[] THEN ASM_SET_TAC[];(*3*) MP_TAC(ISPECL[`(x:real^3)`;` (v:real^3)`;` (u:real^3)`;` (power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num))`]AZIM_COMPL) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN ASM_REWRITE_TAC[] THEN REAL_ARITH_TAC];(*2*) ASM_REWRITE_TAC[if_azims_fan] THEN MP_TAC(ARITH_RULE`i:num < CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)) /\ ~(SUC(i) = CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)))==> SUC(i)<CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN ASSUME_TAC(ARITH_RULE`0<SUC(i:num)`) THEN MP_TAC(ISPECL[`SUC(i:num)`;`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`] key_lemma_cyclic_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`;`i:num`]MONO_AZIM_POWER_SIGMA_FAN) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN SUBGOAL_THEN `{(u:real^3),power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num),power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (SUC(i:num))} SUBSET set_of_edge v V E` ASSUME_TAC THENL(*3*)[ ASM_SET_TAC[];(*3*) MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (u:real^3)`;` (v:real^3)`]properties_of_graph) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`]CYCLIC_SET_EDGE_FAN) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;` (v:real^3)`;`{(u:real^3),power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num),power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (SUC(i:num))}`;`set_of_edge(v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)` ]subset_cyclic_set_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`;`power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num)`;`power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (SUC(i:num))`]sum2_azim_fan) THEN ASM_REWRITE_TAC[]]]]);;
let azim_i_fan=new_definition`
azim_i_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num)
= azim x v (power_map_points sigma_fan x V E v u i) (power_map_points sigma_fan x V E v u (SUC i))`;;
let SUM_EQ_IF_AZIMS_FAN=
prove(`!(i:num) (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3). FAN(x,V,E) /\ ({v,u} IN E) /\ ~(set_of_edge v V E ={u}) /\ ~(1=CARD(set_of_edge v V E )) /\ (i< CARD(set_of_edge v V E)) ==> sum (0..i) (azim_i_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3)) = if_azims_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (SUC i)`,
INDUCT_TAC THENL[ REPEAT STRIP_TAC THEN ASM_REWRITE_TAC[SUM_CLAUSES_NUMSEG;azim_i_fan;power_map_points;if_azims_fan; ARITH_RULE`SUC 0=1`]; POP_ASSUM MP_TAC THEN DISCH_THEN (LABEL_TAC "a") THEN REPEAT STRIP_TAC THEN ASSUME_TAC(ARITH_RULE`0<= SUC (i:num)`)THEN ASSUME_TAC(ARITH_RULE`0< SUC (i:num)`) THEN MP_TAC(ARITH_RULE`SUC (i:num)<CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))==> i< CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN ASM_REWRITE_TAC[SUM_CLAUSES_NUMSEG] THEN REMOVE_THEN"a"(fun th-> MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool) `;`(E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`]th)) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN ASM_REWRITE_TAC[] THEN MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool) `;`(E:(real^3->bool)->bool) `;`(v:real^3) `;`(u:real^3)`;` (SUC(i:num))`]SUM_IF_AZIMS_FAN) THEN ASM_REWRITE_TAC[azim_i_fan] THEN REAL_ARITH_TAC]);;
let SUM_AZIMS_EQ_2PI_FAN=
prove(`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3). FAN(x,V,E) /\ ({v,u} IN E) /\ ~(set_of_edge v V E ={u}) /\ (1<CARD(set_of_edge v V E )) ==> sum (0..(CARD(set_of_edge v V E )-1)) (azim_i_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3)) = &2 *pi`,
REPEAT STRIP_TAC THEN MP_TAC(ARITH_RULE`(1<CARD(set_of_edge v V E )) ==> CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))-1 < CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ARITH_RULE`(1<CARD(set_of_edge v V E )) ==> ~(1=CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)))`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ARITH_RULE`(1<CARD(set_of_edge v V E )) ==> SUC(CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))-1)= CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))-1`;` (x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`]SUM_EQ_IF_AZIMS_FAN) THEN ASM_REWRITE_TAC[if_azims_fan]);;
let AZIM_LE_POWER_SIGMA_FAN=
prove(`!(i:num) (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (j:num). FAN(x,V,E) /\ ({v,u} IN E) /\ ~(set_of_edge v V E ={u}) /\ (j<i) /\ (i< CARD(set_of_edge v V E)) ==> azim x v u (power_map_points sigma_fan x V E v u j) < azim x v u (power_map_points sigma_fan x V E v u i)`,
INDUCT_TAC THENL(*1*)[ ARITH_TAC;(*1*) REPEAT GEN_TAC THEN STRIP_TAC THEN REPEAT (POP_ASSUM MP_TAC) THEN DISCH_THEN(LABEL_TAC"1") THEN DISCH_THEN (LABEL_TAC"a") THEN USE_THEN "a" MP_TAC THEN REWRITE_TAC[FAN;fan6] THEN STRIP_TAC THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN DISCH_THEN (LABEL_TAC "b") THEN REPEAT STRIP_TAC THEN MP_TAC (ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;`(v:real^3)`;` (u:real^3)`]properties_of_set_of_edge_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(i:num)`; `(x:real^3)`;` (V:real^3->bool)`; ` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`] image_power_map_points) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`SUC(i:num)`; `(x:real^3)`;` (V:real^3->bool)`; ` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`] image_power_map_points) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC (ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;`(v:real^3)`;` power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num)`]properties_of_set_of_edge_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC (ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;`(v:real^3)`;` power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (SUC(i:num))`]properties_of_set_of_edge_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN ASSUME_TAC(ARITH_RULE`i< SUC(i:num)`) THEN ASSUME_TAC(ARITH_RULE`0< SUC(i:num)`) THEN MP_TAC(ARITH_RULE`SUC(i)< CARD(set_of_edge(v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))==> i< CARD(set_of_edge(v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`SUC(i:num)`;`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`] key_lemma_cyclic_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`;`i:num`]MONO_AZIM_POWER_SIGMA_FAN) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN DISJ_CASES_TAC(ARITH_RULE `(j:num)< (i:num) \/ (i <= j)`) THENL[ REMOVE_THEN "1" (fun th-> MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`; `(j:num)`] th)) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN REPEAT (POP_ASSUM MP_TAC) THEN REAL_ARITH_TAC; MP_TAC(ARITH_RULE`(j:num) < SUC(i:num) ==> j <= i`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ARITH_RULE` (j:num) <= (i:num) /\ i<= j==> j=i`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN ASM_REWRITE_TAC[] THEN SUBGOAL_THEN`~(azim x v u (power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) ((i:num))) = azim x v u (power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (SUC(i:num))))` ASSUME_TAC THENL[ STRIP_TAC THEN MP_TAC (ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;`(v:real^3)`;`u:real^3`;` power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num)`;` power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (SUC(i:num))`]UNIQUE_AZIM_POINT_FAN) THEN ASM_REWRITE_TAC[] THEN MP_TAC(ISPECL[`(i:num)`;`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`]MONO_POWER_MAP_POINTS1_FAN) THEN ASM_REWRITE_TAC[]; REPEAT(POP_ASSUM MP_TAC) THEN REAL_ARITH_TAC]]]);;
let SUM_AZIM_POWER_SIGMA_FAN=
prove(`!(i:num) (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (j:num). FAN(x,V,E) /\ ({v,u} IN E) /\ ~(set_of_edge v V E ={u}) /\ (j<i) /\ (i< CARD(set_of_edge v V E)) ==> azim x v u (power_map_points sigma_fan x V E v u i)= azim x v u (power_map_points sigma_fan x V E v u j) + azim x v (power_map_points sigma_fan x V E v u j) (power_map_points sigma_fan x V E v u i)`,
REPEAT GEN_TAC THEN STRIP_TAC THEN REPEAT (POP_ASSUM MP_TAC) THEN DISCH_THEN (LABEL_TAC"a") THEN USE_THEN "a" MP_TAC THEN REWRITE_TAC[FAN;fan6] THEN STRIP_TAC THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN DISCH_THEN (LABEL_TAC "b") THEN REPEAT STRIP_TAC THEN MP_TAC (ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;`(v:real^3)`;` (u:real^3)`]properties_of_set_of_edge_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(i:num)`; `(x:real^3)`;` (V:real^3->bool)`; ` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`] image_power_map_points) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(j:num)`; `(x:real^3)`;` (V:real^3->bool)`; ` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`] image_power_map_points) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC (ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;`(v:real^3)`;` power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num)`]properties_of_set_of_edge_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC (ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;`(v:real^3)`;` power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) ((j:num))`]properties_of_set_of_edge_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN SUBGOAL_THEN `{(u:real^3),power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (j:num),power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) ((i:num))} SUBSET set_of_edge v V E` ASSUME_TAC THENL[ASM_SET_TAC[]; MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (u:real^3)`;` (v:real^3)`]properties_of_graph) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`]CYCLIC_SET_EDGE_FAN) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;` (v:real^3)`;`{(u:real^3),power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (j:num),power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) ((i:num))}`;`set_of_edge(v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)` ]subset_cyclic_set_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(i:num)`;` (x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`;` (j:num)`] AZIM_LE_POWER_SIGMA_FAN) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(REAL_ARITH`(azim x v u (power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) ((j:num))) < azim x v u (power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) ((i:num))))==>(azim x v u (power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) ((j:num))) <= azim x v u (power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) ((i:num))))`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`;`power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (j:num)`;`power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) ((i:num))`]sum2_azim_fan) THEN ASM_REWRITE_TAC[]]);;
let SUM1_IFAZIMS_FAN=
prove(`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num) (j:num). FAN(x,V,E) /\ ({v,u} IN E) /\ ~(set_of_edge v V E ={u}) /\ (j<i) /\ (i< CARD(set_of_edge v V E)) ==> if_azims_fan x V E v u i= if_azims_fan x V E v u j + azim x v ((power_map_points sigma_fan x V E v u j)) (power_map_points sigma_fan x V E v u i)`,
REPEAT GEN_TAC THEN STRIP_TAC THEN MP_TAC(ARITH_RULE`(i:num) < CARD(set_of_edge(v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))==> ~(i=CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)))`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ARITH_RULE`(j:num) < i /\(i:num) < CARD(set_of_edge(v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))==> ~(j=CARD(set_of_edge(v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)))`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN ASM_REWRITE_TAC[if_azims_fan] THEN ASM_MESON_TAC[SUM_AZIM_POWER_SIGMA_FAN]);;
let ULEKUUB=
prove(`(!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num) (j:num). FAN(x,V,E) /\ ({v,u} IN E) /\ ~(set_of_edge v V E ={u}) /\ (j<i) /\ (i< CARD(set_of_edge v V E)) ==> if_azims_fan x V E v u i= if_azims_fan x V E v u j + azim x v ((power_map_points sigma_fan x V E v u j)) (power_map_points sigma_fan x V E v u i)) /\ (!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3). FAN(x,V,E) /\ ({v,u} IN E) /\ ~(set_of_edge v V E ={u}) /\ (1<CARD(set_of_edge v V E )) ==> sum (0..(CARD(set_of_edge v V E )-1)) (azim_i_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3)) = &2 *pi) `,
(* g`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3). FAN(x,V,E)/\ {v,u} IN E ==> azim_cycle (set_of_edge v V E) x v u=sigma_fan x V E v u`;;*) (* deprecated, 2011-08-01, thales let lemma_disjiont_exists_fan2=prove(`!x:real^3 (V:real^3->bool) (E:(real^3->bool)->bool) v:real^3 u:real^3 n:num. ~(v=x) /\ ~(u=x) /\ (~(collinear {x, v, u})) /\ {v,u} IN E /\ (v IN V) /\ (u IN V) /\ fan (x,V,E) ==> if_azims_fan x V E v u (0) = &0`, REPEAT GEN_TAC THEN REWRITE_TAC[fan;fan1] THEN STRIP_TAC THEN MP_TAC(ISPECL [`v:real^3`; `(V:real^3->bool)`; `(E:(real^3->bool)->bool)`]remark_finite_fan1) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN SUBGOAL_THEN `(u:real^3) IN set_of_edge (v:real^3) (V:real^3->bool)(E:(real^3->bool)->bool)` ASSUME_TAC THENL[ REWRITE_TAC[set_of_edge; IN_ELIM_THM] THEN ASM_REWRITE_TAC[]; SUBGOAL_THEN ` ~( 0 = CARD (set_of_edge (v:real^3) (V:real^3->bool)(E:((real^3)->bool)->bool))) ` ASSUME_TAC THENL[ STRIP_TAC THEN MP_TAC(ISPEC `set_of_edge (v:real^3) (V:real^3->bool) (E:((real^3)->bool)->bool)`CARD_EQ_0) THEN ASM_REWRITE_TAC[] THEN ASM_SET_TAC[]; SUBGOAL_THEN `azim (x:real^3) (v:real^3) (u:real^3) (u:real^3)= &0` ASSUME_TAC THENL[ ASM_MESON_TAC[ azim_is_zero_fan]; REWRITE_TAC[if_azims_fan; power_map_points;azim;] THEN ASM_REWRITE_TAC[]]]]);; let lemma_disjiont_exists_fan3=prove( `!x:real^3 (V:real^3->bool) (E:(real^3->bool)->bool) v:real^3 u:real^3 y:real^3 n:num. ~(v=x) /\ ~(u=x) /\ (~(collinear {x, v, u})) /\ {v,u} IN E /\ (v IN V) /\ (u IN V) /\ fan (x,V,E) ==> (if_azims_fan x V E v u 0 <= azim x v u y)`, REPEAT GEN_TAC THEN STRIP_TAC THEN MP_TAC(ISPECL[`x:real^3`; `v:real^3`; `u:real^3`; `y:real^3`] azim) THEN STRIP_TAC THEN MP_TAC(ISPECL[`x:real^3` ; `(V:real^3->bool)`; `(E:(real^3->bool)->bool)` ;`v:real^3` ;`u:real^3`; `n:num`]lemma_disjiont_exists_fan2) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN ASM_REWRITE_TAC[azim]);; *)
let wedge2_fan=new_definition`wedge2_fan (x:real^3)  (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num) =
{y:real^3 | ( if_azims_fan x V E v u i = azim x v u y)/\ ( y IN complement_set {x, v})}`;;
(*wedge2_fan=aff_gt*)
let affine_hull_2_fan= 
prove(`(!x:real^3 v:real^3. aff {x , v} = {y:real^3| ?t1:real t2:real. (t1 + t2 = &1 )/\ (y = t1 % x + t2 % v )})`,
REWRITE_TAC[aff;AFFINE_HULL_2] THEN ASM_SET_TAC[]);;
let AFF_GT_1_1 = 
prove (`!x v. DISJOINT {x} {v} ==> aff_gt {x} {v} = {y | ?t1 t2. &0 < t2 /\ t1 + t2 = &1 /\ y = t1 % x + t2 % v}`,
AFF_TAC);;
let th = 
prove (`!x:real^3 v:real^3 u:real^3 w:real^3. ~collinear {x,v,u} /\ ~collinear{x,v,w} ==> {y:real^3 | ~collinear {x,v,y} /\ azim x v u w = azim x v u y} = aff_gt {x , v} {w}`,
GEOM_ORIGIN_TAC `x:real^3` THEN GEOM_BASIS_MULTIPLE_TAC 3 `v:real^3` THEN X_GEN_TAC `v:real` THEN ASM_CASES_TAC `v = &0` THENL [ASM_REWRITE_TAC[VECTOR_MUL_LZERO; INSERT_AC; COLLINEAR_2]; ALL_TAC] THEN ASM_REWRITE_TAC[VECTOR_MUL_LZERO; REAL_LE_LT] THEN DISCH_TAC THEN MAP_EVERY X_GEN_TAC [`u:real^3`; `w:real^3`] THEN ASM_CASES_TAC `w:real^3 = vec 0` THENL [ASM_REWRITE_TAC[INSERT_AC; COLLINEAR_2]; ALL_TAC] THEN ASM_CASES_TAC `w:real^3 = v % basis 3` THENL [ASM_REWRITE_TAC[INSERT_AC; COLLINEAR_2]; ALL_TAC] THEN ASM_SIMP_TAC[AZIM_SPECIAL_SCALE; COLLINEAR_SPECIAL_SCALE] THEN ASM_CASES_TAC `w:real^3 = basis 3` THENL [ASM_REWRITE_TAC[INSERT_AC; COLLINEAR_2]; ALL_TAC] THEN ASM_SIMP_TAC[AFF_GT_SPECIAL_SCALE; IN_SING; FINITE_INSERT; FINITE_EMPTY] THEN POP_ASSUM_LIST(K ALL_TAC) THEN REWRITE_TAC[COLLINEAR_BASIS_3; AZIM_ARG] THEN DISCH_TAC THEN MATCH_MP_TAC EQ_TRANS THEN EXISTS_TAC `{y:real^3 | (dropout 3 y:real^2) IN aff_gt {vec 0} {dropout 3 (w:real^3)}}` THEN CONJ_TAC THENL [REWRITE_TAC[EXTENSION; IN_ELIM_THM] THEN X_GEN_TAC `y:real^3` THEN POP_ASSUM MP_TAC THEN MAP_EVERY SPEC_TAC [`(dropout 3:real^3->real^2) u`,`u:real^2`; `(dropout 3:real^3->real^2) v`,`v:real^2`; `(dropout 3:real^3->real^2) w`,`w:real^2`; `(dropout 3:real^3->real^2) y`,`y:real^2`] THEN SIMP_TAC[AFF_GT_1_1; SET_RULE `DISJOINT {x} {y} <=> ~(x = y)`] THEN REWRITE_TAC[VECTOR_MUL_RZERO; VECTOR_ADD_LID; IN_ELIM_THM] THEN REPEAT STRIP_TAC THEN ONCE_REWRITE_TAC[SWAP_EXISTS_THM] THEN ONCE_REWRITE_TAC[TAUT `a /\ b /\ c <=> a /\ c /\ b`] THEN REWRITE_TAC[REAL_ARITH `t1 + t2 = &1 <=> t1 = &1 - t2`] THEN REWRITE_TAC[RIGHT_EXISTS_AND_THM; EXISTS_REFL] THEN ASM_CASES_TAC `y:real^2 = vec 0` THEN ASM_REWRITE_TAC[] THENL [ASM_MESON_TAC[VECTOR_MUL_EQ_0; REAL_LT_IMP_NZ]; ALL_TAC] THEN RULE_ASSUM_TAC(REWRITE_RULE[COMPLEX_VEC_0]) THEN GEN_REWRITE_TAC LAND_CONV [EQ_SYM_EQ] THEN ASM_SIMP_TAC[ARG_EQ; COMPLEX_CMUL; COMPLEX_FIELD `~(w = Cx(&0)) /\ ~(z = Cx(&0)) ==> ~(w / z = Cx(&0))`] THEN ASM_SIMP_TAC[COMPLEX_FIELD `~(u = Cx(&0)) ==> (w / u = x * y / u <=> w = x * y)`]; SUBGOAL_THEN `~(w:real^3 = vec 0) /\ ~(w = basis 3)` ASSUME_TAC THENL [ASM_MESON_TAC[DROPOUT_BASIS_3; DROPOUT_0]; ALL_TAC] THEN ASM_SIMP_TAC[AFF_GT_1_1; AFF_GT_2_1; DISJOINT_INSERT; IN_INSERT; DISJOINT_EMPTY; NOT_IN_EMPTY] THEN REWRITE_TAC[EXTENSION; IN_ELIM_THM] THEN X_GEN_TAC `y:real^3` THEN REWRITE_TAC[VECTOR_MUL_RZERO; VECTOR_ADD_LID] THEN ONCE_REWRITE_TAC[SWAP_EXISTS_THM] THEN GEN_REWRITE_TAC (RAND_CONV o BINDER_CONV) [SWAP_EXISTS_THM] THEN ONCE_REWRITE_TAC[TAUT `a /\ b /\ c <=> a /\ c /\ b`] THEN REWRITE_TAC[REAL_ARITH `t1 + t2 = &1 <=> t1 = &1 - t2`] THEN REWRITE_TAC[RIGHT_EXISTS_AND_THM; EXISTS_REFL] THEN SIMP_TAC[CART_EQ; DIMINDEX_3; FORALL_3; VECTOR_ADD_COMPONENT; VECTOR_MUL_COMPONENT; BASIS_COMPONENT; ARITH; DIMINDEX_2; DROPOUT_BASIS_3; FORALL_2; dropout; LAMBDA_BETA] THEN ONCE_REWRITE_TAC[SWAP_EXISTS_THM] THEN REWRITE_TAC[REAL_MUL_RZERO; REAL_ADD_LID; RIGHT_EXISTS_AND_THM] THEN REWRITE_TAC[REAL_ARITH `y = t * &1 + s <=> t = y - s`; EXISTS_REFL]]);;
let th1=
prove(`(!x:real^3 v:real^3 u:real^3 w:real^3 t1:real t2:real t3:real. (t3 > &0) /\ (t1 + t2 + t3 = &1) /\ DISJOINT {x,v} {w} /\ ~collinear {x,v,u}/\ ~collinear {x,v,w} ==> azim x v u w = azim x v u (t1 % x + t2 % v + t3 % w))`,
REPEAT GEN_TAC THEN STRIP_TAC THEN ASSUME_TAC(AFF_GT_2_1) THEN POP_ASSUM(MP_TAC o ISPECL [`x:real^3`;`v:real^3`;`w:real^3`]) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN ABBREV_TAC `(y:real^3)= (t1:real) % (x:real^3) + (t2:real) % (v:real^3) + (t3:real) % (w:real^3)` THEN SUBGOAL_THEN `(y:real^3) IN aff_gt {(x:real^3),(v:real^3)} {w:real^3}` ASSUME_TAC THENL[ ASM_REWRITE_TAC[IN_ELIM_THM] THEN EXISTS_TAC `t1:real` THEN EXISTS_TAC `t2:real` THEN EXISTS_TAC `t3:real` THEN EXPAND_TAC "y" THEN ASM_MESON_TAC[REAL_ARITH`(a:real)> &0 <=> &0 < a ` ]; POP_ASSUM MP_TAC THEN ASSUME_TAC(th) THEN POP_ASSUM(MP_TAC o ISPECL [`x:real^3`;`v:real^3`;`u:real^3`;`w:real^3`]) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN POP_ASSUM (fun th-> REWRITE_TAC[SYM(th)]) THEN REWRITE_TAC[IN_ELIM_THM] THEN ASM_SET_TAC[]]);;
let th2= 
prove(`!x:real^3 v:real^3 w:real^3. ~(x=v)==> (w IN complement_set {x,v}==> ~ collinear {x,v,w})`,
REPEAT GEN_TAC THEN DISCH_TAC THEN REWRITE_TAC[CONTRAPOS_THM; COLLINEAR_3;COLLINEAR_LEMMA; complement_set; IN_ELIM_THM;affine_hull_2_fan] THEN STRIP_TAC THENL[ ASM_MESON_TAC[VECTOR_ARITH`(x-v= vec 0)<=> (x=v)`]; EXISTS_TAC `&0` THEN EXISTS_TAC `&1` THEN REWRITE_TAC[REAL_ARITH`&0+ &1 = &1`; VECTOR_ARITH`&0 % x= vec 0`; VECTOR_ARITH`w=vec 0 + &1 % v <=> w - v = vec 0`] THEN ASM_SET_TAC[]; EXISTS_TAC `c:real` THEN EXISTS_TAC `&1 - (c:real)` THEN REWRITE_TAC[REAL_ARITH`c+ &1 - c = &1`; VECTOR_ARITH`w=c % x + (&1 - c) % v <=> w - v = c % (x-v)`] THEN ASM_SET_TAC[]]);;
let COMPLEMENT_SET_FAN=
prove(`!x:real^3 v:real^3 u:real^3 y:real^3 w:real^3 t1:real t2:real t3:real. ~( w IN aff {x, v}) /\ ~(t3 = &0) /\ (t1 + t2 + t3 = &1) ==> t1 % x + t2 % v + t3 % w IN complement_set {x, v}`,
REPEAT GEN_TAC THEN ASSUME_TAC(affine_hull_2_fan) THEN STRIP_TAC THEN REWRITE_TAC[complement_set; IN_ELIM_THM] THEN ASM_REWRITE_TAC[] THEN REWRITE_TAC[IN_ELIM_THM] THEN STRIP_TAC THEN REPEAT(POP_ASSUM MP_TAC) THEN DISCH_TAC THEN ASM_REWRITE_TAC[] THEN REWRITE_TAC[IN_ELIM_THM] THEN REPEAT DISCH_TAC THEN SUBGOAL_THEN ` (t3:real) % w =((t1':real)- (t1:real)) % (x:real^3) + ((t2':real)- (t2:real)) % (v:real^3) ` ASSUME_TAC THENL [POP_ASSUM MP_TAC THEN VECTOR_ARITH_TAC; REPEAT(POP_ASSUM MP_TAC) THEN DISCH_THEN(LABEL_TAC "b") THEN DISCH_THEN(LABEL_TAC "c") THEN DISCH_THEN(LABEL_TAC "d") THEN REPEAT STRIP_TAC THEN USE_THEN "c" MP_TAC THEN REWRITE_TAC[CONTRAPOS_THM] THEN EXISTS_TAC `((t1':real) - (t1:real))/(t3:real)` THEN EXISTS_TAC `((t2':real) - (t2:real))/(t3:real)` THEN SUBGOAL_THEN `((t1':real) - (t1:real))/(t3:real)+ ((t2':real) - (t2:real))/(t3:real) = &1` ASSUME_TAC THENL [REWRITE_TAC[real_div] THEN REWRITE_TAC[REAL_ARITH `a*b+c*b=(a+c)*b`] THEN SUBGOAL_THEN `(t1':real) - (t1:real) + (t2':real) - (t2:real) - (t3:real) = &0` ASSUME_TAC THENL [REPEAT (POP_ASSUM MP_TAC) THEN REAL_ARITH_TAC; SUBGOAL_THEN `(t1':real) - (t1:real) + (t2':real) - (t2:real) = (t3:real)` ASSUME_TAC THENL [POP_ASSUM MP_TAC THEN REAL_ARITH_TAC; ASM_MESON_TAC[REAL_MUL_RINV]]]; ASM_REWRITE_TAC[] THEN REWRITE_TAC[real_div] THEN REWRITE_TAC[VECTOR_ARITH ` (((t1':real) - (t1:real)) * inv (t3:real)) % (x:real^3) + (((t2':real) - (t2:real)) * inv t3) % (v:real^3) = inv t3 % ((t1' - t1) % x + (t2' - t2) % v)`] THEN SUBGOAL_THEN `(t3:real) % (w:real^3) = t3 %( inv t3 % (((t1':real) - (t1:real)) % (x:real^3) + ((t2':real) - (t2:real)) % (v:real^3)))` ASSUME_TAC THENL [REWRITE_TAC[VECTOR_ARITH ` (t3:real) % (inv t3 % (((t1':real) - (t1:real)) % (x:real^3) + ((t2':real) - (t2:real)) % (v:real^3)))= (t3 * inv t3) % ((t1' - t1) % x + (t2' - t2) % v) `] THEN SUBGOAL_THEN `((t3:real) * inv (t3:real) = &1) ` ASSUME_TAC THENL [ASM_MESON_TAC[REAL_MUL_RINV]; ASM_REWRITE_TAC[] THEN VECTOR_ARITH_TAC]; ASM_MESON_TAC[VECTOR_MUL_LCANCEL_IMP]]]]);;
let aff_gt_subset_wedge_fan2=
prove(`!x:real^3 (V:real^3->bool) (E:(real^3->bool)->bool) v:real^3 u:real^3 i:num. ~(i= CARD (set_of_edge v V E)) /\ ~collinear {x,v,u} /\ ~collinear {x,v, power_map_points sigma_fan x V E v u i} ==> aff_gt {x , v} {power_map_points sigma_fan x V E v u i} SUBSET wedge2_fan x V E v u i `,
REWRITE_TAC[SUBSET] THEN REPEAT GEN_TAC THEN ASSUME_TAC(affine_hull_2_fan) THEN STRIP_TAC THEN ASSUME_TAC(th3) THEN POP_ASSUM (MP_TAC o ISPECL [`x:real^3`;`v:real^3`;`(power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num))`]) THEN ASM_REWRITE_TAC[] THEN STRIP_TAC THEN ASSUME_TAC(AFF_GT_2_1) THEN POP_ASSUM (MP_TAC o ISPECL [`x:real^3`;`v:real^3`;`(power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num))`]) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN ASM_REWRITE_TAC[] THEN GEN_TAC THEN REWRITE_TAC[wedge2_fan; IN_ELIM_THM; LEFT_IMP_EXISTS_THM] THEN REPEAT GEN_TAC THEN STRIP_TAC THEN ASM_REWRITE_TAC[] THEN SUBGOAL_THEN `~((t3:real) = &0)` ASSUME_TAC THENL [REPEAT (POP_ASSUM MP_TAC) THEN REAL_ARITH_TAC; ASSUME_TAC(th1) THEN POP_ASSUM( MP_TAC o ISPECL[`x:real^3`;` v:real^3`;` u:real^3`;` power_map_points sigma_fan x V E v u i` ;`t1:real` ;`t2:real` ;`t3:real`]) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN SUBGOAL_THEN `t1 % x + t2 % v + t3 % power_map_points sigma_fan x V E v u i IN complement_set {x, v}` ASSUME_TAC THENL [ASM_MESON_TAC[COMPLEMENT_SET_FAN]; ASM_REWRITE_TAC[] THEN REWRITE_TAC[if_azims_fan;] THEN ASM_MESON_TAC[REAL_ARITH`((t3:real)> &0) <=> (&0 < t3)`]]]);;
let wedge_fan2_subset_aff_gt=
prove(`!x:real^3 (V:real^3->bool) (E:(real^3->bool)->bool) v:real^3 u:real^3 i:num. ~collinear {x,v,u} /\ ~collinear {x, v, power_map_points sigma_fan x V E v u i} /\ ~(i= CARD (set_of_edge v V E)) ==> wedge2_fan x V E v u i SUBSET aff_gt {x , v} {power_map_points sigma_fan x V E v u i}`,
REPEAT GEN_TAC THEN ASSUME_TAC(affine_hull_2_fan) THEN STRIP_TAC THEN ASSUME_TAC(th3) THEN POP_ASSUM (MP_TAC o ISPECL [`x:real^3`;`v:real^3`;`(power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num))`]) THEN ASM_REWRITE_TAC[] THEN STRIP_TAC THEN ASSUME_TAC(AFF_GT_2_1) THEN POP_ASSUM (MP_TAC o ISPECL [`x:real^3`;`v:real^3`;`(power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num))`]) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN ASM_REWRITE_TAC[] THEN REWRITE_TAC[SUBSET] THEN GEN_TAC THEN REWRITE_TAC[wedge2_fan;IN_ELIM_THM] THEN REWRITE_TAC[if_azims_fan; azim] THEN ASM_REWRITE_TAC[] THEN STRIP_TAC THEN ASSUME_TAC(th2) THEN POP_ASSUM(MP_TAC o ISPECL[`x:real^3`; `v:real^3`;`x':real^3`]) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN ASSUME_TAC(th) THEN POP_ASSUM (MP_TAC o SPECL [`x:real^3`;`v:real^3`;`u:real^3`;`(power_map_points sigma_fan x (V:real^3->bool) (E:(real^3->bool)->bool) v u (i:num)):real^3`;]) THEN ASM_REWRITE_TAC[] THEN REWRITE_TAC[EXTENSION] THEN DISCH_TAC THEN POP_ASSUM (MP_TAC o ISPEC `x':real^3`)THEN REWRITE_TAC[IN_ELIM_THM] THEN ASM_REWRITE_TAC[]);;
let wedge_fan2_equal_aff_gt=
prove( ` !x:real^3 (V:real^3->bool) (E:(real^3->bool)->bool) v:real^3 u:real^3 i:num. ~collinear {x,v,u} /\ ~collinear {x, v, power_map_points sigma_fan x V E v u i} /\ ~(i= CARD (set_of_edge v V E)) ==> wedge2_fan x V E v u i = aff_gt {x , v} {power_map_points sigma_fan x V E v u i} `,
REPEAT GEN_TAC THEN STRIP_TAC THEN SUBGOAL_THEN `wedge2_fan x V E v u i SUBSET aff_gt {x , v} {power_map_points sigma_fan x V E v u i}` ASSUME_TAC THENL [ ASM_MESON_TAC[ wedge_fan2_subset_aff_gt;aff_gt_subset_wedge_fan2]; SUBGOAL_THEN ` aff_gt {(x:real^3), (v:real^3)} {power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num)} SUBSET wedge2_fan (x:real^3) V E (v:real^3) (u:real^3) (i:num)` ASSUME_TAC THENL[ASM_MESON_TAC[aff_gt_subset_wedge_fan2]; ASM_SET_TAC[]]]);;
let wedge_fan2_equal_aff_gt_fan=
prove(` !x:real^3 (V:real^3->bool) (E:(real^3->bool)->bool) v:real^3 u:real^3 i:num. FAN(x,V,E)/\ ({v,u} IN E) /\ ~(i= CARD (set_of_edge v V E)) ==> wedge2_fan x V E v u i = aff_gt {x , v} {power_map_points sigma_fan x V E v u i} `,
REPEAT GEN_TAC THEN STRIP_TAC THEN REPEAT (POP_ASSUM MP_TAC) THEN DISCH_THEN (LABEL_TAC"a") THEN USE_THEN "a" MP_TAC THEN REWRITE_TAC[FAN;fan6] THEN STRIP_TAC THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN DISCH_THEN (LABEL_TAC "b") THEN REPEAT STRIP_TAC THEN MP_TAC (ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;`(v:real^3)`;` (u:real^3)`]properties_of_set_of_edge_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(i:num)`; `(x:real^3)`;` (V:real^3->bool)`; ` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`] image_power_map_points) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC (ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;`(v:real^3)`;` power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num)`]properties_of_set_of_edge_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN USE_THEN "b" (fun th-> MP_TAC(ISPEC`{(v:real^3),(u:real^3)}`th)) THEN REMOVE_THEN "b" (fun th-> MP_TAC(ISPEC`{(v:real^3),(power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num))}`th)) THEN ASM_REWRITE_TAC[SET_RULE`{a} UNION {b,c}={a,b,c}`] THEN DISCH_TAC THEN DISCH_TAC THEN ASM_MESON_TAC[wedge_fan2_equal_aff_gt]);;
(*****wedge3_fan=w_dart_fan*******)
let wedge3_fan=new_definition`wedge3_fan (x:real^3)  (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num) =
{y:real^3 | ( if_azims_fan x V E v u (i) < azim x v u y)/\
(azim x v u y < if_azims_fan x V E v u (SUC i)) /\( y IN complement_set {x, v})}`;;
let w_dart_eq_wedge3_fan=
prove(` !x:real^3 (V:real^3->bool) (E:(real^3->bool)->bool) v:real^3 u:real^3 i:num. FAN(x,V,E) /\ ({v,u} IN E) /\ (i< CARD (set_of_edge v V E)) /\ CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))> 1 ==> w_dart_fan x V E (x,v,power_map_points sigma_fan x V E v u i, power_map_points sigma_fan x V E v u (SUC i)) = wedge3_fan x V E v u i`,
REPEAT GEN_TAC THEN STRIP_TAC THEN REPEAT (POP_ASSUM MP_TAC) THEN DISCH_THEN(LABEL_TAC "a") THEN USE_THEN "a" MP_TAC THEN REWRITE_TAC[FAN;fan6] THEN STRIP_TAC THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN DISCH_THEN(LABEL_TAC"1") THEN REPEAT STRIP_TAC THEN MP_TAC(ISPECL[`x:real^3 `;` (V:real^3->bool) `;`(E:(real^3->bool)->bool)`;` u:real^3`;` v:real^3`]th4) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN ASM_REWRITE_TAC[w_dart_fan;wedge;wedge3_fan;complement_set; IN_ELIM_THM;collinear_fan] THEN DISJ_CASES_TAC(ARITH_RULE`i=0 \/ 0< (i:num)`) THENL[ MP_TAC(ARITH_RULE`CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)) > 1 ==> ~(CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))= 0)/\ ~(CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))=1)`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN ASM_REWRITE_TAC[power_map_points;if_azims_fan;ARITH_RULE`SUC 0 =1`;AZIM_REFL;] THEN ASM_REWRITE_TAC[] THEN ASM_SET_TAC[]; MP_TAC(ARITH_RULE`(i:num)<CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))==> ~(i=CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)))`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`x:real^3 `;` (V:real^3->bool) `;`(E:(real^3->bool)->bool)`;` v:real^3`;` u:real^3`;`i:num`]SUM_IF_AZIMS_FAN) THEN ASM_REWRITE_TAC[] THEN DISCH_THEN(LABEL_TAC "bc") THEN ASM_REWRITE_TAC[if_azims_fan;EXTENSION;IN_ELIM_THM] THEN GEN_TAC THEN EQ_TAC THENL[ STRIP_TAC THEN ASM_REWRITE_TAC[] THEN MP_TAC(REAL_ARITH`azim (x:real^3) (v:real^3) ( power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num)) (x':real^3) < azim (x:real^3) (v:real^3) ( power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num)) (sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num)) ) ==> azim (x:real^3) (v:real^3) (u:real^3) ( power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num)) + azim (x:real^3) (v:real^3) ( power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num)) (x':real^3)< azim (x:real^3) (v:real^3) (u:real^3) ( power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num)) + azim (x:real^3) (v:real^3) ( power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num)) (sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) ( power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num)) )`) THEN ASM_REWRITE_TAC[] THEN REMOVE_THEN "bc" MP_TAC THEN GEN_REWRITE_TAC (LAND_CONV o RAND_CONV o REDEPTH_CONV) [if_azims_fan;power_map_points] THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN POP_ASSUM(fun th-> REWRITE_TAC[SYM(th)]) THEN DISCH_TAC THEN ASSUME_TAC (ISPECL[`x:real^3 `;` (V:real^3->bool) `;`(E:(real^3->bool)->bool)`;` v:real^3`;` u:real^3`;`SUC i:num`]if_azims_works_fan) THEN MP_TAC(REAL_ARITH`azim (x:real^3) (v:real^3) (u:real^3) ( power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num)) + azim (x:real^3) (v:real^3) ( power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num)) (x':real^3)< if_azims_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (SUC(i:num)) /\ if_azims_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (SUC(i:num)) <= &2 *pi ==> azim (x:real^3) (v:real^3) (u:real^3) ( power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num)) + azim (x:real^3) (v:real^3) ( power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num)) (x':real^3)< &2 * pi`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`x':real^3`]collinear_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`i:num`;`x:real^3 `;` (V:real^3->bool) `;`(E:(real^3->bool)->bool)`;` v:real^3`;` u:real^3`]IN2_ORBITS_FAN) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`SUC(i:num)`;`x:real^3 `;` (V:real^3->bool) `;`(E:(real^3->bool)->bool)`;` v:real^3`;` u:real^3`]IN2_ORBITS_FAN) THEN ASM_REWRITE_TAC[power_map_points] THEN DISCH_TAC THEN REMOVE_THEN "1" (fun th-> MP_TAC(ISPEC`{(v:real^3),(u:real^3)}`th)THEN ASSUME_TAC(th)) THEN POP_ASSUM (fun th-> MP_TAC(ISPEC`{(v:real^3),( power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num))}`th)) THEN ASM_REWRITE_TAC[SET_RULE`{a}UNION {b,c}={a,b,c}`]THEN DISCH_TAC THEN DISCH_TAC THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`;`( power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num))`; `x':real^3`]sum3_azim_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN ASM_REWRITE_TAC[] THEN ASM_REWRITE_TAC[REAL_ARITH`(a:real) < a +b <=> &0 < b`; REAL_ARITH`(a:real) + c< a +b<=> c< b`;]; STRIP_TAC THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN DISCH_THEN(LABEL_TAC"ma1") THEN DISCH_THEN(LABEL_TAC"ma2") THEN DISCH_TAC THEN ASM_REWRITE_TAC[] THEN MP_TAC(REAL_ARITH`azim (x:real^3) (v:real^3) (u:real^3) ( power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num)) < azim (x:real^3) (v:real^3) (u:real^3) (x':real^3) ==> azim (x:real^3) (v:real^3) (u:real^3) ( power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num)) <= azim (x:real^3) (v:real^3) (u:real^3) (x':real^3) `) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`x':real^3`]collinear_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`i:num`;`x:real^3 `;` (V:real^3->bool) `;`(E:(real^3->bool)->bool)`;` v:real^3`;` u:real^3`]IN2_ORBITS_FAN) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`SUC(i:num)`;`x:real^3 `;` (V:real^3->bool) `;`(E:(real^3->bool)->bool)`;` v:real^3`;` u:real^3`]IN2_ORBITS_FAN) THEN ASM_REWRITE_TAC[power_map_points] THEN DISCH_TAC THEN REMOVE_THEN "1" (fun th-> MP_TAC(ISPEC`{(v:real^3),(u:real^3)}`th)THEN ASSUME_TAC(th)) THEN POP_ASSUM (fun th-> MP_TAC(ISPEC`{(v:real^3),( power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num))}`th)) THEN ASM_REWRITE_TAC[SET_RULE`{a}UNION {b,c}={a,b,c}`]THEN DISCH_TAC THEN DISCH_TAC THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`;`( power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num))`; `x':real^3`]sum4_azim_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN REMOVE_THEN "ma1" MP_TAC THEN REMOVE_THEN "ma2" MP_TAC THEN ASM_REWRITE_TAC[power_map_points] THEN REAL_ARITH_TAC]]);;
let UNION_FAN=
prove( `!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3). FAN(x,V,E)/\ ({v,u}IN E) ==> (UNIV:real^3->bool) = aff {x,v} UNION (UNIONS {wedge3_fan x V E v u i|i| 0 <= i /\ i< CARD(set_of_edge v V E) }) UNION (UNIONS {wedge2_fan x V E v u i|i| 0 <= i /\ i< CARD(set_of_edge v V E) } ) `,
REPEAT STRIP_TAC THEN REWRITE_TAC[EXTENSION; UNION;IN_ELIM_THM] THEN GEN_TAC THEN EQ_TAC THENL(*1*)[ STRIP_TAC THEN DISJ_CASES_TAC(SET_RULE`(x':real^3) IN aff {(x:real^3),(v:real^3)} \/ ~((x':real^3) IN aff {x,v})`) THENL(*2*)[ ASM_SET_TAC[];(*2*) ASM_REWRITE_TAC[] THEN DISJ_CASES_TAC(SET_RULE`(x':real^3) IN (UNIONS {wedge2_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num)|i| 0 <= i /\ i< CARD(set_of_edge v V E)} ) \/ ~((x':real^3) IN (UNIONS {wedge2_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num)|i| 0 <= i/\ i< CARD(set_of_edge v V E)}) )`) THENL(*3*)[ ASM_REWRITE_TAC[];(*3*) ASM_REWRITE_TAC[] THEN POP_ASSUM MP_TAC THEN REWRITE_TAC[UNIONS;IN_ELIM_THM;NOT_EXISTS_THM;DE_MORGAN_THM;ARITH_RULE `(0 <= (i:num))`] THEN DISCH_TAC THEN SUBGOAL_THEN`!i:num. ~((x':real^3) IN wedge2_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num))\/ ~(i< CARD(set_of_edge v V E)) ` ASSUME_TAC THENL(*4*)[ ASM_SET_TAC[];(*4*) POP_ASSUM MP_TAC THEN REWRITE_TAC[wedge2_fan;IN_ELIM_THM] THEN DISCH_THEN(LABEL_TAC"100") THEN SUBGOAL_THEN`(~((x':real^3) IN set_of_orbits_points_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3)))` ASSUME_TAC THENL(*5*)[ MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (u:real^3)`]SIMP_ORBITS_POINTS_FAN) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN POP_ASSUM(fun th-> REWRITE_TAC[SYM(th)]) THEN REWRITE_TAC[IN_ELIM_THM] THEN POP_ASSUM MP_TAC THEN DISCH_THEN(LABEL_TAC"a") THEN STRIP_TAC THEN REMOVE_THEN "a"(fun th-> MP_TAC(ISPEC`i:num`th)) THEN MP_TAC(ARITH_RULE`(i:num) < CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))==> ~(i=CARD(set_of_edge v V E))`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN ASM_REWRITE_TAC[if_azims_fan;complement_set; IN_ELIM_THM] THEN ASM_MESON_TAC[remark_power_map_points];(*5*) MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (u:real^3)`]SIMP_ORBITS_POINTS_FAN) THEN ASM_REWRITE_TAC[] THEN DISCH_THEN(LABEL_TAC"a") THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (u:real^3)`;`x':real^3`]exists_inverse_in_orbits_sigma_fan) THEN ASM_REWRITE_TAC[azim1] THEN STRIP_TAC THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN DISCH_THEN(LABEL_TAC"b") THEN DISCH_TAC THEN DISCH_TAC THEN REMOVE_THEN "b" MP_TAC THEN REMOVE_THEN "a"(fun th->REWRITE_TAC[SYM(th)] THEN ASSUME_TAC(th)) THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN DISCH_THEN(LABEL_TAC"a") THEN DISCH_TAC THEN REWRITE_TAC[IN_ELIM_THM] THEN STRIP_TAC THEN EXISTS_TAC`wedge3_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num)` THEN STRIP_TAC THENL(*6*)[ EXISTS_TAC`i:num` THEN ASM_REWRITE_TAC[];(*6*) ASM_REWRITE_TAC[wedge3_fan; complement_set; IN_ELIM_THM;] THEN SUBGOAL_THEN`if_azims_fan x (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num) < azim (x:real^3) v u (x':real^3)` ASSUME_TAC THENL(*7*)[ MP_TAC(ARITH_RULE`(i:num) < CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))==> ~(i=CARD(set_of_edge v V E))`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN ASM_REWRITE_TAC[if_azims_fan;complement_set; IN_ELIM_THM] THEN POP_ASSUM MP_TAC THEN POP_ASSUM(fun th-> REWRITE_TAC[SYM(th)] THEN ASSUME_TAC(th)) THEN POP_ASSUM MP_TAC THEN DISJ_CASES_TAC(ARITH_RULE`(i:num)=0 \/ 0< i`) THENL(*8*)[ ASM_REWRITE_TAC[power_map_points] THEN DISCH_TAC THEN ASM_REWRITE_TAC[AZIM_REFL] THEN POP_ASSUM (fun th->REWRITE_TAC[]) THEN POP_ASSUM (fun th->REWRITE_TAC[]) THEN POP_ASSUM (fun th->REWRITE_TAC[]) THEN POP_ASSUM (fun th->REWRITE_TAC[]) THEN POP_ASSUM (fun th->REWRITE_TAC[]) THEN POP_ASSUM (fun th->REWRITE_TAC[]) THEN POP_ASSUM (fun th->REWRITE_TAC[]) THEN POP_ASSUM (fun th->MP_TAC(ISPEC`0`th)) THEN DISCH_THEN(LABEL_TAC"a") THEN DISCH_TAC THEN REMOVE_THEN "a" MP_TAC THEN ASM_REWRITE_TAC[if_azims_fan;power_map_points;DE_MORGAN_THM; complement_set; IN_ELIM_THM;AZIM_REFL;ARITH_RULE`(~(0<a)<=> (0=a))`] THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`;`x':real^3`]azim ) THEN POP_ASSUM MP_TAC THEN REAL_ARITH_TAC;(*8*) MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (u:real^3)`;] u_IN_ORBITS_FAN) THEN DISCH_TAC THEN SUBGOAL_THEN `~(u=(x':real^3))` ASSUME_TAC THENL(*9*)[ ASM_SET_TAC[];(*9*) DISCH_TAC THEN REMOVE_THEN "a"(fun th-> MP_TAC(ISPEC`u:real^3`th)) THEN ASM_REWRITE_TAC[] THEN REWRITE_TAC[REAL_ARITH`(b:real)- a<= b-c <=> c <= a`] THEN DISCH_THEN(LABEL_TAC"b1") THEN MP_TAC(ARITH_RULE`0< (i:num)/\ i <CARD(set_of_edge (v:real^3) V E)==> ~(0=CARD(set_of_edge v V E))`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN USE_THEN"100"(fun th-> MP_TAC(ISPEC`0`th)) THEN REWRITE_TAC[if_azims_fan] THEN ASM_REWRITE_TAC[power_map_points;AZIM_REFL;complement_set; IN_ELIM_THM] THEN MP_TAC(ARITH_RULE`i <CARD(set_of_edge (v:real^3) V E)==> ~(i=CARD(set_of_edge v V E))`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN USE_THEN"100"(fun th-> MP_TAC(ISPEC`i:num`th)) THEN REWRITE_TAC[if_azims_fan] THEN ASM_REWRITE_TAC[power_map_points;AZIM_REFL;complement_set; IN_ELIM_THM] THEN GEN_REWRITE_TAC(LAND_CONV o RAND_CONV o ONCE_DEPTH_CONV)[SET_RULE`a=b <=> b=a`] THEN DISCH_TAC THEN DISJ_CASES_TAC(SET_RULE`collinear {(x:real^3),v,x'} \/ ~collinear {x,v,x'}`) THENL(*10*)[ POP_ASSUM MP_TAC THEN GEN_REWRITE_TAC( LAND_CONV o RAND_CONV o ONCE_DEPTH_CONV) [SET_RULE`{a,b,c}= {a,c,b}`] THEN REWRITE_TAC[COLLINEAR_3_EXPAND;] THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (u:real^3)`;` (v:real^3)`] remark1_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN ASM_REWRITE_TAC[] THEN STRIP_TAC THEN SUBGOAL_THEN `(x':real^3) IN aff {x,v}` ASSUME_TAC THENL(*11*)[ REWRITE_TAC[aff; AFFINE_HULL_2; IN_ELIM_THM] THEN EXISTS_TAC`u':real` THEN EXISTS_TAC`&1 -(u':real)` THEN ASM_REWRITE_TAC[] THEN REAL_ARITH_TAC;(*11*) ASM_MESON_TAC[]](*11*);(*10*) STRIP_TAC THENL(*11*)[ POP_ASSUM MP_TAC THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (u:real^3)`;` (v:real^3)`] remark1_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`i:num`;`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (u:real^3)`] remark_power_map_points) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`;`x':real^3`;`( power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num))`]AZIM_EQ_ALT) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`( power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num))`;`x':real^3`]AZIM_EQ_0_ALT) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3) `;`(v:real^3)`;`( power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num))`;` (x':real^3)`] AZIM_COMPL) THEN ASM_REWRITE_TAC[] THEN MP_TAC(ISPECL[`(x:real^3) `;`(v:real^3)`;` (u:real^3)`;`(x':real^3)`] AZIM_COMPL) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN DISCH_TAC THEN REMOVE_THEN"b1" MP_TAC THEN ASM_REWRITE_TAC[REAL_ARITH`b-a<= b-c <=> c<= a`] THEN DISCH_TAC THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`; `( power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num))`;` (x':real^3)`]sum5_azim_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`( power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (i:num))`;` (x':real^3)`]azim) THEN POP_ASSUM MP_TAC THEN POP_ASSUM(fun th->REWRITE_TAC[]) THEN POP_ASSUM(fun th->REWRITE_TAC[]) THEN POP_ASSUM(fun th->REWRITE_TAC[]) THEN POP_ASSUM(fun th->REWRITE_TAC[]) THEN POP_ASSUM MP_TAC THEN REAL_ARITH_TAC;(*11*) REPEAT (POP_ASSUM MP_TAC) THEN ARITH_TAC](*11*)](*10*)](*9*)](*8*);(*7*) ASM_REWRITE_TAC[] THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN DISCH_THEN(LABEL_TAC"b") THEN DISCH_THEN(LABEL_TAC"c") THEN DISJ_CASES_TAC(ARITH_RULE`SUC (i:num)= CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))\/ ~(SUC (i)= CARD(set_of_edge v V E))`) THENL(*8*)[ ASM_REWRITE_TAC[if_azims_fan] THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`;`x':real^3`]azim) THEN REAL_ARITH_TAC; (*8*) DISJ_CASES_TAC(ARITH_RULE`(i:num)=0 \/ 0<i `) THENL(*9*)[ REMOVE_THEN "b" MP_TAC THEN ASM_REWRITE_TAC[if_azims_fan;power_map_points] THEN DISCH_TAC THEN POP_ASSUM(fun th-> REWRITE_TAC[SYM(th)]THEN ASSUME_TAC(SYM(th))) THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (u:real^3)`;] u_IN_ORBITS_FAN) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (u:real^3)`;`w:real^3`] IN_ORBITS_FAN) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN SUBGOAL_THEN `~(sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3)=(x':real^3))` ASSUME_TAC THENL(*10*)[ASM_SET_TAC[];(*10*) REMOVE_THEN "a" (fun th -> MP_TAC(ISPEC`sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3)`th)) THEN ASM_REWRITE_TAC[REAL_ARITH`b-a<= b-c <=> c<= a`]THEN DISCH_THEN(LABEL_TAC"b1") THEN MP_TAC(ARITH_RULE`(i:num)=0/\ i <CARD(set_of_edge (v:real^3) V E)==> ~(0=CARD(set_of_edge v V E))`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN USE_THEN"100"(fun th-> MP_TAC(ISPEC`i:num`th)) THEN REWRITE_TAC[if_azims_fan] THEN ASM_REWRITE_TAC[power_map_points;AZIM_REFL;complement_set; IN_ELIM_THM] THEN GEN_REWRITE_TAC(LAND_CONV o RAND_CONV o ONCE_DEPTH_CONV)[SET_RULE`a=b <=> b=a`] THEN DISCH_TAC THEN MP_TAC(ARITH_RULE`(i:num)=0/\ ~(SUC(i) =CARD(set_of_edge (v:real^3) V E))==> ~(SUC(0)=CARD(set_of_edge v V E))`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN USE_THEN"100"(fun th-> MP_TAC(ISPEC`SUC(0):num`th)) THEN REWRITE_TAC[if_azims_fan] THEN ASM_REWRITE_TAC[power_map_points;AZIM_REFL;complement_set; IN_ELIM_THM] THEN GEN_REWRITE_TAC(LAND_CONV o RAND_CONV o ONCE_DEPTH_CONV)[SET_RULE`a=b <=> b=a`] THEN REWRITE_TAC[power_map_points] THEN DISJ_CASES_TAC(SET_RULE`collinear {(x:real^3),v,x'} \/ ~collinear {x,v,x'}`) THENL(*11*)[ POP_ASSUM MP_TAC THEN GEN_REWRITE_TAC( LAND_CONV o RAND_CONV o ONCE_DEPTH_CONV) [SET_RULE`{a,b,c}= {a,c,b}`] THEN REWRITE_TAC[COLLINEAR_3_EXPAND;] THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (u:real^3)`;` (v:real^3)`] remark1_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN ASM_REWRITE_TAC[] THEN STRIP_TAC THEN SUBGOAL_THEN `(x':real^3) IN aff {x,v}` ASSUME_TAC THENL(*12*)[ REWRITE_TAC[aff; AFFINE_HULL_2; IN_ELIM_THM] THEN EXISTS_TAC`u':real` THEN EXISTS_TAC`&1 -(u':real)` THEN ASM_REWRITE_TAC[] THEN REAL_ARITH_TAC;(*12*) ASM_MESON_TAC[]](*12*);(*11*) STRIP_TAC THENL(*12*)[ MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (u:real^3)`;` (v:real^3)`] remark1_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(SET_RULE`(u:real^3)=(w:real^3) /\ {v,u} IN (E:(real^3->bool)->bool)==> {v,w} IN E`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`SUC(0):num`;`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (w:real^3)`] remark_power_map_points) THEN ASM_REWRITE_TAC[power_map_points] THEN DISCH_TAC THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`;`x':real^3`;`( power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (SUC(0):num))`]AZIM_EQ_ALT) THEN ASM_REWRITE_TAC[power_map_points] THEN DISCH_TAC THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`( power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (SUC(0):num))`;`x':real^3`]AZIM_EQ_0_ALT) THEN ASM_REWRITE_TAC[power_map_points] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3) `;`(v:real^3)`;`( power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (SUC(0):num))`;` (x':real^3)`] AZIM_COMPL) THEN ASM_REWRITE_TAC[power_map_points] THEN MP_TAC(ISPECL[`(x:real^3) `;`(v:real^3)`;` (u:real^3)`;`(x':real^3)`] AZIM_COMPL) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN DISCH_TAC THEN REMOVE_THEN"b1" MP_TAC THEN ASM_REWRITE_TAC[REAL_ARITH`b-a<= b-c <=> c<= a`] THEN DISCH_TAC THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`( power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (SUC(0):num))`;`w:real^3`;` (x':real^3)`]sum5_azim_fan) THEN ASM_REWRITE_TAC[power_map_points;REAL_ARITH`a=b+c <=> c=a-b`] THEN DISCH_TAC THEN ASM_REWRITE_TAC[REAL_ARITH`a-b<c <=> a< b+c`] THEN MP_TAC(ARITH_RULE` (i:num) < (CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))) /\ ~(SUC(i)=CARD(set_of_edge v V E)) ==> SUC(i) < CARD(set_of_edge v V E)`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (u:real^3)`; `SUC(i):num`; `i:num`] cyclic_power_sigma_fan) THEN ASM_REWRITE_TAC[power_map_points;ARITH_RULE`0< SUC 0`; ] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3))`; `w:real^3`; ] UNIQUE_AZIM_0_POINT_FAN) THEN ASM_REWRITE_TAC[power_map_points; ] THEN DISCH_TAC THEN MP_TAC(ISPECL[`x:real^3`; `v:real^3`;` (sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3))`; `w:real^3`]AZIM_COMPL) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN ASM_REWRITE_TAC[REAL_ARITH`c<a+b-a <=> c<b`] THEN MESON_TAC[azim];(*12*) REPEAT(POP_ASSUM MP_TAC) THEN ARITH_TAC](*12*)](*11*)](*10*);(*9*) REMOVE_THEN "b" MP_TAC THEN ASM_REWRITE_TAC[if_azims_fan;power_map_points] THEN DISCH_TAC THEN POP_ASSUM(fun th-> REWRITE_TAC[SYM(th)]THEN ASSUME_TAC(SYM(th))) THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (u:real^3)`;`i:num`] i_IN_ORBITS_FAN) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (u:real^3)`;`w:real^3`] IN_ORBITS_FAN) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN SUBGOAL_THEN `~(sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3)=(x':real^3))` ASSUME_TAC THENL(*10*)[ ASM_SET_TAC[];(*10*) REMOVE_THEN "a" (fun th -> MP_TAC(ISPEC`sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3)`th)) THEN ASM_REWRITE_TAC[REAL_ARITH`b-a<= b-c <=> c<= a`]THEN DISCH_THEN(LABEL_TAC"b1") THEN MP_TAC(ARITH_RULE`i <CARD(set_of_edge (v:real^3) V E)==> ~(i=CARD(set_of_edge v V E))`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN USE_THEN"100"(fun th-> MP_TAC(ISPEC`i:num`th)) THEN REWRITE_TAC[if_azims_fan] THEN ASM_REWRITE_TAC[power_map_points;AZIM_REFL;complement_set; IN_ELIM_THM] THEN GEN_REWRITE_TAC(LAND_CONV o RAND_CONV o ONCE_DEPTH_CONV)[SET_RULE`a=b <=> b=a`] THEN DISCH_TAC THEN USE_THEN"100"(fun th-> MP_TAC(ISPEC`SUC(i):num`th)) THEN REWRITE_TAC[if_azims_fan] THEN ASM_REWRITE_TAC[power_map_points;AZIM_REFL;complement_set; IN_ELIM_THM] THEN GEN_REWRITE_TAC(LAND_CONV o RAND_CONV o ONCE_DEPTH_CONV)[SET_RULE`a=b <=> b=a`] THEN REWRITE_TAC[power_map_points] THEN DISJ_CASES_TAC(SET_RULE`collinear {(x:real^3),v,x'} \/ ~collinear {x,v,x'}`) THENL(*11*)[ POP_ASSUM MP_TAC THEN GEN_REWRITE_TAC( LAND_CONV o RAND_CONV o ONCE_DEPTH_CONV) [SET_RULE`{a,b,c}= {a,c,b}`] THEN REWRITE_TAC[COLLINEAR_3_EXPAND;] THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (u:real^3)`;` (v:real^3)`] remark1_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN ASM_REWRITE_TAC[] THEN STRIP_TAC THEN SUBGOAL_THEN `(x':real^3) IN aff {x,v}` ASSUME_TAC THENL(*12*)[ REWRITE_TAC[aff; AFFINE_HULL_2; IN_ELIM_THM] THEN EXISTS_TAC`u':real` THEN EXISTS_TAC`&1 -(u':real)` THEN ASM_REWRITE_TAC[] THEN REAL_ARITH_TAC;(*12*) ASM_MESON_TAC[]](*12*);(*11*) STRIP_TAC THENL(*12*)[ MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (u:real^3)`;` (v:real^3)`] remark1_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`i:num`;`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (u:real^3)`] remark_power_map_points) THEN ASM_REWRITE_TAC[power_map_points] THEN DISCH_TAC THEN MP_TAC(ISPECL[`SUC(i):num`;`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (u:real^3)`] remark_power_map_points) THEN ASM_REWRITE_TAC[power_map_points] THEN DISCH_TAC THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`;`x':real^3`;`( power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (SUC(i):num))`]AZIM_EQ_ALT) THEN ASM_REWRITE_TAC[power_map_points] THEN DISCH_TAC THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`( power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (SUC(i):num))`;`x':real^3`]AZIM_EQ_0_ALT) THEN ASM_REWRITE_TAC[power_map_points] THEN DISCH_TAC THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`;`x':real^3`;`( power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) ((i):num))`]AZIM_EQ_ALT) THEN ASM_REWRITE_TAC[power_map_points] THEN DISCH_TAC THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`( power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) ((i):num))`;`x':real^3`]AZIM_EQ_0_ALT) THEN ASM_REWRITE_TAC[power_map_points] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3) `;`(v:real^3)`;`( power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (SUC(i):num))`;` (x':real^3)`] AZIM_COMPL) THEN ASM_REWRITE_TAC[power_map_points] THEN MP_TAC(ISPECL[`(x:real^3) `;`(v:real^3)`;` (w:real^3)`;`(x':real^3)`] AZIM_COMPL) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN DISCH_TAC THEN REMOVE_THEN "c" MP_TAC THEN ASM_REWRITE_TAC[if_azims_fan] THEN DISCH_TAC THEN MP_TAC(REAL_ARITH`azim x v u w< azim (x:real^3) v u x'==> azim x v u w<= azim (x:real^3) v u x'`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`(u:real^3)`;`w:real^3`;` (x':real^3)`]sum4_azim_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (u:real^3)`;`i:num`] SUM_IF_AZIMS_FAN) THEN ASM_REWRITE_TAC[if_azims_fan;power_map_points] THEN DISCH_TAC THEN ASM_REWRITE_TAC[REAL_ARITH`a+b<a+c <=> b<c`] THEN REMOVE_THEN"b1" MP_TAC THEN ASM_REWRITE_TAC[REAL_ARITH`b-a<= b-c <=> c<= a`] THEN DISCH_TAC THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`( power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) (SUC(i):num))`;`w:real^3`;` (x':real^3)`]sum5_azim_fan) THEN ASM_REWRITE_TAC[power_map_points;REAL_ARITH`a=b+c <=> c=a-b`] THEN DISCH_TAC THEN ASM_REWRITE_TAC[REAL_ARITH`a-b<c <=> a< b+c`] THEN MP_TAC(ARITH_RULE` (i:num) < (CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))) /\ ~(SUC(i)=CARD(set_of_edge v V E)) ==> SUC(i) < CARD(set_of_edge v V E)`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (u:real^3)`; `SUC(i):num`; `i:num`] cyclic_power_sigma_fan) THEN ASM_REWRITE_TAC[power_map_points;ARITH_RULE`i< SUC i`; ] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3))`; `w:real^3`; ] UNIQUE_AZIM_0_POINT_FAN) THEN ASM_REWRITE_TAC[power_map_points; ] THEN DISCH_TAC THEN MP_TAC(ISPECL[`x:real^3`; `v:real^3`;` (sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3))`; `w:real^3`]AZIM_COMPL) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN ASM_REWRITE_TAC[REAL_ARITH`c<a+b-a <=> c<b`] THEN MESON_TAC[azim];(*12*) REPEAT(POP_ASSUM MP_TAC) THEN ARITH_TAC](*12*)](*11*)]]]]]]]]]; ASM_SET_TAC[]]);;
let aff_subset_aff_ge=
prove(`!x:real^3 v:real^3 w:real^3. DISJOINT {x,v} {w} ==> aff {x,v} SUBSET aff_ge {x,v} {w}`,
REPEAT GEN_TAC THEN STRIP_TAC THEN MP_TAC(ISPECL[`(x:real^3) `;` (v:real^3)`;` (w:real^3)`]AFF_GE_2_1) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN ASM_REWRITE_TAC[aff; AFFINE_HULL_2; SUBSET; AFF_GE_2_1; IN_ELIM_THM] THEN GEN_TAC THEN STRIP_TAC THEN EXISTS_TAC`u:real` THEN EXISTS_TAC`v':real` THEN EXISTS_TAC`&0` THEN ASM_REWRITE_TAC[VECTOR_ARITH`a=b +c + &0 % d<=>a=b+c`] THEN REPEAT (POP_ASSUM MP_TAC) THEN REAL_ARITH_TAC);;
let eq_set_wdart_fan=
prove(`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3). FAN(x,V,E)/\ ({v,u}IN E) ==> ({w_dart_fan x V E (x,v,w,(sigma_fan x V E v w))|w| {v,w} IN E } = {wedge3_fan x V E v u i|i| 0 <= i/\ i< CARD(set_of_edge v V E) }) `,
(
let lem= prove(`!x v u w. 
(&0 < azim x v u w) <=> ~(azim x v u w= &0)`,
MESON_TAC[azim; REAL_ARITH`&0 <= a==> (&0 < a) <=> ~(a= &0)`]) in
( let lem1=prove(`!x v. ~(x = v)==>(!u. ~(u IN aff {x, v}) <=> ~collinear {x, v, u})`,
MESON_TAC[collinear_fan]) in
(let lem2=prove(`!v0 v1 w.
        ~collinear{v0,v1,w}  ==>
!x. ( ~(azim v0 v1 w x = &0)/\ ~collinear{v0,v1,x} <=> ~(x IN aff_ge {v0,v1} {w}) /\ ~collinear{v0,v1,x})`,
MESON_TAC[AZIM_EQ_0_GE_ALT]) in

REPEAT STRIP_TAC THEN REWRITE_TAC[EXTENSION; IN_ELIM_THM] THEN GEN_TAC THEN EQ_TAC
THENL(*1*)[
REWRITE_TAC[GSYM(EXTENSION)] THEN STRIP_TAC 
  THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (w:real^3)`] properties_of_set_of_edge_fan) 
  THEN ASM_REWRITE_TAC[] THEN 
MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (u:real^3)`] ORBITS_EQ_SET_EDGE_FAN) 
  THEN ASM_REWRITE_TAC[] THEN 
MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (u:real^3)`] SIMP_ORBITS_POINTS_FAN) 
  THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN POP_ASSUM(fun th-> REWRITE_TAC[SYM(th)])THEN DISCH_TAC 
THEN POP_ASSUM(fun th->GEN_REWRITE_TAC(LAND_CONV o RAND_CONV o ONCE_DEPTH_CONV)[th])
  THEN REWRITE_TAC[IN_ELIM_THM;] THEN STRIP_TAC THEN EXISTS_TAC `i:num` THEN
ASM_REWRITE_TAC[ARITH_RULE`0<= (i:num)`]
  THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC 
THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (u:real^3)`]CARD_SET_OF_ORBITS_POINTS_FAN) 
  THEN ASM_REWRITE_TAC[] THEN DISCH_TAC 
THEN ASM_REWRITE_TAC[] THEN REPEAT STRIP_TAC
THEN
DISJ_CASES_TAC(ARITH_RULE`(CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)))>1 \/ ~((CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)))> 1)`)
THENL[
MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (u:real^3)`;`i:num`] w_dart_eq_wedge3_fan) 
  THEN ASM_REWRITE_TAC[power_map_points];

MP_TAC(ARITH_RULE`(i:num)<CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)) /\ ~(CARD(set_of_edge v V E)>1)==> i=0`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN 
ASM_REWRITE_TAC[w_dart_fan;wedge3_fan;if_azims_fan;power_map_points]
  THEN DISJ_CASES_TAC(ARITH_RULE` 0= CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)) \/ ~(0=CARD(set_of_edge v V E))`)
THENL[

REPEAT (POP_ASSUM MP_TAC) THEN ARITH_TAC;

MP_TAC(ARITH_RULE`~(CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))>1) /\ ~(0=CARD(set_of_edge v V E))==> SUC (0)=CARD(set_of_edge v V E)`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN 
ASM_REWRITE_TAC[complement_set;IN_ELIM_THM;AZIM_REFL;azim]

  THEN ASM_REWRITE_TAC[] THEN 
MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (u:real^3)`] ORBITS_EQ_SET_EDGE_FAN) 
  THEN ASM_REWRITE_TAC[] THEN 
MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (u:real^3)`] SIMP_ORBITS_POINTS_FAN) 
  THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN POP_ASSUM(fun th-> REWRITE_TAC[SYM(th)])THEN 
 POP_ASSUM(fun th-> REWRITE_TAC[SYM(th)]) THEN REWRITE_TAC[ARITH_RULE`(a:num) < SUC 0 <=> a=0`;SET_RULE`{f i| i=0}={f 0}`;
power_map_points] THEN DISCH_TAC THEN
MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (u:real^3)`;` (v:real^3)`] remark1_fan) 
  THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN
MP_TAC(ISPECL[`x:real^3`;`v:real^3`]lem1) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC
THEN ASM_REWRITE_TAC[lem] THEN POP_ASSUM (fun th-> REWRITE_TAC[]) 
  THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`]lem2) THEN POP_ASSUM (fun th-> REWRITE_TAC[th] THEN ASSUME_TAC(th))
THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`]aff_subset_aff_ge)
  THEN  POP_ASSUM (fun th-> REWRITE_TAC[th] THEN ASSUME_TAC(th)) THEN DISCH_TAC
  THEN DISCH_TAC THEN POP_ASSUM (fun th-> REWRITE_TAC[th;collinear_fan;]) THEN ASM_REWRITE_TAC[GSYM(DE_MORGAN_THM);]
  THEN ASM_SET_TAC[]]];

REWRITE_TAC[GSYM(EXTENSION)] THEN STRIP_TAC
THEN EXISTS_TAC`( power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3)
 (u:real^3) ((i):num)) ` THEN
MP_TAC(ISPECL[`i:num`;`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (u:real^3)`] remark_power_map_points) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN POP_ASSUM(fun th->REWRITE_TAC[th])
  THEN DISJ_CASES_TAC(ARITH_RULE`(CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)))>1 \/ ~((CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)))> 1)`)
THENL[
MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (u:real^3)`;`i:num`] w_dart_eq_wedge3_fan) 
  THEN ASM_REWRITE_TAC[power_map_points] THEN DISCH_TAC THEN POP_ASSUM(fun th->REWRITE_TAC[th]); 

MP_TAC(ARITH_RULE`(i:num)<CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)) /\ ~(CARD(set_of_edge v V E)>1)==> i=0`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN 
ASM_REWRITE_TAC[w_dart_fan;wedge3_fan;if_azims_fan;power_map_points]
  THEN DISJ_CASES_TAC(ARITH_RULE` 0= CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)) \/ ~(0=CARD(set_of_edge v V E))`)
THENL[
REPEAT (POP_ASSUM MP_TAC) THEN ARITH_TAC;

MP_TAC(ARITH_RULE`~(CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))>1) /\ ~(0=CARD(set_of_edge v V E))==> SUC (0)=CARD(set_of_edge v V E)`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN 
ASM_REWRITE_TAC[complement_set;IN_ELIM_THM;AZIM_REFL;azim]

  THEN ASM_REWRITE_TAC[] THEN 
MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (u:real^3)`] ORBITS_EQ_SET_EDGE_FAN) 
  THEN ASM_REWRITE_TAC[] THEN 
MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (u:real^3)`] SIMP_ORBITS_POINTS_FAN) 
  THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN POP_ASSUM(fun th-> REWRITE_TAC[SYM(th)])THEN 
 POP_ASSUM(fun th-> REWRITE_TAC[SYM(th)]) THEN REWRITE_TAC[ARITH_RULE`(a:num) < SUC 0 <=> a=0`;SET_RULE`{f i| i=0}={f 0}`;
power_map_points] THEN DISCH_TAC THEN
MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (u:real^3)`;` (v:real^3)`] remark1_fan) 
  THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN
MP_TAC(ISPECL[`x:real^3`;`v:real^3`]lem1) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC
THEN ASM_REWRITE_TAC[lem] THEN POP_ASSUM (fun th-> REWRITE_TAC[]) 
  THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`]lem2) THEN POP_ASSUM (fun th-> REWRITE_TAC[th] THEN ASSUME_TAC(th))
THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`]aff_subset_aff_ge)
  THEN  POP_ASSUM (fun th-> REWRITE_TAC[th] THEN ASSUME_TAC(th)) THEN DISCH_TAC
  THEN DISCH_TAC THEN POP_ASSUM (fun th-> REWRITE_TAC[th;collinear_fan;]) THEN ASM_REWRITE_TAC[GSYM(DE_MORGAN_THM);]
  THEN ASM_SET_TAC[]]]]))));;
let eq_set_aff_gt=
prove(`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3). FAN(x,V,E)/\ ({v,u}IN E) ==> {aff_gt {x,v} {w} |w| {v,w} IN E} ={wedge2_fan x V E v u i|i| 0 <= i /\ i< CARD(set_of_edge v V E) }`,
REPEAT STRIP_TAC THEN REWRITE_TAC[EXTENSION; IN_ELIM_THM] THEN GEN_TAC THEN EQ_TAC THENL[ REWRITE_TAC[GSYM(EXTENSION)] THEN STRIP_TAC THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (w:real^3)`] properties_of_set_of_edge_fan) THEN ASM_REWRITE_TAC[] THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (u:real^3)`] ORBITS_EQ_SET_EDGE_FAN) THEN ASM_REWRITE_TAC[] THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (u:real^3)`] SIMP_ORBITS_POINTS_FAN) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN POP_ASSUM(fun th-> REWRITE_TAC[SYM(th)])THEN DISCH_TAC THEN POP_ASSUM(fun th->GEN_REWRITE_TAC(LAND_CONV o RAND_CONV o ONCE_DEPTH_CONV)[th]) THEN REWRITE_TAC[IN_ELIM_THM;] THEN STRIP_TAC THEN EXISTS_TAC `i:num` THEN ASM_REWRITE_TAC[ARITH_RULE`0 <= i`] THEN MP_TAC(ARITH_RULE`(i:num) < CARD(set_of_edge v V E) ==> ~(i= CARD(set_of_edge (v:real^3) (V:real^3->bool)(E:(real^3->bool)->bool)))`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (u:real^3)`;`i:num`] wedge_fan2_equal_aff_gt_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN POP_ASSUM(fun th-> REWRITE_TAC[SYM(th)]); REWRITE_TAC[GSYM(EXTENSION)] THEN STRIP_TAC THEN EXISTS_TAC`( power_map_points sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3) ((i):num)) ` THEN MP_TAC(ISPECL[`i:num`;`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (u:real^3)`] remark_power_map_points) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN POP_ASSUM(fun th->REWRITE_TAC[th]) THEN MP_TAC(ARITH_RULE`(i:num) < CARD(set_of_edge v V E) ==> ~(i= CARD(set_of_edge (v:real^3) (V:real^3->bool)(E:(real^3->bool)->bool)))`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (u:real^3)`;`i:num`] wedge_fan2_equal_aff_gt_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN POP_ASSUM(fun th-> REWRITE_TAC[SYM(th)])]);;
let UNION1_FAN=
prove(`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3). FAN(x,V,E)/\ ({v,u}IN E) ==> (UNIV:real^3->bool) = aff {x,v} UNION (UNIONS {w_dart_fan x V E (x,v,w,(sigma_fan x V E v w))|w| {v,w} IN E }) UNION (UNIONS {aff_gt {x,v} {w} |w| {v,w} IN E} ) `,
REPEAT STRIP_TAC THEN MP_TAC (ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (u:real^3)`]UNION_FAN) THEN ASM_REWRITE_TAC[] THEN MP_TAC (ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (u:real^3)`]eq_set_wdart_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN POP_ASSUM (fun th -> REWRITE_TAC[th]) THEN MP_TAC (ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (u:real^3)`]eq_set_aff_gt ) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN POP_ASSUM (fun th -> REWRITE_TAC[th]) THEN ASM_SET_TAC[]);;
let CARD_SING=
prove(`!x:real^3 s:real^3->bool. FINITE s /\ s={x} ==> CARD s = 1`,
REPEAT STRIP_TAC THEN MP_TAC(SET_RULE`(s:real^3->bool)={(x:real^3)} ==> ~(s={}) /\ x IN s /\ s DELETE x ={}`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPEC`s:real^3->bool`CARD_EQ_0) THEN ASM_REWRITE_TAC[] THEN MP_TAC(ISPECL[`x:real^3`;`s:real^3->bool`]CARD_DELETE) THEN ASM_REWRITE_TAC[CARD_CLAUSES] THEN ARITH_TAC);;
let disjoint_set_fan=
prove(`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3) (w1:real^3). FAN(x,V,E)/\ ({v,w}IN E) /\ ({v,w1}IN E) ==> w_dart_fan x V E (x,v,w,(sigma_fan x V E v w)) INTER aff_gt {x,v} {w1}={}`,
(
let lem =prove(`!x:real^3.
 FINITE {x}
==>
CARD {x} = 1`,MESON_TAC[CARD_SING]) in
(let lem1=prove(`!x v. ~(x = v)==>(!u. ~(u IN aff {x, v}) <=> ~collinear {x, v, u})`,
MESON_TAC[collinear_fan]) in
(let lem2=prove(`!v0 v1 w.
        ~collinear{v0,v1,w}  ==>
!x. ( &0 = azim v0 v1 w x /\ ~collinear{v0,v1,x} <=> (x IN aff_ge {v0,v1} {w}) /\ ~collinear{v0,v1,x})`,
MESON_TAC[AZIM_EQ_0_GE_ALT]) in


REPEAT STRIP_TAC    THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (w1:real^3)`] properties_of_set_of_edge_fan) 
  THEN ASM_REWRITE_TAC[] THEN 
MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (w:real^3)`] ORBITS_EQ_SET_EDGE_FAN) 
  THEN ASM_REWRITE_TAC[] THEN 
MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (w:real^3)`] SIMP_ORBITS_POINTS_FAN) 
  THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN POP_ASSUM(fun th-> REWRITE_TAC[SYM(th)])THEN DISCH_TAC 
THEN POP_ASSUM(fun th->GEN_REWRITE_TAC(LAND_CONV o RAND_CONV o ONCE_DEPTH_CONV)[th])
  THEN REWRITE_TAC[IN_ELIM_THM;] THEN STRIP_TAC
  THEN ASM_REWRITE_TAC[] 
  THEN MP_TAC(ARITH_RULE`i< CARD(set_of_edge (v:real^3) V E)==> ~(i=CARD(set_of_edge v V E))`) THEN ASM_REWRITE_TAC[] 
  THEN DISCH_TAC
  THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (w:real^3)`;`i:num`] wedge_fan2_equal_aff_gt_fan)

  THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN POP_ASSUM(fun th-> REWRITE_TAC[SYM(th)])
  THEN DISJ_CASES_TAC(ARITH_RULE`(CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)))>1 \/ ~((CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)))> 1)`)
THENL(*1*)[
 MP_TAC(ARITH_RULE`CARD(set_of_edge (v:real^3) V E)>1==> 0< CARD(set_of_edge v V E)`) THEN ASM_REWRITE_TAC[] 
   THEN DISCH_TAC THEN
  MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (w:real^3)`;`0:num`] w_dart_eq_wedge3_fan) 
  THEN ASM_REWRITE_TAC[power_map_points] THEN DISCH_TAC THEN ASM_REWRITE_TAC[]
THEN REWRITE_TAC[wedge2_fan;wedge3_fan;EXTENSION] THEN GEN_TAC THEN 
REWRITE_TAC[INTER; EMPTY;IN_ELIM_THM]
   THEN DISJ_CASES_TAC(ARITH_RULE`(i:num)=0 \/ (0< i)`)
THENL(*2*)[
ASM_REWRITE_TAC[] THEN REAL_ARITH_TAC;(*2*)

 MP_TAC(ARITH_RULE`CARD(set_of_edge (v:real^3) V E)>1==> ~(0= CARD(set_of_edge v V E))/\  ~(SUC 0= CARD(set_of_edge v V E))`) THEN ASM_REWRITE_TAC[] 
   THEN DISCH_TAC THEN
ASM_REWRITE_TAC[if_azims_fan]
THEN
MP_TAC(ARITH_RULE` (0< i)==> SUC (0)= i \/ SUC 0 <i`) THEN ASM_REWRITE_TAC[] THEN STRIP_TAC
THENL(*3*)[
ASM_REWRITE_TAC[] THEN REAL_ARITH_TAC;(*3*)

DISJ_CASES_TAC(SET_RULE`set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)={w} \/ ~(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)={w})`)
THENL(*4*)[
 MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (w1:real^3)`;` (v:real^3)`]remark1_fan)
    THEN ASM_REWRITE_TAC[IN_SING] THEN DISCH_TAC THEN ASM_REWRITE_TAC[power_map_points] THEN REAL_ARITH_TAC;(*4*)

MP_TAC(ISPECL[`i:num`;`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (w:real^3)`;`SUC (0):num`]  AZIM_LE_POWER_SIGMA_FAN) 
  THEN ASM_REWRITE_TAC[] THEN REAL_ARITH_TAC](*4*)](*3*)](*2*);(*1*)


 MP_TAC(ARITH_RULE`~(CARD(set_of_edge (v:real^3) V E)>1) /\ (i< CARD(set_of_edge v V E))==> i=0/\ ~(0=CARD(set_of_edge (v:real^3) V E))`) THEN ASM_REWRITE_TAC[] 
 THEN STRIP_TAC THEN ASM_REWRITE_TAC[] 
THEN ASM_REWRITE_TAC[wedge2_fan;w_dart_fan;if_azims_fan;power_map_points;complement_set;AZIM_REFL;EXTENSION] THEN GEN_TAC THEN 
REWRITE_TAC[DIFF;INTER;IN_ELIM_THM;GSYM(EXTENSION);COND_ELIM_THM] 
 THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (w:real^3)`;` (v:real^3)`] remark1_fan)
  THEN ASM_REWRITE_TAC[] THEN DISCH_TAC
  THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;]lem1) THEN ASM_REWRITE_TAC[]
  THEN DISCH_TAC THEN POP_ASSUM (fun th-> REWRITE_TAC[th])

  THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`w:real^3`]lem2) THEN ASM_REWRITE_TAC[] 
THEN DISCH_TAC THEN POP_ASSUM (fun th-> REWRITE_TAC[th] ) THEN ASM_REWRITE_TAC[collinear_fan]
THEN
DISJ_CASES_TAC(SET_RULE`set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)={w} \/ ~(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)={w})`)


THENL(*2*)[
ASM_SET_TAC[];(*2*)

MP_TAC(ARITH_RULE`~(CARD(set_of_edge (v:real^3) V E)>1) /\ ~(0= CARD(set_of_edge v V E))==> (1=CARD(set_of_edge (v:real^3) V E))`) THEN ASM_REWRITE_TAC[] 
     THEN DISCH_TAC 
  THEN MP_TAC(SET_RULE`w IN set_of_edge (v:real^3) V E==> {w} SUBSET set_of_edge (v:real^3) V E`) THEN ASM_REWRITE_TAC[]
  THEN DISCH_TAC
  THEN MP_TAC(ISPECL[`{(w:real^3)}`;`set_of_edge (v:real^3) V E`] FINITE_SUBSET) THEN ASM_REWRITE_TAC[] 
 THEN DISCH_TAC THEN
MP_TAC(ISPEC`w:real^3`lem) THEN ASM_REWRITE_TAC[]
  THEN DISCH_TAC
  THEN MP_TAC(ISPECL[`{(w:real^3)}`;`set_of_edge (v:real^3) V E`]CARD_SUBSET_EQ)
  THEN ASM_REWRITE_TAC[]]]))));;
let disjiont1_cor6dot1 = 
prove(`!x:real^3 (V:real^3->bool) (E:(real^3->bool)->bool) v:real^3 u:real^3 i:num. wedge3_fan x V E v u i INTER aff {x,v}={}`,
REPEAT GEN_TAC THEN REWRITE_TAC[wedge3_fan; INTER] THEN REWRITE_TAC[complement_set; FUN_EQ_THM; EMPTY] THEN GEN_TAC THEN REWRITE_TAC[IN_ELIM_THM] THEN STRIP_TAC THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN MESON_TAC[]);;
let disjoint_fan1=
prove(`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3). FAN(x,V,E)/\ ({v,w}IN E) ==> w_dart_fan x V E (x,v,w,(sigma_fan x V E v w)) INTER aff {x,v}={}`,
REPEAT STRIP_TAC THEN DISJ_CASES_TAC(ARITH_RULE`(CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)))>1 \/ ~((CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)))> 1)`) THENL[ MP_TAC(ARITH_RULE`CARD(set_of_edge (v:real^3) V E)>1==> (0<CARD(set_of_edge v V E))`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (w:real^3)`;`0:num`] w_dart_eq_wedge3_fan) THEN ASM_REWRITE_TAC[power_map_points;] THEN DISCH_TAC THEN ASM_REWRITE_TAC[disjiont1_cor6dot1]; MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (w:real^3)`;` (v:real^3)`] remark1_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN ASM_REWRITE_TAC[w_dart_fan;INTER; IN_ELIM_THM;COND_ELIM_THM] THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`w:real^3`]aff_subset_aff_ge) THEN ASM_REWRITE_TAC[] THEN ASM_SET_TAC[]]);;
let disjoint_fan2=
prove(`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3) (w1:real^3). FAN(x,V,E)/\ ({v,w}IN E) /\ ({v,w1}IN E) /\ ~(w=w1) ==> w_dart_fan x V E (x,v,w,(sigma_fan x V E v w)) INTER w_dart_fan x V E (x,v,w1,(sigma_fan x V E v w1))={}`,
REPEAT STRIP_TAC THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (w1:real^3)`] properties_of_set_of_edge_fan) THEN ASM_REWRITE_TAC[] THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (w:real^3)`] ORBITS_EQ_SET_EDGE_FAN) THEN ASM_REWRITE_TAC[] THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (w:real^3)`] SIMP_ORBITS_POINTS_FAN) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN POP_ASSUM(fun th-> REWRITE_TAC[SYM(th)])THEN DISCH_TAC THEN POP_ASSUM(fun th->GEN_REWRITE_TAC(LAND_CONV o RAND_CONV o ONCE_DEPTH_CONV)[th]) THEN REWRITE_TAC[IN_ELIM_THM;] THEN STRIP_TAC THEN ASM_REWRITE_TAC[] THEN DISJ_CASES_TAC(ARITH_RULE`(CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)))>1 \/ ~((CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)))> 1)`) THENL(*1*)[ MP_TAC(ARITH_RULE`CARD(set_of_edge (v:real^3) V E)>1==> 0< CARD(set_of_edge v V E)`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (w:real^3)`;`0:num`] w_dart_eq_wedge3_fan) THEN ASM_REWRITE_TAC[power_map_points] THEN DISCH_TAC THEN ASM_REWRITE_TAC[] THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (w:real^3)`;`i:num`] w_dart_eq_wedge3_fan) THEN ASM_REWRITE_TAC[power_map_points] THEN DISCH_TAC THEN ASM_REWRITE_TAC[wedge3_fan;INTER] THEN POP_ASSUM(fun th -> REWRITE_TAC[]) THEN POP_ASSUM(fun th -> REWRITE_TAC[]) THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN DISJ_CASES_TAC(ARITH_RULE`i:num =0 \/ SUC(0) <= i`) THENL(*2*)[ ASM_REWRITE_TAC[power_map_points];(*2*) DISCH_TAC THEN DISCH_TAC THEN DISCH_TAC THEN ASM_REWRITE_TAC[if_azims_fan] THEN MP_TAC(ARITH_RULE`CARD(set_of_edge (v:real^3) V E)>1==> ~(SUC 0= CARD(set_of_edge v V E))`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ARITH_RULE`i<CARD(set_of_edge (v:real^3) V E)==> ~(i= CARD(set_of_edge v V E))`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN ASM_REWRITE_TAC[IN_ELIM_THM] THEN MP_TAC(ARITH_RULE`SUC 0<= i ==> i:num = SUC 0 \/ SUC(0) < i`) THEN ASM_REWRITE_TAC[] THEN STRIP_TAC THENL(*3*)[ ASM_REWRITE_TAC[EMPTY;EXTENSION;IN_ELIM_THM] THEN GEN_TAC THEN REAL_ARITH_TAC;(*3*) MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (w:real^3)`;` (v:real^3)`] remark1_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN DISJ_CASES_TAC(SET_RULE`set_of_edge (v:real^3) V E ={w} \/ ~(set_of_edge (v:real^3) V E ={w})`) THENL(*4*)[ MP_TAC(ISPECL[`w:real^3`;`set_of_edge (v:real^3) V E`]CARD_SING) THEN ASM_REWRITE_TAC[] THEN POP_ASSUM(fun th->REWRITE_TAC[SYM(th)]) THEN REPEAT(POP_ASSUM MP_TAC) THEN ARITH_TAC;(*4*) MP_TAC(ISPECL[`i:num`;`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (w:real^3)`;`SUC (0):num`] AZIM_LE_POWER_SIGMA_FAN) THEN ASM_REWRITE_TAC[] THEN ASM_REWRITE_TAC[EMPTY;EXTENSION;IN_ELIM_THM] THEN REAL_ARITH_TAC]]]; POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN DISCH_THEN(LABEL_TAC"a") THEN DISCH_TAC THEN MP_TAC(ARITH_RULE`~(CARD(set_of_edge (v:real^3) V E)>1) /\ (i < CARD(set_of_edge v V E)) ==> (i:num =0)`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN REMOVE_THEN "a" MP_TAC THEN ASM_REWRITE_TAC[power_map_points]]);;
let disjoint_fan3=
prove(`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3). FAN(x,V,E)/\ ({v,w}IN E) ==>aff{x,v} INTER aff_gt {x,v} {w}={}`,
REPEAT STRIP_TAC THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (w:real^3)`;` (v:real^3)`] remark1_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN DISJ_CASES_TAC(SET_RULE`aff{(x:real^3),(v:real^3)} INTER aff_gt {x,v} {(w:real^3)}={} \/ (?(u:real^3). u IN aff{x,v} INTER aff_gt {x,v} {w})`) THENL[ ASM_SET_TAC[]; POP_ASSUM MP_TAC THEN STRIP_TAC THEN POP_ASSUM MP_TAC THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`w:real^3`]AFF_GT_2_1) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`]affine_hull_2_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_THEN(LABEL_TAC"a") THEN ASM_REWRITE_TAC[INTER;IN_ELIM_THM;] THEN STRIP_TAC THEN POP_ASSUM MP_TAC THEN ASM_REWRITE_TAC[VECTOR_ARITH`t1 % x + t2 % v = t1' % x + t2' % v + t3 % w <=> t3 % w = (t1 - t1') % x + (t2 -t2') % v`] THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN POP_ASSUM (fun th-> REWRITE_TAC[]) THEN POP_ASSUM (fun th -> REWRITE_TAC[SYM(th);REAL_ARITH`a+b+c=d+e <=> c = (d-a)+ (e-b)`]) THEN DISCH_TAC THEN MP_TAC(REAL_ARITH`&0 < (t3:real) ==> ~(t3= &0)`) THEN ASM_REWRITE_TAC[]THEN DISCH_TAC THEN MP_TAC(ISPEC`t3:real`REAL_MUL_LINV) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN DISCH_TAC THEN MP_TAC(SET_RULE` (t3:real) = (t1- t1') + (t2-t2') ==> (inv t3) *(t3:real) = (inv t3) * ((t1- t1')+ (t2-t2'))`) THEN ASM_REWRITE_TAC[REAL_ARITH`a*(b+c)= a *b + a*c`] THEN POP_ASSUM (fun th-> REWRITE_TAC[SYM(th)]) THEN DISCH_TAC THEN DISCH_TAC THEN MP_TAC(SET_RULE` (t3:real) % w= (t1- t1') % (x:real^3) + (t2-t2') % v ==> (inv t3) % ((t3:real)% w) = (inv t3) % ((t1- t1') %x+ (t2-t2') % v)`) THEN ASM_REWRITE_TAC[VECTOR_ARITH`m% (n% p)=a%(b % x + c % v)<=> (m*n) %p = (a *b)%x + (a*c)% v`] THEN POP_ASSUM (fun th-> REWRITE_TAC[SYM(th)]) THEN POP_ASSUM(fun th->REWRITE_TAC[SYM(th)] THEN ASSUME_TAC(SYM(th))) THEN REWRITE_TAC[VECTOR_ARITH`&1 %w=w`] THEN DISCH_TAC THEN SUBGOAL_THEN`w IN aff{(x:real^3),v}` ASSUME_TAC THENL[ REMOVE_THEN"a"(fun th-> REWRITE_TAC[th;IN_ELIM_THM]) THEN EXISTS_TAC`inv t3 * (t1-t1')` THEN EXISTS_TAC`inv t3 * (t2-t2')` THEN POP_ASSUM(fun th-> REWRITE_TAC[th]) THEN POP_ASSUM(fun th-> REWRITE_TAC[th]); ASM_SET_TAC[]]]);;
let remark3_fan=
prove(`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3) (w1:real^3). FAN(x,V,E)/\ ({v,w}IN E) /\ ({v,w1}IN E) /\ ~(w=w1) ==> aff_gt{x,v} {w} INTER aff_gt {x,v} {w1}={}`,
REPEAT STRIP_TAC THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (w1:real^3)`] properties_of_set_of_edge_fan) THEN ASM_REWRITE_TAC[] THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (w:real^3)`] ORBITS_EQ_SET_EDGE_FAN) THEN ASM_REWRITE_TAC[] THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (w:real^3)`] SIMP_ORBITS_POINTS_FAN) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN POP_ASSUM(fun th-> REWRITE_TAC[SYM(th)])THEN DISCH_TAC THEN POP_ASSUM(fun th->GEN_REWRITE_TAC(LAND_CONV o RAND_CONV o ONCE_DEPTH_CONV)[th]) THEN REWRITE_TAC[IN_ELIM_THM;] THEN STRIP_TAC THEN ASM_REWRITE_TAC[] THEN POP_ASSUM MP_TAC THEN DISJ_CASES_TAC(ARITH_RULE`i:num =0 \/ 0 < i`) THENL[ ASM_REWRITE_TAC[power_map_points]; MP_TAC(ARITH_RULE`i<CARD(set_of_edge (v:real^3) V E)/\ (0<i)==> ~(i= CARD(set_of_edge v V E)) /\ ~(0=CARD(set_of_edge (v:real^3) V E))`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (w:real^3)`;`i:num`] wedge_fan2_equal_aff_gt_fan) THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (w:real^3)`;`0:num`] wedge_fan2_equal_aff_gt_fan) THEN ASM_REWRITE_TAC[power_map_points] THEN DISCH_TAC THEN DISCH_TAC THEN POP_ASSUM(fun th->REWRITE_TAC[SYM(th)]) THEN POP_ASSUM(fun th->REWRITE_TAC[SYM(th)]) THEN ASM_REWRITE_TAC[wedge2_fan;if_azims_fan;power_map_points;INTER;IN_ELIM_THM;AZIM_REFL;] THEN DISCH_TAC THEN POP_ASSUM(fun th->REWRITE_TAC[SYM(th)]) THEN DISJ_CASES_TAC(REAL_ARITH`azim x v w w1 = &0 \/ ~(azim x v w w1 = &0)`) THENL[ MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (w:real^3)`;`w1:real^3`] UNIQUE_AZIM_0_POINT_FAN) THEN ASM_REWRITE_TAC[]; ASM_REWRITE_TAC[EMPTY;EXTENSION;IN_ELIM_THM] THEN POP_ASSUM MP_TAC THEN REAL_ARITH_TAC]]);;
(* (!x:real^3 (V:real^3->bool) (E:(real^3->bool)->bool) v:real^3 w:real^3 w1:real^3. a IN a_node_fan x V E (x,v,w,w1)==>(?n. a=(x,v,(power_map_points sigma_fan x V E v w n),(power_map_points sigma_fan x V E v w (SUC n))))) /\ *)
let VBTIKLP=
prove(`(!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3). FAN(x,V,E)/\ ({v,u}IN E) ==> (UNIV:real^3->bool) = aff {x,v} UNION (UNIONS {w_dart_fan x V E (x,v,w,(sigma_fan x V E v w))|w| {v,w} IN E }) UNION (UNIONS {aff_gt {x,v} {w} |w| {v,w} IN E} )) /\ (!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3). FAN(x,V,E)/\ ({v,w}IN E) ==> w_dart_fan x V E (x,v,w,(sigma_fan x V E v w)) INTER aff {x,v}={}) /\ (!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3) (w1:real^3). FAN(x,V,E)/\ ({v,w}IN E) /\ ({v,w1}IN E) ==> w_dart_fan x V E (x,v,w,(sigma_fan x V E v w)) INTER (aff_gt {x,v} {w1})={}) /\ (!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3) (w1:real^3). FAN(x,V,E)/\ ({v,w}IN E) /\ ({v,w1}IN E) /\ ~(w=w1) ==> w_dart_fan x V E (x,v,w,(sigma_fan x V E v w)) INTER w_dart_fan x V E (x,v,w1,(sigma_fan x V E v w1))={}) /\ (!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3) (w1:real^3). FAN(x,V,E)/\ ({v,w}IN E) /\ ({v,w1}IN E) /\ ~(w=w1) ==> aff_gt{x,v} {w} INTER aff_gt {x,v} {w1}={}) /\ (!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3). FAN(x,V,E)/\ ({v,w}IN E) ==>aff{x,v} INTER aff_gt {x,v} {w}={}) `,
(*lemma62*) (*******************[cor:W]*************************)
let disjiont_union_fan=
prove(`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3) (w1:real^3). FAN(x,V,E)/\ ({v,w}IN E) /\ ({v,w1}IN E) ==> w_dart_fan x V E (x,v,w,(sigma_fan x V E v w)) INTER (aff{x,v} UNION aff_gt {x,v} {w1})={}`,
REPEAT STRIP_TAC THEN REWRITE_TAC[UNION_OVER_INTER] THEN MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (w:real^3)`;` (w1:real^3)`] disjoint_set_fan) THEN ASM_REWRITE_TAC[] THEN MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (w:real^3)`;] disjoint_fan1) THEN ASM_REWRITE_TAC[] THEN ASM_SET_TAC[]);;
let aff_ge_subset_aff_gt_union_aff=
prove(`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3). FAN(x,V,E)/\ {v,w} IN E ==> aff_ge {x} {v , w} SUBSET (aff_gt {x , v} {w}) UNION (aff {x, v})`,
REPEAT STRIP_TAC THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (w:real^3)`;` (v:real^3)`] remark1_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`w:real^3`]AFF_GE_1_2) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`w:real^3`]AFF_GT_2_1) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`]affine_hull_2_fan) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN ASM_REWRITE_TAC[SUBSET; UNION;IN_ELIM_THM] THEN GEN_TAC THEN REWRITE_TAC[REAL_ARITH `(&0 <= (t3:real)) <=> (&0 < t3) \/ ( t3 = &0)`; TAUT `(a \/ b) /\ (c \/ d) /\ e /\ f <=> ((a \/ b)/\ c /\ e /\ f) \/ ((a \/ b) /\ d /\ e /\ f)`; EXISTS_OR_THM] THEN MATCH_MP_TAC MONO_OR THEN SUBGOAL_THEN `((?t1:real t2:real t3:real. (&0 < t2 \/ t2 = &0) /\ &0< t3 /\ t1 + t2 + t3 = &1 /\ (x':real^3) = t1 % x + t2 % v + t3 % w) ==> (?t1 t2 t3. &0< t3 /\ t1 + t2 + t3 = &1 /\ x' = t1 % x + t2 % v + t3 % w))` ASSUME_TAC THENL [MESON_TAC[]; ASM_REWRITE_TAC[] THEN MATCH_MP_TAC MONO_EXISTS THEN GEN_TAC THEN MATCH_MP_TAC MONO_EXISTS THEN GEN_TAC THEN REWRITE_TAC[LEFT_IMP_EXISTS_THM] THEN GEN_TAC THEN REWRITE_TAC[REAL_ARITH `(&0< (t2:real) \/ (t2 = &0)) <=> ( &0<= t2)`] THEN STRIP_TAC THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN ASM_REWRITE_TAC[] THEN REWRITE_TAC [REAL_ARITH `(a:real)+ &0 = a`; VECTOR_ARITH `&0 % (w:real^3) = vec 0`; VECTOR_ARITH ` ((x':real^3) = (t1:real) % (x:real^3) + (t2:real) % (v:real^3) + vec 0)<=> ( x' = t1 % x + t2 % v )` ] THEN MESON_TAC[]]);;
let IBZWFFH=
prove(`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3) (w1:real^3). FAN(x,V,E)/\ ({v,w}IN E) /\ ({v,w1}IN E) ==> w_dart_fan x V E (x,v,w,(sigma_fan x V E v w)) INTER aff_ge {x} {v , w1}={}`,
REPEAT STRIP_TAC THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;` (w1:real^3)`] aff_ge_subset_aff_gt_union_aff) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (v:real^3)`;`w:real^3`;` (w1:real^3)`] disjiont_union_fan) THEN ASM_REWRITE_TAC[] THEN ASM_SET_TAC[]);;
(*---------------------------------------------------------------------------------*) (* aff_ge {x} {v , w}) = (aff_ge {x , v} {w}) INTER (aff_ge {x , w} {v}) *) (*---------------------------------------------------------------------------------*)
let aff_ge_inter_aff_ge=
prove(`!(x:real^3) (v:real^3) (w:real^3). ~collinear {x,v,w} ==> aff_ge {x} {v , w} = aff_ge {x , v} {w} INTER aff_ge {x , w} {v}`,
REPEAT STRIP_TAC THEN MRESA_TAC th3 [`x:real^3`;`v:real^3`;`w:real^3`] THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`w:real^3`]AFF_GE_1_2) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`w:real^3`]AFF_GE_2_1) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`x:real^3`;`w:real^3`;`v:real^3`]AFF_GE_2_1) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN ASM_REWRITE_TAC[INTER;IN_ELIM_THM;EXTENSION]THEN GEN_TAC THEN EQ_TAC THENL(*1*)[ STRIP_TAC THEN STRIP_TAC THENL(*2*)[ EXISTS_TAC `t1:real` THEN EXISTS_TAC `t2:real` THEN EXISTS_TAC `t3:real` THEN ASM_MESON_TAC[]; EXISTS_TAC `(t1:real)` THEN EXISTS_TAC `(t3:real)` THEN EXISTS_TAC `(t2:real)` THEN ASM_MESON_TAC[REAL_ARITH `(t1:real)+ (t3:real) +(t2:real)=t1 + t2 + t3`;VECTOR_ARITH ` t1 % x + t2 % v + t3 % w = (t1:real) % (x:real^3) + (t3:real) % (w:real^3) + (t2:real) % (v:real^3)`]](*2*); STRIP_TAC THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN POP_ASSUM(fun th-> GEN_REWRITE_TAC(PATH_CONV "rrlr" o ONCE_DEPTH_CONV )[th] THEN ASSUME_TAC(th)) THEN POP_ASSUM MP_TAC THEN POP_ASSUM(fun th-> GEN_REWRITE_TAC(PATH_CONV "rrlr" o ONCE_DEPTH_CONV )[SYM(th)] THEN ASSUME_TAC(th)) THEN DISJ_CASES_TAC(SET_RULE`t3 - t2' = &0 \/ ~((t3:real) - (t2':real) = &0) `) THENL[POP_ASSUM MP_TAC THEN REWRITE_TAC[REAL_ARITH`A-B= &0 <=> A=B`] THEN REPEAT STRIP_TAC THEN EXISTS_TAC`t1':real` THEN EXISTS_TAC`t3':real` THEN EXISTS_TAC`t2':real` THEN ASM_REWRITE_TAC[VECTOR_ARITH`t1' % x + t2' % w + t3' % v = t1' % x + t3' % v + t2' % w`; REAL_ARITH`t1' + t3' + t2'=t1' + t2' + t3'`] THEN ASM_TAC THEN REAL_ARITH_TAC; REWRITE_TAC[VECTOR_ARITH `a % x + b % y + c % z= a1 % x + b1 % z + c1 % y <=> (c-b1) % z = (a1-a) % x + (c1-b)% y`] THEN REWRITE_TAC[REAL_ARITH`a+b+c=a1+b1+c1<=> c1-b=(a-a1)+(c-b1)`] THEN MRESA1_TAC REAL_MUL_LINV`t3 - t2'` THEN DISCH_TAC THEN DISCH_TAC THEN DISCH_TAC THEN DISCH_TAC THEN MP_TAC(SET_RULE` (t3 - t2') % w = (t1' - t1) % x + (t3' - t2) % v:real^3 ==> (inv (t3 - t2'))%((t3 - t2') % w ) = (inv (t3 - t2'))%((t1' - t1) % x + (t3' - t2) % v:real^3)`) THEN POP_ASSUM (fun th->GEN_REWRITE_TAC(LAND_CONV o LAND_CONV o ONCE_DEPTH_CONV)[th]) THEN POP_ASSUM(fun th-> ASM_REWRITE_TAC[VECTOR_ARITH`A%B%C= (A*B)%C`;VECTOR_ARITH`&1 %A=A`;VECTOR_ARITH`A%(B+C)=A%B+A%C`] THEN ASSUME_TAC(SYM(th))) THEN STRIP_TAC THEN SUBGOAL_THEN`w IN aff{(x:real^3),v}` ASSUME_TAC THENL[REWRITE_TAC[aff;AFFINE_HULL_2;IN_ELIM_THM;] THEN EXISTS_TAC`inv(t3-t2') *(t1'-t1)` THEN EXISTS_TAC`inv(t3-t2') *(t3'-t2)` THEN ASM_REWRITE_TAC[REAL_ARITH`A*B+A*C=A*(B+C)`]; ASM_SET_TAC[]]]]);;
(*************JGIYDLE*******************) (* rcone^0(x,v,h) *)
let rcone_fan = new_definition `rcone_fan  (x:real^3) (v:real^3) (h:real) = {y:real^3 | (y-x) dot (v-x) >(dist(y,x)*dist(v,x)*h)}`;;
(*---------------------------------------------------------------------------------*) (* aff_ge {x} {v , w} is closed *) (*---------------------------------------------------------------------------------*)
let exp_aff_ge_by_dot=
prove(`!x:real^3 v:real^3 u:real^3. ~collinear {x,v,u} ==> aff_ge {x,v} {u}={w:real^3| (w-x) dot (e2_fan x v u)= &0 /\ &0 <= (w-x) dot (e1_fan x v u) }`,
(
let CROSS_LAGRANGE1 = prove
 (`!x y z. (x cross y) cross z = (x dot z) % y - (z dot y) % x`,
  VEC3_TAC) in

REPEAT STRIP_TAC THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`]th3) THEN RES_TAC
  THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`]AFF_GE_2_1) THEN RESA_TAC
  THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`]properties_coordinate) THEN RESA_TAC
  THEN REWRITE_TAC[EXTENSION;IN_ELIM_THM] THEN GEN_TAC THEN EQ_TAC
THENL[
STRIP_TAC THEN ASM_REWRITE_TAC[VECTOR_ARITH`(a % x + b +c) -x= (a- &1)% x + b + c `] THEN 
REMOVE_ASSUM_TAC THEN SYM_ASSUM_TAC THEN REWRITE_TAC[VECTOR_ARITH`((a-(a+b+c)) % x + b % v +c % u)=  b % (v-x) + c % (u-x)`] 
THEN ASM_REWRITE_TAC[DOT_LADD;DOT_LMUL]
   THEN REDUCE_ARITH_TAC
  THEN ASM_MESON_TAC[REAL_LE_MUL] ; 

STRIP_TAC THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN DISCH_THEN(LABEL_TAC"a")
  THEN DISCH_THEN(LABEL_TAC"b")
THEN MP_TAC(ISPECL[`e1_fan (x:real^3) (v:real^3) (u:real^3)`;`e2_fan (x:real^3)( v:real^3) (u:real^3)`;
`e3_fan (x:real^3) (v:real^3) (u:real^3)`;]ORTHONORMAL_IMP_SPANNING) THEN ASM_REWRITE_TAC[SPAN_3;EXTENSION] 
  THEN DISCH_TAC THEN POP_ASSUM(fun th-> MP_TAC(ISPEC`(x':real^3)-(x:real^3)`th)) THEN REWRITE_TAC[SET_RULE`(a:real^3) IN (:real^3)`;IN_ELIM_THM] THEN RES_TAC THEN REMOVE_THEN "a" MP_TAC THEN ASM_REWRITE_TAC[DOT_LADD;DOT_LMUL]
  THEN POP_ASSUM MP_TAC THEN DISCH_THEN(LABEL_TAC"c")
  THEN FIND_ASSUM(MP_TAC)`orthonormal (e1_fan (x:real^3) (v:real^3) (u:real^3)) (e2_fan x v u) (e3_fan x v u)`
  THEN REWRITE_TAC[orthonormal] THEN STRIP_TAC THEN ASM_REWRITE_TAC[]  THEN ASM_REWRITE_TAC[DOT_SYM]
  THEN REDUCE_ARITH_TAC
  THEN DISCH_TAC THEN REMOVE_THEN "c" MP_TAC THEN ASM_REWRITE_TAC[] THEN REDUCE_VECTOR_TAC THEN DISCH_THEN (LABEL_TAC"a")
  THEN REMOVE_THEN "b" MP_TAC THEN ASM_REWRITE_TAC[DOT_LADD;DOT_LMUL;] THEN REWRITE_TAC[DOT_SYM] THEN ASM_REWRITE_TAC[]
  THEN REDUCE_ARITH_TAC
  THEN DISCH_TAC THEN REMOVE_THEN "a" MP_TAC
  THEN ASM_REWRITE_TAC[e1_fan;e2_fan;CROSS_LMUL;VECTOR_ARITH`a% b% v=(a*b)%v`;CROSS_LAGRANGE1] 
  THEN REDUCE_VECTOR_TAC THEN REWRITE_TAC[VECTOR_ARITH`a%(x- b % v)+ c % v=(c- a* b) % v+  a % x `;
e3_fan;VECTOR_ARITH`a% b% v=(a*b)%v`]
  THEN STRIP_TAC THEN
EXISTS_TAC
`&1 - ((((w:real) -
   ((u':real) * inv (norm (inv (norm ((v:real^3) - (x:real^3))) % (v - x) cross ((u:real^3) - x)))) *
   (inv (norm (v - x)) % (v - x) dot (u - x))) *
  inv (norm (v - x)))+
((u':real) * inv (norm (e3_fan (x:real^3) (v:real^3) (u:real^3) cross (u - x)))))`
  THEN EXISTS_TAC
`(((w:real) -
   ((u':real) * inv (norm (inv (norm ((v:real^3) - (x:real^3))) % (v - x) cross ((u:real^3) - x)))) *
   (inv (norm (v - x)) % (v - x) dot (u - x))) *
  inv (norm (v - x)))`
  THEN EXISTS_TAC
` ((u':real) * inv (norm (e3_fan (x:real^3) (v:real^3) (u:real^3) cross (u - x))))`
THEN
STRIP_TAC
THENL[

SUBGOAL_THEN `~(collinear {vec 0, v-x, u-x})==> ~((e3_fan (x:real^3) (v:real^3) (u:real^3)) cross ((u:real^3)-(x:real^3))= vec 0)` ASSUME_TAC
THENL[
 MATCH_MP_TAC MONO_NOT THEN REWRITE_TAC[e3_fan;CROSS_LMUL] 
THEN DISCH_TAC THEN MP_TAC(ISPECL [`v:real^3`; `x:real^3`] imp_inv_norm_not_zero_fan) 
THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN 
MP_TAC(ISPECL [`inv(norm((v:real^3)-(x:real^3)))`; `((v:real^3) -(x:real^3)) cross ((u:real^3)-(x:real^3))`; `(vec 0):real^3`] VECTOR_MUL_LCANCEL_IMP) 
THEN ASM_REWRITE_TAC[VECTOR_MUL_RZERO;CROSS_EQ_0 ];

POP_ASSUM MP_TAC THEN REWRITE_TAC[GSYM COLLINEAR_3] 
THEN GEN_REWRITE_TAC(LAND_CONV o LAND_CONV o RAND_CONV o ONCE_DEPTH_CONV)[SET_RULE`{a,b,c}={b,a,c}`] THEN RED_TAC
THEN
MP_TAC(ISPECL [`(e3_fan (x:real^3) (v:real^3) (u:real^3)) cross ((u:real^3)-(x:real^3))`; `((vec 0):real^3)`] imp_norm_ge_zero_fan)
  THEN REDUCE_VECTOR_TAC THEN RES_TAC THEN 
MP_TAC(ISPECL[`u':real`;`inv (norm ((e3_fan (x:real^3) (v:real^3) (u:real^3)) cross ((u:real^3)-(x:real^3))))`] 
REAL_LE_MUL) THEN RES_TAC THEN POP_ASSUM MATCH_MP_TAC THEN POP_ASSUM MP_TAC
 THEN REAL_ARITH_TAC];

STRIP_TAC THENL[REAL_ARITH_TAC;
REWRITE_TAC[e3_fan] THEN POP_ASSUM MP_TAC THEN VECTOR_ARITH_TAC]]]));;
let closed_aff_ge_2_1=
prove(`!x:real^3 v:real^3 u:real^3. ~collinear {x,v,u} ==> closed (aff_ge {x,v} {u})`,
(
let lemma=prove(`!x:real^3 v:real^3 u:real^3.
{w:real^3| (w-x) dot (e2_fan x v u)= &0 /\ &0 <= (w-x) dot (e1_fan x v u)  }
={w:real^3| (w-x) dot (e2_fan x v u)= &0} INTER {w:real^3| (w-x) dot (e1_fan x v u) >= &0 }`,
REWRITE_TAC[INTER; IN_ELIM_THM;REAL_ARITH`&0<=a <=> a >= &0`]) in
(
let lemma1=prove(`!x:real^3 v:real^3 u:real^3.
closed {w:real^3| (w-x) dot (e2_fan x v u)= &0}`,
REWRITE_TAC[ DOT_SYM] THEN REWRITE_TAC[DOT_RSUB;REAL_ARITH`a-b= &0<=> a=b`;] 
 THEN REPEAT GEN_TAC THEN MP_TAC(ISPECL[`e2_fan (x:real^3) (v:real^3) (u:real^3)`;
` e2_fan (x:real^3) (v:real^3) (u:real^3) dot x`]CLOSED_HYPERPLANE) THEN ASM_SET_TAC[]) in
 (
let lemma2=prove(`!x:real^3 v:real^3 u:real^3.
closed {w:real^3| (w-x) dot (e1_fan x v u) >= &0 }`,
REWRITE_TAC[ DOT_SYM] THEN REWRITE_TAC[DOT_RSUB;REAL_ARITH`a-b>= &0<=> a>=b`;] 
 THEN REPEAT GEN_TAC THEN MP_TAC(ISPECL[`e1_fan (x:real^3) (v:real^3) (u:real^3)`;
` e1_fan (x:real^3) (v:real^3) (u:real^3) dot x`]CLOSED_HALFSPACE_GE) THEN ASM_SET_TAC[]) in

REPEAT STRIP_TAC THEN
ASM_MESON_TAC[exp_aff_ge_by_dot;lemma;lemma1;lemma2;CLOSED_INTER]))));;
let closed_aff_ge_1_2=
prove(`!(x:real^3) (v:real^3) (w:real^3). ~collinear {x, v, w} ==> closed (aff_ge {x} {v , w})`,
REPEAT STRIP_TAC THEN POP_ASSUM (fun th-> MP_TAC (th) THEN ONCE_REWRITE_TAC[SET_RULE`{A,B,C}={A,C,B}`] THEN ASSUME_TAC(th)) THEN MRESA_TAC aff_ge_inter_aff_ge[`x:real^3`;`v:real^3`;`w:real^3`] THEN MRESA_TAC closed_aff_ge_2_1[`x:real^3`;`w:real^3`;`v:real^3`] THEN MRESA_TAC closed_aff_ge_2_1[`x:real^3`;`v:real^3`;`w:real^3`] THEN ASM_MESON_TAC[CLOSED_INTER]);;
(*--------------------------------------------------------------------------------------------*) (* closed_halfline_fan closed aff_ge {x} {v} *) (*--------------------------------------------------------------------------------------------*)
let AFF_GE_1_1=
prove(`!x:real^3 v:real^3. ~(x=v) ==> aff_ge {x} {v} = {y:real^3 | ?t1:real t2:real. (&0 <= t2 ) /\ (t1 + t2 = &1) /\ (y = t1 % x + t2 % v )}`,
(
let lemma=prove(`!x v.  ~(x=v) <=> DISJOINT {x} {v} `,

REWRITE_TAC[DISJOINT; INTER; IN_SING; EXTENSION; EMPTY; IN_ELIM_THM] THEN ASM_SET_TAC[]) in

REWRITE_TAC[lemma] THEN AFF_TAC));;
let exp_aff_ge_by_dot_1_1=
prove(`!x:real^3 v:real^3 u:real^3. ~collinear {x,v,u} ==> aff_ge {x} {v}={w:real^3| (w-x) dot (e2_fan x v u)= &0 /\ &0 <= (w-x) dot (e3_fan x v u) /\ (w-x) dot (e1_fan x v u)= &0 }`,
REPEAT STRIP_TAC THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`]th3) THEN RES_TAC THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`]AFF_GE_1_1) THEN RESA_TAC THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`]properties_coordinate) THEN RESA_TAC THEN REWRITE_TAC[EXTENSION;IN_ELIM_THM] THEN GEN_TAC THEN EQ_TAC THENL[ STRIP_TAC THEN ASM_REWRITE_TAC[VECTOR_ARITH`(a % x + b) -x= (a- &1)% x + b `] THEN REMOVE_ASSUM_TAC THEN SYM_ASSUM_TAC THEN REWRITE_TAC[VECTOR_ARITH`((a-(a+b)) % x + b % v)= b % (v-x)`] THEN ASM_REWRITE_TAC[DOT_LADD;DOT_LMUL] THEN REDUCE_ARITH_TAC THEN POP_ASSUM MP_TAC THEN FIND_ASSUM(fun th-> REWRITE_TAC[SYM(th)])`dist (v,x) % e3_fan x v u = v- x:real^3` THEN REWRITE_TAC[DOT_LMUL] THEN FIND_ASSUM(MP_TAC)`orthonormal (e1_fan (x:real^3) (v:real^3) (u:real^3)) (e2_fan x v u) (e3_fan x v u)` THEN REWRITE_TAC[orthonormal] THEN RESA_TAC THEN REDUCE_ARITH_TAC THEN MP_TAC(ISPECL[`v:real^3`;`x:real^3`]DIST_POS_LE) THEN MESON_TAC[REAL_LE_MUL]; STRIP_TAC THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN DISCH_THEN(LABEL_TAC"a") THEN DISCH_THEN(LABEL_TAC"b") THEN DISCH_THEN (LABEL_TAC "c") THEN MP_TAC(ISPECL[`e1_fan (x:real^3) (v:real^3) (u:real^3)`;`e2_fan (x:real^3)( v:real^3) (u:real^3)`; `e3_fan (x:real^3) (v:real^3) (u:real^3)`;]ORTHONORMAL_IMP_SPANNING) THEN ASM_REWRITE_TAC[SPAN_3;EXTENSION] THEN DISCH_TAC THEN POP_ASSUM(fun th-> MP_TAC(ISPEC`(x':real^3)-(x:real^3)`th)) THEN REWRITE_TAC[SET_RULE`(a:real^3) IN (:real^3)`;IN_ELIM_THM] THEN RES_TAC THEN REMOVE_THEN "a" MP_TAC THEN ASM_REWRITE_TAC[DOT_LADD;DOT_LMUL] THEN POP_ASSUM MP_TAC THEN DISCH_THEN(LABEL_TAC"d") THEN FIND_ASSUM(MP_TAC)`orthonormal (e1_fan (x:real^3) (v:real^3) (u:real^3)) (e2_fan x v u) (e3_fan x v u)` THEN REWRITE_TAC[orthonormal] THEN STRIP_TAC THEN ASM_REWRITE_TAC[] THEN ASM_REWRITE_TAC[DOT_SYM] THEN REDUCE_ARITH_TAC THEN REMOVE_THEN "c" MP_TAC THEN ASM_REWRITE_TAC[DOT_LADD;DOT_LMUL] THEN ASM_REWRITE_TAC[DOT_SYM] THEN REDUCE_ARITH_TAC THEN DISCH_TAC THEN DISCH_TAC THEN REMOVE_THEN "d" MP_TAC THEN ASM_REWRITE_TAC[] THEN REDUCE_VECTOR_TAC THEN DISCH_TAC THEN REMOVE_THEN "b" MP_TAC THEN ASM_REWRITE_TAC[DOT_LADD;DOT_LMUL;] THEN REWRITE_TAC[DOT_SYM] THEN ASM_REWRITE_TAC[] THEN REDUCE_ARITH_TAC THEN POP_ASSUM MP_TAC THEN REWRITE_TAC[e3_fan;VECTOR_ARITH`a% b% v=(a*b)%v`; VECTOR_ARITH`a-b=c %(v-b)<=> a= (&1-c) % b + c % v`] THEN DISCH_THEN (LABEL_TAC"a") THEN STRIP_TAC THEN EXISTS_TAC `&1 - (w:real) * (inv (norm ((v:real^3) - (x:real^3))))` THEN EXISTS_TAC `(w:real) * (inv (norm ((v:real^3) - (x:real^3))))` THEN STRIP_TAC THENL[ MP_TAC(ISPECL[`v:real^3`;`x:real^3`]imp_norm_ge_zero_fan) THEN RES_TAC THEN MATCH_MP_TAC REAL_LE_MUL THEN ASM_REWRITE_TAC[] THEN POP_ASSUM MP_TAC THEN REAL_ARITH_TAC; STRIP_TAC THENL[REAL_ARITH_TAC; ASM_REWRITE_TAC[]]]]);;
let closed_halfline_fan=
prove(`!(x:real^3) (v:real^3) (u:real^3). ~collinear {x,v,u} ==> closed (aff_ge {x} { v})`,
(
let lemma=prove(`!x v u :real^3.
{w:real^3| (w-x) dot (e2_fan x v u)= &0 /\ &0 <= (w-x) dot (e3_fan x v u) 
/\ (w-x) dot (e1_fan x v u)= &0 }= {w:real^3| (w-x) dot (e2_fan x v u)= &0} INTER
({w:real^3| (w-x) dot (e1_fan x v u)= &0} INTER {w:real^3| &0 <= (w-x) dot (e3_fan x v u)})`,
REWRITE_TAC[INTER;IN_ELIM_THM] THEN ASM_SET_TAC[]) in


(let lemma1=prove(`!x:real^3 v:real^3 u:real^3.
closed {w:real^3| (w-x) dot (e2_fan x v u)= &0}`,
REWRITE_TAC[ DOT_SYM] THEN REWRITE_TAC[DOT_RSUB;REAL_ARITH`a-b= &0<=> a=b`;] 
 THEN REPEAT GEN_TAC THEN MP_TAC(ISPECL[`e2_fan (x:real^3) (v:real^3) (u:real^3)`;
` e2_fan (x:real^3) (v:real^3) (u:real^3) dot x`]CLOSED_HYPERPLANE) THEN ASM_SET_TAC[]) in

(let lemma3=prove(`!x:real^3 v:real^3 u:real^3.
closed {w:real^3| (w-x) dot (e1_fan x v u)= &0}`,
REWRITE_TAC[ DOT_SYM] THEN REWRITE_TAC[DOT_RSUB;REAL_ARITH`a-b= &0<=> a=b`;] 
 THEN REPEAT GEN_TAC THEN MP_TAC(ISPECL[`e1_fan (x:real^3) (v:real^3) (u:real^3)`;
` e1_fan (x:real^3) (v:real^3) (u:real^3) dot x`]CLOSED_HYPERPLANE) THEN ASM_SET_TAC[]) in
 
(let lemma2=prove(`!x:real^3 v:real^3 u:real^3.
closed {w:real^3| &0 <= (w-x) dot (e3_fan x v u)  }`,
REWRITE_TAC[ DOT_SYM] THEN REWRITE_TAC[DOT_RSUB;REAL_ARITH`&0 <= a-b<=> a>=b`;] 
 THEN REPEAT GEN_TAC THEN MP_TAC(ISPECL[`e3_fan (x:real^3) (v:real^3) (u:real^3)`;
` e3_fan (x:real^3) (v:real^3) (u:real^3) dot x`]CLOSED_HALFSPACE_GE) THEN ASM_SET_TAC[]) in
REPEAT STRIP_TAC THEN MP_TAC(ISPECL[`x:real^3`;` v:real^3`; `u:real^3`]exp_aff_ge_by_dot_1_1)
  THEN REWRITE_TAC[lemma]
THEN RESA_TAC THEN ASSUME_TAC(ISPECL[`x:real^3`;` v:real^3`; `u:real^3`]lemma1) THEN ASSUME_TAC(ISPECL[`x:real^3`;` v:real^3`; `u:real^3`]lemma2) THEN ASSUME_TAC(ISPECL[`x:real^3`;` v:real^3`; `u:real^3`]lemma3)
  THEN SUBGOAL_THEN`closed({w:real^3| (w-x) dot (e1_fan x v u)= &0} INTER {w:real^3| &0 <= (w-x) dot (e3_fan x v u)})`
ASSUME_TAC
THENL[ASM_MESON_TAC[CLOSED_INTER];
ASM_MESON_TAC[CLOSED_INTER]])))));;
(*--------------------------------------------------------------------------------------------*) (* The properties of ballnorm_fan (x:real^3)={y:real^3 | dist(x,y) = &1} *) (*--------------------------------------------------------------------------------------------*)
let ballnorm_fan=new_definition`ballnorm_fan (x:real^3)={y:real^3 | dist(x,y) = &1}`;;
let closed_ballnorm_fan=
prove(`!x:real^3. closed (ballnorm_fan x)`,
GEN_TAC THEN REWRITE_TAC[ballnorm_fan] THEN SUBGOAL_THEN `{y:real^3 | dist((x:real^3),(y:real^3)) = &1} = frontier( ball((x:real^3), &1))` ASSUME_TAC THENL [ASSUME_TAC(REAL_ARITH `&0 < &1`) THEN POP_ASSUM MP_TAC THEN SIMP_TAC[frontier; CLOSURE_BALL; INTERIOR_OPEN; OPEN_BALL; REAL_LT_IMP_LE] THEN REWRITE_TAC[EXTENSION; IN_DIFF; IN_ELIM_THM; IN_BALL; IN_CBALL] THEN REAL_ARITH_TAC; ASM_REWRITE_TAC[] THEN MESON_TAC[FRONTIER_CLOSED]]);;
let bounded_ballnorm_fan=
prove(`!x:real^3 . bounded(ballnorm_fan x)`,
REPEAT GEN_TAC THEN REWRITE_TAC[ballnorm_fan;bounded] THEN EXISTS_TAC `norm(x:real^3) + &1` THEN REWRITE_TAC[ dist; IN_ELIM_THM] THEN GEN_TAC THEN STRIP_TAC THEN ASSUME_TAC(NORM_TRIANGLE_SUB) THEN POP_ASSUM (MP_TAC o ISPECL [`(x':real^3)`; `(x:real^3)`] o INST_TYPE [`:real^3`,`:real^3`]) THEN REWRITE_TAC[NORM_SUB] THEN ASM_REWRITE_TAC[]);;
let bounded_ballnorm_fans=
prove(`!x:real^3 v:real^3 w:real^3. bounded (aff_ge {x} {v, w} INTER ballnorm_fan x)`,
REPEAT GEN_TAC THEN ASSUME_TAC (bounded_ballnorm_fan) THEN POP_ASSUM (MP_TAC o ISPEC `x:real^3`) THEN DISCH_TAC THEN SUBGOAL_THEN `aff_ge {x} {(v:real^3), (w:real^3)} INTER ballnorm_fan x SUBSET ballnorm_fan (x:real^3)` ASSUME_TAC THENL [ASM_SET_TAC[]; ASM_MESON_TAC[BOUNDED_SUBSET ]]);;
(*--------------------------------------------------------------------------------------------*) (* The properties of sets in norm ball *) (*--------------------------------------------------------------------------------------------*)
let closed_aff_ge_ballnorm_fan=
prove(`!(x:real^3) (v:real^3) (w:real^3). ~collinear{x,v,w} ==> closed (aff_ge {x} {v, w} INTER ballnorm_fan x)`,
let compact_aff_ge_ballnorm_fan=
prove(` !(x:real^3) (v:real^3) (w:real^3). ~collinear{x,v,w} ==> compact (aff_ge {x} {v, w} INTER ballnorm_fan x)`,
REPEAT GEN_TAC THEN DISCH_TAC THEN SUBGOAL_THEN `closed (aff_ge {x} {v, w} INTER ballnorm_fan x)` ASSUME_TAC THENL [ASM_MESON_TAC[closed_aff_ge_ballnorm_fan]; ASSUME_TAC(bounded_ballnorm_fans) THEN POP_ASSUM (MP_TAC o ISPECL [`x:real^3`; `v:real^3`; `w:real^3`]) THEN ASM_MESON_TAC[BOUNDED_CLOSED_IMP_COMPACT ]]);;
let closed_point_fan=
prove(` (!x:real^3 v:real^3 u:real^3. ~collinear {x,v,u} ==> closed (aff_ge {x} {v} INTER ballnorm_fan x) )`,
REPEAT GEN_TAC THEN DISCH_TAC THEN SUBGOAL_THEN `closed (aff_ge {(x:real^3)} {(v:real^3)})` ASSUME_TAC THENL [ASM_MESON_TAC[ closed_halfline_fan]; SUBGOAL_THEN `closed (ballnorm_fan (x:real^3))` ASSUME_TAC THENL [ASM_MESON_TAC[closed_ballnorm_fan]; ASM_MESON_TAC[CLOSED_INTER]]]);;
let exist_fan=
prove(`(!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3) (v1:real^3) (w1:real^3). FAN(x,V,E) /\ ~(v IN {v1,w1}) /\ {v1,w1} IN E /\ {v,w} IN E ==> ?h:real. (&0 < h) /\ (!y1:real^3 y2:real^3. (y1 IN aff_ge {x} {v} INTER ballnorm_fan x) /\ y2 IN (aff_ge {x} {v1, w1} INTER ballnorm_fan x) ==> h <= dist(y1,y2) ))`,
REPEAT STRIP_TAC THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (w:real^3)`; ` (v:real^3)`] remark1_fan) THEN RES_TAC THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (w1:real^3)`; ` (v1:real^3)`] remark1_fan) THEN RES_TAC THEN MATCH_MP_TAC( ISPECL [`aff_ge {(x:real^3)} {(v:real^3)} INTER ballnorm_fan x`; `aff_ge {(x:real^3)} {(v1:real^3), (w1:real^3)} INTER ballnorm_fan x`] SEPARATE_CLOSED_COMPACT) THEN MP_TAC(ISPECL[`(x:real^3) `;` (v:real^3)`;` (w:real^3)`]closed_point_fan) THEN RESA_TAC THEN MP_TAC(ISPECL[`(x:real^3) `;` (v1:real^3)`;` (w1:real^3)`]compact_aff_ge_ballnorm_fan) THEN RESA_TAC THEN FIND_ASSUM(MP_TAC)`FAN(x:real^3,V,E)` THEN REWRITE_TAC[FAN;fan7] THEN STRIP_TAC THEN POP_ASSUM(fun th-> MP_TAC(ISPECL[`{(v:real^3)}`;`{(v1:real^3),(w1:real^3)}`]th)) THEN ASM_REWRITE_TAC[UNION; IN_ELIM_THM;] THEN GEN_REWRITE_TAC(LAND_CONV o LAND_CONV o RAND_CONV o ONCE_DEPTH_CONV)[EXTENSION;] THEN ASM_REWRITE_TAC[IN_SING; SET_RULE`(!x. x = v <=> x = v') <=> v =v'`;SET_RULE`(?v'. v' IN V /\ v = v')<=> v IN V`] THEN SUBGOAL_THEN `{v:real^3} INTER {v1,w1} ={}` ASSUME_TAC THENL[ REWRITE_TAC[INTER;IN_SING; EXTENSION; EMPTY; IN_ELIM_THM] THEN ASM_SET_TAC[]; ASM_REWRITE_TAC[AFF_GE_EQ_AFFINE_HULL; SET_RULE`(A INTER C) INTER (B INTER C)= (A INTER B) INTER C`;] THEN ASSUME_TAC(AFFINE_SING) THEN MP_TAC(ISPEC`{ (x:real^3) }` AFFINE_HULL_EQ ) THEN RESA_TAC THEN RESA_TAC THEN REWRITE_TAC[ballnorm_fan;INTER; IN_SING; EXTENSION;EMPTY;IN_ELIM_THM; ] THEN GEN_TAC THEN STRIP_TAC THEN POP_ASSUM MP_TAC THEN ASM_REWRITE_TAC[DIST_REFL ] THEN REAL_ARITH_TAC]);;
let ballsets_fan=new_definition`ballsets_fan (s:real^3->bool) (h:real)= {y:real^3| ?x:real^3. dist(x,y) < h /\ x IN s} `;;
let exists_ballsets_fan =
prove( `(!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3) (v1:real^3) (w1:real^3). FAN(x,V,E) /\ ~(v IN {v1,w1}) /\ {v1,w1} IN E /\ {v,w} IN E ==> ?h:real. (&0 < h) /\ (ballsets_fan (aff_ge {x} {v} INTER ballnorm_fan x) h INTER (aff_ge {x} {v1, w1} INTER ballnorm_fan x) = {}) )`,
REPEAT GEN_TAC THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool) `;`(E:(real^3->bool)->bool)`;` (v:real^3)`;` (w:real^3)`;` (v1:real^3)`;` (w1:real^3)`] exist_fan) THEN RES_TAC THEN POP_ASSUM MP_TAC THEN REWRITE_TAC[ballsets_fan; INTER; IN_ELIM_THM] THEN DISCH_TAC THEN EXISTS_TAC`h:real` THEN ASM_REWRITE_TAC[EXTENSION;IN_ELIM_THM;] THEN GEN_TAC THEN EQ_TAC THENL[ POP_ASSUM MP_TAC THEN DISCH_THEN(LABEL_TAC"a") THEN STRIP_TAC THEN REMOVE_THEN "a"(fun th-> MP_TAC(ISPECL[`x'':real^3`;`x':real^3`]th)) THEN ASM_REWRITE_TAC[EMPTY;IN_ELIM_THM] THEN REPEAT (POP_ASSUM MP_TAC) THEN REAL_ARITH_TAC; REWRITE_TAC[EMPTY;IN_ELIM_THM]]);;
(*-------------------------------------------------------------------------------------------*) (* cone_ge_fan_inter_aff_ge_is_empty *) (*-------------------------------------------------------------------------------------------*)
let cone_ge_fan=new_definition`cone_ge_fan (x:real^3) (s:real^3->bool)= {y:real^3| ?a:real z:real^3. (&0 <= a)/\(z IN s) /\ (y =a % (z - x) + x)}`;;
let cone_ge_fan_inter_aff_ge_is_empty=
prove( `(!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3) (v1:real^3) (w1:real^3). FAN(x,V,E) /\ ~(v IN {v1,w1}) /\ {v1,w1} IN E /\ {v,w} IN E ==> ?h:real. (h > &0) /\ (cone_ge_fan x ((ballsets_fan (aff_ge {x} {v} INTER ballnorm_fan x) h)INTER ballnorm_fan x ) INTER aff_ge {x} {v1, w1} = {x}) )`,
REPEAT STRIP_TAC THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (w:real^3)`; `(v:real^3)`] remark1_fan) THEN RES_TAC THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool)`;` (E:(real^3->bool)->bool) `;` (w1:real^3)`; `(v1:real^3)`] remark1_fan) THEN RES_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool) `;`(E:(real^3->bool)->bool)`;` (v:real^3)`; `(w:real^3)`;` (v1:real^3)`;` (w1:real^3)`] exists_ballsets_fan) THEN ASM_REWRITE_TAC[] THEN MATCH_MP_TAC MONO_EXISTS THEN GEN_TAC THEN STRIP_TAC THEN STRIP_TAC THENL(*1*)[ ASM_REWRITE_TAC[REAL_ARITH`a> &0 <=> &0< a`];(*1*) REWRITE_TAC [cone_ge_fan; EXTENSION; IN_SING; INTER; IN_ELIM_THM] THEN GEN_TAC THEN EQ_TAC THENL(*2*)[ ASM_CASES_TAC `(x':real^3)=(x:real^3)` THENL(*3*)[ASM_REWRITE_TAC[];(*3*) MP_TAC (ISPECL [`x':real^3`; `x:real^3`] imp_norm_not_zero_fan) THEN RES_TAC THEN STRIP_TAC THEN POP_ASSUM MP_TAC THEN DISCH_THEN(LABEL_TAC "a") THEN REPEAT STRIP_TAC THEN ASM_REWRITE_TAC[] THEN ABBREV_TAC `(x1:real^3)= inv (norm ((x':real^3)-(x:real^3))) % (x'-x) + x` THEN SUBGOAL_THEN `(x1:real^3) IN ballnorm_fan (x:real^3)` ASSUME_TAC THENL(*4*)[ REWRITE_TAC[ballnorm_fan; IN_ELIM_THM] THEN EXPAND_TAC "x1" THEN REWRITE_TAC[dist] THEN REWRITE_TAC[VECTOR_ARITH `(x:real^3)-((a:real^3)+(x:real^3))= --(a)`; VECTOR_ARITH `-- ((a:real)% (v:real^3))=(-- a) % v`; NORM_MUL;REAL_ABS_NEG; REAL_ABS_INV; REAL_ABS_NORM] THEN USE_THEN "a" MP_TAC THEN MP_TAC(ISPEC `norm ((x':real^3)-(x:real^3))` REAL_MUL_LINV) THEN ASM_MESON_TAC[];(*4*) SUBGOAL_THEN `(x1:real^3) IN aff_ge {(x:real^3)} {(v1:real^3),(w1:real^3)}` ASSUME_TAC THENL(*5*)[REMOVE_THEN "a" MP_TAC THEN MP_TAC(ISPECL[`x:real^3`;`v1:real^3`;`w1:real^3`]AFF_GE_1_2) THEN RESA_TAC THEN REWRITE_TAC[IN_ELIM_THM] THEN STRIP_TAC THEN EXISTS_TAC `&1 - inv (norm((x':real^3)-(x:real^3))) + inv (norm (x' - x)) * (t1:real) ` THEN EXISTS_TAC `inv (norm((x':real^3)-(x:real^3))) * (t2:real) ` THEN EXISTS_TAC `inv (norm((x':real^3)-(x:real^3))) * (t3:real) ` THEN EXPAND_TAC "x1" THEN REWRITE_TAC[VECTOR_ARITH`((a:real)-(b:real)+(c:real))%(v:real^3)=(a:real) % v -(b:real)% v+(c:real) %(v:real^3)`; VECTOR_ARITH `&1 % (x:real^3)=x`; VECTOR_ARITH `((a:real)*(b:real)) % (v:real^3)= (a % (b % v))`; VECTOR_ARITH `(x - inv (norm (x' - x)) % x + inv (norm (x' - x)) % t1 % x) + inv (norm (x' - x)) % t2 % v1 + inv (norm (x' - x)) % t3 % w1 =(inv (norm ((x':real^3)- x))) % ( t1 % x + t2 % v1+ t3% w1 -x)+ (x:real^3)` ] THEN STRIP_TAC THENL(*6*)[SUBGOAL_THEN `&0 <= inv (norm ((x':real^3)-(x:real^3))) ` ASSUME_TAC THENL(*7*)[ MATCH_MP_TAC REAL_LE_INV THEN MESON_TAC[NORM_POS_LE];(*7*) ASM_MESON_TAC[REAL_LE_MUL]](*7*);(*6*) STRIP_TAC THENL(*7*)[ SUBGOAL_THEN `&0 <= inv (norm ((x':real^3)-(x:real^3))) ` ASSUME_TAC THENL(*8*)[ MATCH_MP_TAC REAL_LE_INV THEN MESON_TAC[NORM_POS_LE];(*8*) ASM_MESON_TAC[REAL_LE_MUL; REAL_ARITH `(a:real)>= &0 <=> &0 <= a`]](*8*);(*7*) REWRITE_TAC[REAL_ARITH `(&1 - inv (norm (x' - x)) + inv (norm (x' - x)) * t1) + inv (norm (x' - x)) * t2 + inv (norm (x' - x)) * t3= &1 - inv (norm (x' - x)) + inv (norm (x' - x)) * (t1 + t2 + t3)`] THEN STRIP_TAC THENL(*8*)[ ASM_REWRITE_TAC[] THEN REWRITE_TAC[REAL_ARITH `(a:real) * &1 = a`; REAL_ARITH `&1 - (a:real) +(a:real) = &1`];(*8*) SUBGOAL_THEN `(x':real^3) -(x:real^3)= (t1:real) % (x:real^3) + (t2:real) % (v1:real^3) + (t3:real) % (w1:real^3) -(x:real^3)` ASSUME_TAC THENL(*9*)[ ASM_REWRITE_TAC[] THEN VECTOR_ARITH_TAC;(*9*) SUBGOAL_THEN `inv (norm ((x':real^3) -(x:real^3)) ) % ((x':real^3) -(x:real^3)) = inv (norm ((x':real^3) -(x:real^3)) ) % ((t1:real) % (x:real^3) + (t2:real) % (v1:real^3) + (t3:real) % (w1:real^3) -(x:real^3))` ASSUME_TAC THENL(*10*)[ASM_MESON_TAC[ VECTOR_MUL_LCANCEL ];(*10*) ASM_MESON_TAC[]](*10*)](*9*)](*8*)](*7*)](*6*); (*5*) SUBGOAL_THEN `(x1:real^3) IN ballsets_fan (aff_ge {(x:real^3)} {(v:real^3)} INTER ballnorm_fan x) (h:real)` ASSUME_TAC THENL(*6*)[ SUBGOAL_THEN `norm ((z:real^3)-(x:real^3))= &1` ASSUME_TAC THENL(*7*)[FIND_ASSUM(MP_TAC)`z IN ballnorm_fan (x:real^3)` THEN REWRITE_TAC[ballnorm_fan; IN_ELIM_THM; dist; NORM_SUB];(*7*) POP_ASSUM MP_TAC THEN DISCH_THEN (LABEL_TAC "k") THEN SUBGOAL_THEN `(x':real^3)- (x:real^3)= (a:real) % ((z:real^3)-x )` ASSUME_TAC THENL(*8*)[ FIND_ASSUM(MP_TAC)`x'=a %(z-x) +x:real^3` THEN VECTOR_ARITH_TAC;(*8*) SUBGOAL_THEN `norm((x':real^3)- (x:real^3))= norm((a:real) % ((z:real^3)-x ))` ASSUME_TAC THENL(*9*)[ASM_SET_TAC[];(*9*) POP_ASSUM MP_TAC THEN REWRITE_TAC[NORM_MUL] THEN POP_ASSUM MP_TAC THEN USE_THEN "k" (fun th -> REWRITE_TAC[th]) THEN REDUCE_ARITH_TAC THEN SUBGOAL_THEN `abs (a:real)=a`ASSUME_TAC THENL(*10*)[FIND_ASSUM(MP_TAC)`&0 <= a:real` THEN REAL_ARITH_TAC;(*10*) POP_ASSUM (fun th-> REWRITE_TAC[th]) THEN DISCH_THEN(LABEL_TAC"l") THEN DISCH_THEN (LABEL_TAC "n") THEN REMOVE_THEN "l" MP_TAC THEN USE_THEN "n" (fun th-> REWRITE_TAC[SYM th]) THEN DISCH_THEN (LABEL_TAC "l") THEN SUBGOAL_THEN `(inv (norm (x'- x))) % ((x':real^3)- (x:real^3)) = (inv (norm (x' - x))) % (norm (x' - x) % ((z:real^3)- x ))` ASSUME_TAC THENL(*11*)[POP_ASSUM MP_TAC THEN MESON_TAC[];(*11*) POP_ASSUM MP_TAC THEN REWRITE_TAC[VECTOR_ARITH `(a:real)%(b:real)%(v:real^3)=(a*b)%v`] THEN MP_TAC(ISPEC`norm((x':real^3)-(x:real^3))`REAL_MUL_LINV) THEN FIND_ASSUM(fun th ->REWRITE_TAC[th]) `~(norm((x':real^3)-(x:real^3))= &0)` THEN DISCH_TAC THEN POP_ASSUM(fun th-> REWRITE_TAC[th]) THEN REDUCE_VECTOR_TAC THEN REWRITE_TAC[VECTOR_ARITH `((a:real^3)=(z:real^3)-(x:real^3))<=>(a+x=z)`] THEN FIND_ASSUM(fun th-> REWRITE_TAC[th])`inv (norm (x' - x)) % (x' - x) + x = x1:real^3` THEN DISCH_TAC THEN ASM_REWRITE_TAC[INTER]](*11*)](*10*)](*9*)](*8*)](*7*);(*6*) ASM_SET_TAC[]](*6*)](*5*)](*4*)](*3*);(*2*) STRIP_TAC THEN ASM_REWRITE_TAC[] THEN STRIP_TAC THENL(*2*)[ EXISTS_TAC `&0` THEN EXISTS_TAC`inv (norm ((v:real^3)-(x:real^3))) % (v-x) + x` THEN REDUCE_VECTOR_TAC THEN STRIP_TAC THENL(*3*)[ REAL_ARITH_TAC;(*3*) STRIP_TAC THENL(*4*)[ REWRITE_TAC[ballsets_fan; IN_ELIM_THM] THEN EXISTS_TAC `inv(norm((v:real^3)-(x:real^3))) % (v-x)+x` THEN REWRITE_TAC[dist; VECTOR_ARITH `(a)-a= vec 0`; NORM_0] THEN STRIP_TAC THENL(*5*)[ ASM_SET_TAC[];(*5*) STRIP_TAC THENL(*6*)[ MP_TAC(ISPECL[`x:real^3`;`v:real^3`]AFF_GE_1_1) THEN RESA_TAC THEN REWRITE_TAC[IN_ELIM_THM] THEN EXISTS_TAC `&1 - inv (norm ((v:real^3)-(x:real^3)))` THEN EXISTS_TAC `inv (norm ((v:real^3)-(x:real^3)))` THEN STRIP_TAC THENL(*7*)[ MP_TAC(ISPECL[`v:real^3`;`x:real^3`]imp_norm_ge_zero_fan) THEN RES_TAC THEN POP_ASSUM MP_TAC THEN REAL_ARITH_TAC;(*7*) STRIP_TAC THENL(*8*)[ REAL_ARITH_TAC;(*8*) VECTOR_ARITH_TAC](*8*)](*7*);(*6*) REWRITE_TAC[ballnorm_fan; IN_ELIM_THM; dist; VECTOR_ARITH `(x:real^3)-((a:real^3)+(x:real^3))= --a`; NORM_NEG; NORM_MUL ] THEN SUBGOAL_THEN `inv(norm((v:real^3)-(x:real^3))) > &0 ` ASSUME_TAC THENL(*7*)[MP_TAC(ISPECL[`v:real^3`;`x:real^3`]imp_norm_gl_zero_fan) THEN RESA_TAC;(*7*) SUBGOAL_THEN `abs(inv(norm((v:real^3)-(x:real^3))))=inv(norm((v:real^3)-(x:real^3)))` ASSUME_TAC THENL(*8*)[ASM_REWRITE_TAC[REAL_ABS_REFL] THEN POP_ASSUM MP_TAC THEN REAL_ARITH_TAC;(*8*) POP_ASSUM (fun th -> REWRITE_TAC[th]) THEN SUBGOAL_THEN `~ (norm ((v:real^3)-(x:real^3))= &0)` ASSUME_TAC THENL(*9*)[MP_TAC(ISPECL[`v:real^3`;`x:real^3`]imp_norm_not_zero_fan) THEN RESA_TAC;(*9*) POP_ASSUM MP_TAC THEN MESON_TAC[REAL_MUL_RINV;REAL_MUL_SYM]](*9*)](*8*)](*7*)](*6*)](*5*);(*4*) REWRITE_TAC[ballnorm_fan; IN_ELIM_THM; dist; VECTOR_ARITH `(x:real^3)-((a:real^3)+(x:real^3))= --a`; NORM_NEG; NORM_MUL ] THEN SUBGOAL_THEN `inv(norm((v:real^3)-(x:real^3))) > &0 ` ASSUME_TAC THENL(*5*)[ MP_TAC(ISPECL[`v:real^3`;`x:real^3`]imp_norm_gl_zero_fan) THEN RESA_TAC;(*5*) SUBGOAL_THEN `abs(inv(norm((v:real^3)-(x:real^3))))=inv(norm((v:real^3)-(x:real^3)))` ASSUME_TAC THENL(*6*)[ASM_REWRITE_TAC[REAL_ABS_REFL] THEN POP_ASSUM MP_TAC THEN REAL_ARITH_TAC;(*6*) POP_ASSUM (fun th -> REWRITE_TAC[th]) THEN SUBGOAL_THEN `~ (norm ((v:real^3)-(x:real^3))= &0)` ASSUME_TAC THENL(*7*)[ MP_TAC(ISPECL[`v:real^3`;`x:real^3`]imp_norm_not_zero_fan) THEN RESA_TAC;(*7*) POP_ASSUM MP_TAC THEN MESON_TAC[REAL_MUL_RINV;REAL_MUL_SYM]](*7*)](*6*)](*5*)](*4*)](*3*);(*2*) MP_TAC(ISPECL[`x:real^3`;`v1:real^3`;`w1:real^3`]AFF_GE_1_2) THEN RESA_TAC THEN REWRITE_TAC[IN_ELIM_THM] THEN EXISTS_TAC `&1` THEN EXISTS_TAC `&0` THEN EXISTS_TAC `&0` THEN STRIP_TAC THENL [REAL_ARITH_TAC; STRIP_TAC THENL [REAL_ARITH_TAC; STRIP_TAC THENL [REAL_ARITH_TAC; VECTOR_ARITH_TAC]]]]]]);;
let subset_by_inequality_fan=
prove(`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3) (v1:real^3) (w1:real^3) (h:real) (h1:real). FAN(x,V,E) /\ ~(v IN {v1,w1}) /\ {v1,w1} IN E /\ {v,w} IN E /\ h < h1 ==> cone_ge_fan x ((ballsets_fan (aff_ge {x} {v} INTER ballnorm_fan x) h)INTER ballnorm_fan x ) INTER aff_ge {x} {v1, w1} SUBSET cone_ge_fan x ((ballsets_fan (aff_ge {x} {v} INTER ballnorm_fan x) h1)INTER ballnorm_fan x ) INTER aff_ge {x} {v1, w1} `,
REPEAT STRIP_TAC THEN SUBGOAL_THEN` cone_ge_fan x ((ballsets_fan (aff_ge {x} {v} INTER ballnorm_fan x) h)INTER ballnorm_fan x) SUBSET cone_ge_fan x ((ballsets_fan (aff_ge {x} {v} INTER ballnorm_fan x) h1)INTER ballnorm_fan x ) ` ASSUME_TAC THENL[ REWRITE_TAC[cone_ge_fan; SUBSET;IN_ELIM_THM] THEN GEN_TAC THEN STRIP_TAC THEN EXISTS_TAC`a:real` THEN EXISTS_TAC`z:real^3` THEN ASM_REWRITE_TAC[] THEN POP_ASSUM (fun th-> REWRITE_TAC[]) THEN POP_ASSUM MP_TAC THEN REWRITE_TAC[ballsets_fan;INTER; IN_ELIM_THM] THEN RESA_TAC THEN EXISTS_TAC`x'':real^3` THEN ASM_REWRITE_TAC[] THEN REPEAT (POP_ASSUM MP_TAC) THEN REAL_ARITH_TAC; ASM_SET_TAC[]]);;
let cone_ge_fan_inter_aff_ge_is_empty_fan=
prove( `(!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3) (v1:real^3) (w1:real^3). FAN(x,V,E) /\ ~(v IN {v1,w1}) /\ {v1,w1} IN E /\ {v,w} IN E ==> ?h:real. (&1> h) /\ (h > &0) /\ (cone_ge_fan x ((ballsets_fan (aff_ge {x} {v} INTER ballnorm_fan x) h)INTER ballnorm_fan x ) INTER aff_ge {x} {v1, w1} SUBSET {x}) )`,
REPEAT STRIP_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool) `;`(E:(real^3->bool)->bool)`;` (v:real^3) `; `(w:real^3) `;`(v1:real^3)`;` (w1:real^3)`]cone_ge_fan_inter_aff_ge_is_empty) THEN RESA_TAC THEN DISJ_CASES_TAC(REAL_ARITH `(h >= &1) \/ (&1 > h)` ) THENL[ MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool) `;`(E:(real^3->bool)->bool)`;` (v:real^3) `; `(w:real^3) `;`(v1:real^3)`;` (w1:real^3)`; `&1/ &2`; `(h:real)`]subset_by_inequality_fan) THEN RESA_TAC THEN POP_ASSUM MP_TAC THEN MP_TAC(REAL_ARITH`h>= &1==> &1 / &2 <h`) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN EXISTS_TAC `&1/ &2` THEN ASM_REWRITE_TAC[] THEN REAL_ARITH_TAC; EXISTS_TAC `h:real` THEN ASM_REWRITE_TAC[] THEN ASM_SET_TAC[]]);;
let rcone_subset_cone=
prove( `!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3) h:real. FAN(x,V,E) /\ {v,w} IN E /\(&0< h) /\ (h< &1) ==> ?h1:real. &1 > h1 /\ h1> &0 /\ (rcone_fan x v h1) SUBSET cone_ge_fan x ((ballsets_fan (aff_ge {x} {v} INTER ballnorm_fan x) h)INTER ballnorm_fan x )`,
REWRITE_TAC[rcone_fan;cone_ge_fan; SUBSET;IN_ELIM_THM;dist] THEN REPEAT STRIP_TAC THEN EXISTS_TAC`(&2 -(h:real) pow 2)/ &2` THEN STRIP_TAC THENL[ REWRITE_TAC[REAL_ARITH`&1 > (&2 -(h:real) pow 2)/ &2 <=> h pow 2> &0`] THEN MP_TAC (ISPECL[`h:real`;`2`]REAL_POW_LT) THEN REPEAT(POP_ASSUM MP_TAC) THEN REAL_ARITH_TAC; STRIP_TAC THENL[ REWRITE_TAC[REAL_ARITH`(&2 -h pow 2)/ &2> &0<=> &2 > h pow 2`] THEN MATCH_MP_TAC(REAL_ARITH` h pow 2<= &1 ==> &2 > h pow 2`) THEN MATCH_MP_TAC (ISPECL[`2`;`h:real`;]REAL_POW_1_LE) THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN REAL_ARITH_TAC; REPEAT STRIP_TAC THEN EXISTS_TAC `norm ((x':real^3)-(x:real^3))` THEN EXISTS_TAC `inv(norm ((x':real^3)-(x:real^3)))%(x'-x)+x` THEN REWRITE_TAC[NORM_POS_LE] THEN POP_ASSUM MP_TAC THEN DISJ_CASES_TAC(SET_RULE`((x':real^3)-(x:real^3)= vec 0) \/ ~((x':real^3)-(x:real^3)= vec 0)`) THENL(*1*)[ ASM_REWRITE_TAC[NORM_0;DOT_LZERO;] THEN REDUCE_ARITH_TAC THEN REAL_ARITH_TAC;(*1*) REWRITE_TAC[VECTOR_ARITH`(A+B)-B=A:real^3`;VECTOR_MUL_ASSOC] THEN MP_TAC(ISPEC`x':real^3- x`NORM_EQ_0) THEN RESA_TAC THEN MP_TAC(ISPEC`norm(x':real^3- x)`REAL_MUL_LINV) THEN ASM_REWRITE_TAC[REAL_MUL_SYM] THEN RESA_TAC THEN REDUCE_VECTOR_TAC THEN REWRITE_TAC[VECTOR_ARITH`A-B+B=A:real^3`] THEN SUBGOAL_THEN` inv (norm (x' - x)) % (x' - x) + x IN ballnorm_fan (x:real^3)` ASSUME_TAC THENL(*2*)[ REWRITE_TAC[ballnorm_fan; IN_ELIM_THM; dist; VECTOR_ARITH `(x:real^3)-((a:real^3)+(x:real^3))= --a`; NORM_NEG; NORM_MUL ] THEN MP_TAC(ISPECL[`x':real^3`;`x:real^3`]imp_norm_ge_zero_fan) THEN GEN_REWRITE_TAC(LAND_CONV o LAND_CONV o RAND_CONV o ONCE_DEPTH_CONV)[VECTOR_ARITH`(a:real^3)=b <=> a - b = vec 0`] THEN RESA_TAC THEN MP_TAC(ISPEC`inv(norm((x':real^3)-(x:real^3)))`REAL_ABS_REFL) THEN GEN_REWRITE_TAC( LAND_CONV o RAND_CONV o ONCE_DEPTH_CONV)[REAL_ARITH`&0<= (a:real) <=> a >= &0`] THEN RESA_TAC;(*2*) STRIP_TAC THEN SUBGOAL_THEN` inv (norm (x' - x)) % (x' - x) + x IN ballsets_fan (aff_ge {x} {v} INTER ballnorm_fan (x:real^3)) (h:real)` ASSUME_TAC THENL(*3*)[ REWRITE_TAC[ballsets_fan;IN_ELIM_THM;dist] THEN EXISTS_TAC`inv (norm (v - x)) % (v - x) + (x:real^3)` THEN STRIP_TAC THENL(*4*)[ REWRITE_TAC[VECTOR_ARITH`((v:real^3)+b)-(u+b)= (v-u)`;] THEN SUBGOAL_THEN`norm(inv(norm(v-x))%(v:real^3-x)-inv(norm(x'-x))%(x'-x)) pow 2< h pow 2` ASSUME_TAC THENL(*5*)[ REWRITE_TAC[NORM_POW_2;DOT_LSUB;DOT_RSUB] THEN REWRITE_TAC[DOT_RMUL;DOT_LMUL;DOT_SQUARE_NORM; REAL_ARITH`a-b-(c-d)=a+d-b-c`; REAL_ARITH`a*a*b pow 2=(a*b) pow 2`;DOT_SYM;REAL_ARITH`a+b-e*d*c-d*e*c=a+b- &2 * d*e *c`] THEN MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool) `;`(E:(real^3->bool)->bool)`;`(w:real^3)`; `(v:real^3)`;] remark1_fan) THEN RES_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;`(v:real^3)`;] imp_norm_not_zero_fan) THEN REWRITE_TAC[NORM_SUB] THEN RES_TAC THEN MP_TAC(ISPEC`norm(v:real^3- x)`REAL_MUL_LINV) THEN RES_TAC THEN ASM_REWRITE_TAC[REAL_ARITH`&1 pow 2= &1`; REAL_ARITH`&1+ &1 - &2 * a< h pow 2 <=> a > (&2- h pow 2)/ &2`] THEN MP_TAC (ISPEC `(v:real^3)-(x:real^3)` NORM_POS_LE) THEN DISCH_TAC THEN SUBGOAL_THEN `norm((v:real^3)-(x:real^3))> &0` ASSUME_TAC THENL(*6*)[ REPEAT( POP_ASSUM MP_TAC) THEN REAL_ARITH_TAC;(*6*) MP_TAC (ISPEC `(x':real^3)-(x:real^3)` NORM_POS_LE) THEN DISCH_TAC THEN SUBGOAL_THEN ` norm((x:real^3)-(x':real^3))> &0 ` ASSUME_TAC THENL(*7*)[ ONCE_REWRITE_TAC[NORM_ARITH`norm (x:real^3- x')> &0 <=> norm(x'-x)> &0`] THEN REPEAT( POP_ASSUM MP_TAC) THEN REAL_ARITH_TAC;(*7*) MP_TAC(ISPECL[`(&2 - (h:real) pow 2) / &2`; `inv (norm (x:real^3 - x')) * inv (norm (v - x)) * ((v - x) dot (x' - x))`; `norm (x:real^3 - x')`]REAL_LT_LMUL_EQ) THEN REWRITE_TAC[REAL_ARITH`a<b <=> b>a`] THEN POP_ASSUM(fun th->REWRITE_TAC[th]) THEN POP_ASSUM(fun th->REWRITE_TAC[]) THEN GEN_REWRITE_TAC(LAND_CONV o ONCE_DEPTH_CONV)[SET_RULE`(A<=>B)<=>(B<=>A)`] THEN DISCH_TAC THEN POP_ASSUM(fun th->REWRITE_TAC[th]) THEN MP_TAC(ISPECL[`norm (x:real^3 - x') * (&2 - (h:real) pow 2) / &2`; `norm (x:real^3 - x')*inv (norm (x:real^3 - x')) * inv (norm (v - x)) * ((v - x) dot (x' - x))`; `norm (v:real^3 - x)`]REAL_LT_LMUL_EQ) THEN REWRITE_TAC[REAL_ARITH`a<b <=> b>a`] THEN POP_ASSUM(fun th->REWRITE_TAC[th]) THEN POP_ASSUM(fun th->REWRITE_TAC[]) THEN GEN_REWRITE_TAC(LAND_CONV o ONCE_DEPTH_CONV)[SET_RULE`(A<=>B)<=>(B<=>A)`] THEN DISCH_TAC THEN POP_ASSUM(fun th->REWRITE_TAC[th]) THEN ASM_REWRITE_TAC[REAL_ARITH`A*B*C*D*E>a*b*c<=>(C*B)*(D*A)*E>b*c*a`] THEN ONCE_REWRITE_TAC[NORM_ARITH`norm (x:real^3- x')= norm(x'-x)`] THEN ASM_REWRITE_TAC[] THEN REDUCE_ARITH_TAC THEN GEN_REWRITE_TAC(RAND_CONV o RAND_CONV o ONCE_DEPTH_CONV)[NORM_SUB] THEN GEN_REWRITE_TAC(LAND_CONV o ONCE_DEPTH_CONV)[DOT_SYM] THEN ASM_REWRITE_TAC[]](*7*)](*6*)(*5*); ASM_REWRITE_TAC[NORM_LT_SQUARE;DOT_SQUARE_NORM]](*5*);(*4*) MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool) `;`(E:(real^3->bool)->bool)`;`(w:real^3)`; `(v:real^3)`;] remark1_fan) THEN RES_TAC THEN SUBGOAL_THEN`inv(norm(v-x:real^3)) % (v-x) +x IN aff_ge {x} {v}` ASSUME_TAC THENL(*5*)[ MP_TAC(ISPECL[`x:real^3`;`v:real^3`]AFF_GE_1_1) THEN RESA_TAC THEN REWRITE_TAC[IN_ELIM_THM] THEN EXISTS_TAC `&1 - inv (norm ((v:real^3)-(x:real^3)))` THEN EXISTS_TAC `inv (norm ((v:real^3)-(x:real^3)))` THEN STRIP_TAC THENL(*6*)[ MP_TAC(ISPECL[`v:real^3`;`x:real^3`]imp_norm_ge_zero_fan) THEN RES_TAC THEN POP_ASSUM MP_TAC THEN REAL_ARITH_TAC;(*6*) STRIP_TAC THENL(*7*)[ REAL_ARITH_TAC; VECTOR_ARITH_TAC]](*6*);(*5*) SUBGOAL_THEN` inv (norm (v- x)) % (v - x) + x IN ballnorm_fan (x:real^3)` ASSUME_TAC THENL(*6*)[ REWRITE_TAC[ballnorm_fan; IN_ELIM_THM; dist; VECTOR_ARITH `(x:real^3)-((a:real^3)+(x:real^3))= --a`; NORM_NEG; NORM_MUL ] THEN MP_TAC(ISPECL[`v:real^3`;`x:real^3`]imp_norm_ge_zero_fan) THEN ASM_REWRITE_TAC[VECTOR_ARITH`v-x=vec 0<=> v=x`] THEN GEN_REWRITE_TAC(LAND_CONV o LAND_CONV o RAND_CONV o ONCE_DEPTH_CONV)[VECTOR_ARITH`(a:real^3)=b <=> a - b = vec 0`] THEN RESA_TAC THEN MP_TAC(ISPEC`inv(norm((v:real^3)-(x:real^3)))`REAL_ABS_REFL) THEN GEN_REWRITE_TAC( LAND_CONV o RAND_CONV o ONCE_DEPTH_CONV)[REAL_ARITH`&0<= (a:real) <=> a >= &0`] THEN RESA_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;`(v:real^3)`;] imp_norm_not_zero_fan) THEN REWRITE_TAC[NORM_SUB] THEN RES_TAC THEN MP_TAC(ISPEC`norm(v:real^3- x)`REAL_MUL_LINV) THEN RES_TAC THEN ASM_REWRITE_TAC[];(*6*) ASM_SET_TAC[]](*6*)](*5*)](*4*);(*3*) ASM_SET_TAC[]]]]]]);;
let origin_not_in_rcone_fan=
prove(`!(x:real^3) (v:real^3) (h:real). ~(x IN rcone_fan x v h)`,
REPEAT GEN_TAC THEN REWRITE_TAC[rcone_fan; IN_ELIM_THM; VECTOR_ARITH`x-x= vec 0`; DOT_LZERO;DIST_REFL] THEN REDUCE_ARITH_TAC THEN REAL_ARITH_TAC);;
let inter_is_empty=
prove(` !(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3) (v1:real^3) (w1:real^3). FAN(x,V,E) /\ ~(v IN {v1,w1}) /\ {v1,w1} IN E /\ {v,w} IN E ==> ?h1:real. &1 > h1 /\ h1> &0 /\ rcone_fan x v h1 INTER aff_ge {x} {v1, w1} = {} `,
REPEAT STRIP_TAC THEN MP_TAC(ISPECL[`(x:real^3)`; `(V:real^3->bool)`;`(E:(real^3->bool)->bool)`;` (v:real^3) ` ;`(w:real^3)`;` (v1:real^3) `;`(w1:real^3)`]cone_ge_fan_inter_aff_ge_is_empty_fan) THEN RESA_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool) `;`(v:real^3)`; `(w:real^3)`;` h:real`]rcone_subset_cone) THEN RESA_TAC THEN POP_ASSUM MP_TAC THEN REWRITE_TAC[REAL_ARITH`&0<h<=> h> &0`; REAL_ARITH`h< &1 <=> &1 >h`] THEN RES_TAC THEN SUBGOAL_THEN`(rcone_fan x v h1 INTER aff_ge {x} {v1, w1}) SUBSET {x:real^3}` ASSUME_TAC THENL[ ASM_SET_TAC[]; MP_TAC(ISPECL[`(x:real^3)`;` (v:real^3)`;` (h1:real)`]origin_not_in_rcone_fan) THEN REPEAT STRIP_TAC THEN EXISTS_TAC`h1:real` THEN ASM_REWRITE_TAC[] THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN REWRITE_TAC[SUBSET; IN_SING;EXTENSION;EMPTY] THEN REPEAT STRIP_TAC THEN EQ_TAC THENL[ POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN DISCH_THEN(LABEL_TAC"a") THEN DISCH_TAC THEN DISCH_TAC THEN REMOVE_THEN "a" (fun th->MP_TAC(ISPEC`x':real^3`th)) THEN ASM_REWRITE_TAC[] THEN POP_ASSUM MP_TAC THEN DISCH_THEN(LABEL_TAC"a") THEN DISCH_TAC THEN REMOVE_THEN "a" MP_TAC THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN SUBGOAL_THEN`x:real^3 IN rcone_fan x v h1` ASSUME_TAC THENL[ASM_SET_TAC[]; ASM_SET_TAC[]]; ASM_SET_TAC[]]]);;
(* W^0_{dart}(x,epsilon) *)
let rw_dart_fan= new_definition`rw_dart_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) ((y:real^3),(v:real^3),(w:real^3),(w1:real^3)) (h:real)= w_dart_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) ((y:real^3),(v:real^3),(w:real^3),(w1:real^3)) INTER rcone_fan x v h`;;
let avoids_fan=
prove(`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3) (v1:real^3) (w1:real^3)(w2:real^3). FAN(x,V,E) /\ ~(v IN {v1,w1}) /\ {v1,w1} IN E /\ {v,w} IN E ==> ?h:real. &1 >h /\ h> &0 /\ rw_dart_fan x V E ((x:real^3),(v:real^3),(w:real^3),(w2:real^3)) h INTER aff_ge {x} {v1, w1} = {} `,
REPEAT STRIP_TAC THEN REWRITE_TAC[rw_dart_fan] THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool) `;`(E:(real^3->bool)->bool)`;` (v:real^3)`;` (w:real^3)`;` (v1:real^3)` ;`(w1:real^3)`]inter_is_empty) THEN RESA_TAC THEN EXISTS_TAC`h1:real` THEN ASM_SET_TAC[] );;
let avoids1_fan=
prove(`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3) (w1:real^3). FAN(x,V,E) /\ {v,w} IN E /\ {v,w1} IN E ==> ?h:real. &1 > h /\ h > &0 /\ rw_dart_fan x V E ((x:real^3),(v:real^3),(w:real^3),sigma_fan x V E v w) h INTER aff_ge {x} {v, w1} = {}`,
REPEAT STRIP_TAC THEN REWRITE_TAC[rw_dart_fan] THEN MP_TAC(ISPECL[`(x:real^3) `;`(V:real^3->bool) `;`(E:(real^3->bool)->bool)`;` (v:real^3)`; ` (w:real^3)`;`(w1:real^3)`]IBZWFFH) THEN RESA_TAC THEN EXISTS_TAC`&1/ &2` THEN REWRITE_TAC[REAL_ARITH`&1/ &2 > &0`;REAL_ARITH`&1 > &1/ &2`] THEN ASM_SET_TAC[]);;
let finish_avoids_fan=
prove(`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3) (v1:real^3) (w1:real^3). FAN(x,V,E) /\ {v,w} IN E /\ {v1,w1} IN E ==> ?h:real. &1 >h /\ h> &0/\ rw_dart_fan x V E ((x:real^3),(v:real^3),(w:real^3),sigma_fan x V E v w) h INTER aff_ge {x} {v1, w1} = {}`,
REPEAT STRIP_TAC THEN DISJ_CASES_TAC(SET_RULE`~(v:real^3 IN {v1,w1})\/ (v=v1\/ v=w1)`) THENL[ MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool) `;`(E:(real^3->bool)->bool)`;` (v:real^3) `;`(w:real^3) `;`(v1:real^3)`;`w1:real^3`;` (sigma_fan x V E v w:real^3)`]avoids_fan) THEN RESA_TAC THEN ASM_SET_TAC[]; POP_ASSUM MP_TAC THEN STRIP_TAC THENL[ POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN DISCH_THEN(LABEL_TAC"A") THEN DISCH_TAC THEN REMOVE_THEN "A" MP_TAC THEN POP_ASSUM( fun th-> REWRITE_TAC[SYM(th)]) THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool) `;`(E:(real^3->bool)->bool)`;` (v:real^3) `;`(w:real^3) `;`w1:real^3`]avoids1_fan) THEN RESA_TAC; POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN DISCH_THEN(LABEL_TAC"A") THEN DISCH_TAC THEN REMOVE_THEN "A" MP_TAC THEN POP_ASSUM( fun th-> REWRITE_TAC[SYM(th)]) THEN ONCE_REWRITE_TAC[SET_RULE`{X,Y}={Y,X}`] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool) `;`(E:(real^3->bool)->bool)`;` (v:real^3) `;`(w:real^3) `;`v1:real^3`]avoids1_fan) THEN RESA_TAC]]);;
let continuous_set_fan=
prove(`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3) (h:real) (h1:real). FAN(x,V,E) /\ {v,w} IN E /\ h1 <= h ==> rw_dart_fan x V E ((x:real^3),(v:real^3),(w:real^3),sigma_fan x V E v w) h SUBSET rw_dart_fan x V E ((x:real^3),(v:real^3),(w:real^3),sigma_fan x V E v w) h1`,
REPEAT STRIP_TAC THEN REWRITE_TAC[rw_dart_fan] THEN SUBGOAL_THEN `rcone_fan x v h SUBSET rcone_fan x v h1` ASSUME_TAC THENL[ REWRITE_TAC[rcone_fan;SUBSET; IN_ELIM_THM] THEN REPEAT STRIP_TAC THEN ASSUME_TAC(ISPECL[`v:real^3`;`x:real^3`]DIST_POS_LE) THEN ASSUME_TAC(ISPECL[`x':real^3`;`x:real^3`]DIST_POS_LE) THEN MP_TAC(ISPECL[`dist((v:real^3),x)`;`h1:real`;`h:real`] REAL_LE_LMUL) THEN RESA_TAC THEN MP_TAC(ISPECL[`dist((x':real^3),x)`;`dist((v:real^3),x)* (h1:real)`;`dist((v:real^3),x)* (h:real)`] REAL_LE_LMUL) THEN RESA_TAC THEN REPEAT (POP_ASSUM MP_TAC) THEN REAL_ARITH_TAC; ASM_SET_TAC[]]);;
let CTVTAQA=
prove(`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (E1:(real^3->bool)->bool). FAN(x,V,E) /\ E1 SUBSET E ==> FAN(x,V,E1)`,
REPEAT GEN_TAC THEN REWRITE_TAC[FAN;fan1;fan2;fan6;fan7;graph] THEN ASM_SET_TAC[]);;
let expand_edge_graph_fan=
prove(`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (e:real^3->bool). FAN(x,V,E) /\ e IN E ==> ?v:real^3 w:real^3. e={v,w}`,
REPEAT GEN_TAC THEN REWRITE_TAC[FAN;IN] THEN STRIP_TAC THEN FIND_ASSUM MP_TAC `graph (E:(real^3->bool)->bool)` THEN REWRITE_TAC[graph] THEN DISCH_TAC THEN POP_ASSUM(fun th-> MP_TAC(ISPEC`e:real^3->bool`th)) THEN RESA_TAC THEN POP_ASSUM MP_TAC THEN REWRITE_TAC[HAS_SIZE] THEN STRIP_TAC THEN SUBGOAL_THEN `~((e:real^3->bool)={})` ASSUME_TAC THENL[ STRIP_TAC THEN MP_TAC(ISPEC`(e:real^3->bool)`CARD_EQ_0) THEN RESA_TAC THEN POP_ASSUM MP_TAC THEN ARITH_TAC; MP_TAC(SET_RULE `~((e:real^3->bool)={})==> ?v:real^3. v IN e`) THEN RESA_TAC THEN SUBGOAL_THEN`~((e:real^3->bool) DELETE v={})` ASSUME_TAC THENL[ STRIP_TAC THEN MP_TAC(ISPECL[`v:real^3`;`(e:real^3->bool)`;]CARD_DELETE) THEN RESA_TAC THEN MP_TAC(ISPECL[`(e:real^3->bool)`;`v:real^3`] FINITE_DELETE) THEN RESA_TAC THEN MP_TAC(ISPEC`(e:real^3->bool) DELETE v`CARD_EQ_0) THEN RESA_TAC THEN POP_ASSUM MP_TAC THEN ARITH_TAC; MP_TAC(SET_RULE `~((e:real^3->bool)DELETE v={})==> ?w:real^3. w IN (e:real^3->bool)DELETE v/\ w IN e`) THEN RESA_TAC THEN MP_TAC(SET_RULE `(v IN (e:real^3->bool))/\ (w IN (e:real^3->bool))==> {v,w} SUBSET e`) THEN RESA_TAC THEN MP_TAC(SET_RULE `(w IN (e:real^3->bool)DELETE v)==> ~(v=w)`) THEN RESA_TAC THEN MP_TAC(ISPECL [`{v:real^3,w:real^3}`;`(e:(real^3->bool))`] FINITE_SUBSET) THEN RESA_TAC THEN ASSUME_TAC(SET_RULE `v:real^3 IN {v:real^3,w:real^3} `) THEN MP_TAC(ISPECL[`v:real^3`;`{v:real^3,w:real^3}`;]CARD_DELETE) THEN RESA_TAC THEN MP_TAC(SET_RULE `v IN {v,w}==>{v:real^3,w:real^3} DELETE v PSUBSET {v,w}`) THEN RESA_TAC THEN MP_TAC(ISPECL[`{v:real^3,w:real^3} DELETE v`;`{v:real^3,w:real^3}`]CARD_PSUBSET) THEN POP_ASSUM (fun th->REWRITE_TAC[th]) THEN FIND_ASSUM MP_TAC`FINITE {v:real^3,w:real^3}` THEN DISCH_TAC THEN POP_ASSUM (fun th->REWRITE_TAC[th]) THEN DISCH_TAC THEN MP_TAC(ARITH_RULE`CARD ({v, w} DELETE v) < CARD {v, w}/\ CARD ({v, w} DELETE v) = CARD {v, w}-1 <=>CARD ({v, w} DELETE v) +1= CARD {v:real^3, w:real^3}`) THEN POP_ASSUM (fun th->REWRITE_TAC[th]) THEN POP_ASSUM (fun th->GEN_REWRITE_TAC(LAND_CONV o LAND_CONV o ONCE_DEPTH_CONV)[th;]) THEN REWRITE_TAC[ARITH_RULE`A=A`] THEN DISCH_TAC THEN SUBGOAL_THEN `w:real^3 IN ({v:real^3,w:real^3} DELETE v)` ASSUME_TAC THENL[ ASM_SET_TAC[]; MP_TAC(ISPECL[`{v:real^3,w:real^3}`;`v:real^3`] FINITE_DELETE) THEN RESA_TAC THEN MP_TAC(ISPECL[`w:real^3`;`{v:real^3,w:real^3} DELETE v`;]CARD_DELETE) THEN RESA_TAC THEN MP_TAC(SET_RULE `w IN ({v,w} DELETE v)==>{v:real^3,w:real^3} DELETE v DELETE w PSUBSET {v,w} DELETE v`) THEN RESA_TAC THEN MP_TAC(ISPECL[`{v:real^3,w:real^3} DELETE v DELETE w`;`{v:real^3,w:real^3} DELETE v`]CARD_PSUBSET) THEN POP_ASSUM (fun th->REWRITE_TAC[th]) THEN FIND_ASSUM MP_TAC`FINITE ({v:real^3,w:real^3} DELETE v)` THEN DISCH_TAC THEN POP_ASSUM (fun th->REWRITE_TAC[th]) THEN DISCH_TAC THEN MP_TAC(ARITH_RULE`CARD ({v, w} DELETE v DELETE w) < CARD ({v, w} DELETE v)/\ CARD ({v, w} DELETE v DELETE w) = CARD ({v, w} DELETE v)-1 <=>CARD ({v, w} DELETE v DELETE w) +1= CARD ({v:real^3, w:real^3} DELETE v)`) THEN POP_ASSUM (fun th->REWRITE_TAC[th]) THEN POP_ASSUM (fun th->GEN_REWRITE_TAC(LAND_CONV o LAND_CONV o ONCE_DEPTH_CONV)[th;]) THEN REWRITE_TAC[ARITH_RULE`A=A`] THEN DISCH_TAC THEN POP_ASSUM MP_TAC THEN POP_ASSUM (fun th->REWRITE_TAC[]) THEN POP_ASSUM (fun th->REWRITE_TAC[]) THEN ASSUME_TAC(SET_RULE `{v, w} DELETE v:real^3 DELETE w:real^3={}`) THEN POP_ASSUM (fun th->REWRITE_TAC[th;CARD_CLAUSES; ARITH_RULE `0+1=1`]) THEN POP_ASSUM MP_TAC THEN DISCH_THEN(LABEL_TAC"B") THEN DISCH_TAC THEN REMOVE_THEN "B" MP_TAC THEN POP_ASSUM (fun th->REWRITE_TAC[SYM(th);ARITH_RULE` 1+1=2`]) THEN FIND_ASSUM MP_TAC`CARD (e:real^3->bool)=2` THEN DISCH_TAC THEN POP_ASSUM (fun th->REWRITE_TAC[SYM(th)]) THEN DISCH_TAC THEN MP_TAC(ISPECL[`{v:real^3,w:real^3}`;`e:real^3->bool`]CARD_SUBSET_EQ) THEN POP_ASSUM (fun th->REWRITE_TAC[SYM(th)]) THEN RESA_TAC THEN EXISTS_TAC`v:real^3` THEN EXISTS_TAC`w:real^3` THEN POP_ASSUM (fun th->REWRITE_TAC[SYM(th)])]]]);;
let finish_avoids1_fan=
prove(`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (E':(real^3->bool)->bool) (v:real^3) (w:real^3). FAN(x,V,E) /\ {v,w} IN E /\ E' SUBSET E ==> ?h:real. &1> h /\ h> &0 /\ rw_dart_fan x V E ((x:real^3),(v:real^3),(w:real^3),sigma_fan x V E v w) h INTER {v | ?e. e IN E' /\ v IN aff_ge {x} e}={}`,
REPEAT STRIP_TAC THEN REWRITE_TAC[xfan; IN_ELIM_THM] THEN MP_TAC(ISPECL[`x:real^3`;`V:real^3->bool`;`E:(real^3->bool)->bool`]set_edges_is_finite_fan) THEN RESA_TAC THEN MP_TAC(ISPECL [`(E':(real^3->bool)->bool)`;`(E:(real^3->bool)->bool)`] FINITE_SUBSET) THEN RESA_TAC THEN ABBREV_TAC`n=CARD (E':(real^3->bool)->bool)` THEN REPEAT(POP_ASSUM MP_TAC) THEN SPEC_TAC (`(E':(real^3->bool)->bool)`,`(E':(real^3->bool)->bool)`) THEN SPEC_TAC (`n:num`,`n:num`) THEN INDUCT_TAC THENL(*1*)[ REPEAT STRIP_TAC THEN MP_TAC(ISPECL[`E':(real^3->bool)->bool`]CARD_EQ_0) THEN RESA_TAC THEN EXISTS_TAC`&1 / &2` THEN REWRITE_TAC[REAL_ARITH`&1/ &2 > &0`;REAL_ARITH`&1 > &1/ &2`] THEN ASM_SET_TAC[];(*1*) REPEAT GEN_TAC THEN POP_ASSUM MP_TAC THEN DISCH_THEN (LABEL_TAC "A") THEN REPEAT STRIP_TAC THEN MP_TAC(ISPEC`(E':(real^3->bool)->bool)` CHOOSE_SUBSET) THEN RESA_TAC THEN POP_ASSUM(fun th-> MP_TAC(ISPEC`n:num `th)) THEN REWRITE_TAC[ARITH_RULE `n:num <= SUC n`; HAS_SIZE] THEN STRIP_TAC THEN MP_TAC(SET_RULE` t SUBSET E' /\ E' SUBSET E ==> (t:(real^3->bool)->bool) SUBSET E`) THEN RESA_TAC THEN REMOVE_THEN "A" (fun th-> MP_TAC(ISPEC`(t:(real^3->bool)->bool)`th)) THEN RESA_TAC THEN SUBGOAL_THEN `~((E':(real^3->bool)->bool) DIFF (t:(real^3->bool)->bool)= {})` ASSUME_TAC THENL(*2*)[ STRIP_TAC THEN MP_TAC(SET_RULE`(E':(real^3->bool)->bool) DIFF (t:(real^3->bool)->bool)={} /\ t SUBSET E' ==> t= E'`) THEN RESA_TAC THEN FIND_ASSUM MP_TAC`CARD (t:(real^3->bool)->bool)=n` THEN POP_ASSUM(fun th-> REWRITE_TAC[th]) THEN ASM_REWRITE_TAC[] THEN ARITH_TAC;(*2*) SUBGOAL_THEN`?e. e IN (E':(real^3->bool)->bool) DIFF (t:(real^3->bool)->bool)` ASSUME_TAC THENL(*3*)[ ASM_SET_TAC[];(*3*) POP_ASSUM MP_TAC THEN STRIP_TAC THEN MP_TAC(SET_RULE`e IN (E':(real^3->bool)->bool) DIFF (t:(real^3->bool)->bool)/\ (E':(real^3->bool)->bool) SUBSET (E:(real^3->bool)->bool) /\ t SUBSET E' ==> e IN E'/\ e IN E/\ ~(e IN t) /\ {e} UNION t SUBSET E'`) THEN RESA_TAC THEN MP_TAC(ISPECL [`{e:(real^3->bool)} UNION (t:(real^3->bool)->bool)`;`(E':(real^3->bool)->bool)`] FINITE_SUBSET) THEN RESA_TAC THEN ASSUME_TAC(SET_RULE`e IN {e:(real^3->bool)} UNION (t:(real^3->bool)->bool)`) THEN MP_TAC(ISPECL[`e:real^3->bool`;`{e:(real^3->bool)} UNION (t:(real^3->bool)->bool)`;]CARD_DELETE) THEN RESA_TAC THEN MP_TAC(SET_RULE `e IN {e:(real^3->bool)} UNION (t:(real^3->bool)->bool) ==> ({e:(real^3->bool)} UNION (t:(real^3->bool)->bool)) DELETE e PSUBSET {e:(real^3->bool)} UNION (t:(real^3->bool)->bool)`) THEN RESA_TAC THEN MP_TAC(ISPECL[`({e:(real^3->bool)} UNION (t:(real^3->bool)->bool))DELETE e`;`{e:(real^3->bool)} UNION (t:(real^3->bool)->bool)`]CARD_PSUBSET) THEN POP_ASSUM (fun th->REWRITE_TAC[th]) THEN FIND_ASSUM MP_TAC`FINITE ( {e:(real^3->bool)} UNION (t:(real^3->bool)->bool))` THEN DISCH_TAC THEN POP_ASSUM (fun th->REWRITE_TAC[th]) THEN DISCH_TAC THEN MP_TAC(ARITH_RULE`CARD (({e:(real^3->bool)} UNION (t:(real^3->bool)->bool)) DELETE e) < CARD ( {e:(real^3->bool)} UNION (t:(real^3->bool)->bool)) /\ CARD (({e:(real^3->bool)} UNION (t:(real^3->bool)->bool)) DELETE e) = CARD ({e:(real^3->bool)} UNION (t:(real^3->bool)->bool))-1 <=>CARD (({e:(real^3->bool)} UNION (t:(real^3->bool)->bool)) DELETE e) +1= CARD ({e:(real^3->bool)} UNION (t:(real^3->bool)->bool))`) THEN POP_ASSUM (fun th->REWRITE_TAC[th]) THEN POP_ASSUM (fun th->GEN_REWRITE_TAC(LAND_CONV o LAND_CONV o ONCE_DEPTH_CONV)[th;]) THEN REWRITE_TAC[ARITH_RULE`A=A`; ] THEN MP_TAC(SET_RULE`~(e IN t)==>({e:(real^3->bool)} UNION (t:(real^3->bool)->bool)) DELETE e=t`) THEN RESA_TAC THEN POP_ASSUM (fun th->REWRITE_TAC[th]) THEN FIND_ASSUM MP_TAC`(CARD (E':(real^3->bool)->bool)=SUC n)` THEN REWRITE_TAC[ARITH_RULE`SUC n=(n:num) +1`] THEN DISCH_TAC THEN POP_ASSUM (fun th->REWRITE_TAC[SYM(th)]) THEN DISCH_TAC THEN MP_TAC(ISPECL[`{e:(real^3->bool)} UNION (t:(real^3->bool)->bool)`;`E':(real^3->bool)->bool`]CARD_SUBSET_EQ) THEN POP_ASSUM (fun th->REWRITE_TAC[SYM(th)]) THEN RESA_TAC THEN POP_ASSUM MP_TAC THEN DISCH_THEN(LABEL_TAC"MA") THEN MP_TAC(ISPECL[`(x:real^3)`;` (V:real^3->bool) `;`(E:(real^3->bool)->bool)`;`(e:real^3->bool)`]expand_edge_graph_fan) THEN RESA_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;`(V:real^3->bool)`;`(E:(real^3->bool)->bool)`;` (v:real^3)`;`(w:real^3)`; `(v':real^3)`;` (w':real^3)`]finish_avoids_fan) THEN RESA_TAC THEN POP_ASSUM MP_TAC THEN POP_ASSUM(fun th-> REWRITE_TAC[SYM(th)] THEN ASSUME_TAC(th)) THEN POP_ASSUM MP_TAC THEN RESA_TAC THEN STRIP_TAC THEN ABBREV_TAC`h1= max (h:real) (h':real)` THEN EXISTS_TAC`h1:real` THEN STRIP_TAC THENL(*4*)[ POP_ASSUM(fun th-> REWRITE_TAC[SYM(th)]) THEN REPEAT(POP_ASSUM MP_TAC) THEN REAL_ARITH_TAC;(*4*) STRIP_TAC THENL(*5*)[ POP_ASSUM(fun th-> REWRITE_TAC[SYM(th)]) THEN REPEAT(POP_ASSUM MP_TAC) THEN REAL_ARITH_TAC;(*5*) REMOVE_THEN "MA" MP_TAC THEN DISCH_TAC THEN POP_ASSUM(fun th-> REWRITE_TAC[SYM(th)] THEN ASSUME_TAC(th)) THEN REWRITE_TAC[UNION;IN_ELIM_THM;EXTENSION; INTER;] THEN GEN_TAC THEN EQ_TAC THENL(*6*)[ ASM_REWRITE_TAC[IN_SING] THEN STRIP_TAC THENL[ POP_ASSUM MP_TAC THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;`(V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (w:real^3)` ;`(h1:real)`;` (h':real)`]continuous_set_fan) THEN RESA_TAC THEN POP_ASSUM MP_TAC THEN EXPAND_TAC"h1" THEN REWRITE_TAC[REAL_ARITH`h'<= max (h:real) (h':real)`] THEN RESA_TAC THEN ASM_SET_TAC[]; POP_ASSUM MP_TAC THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;`(V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (w:real^3)` ;`(h1:real)`;` (h:real)`]continuous_set_fan) THEN RESA_TAC THEN POP_ASSUM MP_TAC THEN EXPAND_TAC"h1" THEN REWRITE_TAC[REAL_ARITH`h<= max (h:real) (h':real)`] THEN RESA_TAC THEN ASM_SET_TAC[]]; ASM_SET_TAC[]]]]]]]);;
let rw_dart_avoids_fan=
prove(`!(x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3). FAN(x,V,E) /\ {v,w} IN E ==> ?h:real. &1> h /\ h> &0 /\ rw_dart_fan x V E ((x:real^3),(v:real^3),(w:real^3),sigma_fan x V E v w) h SUBSET yfan(x,V,E) `,
REPEAT STRIP_TAC THEN MP_TAC(ISPECL[`(x:real^3)`;`(V:real^3->bool)`;`(E:(real^3->bool)->bool)`;`(E:(real^3->bool)->bool)`;` (v:real^3)`;` (w:real^3)`]finish_avoids1_fan) THEN RESA_TAC THEN POP_ASSUM MP_TAC THEN REWRITE_TAC[SET_RULE`A SUBSET A`;yfan;xfan] THEN RESA_TAC THEN EXISTS_TAC`h:real` THEN ASM_REWRITE_TAC[] THEN ASM_SET_TAC[]);;
(*------------------------------------------------------------------------*) (*------------------------------------------------------------------------*)
let r_fan=new_definition`r_fan (a:real) (b:real) (c:real) = { y:real^3 | y$1 > &0  /\  y$2 > a  /\ y$2 < b /\ y$3 > &0 /\ y$3 < c}`;;
let r1_le_fan=new_definition`r1_le_fan (a:real)={ y:real^3 | y$1 > a}`;;
let r2_le_fan=new_definition`r2_le_fan (a:real)={ y:real^3 |  y$2 > a}`;;
let r3_le_fan=new_definition`r3_le_fan (a:real)={ y:real^3 | y$3 > a}`;;
let r1_ge_fan=new_definition`r1_ge_fan (a:real)={ y:real^3 |  y$1 < a}`;;
let r2_ge_fan=new_definition`r2_ge_fan (a:real)={ y:real^3 |  y$2 < a}`;;
let r3_ge_fan=new_definition`r3_ge_fan (a:real)={ y:real^3 |  y$3 < a}`;;
let r_fan_is_inter_halfspace=
prove(`!a:real b:real c:real. r_fan a b c = r1_le_fan (&0) INTER r2_le_fan a INTER r2_ge_fan b INTER r3_le_fan (&0) INTER r3_ge_fan c`,
let r1_ge_is_convex_fan = 
prove(`!a:real. convex (r1_ge_fan a)/\ open (r1_ge_fan a) `,
let r2_ge_is_convex_fan = 
prove(`!a:real. convex (r2_ge_fan a)/\ open (r2_ge_fan a)`,
let r3_ge_is_convex_fan = 
prove(`!a:real. convex (r3_ge_fan a) /\ open(r3_ge_fan a)`,
let r1_le_is_convex_fan = 
prove(`!a:real. convex (r1_le_fan a)/\ open (r1_le_fan a) `,
let r2_le_is_convex_fan = 
prove(`!a:real. convex (r2_le_fan a)/\ open (r2_le_fan a) `,
let r3_le_is_convex_fan = 
prove(`!a:real. convex (r3_le_fan a)/\ open (r3_le_fan a) `,
let r_is_connected_fan=
prove(`!a:real b:real c:real. connected (r_fan a b c)/\convex (r_fan a b c) /\ open (r_fan a b c)`,
(
let lemma = prove(`!a:real b:real c:real. convex (r_fan a b c)/\ open (r_fan a b c)`,
ASSUME_TAC (r_fan_is_inter_halfspace) THEN ASM_REWRITE_TAC[] THEN
ASSUME_TAC (r1_ge_is_convex_fan) THEN ASSUME_TAC ( r2_ge_is_convex_fan) THEN
ASSUME_TAC (r3_ge_is_convex_fan) THEN ASSUME_TAC(r1_le_is_convex_fan) THEN
ASSUME_TAC(r2_le_is_convex_fan) THEN ASSUME_TAC( r3_le_is_convex_fan) THEN
ASM_MESON_TAC[CONVEX_INTER;OPEN_INTER]) 
    in
SUBGOAL_THEN `!a:real b:real c:real. convex (r_fan a b c)/\ open (r_fan a b c) ` ASSUME_TAC 
THENL [MESON_TAC[lemma];
       ASM_MESON_TAC[CONVEX_CONNECTED]]));;
(*------------------------------------------------------------*) (* change spherical coordinate in fan *) (*------------------------------------------------------------*)
let change_spherical_coordinate_fan= new_definition`change_spherical_coordinate_fan (x:real^3) (v:real^3) (u:real^3) = ((\t. let r = t$1 and theta = t$2 and phi = t$3 in        
           x +(r * cos theta * sin phi) % e1_fan x v u +                       
           (r * sin theta * sin phi) % e2_fan x v u +                          
           (r * cos phi) % e3_fan x v u):real^3->real^3) ` ;;
(*---------------------------------------------------------------------------------------*) (* the function of change coordinate is(spherecial) continuous *) (*---------------------------------------------------------------------------------------*)
let REAL_CONTINUOUS_AT_COMPONENT = 
prove (`!i a. 1 <= i /\ i <= dimindex(:N) ==> (\x:real^N. x$i) real_continuous at a`,
let continuous_change_spherical_coordinate_fan = 
prove (`!x':real^3 v:real^3 u:real^3 x:real^3. ((\t. let r = t$1 and theta = t$2 and phi = t$3 in (r * cos theta * sin phi) % e1_fan x' v u + (r * sin theta * sin phi) % e2_fan x' v u + (r * cos phi) % e3_fan x' v u)) continuous at x`,
REPEAT STRIP_TAC THEN CONV_TAC(TOP_DEPTH_CONV let_CONV) THEN REPEAT(MATCH_MP_TAC CONTINUOUS_ADD THEN CONJ_TAC) THEN MATCH_MP_TAC CONTINUOUS_VMUL THEN REWRITE_TAC[GSYM REAL_CONTINUOUS_CONTINUOUS1] THEN REPEAT(MATCH_MP_TAC REAL_CONTINUOUS_MUL THEN CONJ_TAC) THEN SIMP_TAC[REAL_CONTINUOUS_AT_COMPONENT; DIMINDEX_3; ARITH] THEN MATCH_MP_TAC(REWRITE_RULE[o_DEF] REAL_CONTINUOUS_AT_COMPOSE) THEN SIMP_TAC[REAL_CONTINUOUS_AT_COMPONENT; DIMINDEX_3; ARITH] THEN REWRITE_TAC[REAL_CONTINUOUS_WITHIN_SIN; REAL_CONTINUOUS_WITHIN_COS]);;
let one_edge_fan=
prove(`!x:real^3 (V:real^3->bool) (E:(real^3->bool)->bool) v:real^3 u:real^3. FAN(x,V,E)/\ {v,u} IN E /\ ~(CARD (set_of_edge v V E) > 1) ==> set_of_edge v V E={u}`,
REPEAT STRIP_TAC THEN MP_TAC(ISPECL[`x:real^3 `;`(V:real^3->bool) `;`(E:(real^3->bool)->bool) `;`u:real^3 `;`v:real^3`]remark1_fan) THEN RESA_TAC THEN MP_TAC(SET_RULE`(u:real^3) IN set_of_edge v V E==> ~(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)={})/\ {(u:real^3)} SUBSET set_of_edge v V E`) THEN RESA_TAC THEN MP_TAC(ISPECL [`{(u:real^3)}`;`set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)`] FINITE_SUBSET) THEN RESA_TAC THEN ASSUME_TAC(SET_RULE`u IN {(u:real^3)} /\ {(u:real^3)} DELETE u= {} /\ {} PSUBSET {(u:real^3)}`) THEN MP_TAC(ISPECL[`(u:real^3)`;`{(u:real^3)}`;]CARD_DELETE) THEN RESA_TAC THEN MP_TAC(ISPECL[`{}:real^3->bool`;`{(u:real^3)}`]CARD_PSUBSET) THEN RESA_TAC THEN POP_ASSUM MP_TAC THEN POP_ASSUM(fun th-> REWRITE_TAC[SYM(th)] THEN ASSUME_TAC(th)) THEN POP_ASSUM MP_TAC THEN REWRITE_TAC[CARD_CLAUSES] THEN REPEAT DISCH_TAC THEN MP_TAC(ARITH_RULE` 0 = CARD ({(u:real^3)}) - 1 /\ 0 < CARD ({u}) <=> 1= CARD {u}`) THEN RESA_TAC THEN MP_TAC(ARITH_RULE`~(CARD (set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)) > 1)==> CARD (set_of_edge v V E) <= 1`) THEN RESA_TAC THEN MP_TAC(ISPECL[`{u:real^3}`;`set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)`]CARD_SUBSET_LE) THEN ASM_SET_TAC[]);;
(* azim(x), x dart. *)
let azim_fan=new_definition`azim_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (w:real^3)
= if (CARD (set_of_edge v V E) > 1) then azim x v w (sigma_fan x V E v w) else &2* pi`;;
let expand_elements_by_azim_fan=
prove(`!x:real^3 (V:real^3->bool) (E:(real^3->bool)->bool) v:real^3 u:real^3 x1:real x2:real x3:real. FAN(x,V,E)/\ {v,u} IN E /\ &0 < x1 /\ &0<= x2 /\ x2 < &2 * pi /\ &0< x3 /\ x3 < pi/ &2 ==> azim x v u (x + (x1 * cos (x2) * sin (x3)) % e1_fan x v u + (x1 * sin (x2) * sin (x3)) % e2_fan x v u + (x1 * cos (x3)) % e3_fan x v u) = x2`,
(
let lem=prove(`!x v u. {x,v,u}= {x,u,v}`,SET_TAC[]) in
 (let lem1=prove(`!x v u. {x,v,u}= {v,x,u}`,SET_TAC[]) in

REPEAT STRIP_TAC
THEN MP_TAC(ISPECL[`x:real^3 `;`(V:real^3->bool) `;
`(E:(real^3->bool)->bool)`;` u:real^3`;` v:real^3`]remark1_fan)
THEN RESA_TAC
THEN FIND_ASSUM MP_TAC`~collinear {(x:real^3),(v:real^3),(u:real^3)}`
THEN GEN_REWRITE_TAC( LAND_CONV  o ONCE_DEPTH_CONV)[lem1]
THEN ONCE_REWRITE_TAC[COLLINEAR_3]
THEN RESA_TAC
THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`]orthonormal_e1_e2_e3_fan)
THEN RESA_TAC
THEN POP_ASSUM(fun th-> MP_TAC(th) THEN ASSUME_TAC(th))
THEN REWRITE_TAC[orthonormal]
THEN STRIP_TAC
THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`]properties_coordinate)
THEN RESA_TAC
THEN MP_TAC(ISPEC`x3:real`SIN_POS_PI2)
THEN RESA_TAC
THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`;`(x +
  (x1 * cos (x2) * sin (x3)) % e1_fan x v u +
  (x1 * sin (x2) * sin (x3)) % e2_fan x v u +
  (x1 * cos (x3)) % e3_fan (x:real^3) (v:real^3) (u:real^3))`;
  `((u-x) dot (e3_fan (x:real^3) (v:real^3) (u:real^3))) *inv (norm((v:real^3)-(x:real^3)))`;
  `(x1 * cos (x3)) * (inv (norm((v:real^3)-(x:real^3))))`;
`((u-x) dot (e1_fan (x:real^3) (v:real^3) (u:real^3)))`;
`x1 * sin (x3:real)`;
`e1_fan (x:real^3) (v:real^3) (u:real^3)`;`e2_fan (x:real^3) (v:real^3) (u:real^3)`;`e3_fan (x:real^3) (v:real^3) (u:real^3)`;`&0`;`x2:real`]AZIM_UNIQUE)
THEN DISCH_TAC
THEN POP_ASSUM MATCH_MP_TAC
THEN ASM_REWRITE_TAC[REAL_ARITH`&0+a=a`;]
THEN STRIP_TAC
THENL[
MATCH_MP_TAC REAL_LT_MUL
THEN REPEAT(POP_ASSUM MP_TAC)
THEN REAL_ARITH_TAC;

STRIP_TAC
THENL[

REWRITE_TAC[SIN_0;COS_0;VECTOR_ARITH`(A*B)%C=A%(B%C)`]
THEN REDUCE_ARITH_TAC
THEN REDUCE_VECTOR_TAC
THEN ONCE_REWRITE_TAC[GSYM e3_fan]
THEN MATCH_MP_TAC(ISPECL[`e3_fan (x:real^3) (v:real^3) (u:real^3)`;`(u:real^3)-(x:real^3)`;`
((u - x) dot e1_fan x v u) % (e1_fan (x:real^3) (v:real^3) (u:real^3)) +
 ((u - x) dot e3_fan x v u) % (e3_fan x v u)`]CROSS_DOT_CANCEL)
THEN ASM_REWRITE_TAC[DOT_RADD;DOT_RMUL;DOT_SYM]
THEN REDUCE_ARITH_TAC
THEN REWRITE_TAC[CROSS_RADD;CROSS_RMUL;CROSS_REFL]
THEN REDUCE_VECTOR_TAC
THEN MP_TAC(ISPECL[`e1_fan (x:real^3) (v:real^3) (u:real^3)`;`e2_fan (x:real^3) (v:real^3) (u:real^3)`;`e3_fan (x:real^3) (v:real^3) (u:real^3)`]ORTHONORMAL_CROSS)
THEN RESA_TAC
THEN ASM_REWRITE_TAC[]
THEN REWRITE_TAC[e1_fan]
THEN ONCE_REWRITE_TAC[CROSS_TRIPLE;e2_fan]
THEN REWRITE_TAC[VECTOR_ARITH`A%(B%C)=(B*A)%C`]
THEN ONCE_REWRITE_TAC[DOT_SYM]
THEN ONCE_REWRITE_TAC[GSYM DOT_RMUL]
THEN ONCE_REWRITE_TAC[GSYM e2_fan]
THEN ASM_REWRITE_TAC[]
THEN REDUCE_VECTOR_TAC
THEN STRIP_TAC
THEN FIND_ASSUM MP_TAC`&0<(e1_fan x v u cross e2_fan x v u) dot e3_fan (x:real^3) (v:real^3) (u:real^3)`
THEN POP_ASSUM(fun th-> REWRITE_TAC[th])
THEN REWRITE_TAC[DOT_RZERO]
THEN REAL_ARITH_TAC;
REWRITE_TAC[e3_fan]
THEN VECTOR_ARITH_TAC]])));;
let rw_dart_is_image_set_spherical_coordinate=
prove(`(!x:real^3 (V:real^3->bool) (E:(real^3->bool)->bool) v:real^3 u:real^3 h:real. FAN(x,V,E)/\ {v,u} IN E/\ &0 <h /\ h< pi/ &2 ==> IMAGE (change_spherical_coordinate_fan x v u) (r_fan (azim x v u u) (azim_fan x V E v u) h)= rw_dart_fan x V E ((x:real^3),(v:real^3),(u:real^3),sigma_fan x V E v u) (cos(h))) `,
(
let lem=prove(`!x v u. {x,v,u}= {x,u,v}`,ASM_SET_TAC[]) in
( let lem1=prove(`!x v u. {x,v,u}= {v,x,u}`,SET_TAC[]) in

REWRITE_TAC[azim_fan;r_fan; rw_dart_fan; change_spherical_coordinate_fan;IMAGE;INTER;
w_dart_fan;rcone_fan;EXTENSION;IN_ELIM_THM]
THEN CONV_TAC(TOP_DEPTH_CONV let_CONV) 
THEN REPEAT STRIP_TAC
THEN MP_TAC(ISPECL[`x:real^3 `;`(V:real^3->bool) `;
`(E:(real^3->bool)->bool)`;` u:real^3`;` v:real^3`]remark1_fan)
THEN RESA_TAC
THEN FIND_ASSUM MP_TAC`~collinear {(x:real^3),(v:real^3),(u:real^3)}`
THEN GEN_REWRITE_TAC( LAND_CONV  o ONCE_DEPTH_CONV)[lem1]
THEN ONCE_REWRITE_TAC[COLLINEAR_3]
THEN RESA_TAC
THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`]orthonormal_e1_e2_e3_fan)
THEN RESA_TAC
THEN POP_ASSUM(fun th-> MP_TAC(th) THEN ASSUME_TAC(th))
THEN REWRITE_TAC[orthonormal]
THEN STRIP_TAC
THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`]properties_coordinate)
THEN RESA_TAC
THEN EQ_TAC
THENL(*1*)[
STRIP_TAC
THEN MP_TAC(ISPEC`(x'':real^3)$3`SIN_POS_PI2)
THEN RESA_TAC
THEN ONCE_REWRITE_TAC[SET_RULE`A /\ B <=> B /\ A`]
THEN STRIP_TAC
THENL(*2*)[




REWRITE_TAC[dist;vector_norm;VECTOR_ARITH`(A+B)-A=(B:real^3)`; DOT_LADD;DOT_RADD;DOT_RMUL;DOT_LMUL;]
THEN ONCE_REWRITE_TAC[DOT_SYM]
THEN ASM_REWRITE_TAC[]
THEN REDUCE_ARITH_TAC
THEN ONCE_REWRITE_TAC[DOT_SYM]
THEN ASM_REWRITE_TAC[]
THEN REDUCE_ARITH_TAC
THEN REWRITE_TAC[REAL_ARITH`((x'':real^3)$1 * cos (x''$2) * sin (x''$3)) * x''$1 * cos (x''$2) * sin (x''$3) +
  (x''$1 * sin (x''$2) * sin (x''$3)) * x''$1 * sin (x''$2) * sin (x''$3) +
  (x''$1 * cos (x''$3)) * x''$1 * cos (x''$3)=(x''$1 * x''$1)* (( sin (x''$2) pow 2 +(cos (x''$2) pow 2)) * (sin (x''$3) pow 2)+ cos (x''$3) pow 2)`]
THEN ASSUME_TAC(ISPEC`(x'':real^3)$2`SIN_CIRCLE)
THEN ASM_REWRITE_TAC[]
THEN REDUCE_ARITH_TAC
THEN ASSUME_TAC(ISPEC`(x'':real^3)$3`SIN_CIRCLE)
THEN ASM_REWRITE_TAC[]
THEN REDUCE_ARITH_TAC
THEN MP_TAC(ISPEC`(x'':real^3)$1`SQRT_POW_2)
THEN MP_TAC(REAL_ARITH`(x'':real^3)$1> &0==> &0 <= (x'':real^3)$1`)
THEN RESA_TAC
THEN RESA_TAC
THEN MP_TAC(ISPECL[`(x'':real^3)$1`;`(x'':real^3)$1`]SQRT_MUL)
THEN RESA_TAC
THEN REWRITE_TAC[REAL_ARITH`A*(A:real)=A pow 2`]
THEN ASM_REWRITE_TAC[e3_fan;DOT_LMUL]
THEN ONCE_REWRITE_TAC[GSYM vector_norm;]
THEN ASSUME_TAC(ISPEC`(v:real^3)-(x:real^3)`DOT_SQUARE_NORM)
THEN POP_ASSUM (fun th-> REWRITE_TAC[th])
THEN REWRITE_TAC[REAL_ARITH`(A*B)*C *D pow 2=A*D*B *(C*D)`]
THEN SUBGOAL_THEN`~(norm((v:real^3)-(x:real^3))= &0)` ASSUME_TAC
THENL(*3*)[

ASM_REWRITE_TAC[NORM_EQ_0;VECTOR_ARITH`v-x=vec 0<=> x=v`];(*3*)	

MP_TAC(ISPEC`norm((v:real^3)-(x:real^3))`REAL_MUL_LINV)
THEN RESA_TAC
THEN ASM_REWRITE_TAC[]
THEN REDUCE_ARITH_TAC
THEN MP_TAC(ISPEC`((v:real^3)-(x:real^3))`NORM_POS_LT)
THEN ASM_REWRITE_TAC[VECTOR_ARITH`v-x=vec 0<=> x=v`;REAL_ARITH`A>B<=> B<A`]
THEN DISCH_TAC
THEN MATCH_MP_TAC REAL_LT_LMUL
THEN ASM_REWRITE_TAC[REAL_ARITH`&0 < A<=> A> &0`]
THEN MATCH_MP_TAC REAL_LT_LMUL
THEN ASM_REWRITE_TAC[]
THEN MATCH_MP_TAC COS_MONO_LT
THEN REPEAT(POP_ASSUM MP_TAC)
THEN REAL_ARITH_TAC];(*2*)



SUBGOAL_THEN`azim (x:real^3) (v:real^3) (u:real^3)
 (x +
  (x''$1 * cos (x''$2) * sin (x''$3)) % e1_fan x v u +
  (x''$1 * sin (x''$2) * sin (x''$3)) % e2_fan x v u +
  (x''$1 * cos (x''$3)) % e3_fan x v u)= (x'':real^3)$2 ` ASSUME_TAC
THENL(*3*)[

MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`;`(x +
  (x''$1 * cos (x''$2) * sin (x''$3)) % e1_fan x v u +
  (x''$1 * sin (x''$2) * sin ((x'':real^3)$3)) % e2_fan x v u +
  (x''$1 * cos (x''$3)) % e3_fan (x:real^3) (v:real^3) (u:real^3))`;
  `((u-x) dot (e3_fan (x:real^3) (v:real^3) (u:real^3))) *inv (norm((v:real^3)-(x:real^3)))`;
  `(x''$1 * cos ((x'':real^3)$3)) * (inv (norm((v:real^3)-(x:real^3))))`;
`((u-x) dot (e1_fan (x:real^3) (v:real^3) (u:real^3)))`;
`x''$1 * sin ((x'':real^3)$3)`;
`e1_fan (x:real^3) (v:real^3) (u:real^3)`;`e2_fan (x:real^3) (v:real^3) (u:real^3)`;`e3_fan (x:real^3) (v:real^3) (u:real^3)`;`&0`;`(x'':real^3)$2`]AZIM_UNIQUE)
THEN DISCH_TAC
THEN POP_ASSUM MATCH_MP_TAC
THEN ASM_REWRITE_TAC[REAL_ARITH`&0+a=a`;]
THEN STRIP_TAC
THENL(*4*)[

MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`;]AZIM_REFL)
THEN REPEAT(POP_ASSUM MP_TAC)
THEN REAL_ARITH_TAC;(*4*)

STRIP_TAC
THENL(*5*)[

MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`;`sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3)`] azim)
THEN REPEAT(POP_ASSUM MP_TAC)
THEN REAL_ARITH_TAC;(*5*)

STRIP_TAC
THENL(*6*)[

MATCH_MP_TAC REAL_LT_MUL
THEN REPEAT(POP_ASSUM MP_TAC)
THEN REAL_ARITH_TAC;(*6*)

STRIP_TAC
THENL(*7*)[

REWRITE_TAC[SIN_0;COS_0;VECTOR_ARITH`(A*B)%C=A%(B%C)`]
THEN REDUCE_ARITH_TAC
THEN REDUCE_VECTOR_TAC
THEN ONCE_REWRITE_TAC[GSYM e3_fan]
THEN MATCH_MP_TAC(ISPECL[`e3_fan (x:real^3) (v:real^3) (u:real^3)`;`(u:real^3)-(x:real^3)`;`
((u - x) dot e1_fan x v u) % (e1_fan (x:real^3) (v:real^3) (u:real^3)) +
 ((u - x) dot e3_fan x v u) % (e3_fan x v u)`]CROSS_DOT_CANCEL)
THEN ASM_REWRITE_TAC[DOT_RADD;DOT_RMUL;DOT_SYM]
THEN REDUCE_ARITH_TAC
THEN REWRITE_TAC[CROSS_RADD;CROSS_RMUL;CROSS_REFL]
THEN REDUCE_VECTOR_TAC
THEN MP_TAC(ISPECL[`e1_fan (x:real^3) (v:real^3) (u:real^3)`;`e2_fan (x:real^3) (v:real^3) (u:real^3)`;`e3_fan (x:real^3) (v:real^3) (u:real^3)`]ORTHONORMAL_CROSS)
THEN RESA_TAC
THEN ASM_REWRITE_TAC[]
THEN REWRITE_TAC[e1_fan]
THEN ONCE_REWRITE_TAC[CROSS_TRIPLE;e2_fan]
THEN REWRITE_TAC[VECTOR_ARITH`A%(B%C)=(B*A)%C`]
THEN ONCE_REWRITE_TAC[DOT_SYM]
THEN ONCE_REWRITE_TAC[GSYM DOT_RMUL]
THEN ONCE_REWRITE_TAC[GSYM e2_fan]
THEN ASM_REWRITE_TAC[]
THEN REDUCE_VECTOR_TAC
THEN STRIP_TAC
THEN FIND_ASSUM MP_TAC`&0<(e1_fan x v u cross e2_fan x v u) dot e3_fan (x:real^3) (v:real^3) (u:real^3)`
THEN POP_ASSUM(fun th-> REWRITE_TAC[th])
THEN REWRITE_TAC[DOT_RZERO]
THEN REAL_ARITH_TAC;(*7*)

REWRITE_TAC[e3_fan]
THEN VECTOR_ARITH_TAC](*7*)](*6*)](*5*)](*4*);(*3*)




SUBGOAL_THEN`~collinear
  {(x:real^3), (v:real^3), x +
         (x''$1 * cos (x''$2) * sin (x''$3)) % e1_fan x v (u:real^3) +
         (x''$1 * sin (x''$2) * sin ((x'':real^3)$3)) % e2_fan x v u +
         (x''$1 * cos (x''$3)) % e3_fan x v u}`ASSUME_TAC
THENL(*4*)[

ONCE_REWRITE_TAC[lem]
THEN REWRITE_TAC[collinear1_fan]
THEN ASM_REWRITE_TAC[aff;AFFINE_HULL_2; IN_ELIM_THM; REAL_ARITH`A+B= &1<=>A= &1-B`]
THEN STRIP_TAC
THEN POP_ASSUM MP_TAC
THEN POP_ASSUM (fun th-> REWRITE_TAC[th])
THEN REWRITE_TAC[VECTOR_ARITH`A+B=(&1-c) % A+ c % D<=>B=c%(D-A)`]
THEN STRIP_TAC
THEN SUBGOAL_THEN`((x''$1 * cos (x''$2) * sin (x''$3)) % e1_fan x v u +
      (x''$1 * sin (x''$2) * sin (x''$3)) % e2_fan x v u +
      (x''$1 * cos ((x'':real^3)$3)) % e3_fan x v (u:real^3)) dot e1_fan x v u =
      ((v':real) % ((v:real^3) - (x:real^3))) dot e1_fan x v u` ASSUME_TAC
THENL(*5*)[
ASM_REWRITE_TAC[];(*5*)

POP_ASSUM MP_TAC
THEN REWRITE_TAC[DOT_LADD;DOT_LMUL]
THEN ASM_REWRITE_TAC[DOT_SYM]
THEN REDUCE_ARITH_TAC
THEN SUBGOAL_THEN`((x''$1 * cos (x''$2) * sin (x''$3)) % e1_fan x v u +
      (x''$1 * sin (x''$2) * sin (x''$3)) % e2_fan x v u +
      (x''$1 * cos ((x'':real^3)$3)) % e3_fan x v (u:real^3)) dot e2_fan x v u =
      ((v':real) % ((v:real^3) - (x:real^3))) dot e2_fan x v u` ASSUME_TAC
THENL(*6*)[
ASM_REWRITE_TAC[];(*6*)

POP_ASSUM MP_TAC
THEN REWRITE_TAC[DOT_LADD;DOT_LMUL]
THEN ASM_REWRITE_TAC[DOT_SYM]
THEN REDUCE_ARITH_TAC
THEN REWRITE_TAC[REAL_ENTIRE]
THEN STRIP_TAC
THENL(*7*)[

REPEAT (POP_ASSUM MP_TAC)
THEN REAL_ARITH_TAC;(*7*)

STRIP_TAC
THENL(*8*)[

REPEAT (POP_ASSUM MP_TAC)
THEN REAL_ARITH_TAC;(*8*)


MP_TAC(ISPEC`(x'':real^3)$2`SIN_CIRCLE)
THEN ASM_REWRITE_TAC[]
THEN REAL_ARITH_TAC;

REPEAT (POP_ASSUM MP_TAC)
THEN REAL_ARITH_TAC];

REPEAT (POP_ASSUM MP_TAC)
THEN REAL_ARITH_TAC](*7*)](*6*)](*5*);(*4*)


REPEAT(POP_ASSUM MP_TAC)
THEN DISJ_CASES_TAC(ARITH_RULE`CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))>1 
\/ ~(CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)) >1)`)
THENL(*5*)[
ASM_REWRITE_TAC[]
THEN REPEAT STRIP_TAC
THEN REWRITE_TAC[wedge;IN_ELIM_THM]
THEN ASM_REWRITE_TAC[]
THEN POP_ASSUM (fun th-> REWRITE_TAC[th])
THEN ASM_REWRITE_TAC[]
THEN FIND_ASSUM MP_TAC`(x'':real^3)$2 > azim (x:real^3) (v:real^3) u (u:real^3)`
THEN REWRITE_TAC[AZIM_REFL]
THEN REAL_ARITH_TAC;(*5*)

	
ASM_REWRITE_TAC[]
THEN REPEAT STRIP_TAC
THEN ONCE_REWRITE_TAC[GSYM EXTENSION]
THEN MP_TAC(ISPECL[`x:real^3`;`(V:real^3->bool)`;`(E:(real^3->bool)->bool)`;`v:real^3`;` u:real^3`]one_edge_fan)
THEN RESA_TAC
THEN REWRITE_TAC[DIFF;IN_ELIM_THM]
THEN STRIP_TAC
THENL(*6*)[

ASM_SET_TAC[];(*6*)

STRIP_TAC
THEN  MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`;`(x:real^3) +
  (x''$1 * cos (x''$2) * sin ((x'':real^3)$3)) % e1_fan x (v:real^3) (u:real^3) +
  (x''$1 * sin (x''$2) * sin (x''$3)) % e2_fan x v u +
  (x''$1 * cos (x''$3)) % e3_fan x v u`]AZIM_EQ_0_GE_ALT)
THEN RESA_TAC
THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`;]AZIM_REFL)
THEN REPEAT(POP_ASSUM MP_TAC)
THEN REAL_ARITH_TAC](*6*)](*5*)](*4*)](*3*)](*2*);(*1*)



ONCE_REWRITE_TAC[GSYM EXTENSION]
THEN DISJ_CASES_TAC(ARITH_RULE`CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool))>1 
\/ ~(CARD(set_of_edge (v:real^3) (V:real^3->bool) (E:(real^3->bool)->bool)) >1)`)
THENL(*2*)[
ASM_REWRITE_TAC[wedge;IN_ELIM_THM]
THEN STRIP_TAC
THEN POP_ASSUM MP_TAC 
THEN DISCH_THEN(LABEL_TAC"A")
THEN EXISTS_TAC`vector[(dist((x:real^3),(x':real^3)));(azim (x:real^3) (v:real^3) (u:real^3) (x':real^3));(arcV (x:real^3) (x':real^3) (v:real^3))]:real^3`
THEN ASM_REWRITE_TAC[VECTOR_3;AZIM_REFL;REAL_ARITH`A> &0 <=> &0 <A`]
THEN SUBGOAL_THEN `~((x:real^3)=(x':real^3))` ASSUME_TAC
THENL(*3*)[


 STRIP_TAC
THEN REMOVE_THEN "A" MP_TAC
THEN ASM_REWRITE_TAC[DIST_REFL;VECTOR_ARITH`A-A= vec 0`;DOT_LZERO]
THEN REDUCE_ARITH_TAC
THEN REAL_ARITH_TAC;(*3*)


MP_TAC(ISPECL[`x:real^3`;`x':real^3`]DIST_EQ_0)
THEN RESA_TAC
THEN ASSUME_TAC(ISPECL[`x:real^3`;`x':real^3`]DIST_POS_LE)
THEN MP_TAC(REAL_ARITH`~(dist((x:real^3),(x':real^3))= &0)/\ &0 <= dist((x:real^3),(x':real^3))==> &0 < dist((x:real^3),(x':real^3))`)
THEN RESA_TAC
THEN ASM_REWRITE_TAC[]
THEN STRIP_TAC
THENL(*4*)[
STRIP_TAC
THENL(*5*)[

REWRITE_TAC[ARCV_ANGLE; angle;]
THEN MP_TAC(ISPECL[`((x':real^3) - (x:real^3)) `;`((v:real^3) - (x:real^3))`]VECTOR_ANGLE_RANGE)
THEN STRIP_TAC
THEN MP_TAC(ISPECL[`((x':real^3) - (x:real^3)) `;`((v:real^3) - (x:real^3))`]COLLINEAR_VECTOR_ANGLE)
THEN ASM_REWRITE_TAC[VECTOR_ARITH`A-B= vec 0<=> B=A`;]
THEN ONCE_REWRITE_TAC[GSYM COLLINEAR_3;]
THEN ONCE_REWRITE_TAC[SET_RULE`{A,B,C}={B,C,A}`]
THEN DISCH_TAC
THEN FIND_ASSUM MP_TAC `~collinear {(x:real^3),(v:real^3),(x':real^3)}`
THEN POP_ASSUM (fun th-> REWRITE_TAC[th])
THEN REWRITE_TAC[DE_MORGAN_THM]
THEN REPEAT(POP_ASSUM MP_TAC)
THEN REAL_ARITH_TAC;(*5*)

MP_TAC(ISPECL[`v:real^3`;`x:real^3`]DIST_EQ_0)
THEN RESA_TAC
THEN ASSUME_TAC(ISPECL[`v:real^3`;`x:real^3`]DIST_POS_LE)
THEN MP_TAC(REAL_ARITH`~(dist((v:real^3),(x:real^3))= &0)/\ &0 <= dist((v:real^3),(x:real^3))==> &0 < dist((v:real^3),(x:real^3))`)
THEN RESA_TAC
THEN MP_TAC(ISPECL[`x':real^3`;`x:real^3`]DIST_EQ_0)
THEN RESA_TAC
THEN ASSUME_TAC(ISPECL[`x':real^3`;`x:real^3`]DIST_POS_LE)
THEN MP_TAC(REAL_ARITH`~(dist((x':real^3),(x:real^3))= &0)/\ &0 <= dist((x':real^3),(x:real^3))==> &0 < dist((x':real^3),(x:real^3))`)
THEN RESA_TAC
THEN MP_TAC(ISPECL[`dist ((v:real^3),(x:real^3)) * cos (h:real)`;`((x':real^3) - x) dot ((v:real^3) - (x:real^3))`; `dist((x':real^3),(x:real^3))`]REAL_LT_RDIV_EQ)
THEN RESA_TAC
THEN MP_TAC(ISPECL[`cos (h:real)`;`(((x':real^3) - x) dot ((v:real^3) - (x:real^3)) )/ dist ((x':real^3),(x:real^3)) `; `dist((v:real^3),(x:real^3))`]REAL_LT_RDIV_EQ)
THEN ASM_REWRITE_TAC[]
THEN ONCE_REWRITE_TAC[REAL_ARITH`A*B=B*A`]
THEN ASM_REWRITE_TAC[]
THEN ONCE_REWRITE_TAC[REAL_ARITH`(A*B)*C =C* A*B`]
THEN REWRITE_TAC[REAL_ARITH`A<B <=> B>A`;]
THEN ASM_REWRITE_TAC[real_div;REAL_ARITH`(A*B)*C =A*(B *C)`]
THEN ONCE_REWRITE_TAC[GSYM REAL_INV_MUL;]
THEN ONCE_REWRITE_TAC[GSYM real_div;]
THEN REWRITE_TAC[dist;arcV]
THEN STRIP_TAC
THEN MP_TAC(REAL_ARITH`&0 < (h:real) /\ h< pi/ &2==> &0<= h /\ h<=pi`)
THEN RESA_TAC
THEN MP_TAC(ISPEC`h:real`ACS_COS)
THEN RESA_TAC
THEN MP_TAC(ISPECL[`cos (h:real)`;`(((x':real^3) - x) dot ((v:real^3) - (x:real^3))) / (norm (x' - x) * norm (v - x))` ;]ACS_MONO_LT)
THEN RESA_TAC
THEN REWRITE_TAC[REAL_ARITH`A>B<=> B<A`]
THEN POP_ASSUM MATCH_MP_TAC
THEN REWRITE_TAC[COS_BOUNDS]
THEN ASM_REWRITE_TAC[REAL_ARITH`A<B<=> B>A`]
THEN MP_TAC(ISPECL[`(x':real^3)-(x:real^3)`;`(v:real^3)-(x:real^3)`]NORM_CAUCHY_SCHWARZ_DIV)
THEN MP_TAC(ISPEC`(((x':real^3)-(x:real^3)) dot ((v:real^3)-(x:real^3))) / (norm (x' - x) * norm (v - x))`REAL_ABS_LE)
THEN REAL_ARITH_TAC](*5*);(*4*)


MATCH_MP_TAC(ISPECL[`u:real^3`;`x:real^3`;`v:real^3`;`x':real^3`;`e1_fan (x:real^3) (v:real^3) (u:real^3)`;
`e2_fan (x:real^3) (v:real^3) (u:real^3)`;`e3_fan (x:real^3) (v:real^3) (u:real^3)`;`dist((x:real^3),(x':real^3))`;`arcV (x:real^3) (x':real^3) (v:real^3)`;`azim (x:real^3) (v:real^3) (u:real^3) (x':real^3)`]SPHERICAL_COORDINATES)
THEN ASM_REWRITE_TAC[]
THEN SUBGOAL_THEN`azim x v u (x+e1_fan (x:real^3) (v:real^3) (u:real^3))= &0` ASSUME_TAC
THENL(*5*)[

MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`;`x + e1_fan (x:real^3) (v:real^3) (u:real^3)`;
  `((u-x) dot (e3_fan (x:real^3) (v:real^3) (u:real^3))) *inv (norm((v:real^3)-(x:real^3)))`;
  `&0`;
`((u-x) dot (e1_fan (x:real^3) (v:real^3) (u:real^3)))`;`&1`;
`e1_fan (x:real^3) (v:real^3) (u:real^3)`;`e2_fan (x:real^3) (v:real^3) (u:real^3)`;`e3_fan (x:real^3) (v:real^3) (u:real^3)`;`&0`;`&0`]AZIM_UNIQUE)
THEN DISCH_TAC
THEN POP_ASSUM MATCH_MP_TAC
THEN ASM_REWRITE_TAC[REAL_ARITH`&0+a=a`;REAL_ARITH`&0<= &0/\ &0 < &1`]
THEN STRIP_TAC
THENL(*6*)[
MP_TAC(PI_WORKS)
THEN REAL_ARITH_TAC;(*6*)

STRIP_TAC
THENL(*7*)[

REWRITE_TAC[SIN_0;COS_0;VECTOR_ARITH`(A*B)%C=A%(B%C)`]
THEN REDUCE_ARITH_TAC
THEN REDUCE_VECTOR_TAC
THEN ONCE_REWRITE_TAC[GSYM e3_fan]
THEN MATCH_MP_TAC(ISPECL[`e3_fan (x:real^3) (v:real^3) (u:real^3)`;`(u:real^3)-(x:real^3)`;`
((u - x) dot e1_fan x v u) % (e1_fan (x:real^3) (v:real^3) (u:real^3)) +
 ((u - x) dot e3_fan x v u) % (e3_fan x v u)`]CROSS_DOT_CANCEL)
THEN ASM_REWRITE_TAC[DOT_RADD;DOT_RMUL;DOT_SYM]
THEN REDUCE_ARITH_TAC
THEN REWRITE_TAC[CROSS_RADD;CROSS_RMUL;CROSS_REFL]
THEN REDUCE_VECTOR_TAC
THEN MP_TAC(ISPECL[`e1_fan (x:real^3) (v:real^3) (u:real^3)`;`e2_fan (x:real^3) (v:real^3) (u:real^3)`;`e3_fan (x:real^3) (v:real^3) (u:real^3)`]ORTHONORMAL_CROSS)
THEN RESA_TAC
THEN ASM_REWRITE_TAC[]
THEN REWRITE_TAC[e1_fan]
THEN ONCE_REWRITE_TAC[CROSS_TRIPLE;e2_fan]
THEN REWRITE_TAC[VECTOR_ARITH`A%(B%C)=(B*A)%C`]
THEN ONCE_REWRITE_TAC[DOT_SYM]
THEN ONCE_REWRITE_TAC[GSYM DOT_RMUL]
THEN ONCE_REWRITE_TAC[GSYM e2_fan]
THEN ASM_REWRITE_TAC[]
THEN REDUCE_VECTOR_TAC
THEN STRIP_TAC
THEN FIND_ASSUM MP_TAC`&0<(e1_fan x v u cross e2_fan x v u) dot e3_fan (x:real^3) (v:real^3) (u:real^3)`
THEN POP_ASSUM(fun th-> REWRITE_TAC[th])
THEN REWRITE_TAC[DOT_RZERO]
THEN REAL_ARITH_TAC;(*7*)

REWRITE_TAC[SIN_0;COS_0]
THEN REDUCE_ARITH_TAC
THEN REDUCE_VECTOR_TAC
THEN VECTOR_ARITH_TAC](*7*)](*6*);(*5*)


MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`;`x + e1_fan (x:real^3) (v:real^3) (u:real^3)`]AZIM_EQ_0_ALT)
THEN RESA_TAC
THEN POP_ASSUM MATCH_MP_TAC
THEN ONCE_REWRITE_TAC[SET_RULE`{A,B,C}={B,A,C}`]
THEN ONCE_REWRITE_TAC[COLLINEAR_3]
THEN REWRITE_TAC[ VECTOR_ARITH`((A:real^3)+(B:real^3))-A=B`;]
THEN ONCE_REWRITE_TAC[GSYM DOT_CAUCHY_SCHWARZ_EQUAL]
THEN ASM_REWRITE_TAC[REAL_ARITH`&0 pow 2= &0`;REAL_ARITH `A=B:real <=> B=A`]
THEN REDUCE_ARITH_TAC
THEN ASM_REWRITE_TAC[DOT_EQ_0;VECTOR_ARITH`A-B=vec 0<=> A=B:real^3`]](*5*)](*4*)](*3*);(*2*)







ASM_REWRITE_TAC[]
THEN ONCE_REWRITE_TAC[GSYM EXTENSION]
THEN MP_TAC(ISPECL[`x:real^3`;`(V:real^3->bool)`;`(E:(real^3->bool)->bool)`;`v:real^3`;` u:real^3`]one_edge_fan)
THEN RESA_TAC
THEN REWRITE_TAC[DIFF;IN_ELIM_THM]
THEN STRIP_TAC
THEN POP_ASSUM MP_TAC 
THEN DISCH_THEN(LABEL_TAC"A")
THEN EXISTS_TAC`vector[(dist((x:real^3),(x':real^3)));(azim (x:real^3) (v:real^3) (u:real^3) (x':real^3));(arcV (x:real^3) (x':real^3) (v:real^3))]:real^3`
THEN ASM_REWRITE_TAC[VECTOR_3;AZIM_REFL;REAL_ARITH`A> &0 <=> &0 <A`]
THEN SUBGOAL_THEN `~((x:real^3)=(x':real^3))` ASSUME_TAC
THENL(*3*)[

STRIP_TAC
THEN REMOVE_THEN "A" MP_TAC
THEN ASM_REWRITE_TAC[DIST_REFL;VECTOR_ARITH`A-A= vec 0`;DOT_LZERO]
THEN REDUCE_ARITH_TAC
THEN REAL_ARITH_TAC;(*3*)

MP_TAC(ISPECL[`x:real^3`;`x':real^3`]DIST_EQ_0)
THEN RESA_TAC
THEN ASSUME_TAC(ISPECL[`x:real^3`;`x':real^3`]DIST_POS_LE)
THEN MP_TAC(REAL_ARITH`~(dist((x:real^3),(x':real^3))= &0)/\ &0 <= dist((x:real^3),(x':real^3))==> &0 < dist((x:real^3),(x':real^3))`)
THEN RESA_TAC
THEN ASM_REWRITE_TAC[azim]
THEN SUBGOAL_THEN`~collinear{(x:real^3),(v:real^3),(x':real^3)}` ASSUME_TAC
THENL(*4*)[

POP_ASSUM (fun th-> REWRITE_TAC[])
THEN POP_ASSUM (fun th-> REWRITE_TAC[])
THEN POP_ASSUM (fun th-> REWRITE_TAC[])
THEN POP_ASSUM (fun th-> REWRITE_TAC[])
THEN POP_ASSUM (fun th-> REWRITE_TAC[])
THEN POP_ASSUM MP_TAC
THEN DISCH_THEN(LABEL_TAC"MA")
THEN ONCE_REWRITE_TAC[lem1]
THEN ASM_REWRITE_TAC[COLLINEAR_3;COLLINEAR_LEMMA;VECTOR_ARITH`v-x=vec 0<=> v=x`]
THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`]AFF_GE_2_1)
THEN RESA_TAC
THEN STRIP_TAC
THENL(*5*)[

REMOVE_THEN "MA" MP_TAC
THEN ASM_REWRITE_TAC[IN_ELIM_THM]
THEN EXISTS_TAC`&1`
THEN EXISTS_TAC`&0`
THEN EXISTS_TAC`&0`
THEN REDUCE_ARITH_TAC
THEN REDUCE_VECTOR_TAC
THEN REAL_ARITH_TAC;(*5*)

REMOVE_THEN "MA" MP_TAC
THEN ASM_REWRITE_TAC[IN_ELIM_THM]
THEN EXISTS_TAC`&1- (c:real)`
THEN EXISTS_TAC`c:real`
THEN EXISTS_TAC`&0`
THEN REDUCE_ARITH_TAC
THEN REDUCE_VECTOR_TAC
THEN ASM_REWRITE_TAC[VECTOR_ARITH`(x':real^3)=(&1 - (c:real)) % (x:real^3)+ c % (v:real^3)<=>x'-x=c%(v-x)`]
THEN REAL_ARITH_TAC](*5*);(*4*)



STRIP_TAC
THENL(*5*)[
STRIP_TAC
THENL(*6*)[

MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`;`x':real^3`]AZIM_EQ_0_GE_ALT)
THEN ASM_REWRITE_TAC[]
THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`;`x':real^3`]azim)
THEN REAL_ARITH_TAC;(*6*)


STRIP_TAC
THENL(*7*)[

REWRITE_TAC[ARCV_ANGLE; angle;]
THEN MP_TAC(ISPECL[`((x':real^3) - (x:real^3)) `;`((v:real^3) - (x:real^3))`]VECTOR_ANGLE_RANGE)
THEN STRIP_TAC
THEN MP_TAC(ISPECL[`((x':real^3) - (x:real^3)) `;`((v:real^3) - (x:real^3))`]COLLINEAR_VECTOR_ANGLE)
THEN ASM_REWRITE_TAC[VECTOR_ARITH`A-B= vec 0<=> B=A`;]
THEN ONCE_REWRITE_TAC[GSYM COLLINEAR_3;]
THEN ONCE_REWRITE_TAC[SET_RULE`{A,B,C}={B,C,A}`]
THEN DISCH_TAC
THEN FIND_ASSUM MP_TAC `~collinear {(x:real^3),(v:real^3),(x':real^3)}`
THEN POP_ASSUM (fun th-> REWRITE_TAC[th])
THEN REWRITE_TAC[DE_MORGAN_THM]
THEN REPEAT(POP_ASSUM MP_TAC)
THEN REAL_ARITH_TAC;(*7*)

MP_TAC(ISPECL[`v:real^3`;`x:real^3`]DIST_EQ_0)
THEN RESA_TAC
THEN ASSUME_TAC(ISPECL[`v:real^3`;`x:real^3`]DIST_POS_LE)
THEN MP_TAC(REAL_ARITH`~(dist((v:real^3),(x:real^3))= &0)/\ &0 <= dist((v:real^3),(x:real^3))==> &0 < dist((v:real^3),(x:real^3))`)
THEN RESA_TAC
THEN MP_TAC(ISPECL[`x':real^3`;`x:real^3`]DIST_EQ_0)
THEN RESA_TAC
THEN ASSUME_TAC(ISPECL[`x':real^3`;`x:real^3`]DIST_POS_LE)
THEN MP_TAC(REAL_ARITH`~(dist((x':real^3),(x:real^3))= &0)/\ &0 <= dist((x':real^3),(x:real^3))==> &0 < dist((x':real^3),(x:real^3))`)
THEN RESA_TAC
THEN MP_TAC(ISPECL[`dist ((v:real^3),(x:real^3)) * cos (h:real)`;`((x':real^3) - x) dot ((v:real^3) - (x:real^3))`; `dist((x':real^3),(x:real^3))`]REAL_LT_RDIV_EQ)
THEN RESA_TAC
THEN MP_TAC(ISPECL[`cos (h:real)`;`(((x':real^3) - x) dot ((v:real^3) - (x:real^3)) )/ dist ((x':real^3),(x:real^3)) `; `dist((v:real^3),(x:real^3))`]REAL_LT_RDIV_EQ)
THEN ASM_REWRITE_TAC[]
THEN ONCE_REWRITE_TAC[REAL_ARITH`A*B=B*A`]
THEN ASM_REWRITE_TAC[]
THEN ONCE_REWRITE_TAC[REAL_ARITH`(A*B)*C =C* A*B`]
THEN REWRITE_TAC[REAL_ARITH`A<B <=> B>A`;]
THEN ASM_REWRITE_TAC[real_div;REAL_ARITH`(A*B)*C =A*(B *C)`]
THEN ONCE_REWRITE_TAC[GSYM REAL_INV_MUL;]
THEN ONCE_REWRITE_TAC[GSYM real_div;]
THEN REWRITE_TAC[dist;arcV]
THEN STRIP_TAC
THEN MP_TAC(REAL_ARITH`&0 < (h:real) /\ h< pi/ &2==> &0<= h /\ h<=pi`)
THEN RESA_TAC
THEN MP_TAC(ISPEC`h:real`ACS_COS)
THEN RESA_TAC
THEN MP_TAC(ISPECL[`cos (h:real)`;`(((x':real^3) - x) dot ((v:real^3) - (x:real^3))) / (norm (x' - x) * norm (v - x))` ;]ACS_MONO_LT)
THEN RESA_TAC
THEN REWRITE_TAC[REAL_ARITH`A>B<=> B<A`]
THEN POP_ASSUM MATCH_MP_TAC
THEN REWRITE_TAC[COS_BOUNDS]
THEN ASM_REWRITE_TAC[REAL_ARITH`A<B<=> B>A`]
THEN MP_TAC(ISPECL[`(x':real^3)-(x:real^3)`;`(v:real^3)-(x:real^3)`]NORM_CAUCHY_SCHWARZ_DIV)
THEN MP_TAC(ISPEC`(((x':real^3)-(x:real^3)) dot ((v:real^3)-(x:real^3))) / (norm (x' - x) * norm (v - x))`REAL_ABS_LE)
THEN REAL_ARITH_TAC](*7*)](*6*);(*5*)

MATCH_MP_TAC(ISPECL[`u:real^3`;`x:real^3`;`v:real^3`;`x':real^3`;`e1_fan (x:real^3) (v:real^3) (u:real^3)`;
`e2_fan (x:real^3) (v:real^3) (u:real^3)`;`e3_fan (x:real^3) (v:real^3) (u:real^3)`;`dist((x:real^3),(x':real^3))`;`arcV (x:real^3) (x':real^3) (v:real^3)`;`azim (x:real^3) (v:real^3) (u:real^3) (x':real^3)`]SPHERICAL_COORDINATES)
THEN ASM_REWRITE_TAC[]
THEN SUBGOAL_THEN`azim x v u (x+e1_fan (x:real^3) (v:real^3) (u:real^3))= &0` ASSUME_TAC
THENL(*6*)[

MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`;`x + e1_fan (x:real^3) (v:real^3) (u:real^3)`;
  `((u-x) dot (e3_fan (x:real^3) (v:real^3) (u:real^3))) *inv (norm((v:real^3)-(x:real^3)))`;
  `&0`;
`((u-x) dot (e1_fan (x:real^3) (v:real^3) (u:real^3)))`;`&1`;
`e1_fan (x:real^3) (v:real^3) (u:real^3)`;`e2_fan (x:real^3) (v:real^3) (u:real^3)`;`e3_fan (x:real^3) (v:real^3) (u:real^3)`;`&0`;`&0`]AZIM_UNIQUE)
THEN DISCH_TAC
THEN POP_ASSUM MATCH_MP_TAC
THEN ASM_REWRITE_TAC[REAL_ARITH`&0+a=a`;REAL_ARITH`&0<= &0/\ &0 < &1`]
THEN STRIP_TAC
THENL(*7*)[
MP_TAC(PI_WORKS)
THEN REAL_ARITH_TAC;(*7*)

STRIP_TAC
THENL(*8*)[

REWRITE_TAC[SIN_0;COS_0;VECTOR_ARITH`(A*B)%C=A%(B%C)`]
THEN REDUCE_ARITH_TAC
THEN REDUCE_VECTOR_TAC
THEN ONCE_REWRITE_TAC[GSYM e3_fan]
THEN MATCH_MP_TAC(ISPECL[`e3_fan (x:real^3) (v:real^3) (u:real^3)`;`(u:real^3)-(x:real^3)`;`
((u - x) dot e1_fan x v u) % (e1_fan (x:real^3) (v:real^3) (u:real^3)) +
 ((u - x) dot e3_fan x v u) % (e3_fan x v u)`]CROSS_DOT_CANCEL)
THEN ASM_REWRITE_TAC[DOT_RADD;DOT_RMUL;DOT_SYM]
THEN REDUCE_ARITH_TAC
THEN REWRITE_TAC[CROSS_RADD;CROSS_RMUL;CROSS_REFL]
THEN REDUCE_VECTOR_TAC
THEN MP_TAC(ISPECL[`e1_fan (x:real^3) (v:real^3) (u:real^3)`;`e2_fan (x:real^3) (v:real^3) (u:real^3)`;`e3_fan (x:real^3) (v:real^3) (u:real^3)`]ORTHONORMAL_CROSS)
THEN RESA_TAC
THEN ASM_REWRITE_TAC[]
THEN REWRITE_TAC[e1_fan]
THEN ONCE_REWRITE_TAC[CROSS_TRIPLE;e2_fan]
THEN REWRITE_TAC[VECTOR_ARITH`A%(B%C)=(B*A)%C`]
THEN ONCE_REWRITE_TAC[DOT_SYM]
THEN ONCE_REWRITE_TAC[GSYM DOT_RMUL]
THEN ONCE_REWRITE_TAC[GSYM e2_fan]
THEN ASM_REWRITE_TAC[]
THEN REDUCE_VECTOR_TAC
THEN STRIP_TAC
THEN FIND_ASSUM MP_TAC`&0<(e1_fan x v u cross e2_fan x v u) dot e3_fan (x:real^3) (v:real^3) (u:real^3)`
THEN POP_ASSUM(fun th-> REWRITE_TAC[th])
THEN REWRITE_TAC[DOT_RZERO]
THEN REAL_ARITH_TAC;(*8*)

REWRITE_TAC[SIN_0;COS_0]
THEN REDUCE_ARITH_TAC
THEN REDUCE_VECTOR_TAC
THEN VECTOR_ARITH_TAC](*8*)](*7*);(*6*)


MP_TAC(ISPECL[`x:real^3`;`v:real^3`;`u:real^3`;`x + e1_fan (x:real^3) (v:real^3) (u:real^3)`]AZIM_EQ_0_ALT)
THEN RESA_TAC
THEN POP_ASSUM MATCH_MP_TAC
THEN ONCE_REWRITE_TAC[SET_RULE`{A,B,C}={B,A,C}`]
THEN ONCE_REWRITE_TAC[COLLINEAR_3]
THEN REWRITE_TAC[ VECTOR_ARITH`((A:real^3)+(B:real^3))-A=B`;]
THEN ONCE_REWRITE_TAC[GSYM DOT_CAUCHY_SCHWARZ_EQUAL]
THEN ASM_REWRITE_TAC[REAL_ARITH`&0 pow 2= &0`;REAL_ARITH `A=B:real <=> B=A`]
THEN REDUCE_ARITH_TAC
THEN ASM_REWRITE_TAC[DOT_EQ_0;VECTOR_ARITH`A-B=vec 0<=> A=B:real^3`]](*6*)](*5*)](*4*)](*3*)](*2*)](*1*))));;
let connected_rw_dart_fan=
prove(`!x:real^3 (V:real^3->bool) (E:(real^3->bool)->bool) v:real^3 u:real^3 h:real. FAN(x,V,E)/\ {v,u} IN E/\ &0 <h /\ h< pi/ &2 ==>connected(rw_dart_fan x V E ((x:real^3),(v:real^3),(u:real^3),sigma_fan x V E v u) (cos(h)))`,
REPEAT STRIP_TAC THEN MP_TAC(ISPECL[`x:real^3`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool) `;`v:real^3`; ` u:real^3` ;`h:real`]rw_dart_is_image_set_spherical_coordinate) THEN RESA_TAC THEN ASM_REWRITE_TAC[] THEN ASSUME_TAC(ISPECL[`(azim (x:real^3) (v:real^3) (u:real^3) u)`; `(azim_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3)) `;`h:real`] r_is_connected_fan) THEN MP_TAC(ISPECL[`change_spherical_coordinate_fan (x:real^3) (v:real^3) (u:real^3)`;`r_fan (azim x v u u) (azim_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3)) (h:real)`]CONTINUOUS_ON_EQ_CONTINUOUS_AT) THEN RESA_TAC THEN MP_TAC(ISPECL[`change_spherical_coordinate_fan (x:real^3) (v:real^3) (u:real^3)`;`r_fan (azim x v u u) (azim_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3)) (h:real)`] CONNECTED_CONTINUOUS_IMAGE) THEN RESA_TAC THEN POP_ASSUM MATCH_MP_TAC THEN GEN_TAC THEN STRIP_TAC THEN MP_TAC(ISPECL[`x:real^3`;`v:real^3`; `u:real^3`;`x':real^3`]continuous_change_spherical_coordinate_fan) THEN REWRITE_TAC[change_spherical_coordinate_fan] THEN CONV_TAC(TOP_DEPTH_CONV let_CONV) THEN DISCH_TAC THEN MATCH_MP_TAC CONTINUOUS_ADD THEN ASM_REWRITE_TAC[] THEN SIMP_TAC[CONTINUOUS_CONST]);;
let not_empty_rw_dart_fan=
prove(`!x:real^3 (V:real^3->bool) (E:(real^3->bool)->bool) v:real^3 u:real^3. FAN(x,V,E)/\ {v,u} IN E ==> (!h:real. &0<h /\ h< pi/ &2 ==> ~(rw_dart_fan x V E ((x:real^3),(v:real^3),(u:real^3),sigma_fan x V E v u) (cos(h))={}))`,
REPEAT STRIP_TAC THEN MRESA_TAC remark1_fan[`x:real^3 `;`(V:real^3->bool) `;`(E:(real^3->bool)->bool)`;` u:real^3`;`v:real^3`] THEN MRESA_TAC rw_dart_is_image_set_spherical_coordinate[`x:real^3`;`(V:real^3->bool)`;`(E:(real^3->bool)->bool)`;`v:real^3`;`u:real^3`;`h:real`] THEN POP_ASSUM MP_TAC THEN REWRITE_TAC[IMAGE_EQ_EMPTY;r_fan;EXTENSION;IN_ELIM_THM;IN;EMPTY;NOT_FORALL_THM;AZIM_REFL;azim_fan] THEN DISJ_CASES_TAC(ARITH_RULE`~(CARD (set_of_edge (v:real^3) V E) > 1)\/ CARD (set_of_edge v V E) > 1`) THENL[ ASM_REWRITE_TAC[] THEN EXISTS_TAC`vector[&1; pi; h/ &2]:real^3` THEN SIMP_TAC[CART_EQ; DIMINDEX_3; FORALL_3; VEC_COMPONENT; VECTOR_3; ARITH] THEN MP_TAC PI_WORKS THEN ASM_TAC THEN REAL_ARITH_TAC; ASM_REWRITE_TAC[] THEN DISJ_CASES_TAC(SET_RULE`(set_of_edge v V E = {u:real^3})\/ ~(set_of_edge v V E = {u})`) THENL[ MRESA_TAC CARD_SING[`u:real^3`; `(set_of_edge v V E):real^3->bool`] THEN FIND_ASSUM MP_TAC `CARD ((set_of_edge v V E):real^3->bool) >1` THEN POP_ASSUM MP_TAC THEN POP_ASSUM (fun TH-> REWRITE_TAC[TH]) THEN ARITH_TAC; DISJ_CASES_TAC(REAL_ARITH `(azim (x:real^3) (v:real^3) (u:real^3) (sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3))= &0) \/ ~(azim (x:real^3) (v:real^3) (u:real^3) (sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3)) = &0)`) THENL[ MRESA_TAC SIGMA_FAN[`(x:real^3)`;` (V:real^3->bool)`;`(E:(real^3->bool)->bool)`;`(v:real^3)`;`(u:real^3)`] THEN MRESA_TAC UNIQUE_AZIM_0_POINT_FAN[`(x:real^3)`;` (V:real^3->bool)`;` (E:(real^3->bool)->bool)`;` (v:real^3)`;` (u:real^3)`;`(sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3))`] THEN MRESA_TAC remark1_fan[`x:real^3 `;`(V:real^3->bool) `;`(E:(real^3->bool)->bool)`;`(sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3))`;`v:real^3`]; MRESA_TAC azim[`(x:real^3)`;` (v:real^3)`;` (u:real^3)`;`(sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3))`] THEN EXISTS_TAC`vector[&1; (azim x v u ((sigma_fan (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3))))/ &2;h/ &2]:real^3` THEN SIMP_TAC[CART_EQ; DIMINDEX_3; FORALL_3; VEC_COMPONENT; VECTOR_3; ARITH] THEN ASM_TAC THEN REAL_ARITH_TAC]]]);;
let JGIYDLE=
prove(`!x:real^3 (V:real^3->bool) (E:(real^3->bool)->bool) v:real^3 u:real^3. FAN(x,V,E)/\ {v,u} IN E ==> (!h:real. &0<h /\ h< pi/ &2 ==> ~(rw_dart_fan x V E ((x:real^3),(v:real^3),(u:real^3),sigma_fan x V E v u) (cos(h))={})) /\(!h:real h1:real. h1 <= h ==> (rw_dart_fan x V E ((x:real^3),(v:real^3),(u:real^3),sigma_fan x V E v u) h SUBSET rw_dart_fan x V E ((x:real^3),(v:real^3),(u:real^3),sigma_fan x V E v u) h1)) /\ (?h:real. &1> h /\ h> &0 /\ rw_dart_fan x V E ((x:real^3),(v:real^3),(u:real^3),sigma_fan x V E v u) h SUBSET yfan(x,V,E)) /\ (!h:real. &0 <h /\ h< pi/ &2 ==> connected(rw_dart_fan x V E ((x:real^3),(v:real^3),(u:real^3),sigma_fan x V E v u) (cos(h))))`,
(****************************************************************************) (****************************LEADS INTO**************************************) (****************************************************************************)
let dart_leads_into=new_definition`dart_leads_into (x:real^3) (V:real^3->bool) (E:(real^3->bool)->bool) (v:real^3) (u:real^3)= 
@(U:real^3->bool). ?h:real. &0<h /\
(!(s:real) (y:real^3). &0 <s /\ s<h
/\ y IN rw_dart_fan x V E ((x:real^3),(v:real^3),(u:real^3),sigma_fan x V E v u) (cos(s))
==> (rw_dart_fan x V E ((x:real^3),(v:real^3),(u:real^3),sigma_fan x V E v u) (cos(s)) SUBSET U /\  connected_component (yfan(x,V,E)) y=U))`;;
let exists_leads_into_fan=
prove(`!x:real^3 (V:real^3->bool) (E:(real^3->bool)->bool) v:real^3 u:real^3. FAN(x,V,E)/\ {v,u} IN E ==> ?(U:real^3->bool). ?h:real. &0<h /\ (!(s:real) (y:real^3). &0 <s /\ s<h /\ y IN rw_dart_fan x V E ((x:real^3),(v:real^3),(u:real^3),sigma_fan x V E v u) (cos(s)) ==> (rw_dart_fan x V E ((x:real^3),(v:real^3),(u:real^3),sigma_fan x V E v u) (cos(s)) SUBSET U /\ connected_component (yfan(x,V,E)) y=U))`,
REPEAT STRIP_TAC THEN MRESA_TAC JGIYDLE[`x:real^3`;`(V:real^3->bool)`;`(E:(real^3->bool)->bool)`;`v:real^3`;`u:real^3`] THEN ASM_TAC THEN DISCH_TAC THEN DISCH_TAC THEN DISCH_THEN (LABEL_TAC "BE") THEN DISCH_THEN (LABEL_TAC "YEU") THEN DISCH_TAC THEN DISCH_TAC THEN DISCH_THEN (LABEL_TAC "EM") THEN DISCH_THEN (LABEL_TAC "NHIEU") THEN MP_TAC(REAL_ARITH`h> &0/\ &1>h ==> -- &1< (h:real)/\ -- &1<= (h:real) /\ h< &1 /\ &0 <h /\ h<= &1`) THEN RESA_TAC THEN MRESA1_TAC ACS_BOUNDS_LT`h:real` THEN REMOVE_ASSUM_TAC THEN MRESAL_TAC ACS_MONO_LT[`&0`;`h:real`][ACS_0;REAL_ARITH`-- &1 <= &0`] THEN MRESA1_TAC COS_ACS `h:real` THEN REMOVE_THEN "BE" (fun th-> MRESA1_TAC th `acs(h:real)`) THEN POP_ASSUM MP_TAC THEN GEN_REWRITE_TAC(LAND_CONV o ONCE_DEPTH_CONV)[EXTENSION] THEN REWRITE_TAC[EMPTY;IN;NOT_FORALL_THM] THEN STRIP_TAC THEN POP_ASSUM MP_TAC THEN GEN_REWRITE_TAC(LAND_CONV o ONCE_DEPTH_CONV)[GSYM IN] THEN STRIP_TAC THEN ONCE_REWRITE_TAC[GSYM FUN_EQ_THM] THEN EXISTS_TAC`(connected_component (yfan((x:real^3),(V:real^3->bool) ,(E:(real^3->bool)->bool))) (x':real^3)):real^3->bool` THEN EXISTS_TAC`acs(h:real)` THEN ASM_REWRITE_TAC[] THEN REPEAT GEN_TAC THEN STRIP_TAC THEN POP_ASSUM MP_TAC THEN GEN_REWRITE_TAC(LAND_CONV o ONCE_DEPTH_CONV)[GSYM IN] THEN DISCH_TAC THEN ASSUME_TAC(PI_WORKS) THEN MP_TAC(REAL_ARITH` &0< s /\ acs (h:real)< pi/ &2 /\ &0< pi ==> &0<= (s:real)/\ acs h<= pi`) THEN RESA_TAC THEN MRESAL_TAC COS_MONO_LT[`s:real`;`acs(h:real)`][] THEN MP_TAC(REAL_ARITH` h< cos(s:real)==>h<= cos(s:real)`) THEN RESA_TAC THEN REMOVE_THEN "NHIEU"(fun th-> MRESA1_TAC th `acs(h:real)`) THEN REMOVE_THEN "YEU" (fun th-> MRESA_TAC th[`cos(s:real)`;`h:real`]) THEN MRESA_TAC CONNECTED_COMPONENT_MAXIMAL [`yfan(x:real^3,(V:real^3->bool),(E:(real^3->bool)->bool))`;`rw_dart_fan x V E ((x:real^3),(v:real^3),(u:real^3),sigma_fan x V E v u) (h:real)`;`x':real^3`] THEN STRIP_TAC THENL[ POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN SET_TAC[]; MATCH_MP_TAC CONNECTED_COMPONENT_EQ THEN ASM_TAC THEN SET_TAC[]]);;
let DART_LEADS_INTO=
prove(`!x:real^3 (V:real^3->bool) (E:(real^3->bool)->bool) v:real^3 u:real^3. FAN(x,V,E)/\ {v,u} IN E ==> ?h:real. &0<h /\ (!(s:real) (y:real^3). &0 <s /\ s<h /\ y IN rw_dart_fan x V E ((x:real^3),(v:real^3),(u:real^3),sigma_fan x V E v u) (cos(s)) ==> (rw_dart_fan x V E ((x:real^3),(v:real^3),(u:real^3),sigma_fan x V E v u) (cos(s)) SUBSET dart_leads_into x V E v u /\ connected_component (yfan(x,V,E)) y=dart_leads_into x V E v u))`,
REPEAT STRIP_TAC THEN ONCE_REWRITE_TAC[dart_leads_into] THEN MRESA_TAC exists_leads_into_fan[`x:real^3`;`(V:real^3->bool)`;`(E:(real^3->bool)->bool)`;`v:real^3`;` u:real^3`] THEN SELECT_ELIM_TAC THEN EXISTS_TAC`U:real^3->bool` THEN EXISTS_TAC`h:real` THEN ASM_REWRITE_TAC[]);;
let unique_dart_leads_into=
prove(`!x:real^3 (V:real^3->bool) (E:(real^3->bool)->bool) v:real^3 u:real^3 (U:real^3->bool). FAN(x,V,E)/\ {v,u} IN E /\(?h:real. &0<h /\ (!(s:real) (y:real^3). &0 <s /\ s<h /\ y IN rw_dart_fan x V E ((x:real^3),(v:real^3),(u:real^3),sigma_fan x V E v u) (cos(s)) ==> (rw_dart_fan x V E ((x:real^3),(v:real^3),(u:real^3),sigma_fan x V E v u) (cos(s)) SUBSET U /\ connected_component (yfan(x,V,E)) y=U))) ==> dart_leads_into x V E v u =U`,
REPEAT STRIP_TAC THEN POP_ASSUM MP_TAC THEN DISCH_THEN (LABEL_TAC"A") THEN MRESA_TAC DART_LEADS_INTO [`x:real^3`;`(V:real^3->bool)`;`(E:(real^3->bool)->bool)`;`v:real^3`;`u:real^3`] THEN POP_ASSUM MP_TAC THEN DISCH_THEN (LABEL_TAC "BE") THEN MRESA_TAC JGIYDLE[`x:real^3`;`(V:real^3->bool)`;`(E:(real^3->bool)->bool)`;`v:real^3`;`u:real^3`] THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN POP_ASSUM MP_TAC THEN DISCH_THEN (LABEL_TAC "YEU") THEN DISCH_THEN (LABEL_TAC "EM") THEN DISCH_TAC THEN DISCH_TAC THEN DISCH_TAC THEN DISCH_THEN (LABEL_TAC "MAI") THEN ASSUME_TAC(PI_WORKS) THEN MP_TAC(REAL_ARITH`&0<h /\ &0<h' /\ &0 <pi==> -- &1< (min (min (h:real) (h':real)/ &2) (pi/ &3)) /\ -- &1<= (min (min (h:real) (h':real)/ &2) (pi/ &3)) /\ (min (min (h:real) (h':real)/ &2) (pi/ &3))< pi/ &2 /\ &0 <(min (min (h:real) (h':real)/ &2) (pi/ &3)) /\ (min (min (h:real) (h':real)/ &2) (pi/ &3))<= pi/ &2 /\ (min (min (h:real) (h':real)/ &2) (pi/ &3))< h /\ (min (min (h:real) (h':real)/ &2) (pi/ &3))< h' `) THEN RESA_TAC THEN REMOVE_THEN "YEU" (fun th-> MRESA1_TAC th ` (min (min (h:real) (h':real)/ &2) (pi/ &3))`) THEN POP_ASSUM MP_TAC THEN GEN_REWRITE_TAC(LAND_CONV o ONCE_DEPTH_CONV)[EXTENSION] THEN REWRITE_TAC[EMPTY;IN;NOT_FORALL_THM] THEN STRIP_TAC THEN POP_ASSUM MP_TAC THEN GEN_REWRITE_TAC(LAND_CONV o ONCE_DEPTH_CONV)[GSYM IN] THEN STRIP_TAC THEN ONCE_REWRITE_TAC[GSYM FUN_EQ_THM] THEN REMOVE_THEN "BE" (fun th-> MRESA_TAC th[`(min ((min (h:real) (h':real))/ &2) (pi/ &3))`;`x':real^3`]) THEN POP_ASSUM MP_TAC THEN REMOVE_THEN "A" (fun th-> MRESA_TAC th[`(min ((min (h:real) (h':real))/ &2) (pi/ &3))`;`x':real^3`]) THEN POP_ASSUM MP_TAC THEN SET_TAC[]);;
let dart_leads_into_fan_in_topological_component_yfan=
prove(`!x:real^3 (V:real^3->bool) (E:(real^3->bool)->bool) v:real^3 u:real^3. FAN(x,V,E)/\ {v,u} IN E ==> dart_leads_into x V E v u IN topological_component_yfan (x,V,E)`,
REPEAT STRIP_TAC THEN MRESA_TAC not_empty_rw_dart_fan[`x:real^3`;`(V:real^3->bool)`;`(E:(real^3->bool)->bool)`;`v:real^3`;`u:real^3`] THEN POP_ASSUM MP_TAC THEN DISCH_THEN(LABEL_TAC"EM") THEN MRESA_TAC DART_LEADS_INTO[`x:real^3`;`(V:real^3->bool)`;`(E:(real^3->bool)->bool)`; `v:real^3`;`u:real^3`;] THEN POP_ASSUM MP_TAC THEN DISCH_THEN(LABEL_TAC"YEU") THEN MRESA_TAC rw_dart_avoids_fan[`(x:real^3)`;`(V:real^3->bool)`;`(E:(real^3->bool)->bool)`;`v:real^3`;`u:real^3`] THEN POP_ASSUM MP_TAC THEN DISCH_THEN(LABEL_TAC"OI") THEN MP_TAC(REAL_ARITH`&1> h' /\ h' > &0==> -- &1 < h' /\ h'< &1 /\ -- &1 <= h' /\ h'<= &1/\ &0 < h' /\ h' <= &1`) THEN RESA_TAC THEN MRESA1_TAC ACS_BOUNDS_LT`h':real` THEN MRESAL_TAC ACS_MONO_LT[`&0`;`h':real`][ACS_0;REAL_ARITH`-- &1 <= &0`] THEN MRESA1_TAC COS_ACS `h':real` THEN ABBREV_TAC`h1= min (h:real) (acs h')/ &2` THEN MP_TAC(REAL_ARITH`h1= min (h:real) (acs h')/ &2 /\ &0<h /\ &0< acs h' /\ acs h'< pi/ &2==> &0< h1 /\ h1< h /\ h1<pi/ &2/\ h1< acs h' /\ acs h' <= pi /\ &0<= h1`) THEN ASM_REWRITE_TAC[PI_WORKS] THEN STRIP_TAC THEN MRESAL_TAC COS_MONO_LT[`h1:real`;`acs h':real`][ACS_0;REAL_ARITH`-- &1 <= &0`] THEN MP_TAC(REAL_ARITH`h'< cos h1==> h'<= cos h1`) THEN RESA_TAC THEN REMOVE_THEN "EM"(fun th-> MRESAL1_TAC th `h1:real`[SET_RULE`~(A={})<=> ?y. y IN A`]) THEN REMOVE_THEN "YEU"(fun th-> MRESA_TAC th [`h1:real`;`y:real^3`]) THEN POP_ASSUM(fun th -> REWRITE_TAC[SYM(th);IN_ELIM_THM;topological_component_yfan;]) THEN EXISTS_TAC`y:real^3` THEN ASM_REWRITE_TAC[] THEN MRESA_TAC continuous_set_fan[`(x:real^3)`;`(V:real^3->bool)`;`(E:(real^3->bool)->bool)`;`v:real^3`;`u:real^3`;`(cos h1:real)`;`(h':real)`] THEN ASM_TAC THEN SET_TAC[]);;
let in_topological_component_yfan_is_connected=
prove(`!x:real^3 (V:real^3->bool) (E:(real^3->bool)->bool) U:real^3->bool. U IN topological_component_yfan (x,V,E) ==> connected U`,
REWRITE_TAC[topological_component_yfan;IN_ELIM_THM] THEN REPEAT STRIP_TAC THEN ASM_REWRITE_TAC[CONNECTED_CONNECTED_COMPONENT]);;
let connected_dart_leads_into_fan=
prove(`!x:real^3 (V:real^3->bool) (E:(real^3->bool)->bool) v:real^3 u:real^3. FAN(x,V,E)/\ {v,u} IN E ==> connected(dart_leads_into x V E v u )`,
REPEAT STRIP_TAC THEN MRESA_TAC dart_leads_into_fan_in_topological_component_yfan[`x:real^3`;`(V:real^3->bool)`;` (E:(real^3->bool)->bool)`;`v:real^3`;`u:real^3`] THEN MATCH_MP_TAC in_topological_component_yfan_is_connected THEN EXISTS_TAC`x:real^3` THEN EXISTS_TAC`V:real^3->bool` THEN EXISTS_TAC`E:(real^3->bool)->bool` THEN ASM_REWRITE_TAC[]);;
end;;