123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113(******************************************************************************)(* *)(* The Alt-Ergo theorem prover *)(* Copyright (C) 2006-2013 *)(* *)(* Sylvain Conchon *)(* Evelyne Contejean *)(* *)(* Francois Bobot *)(* Mohamed Iguernelala *)(* Stephane Lescuyer *)(* Alain Mebsout *)(* *)(* CNRS - INRIA - Universite Paris Sud *)(* *)(* This file is distributed under the terms of the Apache Software *)(* License version 2.0 *)(* *)(* ------------------------------------------------------------------------ *)(* *)(* Alt-Ergo: The SMT Solver For Software Verification *)(* Copyright (C) 2013-2018 --- OCamlPro SAS *)(* *)(* This file is distributed under the terms of the Apache Software *)(* License version 2.0 *)(* *)(******************************************************************************)moduleMyZarith=ZarithNumbers[@@@ocaml.warning"-60"]moduleMyNums=NumsNumbersmoduleZ=MyZarith.ZmoduleQ=structincludeMyZarith.Qlettwo=from_int2letroot_numqn=assert(n>=0);letsgn=signqinassert(sgn>=0);ifn=1thenSomeqelseifsgn=0thenSomezeroelseletv=to_floatqinletw=if(Stdlib.comparevmin_float)<0thenmin_floatelseif(Stdlib.comparevmax_float)>0thenmax_floatelsevinletflt=ifn=2thensqrtwelsew**(1./.floatn)inmatchclassify_floatfltwith|FP_normal|FP_subnormal|FP_zero->Some(from_floatflt)|FP_infinite|FP_nan->Noneletunaccurate_root_defaultqn=matchroot_numqnwith|None->None|(Somes)asres->letd=subq(powersn)inifsignd>=0thenreselseSome(divq(powers(n-1)))letunaccurate_root_excessqn=matchroot_numqnwith|None->None|Somesasres->letd=subq(powersn)inifsignd<=0thenreselseSome(divq(powers(n-1)))letaccurate_root_defaultqn=letdd=unaccurate_root_defaultqninletee=unaccurate_root_excessqninmatchdd,eewith|None,_|_,None->dd|Somed,Somee->letcand=div(addde)twoinifMyZarith.Q.compare(powercandn)q<=0thenSomecandelseddletaccurate_root_excessqn=letdd=unaccurate_root_defaultqninletee=unaccurate_root_excessqninmatchdd,eewith|None,_|_,None->ee|Somed,Somee->letcand=div(addde)twoinifMyZarith.Q.compare(powercandn)q>=0thenSomecandelseeeletsqrt_excessq=matchroot_numq2with|None->None|Somes->ifnot(is_zeros)thenSome(div(adds(divqs))two)elseaccurate_root_defaultq2letsqrt_defaultq=matchsqrt_excessqwith|None->None|Somes->ifnot(is_zeros)thenSome(divqs)elseaccurate_root_excessq2letroot_default=accurate_root_defaultletroot_excess=accurate_root_excessend