Example uses of MSets in Coq

只谈情不闲聊 提交于 2020-05-14 19:07:55

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/44793027/example-uses-of-msets-in-coq

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!