I'm quite new at Coq and trying to develop a framework based on my research. My work is quite definition-heavy and I'm having trouble encoding it because of how Coq seems to treat sets.
There are Type
and Set
, which they call 'sorts', and I can use them to define a new set:
Variable X: Type.
And then there's a library encoding (sub)sets as 'Ensembles', which are functions from some Type
to a Prop
. In other words, they are predicates on a Type
:
Variable Y: Ensemble X.
Ensemble
s feel more like proper mathematical sets. Plus, they are built upon by many other libraries. I've tried focussing on them: defining one universal set U: Set
, and then limiting myself to (sub)Ensemble
s on U
. But no. Ensemble
s cannot be used as types for other variables, nor to define new subsets:
Variable y: Y. (* Error *) Variable Z: Ensemble Y. (* Error *)
Now, I know there are several ways to get around that. The question "Subset parameter" offers two. Both use coercions. The first sticks to Set
s. The second essentially uses Ensemble
s (though not by name). But both require quite some machinery to accomplish something so simple.
Question: What is the recommended way of consistently (and elegantly) handling sets?
Example: Here's an example of what I want to do: Assume a set DD. Define a pair dm = (D, <) where D is a finite subset of DD and < is a strict partial order on D.
I'm sure that with enough tinkering with coercions or other structures, I could accomplish it; but not in a particularly readable way; and without a good intuition of how to manipulate the structure further. For example, the following type-checks:
Record OrderedSet {DD: Set} : Type := { D : (Ensemble DD); order : (relation {d | In _ D d}); is_finite : (Finite _ D); is_strict_partial : (is_strict_partial_order order) }.
But I'm not so sure it's what I want; and it certainly doesn't look very pretty. Note that I'm going backwards and forwards between Set
and Ensemble
in a seemingly arbitrary way.
There are plenty of libraries out there which use Ensemble
s, so there must be a nice way to treat them, but those libraries don't seem to be documented very well (or... at all).
Update: To complicate matters further, there appear to be a number of other set implementations too, like MSets. This one seems to be completely separate and incompatible with Ensemble
. It also uses bool
rather than Prop
for some reason. There is also FSets, but it appears to be an outdated version of MSets.