Ltac generalize_all_areas4 :=
repeat match goal with
H: context [(S4 ?X1 ?X2 ?X3 ?X4)] |- _=> revert H
end.
Ltac uniformize_signed_areas4 :=
generalize_all_areas4;uniformize_signed_areas4_goal;intros.
(****************************************)
(* Signed distance unification tactic   *)
(****************************************)
Ltac uniformize_dir_seg_goal :=
repeat
match goal with
|  |- context [(- - ?X1)] =>
replace (- - X1) with X1; [ idtac | apply simplring1 ]
|  |- context [(?X1 ** ?X1)] =>
rewrite <- (nuldirseg X1)
|  |- context [(?X1 ** ?X2)] =>
match goal with
|  |- context [(?X3 ** ?X4)] =>
match constr:((X3, X4)) with
| (?X2, ?X1) => rewrite (A1a X1 X2)
end
end
end.
Ltac generalize_all_seg :=
repeat match goal with
H: context [(?X1 ** ?X2)] |- _=> revert H
end.
Ltac uniformize_dir_seg_general :=
generalize_all_seg;uniformize_dir_seg_goal;intros.
Ltac try_rw A B := try rewrite <- (A1a B A) in *;
try rewrite    (A1a A B) in *.
Ltac uniformize_dir_seg_spec := match reverse goal with
| [A : Point, B : Point, C : Point,
D : Point, E : Point, F : Point,
G : Point |- _ ] => fail 1
| [A : Point, B : Point, C : Point, D: Point, E: Point, F: Point |- _ ] =>
try_rw A B; try_rw A C; try_rw A D; try_rw A E; try_rw A F;
try_rw B C; try_rw B D; try_rw B E; try_rw B F;
try_rw C D; try_rw C E; try_rw C F;
try_rw D E; try_rw D F;
try_rw E F
| [A : Point, B : Point, C : Point, D: Point, E: Point |- _ ] =>
try_rw A B; try_rw A C; try_rw A D; try_rw A E;
try_rw B C; try_rw B D; try_rw B E;
try_rw C D; try_rw C E;
try_rw D E
| [A : Point, B : Point, C : Point, D: Point |- _ ] =>
try_rw A B; try_rw A C; try_rw A D; try_rw B C; try_rw B D; try_rw C D
| [A : Point, B : Point, C : Point |- _ ] =>
try_rw A B; try_rw A C;try_rw B C
| [A : Point, B : Point |- _ ] =>
try_rw A B
end.
Ltac uniformize_dir_seg := uniformize_dir_seg_spec || uniformize_dir_seg_general.

Lemma test_uniformize_dir_seg_3 : forall A B C,
A ** B = - B**A + A**C + C**A + B**C + C**A ->
A ** B = - B**A.