(* 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                                                          *)
(*                                                                          *)
(****************************************************************************)
(****************************************************************************)
(*                               Nat_compl.v                                *)
(****************************************************************************)
(*********************************************************)
(*             Complements for the natural numbers       *)
(*                                                       *)
(*********************************************************)
Global Set Asymmetric Patterns.
Require Export Arith.
Require Export Compare_dec.
(*********************************************************)
Definition decidable (P : Prop) := P \/ ~ P.
(**********************************************************)
(*       Technical lemmas                                 *)
(**********************************************************)
tauto.
Qed.
intros;
generalize (not_ex_all_not nat (fun n : nat => P n /\ Q n /\ R n /\ S n) H);
intro; generalize (not_symt_et (P k) (Q k) (R k) (S k) (H2 k));
intro; generalize (not_and_or (P k /\ Q k) (R k /\ S k) H3);
intro; generalize (or_to_imply (P k /\ Q k) (~ (R k /\ S k)) H4);
intro; cut (P k /\ Q k); auto with core arith.
intro; generalize (H5 H6); intro; apply (not_and_or (R k) (S k) H7).
Qed.
tauto.
Qed.
intros;
cut
((exists m : nat, P m /\ (forall i : nat, P i -> i >= m)) \/
(forall p : nat, n >= p -> ~ P p)).
intro; elim H1; auto with core arith.
intro; generalize (H2 n (le_n n)); intros; absurd (P n); auto with core arith.
elim n.
elim (H 0); intros.
left; exists 0; auto with core arith.
right; unfold ge in |- *; intros; cut (p = 0).
intro; rewrite H3; auto with core arith.
auto with core arith.
intros; elim H1; auto with core arith.
intro; elim (H (S n0)); intro.
left; exists (S n0); split; auto with core arith.
cut (forall p : nat, S n0 <= p \/ p < S n0).
intros; elim (H4 i); auto with core arith.
unfold lt in |- *; intro; generalize (le_S_n i n0 H6); intro; unfold ge in H2;
elim (H2 i H7); auto with core arith.
intro; apply le_or_lt.
right; intros; cut (p < S n0 \/ p = S n0).
intro; elim H5; intro.
generalize (lt_n_Sm_le p n0 H6).
intro; unfold ge in H2; generalize (H2 p H7); auto with core arith.
rewrite H6; auto with core arith.
apply (le_lt_or_eq p (S n0) H4).
Qed.
intros; cut ({q <= m} + {m < q}).
intro; elim H; intros.
elim H0; intro.
right; auto with core arith.
left; auto with core arith.
apply (le_lt_dec q m).
Qed.
intros; cut ({q <= m} + {m < q}).
intro; elim H; intros.
elim H0; intro.
right; auto with core arith.
left; auto with core arith.
apply (le_lt_dec q m).
Qed.
intros; cut ({n <= m /\ m < p} + {p <= m /\ m < t}).
intro; elim H0; intro y.
left; apply (inser_trans n m p q y).
right; auto with core arith.
apply (inser_trans n m t p H).
Qed.
intros; cut ({n < m /\ m < p} + {p <= m /\ m < t}).
intro; elim H0; intro y.
left; apply (inser_trans_lt n m p q y).
right; auto with core arith.
apply (inser_trans_lt n m t p H).
Qed.
intros; omega.
Qed.
intro; omega.
Qed.

(**********)
Lemma lt_plus_minus : forall n m p : nat, m < n -> n < m + p -> n - m < p.