forked from plclub/metalib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CoqUniquenessTacEx.v
84 lines (57 loc) · 2.59 KB
/
CoqUniquenessTacEx.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
(* This file is distributed under the terms of the MIT License, also
known as the X11 Licence. A copy of this license is in the README
file that accompanied the original distribution of this file.
Based on code written by:
Brian Aydemir *)
Require Import Coq.Arith.Peano_dec.
Require Import Coq.Lists.SetoidList.
Require Import Coq.omega.Omega.
Require Import CoqUniquenessTac.
(* *********************************************************************** *)
(** * Examples *)
(** The examples go through more smoothly if we declare [eq_nat_dec]
as a hint. *)
Hint Resolve eq_nat_dec : eq_dec.
(* *********************************************************************** *)
(** ** Predicates on natural numbers *)
Scheme le_ind' := Induction for le Sort Prop.
Lemma le_unique : forall (x y : nat) (p q: x <= y), p = q.
Proof.
induction p using le_ind'; uniqueness 1.
assert False by omega; intuition.
assert False by omega; intuition.
Qed.
(* ********************************************************************** *)
(** ** Predicates on lists *)
(** Uniqueness of proofs for predicates on lists often comes up when
discussing extensional equality on finite sets, as implemented by
the FSets library. *)
Section Uniqueness_Of_SetoidList_Proofs.
Variable A : Type.
Variable R : A -> A -> Prop.
Hypothesis R_unique : forall (x y : A) (p q : R x y), p = q.
Hypothesis list_eq_dec : forall (xs ys : list A), {xs = ys} + {xs <> ys}.
Scheme lelistA_ind' := Induction for lelistA Sort Prop.
Scheme sort_ind' := Induction for sort Sort Prop.
Scheme eqlistA_ind' := Induction for eqlistA Sort Prop.
Theorem lelistA_unique :
forall (x : A) (xs : list A) (p q : lelistA R x xs), p = q.
Proof. induction p using lelistA_ind'; uniqueness 1. Qed.
Theorem sort_unique :
forall (xs : list A) (p q : sort R xs), p = q.
Proof. induction p using sort_ind'; uniqueness 1. apply lelistA_unique. Qed.
Theorem eqlistA_unique :
forall (xs ys : list A) (p q : eqlistA R xs ys), p = q.
Proof. induction p using eqlistA_ind'; uniqueness 2. Qed.
End Uniqueness_Of_SetoidList_Proofs.
(* *********************************************************************** *)
(** ** Vectors *)
(** [uniqueness] can show that the only vector of length zero is the
empty vector. This shows that the tactic is not restricted to
working only on [Prop]s. *)
Inductive vector (A : Type) : nat -> Type :=
| vnil : vector A 0
| vcons : forall (n : nat) (a : A), vector A n -> vector A (S n).
Theorem vector_O_eq : forall (A : Type) (v : vector A 0),
v = vnil _.
Proof. intros. uniqueness 1. Qed.