(****************************************************************************)
(*                 The Calculus of Inductive Constructions                  *)
(*                                                                          *)
(*                                Projet Coq                                *)
(*                                                                          *)
(*                     INRIA        LRI-CNRS        ENS-CNRS                *)
(*              Rocquencourt         Orsay          Lyon                    *)
(*                                                                          *)
(*                                 Coq V6.2                                 *)
(*                               May 1st 1998                               *)
(*                                                                          *)
(****************************************************************************)
(*                                 Minus.v                                  *)
(****************************************************************************)


(*********************************************************)
(*    Subtraction                                        *)
(*********************************************************)

(* difference between two natural numbers *)

Fixpoint minus [n:nat] : nat -> nat := 
  [m:nat]Cases n m of
            O _        =>  O
         | (S k) O     => (S k)
         | (S k) (S l) => (minus k l)
        end. 

(* Warning: different printing:
Coq < Print minus.
minus =
Fix minus{minus/1 : nat->nat->nat := 
            [n,m:nat]
             <nat>Case n of
                O
                [k:nat]<nat>Case m of (S k)
                                      [l:nat](minus k l)
                                      end
                end}
*)

Lemma minus_plus_simpl : (n,m,p:nat)((minus n m)=(minus (plus p n) (plus p m))).
Proof.
Induction p; Simpl; Auto.
Qed.
Hint minus_plus_simpl.

Lemma minus_n_O : (n:nat)(n=(minus n O)).
Proof.
Induction n; Simpl; Auto.
Qed.
Hint minus_n_O.

Lemma minus_n_n : (n:nat)(O=(minus n n)).
Proof.
Induction n; Simpl; Auto.
Qed.
Hint minus_n_n.

Lemma plus_minus : (n,m,p:nat)(n=(plus m p))->(p=(minus n m)).
Proof.
Intros n m p; Pattern m n; Apply nat_double_ind; Simpl; Intros.
Replace (minus n0 O) with n0; Auto.
Absurd O=(S (plus n0 p)); Auto.
Auto.
Qed.
Immediate plus_minus.

Lemma minus_plus : (n,m:nat)(minus (plus n m) n)=m.
Symmetry; Auto.
Save.
Hint minus_plus.

Require Le.

Lemma le_plus_minus : (n,m:nat)(le n m)->(m=(plus n (minus m n))).
Proof.
Intros n m Le; Pattern n m; Apply le_elim_rel; Simpl; Auto.
Qed.
Hint le_plus_minus.

Lemma le_plus_minus_r : (n,m:nat)(le n m)->(plus n (minus m n))=m.
Proof.
Symmetry; Auto.
Qed.
Hint le_plus_minus_r.


Lemma minus_Sn_m : (n,m:nat)(le m n)->((S (minus n m))=(minus (S n) m)).
Proof.
Intros n m Le; Pattern m n; Apply le_elim_rel; Simpl; Auto.
Qed.
Hint minus_Sn_m.

Require Lt.

Lemma lt_minus : (n,m:nat)(le m n)->(lt O m)->(lt (minus n m) n).
Proof.
Intros n m Le; Pattern m n; Apply le_elim_rel; Simpl; Auto.
Intros; Absurd (lt O O); Auto.
Intros p q lepq Hp gtp.
Elim (le_lt_or_eq O p); Auto.
Auto.
Induction 1; Elim minus_n_O; Auto.
Qed.
Hint lt_minus.

Lemma lt_O_minus_lt : (n,m:nat)(lt O (minus n m))->(lt m n).
Proof.
Intros n m; Pattern n m; Apply nat_double_ind; Simpl; Auto.
Intros; Absurd (lt O O); Trivial.
Qed.
Immediate lt_O_minus_lt.


(* $Id: Minus.v,v 1.8 1998/04/30 16:45:44 mohring Exp $ *)
