Built with Alectryon, running Coq+SerAPI v8.10.0+0.7.0. Coq sources are in this panel; goals and messages will appear in the other. Bubbles () indicate interactive fragments: hover for details, tap to reveal contents. Use Ctrl+↑ Ctrl+↓ to navigate, Ctrl+🖱️ to focus.
(************************************************************************)
(*         *   The Coq Proof Assistant / The Coq Development Team       *)
(*  v      *   INRIA, CNRS and contributors - Copyright 1999-2018       *)
(* <O___,, *       (see CREDITS file for the list of authors)           *)
(*   \VV/  **************************************************************)
(*    //   *    This file is distributed under the terms of the         *)
(*         *     GNU Lesser General Public License Version 2.1          *)
(*         *     (see LICENSE file for the text of the license)         *)
(************************************************************************)
Properties of subtraction between natural numbers.
This file is mostly OBSOLETE now, see module PeanoNat.Nat instead.
minus is now an alias for Nat.sub, which is defined in Init/Nat.v as:
Fixpoint sub (n m:nat) : nat :=
  match n, m with
  | S k, S l => k - l
  | _, _ => n
  end
where "n - m" := (sub n m) : nat_scope.
Require Import PeanoNat Lt Le.

Local Open Scope nat_scope.

0 is right neutral

n:nat

n = n - 0
n:nat

n = n - 0
n:nat

n - 0 = n
apply Nat.sub_0_r. Qed.

Permutation with successor

n, m:nat

m <= n -> S (n - m) = S n - m
n, m:nat

m <= n -> S (n - m) = S n - m
n, m:nat
H:m <= n

S (n - m) = S n - m
n, m:nat
H:m <= n

S n - m = S (n - m)
now apply Nat.sub_succ_l. Qed.
n:nat

Init.Nat.pred n = n - 1
n:nat

Init.Nat.pred n = n - 1
n:nat

n - 1 = Init.Nat.pred n
apply Nat.sub_1_r. Qed. Register pred_of_minus as num.nat.pred_of_minus.

Diagonal

Notation minus_diag := Nat.sub_diag (only parsing). (* n - n = 0 *)

n:nat

0 = n - n
n:nat

0 = n - n
n:nat

n - n = 0
apply Nat.sub_diag. Qed. Notation minus_n_n := minus_diag_reverse.

Simplification

n, m, p:nat

n - m = p + n - (p + m)
n, m, p:nat

n - m = p + n - (p + m)
now rewrite Nat.sub_add_distr, Nat.add_comm, Nat.add_sub. Qed.

Relation with plus

n, m, p:nat

n = m + p -> p = n - m
n, m, p:nat

n = m + p -> p = n - m
n, m, p:nat
H:n = m + p

n - m = p
now apply Nat.add_sub_eq_l. Qed.
n, m:nat

n + m - n = m
n, m:nat

n + m - n = m
n, m:nat

m + n - n = m
apply Nat.add_sub. Qed.
n, m:nat

n <= m -> n + (m - n) = m
n, m:nat

n <= m -> n + (m - n) = m
n, m:nat

n <= m -> m - n + n = m
apply Nat.sub_add. Qed.
n, m:nat

n <= m -> m = n + (m - n)
n, m:nat

n <= m -> m = n + (m - n)
n, m:nat
H:n <= m

m = n + (m - n)
n, m:nat
H:n <= m

n + (m - n) = m
n, m:nat
H:n <= m

m - n + n = m
now apply Nat.sub_add. Qed.

Relation with order

Notation minus_le_compat_r :=
  Nat.sub_le_mono_r (only parsing). (* n <= m -> n - p <= m - p. *)

Notation minus_le_compat_l :=
  Nat.sub_le_mono_l (only parsing). (* n <= m -> p - m <= p - n. *)

Notation le_minus := Nat.le_sub_l (only parsing). (* n - m <= n *)
Notation lt_minus := Nat.sub_lt (only parsing). (* m <= n -> 0 < m -> n-m < n *)

n, m:nat

0 < n - m -> m < n
n, m:nat

0 < n - m -> m < n
apply Nat.lt_add_lt_sub_r. Qed.
n, m:nat

~ m <= n -> n - m = 0
n, m:nat

~ m <= n -> n - m = 0
n, m:nat
H:~ m <= n

n - m = 0
now apply Nat.sub_0_le, Nat.lt_le_incl, Nat.lt_nge. Qed.

Hints

Hint Resolve minus_n_O: arith.
Hint Resolve minus_Sn_m: arith.
Hint Resolve minus_diag_reverse: arith.
Hint Resolve minus_plus_simpl_l_reverse: arith.
Hint Immediate plus_minus: arith.
Hint Resolve minus_plus: arith.
Hint Resolve le_plus_minus: arith.
Hint Resolve le_plus_minus_r: arith.
Hint Resolve lt_minus: arith.
Hint Immediate lt_O_minus_lt: arith.