(* Max and min. *)

Definition maxn m n := if m < n then n else m.Definition minn m n := if m < n then m else n.

(* Specifications: *)
Lemma max0n : left_id 0 maxn.
Lemma maxn0 : right_id 0 maxn.
Lemma maxnC : commutative maxn.
Lemma maxnE m n : maxn m n = m + (n - m).
Lemma maxnAC : right_commutative maxn.
Lemma maxnA : associative maxn.
Lemma maxnCA : left_commutative maxn.
Lemma maxnACA : interchange maxn maxn.
Lemma maxn_idPl {m n} : reflect (maxn m n = m) (m >= n).
Lemma maxn_idPr {m n} : reflect (maxn m n = n) (m <= n).
Lemma maxnn : idempotent maxn.
Lemma leq_max m n1 n2 : (m <= maxn n1 n2) = (m <= n1) || (m <= n2).
Lemma leq_maxl m n : m <= maxn m n.
Lemma leq_maxr m n : n <= maxn m n.
Lemma gtn_max m n1 n2 : (m > maxn n1 n2) = (m > n1) && (m > n2).
Lemma geq_max m n1 n2 : (m >= maxn n1 n2) = (m >= n1) && (m >= n2).
Lemma maxnSS m n : maxn m.+1 n.+1 = (maxn m n).+1.
Lemma addn_maxl : left_distributive addn maxn.
Lemma addn_maxr : right_distributive addn maxn.
Lemma min0n : left_zero 0 minn.
Lemma minn0 : right_zero 0 minn.
Lemma minnC : commutative minn.
Lemma addn_min_max m n : minn m n + maxn m n = m + n.
Lemma minnE m n : minn m n = m - (m - n).
Lemma minnAC : right_commutative minn.
Lemma minnA : associative minn.
Lemma minnCA : left_commutative minn.
Lemma minnACA : interchange minn minn.
Lemma minn_idPl {m n} : reflect (minn m n = m) (m <= n).
Lemma minn_idPr {m n} : reflect (minn m n = n) (m >= n).
Lemma minnn : idempotent minn.
Lemma leq_min m n1 n2 : (m <= minn n1 n2) = (m <= n1) && (m <= n2).
Lemma gtn_min m n1 n2 : (m > minn n1 n2) = (m > n1) || (m > n2).
Lemma geq_min m n1 n2 : (m >= minn n1 n2) = (m >= n1) || (m >= n2).
Lemma geq_minl m n : minn m n <= m.
Lemma geq_minr m n : minn m n <= n.
Lemma addn_minr : right_distributive addn minn.
Lemma addn_minl : left_distributive addn minn.
Lemma minnSS m n : minn m.+1 n.+1 = (minn m n).+1.
Lemma maxnK m n : minn (maxn m n) m = m.
Lemma maxKn m n : minn n (maxn m n) = n.
Lemma minnK m n : maxn (minn m n) m = m.
Lemma minKn m n : maxn n (minn m n) = n.
Lemma maxn_minl : left_distributive maxn minn.
Lemma maxn_minr : right_distributive maxn minn.
Lemma minn_maxl : left_distributive minn maxn.
Lemma minn_maxr : right_distributive minn maxn.
Lemma find_ex_minn : {m | P m & forall n, P n -> n >= m}.