Ltac named_cases_colS A B C H := elim (col_decS A B C);intro H.Ltac test_col A B C Tac1 Tac2 := 
 match goal with 
| HCol : S A B C = 0 |- _ => Tac1 HCol
| HCol : S A B C <>0 |- _ => Tac2 HCol
| _ => let HCol := fresh in 
      (named_cases_colS A B C HCol;
   [ Tac1 HCol | Tac2 HCol])
end.(* TO DO modulo point order *)

Ltac test_parallel A B C D Tac1 Tac2 := 
 match goal with 
| HPar : parallel A B C D |- _ => Tac1 HPar
| HPar : ~ parallel A B C D |- _ => Tac2 HPar
| _ => let HPar := fresh in 
      (named_cases_parallel A B C D HPar;
   [ Tac1 HPar | Tac2 HPar])
end.(** The same for point equality *)

Ltac test_equality A B Tac1 Tac2 := 
 match goal with 
| H : A = B |- _ => Tac1 H
| H : A<>B |- _ => Tac2 H
| _ => let H := fresh in 
      (named_cases_equality A B H;
   [ Tac1 H | Tac2 H])
end.(** Change A<>B into B<>A *)


Ltac invdiffhyp A B :=
  let H := HypOfType (A <> B) in
  let Hnew := fresh in
  (assert (Hnew := ldiff A B H); clear H).(** Unification tactic for signed areas but just concerning one point, 
and puting this point in last position, except for Py where we put it either on
both side, in the middle or on the right *)
(** The use of this specific tactic during the elimination process is 
faster than normalization of signed areas for every quantities *)

Ltac put_on_the_right_areas P :=
  repeat match goal with
    | |- context[S P ?X1 ?X2] => 
         rewrite (S_1 P X1 X2) in *
    | |- context[S ?X1 P ?X2] => 
         rewrite (S_0 X1 P X2) in *
end.Ltac put_on_the_right_pys P :=
  repeat match goal with
    | |- context[Py ?A P ?A] => rewrite (pyth_simpl_4 A P) in *	(* if it is in the middle with two equal points we put it on left and right *)
    | |- context[Py P ?X1 ?X2] => rewrite (pyth_sym P X1 X2) in * (* if it is on the left we put it on the right *)
end.(** This tactics remove one parallel hypotheses and replace it
by the new one *)

Ltac changeparhyp A B C D lpar :=
  let Hpar := HypOfType (parallel A B C D) in
  let HparNew := fresh in
  (assert (HparNew := lpar A B C D Hpar); clear Hpar).Ltac case_equal X5 X6 X7 Y Heq := rewrite Heq in *.Ltac unify_signed_areas_point P :=
  repeat
   match goal with
   |  |- context [(S ?X1 ?X1 ?X2)] =>
       replace (S X1 X1 X2) with 0; [ idtac | apply trivial_col1 ]
   |  |- context [(S ?X2 ?X1 ?X1)] =>
       replace (S X2 X1 X1) with 0; [ idtac | apply trivial_col2 ]
   |  |- context [(S ?X1 ?X2 ?X1)] =>
       replace (S X1 X2 X1) with 0; [ idtac | apply trivial_col3 ]
   |  |- context [(S ?X1 ?X2 P)] =>
    ( let Truc := fresh in
    match goal with
       |  |- context [(S ?X4 ?X5 P)] =>
            (assert (Truc : S X4 X5 P = - S X1 X2 P);
             [ apply S_3 || apply S_2 || apply S_4
             | rewrite Truc in *; clear Truc ]) ||
             (assert (Truc : S X4 X5 P = S X1 X2 P);
               [ apply S_0 || apply S_1 | rewrite Truc in *; clear Truc ])
       end)
   end.(** This tactic prepares the elimination process by putting
the point on the right and unifying the geometric quantities
concerning the point *)

Ltac unify_signed_areas_and_put_on_the_right P :=
 put_on_the_right_areas P;
 put_on_the_right_pys P;
 put_on_the_right_ratios P;
 put_on_the_upper_right_ratios P;
 unify_signed_areas_point P.

(* Specifications: *)
Lemma test_1 : forall A B C, S A B C + S B A C = 0.
Lemma test_4: forall A B Y, Py Y A B = Py B A Y.
Lemma test_5: forall A Y, Py Y A Y = Py Y A Y.
Lemma test_6: forall C B A E, Py B E B + Py E A C = Py E B E + Py C A E.