# Library Coq.Arith.Minus

minus (difference between two natural numbers) is defined in Init/Peano.v as:

    Fixpoint minus (n m:nat) : nat :=
      match n, m with
      | O, _ => n
      | S k, O => S k
      | S k, S l => k - l
      end
    where "n - m" := (minus n m) : nat_scope.

Require Import Lt.
Require Import Le.
Local Open Scope nat_scope.
Implicit Types m n p : nat.

# 0 is right neutral

Lemma minus_n_O : forall n, n = n - 0.
Hint Resolve minus_n_O: arith v62.

# Permutation with successor

Lemma minus_Sn_m : forall n m, m <= n -> S (n - m) = S n - m.
Hint Resolve minus_Sn_m: arith v62.
Theorem pred_of_minus : forall n, pred n = n - 1.

# Diagonal

Lemma minus_diag : forall n, n - n = 0.
Lemma minus_diag_reverse : forall n, 0 = n - n.
Hint Resolve minus_diag_reverse: arith v62.
Notation minus_n_n := minus_diag_reverse.

# Simplification

Lemma minus_plus_simpl_l_reverse : forall n m p, n - m = p + n - ( p + m ).
Hint Resolve minus_plus_simpl_l_reverse: arith v62.

# Relation with plus

Lemma plus_minus : forall n m p, n = m + p -> p = n - m.
Hint Immediate plus_minus: arith v62.
Lemma minus_plus : forall n m, n + m - n = m.
Hint Resolve minus_plus: arith v62.
Lemma le_plus_minus : forall n m, n <= m -> m = n + ( m - n ).
Hint Resolve le_plus_minus: arith v62.
Lemma le_plus_minus_r : forall n m, n <= m -> n + ( m - n ) = m.
Hint Resolve le_plus_minus_r: arith v62.

# Relation with order

Theorem minus_le_compat_r : forall n m p : nat, n <= m -> n - p <= m - p.
Theorem minus_le_compat_l : forall n m p : nat, n <= m -> p - m <= p - n.
Corollary le_minus : forall n m, n - m <= n.
Lemma lt_minus : forall n m, m <= n -> 0 < m -> n - m < n.
Hint Resolve lt_minus: arith v62.
Lemma lt_O_minus_lt : forall n m, 0 < n - m -> m < n.
Hint Immediate lt_O_minus_lt: arith v62.
Theorem not_le_minus_0 : forall n m, ~ m <= n -> n - m = 0.