### coq

#### How to define finite set of N elements in Coq?

How to define, for general parameter N:nat , finite set of N elements, $ A_{0},...A_{N-1} $ ? Is there an elegant way to do it by recursive definition? Could someone point me into good example of reasoning about such structures?

A very convenient solution is to define the nth ordinal, 'I_n as a record: Definition ordinal n := { val :> nat; _ : val < n; }. that is to say, a pair of a natural number, plus a proof that such natural number is less than n, where < : nat -> nat -> bool. It is very convenient to use a computable comparison operator here, in particular means that the proof itself is not very "important", which is what you normally want. This is the solution used in math-comp, and it has nice properties, mainly injectivity of val, val_inj : injective val, which means that you can reuse most of the standard operations over nat with your new datatype. Note that you may want to define addition as either add i j := max n.-1 (i+j) or as (i+j) %% n. Additionally, the library linked above provides general definitions for working with finite types, including a bijection of them to their cardinal ordinal.

### Related Links

How to do “negative” match in Ltac?

How to match a “match” expression?

Inverting an obviously untrue hypothesis does not prove falsehood

COQ gets wrong by proving “forall n:nat, ( n <= 0) -> n=0”

How can I do intros in a different order without using generalize dependent in Coq?

Defining isomorphism classes in Coq

How to prove (forall n m : nat, (n <? m) = false -> m <= n) in Coq?

How to do pseudo polynomial divisions in Coq/Ssreflect

How to prove functions equal, knowing their bodies are equal?

Using dependent types in Coq (safe nth function)

Case based proof using nat comparisons in COQ

Change a function at one point

Apply a function to both sides of an equality in Coq?

Coq induction start at specific nat

Extraction of Type Scheme

Contracting nested let statments