(** Lemma 16.2 in dimension 2. *)

(* Specifications: *)
Lemma Cs_not_Col : forall O E S U1 U2, Cs O E S U1 U2 -> ~ Col U1 S U2.
(** As we are in dimension 2, we skip 16.3 which is only needed to prove 16.4 in dimension n. *)
(** Lemma 16.4 in dimension 2. *)
Lemma exists_grid : exists O E E' S U1 U2, ~ Col O E E' /\ Cs O E S U1 U2.
Lemma exists_grid_spec : exists S U1 U2, Cs PA PB S U1 U2.
Lemma coord_exchange_axes : forall O E S U1 U2 P X Y,
Cd O E S U1 U2 P X Y -> Cd O E S U2 U1 P Y X.
(** Lemma 16.6 in dimension 2. *)
Lemma Cd_Col : forall O E S U1 U2 P X Y,
Cd O E S U1 U2 P X Y -> Col O E X /\ Col O E Y.
Lemma exists_projp : forall A B P, A <> B -> exists P', Projp P P' A B.
Lemma exists_coord : forall O E S U P,
S <> U -> Cong O E S U ->
exists PX, exists X, Projp P PX S U /\ Cong_3 O E X S U PX.
(** Lemma 16.7 in dimension 2. *)
Lemma coordinates_of_point : forall O E S U1 U2 P,
Cs O E S U1 U2 -> exists X, exists Y, Cd O E S U1 U2 P X Y.
Lemma point_of_coordinates_origin : forall O E S U1 U2,
Cs O E S U1 U2 -> Cd O E S U1 U2 S O O.
Lemma point_of_coordinates_on_an_axis : forall O E S U1 U2 X,
Cs O E S U1 U2 -> Col O E X -> O <> X -> exists P, Cd O E S U1 U2 P X O.
Lemma point_of_coordinates : forall O E S U1 U2 X Y,
Cs O E S U1 U2 -> Col O E X -> Col O E Y -> exists P, Cd O E S U1 U2 P X Y.
Lemma eq_points_coordinates : forall O E S U1 U2 P1 X1 Y1 P2 X2 Y2,
Cd O E S U1 U2 P1 X1 Y1 -> Cd O E S U1 U2 P2 X2 Y2 ->
(P1 = P2 <-> (X1 = X2 /\ Y1 = Y2)).
(** As we are in dimension 2, we skip 16.8 which is only needed to prove 16.11 in dimension n. *)
Lemma l16_9_1 : forall O E E' X Y XY XMY,
Col O E X -> Col O E Y -> Is_length O E E' X Y XY ->
LeP O E E' Y X -> Diff O E E' X Y XMY ->
XY = XMY.
Lemma length_eq_or_opp : forall O E E' A B L1 L2,
Length O E E' A B L1 -> Diff O E E' A B L2 -> L1 = L2 \/ Opp O E E' L1 L2.
Lemma l16_9_2 : forall O E E' X Y XY XMY XY2 XMY2,
Col O E X -> Col O E Y -> Is_length O E E' X Y XY ->
Diff O E E' X Y XMY -> Prod O E E' XY XY XY2 -> Prod O E E' XMY XMY XMY2 ->
XY2 = XMY2.
(** Lemma 16.10 for k  = 2. *)
Lemma cong_3_2_cong_4 : forall O E I J S U X Y,
O <> E -> Col O E I -> Col O E J ->
Cong_3 O E I S U X -> Cong_3 O E J S U Y ->
Cong_4 O E I J S U X Y.
(** Lemma 16.10 for k  = 3. *)
Lemma cong_3_3_cong_5: forall O E I J K S U X Y Z,
O <> E -> Col O E I -> Col O E J -> Col O E K ->
Cong_3 O E I S U X -> Cong_3 O E J S U Y -> Cong_3 O E K S U Z ->
Cong_5 O E I J K S U X Y Z.
Lemma square_distance_formula_aux : forall O E E' S U1 U2 P PX PY Q QX PXQX,
Cd O E S U1 U2 P PX PY -> Cd O E S U1 U2 Q QX PY ->
P <> Q -> ~ Col O E E' -> Col O E PX -> Col O E QX -> Col O E PY ->
Cs O E S U1 U2 -> Length O E E' PX QX PXQX ->
Length O E E' Q P PXQX.
Lemma square_distance_formula :
forall O E E' S U1 U2 P Q PX PY QX QY PQ PQ2 PXMQX PYMQY PXMQX2 PYMQY2 F,
Cd O E S U1 U2 P PX PY -> Cd O E S U1 U2 Q QX QY -> Is_length O E E' P Q PQ ->
Prod O E E' PQ PQ PQ2 -> Diff O E E' PX QX PXMQX ->
Prod O E E' PXMQX PXMQX PXMQX2 -> Diff O E E' PY QY PYMQY ->
Prod O E E' PYMQY PYMQY PYMQY2 -> Sum O E E' PXMQX2 PYMQY2 F ->
PQ2 = F.
(** Lemma 16.12 in dimension 2. *)
Lemma characterization_of_congruence :
forall O E E' S U1 U2
A AX AY B BX BY C CX CY D DX DY
AXMBX AXMBX2 AYMBY AYMBY2 AB2
CXMDX CXMDX2 CYMDY CYMDY2 CD2,
Cd O E S U1 U2 A AX AY -> Cd O E S U1 U2 B BX BY ->
Cd O E S U1 U2 C CX CY -> Cd O E S U1 U2 D DX DY ->
Diff O E E' AX BX AXMBX -> Prod O E E' AXMBX AXMBX AXMBX2 ->
Diff O E E' AY BY AYMBY -> Prod O E E' AYMBY AYMBY AYMBY2 ->
Sum O E E' AXMBX2 AYMBY2 AB2 ->
Diff O E E' CX DX CXMDX -> Prod O E E' CXMDX CXMDX CXMDX2 ->
Diff O E E' CY DY CYMDY -> Prod O E E' CYMDY CYMDY CYMDY2 ->
Sum O E E' CXMDX2 CYMDY2 CD2 ->
(Cong A B C D <-> AB2 = CD2).
Lemma bet_betCood_aux : forall O E S U1 U2 A AX AY B BX BY C CX CY,
Cd O E S U1 U2 A AX AY -> Cd O E S U1 U2 B BX BY -> Cd O E S U1 U2 C CX CY ->
Bet A B C ->
Bet AX BX CX.
Lemma bet_betCood : forall O E S U1 U2 A AX AY B BX BY C CX CY,
Cd O E S U1 U2 A AX AY -> Cd O E S U1 U2 B BX BY -> Cd O E S U1 U2 C CX CY ->
Bet A B C ->
Bet AX BX CX /\ Bet AY BY CY.
Lemma characterization_of_betweenness_aux : forall O E E' S U1 U2
A AX AY B BX BY C CX CY
BXMAX CXMAX AB AC IAC T,
Cd O E S U1 U2 A AX AY -> Cd O E S U1 U2 B BX BY -> Cd O E S U1 U2 C CX CY ->
~ Col O E E' -> Col O E AX -> Col O E BX -> Col O E CX ->
Col O E BXMAX -> Col O E CXMAX -> Col O E T ->
Col O E AB -> Col O E AC -> Col O E IAC ->
Diff O E E' BX AX BXMAX -> Diff O E E' CX AX CXMAX ->
Length O E E' A B AB -> Length O E E' A C AC ->
Prod O E E' T AC AB -> Prod O E E' IAC AC E ->
Bet A B C -> A <> B -> A <> C -> B <> C ->
Prod O E E' T CXMAX BXMAX.