123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111(************************************************************************)(* * The Coq Proof Assistant / The Coq Development Team *)(* v * Copyright INRIA, CNRS and contributors *)(* <O___,, * (see version control and CREDITS file for authors & dates) *)(* \VV/ **************************************************************)(* // * This file is distributed under the terms of the *)(* * GNU Lesser General Public License Version 2.1 *)(* * (see LICENSE file for the text of the license) *)(************************************************************************)(************************************************************************)(* *)(* Objective Caml *)(* *)(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)(* *)(* Copyright 1996 Institut National de Recherche en Informatique et *)(* en Automatique. All rights reserved. This file is distributed *)(* under the terms of the GNU Library General Public License. *)(* *)(************************************************************************)moduletypeOrderedType=sigtypetvalcompare:t->t->intendmoduletypeS=sigtypeelttypetvalempty:tvalfull:tvalis_empty:t->boolvalis_full:t->boolvalmem:elt->t->boolvalsingleton:elt->tvaladd:elt->t->tvalremove:elt->t->tvalunion:t->t->tvalinter:t->t->tvaldiff:t->t->tvalcomplement:t->tvalequal:t->t->boolvalsubset:t->t->boolvalelements:t->bool*eltlistvalis_finite:t->boolendmoduleMake(Ord:OrderedType)=structmoduleEltSet=Set.Make(Ord)typeelt=Ord.t(* (false, s) represents a set which is equal to the set s
(true, s) represents a set which is equal to the complement of set s *)typet=bool*EltSet.tletis_finite(b,_)=notbletelements(b,s)=(b,EltSet.elementss)letempty=(false,EltSet.empty)letfull=(true,EltSet.empty)(* assumes the set is infinite *)letis_empty(b,s)=notb&&EltSet.is_emptysletis_full(b,s)=b&&EltSet.is_emptysletmemx(b,s)=ifbthennot(EltSet.memxs)elseEltSet.memxsletsingletonx=(false,EltSet.singletonx)letaddx(b,s)=ifbthen(b,EltSet.removexs)else(b,EltSet.addxs)letremovex(b,s)=ifbthen(b,EltSet.addxs)else(b,EltSet.removexs)letcomplement(b,s)=(notb,s)letunions1s2=match(s1,s2)with((false,p1),(false,p2))->(false,EltSet.unionp1p2)|((true,n1),(true,n2))->(true,EltSet.intern1n2)|((false,p1),(true,n2))->(true,EltSet.diffn2p1)|((true,n1),(false,p2))->(true,EltSet.diffn1p2)letinters1s2=complement(union(complements1)(complements2))letdiffs1s2=inters1(complements2)(* assumes the set is infinite *)letsubsets1s2=match(s1,s2)with((false,p1),(false,p2))->EltSet.subsetp1p2|((true,n1),(true,n2))->EltSet.subsetn2n1|((false,p1),(true,n2))->EltSet.is_empty(EltSet.interp1n2)|((true,_),(false,_))->false(* assumes the set is infinite *)letequal(b1,s1)(b2,s2)=b1=b2&&EltSet.equals1s2end