### 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

Apply partially instantiated lemma

Using reflexivity in Coq

High-speed calculation of Coq's theorems

Topological Definition of Continuous in Coq

Reference in Coq Lists library not found

Purpose of maximal vs non-maximal implicit arguments

Idris type system properties

How to destruct/generalize over Program's rewritten match statements

Show all axioms Coq

Product Type in Coq

Coq inductive definition for the entailment property

How to make sublists in Coq?

Nested theorems in Coq

Why does this rewrite fail in the context of dependent types

How to raise exception in Coq?(in match … end)

How to define set in coq without defining set as a list of elements