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

前端 未结 3 1036
青春惊慌失措
青春惊慌失措 2021-02-09 13:31

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.

3条回答
  •  Happy的楠姐
    2021-02-09 14:37

    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:

      Definition Set A := A -> Prop
      Definition cup A B := fun x => A x /\ B x.
      ...
      

      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:

        forall (A B : set T), (A = B) <-> (forall x, x \in A <-> x \in B).
        

        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.

提交回复
热议问题