Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Example uses of MSets in Coq

Tags:

set

coq

MSets appear to be the way to go for OCaml-style finite sets. Sadly, I can't find example uses.

How can I define an empty MSet or a singleton MSet? How can I union two MSets together?

like image 483
Carl Patenaude Poulin Avatar asked Jun 28 '17 03:06

Carl Patenaude Poulin


1 Answers

Let me show a simple example for finite sets of natural numbers:

From Coq
Require Import MSets Arith.

(* We can make a set out of an ordered type *)
Module S := Make Nat_as_OT.

Definition test := S.union (S.singleton 42)
                           (S.empty).

(* membership *)
Compute S.mem 0 test.   (* evaluates to `false` *)
Compute S.mem 42 test.  (* evaluates to `true`  *)

Compute S.is_empty test.     (* evaluates to `false` *)
Compute S.is_empty S.empty.  (* evaluates to `true` *)

You can read Coq.MSets.MSetInterface to discover the operations and specifications MSets provide.

like image 119
Anton Trunov Avatar answered Oct 18 '22 07:10

Anton Trunov