(* Protected, structurally decreasing subtraction, and basic lemmas.  *)
(* Further properties depend on ordering conditions.                  *)

Definition subn_rec := minus.Definition subn := nosimpl subn_rec.

(* Specifications: *)
Lemma subnE : subn = subn_rec.
Lemma minusE : minus = subn.
Lemma sub0n : left_zero 0 subn.
Lemma subn0 : right_id 0 subn.
Lemma subnn : self_inverse 0 subn.
Lemma subSS n m : m.+1 - n.+1 = m - n.
Lemma subn1 n : n - 1 = n.-1.
Lemma subn2 n : (n - 2)%N = n.-2.
Lemma subnDl p m n : (p + m) - (p + n) = m - n.
Lemma subnDr p m n : (m + p) - (n + p) = m - n.
Lemma addKn n : cancel (addn n) (subn^~ n).
Lemma addnK n : cancel (addn^~ n) (subn^~ n).
Lemma subSnn n : n.+1 - n = 1.
Lemma subnDA m n p : n - (m + p) = (n - m) - p.
Lemma subnAC : right_commutative subn.
Lemma subnS m n : m - n.+1 = (m - n).-1.
Lemma subSKn m n : (m.+1 - n).-1 = m - n.
Lemma ltnS m n : (m < n.+1) = (m <= n).
Lemma leq0n n : 0 <= n.
Lemma ltn0Sn n : 0 < n.+1.
Lemma ltn0 n : n < 0 = false.
Lemma leqnn n : n <= n.
Lemma ltnSn n : n < n.+1.
Lemma eq_leq m n : m = n -> m <= n.
Lemma leqnSn n : n <= n.+1.
Lemma leq_pred n : n.-1 <= n.
Lemma leqSpred n : n <= n.-1.+1.
Lemma ltn_predK m n : m < n -> n.-1.+1 = n.
Lemma prednK n : 0 < n -> n.-1.+1 = n.
Lemma leqNgt m n : (m <= n) = ~~ (n < m).
Lemma ltnNge m n : (m < n) = ~~ (n <= m).
Lemma ltnn n : n < n = false.
Lemma anti_leq : antisymmetric leq.
Lemma ltn_geF m n : m < n -> m >= n = false.
Lemma leq_gtF m n : m <= n -> m > n = false.
Lemma leq_trans n m p : m <= n -> n <= p -> m <= p.
Lemma leq_ltn_trans n m p : m <= n -> n < p -> m < p.
Lemma ltnW m n : m < n -> m <= n.
Lemma leqW m n : m <= n -> m <= n.+1.
Lemma ltn_trans n m p : m < n -> n < p -> m < p.
Lemma leq_total m n : (m <= n) || (m >= n).
Lemma leP m n : reflect (m <= n)%coq_nat (m <= n).
Lemma le_irrelevance m n le_mn1 le_mn2 : le_mn1 = le_mn2 :> (m <= n)%coq_nat.
Lemma ltP m n : reflect (m < n)%coq_nat (m < n).
Lemma lt_irrelevance m n lt_mn1 lt_mn2 : lt_mn1 = lt_mn2 :> (m < n)%coq_nat.
Lemma leqP m n : leq_xor_gtn m n (m <= n) (n < m).
Lemma ltnP m n : ltn_xor_geq m n (n <= m) (m < n).
Lemma leq_add2l p m n : (p + m <= p + n) = (m <= n).
Lemma ltn_add2l p m n : (p + m < p + n) = (m < n).
Lemma leq_add2r p m n : (m + p <= n + p) = (m <= n).
Lemma ltn_add2r p m n : (m + p < n + p) = (m < n).
Lemma leq_add m1 m2 n1 n2 : m1 <= n1 -> m2 <= n2 -> m1 + m2 <= n1 + n2.
Lemma leq_addr m n : n <= n + m.
Lemma leq_addl m n : n <= m + n.
Lemma ltn_addr m n p : m < n -> m < n + p.
Lemma ltn_addl m n p : m < n -> m < p + n.
Lemma addn_gt0 m n : (0 < m + n) = (0 < m) || (0 < n).
Lemma subn_gt0 m n : (0 < n - m) = (m < n).
Lemma leq_subLR m n p : (m - n <= p) = (m <= n + p).
Lemma leq_subr m n : n - m <= n.
Lemma subnKC m n : m <= n -> m + (n - m) = n.
Lemma subnK m n : m <= n -> (n - m) + m = n.
Lemma addnBA m n p : p <= n -> m + (n - p) = m + n - p.
Lemma addnBAC m n p : n <= m -> m - n + p = m + p - n.
Lemma addnBCA m n p : p <= m -> p <= n -> m + (n - p) = n + (m - p).
Lemma addnABC m n p : p <= m -> p <= n -> m + (n - p) = m - p + n.
Lemma subnBA m n p : p <= n -> m - (n - p) = m + p - n.
Lemma subKn m n : m <= n -> n - (n - m) = m.
Lemma subSn m n : m <= n -> n.+1 - m = (n - m).+1.
Lemma subnSK m n : m < n -> (n - m.+1).+1 = n - m.
Lemma leq_sub2r p m n : m <= n -> m - p <= n - p.
Lemma leq_sub2l p m n : m <= n -> p - n <= p - m.
Lemma leq_sub m1 m2 n1 n2 : m1 <= m2 -> n2 <= n1 -> m1 - n1 <= m2 - n2.
Lemma ltn_sub2r p m n : p < n -> m < n -> m - p < n - p.
Lemma ltn_sub2l p m n : m < p -> m < n -> p - n < p - m.
Lemma ltn_subRL m n p : (n < p - m) = (m + n < p).
Lemma subn_if_gt T m n F (E : T) : (if m.+1 - n is m'.+1 then F m' else E) = (if n <= m then F (m - n) else E).