1+ (** Numbers up to @n@ * *)
12Require Coq.Lists.List.
23Require Import ExtLib.Core.RelDec.
34Require Import ExtLib.Tactics.EqDep.
@@ -7,6 +8,9 @@ Set Implicit Arguments.
78Set Strict Implicit .
89Set Asymmetric Patterns.
910
11+ (** `fin n` corresponds to "naturals less than `n`",
12+ ** i.e. a finite set of size n
13+ * *)
1014Inductive fin : nat -> Type :=
1115| F0 : forall {n}, fin (S n)
1216| FS : forall {n}, fin n -> fin (S n).
3943
4044Definition fin0_elim (f : fin 0) : forall T, T :=
4145 match f in fin n return match n with
42- | 0 => forall T, T
43- | _ => unit
46+ | 0 => forall T, T
47+ | _ => unit
4448 end with
45- | F0 _ => tt
46- | FS _ _ => tt
49+ | F0 _ => tt
50+ | FS _ _ => tt
4751 end .
4852
4953Fixpoint pf_lt (n m : nat) : Prop :=
5054 match n , m with
51- | 0 , S _ => True
52- | S n , S m => pf_lt n m
53- | _ , _ => False
55+ | 0 , S _ => True
56+ | S n , S m => pf_lt n m
57+ | _ , _ => False
5458 end .
5559
5660Fixpoint make (m n : nat) {struct m} : pf_lt n m -> fin m :=
5761 match n as n , m as m return pf_lt n m -> fin m with
58- | 0 , 0 => @False_rect _
59- | 0 , S n => fun _ => F0
60- | S n , 0 => @False_rect _
61- | S n , S m => fun pf => FS (make m n pf)
62+ | 0 , 0 => @False_rect _
63+ | 0 , S n => fun _ => F0
64+ | S n , 0 => @False_rect _
65+ | S n , S m => fun pf => FS (make m n pf)
6266 end .
6367
6468Notation "'##' n" := (@make _ n I) (at level 0).
@@ -71,41 +75,34 @@ Defined.
7175
7276Fixpoint fin_eq_dec {n} (x : fin n) {struct x} : fin n -> bool :=
7377 match x in fin n' return fin n' -> bool with
74- | F0 _ => fun y => match y with
75- | F0 _ => true
76- | _ => false
77- end
78- | FS n' x' => fun y : fin (S n') =>
79- match y in fin n'' return (match n'' with
80- | 0 => unit
81- | S n'' => fin n''
82- end -> bool) -> bool with
83- | F0 _ => fun _ => false
84- | FS _ y' => fun f => f y'
85- end (fun y => fin_eq_dec x' y)
86- end .
78+ | F0 _ => fun y => match y with
79+ | F0 _ => true
80+ | _ => false
81+ end
82+ | FS n' x' => fun y : fin (S n') =>
83+ match y in fin n'' return (match n'' with
84+ | 0 => unit
85+ | S n'' => fin n''
86+ end -> bool) -> bool with
87+ | F0 _ => fun _ => false
88+ | FS _ y' => fun f => f y'
89+ end (fun y => fin_eq_dec x' y)
90+ end .
8791
8892Global Instance RelDec_fin_eq (n : nat) : RelDec (@eq (fin n)) :=
8993{ rel_dec := fin_eq_dec }.
9094
9195Global Instance RelDec_Correct_fin_eq (n : nat)
92- : RelDec_Correct (RelDec_fin_eq n).
96+ : RelDec_Correct (RelDec_fin_eq n).
9397Proof .
9498 constructor.
95- induction x. simpl.
96- intro. destruct (fin_case y) ; subst.
97- intuition.
98- destruct H ; subst.
99- intuition ; try congruence.
100- inversion H.
101- intro ; destruct (fin_case y) ; subst ; simpl.
102- intuition ; try congruence.
103- inversion H.
104- destruct H ; subst.
105- split ; intro.
106- f_equal ; eauto.
107- eapply IHx.
108- eapply H.
109- inv_all ; subst.
110- apply IHx. reflexivity.
99+ induction x.
100+ { intro. destruct (fin_case y) ; subst.
101+ { split; reflexivity. }
102+ { destruct H. subst. simpl. split; congruence. } }
103+ { intro; destruct (fin_case y) ; subst ; simpl.
104+ { split; congruence. }
105+ { destruct H. subst. simpl. split.
106+ { intro; f_equal. eapply IHx. assumption. }
107+ { intro. inv_all. apply IHx in H. assumption. } } }
111108Qed .
0 commit comments