Definition contraction a b k := k *: (b - a) + a.

(* Specifications: *)
Lemma extension_eq a b c k :
k != 0 -> (extension a b k == extension a c k) = (b == c).
Lemma contraction_eq x y z k :
k != 0 -> (contraction x y k == contraction x z k) = (y == z).
Lemma extension_contraction x y z k:
k != 0 -> extension x y k == z = (contraction x z k == y).
Lemma extensionP a b c :
a != b -> b - a = ratio (b - a) (c - a) *: (c - a) ->
extension a b (ratio (b - a) (c - a)) = c.
Lemma betS_extension x y z:
betS x y z -> z = extension x y (betR x y z).
Lemma extension_bet a b k1 :
0 < k1 -> k1 < 1 -> bet a b (extension a b k1).
Lemma contraction_betR a b k1 :
b != a -> 0 < k1 -> k1 < 1 -> betR a (contraction a b k1) b = k1.
Lemma contraction_betS a b k :
b != a -> 0 < k -> k < 1 -> betS a (contraction a b k) b.
Lemma extension_col a b c k :
c == extension a b k -> bet a b c \/ bet b c a \/ bet c a b.
Lemma ratio_bet a b c k1 k2 k3 :
0 < k1 -> 0 < k2 -> k1 < 1 -> 0 < k3 -> k3 < k1+k2-k1*k2 ->
b - a == ((k1+k2-k1*k2)/k3)^-1 *: (c - a) -> bet a b c.
Lemma betS_inner_transitivity a b c d (k1 := betR a b d) (k2 := betR b c d) :
betS a b d -> betS b c d -> bet a b c.
Lemma bet_inner_transitivity a b c d: bet a b d -> bet b c d -> bet a b c.
Lemma bet_betS a b c : a <> b -> b <> c -> bet a b c = betS a b c.
Lemma inner_pasch' a b c p q (k1 := betR a p c) (k2 := betR b q c) :
a <> p -> p <> c -> b <> q -> q <> c ->
bet a p c -> bet b q c ->
exists x, bet p x b /\ bet q x a.
Lemma inner_pasch a b c p q :
bet a p c -> bet b q c ->
a <> p -> p <> c -> b <> q -> q <> c ->
~ (bet a b c \/ bet b c a \/ bet c a b) ->
exists x, bet p x b /\ bet q x a.
Lemma euclid'_aux a b c d k1 (k2 := betR b d c) :
0 < k1 -> k1 < 1 -> bet b d c -> b != c ->
bet (extension a b k1) (extension a d k1) (extension a c k1).
Lemma euclid' a b c d t (k1 := betR a d t) (k2 := betR b d c) :
betS a d t -> bet b d c ->
exists x y, bet a b x /\ bet a c y /\ bet x t y.
Lemma euclid a b c d t (k1 := betR a d t) (k2 := betR b d c) :
bet a d t -> bet b d c -> b <> d -> d <> c ->
~ (bet a b c \/ bet b c a \/ bet c a b) ->
exists x y, bet a b x /\ bet a c y /\ bet x t y.
Lemma congC a b c d: cong a b c d = cong b a d c.
Lemma cong_eq a b c : cong a b c c -> a = b.
Lemma betS_ratio a b c (r := betR a b c) :
betS a b c -> (c - b = ((1 - r) / r) *: (b - a)).
Lemma betS_gt0 a b c (r := ratio(b-a)(c-a)) : betS a b c -> 0 < (1 - r) / r.
Lemma five_segment a a' b b' c c' d d' :
cong a b a' b' -> cong b c b' c' -> cong a d a' d' -> cong b d b' d' ->
bet a b c -> bet a' b' c' -> a <> b -> cong c d c' d'.
Lemma point_equality_decidability a b : a = b \/ ~ a = b.
Lemma vector2_eq0 (v :(@Vector R 1)) : (v == 0) = (v 0 0 == 0) && (v 0 1 == 0).
Lemma vector2_neq0 (v : 'rV[R]_(2)) : (v != 0) = (v 0 0 != 0) || (v 0 1 != 0).
Definition sqr_L2_norm_2D a b :=
(b 0 0 - a 0 0) ^+ 2 + (b 0 1 - a 0 1) ^+ 2.
Lemma congP_aux' a b : (b - a) *m (b - a)^T = (sqr_L2_norm_2D a b)%:M.
Lemma congP_aux a b c d :
cong a b c d = (sqr_L2_norm_2D a b == sqr_L2_norm_2D c d).
Lemma congP a b c d :
reflect (sqr_L2_norm_2D a b = sqr_L2_norm_2D c d) (cong a b c d).
Lemma betSP' a b c (r := betR a b c) :
reflect ([ /\ b 0 0 - a 0 0 = r * (c 0 0 - a 0 0),
b 0 1 - a 0 1 = r * (c 0 1 - a 0 1), 0 < r & r < 1])
(betS a b c).
Lemma markov_betE a b c :
~ ~ [ /\ [ \/ a 0 0 != b 0 0 | a 0 1 != b 0 1 ] &
[ \/ b 0 0 != c 0 0 | b 0 1 != c 0 1 ] ] ->
[ /\ [ \/ a 0 0 != b 0 0 | a 0 1 != b 0 1 ] &
[ \/ b 0 0 != c 0 0 | b 0 1 != c 0 1 ] ].
Lemma betEP' a b c :
reflect (~ [ /\ [ \/ a 0 0 != b 0 0 | a 0 1 != b 0 1 ] &
[ \/ b 0 0 != c 0 0 | b 0 1 != c 0 1 ] ]) (betE a b c).
Lemma ratioP_aux (v1 v2 : 'rV[R]_(2)) :
v1 0 0 != 0 -> v1 0 1 != 0 -> v2 0 0 != 0 -> v2 0 1 != 0 ->
v1 0 0 * v2 0 1 == v1 0 1 * v2 0 0 -> ratio v1 v2 = v1 0 0 / v2 0 0.
Lemma ratioP (v1 v2 : 'rV[R]_(2)) :
v1 0 0 != 0 -> v1 0 1 != 0 -> v2 0 0 != 0 -> v2 0 1 != 0 ->
v1 0 0 * v2 0 1 == v1 0 1 * v2 0 0 -> v1 = ratio v1 v2 *: v2.
Lemma ratio_e0_n1 (v1 v2 : 'rV[R]_(2)) :
v2 0 0 = 0 -> v2 0 1 != 0 -> ratio v1 v2 = v1 0 1 / v2 0 1.
Lemma ratio_e1_n0 (v1 v2 : 'rV[R]_(2)) :
v2 0 0 != 0 -> v2 0 1 = 0 -> ratio v1 v2 = v1 0 0 / v2 0 0.
Lemma ratio_cp'_aux_1 (a b c : R) :
b - a != 0 ->
1 < (b-a) / (c-a) -> 0 < (c-b) / (a-b) < 1.
Lemma ratio_cp'_aux_2 (a b c : R) :
a - b != 0 -> (b-a) / (c-a) < 0 -> 0 < (c-b) / (a-b).
Lemma ratio_cp' (a b c : R) :
b - a != 0 -> c - a != 0 -> b - c != 0 ->
[|| 0 < (b-a) / (c-a) < 1, 0 < (c-b) / (a-b) < 1 | 0 < (a-c) / (b-c) < 1].
Lemma ratio_cp (a b c : R) :
a - b != 0 ->  b - c != 0 -> c - a != 0 ->
0 < (b-a) / (c-a) < 1 \/ 0 < (c-b) / (a-b) < 1 \/ 0 < (a-c) / (b-c) < 1.
Lemma col_2D_aux_1 a b c :
((a 0 1 - c 0 1) * (b 0 0 - c 0 0) == (a 0 0 - c 0 0) * (b 0 1 - c 0 1)) =
((a 0 0 - b 0 0) * (b 0 1 - c 0 1) == (a 0 1 - b 0 1) * (b 0 0 - c 0 0)).
Lemma col_2D_aux_2 a b c :
((c 0 1 - b 0 1) * (a 0 0 - b 0 0) == (c 0 0 - b 0 0) * (a 0 1 - b 0 1)) =
((a 0 0 - b 0 0) * (b 0 1 - c 0 1) == (a 0 1 - b 0 1) * (b 0 0 - c 0 0)).
Lemma col_2D_aux_3 a b c :
((b 0 1 - a 0 1) * (c 0 0 - a 0 0) == (b 0 0 - a 0 0) * (c 0 1 - a 0 1)) =
((a 0 0 - b 0 0) * (b 0 1 - c 0 1) == (a 0 1 - b 0 1) * (b 0 0 - c 0 0)).
Lemma col_2D_aux a b c :
((a 0 0 - b 0 0) * (b 0 1 - c 0 1) == (a 0 1 - b 0 1) * (b 0 0 - c 0 0)) ->
c 0 0 != a 0 0 \/ c 0 1 != a 0 1 ->
a 0 0 != b 0 0 \/ a 0 1 != b 0 1 ->
b 0 0 != c 0 0 \/ b 0 1 != c 0 1 ->
[ \/ [ /\ b 0 0 = a 0 0, c 0 0 = a 0 0,
a 0 1 - b 0 1 != 0, b 0 1 - c 0 1 != 0 & c 0 1 - a 0 1 != 0],
[ /\ b 0 1 = a 0 1, c 0 1 = a 0 1,
a 0 0 - b 0 0 != 0, b 0 0 - c 0 0 != 0 & c 0 0 - a 0 0 != 0] |
[ /\ [ /\ a 0 0 - b 0 0 != 0, b 0 0 - c 0 0 != 0 & c 0 0 - a 0 0 != 0] &
[ /\ a 0 1 - b 0 1 != 0, b 0 1 - c 0 1 != 0 & c 0 1 - a 0 1 != 0]]].
Lemma col_2D a b c :
(a 0 0 - b 0 0) * (b 0 1 - c 0 1) == (a 0 1 - b 0 1) * (b 0 0 - c 0 0) ->
(bet a b c \/ bet b c a \/ bet c a b).
Lemma col_2D' a b c : (bet a b c \/ bet b c a \/ bet c a b) ->
(a 0 0 - b 0 0) * (b 0 1 - c 0 1) == (a 0 1 - b 0 1) * (b 0 0 - c 0 0).
Lemma cong_perp_aux1 (a p m : 'rV[R]_(2)) i :
(m 0 i - a 0 i) - (m 0 i - p 0 i) = p 0 i - a 0 i.
Lemma cong_perp (a p q : 'rV[R]_(2)) (m := (1 / (1 + 1)) *: (p + q)) :
cong a p a q ->
(p 0 0 - m 0 0) * (m 0 0 - a 0 0) + (p 0 1 - m 0 1) * (m 0 1 - a 0 1) = 0.
Lemma upper_dim_dgc_aux0 (p q : 'rV[R]_(2)) (m := (1 / (1 + 1)) *: (p + q)) :
p 0 0 - m 0 0 == 0 -> p <> q ->
(m 0 0 - p 0 0 == 0) && (m 0 1 - p 0 1 != 0).
Lemma upper_dim_dgc_aux1 (p q : 'rV[R]_(2)) (m := (1 / (1 + 1)) *: (p + q)) :
p 0 1 - m 0 1 == 0 -> p <> q ->
(m 0 1 - p 0 1 == 0) && (m 0 0 - p 0 0 != 0).
Lemma upper_dim_dgc1_aux (a p q : 'rV[R]_(2)) (m := (1 / (1 + 1)) *: (p + q)) :
m 0 0 - p 0 0 = 0 -> m 0 1 - p 0 1 != 0 ->
cong a p a q ->
m 0 1 = a 0 1.
Lemma upper_dim_dgc1 (a b c p q : 'rV[R]_(2)) (m := (1 / (1 + 1)) *: (p + q)) :
p 0 0 - m 0 0 == 0 -> p <> q ->
cong a p a q -> cong b p b q -> cong c p c q ->
(a 0 0 - b 0 0) * (b 0 1 - c 0 1) == (a 0 1 - b 0 1) * (b 0 0 - c 0 0).
Lemma upper_dim_dgc2_aux (a p q : 'rV[R]_(2)) (m := (1 / (1 + 1)) *: (p + q)) :
m 0 1 - p 0 1 = 0 -> m 0 0 - p 0 0 != 0 ->
cong a p a q ->
m 0 0 = a 0 0.
Lemma upper_dim_dgc2 (a b c p q : 'rV[R]_(2)) (m := (1 / (1 + 1)) *: (p + q)) :
m 0 1 - p 0 1 == 0 -> p <> q ->
cong a p a q -> cong b p b q -> cong c p c q ->
(a 0 0 - b 0 0) * (b 0 1 - c 0 1) == (a 0 1 - b 0 1) * (b 0 0 - c 0 0).
Lemma upper_dim_aux (a b m : 'rV[R]_(2)) (c0 c1: R) :
c0 * (m 0 0 - a 0 0) + c1 * (m 0 1 - a 0 1) = 0 ->
c0 * (m 0 0 - b 0 0) + c1 * (m 0 1 - b 0 1) = 0 ->
c0 * (b 0 0 - a 0 0) = - c1 * (b 0 1 - a 0 1).
Lemma upper_dim a b c p q :
p <> q -> a <> b -> a <> c -> b <> c ->
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).