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

Require Export area_coords_constructions.

(* Those lemma are not proved as they are used only 
in a optimisation of the method. *)

Lemma elim_py_a_ratio_right : forall Y O U V A B ro ru rv,
 a_ratio Y O U V ro ru rv ->
 Py A B Y = ro * Py A B O + ru * Py A B U + rv * Py A B V.
Proof.
Admitted.

Lemma elim_signed_area_a_ratio : forall Y O U V A B ro ru rv,
 a_ratio Y O U V ro ru rv ->
 S A B Y = ro * S A B O + ru * S A B U + rv * S A B V.
Proof.
(* Goal: forall (Y O U V A : Point) (ro ru rv : F) (_ : a_ratio Y O U V ro ru rv), @eq F (Py Y A Y) (Fplus (Fplus (Fmult ro (Fplus (Fplus (Fmult ro (Py O A O)) (Fmult ru (Py O A U))) (Fmult rv (Py O A V)))) (Fmult ru (Fplus (Fplus (Fmult ro (Py U A O)) (Fmult ru (Py U A U))) (Fmult rv (Py U A V))))) (Fmult rv (Fplus (Fplus (Fmult ro (Py V A O)) (Fmult ru (Py V A U))) (Fmult rv (Py V A V))))) *)
intros.
Admitted.

Lemma elim_py_a_ratio_middle : forall Y O U V A B ro ru rv,
 a_ratio Y O U V ro ru rv ->
 Py A Y B = ro * Py A O B + ru * Py A U B + rv * Py A V B 
     - ro*ru*Py O U O - ro*ru*Py O V O - ru*rv * Py U V U.
Proof.
(* Goal: forall (Y O U V A : Point) (ro ru rv : F) (_ : a_ratio Y O U V ro ru rv), @eq F (Py Y A Y) (Fplus (Fplus (Fmult ro (Fplus (Fplus (Fmult ro (Py O A O)) (Fmult ru (Py O A U))) (Fmult rv (Py O A V)))) (Fmult ru (Fplus (Fplus (Fmult ro (Py U A O)) (Fmult ru (Py U A U))) (Fmult rv (Py U A V))))) (Fmult rv (Fplus (Fplus (Fmult ro (Py V A O)) (Fmult ru (Py V A U))) (Fmult rv (Py V A V))))) *)
intros.
Admitted.


Lemma elim_py_a_ratio_left_right : forall Y O U V A ro ru rv,
 a_ratio Y O U V ro ru rv ->
 Py Y A Y = ro * (ro * Py O A O + ru * Py O A U + rv * Py O A V) +
                   ru * (ro * Py U A O + ru * Py U A U + rv * Py U A V) +
                   rv * (ro * Py V A O + ru * Py V A U + rv * Py V A V).
Proof.
(* Goal: forall (Y O U V A : Point) (ro ru rv : F) (_ : a_ratio Y O U V ro ru rv), @eq F (Py Y A Y) (Fplus (Fplus (Fmult ro (Fplus (Fplus (Fmult ro (Py O A O)) (Fmult ru (Py O A U))) (Fmult rv (Py O A V)))) (Fmult ru (Fplus (Fplus (Fmult ro (Py U A O)) (Fmult ru (Py U A U))) (Fmult rv (Py U A V))))) (Fmult rv (Fplus (Fplus (Fmult ro (Py V A O)) (Fmult ru (Py V A U))) (Fmult rv (Py V A V))))) *)
intros.
rewrite (elim_py_a_ratio_right  Y O U V Y A ro ru rv H).
(* Goal: @eq F (Fplus (Fplus (Fmult ro (Py Y A O)) (Fmult ru (Py Y A U))) (Fmult rv (Py Y A V))) (Fplus (Fplus (Fmult ro (Fplus (Fplus (Fmult ro (Py O A O)) (Fmult ru (Py O A U))) (Fmult rv (Py O A V)))) (Fmult ru (Fplus (Fplus (Fmult ro (Py U A O)) (Fmult ru (Py U A U))) (Fmult rv (Py U A V))))) (Fmult rv (Fplus (Fplus (Fmult ro (Py V A O)) (Fmult ru (Py V A U))) (Fmult rv (Py V A V))))) *)
replace (Py Y A O) with (Py O A Y) by auto with Geom.
(* Goal: @eq F (Fplus (Fplus (Fmult ro (Py O A Y)) (Fmult ru (Py Y A U))) (Fmult rv (Py Y A V))) (Fplus (Fplus (Fmult ro (Fplus (Fplus (Fmult ro (Py O A O)) (Fmult ru (Py O A U))) (Fmult rv (Py O A V)))) (Fmult ru (Fplus (Fplus (Fmult ro (Py U A O)) (Fmult ru (Py U A U))) (Fmult rv (Py U A V))))) (Fmult rv (Fplus (Fplus (Fmult ro (Py V A O)) (Fmult ru (Py V A U))) (Fmult rv (Py V A V))))) *)
replace (Py Y A U) with (Py U A Y) by auto with Geom.
(* Goal: @eq F (Fplus (Fplus (Fmult ro (Py O A Y)) (Fmult ru (Py U A Y))) (Fmult rv (Py Y A V))) (Fplus (Fplus (Fmult ro (Fplus (Fplus (Fmult ro (Py O A O)) (Fmult ru (Py O A U))) (Fmult rv (Py O A V)))) (Fmult ru (Fplus (Fplus (Fmult ro (Py U A O)) (Fmult ru (Py U A U))) (Fmult rv (Py U A V))))) (Fmult rv (Fplus (Fplus (Fmult ro (Py V A O)) (Fmult ru (Py V A U))) (Fmult rv (Py V A V))))) *)
replace (Py Y A V) with (Py V A Y) by auto with Geom.
rewrite (elim_py_a_ratio_right  Y O U V O A ro ru rv H).
rewrite (elim_py_a_ratio_right  Y O U V U A ro ru rv H).
rewrite (elim_py_a_ratio_right  Y O U V V A ro ru rv H).
(* Goal: @eq F (Fplus (Fplus (Fmult ro (Fplus (Fplus (Fmult ro (Py O A O)) (Fmult ru (Py O A U))) (Fmult rv (Py O A V)))) (Fmult ru (Fplus (Fplus (Fmult ro (Py U A O)) (Fmult ru (Py U A U))) (Fmult rv (Py U A V))))) (Fmult rv (Fplus (Fplus (Fmult ro (Py V A O)) (Fmult ru (Py V A U))) (Fmult rv (Py V A V))))) (Fplus (Fplus (Fmult ro (Fplus (Fplus (Fmult ro (Py O A O)) (Fmult ru (Py O A U))) (Fmult rv (Py O A V)))) (Fmult ru (Fplus (Fplus (Fmult ro (Py U A O)) (Fmult ru (Py U A U))) (Fmult rv (Py U A V))))) (Fmult rv (Fplus (Fplus (Fmult ro (Py V A O)) (Fmult ru (Py V A U))) (Fmult rv (Py V A V))))) *)
auto.
Qed.

