123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110(******************************************************************************)(* ocplib-simplex *)(* *)(* Copyright (C) --- OCamlPro --- See README.md for information and licensing *)(******************************************************************************)openExtSigsmoduletypeSIG=sigmoduleR:CoefsmoduleV:Valuewithtyper=R.ttypet=private{v:V.t;offset:R.t}valzero:tvalof_r:V.t->tvalupper:V.t->tvallower:V.t->tvalminus:t->tvaladd:t->t->tvalsub:t->t->tvalmult_by_const:R.t->t->tvaldiv_by_const:R.t->t->tvalcompare:t->t->intvalequal:t->t->boolvalis_zero:t->boolvalis_pure_rational:t->boolvalis_int:t->boolvalfloor:t->tvalceiling:t->tvalprint:Format.formatter->t->unitendmoduleMake(R:Rationals)(V:Valuewithtyper=R.t):SIGwithmoduleR=RandmoduleV=V=structmoduleR=RmoduleV=Vtypet={v:V.t;offset:R.t;(* When working on strict bounds, an epsilon is added to the bounds.
The offset represents the amount of epsilon are added. *)}letof_rv={v;offset=R.zero}letupperv={v;offset=R.m_one}letlowerv={v;offset=R.one}letzero=of_rV.zeroletis_pure_rationalr=R.equalr.offsetR.zeroletis_intr=is_pure_rationalr&&V.is_intr.vletmapfga={v=fa.v;offset=ga.offset}letmap2fgab={v=fa.vb.v;offset=ga.offsetb.offset}letadd=map2V.addR.addletsub=map2V.subR.subletmult_by_constce=ifR.is_onectheneelsemap(funv->V.mult_by_coefvc)(funv->R.multvc)eletdiv_by_constce=ifR.is_onectheneelsemap(funv->V.div_by_coefvc)(funv->R.divvc)eletcompareab=letc=V.comparea.vb.vinifc<>0thencelseR.comparea.offsetb.offsetletequalab=compareab=0letis_zeroa=V.is_zeroa.v&&R.is_zeroa.offsetletminus=mapV.minusR.minusletfloorr=ifV.is_intr.vthenifis_pure_rationalrthenrelseof_r(V.subr.vV.one)elseof_r(V.floorr.v)letceilingr=ifV.is_intr.vthenifis_pure_rationalrthenrelseof_r(V.addr.vV.one)elseof_r(V.ceilingr.v)letprint_offsetfmtoff=letc=R.compareoffR.zeroinifc=0then()elseifc>0thenFormat.fprintffmt"+%aƐ"R.printoffelseFormat.fprintffmt"%aƐ"R.printoffletprintfmtr=Format.fprintffmt"%a%a"V.printr.vprint_offsetr.offsetend