Section T.
Context `{TnEQD:Tarski_neutral_dimensionless_with_decidable_point_equality}.
(** We need a notion of line. *)
Definition Line := @Couple Tpoint.
Definition Lin := build_couple Tpoint.
Definition IncidentL := fun A l => Col A (P1 l) (P2 l).
(** * Group I Incidence *)
(** For every pair of distinct points there is a line containing them. *)
(** We need a notion of equality over lines. *)
Definition EqL : relation Line := fun l m => forall X, IncidentL X l <-> IncidentL X m.
Infix "=l=" := EqL (at level 70):type_scope.
(** Our equality is an equivalence relation. *)
Instance EqL_Equiv : Equivalence EqL.
Instance incident_Proper (A:Tpoint) :
Proper (EqL ==>iff) (IncidentL A).
(** There is only one line going through two points. *)
(** Every line contains at least two points. *)
(** Definition of the collinearity predicate. We say that three points are collinear if they belongs to the same line. *)
Definition Col_H := fun A B C =>
exists l, IncidentL A l /\ IncidentL B l /\ IncidentL C l.
(** We show that the notion of collinearity we just defined is equivalent to the notion of collinearity of Tarski. *)
(** There exists three non collinear points. *)
(** We need a notion of plane. *)
Record Plane := Plan {M1; M2; M3; NCol : ~ Col_H M1 M2 M3}.
Definition IncidentP := fun A p => Coplanar (M1 p) (M2 p) (M3 p) A.
(** For every triplet of non collinear points there is a plane containing them. *)
(** We need a notion of equality over planes. *)
Definition EqP : relation Plane := fun p q => forall X, IncidentP X p <-> IncidentP X q.
Infix "=p=" := EqP (at level 70):type_scope.
(** Our equality is an equivalence relation. *)
Instance EqP_Equiv : Equivalence EqP.
Instance incidentp_Proper (A:Tpoint) :
Proper (EqP ==>iff) (IncidentP A).
(** There is only one plane going through three non collinear points. *)
(** Every plane contains at least one point. *)
(** Definition of a line belonging to a plane. We say that a line belongs to a plane if every point of the line belongs to the plane. *)
Definition  IncidentLP := fun l p => forall A, IncidentL A l -> IncidentP A p.
(** If two distinct points of a line belong to a plane, then the line belongs to the plane. *)
(** * Group II Order *)
(** Definition of the Between predicate of Hilbert. Note that it is different from the Between of Tarski. The Between of Hilbert is strict. *)
Definition Between_H := fun A B C =>
Bet A B C /\ A <> B /\ B <> C /\ A <> C.
(** If B is between A and C, it is also between C and A. *)
(** Axiom of Pasch, (Hilbert version). *)
(** First we define a predicate which means that the line l intersects the segment AB. *)
Definition cut := fun l A B =>
~ IncidentL A l /\ ~ IncidentL B l /\ exists I, IncidentL I l /\ Between_H A I B.
(** We show that this definition is equivalent to the predicate TS of Tarski. *)
(** * Group III Congruence *)
(** The cong predicate of Hilbert is the same as the one of Tarski: *)
Definition outH := fun P A B => Between_H P A B \/ Between_H P B A \/ (P <> A /\ A = B).
unfold Out.
unfold outH.
intros.
spliter.
induction H1.
induction (eq_dec_points A B).
right; right.
split; auto.
left.
unfold Between_H.
repeat split; auto.
induction (eq_dec_points A B).
right; right.
split; auto.
right; left.
unfold Between_H.
repeat split; auto.
Qed.
(** As a remark we also prove another version of this axiom as formalized in Isabelle by Phil Scott. *)
Definition same_side_scott := fun E A B => E <> A /\ E <> B /\ Col_H E A B /\ ~ Between_H A E B.
Remark axiom_hcong_scott:
forall P Q A C, A <> C -> P <> Q ->
exists B, same_side_scott A B C  /\ Cong P Q A B.
(** We define when two segments do not intersect. *)
Definition disjoint := fun A B C D => ~ exists P, Between_H A P B /\ Between_H C P D.
(** Note that two disjoint segments may share one of their extremities. *)
Definition same_side := fun A B l => exists P, cut l A P /\ cut l B P.
(** Same side predicate corresponds to OS of Tarski. *)
Definition same_side' := fun A B X Y =>
X <> Y /\ forall l, IncidentL X l -> IncidentL Y l -> same_side A B l.
(** This is equivalent to the out predicate of Tarski. *)
(** The 2D version of the fourth congruence axiom **)

Lemma same_side_trans :
forall A B C l,
same_side A B l -> same_side B C l -> same_side A C l.