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
(* $Id: DecidableTypeEx.v 11699 2008-12-18 11:49:08Z letouzey $ *)
11
Require Import DecidableType OrderedType OrderedTypeEx.
12
Set Implicit Arguments.
13
Unset Strict Implicit.
15
(** * Examples of Decidable Type structures. *)
17
(** A particular case of [DecidableType] where
18
the equality is the usual one of Coq. *)
20
Module Type UsualDecidableType.
21
Parameter Inline t : Type.
22
Definition eq := @eq t.
23
Definition eq_refl := @refl_equal t.
24
Definition eq_sym := @sym_eq t.
25
Definition eq_trans := @trans_eq t.
26
Parameter eq_dec : forall x y, { eq x y }+{~eq x y }.
27
End UsualDecidableType.
29
(** a [UsualDecidableType] is in particular an [DecidableType]. *)
31
Module UDT_to_DT (U:UsualDecidableType) <: DecidableType := U.
33
(** an shortcut for easily building a UsualDecidableType *)
35
Module Type MiniDecidableType.
36
Parameter Inline t : Type.
37
Parameter eq_dec : forall x y:t, { x=y }+{ x<>y }.
38
End MiniDecidableType.
40
Module Make_UDT (M:MiniDecidableType) <: UsualDecidableType.
42
Definition eq := @eq t.
43
Definition eq_refl := @refl_equal t.
44
Definition eq_sym := @sym_eq t.
45
Definition eq_trans := @trans_eq t.
46
Definition eq_dec := M.eq_dec.
49
(** An OrderedType can now directly be seen as a DecidableType *)
51
Module OT_as_DT (O:OrderedType) <: DecidableType := O.
53
(** (Usual) Decidable Type for [nat], [positive], [N], [Z] *)
55
Module Nat_as_DT <: UsualDecidableType := Nat_as_OT.
56
Module Positive_as_DT <: UsualDecidableType := Positive_as_OT.
57
Module N_as_DT <: UsualDecidableType := N_as_OT.
58
Module Z_as_DT <: UsualDecidableType := Z_as_OT.
60
(** From two decidable types, we can build a new DecidableType
61
over their cartesian product. *)
63
Module PairDecidableType(D1 D2:DecidableType) <: DecidableType.
65
Definition t := prod D1.t D2.t.
67
Definition eq x y := D1.eq (fst x) (fst y) /\ D2.eq (snd x) (snd y).
69
Lemma eq_refl : forall x : t, eq x x.
71
intros (x1,x2); red; simpl; auto.
74
Lemma eq_sym : forall x y : t, eq x y -> eq y x.
76
intros (x1,x2) (y1,y2); unfold eq; simpl; intuition.
79
Lemma eq_trans : forall x y z : t, eq x y -> eq y z -> eq x z.
81
intros (x1,x2) (y1,y2) (z1,z2); unfold eq; simpl; intuition eauto.
84
Definition eq_dec : forall x y, { eq x y }+{ ~eq x y }.
86
intros (x1,x2) (y1,y2); unfold eq; simpl.
87
destruct (D1.eq_dec x1 y1); destruct (D2.eq_dec x2 y2); intuition.
90
End PairDecidableType.
92
(** Similarly for pairs of UsualDecidableType *)
94
Module PairUsualDecidableType(D1 D2:UsualDecidableType) <: UsualDecidableType.
95
Definition t := prod D1.t D2.t.
96
Definition eq := @eq t.
97
Definition eq_refl := @refl_equal t.
98
Definition eq_sym := @sym_eq t.
99
Definition eq_trans := @trans_eq t.
100
Definition eq_dec : forall x y, { eq x y }+{ ~eq x y }.
102
intros (x1,x2) (y1,y2);
103
destruct (D1.eq_dec x1 y1); destruct (D2.eq_dec x2 y2);
104
unfold eq, D1.eq, D2.eq in *; simpl;
105
(left; f_equal; auto; fail) ||
106
(right; intro H; injection H; auto).
109
End PairUsualDecidableType.