(* ========================================================================= *)
(* Formalization of Electromagnetic Optics *)
(* *)
(* (c) Copyright, Sanaz Khan Afshar & Vincent Aravantinos 2011-14 *)
(* Hardware Verification Group, *)
(* Concordia University *)
(* *)
(* Contact: <s_khanaf@encs.concordia.ca> *)
(* <vincent@encs.concordia.ca> *)
(* *)
(* Extentions of the vector library. *)
(* ========================================================================= *)
prioritize_vector ();;
(** Additions to euclidean space *)
let [ORTHOGONAL_RZERO;ORTHOGONAL_RMUL;ORTHOGONAL_RNEG;ORTHOGONAL_RADD;
ORTHOGONAL_RSUB;ORTHOGONAL_LZERO;ORTHOGONAL_LMUL;ORTHOGONAL_LNEG;
ORTHOGONAL_LADD;ORTHOGONAL_LSUB] =
CONJUNCTS ORTHOGONAL_CLAUSES;;
let NON_VEC0_DIM3 = prove
(`!x:real^3. ~(x=
vec 0) <=> ~(x$1= &0) \/ ~(x$2= &0) \/ ~(x$3= &0)`,
REWRITE_TAC[
NON_VEC0;DIMINDEX_3]
THEN MESON_TAC[ARITH_RULE `1 <= i /\ i <= 3 <=> i = 1 \/ i = 2 \/ i = 3`]);;
(* NORMALIZING VECTORS *)
let UNIT_ELIM = GSYM UNIT_INTRO;;
let DOT_RUNIT_POS,DOT_LUNIT_POS = CONJ_PAIR(prove
(`(!x y. &0 < x dot (unit y) <=> &0 < x dot y)
/\ (!x y. &0 < (unit x) dot y <=> &0 < x dot y)`,
REWRITE_TAC[unit;DOT_RMUL;DOT_LMUL;REAL_MUL_POS_LT;REAL_LT_INV_EQ;
NORM_POS_LT;REWRITE_RULE[REAL_INV_NEG;REAL_NEG_GT0]
(SPEC `--x:real` REAL_LT_INV_EQ);
REWRITE_RULE[REWRITE_RULE[MESON[]`(p<=> ~q) <=> (q<=> ~p)`] real_lt]
NORM_POS_LE]
THEN MESON_TAC[DOT_RZERO;DOT_LZERO;REAL_LT_REFL]));;
let DOT_RUNIT_EQ0,DOT_LUNIT_EQ0 = CONJ_PAIR(prove
(`(!x y. x dot (unit y) = &0 <=> x dot y = &0)
/\ (!x y. (unit x) dot y = &0 <=> x dot y = &0)`,
REWRITE_TAC[GSYM orthogonal;ORTHOGONAL_LUNIT;ORTHOGONAL_RUNIT]));;
let DOT_RUNIT_LT0,DOT_LUNIT_LT0 = CONJ_PAIR(prove
(`(!x y. x dot (unit y) < &0 <=> x dot y < &0)
/\ (!x y. (unit x) dot y < &0 <=> x dot y < &0)`,
REWRITE_TAC[real_lt;MESON[] `(~p <=> ~q) <=> (p <=> q)`]
THEN REWRITE_TAC[REAL_LE_LT]
THEN MESON_TAC[DOT_RUNIT_EQ0;DOT_LUNIT_EQ0;DOT_RUNIT_POS;DOT_LUNIT_POS]));;
let DOT_RUNIT_LE0,DOT_LUNIT_LE0 = CONJ_PAIR(prove
(`(!x y. x dot (unit y) <= &0 <=> x dot y <= &0)
/\ (!x y. (unit x) dot y <= &0 <=> x dot y <= &0)`,
MESON_TAC[REAL_LE_LT;DOT_RUNIT_LT0;DOT_LUNIT_LT0;DOT_RUNIT_EQ0;
DOT_LUNIT_EQ0]));;
let DOT_RUNIT_GE0,DOT_LUNIT_GE0 = CONJ_PAIR(prove
(`(!x y. &0 <= x dot (unit y) <=> &0 <= x dot y)
/\ (!x y. &0 <= (unit x) dot y <=> &0 <= x dot y)`,
REWRITE_TAC[REAL_LE_LT]
THEN MESON_TAC[DOT_RUNIT_POS;DOT_LUNIT_POS;DOT_RUNIT_EQ0;DOT_LUNIT_EQ0]));;
(* CONNECTION BETWEEN SPANS AND PLANES *)
new_type_abbrev("point",`:real^3`);;
new_type_abbrev("plane",`:point->bool`);;
(* That theorem is (one of) the last which makes use of the affine definition of `plane` *)
let EXISTS_PLANE_BASIS = prove
(`!p.
plane p ==> ?b.
is_plane_basis b p`,
GEN_TAC
THEN DISCH_THEN (fun x ->
STRIP_ASSUME_TAC (REWRITE_RULE[
plane;
AFFINE_HULL_3] x)
THEN STRIP_ASSUME_TAC (MATCH_MP (REWRITE_RULE[GSYM
MEMBER_NOT_EMPTY]
PLANE_NON_EMPTY) x))
THEN POP_ASSUM MP_TAC THEN ASM_REWRITE_TAC[
is_plane_basis] THEN DISCH_TAC
THEN MAP_EVERY EXISTS_TAC [`{v-u,w-u:real^3}`;`v-u:real^3`; `w-u:real^3`]
THEN ASM_REWRITE_TAC[] THEN REPEAT STRIP_TAC
THENL [
ASM_MESON_TAC[
INSERT_AC;
COLLINEAR_3];
POP_ASSUM MP_TAC THEN REWRITE_TAC[
IN_ELIM_THM] THEN REPEAT STRIP_TAC
THEN EQ_TAC THEN STRIP_TAC
THENL [
RULE_ASSUM_TAC (REWRITE_RULE[REAL_ARITH `x+y+z= &1 <=> x= &1-y-z`])
THEN MAP_EVERY EXISTS_TAC [`v''-v':real`; `w''-w':real`]
THEN ASM_REWRITE_TAC[] THEN VECTOR_ARITH_TAC;
MAP_EVERY EXISTS_TAC [`u'-a-b:real`;`v'+a:real`;`w'+b:real`]
THEN CONJ_TAC
THENL [
ASM_ARITH_TAC;
REPLICATE_TAC 2 (POP_ASSUM MP_TAC) THEN VECTOR_ARITH_TAC]
]]);;
let UNIT_OF_BASIS_IS_BASIS = prove
(`!p.
plane p ==> !u v.
is_plane_basis {u,v} p ==>
is_plane_basis {unit u,unit v} p`,
REPEAT STRIP_TAC THEN REWRITE_TAC[
is_plane_basis]
THEN MAP_EVERY EXISTS_TAC [`unit u:real^3`; `unit v:real^3`]
THEN REWRITE_TAC[]
THEN POP_ASSUM
(DISTRIB [ASSUME_TAC;STRIP_ASSUME_TAC o REWRITE_RULE[
is_plane_basis]])
THEN ASM_REWRITE_TAC[GSYM
COLLINEAR_UNIT]
THEN ASM_CSQ_THEN ~remove:true
PAIR_SETS_EQ STRIP_ASSUME_TAC
THEN REPEAT (FIRST_X_ASSUM SUBST_VAR_TAC)
THEN ASM_CSQ_THEN
BASIS_NON_NULL (C ASM_CSQ_THEN (STRIP_ASSUME_TAC
o REWRITE_RULE[
IN_INSERT;
IN_SING;
MESON[]`(!u. u=a \/ u=b ==> p u) <=> p a /\ p b`]))
THEN GEN_TAC
THEN DISCH_THEN (fun x -> FIRST_X_ASSUM (ASSUME_TAC o C MATCH_MP x))
THEN ASM_REWRITE_TAC[unit;
VECTOR_MUL_ASSOC]
THEN REPEAT (STRIP_TAC ORELSE EQ_TAC) THEN ASM_REWRITE_TAC[]
THENL [
MAP_EVERY EXISTS_TAC [`a*norm(u':real^3)`;`b*norm(v':real^3)`]
THEN RULE_ASSUM_TAC (REWRITE_RULE[GSYM
NORM_EQ_0])
THEN ASM_SIMP_TAC[GSYM REAL_MUL_ASSOC;
REAL_MUL_RINV] THEN VECTOR_ARITH_TAC;
MESON_TAC[];
MAP_EVERY EXISTS_TAC [`b*norm(v':real^3)`;`a*norm(u':real^3)`]
THEN RULE_ASSUM_TAC (REWRITE_RULE[GSYM
NORM_EQ_0])
THEN ASM_SIMP_TAC[GSYM REAL_MUL_ASSOC;
REAL_MUL_RINV] THEN VECTOR_ARITH_TAC;
MESON_TAC[
VECTOR_ADD_AC];
]);;
(* This theorem makes the connection between the (affine) notion of plane and the (vector) notion of span.
* From now on, we can generally rely only on this result to reason about the spanning set of a plane.
*)
let PLANE_SPAN = prove
(`!p.
plane p ==> !b.
is_plane_basis b p ==> !pt:point. pt
IN p
==> { pt' - pt | pt'
IN p } = span b`,
REPEAT STRIP_TAC THEN ASM_CSQ_THEN
PLANE_AS_SPAN (C ASM_CSQ_THEN (C
ASM_CSQ_THEN (SINGLE (GEN_REWRITE_TAC (RATOR_CONV o ONCE_DEPTH_CONV)))))
THEN REWRITE_TAC[
IN_ELIM_THM;
EXTENSION] THEN GEN_TAC THEN EQ_TAC
THENL [
REPEAT STRIP_TAC THEN ASM_REWRITE_TAC[VECTOR_ARITH `(x + y)-x = y:real^N`];
DISCH_TAC THEN EXISTS_TAC `x+pt:real^3` THEN REWRITE_TAC (map VECTOR_ARITH
[`(x + y) - y = x:real^N`; `x+z=z+y <=> x=y:real^N`]) THEN ASM_MESON_TAC[]
]);;
(** Is u the projection of v on the hyperplane represented by the non-null vector w? *)
(** Additions to affine spaces *)
let LSUB_PLANE_EQ_RSUB_PLANE = prove
(`!p:plane.
plane p ==> !x. x
IN p ==> {y - x | y
IN p} = {x - y | y
IN p}`,
let COMMON_TAC t =
EXISTS_TAC t THEN CONJ_TAC THEN TRY VECTOR_ARITH_TAC
THEN SUBGOAL_TAC "" `(x':real^3)
IN span b` [ASM SET_TAC []]
in
REWRITE_TAC[
GSPEC;
SETSPEC;
FUN_EQ_THM] THEN REPEAT STRIP_TAC
THEN ASM_CSQ_THEN
EXISTS_PLANE_BASIS STRIP_ASSUME_TAC
THEN ASM_CSQS_THEN
PLANE_AS_SPAN ASSUME_TAC THEN EQ_TAC THENL [
ASM_CSQS_THEN
PLANE_SPAN ASSUME_TAC THEN STRIP_TAC
THEN COMMON_TAC `x-x':point` THEN REWRITE_TAC[
VECTOR_SUB]
THEN POP_ASSUM (ASSUME_TAC o MATCH_MP
SPAN_NEG)
THEN ASSUM_LIST (FIRST o List.rev_map (CHANGED_TAC o SINGLE REWRITE_TAC))
THEN ASSUM_LIST SET_TAC;
STRIP_TAC THEN ASM_CSQS_THEN
PLANE_SPAN ASSUME_TAC
THEN COMMON_TAC `x+x':point` THEN ASSUM_LIST SET_TAC]);;
(* Additional functions *)