1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374(************************************************************************)(* * 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) *)(************************************************************************)openNumCompatopenQ.Notations(** Intervals (extracted from mfourier.ml) *)(** The type of intervals is *)typeinterval=Q.toption*Q.toption(** None models the absence of bound i.e. infinity
As a result,
- None , None -> \]-oo,+oo\[
- None , Some v -> \]-oo,v\]
- Some v, None -> \[v,+oo\[
- Some v, Some v' -> \[v,v'\]
Intervals needs to be explicitly normalised.
*)letppo(n1,n2)=(matchn1with|None->output_stringo"]-oo"|Somen->Printf.fprintfo"[%s"(Q.to_stringn));output_stringo",";matchn2with|None->output_stringo"+oo["|Somen->Printf.fprintfo"%s]"(Q.to_stringn)(** if then interval [itv] is empty, [norm_itv itv] returns [None]
otherwise, it returns [Some itv] *)letnorm_itvitv=matchitvwith|Somea,Someb->ifa<=/bthenSomeitvelseNone|_->Someitv(** [inter i1 i2 = None] if the intersection of intervals is empty
[inter i1 i2 = Some i] if [i] is the intersection of the intervals [i1] and [i2] *)letinteri1i2=letl1,r1=i1andl2,r2=i2inletinterfo1o2=match(o1,o2)with|None,None->None|Some_,None->o1|None,Some_->o2|Somen1,Somen2->Some(fn1n2)innorm_itv(interQ.maxl1l2,interQ.minr1r2)letrange=function|None,_|_,None->None|Somei,Somej->Some(Q.floorj-/Q.ceilingi+/Q.one)letsmaller_itvi1i2=match(rangei1,rangei2)with|None,_->false|_,None->true|Somei,Somej->i<=/j(** [in_bound bnd v] checks whether [v] is within the bounds [bnd] *)letin_boundbndv=letl,r=bndinmatch(l,r)with|None,None->true|None,Somea->v<=/a|Somea,None->a<=/v|Somea,Someb->a<=/v&&v<=/b