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