From 8ed87d7a05de4dce4e4cf6d0806321595f481cb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Pe=C3=B1aranda?= Date: Tue, 20 Feb 2007 18:08:21 +0000 Subject: [PATCH] Horner's method to evaluate poly_1's and easier refine_and_compare algorithm --- .../include/CGAL/Gbrs_polynomial_1.h | 2 +- .../src/Gbrs/Gbrs_polynomial_1.cpp | 55 +++++-- .../src/Gbrs/Gbrs_solve_1.cpp | 135 +----------------- 3 files changed, 48 insertions(+), 144 deletions(-) diff --git a/Algebraic_kernel_GBRS/include/CGAL/Gbrs_polynomial_1.h b/Algebraic_kernel_GBRS/include/CGAL/Gbrs_polynomial_1.h index 87745e53ae3..982ee8ae338 100644 --- a/Algebraic_kernel_GBRS/include/CGAL/Gbrs_polynomial_1.h +++ b/Algebraic_kernel_GBRS/include/CGAL/Gbrs_polynomial_1.h @@ -70,7 +70,7 @@ class Rational_polynomial_1 { void set_root(const Algebraic_1&);*/ //CGAL::Algebraic_1 eval_alg(const CGAL::Algebraic_1&)const; CGAL::Gmpz eval (const CGAL::Gmpz &) const; - void eval_mpfr(mpfr_ptr,mpfr_srcptr,mp_prec_t)const; + void eval_mpfr(mpfr_ptr,mpfr_srcptr)const; void eval_mpfi(mpfi_ptr,mpfi_srcptr)const; Rational_polynomial_1 derive () const; std::ostream& show (std::ostream &) const; diff --git a/Algebraic_kernel_GBRS/src/Gbrs/Gbrs_polynomial_1.cpp b/Algebraic_kernel_GBRS/src/Gbrs/Gbrs_polynomial_1.cpp index 1fbcc15207b..569a5143510 100644 --- a/Algebraic_kernel_GBRS/src/Gbrs/Gbrs_polynomial_1.cpp +++ b/Algebraic_kernel_GBRS/src/Gbrs/Gbrs_polynomial_1.cpp @@ -153,20 +153,49 @@ CGAL::Gmpz Rational_polynomial_1::eval(const CGAL::Gmpz &x)const{ return ret; }; -void Rational_polynomial_1::eval_mpfr -(mpfr_ptr result,mpfr_srcptr x,mp_prec_t prec)const{ - mpfr_t x_pow,temp; - mp_prec_t prec_r=mpfr_get_prec(result); - mpfr_inits2(prec0){ // shift h0 and add + mpz_mul_2exp(h0,h0,e0); + mpz_add(h0,h0,c[d-i]); + e0=0; + }else{ + if(e0<0){ // shift c[d-i] and add + mpz_mul_2exp(temp,c[d-i],-e0); + mpz_add(h0,h0,temp); + e0=0; + }else // we are lucky, e0=0 + mpz_add(h0,h0,c[d-i]); + } + // at this point, H0 is the evaluation of the polynomial } - mpfr_clears(x_pow,temp,NULL); - return; + mpfr_set_prec(result,mpz_sizeinbase(h0,2)); + mpfr_set_z(result,h0,GMP_RNDN); + mpfr_mul_2si(result,result,e0,GMP_RNDN); + mpz_clear(h0); + mpz_clear(x); + mpz_clear(temp); }; // I think RS should do this diff --git a/Algebraic_kernel_GBRS/src/Gbrs/Gbrs_solve_1.cpp b/Algebraic_kernel_GBRS/src/Gbrs/Gbrs_solve_1.cpp index cd6547efd8e..bd3ef4d48ef 100644 --- a/Algebraic_kernel_GBRS/src/Gbrs/Gbrs_solve_1.cpp +++ b/Algebraic_kernel_GBRS/src/Gbrs/Gbrs_solve_1.cpp @@ -299,140 +299,15 @@ int get_root (mpfi_ptr x, int n) { return 0; // false: we couldn't copy the root } -int refine_1_rs(Algebraic_1 &a){ - rs_reset_all (); - create_rs_upoly (a.pol().get_coefs (), a.pol().get_degree (), - rs_get_default_up ()); - int newprec = a.rsprec() * CGAL_RS_PREC_FACTOR; - a.set_rsprec (newprec); - set_rs_precisol (newprec); - set_rs_verbose (CGAL_RS_VERB); - rs_run_algo ("UISOLE"); - return get_root (a.mpfi(), a.nr()); -} - -// TODO: rewrite this awful function -// TODO: test cases where RS is called Comparison_result refine_and_compare_1(Algebraic_1 &r1,Algebraic_1 &r2){ - mpfr_t left1,right1,center1,evall1,evalc1,evalr1, - left2,right2,center2,evall2,evalc2,evalr2; - mp_prec_t prec1,prec2,prec; - if((prec1=r1.rsprec())<(prec2=r2.rsprec())) - prec=(prec2*=2); - else - prec=(prec1*=2); - mp_prec_t local_prec=prec; - mpfr_inits2(local_prec,left1,right1,center1,evall1,evalc1,evalr1, - left2,right2,center2,evall2,evalc2,evalr2,NULL); - bool flag1,flag2; - int res1,res2; - int prec_changes=1; do{ - // refine r1 - flag1=true; - r1.get_endpoints(left1,right1); - mpfi_get_fr(center1,r1.mpfi()); - r1.pol().eval_mpfr(evall1,left1,prec); - r1.pol().eval_mpfr(evalc1,center1,prec); - r1.pol().eval_mpfr(evalr1,right1,prec); - int sl1=mpfr_sgn(evall1); - int sr1=mpfr_sgn(evalr1); - // if the following assertion fails, it means that the - // precision of the mpfr's was not correctly calculated - //std::cout<<"sl1="<