Theory Tarski_Neutral

(* IsageoCoq - Tarski_Neutral.thy
Port part of GeoCoq 3.4.0 (https://geocoq.github.io/GeoCoq/)

Version 2.0.0 IsaGeoCoq
Copyright (C) 2021-2025 Roland Coghetto roland.coghetto ( a t ) cafr-msa2p.be

History
Version 1.0.0 IsaGeoCoq
Port part of GeoCoq 3.4.0 (https://geocoq.github.io/GeoCoq/) in Isabelle/Hol (Isabelle2021)
Copyright (C) 2021  Roland Coghetto roland_coghetto (at) hotmail.com

License: LGPL

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*)

theory Tarski_Neutral

imports
  Main

begin

section "Neutral geometry dimensionless"

subsection "Tarski's axiom system for neutral geometry: dimensionless"

locale Tarski_neutral_dimensionless =
  fixes Bet  :: "'p  'p  'p  bool" ("(_  _  _) ")
    and Cong :: "'p  'p  'p  'p  bool"
    and TPA TPB TPC :: 'p
  assumes cong_pseudo_reflexivity: " a b. 

Cong a b b a"

and   cong_inner_transitivity: " a b p q r s.

Cong a b p q 
Cong a b r s

Cong p q r s"

and   cong_identity: " a b c.

Cong a b c c

a = b"

and   segment_construction: " a b c q.

x. (Bet q a x  Cong a x b c)"

and   five_segment: " a b c d a' b' c' d'.

a  b 
Bet a b c 
Bet a' b' c'
Cong a b a' b' 
Cong b c b' c' 
Cong a d a' d' 
Cong b d b' d'

Cong c d c' d'"

and   between_identity: " a b.

Bet a b a

a = b"

and   inner_pasch: " a b c p q.

Bet a p c 
Bet b q c

( x. Bet p x b  Bet q x a)"

and   lower_dim:  "¬ Bet TPA TPB TPC  ¬ Bet TPB TPC TPA  ¬ Bet TPC TPA TPB"

context Tarski_neutral_dimensionless

begin

subsection "Definitions"

definition OFSC ::
  "['p,'p,'p,'p,'p,'p,'p,'p]  bool"
  ("_ _ _ _ OFSC _ _ _ _" [99,99,99,99,99,99,99,99] 50)
  where
    "A B C D OFSC A' B' C' D' 

Bet A B C 
Bet A' B' C' 
Cong A B A' B' 
Cong B C B' C' 
Cong A D A' D' 
Cong B D B' D'"

definition Cong3 ::
  "['p,'p,'p,'p,'p,'p]  bool"
  ("_ _ _ Cong3 _ _ _" [99,99,99,99,99,99] 50)
  where
    "A B C Cong3 A' B' C' 

Cong A B A' B' 
Cong A C A' C' 
Cong B C B' C'"

definition Col ::
  "['p,'p,'p]  bool"
  ("Col _ _ _" [99,99,99] 50)
  where
    "Col A B C 

Bet A B C  Bet B C A  Bet C A B"

definition Bet4 ::
  "['p,'p,'p,'p]  bool"
  ("Bet4 _ _ _ _" [99,99,99,99] 50)
  where
    "Bet4 A1 A2 A3 A4 

Bet A1 A2 A3 
Bet A2 A3 A4 
Bet A1 A3 A4 
Bet A1 A2 A4"

definition BetS ::
  "['p,'p,'p]  bool" ("BetS _ _ _" [99,99,99] 50)
  where
    "BetS A B C 

Bet A B C 
A  B 
B  C"

(** Definition of the sum of segments.
SumS A B C D E F means that AB + CD = EF. *)

definition SumS ::
  "['p,'p,'p,'p,'p,'p]  bool" 
  ("_ _ _ _ SumS _ _" [99,99,99,99,99,99] 50)
  where
    "A B C D SumS E F 

 P Q R. Bet P Q R  Cong P Q A B  Cong Q R C D  Cong P R E F"

definition FSC ::
  "['p,'p,'p,'p,'p,'p,'p,'p]  bool"
  ("_ _ _ _ FSC _ _ _ _" [99,99,99,99,99,99,99,99] 50)
  where
    "A B C D FSC A' B' C' D' 

Col A B C 
A B C Cong3 A' B' C' 
Cong A D A' D' 
Cong B D B' D'"

definition IFSC ::
  "['p,'p,'p,'p,'p,'p,'p,'p]  bool"
  ("_ _ _ _ IFSC _ _ _ _" [99,99,99,99,99,99,99,99] 50)
  where
    "A B C D IFSC A' B' C' D' 

Bet A B C 
Bet A' B' C' 
Cong A C A' C' 
Cong B C B' C' 
Cong A D A' D' 
Cong C D C' D'"

definition Le ::
  "['p,'p,'p,'p]  bool" 
  ("_ _ Le _ _" [99,99,99,99] 50)
  where 
    "A B Le C D 

 E. (Bet C E D  Cong A B C E)"

definition Lt ::
  "['p,'p,'p,'p]  bool" 
  ("_ _ Lt _ _" [99,99,99,99] 50)
  where 
    "A B Lt C D 

A B Le C D  ¬ Cong A B C D"

definition Ge ::
  "['p,'p,'p,'p]  bool" 
  ("_ _Ge _ _" [99,99,99,99] 50)
  where 
    "A B Ge C D 

C D Le A B"

definition Gt ::
  "['p,'p,'p,'p]  bool" 
  ("_ _ Gt _ _" [99,99,99,99] 50)
  where 
    "A B Gt C D 

C D Lt A B"

definition Out ::
  "['p,'p,'p]  bool" 
  ("_ Out _ _" [99,99,99] 50)
  where 
    "P Out A B 

A  P 
B  P 
(Bet P A B  Bet P B A)"

definition Midpoint ::
  "['p,'p,'p]  bool" 
  ("_ Midpoint _ _" [99,99,99] 50)
  where 
    "M Midpoint A B 

Bet A M B 
Cong A M M B"

definition Per ::
  "['p,'p,'p]  bool" 
  ("Per _ _ _" [99,99,99] 50)
  where 
    "Per A B C 

 C'. (B Midpoint C C'  Cong A C A C')"

definition PerpAt ::
  "['p,'p,'p,'p,'p]  bool" 
  ("_ PerpAt _ _ _ _ " [99,99,99,99,99] 50)
  where 
    "X PerpAt A B C D 

A  B 
C  D 
Col X A B 
Col X C D 
( U V. ((Col U A B  Col V C D)  Per U X V))"

definition Perp ::
  "['p,'p,'p,'p]  bool" 
  ("_ _ Perp _ _" [99,99,99,99] 50)
  where 
    "A B Perp C D 

 X::'p. X PerpAt A B C D"

definition Coplanar ::
  "['p,'p,'p,'p]  bool" 
  ("Coplanar _ _ _ _" [99,99,99,99] 50)
  where 
    "Coplanar A B C D 

 X. (Col A B X  Col C D X) 
(Col A C X  Col B D X) 
(Col A D X  Col B C X)"

definition TS ::
  "['p,'p,'p,'p]  bool" 
  ("_ _ TS _ _" [99,99,99,99] 50)
  where 
    "A B TS P Q 

¬ Col P A B  ¬ Col Q A B  ( T::'p. Col T A B  Bet P T Q)"

definition ReflectL ::
  "['p,'p,'p,'p]  bool" 
  ("_ _ ReflectL _ _" [99,99,99,99] 50)
  where 
    "P' P ReflectL A B 

( X. X Midpoint P P'  Col A B X)  (A B Perp P P'  P = P')"

definition Reflect ::
  "['p,'p,'p,'p]  bool" 
  ("_ _ Reflect _ _" [99,99,99,99] 50)
  where 
    "P' P Reflect A B 

(A  B  P' P ReflectL A B)  (A = B  A Midpoint P P')"

definition InAngle ::
  "['p,'p,'p,'p]  bool" 
  ("_ InAngle _ _ _" [99,99,99,99] 50)
  where 
    "P InAngle A B C 

A  B  C  B  P  B 
( X. Bet A X C  (X = B  B Out X P))"

definition ParStrict::
  "['p,'p,'p,'p]  bool" 
  ("_ _ ParStrict _ _" [99,99,99,99] 50)
  where 
    "A B ParStrict C D 
  
Coplanar A B C D  
¬ ( X. Col X A B  Col X C D)"

definition Par::
  "['p,'p,'p,'p]  bool" 
  ("_ _ Par _ _" [99,99,99,99] 50)
  where 
    "A B Par C D 

A B ParStrict C D  (A  B  C  D  Col A C D  Col B C D)"

definition Plg::
  "['p,'p,'p,'p]  bool" 
  ("Plg _ _ _ _" [99,99,99,99] 50)
  where 
    "Plg  A B C D 

(A  C  B  D)  ( M. M Midpoint A C  M Midpoint B D)"

definition ParallelogramStrict::
  "['p,'p,'p,'p]  bool" 
  ("ParallelogramStrict _ _ _ _" [99,99,99,99] 50)
  where 
    "ParallelogramStrict A B A' B' 

A A' TS B B'  
A B Par A' B'  
Cong A B A' B'"

definition ParallelogramFlat::
  "['p,'p,'p,'p]  bool" 
  ("ParallelogramFlat _ _ _ _" [99,99,99,99] 50)
  where
    "ParallelogramFlat A B A' B' 

Col A B A'  
Col A B B' 
Cong A B A' B'  
Cong A B' A' B 
(A  A'  B  B')"

definition Parallelogram::
  "['p,'p,'p,'p]  bool" 
  ("Parallelogram _ _ _ _" [99,99,99,99] 50)
  where 
    "Parallelogram A B A' B' 

ParallelogramStrict A B A' B'  ParallelogramFlat A B A' B'"

definition Rhombus::
  "['p,'p,'p,'p]  bool" 
  ("Rhombus _ _ _ _" [99,99,99,99] 50)
  where 
    "Rhombus A B C D 
 
Plg A B C D  Cong A B B C"

definition Rectangle::
  "['p,'p,'p,'p]  bool" 
  ("Rectangle _ _ _ _" [99,99,99,99] 50)
  where 
    "Rectangle A B C D 
 
Plg A B C D  Cong A C B D"

definition Square::
  "['p,'p,'p,'p]  bool" 
  ("Square _ _ _ _" [99,99,99,99] 50)
  where 
    "Square A B C D 
 
Rectangle A B C D  Cong A B B C"

definition Kite::
  "['p,'p,'p,'p]  bool" 
  ("Kite _ _ _ _" [99,99,99,99] 50)
  where 
    "Kite A B C D 
 
Cong B C C D  Cong D A A B"

definition Lambert::
  "['p,'p,'p,'p]  bool" 
  ("Lambert _ _ _ _" [99,99,99,99] 50)
  where 
    "Lambert A B C D 

A  B  B  C  C  D  A  D  
Per B A D  
Per A D C  
Per A B C  
Coplanar A B C D"

definition OS ::
  "['p,'p,'p,'p]  bool" 
  ("_ _ OS _ _" [99,99,99,99] 50)
  where 
    "A B OS P Q 

 R::'p. A B TS P R  A B TS Q R"

definition TSP ::
  "['p,'p,'p,'p,'p]  bool" 
  ("_ _ _ TSP _ _" [99,99,99,99,99] 50)
  where 
    "A B C TSP P Q 

(¬ Coplanar A B C P)  (¬ Coplanar A B C Q) 
( T. Coplanar A B C T  Bet P T Q)"

definition OSP ::
  "['p,'p,'p,'p,'p]  bool" 
  ("_ _ _ OSP _ _" [99,99,99,99,99] 50)
  where 
    "A B C OSP P Q 

 R. ((A B C TSP P R)  (A B C TSP Q R))"

definition Saccheri::
  "['p,'p,'p,'p]  bool" 
  ("Saccheri _ _ _ _" [99,99,99,99] 50)
  where 
    "Saccheri A B C D 

Per B A D  
Per A D C  
Cong A B C D  A D OS B C"

definition ReflectLAt ::
  "['p,'p,'p,'p,'p]  bool" 
  ("_ ReflectLAt _ _ _ _" [99,99,99,99,99] 50)
  where 
    "M ReflectLAt P' P A B 

(M Midpoint P P'  Col A B M)  (A B Perp P P'  P = P')"

definition ReflectAt ::
  "['p,'p,'p,'p,'p]  bool" 
  ("_ ReflectAt _ _ _ _" [99,99,99,99,99] 50)
  where 
    "M ReflectAt P' P A B 

(A  B  M ReflectLAt P' P A B)  (A = B  A = M  M Midpoint P P')"

definition upper_dim_axiom ::
  "bool" 
  ("UpperDimAxiom" [] 50)
  where
    "upper_dim_axiom 
 
 A B C P Q.
P  Q 
Cong A P A Q 
Cong B P B Q 
Cong C P C Q

(Bet A B C  Bet B C A  Bet C A B)"

definition all_coplanar_axiom ::
  "bool" 
  ("AllCoplanarAxiom" [] 50)
  where
    "AllCoplanarAxiom 
 
 A B C P Q.
P  Q 
Cong A P A Q 
Cong B P B Q 
Cong C P C Q

(Bet A B C  Bet B C A  Bet C A B)"

(** If three points A, B and C are equidistant to three distinct points P, Q and R,
    then A, B and C are collinear. *)

definition upper_dim_3_axiom :: 
  "bool" 
  where
    "upper_dim_3_axiom 
 
 A B C P Q R. P  Q  Q  R  P  R 
  Cong A P A Q  Cong B P B Q  Cong C P C Q 
  Cong A P A R  Cong B P B R  Cong C P C R 
  (Bet A B C  Bet B C A  Bet C A B)"

(** If four points are equidistant to two distinct points, then they are coplanar. *)

definition median_planes_axiom :: 
  "bool" 
  where
    "median_planes_axiom 
 
 A B C D P Q. P  Q 
  Cong A P A Q  Cong B P B Q  Cong C P C Q  Cong D P D Q 
  Coplanar A B C D"

(** If two planes meet in some point, then they also meet in another point. *)

definition plane_intersection_axiom :: 
  "bool" 
  where
    "plane_intersection_axiom 
 
 A B C D E F P.
  Coplanar A B C P  Coplanar D E F P 
( Q. Coplanar A B C Q  Coplanar D E F Q  P  Q)"

(** If two points do not lie on a plane, then they are either
    on opposite sides or on the same side of the plane. *)

definition space_separation_axiom :: 
  "bool" 
  where 
    "space_separation_axiom 
 
 A B C P Q.
  ¬ Coplanar A B C P  ¬ Coplanar A B C Q 
  (A B C TSP P Q  A B C OSP P Q)"

(** The line segments SU1, SU2, SU3 and SU4 can not form an orthonormal family *)

definition orthonormal_family_axiom :: 
  "bool" 
  where
    "orthonormal_family_axiom 
 
 S U1' U1 U2 U3 U4.
  ¬ (S  U1'  Bet U1 S U1' 
     Cong S U1 S U1'  Cong S U2 S U1'  Cong S U3 S U1'  Cong S U4 S U1' 
     Cong U1 U2 U1' U2  Cong U1 U3 U1' U2  Cong U1 U4 U1' U2 
     Cong U2 U3 U1' U2  Cong U2 U4 U1' U2  Cong U3 U4 U1' U2)"

definition CongA ::
  "['p,'p,'p,'p,'p,'p]  bool" 
  ("_ _ _ CongA _ _ _" [99,99,99,99,99,99] 50)
  where 
    "A B C CongA D E F 

A  B  C  B  D  E  F  E 
( A' C' D' F'. Bet B A A'  Cong A A' E D  Bet B C C'  Cong C C' E F 
Bet E D D'  Cong D D' B A  Bet E F F'  Cong F F' B C 
Cong A' C' D' F')"

definition LeA ::
  "['p,'p,'p,'p,'p,'p]  bool" 
  ("_ _ _ LeA _ _ _" [99,99,99,99,99,99] 50)
  where 
    "A B C LeA D E F 

 P. (P InAngle D E F  A B C CongA D E P)"

definition LtA ::
  "['p,'p,'p,'p,'p,'p]  bool" 
  ("_ _ _ LtA _ _ _" [99,99,99,99,99,99] 50)
  where 
    "A B C LtA D E F 
 
A B C LeA D E F  ¬ A B C CongA D E F"

definition GtA ::
  "['p,'p,'p,'p,'p,'p]  bool" 
  ("_ _ _ GtA _ _ _" [99,99,99,99,99,99] 50)
  where 
    "A B C GtA D E F 
 
D E F LtA A B C"

definition Acute ::
  "['p,'p,'p]  bool" 
  ("Acute _ _ _" [99,99,99] 50)
  where 
    "Acute A B C 

 A' B' C'. (Per A' B' C'  A B C LtA A' B' C')"

definition Obtuse ::
  "['p,'p,'p]  bool" 
  ("Obtuse _ _ _" [99,99,99] 50)
  where 
    "Obtuse A B C 

 A' B' C'. (Per A' B' C'  A' B' C' LtA A B C)"

definition OrthAt ::
  "['p,'p,'p,'p,'p,'p]  bool" 
  ("_ OrthAt _ _ _ _ _" [99,99,99,99,99,99] 50)
  where 
    "X OrthAt A B C U V 

¬ Col A B C  U  V  Coplanar A B C X  Col U V X 
( P Q. (Coplanar A B C P  Col U V Q)  Per P X Q)"

definition Orth ::
  "['p,'p,'p,'p,'p]  bool" 
  ("_ _ _ Orth _ _" [99,99,99,99,99] 50)
  where 
    "A B C Orth U V 

 X. X OrthAt A B C U V"

definition SuppA ::
  "['p,'p,'p,'p,'p,'p]  bool"
  ("_ _ _ SuppA _ _ _ " [99,99,99,99,99,99] 50)
  where
    "A B C SuppA D E F 

A  B  ( A'. Bet A B A'   D E F CongA C B A')"

definition SumA ::
  "['p,'p,'p,'p,'p,'p,'p,'p,'p]  bool" 
  ("_ _ _ _ _ _ SumA _ _ _" [99,99,99,99,99,99,99,99,99] 50)
  where
    "A B C D E F SumA G H I 

 J. (C B J CongA D E F  ¬ B C OS A J  Coplanar A B C J  A B J CongA G H I)"

definition TriSumA ::
  "['p,'p,'p,'p,'p,'p]  bool" 
  ("_ _ _ TriSumA _ _ _" [99,99,99,99,99,99] 50)
  where
    "A B C TriSumA D E F 

 G H I. (A B C B C A SumA G H I  G H I C A B SumA D E F)"

definition SAMS ::
  "['p,'p,'p,'p,'p,'p]  bool" 
  ("SAMS _ _ _ _ _ _" [99,99,99,99,99,99] 50)
  where
    "SAMS A B C D E F 

(A  B 
(E Out D F  ¬ Bet A B C)) 
( J. (C B J CongA D E F  ¬ (B C OS A J)  ¬ (A B TS C J)  Coplanar A B C J))"

definition Inter ::
  "['p,'p,'p,'p,'p]  bool" 
  ("_ Inter _ _ _ _" [99,99,99,99,99] 50)
  where 
    "X Inter A1 A2 B1 B2 

B1  B2 
( P::'p. (Col P B1 B2  ¬ Col P A1 A2)) 
Col A1 A2 X  Col B1 B2 X"

definition Perp2 :: (*GeoCoq 'Perp2 A B C D E' = IsaGeoCoq 'E Perp2 A B C D'*)
  "['p,'p,'p,'p,'p]  bool" 
  ("_ Perp2 _ _ _ _" [99,99,99,99,99] 50)
  where
    "P Perp2 A B C D 

 X Y. (Col P X Y  X Y Perp A B  X Y Perp C D)"

definition Perp_bisect ::
  "['p,'p,'p,'p]  bool" 
  ("_ _ PerpBisect _ _" [99,99,99,99] 50)
  where 
    "P Q PerpBisect A B 

A B ReflectL P Q  A  B"

definition Perp_bisect_bis ::
  "['p,'p,'p,'p]  bool" 
  ("_ _ PerpBisectBis _ _" [99,99,99,99] 50)
  where 
    "P Q PerpBisectBis A B 

 I. I PerpAt P Q A B  I Midpoint A B"

definition Is_on_perp_bisect ::
  "['p,'p,'p]  bool" 
  ("_ IsOnPerpBisect _ _" [99,99,99] 50)
  where 
    "P IsOnPerpBisect A B 

Cong A P P B"

definition isosceles::
  "['p,'p,'p]  bool"
  ("_ _ _ isosceles" [99,99,99] 50)
  where
    "A B C isosceles 

Cong A B B C"

definition equilateral::
  "['p,'p,'p]  bool"
  ("_ _ _ equilateral" [99,99,99] 50)
  where
    "A B C equilateral 

Cong A B B C  Cong B C C A"

definition equilateralStrict::
  "['p,'p,'p]  bool"
  ("_ _ _ equilateralStrict" [99,99,99] 50)
  where
    "A B C equilateralStrict 

A B C equilateral  A  B"

definition QCong::
  "(['p,'p]  bool)  bool" 
  ("QCong _" [99] 50)
  where
    "QCong l 

 A B. ( X Y. (Cong A B X Y  l X Y))"

definition TarskiLen::
  "['p,'p,(['p,'p]  bool)]  bool" 
  ("TarskiLen _ _ _" [99,99,99] 50)
  where
    "TarskiLen A B l 

QCong l  l A B"

definition QCongNull ::
  "(['p,'p]  bool)  bool" 
  ("QCongNull _" [99] 50)
  where
    "QCongNull l 

QCong l  ( A. l A A)"

definition QCongA ::
  "(['p, 'p, 'p]  bool)  bool" 
  ("QCongA _" [99] 50)
  where
    "QCongA a 

 A B C. (A  B  C  B  ( X Y Z. A B C CongA X Y Z  a X Y Z))"

definition Ang ::
  "['p,'p,'p, (['p, 'p, 'p]  bool) ]  bool" 
  ("_ _ _ Ang _" [99,99,99,99] 50)
  where
    "A B C Ang a 

QCongA a 
a A B C"

definition QCongAAcute ::
  "(['p, 'p, 'p]  bool)  bool" 
  ("QCongAACute _" [99] 50)
  where
    "QCongAAcute a 

 A B C. (Acute A B C  ( X Y Z. (A B C CongA X Y Z  a X Y Z)))"

definition AngAcute ::
  "['p,'p,'p, (['p,'p,'p]  bool)]  bool" 
  ("_ _ _ AngAcute _" [99,99,99,99] 50)
  where
    "A B C AngAcute a 

((QCongAAcute a)  (a A B C))"

definition QCongANullAcute ::
  "(['p,'p,'p]  bool)  bool" 
  ("QCongANullAcute _" [99] 50)
  where
    "QCongANullAcute a 

QCongAAcute a 
( A B C. (a A B C  B Out A C))"

definition QCongAnNull ::
  "(['p,'p,'p]  bool)  bool" 
  ("QCongAnNull _" [99] 50)
  where
    "QCongAnNull a 

QCongA a 
( A B C. (a A B C  ¬ B Out A C))"

definition QCongAnFlat ::
  "(['p,'p,'p]  bool)  bool" 
  ("QCongAnFlat _" [99] 50)
  where
    "QCongAnFlat a 

QCongA a 
( A B C. (a A B C  ¬ Bet A B C))"

definition IsNullAngaP ::
  "(['p,'p,'p]  bool)  bool" 
  ("IsNullAngaP _" [99] 50)
  where
    "IsNullAngaP a

QCongAAcute a 
( A B C. (a A B C  B Out A C))"

definition QCongANull ::
  "(['p,'p,'p]  bool)  bool" 
  ("QCongANull _" [99] 50)
  where
    "QCongANull a 

QCongA a 
( A B C. (a A B C  B Out A C))"

definition AngFlat ::
  "(['p, 'p, 'p]  bool)  bool" 
  ("AngFlat _" [99] 50)
  where
    "AngFlat a 

QCongA a 
( A B C. (a A B C  Bet A B C))"

definition EqLTarski ::
  "(['p, 'p]  bool)  (['p, 'p]  bool)  bool" 
  ("_ EqLTarski _" [99,99] 50)
  where
    "l1 EqLTarski l2 
 
 A B. l1 A B  l2 A B"

definition EqA ::
  "(['p, 'p, 'p]  bool)  (['p, 'p, 'p]  bool)  bool" 
  ("_ EqA _" [99,99] 50)
  where
    "a1 EqA a2 
 
 A B C. a1 A B C  a2 A B C"

definition hypothesis_of_right_saccheri_quadrilaterals ::
  "bool"
  ("HypothesisRightSaccheriQuadrilaterals")
  where
    "hypothesis_of_right_saccheri_quadrilaterals 

 A B C D. Saccheri A B C D  Per A B C"

definition hypothesis_of_acute_saccheri_quadrilaterals ::
  "bool"
  ("HypothesisAcuteSaccheriQuadrilaterals")
  where
    "hypothesis_of_acute_saccheri_quadrilaterals 

 A B C D. Saccheri A B C D  Acute A B C"

definition hypothesis_of_obtuse_saccheri_quadrilaterals ::
  "bool"
  ("HypothesisObtuseSaccheriQuadrilaterals")
  where
    "hypothesis_of_obtuse_saccheri_quadrilaterals 

 A B C D. Saccheri A B C D  Obtuse A B C"

definition Defect ::
  "['p,'p,'p,'p,'p,'p]  bool" 
  ("Defect _ _ _ _ _ _ " [99,99,99,99,99,99] 50)
  where
    "Defect A B C D E F

( G H I. (A B C TriSumA G H I  G H I SuppA D E F))"

(** Definition 14.1 **)

definition Ar1 ::
  "['p,'p,'p,'p,'p]  bool" 
  ("Ar1 _ _ _ _ _" [99,99,99,99,99] 50)
  where 
    "Ar1 PO E A B C 

PO  E  Col PO E A  Col PO E B  Col PO E C"

definition Ar2 ::
  "['p,'p,'p,'p,'p,'p]  bool" 
  ("Ar2 _ _ _ _ _ _" [99,99,99,99,99,99] 50)
  where 
    "Ar2 PO E E' A B C 

¬ Col PO E E'  Col PO E A  Col PO E B  Col PO E C"

(** Definition 14.2 **)

definition Pj ::
  "['p,'p,'p,'p]  bool" 
  ("_ _ Pj _ _" [99,99,99,99] 50)
  where 
    "A B Pj C D

A B Par C D  C = D"

(** Definition 14.3. **)

definition Sum ::
  "['p,'p,'p,'p,'p,'p]  bool" 
  ("Sum _ _ _ _ _ _" [99,99,99,99,99,99] 50)
  where 
    "Sum PO E E' A B C 

Ar2 PO E E' A B C 
( A' C'. E E' Pj A  A'  Col PO E' A'  PO E Pj A' C'  
         PO E' Pj B  C'  E' E Pj C' C)"

definition Proj ::
  "['p,'p,'p,'p,'p,'p]  bool" 
  ("_ _ Proj _ _ _ _" [99,99,99,99,99,99] 50)
  where
    "P Q Proj A B X Y

A  B  X  Y  ¬ A B Par X Y  Col A B Q  (P Q Par X Y  P = Q)"

definition Sump ::
  "['p,'p,'p,'p,'p,'p]  bool" 
  ("Sump _ _ _ _ _ _" [99,99,99,99,99,99] 50)
  where
    "Sump PO E E' A B C
  
Col PO E A  Col PO E B 
( A' C' P'. A A' Proj PO E' E E'  PO E Par A' P' 
             B C' Proj A' P' PO E'  C' C Proj PO E E E')"

(** Definition 14.4. *)

definition Prod ::
  "['p,'p,'p,'p,'p,'p]  bool" 
  ("Prod _ _ _ _ _ _" [99,99,99,99,99,99] 50)
  where
    "Prod PO E E' A B C 

Ar2 PO E E' A B C 
 ( B'. E E' Pj B B'  Col PO E' B'  E' A Pj B' C)"

definition Prodp ::
  "['p,'p,'p,'p,'p,'p]  bool" 
  ("Prodp _ _ _ _ _ _" [99,99,99,99,99,99] 50)
  where
    "Prodp PO E E' A B C 

Col PO E A  Col PO E B 
 ( B'. B B' Proj PO E' E E'  B' C Proj PO E A E')"

(** Definition 14.8. *)

definition Opp ::
  "['p,'p,'p,'p,'p]  bool" 
  ("Opp _ _ _ _ _" [99,99,99,99,99] 50)
  where 
    "Opp PO E E' A B 

Sum PO E E' B A PO"

(** Definition 14.38. *)

definition Diff ::
  "['p,'p,'p,'p,'p,'p]  bool" 
  ("Diff _ _ _ _ _ _" [99,99,99,99,99,99] 50)
  where
    "Diff PO E E' A B C

 B'. Opp PO E E' B B'  Sum PO E E' A B' C"

definition sum3 ::
  "['p,'p,'p,'p,'p,'p,'p]  bool" 
  ("sum3 _ _ _ _ _ _ _" [99,99,99,99,99,99,99] 50)
  where
    "sum3 PO E E' A B C S

 AB. Sum PO E E' A B AB  Sum PO E E' AB C S"

definition sum4 ::
  "['p,'p,'p,'p,'p,'p,'p,'p]  bool" 
  ("Sum4 _ _ _ _ _ _ _ _" [99,99,99,99,99,99,99,99] 50)
  where
    "Sum4 PO E E' A B C D S 

 ABC. sum3 PO E E' A B C ABC  Sum PO E E' ABC D S"

definition sum22 ::
  "['p,'p,'p,'p,'p,'p,'p,'p]  bool" 
  ("sum22 _ _ _ _ _ _ _ _" [99,99,99,99,99,99,99,99] 50)
  where
    "sum22 PO E E' A B C D S 

 AB CD. Sum PO E E' A B AB  Sum PO E E' C D CD  Sum PO E E' AB CD S"

definition Ar2p4 :: (* Ar2_4 *)
  "['p,'p,'p,'p,'p,'p,'p]  bool" 
  ("Ar2p4 _ _ _ _ _ _ _" [99,99,99,99,99,99,99] 50)
  where
    "Ar2p4 PO E E' A B C D

¬ Col PO E E'  Col PO E A  Col PO E B  Col PO E C  Col PO E D" 

(** Definition 14.34. *)

definition Ps ::
  "['p,'p,'p]  bool" 
  ("Ps _ _ _" [99,99,99] 50)
  where 
    "Ps X E A 
 
 X Out A E"

definition Ng ::
  "['p,'p,'p]  bool" 
  ("Ng _ _ _" [99,99,99] 50)
  where 
    "Ng X E A 

 A  X  E  X  Bet A X E"

(** Definition 14.38. *)

definition LtP ::
  "['p,'p,'p,'p,'p]  bool" 
  ("LtP _ _ _ _ _ " [99,99,99,99,99] 50)
  where 
    "LtP X E E' A B

 D. Diff X E E' B A D  Ps X E D"

definition LeP :: 
  "['p,'p,'p,'p,'p]  bool" 
  ("LeP _ _ _ _ _" [99,99,99,99,99] 50)
  where 
    "LeP X E E' A B
 
LtP X E E' A B  A = B"

definition Length ::
  "['p,'p,'p,'p,'p,'p]  bool" 
  ("Length _ _ _ _ _ _ " [99,99,99,99,99,99] 50)
  where 
    "Length X E E' A B L

 X  E  Col X E L  LeP X E E' X L  Cong X L A B"

(** Definition 15.1. *)

definition IsLength ::
  "['p,'p,'p,'p,'p,'p]  bool" 
  ("IsLength _ _ _ _ _ _ " [99,99,99,99,99,99] 50)
  where 
    "IsLength X E E' A B L 
  
Length X E E' A B L  (X = E  X = L)"

definition Sumg ::
  "['p,'p,'p,'p,'p,'p]  bool" 
  ("Sumg _ _ _ _ _ _ " [99,99,99,99,99,99] 50)
  where 
    "Sumg X E E' A B C 

Sum X E E' A B C  (¬ Ar2 X E E' A B B  C = X)"

definition Prodg ::
  "['p,'p,'p,'p,'p,'p]  bool" 
  ("Prodg _ _ _ _ _ _ " [99,99,99,99,99,99] 50)
  where 
    "Prodg X E E' A B C 

Prod X E E' A B C  (¬ Ar2 X E E' A B B  C = X)"

definition PythRel ::
  "['p,'p,'p,'p,'p,'p]  bool" 
  ("PythRel _ _ _ _ _ _ " [99,99,99,99,99,99] 50)
  where 
    "PythRel X E E' A B C 

Ar2 X E E' A B C 
((X = B  (A = C  Opp X E E' A C))  ( B'. X B' Perp X B  Cong X B' X B  Cong X C A B'))"

definition SignEq ::
  "['p,'p,'p,'p]  bool" 
  ("SignEq _ _ _ _ " [99,99,99,99] 50)
  where 
    "SignEq X E A B 

Ps X E A  Ps X E B  Ng X E A  Ng X E B" 

definition LtPs ::
  "['p,'p,'p,'p,'p]  bool" 
  ("LtPs _ _ _ _ _" [99,99,99,99,99] 50)
  where 
    "LtPs X E E' A B 

 D. Ps X E D  Sum X E E' A D B" 

definition IsOrthocenter ::
  "['p,'p,'p,'p]  bool"
  ("_ IsOrthocenter _ _ _" [99,99,99,99] 50)
  where
    "H IsOrthocenter A B C  ¬ Col A B C  
                              A H Perp B C  
                              B H Perp A C  
                              C H Perp A B"

definition IsCircumcenter ::
  "['p,'p,'p,'p]  bool"
  ("_ IsCircumcenter _ _ _" [99,99,99,99] 50)
  where
    "G IsCircumcenter A B C 
Cong A G B G  
Cong B G C G  
Coplanar G A B C"

definition IsGravityCenter ::
  "['p,'p,'p,'p]  bool"
  ("_ IsGravityCenter _ _ _" [99,99,99,99] 50)
  where
    "G IsGravityCenter A B C  ¬ Col A B C  
                               ( I J. I Midpoint B C  
                                       J Midpoint A C  
                                       Col G A I  
                                       Col G B J)"

(** Definition 13.9. *)

definition Lcos :: "(['p,'p]  bool)  
(['p,'p]  bool) 
(['p, 'p, 'p]  bool)  
bool"
  where
    "Lcos lb lc a 
  QCong lb  QCong lc  QCongAAcute a 
  ( A B C. (Per C B A  lb A B  lc A C  a B A C))"

definition EqLcos :: "(['p,'p]  bool)  
(['p, 'p, 'p]  bool)  
(['p,'p]  bool) 
(['p, 'p, 'p]  bool)  
bool"
  where
    "EqLcos la a lb b  ( lp. Lcos lp la a  Lcos lp lb b)"

definition Lcos2 :: "(['p,'p]  bool)  
(['p,'p]  bool) 
(['p, 'p, 'p]  bool)  
(['p, 'p, 'p]  bool)  
bool"
  where
    "Lcos2 lp l a b   la. Lcos la l a  Lcos lp la b" 

definition EqLcos2 :: "(['p,'p]  bool)  
(['p, 'p, 'p]  bool)  
(['p, 'p, 'p]  bool)  
(['p,'p]  bool) 
(['p, 'p, 'p]  bool)  
(['p, 'p, 'p]  bool)  
bool"
  where
    "EqLcos2 l1 a b l2 c d  ( lp. Lcos2 lp l1 a b  Lcos2 lp l2 c d)" 

definition Lcos3 :: "(['p,'p]  bool)  
(['p,'p]  bool) 
(['p, 'p, 'p]  bool)  
(['p, 'p, 'p]  bool)  
(['p, 'p, 'p]  bool)  
bool"
  where
    "Lcos3 lp l a b c   la lab. Lcos la l a 
Lcos lab la b  Lcos lp lab c"

definition EqLcos3 :: "(['p,'p]  bool)  
(['p, 'p, 'p]  bool)  
(['p, 'p, 'p]  bool)  
(['p, 'p, 'p]  bool)  
(['p,'p]  bool) 
(['p, 'p, 'p]  bool)  
(['p, 'p, 'p]  bool)  
(['p, 'p, 'p]  bool)  
bool"
  where
    "EqLcos3 l1 a b c l2 d e f  ( lp. Lcos3 lp l1 a b c  Lcos3 lp l2 d e f)" 

(** Vector *)

definition EqV :: "'p  'p  'p  'p  bool"
  ("_ _ EqV _ _ " [99,99,99,99] 50)
  where
    "A B EqV C D  Parallelogram A B D C  (A = B  C = D)"

definition SumV :: "'p  'p  'p  'p  'p  'p  bool"
  ("_ _ _ _ SumV _ _ " [99,99,99,99,99,99] 50)
  where
    "A B C D SumV E F   D'. C D EqV B D'  A D' EqV E F"

definition SumVExists :: "'p  'p  'p  'p  'p  'p  bool"
  ("_ _ _ _ SumVExists _ _ " [99,99,99,99,99,99] 50)
  where
    "A B C D SumVExists E F  ( D'. B D' EqV C D  A D' EqV E F)"

definition SameDir :: "'p  'p  'p  'p  bool"
  ("_ _ SameDir _ _ " [99,99,99,99] 50)
  where
    "A B SameDir C D   
(A = B  C = D)  ( D'. C Out D D'  A B EqV C D')" 

definition OppDir :: "'p  'p  'p  'p  bool"
  ("_ _ OppDir _ _ " [99,99,99,99] 50)
  where
    "A B OppDir C D   A B SameDir D C"

(* definition Proj :: "'p ⇒ 'p ⇒ 'p ⇒ 'p ⇒ 'p ⇒ 'p ⇒ bool"
  ("_ _ Proj _ _ _ _" [99,99,99,99,99,99] 50)
  where
    "P Q Proj A B X Y ≡

  A ≠ B ∧ X ≠ Y ∧ ¬ A B Par X Y ∧ Col A B Q ∧ (P Q Par X Y ∨ P = Q)"
*)

definition CongA3 :: "'p  'p  'p  'p  'p  'p  bool"
  ("_ _ _ CongA3 _ _ _" [99,99,99,99,99,99] 50)
  where
    "A B C CongA3 A' B' C' 
  A B C CongA A' B' C'  B C A CongA B' C' A'  C A B CongA C' A' B'" 

(** Q is the orthogonal projection of P on the line AB. *)
definition Projp :: "'p  'p  'p  'p  bool"
  ("_ _ Projp _ _" [99,99,99,99] 50)
  where
    "P Q Projp A B 
  A  B  ((Col A B Q  A B Perp P Q)  (Col A B P  P = Q))"

subsection "Propositions"

lemma cong_reflexivity:
  shows "Cong A B A B"
  using cong_inner_transitivity cong_pseudo_reflexivity by blast

lemma cong_symmetry:
  assumes "Cong A B C D"
  shows "Cong C D A B"
  using assms cong_inner_transitivity cong_reflexivity by blast

lemma cong_transitivity:
  assumes "Cong A B C D" and "Cong C D E F"
  shows "Cong A B E F"
  by (meson assms(1) assms(2) cong_inner_transitivity cong_pseudo_reflexivity)

lemma cong_left_commutativity:
  assumes "Cong A B C D"
  shows "Cong B A C D"
  using assms cong_inner_transitivity cong_pseudo_reflexivity by blast

lemma cong_right_commutativity:
  assumes "Cong A B C D"
  shows "Cong A B D C"
  using assms cong_left_commutativity cong_symmetry by blast

lemma cong_3421:
  assumes "Cong A B C D"
  shows "Cong C D B A"
  using assms cong_left_commutativity cong_symmetry by blast

lemma cong_4312:
  assumes "Cong A B C D"
  shows "Cong D C A B"
  using assms cong_left_commutativity cong_symmetry by blast

lemma cong_4321:
  assumes "Cong A B C D"
  shows "Cong D C B A"
  using assms cong_3421 cong_left_commutativity by blast

lemma cong_trivial_identity:
  shows "Cong A A B B"
  using cong_identity segment_construction by blast

lemma cong_reverse_identity:
  assumes "Cong A A C D"
  shows "C = D"
  using assms cong_3421 cong_identity by blast

lemma cong_commutativity:
  assumes "Cong A B C D"
  shows "Cong B A D C"
  using assms cong_3421 by blast

lemma not_cong_2134:
  assumes " ¬ Cong A B C D"
  shows "¬ Cong B A C D"
  using assms cong_left_commutativity by blast

lemma not_cong_1243:
  assumes "¬ Cong A B C D"
  shows "¬ Cong A B D C"
  using assms cong_right_commutativity by blast

lemma not_cong_2143:
  assumes "¬ Cong A B C D"
  shows "¬ Cong B A D C"
  using assms cong_commutativity by blast

lemma not_cong_3412:
  assumes "¬ Cong A B C D"
  shows "¬ Cong C D A B"
  using assms cong_symmetry by blast

lemma not_cong_4312:
  assumes "¬ Cong A B C D"
  shows "¬ Cong D C A B"
  using assms cong_3421 by blast

lemma not_cong_3421:
  assumes "¬ Cong A B C D"
  shows "¬ Cong C D B A"
  using assms cong_4312 by blast

lemma not_cong_4321:
  assumes "¬ Cong A B C D"
  shows "¬ Cong D C B A"
  using assms cong_4321 by blast

lemma five_segment_with_def:
  assumes "A B C D OFSC A' B' C' D'" and "A  B"
  shows "Cong C D C' D'"
  using assms(1) assms(2) OFSC_def five_segment by blast

lemma cong_diff:
  assumes "A  B" and "Cong A B C D"
  shows "C  D"
  using assms(1) assms(2) cong_identity by blast

lemma cong_diff_2:
  assumes "B  A" and "Cong A B C D"
  shows "C  D"
  using assms(1) assms(2) cong_identity by blast

lemma cong_diff_3:
  assumes "C  D" and "Cong A B C D"
  shows "A  B"
  using assms(1) assms(2) cong_reverse_identity by blast

lemma cong_diff_4:
  assumes "D  C" and "Cong A B C D"
  shows "A  B"
  using assms(1) assms(2) cong_reverse_identity by blast

lemma cong_3_sym:
  assumes "A B C Cong3 A' B' C'"
  shows "A' B' C' Cong3 A B C"
  using assms Cong3_def not_cong_3412 by blast

lemma cong_3_swap:
  assumes "A B C Cong3 A' B' C'"
  shows "B A C Cong3 B' A' C'"
  using assms Cong3_def cong_commutativity by blast

lemma cong_3_swap_2:
  assumes "A B C Cong3 A' B' C'"
  shows "A C B Cong3 A' C' B'"
  using assms Cong3_def cong_commutativity by blast

lemma cong3_transitivity:
  assumes "A0 B0 C0 Cong3 A1 B1 C1" and
    "A1 B1 C1 Cong3 A2 B2 C2"
  shows "A0 B0 C0 Cong3 A2 B2 C2"
  by (meson assms(1) assms(2) Cong3_def cong_inner_transitivity not_cong_3412)

lemma eq_dec_points:
  shows "A = B  ¬ A = B"
  by simp

lemma distinct:
  assumes "P  Q"
  shows "R  P  R  Q"
  using assms by simp

lemma l2_11:
  assumes "Bet A B C" and
    "Bet A' B' C'" and
    "Cong A B A' B'" and
    "Cong B C B' C'"
  shows "Cong A C A' C'"
proof cases
  assume "A = B"
  thus ?thesis 
    using assms(3) assms(4) cong_reverse_identity by blast
next
  assume "A  B"
  thus ?thesis 
    using five_segment Tarski_neutral_dimensionless_axioms assms(1) assms(2) assms(3) assms(4) 
      cong_commutativity cong_trivial_identity by blast
qed

lemma bet_cong3:
  assumes "Bet A B C" and
    "Cong A B A' B'"
  shows " C'. A B C Cong3 A' B' C'"
  by (meson assms(1) assms(2) Cong3_def l2_11 not_cong_3412 segment_construction)

lemma construction_uniqueness:
  assumes "Q  A" and
    "Bet Q A X" and
    "Cong A X B C" and
    "Bet Q A Y" and
    "Cong A Y B C"
  shows "X = Y"
  by (meson assms(1) assms(2) assms(3) assms(4) assms(5) cong_identity cong_inner_transitivity 
      cong_reflexivity five_segment)

lemma Cong_cases:
  assumes "Cong A B C D  Cong A B D C  Cong B A C D  Cong B A D C  Cong C D A B  
Cong C D B A  Cong D C A B  Cong D C B A"
  shows "Cong A B C D"
  using assms not_cong_3421 not_cong_4321 by blast

lemma Cong_perm :
  assumes "Cong A B C D"
  shows "Cong A B C D  Cong A B D C  Cong B A C D  Cong B A D C  Cong C D A B  
Cong C D B A  Cong D C A B  Cong D C B A"
  using assms not_cong_1243 not_cong_3412 by blast

lemma bet_col:
  assumes "Bet A B C"
  shows "Col A B C"
  by (simp add: assms Col_def)

lemma between_trivial:
  shows "Bet A B B"
  using cong_identity segment_construction by blast

lemma between_symmetry:
  assumes "Bet A B C"
  shows "Bet C B A"
  using assms between_identity between_trivial inner_pasch by blast

lemma Bet_cases:
  assumes "Bet A B C  Bet C B A"
  shows "Bet A B C"
  using assms between_symmetry by blast

lemma Bet_perm:
  assumes "Bet A B C"
  shows "Bet A B C  Bet C B A"
  using assms Bet_cases by blast

lemma between_trivial2:
  shows "Bet A A B"
  using Bet_perm between_trivial by blast

lemma between_equality:
  assumes "Bet A B C" and "Bet B A C"
  shows "A = B"
  using assms(1) assms(2) between_identity inner_pasch by blast

lemma between_equality_2:
  assumes "Bet A B C" and
    "Bet A C B"
  shows "B = C"
  using assms(1) assms(2) between_equality between_symmetry by blast

lemma between_exchange3:
  assumes "Bet A B C" and
    "Bet A C D"
  shows "Bet B C D"
  by (metis Bet_perm assms(1) assms(2) between_identity inner_pasch)

lemma bet_neq12__neq:
  assumes "Bet A B C" and
    "A  B"
  shows "A  C"
  using assms(1) assms(2) between_identity by blast

lemma bet_neq21__neq:
  assumes "Bet A B C" and
    "B  A"
  shows "A  C"
  using assms(1) assms(2) between_identity by blast

lemma bet_neq23__neq:
  assumes "Bet A B C" and
    "B  C"
  shows "A  C"
  using assms(1) assms(2) between_identity by blast

lemma bet_neq32__neq:
  assumes "Bet A B C" and
    "C  B"
  shows "A  C"
  using assms(1) assms(2) between_identity by blast

lemma not_bet_distincts:
  assumes "¬ Bet A B C"
  shows "A  B  B  C"
  using assms between_trivial between_trivial2 by blast

lemma between_inner_transitivity:
  assumes "Bet A B D" and
    "Bet B C D"
  shows "Bet A B C"
  using assms(1) assms(2) Bet_perm between_exchange3 by blast

lemma outer_transitivity_between2:
  assumes "Bet A B C" and
    "Bet B C D" and
    "B  C"
  shows "Bet A C D"
proof -
  obtain X where "Bet A C X" and "Cong C X C D"
    using segment_construction by blast
  thus ?thesis
    using assms(1) assms(2) assms(3) between_exchange3 cong_inner_transitivity 
      construction_uniqueness by blast
qed

lemma between_exchange2:
  assumes "Bet A B D" and
    "Bet B C D"
  shows "Bet A C D"
  using assms(1) assms(2) between_inner_transitivity outer_transitivity_between2 by blast

lemma outer_transitivity_between:
  assumes "Bet A B C" and
    "Bet B C D" and
    "B  C"
  shows "Bet A B D"
  using assms(1) assms(2) assms(3) between_symmetry outer_transitivity_between2 by blast

lemma between_exchange4:
  assumes "Bet A B C" and
    "Bet A C D"
  shows "Bet A B D"
  using assms(1) assms(2) between_exchange2 between_symmetry by blast

lemma l3_9_4:
  assumes "Bet4 A1 A2 A3 A4"
  shows "Bet4 A4 A3 A2 A1"
  using assms Bet4_def Bet_cases by blast

lemma l3_17:
  assumes "Bet A B C" and
    "Bet A' B' C" and
    "Bet A P A'"
  shows " Q. Bet P Q C  Bet B Q B'"
proof -
  obtain X where "Bet B' X A" and "Bet P X C"
    using Bet_perm assms(2) assms(3) inner_pasch by blast
  moreover then obtain Y where "Bet X Y C" and "Bet B Y B'"
    using Bet_perm assms(1) inner_pasch by blast
  ultimately show ?thesis
    using between_exchange2 by blast
qed

lemma lower_dim_ex:
  " A B C. ¬ (Bet A B C  Bet B C A  Bet C A B)"
  using lower_dim by auto

lemma two_distinct_points:
  " X::'p.  Y::'p. X  Y"
  using lower_dim_ex not_bet_distincts by blast

lemma point_construction_different:
  " C. Bet A B C  B  C"
  using two_distinct_points Tarski_neutral_dimensionless_axioms 
    cong_reverse_identity segment_construction by blast

lemma another_point:
  " B::'p. A  B"
  using point_construction_different by blast

lemma Cong_stability:
  assumes "¬ ¬ Cong A B C D"
  shows "Cong A B C D"
  using assms by simp

lemma l2_11_b:
  assumes "Bet A B C" and
    "Bet A' B' C'" and
    "Cong A B A' B'" and
    "Cong B C B' C'"
  shows "Cong A C A' C'"
  using assms(1) assms(2) assms(3) assms(4) l2_11 by auto

lemma cong_dec_eq_dec_b:
  assumes "¬ A  B"
  shows "A = B"
  using assms(1) by simp

lemma BetSEq:
  assumes "BetS A B C"
  shows "Bet A B C  A  B  A  C  B  C"
  using assms BetS_def between_identity by auto

lemma l4_2:
  assumes "A B C D IFSC A' B' C' D'"
  shows "Cong B D B' D'"
proof cases
  assume "A = C"
  thus ?thesis
    by (metis IFSC_def between_identity assms cong_diff_3)
next
  assume "A  C"
  have "Bet A B C" and "Bet A' B' C'" and
    "Cong A C A' C'" and "Cong B C B' C'"
    "Cong A D A' D'" and "Cong C D C' D'"
    using IFSC_def assms by auto
  obtain E where "Bet A C E" and "Cong C E A C"
    using segment_construction by blast
  obtain E' where "Bet A' C' E'" and "Cong C' E' C E"
    using segment_construction by blast
  hence "Cong C E C' E'" 
    using Cong_cases by blast
  hence "Cong E D E' D'" 
    using A  C Bet A C E Bet A' C' E' Cong A C A' C' 
      Cong A D A' D' Cong C D C' D' 
      five_segment by blast
  moreover
  have "E  C" 
    using A  C Cong C E A C cong_reverse_identity by blast
  moreover
  have "Bet E C B" 
    using Bet A B C Bet A C E between_exchange3 between_symmetry by blast
  moreover
  have "Bet E' C' B'" 
    using Bet A' B' C' Bet A' C' E' between_exchange3 between_symmetry by blast
  moreover
  have "Cong E C E' C'" 
    by (simp add: Cong C E C' E' cong_commutativity)
  moreover
  have "Cong C B C' B' " 
    using Cong_cases Cong B C B' C' by blast
  ultimately show ?thesis
    using Cong C D C' D' five_segment by blast
qed

lemma l4_3:
  assumes "Bet A B C" and
    "Bet A' B' C'" and
    "Cong A C A' C'"
    and "Cong B C B' C'"
  shows "Cong A B A' B'"
proof -
  have "A B C A IFSC A' B' C' A'"
    using IFSC_def assms(1) assms(2) assms(3) assms(4) cong_trivial_identity 
      not_cong_2143 by blast
  thus ?thesis
    using l4_2 not_cong_2143 by blast
qed


lemma l4_3_1:
  assumes "Bet A B C" and
    "Bet A' B' C'" and
    "Cong A B A' B'" and
    "Cong A C A' C'"
  shows "Cong B C B' C'"
  by (meson assms(1) assms(2) assms(3) assms(4) between_symmetry cong_4321 l4_3)

lemma l4_5:
  assumes "Bet A B C" and
    "Cong A C A' C'"
  shows  " B'. (Bet A' B' C'  A B C Cong3 A' B' C')"
proof -
  obtain X' where "Bet C' A' X'" and "A'  X'"
    using point_construction_different by auto
  obtain B' where "Bet X' A' B'" and "Cong A' B' A B"
    using segment_construction by blast
  obtain C'' where "Bet X' B' C''" and "Cong B' C'' B C"
    using segment_construction by blast
  hence "Bet A' B' C''"
    using Bet X' A' B' between_exchange3 by blast
  moreover
  have "A B C Cong3 A' B' C''" 
    using Cong3_def Cong A' B' A B Cong B' C'' B C assms(1) calculation cong_symmetry l2_11_b 
    by blast
  moreover
  have "C'' = C'"
  proof -
    have "Bet X' A' C''" 
      using Bet X' A' B' Bet X' B' C'' between_exchange4 by blast
    moreover have "Bet X' A' C'" 
      using Bet_cases Bet C' A' X' by auto
    moreover have "Cong A' C'' A C" 
      using Bet A' B' C'' Cong A' B' A B Cong B' C'' B C assms(1) l2_11_b by blast
    ultimately show ?thesis 
      by (metis A'  X' assms(2) cong_symmetry construction_uniqueness)
  qed
  ultimately show ?thesis
    by auto
qed

lemma l4_6:
  assumes "Bet A B C" and
    "A B C Cong3 A' B' C'"
  shows "Bet A' B' C'"
proof -
  obtain x where P1: "Bet A' x C'  A B C Cong3 A' x C'"
    using Cong3_def assms(1) assms(2) l4_5 by blast
  hence "A' x C' Cong3 A' B' C'"
    using assms(2) cong3_transitivity cong_3_sym by blast
  hence "A' x C' x IFSC A' x C' B'"
    by (meson Cong3_def Cong_perm IFSC_def P1 cong_reflexivity)
  hence "Cong x x x B'"
    using l4_2 by auto
  thus ?thesis
    using P1 cong_reverse_identity by blast
qed

lemma cong3_bet_eq:
  assumes "Bet A B C" and
    "A B C Cong3 A X C"
  shows "X = B"
proof -
  have "A B C B IFSC A B C X"
    by (meson Cong3_def Cong_perm IFSC_def assms(1) assms(2) cong_reflexivity)
  thus ?thesis
    using cong_reverse_identity l4_2 by blast
qed

lemma col_permutation_1:
  assumes "Col A B C"
  shows "Col B C A"
  using assms(1) Col_def by blast

lemma col_permutation_2:
  assumes "Col A B C"
  shows "Col C A B"
  using assms(1) col_permutation_1 by blast

lemma col_permutation_3:
  assumes "Col A B C"
  shows "Col C B A"
  using assms(1) Bet_cases Col_def by auto

lemma col_permutation_4:
  assumes "Col A B C"
  shows "Col B A C"
  using assms(1) Bet_perm Col_def by blast

lemma col_permutation_5:
  assumes "Col A B C"
  shows "Col A C B"
  using assms(1) col_permutation_1 col_permutation_3 by blast

lemma not_col_permutation_1:
  assumes "¬ Col A B C"
  shows "¬ Col B C A"
  using assms col_permutation_2 by blast

lemma not_col_permutation_2:
  assumes "¬ Col A B C"
  shows  "¬ Col C A B"
  using assms col_permutation_1 by blast

lemma not_col_permutation_3:
  assumes "¬ Col A B C"
  shows "¬ Col C B A"
  using assms col_permutation_3 by blast

lemma not_col_permutation_4:
  assumes "¬ Col A B C"
  shows "¬ Col B A C"
  using assms col_permutation_4 by blast

lemma not_col_permutation_5:
  assumes "¬ Col A B C"
  shows "¬ Col A C B"
  using assms col_permutation_5 by blast

lemma Col_cases:
  assumes "Col A B C  Col A C B  Col B A C  Col B C A  Col C A B  Col C B A"
  shows "Col A B C"
  using assms not_col_permutation_4 not_col_permutation_5 by blast

lemma Col_perm:
  assumes "Col A B C"
  shows "Col A B C  Col A C B  Col B A C  Col B C A  Col C A B  Col C B A"
  using Col_cases assms by blast

lemma col_trivial_1:
  "Col A A B"
  using bet_col not_bet_distincts by blast

lemma col_trivial_2:
  "Col A B B"
  by (simp add: Col_def between_trivial2)

lemma col_trivial_3:
  "Col A B A"
  by (simp add: Col_def between_trivial2)

lemma l4_13:
  assumes "Col A B C" and
    "A B C Cong3 A' B' C'"
  shows "Col A' B' C'"
  by (metis Col_def cong_3_swap cong_3_swap_2 assms(1) assms(2) l4_6)

lemma l4_14R1:
  assumes "Bet A B C" and
    "Cong A B A' B'"
  shows " C'. A B C Cong3 A' B' C'"
  by (simp add: assms(1) assms(2) bet_cong3)

lemma l4_14R2:
  assumes "Bet B C A" and
    "Cong A B A' B'"
  shows " C'. A B C Cong3 A' B' C'"
  by (meson assms(1) assms(2) between_symmetry cong_3_swap_2 l4_5)

lemma l4_14R3:
  assumes "Bet C A B" and
    "Cong A B A' B'"
  shows " C'. A B C Cong3 A' B' C'"
  by (meson assms(1) assms(2) between_symmetry cong_3_swap l4_14R1 not_cong_2143)

lemma l4_14:
  assumes "Col A B C" and
    "Cong A B A' B'"
  shows " C'. A B C Cong3 A' B' C'"
  using Col_def assms(1) assms(2) l4_14R1 l4_14R2 l4_14R3 by blast

lemma l4_16R1:
  assumes "A B C D FSC A' B' C' D'" and
    "A  B" and
    "Bet A B C"
  shows "Cong C D C' D'"
proof -
  have "A B C Cong3 A' B' C'"
    using FSC_def assms(1) by blast
  hence "Bet A' B' C'"
    using assms(3) l4_6 by blast
  hence "A B C D OFSC A' B' C' D'"
    by (meson Cong3_def FSC_def OFSC_def assms(1) cong_3_sym l4_6)
  thus ?thesis
    using assms(2) five_segment_with_def by blast
qed

lemma l4_16R2:
  assumes "A B C D FSC A' B' C' D'"
    and "Bet B C A"
  shows "Cong C D C' D'"
proof -
  have "A B C Cong3 A' B' C'"
    using FSC_def assms(1) by blast
  hence "Bet B' C' A'"
    using Bet_perm assms(2) cong_3_swap_2 l4_6 by blast
  hence "B C A D IFSC B' C' A' D'"
    by (meson Cong3_def FSC_def IFSC_def assms(1) assms(2) not_cong_2143)
  thus ?thesis
    using l4_2 by auto
qed

lemma l4_16R3:
  assumes "A B C D FSC A' B' C' D'" and 
    "A  B" and 
    "Bet C A B"
  shows "Cong C D C' D'"
proof -
  have "A B C Cong3 A' B' C'"
    using FSC_def assms(1) by blast
  hence "Bet C' A' B'"
    using assms(3) between_symmetry cong_3_swap l4_6 by blast
  thus ?thesis 
    by (metis Bet_cases Col_def FSC_def cong_3_swap assms(1) assms(2) assms(3) l4_16R1)
qed

lemma l4_16:
  assumes "A B C D FSC A' B' C' D'" and
    "A  B"
  shows "Cong C D C' D'"
  by (meson Col_def FSC_def assms(1) assms(2) l4_16R1 l4_16R2 l4_16R3)

lemma l4_17:
  assumes "A  B" and
    "Col A B C" and
    "Cong A P A Q" and
    "Cong B P B Q"
  shows "Cong C P C Q"
proof -
  {
    assume "¬ Bet B C A"
    hence "p pa. Bet p pa C  Cong pa P pa Q  Cong p P p Q  p  pa"
      using Col_def assms(1) assms(2) assms(3) assms(4) between_symmetry by blast
    hence ?thesis
      using cong_reflexivity five_segment by blast
  }
  thus ?thesis
    by (meson IFSC_def assms(3) assms(4) cong_reflexivity l4_2)
qed

lemma l4_18:
  assumes "A  B" and
    "Col A B C" and
    "Cong A C A C'" and
    "Cong B C B C'"
  shows "C = C'"
  using assms(1) assms(2) assms(3) assms(4) cong_diff_3 l4_17 by blast

lemma l4_19:
  assumes "Bet A C B" and
    "Cong A C A C'" and
    "Cong B C B C'"
  shows "C = C'"
  by (metis Col_def assms(1) assms(2) assms(3) between_equality between_trivial cong_identity 
      l4_18 not_cong_3421)

lemma not_col_distincts:
  assumes "¬ Col A B C"
  shows "¬ Col A B C  A  B  B  C  A  C"
  using Col_def assms between_trivial by blast

lemma NCol_cases:
  assumes "¬ Col A B C  ¬ Col A C B  ¬ Col B A C  ¬ Col B C A  ¬ Col C A B  ¬ Col C B A"
  shows  "¬ Col A B C"
  using assms not_col_permutation_2 not_col_permutation_3 by blast

lemma NCol_perm:
  assumes "¬ Col A B C"
  shows "¬ Col A B C  ¬ Col A C B  ¬ Col B A C  ¬ Col B C A  ¬ Col C A B  ¬ Col C B A"
  using NCol_cases assms by blast

lemma col_cong_3_cong_3_eq:
  assumes "A  B"
    and "Col A B C"
    and "A B C Cong3 A' B' C1"
    and  "A B C Cong3 A' B' C2"
  shows  "C1 = C2"
  using Cong3_def cong_diff l4_18 assms(1) assms(2) assms(3) assms(4) cong_inner_transitivity 
    l4_13 by meson

lemma l5_1:
  assumes "A  B" and
    "Bet A B C" and
    "Bet A B D"
  shows "Bet A C D  Bet A D C"
proof -
  obtain C' where "Bet A D C'" and "Cong D C' C D"
    using segment_construction by blast
  obtain D' where "Bet A C D'" and "Cong C D' C D"
    using segment_construction by blast
  obtain B' where "Bet A C' B'" and "Cong C' B' C B"
    using segment_construction by blast
  obtain B'' where "Bet A D' B''" and "Cong D' B'' D B"
    using segment_construction by blast
  hence "Cong B C' B'' C"
    using assms(3) between_exchange3 between_symmetry cong_4312 cong_inner_transitivity l2_11_b
      Bet A C D' Bet A D C' Cong C D' C D Cong D C' C D by meson
  hence "Cong B B' B'' B"
    by (meson Bet_cases assms(2) assms(3) between_exchange4 between_inner_transitivity l2_11_b
        Bet A C D' Bet A C' B' Bet A D C' Bet A D' B'' Cong C' B' C B)
  hence "B'' = B'"
    by (meson assms(1) assms(2) assms(3) between_exchange4 cong_inner_transitivity 
        construction_uniqueness not_cong_2134 Bet A C D' Bet A C' B' Bet A D C' 
        Bet A D' B'')
  have "B C D' Cong3 B' C' D" 
  proof -
    have "Cong B C B' C'" 
      using Cong C' B' C B not_cong_4321 by blast
    moreover
    have "Bet B' C' D" 
      using Bet A C' B' Bet A D C' between_exchange3 between_symmetry by blast
    have "Bet B C D'" 
      using Bet A C D' assms(2) between_exchange3 by blast
    moreover have "Cong B D' B' D" 
      using l2_11  Cong_cases Bet B C D' Bet B' C' D Cong C D' C D Cong D C' C D 
        cong_transitivity Cong B C B' C' by blast
    moreover have "Cong C D' C' D" 
      by (metis Cong_cases Cong C D' C D Cong D C' C D cong_transitivity)
    ultimately show ?thesis 
      using Cong3_def by blast
  qed
  have "Bet B C D'"
    using assms(2) between_exchange3 Bet A C D' by blast
  have "Cong C D' C' D" 
    by (metis Cong_perm cong_transitivity Cong C D' C D Cong D C' C D)
  hence "B C D' C' FSC B' C' D C" 
    using FSC_def B C D' Cong3 B' C' D B'' = B' Bet B C D' Cong B C' B'' C 
      bet_col cong_pseudo_reflexivity by presburger
  hence "Cong D' C' D C"
    using cong_identity l4_16 B'' = B' Cong C' B' C B Cong D' B'' D B by blast
  obtain E where "Bet C E C'" and "Bet D E D'"
    using between_trivial2 l3_17 Bet A C D' Bet A D C' by blast
  hence "D E D' C IFSC D E D' C'"
    by (meson IFSC_def cong_reflexivity cong_3421 cong_inner_transitivity Cong C D' C D 
        Cong D C' C D Cong D' C' D C)
  hence "Cong E C E C'"
    using l4_2 by auto
  have "C E C' D IFSC C E C' D'"
    using IFSC_def cong_reflexivity cong_3421 cong_inner_transitivity
    by (meson Bet C E C' Cong C D' C' D D E D' C IFSC D E D' C')
  hence "Cong E D E D'"
    using l4_2 by auto
  obtain P where "Bet C' C P" and "Cong C P C D'"
    using segment_construction by blast
  obtain R where "Bet D' C R" and "Cong C R C E"
    using segment_construction by blast
  obtain Q where "Bet P R Q" and "Cong R Q R P"
    using segment_construction by blast
  have "D' C R P FSC P C E D'"
    by (meson Bet_perm Cong3_def FSC_def Bet C E C' Bet C' C P Cong C P C D'  Bet D' C R 
        Cong C R C E bet_col between_exchange3 cong_pseudo_reflexivity l2_11_b not_cong_4321)
  have "Cong R P E D'" 
    by (metis Cong C P C D' Cong C R C E D' C R P FSC P C E D' cong_commutativity 
        cong_diff l4_16)
  have "Cong R Q E D" 
    by (metis cong_symmetry cong_transitivity Cong E D E D' Cong R P E D' Cong R Q R P)
  have "D' E D C FSC P R Q C" 
    by (meson Cong3_def FSC_def Bet D E D' Bet P R Q Cong C P C D' Cong C R C E 
        Cong R P E D' Cong R Q E D bet_col between_symmetry l2_11_b not_cong_3412 
        not_cong_4321)
  have "Cong D C Q C" 
    by (metis Cong E D E D' D' E D C FSC P R Q C between_trivial2 cong_identity l4_16 l4_16R2)
  have "Cong C P C Q" 
    by (meson Cong C D' C D Cong C P C D' Cong D C Q C cong_transitivity not_cong_2143)
  have "Bet A C D  Bet A D C"
  proof cases
    assume "R = C"
    thus ?thesis 
      using Bet A D C' Cong C R C E Cong E C E C' cong_reverse_identity by blast
  next
    assume "R  C"
    {
      have "Cong D' P D' Q"
      proof -
        have "Col R C D'"
          by (simp add: Bet D' C R Cong C R C E bet_col between_symmetry)
        have "Cong R P R Q" 
          by (metis Cong_cases Cong R Q R P)
        have "Cong C P C Q"
          by (simp add: Cong C P C Q)
        thus ?thesis
          using Col R C D' Cong R P R Q R  C l4_17 by blast
      qed
      hence "Cong B P B Q"  
        by (metis Col_def Bet B C D' Cong C P C D' Cong C P C Q cong_identity 
            cong_reflexivity l4_17 l4_19 not_bet_distincts)
      have "Cong B' P B' Q" 
        by (metis cong_diff_2 cong_diff_4 B'' = B' Bet A C D' Bet A D' B'' Bet C E C' 
            Cong C D' C D Cong C D' C' D Cong C P C Q Cong C R C E Cong D' P D' Q R  C 
            between_exchange3 between_identity cong_reflexivity five_segment)
      have "Cong C' P C' Q"
      proof -
        have "Bet B C' B'" 
          using Bet A C' B' Bet A D C' assms(3) between_exchange3 between_exchange4 by blast
        thus ?thesis
          by (metis Col_def Cong B P B Q Cong B' P B' Q between_equality l4_17 
              not_bet_distincts)
      qed
      have "Cong P P P Q" 
        by (metis cong_diff Bet C E C' Bet C' C P Cong C P C Q Cong C R C E 
            Cong C' P C' Q R  C bet_col between_equality_2 between_trivial2 l4_17)
      thus ?thesis 
        using Bet A C D' Bet P R Q Cong R P E D' Cong R Q E D between_identity 
          cong_reverse_identity by blast
    }
    hence "R  C  Bet A C D  Bet A D C" by blast
  qed
  thus ?thesis
    by simp
qed

lemma l5_2:
  assumes "A  B" and
    "Bet A B C" and
    "Bet A B D"
  shows  "Bet B C D  Bet B D C"
  using assms(1) assms(2) assms(3) between_exchange3 l5_1 by blast

lemma segment_construction_2:
  assumes  "A  Q"
  shows " X. ((Bet Q A X  Bet Q X A)  Cong Q X B C)"
proof -
  obtain A' where "Bet A Q A'" and "Cong Q A' A Q"
    using segment_construction by blast
  obtain X where "Bet A' Q X" and "Cong Q X B C"
    using segment_construction by blast
  thus ?thesis
    by (metis Bet A Q A' Cong Q A' A Q cong_diff_4 between_symmetry l5_2)
qed

lemma l5_3:
  assumes "Bet A B D" and
    "Bet A C D"
  shows "Bet A B C  Bet A C B"
  by (metis Bet_perm assms(1) assms(2) between_inner_transitivity l5_2 
      point_construction_different)

lemma bet3__bet:
  assumes "Bet A B E" and
    "Bet A D E" and
    "Bet B C D"
  shows "Bet A C E"
  by (meson assms(1) assms(2) assms(3) between_exchange2 between_symmetry l5_3)

lemma le_bet:
  assumes "C D Le A B"
  shows " X. (Bet A X B  Cong A X C D)"
  by (meson Le_def assms cong_symmetry)

lemma l5_5_1:
  assumes "A B Le C D"
  shows " X. (Bet A B X  Cong A X C D)"
proof -
  obtain P where "Bet C P D" and "Cong A B C P"
    using Le_def assms by blast
  obtain X where "Bet A B X" and "Cong B X P D"
    using segment_construction by blast
  thus ?thesis 
    by (meson Bet C P D Cong A B C P l2_11_b)
qed

lemma l5_5_2:
  assumes " X. (Bet A B X  Cong A X C D)"
  shows "A B Le C D"
proof -
  obtain P where "Bet A B P" and "Cong A P C D"
    using assms by blast
  then obtain B' where "Bet C B' D" and "A B P Cong3 C B' D"
    using l4_5 by blast
  thus ?thesis
    using Cong3_def Le_def by blast
qed

lemma l5_6:
  assumes "A B Le C D" and
    "Cong A B A' B'" and
    "Cong C D C' D'"
  shows "A' B' Le C' D'"
  by (meson Cong3_def Le_def assms(1) assms(2) assms(3) cong_inner_transitivity l4_5)

lemma le_reflexivity:
  shows "A B Le A B"
  using between_trivial cong_reflexivity l5_5_2 by blast

lemma le_transitivity:
  assumes "A B Le C D" and
    "C D Le E F"
  shows "A B Le E F"
  by (meson assms(1) assms(2) between_exchange4 cong_reflexivity l5_5_1 l5_5_2 l5_6 le_bet)

lemma between_cong:
  assumes "Bet A C B" and
    "Cong A C A B"
  shows "C = B" 
  by (metis assms(1) assms(2) between_trivial cong_diff_2 cong_reflexivity l4_3_1)

lemma cong3_symmetry:
  assumes "A B C Cong3 A' B' C'"
  shows "A' B' C' Cong3 A B C"
  by (simp add: assms cong_3_sym)

lemma between_cong_2:
  assumes "Bet A D B" and
    "Bet A E B" and 
    "Cong A D A E"
  shows "D = E" 
  using l5_3 by (metis Cong_cases assms(1) assms(2) assms(3) between_cong)

lemma between_cong_3:
  assumes "A  B"
    and "Bet A B D"
    and "Bet A B E"
    and "Cong B D B E"
  shows "D = E"
  by (meson assms(1) assms(2) assms(3) assms(4) cong_reflexivity construction_uniqueness)

lemma le_anti_symmetry:
  assumes "A B Le C D" and
    "C D Le A B"
  shows "Cong A B C D" 
proof -
  obtain Y where "Bet C Y D" and "Cong A B C Y" 
    using Le_def assms(1) by blast
  obtain T where "Bet C D T" and "Cong C T A B" 
    using assms(2) l5_5_1 by blast
  have "Cong C Y C T" 
    by (metis cong_transitivity Cong A B C Y Cong C T A B cong_symmetry)
  have "Bet C Y T" 
    using Bet C D T Bet C Y D between_exchange4 by blast
  have "Y = T" 
    using Bet C Y T Cong C Y C T between_cong by auto
  moreover have "T = D" 
    using Bet C D T Bet C Y D between_equality_2 calculation by auto
  ultimately show ?thesis 
    using Cong A B C Y by auto
qed

lemma cong_dec:
  shows "Cong A B C D  ¬ Cong A B C D"
  by simp

lemma bet_dec:
  shows "Bet A B C   ¬ Bet A B C"
  by simp

lemma col_dec:
  shows "Col A B C  ¬ Col A B C"
  by simp

lemma le_trivial:
  shows "A A Le C D"
  using Le_def between_trivial2 cong_trivial_identity by blast

lemma le_cases:
  shows "A B Le C D  C D Le A B" 
  by (metis Cong_cases Le_def l5_5_2 le_trivial segment_construction_2)

lemma le_zero:
  assumes "A B Le C C"
  shows "A = B"
  by (metis assms cong_diff_4 le_anti_symmetry le_trivial)

lemma le_diff:
  assumes "A  B" and "A B Le C D"
  shows "C  D"
  using assms(1) assms(2) le_zero by blast

lemma lt_diff:
  assumes "A B Lt C D"
  shows "C  D"
  using Lt_def assms cong_trivial_identity le_zero by blast

lemma bet_cong_eq:
  assumes "Bet A B C" and
    "Bet A C D" and
    "Cong B C A D"
  shows "C = D  A = B"
proof -
  have "Bet C B A"
    using Bet_perm assms(1) by blast
  thus ?thesis
    by (metis Cong_perm Le_def assms(2) assms(3) between_cong cong_pseudo_reflexivity 
        le_anti_symmetry)
qed

lemma cong__le:
  assumes "Cong A B C D"
  shows "A B Le C D"
  using Le_def assms between_trivial by blast

lemma cong__le3412:
  assumes "Cong A B C D"
  shows "C D Le A B"
  using assms cong__le cong_symmetry by blast

lemma le1221:
  shows "A B Le B A"
  by (simp add: cong__le cong_pseudo_reflexivity)

lemma le_left_comm:
  assumes "A B Le C D"
  shows "B A Le C D"
  using assms le1221 le_transitivity by blast

lemma le_right_comm:
  assumes "A B Le C D"
  shows "A B Le D C"
  by (meson assms cong_right_commutativity l5_5_1 l5_5_2)

lemma le_comm:
  assumes "A B Le C D"
  shows "B A Le D C"
  using assms le_left_comm le_right_comm by blast

lemma ge_left_comm:
  assumes "A B Ge C D"
  shows "B A Ge C D"
  by (meson Ge_def assms le_right_comm)

lemma ge_right_comm:
  assumes "A B Ge C D"
  shows "A B Ge D C"
  using Ge_def assms le_left_comm by presburger

lemma ge_comm0:
  assumes "A B Ge C D"
  shows "B A Ge D C"
  by (meson assms ge_left_comm ge_right_comm)

lemma lt_right_comm:
  assumes "A B Lt C D"
  shows "A B Lt D C"
  using Lt_def assms le_right_comm not_cong_1243 by blast

lemma lt_left_comm:
  assumes "A B Lt C D"
  shows "B A Lt C D"
  using Lt_def assms le_comm lt_right_comm not_cong_2143 by blast

lemma lt_comm:
  assumes "A B Lt C D"
  shows "B A Lt D C"
  using assms lt_left_comm lt_right_comm by blast

lemma gt_left_comm0:
  assumes "A B Gt C D"
  shows "B A Gt C D"
  by (meson Gt_def assms lt_right_comm)

lemma gt_right_comm:
  assumes "A B Gt C D"
  shows "A B Gt D C"
  using Gt_def assms lt_left_comm by presburger

lemma gt_comm:
  assumes "A B Gt C D"
  shows "B A Gt D C"
  by (meson assms gt_left_comm0 gt_right_comm)

lemma cong2_lt__lt:
  assumes "A B Lt C D" and
    "Cong A B A' B'" and
    "Cong C D C' D'"
  shows "A' B' Lt C' D'"
  by (meson Lt_def assms(1) assms(2) assms(3) l5_6 le_anti_symmetry not_cong_3412)

lemma fourth_point:
  assumes "A  B" and
    "B  C" and
    "Col A B P" and
    "Bet A B C"
  shows "Bet P A B  Bet A P B  Bet B P C  Bet B C P"
  by (metis Col_def l5_2 assms(3) assms(4) between_symmetry)

lemma third_point:
  assumes "Col A B P"
  shows "Bet P A B  Bet A P B  Bet A B P"
  using Col_def assms between_symmetry by blast

lemma l5_12_a:
  assumes "Bet A B C"
  shows "A B Le A C  B C Le A C"
  using assms between_symmetry cong_left_commutativity cong_reflexivity l5_5_2 le_left_comm 
  by blast

lemma bet__le1213:
  assumes "Bet A B C"
  shows "A B Le A C"
  using assms l5_12_a by blast

lemma bet__le2313:
  assumes "Bet A B C"
  shows "B C Le A C"
  by (simp add: assms l5_12_a)

lemma bet__lt1213:
  assumes "B  C" and
    "Bet A B C"
  shows "A B Lt A C"
  using Lt_def assms(1) assms(2) bet__le1213 between_cong by blast

lemma bet__lt2313:
  assumes "A  B" and
    "Bet A B C"
  shows "B C Lt A C"
  using Lt_def assms(1) assms(2) bet__le2313 bet_cong_eq l5_1 by blast

lemma l5_12_b:
  assumes "Col A B C" and
    "A B Le A C" and
    "B C Le A C"
  shows "Bet A B C"
proof -
  {
    assume "Bet B C A"
    hence ?thesis 
      using assms(2) between_cong between_symmetry l5_12_a le_anti_symmetry by blast
  }
  moreover
  {
    assume "Bet C A B"
    hence ?thesis 
      by (metis assms(3) bet_cong_eq between_trivial2 l5_12_a le_anti_symmetry le_comm)
  }
  ultimately show ?thesis 
    using Col_def assms(1) by blast
qed

lemma bet_le_eq:
  assumes "Bet A B C"
    and "A C Le B C"
  shows "A = B"
  by (meson assms(1) assms(2) bet__le2313 bet_cong_eq l5_1 le_anti_symmetry)

lemma or_lt_cong_gt:
  "A B Lt C D  A B Gt C D  Cong A B C D"
  by (meson Gt_def Lt_def cong_symmetry local.le_cases)

lemma lt__le:
  assumes "A B Lt C D"
  shows "A B Le C D"
  using Lt_def assms by blast

lemma le1234_lt__lt:
  assumes "A B Le C D" and
    "C D Lt E F"
  shows "A B Lt E F"
  by (meson Lt_def assms(1) assms(2) cong__le3412 le_anti_symmetry le_transitivity)

lemma le3456_lt__lt:
  assumes "A B Lt C D" and
    "C D Le E F"
  shows "A B Lt E F"
  by (meson Lt_def assms(1) assms(2) cong2_lt__lt cong_reflexivity le1234_lt__lt)

lemma lt_transitivity:
  assumes "A B Lt C D" and
    "C D Lt E F"
  shows "A B Lt E F"
  using Lt_def assms(1) assms(2) le1234_lt__lt by blast

lemma not_and_lt:
  "¬ (A B Lt C D  C D Lt A B)"
  by (simp add: Lt_def le_anti_symmetry)

lemma nlt:
  "¬ A B Lt A B"
  using not_and_lt by blast

lemma le__nlt:
  assumes "A B Le C D"
  shows "¬ C D Lt A B"
  using assms le3456_lt__lt nlt by blast

lemma cong__nlt:
  assumes "Cong A B C D"
  shows "¬ A B Lt C D"
  by (simp add: Lt_def assms)

lemma nlt__le:
  assumes "¬ A B Lt C D"
  shows "C D Le A B"
  using Lt_def assms cong__le3412 local.le_cases by blast

lemma lt__nle:
  assumes "A B Lt C D"
  shows "¬ C D Le A B"
  using assms le__nlt by blast

lemma nle__lt:
  assumes "¬ A B Le C D"
  shows "C D Lt A B"
  using assms nlt__le by blast

lemma lt1123:
  assumes "B  C"
  shows "A A Lt B C"
  using assms le_diff nle__lt by blast

lemma bet2_le2__le_R1:
  assumes "Bet a P b" and
    "Bet A Q B" and
    "P a Le Q A" and
    "P b Le Q B" and
    "B = Q"
  shows "a b Le A B"
  by (metis assms(3) assms(4) assms(5) le_comm le_diff)

lemma bet2_le2__le_R2:
  assumes "Bet a Po b" and
    "Bet A PO B" and
    "Po a Le PO A" and
    "Po b Le PO B" and
    "A  PO" and
    "B  PO"
  shows "a b Le A B"
proof -
  obtain b' where "Bet A PO b'" and "Cong PO b' b Po"
    using segment_construction by blast
  obtain a' where "Bet B PO a'" and "Cong PO a' a Po"
    using segment_construction by blast
  obtain a'' where "Bet PO a'' A" and "Cong Po a PO a''"
    using Le_def assms(3) by blast
  have "Cong PO a'' a Po" 
    using Cong_cases Cong Po a PO a'' by blast
  hence "a' = a''" 
    by (meson Bet_perm Bet B PO a' Bet PO a'' A Cong PO a' a Po assms(2) assms(6) 
        between_inner_transitivity construction_uniqueness)
  have "B a' Le B A" 
    by (metis Bet B PO a' Bet PO a'' A a' = a'' assms(2) bet__le1213 bet_le_eq le_comm 
        le_cases outer_transitivity_between2)
  obtain b'' where "Bet PO b'' B" and "Cong Po b PO b''"
    using Le_def assms(4) by blast
  hence "b' = b''"
    using assms(2) assms(5) between_inner_transitivity cong_right_commutativity 
      construction_uniqueness not_cong_3412 by (meson Bet A PO b' Cong PO b' b Po)
  hence "a' b' Le a' B"
    using Bet_cases bet__le1213 between_exchange2 Bet B PO a' Bet PO b'' B by blast
  hence "a' b' Le A B"
    using le_comm le_transitivity by (meson B a' Le B A)
  have "Cong a' b' a b" 
  proof -
    have "Bet a' PO b'" 
      using Bet_cases Bet A PO b' Bet PO a'' A a' = a'' between_exchange3 by blast
    moreover have "Cong a' PO a Po" 
      using Cong_cases Cong PO a' a Po by auto
    moreover have "Cong PO b' Po b" 
      using Cong PO b' b Po not_cong_1243 by blast
    ultimately show ?thesis 
      using assms(1) l2_11_b by blast
  qed
  thus ?thesis
    using a' b' Le A B cong_reflexivity l5_6 by blast
qed

lemma bet2_le2__le:
  assumes "Bet a P b" and
    "Bet A Q B" and
    "P a Le Q A" and
    "P b Le Q B"
  shows "a b Le A B"
proof cases
  assume "A = Q"
  thus ?thesis
    using assms(3) assms(4) le_diff by force
next
  assume "¬ A = Q"
  thus ?thesis
    using assms(1) assms(2) assms(3) assms(4) bet2_le2__le_R1 bet2_le2__le_R2 by blast
qed

lemma Le_cases:
  assumes "A B Le C D  B A Le C D  A B Le D C  B A Le D C"
  shows "A B Le C D"
  using assms le_left_comm le_right_comm by blast

lemma Lt_cases:
  assumes "A B Lt C D  B A Lt C D  A B Lt D C  B A Lt D C"
  shows "A B Lt C D"
  using assms lt_comm lt_left_comm by blast

lemma bet_out:
  assumes "B  A" and
    "Bet A B C"
  shows  "A Out B C"
  using Out_def assms(1) assms(2) bet_neq12__neq by fastforce

lemma bet_out_1:
  assumes "B  A" and
    "Bet C B A"
  shows "A Out B C"
  by (simp add: assms(1) assms(2) bet_out between_symmetry)

lemma out_dec:
  shows "P Out A B  ¬ P Out A B"
  by simp

lemma out_diff1:
  assumes "A Out B C"
  shows "B  A"
  using Out_def assms by auto

lemma out_diff2:
  assumes "A Out B C"
  shows "C  A"
  using Out_def assms by auto

lemma out_distinct:
  assumes "A Out B C"
  shows  "B  A  C  A"
  using assms out_diff1 out_diff2 by auto

lemma out_col:
  assumes "A Out B C"
  shows "Col A B C"
  using Col_def Out_def assms between_symmetry by auto

lemma l6_2:
  assumes "A  P" and
    "B  P" and
    "C  P" and
    "Bet A P C"
  shows "Bet B P C  P Out A B"
proof -
  {
    assume "Bet B P C"
    hence "P Out A B" 
      using Out_def assms(1) assms(2) assms(3) assms(4) between_symmetry l5_2 by presburger
  }
  moreover
  {
    assume "P Out A B" 
    hence "Bet B P C" 
      by (metis Bet_perm Out_def between_exchange3 outer_transitivity_between2 assms(4))
  }
  ultimately show ?thesis 
    by auto
qed

lemma bet_out__bet:
  assumes "Bet A P C" and
    "P Out A B"
  shows "Bet B P C"
  by (metis l6_2 assms(1) assms(2) not_bet_distincts out_diff1)

lemma l6_3_1:
  assumes "P Out A B"
  shows "A  P  B  P  ( C. (C  P  Bet A P C  Bet B P C))"
  using assms bet_out__bet out_diff1 out_diff2 point_construction_different by fastforce

lemma l6_3_2:
  assumes "A  P" and
    "B  P" and
    " C. (C  P  Bet A P C  Bet B P C)"
  shows "P Out A B"
  using assms(1) assms(2) assms(3) l6_2 by blast

lemma l6_4_1:
  assumes "P Out A B" and
    "Col A P B"
  shows "¬ Bet A P B"
  using Out_def assms(1) between_equality between_symmetry by fastforce

lemma l6_4_2:
  assumes "Col A P B"
    and "¬ Bet A P B"
  shows "P Out A B"
  by (metis Out_def assms(1) assms(2) bet_out col_permutation_1 third_point)

lemma out_trivial:
  assumes "A  P"
  shows "P Out A A"
  by (simp add: assms bet_out_1 between_trivial2)

lemma l6_6:
  assumes "P Out A B"
  shows "P Out B A"
  using Out_def assms by auto

lemma l6_7:
  assumes "P Out A B" and
    "P Out B C"
  shows "P Out A C" 
  by (metis assms(1) assms(2) l6_2 l6_6 out_diff2 point_construction_different)

lemma bet_out_out_bet:
  assumes "Bet A B C" and
    "B Out A A'" and
    "B Out C C'"
  shows "Bet A' B C'"
  by (metis Out_def assms(1) assms(2) assms(3) bet_out__bet between_inner_transitivity 
      outer_transitivity_between)

lemma out2_bet_out:
  assumes "B Out A C" and
    "B Out X P" and
    "Bet A X C"
  shows "B Out A P  B Out C P"
proof -
  have "Bet B A C  Bet B C A" 
    using Out_def assms(1) by auto
  {
    assume "Bet B A C"
    have "B Out A P  B Out C P" 
      by (metis Out_def between_inner_transitivity l6_7 Bet B A C assms(1) assms(2) assms(3))
  }
  moreover
  {
    assume "Bet B C A" 
    hence "B Out A P" 
      by (metis Bet_perm bet3__bet bet_out_1 l5_1 l6_6 l6_7 out_distinct assms(2) assms(3))
  }
  moreover
  {
    assume "Bet B C A" 
    hence "B Out C P" 
      using Bet B C A assms(1) calculation(2) l6_6 l6_7 by blast
  }
  ultimately show ?thesis 
    using Bet B A C  Bet B C A by blast
qed

lemma l6_11_uniqueness:
  assumes "A Out X R" and
    "Cong A X B C" and
    "A Out Y R" and
    "Cong A Y B C"
  shows "X = Y"
  by (metis Out_def assms(1) assms(2) assms(3) assms(4) between_cong cong_symmetry 
      cong_transitivity l6_6 l6_7)

lemma l6_11_existence:
  assumes "R  A" and
    "B  C"
  shows " X. (A Out X R  Cong A X B C)"
  by (metis Out_def assms(1) assms(2) cong_reverse_identity segment_construction_2)


lemma segment_construction_3:
  assumes "A  B" and
    "X  Y"
  shows " C. (A Out B C  Cong A C X Y)"
  by (metis assms(1) assms(2) l6_11_existence l6_6)

lemma l6_13_1:
  assumes "P Out A B" and
    "P A Le P B"
  shows "Bet P A B"
  by (metis Out_def assms(1) assms(2) bet__lt1213 le__nlt)

lemma l6_13_2:
  assumes "P Out A B" and
    "Bet P A B"
  shows "P A Le P B"
  by (simp add: assms(2) bet__le1213)

lemma l6_16_1:
  assumes "P  Q" and
    "Col S P Q" and
    "Col X P Q"
  shows "Col X P S"
proof cases
  assume "S = P"
  thus ?thesis 
    using col_trivial_2 by blast
next
  assume "S  P" 
  {
    assume "Bet S P Q" and "Bet X P Q"  
    hence "Col X P S" 
      by (metis Col_cases assms(1) col_trivial_1 l6_2 out_col)
  }
  moreover
  {
    assume "Bet P Q S" and "Bet X P Q"  
    hence "Col X P S" 
      using assms(1) bet_col outer_transitivity_between by blast
  }
  moreover
  {
    assume "Bet Q S P" and "Bet X P Q"  
    hence "Col X P S" 
      using bet_col between_inner_transitivity between_symmetry by blast
  }
  moreover
  {
    assume "Bet P Q S" and "Bet P Q X"  
    hence "Col X P S" 
      by (meson Col_def assms(1) l5_1 not_col_permutation_5)
  }
  moreover
  {
    assume "Bet Q S P" and "Bet P Q X"  
    hence "Col X P S" 
      using Col_def between_exchange4 between_symmetry by blast
  }
  moreover
  {
    assume "Bet S P Q" and "Bet P Q X"  
    hence "Col X P S" 
      using Bet_cases assms(1) bet_col outer_transitivity_between by blast
  }
  moreover
  {
    assume "Bet P Q S" and "Bet Q X P"  
    hence "Col X P S" 
      using Bet_cases Col_def between_exchange2 by blast
  }
  moreover
  {
    assume "Bet Q S P" and "Bet Q X P"  
    hence "Col X P S"
      by (meson Col_def between_exchange3 l5_3 not_col_permutation_3)
  }
  moreover
  {
    assume "Bet S P Q" and "Bet Q X P"  
    hence "Col X P S" 
      using bet_col between_exchange3 between_symmetry by blast
  }
  ultimately show ?thesis 
    by (metis Col_def assms(2) assms(3))
qed

lemma col_transitivity_1:
  assumes "P  Q" and
    "Col P Q A" and
    "Col P Q B"
  shows "Col P A B"
  by (meson l6_16_1 assms(1) assms(2) assms(3) not_col_permutation_2)

lemma col_transitivity_2:
  assumes "P  Q" and
    "Col P Q A" and
    "Col P Q B"
  shows "Col Q A B"
  by (metis col_transitivity_1 assms(1) assms(2) assms(3) not_col_permutation_4)

lemma l6_21:
  assumes "¬ Col A B C" and
    "C  D" and
    "Col A B P" and
    "Col A B Q" and
    "Col C D P" and
    "Col C D Q"
  shows "P = Q"
  by (metis assms(1) assms(2) assms(3) assms(4) assms(5) assms(6) col_transitivity_1 l6_16_1 
      not_col_distincts)

lemma col2__eq:
  assumes "Col A X Y" and
    "Col B X Y" and
    "¬ Col A X B"
  shows  "X = Y"
  using assms(1) assms(2) assms(3) l6_16_1 by blast

lemma not_col_exists:
  assumes  "A  B"
  shows " C. ¬ Col A B C"
  by (metis Col_def assms col_transitivity_2 lower_dim_ex)

lemma col3:
  assumes "X  Y" and
    "Col X Y A" and
    "Col X Y B" and
    "Col X Y C"
  shows "Col A B C"
  by (metis assms(1) assms(2) assms(3) assms(4) col_transitivity_2)

lemma colx:
  assumes "A  B" and
    "Col X Y A" and
    "Col X Y B" and
    "Col A B C"
  shows "Col X Y C"
  by (metis assms(1) assms(2) assms(3) assms(4) l6_21 not_col_distincts)

lemma out2__bet:
  assumes "A Out B C" and
    "C Out A B"
  shows "Bet A B C"
  by (metis Out_def assms(1) assms(2) between_equality between_symmetry)

lemma bet2_le2__le1346:
  assumes "Bet A B C" and
    "Bet A' B' C'" and
    "A B Le A' B'" and
    "B C Le B' C'"
  shows "A C Le A' C'"
  using Le_cases assms(1) assms(2) assms(3) assms(4) bet2_le2__le by blast

lemma bet2_le2__le2356_R1:
  assumes "Bet A A C" and
    "Bet A' B' C'" and
    "A A Le A' B'" and
    "A' C' Le A C"
  shows "B' C' Le A C"
  using assms(2) assms(4) bet__le2313 le3456_lt__lt lt__nle nlt__le by blast

lemma bet2_le2__le2356_R2:
  assumes "A  B" and
    "Bet A B C" and
    "Bet A' B' C'" and
    "A B Le A' B'" and
    "A' C' Le A C"
  shows "B' C' Le B C"
proof -
  obtain B0 where "Bet A B B0" and "Cong A B0 A' B'"
    using assms(4) l5_5_1 by blast
  hence "A  B0"
    using assms(1) bet_neq12__neq by blast
  obtain C0 where "Bet A C0 C" and "Cong A' C' A C0"
    using Le_def assms(5) by blast
  hence "A  C0"
    using assms(1) assms(3) assms(4) bet_neq12__neq cong_diff le_diff by blast
  hence "Bet A B0 C0" 
    by (metis Bet_cases Cong_cases A  B0 Bet A B B0 Bet A C0 C Cong A B0 A' B' 
        Cong A' C' A C0 assms(1) assms(2) assms(3) bet__le1213 between_inner_transitivity 
        cong__nlt l6_13_1 l6_2 le_transitivity nlt__le outer_transitivity_between 
        point_construction_different)
  have "B0 C0 Le B C0" 
    using Bet A B B0 Bet A B0 C0 bet__le2313 between_exchange3 by blast
  moreover have "B C0 Le B C" 
    by (meson Bet A B B0 Bet A B0 C0 Bet A C0 C bet__le1213 between_exchange3 
        between_exchange4)
  moreover have "Cong B0 C0 B' C'" 
    using Bet A B0 C0 Cong A B0 A' B' Cong A' C' A C0 assms(3) l4_3_1 not_cong_3412 by blast
  ultimately show ?thesis 
    using cong__le3412 le_transitivity by blast
qed

lemma bet2_le2__le2356:
  assumes "Bet A B C" and
    "Bet A' B' C'" and
    "A B Le A' B'" and
    "A' C' Le A C"
  shows "B' C' Le B C"
proof (cases)
  assume "A = B"
  thus ?thesis
    using assms(1) assms(2) assms(3) assms(4) bet2_le2__le2356_R1 by blast
next
  assume "¬ A = B"
  thus ?thesis
    using assms(1) assms(2) assms(3) assms(4) bet2_le2__le2356_R2 by blast
qed

lemma bet2_le2__le1245:
  assumes "Bet A B C" and
    "Bet A' B' C'" and
    "B C Le B' C'" and
    "A' C' Le A C"
  shows "A' B' Le A B"
  using assms(1) assms(2) assms(3) assms(4) bet2_le2__le2356 between_symmetry le_comm by blast

lemma cong_preserves_bet:
  assumes "Bet B A' A0" and
    "Cong B A' E D'" and
    "Cong B A0 E D0" and
    "E Out D' D0"
  shows "Bet E D' D0"
  using l6_13_1 Tarski_neutral_dimensionless_axioms assms(1) assms(2) assms(3) assms(4)
    bet__le1213 l5_6 by fastforce

lemma out_cong_cong:
  assumes "B Out A A0" and
    "E Out D D0" and
    "Cong B A E D" and
    "Cong B A0 E D0"
  shows "Cong A A0 D D0"
  by (meson Out_def assms(1) assms(2) assms(3) assms(4) cong_4321 cong_symmetry l4_3_1 l5_6 
      l6_13_1 l6_13_2)

lemma not_out_bet:
  assumes "Col A B C" and
    "¬ B Out A C"
  shows "Bet A B C"
  using assms(1) assms(2) l6_4_2 by blast

lemma or_bet_out:
  shows "Bet A B C  B Out A C  ¬ Col A B C"
  using not_out_bet by blast

lemma not_bet_out:
  assumes "Col A B C" and
    "¬ Bet A B C"
  shows "B Out A C"
  by (simp add: assms(1) assms(2) l6_4_2)

lemma not_bet_and_out:
  shows  "¬ (Bet A B C  B Out A C)"
  using bet_col l6_4_1 by blast

lemma out_to_bet:
  assumes "Col A' B' C'" and
    "B Out A C  B' Out A' C'" and
    "Bet A B C"
  shows "Bet A' B' C'"
  using assms(1) assms(2) assms(3) not_bet_and_out or_bet_out by blast

lemma col_out2_col:
  assumes "Col A B C" and
    "B Out A AA" and
    "B Out C CC"
  shows "Col AA B CC" 
  by (metis Col_cases assms(1) assms(2) assms(3) col_transitivity_1 out_col out_diff1)

lemma bet2_out_out:
  assumes "B  A" and
    "B'  A" and
    "A Out C C'" and
    "Bet A B C" and
    "Bet A B' C'"
  shows "A Out B B'"
  by (meson assms(1) assms(2) assms(3) assms(4) assms(5) bet_out l6_6 l6_7)

lemma bet2__out:
  assumes "A  B" and
    "A  B'" and
    "Bet A B C"
    and "Bet A B' C"
  shows "A Out B B'"
  using Out_def assms(1) assms(2) assms(3) assms(4) l5_3 by auto

lemma out_bet_out_1:
  assumes "P Out A C" and
    "Bet A B C"
  shows "P Out A B"
  by (metis assms(1) assms(2) not_bet_and_out out2_bet_out out_trivial)

lemma out_bet_out_2:
  assumes "P Out A C" and
    "Bet A B C"
  shows "P Out B C"
  using assms(1) assms(2) l6_6 l6_7 out_bet_out_1 by blast

lemma out_bet__out:
  assumes "Bet P Q A" and
    "Q Out A B"
  shows "P Out A B"
  by (smt (verit, best) Out_def assms(1,2) bet3__bet l5_1 not_bet_and_out
      outer_transitivity_between2) 

lemma segment_reverse:
  assumes "Bet A B C "
  shows " B'. Bet A B' C  Cong C B' A B"
  by (metis Bet_perm Cong_perm assms bet_cong_eq cong_reflexivity segment_construction_2)

lemma diff_col_ex:
  shows " C. A  C  B  C  Col A B C"
  by (metis bet_col bet_neq12__neq point_construction_different)

lemma diff_bet_ex3:
  assumes "Bet A B C"
  shows " D. A  D  B  D  C  D  Col A B D"
  by (metis Col_def bet_out_1 between_trivial2 col_transitivity_1 l6_4_1 
      point_construction_different)

lemma diff_col_ex3:
  assumes "Col A B C"
  shows " D. A  D  B  D  C  D  Col A B D"
  by (metis Bet_perm Col_def between_equality between_trivial2 point_construction_different)

lemma Out_cases:
  assumes "A Out B C  A Out C B"
  shows "A Out B C"
  using assms l6_6 by blast

(** Existence of the sum *)

lemma ex_sums: 
  shows " E F. A B C D SumS E F" 
proof -
  obtain R where "Bet A B R" and "Cong B R C D" 
    using segment_construction by blast
  thus ?thesis 
    using SumS_def cong_reflexivity by blast
qed

(** Commutativity of the sum. *)

lemma sums_sym:
  assumes "A B C D SumS E F" 
  shows "C D A B SumS E F" 
proof -
  obtain P Q R where "Bet P Q R" and "Cong P Q A B" and "Cong Q R C D" and "Cong P R E F" 
    using SumS_def assms by auto
  thus ?thesis 
    by (meson Cong_cases SumS_def between_symmetry)
qed

(** Unicity of the sum. *)

lemma sums2__cong56:
  assumes "A B C D SumS E F" and
    "A B C D SumS E' F'"
  shows "Cong E F E' F'" 
proof -
  obtain P Q R where "Bet P Q R" and "Cong P Q A B" and "Cong Q R C D" and "Cong P R E F"
    using SumS_def assms(1) by blast
  obtain P' Q' R' where "Bet P' Q' R'" and "Cong P' Q' A B" and "Cong Q' R' C D" and "Cong P' R' E' F'"
    using SumS_def assms(2) by blast
  have "Cong P Q P' Q'" 
    using Cong_cases Cong P Q A B Cong P' Q' A B cong_transitivity by blast
  have "Cong Q R Q' R'" 
    using Cong_cases Cong Q R C D Cong Q' R' C D cong_transitivity by blast
  hence "Cong P R P' R'" 
    using Bet P Q R Bet P' Q' R' Cong P Q P' Q' l2_11_b by blast
  hence "Cong P R E' F'" 
    using Cong P' R' E' F' cong_transitivity by blast
  thus ?thesis 
    using Cong P R E F cong_inner_transitivity by blast
qed
  (** Unicity of the difference of segments. *)

lemma sums2__cong12: 
  assumes "A B C D SumS E F" 
    and "A' B' C D SumS E F" 
  shows "Cong A B A' B'" 
proof -
  obtain P Q R where "Bet P Q R" and "Cong P Q A B" and "Cong Q R C D" and "Cong P R E F"
    using SumS_def assms(1) by blast
  obtain P' Q' R' where "Bet P' Q' R'" and "Cong P' Q' A' B'" and "Cong Q' R' C D" and "Cong P' R' E F"
    using SumS_def assms(2) by blast
  have "Cong P R P' R'" 
    using Cong_cases Cong P R E F Cong P' R' E F cong_transitivity by blast
  moreover have "Cong Q R Q' R'" 
    using Cong Q R C D Cong Q' R' C D cong_inner_transitivity cong_symmetry by blast
  ultimately have "Cong P Q P' Q'" 
    using Bet P Q R Bet P' Q' R' l4_3 by blast
  hence "Cong P Q A' B'" 
    using Cong P' Q' A' B' cong_transitivity by blast
  thus ?thesis 
    using Cong P Q A B cong_inner_transitivity by blast
qed
  (** Unicity of the difference of segments on the right. *)

lemma sums2__cong34: 
  assumes "A B C D SumS E F" and
    "A B C' D' SumS E F"
  shows "Cong C D C' D'" 
  using assms(1) assms(2) sums2__cong12 sums_sym by blast

(** Cong preserves SumS *)

lemma cong3_sums__sums:
  assumes "Cong A B A' B'" and
    "Cong C D C' D'" and 
    "Cong E F E' F'" and 
    "A B C D SumS E F" 
  shows "A' B' C' D' SumS E' F'" 
  by (meson SumS_def assms(1) assms(2) assms(3) assms(4) cong_inner_transitivity cong_symmetry)

(** The degenerate segments represent the additive identity *)

lemma sums123312:
  shows "A B C C SumS A B" 
  using SumS_def between_trivial cong_reflexivity cong_trivial_identity by blast

lemma sums__cong1245: 
  assumes "A B C C SumS D E"
  shows "Cong A B D E" 
  using assms sums123312 sums2__cong56 by blast

lemma sums__eq34: 
  assumes "A B C D SumS A B"
  shows "C = D" 
  using assms cong_reverse_identity sums123312 sums2__cong34 by blast

lemma sums112323: 
  shows "A A B C SumS B C" 
  by (simp add: sums123312 sums_sym)

lemma sums__cong2345: 
  assumes "A A B C SumS D E"
  shows "Cong B C D E" 
  using assms sums112323 sums2__cong56 by blast

lemma sums__eq12: 
  assumes "A B C D SumS C D" 
  shows "A = B" 
  using assms sums__eq34 sums_sym by blast

(** Some permutation properties *)

lemma sums_left_comm:
  assumes "A B C D SumS E F"
  shows "B A C D SumS E F" 
  using assms cong3_sums__sums cong_pseudo_reflexivity cong_reflexivity by blast

lemma sums_middle_comm: 
  assumes "A B C D SumS E F"
  shows "A B D C SumS E F" 
  using assms sums_left_comm sums_sym by blast

lemma sums_right_comm: 
  assumes "A B C D SumS E F" 
  shows "A B C D SumS F E" 
  using assms cong3_sums__sums cong_pseudo_reflexivity cong_reflexivity by blast

lemma sums_comm: 
  assumes "A B C D SumS E F"
  shows "B A D C SumS F E" 
  using assms cong3_sums__sums cong_pseudo_reflexivity by blast

(** Basic case of sum *)

lemma bet__sums: 
  assumes "Bet A B C" 
  shows "A B B C SumS A C"
  using SumS_def assms cong_reflexivity by blast

lemma sums_assoc_1:
  assumes "A B C D SumS G H" and
    "C D E F SumS I J" and
    "G H E F SumS K L" 
  shows "A B I J SumS K L" 
proof -
  obtain P Q R where "Bet P Q R" and "Cong P Q A B" and 
    "Cong Q R C D" and "Cong P R G H"
    using assms(1) SumS_def by fastforce
  obtain S where "Bet P R S" and "Cong R S E F" 
    using segment_construction by blast
  hence "Bet P Q S" 
    using Bet P Q R between_exchange4 by blast
  moreover have "Cong Q S I J" 
    using SumS_def Bet P Q R Bet P R S Cong Q R C D Cong R S E F assms(2) between_exchange3 cong_reflexivity sums2__cong56 by blast
  moreover have "Cong P S K L" 
    using SumS_def Bet P R S Cong P R G H Cong R S E F assms(3) cong_reflexivity sums2__cong56 by blast
  ultimately show ?thesis 
    using SumS_def Cong P Q A B by blast
qed

lemma sums_assoc_2:
  assumes "A B C D SumS G H" and
    "C D E F SumS I J" and
    "A B I J SumS K L"
  shows "G H E F SumS K L"
proof -
  have "E F G H SumS K L"
  proof -
    have "E F C D SumS I J" 
      by (simp add: assms(2) sums_sym)
    moreover have "C D A B SumS G H" 
      by (simp add: assms(1) sums_sym)
    moreover have "I J A B SumS K L" 
      using assms(3) sums_sym by blast
    ultimately show ?thesis
      using sums_assoc_1 by blast
  qed
  thus ?thesis     
    using sums_sym by blast
qed

(** Associativity of the sum. *)

lemma sums_assoc:
  assumes "A B C D SumS G H" and
    "C D E F SumS I J"
  shows "G H E F SumS K L  A B I J SumS K L" 
  by (meson assms(1) assms(2) sums_assoc_1 sums_assoc_2)

(** AB <= AB + CD *)

lemma sums__le1256: 
  assumes "A B C D SumS E F"
  shows "A B Le E F" 
proof -
  obtain P Q R where "Bet P Q R" and "Cong P Q A B" and 
    "Cong Q R C D" and "Cong P R E F" 
    using SumS_def assms by blast
  thus ?thesis 
    using bet__le1213 l5_6 by blast
qed

(** CD <= AB + CD *)

lemma sums__le3456: 
  assumes "A B C D SumS E F" 
  shows "C D Le E F" 
  using assms sums__le1256 sums_sym by blast

(** If the sum of two segments is degenerate, then the segments are degenerate *)

lemma eq_sums__eq: 
  assumes "A B C D SumS E E"
  shows "A = B  C = D" 
  by (metis assms cong_identity le_diff sums__cong1245 sums__le3456)

lemma sums_diff_1: 
  assumes "A  B" and
    "A B C D SumS E F"
  shows "E  F" 
  using assms(1) assms(2) eq_sums__eq by force

lemma sums_diff_2: 
  assumes "C  D" and
    "A B C D SumS E F" 
  shows "E  F" 
  using assms(1) assms(2) eq_sums__eq by blast

(** SumS preserves Le *)

lemma le2_sums2__le:
  assumes "A B Le A' B'" and
    "C D Le C' D'" and
    "A B C D SumS E F" and
    "A' B' C' D' SumS E' F'" 
  shows "E F Le E' F'"
proof -
  obtain P Q R where "Bet P Q R" and "Cong P Q A B" and 
    "Cong Q R C D" and "Cong P R E F" 
    using SumS_def assms(3) by blast
  obtain P' Q' R' where "Bet P' Q' R'" and "Cong P' Q' A' B'" and 
    "Cong Q' R' C' D'" and "Cong P' R' E' F'" 
    using SumS_def assms(4) by blast
  have "P Q Le P' Q'" 
    by (meson Cong P Q A B Cong P' Q' A' B' assms(1) cong_symmetry l5_6)
  moreover have "Q R Le Q' R'" 
    by (meson Cong_perm Cong Q R C D Cong Q' R' C' D' assms(2) l5_6)
  ultimately have "P R Le P' R'" 
    using Bet P Q R Bet P' Q' R' bet2_le2__le1346 by blast
  thus ?thesis 
    using Cong P R E F Cong P' R' E' F' l5_6 by blast
qed

(** If AB <= A'B', CD <= C'D' and AB + CD = A'B' + C'D', then AB = A'B' and CD = C'D' *)

lemma le2_sums2__cong12:
  assumes "A B Le A' B'" and
    "C D Le C' D'" and
    "A B C D SumS E F" and
    "A' B' C' D' SumS E F" 
  shows "Cong A B A' B'" 
proof -
  obtain E' F' where "A' B' C D SumS E' F'" 
    using ex_sums by blast
  hence "Cong E' F' E F" 
    by (meson assms(1) assms(2) assms(3) assms(4) le2_sums2__le le_anti_symmetry le_reflexivity)
  hence "A' B' C D SumS E F" 
    using A' B' C D SumS E' F' cong3_sums__sums cong_reflexivity by blast
  thus ?thesis
    using assms(3) sums2__cong12 by blast
qed

lemma le2_sums2__cong34:
  assumes "A B Le A' B'" and
    "C D Le C' D'" and
    "A B C D SumS E F" and
    "A' B' C' D' SumS E F" 
  shows "Cong C D C' D'" 
  by (meson assms(1) assms(2) assms(3) assms(4) cong3_sums__sums cong_reflexivity 
      le2_sums2__cong12 sums2__cong34)

(** If AB < A'B' and CD <= C'D', then AB + CD < A'B' + C'D' *)

lemma le_lt12_sums2__lt:
  assumes "A B Lt A' B'" and 
    "C D Le C' D'" and
    "A B C D SumS E F" and
    "A' B' C' D' SumS E' F'" 
  shows "E F Lt E' F'" 
proof -
  have "E F Le E' F'" 
    using Lt_def assms(1) assms(2) assms(3) assms(4) le2_sums2__le by blast
  moreover {
    assume "Cong E F E' F'" 
    hence "A' B' C' D' SumS E F" 
      by (meson assms(4) cong3_sums__sums cong_reflexivity not_cong_3412)
    hence "Cong A B A' B'" 
      using assms(1) assms(2) assms(3) le2_sums2__cong12 lt__le by blast
    hence False 
      using assms(1) cong__nlt lt__le by blast 
  }
  ultimately show ?thesis 
    using Lt_def by blast
qed

lemma le_lt34_sums2__lt:
  assumes "A B Le A' B'" and 
    "C D Lt C' D'" and
    "A B C D SumS E F" and
    "A' B' C' D' SumS E' F'" 
  shows "E F Lt E' F'" 
  using assms(1) assms(2) assms(3) assms(4) le_lt12_sums2__lt sums_sym by blast

lemma lt2_sums2__lt:
  assumes "A B Lt A' B'" and
    "C D Lt C' D'" and
    "A B C D SumS E F" and
    "A' B' C' D' SumS E' F'" 
  shows "E F Lt E' F'" 
  using assms(1) assms(2) assms(3) assms(4) le_lt12_sums2__lt lt__le by blast

(** If CD >= C'D' and AB + CD <= A'B' + C'D', then AB <= A'B' *)

lemma le2_sums2__le12:
  assumes "C' D' Le C D" and
    "E F Le E' F'" and 
    "A B C D SumS E F" and
    "A' B' C' D' SumS E' F'" 
  shows "A B Le A' B'" 
  using assms(1) assms(2) assms(3) assms(4) le_lt12_sums2__lt lt__nle nlt__le by blast

lemma le2_sums2__le34:
  assumes "A' B' Le A B" and
    "E F Le E' F'" and
    "A B C D SumS E F" and 
    "A' B' C' D' SumS E' F'" 
  shows "C D Le C' D'" 
  by (meson assms(1) assms(2) assms(3) assms(4) le_lt12_sums2__lt lt__nle nlt__le sums_sym)

(** If CD > C'D' and AB + CD <= A'B' + C'D', then AB < A'B' *)

lemma le_lt34_sums2__lt12:
  assumes "C' D' Lt C D" and
    "E F Le E' F'" and
    "A B C D SumS E F" and
    "A' B' C' D' SumS E' F'" 
  shows "A B Lt A' B'" 
  by (meson assms(1) assms(2) assms(3) assms(4) le3456_lt__lt le_lt34_sums2__lt nle__lt nlt)

lemma le_lt12_sums2__lt34:
  assumes "A' B' Lt A B" and
    "E F Le E' F'" and
    "A B C D SumS E F" and
    "A' B' C' D' SumS E' F'" 
  shows "C D Lt C' D'" 
  using assms(1) assms(2) assms(3) assms(4) le_lt12_sums2__lt lt__nle nlt__le by blast

(** If CD >= C'D' and AB + CD < A'B' + C'D', then AB < A'B' *)

lemma le_lt56_sums2__lt12:
  assumes "C' D' Le C D" and
    "E F Lt E' F'" and
    "A B C D SumS E F" and
    "A' B' C' D' SumS E' F'" 
  shows "A B Lt A' B'" 
  by (meson assms(1) assms(2) assms(3) assms(4) le2_sums2__le le__nlt nle__lt)

lemma le_lt56_sums2__lt34:
  assumes "A' B' Le A B" and
    "E F Lt E' F'" and
    "A B C D SumS E F" and
    "A' B' C' D' SumS E' F'" 
  shows "C D Lt C' D'" 
  using assms(1) assms(2) assms(3) assms(4) le2_sums2__le lt__nle nlt__le by blast

lemma lt2_sums2__lt12:
  assumes "C' D' Lt C D" and
    "E F Lt E' F'" and 
    "A B C D SumS E F" and
    "A' B' C' D' SumS E' F'" 
  shows "A B Lt A' B'" 
  using assms(1) assms(2) assms(3) assms(4) le_lt34_sums2__lt nle__lt not_and_lt by blast

lemma lt2_sums2__lt34: 
  assumes "A' B' Lt A B" and
    "E F Lt E' F'" and
    "A B C D SumS E F" and
    "A' B' C' D' SumS E' F'" 
  shows "C D Lt C' D'" 
  by (meson assms(1) assms(2) assms(3) assms(4) le_lt12_sums2__lt nlt__le not_and_lt)

lemma midpoint_dec:
  "I Midpoint A B  ¬ I Midpoint A B"
  by simp

lemma is_midpoint_id:
  assumes "A Midpoint A B"
  shows "A = B"
  using Midpoint_def assms between_cong by blast

lemma is_midpoint_id_2:
  assumes "A Midpoint B A"
  shows "A = B"
  using Midpoint_def assms cong_diff_2 by blast

lemma l7_2:
  assumes "M Midpoint A B"
  shows "M Midpoint B A"
  using Bet_perm Cong_perm Midpoint_def assms by blast

lemma l7_3:
  assumes "M Midpoint A A"
  shows "M = A"
  using Midpoint_def assms bet_neq23__neq by blast

lemma l7_3_2:
  "A Midpoint A A"
  by (simp add: Midpoint_def between_trivial2 cong_reflexivity)

lemma symmetric_point_construction:
  " P'. A Midpoint P P'"
  by (meson Midpoint_def cong__le cong__le3412 le_anti_symmetry segment_construction)

lemma symmetric_point_uniqueness:
  assumes "P Midpoint A P1" and
    "P Midpoint A P2"
  shows "P1 = P2"
  by (metis Midpoint_def assms(1) assms(2) between_cong_3 cong_diff_4 cong_inner_transitivity)

lemma l7_9:
  assumes "A Midpoint P X" and
    "A Midpoint Q X"
  shows "P = Q"
  using assms(1) assms(2) l7_2 symmetric_point_uniqueness by blast

lemma l7_9_bis:
  assumes "A Midpoint P X" and
    "A Midpoint X Q"
  shows "P = Q"
  using assms(1) assms(2) l7_2 symmetric_point_uniqueness by blast

lemma l7_13_R1:
  assumes "A  P" and
    "A Midpoint P' P" and
    "A Midpoint Q' Q"
  shows "Cong P Q P' Q'"
proof -
  obtain X where "Bet P' P X" and "Cong P X Q A"
    using segment_construction by blast
  obtain X' where "Bet X P' X'" and "Cong P' X' Q A"
    using segment_construction by blast
  obtain Y where "Bet Q' Q Y" and "Cong Q Y P A"
    using segment_construction by blast
  obtain Y' where "Bet Y Q' Y'" and "Cong Q' Y' P A"
    using segment_construction by blast
  have "Bet Y A Q'"
    using Bet_cases Midpoint_def Bet Q' Q Y assms(3) between_exchange4 by blast
  have "Bet P' A X"
    using Midpoint_def Bet P' P X assms(2) between_exchange4 by blast
  have "Bet A P X" 
    using Midpoint_def Bet P' P X assms(2) between_exchange3 by blast
  have "Bet Y Q A" 
    using Midpoint_def Bet Q' Q Y assms(3) between_exchange3 between_symmetry by blast
  have "Bet A Q' Y'"
    using Bet Y A Q' Bet Y Q' Y' between_exchange3 by blast
  have "Bet X' P' A" 
    using Bet P' A X Bet X P' X' between_exchange3 between_symmetry by blast
  hence "Bet X A X'"
    using Bet P' A X Bet X P' X' between_symmetry outer_transitivity_between2 by blast
  have "Bet Y A Y'" 
    using Bet Y A Q' Bet Y Q' Y' between_exchange4 by blast
  have "Cong A X Y A"
    using Bet A P X Bet Y Q A Cong P X Q A Cong Q Y P A l2_11_b not_cong_4321 by blast
  have "Cong A Y' X' A"
  proof -
    have "Cong Q' Y' P' A"
      using Midpoint_def Cong Q' Y' P A assms(2) cong_4312 cong_transitivity by blast
    have "Cong A Q' X' P'"
      by (metis Cong_cases Midpoint_def Cong P' X' Q A assms(3) cong_transitivity)
    thus ?thesis 
      using Bet A Q' Y' Bet X' P' A Cong Q' Y' P' A l2_11_b by force
  qed
  have "Cong A Y A Y'"
  proof -
    have "Cong Q Y Q' Y'" 
      using Cong Q Y P A Cong Q' Y' P A cong_inner_transitivity cong_symmetry by blast
    thus ?thesis 
      by (meson Midpoint_def Bet A Q' Y' Bet Q' Q Y assms(3) between_exchange3 
          cong_left_commutativity cong_symmetry l2_11_b)
  qed
  have "Cong X A Y' A" 
    by (metis cong_inner_transitivity Cong A X Y A Cong A Y A Y' cong_4312)
  have "Cong A X' A Y" 
    using Cong A Y A Y' Cong A Y' X' A cong_4312 cong_transitivity by blast
  have "Cong A X A X'"
    using Cong_cases Cong A X Y A Cong A X' A Y cong_transitivity by blast
  have "X A X' Y' FSC Y' A Y X" 
  proof -
    have "Col X A X'"
      using Col_def Bet X A X' by blast
    have "Cong X X' Y' Y" 
      using Cong_cases Bet X A X' Bet Y A Y' Cong A X Y A Cong A Y' X' A l2_11_b by blast
    thus ?thesis 
      using Cong3_def FSC_def Col X A X' Cong A X' A Y Cong X A Y' A 
        cong_pseudo_reflexivity not_cong_4321 by blast
  qed
  hence "Y Q A X IFSC Y' Q' A X'" 
    by (metis Bet_cases Cong_cases IFSC_def Midpoint_def bet_neq23__neq 
        Bet A P X Bet A Q' Y' Bet X A X' Bet Y Q A Cong A X A X' Cong A Y A Y' 
        assms(1) assms(3) l4_16R1)
  hence "X P A Q IFSC X' P' A Q'" 
    by (metis Cong_cases IFSC_def Midpoint_def Bet A P X Bet X' P' A assms(2) 
        between_symmetry l4_2)
  thus ?thesis 
    using l4_2 by force
qed

lemma l7_13:
  assumes "A Midpoint P' P" and
    "A Midpoint Q' Q"
  shows "Cong P Q P' Q'"
proof (cases)
  assume "A = P"
  thus ?thesis
    using Midpoint_def assms(1) assms(2) cong_3421 is_midpoint_id_2 by blast
next
  show ?thesis
    by (metis l7_13_R1 assms(1) assms(2) cong_trivial_identity is_midpoint_id_2 not_cong_2143)
qed

lemma l7_15:
  assumes "A Midpoint P P'" and
    "A Midpoint Q Q'" and
    "A Midpoint R R'" and
    "Bet P Q R"
  shows "Bet P' Q' R'"
proof -
  have "P Q R Cong3 P' Q' R'"
    using Cong3_def assms(1) assms(2) assms(3) l7_13 l7_2 by blast
  thus ?thesis
    using assms(4) l4_6 by blast
qed

lemma l7_16:
  assumes "A Midpoint P P'" and
    "A Midpoint Q Q'" and
    "A Midpoint R R'" and
    "A Midpoint S S'" and
    "Cong P Q R S"
  shows "Cong P' Q' R' S'"
  by (meson assms(1) assms(2) assms(3) assms(4) assms(5) cong_transitivity l7_13 not_cong_3412)

lemma symmetry_preserves_midpoint:
  assumes "Z Midpoint A D" and
    "Z Midpoint B E" and
    "Z Midpoint C F" and
    "B Midpoint A C"
  shows "E Midpoint D F"
  by (meson Midpoint_def assms(1) assms(2) assms(3) assms(4) l7_15 l7_16)

lemma Mid_cases:
  assumes "A Midpoint B C  A Midpoint C B"
  shows "A Midpoint B C"
  using assms l7_2 by blast

lemma Mid_perm:
  assumes "A Midpoint B C"
  shows "A Midpoint B C  A Midpoint C B"
  by (simp add: assms l7_2)

lemma l7_17:
  assumes "A Midpoint P P'" and
    "B Midpoint P P'"
  shows "A = B"
proof -
  have "Cong P B P' B" 
    using Cong_cases Midpoint_def assms(2) by blast
  obtain x where "A Midpoint B x" 
    using symmetric_point_construction by presburger
  hence "Cong P' B P x" 
    using assms(1) l7_13 l7_2 by blast
  hence "Cong P B P x" 
    using Cong P B P' B cong_transitivity by blast
  have "Cong P B P' x" 
    using A Midpoint B x assms(1) cong_4321 l7_13 by blast
  have "Cong P' B P' x" 
    using cong_inner_transitivity Cong P B P' B Cong P B P' x by blast
  have "Bet P B P'" 
    using Midpoint_def assms(2) by blast
  hence "B = x" 
    using Cong P B P x Cong P' B P' x l4_19 by auto
  thus ?thesis 
    using A Midpoint B x l7_3 by blast
qed

lemma l7_17_bis:
  assumes "A Midpoint P P'" and
    "B Midpoint P' P"
  shows "A = B"
  by (meson l7_17 l7_2 Tarski_neutral_dimensionless_axioms assms(1) assms(2))

lemma l7_20:
  assumes "Col A M B" and
    "Cong M A M B"
  shows "A = B  M Midpoint A B"
  by (metis Bet_cases Col_def Midpoint_def assms(1) assms(2) between_cong 
      cong_left_commutativity not_cong_3412)

lemma l7_20_bis:
  assumes "A  B" and
    "Col A M B" and
    "Cong M A M B"
  shows "M Midpoint A B"
  using assms(1) assms(2) assms(3) l7_20 by blast

lemma cong_col_mid:
  assumes "A  C" and
    "Col A B C" and
    "Cong A B B C"
  shows "B Midpoint A C"
  using assms(1) assms(2) assms(3) cong_left_commutativity l7_20 by blast

lemma l7_21_R1:
  assumes "¬ Col A B C" and
    "B  D" and
    "Cong A B C D" and
    "Cong B C D A" and
    "Col A P C" and
    "Col B P D"
  shows "P Midpoint A C"
proof -
  obtain X where "B D P Cong3 D B X"
    using Col_perm assms(6) cong_pseudo_reflexivity l4_14 by blast
  hence "Col D B X"
    using assms(6) l4_13 not_col_permutation_5 by blast
  have "B D P A FSC D B X C" 
    by (meson Col_cases Cong_cases FSC_def B D P Cong3 D B X assms(3) assms(4) assms(6))
  have "B D P C FSC D B X A" 
    using Col_cases Cong_perm FSC_def B D P Cong3 D B X assms(3) assms(4) assms(6) by blast
  hence "A P C Cong3 C X A" 
    using Cong3_def Cong_cases B D P A FSC D B X C assms(2) cong_pseudo_reflexivity l4_16 
    by blast
  hence "Col C X A" 
    using assms(5) l4_13 by blast
  hence "P = X" 
    using Col D B X assms(1) assms(2) assms(5) assms(6) l6_21 not_col_permutation_1 
      not_col_permutation_5 by blast
  thus ?thesis 
    by (metis Col_perm B D P A FSC D B X C Col C X A assms(1) assms(2) l4_16 l7_20_bis 
        not_col_distincts)
qed

lemma l7_21:
  assumes "¬ Col A B C" and
    "B  D" and
    "Cong A B C D" and
    "Cong B C D A" and
    "Col A P C" and
    "Col B P D"
  shows "P Midpoint A C  P Midpoint B D" 
  by (metis Cong_cases Midpoint_def assms(1) assms(2) assms(3) assms(4) assms(5) assms(6) 
      cong_reverse_identity l7_21_R1 not_col_distincts)

lemma l7_22_aux_R1:
  assumes "Bet A1 C C" and
    "Bet B1 C B2" and
    "Cong C A1 C B1" and
    "Cong C C C B2" and
    "M1 Midpoint A1 B1" and
    "M2 Midpoint A2 B2"and
    "C A1 Le C C"
  shows "Bet M1 C M2"
  by (metis assms(3) assms(5) assms(7) cong_diff_3 l7_3 le_diff not_bet_distincts)

lemma l7_22_aux_R2:
  assumes "A2  C" and
    "Bet A1 C A2" and
    "Bet B1 C B2" and
    "Cong C A1 C B1" and
    "Cong C A2 C B2" and
    "M1 Midpoint A1 B1" and
    "M2 Midpoint A2 B2" and
    "C A1 Le C A2"
  shows "Bet M1 C M2"
proof -
  obtain X where "C Midpoint A2 X"
    using symmetric_point_construction by blast
  obtain X0 where "C Midpoint B2 X0"
    using symmetric_point_construction by blast
  obtain X1 where "C Midpoint M2 X1"
    using symmetric_point_construction by blast
  hence "X1 Midpoint X X0"
    using C Midpoint A2 X C Midpoint B2 X0 assms(7) symmetry_preserves_midpoint by blast
  have "C A1 Le C X" 
    by (metis Midpoint_def cong_reflexivity l5_6 C Midpoint A2 X assms(8) le_right_comm)
  hence "Bet C A1 X"
    by (metis (full_types) Bet_cases Le_cases Midpoint_def C Midpoint A2 X assms(1,2)
        bet_le_eq l5_2) 
  have "Cong C X C X0" 
    by (meson l7_3_2 C Midpoint A2 X C Midpoint B2 X0 assms(5) l7_16)
  hence "C B1 Le C X0"
    using C A1 Le C X assms(4) l5_6 by blast
  have "Bet C B1 X0" 
  proof cases
    assume "B1 = C"
    thus ?thesis 
      using between_trivial2 by auto
  next
    assume "B1  C"
    thus ?thesis
      by (metis (full_types) Bet_cases Le_cases Midpoint_def C B1 Le C X0 C Midpoint B2 X0 assms(3)
          bet_cong_eq bet_le_eq l5_2)
  qed
  hence "Bet X0 B1 C" 
    using Bet_cases by blast
  have " Q. Bet X1 Q C  Bet A1 Q B1" 
  proof -
    have "Bet X A1 C" 
      using Bet_cases Bet C A1 X by blast
    moreover have "Bet X X1 X0" 
      using Midpoint_def X1 Midpoint X X0 by auto
    ultimately show ?thesis 
      using Bet X0 B1 C l3_17 by blast
  qed
  then obtain Q where "Bet X1 Q C" and "Bet A1 Q B1" 
    by blast
  have "X A1 C X1 IFSC X0 B1 C X1" 
    by (metis Bet_cases Cong_cases IFSC_def Midpoint_def Bet C A1 X Bet X0 B1 C 
        Cong C X C X0 X1 Midpoint X X0 assms(4) cong_reflexivity)
  hence "Cong A1 X1 B1 X1" 
    using l4_2 by auto
  have  "Cong Q A1 Q B1"
  proof cases
    assume "C = X1"
    thus ?thesis 
      using between_identity Bet X1 Q C assms(4) by blast
  next
    assume "¬ C = X1"
    moreover
    have "Col C X1 Q" 
      by (simp add: Col_def Bet X1 Q C)
    moreover
    have "Cong X1 A1 X1 B1" 
      using Cong_cases Cong A1 X1 B1 X1 by auto
    ultimately show ?thesis 
      by (simp add: assms(4) l4_17)
  qed
  have "Q Midpoint A1 B1" 
    using Midpoint_def Bet A1 Q B1 Cong Q A1 Q B1 not_cong_2134 by blast
  thus ?thesis 
    by (metis Midpoint_def Bet X1 Q C C Midpoint M2 X1 assms(6) between_inner_transitivity 
        between_symmetry l7_17)
qed

lemma l7_22_aux:
  assumes "Bet A1 C A2" and
    "Bet B1 C B2" and
    "Cong C A1 C B1" and
    "Cong C A2 C B2" and
    "M1 Midpoint A1 B1" and
    "M2 Midpoint A2 B2" and
    "C A1 Le C A2"
  shows "Bet M1 C M2" 
  by (metis assms(1) assms(2) assms(3) assms(4) assms(5) assms(6) assms(7) between_trivial 
      cong_diff_4 l7_22_aux_R2 l7_3)

lemma l7_22:
  assumes "Bet A1 C A2" and
    "Bet B1 C B2" and
    "Cong C A1 C B1" and
    "Cong C A2 C B2" and
    "M1 Midpoint A1 B1" and
    "M2 Midpoint A2 B2"
  shows "Bet M1 C M2"
  by (meson assms(1) assms(2) assms(3) assms(4) assms(5) assms(6) between_symmetry l7_22_aux 
      le_cases)

lemma bet_col1:
  assumes "Bet A B D" and
    "Bet A C D"
  shows "Col A B C"
  using Bet_perm Col_def assms(1) assms(2) l5_3 by blast

lemma l7_25_R1:
  assumes "Cong C A C B" and
    "Col A B C"
  shows " X. X Midpoint A B"
  using assms(1) assms(2) l7_20 l7_3_2 not_col_permutation_5 by blast

lemma l7_25_R2:
  assumes "Cong C A C B" and
    "¬ Col A B C"
  shows " X. X Midpoint A B"
proof -
  obtain P where "Bet C A P" and "A  P"
    using point_construction_different by auto
  obtain Q where "Bet C B Q" and "Cong B Q A P"
    using segment_construction by blast
  obtain R where "Bet A R Q" and "Bet B R P" 
    by (meson Bet C A P Bet C B Q l3_17 not_bet_distincts)
  obtain X where "Bet A X B" and "Bet R X C" 
    using Bet B R P Bet C A P inner_pasch by blast
  have "Cong X A X B"
  proof -
    have "Cong R A R B  Cong X A X B"
    proof cases
      assume "R = C"
      thus ?thesis 
        using Bet R X C between_identity by blast
    next
      assume "¬ R = C"
      have "Col R C X" 
        using Bet R X C bet_col1 between_trivial by blast
      thus ?thesis 
        using R  C assms(1) l4_17 by blast
    qed
    have "Cong R A R B"
    proof -
      have "C A P B OFSC C B Q A" 
        by (metis OFSC_def Bet C A P Bet C B Q Cong B Q A P assms(1) 
            cong_pseudo_reflexivity not_cong_3412)
      hence "Cong P B Q A" 
        using assms(2) col_trivial_3 five_segment_with_def by blast
      hence "Cong B P A Q" 
        using Cong_cases by blast
      then obtain R' where "Bet A R' Q" and "B R P Cong3 A R' Q" 
        using Bet B R P l4_5 by blast
      have "B R P A IFSC A R' Q B" 
        using Cong3_def IFSC_def B R P Cong3 A R' Q Bet A R' Q Bet B R P Cong B Q A P 
          cong_pseudo_reflexivity not_cong_4321 by blast
      hence "Cong R A R' B" 
        using l4_2 by auto
      have "B R P Q IFSC A R' Q P" 
        using Cong3_def IFSC_def B R P Cong3 A R' Q Bet A R' Q Bet B R P Cong B Q A P 
          cong_pseudo_reflexivity by blast
      hence "Cong R Q R' P" 
        using l4_2 by blast
      hence "A R Q Cong3 B R' P" 
        using Cong3_def Cong_cases Cong B P A Q Cong R A R' B by blast
      have "Col B R' P" 
        using A R Q Cong3 B R' P Bet A R Q bet_col l4_13 by blast
      have "R = R'"
      proof -
        have "B  P" 
          using Col_def Bet C A P assms(2) by blast
        moreover
        have "B  Q" 
          using A  P Cong B Q A P cong_reverse_identity by force
        hence "¬ Col A Q B" 
          using Bet C B Q assms(2) bet_col col2__eq not_col_permutation_5 by blast
        moreover have "Col A Q R" 
          using Bet_cases Col_def Bet A R Q by auto
        moreover have "Col A Q R'" 
          using Bet A R' Q bet_col not_col_permutation_5 by blast
        moreover have "Col B P R" 
          using Bet_cases Col_def Bet B R P by auto
        moreover have "Col B P R'" 
          using Col B R' P not_col_permutation_5 by blast
        ultimately show ?thesis 
          using B  P ¬ Col A Q B l6_21 by blast
      qed
      thus ?thesis 
        using Cong R A R' B by auto
    qed
    thus ?thesis 
      by (simp add: Cong R A R B  Cong X A X B)
  qed
  thus ?thesis 
    using Col_def Bet A X B between_symmetry l7_25_R1 by blast
qed

lemma l7_25:
  assumes "Cong C A C B"
  shows " X. X Midpoint A B"
  using assms l7_25_R1 l7_25_R2 by blast

lemma midpoint_distinct_1:
  assumes "A  B" and
    "I Midpoint A B"
  shows "I  A  I  B"
  using assms(1) assms(2) is_midpoint_id is_midpoint_id_2 by blast

lemma midpoint_distinct_2:
  assumes "I  A" and
    "I Midpoint A B"
  shows "A  B  I  B"
  using assms(1) assms(2) is_midpoint_id_2 l7_3 by blast

lemma midpoint_distinct_3:
  assumes "I  B" and
    "I Midpoint A B"
  shows "A  B  I  A"
  using assms(1) assms(2) is_midpoint_id l7_3 by blast

lemma midpoint_def:
  assumes "Bet A B C" and
    "Cong A B B C"
  shows "B Midpoint A C"
  using Midpoint_def assms(1) assms(2) by blast

lemma midpoint_bet:
  assumes "B Midpoint A C"
  shows "Bet A B C"
  using Midpoint_def assms by blast

lemma midpoint_col:
  assumes "M Midpoint A B"
  shows "Col M A B"
  using assms bet_col col_permutation_4 midpoint_bet by blast

lemma midpoint_cong:
  assumes "B Midpoint A C"
  shows "Cong A B B C"
  using Midpoint_def assms by blast

lemma midpoint_out:
  assumes "A  C" and
    "B Midpoint A C"
  shows "A Out B C"
  using assms(1) assms(2) bet_out midpoint_bet midpoint_distinct_1 by blast

lemma midpoint_out_1:
  assumes "A  C" and
    "B Midpoint A C"
  shows "C Out A B"
  by (metis midpoint_bet midpoint_distinct_1 assms(1) assms(2) bet_out_1 l6_6)

lemma midpoint_not_midpoint:
  assumes "A  B" and
    "I Midpoint A B"
  shows "¬ B Midpoint A I"
  using assms(1) assms(2) between_equality_2 midpoint_bet midpoint_distinct_1 by blast

lemma swap_diff:
  assumes "A  B"
  shows "B  A"
  using assms by auto

lemma cong_cong_half_1:
  assumes "M Midpoint A B" and
    "M' Midpoint A' B'" and
    "Cong A B A' B'"
  shows "Cong A M A' M'"
proof -
  obtain M'' where "Bet A' M'' B'" and "A M B Cong3 A' M'' B'"
    using assms(1) assms(3) l4_5 midpoint_bet by blast
  hence "M'' Midpoint A' B'"
    by (meson Cong3_def assms(1) cong_inner_transitivity midpoint_cong midpoint_def)
  hence "M' = M''"
    using assms(2) l7_17 by auto
  thus ?thesis 
    using Cong3_def A M B Cong3 A' M'' B' by blast
qed

lemma cong_cong_half_2:
  assumes "M Midpoint A B" and
    "M' Midpoint A' B'" and
    "Cong A B A' B'"
  shows "Cong B M B' M'"
  using assms(1) assms(2) assms(3) cong_cong_half_1 l7_2 not_cong_2143 by blast

lemma cong_mid2__cong:
  assumes "M Midpoint A B" and
    "M' Midpoint A' B'" and
    "Cong A M A' M'"
  shows "Cong A B A' B'"
  by (meson assms(1) assms(2) assms(3) cong_inner_transitivity l2_11_b midpoint_bet midpoint_cong)

lemma mid__lt:
  assumes "A  B" and
    "M Midpoint A B"
  shows "A M Lt A B"
  using assms(1) assms(2) bet__lt1213 midpoint_bet midpoint_distinct_1 by blast

lemma le_mid2__le13:
  assumes "M Midpoint A B" and
    "M' Midpoint A' B'" and
    "A M Le A' M'"
  shows "A B Le A' B'" 
  by (meson Midpoint_def l5_6 assms(1) assms(2) assms(3) bet2_le2__le1346)

lemma le_mid2__le12:
  assumes "M Midpoint A B" and
    "M' Midpoint A' B'"
    and "A B Le A' B'"
  shows "A M Le A' M'"
  by (meson assms(1) assms(2) assms(3) cong__le3412 cong_cong_half_1 le_anti_symmetry 
      le_mid2__le13 local.le_cases)

lemma lt_mid2__lt13:
  assumes "M Midpoint A B" and
    "M' Midpoint A' B'" and
    "A M Lt A' M'"
  shows "A B Lt A' B'"
  by (meson le_mid2__le12 Tarski_neutral_dimensionless_axioms assms(1) assms(2) assms(3) 
      lt__nle nlt__le)

lemma lt_mid2__lt12:
  assumes "M Midpoint A B" and
    "M' Midpoint A' B'" and
    "A B Lt A' B'"
  shows "A M Lt A' M'"
  by (meson le_mid2__le13 Tarski_neutral_dimensionless_axioms assms(1) assms(2) assms(3) 
      le__nlt nle__lt)

lemma midpoint_preserves_out:
  assumes "A Out B C" and
    "M Midpoint A A'" and
    "M Midpoint B B'" and
    "M Midpoint C C'"
  shows "A' Out B' C'" 
  using Out_def assms(1) assms(2) assms(3) assms(4) l7_15 l7_9 by fastforce

lemma col_cong_bet:
  assumes "Col A B D" and
    "Cong A B C D" and
    "Bet A C B"
  shows "Bet C A D  Bet C B D" 
proof -
  obtain D1 where "Bet B A D1" and "Cong A D1 B C" 
    using segment_construction by blast
  obtain D2 where "Bet A B D2" and "Cong B D2  A C" 
    using segment_construction by blast
  have "Cong A B C D1" 
    by (meson Bet_cases Bet B A D1 Cong A D1 B C assms(3) between_exchange4 
        cong_pseudo_reflexivity l4_3_1 not_cong_2134)
  have "D = D1  C Midpoint D D1" 
  proof -
    have "Col D C D1" 
    proof cases
      assume "A = B"
      thus ?thesis 
        by (metis assms(2) col_trivial_1 cong_diff_3)
    next
      assume "A  B"
      thus ?thesis 
        by (meson Col_def Bet B A D1 assms(1) assms(3) col3 not_col_permutation_4)
    qed
    moreover have "Cong C D C D1" 
      using Cong A B C D1 assms(2) cong_inner_transitivity by blast
    ultimately show ?thesis 
      using l7_20 by auto
  qed
  {
    assume "D = D1"
    hence "Bet C A D  Bet C B D" 
      using Bet B A D1 assms(3) between_exchange3 between_symmetry by blast
  }
  moreover
  {
    assume "C Midpoint D D1"
    have "Cong B A C D2" 
    proof -
      have "Bet B C A" 
        using Bet_cases assms(3) by blast
      moreover have "Bet C B D2" 
        using Bet A B D2 assms(3) between_exchange3 by blast
      moreover have "Cong B C C B" 
        using cong_pseudo_reflexivity by blast
      have "Cong C A B D2" 
        using Cong_cases Cong B D2 A C by blast
      ultimately show ?thesis 
        using Cong B C C B l2_11_b by blast
    qed
    have "C Midpoint D2 D1" 
    proof cases
      assume "A = B"
      thus ?thesis 
        by (metis C Midpoint D D1 Cong B A C D2 assms(2) cong_diff_3)
    next
      assume "A  B"
      show ?thesis 
      proof cases
        assume "B = C"
        thus ?thesis 
          using Midpoint_def Bet A B D2 Cong A D1 B C Cong B D2 A C between_symmetry 
            cong_commutativity cong_identity by blast
      next
        assume "B  C"
        have "Bet D1 C B" 
          using Bet B A D1 assms(3) between_exchange4 between_symmetry by blast
        have "Bet C B D2" 
          using Bet A B D2 assms(3) between_exchange3 by blast
        thus ?thesis 
          by (metis Midpoint_def cong_inner_transitivity B  C Bet D1 C B 
              Cong A B C D1 Cong B A C D2 between_symmetry not_cong_2134 
              outer_transitivity_between2)
      qed
    qed
    have "Bet C A D  Bet C B D" 
      using Bet A B D2 C Midpoint D2 D1 D = D1  C Midpoint D D1 assms(3) 
        between_exchange3 calculation l7_9 by blast
  }
  ultimately show ?thesis 
    using D = D1  C Midpoint D D1 by blast
qed

lemma col_cong2_bet1:
  assumes "Col A B D" and
    "Bet A C B" and
    "Cong A B C D" and
    "Cong A C B D"
  shows "Bet C B D"
  by (metis assms(1) assms(2) assms(3) assms(4) bet__le1213 bet_cong_eq between_symmetry 
      col_cong_bet cong__le cong_left_commutativity l5_12_b l5_6 outer_transitivity_between2)

lemma col_cong2_bet2:
  assumes "Col A B D" and
    "Bet A C B" and
    "Cong A B C D" and
    "Cong A D B C"
  shows "Bet C A D"
  by (metis assms(1) assms(2) assms(3) assms(4) bet_cong_eq col_cong_bet 
      cong_identity not_bet_distincts not_cong_3421 outer_transitivity_between2)

lemma col_cong2_bet3:
  assumes "Col A B D" and
    "Bet A B C" and
    "Cong A B C D" and
    "Cong A C B D"
  shows "Bet B C D"
  by (metis assms(1) assms(2) assms(3) assms(4) bet__le1213 bet__le2313 
      bet_col col_transitivity_2 cong_diff_3 cong_reflexivity l5_12_b l5_6 not_bet_distincts)

lemma col_cong2_bet4:
  assumes "Col A B C" and
    "Bet A B D" and
    "Cong A B C D" and
    "Cong A D B C"
  shows "Bet B D C"
  using assms(1) assms(2) assms(3) assms(4) col_cong2_bet3 cong_right_commutativity by blast

lemma col_bet2_cong1:
  assumes "Col A B D" and
    "Bet A C B" and
    "Cong A B C D" and
    "Bet C B D"
  shows "Cong A C D B"
  by (meson assms(2) assms(3) assms(4) between_symmetry cong_pseudo_reflexivity 
      cong_right_commutativity l4_3)

lemma col_bet2_cong2:
  assumes "Col A B D" and
    "Bet A C B" and
    "Cong A B C D" and
    "Bet C A D"
  shows "Cong D A B C"
  by (meson assms(2) assms(3) assms(4) between_symmetry cong_commutativity 
      cong_pseudo_reflexivity cong_symmetry l4_3)

lemma bet2_lt2__lt:
  assumes "Bet a Po b" and
    "Bet A PO B" and
    "Po a Lt PO A" and
    "Po b Lt PO B"
  shows "a b Lt A B"
  by (metis Lt_cases nle__lt assms(1) assms(2) assms(3) assms(4) bet2_le2__le1245 le__nlt lt__le)

lemma bet2_lt_le__lt:
  assumes "Bet a Po b" and
    "Bet A PO B" and
    "Cong Po a PO A" and
    "Po b Lt PO B"
  shows "a b Lt A B" 
proof -
  have "Po a Le PO A" 
    using assms(3) cong__le by blast
  thus ?thesis
    by (meson Le_cases nlt__le assms(1) assms(2) assms(4) bet2_le2__le2356 lt__nle)
qed

lemma per_dec:
  "Per A B C  ¬ Per A B C"
  by simp

lemma l8_2:
  assumes "Per A B C"
  shows "Per C B A"
proof -
  obtain C' where "B Midpoint C C'" and "Cong A C A C'"
    using Per_def assms by blast
  obtain A' where "B Midpoint A A'"
    using symmetric_point_construction by blast
  hence "Cong C' A C A'" 
    using Mid_cases B Midpoint C C' l7_13 by blast
  thus ?thesis 
    using Per_def B Midpoint A A' Cong A C A C' cong_transitivity not_cong_2143 by blast
qed

lemma Per_cases:
  assumes "Per A B C  Per C B A"
  shows "Per A B C"
  using assms l8_2 by blast

lemma Per_perm :
  assumes "Per A B C"
  shows "Per A B C  Per C B A"
  by (simp add: assms l8_2)

lemma l8_3 :
  assumes "Per A B C" and
    "A  B" and
    "Col B A A'"
  shows "Per A' B C" 
  by (metis Per_def cong_left_commutativity assms(1) assms(2) assms(3) l4_17 midpoint_cong)

lemma l8_4:
  assumes "Per A B C" and
    "B Midpoint C C'"
  shows "Per A B C'"
  by (metis l8_2 assms(1) assms(2) l8_3 midpoint_col midpoint_distinct_1)

lemma l8_5:
  shows "Per A B B"
  using Per_def cong_reflexivity l7_3_2 by blast

lemma l8_6:
  assumes "Per A B C" and
    "Per A' B C" and
    "Bet A C A'"
  shows "B = C"
  by (metis Per_def assms(1) assms(2) assms(3) l4_19 midpoint_distinct_3 
      symmetric_point_uniqueness)

lemma l8_7:
  assumes "Per A B C" and
    "Per A C B"
  shows "B = C"
proof -
  obtain C' where P1: "B Midpoint C C'  Cong A C A C'"
    using Per_def assms(1) by blast
  obtain A' where P2: "C Midpoint A A'"
    using Per_def assms(2) l8_2 by blast
  have "Per C' C A"
    by (metis P1 l8_3 assms(2) bet_col l8_2 midpoint_bet midpoint_distinct_3)
  hence "Cong A C' A' C'"
    using Cong_perm P2 Per_def symmetric_point_uniqueness by blast
  hence "Cong A' C A' C'"
    using P1 P2 cong_inner_transitivity midpoint_cong not_cong_2134 by blast
  hence Q4: "Per A' B C"
    using P1 Per_def by blast
  have "Bet A' C A"
    using Mid_perm P2 midpoint_bet by blast
  thus ?thesis
    using Q4 assms(1) l8_6 by blast
qed

lemma l8_8:
  assumes "Per A B A"
  shows "A = B"
  using l8_6 Tarski_neutral_dimensionless_axioms assms between_trivial2 by fastforce

lemma per_distinct:
  assumes "Per A B C" and
    "A  B"
  shows "A  C"
  using assms(1) assms(2) l8_8 by blast

lemma per_distinct_1:
  assumes "Per A B C" and
    "B  C"
  shows "A  C"
  using assms(1) assms(2) l8_8 by blast

lemma l8_9:
  assumes "Per A B C" and
    "Col A B C"
  shows "A = B  C = B"
  using Col_cases assms(1) assms(2) l8_3 l8_8 by blast

lemma l8_10:
  assumes "Per A B C" and
    "A B C Cong3 A' B' C'"
  shows "Per A' B' C'"
proof -
  obtain D where "B Midpoint C D" and "Cong A C A D"
    using Per_def assms(1) by blast
  obtain D' where "Bet C' B' D'" and "Cong B' D' B' C'"
    using segment_construction by blast
  hence "B' Midpoint C' D'"
    by (simp add: Midpoint_def cong_4312)
  have "Cong A' C' A' D'"
  proof cases
    assume "C = B"
    thus ?thesis 
      by (metis Cong3_def Cong_cases Cong B' D' B' C' assms(2) cong_reflexivity 
          cong_reverse_identity)
  next
    assume "¬ C = B"
    hence "C B D A OFSC C' B' D' A'"
      by (meson Cong3_def OFSC_def B Midpoint C D B' Midpoint C' D' assms(2) cong_commutativity
          cong_cong_half_2 cong_mid2__cong midpoint_bet) 
    thus ?thesis 
      by (meson Cong3_def C  B Cong A C A D assms(2) cong_inner_transitivity 
          five_segment_with_def not_cong_2143)
  qed
  thus ?thesis 
    using Per_def B' Midpoint C' D' by blast
qed

lemma col_col_per_per:
  assumes "A  X" and
    "C  X" and
    "Col U A X" and
    "Col V C X" and
    "Per A X C"
  shows "Per U X V"
  by (meson l8_2 l8_3 Tarski_neutral_dimensionless_axioms assms(1) assms(2) assms(3) assms(4) 
      assms(5) not_col_permutation_3)

lemma perp_in_dec:
  "X PerpAt A B C D  ¬ X PerpAt A B C D"
  by simp

lemma perp_distinct:
  assumes "A B Perp C D"
  shows "A  B  C  D"
  using PerpAt_def Perp_def assms by auto

lemma l8_12:
  assumes "X PerpAt A B C D"
  shows "X PerpAt C D A B"
  using Per_perm PerpAt_def assms by auto

lemma per_col:
  assumes "B  C" and
    "Per A B C" and
    "Col B C D"
  shows "Per A B D"
  by (metis l8_3 assms(1) assms(2) assms(3) l8_2)

lemma l8_13_2:
  assumes "A  B" and
    "C  D" and
    "Col X A B" and
    "Col X C D" and
    " U.  V. Col U A B  Col V C D  U  X  V  X  Per U X V"
  shows "X PerpAt A B C D"
proof -
  obtain U V where "Col U A B" and "Col V C D" and "U  X" and "V  X" and "Per U X V" 
    using assms(5) by blast
  {
    fix U0 V0
    assume "Col U0 A B" and "Col V0 C D"
    have "Col X U U0" 
      using Col U A B Col U0 A B assms(1) assms(3) col3 not_col_permutation_2 by blast
    hence "Per U0 X V" 
      using Per U X V U  X l8_3 by blast
    hence "Per V X U0" 
      using l8_2 by blast
    hence "Per U0 X V0" 
      by (metis NCol_perm 
          Col V C D Col V0 C D Per U0 X V V  X assms(2) assms(4) l6_16_1 per_col)
  }
  thus ?thesis 
    by (simp add: PerpAt_def assms(1) assms(2) assms(3) assms(4))
qed

lemma l8_14_1:
  "¬ A B Perp A B"
  by (metis PerpAt_def Perp_def col_trivial_1 col_trivial_3 l8_8)

lemma l8_14_2_1a:
  assumes "X PerpAt A B C D"
  shows "A B Perp C D"
  using Perp_def assms by blast

lemma perp_in_distinct:
  assumes "X PerpAt A B C D"
  shows "A  B  C  D"
  using PerpAt_def assms by blast

lemma l8_14_2_1b:
  assumes "X PerpAt A B C D" and
    "Col Y A B" and
    "Col Y C D"
  shows "X = Y"
  by (metis PerpAt_def assms(1) assms(2) assms(3) l8_13_2 l8_14_1 l8_14_2_1a)

lemma l8_14_2_1b_bis:
  assumes "A B Perp C D" and
    "Col X A B" and
    "Col X C D"
  shows "X PerpAt A B C D"
  using Perp_def assms(1) assms(2) assms(3) l8_14_2_1b by blast

lemma l8_14_2_2:
  assumes "A B Perp C D" and
    " Y. (Col Y A B  Col Y C D)  X = Y"
  shows "X PerpAt A B C D"
  by (metis PerpAt_def Perp_def assms(1) assms(2))

lemma l8_14_3:
  assumes "X PerpAt A B C D" and
    "Y PerpAt A B C D"
  shows "X = Y"
  by (meson PerpAt_def assms(1) assms(2) l8_14_2_1b)

lemma l8_15_1:
  assumes "Col A B X" and
    "A B Perp C X"
  shows "X PerpAt A B C X"
  using NCol_perm assms(1) assms(2) col_trivial_3 l8_14_2_1b_bis by blast

lemma l8_15_2:
  assumes "Col A B X" and
    "X PerpAt A B C X"
  shows "A B Perp C X"
  using assms(2) l8_14_2_1a by blast

lemma perp_in_per:
  assumes "B PerpAt A B B C"
  shows "Per A B C"
  by (meson NCol_cases PerpAt_def assms col_trivial_3)

lemma perp_sym:
  assumes "A B Perp A B"
  shows "C D Perp C D"
  using assms l8_14_1 by auto

lemma perp_col0:
  assumes "A B Perp C D" and
    "X  Y" and
    "Col A B X" and
    "Col A B Y"
  shows "C D Perp X Y"
proof -
  obtain X0 where "X0 PerpAt A B C D"
    using Perp_def assms(1) by blast
  hence " A  B  C  D  Col X0 A B  Col X0 C D 
((Col U A B  Col V C D)  Per U X0 V)" 
    using PerpAt_def by blast
  have "C  D" 
    by (simp add: A  B  C  D  Col X0 A B  Col X0 C D  
    (Col U A B  Col V C D  Per U X0 V))
  have "X  Y"
    by (simp add: assms(2))
  have "Col X0 C D" 
    using A  B  C  D  Col X0 A B  Col X0 C D  (Col U A B  Col V C D  Per U X0 V) 
    by blast
  have "Col X0 X Y" 
    by (meson A  B  C  D  Col X0 A B  Col X0 C D  (Col U A B  Col V C D  Per U X0 V) 
        assms(3) assms(4) col3 not_col_permutation_2)
  have "X0 PerpAt C D X Y"
  proof -
    have " U V. (Col U C D  Col V X Y)  Per U X0 V" 
      by (metis Per_perm PerpAt_def col_trivial_2 X0 PerpAt A B C D assms(2) assms(3) 
          assms(4) l6_21 not_col_permutation_1)
    thus ?thesis 
      by (simp add: PerpAt_def C  D Col X0 C D Col X0 X Y assms(2))
  qed
  thus ?thesis
    using Perp_def by auto
qed

lemma per_perp_in:
  assumes "A  B" and
    "B  C" and
    "Per A B C"
  shows "B PerpAt A B B C"
  by (metis Col_def assms(1) assms(2) assms(3) between_trivial2 l8_13_2)

lemma per_perp:
  assumes "A  B" and
    "B  C" and
    "Per A B C"
  shows "A B Perp B C"
  using Perp_def assms(1) assms(2) assms(3) per_perp_in by blast

lemma perp_left_comm:
  assumes "A B Perp C D"
  shows "B A Perp C D"
proof -
  obtain X where "X PerpAt A B C D"
    using Perp_def assms by blast
  hence "X PerpAt B A C D"
    using PerpAt_def col_permutation_5 by auto
  thus ?thesis
    using Perp_def by blast
qed

lemma perp_right_comm:
  assumes "A B Perp C D"
  shows "A B Perp D C"
  by (meson Perp_def assms l8_12 perp_left_comm)

lemma perp_comm:
  assumes "A B Perp C D"
  shows "B A Perp D C"
  by (simp add: assms perp_left_comm perp_right_comm)

lemma perp_in_sym:
  assumes  "X PerpAt A B C D"
  shows "X PerpAt C D A B"
  by (simp add: assms l8_12)

lemma perp_in_left_comm:
  assumes "X PerpAt A B C D"
  shows "X PerpAt B A C D"
  by (metis Col_cases PerpAt_def assms)

lemma perp_in_right_comm:
  assumes "X PerpAt A B C D"
  shows "X PerpAt A B D C"
  using assms perp_in_left_comm perp_in_sym by blast

lemma perp_in_comm:
  assumes "X PerpAt A B C D"
  shows "X PerpAt B A D C"
  by (simp add: assms perp_in_left_comm perp_in_right_comm)

lemma Perp_cases:
  assumes "A B Perp C D  B A Perp C D  A B Perp D C  B A Perp D C  C D Perp A B  
C D Perp B A  D C Perp A B  D C Perp B A"
  shows "A B Perp C D"
  by (meson Perp_def assms perp_in_sym perp_left_comm)

lemma Perp_perm :
  assumes "A B Perp C D"
  shows "A B Perp C D  B A Perp C D  A B Perp D C  B A Perp D C  C D Perp A B  
C D Perp B A  D C Perp A B  D C Perp B A"
  by (meson Perp_def assms perp_in_sym perp_left_comm)

lemma Perp_in_cases:
  assumes "X PerpAt A B C D  X PerpAt B A C D  X PerpAt A B D C  X PerpAt B A D C  
X PerpAt C D A B  X PerpAt C D B A  X PerpAt D C A B  X PerpAt D C B A"
  shows "X PerpAt A B C D"
  using assms perp_in_left_comm perp_in_sym by blast

lemma Perp_in_perm:
  assumes "X PerpAt A B C D"
  shows "X PerpAt A B C D  X PerpAt B A C D  X PerpAt A B D C  X PerpAt B A D C  
X PerpAt C D A B  X PerpAt C D B A  X PerpAt D C A B  X PerpAt D C B A"
  using Perp_in_cases assms by blast

lemma perp_in_col:
  assumes "X PerpAt A B C D"
  shows "Col A B X  Col C D X"
  using PerpAt_def assms col_permutation_2 by presburger

lemma perp_perp_in:
  assumes "A B Perp C A"
  shows "A PerpAt A B C A"
  using assms l8_15_1 not_col_distincts by blast

lemma perp_per_1:
  assumes "A B Perp C A"
  shows "Per B A C"
  using Perp_in_cases assms perp_in_per perp_perp_in by blast

lemma perp_per_2:
  assumes "A B Perp A C"
  shows "Per B A C"
  by (simp add: Perp_perm assms perp_per_1)

lemma perp_col:
  assumes "A  E" and
    "A B Perp C D" and
    "Col A B E"
  shows "A E Perp C D"
  using Perp_perm assms(1) assms(2) assms(3) col_trivial_3 perp_col0 by blast

lemma perp_col2:
  assumes "A B Perp X Y" and
    "C  D" and
    "Col A B C" and
    "Col A B D"
  shows "C D Perp X Y"
  using Perp_perm assms(1) assms(2) assms(3) assms(4) perp_col0 by blast

lemma perp_col4:
  assumes "P  Q" and
    "R  S" and
    "Col A B P" and
    "Col A B Q" and
    "Col C D R" and
    "Col C D S" and
    "A B Perp C D"
  shows "P Q Perp R S"
  using assms(1) assms(2) assms(3) assms(4) assms(5) assms(6) assms(7) perp_col0 by blast

lemma perp_not_eq_1:
  assumes "A B Perp C D"
  shows "A  B"
  using assms perp_distinct by auto

lemma perp_not_eq_2:
  assumes "A B Perp C D"
  shows "C  D"
  using assms perp_distinct by auto

lemma diff_per_diff:
  assumes "A  B" and
    "Cong A P B R" and
    "Per B A P"
    and "Per A B R"
  shows "P  R"
  using assms(1) assms(3) assms(4) l8_2 l8_7 by blast

lemma per_not_colp:
  assumes "A  B" and
    "A  P" and
    "B  R" and
    "Per B A P"
    and "Per A B R"
  shows "¬ Col P A R"
  by (metis Per_cases col_permutation_4 assms(1) assms(2) assms(4) assms(5) l8_3 l8_7)

lemma per_not_col:
  assumes "A  B" and
    "B  C" and
    "Per A B C"
  shows "¬ Col A B C"
  using assms(1) assms(2) assms(3) l8_9 by auto

lemma perp_not_col2:
  assumes "A B Perp C D"
  shows "¬ Col A B C  ¬ Col A B D"
  using assms l8_14_1 perp_col2 perp_distinct by blast

lemma perp_not_col:
  assumes "A B Perp P A"
  shows "¬ Col A B P"
proof -
  have "A PerpAt A B P A"
    using assms perp_perp_in by auto
  hence "Per P A B"
    by (simp add: perp_in_per perp_in_sym)
  hence "¬ Col B A P"
    by (metis NCol_perm perp_not_eq_1 perp_not_eq_2 assms per_not_col)
  thus ?thesis
    using Col_perm by blast
qed

lemma perp_in_col_perp_in:
  assumes "C  E" and
    "Col C D E" and
    "P PerpAt A B C D"
  shows "P PerpAt A B C E"
proof -
  have "C  D"
    using assms(3) perp_in_distinct by blast
  have "Col P C D"
    using PerpAt_def assms(3) by blast
  hence "Col P C E" 
    using C  D assms(2) col_trivial_2 colx by blast
  moreover
  {
    fix U V 
    assume "Col U A B" and "Col V C E" 
    hence "Per U P V"
      by (metis PerpAt_def assms(1) assms(2) assms(3) col_permutation_1 col_trivial_2 colx)
  }
  ultimately
  show ?thesis 
    using PerpAt_def assms(1) assms(3) by presburger
qed

lemma perp_col2_bis:
  assumes "A B Perp C D" and
    "Col C D P" and
    "Col C D Q" and
    "P  Q"
  shows "A B Perp P Q"
  using Perp_cases assms(1) assms(2) assms(3) assms(4) perp_col0 by blast

lemma perp_in_perp_bis_R1:
  assumes "X  A" and
    "X PerpAt A B C D"
  shows "X B Perp C D  A X Perp C D"
  by (metis assms(2) l8_14_2_1a perp_col perp_in_col)

lemma perp_in_perp_bis:
  assumes "X PerpAt A B C D"
  shows "X B Perp C D  A X Perp C D"
  by (metis assms l8_14_2_1a perp_in_perp_bis_R1)

lemma col_per_perp:
  assumes "A  B" and
    "B  C" and
    (*   "D ≠ B" and  *)
    "D  C" and
    "Col B C D" and
    "Per A B C"
  shows "C D Perp A B"
  by (metis Perp_cases assms(1) assms(2) assms(3) assms(4) assms(5) col_trivial_2 
      per_perp perp_col2_bis)

lemma per_cong_mid_R1:
  assumes "B = H" and
    (*  "B ≠ C" and *)
    "Bet A B C" and
    "Cong A H C H" and
    "Per H B C"
  shows "B Midpoint A C"
  using assms(1) assms(2) assms(3) midpoint_def not_cong_1243 by blast

lemma per_cong_mid_R2:
  assumes (*"B ≠ H" and *)
    "B  C" and
    "Bet A B C" and
    "Cong A H C H" and
    "Per H B C"
  shows "B Midpoint A C"
proof -
  have P1: "Per C B H"
    using Per_cases assms(4) by blast
  have P2: "Per H B A"
    using assms(1) assms(2) assms(4) bet_col col_permutation_1 per_col by blast
  hence P3: "Per A B H"
    using Per_cases by blast
  obtain C' where P4: "B Midpoint C C'  Cong H C H C'"
    using Per_def assms(4) by blast
  obtain H' where P5: "B Midpoint H H'  Cong C H C H'"
    using P1 Per_def by blast
  obtain A' where P6: "B Midpoint A A'  Cong H A H A'"
    using P2 Per_def by blast
  obtain H'' where P7: "B Midpoint H H''  Cong A H A H'"
    using P3 P5 Per_def Tarski_neutral_dimensionless_axioms symmetric_point_uniqueness 
    by fastforce
  hence P8: "H' = H''"
    using P5 symmetric_point_uniqueness by blast
  have "H B H' A IFSC H B H' C"
  proof -
    have Q1: "Bet H B H'"
      by (simp add: P7 P8 midpoint_bet)
    have Q2: "Cong H H' H H'"
      by (simp add: cong_reflexivity)
    have Q3: "Cong B H' B H'"
      by (simp add: cong_reflexivity)
    have Q4: "Cong H A H C"
      using assms(3) not_cong_2143 by blast
    have "Cong H' A H' C"
      using P5 P7 assms(3) cong_commutativity cong_inner_transitivity by blast
    thus ?thesis
      by (simp add: IFSC_def Q1 Q2 Q3 Q4)
  qed
  thus ?thesis
    using assms(1) assms(2) bet_col bet_neq23__neq l4_2 l7_20_bis by auto
qed

lemma per_cong_mid:
  assumes "B  C" and
    "Bet A B C" and
    "Cong A H C H" and
    "Per H B C"
  shows "B Midpoint A C"
  using assms(1) assms(2) assms(3) assms(4) per_cong_mid_R1 per_cong_mid_R2 by blast

lemma per_double_cong:
  assumes "Per A B C" and
    "B Midpoint C C'"
  shows "Cong A C A C'"
  using Mid_cases Per_def assms(1) assms(2) l7_9_bis by blast

lemma cong_perp_or_mid_R1:
  assumes "Col A B X" and
    "A  B" and
    "M Midpoint A B" and
    "Cong A X B X"
  shows "X = M  ¬ Col A B X  M PerpAt X M A B"
  using assms(1) assms(2) assms(3) assms(4) col_permutation_5 cong_commutativity l7_17_bis 
    l7_2 l7_20 by blast

lemma cong_perp_or_mid_R2:
  assumes "¬ Col A B X" and
    "A  B" and
    "M Midpoint A B" and
    "Cong A X B X"
  shows "X = M  ¬ Col A B X  M PerpAt X M A B"
proof -
  have P1: "Col M A B"
    by (simp add: assms(3) midpoint_col)
  have "Per X M A"
    using Per_def assms(3) assms(4) cong_commutativity by blast
  thus ?thesis
    by (metis P1 assms(1) assms(2) assms(3) midpoint_distinct_1 not_col_permutation_4 
        per_perp_in perp_in_col_perp_in perp_in_right_comm)
qed

lemma cong_perp_or_mid:
  assumes "A  B" and
    "M Midpoint A B" and
    "Cong A X B X"
  shows "X = M  ¬ Col A B X  M PerpAt X M A B"
  using assms(1) assms(2) assms(3) cong_perp_or_mid_R1 cong_perp_or_mid_R2 by blast

lemma col_per2_cases:
  assumes "B  C" and
    "B'  C" and
    "C  D" and
    "Col B C D" and
    "Per A B C" and
    "Per A B' C"
  shows  "B = B'  ¬ Col B' C D"
  by (meson l8_7 Tarski_neutral_dimensionless_axioms assms(1) assms(2) assms(3) assms(4) 
      assms(5) assms(6) l6_16_1 per_col)

lemma l8_16_1:
  assumes "Col A B X" and
    "Col A B U" and
    "A B Perp C X"
  shows "¬ Col A B C  Per C X U"
  by (metis assms(1) assms(2) assms(3) l8_5 perp_col0 perp_left_comm perp_not_col2 perp_per_2)

lemma l8_16_2:
  assumes "Col A B X" and
    "Col A B U" and 
    "U  X" and
    "¬ Col A B C" and
    "Per C X U"
  shows "A B Perp C X"
proof -
  obtain X where "X PerpAt A B C X"
    by (metis NCol_perm assms(1) assms(2) assms(3) assms(4) assms(5) l8_13_2 l8_2 
        not_col_distincts)
  thus ?thesis 
    by (metis Perp_perm per_col assms(1) assms(2) assms(3) assms(4) assms(5) col3 col_per_perp
        not_col_distincts)
qed

lemma l8_18_uniqueness:
  assumes (*"¬ Col A B C" and *)
    "Col A B X" and
    "A B Perp C X" and
    "Col A B Y" and
    "A B Perp C Y"
  shows "X = Y"
  using assms(1) assms(2) assms(3) assms(4) l8_16_1 l8_7 by blast

lemma midpoint_distinct:
  assumes "¬ Col A B C" and
    "Col A B X" and
    "X Midpoint C C'"
  shows "C  C'"
  using assms(1) assms(2) assms(3) l7_3 by auto

lemma l8_20_1_R1:
  assumes "A = B"
  shows "Per B A P"
  by (simp add: assms l8_2 l8_5)

lemma l8_20_1_R2:
  assumes "A  B" and
    "Per A B C" and
    "P Midpoint C' D" and
    "A Midpoint C' C" and
    "B Midpoint D C"
  shows "Per B A P"
proof -
  obtain B' where P1: "A Midpoint B B'"
    using symmetric_point_construction by blast
  obtain D' where P2: "A Midpoint D D'"
    using symmetric_point_construction by blast
  obtain P' where P3: "A Midpoint P P'"
    using symmetric_point_construction by blast
  have P4: "Per B' B C"
    by (metis P1 Per_cases per_col assms(1) assms(2) midpoint_col not_col_permutation_4)
  have P5: "Per B B' C'"
  proof -
    have "Per B' B C"
      by (simp add: P4)
    have "B' B C Cong3 B B' C'"
      by (meson Cong3_def P1 assms(4) l7_13 l7_2)
    thus ?thesis
      using P4 l8_10 by blast
  qed
  have P6: "B' Midpoint D' C'"
    by (meson P1 P2 assms(4) assms(5) l7_15 l7_16 l7_2 midpoint_bet midpoint_cong midpoint_def)
  have P7: "P' Midpoint C D'"
    using P2 P3 assms(3) assms(4) symmetry_preserves_midpoint by blast
  have P8: "A Midpoint P P'"
    by (simp add: P3)
  obtain D'' where P9: "B Midpoint C D''  Cong B' C B' D"
    using P4 assms(5) l7_2 per_double_cong by blast
  have P10: "D'' = D"
    using P9 assms(5) l7_9_bis by blast
  obtain D'' where P11: "B' Midpoint C' D''  Cong B C' B D''"
    using P5 Per_def by blast
  have P12: "D' = D''"
    by (meson P11 P6 l7_9_bis Tarski_neutral_dimensionless_axioms)
  have P13: "P Midpoint C' D"
    using assms(3) by blast
  have P14: "Cong C D C' D'"
    using P2 assms(4) l7_13 l7_2 by blast
  have P15: "Cong C' D C D'"
    using P2 assms(4) cong_4321 l7_13 by blast
  have P16: "Cong P D P' D'"
    using P2 P8 cong_symmetry l7_13 by blast
  have P17: "Cong P D P' C"
    using P16 P7 cong_3421 cong_transitivity midpoint_cong by blast
  have P18: "C' P D B IFSC D' P' C B"
    by (metis Bet_cases IFSC_def P10 P11 P12 P13 P15 P17 P7 P9 cong_commutativity 
        cong_right_commutativity l7_13 l7_3_2 midpoint_bet)
  hence "Cong B P B P'"
    using l4_2 Tarski_neutral_dimensionless_axioms not_cong_2143 by fastforce
  thus ?thesis
    using P8 Per_def by blast
qed

lemma l8_20_1:
  assumes "Per A B C" and
    "P Midpoint C' D" and
    "A Midpoint C' C" and
    "B Midpoint D C"
  shows "Per B A P"
  using assms(1) assms(2) assms(3) assms(4) l8_20_1_R1 l8_20_1_R2 by fastforce

lemma l8_20_2:
  assumes "P Midpoint C' D" and
    "A Midpoint C' C" and
    "B Midpoint D C" and
    "B  C"
  shows "A  P"
  using assms(1) assms(2) assms(3) assms(4) l7_3 symmetric_point_uniqueness by blast

lemma perp_col1:
  assumes "C  X" and
    "A B Perp C D" and
    "Col C D X"
  shows "A B Perp C X"
  using assms(1) assms(2) assms(3) col_trivial_3 perp_col2_bis by blast

lemma l8_18_existence:
  assumes "¬ Col A B C"
  shows " X. Col A B X  A B Perp C X"
proof -
  obtain Y where "Bet B A Y" and "Cong A Y A C"
    using segment_construction by blast
  then obtain P where "P Midpoint C Y"
    using Mid_cases l7_25 by blast
  hence "Per A P Y" 
    using Per_def Cong A Y A C l7_2 by blast
  obtain Z where "Bet A Y Z" and "Cong Y Z Y P" 
    using segment_construction by blast
  obtain Q where "Bet P Y Q" and "Cong Y Q Y A"
    using segment_construction by blast
  obtain Q' where "Bet Q Z Q'" and "Cong Z Q' Q Z"
    using segment_construction by blast
  hence "Z Midpoint Q Q'"
    using midpoint_def not_cong_3412 by blast
  obtain C' where "Bet Q' Y C'" and "Cong Y C' Y C"
    using segment_construction by blast
  obtain X where "X Midpoint C C'" 
    using Cong Y C' Y C l7_2 l7_25 by blast
  have "A Y Z Q OFSC Q Y P A" 
    by (simp add: OFSC_def Bet A Y Z Bet P Y Q Cong Y Q Y A Cong Y Z Y P 
        between_symmetry cong_4321 cong_pseudo_reflexivity)
  have "A  Y" 
    using Cong A Y A C assms is_midpoint_id l7_20 not_col_distincts by blast
  hence "Cong Z Q P A" 
    using A Y Z Q OFSC Q Y P A five_segment_with_def by auto
  hence "A P Y Cong3 Q Z Y" 
    using Cong3_def Cong_cases Cong Y Q Y A Cong Y Z Y P by blast
  hence "Per Q Z Y" 
    using Per A P Y l8_10 by blast
  hence "Per Y Z Q" 
    using l8_2 by blast
  have "P  Y" 
    by (metis Col_def Bet B A Y P Midpoint C Y assms between_symmetry midpoint_not_midpoint)
  obtain Q'' where "Z Midpoint Q Q''" and "Cong Y Q Y Q'" 
    using Per Y Z Q Z Midpoint Q Q' per_double_cong by force
  hence "Q' = Q''" 
    by (meson symmetric_point_uniqueness Z Midpoint Q Q')
  have "Bet Q Y C" 
    by (metis midpoint_bet Bet P Y Q P Midpoint C Y P  Y between_symmetry 
        outer_transitivity_between2)
  hence "Bet Z Y X"
    by (meson l7_22 Bet Q' Y C' Cong Y C' Y C Cong Y Q Y Q' X Midpoint C C' 
        Z Midpoint Q Q' cong_symmetry)
  have "Q  Y" 
    using A  Y Cong Y Q Y A cong_reverse_identity by blast
  have "Bet C P Y" 
    using Midpoint_def P Midpoint C Y by auto
  hence "Per Y X C"
    using Per_def Cong Y C' Y C X Midpoint C C' cong_inner_transitivity 
      cong_reflexivity by blast
  moreover
  have "Col P Y Q" 
    by (simp add: Col_def Bet P Y Q)
  have "Col P Y C" 
    by (simp add: Col_def Bet C P Y)
  have "Col P Q C" 
    using Col P Y C Col P Y Q P  Y col_transitivity_1 by blast
  have "Col Y Q C" 
    using Bet_cases Col_def Bet Q Y C by auto
  have "Col A Y B" 
    by (simp add: Col_def Bet B A Y)
  moreover
  have "Col A Y Z" 
    using Col_def Bet A Y Z by blast
  have "Col A B Z" 
    using A  Y Col A Y B Col A Y Z col_transitivity_1 by blast
  have "Col Y B Z" 
    using A  Y Col A Y B Col A Y Z col_transitivity_2 by blast
  have "Col Q Y P" 
    using Col_cases Col P Y Q by blast
  have "Q  C" 
    using Bet Q Y C Q  Y between_identity by blast
  have "Col Y Q' C'" 
    using Col_cases Col_def Bet Q' Y C' by blast
  {
    assume "Q = Q'"
    hence "Col P B C" 
      by (metis cong_reverse_identity Col A Y B Col P Y C Cong Z Q P A P  Y 
          Q' = Q'' Z Midpoint Q Q'' col_transitivity_1 midpoint_distinct_2)
    moreover have "¬ Col P B C" 
      by (metis Q = Q' Bet Q Z Q' Cong Z Q P A assms bet_neq12__neq cong_diff_3)
    ultimately have False 
      by blast
  }
  hence "C  C'" 
    by (metis between_cong_3 Bet Q Y C Bet Q' Y C' Cong Y Q Y Q' P Midpoint C Y 
        P  Y between_symmetry midpoint_distinct_3)
  have "Q Y C Z OFSC Q' Y C' Z" 
    by (simp add: OFSC_def Bet Q Y C Bet Q' Y C' Cong Y C' Y C Cong Y Q Y Q' 
        Cong Z Q' Q Z cong_3421 cong_reflexivity cong_symmetry)
  hence "Cong C Z C' Z" 
    using Q  Y five_segment_with_def by force
  have "Col Z Y X" 
    using Col_def Bet Z Y X by blast
  have "Y  Z" 
    using Cong Y Z Y P P  Y cong_diff_4 by blast
  {
    assume "X = Y"
    hence "C'  Y" 
      using C  C' Cong Y C' Y C cong_reverse_identity by blast
    have "Col Y C' P" 
      by (metis Col_def Midpoint_def Bet C P Y X = Y X Midpoint C C' between_equality_2 
          col_transitivity_1 not_bet_distincts)
    hence "Col Y P Q'" 
      by (metis C'  Y Col Y Q' C' col_trivial_3 colx not_col_permutation_5)
    hence "Col Y Q Q'" 
      by (meson Col P Y Q P  Y colx not_col_distincts not_col_permutation_5)
    hence False 
      using l7_20 Cong Y Q Y Q' Q = Q'  False Q' = Q'' Y  Z 
        Z Midpoint Q Q'' col_permutation_4 l7_17 by blast
  }
  hence "X  Y" 
    by auto
  moreover have "Col A B X" 
    by (meson Col A Y Z Col Y B Z Col Z Y X Y  Z col3 col_permutation_3 
        not_col_permutation_1)
  ultimately show ?thesis 
    by (metis Col_cases l8_2 assms l8_16_2)
qed

lemma l8_21_aux:
  assumes "¬ Col A B C"
  shows " P.  T. (A B Perp P A  Col A B T  Bet C T P)"
proof -
  obtain X where "Col A B X" and "A B Perp C X"
    using assms l8_18_existence by blast
  hence "X PerpAt A B C X"
    by (simp add: l8_15_1)
  have "Per A X C" 
    using PerpAt_def X PerpAt A B C X col_trivial_1 by presburger
  obtain C' where "X Midpoint C C'" and "Cong A C A C'" 
    using Per_def Per A X C by auto
  obtain C'' where "A Midpoint C C''"
    using symmetric_point_construction by blast
  obtain P where "P Midpoint C' C''" 
    by (metis Cong_cases A Midpoint C C'' Cong A C A C' cong_inner_transitivity 
        l7_25 midpoint_cong)
  have "Per X A P" 
  proof -
    have "P Midpoint C'' C'" 
      using P Midpoint C' C'' l7_2 by blast
    moreover have "A Midpoint C'' C" 
      using A Midpoint C C'' l7_2 by blast
    moreover have "X Midpoint C' C" 
      by (simp add: X Midpoint C C' l7_2)
    ultimately show ?thesis 
      using Per A X C l8_20_1 by blast
  qed
  have "X  C" 
    using Col A B X assms by blast
  hence "A  P" 
    using A Midpoint C C'' P Midpoint C' C'' X Midpoint C C' l7_9 midpoint_distinct_2 
    by blast
  have " T. Bet P T C  Bet A T X"
  proof -
    have "Bet C'' A C" 
      using Mid_cases A Midpoint C C'' midpoint_bet by blast
    moreover have "Bet C' X C" 
      using Bet_cases Midpoint_def X Midpoint C C' by auto
    moreover have "Bet C'' P C'" 
      using P Midpoint C' C'' between_symmetry midpoint_bet by blast
    ultimately show ?thesis 
      using l3_17 by fastforce
  qed
  then obtain T where "Bet P T C" and "Bet A T X" 
    by blast
  show ?thesis
  proof cases
    assume "A = X"
    thus ?thesis 
      by (metis Bet_perm between_identity midpoint_col midpoint_not_midpoint perp_col1 
          A B Perp C X A Midpoint C C'' Bet A T X Bet P T C Col A B X 
          P Midpoint C' C'' X Midpoint C C' l8_20_2 perp_comm)
  next
    assume "A  X"
    have "A B Perp P A" 
      by (metis col3 l8_2 per_not_col A  P A  X Col A B X Per X A P 
          assms l8_16_2 not_col_distincts)
    moreover have "Col A B T" 
      by (metis Col_def A  X Bet A T X Col A B X col_transitivity_2)
    moreover have "Bet C T P" 
      using Bet_cases Bet P T C by blast
    ultimately show ?thesis 
      by blast
  qed
qed

lemma l8_21:
  assumes "A  B"
  shows " P T. A B Perp P A  Col A B T  Bet C T P"
  by (meson assms between_trivial2 l8_21_aux not_col_exists)

lemma per_cong:
  assumes "A  B" and
    "A  P" and
    "Per B A P" and
    "Per A B R" and
    "Cong A P B R" and
    "Col A B X" and
    "Bet P X R"
  shows "Cong A R P B"
proof -
  have "Per P A B"
    using Per_cases assms(3) by blast
  obtain Q where "R Midpoint B Q"
    using symmetric_point_construction by auto
  have "B  R"
    using assms(2) assms(5) cong_identity by blast
  hence "Per A B Q" 
    using Col_def Midpoint_def R Midpoint B Q assms(4) per_col by blast
  have "Per P A X" 
    using Per P A B assms(1) assms(6) per_col by blast
  have "B  Q" 
    using B  R R Midpoint B Q l7_3 by blast
  have "Per R B X" 
    by (metis col_permutation_4 per_col assms(1) assms(4) assms(6) l8_2)
  have "X  A" 
    using B  R assms(1) assms(2) assms(3) assms(4) assms(7) bet_col per_not_colp by blast
  obtain P' where "A Midpoint P P'" 
    using Per_def assms(3) by blast
  obtain R' where "Bet P' X R'" and "Cong X R' X R"   
    using segment_construction by blast
  obtain M where "M Midpoint R R'"
    using Cong X R' X R l7_2 l7_25 by blast
  have "Per X M R" 
    by (metis Per_def Cong X R' X R M Midpoint R R' cong_symmetry)
  have "Cong X P X P'" 
    using Per_cases A Midpoint P P' Per P A X per_double_cong by blast
  have "X  P'" 
    using Cong X P X P' Per P A X assms(2) cong_identity l8_8 by blast
  have "P  P'" 
    using A Midpoint P P' assms(2) l7_3 by blast
  have "¬ Col X P P'" 
    using A Midpoint P P' Cong X P X P' P  P' X  A col_permutation_4 l7_17 l7_20 
    by blast
  have "Bet A X M" 
    by (meson A Midpoint P P' Bet P' X R' Cong X P X P' Cong X R' X R M Midpoint R R' 
        assms(7) cong_symmetry l7_22)
  have "X  R" 
    using B  R Per R B X l8_8 by blast
  have "X  R'" 
    using Cong X R' X R X  R cong_diff_3 by blast
  {
    assume "X = M"
    have "Col X P P'" 
    proof -
      have "Col X R P" 
        using Col_def assms(7) by blast
      moreover have "Col X R P'" 
        by (metis Col_def Bet P' X R' M Midpoint R R' X = M X  R' 
            col_transitivity_1 midpoint_col)
      ultimately show ?thesis 
        using X  R col_transitivity_1 by blast
    qed
    hence False 
      by (simp add: ¬ Col X P P')
  }
  have "M = B" 
  proof -
    have "¬ Col A X R" 
      by (metis B  R X  A assms(1) assms(4) assms(6) col_trivial_3 colx per_not_col)
    moreover have "Col A X M" 
      using Col_def Bet A X M by auto
    moreover have "A X Perp R M" 
      by (metis Col_cases Per_cases Per X M R X = M  False X  A calculation(1) 
          calculation(2) col_per_perp perp_left_comm)
    moreover have "Col A X B" 
      using Col_cases assms(6) by blast
    moreover have "A X Perp R B" 
      by (metis Col_cases Per_cases B  R X  A assms(1) assms(4) assms(6) col_per_perp)
    ultimately show ?thesis 
      using l8_18_uniqueness by blast
  qed
  have "P X R P' OFSC P' X R' P" 
    using Cong_cases OFSC_def Bet P' X R' Cong X P X P' Cong X R' X R assms(7) 
      cong_pseudo_reflexivity by auto
  hence "Cong R P' R' P" 
    using ¬ Col X P P' five_segment_with_def not_col_distincts by blast
  have "P' A P R IFSC R' B R P"
  proof -
    have "M = B"
      using M = B by auto
    then have "B Midpoint R R'"
      using M Midpoint R R' by blast
    then show ?thesis
      by (smt (z3) Bet_cases Cong_cases IFSC_def Midpoint_def A Midpoint P P' 
          Cong R P' R' P assms(5) cong_mid2__cong cong_pseudo_reflexivity)
  qed
  thus ?thesis
    using l4_2 not_cong_1243 by blast
qed

lemma perp_cong:
  assumes "A  B" and
    "A  P" and
    "A B Perp P A" and
    "A B Perp R B" and
    "Cong A P B R" and
    "Col A B X" and
    "Bet P X R"
  shows "Cong A R P B"
  using Perp_cases assms(1) assms(2) assms(3) assms(4) assms(5) assms(6) assms(7) per_cong 
    perp_per_1 by blast

lemma perp_exists:
  assumes "A  B"
  shows " X. PO X Perp A B"
proof cases
  assume "Col A B PO"
  then obtain C where "A  C" and "B  C" and "PO  C" and "Col A B C"
    using diff_col_ex3 by blast
  then obtain P T where "PO C Perp P PO" and "Col PO C T" and "Bet PO T P" 
    using l8_21 by blast
  hence "PO P Perp A B" 
    by (metis Perp_perm col_transitivity_2 Col A B C Col A B PO assms 
        not_col_permutation_2 perp_col0)
  thus ?thesis
    by blast
next
  assume "¬ Col A B PO"
  thus ?thesis 
    using l8_18_existence assms col_trivial_2 col_trivial_3 l8_18_existence perp_col0 by blast
qed

lemma perp_vector:
  assumes "A  B"
  shows " X Y. A B Perp X Y"
  using assms l8_21 by blast

lemma midpoint_existence_aux:
  assumes "A  B" and
    "A B Perp Q B" and
    "A B Perp P A" and
    "Col A B T" and
    "Bet Q T P" and
    "A P Le B Q"
  shows " X. X Midpoint A B"
proof -
  obtain R where "Bet B R Q" and "Cong A P B R"
    using Le_def assms(6) by blast
  obtain X where "Bet T X B" and "Bet R X P" 
    by (meson Bet B R Q assms(5) between_symmetry inner_pasch)
  have "Col A B X" 
    by (metis Col_def Bet T X B assms(4) between_equality_2 between_trivial2 col2__eq)
  have "B  R"
    using Cong A P B R assms(3) cong_identity perp_not_eq_2 by blast
  have "¬ Col A B Q" 
    using Col_cases Perp_cases assms(2) perp_not_col by blast
  have "¬ Col A B R" 
    using Col_def B  R Bet B R Q ¬ Col A B Q l6_16_1 by blast
  have "P  R" 
    using Bet R X P Col A B X ¬ Col A B R between_identity by blast
  have " X. X Midpoint A B"
  proof cases
    assume "A = P"
    thus ?thesis
      using assms(3) col_trivial_3 perp_not_col2 by blast
  next
    assume "¬ A = P"
    have "A B Perp R B" 
      by (metis Col_def B  R Bet B R Q assms(2) not_col_distincts perp_col2_bis)
    hence "Cong A R P B" 
      using A  P Bet R X P Col A B X Cong A P B R assms(1) assms(3) 
        between_symmetry perp_cong by blast
    hence "X Midpoint A B  X Midpoint P R" 
      by (meson Bet R X P Col A B X Cong A P B R P  R assms(3) bet_col 
          between_symmetry cong_4312 l7_2 l7_21 not_col_permutation_2 perp_not_col)
    thus ?thesis
      by blast
  qed
  thus ?thesis by blast
qed

lemma midpoint_existence:
  " X. X Midpoint A B"
proof cases
  assume "A = B"
  thus ?thesis
    using l7_3_2 by blast
next
  assume P1: "¬ A = B"
  obtain Q where P2: "A B Perp B Q"
    by (metis P1 l8_21 perp_comm)
  obtain P T where P3: "A B Perp P A  Col A B T  Bet Q T P"
    using P2 l8_21_aux not_col_distincts perp_not_col2 by blast
  have P4: "A P Le B Q  B Q Le A P"
    by (simp add: local.le_cases)
  have P5: "A P Le B Q  ( X. X Midpoint A B)"
    by (meson P1 P2 P3 Perp_cases midpoint_existence_aux Tarski_neutral_dimensionless_axioms)
  have P6: "B Q Le A P  ( X. X Midpoint A B)"
  proof -
    {
      assume H1: "B Q Le A P"
      have Q6: "B  A"
        using P1 by auto
      have Q2: "B A Perp P A"
        by (simp add: P3 perp_left_comm)
      have Q3: "B A Perp Q B"
        using P2 Perp_perm by blast
      have Q4: "Col B A T"
        using Col_perm P3 by blast
      have Q5: "Bet P T Q"
        using Bet_perm P3 by blast
      obtain X where "X Midpoint B A"
        using H1 Q2 Q3 Q4 Q5 Q6 midpoint_existence_aux by blast
      hence " X. X Midpoint A B"
        using l7_2 by blast
    }
    thus ?thesis
      by simp
  qed
  thus ?thesis
    using P4 P5 by blast
qed

lemma MidR_uniq_aux:
  shows "∃!x. x Midpoint A B"
  using l7_17_bis midpoint_existence by blast

lemma SymR_uniq_aux:
  assumes "B Midpoint A x" and
    "B Midpoint A y"
  shows "x = y"
  using assms(1) assms(2) symmetric_point_uniqueness by auto

lemma perp_in_id:
  assumes "X PerpAt A B C A"
  shows "X = A"
  by (meson Col_cases assms col_trivial_3 l8_14_2_1b)

lemma l8_22:
  assumes "A  B" and
    "A  P" and
    "Per B A P" and
    "Per A B R" and
    "Cong A P B R" and
    "Col A B X" and
    "Bet P X R" and
    "Cong A R P B"
  shows "X Midpoint A B  X Midpoint P R"
  by (metis assms(1) assms(2) assms(3) assms(4) assms(5) assms(6) assms(7) assms(8) 
      bet_col cong_commutativity cong_diff cong_right_commutativity l7_21 
      not_col_permutation_5 per_not_colp)

lemma l8_22_bis:
  assumes "A  B" and
    "A  P" and
    "A B Perp P A" and
    "A B Perp R B" and
    "Cong A P B R" and
    "Col A B X" and
    "Bet P X R"
  shows "Cong A R P B  X Midpoint A B  X Midpoint P R"
  by (metis l8_22 Perp_cases assms(1) assms(2) assms(3) assms(4) assms(5) assms(6) 
      assms(7) perp_cong perp_per_2)

lemma perp_in_perp:
  assumes "X PerpAt A B C D"
  shows "A B Perp C D"
  using assms l8_14_2_1a by auto

lemma perp_proj:
  assumes "A B Perp C D" and
    "¬ Col A C D"
  shows " X. Col A B X  A X Perp C D"
  using assms(1) not_col_distincts by auto

lemma l8_24 :
  assumes "P A Perp A B" and
    "Q B Perp A B" and
    "Col A B T" and
    "Bet P T Q" and
    "Bet B R Q" and
    "Cong A P B R"
  shows " X. X Midpoint A B  X Midpoint P R"
proof -
  obtain X where P1: "Bet T X B  Bet R X P"
    using assms(4) assms(5) inner_pasch by blast
  have P2: "Col A B X"
    by (metis Out_cases P1 assms(3) bet_out_1 col_out2_col not_col_distincts out_trivial)
  have P3: "A  B"
    using assms(1) col_trivial_2 l8_16_1 by blast
  have P4: "A  P"
    using assms(1) col_trivial_1 l8_16_1 by blast
  have " X. X Midpoint A B  X Midpoint P R"
  proof cases
    assume "Col A B P"
    thus ?thesis
      using Perp_perm assms(1) perp_not_col by blast
  next
    assume Q1: "¬ Col A B P"
    have Q2: "B  R"
      using P4 assms(6) cong_diff by blast
    have Q3: "Q  B"
      using Q2 assms(5) between_identity by blast
    have Q4: "¬ Col A B Q"
      by (metis assms(2) col_permutation_3 l8_14_1 perp_col1 perp_not_col)
    have Q5: "¬ Col A B R"
      by (meson Q2 Q4 assms(5) bet_col col_transitivity_1 not_col_permutation_2)
    have Q6: "P  R"
      using P1 P2 Q5 between_identity by blast
    have " X. X Midpoint A B  X Midpoint P R"
    proof cases
      assume "A = P"
      thus ?thesis
        using P4 by blast
    next
      assume R0: "¬ A = P"
      have R1: "A B Perp R B"
        by (metis Perp_cases Q2 bet_col1 assms(2) assms(5) bet_col col_transitivity_1 perp_col1)
      have R2: "Cong A R P B"
        using P1 P2 P3 Perp_perm R0 R1 assms(1) assms(6) between_symmetry perp_cong by blast
      have R3: "¬ Col A P B"
        using Col_perm Q1 by blast
      have R4: "P  R"
        by (simp add: Q6)
      have R5: "Cong A P B R"
        by (simp add: assms(6))
      have R6: "Cong P B R A"
        using R2 not_cong_4312 by blast
      have R7: "Col A X B"
        using Col_perm P2 by blast
      have R8: "Col P X R"
        by (simp add: P1 bet_col between_symmetry)
      thus ?thesis using l7_21
        using R3 R4 R5 R6 R7 by blast
    qed
    thus ?thesis by simp
  qed
  thus ?thesis
    by simp
qed

lemma col_per2__per:
  assumes "A  B" and
    "Col A B C" and
    "Per A X P" and
    "Per B X P"
  shows "Per C X P"
  by (meson Per_def assms(1) assms(2) assms(3) assms(4) l4_17 per_double_cong)

lemma perp_in_per_1:
  assumes "X PerpAt A B C D"
  shows "Per A X C"
  using PerpAt_def assms col_trivial_1 by auto

lemma perp_in_per_2:
  assumes "X PerpAt A B C D"
  shows "Per A X D"
  using assms perp_in_per_1 perp_in_right_comm by blast

lemma perp_in_per_3:
  assumes "X PerpAt A B C D"
  shows "Per B X C"
  using assms perp_in_comm perp_in_per_2 by blast

lemma perp_in_per_4:
  assumes "X PerpAt A B C D"
  shows "Per B X D"
  using assms perp_in_per_3 perp_in_right_comm by blast

lemma coplanar_perm_1:
  assumes "Coplanar A B C D"
  shows "Coplanar A B D C"
proof -
  obtain X where "(Col A B X  Col C D X)  (Col A C X  Col B D X)  (Col A D X  Col B C X)"
    using Coplanar_def assms by blast
  thus ?thesis
    using Coplanar_def col_permutation_4 by blast
qed

lemma coplanar_perm_2:
  assumes "Coplanar A B C D"
  shows "Coplanar A C B D"
proof -
  obtain X where "(Col A B X  Col C D X)  (Col A C X  Col B D X)  (Col A D X  Col B C X)"
    using Coplanar_def assms by blast
  thus ?thesis
    using Coplanar_def col_permutation_4 by blast
qed

lemma coplanar_perm_3:
  assumes "Coplanar A B C D"
  shows "Coplanar A C D B"
proof -
  obtain X where "(Col A B X  Col C D X)  (Col A C X  Col B D X)  (Col A D X  Col B C X)"
    using Coplanar_def assms by blast
  thus ?thesis
    using Coplanar_def col_permutation_4 by blast
qed

lemma coplanar_perm_4:
  assumes "Coplanar A B C D"
  shows "Coplanar A D B C"
proof -
  obtain X where "(Col A B X  Col C D X)  (Col A C X  Col B D X)  (Col A D X  Col B C X)"
    using Coplanar_def assms by blast
  thus ?thesis
    using Coplanar_def col_permutation_4 by blast
qed

lemma coplanar_perm_5:
  assumes "Coplanar A B C D"
  shows "Coplanar A D C B"
proof -
  obtain X where "(Col A B X  Col C D X)  (Col A C X  Col B D X)  (Col A D X  Col B C X)"
    using Coplanar_def assms by blast
  thus ?thesis
    using Coplanar_def col_permutation_4 by blast
qed

lemma coplanar_perm_6:
  assumes "Coplanar A B C D"
  shows "Coplanar B A C D"
proof -
  obtain X where "(Col A B X  Col C D X)  (Col A C X  Col B D X)  (Col A D X  Col B C X)"
    using Coplanar_def assms by blast
  thus ?thesis
    using Coplanar_def col_permutation_4 by blast
qed

lemma coplanar_perm_7:
  assumes "Coplanar A B C D"
  shows "Coplanar B A D C"
proof -
  obtain X where "(Col A B X  Col C D X)  (Col A C X  Col B D X)  (Col A D X  Col B C X)"
    using Coplanar_def assms by blast
  thus ?thesis
    using Coplanar_def col_permutation_4 by blast
qed

lemma coplanar_perm_8:
  assumes "Coplanar A B C D"
  shows "Coplanar B C A D"
proof -
  obtain X where "(Col A B X  Col C D X)  (Col A C X  Col B D X)  (Col A D X  Col B C X)"
    using Coplanar_def assms by blast
  thus ?thesis
    using Coplanar_def col_permutation_4 by blast
qed

lemma coplanar_perm_9:
  assumes "Coplanar A B C D"
  shows "Coplanar B C D A"
proof -
  obtain X where "(Col A B X  Col C D X)  (Col A C X  Col B D X)  (Col A D X  Col B C X)"
    using Coplanar_def assms by blast
  thus ?thesis
    using Coplanar_def col_permutation_4 by blast
qed

lemma coplanar_perm_10:
  assumes "Coplanar A B C D"
  shows "Coplanar B D A C"
proof -
  obtain X where "(Col A B X  Col C D X)  (Col A C X  Col B D X)  (Col A D X  Col B C X)"
    using Coplanar_def assms by blast
  thus ?thesis
    using Coplanar_def col_permutation_4 by blast
qed

lemma coplanar_perm_11:
  assumes "Coplanar A B C D"
  shows "Coplanar B D C A"
proof -
  obtain X where "(Col A B X  Col C D X)  (Col A C X  Col B D X)  (Col A D X  Col B C X)"
    using Coplanar_def assms by blast
  thus ?thesis
    using Coplanar_def col_permutation_4 by blast
qed

lemma coplanar_perm_12:
  assumes "Coplanar A B C D"
  shows "Coplanar C A B D"
proof -
  obtain X where "(Col A B X  Col C D X)  (Col A C X  Col B D X)  (Col A D X  Col B C X)"
    using Coplanar_def assms by blast
  thus ?thesis
    using Coplanar_def col_permutation_4 by blast
qed

lemma coplanar_perm_13:
  assumes "Coplanar A B C D"
  shows "Coplanar C A D B"
proof -
  obtain X where "(Col A B X  Col C D X)  (Col A C X  Col B D X)  (Col A D X  Col B C X)"
    using Coplanar_def assms by blast
  thus ?thesis
    using Coplanar_def col_permutation_4 by blast
qed

lemma coplanar_perm_14:
  assumes "Coplanar A B C D"
  shows "Coplanar C B A D"
proof -
  obtain X where "(Col A B X  Col C D X)  (Col A C X  Col B D X)  (Col A D X  Col B C X)"
    using Coplanar_def assms by blast
  thus ?thesis
    using Coplanar_def col_permutation_4 by blast
qed

lemma coplanar_perm_15:
  assumes "Coplanar A B C D"
  shows "Coplanar C B D A"
proof -
  obtain X where "(Col A B X  Col C D X)  (Col A C X  Col B D X)  (Col A D X  Col B C X)"
    using Coplanar_def assms by blast
  thus ?thesis
    using Coplanar_def col_permutation_4 by blast
qed

lemma coplanar_perm_16:
  assumes "Coplanar A B C D"
  shows "Coplanar C D A B"
proof -
  obtain X where "(Col A B X  Col C D X)  (Col A C X  Col B D X)  (Col A D X  Col B C X)"
    using Coplanar_def assms by blast
  thus ?thesis
    using Coplanar_def col_permutation_4 by blast
qed

lemma coplanar_perm_17:
  assumes "Coplanar A B C D"
  shows "Coplanar C D B A"
proof -
  obtain X where "(Col A B X  Col C D X)  (Col A C X  Col B D X)  (Col A D X  Col B C X)"
    using Coplanar_def assms by blast
  thus ?thesis
    using Coplanar_def col_permutation_4 by blast
qed

lemma coplanar_perm_18:
  assumes "Coplanar A B C D"
  shows "Coplanar D A B C"
proof -
  obtain X where "(Col A B X  Col C D X)  (Col A C X  Col B D X)  (Col A D X  Col B C X)"
    using Coplanar_def assms by blast
  thus ?thesis
    using Coplanar_def col_permutation_4 by blast
qed

lemma coplanar_perm_19:
  assumes "Coplanar A B C D"
  shows "Coplanar D A C B"
proof -
  obtain X where "(Col A B X  Col C D X)  (Col A C X  Col B D X)  (Col A D X  Col B C X)"
    using Coplanar_def assms by blast
  thus ?thesis
    using Coplanar_def col_permutation_4 by blast
qed

lemma coplanar_perm_20:
  assumes "Coplanar A B C D"
  shows "Coplanar D B A C"
proof -
  obtain X where "(Col A B X  Col C D X)  (Col A C X  Col B D X)  (Col A D X  Col B C X)"
    using Coplanar_def assms by blast
  thus ?thesis
    using Coplanar_def col_permutation_4 by blast
qed

lemma coplanar_perm_21:
  assumes "Coplanar A B C D"
  shows "Coplanar D B C A"
proof -
  obtain X where "(Col A B X  Col C D X)  (Col A C X  Col B D X)  (Col A D X  Col B C X)"
    using Coplanar_def assms by blast
  thus ?thesis
    using Coplanar_def col_permutation_4 by blast
qed

lemma coplanar_perm_22:
  assumes "Coplanar A B C D"
  shows "Coplanar D C A B"
proof -
  obtain X where "(Col A B X  Col C D X)  (Col A C X  Col B D X)  (Col A D X  Col B C X)"
    using Coplanar_def assms by blast
  thus ?thesis
    using Coplanar_def col_permutation_4 by blast
qed

lemma coplanar_perm_23:
  assumes "Coplanar A B C D"
  shows "Coplanar D C B A"
proof -
  obtain X where "(Col A B X  Col C D X)  (Col A C X  Col B D X)  (Col A D X  Col B C X)"
    using Coplanar_def assms by blast
  thus ?thesis
    using Coplanar_def col_permutation_4 by blast
qed

lemma ncoplanar_perm_1:
  assumes "¬ Coplanar A B C D"
  shows "¬ Coplanar A B D C"
  using assms coplanar_perm_1 by blast

lemma ncoplanar_perm_2:
  assumes "¬ Coplanar A B C D"
  shows "¬ Coplanar A C B D"
  using assms coplanar_perm_2 by blast

lemma ncoplanar_perm_3:
  assumes "¬ Coplanar A B C D"
  shows "¬ Coplanar A C D B"
  using assms coplanar_perm_4 by blast

lemma ncoplanar_perm_4:
  assumes "¬ Coplanar A B C D"
  shows "¬ Coplanar A D B C"
  using assms coplanar_perm_3 by blast

lemma ncoplanar_perm_5:
  assumes "¬ Coplanar A B C D"
  shows "¬ Coplanar A D C B"
  using assms coplanar_perm_5 by blast

lemma ncoplanar_perm_6:
  assumes "¬ Coplanar A B C D"
  shows "¬ Coplanar B A C D"
  using assms coplanar_perm_6 by blast

lemma ncoplanar_perm_7:
  assumes "¬  Coplanar A B C D"
  shows "¬ Coplanar B A D C"
  using assms coplanar_perm_7 by blast

lemma ncoplanar_perm_8:
  assumes "¬ Coplanar A B C D"
  shows "¬ Coplanar B C A D"
  using assms coplanar_perm_12 by blast

lemma ncoplanar_perm_9:
  assumes "¬ Coplanar A B C D"
  shows "¬ Coplanar B C D A"
  using assms coplanar_perm_18 by blast

lemma ncoplanar_perm_10:
  assumes "¬ Coplanar A B C D"
  shows "¬ Coplanar B D A C"
  using assms coplanar_perm_13 by blast

lemma ncoplanar_perm_11:
  assumes "¬ Coplanar A B C D"
  shows "¬  Coplanar B D C A"
  using assms coplanar_perm_19 by blast

lemma ncoplanar_perm_12:
  assumes "¬ Coplanar A B C D"
  shows "¬ Coplanar C A B D"
  using assms coplanar_perm_8 by blast

lemma ncoplanar_perm_13:
  assumes "¬ Coplanar A B C D"
  shows "¬ Coplanar C A D B"
  using assms coplanar_perm_10 by blast

lemma ncoplanar_perm_14:
  assumes "¬ Coplanar A B C D"
  shows "¬ Coplanar C B A D"
  using assms coplanar_perm_14 by blast

lemma ncoplanar_perm_15:
  assumes "¬ Coplanar A B C D"
  shows "¬ Coplanar C B D A"
  using assms coplanar_perm_20 by blast

lemma ncoplanar_perm_16:
  assumes "¬ Coplanar A B C D"
  shows "¬ Coplanar C D A B"
  using assms coplanar_perm_16 by blast

lemma ncoplanar_perm_17:
  assumes "¬ Coplanar A B C D"
  shows "¬ Coplanar C D B A"
  using assms coplanar_perm_22 by blast

lemma ncoplanar_perm_18:
  assumes "¬ Coplanar A B C D"
  shows "¬ Coplanar D A B C"
  using assms coplanar_perm_9 by blast

lemma ncoplanar_perm_19:
  assumes "¬ Coplanar A B C D"
  shows "¬ Coplanar D A C B"
  using assms coplanar_perm_11 by blast

lemma ncoplanar_perm_20:
  assumes "¬ Coplanar A B C D"
  shows "¬ Coplanar D B A C"
  using assms coplanar_perm_15 by blast

lemma ncoplanar_perm_21:
  assumes "¬ Coplanar A B C D"
  shows "¬ Coplanar D B C A"
  using assms coplanar_perm_21 by blast

lemma ncoplanar_perm_22:
  assumes "¬ Coplanar A B C D"
  shows "¬ Coplanar D C A B"
  using assms coplanar_perm_17 by blast

lemma ncoplanar_perm_23:
  assumes "¬  Coplanar A B C D"
  shows "¬ Coplanar D C B A"
  using assms coplanar_perm_23 by blast

lemma coplanar_trivial:
  shows "Coplanar A A B C"
  using Coplanar_def NCol_cases col_trivial_1 by blast

lemma col__coplanar:
  assumes "Col A B C"
  shows "Coplanar A B C D"
  using Coplanar_def assms not_col_distincts by blast

lemma ncop__ncol:
  assumes "¬ Coplanar A B C D"
  shows "¬ Col A B C"
  using assms col__coplanar by blast

lemma ncop__ncols:
  assumes "¬ Coplanar A B C D"
  shows "¬ Col A B C  ¬ Col A B D  ¬ Col A C D  ¬ Col B C D"
  by (meson assms col__coplanar coplanar_perm_4 ncoplanar_perm_9)

lemma bet__coplanar:
  assumes "Bet A B C"
  shows "Coplanar A B C D"
  using assms bet_col ncop__ncol by blast

lemma out__coplanar:
  assumes "A Out B C"
  shows "Coplanar A B C D"
  using assms col__coplanar out_col by blast

lemma midpoint__coplanar:
  assumes "A Midpoint B C"
  shows "Coplanar A B C D"
  using assms midpoint_col ncop__ncol by blast

lemma perp__coplanar:
  assumes "A B Perp C D"
  shows "Coplanar A B C D"
proof -
  obtain P where "P PerpAt A B C D"
    using Perp_def assms by blast
  thus ?thesis
    using Coplanar_def perp_in_col by blast
qed

lemma ts__coplanar:
  assumes "A B TS C D"
  shows "Coplanar A B C D"
  by (metis Coplanar_def TS_def assms bet_col col_permutation_2 col_permutation_3)

lemma reflectl__coplanar:
  assumes "A B ReflectL C D"
  shows "Coplanar A B C D"
  by (metis ReflectL_def perp__coplanar assms col__coplanar col_trivial_1 ncoplanar_perm_17)

lemma reflect__coplanar:
  assumes "A B Reflect C D"
  shows "Coplanar A B C D"
  by (metis Reflect_def reflectl__coplanar assms col_trivial_2 ncop__ncols)

lemma inangle__coplanar:
  assumes "A InAngle B C D"
  shows "Coplanar A B C D"
proof -
  obtain X where "Bet B X D  (X = C  C Out X A)"
    using InAngle_def assms by auto
  thus ?thesis
    by (meson Col_cases Coplanar_def bet_col ncop__ncols out_col)
qed

lemma pars__coplanar:
  assumes "A B ParStrict C D"
  shows "Coplanar A B C D"
  using ParStrict_def assms by auto

lemma par__coplanar:
  assumes "A B Par C D"
  shows "Coplanar A B C D"
  using Par_def assms ncop__ncols pars__coplanar by blast

lemma plg__coplanar:
  assumes "Plg A B C D"
  shows "Coplanar A B C D"
proof -
  obtain M where "Bet A M C  Bet B M D"
    by (meson Plg_def assms midpoint_bet)
  thus ?thesis
    by (metis InAngle_def bet_out_1 inangle__coplanar ncop__ncols not_col_distincts)
qed

lemma plgs__coplanar:
  assumes "ParallelogramStrict A B C D"
  shows "Coplanar A B C D"
  using ParallelogramStrict_def assms par__coplanar by blast

lemma plgf__coplanar:
  assumes "ParallelogramFlat A B C D"
  shows "Coplanar A B C D"
  using ParallelogramFlat_def assms col__coplanar by auto

lemma parallelogram__coplanar:
  assumes "Parallelogram A B C D"
  shows "Coplanar A B C D"
  using Parallelogram_def assms plgf__coplanar plgs__coplanar by auto

lemma rhombus__coplanar:
  assumes "Rhombus A B C D"
  shows "Coplanar A B C D"
  using Rhombus_def assms plg__coplanar by blast

lemma rectangle__coplanar:
  assumes "Rectangle A B C D"
  shows "Coplanar A B C D"
  using Rectangle_def assms plg__coplanar by blast

lemma square__coplanar:
  assumes "Square A B C D"
  shows "Coplanar A B C D"
  using Square_def assms rectangle__coplanar by blast

lemma lambert__coplanar:
  assumes "Lambert A B C D"
  shows "Coplanar A B C D"
  using Lambert_def assms by presburger

lemma ts_distincts:
  assumes "A B TS P Q"
  shows "A  B  A  P  A  Q  B  P  B  Q  P  Q"
  using TS_def assms bet_neq12__neq not_col_distincts by blast

lemma l9_2:
  assumes "A B TS P Q"
  shows "A B TS Q P"
  using TS_def assms between_symmetry by blast

lemma invert_two_sides:
  assumes "A B TS P Q"
  shows "B A TS P Q"
  using TS_def assms not_col_permutation_5 by blast

lemma l9_3:
  assumes "P Q TS A C" and
    "Col M P Q" and
    "M Midpoint A C" and
    "Col R P Q" and
    "R Out A B"
  shows "P Q TS B C"
proof -
  have "¬ Col A P Q"
    using TS_def assms(1) by blast
  hence "P  Q"
    using not_col_distincts by auto
  obtain T where "Col T P Q" and "Bet A T C"
    using assms(2) assms(3) midpoint_bet by blast
  have "A  C"
    using assms(1) ts_distincts by blast
  have "T = M" 
  proof -
    have "Bet A M C" 
      using assms(3) midpoint_bet by blast
    hence "Col A M C" 
      using Col_def by force
    moreover have "Col A T C" 
      using Bet A T C bet_col by blast
    moreover have "Col R A B" 
      using assms(5) out_col by auto
    ultimately show ?thesis
      by (meson l6_21 A  C Col T P Q ¬ Col A P Q assms(2) col_permutation_3 
          col_permutation_5)
  qed
  have "P Q TS B C"
  proof cases
    assume "C = M"
    thus ?thesis 
      using A  C assms(3) is_midpoint_id_2 by blast
  next
    assume "¬ C = M"
    have "¬ Col B P Q" 
      by (metis ¬ Col A P Q assms(4) assms(5) col_permutation_2 colx out_col out_diff2)
    have "Bet R A B  Bet R B A"
      using Out_def assms(5) by auto
    {
      assume "Bet R A B"
      obtain B' where "M Midpoint B B'"
        using symmetric_point_construction by blast
      obtain R' where "M Midpoint R R'"
        using symmetric_point_construction by blast
      have "Bet B' C R'" 
        using l7_15 Bet R A B M Midpoint B B' M Midpoint R R' assms(3) between_symmetry 
        by fastforce
      have " X. Bet M X R'  Bet C X B" 
      proof -
        have "Bet B M B'" 
          using Midpoint_def M Midpoint B B' by auto
        moreover have "Bet R' C B'" 
          using Bet_cases Bet B' C R' by auto
        ultimately show ?thesis 
          by (simp add: inner_pasch)
      qed
      then obtain X where "Bet M X R'" and "Bet C X B" 
        by blast
      have "Col X P Q"
      proof -
        have "Col P M R" 
          using P  Q assms(2) assms(4) l6_16_1 not_col_permutation_2 by blast
        have "Col Q M R" 
          by (metis l6_16_1 Col P M R assms(2) assms(4) col_permutation_2)
        {
          assume "M = X"
          hence "Col X P Q"
            using assms(2) by blast
        }
        hence "M = X  Col X P Q" by simp
        {
          assume "M  X"
          hence "M  R'" 
            using Bet M X R' between_identity by blast
          hence "M  R" 
            using M Midpoint R R' is_midpoint_id by blast
          hence "Col X P Q" 
            by (metis Bet M X R' M Midpoint R R' M  R' assms(2) assms(4) 
                bet_col col_permutation_4 col_permutation_5 colx midpoint_col)
        }
        hence "M  X  Col X P Q" by simp
        thus ?thesis 
          using assms(2) by blast
      qed
      have "Bet B X C" 
        using Bet_cases Bet C X B by blast
      hence "P Q TS B C" 
        using TS_def Col X P Q ¬ Col B P Q assms(1) by blast
    }
    hence "Bet R A B  P Q TS B C" by simp
    {
      assume "Bet R B A"
      have "Bet C M A" 
        using Bet_cases Bet A T C T = M by blast
      then obtain X where "Bet B X C" and "Bet M X R" 
        using Bet R B A inner_pasch by blast
      have "Col X P Q"  
        by (metis Col_def Bet M X R assms(2) assms(4) between_equality_2 
            between_trivial2 col_transitivity_1)
      hence "P Q TS B C" 
        using TS_def Bet B X C ¬ Col B P Q assms(1) by blast
    }
    hence "Bet R B A  P Q TS B C" by simp
    thus ?thesis 
      using Bet R A B  P Q TS B C Bet R A B  Bet R B A by blast
  qed
  thus ?thesis by blast
qed

lemma mid_preserves_col:
  assumes "Col A B C" and
    "M Midpoint A A'" and
    "M Midpoint B B'" and
    "M Midpoint C C'"
  shows "Col A' B' C'"
  using Col_def assms(1) assms(2) assms(3) assms(4) l7_15 by auto

lemma per_mid_per:
  assumes (*"A ≠ B" and*)
    "Per X A B" and
    "M Midpoint A B" and
    "M Midpoint X Y"
  shows "Cong A X B Y  Per Y B A"
  by (meson Cong3_def Mid_perm assms(1) assms(2) assms(3) l7_13 l8_10)

lemma sym_preserve_diff:
  assumes "A  B" and
    "M Midpoint A A'" and
    "M Midpoint B B'"
  shows "A' B'"
  using assms(1) assms(2) assms(3) l7_9 by blast

lemma l9_4_1_aux_R1:
  assumes "R = S" and
    "S C Le R A" and
    "P Q TS A C" and
    "Col R P Q" and
    "P Q Perp A R" and
    "Col S P Q" and
    "P Q Perp C S" and
    "M Midpoint R S"
  shows " U C'. M Midpoint U C'  (R Out U A  S Out C C')"
proof -
  have "M = R"
    using assms(1) assms(8) l7_3 by blast
  have "¬ Col A P Q"
    using TS_def assms(3) by auto
  hence "P  Q"
    using not_col_distincts by blast
  obtain T where "Col T P Q" and "Bet A T C"
    using TS_def assms(3) by blast
  {
    assume "¬ M = T"
    hence "M PerpAt M T A M" 
      using perp_col2 assms(4) assms(5) not_col_permutation_3 perp_left_comm perp_perp_in
      by (metis Col T P Q M = R)
    hence "M T Perp C M"
      using M  T assms(1) assms(4) assms(7) col_permutation_1 perp_col2 Col T P Q M = R 
      by blast
    hence "Per T M A"
      using M PerpAt M T A M perp_in_per_3 by blast
    have "Per T M C"
      by (simp add: M T Perp C M perp_per_1)
    have "M = T"
    proof -
      have "Per C M T"
        by (simp add: Per T M C l8_2)
      thus ?thesis 
        using l8_6 l8_2 Bet A T C Per T M A by blast
    qed
    hence "False"
      using M  T by blast
  }
  hence "M = T" by blast
  have " U C'. ((M Midpoint U C'  M Out U A)  M Out C C')"
  proof -
    {
      fix U C'
      assume "M Midpoint U C'" and "M Out U A"
      have "C  M"
        using assms(1) assms(7) perp_not_eq_2 M = R by blast
      have "C'  M"
        using midpoint_not_midpoint out_diff1 M Midpoint U C' M Out U A by blast
      have "Bet U M C"
        using bet_out__bet l6_6 Bet A T C M = T M Out U A by blast
      hence "M Out C C'" 
        by (metis Out_def midpoint_bet C  M C'  M M Midpoint U C' M Out U A l5_2)
    }
    thus ?thesis by blast
  qed
  have " U C'. ((M Midpoint U C'  M Out C C')  M Out U A)"
  proof -
    {
      fix U C'
      assume "M Midpoint U C'" and "M Out C C'"
      have "C  M"
        using assms(1) assms(7) perp_not_eq_2 M = R by blast
      have "C'  M"
        using l6_3_1 M Out C C' by blast
      have "Bet U M C"
        using Out_def between_inner_transitivity midpoint_bet outer_transitivity_between 
        by (metis M Midpoint U C' M Out C C')
      hence "M Out U A"
        using l6_2 midpoint_distinct_1 
        by (metis Bet A T C C  M C'  M M = R M Midpoint U C' 
            M  T  False ¬ Col A P Q assms(4))
    }
    thus ?thesis by blast
  qed
  thus ?thesis 
    using M = R U C'. M Midpoint U C'  M Out U A  M Out C C' assms(1) by blast
qed

lemma l9_4_1_aux_R21:
  assumes "R  S" and
    "S C Le R A" and
    "P Q TS A C" and
    "Col R P Q" and
    "P Q Perp A R" and
    "Col S P Q" and
    "P Q Perp C S" and
    "M Midpoint R S"
  shows " U C'. M Midpoint U C'   (R Out U A  S Out C C')"
proof -
  obtain D where "Bet R D A" and "Cong S C R D"
    using Le_def assms(2) by blast
  have "C  S"
    using assms(7) perp_not_eq_2 by auto
  have "R  D"
    using cong_identity C  S Cong S C R D by blast
  have "R S Perp A R"
    using assms(1) assms(4) assms(5) assms(6) not_col_permutation_2 perp_col2 by blast
  have " M. (M Midpoint S R  M Midpoint C D)"
  proof -
    have "¬ Col A P Q"
      using TS_def assms(3) by blast
    have "P  Q"
      using not_col_distincts assms(3) ts_distincts by blast
    obtain T where "Col T P Q" and "Bet A T C"
      using TS_def assms(3) by blast
    have "C S Perp S R"
      by (metis NCol_perm assms(1) assms(4) assms(6) assms(7) perp_col0)
    have "A R Perp S R"
      using Perp_perm R S Perp A R by blast
    have "Col S R T"
      using Col_cases assms(4) assms(6) col3 Col T P Q P  Q by blast
    have "Bet C T A"
      using Bet_perm Bet A T C by blast
    thus ?thesis 
      using l8_24 A R Perp S R Bet R D A C S Perp S R Col S R T Cong S C R D by blast
  qed
  then obtain M' where "M' Midpoint S R" and "M' Midpoint C D" by blast
  have "M = M'" 
    using assms(8) l7_17_bis M' Midpoint S R by blast
  have " U C'. (M Midpoint U C'  R Out U A)  S Out C C'"
  proof -
    {
      fix U C'
      assume "M Midpoint U C'" and "R Out U A"
      have "C'  S"
        using M Midpoint U C' R Out U A assms(8) l7_9 out_diff1 by blast
      have "Bet S C C'  Bet S C' C"
      proof -
        have "Bet R U A  Bet R A U"
          using Out_def R Out U A by auto
        {
          assume "Bet R U A"
          hence "Bet R U D  Bet R D U"
            by (simp add: Bet R D A l5_3)
          hence "Bet S C C'  Bet S C' C"
            using l7_15 l7_2 M = M' M Midpoint U C' M' Midpoint C D assms(8) by blast
        }
        hence "Bet R U A  Bet S C C'  Bet S C' C" by simp
        have "Bet R A U  Bet S C C'  Bet S C' C"
          using l7_15 l7_2 Bet R D A M = M' M Midpoint U C' M' Midpoint C D 
            assms(8) between_exchange4 by blast
        thus ?thesis 
          using Bet R U A  Bet S C C'  Bet S C' C Bet R U A  Bet R A U by blast
      qed
      hence "S Out C C'" 
        using Out_def C  S C'  S by auto
    }
    thus ?thesis
      by blast
  qed
  have " U C'. (M Midpoint U C'  S Out C C')  R Out U A"
  proof -
    {
      fix U C'
      assume "M Midpoint U C'" and "S Out C C'"
      hence "U  R" 
        using l7_9_bis M = M' M' Midpoint S R out_distinct by blast
      have "A  R"
        using assms(5) perp_distinct by auto
      have "Bet S C C'  Bet S C' C"
        using Out_def S Out C C' by fastforce
      {
        assume "Bet S C C'"
        have "Bet R D U"
        proof -
          have "M Midpoint S R" 
            by (simp add: M = M' M' Midpoint S R)
          moreover have "M Midpoint C D" 
            by (simp add: M = M' M' Midpoint C D)
          moreover have "M Midpoint C' U" 
            by (simp add: M Midpoint U C' l7_2)
          ultimately show ?thesis 
            by (simp add: Bet S C C' l7_15)
        qed
        hence "Bet R U A  Bet R A U" 
          using Bet R D A R  D l5_1 by auto
      }
      hence "Bet S C C'  Bet R U A  Bet R A U" by simp
      {
        assume "Bet S C' C"
        have "Bet R U A" 
          using l7_15 l7_2 between_exchange4 Bet R D A M = M' M Midpoint U C' 
          by (meson Bet S C' C M' Midpoint C D M' Midpoint S R)
      }
      hence "Bet S C' C  Bet R U A  Bet R A U" by simp
      hence "Bet R U A  Bet R A U" 
        using Bet S C C'  Bet R U A  Bet R A U Bet S C C'  Bet S C' C by blast
      hence "R Out U A" 
        by (simp add: Out_def A  R U  R)
    }
    thus ?thesis by blast
  qed
  thus ?thesis 
    using U C'. M Midpoint U C'  R Out U A  S Out C C' by blast
qed

lemma l9_4_1_aux:
  assumes "S C Le R A" and
    "P Q TS A C" and
    "Col R P Q" and
    "P Q Perp A R" and
    "Col S P Q" and
    "P Q Perp C S" and
    "M Midpoint R S"
  shows " U C'. (M Midpoint U C'  (R Out U A  S Out C C'))"
  using l9_4_1_aux_R1 l9_4_1_aux_R21 assms by fast


lemma per_col_eq:
  assumes "Per A B C" and
    "Col A B C" and
    "B  C"
  shows "A = B"
  using assms(1) assms(2) assms(3) l8_9 by blast

lemma l9_4_1:
  assumes "P Q TS A C" and
    "Col R P Q" and
    "P Q Perp A R" and
    "Col S P Q" and
    "P Q Perp C S" and
    "M Midpoint R S"
  shows " U C'. M Midpoint U C'  (R Out U A  S Out C C')"
proof -
  have "S C Le R A  R A  Le S C"
    using le_cases by blast
  {
    assume "S C Le R A"
    {
      fix U C'
      assume "M Midpoint U C'"
      hence "(R Out U A  S Out C C')"
        using assms(1) assms(2) assms(3) assms(4) assms(5) assms(6) l9_4_1_aux S C Le R A 
        by blast
    }
    hence " U C'. M Midpoint U C'  (R Out U A  S Out C C')" by simp
  }
  hence "S C Le R A  ( U C'. M Midpoint U C'  (R Out U A  S Out C C'))" by simp
  moreover
  {
    assume " R A Le S C"
    {
      fix U C'
      assume "M Midpoint U C'"
      hence "(R Out A U  S Out C' C)"
        using assms(1) assms(2) assms(3) assms(4) assms(5) assms(6) l7_2 l9_2 l9_4_1_aux 
        by (meson Out_cases le_cases)
      hence "(R Out U A  S Out C C')"
        using l6_6 by blast
    }
    hence " U C'. M Midpoint U C'  (R Out U A  S Out C C')" by simp
  }
  hence "R A Le S C  ( U C'. M Midpoint U C'  (R Out U A  S Out C C'))" by simp
  thus ?thesis 
    using S C Le R A  R A Le S C calculation by presburger
qed

lemma mid_two_sides:
  assumes "M Midpoint A B" and
    "¬ Col A B X" and
    "M Midpoint X Y"
  shows "A B TS X Y"
proof -
  have "¬ Col Y A B"
    by (meson Mid_cases mid_preserves_col assms(1) assms(2) assms(3) col_permutation_3)
  moreover have "Bet X M Y"
    using assms(3) midpoint_bet by blast
  ultimately show ?thesis 
    by (metis TS_def not_col_permutation_2 assms(1) assms(2) midpoint_col)
qed

lemma col_preserves_two_sides:
  assumes "C  D" and
    "Col A B C" and
    "Col A B D" and
    "A B TS X Y"
  shows "C D TS X Y"
proof -
  have "¬ Col X A B"
    using TS_def assms(4) by blast
  hence "A  B"
    using not_col_distincts by blast
  have "¬ Col X C D"
    using colx assms(1) assms(2) assms(3)
    by (meson ¬ Col X A B not_col_permutation_2)
  have "¬ Col Y C D"
    by (metis Col_cases TS_def colx assms(1) assms(2) assms(3) assms(4))
  thus ?thesis
  proof -
    obtain PP where "¬ Col X A B" and "¬ Col Y A B" and "Col PP A B" and "Bet X PP Y" 
      using TS_def assms(4) by blast
    hence "Col PP C D" 
      using A  B assms(2) assms(3) col3 col_permutation_1 by blast
    thus ?thesis 
      using TS_def Bet X PP Y ¬ Col X C D ¬ Col Y C D by blast
  qed
qed

lemma out_out_two_sides:
  assumes "A  B" and
    "A B TS X Y" and
    "Col I A B" and
    "Col I X Y" and
    "I Out X U" and
    "I Out Y V"
  shows "A B TS U V"
proof -
  have "¬ Col X A B"
    using TS_def assms(2) by blast
  {
    assume "Col V A B"
    hence "Col Y A B" 
      by (metis out_distinct assms(3) assms(6) col_permutation_2 colx out_col)
    have False 
      using TS_def Col Y A B assms(2) by blast
  }
  moreover
  have "¬ Col U A B" 
    using assms(3) assms(5) col_permutation_2 colx out_col out_distinct by (meson ¬ Col X A B)
  moreover
  obtain T where "Col T A B" and "Bet X T Y"
    using TS_def assms(2) by blast
  have "I = T"
  proof -
    have "Col X Y I" 
      using assms(4) Col_cases by blast
    moreover have "Col B A I"
      using assms(3) Col_cases by blast
    moreover have "Col B A T" 
      using Col_cases Col T A B by auto
    moreover have "¬ Col X A B  ¬ Col X B A  ¬ Col A X B  ¬ Col A B X  ¬ Col B X A  ¬ Col B A X"
      using ¬ Col X A B Col_cases by blast
    moreover have "A  B  A  X  A  Y  B  X  B  Y  X  Y"
      using assms(2) ts_distincts by presburger
    moreover have "Col X Y T" 
      using Bet X T Y bet_col1 between_trivial by blast
    ultimately show ?thesis 
      using l6_21 by blast
  qed
  hence "Bet U T V"
    using assms(5) assms(6) bet_out_out_bet Bet X T Y by blast
  ultimately show ?thesis 
    using TS_def Col T A B by blast
qed

lemma l9_4_2_aux_R1:
  assumes "R = S " and
    "S C Le R A" and
    "P Q TS A C" and
    "Col R P Q" and
    "P Q Perp A R" and
    "Col S P Q" and
    "P Q Perp C S" and
    "R Out U A" and
    "S Out V C"
  shows "P Q TS U V"
proof -
  have "¬ Col A P Q"
    using TS_def assms(3) by auto
  hence "P  Q"
    using not_col_distincts by blast
  obtain T where "Col T P Q" and "Bet A T C"
    using TS_def assms(3) by blast
  have "R = T" 
    using assms(1) assms(5) assms(6) assms(7) col_permutation_1 l8_16_1 l8_6 
    by (meson Bet A T C Col T P Q)
  thus ?thesis 
    by (metis Bet A T C Col T P Q P  Q assms(1) assms(3) assms(8) assms(9) 
        bet_col col_permutation_4 l6_6 out_out_two_sides)
qed

lemma l9_4_2_aux_R2:
  assumes "R  S" and
    "S C Le R A" and
    "P Q TS A C" and
    "Col R P Q" and
    "P Q Perp A R" and
    "Col S P Q" and
    "P Q Perp C S" and
    "R Out U A" and
    "S Out V C"
  shows "P Q TS U V"
proof -
  have "P  Q"
    using assms(7) perp_distinct by auto
  have "R S TS A C"
    using assms(1) assms(3) assms(4) assms(6) col_permutation_1 col_preserves_two_sides by blast
  have "Col R S P"
    using assms(4) assms(6) col2__eq not_col_permutation_1 P  Q by blast
  have "Col R S Q"
    using colx Tarski_neutral_dimensionless_axioms assms(4) assms(6) col_trivial_2 
    by (metis Col R S P)
  have "R S Perp A R"
    using NCol_perm assms(1) assms(4) assms(5) assms(6) perp_col2 by blast
  have "R S Perp C S"
    using assms(1) assms(4) assms(6) assms(7) col_permutation_1 perp_col2 by blast
  have "¬ Col A R S" 
    using TS_def R S TS A C by force
  obtain T where "Col T R S" and "Bet A T C" 
    using TS_def R S TS A C by blast
  obtain C' where "Bet R C' A" and "Cong S C R C'" 
    using Le_def assms(2) by blast
  have " X. X Midpoint S R  X Midpoint C C'"
  proof -
    have "C S Perp S R" 
      using Perp_perm R S Perp C S by blast
    moreover have "A R Perp S R" 
      using Perp_perm R S Perp A R by blast
    moreover have "Col S R T" 
      using Col_cases Col T R S by auto
    moreover have "Bet C T A" 
      using Bet_cases Bet A T C by blast
    ultimately show ?thesis 
      using l8_24 Bet R C' A Cong S C R C' by blast
  qed
  then obtain M where "M Midpoint S R" and "M Midpoint C C'" 
    by blast
  obtain U' where "M Midpoint U U'"
    using symmetric_point_construction by blast
  have "R  U"
    using assms(8) out_diff1 by blast
  have "R S TS U U'" 
    by (metis Col_def Out_def invert_two_sides l6_16_1 mid_two_sides M Midpoint S R 
        M Midpoint U U' ¬ Col A R S assms(8))
  have "R S TS V U"
  proof -
    have "Col M R S" 
      using Col_def Midpoint_def M Midpoint S R by force
    moreover have "M Midpoint U' U" 
      by (simp add: M Midpoint U U' l7_2)
    moreover have "S Out U' V" 
      by (meson l6_7 M Midpoint S R M Midpoint U U' assms(2) assms(3) assms(4) 
          assms(5) assms(6) assms(7) assms(8) assms(9) l6_6 l7_2 l9_4_1_aux)
    ultimately show ?thesis 
      using R S TS U U' col_trivial_3 l9_2 l9_3 by blast
  qed
  thus ?thesis 
    using Col R S P Col R S Q P  Q col_preserves_two_sides l9_2 by presburger
qed

lemma l9_4_2_aux:
  assumes "S C Le R A" and
    "P Q TS A C" and
    "Col R P Q" and
    "P Q Perp A R" and
    "Col S P Q" and
    "P Q Perp C S" and
    "R Out U A" and
    "S Out V C"
  shows "P Q TS U V"
  using l9_4_2_aux_R1 l9_4_2_aux_R2 
  by (metis assms(1) assms(2) assms(3) assms(4) assms(5) assms(6) assms(7) assms(8))

lemma l9_4_2:
  assumes "P Q TS A C" and
    "Col R P Q" and
    "P Q Perp A R" and
    "Col S P Q" and
    "P Q Perp C S" and
    "R Out U A" and
    "S Out V C"
  shows "P Q TS U V"
proof -
  have "S C Le R A  R A Le S C"
    by (simp add: local.le_cases)
  moreover have "S C Le R A  P Q TS U V"
    by (simp add: assms(1) assms(2) assms(3) assms(4) assms(5) assms(6) assms(7) l9_4_2_aux)
  moreover have "R A Le S C  P Q TS U V"
    by (simp add: assms(1) assms(2) assms(3) assms(4) assms(5) assms(6) assms(7) l9_2 l9_4_2_aux)
  ultimately show ?thesis
    by blast
qed

lemma l9_5:
  assumes "P Q TS A C" and
    "Col R P Q" and
    "R Out A B"
  shows "P Q TS B C"
proof -
  have "P  Q"
    using assms(1) ts_distincts by blast
  obtain A' where "Col P Q A'" and "P Q Perp A A'"
    by (metis NCol_perm TS_def assms(1) l8_18_existence)
  obtain C' where "Col P Q C'" and "P Q Perp C C'"
    using Col_perm TS_def assms(1) l8_18_existence by blast
  obtain M where "M Midpoint A' C'"
    using midpoint_existence by blast
  obtain D where "M Midpoint A D"
    using symmetric_point_construction by auto
  have " B0. Col P Q B0  P Q Perp B B0"
  proof -
    have "¬ Col P Q B"
      using colx perp_not_col2 Tarski_neutral_dimensionless_axioms assms(2) assms(3) 
        col_permutation_1 l6_3_1 out_col by (meson Col P Q A' P Q Perp A A')
    thus ?thesis
      by (simp add: l8_18_existence)
  qed
  then obtain B' where "Col P Q B'" and "P Q Perp B B'" by blast
  have "P Q TS B C"
  proof -
    have "C' Out D C  A' Out A A"
      using Out_cases assms(1) l9_4_1 not_col_permutation_1 Col P Q A' Col P Q C' 
        M Midpoint A D M Midpoint A' C' P Q Perp A A' P Q Perp C C' by blast
    hence "C' Out D C"
      using perp_not_eq_2 Tarski_neutral_dimensionless_axioms out_trivial P Q Perp A A' by blast
    have "P Q TS A D"
      using assms(1) col_permutation_2 l9_4_2 
      by (meson (C' Out D C) = (A' Out A A) C' Out D C Col P Q A' Col P Q C' 
          P Q Perp A A' P Q Perp C C')
    {
      assume "A'  C'"
      hence "Col M P Q"
        using col_trivial_2 l6_21 midpoint_col not_col_permutation_1 
          Col P Q A' Col P Q C' M Midpoint A' C' by fast
      hence "P Q TS B D"
        using assms(2) assms(3) l9_3 M Midpoint A D P Q TS A D by blast
    }
    hence "A'  C'  P Q TS B D" by simp
    hence "P Q TS B D"
      using assms(2) assms(3) l9_3 midpoint_distinct_2 not_col_permutation_1 
      by (metis Col P Q A' M Midpoint A D M Midpoint A' C' P Q TS A D)
    moreover have "Col B' P Q" 
      using Col P Q B' not_col_permutation_1 by blast
    moreover have "Col C' P Q" 
      using Col P Q C' col_permutation_2 by blast
    moreover have "P Q Perp D C'"
      using Col_perm l6_3_1 out_col perp_col1 perp_right_comm 
      by (metis C' Out D C P Q Perp C C')
    moreover have "B' Out B B" 
      using P Q Perp B B' out_trivial perp_not_eq_2 by auto
    moreover have "C' Out C D" 
      using Out_cases C' Out D C by auto
    ultimately show ?thesis 
      using l9_4_2 P Q Perp B B' by blast
  qed
  thus ?thesis using l8_18_existence by blast
qed

lemma outer_pasch_R1:
  assumes "Col P Q C" and
    "Bet A C P" and
    "Bet B Q C"
  shows " X. Bet A X B  Bet P Q X"
proof cases
  assume "Bet P Q C"
  thus ?thesis 
    using Bet_cases assms(2) between_exchange4 between_trivial2 by blast
next
  assume "¬ Bet P Q C"
  thus ?thesis 
    by (metis Bet_cases assms(1) assms(3) between_exchange3 between_trivial 
        outer_transitivity_between2 third_point)
qed

lemma outer_pasch_R2:
  assumes "¬ Col P Q C" and
    "Bet A C P" and
    "Bet B Q C"
  shows " X. Bet A X B  Bet P Q X"
proof cases
  assume "B = Q"
  thus ?thesis
    using between_trivial by blast
next
  assume "B  Q"
  have "A  P"
    using assms(1) assms(2) between_identity col_trivial_3 by blast
  have "P  Q"
    using assms(1) col_trivial_1 by blast
  have "P  B"
    using assms(1) assms(3) bet_col by blast
  have "P Q TS C B"
  proof -
    have "¬ Col C P Q"
      using Col_cases assms(1) by blast
    moreover have "¬ Col B P Q"
      using Col_cases colx Tarski_neutral_dimensionless_axioms assms(1) assms(3) bet_col 
        col_trivial_2 B  Q by fast
    moreover have " T. Col T P Q  Bet C T B"
      using Col_cases assms(3) between_symmetry col_trivial_2 by blast
    ultimately show ?thesis 
      using TS_def by blast
  qed
  have "P Q TS A B"
    using assms(1) assms(2) bet_out_1 l9_5 not_col_distincts P Q TS C B by metis
  obtain X where "Col X P Q" and "Bet A X B" 
    using TS_def P Q TS A B by blast
  have "Bet P Q X"
  proof -
    obtain T where "Bet X T P" and "Bet C T B"
      using assms(2) between_symmetry inner_pasch by (meson Bet A X B)
    have "B  C"
      using assms(3) bet_neq12__neq B  Q by auto
    have "T = Q"
    proof -
      have "Col Q C B"
        using NCol_cases assms(3) Col_def by blast
      have "Col T C B" 
        using Bet C T B bet_col col_permutation_4 by presburger
      have "¬ Col X P B" 
        by (metis Bet_cases TS_def Bet C T B Bet X T P Col X P Q P Q TS C B 
            assms(3) bet_col1 between_equality_2 between_trivial2 col_transitivity_2)
      thus ?thesis
        by (metis Col_def B  C Bet C T B Bet X T P Col Q C B Col X P Q 
            between_symmetry l6_21)
    qed
    thus ?thesis 
      using Bet X T P between_symmetry by blast
  qed
  thus ?thesis 
    using Bet A X B by blast
qed

(** GeoCoq: Ch09_planve.v **)
(** This lemma used to be an axiom in previous versions of Tarski's axiom system.
It is a been shown to a theorem by Gupta in his Phd 1965. *)
(** This corresponds to l9_6 in Tarski's book. *)
lemma outer_pasch:
  assumes "Bet A C P" and
    "Bet B Q C"
  shows " X. Bet A X B  Bet P Q X"
  using assms(1) assms(2) outer_pasch_R1 outer_pasch_R2 by blast

lemma os_distincts:
  assumes "A B OS X Y"
  shows "A  B  A  X  A  Y  B  X  B  Y"
  using OS_def assms ts_distincts by blast

lemma invert_one_side:
  assumes "A B OS P Q"
  shows "B A OS P Q"
proof -
  obtain T where "A B TS P T  A B TS Q T"
    using OS_def assms by blast
  hence "B A TS P T  B A TS Q T"
    using invert_two_sides by blast
  thus ?thesis
    using OS_def by blast
qed

lemma l9_8_1:
  assumes "P Q TS A C" and
    "P Q TS B C"
  shows "P Q OS A B"
proof -
  have " R::'p. (P Q TS A R  P Q TS B R)"
    using assms(1) assms(2) by blast
  thus ?thesis
    using OS_def by blast
qed

lemma not_two_sides_id:
  shows "¬ P Q TS A A"
  using ts_distincts by blast

lemma l9_8_2:
  assumes "P Q TS A C" and
    "P Q OS A B"
  shows "P Q TS B C"
proof -
  obtain D where P1: "P Q TS A D  P Q TS B D"
    using assms(2) OS_def by blast
  hence "P  Q"
    using ts_distincts by blast
  obtain T where P2: "Col T P Q  Bet A T C"
    using TS_def assms(1) by blast
  obtain X where P3: "Col X P Q  Bet A X D"
    using TS_def P1 by blast
  obtain Y where P4: "Col Y P Q  Bet B Y D"
    using TS_def P1 by blast
  then obtain M where P5: "Bet Y M A  Bet X M B" using P3 inner_pasch by blast
  have P6: "A  D"
    using P1 ts_distincts by blast
  have P7: "B  D"
    using P1 not_two_sides_id by blast
  {
    assume Q0: "Col A B D"
    have "P Q TS B C"
    proof cases
      assume Q1: "M = Y"
      have "X = Y"
      proof -
        have S1: "¬ Col P Q A"
          using TS_def assms(1) not_col_permutation_1 by blast
        have S3: "Col P Q X"
          using Col_perm P3 by blast
        have S4: "Col P Q Y"
          using Col_perm P4 by blast
        have S5: "Col A D X"
          by (simp add: P3 bet_col col_permutation_5)
        have "Col A D Y"
          by (metis Col_def P5 Q1 S5 Q0 between_equality between_trivial l6_16_1)
        thus ?thesis using S1 S3 S4 S5 P6 l6_21
          by blast
      qed
      hence "X Out A B"
        by (metis P1 P3 P4 TS_def l6_2)
      thus ?thesis using assms(1) P3 l9_5 by blast
    next
      assume Z1: "¬ M = Y"
      have "X = Y"
      proof -
        have S1: "¬ Col P Q A"
          using TS_def assms(1) not_col_permutation_1 by blast
        have S3: "Col P Q X"
          using Col_perm P3 by blast
        have S4: "Col P Q Y"
          using Col_perm P4 by blast
        have S5: "Col A D X"
          by (simp add: P3 bet_col col_permutation_5)
        have "Col A D Y"
          by (metis Col_def P4 Q0 P7 l6_16_1)
        thus ?thesis using S1 S3 S4 S5 P6 l6_21
          by blast
      qed
      hence Z3: "M  X" using Z1 by blast
      have Z4: "P Q TS M C"
        by (meson Out_cases P4 P5 l9_5 Tarski_neutral_dimensionless_axioms Z1 assms(1) bet_out)
      have "X Out M B"
        using P5 Z3 bet_out by auto
      thus ?thesis using Z4 P3 l9_5 by blast
    qed
  }
  hence Z99: "Col A B D  P Q TS B C" by blast
  {
    assume Q0: "¬ Col A B D"
    have Q1: "P Q TS M C"
    proof -
      have S3: "Y Out A M"
      proof -
        have T1: "A  Y"
          using Col_def P4 Q0 col_permutation_4 by blast
        have T2: "M  Y"
        proof -
          {
            assume T3: "M = Y"
            have "Col B D X"
            proof -
              have U1: "B  M"
                using P1 P4 T3 TS_def by blast
              have U2: "Col B M D"
                by (simp add: P4 T3 bet_col)
              have "Col B M X"
                by (simp add: P5 bet_col between_symmetry)
              thus ?thesis using U1 U2
                using col_transitivity_1 by blast
            qed
            have "False"
              by (metis NCol_cases P1 P3 TS_def Col B D X Q0 bet_col col_trivial_2 l6_21)
          }
          thus ?thesis by blast
        qed
        have "Bet Y A M  Bet Y M A" using P5 by blast
        thus ?thesis using T1 T2
          by (simp add: Out_def)
      qed
      hence "X Out M B"
        by (metis P1 P3 P4 P5 TS_def bet_out l9_5)
      thus ?thesis using assms(1) S3 l9_5 P3 P4 by blast
    qed
    have "X Out M B"
      by (metis P3 P5 Q1 TS_def bet_out)
    hence "P Q TS B C" using Q1 P3 l9_5 by blast
  }
  hence "¬ Col A B D  P Q TS B C" by blast
  thus ?thesis using Z99 by blast
qed

lemma l9_9:
  assumes "P Q TS A B"
  shows "¬ P Q OS A B"
  using assms l9_8_2 not_two_sides_id by blast

lemma l9_9_bis:
  assumes "P Q OS A B"
  shows "¬ P Q TS A B"
  using assms l9_9 by blast

lemma one_side_chara:
  assumes "P Q OS A B"
  shows " X. Col X P Q  ¬ Bet A X B"
proof -
  have "¬ Col A P Q  ¬ Col B P Q"
    using OS_def TS_def assms by auto
  thus ?thesis
    using l9_9_bis TS_def assms by blast
qed

lemma l9_10:
  assumes "¬ Col A P Q"
  shows " C. P Q TS A C"
  by (meson Col_perm assms mid_two_sides midpoint_existence symmetric_point_construction)

lemma one_side_reflexivity:
  assumes "¬ Col A P Q"
  shows "P Q OS A A"
  using assms l9_10 l9_8_1 by blast

lemma one_side_symmetry:
  assumes "P Q OS A B"
  shows "P Q OS B A"
  by (meson OS_def Tarski_neutral_dimensionless_axioms assms invert_two_sides)

lemma one_side_transitivity:
  assumes "P Q OS A B" and
    "P Q OS B C"
  shows "P Q OS A C"
  by (meson OS_def l9_8_2 Tarski_neutral_dimensionless_axioms assms(1) assms(2))

lemma l9_17:
  assumes "P Q OS A C" and
    "Bet A B C"
  shows "P Q OS A B"
proof cases
  assume "A = C"
  thus ?thesis
    using assms(1) assms(2) between_identity by blast
next
  assume P1: "¬ A = C"
  obtain D where P2: "P Q TS A D  P Q TS C D"
    using OS_def assms(1) by blast
  hence P3: "P  Q"
    using ts_distincts by blast
  obtain X where P4: "Col X P Q  Bet A X D"
    using P2 TS_def by blast
  obtain Y where P5: "Col Y P Q  Bet C Y D"
    using P2 TS_def by blast
  obtain T where P6: "Bet B T D  Bet X T Y"
    using P4 P5 assms(2) l3_17 by blast
  have P7: "P Q TS A D"
    by (simp add: P2)
  have "P Q TS B D"
  proof -
    have Q1: "¬ Col B P Q"
      using assms(1) assms(2) one_side_chara by blast
    have Q2: "¬ Col D P Q"
      using P2 TS_def by blast
    obtain T0 where "Col T0 P Q  Bet B T0 D"
    proof -
      assume a1: "T0. Col T0 P Q  Bet B T0 D  thesis"
      obtain pp :: 'p where
        f2: "Bet B pp D  Bet X pp Y"
        using thesis. (T. Bet B T D  Bet X T Y  thesis)  thesis by blast
      have "Col P Q Y"
        using Col_def P5 by blast
      hence "Y = X  Col P Q pp"
        using f2 Col_def P4 colx by blast
      thus ?thesis
        using f2 a1 by (metis BetSEq BetS_def Col_def P4)
    qed
    thus ?thesis 
      using Q1 Q2 TS_def by blast
  qed
  thus ?thesis using P7
    using OS_def by blast
qed

lemma l9_18_R1:
  assumes "Col X Y P" and
    "Col A B P"
    and "X Y TS A B"
  shows "Bet A P B  ¬ Col X Y A  ¬ Col X Y B"
  by (meson TS_def assms(1) assms(2) assms(3) col_permutation_5 l9_5 not_col_permutation_1 
      not_out_bet not_two_sides_id)

lemma l9_18_R2:
  assumes "Col X Y P" and
    "Col A B P" and
    "Bet A P B" and
    "¬ Col X Y A" and
    "¬ Col X Y B"
  shows "X Y TS A B"
  using Col_perm TS_def assms(1) assms(3) assms(4) assms(5) by blast

lemma l9_18:
  assumes "Col X Y P" and
    "Col A B P"
  shows "X Y TS A B  (Bet A P B  ¬ Col X Y A  ¬ Col X Y B)"
  using l9_18_R1 l9_18_R2 assms(1) assms(2) by blast

lemma l9_19_R1:
  assumes "Col X Y P" and
    "Col A B P" and
    "X Y OS A B"
  shows "P Out A B  ¬ Col X Y A"
  by (meson OS_def TS_def assms(1) assms(2) assms(3) col_permutation_5 not_col_permutation_1 
      not_out_bet one_side_chara)

lemma l9_19_R2:
  assumes "Col X Y P" and
    (*    "Col A B P" and *)
    "P Out A B" and
    "¬ Col X Y A"
  shows "X Y OS A B"
proof -
  obtain D where "X Y TS A D"
    using Col_perm assms(3) l9_10 by blast
  thus ?thesis
    using OS_def assms(1) assms(2) l9_5 not_col_permutation_1 by blast
qed

lemma l9_19:
  assumes "Col X Y P" and
    "Col A B P"
  shows "X Y OS A B  (P Out A B  ¬ Col X Y A)"
  using l9_19_R1 l9_19_R2 assms(1) assms(2) by blast

lemma one_side_not_col123:
  assumes "A B OS X Y"
  shows "¬ Col A B X"
  using assms col_trivial_3 l9_19 by blast

lemma one_side_not_col124:
  assumes "A B OS X Y"
  shows "¬ Col A B Y"
  using assms one_side_not_col123 one_side_symmetry by blast

lemma col_two_sides:
  assumes "Col A B C" and
    "A  C" and
    "A B TS P Q"
  shows "A C TS P Q"
  using assms(1) assms(2) assms(3) col_preserves_two_sides col_trivial_3 by blast

lemma col_one_side:
  assumes "Col A B C" and
    "A  C" and
    "A B OS P Q"
  shows "A C OS P Q"
proof -
  obtain T where "A B TS P T  A B TS Q T" using assms(1) assms(2) assms(3) OS_def by blast
  thus ?thesis
    using col_two_sides OS_def assms(1) assms(2) by blast
qed

lemma out_out_one_side:
  assumes "A B OS X Y" and
    "A Out Y Z"
  shows "A B OS X Z"
  by (meson Col_cases OS_def Tarski_neutral_dimensionless_axioms assms(1) assms(2) 
      col_trivial_3 l9_5)

lemma out_one_side:
  assumes "¬ Col A B X  ¬ Col A B Y" and
    "A Out X Y"
  shows "A B OS X Y"
  using assms(1) assms(2) l6_6 not_col_permutation_2 one_side_reflexivity one_side_symmetry 
    out_out_one_side by blast

lemma bet__ts:
  assumes "A  Y" and
    "¬ Col A B X" and
    "Bet X A Y"
  shows "A B TS X Y"
proof -
  have "¬ Col Y A B"
    using NCol_cases assms(1) assms(2) assms(3) bet_col col2__eq by blast
  thus ?thesis
    by (meson TS_def assms(2) assms(3) col_permutation_3 col_permutation_5 col_trivial_3)
qed

lemma bet_ts__ts:
  assumes "A B TS X Y" and
    "Bet X Y Z"
  shows "A B TS X Z"
proof -
  have "¬ Col Z A B"
    using assms(1) assms(2) bet_col between_equality_2 col_permutation_1 l9_18 by blast
  thus ?thesis
    using TS_def assms(1) assms(2) between_exchange4 by blast
qed

lemma bet_ts__os:
  assumes "A B TS X Y" and
    "Bet X Y Z"
  shows "A B OS Y Z"
  using OS_def assms(1) assms(2) bet_ts__ts l9_2 by blast

lemma l9_31 :
  assumes "A X OS Y Z" and
    "A Z OS Y X"
  shows "A Y TS X Z"
proof -
  have "A  X  A  Z  ¬ Col Y A X  ¬ Col Z A X  ¬ Col Y A Z"
    using assms(1) assms(2) col_permutation_1 one_side_not_col123 one_side_not_col124 
      os_distincts by blast
  obtain Z' where "Bet Z A Z'" and "Cong A Z' Z A" 
    using segment_construction by blast
  have "Z'  A" 
    by (metis Cong A Z' Z A assms(1) cong_diff_3 os_distincts)
  have "A X TS Y Z'" 
    by (metis l9_8_2 one_side_symmetry Bet Z A Z' Z'  A assms(1) bet__ts 
        one_side_not_col124)
  have "¬ Col Y A X" 
    using A  X  A  Z  ¬ Col Y A X  ¬ Col Z A X  ¬ Col Y A Z by auto
  obtain T where "Col A T X" and "Bet Y T Z'" 
    by (meson TS_def col_permutation_4 A X TS Y Z')
  hence "T  A"
  proof -
    have "¬ A Out Z Y" 
      using Col_cases A  X  A  Z  ¬ Col Y A X  ¬ Col Z A X  ¬ Col Y A Z out_col by blast
    have "A  Z'" 
      using Z'  A by auto
    thus ?thesis 
      by (metis A  X  A  Z  ¬ Col Y A X  ¬ Col Z A X  ¬ Col Y A Z Bet Y T Z' 
          Bet Z A Z' bet_col l6_21 not_col_distincts)
  qed
  have "Y A OS Z' T" 
    by (metis NCol_cases Out_def col3 col_trivial_3 out_one_side A X TS Y Z' Bet Y T Z' 
        Col A T X T  A ¬ Col Y A X ts_distincts)
  have "A Y TS Z' Z" 
    by (metis Bet_cases Col_cases A  X  A  Z  ¬ Col Y A X  ¬ Col Z A X  ¬ Col Y A Z 
        Bet Z A Z' Y A OS Z' T bet__ts one_side_not_col123)
  {
    assume "Bet T A X"
    have "Z' Z OS Y T" 
      using BetSEq BetS_def TS_def l6_6 bet_col bet_out_1 col_trivial_3 
        colx not_col_permutation_3 not_col_permutation_4 out_one_side 
        A Y TS Z' Z A  X  A  Z  ¬ Col Y A X  ¬ Col Z A X  ¬ Col Y A Z 
        Bet Y T Z' Bet Z A Z' Col A T X by metis
    hence "Z' Out T Y" 
      by (metis Bet Y T Z' bet_out_1 os_distincts)
    hence "A Z OS Y T" 
      using A  X  A  Z  ¬ Col Y A X  ¬ Col Z A X  ¬ Col Y A Z Bet Z A Z' 
        bet_col invert_one_side l6_6 l9_19_R2 not_col_permutation_3 by blast
    have "A Z TS X T"
    proof -
      have "¬ Col X A Z" 
        using Col_cases A  X  A  Z  ¬ Col Y A X  ¬ Col Z A X  ¬ Col Y A Z by blast
      have "¬ Col T A Z" 
        using A Z OS Y T col_permutation_1 one_side_not_col124 by blast
      have " T0. Col T0 A Z  Bet X T0 T"
      proof -
        have "Col A A Z" 
          by (simp add: col_trivial_1)
        moreover have "Bet X A T" 
          using Bet_cases Bet T A X by blast
        ultimately show ?thesis 
          by auto
      qed
      thus ?thesis 
        using TS_def ¬ Col T A Z ¬ Col X A Z by presburger
    qed
    have "A Y TS X Z" 
      by (meson l9_8_2 A Z OS Y T A Z TS X T assms(2) l9_9 one_side_symmetry)
  }
  moreover
  {
    assume "Bet A X T"
    hence "A Y OS Z' X" 
      using Bet_cases between_equality invert_one_side not_col_permutation_4 
        not_out_bet out_out_one_side 
      by (meson OS_def A Y TS Z' Z Col A T X Y A OS Z' T calculation)
    have "A Y TS X Z" 
      using A Y OS Z' X A Y TS Z' Z l9_8_2 by blast
  }
  moreover
  {
    assume "Bet X T A"
    hence "A Y OS T X" 
      using A  X  A  Z  ¬ Col Y A X  ¬ Col Z A X  ¬ Col Y A Z T  A 
        bet_out_1 not_col_permutation_4 out_one_side by presburger
    hence "A Y TS X Z" 
      using A Y TS Z' Z Y A OS Z' T invert_two_sides l9_8_2 by blast
  }
  ultimately show ?thesis 
    using Bet_cases Col A T X third_point by blast
qed

lemma col123__nos:
  assumes "Col P Q A"
  shows "¬ P Q OS A B"
  using assms one_side_not_col123 by blast

lemma col124__nos:
  assumes "Col P Q B"
  shows "¬ P Q OS A B"
  using assms one_side_not_col124 by blast

lemma col2_os__os:
  assumes "C  D" and
    "Col A B C" and
    "Col A B D" and
    "A B OS X Y"
  shows "C D OS X Y"
  by (metis assms(1) assms(2) assms(3) assms(4) col3 col_one_side col_trivial_3 
      invert_one_side os_distincts)

lemma os_out_os:
  assumes "Col A B P" and
    "A B OS C D" and
    "P Out C C'"
  shows "A B OS C' D"
  using OS_def assms(1) assms(2) assms(3) l9_5 not_col_permutation_1 by blast

lemma ts_ts_os:
  assumes "A B TS C D" and
    "C D TS A B"
  shows "A C OS B D"
proof -
  obtain T1 where P1: "Col T1 A B  Bet C T1 D"
    using TS_def assms(1) by blast
  obtain T where P2: "Col T C D  Bet A T B"
    using TS_def assms(2) by blast
  have P3: "T1 = T"
  proof -
    have "A  B"
      using assms(2) ts_distincts by blast
    thus ?thesis
    proof -
      have "Col T1 D C"
        using Col_def P1 by blast
      hence f1: "p. (C = T1  Col C p T1)  ¬ Col C T1 p"
        by (metis assms(1) col_transitivity_1 l6_16_1 ts_distincts)
      have f2: "¬ Col C A B"
        using TS_def assms(1) by presburger
      have f3: "(Bet B T1 A  Bet T1 A B)  Bet A B T1"
        using Col_def P1 by blast
      {
        assume "T1  B"
        hence "C  T1  ¬ Col C T1 B  (p. ¬ Col p T1 B  Col p T1 T)  T  A  T  B"
          using f3 f2 by (metis (no_types) Col_def col_transitivity_1 l6_16_1)
        hence "T  A  T  B  C  T1  ¬ Col C T1 T  T1 = T"
          using f3 by (meson Col_def l6_16_1)
      }
      moreover
      {
        assume "T  A  T  B"
        hence "C  T1  ¬ Col C T1 T  T1 = T"
          using f2 by (metis (no_types) Col_def P1 P2 A  B col_transitivity_1 l6_16_1)
      }
      ultimately have "C  T1  ¬ Col C T1 T  T1 = T"
        using f2 f1 assms(1) ts_distincts by blast
      thus ?thesis
        by (metis (no_types) Col_def P1 P2 assms(1) l6_16_1 ts_distincts)
    qed
  qed
  have P4: "A C OS T B"
    by (metis Col_cases P2 TS_def assms(1) assms(2) bet_out out_one_side)
  hence "C A OS T D"
    by (metis Col_cases P1 TS_def P3 assms(2) bet_out os_distincts out_one_side)
  thus ?thesis
    by (meson P4 invert_one_side one_side_symmetry Tarski_neutral_dimensionless_axioms 
        one_side_transitivity)
qed

lemma col_one_side_out:
  assumes "Col A X Y" and
    "A B OS X Y"
  shows "A Out X Y"
  by (meson assms(1) assms(2) l6_4_2 not_col_distincts not_col_permutation_4 one_side_chara)

lemma col_two_sides_bet:
  assumes "Col A X Y" and
    "A B TS X Y"
  shows "Bet X A Y"
  using Col_cases assms(1) assms(2) l9_8_1 l9_9 or_bet_out out_out_one_side by blast

lemma os_ts1324__os:
  assumes "A X OS Y Z" and
    "A Y TS X Z"
  shows "A Z OS X Y"
proof -
  obtain P where P1: "Col P A Y  Bet X P Z"
    using TS_def assms(2) by blast
  have P2: "A Z OS X P"
    by (metis Col_cases P1 TS_def assms(1) assms(2) bet_col bet_out_1 col124__nos 
        col_trivial_2 l6_6 l9_19)
  have "A Z OS P Y"
  proof -
    have "¬ Col A Z P  ¬ Col A Z Y"
      using P2 col124__nos by blast
    moreover have "A Out P Y"
    proof -
      have "X A OS P Z"
        by (metis Col_cases P1 P2 assms(1) bet_out col123__nos out_one_side)
      hence "A X OS P Y"
        by (meson invert_one_side one_side_symmetry Tarski_neutral_dimensionless_axioms 
            assms(1) one_side_transitivity)
      thus ?thesis
        using P1 col_one_side_out not_col_permutation_4 by blast
    qed
    ultimately show ?thesis
      by (simp add: out_one_side)
  qed
  thus ?thesis
    using P2 one_side_transitivity by blast
qed

lemma ts2__ex_bet2:
  assumes "A C TS B D" and
    "B D TS A C"
  shows " X. Bet A X C  Bet B X D"
  by (metis TS_def assms(1) assms(2) bet_col col_permutation_5 l9_18_R1 not_col_permutation_2)

lemma out_one_side_1:
  assumes "¬ Col A B C" and
    "Col A B X" and
    "X Out C D"
  shows "A B OS C D"
  using assms(1) assms(2) assms(3) not_col_permutation_2 one_side_reflexivity 
    one_side_symmetry os_out_os by blast

lemma out_two_sides_two_sides:
  assumes (*"A ≠ PX" and *)
    "Col A B PX" and
    "PX Out X P" and
    "A B TS P Y"
  shows "A B TS X Y"
  using assms(1) assms(2) assms(3) l6_6 l9_5 not_col_permutation_1 by blast

lemma l8_21_bis:
  assumes "X  Y" and
    "¬ Col C A B"
  shows " P. Cong A P X Y  A B Perp P A  A B TS C P"
proof -
  have "A  B"
    using assms(2) not_col_distincts by blast
  hence " P T. A B Perp P A  Col A B T  Bet C T P"
    using l8_21 by auto
  then obtain P T where "A B Perp P A" and "Col A B T" and "Bet C T P" by blast
  have "A B TS C P"
  proof -
    have "¬ Col P A B"
      using col_permutation_1 perp_not_col A B Perp P A by blast
    thus ?thesis 
      using Col_cases TS_def Bet C T P Col A B T assms(2) by blast
  qed
  have "P  A" 
    using A B Perp P A perp_distinct by auto
  obtain P' where "(Bet A P P'  Bet A P' P)" and "Cong A P' X Y"
    using segment_construction_2 P  A by blast
  have "A B Perp P' A" 
    by (metis Bet_cases Col_def cong_identity perp_col1 A B Perp P A 
        Bet A P P'  Bet A P' P Cong A P' X Y assms(1) cong_symmetry perp_comm)
  have "¬ Col P' A B" 
    using A B Perp P' A not_col_permutation_2 perp_not_col by blast
  hence "A B OS P P'" 
    using Out_def A B Perp P A A B Perp P' A Bet A P P'  Bet A P' P 
      out_one_side perp_not_col perp_not_eq_2 by presburger
  hence "A B TS C P'" 
    using A B TS C P l9_2 l9_8_2 by blast
  thus ?thesis 
    using A B Perp P' A Cong A P' X Y by blast
qed

lemma ts__ncol:
  assumes "A B TS X Y"
  shows  "¬ Col A X Y  ¬ Col B X Y"
  by (metis TS_def assms col_permutation_1 col_transitivity_2 ts_distincts)

lemma one_or_two_sides_aux:
  assumes "¬ Col C A B" and
    "¬ Col D A B" and
    "Col A C X"
    and "Col B D X"
  shows "A B TS C D  A B OS C D"
proof -
  have P1: "A  X"
    using assms(2) assms(4) col_permutation_2 by blast
  have P2: "B  X"
    using assms(1) assms(3) col_permutation_4 by blast
  have P3: "¬ Col X A B"
    using P1 assms(1) assms(3) col_permutation_5 col_transitivity_1 not_col_permutation_4 
    by blast
  {
    assume Q0: "Bet A C X  Bet B D X"
    hence Q1: "A B OS C X"
      using assms(1) bet_out not_col_distincts not_col_permutation_1 out_one_side by blast
    hence "A B OS X D"
      by (metis Q0 assms(2) assms(4) bet_out_1 col_permutation_2 col_permutation_3 
          invert_one_side l6_4_2 not_bet_and_out not_col_distincts out_one_side)
    hence "A B OS C D"
      using Q1 one_side_transitivity by blast
  }
  hence P4: "Bet A C X  Bet B D X  A B OS C D" by blast
  {
    assume "Bet A C X  Bet D X B"
    hence "A B OS C D" 
      by (metis P2 assms(1) bet_out bet_out_1 not_col_distincts one_side_reflexivity 
          one_side_symmetry os_out_os)
  }
  hence P5: "Bet A C X  Bet D X B  A B OS C D " by blast
  {
    assume Q0: "Bet A C X  Bet X B D"
    have Q1: "A B TS X D"
      using P3 Q0 TS_def assms(2) col_trivial_3 by blast
    have "A B OS X C"
      using Q0 assms(1) bet_out not_col_distincts one_side_reflexivity one_side_symmetry 
        out_out_one_side by blast
    hence "A B TS C D"
      using Q1 l9_8_2 by blast
  }
  hence P6: "Bet A C X  Bet X B D  A B TS C D" by blast
  {
    assume Q1: "Bet C X A  Bet B D X"
    hence Q2: "A B OS C X"
      using P1 assms(1) assms(3) between_equality_2 l6_4_2 not_col_permutation_1 
        not_col_permutation_4 out_one_side by blast
    have "A B OS X D"
      using Q1 assms(2) bet_out not_col_distincts one_side_reflexivity os_out_os by blast
    hence "A B OS C D" using Q2
      using one_side_transitivity by blast
  }
  hence P7: "Bet C X A  Bet B D X  A B OS C D" by blast
  {
    assume "Bet C X A  Bet D X B"
    hence "A B OS C D" 
      by (metis Out_def P1 P2 assms(1) bet_out between_symmetry col2__eq invert_one_side 
          l9_19_R2 not_col_distincts out_out_one_side)
  }
  hence P8: "Bet C X A  Bet D X B  A B OS C D" by blast
  {
    assume Q1: "Bet C X A  Bet X B D"
    have Q2: "A B TS X D"
      by (metis P3 Q1 assms(2) bet__ts invert_two_sides not_col_distincts not_col_permutation_3)
    have Q3: "A B OS X C"
      using P1 Q1 assms(1) bet_out_1 not_col_permutation_1 out_one_side by auto
    hence "A B TS C D"
      using Q2 l9_8_2 by blast
  }
  hence P9: "Bet C X A  Bet X B D  A B TS C D" by blast
  {
    assume Q0: "Bet X A C  Bet B D X"
    have Q1: "A B TS X C"
      by (metis P3 Q0 assms(1) bet__ts col_permutation_2 not_col_distincts)
    have "A B OS X D"
      by (metis NCol_cases Q0 out_one_side assms(2) assms(4) bet_out_1 invert_one_side 
          l6_4_1 not_col_distincts not_out_bet)
    hence "A B TS C D"
      using Q1 l9_2 l9_8_2 by blast
  }
  hence P10: "Bet X A C  Bet B D X  A B TS C D" by blast
  {
    assume Q0: "Bet X A C  Bet D X B"
    have Q1: "A B TS X C"
      by (metis NCol_cases P3 Q0 assms(1) bet__ts not_col_distincts)
    have "A B OS X D"
      by (metis P2 P3 Q0 bet_out_1 col_permutation_3 invert_one_side out_one_side)
    hence "A B TS C D"
      using Q1 l9_2 l9_8_2 by blast
  }
  hence P11: "Bet X A C  Bet D X B  A B TS C D"
    by blast
  {
    assume Q0: "Bet X A C  Bet X B D"
    hence Q1: "A B TS C X"
      by (simp add: P1 Q0 assms(1) bet__ts between_symmetry not_col_permutation_1)
    have "A B TS D X"
      by (simp add: P2 Q0 assms(2) bet__ts between_symmetry invert_two_sides 
          not_col_permutation_3)
    hence "A B OS C D"
      using Q1 l9_8_1 by blast
  }
  hence P12: "Bet X A C  Bet X B D  A B OS C D" by blast
  thus ?thesis using P4 P5 P6 P7 P8 P9 P10 P11
    using Col_def assms(3) assms(4) by auto
qed

lemma cop__one_or_two_sides:
  assumes "Coplanar A B C D" and
    "¬ Col C A B" and
    "¬ Col D A B"
  shows "A B TS C D  A B OS C D"
proof -
  obtain X where P1: "Col A B X  Col C D X  Col A C X  Col B D X  Col A D X  Col B C X"
    using Coplanar_def assms(1) by auto
  have P2: "Col A B X  Col C D X  A B TS C D  A B OS C D"
    by (metis TS_def l9_19_R2 assms(2) assms(3) not_col_permutation_3 not_col_permutation_5 
        not_out_bet)
  have P3: "Col A C X  Col B D X   A B TS C D  A B OS C D"
    using assms(2) assms(3) one_or_two_sides_aux by blast
  have "Col A D X  Col B C X   A B TS C D  A B OS C D"
    using assms(2) assms(3) l9_2 one_or_two_sides_aux one_side_symmetry by blast
  thus ?thesis
    using P1 P2 P3 by blast
qed

lemma os__coplanar:
  assumes "A B OS C D"
  shows "Coplanar A B C D"
proof -
  have P1: "¬ Col A B C"
    using assms one_side_not_col123 by blast
  obtain C' where P2: "Bet C B C'  Cong B C' B C"
    using segment_construction by presburger
  have P3: "A B TS D C'"
    by (metis Cong_perm OS_def P2 TS_def assms bet__ts bet_cong_eq invert_one_side l9_10 
        l9_8_2 one_side_not_col123 ts_distincts)
  obtain T where P4: "Col T A B  Bet D T C'"
    using P3 TS_def by blast
  have P5: "C'  T"
    using P3 P4 TS_def by blast
  have P6: "Col T B C  Coplanar A B C D"
    by (metis Col_def Coplanar_def P2 P4 P5 col_trivial_2 l6_16_1)
  {
    assume Q0: "¬ Col T B C"
    {
      assume R0: "Bet T B A"
      have S1: "B C TS T A"
        by (metis P1 Q0 R0 bet__ts col_permutation_2 not_col_distincts)
      have "C' Out T D"
        using P4 P5 bet_out_1 by auto
      hence "B C OS T D"
        using P2 Q0 bet_col invert_one_side not_col_permutation_3 out_one_side_1 by blast
      hence R1: "B C TS D A"
        using S1 l9_8_2 by blast
      hence "Coplanar A B C D"
        using ncoplanar_perm_9 ts__coplanar by blast
    }
    hence Q1: "Bet T B A  Coplanar A B C D" by blast
    {
      assume R0: "¬ Bet T B A"
      {
        have R2: "B C OS D T"
        proof -
          have S1: "¬ Col B C D"
            by (metis Col_perm P2 P3 P4 Q0 bet_col colx ts_distincts)
          have S2: "Col B C C'"
            by (simp add: P2 bet_col col_permutation_4)
          have S3: "C' Out D T"
            using P4 P5 bet_out_1 l6_6 by auto
          thus ?thesis
            using S1 S2 out_one_side_1 by blast
        qed
        have R3: "B C OS T A"
          using P4 Q0 R0 col_permutation_2 col_permutation_5 not_bet_out out_one_side by blast
      }
      hence R1: "B C OS D A"
        by (metis P2 P4 Q0 bet_col bet_out_1 col_permutation_2 col_permutation_5 os_out_os)
      hence "Coplanar A B C D"
        by (simp add: R1 assms coplanar_perm_19 invert_one_side l9_31 one_side_symmetry 
            ts__coplanar)
    }
    hence "¬ Bet T B A  Coplanar A B C D" by blast
    hence "Coplanar A B C D" using Q1 by blast
  }
  hence "¬ Col T B C  Coplanar A B C D" by blast
  thus ?thesis using P6 by blast
qed

lemma coplanar_trans_1:
  assumes "¬ Col P Q R" and
    "Coplanar P Q R A" and
    "Coplanar P Q R B"
  shows "Coplanar Q R A B"
proof -
  have P1: "Col Q R A  Coplanar Q R A B"
    by (simp add: col__coplanar)
  {
    assume T1: "¬ Col Q R A"
    {
      assume T2: "¬ Col Q R B"
      {
        have "Col Q A B  Coplanar Q R A B"
          using ncop__ncols by blast
        {
          assume S1: "¬ Col Q A B"
          have U1: "Q R TS P A  Q R OS P A"
            by (simp add: T1 assms(1) assms(2) cop__one_or_two_sides coplanar_perm_8 
                not_col_permutation_2)
          have U2: "Q R TS P B  Q R OS P B"
            using T2 assms(1) assms(3) col_permutation_1 cop__one_or_two_sides 
              coplanar_perm_8 by blast
          have W1: "Q R TS P A  Q R OS P A  Q R TS A B  Q R OS A B"
            using l9_9 by blast
          have W2: "Q R TS P A  Q R OS P B  Q R TS A B  Q R OS A B"
            using l9_2 l9_8_2 by blast
          have W3: "Q R TS P B  Q R OS P A  Q R TS A B  Q R OS A B"
            using l9_8_2 by blast
          have "Q R TS P B  Q R OS P B  Q R TS A B  Q R OS A B"
            using l9_9 by blast
          hence S2: "Q R TS A B  Q R OS A B" using U1 U2 W1 W2 W3
            using OS_def l9_2 one_side_transitivity by blast
          have "Coplanar Q R A B"
            using S2 os__coplanar ts__coplanar by blast
        }
        hence "¬ Col Q A B  Coplanar Q R A B" by blast
      }
      hence "Coplanar Q R A B"
        using ncop__ncols by blast
    }
    hence "¬ Col Q R B  Coplanar Q R A B"
      by blast
  }
  hence "¬ Col Q R A  Coplanar Q R A B"
    using ncop__ncols by blast
  thus ?thesis using P1 by blast
qed

lemma col_cop__cop:
  assumes "Coplanar A B C D" and
    "C  D" and
    "Col C D E"
  shows "Coplanar A B C E"
proof -
  have "Col D A C  Coplanar A B C E"
    by (meson assms(2) assms(3) col_permutation_1 l6_16_1 ncop__ncols)
  moreover
  {
    assume "¬ Col D A C"
    hence "Coplanar A C B E"
      by (meson assms(1) assms(3) col__coplanar coplanar_trans_1 ncoplanar_perm_11 
          ncoplanar_perm_13)
    hence "Coplanar A B C E"
      using ncoplanar_perm_2 by blast
  }
  ultimately show ?thesis
    by blast
qed

lemma bet_cop__cop:
  assumes "Coplanar A B C E" and
    "Bet C D E"
  shows "Coplanar A B C D"
  by (metis NCol_perm col_cop__cop assms(1) assms(2) bet_col bet_neq12__neq)

lemma col2_cop__cop:
  assumes "Coplanar A B C D" and
    "C  D" and
    "Col C D E" and
    "Col C D F"
  shows "Coplanar A B E F"
proof cases
  assume "C = E"
  thus ?thesis
    using assms(1) assms(2) assms(4) col_cop__cop by blast
next
  assume "C  E"
  thus ?thesis
    by (metis assms(1) assms(2) assms(3) assms(4) col_cop__cop col_transitivity_1 
        ncoplanar_perm_1 not_col_permutation_4)
qed

lemma col_cop2__cop:
  assumes "U  V" and
    "Coplanar A B C U" and
    "Coplanar A B C V" and
    "Col U V P"
  shows "Coplanar A B C P"
proof cases
  assume "Col A B C"
  thus ?thesis
    using ncop__ncol by blast
next
  assume "¬ Col A B C"
  {
    fix A0 B0 C0
    assume "¬ Col A0 B0 C0" and "¬ Col U A0 B0" and "Coplanar A0 B0 C0 U" and 
      "Coplanar A0 B0 C0 V" and "¬ Col A0 B0 C0"
    have "Coplanar U A0 B0 P" 
      by (meson col_trivial_3 Coplanar A0 B0 C0 U Coplanar A0 B0 C0 V ¬ Col A0 B0 C0 
          assms(1) assms(4) col2_cop__cop coplanar_trans_1 ncoplanar_perm_8 
          not_col_permutation_1)
    hence "Coplanar A0 B0 C0 P" 
      using Coplanar A0 B0 C0 U  ¬ Col U A0 B0 coplanar_perm_18 coplanar_trans_1 by blast
  }
  moreover
  {
    assume "Col U A B" and "Col U A C"
    hence "Coplanar A B C P" 
      by (metis ¬ Col A B C assms(1) assms(3) assms(4) col_cop__cop 
          col_transitivity_2 coplanar_perm_14)
  }
  moreover
  {
    assume "Col U A B" and "¬ Col U A C"
    hence "Coplanar A B C P" 
      using calculation(1) ¬ Col A B C assms(2) assms(3) coplanar_perm_2 
        not_col_permutation_5 by blast
  }
  moreover
  {
    assume "¬ Col U A B" and "Col U A C"
    hence "Coplanar A B C P" 
      using ¬ Col A B C assms(2) assms(3) calculation(1) by blast
  }
  moreover
  {
    assume "¬ Col U A B" and "¬ Col U A C"
    hence "Coplanar A B C P" 
      using ¬ Col A B C assms(2) assms(3) calculation(1) by blast
  }
  ultimately show ?thesis 
    by blast
qed

lemma bet_cop2__cop:
  assumes "Coplanar A B C U" and
    "Coplanar A B C W" and
    "Bet U V W"
  shows "Coplanar A B C V"
proof -
  have "Col U V W"
    using assms(3) bet_col by blast
  hence "Col U W V"
    by (meson not_col_permutation_5)
  thus ?thesis
    using assms(1) assms(2) assms(3) bet_neq23__neq col_cop2__cop by blast
qed

lemma coplanar_pseudo_trans_lem1:
  assumes "¬ Col P Q R" and
    "Coplanar P Q R A" and
    "Coplanar P Q R B" and
    "Coplanar P Q R C"
  shows "Coplanar A B C R" 
proof cases
  assume "Col R Q A"
  have "Coplanar B C R Q" 
    using assms(1) assms(3) assms(4) coplanar_perm_17 coplanar_trans_1 by blast
  thus ?thesis
    using Col R Q A assms(1) col_cop__cop coplanar_perm_2 coplanar_perm_20 
      not_col_distincts by blast
next
  assume "¬ Col R Q A"
  thus ?thesis
    by (meson assms(1) assms(2) assms(3) assms(4) coplanar_trans_1 ncoplanar_perm_18 
        not_col_permutation_4)
qed

lemma coplanar_pseudo_trans:
  assumes "¬ Col P Q R" and
    "Coplanar P Q R A" and
    "Coplanar P Q R B" and
    "Coplanar P Q R C" and
    "Coplanar P Q R D"
  shows "Coplanar A B C D"
proof cases
  assume "Col P Q D"
  moreover have "P  Q"
    using assms(1) col_trivial_1 by blast
  moreover have "Coplanar A B C Q" 
    using coplanar_pseudo_trans_lem1 
    by (meson assms(1) assms(2) assms(3) assms(4) col_permutation_5 coplanar_perm_2)
  moreover have "Coplanar A B C P" 
  proof -
    have "¬ Col Q R P"
      using Col_cases assms(1) by blast
    moreover have "Coplanar Q R P A"
      using assms(2) ncoplanar_perm_12 by blast
    moreover have "Coplanar Q R P B"
      using assms(3) ncoplanar_perm_12 by blast
    moreover have "Coplanar Q R P C"
      using assms(4) ncoplanar_perm_12 by blast
    ultimately show ?thesis
      using coplanar_pseudo_trans_lem1 by blast
  qed
  ultimately show ?thesis
    using coplanar_pseudo_trans_lem1 col_cop2__cop by blast
next
  assume "¬ Col P Q D"
  moreover have "Coplanar P Q D A"
    using NCol_cases assms(1) assms(2) assms(5) coplanar_trans_1 ncoplanar_perm_8 by blast
  moreover have "Coplanar P Q D B"
    using assms(1) assms(3) assms(5) col_permutation_1 coplanar_perm_12 
      coplanar_trans_1 by blast
  moreover have "Coplanar P Q D C"
    by (meson assms(1) assms(4) assms(5) coplanar_perm_7 coplanar_trans_1 
        ncoplanar_perm_14 not_col_permutation_3)
  ultimately show ?thesis 
    using coplanar_pseudo_trans_lem1 by blast
qed

lemma l9_30:
  assumes "¬ Coplanar A B C P" and
    "¬ Col D E F" and
    "Coplanar D E F P" and
    "Coplanar A B C X" and
    "Coplanar A B C Y" and
    "Coplanar A B C Z" and
    "Coplanar D E F X" and
    "Coplanar D E F Y" and
    "Coplanar D E F Z"
  shows "Col X Y Z"
proof -
  {
    assume P1: "¬ Col X Y Z"
    have P2: "¬ Col A B C"
      using assms(1) col__coplanar by blast
    have "Coplanar A B C P"
    proof -
      have Q2: "Coplanar X Y Z A" 
        by (meson P2 col_trivial_3 assms(4) assms(5) assms(6) coplanar_pseudo_trans ncop__ncols)
      have Q3: "Coplanar X Y Z B"
        using P2 assms(4) assms(5) assms(6) col_trivial_3 coplanar_pseudo_trans 
          ncop__ncols by blast
      have Q4: "Coplanar X Y Z C"
        using P2 assms(4) assms(5) assms(6) col_trivial_2 coplanar_pseudo_trans 
          ncop__ncols by blast
      have "Coplanar X Y Z P"
        using assms(2) assms(3) assms(7) assms(8) assms(9) coplanar_pseudo_trans by blast
      thus ?thesis using P1 Q2 Q3 Q4
        using assms(2) assms(3) assms(7) assms(8) assms(9) coplanar_pseudo_trans by blast
    qed
    hence "False" using assms(1) by blast
  }
  thus ?thesis by blast
qed

lemma cop_per2__col:
  assumes "Coplanar A X Y Z" and
    "A  Z" and
    "Per X Z A" and
    "Per Y Z A"
  shows "Col X Y Z"
proof cases
  assume "X = Y  X = Z  Y = Z"
  thus ?thesis
    using not_col_distincts by blast
next
  assume "¬ (X = Y  X = Z  Y = Z)"
  obtain B where "Cong X A X B" and "Z Midpoint A B" and "Cong Y A Y B"
    using Per_def assms(3) assms(4) per_double_cong by blast
  have "X  Y" 
    using ¬ (X = Y  X = Z  Y = Z) by blast
  have "X  Z" 
    using ¬ (X = Y  X = Z  Y = Z) by blast
  have "Y  Z" 
    using ¬ (X = Y  X = Z  Y = Z) by blast
  obtain I where "Col A X I  Col Y Z I  Col A Y I  Col X Z I  Col A Z I  Col X Y I"
    using Coplanar_def assms(1) by auto
  moreover
  {
    assume "Col A X I" and "Col Y Z I"
    have "Col X Y Z" 
    proof (cases "X = I")
      assume "X = I"
      thus ?thesis
        using Col_cases Col Y Z I by blast
    next
      assume "X  I"
      have "Col A X I  Col Y Z I  Col X Y Z"
        by (metis (full_types) ¬ (X = Y  X = Z  Y = Z) assms(2,3,4) col_per2__per l8_3 l8_8
            not_col_permutation_2 not_col_permutation_4) 
      moreover have "Col A Y I  Col X Z I  Col X Y Z"
        by (simp add: Col A X I Col Y Z I calculation) 
      moreover have "Col A Z I  Col X Y I  Col X Y Z"
        by (simp add: Col A X I Col Y Z I calculation(1))
      ultimately show "Col X Y Z"
        using Col A X I Col Y Z I by blast 
    qed
  }
  moreover have "Col A Y I  Col X Z I  Col X Y Z"
  proof cases
    assume "X = I"
    thus ?thesis
      by (metis Col_cases Cong X A X B Cong Y A Y B Z Midpoint A B 
          l4_18 midpoint_distinct_3)
  next
    assume "X  I"
    thus ?thesis 
      by (metis Col_cases midpoint_bet per_double_cong Cong Y A Y B Z Midpoint A B 
          assms(2) assms(3) between_equality between_trivial col_trivial_3 l4_18 l8_3)
  qed
  moreover 
  {
    assume "Col A Z I" and "Col X Y I"
    hence "Z = I  Col X Y Z" 
      by simp 
    moreover
    {
      assume "Z  I" 
      have "Cong I A I B" 
        using l4_17 [where ?A = "X" and ?B ="Y"]
          X  Y Col X Y I Cong X A X B Cong Y A Y B by auto
      have "(Col A I B  Cong I A I B)  (A = B  I Midpoint A B)" 
        using l7_20_bis by blast
      moreover have "A = B  Col X Y Z" 
        using Z Midpoint A B assms(2) l7_3 by auto
      moreover have "I Midpoint A B  ?thesis" 
        using Z Midpoint A B Z  I l7_17 by blast
      ultimately have "Col X Y Z" 
        using Col_cases Per_def Col A Z I Cong I A I B Z Midpoint A B 
          assms(2) l8_9 by blast
    }
    ultimately have "Col X Y Z" 
      by blast
  }
  ultimately show ?thesis
    by blast
qed

lemma cop_perp2__col:
  assumes "Coplanar A B Y Z" and
    "X Y Perp A B" and
    "X Z Perp A B"
  shows "Col X Y Z"
proof cases
  assume P1: "Col A B X"
  {
    assume Q0: "X = A"
    hence Q1: "X  B"
      using assms(3) perp_not_eq_2 by blast
    have Q2: "Coplanar B Y Z X"
      by (simp add: Q0 assms(1) coplanar_perm_9)
    have Q3: "Per Y X B"
      using Q0 assms(2) perp_per_2 by blast
    have "Per Z X B"
      using Q0 assms(3) perp_per_2 by blast
    hence "Col X Y Z"
      using Q1 Q2 Q3 cop_per2__col not_col_permutation_1 by blast
  }
  hence P2: "X = A  Col X Y Z" by blast
  {
    assume Q0: "X  A"
    have Q1: "A X Perp X Y"
      by (metis P1 Perp_perm Q0 assms(2) perp_col1)
    have Q2: "A X Perp X Z"
      by (metis P1 Perp_perm Q0 assms(3) perp_col1)
    have Q3: "Coplanar A Y Z X" 
      by (metis P1 assms(1) assms(2) col_cop2__cop coplanar_perm_3 coplanar_trivial 
          perp_distinct)
    have Q4: "Per Y X A"
      using Perp_perm Q1 perp_per_2 by blast
    have "Per Z X A"
      using P1 Q0 assms(3) perp_col1 perp_per_1 by auto
    hence "Col X Y Z"
      using Q0 Q3 Q4 cop_per2__col not_col_permutation_1 by blast
  }
  hence "X  A  Col X Y Z" by blast
  thus ?thesis
    using P2 by blast
next
  assume P1: "¬ Col A B X"
  obtain Y0 where P2: "Y0 PerpAt X Y A B"
    using Perp_def assms(2) by blast
  obtain Z0 where P3: "Z0 PerpAt X Z A B"
    using Perp_def assms(3) by auto
  have P4: "X Y0 Perp A B"
    by (metis P1 P2 assms(2) perp_col perp_in_col)
  have P5: "X Z0 Perp A B"
    by (metis P1 P3 assms(3) perp_col perp_in_col)
  have P6: "Y0 = Z0"
    by (meson P1 P2 P3 P4 P5 Perp_perm l8_18_uniqueness perp_in_col)
  have P7: "X  Y0"
    using P4 perp_not_eq_1 by blast
  have P8: "Col X Y0 Y"
    using P2 col_permutation_5 perp_in_col by blast
  have "Col X Y0 Z"
    using P3 P6 col_permutation_5 perp_in_col by blast
  thus ?thesis
    using P7 P8 col_transitivity_1 by blast
qed

lemma two_sides_dec:
  shows "A B TS C D  ¬ A B TS C D"
  by simp

lemma cop_nts__os:
  assumes "Coplanar A B C D" and
    "¬ Col C A B" and
    "¬ Col D A B" and
    "¬ A B TS C D"
  shows "A B OS C D"
  using assms(1) assms(2) assms(3) assms(4) cop__one_or_two_sides by blast

lemma cop_nos__ts:
  assumes "Coplanar A B C D" and
    "¬ Col C A B" and
    "¬ Col D A B" and
    "¬ A B OS C D"
  shows "A B TS C D"
  using assms(1) assms(2) assms(3) assms(4) cop_nts__os by blast

lemma one_side_dec:
  "A B OS C D  ¬ A B OS C D"
  by simp

lemma cop_dec:
  "Coplanar A B C D  ¬ Coplanar A B C D"
  by simp

lemma ex_diff_cop:
  " E. Coplanar A B C E  D  E"
  by (metis col_trivial_2 diff_col_ex ncop__ncols)

lemma ex_ncol_cop:
  assumes "D  E"
  shows " F. Coplanar A B C F  ¬ Col D E F"
proof cases
  assume "Col A B C"
  thus ?thesis
    using assms ncop__ncols not_col_exists by blast
next
  assume P1: "¬ Col A B C"
  thus ?thesis
  proof -
    have P2: "(Col D E A  Col D E B)  ( F. Coplanar A B C F  ¬ Col D E F)"
      by (meson P1 assms col3 col_trivial_2 ncop__ncols)
    have P3: "(¬Col D E A  Col D E B)  ( F. Coplanar A B C F  ¬ Col D E F)"
      using col_trivial_3 ncop__ncols by blast
    have P4: "(Col D E A  ¬Col D E B)  ( F. Coplanar A B C F  ¬ Col D E F)"
      using col_trivial_2 ncop__ncols by blast
    have "(¬Col D E A  ¬Col D E B)  ( F. Coplanar A B C F  ¬ Col D E F)"
      using col_trivial_3 ncop__ncols by blast
    thus ?thesis using P2 P3 P4 by blast
  qed
qed

lemma ex_ncol_cop2:
  " E F. (Coplanar A B C E  Coplanar A B C F  ¬ Col D E F)"
proof -
  have "Coplanar A B C A" 
    by (simp add: coplanar_perm_3 coplanar_trivial)
  have "Coplanar A B C C" 
    using col_trivial_2 ncop__ncols by blast
  have "p. A  p"
    by (meson col_trivial_3 diff_col_ex3)
  moreover
  { 
    assume "B  A"
    hence "D = B  (p. ¬ Col D p A  Coplanar A B C p)" 
      by (metis Col_cases Coplanar A B C C ncop__ncols not_col_exists)
    hence "D = B  (p pa. Coplanar A B C p  Coplanar A B C pa  ¬ Col D p pa)" 
      using Coplanar A B C A by blast
  }
  moreover
  { 
    assume "D  B"
    moreover
    { 
      assume "p. D  B  ¬ Coplanar A B C p"
      hence "D  B  ¬ Col A B C"
        using ncop__ncols by blast
      hence "p. ¬ Col D p B  Coplanar A B C p" 
        by (metis Col_cases Coplanar A B C A Coplanar A B C C col2__eq)
    }
    ultimately have ?thesis 
      by (meson col_trivial_3 ncop__ncols not_col_exists)
  }
  ultimately show ?thesis 
    using coplanar_trivial ex_ncol_cop by blast
qed

lemma col2_cop2__eq:
  assumes "¬ Coplanar A B C U" and
    "U  V" and
    "Coplanar A B C P" and
    "Coplanar A B C Q" and
    "Col U V P" and
    "Col U V Q"
  shows "P = Q"
proof -
  have "Col U Q P"
    by (meson assms(2) assms(5) assms(6) col_transitivity_1)
  hence "Col P Q U"
    using not_col_permutation_3 by blast
  thus ?thesis
    using assms(1) assms(3) assms(4) col_cop2__cop by blast
qed

lemma cong3_cop2__col:
  assumes "Coplanar A B C P" and
    "Coplanar A B C Q" and
    "P  Q" and
    "Cong A P A Q" and
    "Cong B P B Q" and
    "Cong C P C Q"
  shows "Col A B C"
proof cases
  assume "Col A B C"
  thus ?thesis by blast
next
  assume P1: "¬ Col A B C"
  obtain M where P2: "M Midpoint P Q"
    using assms(6) l7_25 by blast
  have P3: "Per A M P"
    using P2 Per_def assms(4) by blast
  have P4: "Per B M P"
    using P2 Per_def assms(5) by blast
  have P5: "Per C M P"
    using P2 Per_def assms(6) by blast
  have "False"
  proof cases
    assume Q1: "A = M"
    have Q2: "Coplanar P B C A"
      using assms(1) ncoplanar_perm_21 by blast
    have Q3: "P  A"
      by (metis assms(3) assms(4) cong_diff_4)
    have Q4: "Per B A P"
      by (simp add: P4 Q1)
    have Q5: "Per C A P"
      by (simp add: P5 Q1)
    thus ?thesis using Q1 Q2 Q3 Q4 cop_per2__col
      using P1 not_col_permutation_1 by blast
  next
    assume Q0: "A  M"
    have Q1: "Col A B M"
    proof -
      have R1: "Coplanar A B P Q"
        using P1 assms(1) assms(2) coplanar_trans_1 ncoplanar_perm_8 not_col_permutation_2 
        by blast
      hence R2: "Coplanar P A B M"
        using P2 bet_cop__cop coplanar_perm_14 midpoint_bet ncoplanar_perm_6 by blast
      have R3: "P  M"
        using P2 assms(3) l7_3_2 l7_9_bis by blast
      have R4: "Per A M P"
        by (simp add: P3)
      have R5: "Per B M P"
        by (simp add: P4)
      thus ?thesis
        using R2 R3 R4 cop_per2__col by blast
    qed
    have "Col A C M"
    proof -
      have R1: "Coplanar P A C M"
        using P1 Q1 assms(1) col2_cop__cop coplanar_perm_22 ncoplanar_perm_3 
          not_col_distincts by blast
      have R2: "P  M"
        using P2 assms(3) l7_3_2 symmetric_point_uniqueness by blast
      have R3: "Per A M P"
        by (simp add: P3)
      have "Per C M P"
        by (simp add: P5)
      thus ?thesis
        using R1 R2 R3 cop_per2__col by blast
    qed
    thus ?thesis
      using NCol_perm P1 Q0 Q1 col_trivial_3 colx by blast
  qed
  thus ?thesis by blast
qed

lemma l9_38:
  assumes "A B C TSP P Q"
  shows "A B C TSP Q P"
  using Bet_perm TSP_def assms by blast

lemma l9_39:
  assumes "A B C TSP P R" and
    "Coplanar A B C D" and
    "D Out P Q"
  shows "A B C TSP Q R"
proof -
  have P1: "¬ Col A B C"
    using TSP_def assms(1) ncop__ncol by blast
  have P2: "¬ Coplanar A B C Q"
    by (metis TSP_def assms(1) assms(2) assms(3) col_cop2__cop l6_6 out_col out_diff2)
  have P3: "¬ Coplanar A B C R"
    using TSP_def assms(1) by blast
  obtain T where P3A: "Coplanar A B C T  Bet P T R"
    using TSP_def assms(1) by blast
  have W1: "D = T  A B C TSP Q R"
    using P2 P3 P3A TSP_def assms(3) bet_out__bet by blast
  {
    assume V1: "D  T"
    have V1A: "¬ Col P D T" using P3A col_cop2__cop
      by (metis TSP_def V1 assms(1) assms(2) col2_cop2__eq col_trivial_2)
    have V1B: "D T TS P R"
      by (metis P3 P3A V1A bet__ts invert_two_sides not_col_permutation_3)
    have "D T OS P Q"
      using V1A assms(3) not_col_permutation_1 out_one_side by blast
    hence V2: "D T TS Q R"
      using V1B l9_8_2 by blast
    then obtain T' where V3: "Col T' D T  Bet Q T' R"
      using TS_def by blast
    have V4: "Coplanar A B C T'"
      using Col_cases P3A V1 V3 assms(2) col_cop2__cop by blast
    hence "A B C TSP Q R"
      using P2 P3 TSP_def V3 by blast
  }
  hence "D  T  A B C TSP Q R" by blast
  thus ?thesis using W1 by blast
qed

lemma l9_41_1:
  assumes "A B C TSP P R" and
    "A B C TSP Q R"
  shows "A B C OSP P Q"
  using OSP_def assms(1) assms(2) by blast

lemma l9_41_2:
  assumes "A B C TSP P R" and
    "A B C OSP P Q"
  shows "A B C TSP Q R"
proof -
  have P1: "¬ Coplanar A B C P"
    using TSP_def assms(1) by blast
  obtain S where P2: " A B C TSP P S  A B C TSP Q S"
    using OSP_def assms(2) by blast
  obtain X where P3: "Coplanar A B C X  Bet P X S"
    using P2 TSP_def by blast
  have P4: "¬ Coplanar A B C P  ¬ Coplanar A B C S"
    using P2 TSP_def by blast
  obtain Y where P5: "Coplanar A B C Y  Bet Q Y S"
    using P2 TSP_def by blast
  have P6: "¬ Coplanar A B C Q  ¬ Coplanar A B C S"
    using P2 TSP_def by blast
  have P7: "X  P  S  X  Q  Y  S  Y"
    using P3 P4 P5 P6 by blast
  {
    assume Q1: "Col P Q S"
    have Q2: "X = Y"
    proof -
      have R2: "Q  S"
        using P5 P6 bet_neq12__neq by blast
      have R5: "Col Q S X" 
        by (metis Col_def P3 Q1 between_equality_2 l6_16_1 not_bet_distincts)
      have "Col Q S Y"
        by (simp add: P5 bet_col col_permutation_5)
      thus ?thesis
        using P2 P3 P5 R2 R5 TSP_def col2_cop2__eq by blast
    qed
    hence "X Out P Q"
      by (metis P3 P5 P7 l6_2)
    hence "A B C TSP Q R"
      using P3 assms(1) l9_39 by blast
  }
  hence P7: "Col P Q S  A B C TSP Q R" by blast
  {
    assume Q1: "¬ Col P Q S"
    obtain Z where Q2: "Bet X Z Q  Bet Y Z P"
      using P3 P5 inner_pasch by blast
    {
      assume "X = Z"
      hence "False"
        by (metis P2 P3 P5 Q1 Q2 TSP_def bet_col col_cop2__cop l6_16_1 not_col_permutation_5)
    }
    hence Q3: "X  Z" by blast
    have "Y  Z"
    proof -
      have "X  Z"
        by (meson X = Z  False)
      hence "Z  Y"
        by (metis P2 P3 P5 Q2 TSP_def bet_col col_cop2__cop)
      thus ?thesis
        by meson
    qed
    hence "Y Out P Z"
      using Q2 bet_out l6_6 by auto
    hence Q4: "A B C TSP Z R"
      using assms(1) P5 l9_39 by blast
    have "X Out Z Q"
      using Q2 Q3 bet_out by auto
    hence "A B C TSP Q R"
      using Q4 P3 l9_39 by blast
  }
  hence "¬ Col P Q S  A B C TSP Q R" by blast
  thus ?thesis using P7 by blast
qed

lemma tsp_exists:
  assumes "¬ Coplanar A B C P"
  shows " Q. A B C TSP P Q"
proof -
  obtain Q where "Bet P A Q" and "Cong A Q A P"
    using segment_construction by blast
  moreover have "Coplanar A B C A"
    using coplanar_trivial ncoplanar_perm_5 by blast
  moreover have "¬ Coplanar A B C Q" 
    by (metis assms bet_col bet_col1 between_cong between_symmetry calculation(1) 
        calculation(2) calculation(3) col2_cop2__eq)
  ultimately show ?thesis
    using TSP_def assms by blast
qed

lemma osp_reflexivity:
  assumes "¬ Coplanar A B C P"
  shows "A B C OSP P P"
  by (meson assms l9_41_1 tsp_exists)

lemma osp_symmetry:
  assumes "A B C OSP P Q"
  shows "A B C OSP Q P"
  using OSP_def assms by auto

lemma osp_transitivity:
  assumes "A B C OSP P Q" and
    "A B C OSP Q R"
  shows "A B C OSP P R"
  using OSP_def assms(1) assms(2) l9_41_2 by blast

lemma cop3_tsp__tsp:
  assumes "¬ Col D E F" and
    "Coplanar A B C D" and
    "Coplanar A B C E" and
    "Coplanar A B C F" and
    "A B C TSP P Q"
  shows "D E F TSP P Q"
proof -
  obtain T where "Coplanar A B C T" and "Bet P T Q"
    using TSP_def assms(5) by blast
  have "¬ Col A B C"
    using TSP_def assms(5) ncop__ncols by blast
  have "Coplanar D E F A  Coplanar D E F B  Coplanar D E F C  Coplanar D E F T"
  proof -
    have "Coplanar D E F A"
      using assms(2) assms(3) assms(4) col_trivial_3 coplanar_pseudo_trans ncop__ncols 
      by (meson ¬ Col A B C)
    moreover have "Coplanar D E F B"
      using assms(2) assms(3) assms(4) col_trivial_2 coplanar_pseudo_trans ncop__ncols 
      by (meson ¬ Col A B C)
    moreover have "Coplanar D E F C"
      by (meson  ¬ Col A B C assms(2) assms(3) assms(4) coplanar_perm_16 coplanar_pseudo_trans 
          coplanar_trivial)
    moreover have "Coplanar D E F T"
      using ¬ Col A B C assms(2) assms(3) assms(4) coplanar_pseudo_trans Coplanar A B C T 
      by blast
    ultimately show ?thesis 
      by simp
  qed
  hence "¬ Coplanar D E F P"
    using TSP_def assms(1) assms(5) coplanar_pseudo_trans by auto
  hence "¬ Coplanar D E F Q"
    using TSP_def assms(5) bet_col bet_col1 col2_cop2__eq Bet P T Q Coplanar A B C T 
      Coplanar D E F A  Coplanar D E F B  Coplanar D E F C  Coplanar D E F T by metis
  thus ?thesis 
    using TSP_def Bet P T Q ¬ Coplanar D E F P
      Coplanar D E F A  Coplanar D E F B  Coplanar D E F C  Coplanar D E F T by blast
qed

lemma cop3_osp__osp:
  assumes "¬ Col D E F" and
    "Coplanar A B C D" and
    "Coplanar A B C E" and
    "Coplanar A B C F" and
    "A B C OSP P Q"
  shows "D E F OSP P Q"
proof -
  obtain R where "A B C TSP P R" and "A B C TSP Q R"
    using OSP_def assms(5) by blast
  thus ?thesis
    using OSP_def assms(1) assms(2) assms(3) assms(4) cop3_tsp__tsp by blast
qed

lemma ncop_distincts:
  assumes "¬ Coplanar A B C D"
  shows "A  B  A  C  A  D  B  C  B  D  C  D"
  using Coplanar_def assms col_trivial_1 col_trivial_2 by blast

lemma tsp_distincts:
  assumes "A B C TSP P Q"
  shows "A  B  A  C  B  C  A  P  B  P  C  P  A  Q  B  Q  C  Q  P  Q"
proof -
  obtain X where "¬ Coplanar A B C P  ¬ Coplanar A B C Q  Coplanar A B C X  Bet P X Q" 
    by (metis TSP_def assms)
  hence "Q  X"
    by force
  thus ?thesis 
    using ¬ Coplanar A B C P  ¬ Coplanar A B C Q  Coplanar A B C X  Bet P X Q 
      bet_neq32__neq ncop_distincts by blast
qed

lemma osp_distincts:
  assumes "A B C OSP P Q"
  shows "A  B  A  C  B  C  A  P  B  P  C  P  A  Q  B  Q  C  Q"
  using OSP_def assms tsp_distincts by blast

lemma tsp__ncop1:
  assumes "A B C TSP P Q"
  shows "¬ Coplanar A B C P"
  using TSP_def assms by blast

lemma tsp__ncop2:
  assumes "A B C TSP P Q"
  shows "¬ Coplanar A B C Q"
  using TSP_def assms by auto

lemma osp__ncop1:
  assumes "A B C OSP P Q"
  shows "¬ Coplanar A B C P"
  using OSP_def TSP_def assms by blast

lemma osp__ncop2:
  assumes "A B C OSP P Q"
  shows "¬ Coplanar A B C Q"
  using assms osp__ncop1 osp_symmetry by blast

lemma tsp__nosp:
  assumes "A B C TSP P Q"
  shows "¬ A B C OSP P Q"
  using assms l9_41_2 tsp_distincts by blast

lemma osp__ntsp:
  assumes "A B C OSP P Q"
  shows "¬ A B C TSP P Q"
  using assms tsp__nosp by blast

lemma osp_bet__osp:
  assumes "A B C OSP P R" and
    "Bet P Q R"
  shows "A B C OSP P Q"
proof -
  obtain S where "A B C TSP P S"
    using OSP_def assms(1) by blast
  then obtain Y where "Coplanar A B C Y" and "Bet R Y S"
    using TSP_def assms(1) l9_41_2 by blast
  obtain X where "Coplanar A B C X" and "Bet P X S" 
    by (metis TSP_def A B C TSP P S)
  have "P  X  S  X  R  Y" 
    using TSP_def A B C TSP P S Coplanar A B C X Coplanar A B C Y assms(1) 
      osp__ncop2 by blast
  {
    assume "Col P R S"
    have "A B C TSP Q S"
    proof -
      have "X = Y"
      proof -
        have "¬ Coplanar A B C R"
          using assms(1) osp__ncop2 by blast
        moreover have "R  S" 
          using Bet R Y S P  X  S  X  R  Y between_identity by blast
        moreover have "Col R S X" 
          by (metis Bet_cases Col_cases Col_def Bet P X S Col P R S between_equality_2 
              col_transitivity_1 outer_transitivity_between point_construction_different)
        moreover have "Col R S Y" 
          using Bet R Y S bet_col1 between_trivial by blast
        ultimately show ?thesis 
          using  Coplanar A B C X Coplanar A B C Y col2_cop2__eq by blast
      qed
      have "X Out P R" 
        using Bet P X S Bet R Y S P  X  S  X  R  Y X = Y l6_2 by blast
      hence "Y Out P Q" 
        using X = Y assms(2) out_bet_out_1 by blast 
      thus ?thesis 
        using A B C TSP P S Coplanar A B C Y l9_39 by blast
    qed
    hence "A B C OSP P Q" 
      using OSP_def A B C TSP P S by blast
  }
  moreover
  {
    assume "¬ Col P R S"
    have "X Y OS P R"
    proof -
      have "P  X  S  X  R  Y  S  Y" 
        using A B C TSP P S Coplanar A B C Y P  X  S  X  R  Y tsp__ncop2 by force
      have "¬ Col S X Y"
        using bet_out_1 col_out2_col col_permutation_5 not_col_permutation_4 
        by (metis Bet P X S Bet R Y S P  X  S  X  R  Y  S  Y ¬ Col P R S)
      have "X Y TS P S"
        using Col_perm bet__ts bet_col col_transitivity_2 
        by (metis Bet P X S P  X  S  X  R  Y ¬ Col S X Y)
      have "X Y TS R S"
        using assms(1) bet__ts col_cop2__cop invert_two_sides not_col_distincts osp__ncop2 
          Bet R Y S Coplanar A B C X Coplanar A B C Y ¬ Col S X Y by metis
      thus ?thesis 
        using X Y TS P S l9_8_1 by auto
    qed
    hence "X Y OS P Q" 
      using assms(2) l9_17 by blast
    then obtain S' where "X Y TS P S'" and "X Y TS Q S'"
      using OS_def by blast
    have "¬ Col P X Y  ¬ Col S' X Y  ( T::'p. Col T X Y  Bet P T S')" 
      using TS_def X Y TS P S' by blast
    have "¬ Col Q X Y  ¬ Col S' X Y  ( T::'p. Col T X Y  Bet Q T S')" 
      using TS_def X Y TS Q S' by force
    obtain X' where "Col X' X Y" and "Bet P X' S'" and "X Y TS Q S'" 
      using X Y TS Q S' ¬ Col P X Y  ¬ Col S' X Y  (T. Col T X Y  Bet P T S') by blast
    obtain Y' where "Col Y' X Y" and "Bet Q Y' S'" 
      using ¬ Col Q X Y  ¬ Col S' X Y  (T. Col T X Y  Bet Q T S') by blast
    have "Coplanar A B C X'" 
      using Coplanar A B C X Col_cases col_cop2__cop ts_distincts 
      by (metis not_col_distincts Col X' X Y Coplanar A B C Y 
          ¬ Col P X Y  ¬ Col S' X Y  (T. Col T X Y  Bet P T S'))
    have "Coplanar A B C Y'"
      using Col_cases col_cop2__cop ts_distincts 
      by (metis not_col_distincts Col Y' X Y Coplanar A B C X Coplanar A B C Y 
          ¬ Col P X Y  ¬ Col S' X Y  (T. Col T X Y  Bet P T S'))
    have "¬ Coplanar A B C S'"
      using assms(1) bet_col bet_col1 col2_cop2__eq osp__ncop1 
      by (metis Bet P X' S' Col X' X Y Coplanar A B C X' 
          ¬ Col P X Y  ¬ Col S' X Y  (T. Col T X Y  Bet P T S'))
    hence "A B C OSP P Q"
    proof -
      have "A B C TSP P S'"
        using TSP_def 
        by (meson osp__ncop1 Bet P X' S' Coplanar A B C X' ¬ Coplanar A B C S' assms(1))
      moreover have "A B C TSP Q S'"
        using TSP_def bet_col col_cop2__cop 
        by (metis Bet Q Y' S' Col Y' X Y Coplanar A B C Y' 
            ¬ Col Q X Y  ¬ Col S' X Y  (T. Col T X Y  Bet Q T S') ¬ Coplanar A B C S')
      ultimately show ?thesis 
        using l9_41_1 by blast
    qed
  }
  ultimately show ?thesis 
    by blast
qed

lemma l9_18_3:
  assumes "Coplanar A B C P" and
    "Col X Y P"
  shows "A B C TSP X Y  (Bet X P Y  ¬ Coplanar A B C X  ¬ Coplanar A B C Y)"
  by (meson TSP_def assms(1) assms(2) l9_39 not_bet_out not_col_permutation_5 tsp_distincts)

lemma bet_cop__tsp:
  assumes "¬ Coplanar A B C X" and
    "P  Y" and
    "Coplanar A B C P" and
    "Bet X P Y"
  shows "A B C TSP X Y"
  using TSP_def assms(1) assms(2) assms(3) assms(4) bet_col bet_col1 col2_cop2__eq by metis

lemma cop_out__osp:
  assumes "¬ Coplanar A B C X" and
    "Coplanar A B C P" and
    "P Out X Y"
  shows "A B C OSP X Y"
  by (meson OSP_def assms(1) assms(2) assms(3) l9_39 tsp_exists)

lemma l9_19_3:
  assumes "Coplanar A B C P" and
    "Col X Y P"
  shows "A B C OSP X Y  (P Out X Y  ¬ Coplanar A B C X)"
  by (meson assms(1) assms(2) cop_out__osp l6_4_2 l9_18_3 not_col_permutation_5 osp__ncop1 
      osp__ncop2 tsp__nosp)

lemma cop2_ts__tsp:
  assumes "¬ Coplanar A B C X" and "Coplanar A B C D" and
    "Coplanar A B C E" and "D E TS X Y"
  shows "A B C TSP X Y"
proof -
  obtain T where "Col T D E" and "Bet X T Y"
    using TS_def assms(4) by blast
  moreover hence "Coplanar A B C T"
    using assms(2) assms(3) assms(4) col_cop2__cop not_col_permutation_2 ts_distincts by blast
  ultimately show ?thesis 
    by (metis TS_def assms(1) assms(4) bet_cop__tsp)
qed

lemma cop2_os__osp:
  assumes "¬ Coplanar A B C X" and
    "Coplanar A B C D" and
    "Coplanar A B C E" and
    "D E OS X Y"
  shows "A B C OSP X Y"
proof -
  obtain Z where "D E TS X Z" and "D E TS Y Z"
    using OS_def assms(4) by blast
  hence "A B C TSP X Z"
    using assms(1) assms(2) assms(3) cop2_ts__tsp by blast
  moreover hence "A B C TSP Y Z"
    using assms(2) assms(3) cop2_ts__tsp l9_2 tsp__ncop2 D E TS Y Z by meson
  ultimately show ?thesis
    using l9_41_1 by blast
qed

lemma cop3_tsp__ts:
  assumes "D  E" and
    "Coplanar A B C D" and
    "Coplanar A B C E" and
    "Coplanar D E X Y" and
    "A B C TSP X Y"
  shows "D E TS X Y"
  by (meson assms(1) assms(2) assms(3) assms(4) assms(5) col_cop2__cop cop2_os__osp
      cop_nts__os not_col_permutation_2 tsp__ncop1 tsp__ncop2 tsp__nosp)

lemma cop3_osp__os:
  assumes "D  E" and
    "Coplanar A B C D" and
    "Coplanar A B C E" and
    "Coplanar D E X Y" and
    "A B C OSP X Y"
  shows "D E OS X Y"
  by (meson assms(1) assms(2) assms(3) assms(4) assms(5) col_cop2__cop cop2_ts__tsp 
      cop_nts__os not_col_permutation_2 osp__ncop1 osp__ncop2 tsp__nosp)

lemma cop_tsp__ex_cop2:
  assumes (*"Coplanar A B C P" and*)
    "A B C TSP D E"
  shows " Q. (Coplanar A B C Q  Coplanar D E P Q  P  Q)"
proof cases
  assume "Col D E P"
  thus ?thesis
    by (meson ex_diff_cop ncop__ncols)
next
  assume "¬ Col D E P"
  then obtain Q where "Coplanar A B C Q  Bet D Q E  ¬ Col D E P"
    using TSP_def assms(1) by blast
  thus ?thesis
    using Col_perm bet_col ncop__ncols by blast
qed

lemma cop_osp__ex_cop2:
  assumes "Coplanar A B C P" and
    "A B C OSP D E"
  shows " Q. Coplanar A B C Q  Coplanar D E P Q  P  Q"
proof cases
  assume "Col D E P"
  thus ?thesis
    by (metis col_trivial_3 diff_col_ex ncop__ncols)
next
  assume P1: "¬ Col D E P"
  obtain E' where P2: "Bet E P E'  Cong P E' P E"
    using segment_construction by blast
  have P3: "¬ Col D E' P"
    by (metis P1 P2 bet_col bet_cong_eq between_symmetry col_permutation_5 l5_2 l6_16_1)
  have P4: "A B C TSP D E'"
    by (metis P2 P3 assms(1) assms(2) bet_cop__tsp l9_41_2 not_col_distincts 
        osp__ncop2 osp_symmetry)
  hence "¬ Coplanar A B C D  ¬ Coplanar A B C E'  ( T. Coplanar A B C T  Bet D T E')"
    by (simp add: TSP_def)
  then obtain Q where P7: "Coplanar A B C Q  Bet D Q E'"
    by blast
  hence "Coplanar D E' P Q"
    using bet_col ncop__ncols ncoplanar_perm_5 by blast
  hence "Coplanar D E P Q"
    using Col_perm P2 P3 bet_col col_cop__cop ncoplanar_perm_5 not_col_distincts by blast
  thus ?thesis
    using P3 P7 bet_col col_permutation_5 by blast
qed

lemma sac__coplanar:
  assumes "Saccheri A B C D"
  shows "Coplanar A B C D"
  using Saccheri_def assms ncoplanar_perm_4 os__coplanar by blast

lemma ex_sym:
  " Y. (A B Perp X Y  X = Y)  ( M. Col A B M  M Midpoint X Y)"
proof cases
  assume "Col A B X"
  thus ?thesis
    using l7_3_2 by blast
next
  assume "¬ Col A B X"
  then obtain M0 where "Col A B M0" and "A B Perp X M0"
    using l8_18_existence by blast
  obtain Z where "M0 Midpoint X Z"
    using symmetric_point_construction by blast
  thus ?thesis 
    using Perp_cases bet_col midpoint_bet perp_col 
    by (metis A B Perp X M0 Col A B M0)
qed

lemma is_image_is_image_spec:
  assumes "A  B"
  shows "P' P Reflect A B  P' P ReflectL A B"
  by (simp add: Reflect_def assms)

lemma ex_sym1:
  assumes "A  B"
  shows " Y. (A B Perp X Y  X = Y)  ( M. Col A B M  M Midpoint X Y  X Y Reflect A B)"
proof cases
  assume "Col A B X"
  thus ?thesis
    by (meson ReflectL_def Reflect_def assms l7_3_2)
next
  assume P0: "¬ Col A B X"
  then obtain M0 where P1: "Col A B M0  A B Perp X M0"
    using l8_18_existence by blast
  obtain Z where P2: "M0 Midpoint X Z"
    using symmetric_point_construction by blast
  have P3: "A B Perp X Z"
  proof cases
    assume "X = Z"
    thus ?thesis
      using P1 P2 P0 midpoint_distinct by blast
  next
    assume "X  Z"
    hence P2: "X Z Perp A B"
      using P1 P2 Perp_cases bet_col midpoint_bet perp_col by blast
    show ?thesis
      by (simp add: Perp_perm Tarski_neutral_dimensionless_axioms P2)
  qed
  have P10: "(A B Perp X Z  X = Z)"
    by (simp add: P3)
  have " M. Col A B M  M Midpoint X Z  X Z Reflect A B"
    using P1 P2 P3 ReflectL_def assms is_image_is_image_spec l7_2 perp_right_comm by blast
  thus ?thesis
    using P3 by blast
qed

lemma l10_2_uniqueness:
  assumes "P1 P Reflect A B" and
    "P2 P Reflect A B"
  shows "P1 = P2"
proof cases
  assume "A = B"
  thus ?thesis
    using Reflect_def assms(1) assms(2) symmetric_point_uniqueness by auto
next
  assume "A  B"
  hence "P1 P ReflectL A B"
    using assms(1) is_image_is_image_spec by auto
  hence "A B Perp P P1  P = P1"
    using ReflectL_def by blast
  have "P2 P ReflectL A B"
    using assms(2) is_image_is_image_spec A  B by blast
  hence "A B Perp P P2  P = P2"
    using ReflectL_def by blast
  obtain X where "X Midpoint P P1" and "Col A B X"
    by (metis ReflectL_def assms(1) col_trivial_1 is_image_is_image_spec midpoint_existence)
  obtain Y where "Y Midpoint P P2" and "Col A B Y"
    by (metis ReflectL_def assms(2) col_trivial_1 is_image_is_image_spec midpoint_existence)
  {
    assume "A B Perp P P1" and "A B Perp P P2"
    have "P  X" 
      using A B Perp P P1 X Midpoint P P1 is_midpoint_id perp_not_eq_2 by blast
    have "P  Y" 
      using A B Perp P P2 Y Midpoint P P2 is_midpoint_id perp_not_eq_2 by blast
    have "P X Perp A B" 
      using Perp_perm A B Perp P P1 P  X X Midpoint P P1 bet_col midpoint_bet 
        not_col_permutation_5 perp_col1 by blast
    have "P Y Perp A B" 
      using Perp_perm A B Perp P P2 P  Y Y Midpoint P P2 bet_col midpoint_bet 
        not_col_permutation_5 perp_col1 by blast
    hence "P1 = P2" 
      by (metis Perp_perm l7_2 l7_9_bis Col A B Y P X Perp A B X Midpoint P P1 
          thesis. (X. X Midpoint P P1; Col A B X  thesis)  thesis 
          Y Midpoint P P2 l7_17 l8_18_uniqueness)
  }
  hence "(A B Perp P P1  A B Perp P P2)  P1 = P2" by blast
  moreover have "(P = P1  A B Perp P P2)  P1 = P2" 
    by (metis Col A B X Col A B Y X Midpoint P P1 Y Midpoint P P2 colx is_midpoint_id 
        l8_16_1 midpoint_col midpoint_distinct_2)
  moreover have "(P = P2  A B Perp P P1)  P1 = P2" 
    by (metis Col A B X Col A B Y X Midpoint P P1 Y Midpoint P P2 l8_16_1 
        l8_20_2 midpoint_col not_col_distincts perp_col2)
  ultimately show ?thesis 
    using A B Perp P P1  P = P1 A B Perp P P2  P = P2 by fastforce
qed

lemma l10_2_uniqueness_spec:
  assumes "P1 P ReflectL A B" and
    "P2 P ReflectL A B"
  shows "P1 = P2"
proof -
  have "A B Perp P P1  P = P1"
    using ReflectL_def assms(1) by blast
  moreover obtain X1 where "X1 Midpoint P P1" and "Col A B X1"
    using ReflectL_def assms(1) by blast
  moreover have "A B Perp P P2  P = P2"
    using ReflectL_def assms(2) by blast
  moreover obtain X2 where "X2 Midpoint P P2" and "Col A B X2"
    using ReflectL_def assms(2) by blast
  {
    assume "A B Perp P P1" and "A B Perp P P2"
    have "P1 P Reflect A B" 
      using Reflect_def A B Perp P P1 assms(1) perp_distinct by auto
    moreover have "P2 P Reflect A B" 
      using A B Perp P P2 assms(2) is_image_is_image_spec perp_distinct by auto
    ultimately have "P1 = P2" 
      using l10_2_uniqueness by auto
  }
  moreover
  {
    assume "A B Perp P P1  P = P2"
    hence "P1 = P2" 
      by (metis colx perp_not_col2 Col A B X2 X2 Midpoint P P2 calculation(2) 
          calculation(3) l8_20_2 midpoint_col)
  }
  moreover
  {
    assume "P = P1" and "A B Perp P P2"
    hence "P1 = P2" 
      by (metis Col A B X2 X2 Midpoint P P2 calculation(2) calculation(3) 
          colx l8_20_2 midpoint_col perp_not_col2)
  }
  ultimately show ?thesis 
    by blast
qed

lemma l10_2_existence_spec:
  " P'. P' P ReflectL A B"
proof cases
  assume "Col A B P"
  thus ?thesis
    using ReflectL_def l7_3_2 by blast
next
  assume "¬ Col A B P"
  then obtain X where "Col A B X  A B Perp P X"
    using l8_18_existence by blast
  moreover obtain P' where "X Midpoint P P'"
    using symmetric_point_construction by blast
  ultimately show ?thesis
    using ReflectL_def bet_col midpoint_bet perp_col1 by blast
qed

lemma l10_2_existence:
  " P'. P' P Reflect A B"
  by (metis Reflect_def l10_2_existence_spec symmetric_point_construction)

lemma l10_4_spec:
  assumes "P P' ReflectL A B"
  shows "P' P ReflectL A B"
proof -
  obtain X where "X Midpoint P P'  Col A B X"
    using ReflectL_def assms l7_2 by blast
  thus ?thesis
    using Perp_cases ReflectL_def assms by auto
qed

lemma l10_4:
  assumes "P P' Reflect A B"
  shows "P' P Reflect A B"
  using Reflect_def l7_2 Tarski_neutral_dimensionless_axioms assms l10_4_spec by fastforce

lemma l10_5:
  assumes "P' P Reflect A B" and
    "P'' P' Reflect A B"
  shows "P = P''"
  by (meson assms(1) assms(2) l10_2_uniqueness l10_4)

lemma l10_6_uniqueness:
  assumes "P P1 Reflect A B" and
    "P P2 Reflect A B"
  shows "P1 = P2"
  using assms(1) assms(2) l10_4 l10_5 by blast

lemma l10_6_uniqueness_spec:
  assumes "P P1 ReflectL A B" and
    "P P2 ReflectL A B"
  shows "P1 = P2"
  using assms(1) assms(2) l10_2_uniqueness_spec l10_4_spec by blast

lemma l10_6_existence_spec:
  assumes "A  B"
  shows " P. P' P ReflectL A B"
  using l10_2_existence_spec l10_4_spec by blast

lemma l10_6_existence:
  " P. P' P Reflect A B"
  using l10_2_existence l10_4 by blast

lemma l10_7:
  assumes "P' P Reflect A B" and
    "Q' Q Reflect A B" and
    "P' = Q'"
  shows "P = Q"
  using assms(1) assms(2) assms(3) l10_6_uniqueness by blast

lemma l10_8:
  assumes "P P Reflect A B"
  shows "Col P A B"
  by (metis Col_perm assms col_trivial_2 ex_sym1 l10_6_uniqueness l7_3)

lemma col__refl:
  assumes "Col P A B"
  shows "P P ReflectL A B"
  using ReflectL_def assms col_permutation_1 l7_3_2 by blast

lemma is_image_col_cong:
  assumes "A  B" and
    "P P' Reflect A B" and
    "Col A B X"
  shows "Cong P X P' X"
proof -
  have P1: "P P' ReflectL A B"
    using assms(1) assms(2) is_image_is_image_spec by blast
  obtain M0 where P2: "M0 Midpoint P' P  Col A B M0"
    using P1 ReflectL_def by blast
  have "A B Perp P' P  P' = P"
    using P1 ReflectL_def by auto
  moreover
  {
    assume S1: "A B Perp P' P"
    hence "A  B  P'  P"
      using perp_distinct by blast
    have S2: "M0 = X  Cong P X P' X"
      using P2 cong_4312 midpoint_cong by blast
    {
      assume "M0  X"
      hence "M0 X Perp P' P"
        using P2 S1 assms(3) perp_col2 by blast
      hence "¬ Col A B P  Per P M0 X"
        by (metis Col_perm P2 S1 colx l8_2 midpoint_col midpoint_distinct_1 
            per_col perp_col1 perp_not_col2 perp_per_1)
      hence "Cong P X P' X"
        using P2 cong_commutativity l7_2 l8_2 per_double_cong by blast
    }
    hence "Cong P X P' X"
      using S2 by blast
  }
  hence "A B Perp P' P  Cong P X P' X" by blast
  moreover
  {
    assume "P = P'"
    hence "Cong P X P' X"
      by (simp add: cong_reflexivity)
  }
  ultimately show ?thesis by blast
qed

lemma is_image_spec_col_cong:
  assumes "P P' ReflectL A B" and
    "Col A B X"
  shows "Cong P X P' X"
  by (metis Col_def Reflect_def assms(1) assms(2) between_trivial col__refl 
      cong_reflexivity is_image_col_cong l10_6_uniqueness_spec)

lemma image_id:
  assumes "A  B" and
    "Col A B T" and
    "T T' Reflect A B"
  shows "T = T'"
  using assms(1) assms(2) assms(3) cong_diff_4 is_image_col_cong by blast

lemma osym_not_col:
  assumes "P P' Reflect A B" and
    "¬ Col A B P"
  shows "¬ Col A B P'"
  using assms(1) assms(2) l10_4 local.image_id not_col_distincts by blast

lemma midpoint_preserves_image:
  assumes "A  B" and
    "Col A B M" and
    "P P' Reflect A B" and
    "M Midpoint P Q" and
    "M Midpoint P' Q'"
  shows "Q Q' Reflect A B"
proof -
  obtain X where "X Midpoint P' P" and "Col A B X"
    using ReflectL_def assms(1) assms(3) is_image_is_image_spec by blast
  {
    assume "A B Perp P' P"
    obtain Y where "M Midpoint X Y"
      using symmetric_point_construction by blast
    have "Y Midpoint Q Q'"
    proof -
      have "X Midpoint P P'" 
        using X Midpoint P' P l7_2 by blast
      thus ?thesis 
        using assms(4) assms(5) symmetry_preserves_midpoint M Midpoint X Y by blast
    qed
    have "P  P'" 
      using A B Perp P' P perp_distinct by blast
    hence "Q  Q'"
      using l7_9 Tarski_neutral_dimensionless_axioms assms(4) assms(5) by fastforce
    have "Y Midpoint Q' Q  Col A B Y"
      using assms(2) colx l7_2 midpoint_col midpoint_distinct_1 
      by (metis Col A B X M Midpoint X Y Y Midpoint Q Q')
    have "A B Perp Q' Q  Q = Q'"
    proof -
      have "Per M Y Q"
      proof -
        have "Y Midpoint Q Q'" 
          using Y Midpoint Q Q' by auto
        have "Cong M Q M Q'"
          using assms(1) assms(2) assms(3) assms(4) assms(5) cong_commutativity 
            is_image_col_cong l7_16 l7_3_2 by blast
        thus ?thesis 
          using Per_def Y Midpoint Q Q' by blast
      qed
      {
        have "X = Y  (A B Perp Q' Q  Q = Q')"
          using Perp_cases assms(5) l7_3 l7_9_bis 
          by (metis A B Perp P' P M Midpoint X Y X Midpoint P' P assms(4))
        {
          assume "X  Y"
          hence "Y PerpAt M Y Y Q"
            using midpoint_distinct_1 per_perp_in 
            by (metis M Midpoint X Y Per M Y Q Q  Q' Y Midpoint Q' Q  Col A B Y)
          hence "Y Y Perp Y Q  M Y Perp Y Q" 
            by (simp add: perp_in_perp_bis)
          {
            have "Y Y Perp Y Q  A B Perp Q' Q  Q = Q'"
              using perp_not_eq_1 by blast
            {
              assume "M Y Perp Y Q"
              have "Y Q Perp A B"
              proof cases
                assume "A = M"
                thus ?thesis 
                  using Perp_cases M Y Perp Y Q Y Midpoint Q' Q  Col A B Y 
                    assms(1) not_col_permutation_5 perp_col1 by blast
              next
                assume "A  M"
                thus ?thesis 
                  by (metis Y Midpoint Q' Q  Col A B Y Y Y Perp Y Q  M Y Perp Y Q 
                      assms(1) assms(2) col3 not_col_distincts perp_col0)
              qed
              have "A B Perp Q' Q  Q = Q'"
                using midpoint_col not_col_distincts perp_col0 
                by (metis Y Midpoint Q Q' Y Q Perp A B)
            }
            hence "M Y Perp Y Q  A B Perp Q' Q  Q = Q'" by blast
          }
          hence "A B Perp Q' Q  Q = Q'"
            using perp_distinct Y Y Perp Y Q  M Y Perp Y Q by blast
        }
        hence "X  Y  (A B Perp Q' Q  Q = Q')" by blast
      }
      thus ?thesis
        using Perp_cases assms(5) l7_3 l7_9_bis
        by (metis A B Perp P' P M Midpoint X Y Y Midpoint Q Q' assms(4))
    qed
    hence "Q Q' ReflectL A B" 
      using ReflectL_def Y Midpoint Q' Q  Col A B Y by blast
  }
  moreover
  {
    assume "P = P'"
    hence "Q Q' ReflectL A B"
      using assms(2) assms(4) assms(5) col__refl col_permutation_2 colx midpoint_col 
        midpoint_distinct_3 symmetric_point_uniqueness by (metis Col A B X X Midpoint P' P)
  }
  ultimately show ?thesis
    using ReflectL_def assms(1) assms(3) is_image_is_image_spec by auto
qed

lemma image_in_is_image_spec:
  assumes "M ReflectLAt P P' A B"
  shows "P P' ReflectL A B"
proof -
  have P1: "M Midpoint P' P"
    using ReflectLAt_def assms by blast
  have P2: "Col A B M"
    using ReflectLAt_def assms by blast
  have "A B Perp P' P  P' = P"
    using ReflectLAt_def assms by blast
  thus ?thesis using P1 P2
    using ReflectL_def by blast
qed

lemma image_in_gen_is_image:
  assumes "M ReflectAt P P' A B"
  shows "P P' Reflect A B"
  using ReflectAt_def Reflect_def assms image_in_is_image_spec by auto

lemma image_image_in:
  assumes "P  P'" and
    "P P' ReflectL A B" and
    "Col A B M" and
    "Col P M P'"
  shows "M ReflectLAt P P' A B"
proof -
  obtain M' where P1: "M' Midpoint P' P  Col A B M'"
    using ReflectL_def assms(2) by blast
  have Q1: "P M' Perp A B"
    by (metis Col_cases P1 Perp_perm ReflectL_def assms(1) assms(2) bet_col cong_diff_3 
        midpoint_bet midpoint_cong not_cong_4321 perp_col1)
  {
    assume R1: "A B Perp P' P"
    have R3: "P  M'"
      using Q1 perp_not_eq_1 by auto
    have R4: "A B Perp P' P"
      by (simp add: R1)
    have R5: "Col P P' M'"
      using P1 midpoint_col not_col_permutation_3 by blast
    have R6: "M' Midpoint P' P"
      by (simp add: P1)
    have R7: "¬ Col A B P"
      using assms(1) assms(2) col__refl col_permutation_2 l10_2_uniqueness_spec l10_4_spec 
      by blast
    have R8: "P  P'"
      by (simp add: assms(1))
    have R9: "Col A B M'"
      by (simp add: P1)
    have R10: "Col A B M"
      by (simp add: assms(3))
    have R11: "Col P P' M'"
      by (simp add: R5)
    have R12: "Col P P' M"
      using Col_perm assms(4) by blast
    have "M = M'"
    proof cases
      assume S1: "A = M'"
      have "Per P M' A"
        by (simp add: S1 l8_5)
      thus ?thesis using l6_21 R8 R9 R10 R11 R12
        using R7 by blast
    next
      assume "A  M'"
      thus ?thesis
        using R10 R12 R5 R7 R8 R9 l6_21 by blast
    qed
    hence "M Midpoint P' P"
      using R6 by blast
  }
  hence Q2: "A B Perp P' P  M Midpoint P' P" by blast
  have Q3: "P' = P  M Midpoint P' P"
    using assms(1) by auto
  have Q4: "A B Perp P' P  P' = P"
    using ReflectL_def assms(2) by auto
  hence "M Midpoint P' P"
    using Q2 Q3 by blast
  thus ?thesis
    by (simp add: ReflectLAt_def Q4 assms(3))
qed

lemma image_in_col:
  assumes "Y ReflectLAt P P' A B"
  shows "Col P P' Y"
  using Col_perm ReflectLAt_def assms midpoint_col by blast

lemma is_image_spec_rev:
  assumes "P P' ReflectL A B"
  shows "P P' ReflectL B A"
proof -
  obtain M0 where P1: "M0 Midpoint P' P  Col A B M0"
    using ReflectL_def assms by blast
  have P2: "Col B A M0"
    using Col_cases P1 by blast
  have "A B Perp P' P  P' = P"
    using ReflectL_def assms by blast
  thus ?thesis
    using P1 P2 Perp_cases ReflectL_def by auto
qed

lemma is_image_rev:
  assumes "P P' Reflect A B"
  shows "P P' Reflect B A"
  using Reflect_def assms is_image_spec_rev by auto

lemma midpoint_preserves_per:
  assumes "Per A B C" and
    "M Midpoint A A1" and
    "M Midpoint B B1" and
    "M Midpoint C C1"
  shows "Per A1 B1 C1"
proof -
  obtain C' where P1: "B Midpoint C C'  Cong A C A C'"
    using Per_def assms(1) by blast
  obtain C1' where P2: "M Midpoint C' C1'"
    using symmetric_point_construction by blast
  thus ?thesis
    by (meson P1 Per_def assms(2) assms(3) assms(4) l7_16 symmetry_preserves_midpoint)
qed

lemma col__image_spec:
  assumes "Col A B X"
  shows "X X ReflectL A B"
  by (simp add: assms col__refl col_permutation_2)

lemma image_triv:
  "A A Reflect A B"
  by (simp add: Reflect_def col__refl col_trivial_1 l7_3_2)

lemma cong_midpoint__image:
  assumes "Cong A X A Y" and
    "B Midpoint X Y"
  shows "Y X Reflect A B"
proof cases
  assume "A = B"
  thus ?thesis
    by (simp add: Reflect_def assms(2))
next
  assume S0: "A  B"
  {
    assume S1: "X  Y"
    hence "X Y Perp A B"
    proof -
      have T1: "B  X"
        using S1 assms(2) midpoint_distinct_1 by blast
      have T2: "B  Y"
        using S1 assms(2) midpoint_not_midpoint by blast
      have "Per A B X"
        using Per_def assms(1) assms(2) by auto
      thus ?thesis
        using S0 S1 T1 T2 assms(2) col_per_perp midpoint_col by auto
    qed
    hence "A B Perp X Y  X = Y"
      using Perp_perm by blast
    hence "Y X Reflect A B"
      using ReflectL_def S0 assms(2) col_trivial_2 is_image_is_image_spec by blast
  }
  hence "X  Y  Y X Reflect A B" by blast
  thus ?thesis
    using assms(2) image_triv is_image_rev l7_3 by blast
qed


lemma col_image_spec__eq:
  assumes "Col A B P" and
    "P P' ReflectL A B"
  shows "P = P'"
  using assms(1) assms(2) col__image_spec l10_2_uniqueness_spec l10_4_spec by blast

lemma image_spec_triv:
  "A A ReflectL B B"
  using col__image_spec not_col_distincts by blast

lemma image_spec__eq:
  assumes "P P' ReflectL A A"
  shows "P = P'"
  using assms col_image_spec__eq not_col_distincts by blast

lemma image__midpoint:
  assumes "P P' Reflect A A"
  shows "A Midpoint P' P"
  using Reflect_def assms by auto

lemma is_image_spec_dec:
  "A B ReflectL C D  ¬ A B ReflectL C D"
  by simp

lemma l10_14:
  assumes "P  P'" and
    "A  B" and
    "P P' Reflect A B"
  shows "A B TS P P'"
proof -
  have P1: "P P' ReflectL A B"
    using assms(2) assms(3) is_image_is_image_spec by blast
  then obtain M0 where "M0 Midpoint P' P  Col A B M0"
    using ReflectL_def by blast
  hence "A B Perp P' P  A B TS P P'"
    by (meson TS_def assms(1) assms(2) assms(3) between_symmetry col_permutation_2 
        image_id midpoint_bet osym_not_col)
  thus ?thesis
    using assms(1) P1 ReflectL_def by blast
qed

lemma l10_15:
  assumes "Col A