Skip to content

Instantly share code, notes, and snippets.

@DmxLarchey
Created September 14, 2022 20:44
Show Gist options
  • Save DmxLarchey/ee2ae2d134e467adadbb6a90befe6a41 to your computer and use it in GitHub Desktop.
Save DmxLarchey/ee2ae2d134e467adadbb6a90befe6a41 to your computer and use it in GitHub Desktop.
Much nicer inversion for Fin (S n), without fixpoints
Section Fin.
Inductive Fin : nat -> Type :=
| Fz {n : nat} : Fin (S n)
| Fs {n : nat} : Fin n -> Fin (S n).
Inductive Fin_shape_O : Fin 0 -> Type := .
Inductive Fin_shape_S {n} : Fin (S n) -> Type :=
| Fin_shape_S_fst : Fin_shape_S Fz
| Fin_shape_S_nxt i : Fin_shape_S (Fs i).
Let Fin_invert_t {n} : Fin n -> Type :=
match n with
| O => Fin_shape_O
| S n => Fin_shape_S
end.
Definition Fin_invert {n} (i : Fin n) : Fin_invert_t i :=
match i with
| Fz => Fin_shape_S_fst
| Fs i => Fin_shape_S_nxt i
end.
Lemma fin_ind :
forall (n : nat) (P : Fin (S n) -> Type),
P Fz -> (forall (f : Fin n), P (Fs f)) ->
forall fw : Fin (S n), P fw.
Proof.
intros n P HP1 HP2 fw.
now destruct (Fin_invert fw).
Qed.
End Fin.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment