Library Coq.Structures.GenericMinMax
A Generic construction of min and max
First, an interface for types with max and/or min
Any OrderedTypeFull can be equipped by max and min
based on the compare function.
Consequences of the minimalist interface: facts about max and min.
An alternative caracterisation of max, equivalent to
max_l /\ max_r
A more symmetric version of max_spec, based only on le.
Beware that left and right alternatives overlap.
A function satisfying the same specification is equal to max.
max commutes with monotone functions.
Semi-lattice algebraic properties of max
Least-upper bound properties of max
Properties of min
Combined properties of min and max
Distributivity
Modularity
Disassociativity
Anti-monotonicity swaps the role of min and max
Properties requiring a decidable order
Induction principles for max.
max returns one of its arguments.
Idem for min
When the equality is Leibniz, we can skip a few Proper precondition.
Module UsualMinMaxLogicalProperties
(
Import O:
UsualTotalOrder´)(
Import M:
HasMinMax O).
Include MinMaxLogicalProperties O M.
Lemma max_monotone f :
Proper (
le ==> le)
f ->
forall x y,
max (
f x) (
f y)
= f (
max x y).
Lemma min_monotone f :
Proper (
le ==> le)
f ->
forall x y,
min (
f x) (
f y)
= f (
min x y).
Lemma min_max_antimonotone f :
Proper (
le ==> inverse le)
f ->
forall x y,
min (
f x) (
f y)
= f (
max x y).
Lemma max_min_antimonotone f :
Proper (
le ==> inverse le)
f ->
forall x y,
max (
f x) (
f y)
= f (
min x y).
End UsualMinMaxLogicalProperties.
Module UsualMinMaxDecProperties
(
Import O:
UsualOrderedTypeFull´)(
Import M:
HasMinMax O).
Module Import Private_Dec :=
MinMaxDecProperties O M.
Lemma max_case_strong :
forall n m (
P:
t ->
Type),
(
m<=n ->
P n) -> (
n<=m ->
P m) ->
P (
max n m).
Lemma max_case :
forall n m (
P:
t ->
Type),
P n ->
P m ->
P (
max n m).
Lemma max_dec :
forall n m,
{max n m = n} + {max n m = m}.
Lemma min_case_strong :
forall n m (
P:
O.t ->
Type),
(
n<=m ->
P n) -> (
m<=n ->
P m) ->
P (
min n m).
Lemma min_case :
forall n m (
P:
O.t ->
Type),
P n ->
P m ->
P (
min n m).
Lemma min_dec :
forall n m,
{min n m = n} + {min n m = m}.
End UsualMinMaxDecProperties.
Module UsualMinMaxProperties
(
Import O:
UsualOrderedTypeFull´)(
Import M:
HasMinMax O).
Module OT :=
OTF_to_TotalOrder O.
Include UsualMinMaxLogicalProperties OT M.
Include UsualMinMaxDecProperties O M.
Definition max_l :=
max_l.
Definition max_r :=
max_r.
Definition min_l :=
min_l.
Definition min_r :=
min_r.
End UsualMinMaxProperties.
From TotalOrder and HasMax and HasEqDec, we can prove
that the order is decidable and build an OrderedTypeFull.
TODO: Some Remaining questions...
--> Compare with a type-classes version ?
--> Is max_unicity and max_unicity_ext really convenient to express
that any possible definition of max will in fact be equivalent ?
--> Is it possible to avoid copy-paste about min even more ?