mathlib3 documentation

data.nat.psub

Partial predecessor and partial subtraction on the natural numbers #

THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.

The usual definition of natural number subtraction (nat.sub) returns 0 as a "garbage value" for a - b when a < b. Similarly, nat.pred 0 is defined to be 0. The functions in this file wrap the result in an option type instead:

Main definitions #

@[simp]

Partial predecessor operation. Returns ppred n = some m if n = m + 1, otherwise none.

Equations
@[simp]
def nat.psub (m : ) :

Partial subtraction operation. Returns psub m n = some k if m = n + k, otherwise none.

Equations
theorem nat.sub_eq_psub (m n : ) :
m - n = (m.psub n).get_or_else 0
@[simp]
theorem nat.ppred_eq_some {m n : } :
@[simp]
theorem nat.ppred_eq_none {n : } :
theorem nat.psub_eq_some {m n k : } :
m.psub n = option.some k k + n = m
theorem nat.psub_eq_none {m n : } :
theorem nat.ppred_eq_pred {n : } (h : 0 < n) :
theorem nat.psub_eq_sub {m n : } (h : n m) :
m.psub n = option.some (m - n)
theorem nat.psub_add (m n k : ) :
m.psub (n + k) = m.psub n >>= λ (x : ), x.psub k
def nat.psub' (m n : ) :

Same as psub, but with a more efficient implementation.

Equations
theorem nat.psub'_eq_psub (m n : ) :
m.psub' n = m.psub n