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

前端 未结 3 1026
青春惊慌失措
青春惊慌失措 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条回答
  •  生来不讨喜
    2021-02-09 14:31

    The standard library of coq provides the following finite set modules:

    1. Coq.MSets abstracts away the implementation details of the set. For instance, there is an implementation that uses AVL trees and another based on lists.
    2. Coq.FSets abstracts away the implementation details of the set; it is a previous version of MSets.
    3. Coq.Lists.ListSet is an encoding of lists as sets, which I am including for the sake of completeness

    Here is an example on how to define a set with FSets:

    Require Import Coq.Structures.OrderedTypeEx.
    Require Import Coq.FSets.FSetAVL.
    
    Module NSet := FSetAVL.Make Nat_as_OT.
    (* Creates a set with only element 3 inside: *)
    Check (NSet.add 3 NSet.empty).
    

提交回复
热议问题