(* Julien Narboux *)
(* Formalization of *)
(* Tarski's axiomatic *)
Require Export Ch07_midpoint.
Unset Regular Subst Tactic.
Definition Per := fun A B C =>
exists C', is_midpoint B C C' /\ Cong A C A C'.
Hint Resolve l8_2 : Perp.
Ltac Perp := eauto with Perp.
intros.
unfold Per.
exists B;intuition.
Qed.
Hint Resolve l8_5 : Perp.
intros.
unfold Per in *.
DecompExAnd H C'.
suppose (Cong A' C A' C').
assert (C=C').
eapply l4_19.
2:apply H4.
2:apply H.
assumption.
subst C'.
eapply l7_3.
assumption.
DecompExAnd H0 C''.
assert (Cong C C C' C'').
eapply l7_13.
apply l7_2.
apply H3.
apply l7_2.
apply H2.
treat_equalities.
auto.
Qed.
Ltac let_symmetric C P A :=
let id1:=fresh in (assert (id1:(exists A', is_midpoint P A A'));
[apply symmetric_point_construction|DecompEx id1 C]).
Hint Resolve l8_7 : Perp.
Proof with Perp.
intros.
eapply l8_7...
Qed.
Proof with Perp.
intros.
cases_equality A B.
left;auto.
right.
assert (Per C B C).
eapply l8_3...
eauto with Col.
Perp.
Qed.
Proof with Perp.
intros.
cases_equality B C.
unfold Cong_3 in H0;intuition.
treat_equalities...
assert (B'<>C').
unfold Cong_3 in H0;intuition.
treat_equalities...
unfold Per in H.
DecompExAnd H D.
let_symmetric D' B' C'.
assert (OFSC C B D A C' B' D' A').
unfold OFSC,Cong_3,is_midpoint in *;intuition.
eapply cong_transitivity with (C:=B) (D:=C);sTarski.
eapply cong_transitivity with (C:=B') (D:=C');sTarski.
assert (Cong D A D' A').
eapply five_segments_with_def;eauto.
unfold OFSC,Cong_3,is_midpoint in *;intuition.
clean_duplicated_hyps.
assert (Cong A' C' A' D').
eapply cong_transitivity with (C:=A) (D:=C);sTarski.
eapply cong_transitivity with (C:=A) (D:=D);sTarski.
unfold Per.
exists D'.
intuition.
unfold is_midpoint...
Qed.
Definition Perp_in := fun X A B C D =>
A<>B /\ C<>D /\ Col X A B /\ Col X C D /\
(forall U V,  Col U A B -> Col V C D -> Per U X V).
Definition Perp := fun A B C D => exists X, Perp_in X A B C D.
Proof with Perp.
unfold Perp_in.
intros;intuition.
Qed.
Definition DistLn := fun A B C D =>
(exists X, Col X A B /\ ~Col X C D) \/ (exists X, ~ Col X A B /\ Col X C D).
Hint Resolve l8_14_1 : Perp.
(* Lemma l8_14_1 : forall A B C D, Perp A B C D -> DistLn A B C D.  Lemma l8_14_2_1b : forall X A B C D Y, Perp_in X A B C D -> Col Y A B -> Col Y C D -> X=Y. Proof with Perp. intros. unfold Perp_in in H. decompose [and] H;clear H. assert (Per Y X Y). apply H7... symmetry. eapply l8_8... Qed.  Lemma l8_14_2_1b_bis : forall A B C D X, Perp A B C D -> Col X A B -> Col X C D -> Perp_in X A B C D. Proof with Perp. intros. unfold Perp in H. DecompEx H Y. assert (X=Y). symmetry. eapply l8_14_2_1b;eauto. subst. auto. Qed.  Hint Resolve  l8_14_2_1b_bis : Perp.  Lemma l8_14_2_2 : forall X A B C D, Perp A B C D -> (forall Y, Col Y A B -> Col Y C D -> X=Y) -> Perp_in X A B C D. Proof with Perp. intros. unfold Perp in H. DecompEx H X0. assert (X=X0). apply H0;unfold Perp_in in H1;intuition. subst... Qed.  Lemma l8_14_3 : forall A B C D X Y, Perp_in X A B C D -> Perp_in Y A B C D -> X=Y. Proof with Perp. intros. unfold Perp_in in *. decompose [and] H;clear H. decompose [and] H0;clear H0. eapply l8_8. eapply H10;auto. Qed.  Lemma l8_15_1 : forall A B C X, A<>B -> Col A B X -> Perp A B C X -> Perp_in X A B C X. Proof with Perp. intros. unfold Perp in H1. DecompEx H1 X0. unfold Perp_in in *. intuition. assert (Per X X0 X). apply H6;Col;Tarski... assert (X =X0)... subst X0. apply H6... Qed.  Lemma l8_15_2 : forall A B C X, A<>B -> Col A B X -> Perp_in X A B C X -> Perp A B C X. Proof with Perp. intros. unfold Perp. exists X. auto. Qed.  Lemma l8_16_1 : forall A B C U X, A<>B -> Col A B X -> Col A B U -> U<>X -> Perp A B C X -> ~ Col A B C /\ Per C X U. Proof with Perp. intros. assert (Perp_in X  A B C X). eapply l8_15_1... assert (Per C X U). unfold Perp, Perp_in in *. DecompEx H3 X0. intuition. split;auto. assert (C<>X). unfold not;intro. subst X. unfold Perp_in in H4;intuition. assert (~ Col U C X). unfold not;intro. assert (C=X \/ U=X). eapply l8_9... Col. intuition. unfold not;intro. assert (Col A X C). eapply col_transitivity_1;Col. assert (Col A C U). eapply col_transitivity_1;Col. assert (A<>C). unfold not;intro. unfold Perp_in in *;intuition. smart_subst C. assert (A<>B);auto. assert (Col A X U). eapply col_transitivity_1;Col. intuition. assert (Col C U X). eapply col_transitivity_2;Col. intuition. Qed.  Lemma l8_16_2 : forall A B C U X, A<>B -> Col A B X -> Col A B U -> U<>X -> ~ Col A B C -> Per C X U ->Perp A B C X. Proof with Perp. intros. assert (C<>X). unfold not;intro. smart_subst X;auto. assert (Perp_in X A B C X). eapply l8_13_2... Col. Tarski. exists U. exists C. intuition. exists X... Qed.  Lemma l8_18_unicity : forall A B C X Y, ~ Col A B C -> Col A B X -> Perp A B C X -> Col A B Y -> Perp A B C Y -> X=Y. Proof with Perp. intros. assert (Perp_in X A B C X). eapply l8_15_1. unfold not;intro;subst B;auto. intuition. Col. assumption. assert (Perp_in Y A B C Y). eapply l8_15_1. unfold not;intro;subst B;auto. intuition. Col. assumption. unfold Perp_in in *. decompose [and] H4;clear H4. decompose [and] H5;clear H5. eapply l8_7 with (A:=C). apply l8_2. apply H11. Col. Tarski. apply l8_2. apply H15. assumption. Tarski. Qed.  Ltac show_distinct X Y := assert (X<>Y);[unfold not;intro;treat_equalities|idtac].  Lemma l8_18_existence : forall A B C, ~ Col A B C -> exists X, Col A B X /\ Perp A B C X. Proof with Tarski. intros. assert (exists Y, Bet B A Y /\ Cong A Y A C)... DecompExAnd H0 Y. assert (exists P : Point, is_midpoint P C Y). eapply l7_25. apply cong_symmetry;eauto. DecompEx H0 P. assert (Per A P Y). unfold Per. exists C;intuition;Tarski. assert (exists Z, Bet A Y Z /\ Cong Y Z Y P)... DecompExAnd H4 Z. assert (exists Q, Bet P Y Q /\ Cong Y Q Y A)... DecompExAnd H4 Q. let_symmetric Q' Z Q. assert (exists C', Bet Q' Y C' /\ Cong Y C' Y C)... DecompExAnd H4 C'. assert (OFSC A Y Z Q Q Y P A). unfold OFSC;intuition. show_distinct A Y... assert (Cong Z Q P A). eapply five_segments_with_def;eauto. assert (Cong_3 A P Y Q Z Y). unfold Cong_3;intuition. assert (Per Q Z Y). eapply l8_10. 2:apply H14. auto. assert (Cong Y Q Y Q'). assert (Per Y Z Q);Perp. unfold Per in H16;intuition. elim H16;intro Q'';intros. decompose [and] H17. assert (Q''=Q'). eapply symmetric_point_unicity. apply H18. auto. subst Q''. auto. assert (exists X : Point, is_midpoint X C C'). eapply l7_25. apply cong_symmetry;eauto. DecompEx H17 X. assert (Per Y X C). unfold Per. exists C';intuition. show_distinct Q Y... cases_equality C C'. unfold OFSC,Cong_3,is_midpoint in *;DecompAndAll. treat_equalities. show_distinct P Y... assert (Col A B C)... intuition. show_distinct A B... show_distinct A C... show_distinct B C... show_distinct Y C... assert (Col P Y Q)... assert (Col P Y C)... assert (Col P Q C). eapply col_transitivity_1;try apply H1;auto. assert (Col Y Q C). eapply col_transitivity_2;try apply H1;auto. assert (Col Y Q' P). eapply col_transitivity_1;try apply H21;auto. assert (Col C Q' P). eapply col_transitivity_2;try apply H21;auto. assert (Col A Y B)... assert (Col A Y Z)... assert (Col A B Z). eapply col_transitivity_1;try apply H10;auto. assert (Col Y B Z). eapply col_transitivity_2;try apply H10;auto. assert (Col Q Y P)... assert (Col Q' Y P). Col. assert (Col P Q Q'). eapply col_transitivity_1;try apply H1;auto. Col. assert (Col Y Q Q'). eapply col_transitivity_2;try apply H1;auto. Col. assert (Col Z Q Q')... Col. show_distinct Q' Q... assert (Col P B C). eapply col_transitivity_1;try apply H1;auto. intuition. assert (Col Q' P Y). eapply col_transitivity_1;try apply H42;Col. assert (Col Q' Z Y). eapply col_transitivity_1;try apply H42;Col. show_distinct Z Y... assert (Col Z A Q'). eapply col_transitivity_1;try apply H45;Col. assert (Col Y A Q'). eapply col_transitivity_2;try apply H45;Col. show_distinct Z A... assert (Col Z B Q'). eapply col_transitivity_1;try apply H48;Col. assert (Col A B Q'). eapply col_transitivity_2;try apply H48;Col. assert (Col B Y Q'). eapply col_transitivity_2;try apply H12;Col. show_distinct Y Q'... assert (Col Y Q B). eapply col_transitivity_1;try apply H52;Col. show_distinct Y B... assert (Col Y B C). eapply col_transitivity_1;try apply H52;Col. assert (B<>Y)... assert (Col B A C). eapply col_transitivity_1;try apply H56;Col. assert (Col A B C)... Col. intuition. (* Now we know that C<> C' ! *)
suppose (OFSC Q Y C Z Q' Y C' Z).
assert (Cong C Z C' Z).
eapply five_segments_with_def;eauto.
assert (Col Z Y X).
eapply upper_dim.
apply H20.
apply cong_commutativity.
assumption.
sTarski.
unfold is_midpoint in H18;intuition.
show_distinct Y Z.
unfold OFSC,Cong_3,is_midpoint in *;DecompAndAll.
treat_equalities.
auto.
show_distinct C X.
unfold OFSC,Cong_3,is_midpoint in *;DecompAndAll.
treat_equalities.
auto.
show_distinct Y X.
unfold OFSC,Cong_3,is_midpoint in *;DecompAndAll.
treat_equalities.
auto.
clean_trivial_hyps.
clean_duplicated_hyps.
Focus 2.
assert (Perp_in X Y Z C X).
eapply l8_13_2...
Col.
exists Y.
exists C.
repeat split...
assert (Col A B X).
unfold OFSC,Cong_3,is_midpoint in *;DecompAndAll.
clean_trivial_hyps.
clean_duplicated_hyps.
assert (Col A Y B)...
assert (Col A Y Z)...
assert (Col Y B Z).
eapply col_transitivity_2.
apply H10.
auto.
auto.
assert (Col Y Z X)...
Col.
assert (Col Y B X).
eapply col_transitivity_1.
apply H24.
Col.
Col.
assert (X<>Y)...
assert (Col X A B).
eapply col_transitivity_1.
apply H39.
assert (Col Y Z X)...
assert (Col Y Z A)...
assert (Col Y X A).
eapply col_transitivity_1;try apply H24;auto.
Col.
Col.
Col.
exists X.
split...
unfold Perp.
exists X.
unfold Perp_in.
repeat split.
unfold not;intro;subst B;intuition.
assumption.
Col.
Tarski.
unfold Perp_in in H27.
decompose [and] H27;clear H27.
intros.
apply H34.
2:assumption.
unfold OFSC,Cong_3,is_midpoint in *;DecompAndAll.
assert (Col A Y Z)...
assert (Col A B U)...
Col.
assert (Col A B Y).
Col.
assert (Col A Y Z).
assert (Col A U Y).
assert (A<>B).
unfold not;intro.
subst B;intuition.
eapply col_transitivity_1.
apply H53.
auto.
auto.
auto.
assert (Col Y U Z).
assert (Y<>A)...
eapply col_transitivity_1.
apply H54.
2:Col.
assert (Col A Y U).
eapply col_transitivity_1.
assert (A<>B)...
unfold not;intro;subst B;intuition.
apply H55.
Col.
Col.
Col.
Col.
Focus 2.
unfold OFSC;repeat split;sTarski...
2:unfold OFSC ,is_midpoint, Cong_3 in *;DecompAndAll.
2:apply cong_right_commutativity.
2:assumption.
unfold is_midpoint in H1.
DecompAndAll.
show_distinct P Y...
clear  H6 H2 H3 H7 H9 H5 H12 H13 H14 H15 H16 H18 H17 H22 H0 H.
Between.
(* retour de focus *)
show_distinct A B...
show_distinct A C...
show_distinct B C...
show_distinct Y C...
show_distinct P Y...
show_distinct A Y...
show_distinct A Z...
show_distinct Y B...
show_distinct Y Z...
show_distinct C' Y...
show_distinct Q Q'...
assert (Col P B C).
eapply col_transitivity_1;try apply H32;Col.
intuition.
show_distinct Y Q...
clear H17 H0 H3 H7 H9 H12 H13 H15 H16 H22 H26 H27 H29 H30 H21 H33 H34 H38 H40.
assert (Col B A Y)...
assert (Col A Y Z)...
assert (Col P Y Q)...
assert (Col P Y C)...
assert (Col P Q C).
eapply col_transitivity_1;try apply H32;auto.
assert (Col Y Q C).
eapply col_transitivity_2;try apply H32;auto.
assert (Col Q' Y  C')...
assert (Col Q Z Q')...
assert (Col C Y C')...
clear H18 H23 H35 H4 H5 H11 H8 H2 H6.
assert (Col A Z B).
eapply col_transitivity_1;try apply H36;Col.
assert (Col Y Z B).
eapply col_transitivity_2;try apply H36;Col.
assert (Col C' C Q').
eapply col_transitivity_1;try apply H42;Col.
assert (Col Y C Q').
eapply col_transitivity_2;try apply H42;Col.
assert (Col C P Q').
eapply col_transitivity_1;try apply H25;Col.
assert (Col Y P Q').
eapply col_transitivity_2;try apply H25;Col.
assert (Col Y Q Q').
eapply col_transitivity_2;try apply H32;Col.
assert (Col P Q Q').
eapply col_transitivity_2;try apply H32;Col.
assert (Col Q Z P).
eapply col_transitivity_1;try apply H43;Col.
assert (Col Q Z Y).
eapply col_transitivity_1;try apply H43;Col.
assert (Col Q' Z P).
eapply col_transitivity_2;try apply H43;Col.
assert (Col Q' Z Y).
eapply col_transitivity_2;try apply H43;Col.
assert (Col Q' P Y).
eapply col_transitivity_2;try apply H43;Col.
assert (Col Y Z C).
eapply col_transitivity_1;try apply H43;Col.
assert (Col Y A C).
eapply col_transitivity_1;try apply H41;Col.
assert (Col A B C).
eapply col_transitivity_1;try apply H10;Col.
intuition.
Qed.
Proof with Tarski.
intros.
assert (exists X : Point, Col A B X /\ Perp A B C X).
eapply l8_18_existence...
DecompExAnd H1 X.
assert (Per A X C).
assert (Perp_in X A B C X).
eapply l8_15_1;auto.
unfold Perp_in in H1.
DecompAndAll.
apply H9;Tarski.
assert (HH:=H1).
unfold Per in H1.
DecompExAnd H1 C'.
let_symmetric C'' A C.
assert (exists P, is_midpoint P C' C'').
eapply l7_25.
unfold is_midpoint in H2.
decompose [and] H2.
eapply cong_transitivity with (C:=C) (D:=A).
2:apply H7.
sTarski.
DecompEx H1 P.
assert (Per X A P).
eapply l8_20_1.
apply HH.
apply l7_2.
apply H7.
Midpoint.
Midpoint.
show_distinct X C.
unfold is_midpoint in*;DecompAndAll.
intuition.
assert (A<>P).
eapply l8_20_2.
apply HH.
apply l7_2.
apply H7.
Midpoint.
Midpoint.
auto.
assert (exists T, Bet P T C /\ Bet A T X).
eapply l3_17 with (A:=C'') (A':=C');unfold is_midpoint in *;intuition.
DecompExAnd H10 T.
cases_equality A X.
exists P.
exists T.
treat_equalities.
repeat split;Tarski;Between.
unfold Perp.
assert (Perp_in A A B C A).
eapply l8_15_1;auto.
Tarski.
unfold Perp_in in H3.
decompose [and] H3;clear H3.
exists A.
unfold Perp_in;repeat split;Tarski;auto.
intros.
eapply H16;auto.
assert (Col A P C).
Col.
assert (Col A P V).
Col.
assert (Col A C V).
eapply col_transitivity_1;try apply H9;auto.
Col.
assert (Col A B T).
eapply col_transitivity_1.
apply H10.
unfold is_midpoint;intuition.
unfold is_midpoint;intuition.
exists P.
exists T.
repeat split;Between.
unfold Perp.
exists A.
eapply l8_13_2;auto.
Tarski.
Tarski.
exists X.
exists P.
repeat split.
Col.
Tarski.
auto.
auto.
auto.
Qed.
Proof with Tarski.
intros.
cases_col A B C.
assert (exists C', ~ Col A B C').
eapply l6_25...
DecompEx H1 C'.
assert (  exists P : Point,
(exists T : Point, Perp A B P A /\ Col A B T /\ Bet C' T P)).
apply (l8_21_aux A B C');auto.
DecompEx H1 P.
DecompEx H3 T.
exists P.
exists C.
intuition.
eapply l8_21_aux;auto.
Qed.

Lemma perp_in_right_commutativity : forall A B C D X,
Perp_in X A B C D -> Perp_in X A B D C.