(***************************************************************************)
(* 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 parallel_lemmas.
(*********************************************************************)
(*  Construction statements                                                         *)
(*********************************************************************)
Definition on_line (A B C : Point) : Prop := Col A B C /\ B <> C.
Definition on_line_d (A B C : Point) (lambda : F) : Prop :=
Col A B C /\ B <> C /\ B ** A = lambda * B ** C.
Definition inter_ll (I A B C D : Point) : Prop :=
Col I A B /\ Col I C D /\ ~ parallel A B C D.
Definition on_parallel (A' A B C : Point) : Prop := B <> C  /\ parallel A A' B C.
Definition on_parallel_d (Y R P Q : Point) (lambda : F) : Prop :=
P <> Q  /\ parallel Y R P Q /\ R ** Y = lambda * P ** Q.
Definition on_inter_line_parallel (Y R U V P Q : Point) : Prop :=
~Col R P Q /\ Col Y U V /\ parallel Y R P Q /\ ~ parallel P Q U V.
Definition on_inter_parallel_parallel (Y R U V W P Q : Point) : Prop :=
~Col R P Q /\ parallel Y R U V /\ parallel Y W P Q /\ ~ parallel P Q U V.
Definition is_midpoint (I A B : Point) := on_line_d I A B (1 / 2).
Definition mratio (Y U V : Point) (r : F) :=
on_parallel_d Y U U V (r / (1 + r)) /\ 1 + r  <> 0.
(** Lemma to go from point at some distance to point on a line *)
Proof with Geometry.
intros.
assert (T := A2a P Q 1)...
DecompExAnd T X.
exists X...
Qed.
Proof with Geometry.
intros.
assert {Y : Point | Col Y P Q}.
apply on_lineex...
DecompEx H0 Y.
exists Y.
unfold on_line...
Qed.
Proof with Geometry.
intros.
assert (T := A2a P Q lambda).
DecompExAnd T X.
exists X...
Qed.
Proof with Geometry.
intros.
assert (P <> Q).
eapply par_aux_1.
apply H...
assert (T := A2a P Q (S P U V / S4 P U Q V))...
elim T; intro O; intros...
decompose [and] p...
clear T p...
cut (O ** Q / P ** Q = - (S Q U V / S4 P U Q V))...
intro...
assert (S O U V = P ** O / P ** Q * S Q U V + O ** Q / P ** Q * S P U V)...
apply l2_9...
assert (P ** O / P ** Q = S P U V / S4 P U Q V)...
rewrite H2...
field...
clear H2; rename H5 into H2...
rewrite H2 in H4...
rewrite H3 in H4...
assert (S O U V = 0)...
rewrite H4; field...
exists O...
assert (P ** O / P ** Q = S P U V / S4 P U Q V)...
rewrite H2; field...
clear H2; rename H3 into H2...
assert (P ** Q + Q ** O = P ** O)...
rewrite <- H3 in H2...
assert (O ** Q / P ** Q = 1 - S P U V / S4 P U Q V)...
rewrite <- H2...
assert (O ** Q = - Q ** O)...
rewrite H4...
field...
assert (1 - S P U V / S4 P U Q V = (S4 P U Q V - S P U V) / S4 P U Q V)...
field...
rewrite H5 in H4...
clear H5...
unfold S4 in H4...
assert (S P U Q + S P Q V - S P U V = - S Q U V)...
assert (S P Q V = S P Q U + S P U V + S U Q V)...
rewrite H5...
assert (S P Q U = - S P U Q)...
rewrite H6...
assert (S U Q V = - S Q U V)...
rewrite H7...
ring...
rewrite H5 in H4...
rewrite H4...
unfold S4 in |- *...
field...
Qed.

Lemma inter_ll_ex :  forall P Q U V : Point,
~ parallel P Q U V -> exists Y, inter_ll Y P Q U V.