(* ========================================================================= *)
(* Maximum of two nums and of a list of nums. *)
(* *)
(* Author: Marco Maggesi *)
(* University of Florence, Italy *)
(* http://www.math.unifi.it/~maggesi/ *)
(* *)
(* (c) Copyright, Marco Maggesi, 2005-2007 *)
(* ========================================================================= *)
needs "Permutation/morelist.ml";;
(* ------------------------------------------------------------------------- *)
(* Maximum of two nums. *)
(* ------------------------------------------------------------------------- *)
let MAX_LE = prove
(`!m n p.
MAX m n <= p <=> m <= p /\ n <= p`,
REWRITE_TAC [
MAX] THEN ARITH_TAC);;
let LE_MAX = prove
(`!m n p. p <=
MAX m n <=> p <= m \/ p <= n`,
REWRITE_TAC [
MAX] THEN ARITH_TAC);;
let MAX_SYM = prove
(`!m n.
MAX n m =
MAX m n`,
MATCH_MP_TAC
WLOG_LE THEN CONJ_TAC THEN REPEAT GEN_TAC THENL
[EQ_TAC THEN SIMP_TAC []; SIMP_TAC [
MAX] THEN ARITH_TAC]);;
let MAX_ASSOC = prove
(`!m n p.
MAX (
MAX m n) p =
MAX m (
MAX n p)`,
REPEAT GEN_TAC THEN REWRITE_TAC [
MAX] THEN
ASM_CASES_TAC `m <= n` THEN ASM_REWRITE_TAC [] THEN
ASM_CASES_TAC `n <= p` THEN ASM_REWRITE_TAC [] THENL
[SUBGOAL_THEN `m <= p` (fun th -> REWRITE_TAC [th]) THEN
MATCH_MP_TAC
LE_TRANS THEN ASM_MESON_TAC [];
SUBGOAL_THEN `~(m <= p)` (fun th -> REWRITE_TAC [th]) THEN
FIRST_X_ASSUM MP_TAC THEN FIRST_X_ASSUM MP_TAC THEN ARITH_TAC]);;
(* ------------------------------------------------------------------------- *)
(* Maximum of a list of nums. *)
(* ------------------------------------------------------------------------- *)