(*
2009 definitions.
*)
(* ------------------------------------------------------------------ *)
(* ------------------------------------------------------------------ *)
(* This polynomial is essentially the Cayley-Menger determinant. *)
(* ------------------------------------------------------------------ *)
let delta_x = kepler_def (`delta_x x1 x2 x3 x4 x5 x6 =
x1*x4*(--x1 + x2 + x3 -x4 + x5 + x6) +
x2*x5*(x1 - x2 + x3 + x4 -x5 + x6) +
x3*x6*(x1 + x2 - x3 + x4 + x5 - x6)
-x2*x3*x4 - x1*x3*x5 - x1*x2*x6 -x4*x5*x6`);;
(* ------------------------------------------------------------------ *)
(* The partial derivative of delta_x with respect to x4. *)
(* ------------------------------------------------------------------ *)
let delta_x4 = kepler_def(`delta_x4 x1 x2 x3 x4 x5 x6
= -- x2* x3 - x1* x4 + x2* x5
+ x3* x6 - x5* x6 + x1* (-- x1 + x2 + x3 - x4 + x5 + x6)`);;
let delta_x6 = kepler_def(`delta_x6 x1 x2 x3 x4 x5 x6
= -- x1 * x2 - x3*x6 + x1 * x4
+ x2* x5 - x4* x5 + x3*(-- x3 + x1 + x2 - x6 + x4 + x5)`);;
(* ------------------------------------------------------------------ *)
(* Circumradius . *)
(* ------------------------------------------------------------------ *)
(* same as ups_x
let u_x = kepler_def(
`u_x x1 x2 x3 = (--(x1*x1+x2*x2+x3*x3)) +
(&2) * (x1*x2+x2*x3+x3*x1)`);;
*)
let ups_x = kepler_def(`ups_x x1 x2 x6 =
--x1*x1 - x2*x2 - x6*x6
+ &2 *x1*x6 + &2 *x1*x2 + &2 *x2*x6`);;
let eta_x = kepler_def(`eta_x x1 x2 x3 =
(sqrt ((x1*x2*x3)/(ups_x x1 x2 x3)))
`);;
let eta_y = kepler_def(`eta_y y1 y2 y3 =
let x1 = y1*y1 in
let x2 = y2*y2 in
let x3 = y3*y3 in
eta_x x1 x2 x3`);;
let rho_x = kepler_def(`rho_x x1 x2 x3 x4 x5 x6 =
--x1*x1*x4*x4 - x2*x2*x5*x5 - x3*x3*x6*x6 +
(&2)*x1*x2*x4*x5 + (&2)*x1*x3*x4*x6 + (&2)*x2*x3*x5*x6`);;
let rad2_y = kepler_def(`rad2_y y1 y2 y3 y4 y5 y6 =
let (x1,x2,x3,x4,x5,x6)= (y1*y1,y2*y2,y3*y3,y4*y4,y5*y5,y6*y6) in
(rho_x x1 x2 x3 x4 x5 x6)/((delta_x x1 x2 x3 x4 x5 x6)*(&4))`);;
let chi_x = kepler_def(`chi_x x1 x2 x3 x4 x5 x6
= -- (x1*x4*x4) + x1*x4*x5 + x2*x4*x5 - x2*x5*x5
+ x1*x4*x6 + x3*x4*x6 +
x2*x5*x6 + x3*x5*x6 - (&2) * x4*x5*x6 - x3*x6*x6`);;
(* ------------------------------------------------------------------ *)
(* The formula for the dihedral angle of a simplex. *)
(* The variables xi are the squares of the lengths of the edges. *)
(* The angle is computed along the first edge (x1). *)
(* ------------------------------------------------------------------ *)
let dih_x = kepler_def(`dih_x x1 x2 x3 x4 x5 x6 =
let d_x4 = delta_x4 x1 x2 x3 x4 x5 x6 in
let d = delta_x x1 x2 x3 x4 x5 x6 in
pi/ (&2) + atn2( (sqrt ((&4) * x1 * d)),-- d_x4)`);;
let dih_y = kepler_def(`dih_y y1 y2 y3 y4 y5 y6 =
let (x1,x2,x3,x4,x5,x6)= (y1*y1,y2*y2,y3*y3,y4*y4,y5*y5,y6*y6) in
dih_x x1 x2 x3 x4 x5 x6`);;
let dih2_y = kepler_def(`dih2_y y1 y2 y3 y4 y5 y6 =
dih_y y2 y1 y3 y5 y4 y6`);;
let dih3_y = kepler_def(`dih3_y y1 y2 y3 y4 y5 y6 =
dih_y y3 y1 y2 y6 y4 y5`);;
let dih2_x = kepler_def(`dih2_x x1 x2 x3 x4 x5 x6 =
dih_x x2 x1 x3 x5 x4 x6`);;
let dih3_x = kepler_def(`dih3_x x1 x2 x3 x4 x5 x6 =
dih_x x3 x1 x2 x6 x4 x5`);;
(* ------------------------------------------------------------------ *)
(* Harriot-Euler formula for the area of a spherical triangle *)
(* in terms of the angles: area = alpha+beta+gamma - pi *)
(* ------------------------------------------------------------------ *)
let sol_x = kepler_def(`sol_x x1 x2 x3 x4 x5 x6 =
(dih_x x1 x2 x3 x4 x5 x6) +
(dih_x x2 x3 x1 x5 x6 x4) + (dih_x x3 x1 x2 x6 x4 x5) - pi`);;
let sol_y = kepler_def(`sol_y y1 y2 y3 y4 y5 y6 =
(dih_y y1 y2 y3 y4 y5 y6) +
(dih_y y2 y3 y1 y5 y6 y4) + (dih_y y3 y1 y2 y6 y4 y5) - pi`);;
(* ------------------------------------------------------------------ *)
(* The Cayley-Menger formula for the volume of a simplex *)
(* The variables xi are the squares of the lengths of the edges. *)
(* ------------------------------------------------------------------ *)
let vol_x = kepler_def(`vol_x x1 x2 x3 x4 x5 x6 =
(sqrt (delta_x x1 x2 x3 x4 x5 x6))/ (&12)`);;
(* ------------------------------------------------------------------ *)
(* Some lower dimensional funcions and Rogers simplices. *)
(* ------------------------------------------------------------------ *)
let arclength = kepler_def(`arclength a b c =
pi/(&2) + (atn2( (sqrt (ups_x (a*a) (b*b) (c*c))),(c*c - a*a -b*b)))`);;
let volR = kepler_def(`volR a b c =
(sqrt (a*a*(b*b-a*a)*(c*c-b*b)))/(&6)`);;
let solR = kepler_def(`solR a b c =
(&2)*atn2( sqrt(((c+b)*(b+a))), sqrt ((c-b)*(b-a)))`);;
let dihR = kepler_def(`dihR a b c =
atn2( sqrt(b*b-a*a),sqrt (c*c-b*b))`);;
let vorR = kepler_def(`vorR a b c =
(&4)*(--doct*(volR a b c) + (solR a b c)/(&3))`);;
let rad2_x = kepler_def(`rad2_x x1 x2 x3 x4 x5 x6 =
(rho_x x1 x2 x3 x4 x5 x6)/((delta_x x1 x2 x3 x4 x5 x6)*(&4))`);;
(* deprecated:
let d3 = new_definition `d3 (v:real^3) w = dist(v,w)`;;
let mk_vec3 = new_definition `mk_vec3 a b c = vector[a; b; c]`;;
let real3_of_triple = new_definition `real3_of_triple (a,b,c) = (mk_vec3 a b c):real^3`;;
let triple_of_real3 = new_definition `triple_of_real3 (v:real^3) =
(v$1, v$2, v$3)`;;
*)
(* aff is deprecated *)
(* conv is deprecated. Use `convex hull S` instead *)
(* WMJHKBL *)
(* TIWZVEW *)
(* XCJABYH *)
(* XPLPHNG *)
(* circumradius *)
(* EOBLRCS *)
(* ANGLE *)
let dihV = new_definition `dihV w0 w1 w2 w3 =
let va = w2 - w0 in
let vb = w3 - w0 in
let vc = w1 - w0 in
let vap = ( vc dot vc) % va - ( va dot vc) % vc in
let vbp = ( vc dot vc) % vb - ( vb dot vc) % vc in
arcV (vec 0) vap vbp`;;
(* polar coordinates *)
let iter_spec = prove(`?iter. !f u:A. (iter 0 f u = u) /\ (!n. (iter (SUC n) f u = f(iter n f u)))`,
(SUBGOAL_THEN `?g. !f (u:A). (g f u 0 = u) /\ (!n. (g f u (SUC n) = f (g f u n)))` CHOOSE_TAC) THENL
([REWRITE_TAC[GSYM
SKOLEM_THM;
num_RECURSION_STD];REWRITE_TAC[]]) THEN
(EXISTS_TAC `\ (i:num) (f:A->A) (u:A). (g f u i):A`) THEN
(BETA_TAC) THEN
(ASM_REWRITE_TAC[]));;
(* spherical coordinates *)
(* ------------------------------------------------------------------ *)
(* Definitions from the Collection in Elementary Geometry *)
(* ------------------------------------------------------------------ *)
(* EDSFZOT *)
let cayleyR = new_definition `cayleyR x12 x13 x14 x15 x23 x24 x25 x34 x35 x45 =
-- (x14*x14*x23*x23) + &2 *x14*x15*x23*x23 - x15*x15*x23*x23 + &2 *x13*x14*x23*x24 - &2 *x13*x15*x23*x24 - &2 *x14*x15*x23*x24 +
&2 *x15*x15*x23*x24 - x13*x13*x24*x24 + &2 *x13*x15*x24*x24 - x15*x15*x24*x24 - &2 *x13*x14*x23*x25 +
&2 *x14*x14*x23*x25 + &2 *x13*x15*x23*x25 - &2 *x14*x15*x23*x25 + &2 *x13*x13*x24*x25 - &2 *x13*x14*x24*x25 - &2 *x13*x15*x24*x25 +
&2 *x14*x15*x24*x25 - x13*x13*x25*x25 + &2 *x13*x14*x25*x25 - x14*x14*x25*x25 + &2 *x12*x14*x23*x34 - &2 *x12*x15*x23*x34 -
&2 *x14*x15*x23*x34 + &2 *x15*x15*x23*x34 + &2 *x12*x13*x24*x34 - &2 *x12*x15*x24*x34 - &2 *x13*x15*x24*x34 + &2 *x15*x15*x24*x34 +
&4 *x15*x23*x24*x34 - &2 *x12*x13*x25*x34 - &2 *x12*x14*x25*x34 + &4 *x13*x14*x25*x34 + &4 *x12*x15*x25*x34 - &2 *x13*x15*x25*x34 - &2 *x14*x15*x25*x34 -
&2 *x14*x23*x25*x34 - &2 *x15*x23*x25*x34 - &2 *x13*x24*x25*x34 - &2 *x15*x24*x25*x34 + &2 *x13*x25*x25*x34 + &2 *x14*x25*x25*x34 -
x12*x12*x34*x34 + &2 *x12*x15*x34*x34 - x15*x15*x34*x34 + &2 *x12*x25*x34*x34 + &2 *x15*x25*x34*x34 -
x25*x25*x34*x34 - &2 *x12*x14*x23*x35 + &2 *x14*x14*x23*x35 + &2 *x12*x15*x23*x35 - &2 *x14*x15*x23*x35 - &2 *x12*x13*x24*x35 +
&4 *x12*x14*x24*x35 - &2 *x13*x14*x24*x35 - &2 *x12*x15*x24*x35 + &4 *x13*x15*x24*x35 - &2 *x14*x15*x24*x35 - &2 *x14*x23*x24*x35 - &2 *x15*x23*x24*x35 +
&2 *x13*x24*x24*x35 + &2 *x15*x24*x24*x35 + &2 *x12*x13*x25*x35 - &2 *x12*x14*x25*x35 - &2 *x13*x14*x25*x35 + &2 *x14*x14*x25*x35 +
&4 *x14*x23*x25*x35 - &2 *x13*x24*x25*x35 - &2 *x14*x24*x25*x35 + &2 *x12*x12*x34*x35 - &2 *x12*x14*x34*x35 - &2 *x12*x15*x34*x35 +
&2 *x14*x15*x34*x35 - &2 *x12*x24*x34*x35 - &2 *x15*x24*x34*x35 - &2 *x12*x25*x34*x35 - &2 *x14*x25*x34*x35 + &2 *x24*x25*x34*x35 -
x12*x12*x35*x35 + &2 *x12*x14*x35*x35 - x14*x14*x35*x35 + &2 *x12*x24*x35*x35 + &2 *x14*x24*x35*x35 -
x24*x24*x35*x35 + &4 *x12*x13*x23*x45 - &2 *x12*x14*x23*x45 - &2 *x13*x14*x23*x45 - &2 *x12*x15*x23*x45 - &2 *x13*x15*x23*x45 +
&4 *x14*x15*x23*x45 + &2 *x14*x23*x23*x45 + &2 *x15*x23*x23*x45 - &2 *x12*x13*x24*x45 + &2 *x13*x13*x24*x45 + &2 *x12*x15*x24*x45 -
&2 *x13*x15*x24*x45 - &2 *x13*x23*x24*x45 - &2 *x15*x23*x24*x45 - &2 *x12*x13*x25*x45 + &2 *x13*x13*x25*x45 + &2 *x12*x14*x25*x45 -
&2 *x13*x14*x25*x45 - &2 *x13*x23*x25*x45 - &2 *x14*x23*x25*x45 + &4 *x13*x24*x25*x45 + &2 *x12*x12*x34*x45 - &2 *x12*x13*x34*x45 -
&2 *x12*x15*x34*x45 + &2 *x13*x15*x34*x45 - &2 *x12*x23*x34*x45 - &2 *x15*x23*x34*x45 - &2 *x12*x25*x34*x45 - &2 *x13*x25*x34*x45 + &2 *x23*x25*x34*x45 +
&2 *x12*x12*x35*x45 - &2 *x12*x13*x35*x45 - &2 *x12*x14*x35*x45 + &2 *x13*x14*x35*x45 - &2 *x12*x23*x35*x45 - &2 *x14*x23*x35*x45 -
&2 *x12*x24*x35*x45 - &2 *x13*x24*x35*x45 + &2 *x23*x24*x35*x45 + &4 *x12*x34*x35*x45 - x12*x12*x45*x45 + &2 *x12*x13*x45*x45 -
x13*x13*x45*x45 + &2 *x12*x23*x45*x45 + &2 *x13*x23*x45*x45 - x23*x23*x45*x45`;;
(* PUSACOU *)
(* SIDEXYO *)
let wedge = new_definition (`wedge v1 v2 w1 w2 =
let z = v2 - v1 in
let u1 = w1 - v1 in
let u2 = w2 - v1 in
let n = cross z u1 in
let d = n dot u2 in
if (aff_ge {v1,v2} {w1} w2) then {} else
if (aff_lt {v1,v2} {w1} w2) then aff_gt {v1,v2,w1} {n} else
if (d > &0) then aff_gt {v1,v2} {w1,w2} else
(:real^3) DIFF aff_ge {v1,v2} {w1,w2}`);;
(* ------------------------------------------------------------------ *)
(* Measure and Volume, following Nguyen Tat Thang *)
(* ------------------------------------------------------------------ *)
let sphere= new_definition`sphere x=(?(v:real^3)(r:real). (r> &0)/\ (x={w:real^3 | norm (w-v)= r}))`;;
let NULLSET_RULES,NULLSET_INDUCT,NULLSET_CASES =
new_inductive_definition
`(!P. ((plane P)\/ (sphere P) \/ (circular_cone P)) ==> NULLSET P) /\
!(s:real^3->bool) t. (NULLSET s /\ NULLSET t) ==> NULLSET (s UNION t)`;;
(* drop primes *)
let scale = new_definition `scale (t:real^3) (u:real^3) = vector[t$1 * u$1; t$2 * u$2; t$3 * u$3]`;;
let frustum = new_definition `frustum v0 v1 h1 h2 a = { y | rcone_gt v0 v1 a y /\
let d = (y - v0) dot (v1 - v0) in
let n = norm(v1 - v0) in
(h1*n < d /\ d < h2*n)}`;;
let rect = new_definition `rect (a:real^3) (b:real^3) = {(v:real^3) | !i. ( a$i < v$i /\ v$i < b$i )}`;;
(*
let is_tetrahedron = new_definition `is_tetrahedron S = ?v0 v1 v2 v3. (S = conv0 {v0,v1,v2,v3})`;;
*)
let MEASURABLE_RULES,MEASURABLE_INDUCT,MEASURABLE_CASES =
new_inductive_definition
`(!C. primitive C ==> measurable C) /\
( !Z. NULLSET Z ==> measurable Z) /\
(!X t. measurable X ==> (measurable (IMAGE (scale t) X))) /\
(!X v. measurable X ==> (measurable (IMAGE ((+) v) X))) /\
( !(s:real^3->bool) t. (measurable s /\ measurable t) ==> measurable (s UNION t)) /\
( !(s:real^3->bool) t. (measurable s /\ measurable t) ==> measurable (s INTER t)) /\
( !(s:real^3->bool) t. (measurable s /\ measurable t) ==> measurable (s DIFF t))
`;;
(* volume of intersection of conic cap and wedge *)
let vol_conv = new_definition `vol_conv v1 v2 v3 v4 =
let x12 = dist(v1,v2) pow 2 in
let x13 = dist(v1,v3) pow 2 in
let x14 = dist(v1,v4) pow 2 in
let x23 = dist(v2,v3) pow 2 in
let x24 = dist(v2,v4) pow 2 in
let x34 = dist(v3,v4) pow 2 in
sqrt(delta_x x12 x13 x14 x34 x24 x34)/(&12)`;;
let vol_rect = new_definition `vol_rect a b =
if (a$1 < b$1) /\ (a$2 < b$2) /\ (a$3 < b$3) then (b$3-a$3)*(b$2-a$2)*(b$1-a$1) else &0`;;
let volume_props = new_definition `volume_props (vol:(real^3->bool)->real) =
( (!C. vol C >= &0) /\
(!Z. NULLSET Z ==> (vol Z = &0)) /\
(!X Y. measurable X /\ measurable Y /\ NULLSET (SDIFF X Y) ==> (vol X = vol Y)) /\
(!X t. (measurable X) /\ (measurable (IMAGE (scale t) X)) ==> (vol (IMAGE (scale t) X) = abs(t$1 * t$2 * t$3)*vol(X))) /\
(!X v. measurable X ==> (vol (IMAGE ((+) v) X) = vol X)) /\
(!v0 v1 v2 v3 r. (r > &0) /\ (~(collinear {v0,v1,v2})) /\ ~(collinear {v0,v1,v3}) ==> vol (solid_triangle v0 {v1,v2,v3} r) = vol_solid_triangle v0 v1 v2 v3 r) /\
(!v0 v1 v2 v3. vol(conv0 {v0,v1,v2,v3}) = vol_conv v0 v1 v2 v3) /\
(!v0 v1 v2 v3 h a. ~(collinear {v0,v1,v2}) /\ ~(collinear {v0,v1,v3}) /\ (h >= &0) /\ (a > &0) /\ (a <= &1) ==> vol(frustt v0 v1 h a INTER wedge v0 v1 v2 v3) = vol_frustt_wedge v0 v1 v2 v3 h a) /\
(!v0 v1 v2 v3 r c. ~(collinear {v0,v1,v2}) /\ ~(collinear {v0,v1,v3}) /\ (r >= &0) /\ (c >= -- (&1)) /\ (c <= &1) ==> (vol(conic_cap v0 v1 r c INTER wedge v0 v1 v2 v3) = vol_conic_cap_wedge v0 v1 v2 v3 r c)) /\
(!(a:real^3) (b:real^3). vol(rect a b) = vol_rect a b) /\
(!v0 v1 v2 v3 r. ~(collinear {v0,v1,v2}) /\ ~(collinear {v0,v1,v3}) /\ (r >= &0) ==> (vol(normball v0 r INTER wedge v0 v1 v2 v3) = vol_ball_wedge v0 v1 v2 v3 r)))`;;
let abc_param = new_definition `abc_param v0 v1 v2 c =
let a = (&1/(&2)) * dist(v0,v1) in
let b = radV {v0,v1,v2} in
(a,b,c)`;;