Section T18.
Context `{T2D:Tarski_2D}.
Context `{TE:@Tarski_euclidean Tn TnEQD}.
Variable SS U1 U2 : Tpoint.
Variable orthonormal_grid : Cs O E SS U1 U2.
Definition F : Type := {P : Tpoint | Col O E P}.
Definition EqF (x y : F) := (proj1_sig x) = (proj1_sig y).
Instance eqF_Reflexive : Reflexive EqF.
Definition LeF (x y : F) := LeP O E E' (proj1_sig x) (proj1_sig y).
Instance leF_Antisymmetric : Antisymmetric F EqF LeF.
(* For 8.5 Instance leF_Antisymmetric : Antisymmetric eqF leF. *)
Definition MulF (x y : F) : F.
Add Ring GeometricRing : ringF.
Add Field GeometricField : fieldF.
Global Instance Fops: (@Ring_ops F OF OneF AddF MulF SubF OppF EqF) := {}.
Global Instance FRing : (Ring (Ro:=Fops)).
Global Instance Fintegral : (Integral_domain (Rcr:=Fcri)).
Definition sqrt3 := PythF 1 (PythF 1 1).
Ltac decompose_coordinates :=
repeat
match goal with
H: _ |- context[ (coordinates_of_point_F ?X) ] =>
let fx := fresh X "x" in
let fy := fresh X "y" in
destruct (coordinates_of_point_F X) as [[fx fy] _]
end.
Ltac convert_to_algebra :=
try setoid_rewrite characterization_of_betweenness_F;
try setoid_rewrite characterization_of_congruence_F;
try setoid_rewrite characterization_of_midpoint_F;
try setoid_rewrite characterization_of_collinearity_F;
try setoid_rewrite characterization_of_right_triangle_F;
try setoid_rewrite characterization_of_perpendicularity_F;
try setoid_rewrite characterization_of_parallelism_F;
try setoid_rewrite characterization_of_equality_F;
try setoid_rewrite characterization_of_neq_F.
Ltac express_disj_as_a_single_poly := repeat rewrite <- mulF__eq0.
(** We deduce the axioms of the area method. *)
Definition vect := (F * F)%type.
Definition cross_product (u v : vect) : F :=
fst u * snd v - snd u * fst v.
Definition scalar_product (u v : vect) : F :=
fst u * fst v + snd u * snd v.
Definition ratio A B C D :=
let (Ac, _) := coordinates_of_point_F A in
let (Ax, Ay) := Ac in
let (Bc, _) := coordinates_of_point_F B in
let (Bx, By) := Bc in
let (Cc, _) := coordinates_of_point_F C in
let (Cx, Cy) := Cc in
let (Dc, _) := coordinates_of_point_F D in
let (Dx, Dy) := Dc in
let VAB := (Bx-Ax, By-Ay) in
let VCD := (Dx-Cx, Dy-Cy) in
scalar_product VAB VCD / scalar_product VCD VCD.
Definition signed_area A B C :=
let (Ac, _) := coordinates_of_point_F A in
let (Ax, Ay) := Ac in
let (Bc, _) := coordinates_of_point_F B in
let (Bx, By) := Bc in
let (Cc, _) := coordinates_of_point_F C in
let (Cx, Cy) := Cc in
let VAB := (Bx-Ax, By-Ay) in
let VAC := (Cx-Ax, Cy-Ay) in
1 / 2 * cross_product VAB VAC.
(** We introduce this definition to simplify the automatic proofs:*)
Definition twice_signed_area A B C :=
let (Ac, _) := coordinates_of_point_F A in
let (Ax, Ay) := Ac in
let (Bc, _) := coordinates_of_point_F B in
let (Bx, By) := Bc in
let (Cc, _) := coordinates_of_point_F C in
let (Cx, Cy) := Cc in
let VAB := (Bx-Ax, By-Ay) in
let VAC := (Cx-Ax, Cy-Ay) in
cross_product VAB VAC.
Definition square_dist A B :=
let (Ac, _) := coordinates_of_point_F A in
let (Ax, Ay) := Ac in
let (Bc, _) := coordinates_of_point_F B in
let (Bx, By) := Bc in
(Ax - Bx) * (Ax - Bx) + (Ay - By) * (Ay - By).
Definition twice_signed_area4 A B C D :=
twice_signed_area A B C + twice_signed_area A C D.
Definition Py A B C := square_dist A B + square_dist B C - square_dist A C.
Definition Py4 A B C D := Py A B D - Py C B D.
Definition AM_Cong A B C D := Py A B A =F= Py C D C.
Definition AM_Col A B C := twice_signed_area A B C =F= 0.
Definition AM_Per A B C := Py A B C =F= 0.
Definition AM_Perp A B C D := Py4 A C B D =F= 0.
Definition AM_Par A B C D := twice_signed_area4 A C B D =F= 0.
Definition AM_on_foot Y P U V := AM_Perp Y P U V /\ AM_Col Y U V /\ U <> V.

Lemma Per_AM_Per : forall A B C, AM_Per A B C <-> Per A B C.