(***************************************************************************)
(* Formalization of the Chou, Gao and Zhang's decision procedure.          *)
(* Julien Narboux (Julien@narboux.fr)                                      *)
(* LIX/INRIA FUTURS 2004-2006                                              *)
(* University of Strasbourg 2008                                           *)
(***************************************************************************)

Require Export geometry_tools.

Theorem field_prop1 : forall a : F, -a=0 -> a=0.
Proof with try solve [ ring | congruence ].
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros.
assert (- -a=-0).
rewrite H...
assert (- -a=a)...
assert (-0=0)...
Qed.

Hint Resolve field_prop1 : Geom.

(** Some propositions about Col *)

Theorem col_1 : forall A B C : Point, Col A B C -> Col B A C.
Proof with uniformize_signed_areas;Geometry.
(* Goal: not (Col P Q V) *)
(* Goal: or (not (Col P U Q)) (not (Col P Q V)) *)
unfold Col in |- *.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros...
Qed.

Theorem col_2 : forall A B C : Point, Col A B C -> Col A C B.
Proof with uniformize_signed_areas;Geometry.
(* Goal: not (Col P Q V) *)
(* Goal: or (not (Col P U Q)) (not (Col P Q V)) *)
unfold Col in |- *.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros...
Qed.

Theorem col_3 : forall A B C : Point, Col A B C -> Col B C A.
Proof with uniformize_signed_areas;Geometry.
(* Goal: not (Col P Q V) *)
(* Goal: or (not (Col P U Q)) (not (Col P Q V)) *)
unfold Col in |- *.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros...
Qed.

Theorem col_4 : forall A B C : Point, Col A B C -> Col C B A.
Proof with uniformize_signed_areas;Geometry.
(* Goal: not (Col P Q V) *)
(* Goal: or (not (Col P U Q)) (not (Col P Q V)) *)
unfold Col in |- *.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros...
Qed.

Theorem col_5 : forall A B C : Point, Col A B C -> Col C A B.
Proof with uniformize_signed_areas;Geometry.
(* Goal: not (Col P Q V) *)
(* Goal: or (not (Col P U Q)) (not (Col P Q V)) *)
unfold Col in |- *.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros...
Qed.

Hint Resolve col_1 col_2 col_3 col_4 col_5: Geom.

(** Proposition about equality and nullity of geometric quantities *)

Theorem noteqnotzero : forall A B : Point, A <> B -> A ** B <> 0.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros.
(* Goal: not (@eq F (DSeg A B) F0) *)
assert (A ** B = 0 <-> A = B).
(* Goal: @eq Point P Q *)
(* Goal: parallel D Q P D *)
(* Goal: parallel D Q P C *)
apply A1b.
(* Goal: not (@eq Point A B) *)
intuition.
Qed.
Hint Resolve noteqnotzero: Geom.

Theorem egalcol : forall A B C : Point, A = B -> Col A B C.
Proof with try solve [ Geometry | congruence ].
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros.
(* Goal: not (Col P Q V) *)
(* Goal: or (not (Col P U Q)) (not (Col P Q V)) *)
unfold Col.
rewrite H...
Qed.

Theorem notcolnotegal_1 : forall A B C : Point, ~ Col A B C -> A <> B.
(* Goal: not (Col P Q V) *)
(* Goal: or (not (Col P U Q)) (not (Col P Q V)) *)
unfold Col in |- *.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros.
(* Goal: not (@eq Point A B) *)
intuition.
(* Goal: False *)
assert (T := egalcol A B C H0).
(* Goal: False *)
auto.
Qed.

Theorem notcolnotegal_2 : forall A B C : Point, ~ Col A B C -> B <> C.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros.
assert (~ Col A B C -> ~ Col B C A).
(* Goal: not (@eq Point A B) *)
intuition.
assert (~ Col B C A).
(* Goal: False *)
auto.
eapply notcolnotegal_1.
apply H1.
Qed.

Theorem notcolnotegal_3 : forall A B C : Point, ~ Col A B C -> A <> C.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros.
assert (~ Col A B C -> ~ Col A C B).
(* Goal: not (@eq Point A B) *)
intuition.
assert (~ Col A C B).
(* Goal: False *)
auto.
eapply notcolnotegal_1.
apply H1.
Qed.

Hint Resolve notcolnotegal_1 notcolnotegal_2 notcolnotegal_3: Geom.

Theorem notparallelnotegal_1 : forall A B C D, 
 ~ parallel A B C D -> A<>B.
Proof.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros.
(* Goal: not (@eq Point C D) *)
unfold not;intro.
(* Goal: parallel D Q P D *)
(* Goal: parallel D Q P C *)
subst.
(* Goal: False *)
auto with Geom.
Qed.

Theorem notparallelnotegal_2 : forall A B C D, 
 ~ parallel A B C D -> C<>D.
Proof.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros.
(* Goal: not (@eq Point C D) *)
unfold not;intro.
(* Goal: parallel D Q P D *)
(* Goal: parallel D Q P C *)
subst.
(* Goal: False *)
auto with Geom.
Qed.

Hint Resolve notparallelnotegal_1 notparallelnotegal_2 : Geom.

(** Some usefull lemmas about ratios of signed distances *)

Theorem dirseg_1 :
 forall A B C D : Point, D ** C <> 0 -> A ** B / C ** D = B ** A / D ** C.
Proof with Geometry.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros.
uniformize_dir_seg.
field...
Qed.
Hint Resolve dirseg_1: Geom.

Theorem dirseg_2 : forall A B C D : Point, A ** B = C ** D -> B ** A = D ** C.
Proof with Geometry.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros.
uniformize_dir_seg.
rewrite H.
(* Goal: False *)
auto.
Qed.
Hint Resolve dirseg_2: Geom.

(*
Theorem dirseg_1 : (A,B,C,D:Point) C<>D -> -(A**B/C**D) = B**A /C**D.
Proof with Geometry.
Intros.
Replace A**B with -B**A.
Field.
Symmetry.
Qed.

Theorem dirseg_2 : (A,B,C,D:Point) C<>D -> -(A**B/C**D) = A**B /D**C.
Proof with Geometry.
Intros.
Replace C**D with -D**C.
Field.
Symmetry.
Qed.


Hints Resolve dirseg_1 dirseg_2 : Geom.
*)

Theorem dirseg_3 :
 forall A B C D : Point, C ** D <> 0 -> A ** B / C ** D = - (B ** A / C ** D).
Proof with Geometry.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros.
uniformize_dir_seg.
field...
Qed.

Theorem dirseg_4 :
 forall A B C D : Point, C ** D <> 0 -> A ** B / C ** D = - (A ** B / D ** C).
Proof with Geometry.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros...
uniformize_dir_seg.
field...
Qed.

Hint Resolve dirseg_3 dirseg_4: Geom.

Theorem dirseg_simpl_1 : 
 forall A B, A<>B -> A**B / A**B = 1.
Proof.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros.
(* Goal: False *)
field;auto with Geom.
Qed.

Theorem dirseg_simpl_2 : 
 forall A B, A<>B -> B**A / A**B = -(1).
Proof.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros.
(* Goal: @eq F (Fdiv (DSeg B A) (DSeg A B)) (Fopp F1) *)
replace (B**A) with (- A**B).
(* Goal: False *)
field;auto with Geom.
(* Goal: False *)
symmetry;auto with Geom.
Qed.


Theorem dirsur_1 :
 forall A B C D E F : Point,
 ~ Col D E F -> S A B C / S D E F = S A C B / S D F E.
Proof with Geometry.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros.
uniformize_signed_areas.
field...
Qed.
Hint Resolve dirsur_1: Geom.



Theorem col_trans_1 :
 forall A B C D : Point, A <> B -> Col A B C -> Col A B D -> Col A C D.
Proof with Geometry.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros. 
assert (S A B C = S A B D + S A D C + S D B C)...
rewrite H0 in H2. 
rewrite H1 in H2.
cases_col A D C...
cases_equality C A...
apply egalcol...
NormalizeRing H2...
assert (C ** B / C ** A = S D C B / S D C A)...
assert (C ** A + A ** B = C ** B)...
rewrite <- H6 in H5...
assert ((C ** A + A ** B) / C ** A = 1 + A ** B / C ** A)...
field...
rewrite H7 in H5.
clear H7 H6.

assert (S D B C = - S D C B)...
rewrite H6 in H2...

assert (S A D C = S D C A)...
rewrite H7 in H2...
IsoleVarRing (S D C B) H2... 
rewrite H2 in H5...
assert (S D C A / S D C A = 1)...
field...
rewrite H8 in H5.
clear H6 H7 H8.
IsoleVarRing (A ** B) H5...
assert (A = B)...
(* Goal: not (@eq Point A B) *)
intuition...
Qed.

Hint Resolve col_trans_1.

Lemma build_point_not_collinear_1 : forall A B, A<>B -> exists C, ~ Col A B C. 
Proof with Geometry.
assert ({A : Point &  {B : Point &  {C : Point | ~ Col A B C}}}).
apply A4.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
elim H;intro X;intros.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
elim p;intro Y;intros.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
elim p0;intro Z;intros.
cases_col A B X.
cases_col A B Y.
cases_col A B Z.
cases_equality Y A.
subst Y.
assert (Col A X Z).
eapply col_trans_1 with (B:=B)...
assert (Col X A Z)...
(* Goal: not (@eq Point A B) *)
intuition.
assert (Col A Y Z).
eapply col_trans_1 with (B:=B)...
assert (Col A Y X).
eapply col_trans_1 with (B:=B)...
assert (Col Y X Z).
eapply col_trans_1 with (B:=A)...
assert (Col X Y Z)...
(* Goal: not (@eq Point A B) *)
intuition.
exists Z...
exists Y...
exists X...
Qed.

Lemma build_point_not_collinear_2 : forall A, exists B, exists C, ~ Col A B C. 
Proof with Geometry.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros.
assert ({A : Point &  {B : Point &  {C : Point | ~ Col A B C}}}).
apply A4.
DecompEx H A1.
DecompEx p B.
DecompEx p0 C.
cases_equality A B.
subst A.
exists A1.
exists C...
assert  (T:=build_point_not_collinear_1 A B H).
DecompEx T C1.
exists B.
exists C1...
Qed.

Theorem col_not_col_1 :
 forall A B O P : Point, A <> O -> Col A P O -> ~ Col P A B -> ~ Col O A B.
Proof with Geometry.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros.
(* Goal: not (@eq Point C D) *)
unfold not in |- *; intro.
assert (Col A O P)...
assert (Col A O B)...
assert (Col A P B)...
(* Goal: False *)
eauto with Geom...
Qed.

Hint Resolve col_not_col_1.

Theorem A6_1 :
 forall P Q A M : Point,
 M <> Q -> ~ Col Q A M -> Col P Q M -> P ** M / Q ** M = S P A M / S Q A M.
Proof with try solve [ Geometry | congruence ].
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros...
assert (P ** M / Q ** M = M ** P / M ** Q)...
assert (M ** P / M ** Q = S A M P / S A M Q)...
assert (S A M P = S P A M)...
assert (S A M Q = S Q A M)...
Qed.
Hint Resolve A6_1: Geom.

Theorem A6_2 :
 forall P Q R A : Point,
 P <> Q -> ~ Col Q A P -> Col P Q R -> P ** R / P ** Q = S R A P / S Q A P.
Proof with try solve [ Geometry | congruence ].
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros...
assert (P ** R / P ** Q = S A P R / S A P Q)...
assert (S A P R = S R A P)... 
assert (S A P Q = S Q A P)... 
Qed.
Hint Resolve A6_2: Geom.

Theorem A6_3 :
 forall A B C P : Point,
 A <> C -> ~ Col P A C -> Col A B C -> C ** B / A ** C = S P C B / S P A C.
Proof with Geometry.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros...
assert (C ** A = - A ** C)...
assert (S P C A = - S P A C)...
assert (C ** B / C ** A = S P C B / S P C A)...
rewrite H3 in H4...
rewrite H2 in H4...

RewriteVar (C ** B) H4...
field...
Qed.
Hint Resolve A6_3: Geom.

Theorem A6_4 :
 forall A B C P : Point,
 A <> B -> ~ Col P A B -> Col A B C -> C ** A / A ** B = S P C A / S P A B.
Proof with Geometry.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros...
assert (A ** C / B ** A = S P A C / S P B A)...
assert (A ** C / B ** A = C ** A / A ** B)...
assert (S P C A / S P A B = S P A C / S P B A)...
congruence...
Qed.
Hint Resolve A6_4: Geom.

Theorem A6_5 :
 forall A B O P : Point,
 O <> A -> ~ Col O A B -> Col P A O -> P ** A / O ** A = S P A B / S O A B.
Proof with Geometry.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros...
assert (P ** A / O ** A = S P B A / S O B A)...
assert (S P A B = - S P B A)...
assert (S O A B = - S O B A)...
rewrite H3...
rewrite H4...
rewrite H2...
assert (S O B A <> 0)...
field...
Qed.

Hint Resolve A6_5: Geom.

Theorem A6_6 :
 forall A B R Q : Point,
 A <> Q -> ~ Col Q A B -> Col A R Q -> A ** R / A ** Q = S R A B / S Q A B.
Proof with Geometry.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros...
assert (S R A B / S Q A B = S R B A / S Q B A)...
rewrite H2...
Qed.

Hint Resolve A6_6: Geom.

Theorem l2_7 :
 forall A B C D P : Point,
 Col C A B ->
 Col D A B ->
 ~ Col P C A -> ~ Col P A B -> A <> B -> S P C D / S P A B = C ** D / A ** B.
Proof with try solve [ Geometry | congruence | field; Geometry ].
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros...
cases_equality C A...
assert (Col A B D)...
rewrite H4...
symmetry  in |- *...
assert (S P C D / S P A B = S P C D / S P C A * (S P C A / S P A B))...
assert (A <> C)...
assert (Col C D A)...
(* Goal: False *)
eauto with Geom...
assert (C ** D / C ** A = S P C D / S P C A)...
assert (A ** C / A ** B = S P A C / S P A B)...
assert (C ** A / A ** B = S P C A / S P A B)...
assert (C ** D / C ** A * (C ** A / A ** B) = C ** D / A ** B)...
Qed.


Theorem par_aux_1 : forall P Q U V : Point, ~ parallel P Q U V -> P <> Q.
Proof with Geometry.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros...
unfold parallel in H...
  unfold S4 in H...
(* Goal: not (@eq Point C D) *)
  unfold not in |- *; intro...
  assert (S P U Q = 0)...
  rewrite H0...
  assert (S P Q V = 0)...
  rewrite H0...
  rewrite H1 in H...
  rewrite H2 in H...
Qed.



Theorem par_not_all_col :
 forall P Q U V : Point, ~ parallel P Q U V -> ~ Col P U Q \/ ~ Col P Q V. 
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros.
(* Goal: or (not (Col P U Q)) (not (Col P Q V)) *)
cases_col P U Q.
(* Goal: or (not (Col P U Q)) (not (Col P Q V)) *)
(* Goal: or (not (Col P U Q)) (not (Col P Q V)) *)
unfold parallel in H.
(* Goal: or (not (Col P U Q)) (not (Col P Q V)) *)
(* Goal: or (not (Col P U Q)) (not (Col P Q V)) *)
unfold S4 in H.
(* Goal: or (not (Col P U Q)) (not (Col P Q V)) *)
(* Goal: or (not (Col P U Q)) (not (Col P Q V)) *)
rewrite H0 in H.
(* Goal: or (not (Col P U Q)) (not (Col P Q V)) *)
(* Goal: or (not (Col P U Q)) (not (Col P Q V)) *)
assert (0 + S P Q V = S P Q V).
(* Goal: @eq F (Fopp (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q B A)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P B A)))) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (Fopp (S Q B A))) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (Fopp (S P B A)))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
ring.
(* Goal: or (not (Col P U Q)) (not (Col P Q V)) *)
(* Goal: or (not (Col P U Q)) (not (Col P Q V)) *)
rewrite H1 in H.
(* Goal: or (not (Col P U Q)) (not (Col P Q V)) *)
(* Goal: or (not (Col P U Q)) (not (Col P Q V)) *)
right.
(* Goal: not (Col P Q V) *)
(* Goal: or (not (Col P U Q)) (not (Col P Q V)) *)
unfold Col in |- *.
(* Goal: @eq F F0 F0 *)
(* Goal: parallel D Q P C *)
trivial.
(* Goal: or (not (Col P U Q)) (not (Col P Q V)) *)
left.
(* Goal: @eq F F0 F0 *)
(* Goal: parallel D Q P C *)
trivial.
Qed.

Theorem co_side_main :
 forall A B P Q M : Point,
 ~ Col Q A B ->
 ~ Col P A M ->
 ~ Col Q A M ->
 Q <> M -> Col A B M -> Col P Q M -> P ** M / Q ** M = S P A B / S Q A B.
Proof with try solve [ Geometry | congruence | field; Geometry ].
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros...
assert
 (S P A B / S Q A B =
  S P A B / S P A M * (S P A M / S Q A M * (S Q A M / S Q A B)))...
(* Goal: False *)
assert (A <> B); eauto with Geom...
(* Goal: False *)
assert (A <> M); eauto with Geom...
assert (A ** B / A ** M * (P ** M / Q ** M * (A ** M / A ** B)) = P ** M / Q ** M)...
assert (A ** B / A ** M = S P A B / S P A M)...
assert (P ** M / Q ** M = S P A M / S Q A M)...
assert (A ** M / A ** B = S Q A M / S Q A B)...
Qed.


Theorem co_side :
 forall A B P Q M : Point,
 ~ Col Q A B ->
 Q <> M -> Col A B M -> Col P Q M -> P ** M / Q ** M = S P A B / S Q A B.
Proof with Geometry.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros...
cases_equality M A...
rewrite H3...
rewrite H3 in H0...
rewrite H3 in H2...
assert (~ Col Q A M)...
(* Goal: not (@eq Point C D) *)
unfold not in |- *; intro...
assert (Col Q M A)...
assert (Col Q M P)...
(* Goal: False *)
assert (Col Q A P); eauto with Geom...
assert (Col A M Q)...
assert (Col A M B)...
(* Goal: False *)
assert (Col A B Q); eauto with Geom...

cases_equality P M...
rewrite <- H5 in H1...
assert (Col P A B)...
rewrite H6...
assert (P ** M = 0)...
rewrite H7...
field...

cases_equality P Q...
rewrite H6...
field...

assert (~ Col P A M)...
(* Goal: not (@eq Point C D) *)
unfold not in |- *; intro...
assert (Col P M A)...
assert (Col P M Q)...
(* Goal: False *)
assert (Col P A Q); eauto with Geom...

apply co_side_main...
Qed.






Hint Resolve co_side: Geom.

Theorem inter_unicity :
 forall A B P Q M : Point,
 ~ parallel P Q A B -> Col A B M -> Col P Q M -> A = Q -> A = M.
Proof with Geometry.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros...
cases_equality A M...
assert (Col A M B)...
assert (Col Q M P)...
rewrite <- H2 in H5...
assert (Col A B P)...
(* Goal: False *)
eauto with Geom...
assert (~ Col P A Q \/ ~ Col P Q B)...
apply par_not_all_col...
case H7; intro...
assert (Col P A A)...
rewrite <- H2 in H8...
(* Goal: not (@eq Point A B) *)
intuition...
rewrite H2 in H6...
assert (Col P Q B)...
(* Goal: not (@eq Point A B) *)
intuition...
Qed.

Theorem inter_unicity_2 :
 forall A B P Q M N: Point,
 ~ parallel P Q A B -> 
 Col A B M -> Col P Q M -> 
 Col A B N -> Col P Q N -> 
 M = N.
Proof with Geometry.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros.
assert (A<>B)
 by (intro;subst;auto with Geom).
assert (P<>Q)
 by (intro;subst;auto with Geom).
assert (Col A M N)
 by (apply (col_trans_1 A B M N);auto).
assert (Col P M N)
 by (apply (col_trans_1 P Q M N);auto).
(* Goal: False *)
cases_equality M N;auto.
assert (Col M A P) 
by (apply (col_trans_1 M N A P); auto with Geom).

assert (Col B M N) 
 by (apply (col_trans_1 B A M N);auto with Geom).
assert (Col Q M N)
 by (apply (col_trans_1 Q P M N);auto with Geom).
assert (Col M Q B) 
 by (apply (col_trans_1 M N Q B);auto with Geom).

cases_equality P M.
(* Goal: parallel D Q P D *)
(* Goal: parallel D Q P C *)
subst.
(* Goal: parallel D Q Q D *)
(* Goal: parallel D Q P C *)
unfold parallel, S4 in *.
rewrite H12 in H.
(* Goal: @eq F (Fplus (S D Q Q) (S D Q D)) F0 *)
(* Goal: parallel D Q P C *)
basic_simpl.
clear H7 H9 H1 H3.
assert (Col M A Q)
 by (apply  (col_trans_1 M N A Q);auto with Geom).
(* Goal: not (@eq Point A B) *)
intuition.

assert (Col P A Q) 
by (apply (col_trans_1 P M A Q);auto with Geom).

(* Goal: parallel D Q Q D *)
(* Goal: parallel D Q P C *)
unfold parallel, S4 in *.
rewrite H14 in H.
(* Goal: @eq F (Fplus (S D Q Q) (S D Q D)) F0 *)
(* Goal: parallel D Q P C *)
basic_simpl.

cases_equality Q M.
(* Goal: parallel D Q P D *)
(* Goal: parallel D Q P C *)
subst.
clear H1 H11 H12 H14.
assert (Col M P B) 
by (apply (col_trans_1 M N P B);auto with Geom).
(* Goal: False *)
assert (Col P M B) by auto with Geom.
(* Goal: not (@eq Point A B) *)
intuition.

assert (Col Q B P)
by (apply (col_trans_1 Q M B P);auto with Geom).
(* Goal: False *)
assert (Col P Q B) by auto with Geom.
(* Goal: not (@eq Point A B) *)
intuition.
Qed.




Theorem co_side_bis :
 forall A B P Q M : Point,
 ~ parallel P Q A B ->
 Col A B M -> Col P Q M -> Q ** M / P ** Q = S Q A B / S4 P A Q B.

Proof with Geometry.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros...
assert (P <> Q)...
eapply par_aux_1; apply H...
cases_equality Q M...
assert (Q ** M = 0)...
rewrite H4...
rewrite <- H3 in H0...
assert (Col Q A B)...
unfold parallel in H...
rewrite H5; field...

cases_equality A Q...
assert (A = M)...
apply (inter_unicity A B P Q M H H0 H1 H4)...
rewrite H4...
assert (Q = M)...
congruence...
assert (Q ** M = 0)...
assert (S Q Q B = 0)...
rewrite H7...
rewrite H8...
field...

assert (~ Col Q A B)...
(* Goal: not (@eq Point C D) *)
unfold not in |- *; intro...
unfold parallel in H...
unfold S4 in H...
assert (S P A B = S P A Q + S P Q B + S Q A B)...
rewrite H5 in H6...
IsoleVar (S P A Q) H6...
rewrite H6 in H...
assert (S P A B - 0 - S P Q B + S P Q B = S P A B)...
(* Goal: @eq F (Fopp (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q B A)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P B A)))) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (Fopp (S Q B A))) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (Fopp (S P B A)))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
ring...
rewrite H7 in H...
clear H6 H7...
assert (Col A B Q)...
assert (A <> B)...
(* Goal: not (@eq Point C D) *)
unfold not in |- *; intro...
assert (S P A B = 0)...
rewrite H7...
(* Goal: False *)
assert (Col A M Q); eauto with Geom...
assert (Col Q M P)...
assert (Col Q M A)...
(* Goal: False *)
assert (Col Q A P); eauto with Geom...
assert (Col A Q B)...
assert (Col A Q P)...

(* Goal: False *)
assert (Col A B P); eauto with Geom...
assert (Col P A B)...

assert (P ** M / Q ** M = S P A B / S Q A B)...
assert (Q ** M / P ** Q * (P ** Q / Q ** M) = 1)...
field...
assert (P ** M / Q ** M - 1 = P ** Q / Q ** M).
replace (P ** Q) with (P ** M - Q ** M).
field...
assert (Q ** M = - M ** Q)...
rewrite H8 in |- *.
ring_simplify...

rewrite <- H8 in H7.
clear H8.
rewrite H6 in H7.
assert (S4 P A Q B = S P A B - S Q A B)...
rewrite H8.
clear H8.
IsoleVar (Q ** M / P ** Q) H7...
rewrite H7.
field...
split...
assert (S4 P A Q B = S P A B - S Q A B)...
(* Goal: or (not (Col P U Q)) (not (Col P Q V)) *)
(* Goal: or (not (Col P U Q)) (not (Col P Q V)) *)
unfold parallel in H.
rewrite H9 in H...
assert (S P A B / S Q A B - 1 = (S P A B - S Q A B) / S Q A B).
field...
rewrite H8...
apply nonzerodiv...
assert (S4 P A Q B = S P A B - S Q A B)...
rewrite <- H9...
Qed.

Hint Resolve co_side_bis: Geom.


Theorem co_side_ter :
 forall A B P Q M : Point,
 ~ parallel P Q A B ->
 Col A B M -> Col P Q M -> P ** M / P ** Q = S P A B / S4 P A Q B.
Proof with Geometry.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros...
assert (Q ** M / P ** Q = S Q A B / S4 P A Q B)...
assert (P ** Q + Q ** M = P ** M)...
rewrite <- H3...
RewriteVar (Q ** M) H2...
assert (S P A B = S P A Q + S P Q B + S Q A B)...
rewrite H5...
unfold S4 in |- *...
field...
assert (P <> Q)...
eapply par_aux_1; apply H...
Qed.

Hint Resolve co_side_ter: Geom.


Theorem l2_9_weak :
 forall A B P Q R : Point,
 P <> Q ->
 ~ Col Q A P ->
 ~ Col Q P B ->
 Col R P Q -> S R A B = P ** R / P ** Q * S Q A B + R ** Q / P ** Q * S P A B.
Proof with Geometry.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros...
assert (S R A B = S R A P + S R P B + S P A B)...
assert (P ** R / P ** Q = S R A P / S Q A P)...

RewriteVar (S R A P) H4...
clear H4...

assert (P ** R / P ** Q = S B P R / S B P Q)...
assert (- S B P R = S R P B)...
rewrite <- H6 in H3...
RewriteVar (S B P R) H4...
clear H4 H6...

assert (S R A B = P ** R / P ** Q * (S Q A P - S B P Q) + S P A B)...
rewrite H3...
field...
clear H3...
assert (S A P Q - S B P Q = S4 A P B Q)...
unfold S4 in H3...
assert (S Q A P = S A P Q)...
rewrite <- H6 in H3...
rewrite H3 in H4...
clear H3 H6...
assert (S A B Q = S Q A B)...
rewrite H3 in H4...
clear H3...
assert (S A P B = - S P A B)...
rewrite H3 in H4...
clear H3...
assert
 (P ** R / P ** Q * (- S P A B + S Q A B) + S P A B =
  P ** R / P ** Q * S Q A B + (1 - P ** R / P ** Q) * S P A B)...
field...
rewrite H3 in H4...
clear H3...
assert (1 - P ** R / P ** Q = R ** Q / P ** Q)...
assert (R ** P + P ** Q = R ** Q)...
rewrite <- H3...
assert (R ** P = - P ** R)...
(* Goal: @eq F (Fopp (S R B A)) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (Fopp (S Q B A))) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
rewrite H6.
field...
congruence...
Qed.

Theorem l2_9aux :
 forall A B P Q R : Point,
 P <> Q ->
 Col R P Q ->
 Col Q A P ->
 ~ Col Q P B -> S R A B = P ** R / P ** Q * S Q A B + R ** Q / P ** Q * S P A B.
Proof.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros.
cases_equality Q A.
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
assert (Col Q A B).
apply egalcol.
(* Goal: False *)
auto.
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
rewrite H4.
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) F0) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) F0)) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
ring_simplify.
rewrite <- H3.
assert (R ** Q / P ** Q = S R Q B / S P Q B); Geometry.
(* Goal: @eq F (Fopp (S R B A)) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
rewrite H5.
field; Geometry.

assert (~ Col Q A B).
(* Goal: not (@eq Point C D) *)
unfold not in |- *; intro.
assert (Col Q P B).
(* Goal: False *)
eauto with Geom.
(* Goal: False *)
auto.

(* Goal: Col R A B *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
assert (Col Q R A).
assert (Col P Q R); Geometry.
assert (Col P Q A); Geometry.
(* Goal: False *)
eauto with Geom.

assert (A ** R / A ** Q = S R A B / S Q A B); Geometry.
assert (A ** P / A ** Q = S P A B / S Q A B); Geometry.

RewriteVar (S R A B) H6.
RewriteVar (S P A B) H7.
(* Goal: @eq F F0 F0 *)
(* Goal: parallel D Q P C *)
2: trivial.

assert (A ** R / A ** Q = P ** R / P ** Q + R ** Q / P ** Q * (A ** P / A ** Q)).

assert (A ** Q + Q ** R = A ** R).
apply chasles.
(* Goal: @eq Point A B *)
Geometry.
assert (A ** R * P ** Q = A ** Q * P ** Q + Q ** R * P ** Q).
rewrite <- H9.
(* Goal: @eq F (Fopp (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q B A)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P B A)))) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (Fopp (S Q B A))) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (Fopp (S P B A)))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
ring.

assert (P ** R + R ** Q = P ** Q).
apply chasles.
(* Goal: @eq Point A B *)
Geometry.
assert
 (A ** Q * P ** Q + Q ** R * P ** Q = A ** Q * (P ** R + R ** Q) + Q ** R * P ** Q).
rewrite <- H11.
(* Goal: @eq F (Fopp (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q B A)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P B A)))) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (Fopp (S Q B A))) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (Fopp (S P B A)))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
ring.
rewrite H12 in H10.
clear H12.
NormalizeRing H10.

assert (P ** Q * Q ** R + A ** Q * R ** Q = R ** Q * A ** P).
assert (A ** Q + Q ** P = A ** P).
apply chasles.
(* Goal: @eq Point A B *)
Geometry.

rewrite <- H12.
(* Goal: @eq Point A B *)
assert (P ** Q = - Q ** P); Geometry.
rewrite H13.
(* Goal: @eq Point A B *)
assert (Q ** R = - R ** Q); Geometry.
rewrite H14.
(* Goal: @eq F (Fopp (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q B A)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P B A)))) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (Fopp (S Q B A))) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (Fopp (S P B A)))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
ring.

assert (P ** Q * A ** R = A ** Q * P ** R + R ** Q * A ** P).
(* Goal: @eq F (Fopp (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q B A)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P B A)))) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (Fopp (S Q B A))) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (Fopp (S P B A)))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
replace (P ** Q * A ** R) with (A ** R * P ** Q) by  ring.
rewrite H10.
rewrite <- H12.
(* Goal: @eq F (Fopp (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q B A)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P B A)))) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (Fopp (S Q B A))) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (Fopp (S P B A)))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
ring.

clear H9 H10 H11 H12. 
IsoleVar (A ** R) H13.
rewrite H13.
field; Geometry.
(* Goal: @eq Point A B *)
Geometry.

rewrite H9.
(* Goal: @eq F (Fopp (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q B A)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P B A)))) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (Fopp (S Q B A))) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (Fopp (S P B A)))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
ring.
Qed.

Theorem l2_9 :
 forall A B P Q R : Point,
 P <> Q ->
 Col R P Q -> S R A B = P ** R / P ** Q * S Q A B + R ** Q / P ** Q * S P A B.
Proof.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros.
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
cases_col Q A P.
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
cases_col Q P B.
(* Goal: @eq Point A B *)
assert (Col Q P A); Geometry.
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
clear H1.
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
assert (Col Q A B).
(* Goal: False *)
eauto with Geom.
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
assert (Col P A B).
(* Goal: False *)
eauto with Geom. 
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
rewrite H1.
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
rewrite H4.
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) F0) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) F0)) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
ring_simplify.
(* Goal: @eq F (S R A B) F0 *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
change (Col R A B) in |- *.
(* Goal: Col R A B *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
assert (Col Q R B).
(* Goal: False *)
eauto with Geom.
(* Goal: Col R A B *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
assert (Col Q R A).
(* Goal: False *)
eauto with Geom.
(* Goal: @eq Point A B *)
assert (Col R Q B); Geometry.
(* Goal: @eq Point A B *)
assert (Col R Q A); Geometry.
(* Goal: Col R A B *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
cases_equality R Q.
(* Goal: @eq F F0 F0 *)
(* Goal: parallel D Q P C *)
rewrite H9; trivial.
(* Goal: False *)
eauto with Geom.

(* Goal: False *)
apply l2_9aux; auto.
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
cases_col Q P B.
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
assert (S R B A = P ** R / P ** Q * S Q B A + R ** Q / P ** Q * S P B A).
(* Goal: @eq Point A B *)
apply l2_9aux; Geometry.

(* Goal: @eq Point A B *)
assert (S R A B = - S R B A); Geometry.
(* Goal: @eq Point A B *)
assert (S Q A B = - S Q B A); Geometry.
(* Goal: @eq Point A B *)
assert (S P A B = - S P B A); Geometry.
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
rewrite H4.
(* Goal: @eq F (Fopp (S R B A)) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
rewrite H5.
(* Goal: @eq F (Fopp (S R B A)) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (Fopp (S Q B A))) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
rewrite H6.
(* Goal: @eq F (Fopp (S R B A)) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (Fopp (S Q B A))) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (Fopp (S P B A)))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
rewrite H3.
(* Goal: @eq F (Fopp (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q B A)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P B A)))) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (Fopp (S Q B A))) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (Fopp (S P B A)))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
ring.

(* Goal: False *)
apply l2_9_weak; auto.
Qed.


(********************************************************************)
(* Construction lemmas                                              *)
(********************************************************************)

Theorem A2bgen :
 forall (A B P P' : Point) (r : F),
 Col A B P -> A ** P = r * A ** B -> Col A B P' -> A ** P' = r * A ** B -> P = P'.
Proof with Geometry.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros...
cases_equality A B...
assert (A ** B = 0)...
rewrite H4 in H2...
rewrite H4 in H0...
NormalizeRing H2...
NormalizeRing H0...
assert (A = P')...
assert (A = P)...
congruence...
(* exemple de conflis proof with et metavariable ici *)
apply (A2b A B P P' r H3 H H0 H1 H2)...
Qed.


Definition mid_point (I A B : Point) : Prop := 
  Col A B I /\ A ** I = I ** B.

Definition symmetric_point (I A B : Point) : Prop :=
  Col A B I /\ A ** B = B ** I.


Theorem mid_point_ex : forall A B : Point, {O : Point | mid_point O A B}.
Proof with try solve [ Geometry | field; Geometry | congruence ].
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros...
assert (T := A2a A B (1 / 2))...
elim T; intros; clear T...
exists x...
(* Goal: not (@eq Point A B) *)
intuition...
assert (A ** x + x ** B = A ** B)...
unfold mid_point in |- *...
(* Goal: not (@eq Point A B) *)
intuition...
RewriteVar (A ** x) H0...
RewriteVar (x ** B) H1...
Qed.


Theorem symmetric_point_ex :
 forall A O : Point, {A' : Point | Col A O A' /\ A ** O = O ** A'}.
Proof with try solve [ Geometry | ring | congruence ].
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros...
assert (T := A2a A O 2)...
elim T; intros; clear T...
exists x...
unfold symmetric_point in |- *...
(* Goal: not (@eq Point A B) *)
intuition...
assert (O ** x = - x ** O)...
assert (A ** x + x ** O = A ** O)...
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
rewrite H1; clear H1...
RewriteVar (A ** x) H0...
RewriteVar (x ** O) H2...
Qed.



Lemma mid_point_comm :
  forall A B C,
  mid_point A B C -> mid_point A C B.
Proof with Geometry.
unfold mid_point.
(* Goal: not (@eq Point A B) *)
intuition.
Qed.

Hint Immediate mid_point_comm : Geom.


Theorem diag_mid_point_parallel : forall O A P B Q,
mid_point O A P -> mid_point O B Q -> parallel A B P Q.
Proof with Geometry.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros.
unfold mid_point in *.
(* Goal: @eq Point A B *)
DecompAndAll.
rename H0 into H.
assert (Col B O Q)...
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
clear H1.
rename H0 into H1.
rename H3 into H0.




cases_equality A P...
assert (A = O)...
assert (A ** O + O ** P = A ** P)...
assert (A ** P = 0)...
rewrite H5 in H4; clear H5...
rewrite <- H0 in H4...
assert (A ** O + A ** O = 2 * A ** O)...
(* Goal: @eq F (Fopp (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q B A)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P B A)))) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (Fopp (S Q B A))) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (Fopp (S P B A)))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
ring...
rewrite H5 in H4; clear H5...
IsoleVar (A ** O) H4...
assert (0 / 2 = 0)...
field...
rewrite H6 in H4...
unfold parallel in |- *...
unfold S4 in |- *...
rewrite H3...
assert (S P P B = 0)...
rewrite H5...
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) F0) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) F0)) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
ring_simplify.
assert (Col P B Q)...
rewrite <- H3...
rewrite <- H4 in H1...


assert (A <> O)...
(* Goal: not (@eq Point C D) *)
  unfold not in |- *; intro...
  assert (A ** O = 0)...
  rewrite H5 in H0...
  assert (O = P)...
  assert (A = P)...
  congruence...

cases_equality B O...
unfold parallel in |- *...
unfold S4 in |- *...
assert (B ** O = 0)...
rewrite H6 in H2...
assert (O = Q)...
assert (B = Q)...
congruence...
rewrite H7 in H...
rewrite H8...
rewrite H...
assert (S A Q Q = 0)...
rewrite H9...

cases_col O A B...
unfold parallel in |- *...
unfold S4 in |- *...
assert (Col A O B)...
assert (Col A O P)...
(* Goal: False *)
assert (Col A P B); eauto with Geom...
assert (Col B O Q)...
assert (Col B O A)...
(* Goal: False *)
assert (Col B Q A); eauto with Geom...
rewrite H9...
assert (Col A B Q)...
rewrite H13...


assert (Q ** B / O ** B = S Q A B / S O A B)...

assert (Q <> O)...
(* Goal: not (@eq Point C D) *)
unfold not in |- *; intro...
assert (O ** Q = 0)...
assert (B ** O = 0)...
congruence...


assert (Q ** B / O ** B = 2)...
assert (Q ** B = Q ** O + O ** B)...
symmetry  in |- *...
rewrite H9...
assert (O ** B = Q ** O)...
rewrite H10...
field...

assert (O <> P)...
(* Goal: not (@eq Point C D) *)
unfold not in |- *; intro...
assert (O ** P = 0)...
assert (A ** O = 0)...
congruence...

assert (P ** A / O ** A = S P A B / S O A B)...
assert (P ** A / O ** A = A ** P / A ** O)...
assert (A ** O + O ** P = A ** P)...
rewrite <- H13 in H12...
rewrite H0 in H12...
assert ((O ** P + O ** P) / O ** P = 2)...
field...

rewrite H14 in H12...
unfold parallel in |- *...

assert (S Q A B / S O A B = S P A B / S O A B)...
congruence...
assert (S Q A B = S A B Q)...
assert (S A P B = - S P A B)...
unfold S4 in |- *...
rewrite <- H16...
rewrite H17...
RewriteVar (S Q A B) H15...
field...
Qed.


Theorem euclid_parallel_existence_strong :
 forall A B P : Point, A<>B -> {Q : Point | parallel A B P Q /\ P<>Q}.
Proof with Geometry.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros.
assert (Op := mid_point_ex A P)... 
elim Op; intro O; clear Op...
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros...
elim p; intros; clear p...
assert (Op := symmetric_point_ex B O)...
elim Op; intro Q; clear Op...
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros...
elim p; intros; clear p...
exists Q...

split.
eapply diag_mid_point_parallel;unfold mid_point;split.
apply H0.
(* Goal: @eq F (DSeg P Q) F0 *)
(* Goal: parallel D Q P D *)
(* Goal: parallel D Q P C *)
assumption.
(* Goal: @eq Point A B *)
Geometry.
(* Goal: @eq F (DSeg P Q) F0 *)
(* Goal: parallel D Q P D *)
(* Goal: parallel D Q P C *)
assumption.

(* Goal: not (@eq Point C D) *)
unfold not;intro.
subst Q.
rewrite <- H1 in H3.
cases_equality O P.
subst P.
replace (O**O) with 0 in H1.
(* Goal: @eq Point A B *)
2:symmetry;Geometry.
assert (A=O).
(* Goal: @eq Point A B *)
Geometry.
subst A.
replace (O**O) with 0 in H3.
assert (B=O).
(* Goal: @eq Point A B *)
Geometry.
subst B.
(* Goal: not (@eq Point A B) *)
intuition.
assert (Col O A B).
eapply col_trans_1 with (B:=P)...
assert (A**O+O**B=A**B)...
rewrite <- H3 in H6.
replace (B**O) with (-O**B) in H6.
NormalizeRing H6.
assert (A=B)...
(* Goal: @eq Point A B *)
symmetry;Geometry.
Qed.

Theorem euclid_parallel_existence :
 forall A B P : Point, {Q : Point | parallel A B P Q}.
Proof with Geometry.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros.
assert (Op := mid_point_ex A P)... 
elim Op; intro O; clear Op...
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros...
elim p; intros; clear p...
assert (Op := symmetric_point_ex B O)...
elim Op; intro Q; clear Op...
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros...
elim p; intros; clear p...
exists Q...


eapply diag_mid_point_parallel;unfold mid_point;split.
apply H.
(* Goal: @eq F (DSeg P Q) F0 *)
(* Goal: parallel D Q P D *)
(* Goal: parallel D Q P C *)
assumption.
(* Goal: @eq Point A B *)
Geometry.
(* Goal: @eq F (DSeg P Q) F0 *)
(* Goal: parallel D Q P D *)
(* Goal: parallel D Q P C *)
assumption.
Qed.


(*******************************)
(* Some lemmas about parallels *)
(*******************************)

Theorem par_1 : forall A B C D : Point, 
   parallel A B C D -> parallel B A C D.
Proof with Geometry.
unfold parallel, S4 in |- *.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros.
uniformize_signed_areas.
RewriteVar (S A C B) H.
(* Goal: @eq F (Fopp (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q B A)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P B A)))) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (Fopp (S Q B A))) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (Fopp (S P B A)))) *)
(* Goal: @eq F (S R A B) (Fplus (Fmult (Fdiv (DSeg P R) (DSeg P Q)) (S Q A B)) (Fmult (Fdiv (DSeg R Q) (DSeg P Q)) (S P A B))) *)
ring.
Qed.

Hint Resolve par_1: Geom.

Theorem par_2 : forall A B C D : Point, 
   parallel A B C D -> parallel C D A B.
Proof with Geometry.
unfold parallel in |- *.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros.
assert (S4 A C B D = - S4 C A D B)...
(* Goal: or (not (Col P U Q)) (not (Col P Q V)) *)
(* Goal: or (not (Col P U Q)) (not (Col P Q V)) *)
rewrite H0 in H...
Qed.

Hint Resolve par_2: Geom.

Theorem not_parallel_not_eq_1 : forall A B C D,
  ~ parallel A B C D -> A<>B. 
Proof with Geometry.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros.
unfold not;intro;subst A...
Qed.

Theorem not_parallel_not_eq_2 : forall A B C D,
  ~ parallel A B C D -> C<>D. 
Proof with Geometry.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros.
unfold not;intro;subst C...
Qed.

Hint Resolve not_parallel_not_eq_1 not_parallel_not_eq_2 : Geom.

Lemma mid_point_degenerated_1 : forall A B, mid_point A A B -> A=B.
Proof.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros.
(* Goal: @eq Point A B *)
unfold mid_point in H.
(* Goal: @eq Point A B *)
DecompAndAll.
(* Goal: @eq F (Fplus (S D Q Q) (S D Q D)) F0 *)
(* Goal: parallel D Q P C *)
basic_simpl.
(* Goal: @eq Point A B *)
Geometry.
Qed.

Lemma mid_point_degenerated_2 : forall A B, mid_point A B B -> A=B.
Proof with Geometry.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros.
(* Goal: @eq Point A B *)
unfold mid_point in H.
(* Goal: @eq Point A B *)
DecompAndAll.
replace (A**B) with (- B**A) in H1.
2:symmetry...
assert (B**A = 0)...
(* Goal: @eq Point A B *)
symmetry;Geometry.
Qed.

Lemma mid_point_degenerated_3 : forall A B, mid_point A B A -> A=B.
Proof.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros.
(* Goal: @eq Point A B *)
unfold mid_point in H.
(* Goal: @eq Point A B *)
DecompAndAll.
(* Goal: @eq F (Fplus (S D Q Q) (S D Q D)) F0 *)
(* Goal: parallel D Q P C *)
basic_simpl.
(* Goal: @eq Point A B *)
symmetry;Geometry.
Qed.


Hint Resolve mid_point_degenerated_1 mid_point_degenerated_2 mid_point_degenerated_3:Geom.

Lemma eq_diff_diff : forall A B C D, A<>B -> A**B=C**D -> C<>D.
Proof with Geometry.
intuition idtac.
subst C.
(* Goal: @eq F (Fplus (S D Q Q) (S D Q D)) F0 *)
(* Goal: parallel D Q P C *)
basic_simpl...
Qed.

Hint Resolve eq_diff_diff : Geom.

Lemma parallel_side_eq_parallel' : forall P Q C D,
  parallel P Q C D -> P**Q=C**D -> parallel D Q P C. 
Proof.
(* Goal: forall (P Q C D : Point) (_ : parallel P Q C D) (_ : @eq F (DSeg P Q) (DSeg C D)), parallel D Q P C *)
intros.
(* Goal: parallel D Q P C *)
cases_equality C D.
(* Goal: parallel D Q P D *)
(* Goal: parallel D Q P C *)
subst.
(* Goal: @eq F (Fplus (S D Q Q) (S D Q D)) F0 *)
(* Goal: parallel D Q P C *)
basic_simpl.
(* Goal: parallel D Q P D *)
(* Goal: parallel D Q P C *)
assert (P=Q).
(* Goal: @eq Point P Q *)
(* Goal: parallel D Q P D *)
(* Goal: parallel D Q P C *)
apply A1b.
(* Goal: @eq F (DSeg P Q) F0 *)
(* Goal: parallel D Q P D *)
(* Goal: parallel D Q P C *)
assumption.
(* Goal: parallel D Q P D *)
(* Goal: parallel D Q P C *)
subst.
(* Goal: parallel D Q Q D *)
(* Goal: parallel D Q P C *)
clear H0.
(* Goal: parallel D Q Q D *)
(* Goal: parallel D Q P C *)
unfold parallel,S4 in *.
(* Goal: @eq F (Fplus (S D Q Q) (S D Q D)) F0 *)
(* Goal: parallel D Q P C *)
basic_simpl.
(* Goal: @eq F F0 F0 *)
(* Goal: parallel D Q P C *)
trivial.
(* Goal: False *)
apply parallel_side_eq_parallel;auto.
Qed.



