I am trying to define (1,2,3) as a set of elements in coq. I can define it using list as (1 :: (2 :: (3 :: nil))). Is there any way to define set in coq without using list.
相关问题
- Rewriting with John Major's equality
- Python: Calculate difference between all elements
- Grouping integers by set membership in Python
- Computing unique intersections of subsets
- Find Closest Element in a Set
相关文章
- C#中 public virtual string Category { get; }这么写会报错:
- coq error when trying to use Case. Example from So
- How to switch the current goal in Coq?
- What does “Error: Universe inconsistency” mean in
- Compare sets inside a set
- Set properties to jsf managed-bean
- Efficient all-pairs set intersection on GPU
- Umbraco - how to set the value of a property using
The are basically four possible choices to be made when defining sets in Coq depending on your constraints on the base type of the set and computation needs:
If the base type doesn't have decidable equality, it is common to use:
basically, Coq's Ensembles. This representation cannot "compute", as we can't even decide if two elements are equal.
If the base data type has decidable equality, then there are two choices depending if extensionality is wanted:
Extensionality means that two sets are equal in Coq's logic iff they have the same elements, formally:
If extensionality is wanted, sets should be represented by a canonically-sorted duplicate-free structure, usually a list. A good example is Cyril's Cohen finmap library. This representation however is very inefficient for computing as re-sorting is needed every time a set is modified.
If extensionality is not needed (usually a bad idea if proofs are wanted), you can use representations based on binary trees such as Coq's MSet, which are similar to standard Functional Programming set implementations and can work efficiently.
Finally, when the base type is finite, the set of all sets is a finite type too. The best example of this approach is IMO math-comp's finset, which encodes finite sets as the space of finitely supported membership functions, which is extensional, and forms a complete lattice.
The standard library of coq provides the following finite set modules:
Coq.MSets
abstracts away the implementation details of the set. For instance, there is an implementation that uses AVL trees and another based onlist
s.Coq.FSets
abstracts away the implementation details of the set; it is a previous version ofMSets
.Coq.Lists.ListSet
is an encoding of lists as sets, which I am including for the sake of completenessHere is an example on how to define a set with
FSets
:There are many encodings of sets in Coq (lists, function, trees, ...) which can be finite or not. You should have a look at Coq's standard library. For example the 'simplest' set definition I know is this one