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 addition.
This file is mostly OBSOLETE now, see module PeanoNat.Nat instead.
Nat.add is defined in Init/Nat.v as:
Fixpoint add (n m:nat) : nat :=
  match n with
  | O => m
  | S p => S (p + m)
  end
where "n + m" := (add n m) : nat_scope.
Require Import PeanoNat.

Local Open Scope nat_scope.

Neutrality of 0, commutativity, associativity

Notation plus_0_l := Nat.add_0_l (only parsing).
Notation plus_0_r := Nat.add_0_r (only parsing).
Notation plus_comm := Nat.add_comm (only parsing).
Notation plus_assoc := Nat.add_assoc (only parsing).

Notation plus_permute := Nat.add_shuffle3 (only parsing).

Definition plus_Snm_nSm : forall n m, S n + m = n + S m :=
 Peano.plus_n_Sm.

n, m, p:nat

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

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

n + (m + p) = n + m + p
apply Nat.add_assoc. Qed.

Simplification

n, m, p:nat

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

p + n = p + m -> n = m
apply Nat.add_cancel_l. Qed.
n, m, p:nat

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

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

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

p + n < p + m -> n < m
apply Nat.add_lt_mono_l. Qed.

Compatibility with order

n, m, p:nat

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

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

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

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

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

n < m -> p + n < p + m
apply Nat.add_lt_mono_l. Qed.
n, m, p:nat

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

n < m -> n + p < m + p
apply Nat.add_lt_mono_r. Qed.
n, m, p, q:nat

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

n <= m -> p <= q -> n + p <= m + q
apply Nat.add_le_mono. Qed.
n, m, p, q:nat

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

n <= m -> p < q -> n + p < m + q
apply Nat.add_le_lt_mono. Qed.
n, m, p, q:nat

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

n < m -> p <= q -> n + p < m + q
apply Nat.add_lt_le_mono. Qed.
n, m, p, q:nat

n < m -> p < q -> n + p < m + q
n, m, p, q:nat

n < m -> p < q -> n + p < m + q
apply Nat.add_lt_mono. Qed.
n, m:nat

n <= n + m
n, m:nat

n <= n + m
apply Nat.le_add_r. Qed.
n, m:nat

m <= n + m
n, m:nat

m <= n + m
n, m:nat

m <= m + n
apply Nat.le_add_r. Qed.
n, m, p:nat

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

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

n <= m + p
now rewrite <- Nat.le_add_r. Qed.
n, m, p:nat

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

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

n < m + p
n, m, p:nat
H:n < m

n < m
n, m, p:nat
H:n < m
m <= m + p
n, m, p:nat
H:n < m

m <= m + p
apply Nat.le_add_r. Qed.

Inversion lemmas

n, m:nat

n + m = 0 -> n = 0 /\ m = 0
n, m:nat

n + m = 0 -> n = 0 /\ m = 0
destruct n; now split. Qed.
m, n:nat

m + n = 1 -> {m = 0 /\ n = 1} + {m = 1 /\ n = 0}
m, n:nat

m + n = 1 -> {m = 0 /\ n = 1} + {m = 1 /\ n = 0}
m, n:nat

S m + n = 1 -> {S m = 0 /\ n = 1} + {S m = 1 /\ n = 0}
m, n:nat

S (S m) + n = 1 -> {S (S m) = 0 /\ n = 1} + {S (S m) = 1 /\ n = 0}
discriminate. Defined.

Derived properties

Notation plus_permute_2_in_4 := Nat.add_shuffle1 (only parsing).

Tail-recursive plus

tail_plus is an alternative definition for plus which is tail-recursive, whereas plus is not. This can be useful when extracting programs.
Fixpoint tail_plus n m : nat :=
  match n with
    | O => m
    | S n => tail_plus n (S m)
  end.


forall n m : nat, n + m = tail_plus n m

forall n m : nat, n + m = tail_plus n m
n:nat
IHn:forall m : nat, n + m = tail_plus n m

forall m : nat, S (n + m) = tail_plus n (S m)
intro m; rewrite <- IHn; simpl; auto. Qed.

Discrimination

n, m:nat

n <> S (m + n)
n, m:nat

n <> S (m + n)
apply Nat.succ_add_discr. Qed.
n:nat

n <> S (S n)
Proof (succ_plus_discr n 1).
n:nat

n <> S (S (S n))
Proof (succ_plus_discr n 2).
n:nat

n <> S (S (S (S n)))
Proof (succ_plus_discr n 3).

Compatibility Hints

Hint Immediate plus_comm : arith.
Hint Resolve plus_assoc plus_assoc_reverse : arith.
Hint Resolve plus_le_compat_l plus_le_compat_r : arith.
Hint Resolve le_plus_l le_plus_r le_plus_trans : arith.
Hint Immediate lt_plus_trans : arith.
Hint Resolve plus_lt_compat_l plus_lt_compat_r : arith.
For compatibility, we "Require" the same files as before
Require Import Le Lt.