(* This program 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 program 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 General Public License for more details.                       *)
(*                                                                    *)
(* You should have received a copy of the GNU Lesser General Public   *)
(* License along with this program; if not, write to the Free         *)
(* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *)
(* 02110-1301 USA                                                     *)
(****************************************************************************)
(*                                                                          *)
(*  Proof of the three gap theorem.                                         *)
(*                                                                          *)
(*  Micaela Mayero (INRIA-Rocquencourt)                                     *)
(*  September 1998                                                          *)
(*                                                                          *)
(****************************************************************************)
(****************************************************************************)
(*                               tools.v                                    *)
(****************************************************************************)
(*********************************************************)
(*            Tools for The three gap theorem            *)
(*                                                       *)
(*********************************************************)
Require Export Reals.
Require Export Nat_compl.
Unset Standard Proposition Elimination Names.
Parameter alpha : R.
(*********************************************************)
(*********************************************************)
(*           first and last                              *)
(*********************************************************)
(**********)
Definition frac_part_n_alpha (n : nat) : R := frac_part (INR n * alpha).
(**********)
Definition ordre_total (n m : nat) :=
(0 < alpha)%R /\ (alpha < 1)%R ->
(frac_part_n_alpha n <= frac_part_n_alpha m)%R.
simple induction N; auto with arith real.
intros; elim H; intro y.
elim y; intro y0.
left; right; auto with arith real.
right; rewrite <- y0; auto with arith real.
right; auto with arith real.
Qed.
intro; unfold ordre_total in |- *; intro; unfold Rle in |- *; right;
auto with arith real.
Qed.
simple induction N; intro.
absurd (0 >= 2).
inversion H.
auto with arith real.
intro X; case (N_classic n); intro.
elim s; intro y.
rewrite y; intro; absurd (1 >= 2); inversion H; inversion H1;
auto with arith real.
rewrite y; intro; exists 1; split; auto with arith real.
split; auto with arith real.
intros; replace m with 1.
apply tech_total_order.
apply sym_equal; elim H0; intro.
inversion H1; auto with arith real.
intros.
elim (X g); intros.
cut
({(frac_part_n_alpha x <= frac_part_n_alpha n)%R} +
{~ (frac_part_n_alpha x <= frac_part_n_alpha n)%R}).
intro X0; elim X0; intro.
exists x; split.
elim p; intros; auto with arith real.
split.
elim p; intros.
elim H1; intros; auto with arith real.
intros; elim p; intros; elim H2; intros; cut (0 < m /\ m < n \/ m = n).
intro; elim H5; intro.
elim (H4 m H6); auto with arith real.
apply prop_alpha.
rewrite H6; unfold ordre_total in |- *; intro; auto with arith real.
elim H0; intros; cut (0 < m /\ m < n \/ 0 < m /\ m = n).
intro; elim H7; intros.
left; auto with arith real.
elim H8; intros; right; auto with arith real.
cut (0 < m /\ (m < n \/ m = n)).
intro; elim H7; intros; elim H9; intro.
left; auto with arith real.
right; auto with arith real.
split; auto with arith real.
unfold lt in H6; inversion H6; auto with arith real.
exists n; split; auto with arith real.
split; auto with arith real.
intros; cut (0 < m /\ m < n \/ m = n).
intro; elim H1.
intro; elim p; intros; elim H4; intros; unfold ordre_total in |- *; intro.
cut (frac_part_n_alpha x <= frac_part_n_alpha m)%R.
cut (frac_part_n_alpha x > frac_part_n_alpha n)%R.
intros; unfold Rgt in H8; cut (frac_part_n_alpha n < frac_part_n_alpha m)%R.
intro; apply (Rlt_le (frac_part_n_alpha n) (frac_part_n_alpha m) H10).
apply
(Rlt_le_trans (frac_part_n_alpha n) (frac_part_n_alpha x)
(frac_part_n_alpha m) H8 H9).
apply (Rnot_le_lt (frac_part_n_alpha x) (frac_part_n_alpha n) b).
elim (H6 m H2).
intro; apply (Rlt_le (frac_part_n_alpha x) (frac_part_n_alpha m) H8).
intro; rewrite H8; unfold Rle in |- *; right; auto with arith real.
apply prop_alpha.
intro; rewrite H2; apply tech_total_order.
elim H0; intros.
cut (0 < m /\ m < n \/ 0 < m /\ m = n).
intro; elim H3; intro.
left; auto with arith real.
elim H4; intros.
right; auto with arith real.
cut (0 < m /\ (m < n \/ m = n)).
intro; elim H3; intros.
elim H5; intro.
left; auto with arith real.
right; auto with arith real.
split; auto with arith real.
unfold lt in H2; inversion H2; auto with arith real.
apply (Rle_dec (frac_part_n_alpha x) (frac_part_n_alpha n)).
Qed.
simple induction N; intro.
absurd (0 >= 2).
inversion H.
auto with arith real.
intro X; case (N_classic n); intro.
elim s; intro y.
rewrite y; intro; absurd (1 >= 2); inversion H; inversion H1;
auto with arith real.
rewrite y; intro; exists 1; split; auto with arith real.
split; auto with arith real.
intros; replace m with 1.
apply tech_total_order.
apply sym_equal; elim H0; intro.
inversion H1; auto with arith real.
intros.
elim (X g); intros.
cut
({(frac_part_n_alpha x <= frac_part_n_alpha n)%R} +
{~ (frac_part_n_alpha x <= frac_part_n_alpha n)%R}).
intro X0; elim X0; intro.
exists n; split; auto with arith real.
split; auto with arith real.
intros; cut (0 < m /\ m < n \/ m = n).
intro; elim H1.
intro; elim p; intros; elim H4; intros; unfold ordre_total in |- *; intro.
cut (frac_part_n_alpha m <= frac_part_n_alpha x)%R.
intro;
apply
(Rle_trans (frac_part_n_alpha m) (frac_part_n_alpha x)
(frac_part_n_alpha n) H8 a).
elim (H6 m H2).
intro; apply (Rlt_le (frac_part_n_alpha m) (frac_part_n_alpha x) H8).
intro; rewrite H8; unfold Rle in |- *; right; auto with arith real.
apply prop_alpha.
intro; rewrite H2; apply tech_total_order.
elim H0; intros.
cut (0 < m /\ m < n \/ 0 < m /\ m = n).
intro; elim H3; intro.
left; auto with arith real.
elim H4; intros.
right; auto with arith real.
cut (0 < m /\ (m < n \/ m = n)).
intro; elim H3; intros.
elim H5; intro.
left; auto with arith real.
right; auto with arith real.
split; auto with arith real.
unfold lt in H2; inversion H2; auto with arith real.
exists x; split.
elim p; intros; auto with arith real.
split.
elim p; intros.
elim H1; intros; auto with arith real.
intros; elim p; intros; elim H2; intros; cut (0 < m /\ m < n \/ m = n).
intro; elim H5; intro.
elim (H4 m H6); auto with arith real.
apply prop_alpha.
rewrite H6; unfold ordre_total in |- *; intro.
cut (frac_part_n_alpha n < frac_part_n_alpha x)%R.
intro; apply (Rlt_le (frac_part_n_alpha n) (frac_part_n_alpha x) H8).
apply (Rnot_le_lt (frac_part_n_alpha x) (frac_part_n_alpha n) b).
elim H0; intros; cut (0 < m /\ m < n \/ 0 < m /\ m = n).
intro; elim H7; intros.
left; auto with arith real.
elim H8; intros; right; auto with arith real.
cut (0 < m /\ (m < n \/ m = n)).
intro; elim H7; intros; elim H9; intro.
left; auto with arith real.
right; auto with arith real.
split; auto with arith real.
unfold lt in H6; inversion H6; auto with arith real.
apply (Rle_dec (frac_part_n_alpha x) (frac_part_n_alpha n)).
Qed.
(**********)
Definition first (N : nat) :=
match N_classic N with
| inright p => match exist_first N p return nat with
| existT a b => a
end
| _ => 0
end.
(**********)
Definition last (N : nat) :=
match N_classic N with
| inright p => match exist_last N p return nat with
| existT a b => a
end
| _ => 0
end.
(*********************************************************)
(*       Definition of the next point                    *)
(*********************************************************)

Lemma exist_after_M :
forall M : R,
(0 <= M)%R ->
(M < 1)%R ->
forall N : nat,
sig
(fun I : nat =>
0 < I /\
I < N /\
(M < frac_part_n_alpha I)%R /\
(forall m : nat,
0 <= m ->
m < N ->
(frac_part_n_alpha m > M)%R ->
(frac_part_n_alpha m >= frac_part_n_alpha I)%R)) +
{(forall m : nat,
0 <= m ->
m < N -> (0 <= frac_part_n_alpha m)%R /\ (frac_part_n_alpha m <= M)%R)}.