(***************************************************************************)
(* 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 general_tactics.
Require Export Rgeometry_tools.
Require Export constructed_points_elimination.
Require Export free_points_elimination.
Require Export simplify_constructions.
Require Export construction_tactics.
Require Export my_field_tac.
(* Ltac kill_not_eq := (match goal with | H: ?X <> F0 |- _  => ((let tmp := fresh in ( intros tmp; case H; rewrite <- tmp); newring; fail) || clear H); kill_not_eq end).  Ltac kill_cond_tac := repeat (remove_hyp_div_not_eq_zero; repeat split; auto; try Geometry); try newfield; (repeat split); auto; try Geometry; try split_goal_not_eq_zero; auto; unfold_field; kill_not_eq.   Ltac field_and_conclude := abstract kill_cond_tac. *)
Ltac decomp_non_zero_mult_div H :=
(apply (multnonzero) in H || apply (divnonzero) in H; use H).
Ltac decomp_all_non_zero_mult_div := repeat match goal with
H: ?X <> 0 |- _ => decomp_non_zero_mult_div H
end.
Ltac field_and_conclude :=
(abstract (field;decomp_all_non_zero_mult_div;solve_conds)) ||
(abstract (Ffield)).
(* TODO debugger Ffield instead of using second version *)
Ltac DecomposeMratio :=
repeat
match goal with
| H:(mratio _ _ _ _) |- _ =>
unfold mratio in H; decompose [and] H; clear H
end.
(** This tactic change on_line into on_line_d on_parallel into on_parallel_d on_perp into on_perp_d by setting the distance as a parameter.*)
(** This has the advantage to reduce the number of cases in the elimination process and to ease the development because then all constructed point can be eliminated, otherwise we get ratios such as A**Y/C**D which are parameters of the problem, here Y can not be eliminated. *)
Ltac prepare_half_free_construction :=
repeat  match goal with
| H:(on_line ?X1 ?X2 ?X3) |- _ =>
let T:= fresh in
(assert (T:=(on_line_to_on_line_d X1 X2 X3 H));clear H;set ((X2**X1)/(X2**X3)) in * )
| H:(on_parallel ?X1 ?X2 ?X3 ?X4) |- _ =>
let T:= fresh in
(assert (T:=(on_parallel_to_on_parallel_d X1 X2 X3 X4 H));clear H;set ((X2**X1)/(X3**X4)) in * )
| H:(on_perp ?X1 ?X2 ?X3 ) |- _ =>
let T:= fresh in
(assert (T:=(on_perp_to_on_perp_d X1 X2 X3 H));clear H;set ((2 + 2) * S X2 X3 X1 / Py X2 X3 X2) in * )
end.
Ltac add_non_zero_hyps :=
repeat
match goal with
| H:?A<>?B |- _ =>
assert_if_not_exist (A**B<>0);[apply neq_not_zero;assumption|revert H]
end;intros.
Ltac check_ratio_hyps_aux A B C D :=
((match goal with
| H : parallel A B C D , H2 : C<>D |- _ => fail 2
end) || fail 3 "Error, one the following hypotheses are missing : parallel" A B C D ", " C "<>" D) || idtac.
Ltac check_ratio_hyps :=
try    match goal with
| H : _ |- context [?A**?B/?C**?D] => check_ratio_hyps_aux A B C D
end.

Lemma test_check_ratio_hyp : forall A B C D,
parallel A B C D ->
C<>D ->
A**B / C**D = A**B/C**D.