1
(***********************************************************************)
2
(* v * The Coq Proof Assistant / The Coq Development Team *)
3
(* <O___,, * INRIA-Rocquencourt & LRI-CNRS-Orsay *)
4
(* \VV/ *************************************************************)
5
(* // * This file is distributed under the terms of the *)
6
(* * GNU Lesser General Public License Version 2.1 *)
7
(***********************************************************************)
9
(* Finite sets library.
10
* Authors: Pierre Letouzey and Jean-Christophe Filliâtre
11
* Institution: LRI, CNRS UMR 8623 - Université Paris Sud
12
* 91405 Orsay, France *)
14
(* $Id: OrderedTypeAlt.v 11699 2008-12-18 11:49:08Z letouzey $ *)
16
Require Import OrderedType.
18
(** * An alternative (but equivalent) presentation for an Ordered Type
21
(** NB: [comparison], defined in [Datatypes.v] is [Eq|Lt|Gt]
22
whereas [compare], defined in [OrderedType.v] is [EQ _ | LT _ | GT _ ]
25
Module Type OrderedTypeAlt.
29
Parameter compare : t -> t -> comparison.
31
Infix "?=" := compare (at level 70, no associativity).
33
Parameter compare_sym :
34
forall x y, (y?=x) = CompOpp (x?=y).
35
Parameter compare_trans :
36
forall c x y z, (x?=y) = c -> (y?=z) = c -> (x?=z) = c.
40
(** From this new presentation to the original one. *)
42
Module OrderedType_from_Alt (O:OrderedTypeAlt) <: OrderedType.
47
Definition eq x y := (x?=y) = Eq.
48
Definition lt x y := (x?=y) = Lt.
50
Lemma eq_refl : forall x, eq x x.
54
assert (H:=compare_sym x x).
55
destruct (x ?= x); simpl in *; try discriminate; auto.
58
Lemma eq_sym : forall x y, eq x y -> eq y x.
62
rewrite H; simpl; auto.
65
Definition eq_trans := (compare_trans Eq).
67
Definition lt_trans := (compare_trans Lt).
69
Lemma lt_not_eq : forall x y, lt x y -> ~eq x y.
71
unfold eq, lt; intros.
72
rewrite H; discriminate.
75
Definition compare : forall x y, Compare lt eq x y.
78
case_eq (x ?= y); intros.
82
rewrite compare_sym; rewrite H; auto.
85
Definition eq_dec : forall x y, { eq x y } + { ~ eq x y }.
88
case (x ?= y); [ left | right | right ]; auto; discriminate.
91
End OrderedType_from_Alt.
93
(** From the original presentation to this alternative one. *)
95
Module OrderedType_to_Alt (O:OrderedType) <: OrderedTypeAlt.
97
Module MO:=OrderedTypeFacts(O).
102
Definition compare x y := match compare x y with
108
Infix "?=" := compare (at level 70, no associativity).
111
forall x y, (y?=x) = CompOpp (x?=y).
113
intros x y; unfold compare.
114
destruct O.compare; elim_comp; simpl; auto.
117
Lemma compare_trans :
118
forall c x y z, (x?=y) = c -> (y?=z) = c -> (x?=z) = c.
121
destruct c; unfold compare;
122
do 2 (destruct O.compare; intros; try discriminate);
126
End OrderedType_to_Alt.