From 37694c45c4480ec7f74deff7e44a6822a7cd1b5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Pe=C3=B1aranda?= Date: Mon, 16 Oct 2006 17:50:13 +0000 Subject: [PATCH] Some adjustements to the RS interface. --- .../include/CGAL/Gbrs_algebraic_kernel.h | 6 +++ .../include/CGAL/Gbrs_functors.h | 46 ++++++++++--------- .../include/CGAL/Gbrs_solve_1.C | 32 ++++++------- .../include/CGAL/Gbrs_solve_1.h | 8 +++- 4 files changed, 52 insertions(+), 40 deletions(-) diff --git a/Algebraic_kernel_GBRS/include/CGAL/Gbrs_algebraic_kernel.h b/Algebraic_kernel_GBRS/include/CGAL/Gbrs_algebraic_kernel.h index f005162aa41..5a3ed8baa7a 100644 --- a/Algebraic_kernel_GBRS/include/CGAL/Gbrs_algebraic_kernel.h +++ b/Algebraic_kernel_GBRS/include/CGAL/Gbrs_algebraic_kernel.h @@ -32,6 +32,12 @@ class GBRS_algebraic_kernel { public: + // constructor: we must initialize RS just a time, so this is a good + // time to do it + GBRS_algebraic_kernel () { + CGAL_assertion_msg (!(init_rs ()), "error initializing RS"); + }; + typedef IntegralDomain_ Coefficient; typedef Rational_polynomial_1 Polynomial_1; typedef MpfiInterval Algebraic_real_1; diff --git a/Algebraic_kernel_GBRS/include/CGAL/Gbrs_functors.h b/Algebraic_kernel_GBRS/include/CGAL/Gbrs_functors.h index b5c938538d7..247dd1453eb 100644 --- a/Algebraic_kernel_GBRS/include/CGAL/Gbrs_functors.h +++ b/Algebraic_kernel_GBRS/include/CGAL/Gbrs_functors.h @@ -42,8 +42,7 @@ class Construct_polynomial_1 { InputIterator it; for (it = first; it != last; ++it) ++elements; - CGAL_assertion_msg (elements != 0, - "the container can't be empty"); + CGAL_assertion_msg (elements, "the container can't be empty"); int degree = elements-1; Polynomial_1 p (degree); for (it = first; it != last; ++it) @@ -51,7 +50,10 @@ class Construct_polynomial_1 { return p; }; - // TODO: check this "functor" (is this a functor?) + // TODO: check this "functor" (what is a functor in C++?) + + // great! now I know what is that... now I hate C++ a lot more than + // ten minutes ago... f_-_! template Polynomial_1 operator() (InputIterator1 first_coeff, InputIterator1 last_coeff, @@ -60,17 +62,13 @@ class Construct_polynomial_1 { unsigned int greater = 0; InputIterator1 c; InputIterator2 d = deg; - for (c = first_coeff; c != last_coeff; ++c) { + for (c = first_coeff; c != last_coeff; ++c) if (d > greater) - greater = d; - ++d; - } + greater = d++; // now, construct the polynomial of degree d Polynomial_1 p (d); - for (c = first_coeff; c != last_coeff; ++c) { - p.set_coef (deg, *c); - ++deg; - } + for (c = first_coeff; c != last_coeff; ++c) + p.set_coef (deg++, *c); return p; }; }; // Construct_polynomial_1 @@ -87,13 +85,15 @@ class Solve_1 { if (known_to_be_square_free) return res; mpfi_t *x; - int nr = solve_1 (x, p); - if (nr > 0) + int nr; + CGAL_assertion_msg (((nr = solve_1 (x, p)) >= 0), + "error in resolution"); + if (nr) for (int i=0; i 0) + int nr; + CGAL_assertion_msg (!((nr = solve_1 (x, p)) < 0), + "error in resolution"); + if (nr) for (int i=0; i -// this file is based on the RS original example, rs_demo_mp.c +// this file is based on the RS original example, rs_demo_mp.c (because we +// don't know RS, this little funny suprising amazing fantastic candy-flavored +// library) #include #include @@ -32,6 +34,11 @@ CGAL_BEGIN_NAMESPACE #define DEF_PREC 23 #endif +int init_rs () { + rs_init_rs (); + return 0; +}; + int affiche_vect_ibfr (mpfi_t *&x, int index, const int ident_vect) { int ident_elt; int nb = rs_export_dim_vect_ibfr (ident_vect); @@ -42,8 +49,7 @@ int affiche_vect_ibfr (mpfi_t *&x, int index, const int ident_vect) { } int affiche_sols_eqs (mpfi_t *&x) { - int ident_sols_eqs, nb_elts, ident_node, ident_vect; - int i; + int ident_sols_eqs, nb_elts, ident_node, ident_vect, i; ident_sols_eqs = rs_get_default_sols_eqs (); // the number of solutions nb_elts = rs_export_list_vect_ibfr_nb (ident_sols_eqs); @@ -60,28 +66,22 @@ int affiche_sols_eqs (mpfi_t *&x) { } void create_rs_upoly(mpz_t *poly, const int deg, const int ident_pol) { - int i; - int /*ident_pol,*/ ident_mon, ident_coeff; - rs_import_uppring ("T"); + int ident_mon, ident_coeff, i; + rs_import_uppring ("T"); // what the heck is this? for (i=0; i<=deg; ++i) - if (mpz_sgn (poly[/*deg-*/i]) != 0) { // don't add if == 0 + if (mpz_sgn (poly[i])) { // don't add if == 0 + // (this is one of the few things we know about RS) ident_mon = rs_export_new_mon_upp_bz (); ident_coeff = rs_export_new_gmp (); - /*CGAL_assertion_msg - (mpz_cmp_ui (mpq_denref (poly[deg-i]), 1) == 0, - "by now, RS works only with integer coeffs");*/ - /*rs_import_bz_gmp - (ident_coeff, - TO_RSPTR_IN (mpq_numref (poly[deg-i])));*/ rs_import_bz_gmp - (ident_coeff, TO_RSPTR_IN (&(poly[/*deg-*/i]))); + (ident_coeff, TO_RSPTR_IN (&(poly[i]))); rs_dset_mon_upp_bz (ident_mon, ident_coeff, i); rs_dappend_list_mon_upp_bz (ident_pol, ident_mon); } } int solve_1 (mpfi_t *&x, const Rational_polynomial_1 &p1, unsigned int prec) { - rs_init_rs (); + // the solver must be initialized rs_reset_all (); create_rs_upoly (p1.get_coefs (), p1.get_degree (), rs_get_default_up ()); @@ -93,7 +93,7 @@ int solve_1 (mpfi_t *&x, const Rational_polynomial_1 &p1, unsigned int prec) { return affiche_sols_eqs (x); // return the number of solutions } -int solve_1 (mpfi_t *&x, const Rational_polynomial_1 &p1) { +inline int solve_1 (mpfi_t *&x, const Rational_polynomial_1 &p1) { return solve_1 (x, p1, DEF_PREC); } diff --git a/Algebraic_kernel_GBRS/include/CGAL/Gbrs_solve_1.h b/Algebraic_kernel_GBRS/include/CGAL/Gbrs_solve_1.h index 678b4e587b5..ef5bb41020c 100644 --- a/Algebraic_kernel_GBRS/include/CGAL/Gbrs_solve_1.h +++ b/Algebraic_kernel_GBRS/include/CGAL/Gbrs_solve_1.h @@ -24,13 +24,17 @@ #include CGAL_BEGIN_NAMESPACE -// both functions return the number of roots + +// initialize the RS solver, returns 0 if everything was OK +int init_solver (); + +// next functions return the number of roots: // solve given the precision int solve_1 (mpfi_t *&, const Rational_polynomial_1 &, unsigned int); // solve with the default precision -int solve_1 (mpfi_t *&, const Rational_polynomial_1 &); +inline int solve_1 (mpfi_t *&, const Rational_polynomial_1 &); CGAL_END_NAMESPACE