From 0f1861d275f54a1dc4d4edac12c0d21226ea8707 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 6 Aug 2024 12:14:31 +0100 Subject: [PATCH 1/4] Algebraic_kernel: Remove RS --- .../Algebraic_kernel_d/Algebraic_kernel_d.txt | 43 +- .../CGAL/Algebraic_kernel_rs_gmpq_d_1.h | 59 -- .../CGAL/Algebraic_kernel_rs_gmpz_d_1.h | 57 -- .../Concepts/AlgebraicKernel_d_1.h | 4 +- .../Concepts/AlgebraicKernel_d_2.h | 6 +- .../Algebraic_kernel_d/PackageDescription.txt | 7 +- .../CGAL/Algebraic_kernel_rs_gmpq_d_1.h | 114 --- .../CGAL/Algebraic_kernel_rs_gmpz_d_1.h | 65 -- .../include/CGAL/RS/Gmpfr_make_unique.h | 30 - Algebraic_kernel_d/include/CGAL/RS/ak_1.h | 172 ----- Algebraic_kernel_d/include/CGAL/RS/ak_z_1.h | 202 ----- .../include/CGAL/RS/algebraic_1.h | 353 --------- .../include/CGAL/RS/algebraic_z_1.h | 351 --------- .../include/CGAL/RS/bisection_refiner_1.h | 165 ----- .../include/CGAL/RS/comparator_1.h | 81 -- Algebraic_kernel_d/include/CGAL/RS/dyadic.h | 430 ----------- .../include/CGAL/RS/exact_signat_1.h | 52 -- .../include/CGAL/RS/functors_1.h | 648 ---------------- .../include/CGAL/RS/functors_z_1.h | 699 ------------------ .../include/CGAL/RS/polynomial_converter_1.h | 49 -- .../include/CGAL/RS/rs23_k_isolator_1.h | 140 ---- .../include/CGAL/RS/rs2_calls.h | 141 ---- .../include/CGAL/RS/rs2_isolator_1.h | 114 --- .../include/CGAL/RS/rs3_k_refiner_1.h | 157 ---- .../include/CGAL/RS/rs3_refiner_1.h | 169 ----- Algebraic_kernel_d/include/CGAL/RS/signat_1.h | 105 --- .../Algebraic_kernel_rs_gmpq_d_1.cpp | 142 ---- .../Algebraic_kernel_rs_gmpz_d_1.cpp | 189 ----- .../test/Algebraic_kernel_d/CMakeLists.txt | 11 - 29 files changed, 8 insertions(+), 4747 deletions(-) delete mode 100644 Algebraic_kernel_d/doc/Algebraic_kernel_d/CGAL/Algebraic_kernel_rs_gmpq_d_1.h delete mode 100644 Algebraic_kernel_d/doc/Algebraic_kernel_d/CGAL/Algebraic_kernel_rs_gmpz_d_1.h delete mode 100644 Algebraic_kernel_d/include/CGAL/Algebraic_kernel_rs_gmpq_d_1.h delete mode 100644 Algebraic_kernel_d/include/CGAL/Algebraic_kernel_rs_gmpz_d_1.h delete mode 100644 Algebraic_kernel_d/include/CGAL/RS/Gmpfr_make_unique.h delete mode 100644 Algebraic_kernel_d/include/CGAL/RS/ak_1.h delete mode 100644 Algebraic_kernel_d/include/CGAL/RS/ak_z_1.h delete mode 100644 Algebraic_kernel_d/include/CGAL/RS/algebraic_1.h delete mode 100644 Algebraic_kernel_d/include/CGAL/RS/algebraic_z_1.h delete mode 100644 Algebraic_kernel_d/include/CGAL/RS/bisection_refiner_1.h delete mode 100644 Algebraic_kernel_d/include/CGAL/RS/comparator_1.h delete mode 100644 Algebraic_kernel_d/include/CGAL/RS/dyadic.h delete mode 100644 Algebraic_kernel_d/include/CGAL/RS/exact_signat_1.h delete mode 100644 Algebraic_kernel_d/include/CGAL/RS/functors_1.h delete mode 100644 Algebraic_kernel_d/include/CGAL/RS/functors_z_1.h delete mode 100644 Algebraic_kernel_d/include/CGAL/RS/polynomial_converter_1.h delete mode 100644 Algebraic_kernel_d/include/CGAL/RS/rs23_k_isolator_1.h delete mode 100644 Algebraic_kernel_d/include/CGAL/RS/rs2_calls.h delete mode 100644 Algebraic_kernel_d/include/CGAL/RS/rs2_isolator_1.h delete mode 100644 Algebraic_kernel_d/include/CGAL/RS/rs3_k_refiner_1.h delete mode 100644 Algebraic_kernel_d/include/CGAL/RS/rs3_refiner_1.h delete mode 100644 Algebraic_kernel_d/include/CGAL/RS/signat_1.h delete mode 100644 Algebraic_kernel_d/test/Algebraic_kernel_d/Algebraic_kernel_rs_gmpq_d_1.cpp delete mode 100644 Algebraic_kernel_d/test/Algebraic_kernel_d/Algebraic_kernel_rs_gmpz_d_1.cpp diff --git a/Algebraic_kernel_d/doc/Algebraic_kernel_d/Algebraic_kernel_d.txt b/Algebraic_kernel_d/doc/Algebraic_kernel_d/Algebraic_kernel_d.txt index f7090c76a103..46ef18f5a2d8 100644 --- a/Algebraic_kernel_d/doc/Algebraic_kernel_d/Algebraic_kernel_d.txt +++ b/Algebraic_kernel_d/doc/Algebraic_kernel_d/Algebraic_kernel_d.txt @@ -10,7 +10,7 @@ namespace CGAL { \section Algebraic_kernel_dIntroduction Introduction Real solving of polynomials is a fundamental problem with a wide application range. -This package is targeted at providing black-box implementations of state-of-the-art +This package provides black-box implementations of algorithms to determine, compare, and approximate real roots of univariate polynomials and bivariate polynomial systems. Such a black-box is called an *Algebraic Kernel*. Since this package is aimed at providing more than one implementation, the interface of @@ -283,41 +283,6 @@ is not stored internally in terms of an `Algebraic_real_1` object. Querying such a representation by calling `Compute_y_2` is a time-consuming step, and should be avoided for efficiency reasons if possible. -\subsection Algebraic_kernel_dAlgebraicKernelsBasedon Algebraic Kernels Based on RS - -The package offers two univariate algebraic kernels that are based on -the library RS \cgalCite{cgal:r-rs}, namely `Algebraic_kernel_rs_gmpz_d_1` -and `Algebraic_kernel_rs_gmpq_d_1`. As the names indicate, -the kernels are based on the library RS \cgalCite{cgal:r-rs} and support univariate -polynomials over `Gmpz` or `Gmpq`, respectively. - -In general we encourage to use `Algebraic_kernel_rs_gmpz_d_1` -instead of `Algebraic_kernel_rs_gmpq_d_1`. This is caused by -the fact that the most efficient way to compute operations (such as gcd) -on polynomials with rational coefficients is to use the corresponding -implementation for polynomials with integer coefficients. That is, -the `Algebraic_kernel_rs_gmpq_d_1` is slightly slower due to -overhead caused by the necessary conversions. However, since this may -not always be a major issue, the `Algebraic_kernel_rs_gmpq_d_1` -is provided for convenience. - -The core of both kernels is the implementation of the interval Descartes -algorithm \cgalCite{cgal:rz-jcam-04} of the library RS \cgalCite{cgal:r-rs}, -which is used to isolate the roots of the polynomial. -The RS library restricts its attention to univariate integer -polynomials and some substantial gain of efficiency can be made by using a kernel -that does not follow the generic programming paradigm, by avoiding -interfaces between layers. Specifically, working with -only one number type allows to optimize some polynomial operations -as well as memory handling. The implementation of these kernels -make heavy use of the \mpfr \cgalCite{cgal:mt-mpfr} and \mpfi \cgalCite{cgal:r-mpfi} -libraries, and of their \cgal interfaces, `Gmpfr` and `Gmpfi`. -The algebraic numbers (roots of the polynomials) are represented -in the two RS kernels by a `Gmpfi` interval and a pointer to -the polynomial of which they are roots. See \cgalCite{cgal:lpt-wea-09} -for more details on the implementation, tests of these kernels, -comparisons with other algebraic kernels and discussions about the -efficiency. \section Algebraic_kernel_dExamples Examples @@ -376,12 +341,6 @@ Michael Hemmer and Michael Kerber, respectively. Notwithstanding, the authors al contribution of all authors of the \exacus project, particularly the contribution of Arno Eigenwillig, Sebastian Limbach and Pavel Emeliyanenko. -The two univariate kernels that interface the library RS \cgalCite{cgal:r-rs} were -written by Luis Peñaranda and Sylvain Lazard. -Both models interface the library RS \cgalCite{cgal:r-rs} by Fabrice Rouillier. -The authors want to thank Fabrice Rouillier and Elias Tsigaridas for -strong support and many useful discussions that lead to the integration of RS. */ } /* namespace CGAL */ - diff --git a/Algebraic_kernel_d/doc/Algebraic_kernel_d/CGAL/Algebraic_kernel_rs_gmpq_d_1.h b/Algebraic_kernel_d/doc/Algebraic_kernel_d/CGAL/Algebraic_kernel_rs_gmpq_d_1.h deleted file mode 100644 index dc0f525aeeb3..000000000000 --- a/Algebraic_kernel_d/doc/Algebraic_kernel_d/CGAL/Algebraic_kernel_rs_gmpq_d_1.h +++ /dev/null @@ -1,59 +0,0 @@ - -namespace CGAL { - -/*! -\ingroup PkgAlgebraicKernelDModels - -\anchor Algebraic_kernel_rs_gmpq_d_1 - -This univariate algebraic kernel uses the Rs library to perform -rational univariate polynomial root isolation. It is a model of the -`AlgebraicKernel_d_1` concept. Due to the fact that RS can only -isolate integer polynomials, the operations of this kernel have the -overhead of converting the polynomials to integer. - -\cgalModels{AlgebraicKernel_d_1} - -\sa `Algebraic_kernel_rs_gmpz_d_1` - -*/ - -class Algebraic_kernel_rs_gmpq_d_1 { -public: - -/// \name Types -/// @{ - -/*! -It is a typedef to `CGAL::Gmpq`. -*/ -typedef unspecified_type Coefficient; - -/*! -It is defined as `CGAL::Polynomial`. -*/ -typedef unspecified_type Polynomial_1; - -/*! -Type that represents the real roots of -integer univariate polynomials, containing a pointer to the polynomial of -which the represented algebraic number is root and and a `CGAL::Gmpfi` -isolating interval. -*/ -typedef unspecified_type Algebraic_real_1; - -/*! -Since the isolating intervals of the roots have type -`CGAL::Gmpfi`, the bounds have type `CGAL::Gmpfr`. -*/ -typedef unspecified_type Bound; - -/*! -The multiplicity is an `int`. -*/ -typedef unspecified_type Multiplicity_type; - -/// @} - -}; /* end Algebraic_kernel_rs_gmpq_d_1 */ -} /* end namespace CGAL */ diff --git a/Algebraic_kernel_d/doc/Algebraic_kernel_d/CGAL/Algebraic_kernel_rs_gmpz_d_1.h b/Algebraic_kernel_d/doc/Algebraic_kernel_d/CGAL/Algebraic_kernel_rs_gmpz_d_1.h deleted file mode 100644 index 7f4e7eb0966f..000000000000 --- a/Algebraic_kernel_d/doc/Algebraic_kernel_d/CGAL/Algebraic_kernel_rs_gmpz_d_1.h +++ /dev/null @@ -1,57 +0,0 @@ - -namespace CGAL { - -/*! -\ingroup PkgAlgebraicKernelDModels - -\anchor Algebraic_kernel_rs_gmpz_d_1 - -This univariate algebraic kernel uses the Rs library to perform -integer univariate polynomial root isolation. It is a model of the -`AlgebraicKernel_d_1` concept. - -\cgalModels{AlgebraicKernel_d_1} - -\sa `Algebraic_kernel_rs_gmpz_d_1` - -*/ - -class Algebraic_kernel_rs_gmpz_d_1 { -public: - -/// \name Types -/// @{ - -/*! -It is a typedef to `CGAL::Gmpz`. -*/ -typedef unspecified_type Coefficient; - -/*! -It is defined as `CGAL::Polynomial`. -*/ -typedef unspecified_type Polynomial_1; - -/*! -Type that represents the real roots of -integer univariate polynomials, containing a pointer to the polynomial of -which the represented algebraic number is root and and a `CGAL::Gmpfi` -isolating interval. -*/ -typedef unspecified_type Algebraic_real_1; - -/*! -Since the isolating intervals of the roots have type -`CGAL::Gmpfi`, the bounds have type `CGAL::Gmpfr`. -*/ -typedef unspecified_type Bound; - -/*! -The multiplicity is an `int`. -*/ -typedef unspecified_type Multiplicity_type; - -/// @} - -}; /* end Algebraic_kernel_rs_gmpz_d_1 */ -} /* end namespace CGAL */ diff --git a/Algebraic_kernel_d/doc/Algebraic_kernel_d/Concepts/AlgebraicKernel_d_1.h b/Algebraic_kernel_d/doc/Algebraic_kernel_d/Concepts/AlgebraicKernel_d_1.h index b895e7665b9f..b1e54fa13963 100644 --- a/Algebraic_kernel_d/doc/Algebraic_kernel_d/Concepts/AlgebraicKernel_d_1.h +++ b/Algebraic_kernel_d/doc/Algebraic_kernel_d/Concepts/AlgebraicKernel_d_1.h @@ -9,8 +9,7 @@ algebraic functionalities on univariate polynomials of general degree \f$ d\f$. \cgalRefines{CopyConstructible,Assignable} \cgalHasModelsBegin -\cgalHasModels{CGAL::Algebraic_kernel_rs_gmpz_d_1} -\cgalHasModels{CGAL::Algebraic_kernel_rs_gmpq_d_1} +\cgalHasModels{CGAL::Algebraic_kernel_d_1} \cgalHasModelsEnd \sa `AlgebraicKernel_d_2` @@ -172,4 +171,3 @@ AlgebraicKernel_d_1::Bound_between_1 bound_between_1_object() const; /// @} }; /* end AlgebraicKernel_d_1 */ - diff --git a/Algebraic_kernel_d/doc/Algebraic_kernel_d/Concepts/AlgebraicKernel_d_2.h b/Algebraic_kernel_d/doc/Algebraic_kernel_d/Concepts/AlgebraicKernel_d_2.h index 40eb088b2c95..d6c2be05319a 100644 --- a/Algebraic_kernel_d/doc/Algebraic_kernel_d/Concepts/AlgebraicKernel_d_2.h +++ b/Algebraic_kernel_d/doc/Algebraic_kernel_d/Concepts/AlgebraicKernel_d_2.h @@ -8,6 +8,11 @@ for solving and handling bivariate polynomial systems of general degree \f$ d\f$ \cgalRefines{AlgebraicKernel_d_1,CopyConstructible,Assignable} + +\cgalHasModelsBegin +\cgalHasModels{CGAL::Algebraic_kernel_d_2} +\cgalHasModelsEnd + \sa `AlgebraicKernel_d_1` */ @@ -176,4 +181,3 @@ AlgebraicKernel_d_2::Bound_between_x_2 bound_between_x_2_object() const; /// @} }; /* end AlgebraicKernel_d_2 */ - diff --git a/Algebraic_kernel_d/doc/Algebraic_kernel_d/PackageDescription.txt b/Algebraic_kernel_d/doc/Algebraic_kernel_d/PackageDescription.txt index aa61f788908f..4907d2a41922 100644 --- a/Algebraic_kernel_d/doc/Algebraic_kernel_d/PackageDescription.txt +++ b/Algebraic_kernel_d/doc/Algebraic_kernel_d/PackageDescription.txt @@ -21,12 +21,11 @@ \cgalPkgPicture{Algebraic_kernel_d.png} \cgalPkgSummaryBegin \cgalPkgAuthors{Eric Berberich, Michael Hemmer, Michael Kerber, Sylvain Lazard, Luis Peñaranda, and Monique Teillaud} -\cgalPkgDesc{Real solving of polynomials is a fundamental problem with a wide application range. This package is targeted to provide black-box implementations of state-of-the-art algorithms to determine, compare and approximate real roots of univariate polynomials and bivariate polynomial systems. Such a black-box is called an *Algebraic %Kernel*. So far the package only provides models for the univariate kernel. Nevertheless, it already defines concepts for the bivariate kernel, since this settles the interface for upcoming implementations.} +\cgalPkgDesc{Real solving of polynomials is a fundamental problem with a wide application range. This package is targeted to provide black-box implementation algorithms to determine, compare and approximate real roots of univariate polynomials and bivariate polynomial systems. Such a black-box is called an *Algebraic %Kernel*. So far the package only provides models for the univariate kernel. Nevertheless, it already defines concepts for the bivariate kernel, since this settles the interface for upcoming implementations.} \cgalPkgManuals{Chapter_Algebraic_Kernel,PkgAlgebraicKernelDRef} \cgalPkgSummaryEnd \cgalPkgShortInfoBegin \cgalPkgSince{3.6} -\cgalPkgDependsOn{Some models depend on \ref thirdpartyRS3.} \cgalPkgBib{cgal:bht-ak} \cgalPkgLicense{\ref licensesLGPL "LGPL"} \cgalPkgShortInfoEnd @@ -100,8 +99,4 @@ - `CGAL::Algebraic_kernel_d_1` - `CGAL::Algebraic_kernel_d_2` -- `CGAL::Algebraic_kernel_rs_gmpz_d_1` -- `CGAL::Algebraic_kernel_rs_gmpq_d_1` - */ - diff --git a/Algebraic_kernel_d/include/CGAL/Algebraic_kernel_rs_gmpq_d_1.h b/Algebraic_kernel_d/include/CGAL/Algebraic_kernel_rs_gmpq_d_1.h deleted file mode 100644 index 287d1a307c5c..000000000000 --- a/Algebraic_kernel_d/include/CGAL/Algebraic_kernel_rs_gmpq_d_1.h +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright (c) 2006-2013 INRIA Nancy-Grand Est (France). All rights reserved. -// -// This file is part of CGAL (www.cgal.org) -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial -// -// Author: Luis Peñaranda - -#ifndef CGAL_ALGEBRAIC_KERNEL_RS_GMPQ_D_1 -#define CGAL_ALGEBRAIC_KERNEL_RS_GMPQ_D_1 - -#include - -#include -#include -#include -#include "RS/rs2_isolator_1.h" -#ifdef CGAL_USE_RS3 -#include "RS/rs23_k_isolator_1.h" -#include "RS/rs3_refiner_1.h" -#include "RS/rs3_k_refiner_1.h" -#else -#include "RS/bisection_refiner_1.h" -#endif -#ifdef CGAL_RS_USE_NATIVE_GMPQ_KERNEL -#include "RS/ak_1.h" -#else -#include "RS/ak_z_1.h" -#endif - -// The RS algebraic kernel for non-Gmpz types comes in two flavors. The -// native kernel converts, before each operation, the input polynomial to a -// Polynomial. The z-kernel only converts to a Polynomial -// before isolation and stores both polynomials in the algebraic number. -// The latter is the default behavior, but the former can be selected by -// setting the compilation flag CGAL_RS_USE_NATIVE_GMPQ_KERNEL. - -namespace CGAL{ - -#ifdef CGAL_RS_USE_NATIVE_GMPQ_KERNEL // Use the native kernel. -// Choice of the isolator: RS default or RS-k. -#ifdef CGAL_RS_USE_K -typedef CGAL::RS23_k_isolator_1,CGAL::Gmpfr> - QIsolator; -#else -typedef CGAL::RS2::RS2_isolator_1,CGAL::Gmpfr> - QIsolator; -#endif - -// Choice of the refiner: bisection, RS3 or RS3-k. -#ifdef CGAL_USE_RS3 -#ifdef CGAL_RS_USE_K -typedef CGAL::RS3::RS3_k_refiner_1,CGAL::Gmpfr> - QRefiner; -#else -typedef CGAL::RS3::RS3_refiner_1,CGAL::Gmpfr> - QRefiner; -#endif -#else -typedef CGAL::Bisection_refiner_1,CGAL::Gmpfr> - QRefiner; -#endif - -typedef CGAL::RS_AK1::Algebraic_kernel_1< - CGAL::Polynomial, - CGAL::Gmpfr, - QIsolator, - QRefiner> - Algebraic_kernel_rs_gmpq_d_1; - -#else // Use the z-kernel. - -// Choice of the z-isolator: RS default or RS-k. -#ifdef CGAL_RS_USE_K -typedef CGAL::RS23_k_isolator_1,CGAL::Gmpfr> - ZIsolator; -#else -typedef CGAL::RS2::RS2_isolator_1,CGAL::Gmpfr> - ZIsolator; -#endif - -// Choice of the z-refiner: bisection, RS3 or RS3-k. -#ifdef CGAL_USE_RS3 -#ifdef CGAL_RS_USE_K -typedef CGAL::RS3::RS3_k_refiner_1,CGAL::Gmpfr> - ZRefiner; -#else -typedef CGAL::RS3::RS3_refiner_1,CGAL::Gmpfr> - ZRefiner; -#endif -#else -typedef CGAL::Bisection_refiner_1,CGAL::Gmpfr> - ZRefiner; -#endif - -typedef CGAL::RS_AK1::Algebraic_kernel_z_1< - CGAL::Polynomial, - CGAL::Polynomial, - CGAL::RS_AK1::Polynomial_converter_1, - CGAL::Polynomial >, - CGAL::Gmpfr, - ZIsolator, - ZRefiner> - Algebraic_kernel_rs_gmpq_d_1; - -#endif - -} // namespace CGAL - -#include - -#endif // CGAL_ALGEBRAIC_KERNEL_RS_GMPQ_D_1 diff --git a/Algebraic_kernel_d/include/CGAL/Algebraic_kernel_rs_gmpz_d_1.h b/Algebraic_kernel_d/include/CGAL/Algebraic_kernel_rs_gmpz_d_1.h deleted file mode 100644 index 0ca68bdeb3ec..000000000000 --- a/Algebraic_kernel_d/include/CGAL/Algebraic_kernel_rs_gmpz_d_1.h +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (c) 2006-2013 INRIA Nancy-Grand Est (France). All rights reserved. -// -// This file is part of CGAL (www.cgal.org) -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial -// -// Author: Luis Peñaranda - -#ifndef CGAL_ALGEBRAIC_KERNEL_RS_GMPZ_D_1 -#define CGAL_ALGEBRAIC_KERNEL_RS_GMPZ_D_1 - -#include - -#include -#include -#include -#include "RS/rs2_isolator_1.h" -#ifdef CGAL_USE_RS3 -#include "RS/rs23_k_isolator_1.h" -#include "RS/rs3_refiner_1.h" -#include "RS/rs3_k_refiner_1.h" -#else -#include "RS/bisection_refiner_1.h" -#endif -#include "RS/ak_1.h" - -namespace CGAL{ - -// Choice of the isolator: RS default or RS-k. -#ifdef CGAL_RS_USE_K -typedef CGAL::RS23_k_isolator_1,CGAL::Gmpfr> - Isolator; -#else -typedef CGAL::RS2::RS2_isolator_1,CGAL::Gmpfr> - Isolator; -#endif - -// Choice of the refiner: bisection, RS3 or RS3-k. -#ifdef CGAL_USE_RS3 -#ifdef CGAL_RS_USE_K -typedef CGAL::RS3::RS3_k_refiner_1,CGAL::Gmpfr> - Refiner; -#else -typedef CGAL::RS3::RS3_refiner_1,CGAL::Gmpfr> - Refiner; -#endif -#else -typedef CGAL::Bisection_refiner_1,CGAL::Gmpfr> - Refiner; -#endif - -typedef CGAL::RS_AK1::Algebraic_kernel_1< - CGAL::Polynomial, - CGAL::Gmpfr, - Isolator, - Refiner> - Algebraic_kernel_rs_gmpz_d_1; - -} - -#include - -#endif // CGAL_ALGEBRAIC_KERNEL_RS_GMPZ_D_1 diff --git a/Algebraic_kernel_d/include/CGAL/RS/Gmpfr_make_unique.h b/Algebraic_kernel_d/include/CGAL/RS/Gmpfr_make_unique.h deleted file mode 100644 index 862f317b0965..000000000000 --- a/Algebraic_kernel_d/include/CGAL/RS/Gmpfr_make_unique.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) 2006-2013 INRIA Nancy-Grand Est (France). All rights reserved. -// -// This file is part of CGAL (www.cgal.org) -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial -// -// Author: Luis Peñaranda - -#ifndef CGAL_RS_GMPFR_MAKE_UNIQUE_H -#define CGAL_RS_GMPFR_MAKE_UNIQUE_H - -#include - -// Make sure a number does not share references. If it does, copy it. -#ifdef CGAL_GMPFR_NO_REFCOUNT -# define CGAL_RS_GMPFR_MAKE_UNIQUE(_number,_tempvar) {}; -#else // CGAL_GMPFR_NO_REFCOUNT -# define CGAL_RS_GMPFR_MAKE_UNIQUE(_number,_tempvar) \ - if(!_number.is_unique()){ \ - Gmpfr _tempvar(0,_number.get_precision()); \ - mpfr_set(_tempvar.fr(),_number.fr(),GMP_RNDN); \ - _number=_tempvar; \ - CGAL_assertion_code(_tempvar=Gmpfr();) \ - CGAL_assertion(_number.is_unique()); \ - } -#endif // CGAL_GMPFR_NO_REFCOUNT - -#endif // CGAL_RS_GMPFR_MAKE_UNIQUE_H diff --git a/Algebraic_kernel_d/include/CGAL/RS/ak_1.h b/Algebraic_kernel_d/include/CGAL/RS/ak_1.h deleted file mode 100644 index 40fab5e337b8..000000000000 --- a/Algebraic_kernel_d/include/CGAL/RS/ak_1.h +++ /dev/null @@ -1,172 +0,0 @@ -// Copyright (c) 2006-2013 INRIA Nancy-Grand Est (France). All rights reserved. -// -// This file is part of CGAL (www.cgal.org) -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial -// -// Author: Luis Peñaranda - -#ifndef CGAL_RS_AK_1_H -#define CGAL_RS_AK_1_H - -#include // included only to define size_t -#include -#include "algebraic_1.h" -#include "comparator_1.h" -#include "signat_1.h" -#include "functors_1.h" - -namespace CGAL{ -namespace RS_AK1{ - -template > -class Algebraic_kernel_1{ - public: - typedef Polynomial_ Polynomial_1; - typedef typename Polynomial_1::NT Coefficient; - typedef Bound_ Bound; - private: - typedef Isolator_ Isolator; - typedef Refiner_ Refiner; - typedef Ptraits_ Ptraits; - typedef CGAL::RS_AK1::Signat_1 - Signat; - typedef CGAL::RS_AK1::Simple_comparator_1 - Comparator; - public: - typedef CGAL::RS_AK1::Algebraic_1 - Algebraic_real_1; - typedef size_t size_type; - typedef unsigned Multiplicity_type; - - // default constructor and destructor - public: - Algebraic_kernel_1(){}; - ~Algebraic_kernel_1(){}; - - // functors from the CGAL concept - public: - typedef CGAL::RS_AK1::Construct_algebraic_real_1 - Construct_algebraic_real_1; - typedef CGAL::RS_AK1::Compute_polynomial_1 - Compute_polynomial_1; - typedef CGAL::RS_AK1::Isolate_1 - Isolate_1; - typedef typename Ptraits::Is_square_free Is_square_free_1; - typedef typename Ptraits::Make_square_free Make_square_free_1; - typedef typename Ptraits::Square_free_factorize - Square_free_factorize_1; - typedef CGAL::RS_AK1::Is_coprime_1 - Is_coprime_1; - typedef CGAL::RS_AK1::Make_coprime_1 - Make_coprime_1; - typedef CGAL::RS_AK1::Solve_1 - Solve_1; - typedef CGAL::RS_AK1::Number_of_solutions_1 - Number_of_solutions_1; - - typedef CGAL::RS_AK1::Sign_at_1 - Sign_at_1; - typedef CGAL::RS_AK1::Is_zero_at_1 - Is_zero_at_1; - typedef CGAL::RS_AK1::Compare_1 - Compare_1; - typedef CGAL::RS_AK1::Bound_between_1 - Bound_between_1; - typedef CGAL::RS_AK1::Approximate_absolute_1 - Approximate_absolute_1; - typedef CGAL::RS_AK1::Approximate_relative_1 - Approximate_relative_1; - -#define CREATE_FUNCTION_OBJECT(T,N) \ - T N##_object()const{return T();} - CREATE_FUNCTION_OBJECT(Construct_algebraic_real_1, - construct_algebraic_real_1) - CREATE_FUNCTION_OBJECT(Compute_polynomial_1, - compute_polynomial_1) - CREATE_FUNCTION_OBJECT(Isolate_1, - isolate_1) - CREATE_FUNCTION_OBJECT(Is_square_free_1, - is_square_free_1) - CREATE_FUNCTION_OBJECT(Make_square_free_1, - make_square_free_1) - CREATE_FUNCTION_OBJECT(Square_free_factorize_1, - square_free_factorize_1) - CREATE_FUNCTION_OBJECT(Is_coprime_1, - is_coprime_1) - CREATE_FUNCTION_OBJECT(Make_coprime_1, - make_coprime_1) - CREATE_FUNCTION_OBJECT(Solve_1, - solve_1) - CREATE_FUNCTION_OBJECT(Number_of_solutions_1, - number_of_solutions_1) - CREATE_FUNCTION_OBJECT(Sign_at_1, - sign_at_1) - CREATE_FUNCTION_OBJECT(Is_zero_at_1, - is_zero_at_1) - CREATE_FUNCTION_OBJECT(Compare_1, - compare_1) - CREATE_FUNCTION_OBJECT(Bound_between_1, - bound_between_1) - CREATE_FUNCTION_OBJECT(Approximate_absolute_1, - approximate_absolute_1) - CREATE_FUNCTION_OBJECT(Approximate_relative_1, - approximate_relative_1) -#undef CREATE_FUNCTION_OBJECT - -}; // class Algebraic_kernel_1 - -} // namespace RS_AK1 -} // namespace CGAL - -#endif // CGAL_RS_AK_1_H diff --git a/Algebraic_kernel_d/include/CGAL/RS/ak_z_1.h b/Algebraic_kernel_d/include/CGAL/RS/ak_z_1.h deleted file mode 100644 index c4e0406e8adb..000000000000 --- a/Algebraic_kernel_d/include/CGAL/RS/ak_z_1.h +++ /dev/null @@ -1,202 +0,0 @@ -// Copyright (c) 2006-2013 INRIA Nancy-Grand Est (France). All rights reserved. -// -// This file is part of CGAL (www.cgal.org) -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial -// -// Author: Luis Peñaranda - -#ifndef CGAL_RS_AK_Z_1_H -#define CGAL_RS_AK_Z_1_H - -#include // included only to define size_t -#include -#include "algebraic_z_1.h" -#include "comparator_1.h" -#include "signat_1.h" -#include "functors_z_1.h" - -// This file defines the "Z-algebraic kernel". This kind of kernel performs -// all the internal operations using an integer polynomial type (the name -// "Z" comes from there). For this, a converter functor (passed as a -// template parameter) is used, which converts the input polynomial to the -// integer representation. - -namespace CGAL{ -namespace RS_AK1{ - -template , - class ZPtraits_=CGAL::Polynomial_traits_d > -class Algebraic_kernel_z_1{ - public: - typedef ExtPolynomial_ Polynomial_1; - typedef IntPolynomial_ ZPolynomial_1; - typedef PolConverter_ PolConverter; - typedef typename Polynomial_1::NT Coefficient; - typedef Bound_ Bound; - private: - typedef Isolator_ Isolator; - typedef Refiner_ Refiner; - typedef Ptraits_ Ptraits; - typedef ZPtraits_ ZPtraits; - typedef CGAL::RS_AK1::Signat_1 - Signat; - typedef CGAL::RS_AK1::Simple_comparator_1 - Comparator; - public: - typedef CGAL::RS_AK1::Algebraic_z_1 - Algebraic_real_1; - typedef size_t size_type; - typedef unsigned Multiplicity_type; - - // default constructor and destructor - public: - Algebraic_kernel_z_1(){}; - ~Algebraic_kernel_z_1(){}; - - // functors from the CGAL concept - public: - typedef CGAL::RS_AK1::Construct_algebraic_real_z_1 - Construct_algebraic_real_1; - typedef CGAL::RS_AK1::Compute_polynomial_z_1 - Compute_polynomial_1; - typedef CGAL::RS_AK1::Isolate_z_1 - Isolate_1; - typedef typename Ptraits::Is_square_free Is_square_free_1; - typedef typename Ptraits::Make_square_free Make_square_free_1; - typedef typename Ptraits::Square_free_factorize Square_free_factorize_1; - typedef CGAL::RS_AK1::Is_coprime_z_1 - Is_coprime_1; - typedef CGAL::RS_AK1::Make_coprime_z_1 - Make_coprime_1; - typedef CGAL::RS_AK1::Solve_z_1 - Solve_1; - typedef CGAL::RS_AK1::Number_of_solutions_z_1 - Number_of_solutions_1; - - typedef CGAL::RS_AK1::Sign_at_z_1 - Sign_at_1; - typedef CGAL::RS_AK1::Is_zero_at_z_1 - Is_zero_at_1; - typedef CGAL::RS_AK1::Compare_z_1 - Compare_1; - typedef CGAL::RS_AK1::Bound_between_z_1 - Bound_between_1; - typedef CGAL::RS_AK1::Approximate_absolute_z_1 - Approximate_absolute_1; - typedef CGAL::RS_AK1::Approximate_relative_z_1 - Approximate_relative_1; - -#define CREATE_FUNCTION_OBJECT(T,N) \ - T N##_object()const{return T();} - CREATE_FUNCTION_OBJECT(Construct_algebraic_real_1, - construct_algebraic_real_1) - CREATE_FUNCTION_OBJECT(Compute_polynomial_1, - compute_polynomial_1) - CREATE_FUNCTION_OBJECT(Isolate_1, - isolate_1) - CREATE_FUNCTION_OBJECT(Is_square_free_1, - is_square_free_1) - CREATE_FUNCTION_OBJECT(Make_square_free_1, - make_square_free_1) - CREATE_FUNCTION_OBJECT(Square_free_factorize_1, - square_free_factorize_1) - CREATE_FUNCTION_OBJECT(Is_coprime_1, - is_coprime_1) - CREATE_FUNCTION_OBJECT(Make_coprime_1, - make_coprime_1) - CREATE_FUNCTION_OBJECT(Solve_1, - solve_1) - CREATE_FUNCTION_OBJECT(Number_of_solutions_1, - number_of_solutions_1) - CREATE_FUNCTION_OBJECT(Sign_at_1, - sign_at_1) - CREATE_FUNCTION_OBJECT(Is_zero_at_1, - is_zero_at_1) - CREATE_FUNCTION_OBJECT(Compare_1, - compare_1) - CREATE_FUNCTION_OBJECT(Bound_between_1, - bound_between_1) - CREATE_FUNCTION_OBJECT(Approximate_absolute_1, - approximate_absolute_1) - CREATE_FUNCTION_OBJECT(Approximate_relative_1, - approximate_relative_1) -#undef CREATE_FUNCTION_OBJECT - -}; // class Algebraic_kernel_z_1 - -} // namespace RS_AK1 -} // namespace CGAL - -#endif // CGAL_RS_AK_Z_1_H diff --git a/Algebraic_kernel_d/include/CGAL/RS/algebraic_1.h b/Algebraic_kernel_d/include/CGAL/RS/algebraic_1.h deleted file mode 100644 index cbbc66eb9cde..000000000000 --- a/Algebraic_kernel_d/include/CGAL/RS/algebraic_1.h +++ /dev/null @@ -1,353 +0,0 @@ -// Copyright (c) 2006-2013 INRIA Nancy-Grand Est (France). All rights reserved. -// -// This file is part of CGAL (www.cgal.org) -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial -// -// Author: Luis Peñaranda - -#ifndef CGAL_RS_ALGEBRAIC_1_H -#define CGAL_RS_ALGEBRAIC_1_H - -#include -#include -#include -#include - -namespace CGAL{ -namespace RS_AK1{ - -// This class represents the simplest algebraic number one can think about. -// One algebraic number is represented by the polynomial of which it is -// root and the two endpoints of an interval that contains it, and no other -// root. Polynomial type and bound type are the first two template -// parameters. -// -// The third template parameter is a refiner, a function object that -// receives the polynomial and the bounds defining an algebraic number and -// an integer p, and modifies the two bounds until the difference between -// the two bounds is less than x*2^(-p), where x is the value of the -// represented algebraic number. The signature of a refiner must be: -// void -// Refiner_()(const Polynomial_&,Bound_&,Bound_&,int p); -// -// The fourth template argument is a comparator, a function object that -// receives the polynomials and bounds defining two algebraic numbers and -// just compares them, returning a CGAL::Comparison_result. The signature -// of a comparator must be: -// CGAL::Comparison_result -// Comparator_()(const Polynomial_&,Bound_&,Bound_&, -// const Polynomial_&,Bound_&,Bound_&); -// The comparator can modify the bounds, with the condition that the -// algebraic numbers remain consistent (one and only one root on each -// interval). - -template -class Algebraic_1: -boost::totally_ordered, - double>{ - protected: - typedef Polynomial_ Polynomial; - typedef Bound_ Bound; - typedef Refiner_ Refiner; - typedef Comparator_ Comparator; - typedef Ptraits_ Ptraits; - typedef typename Ptraits::Coefficient_type Coefficient; - typedef typename Ptraits::Scale Scale; - typedef Algebraic_1 - Algebraic; - - Polynomial pol; - mutable Bound left,right; - - public: - Algebraic_1(){}; - Algebraic_1(const Polynomial &p, - const Bound &l, - const Bound &r):pol(p),left(l),right(r){ - CGAL_assertion(l<=r); - } - Algebraic_1(const Algebraic &a): - pol(a.pol),left(a.left),right(a.right){} - // XXX: This assumes that Gmpq is constructible from bound type and - // that polynomial coefficient type is constructible from mpz_t. - Algebraic_1(const Bound &b):left(b),right(b){ - typedef typename Ptraits::Shift shift; - Gmpq q(b); - pol=Coefficient(mpq_denref(q.mpq()))* - shift()(Polynomial(1),1,0)- - Coefficient(mpq_numref(q.mpq())); - CGAL_assertion(left==right&&left==b); - } - // XXX: This implementation assumes that the bound type is Gmpfr - // and that T can be exactly converted to Gmpq. This constructor - // can handle types such as int, unsigned and long. - template - Algebraic_1(const T &t){ - typedef typename Ptraits::Shift shift; - CGAL::Gmpq q(t); - pol=Coefficient(mpq_denref(q.mpq()))* - shift()(Polynomial(1),1,0)- - Coefficient(mpq_numref(q.mpq())); - left=Bound(t,std::round_toward_neg_infinity); - right=Bound(t,std::round_toward_infinity); - CGAL_assertion(left<=t&&right>=t); - } - // XXX: This constructor assumes the bound is a Gmpfr. - Algebraic_1(const CGAL::Gmpq &q){ - typedef typename Ptraits::Shift shift; - pol=Coefficient(mpq_denref(q.mpq()))* - shift()(Polynomial(1),1,0)- - Coefficient(mpq_numref(q.mpq())); - left=Bound(); - right=Bound(); - mpfr_t b; - mpfr_init(b); - mpfr_set_q(b,q.mpq(),GMP_RNDD); - mpfr_swap(b,left.fr()); - mpfr_set_q(b,q.mpq(),GMP_RNDU); - mpfr_swap(b,right.fr()); - mpfr_clear(b); - CGAL_assertion(left<=q&&right>=q); - } - ~Algebraic_1(){} - - Algebraic_1& operator=(const Algebraic &a){ - pol=a.get_pol(); - left=a.get_left(); - right=a.get_right(); - return *this; - } - - Polynomial get_pol()const{return pol;} - Bound& get_left()const{return left;} - Bound& get_right()const{return right;} - - Algebraic operator-()const{ - return Algebraic(Scale()(get_pol(),Coefficient(-1)), - -right, - -left); - } - -#define CGAL_RS_COMPARE_ALGEBRAIC(_a) \ - (Comparator()(get_pol(),get_left(),get_right(), \ - (_a).get_pol(),(_a).get_left(),(_a).get_right())) - - Comparison_result compare(Algebraic a)const{ - return CGAL_RS_COMPARE_ALGEBRAIC(a); - }; - -#define CGAL_RS_COMPARE_ALGEBRAIC_TYPE(_t) \ - bool operator<(_t t)const \ - {Algebraic a(t);return CGAL_RS_COMPARE_ALGEBRAIC(a)==CGAL::SMALLER;} \ - bool operator>(_t t)const \ - {Algebraic a(t);return CGAL_RS_COMPARE_ALGEBRAIC(a)==CGAL::LARGER;} \ - bool operator==(_t t)const \ - {Algebraic a(t);return CGAL_RS_COMPARE_ALGEBRAIC(a)==CGAL::EQUAL;} - - bool operator==(Algebraic a)const - {return CGAL_RS_COMPARE_ALGEBRAIC(a)==CGAL::EQUAL;} - bool operator!=(Algebraic a)const - {return CGAL_RS_COMPARE_ALGEBRAIC(a)!=CGAL::EQUAL;} - bool operator<(Algebraic a)const - {return CGAL_RS_COMPARE_ALGEBRAIC(a)==CGAL::SMALLER;} - bool operator<=(Algebraic a)const - {return CGAL_RS_COMPARE_ALGEBRAIC(a)!=CGAL::LARGER;} - bool operator>(Algebraic a)const - {return CGAL_RS_COMPARE_ALGEBRAIC(a)==CGAL::LARGER;} - bool operator>=(Algebraic a)const - {return CGAL_RS_COMPARE_ALGEBRAIC(a)!=CGAL::SMALLER;} - - CGAL_RS_COMPARE_ALGEBRAIC_TYPE(double) - -#undef CGAL_RS_COMPARE_ALGEBRAIC_TYPE -#undef CGAL_RS_COMPARE_ALGEBRAIC - -#ifdef IEEE_DBL_MANT_DIG -#define CGAL_RS_DBL_PREC IEEE_DBL_MANT_DIG -#else -#define CGAL_RS_DBL_PREC 53 -#endif - // This function is const because left and right are mutable. - double to_double()const{ - typedef Real_embeddable_traits RT; - typedef typename RT::To_double TD; - Refiner()(pol,left,right,CGAL_RS_DBL_PREC); - CGAL_assertion(TD()(left)==TD()(right)); - return TD()(left); - } - std::pair to_interval()const{ - typedef Real_embeddable_traits RT; - typedef typename RT::To_interval TI; - return std::make_pair(TI()(get_left()).first, - TI()(get_right()).second); - } -#undef CGAL_RS_DBL_PREC - - void set_left(const Bound &l)const{ - left=l; - } - void set_right(const Bound &r)const{ - right=r; - } - void set_pol(const Polynomial &p){ - pol=p; - } - -}; // class Algebraic_1 - -} // namespace RS_AK1 - -// We define Algebraic_1 as real-embeddable -template -class Real_embeddable_traits >: -public INTERN_RET::Real_embeddable_traits_base< - RS_AK1::Algebraic_1, - CGAL::Tag_true>{ - typedef Polynomial_ P; - typedef Bound_ B; - typedef Refiner_ R; - typedef Comparator_ C; - typedef Ptraits_ T; - - public: - - typedef RS_AK1::Algebraic_1 Type; - typedef CGAL::Tag_true Is_real_embeddable; - typedef bool Boolean; - typedef CGAL::Sign Sign; - typedef CGAL::Comparison_result Comparison_result; - - typedef INTERN_RET::Real_embeddable_traits_base - Base; - typedef typename Base::Compare Compare; - - class Sgn:public CGAL::cpp98::unary_function{ - public: - CGAL::Sign operator()(const Type &a)const{ - return Compare()(a,Type(0)); - } - }; - - class To_double:public CGAL::cpp98::unary_function{ - public: - double operator()(const Type &a)const{return a.to_double();} - }; - - class To_interval: - public CGAL::cpp98::unary_function >{ - public: - std::pair operator()(const Type &a)const{ - return a.to_interval(); - } - }; - - class Is_zero:public CGAL::cpp98::unary_function{ - public: - bool operator()(const Type &a)const{ - return Sgn()(a)==CGAL::ZERO; - } - }; - - class Is_finite:public CGAL::cpp98::unary_function{ - public: - bool operator()(const Type&)const{return true;} - }; - - class Abs:public CGAL::cpp98::unary_function{ - public: - Type operator()(const Type &a)const{ - return Sgn()(a)==CGAL::NEGATIVE?-a:a; - } - }; -}; - -template -inline -RS_AK1::Algebraic_1 min -BOOST_PREVENT_MACRO_SUBSTITUTION(RS_AK1::Algebraic_1 a, - RS_AK1::Algebraic_1 b){ - return(a -inline -RS_AK1::Algebraic_1 max -BOOST_PREVENT_MACRO_SUBSTITUTION(RS_AK1::Algebraic_1 a, - RS_AK1::Algebraic_1 b){ - return(a>b?a:b); -} - -template -inline -std::ostream& operator<<(std::ostream &o, - const RS_AK1::Algebraic_1 &a){ - return(o<<'['< -inline -std::istream& operator>>(std::istream &i, - RS_AK1::Algebraic_1 &a){ - std::istream::int_type c; - P pol; - B lb,rb; - c=i.get(); - if(c!='['){ - CGAL_error_msg("error reading istream, \'[\' expected"); - return i; - } - i>>pol; - c=i.get(); - if(c!=','){ - CGAL_error_msg("error reading istream, \',\' expected"); - return i; - } - i>>lb; - c=i.get(); - if(c!=','){ - CGAL_error_msg("error reading istream, \',\' expected"); - return i; - } - i>>rb; - c=i.get(); - if(c!=']'){ - CGAL_error_msg("error reading istream, \']\' expected"); - return i; - } - a=RS_AK1::Algebraic_1(pol,lb,rb); - return i; -} - -} // namespace CGAL - -#endif // CGAL_RS_ALGEBRAIC_1_H diff --git a/Algebraic_kernel_d/include/CGAL/RS/algebraic_z_1.h b/Algebraic_kernel_d/include/CGAL/RS/algebraic_z_1.h deleted file mode 100644 index 1b0e3b0f081a..000000000000 --- a/Algebraic_kernel_d/include/CGAL/RS/algebraic_z_1.h +++ /dev/null @@ -1,351 +0,0 @@ -// Copyright (c) 2006-2013 INRIA Nancy-Grand Est (France). All rights reserved. -// -// This file is part of CGAL (www.cgal.org) -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial -// -// Author: Luis Peñaranda - -#ifndef CGAL_RS_ALGEBRAIC_Z_1_H -#define CGAL_RS_ALGEBRAIC_Z_1_H - -#include "algebraic_1.h" - -namespace CGAL{ -namespace RS_AK1{ - -// This class represents an algebraic number storing two polynomials of -// which it is root: one of them is the given polynomial; the other one is -// an integer polynomial, which is used to perform the operations such as -// refinements. Since RS works only with integer polynomials, this -// architecture permits to convert the input polynomials only once. - -template -class Algebraic_z_1: -public Algebraic_1, -boost::totally_ordered, - double>{ - protected: - typedef Polynomial_ Polynomial; - typedef ZPolynomial_ ZPolynomial; - typedef Bound_ Bound; - typedef ZRefiner_ ZRefiner; - typedef ZComparator_ ZComparator; - typedef ZPtraits_ ZPtraits; - typedef typename ZPtraits::Coefficient_type ZCoefficient; - typedef typename ZPtraits::Scale ZScale; - typedef Ptraits_ Ptraits; - typedef typename Ptraits::Coefficient_type Coefficient; - typedef typename Ptraits::Scale Scale; - typedef Algebraic_1 - Algebraic_base; - typedef Algebraic_z_1 - Algebraic; - ZPolynomial zpol; - - public: - Algebraic_z_1(){}; - Algebraic_z_1(const Polynomial &p, - const ZPolynomial &zp, - const Bound &l, - const Bound &r):Algebraic_base(p,l,r),zpol(zp){ - CGAL_assertion(l<=r); - } - Algebraic_z_1(const Algebraic &a): - Algebraic_base(a.pol,a.left,a.right),zpol(a.zpol){} - Algebraic_z_1(const Bound &b){ - typedef typename Ptraits::Shift Shift; - typedef typename ZPtraits::Shift ZShift; - this->left=b; - this->right=b; - Gmpq q(b); - this->pol=Coefficient(mpq_denref(q.mpq()))* - Shift()(Polynomial(1),1,0)- - Coefficient(mpq_numref(q.mpq())); - zpol=ZCoefficient(mpq_denref(q.mpq()))* - ZShift()(ZPolynomial(1),1,0)- - ZCoefficient(mpq_numref(q.mpq())); - CGAL_assertion(this->left==this->right); - CGAL_assertion(this->left==b); - } - template - Algebraic_z_1(const T &t){ - typedef typename Ptraits::Shift Shift; - typedef typename ZPtraits::Shift ZShift; - CGAL::Gmpq q(t); - this->pol=Coefficient(mpq_denref(q.mpq()))* - Shift()(Polynomial(1),1,0)- - Coefficient(mpq_numref(q.mpq())); - zpol=ZCoefficient(mpq_denref(q.mpq()))* - ZShift()(ZPolynomial(1),1,0)- - ZCoefficient(mpq_numref(q.mpq())); - this->left=Bound(t,std::round_toward_neg_infinity); - this->right=Bound(t,std::round_toward_infinity); - CGAL_assertion(this->left<=t&&this->right>=t); - } - Algebraic_z_1(const CGAL::Gmpq &q){ - typedef typename Ptraits::Shift Shift; - typedef typename ZPtraits::Shift ZShift; - this->pol=Coefficient(mpq_denref(q.mpq()))* - Shift()(Polynomial(1),1,0)- - Coefficient(mpq_numref(q.mpq())); - zpol=ZCoefficient(mpq_denref(q.mpq()))* - ZShift()(ZPolynomial(1),1,0)- - ZCoefficient(mpq_numref(q.mpq())); - this->left=Bound(); - this->right=Bound(); - mpfr_t b; - mpfr_init(b); - mpfr_set_q(b,q.mpq(),GMP_RNDD); - mpfr_swap(b,this->left.fr()); - mpfr_set_q(b,q.mpq(),GMP_RNDU); - mpfr_swap(b,this->right.fr()); - mpfr_clear(b); - CGAL_assertion(this->left<=q&&this->right>=q); - } - ~Algebraic_z_1(){} - - ZPolynomial get_zpol()const{return zpol;} - void set_zpol(const ZPolynomial &p){zpol=p;} - - Algebraic operator-()const{ - return Algebraic(Scale()(this->get_pol(),Coefficient(-1)), - ZScale()(get_zpol(),ZCoefficient(-1)), - -this->right, - -this->left); - } - -#define CGAL_RS_COMPARE_ALGEBRAIC_Z(_a) \ - (ZComparator()(get_zpol(),this->get_left(),this->get_right(), \ - (_a).get_zpol(),(_a).get_left(),(_a).get_right())) - - Comparison_result compare(Algebraic a)const{ - return CGAL_RS_COMPARE_ALGEBRAIC_Z(a); - }; - -#define CGAL_RS_COMPARE_ALGEBRAIC_Z_TYPE(_t) \ - bool operator<(_t t)const \ - {Algebraic a(t);return CGAL_RS_COMPARE_ALGEBRAIC_Z(a)==CGAL::SMALLER;} \ - bool operator>(_t t)const \ - {Algebraic a(t);return CGAL_RS_COMPARE_ALGEBRAIC_Z(a)==CGAL::LARGER;} \ - bool operator==(_t t)const \ - {Algebraic a(t);return CGAL_RS_COMPARE_ALGEBRAIC_Z(a)==CGAL::EQUAL;} - - bool operator==(Algebraic a)const - {return CGAL_RS_COMPARE_ALGEBRAIC_Z(a)==CGAL::EQUAL;} - bool operator!=(Algebraic a)const - {return CGAL_RS_COMPARE_ALGEBRAIC_Z(a)!=CGAL::EQUAL;} - bool operator<(Algebraic a)const - {return CGAL_RS_COMPARE_ALGEBRAIC_Z(a)==CGAL::SMALLER;} - bool operator<=(Algebraic a)const - {return CGAL_RS_COMPARE_ALGEBRAIC_Z(a)!=CGAL::LARGER;} - bool operator>(Algebraic a)const - {return CGAL_RS_COMPARE_ALGEBRAIC_Z(a)==CGAL::LARGER;} - bool operator>=(Algebraic a)const - {return CGAL_RS_COMPARE_ALGEBRAIC_Z(a)!=CGAL::SMALLER;} - - CGAL_RS_COMPARE_ALGEBRAIC_Z_TYPE(double) - -#undef CGAL_RS_COMPARE_ALGEBRAIC_Z_TYPE -#undef CGAL_RS_COMPARE_ALGEBRAIC_Z - -#ifdef IEEE_DBL_MANT_DIG -#define CGAL_RS_DBL_PREC IEEE_DBL_MANT_DIG -#else -#define CGAL_RS_DBL_PREC 53 -#endif - double to_double()const{ - typedef Real_embeddable_traits RT; - typedef typename RT::To_double TD; - ZRefiner()(get_zpol(), - this->get_left(), - this->get_right(), - CGAL_RS_DBL_PREC); - CGAL_assertion(TD()(this->get_left())==TD()(this->get_right())); - return TD()(this->get_left()); - } - std::pair to_interval()const{ - typedef Real_embeddable_traits RT; - typedef typename RT::To_interval TI; - return std::make_pair(TI()(this->get_left()).first, - TI()(this->get_right()).second); - } -#undef CGAL_RS_DBL_PREC -}; // class Algebraic_z_1 - -} // namespace RS_AK1 - -// We define Algebraic_z_1 as real-embeddable -template -class Real_embeddable_traits >: -public INTERN_RET::Real_embeddable_traits_base< - RS_AK1::Algebraic_z_1, - CGAL::Tag_true>{ - typedef Polynomial_ P; - typedef ZPolynomial_ ZP; - typedef Bound_ B; - typedef ZRefiner_ R; - typedef ZComparator_ C; - typedef Ptraits_ T; - typedef ZPtraits_ ZT; - - public: - - typedef RS_AK1::Algebraic_z_1 Type; - typedef CGAL::Tag_true Is_real_embeddable; - typedef bool Boolean; - typedef CGAL::Sign Sign; - typedef CGAL::Comparison_result Comparison_result; - - typedef INTERN_RET::Real_embeddable_traits_base - Base; - typedef typename Base::Compare Compare; - - class Sgn:public CGAL::cpp98::unary_function{ - public: - CGAL::Sign operator()(const Type &a)const{ - return Compare()(a,Type(0)); - } - }; - - class To_double:public CGAL::cpp98::unary_function{ - public: - double operator()(const Type &a)const{return a.to_double();} - }; - - class To_interval: - public CGAL::cpp98::unary_function >{ - public: - std::pair operator()(const Type &a)const{ - return a.to_interval(); - } - }; - - class Is_zero:public CGAL::cpp98::unary_function{ - public: - bool operator()(const Type &a)const{ - return Sgn()(a)==CGAL::ZERO; - } - }; - - class Is_finite:public CGAL::cpp98::unary_function{ - public: - bool operator()(const Type&)const{return true;} - }; - - class Abs:public CGAL::cpp98::unary_function{ - public: - Type operator()(const Type &a)const{ - return Sgn()(a)==CGAL::NEGATIVE?-a:a; - } - }; -}; - -template -inline -RS_AK1::Algebraic_z_1 min -BOOST_PREVENT_MACRO_SUBSTITUTION(RS_AK1::Algebraic_z_1 a, - RS_AK1::Algebraic_z_1 b){ - return(a -inline -RS_AK1::Algebraic_z_1 max -BOOST_PREVENT_MACRO_SUBSTITUTION(RS_AK1::Algebraic_z_1 a, - RS_AK1::Algebraic_z_1 b){ - return(a>b?a:b); -} - -template -inline -std::ostream& operator<<(std::ostream &o, - const RS_AK1::Algebraic_z_1 &a){ - return(o<<'['< -inline -std::istream& operator>>(std::istream &i, - RS_AK1::Algebraic_z_1 &a){ - std::istream::int_type c; - P pol; - ZP zpol; - B lb,rb; - c=i.get(); - if(c!='['){ - CGAL_error_msg("error reading istream, \'[\' expected"); - return i; - } - i>>pol; - c=i.get(); - if(c!=','){ - CGAL_error_msg("error reading istream, \',\' expected"); - return i; - } - i>>zpol; - c=i.get(); - if(c!=','){ - CGAL_error_msg("error reading istream, \',\' expected"); - return i; - } - i>>lb; - c=i.get(); - if(c!=','){ - CGAL_error_msg("error reading istream, \',\' expected"); - return i; - } - i>>rb; - c=i.get(); - if(c!=']'){ - CGAL_error_msg("error reading istream, \']\' expected"); - return i; - } - a=RS_AK1::Algebraic_z_1(pol,zpol,lb,rb); - return i; -} - -} // namespace CGAL - -#endif // CGAL_RS_ALGEBRAIC_Z_1_H diff --git a/Algebraic_kernel_d/include/CGAL/RS/bisection_refiner_1.h b/Algebraic_kernel_d/include/CGAL/RS/bisection_refiner_1.h deleted file mode 100644 index 28c655a8314e..000000000000 --- a/Algebraic_kernel_d/include/CGAL/RS/bisection_refiner_1.h +++ /dev/null @@ -1,165 +0,0 @@ -// Copyright (c) 2006-2013 INRIA Nancy-Grand Est (France). All rights reserved. -// -// This file is part of CGAL (www.cgal.org) -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial -// -// Author: Luis Peñaranda - -// This file contains the simplest refiner, that bisects the interval a given -// number of times. - -#ifndef CGAL_RS_BISECTION_REFINER_1_H -#define CGAL_RS_BISECTION_REFINER_1_H - -#include -#include "signat_1.h" -#include "Gmpfr_make_unique.h" - -namespace CGAL{ - -template -struct Bisection_refiner_1{ - typedef CGAL::RS_AK1::Signat_1 Signat; - void operator()(const Polynomial_&,Bound_&,Bound_&,int); -}; // class Bisection_refiner_1 - -// TODO: Write in a generic way, if possible (see next function). -template -void -Bisection_refiner_1:: -operator()(const Polynomial_&,Bound_&,Bound_&,int){ - CGAL_error_msg("bisection refiner not implemented for these types"); - return; -} - -// This works with any type of polynomial, but only for Gmpfr bounds. -// TODO: Beyond writing generically, optimize this function. This would -// remove the need for the next function, which is essentially the same. -template<> -void -Bisection_refiner_1,Gmpfr>:: -operator()(const Polynomial &pol,Gmpfr &left,Gmpfr &right,int prec){ - typedef Polynomial Polynomial; - typedef Polynomial_traits_d Ptraits; - typedef Ptraits::Make_square_free Sfpart; - typedef CGAL::RS_AK1::Signat_1 - Signat; - CGAL_precondition(left<=right); - //std::cout<<"refining ["<pc?pl:pc)+(mp_prec_t)prec; - mpfr_init2(center,pc); - CGAL_assertion_code(int round=) - mpfr_prec_round(left.fr(),pc,GMP_RNDN); - CGAL_assertion(!round); - CGAL_assertion_code(round=) - mpfr_prec_round(right.fr(),pc,GMP_RNDN); - CGAL_assertion(!round); - for(int i=0;i -void -Bisection_refiner_1,Gmpfr>:: -operator()(const Polynomial &pol,Gmpfr &left,Gmpfr &right,int prec){ - typedef Polynomial Polynomial; - typedef Polynomial_traits_d Ptraits; - typedef Ptraits::Make_square_free Sfpart; - typedef CGAL::RS_AK1::Signat_1 - Signat; - CGAL_precondition(left<=right); - //std::cout<<"refining ["<pc?pl:pc)+(mp_prec_t)prec; - mpfr_init2(center,pc); - CGAL_assertion_code(int round=) - mpfr_prec_round(left.fr(),pc,GMP_RNDN); - CGAL_assertion(!round); - CGAL_assertion_code(round=) - mpfr_prec_round(right.fr(),pc,GMP_RNDN); - CGAL_assertion(!round); - for(int i=0;i - -#ifndef CGAL_RS_COMPARATOR_1_H -#define CGAL_RS_COMPARATOR_1_H - -namespace CGAL{ -namespace RS_AK1{ - -template -struct Simple_comparator_1{ - typedef Polynomial_ Polynomial; - typedef Bound_ Bound; - typedef Refiner_ Refiner; - typedef Signat_ Signat; - typedef Ptraits_ Ptraits; - typedef typename Ptraits::Gcd_up_to_constant_factor Gcd; - typedef typename Ptraits::Degree Degree; - - CGAL::Comparison_result - operator()(const Polynomial &p1,Bound &l1,Bound &r1, - const Polynomial &p2,Bound &l2,Bound &r2)const{ - CGAL_precondition(l1<=r1&&l2<=r2); - if(l1<=l2){ - if(r1l2?l1:l2); - if(sleft==ZERO) - return EQUAL; - CGAL::Sign sright=sg(r1=l2:r2>=l1); - return (r1 - -#ifndef CGAL_RS_DYADIC_H -#define CGAL_RS_DYADIC_H - -#include -#include -#include -#include -#include - -// for c++, compile with -lgmpxx -#ifdef __cplusplus -#include -#endif - -#define CGALRS_dyadic_struct __mpfr_struct -#define CGALRS_dyadic_t mpfr_t -#define CGALRS_dyadic_ptr mpfr_ptr -#define CGALRS_dyadic_srcptr mpfr_srcptr - -// some auxiliary defines -#define CGALRS_dyadic_set_prec(D,P) \ - ( mpfr_set_prec( (D), (P)>MPFR_PREC_MIN?(P):MPFR_PREC_MIN) ) - -#define CGALRS_dyadic_prec_round(D,P) \ - ( mpfr_prec_round( (D), (P)>MPFR_PREC_MIN?(P):MPFR_PREC_MIN, GMP_RNDN) ) - -#define CGALRS_dyadic_set_exp(D,E) \ - ( CGAL_assertion( (E) <= mpfr_get_emax() && \ - (E) >= mpfr_get_emin() ) ,\ - mpfr_set_exp(D,E) ) - -// init functions -#define CGALRS_dyadic_init(D) mpfr_init2(D,MPFR_PREC_MIN) -#define CGALRS_dyadic_init2(D,P) mpfr_init2(D,P) -#define CGALRS_dyadic_clear(D) mpfr_clear(D) - -inline void CGALRS_dyadic_set(CGALRS_dyadic_ptr rop,CGALRS_dyadic_srcptr op){ - if(rop!=op){ - CGALRS_dyadic_set_prec(rop,mpfr_get_prec(op)); - mpfr_set(rop,op,GMP_RNDN); - } - CGAL_assertion(mpfr_equal_p(rop,op)!=0); -} - -inline void CGALRS_dyadic_set_z(CGALRS_dyadic_ptr rop,mpz_srcptr z){ - size_t prec; - prec=mpz_sizeinbase(z,2)-(mpz_tstbit(z,0)?0:mpz_scan1(z,0)); - CGALRS_dyadic_set_prec(rop,prec); - mpfr_set_z(rop,z,GMP_RNDN); - CGAL_assertion(!mpfr_cmp_z(rop,z)); -} - -inline void CGALRS_dyadic_set_si(CGALRS_dyadic_ptr rop,long s){ - CGALRS_dyadic_set_prec(rop,sizeof(long)); - mpfr_set_si(rop,s,GMP_RNDN); - CGAL_assertion(!mpfr_cmp_si(rop,s)); -} - -inline void CGALRS_dyadic_set_ui(CGALRS_dyadic_ptr rop,unsigned long u){ - CGALRS_dyadic_set_prec(rop,sizeof(unsigned long)); - mpfr_set_ui(rop,u,GMP_RNDN); - CGAL_assertion(!mpfr_cmp_ui(rop,u)); -} - -inline void CGALRS_dyadic_set_fr(CGALRS_dyadic_ptr rop,mpfr_srcptr op){ - if(rop!=op){ - CGALRS_dyadic_set_prec(rop,mpfr_get_prec(op)); - mpfr_set(rop,op,GMP_RNDN); - CGAL_assertion(mpfr_equal_p(rop,op)!=0); - } -} - -#define CGALRS_dyadic_init_set(R,D) \ - ( CGALRS_dyadic_init(R), CGALRS_dyadic_set((R), (D)) ) -#define CGALRS_dyadic_init_set_z(R,Z) \ - ( CGALRS_dyadic_init(R), CGALRS_dyadic_set_z((R), (Z)) ) -#define CGALRS_dyadic_init_set_si(R,I) \ - ( CGALRS_dyadic_init(R), CGALRS_dyadic_set_si((R), (I)) ) -#define CGALRS_dyadic_init_set_ui(R,I) \ - ( CGALRS_dyadic_init(R), CGALRS_dyadic_set_ui((R), (I)) ) -#define CGALRS_dyadic_init_set_fr(R,F) \ - ( CGALRS_dyadic_init(R), CGALRS_dyadic_set_fr((R), (F)) ) - -#define CGALRS_dyadic_get_fr(M,D) mpfr_set(M,D,GMP_RNDN) -#define CGALRS_dyadic_get_d(D,RM) mpfr_get_d(D,RM) -inline void CGALRS_dyadic_get_exactfr(mpfr_ptr rop,CGALRS_dyadic_srcptr op){ - if(rop!=op){ - CGALRS_dyadic_set_prec(rop,mpfr_get_prec(op)); - mpfr_set(rop,op,GMP_RNDN); - CGAL_assertion(mpfr_equal_p(rop,op)!=0); - } -} - -#define CGALRS_dyadic_canonicalize(D) () - -// comparison functions -#define CGALRS_dyadic_sgn(D) mpfr_sgn(D) -#define CGALRS_dyadic_zero(D) mpfr_zero_p(D) -#define CGALRS_dyadic_cmp(D,E) mpfr_cmp(D,E) - -// arithmetic functions -#define CGALRS_dyadic_add(R,D,E) CGALRS_dyadic_ll_add(R,D,E,0) -#define CGALRS_dyadic_sub(R,D,E) CGALRS_dyadic_ll_sub(R,D,E,0) -#define CGALRS_dyadic_mul(R,D,E) CGALRS_dyadic_ll_mul(R,D,E,0) - -inline void CGALRS_dyadic_neg(CGALRS_dyadic_ptr rop,CGALRS_dyadic_srcptr op){ - if(rop!=op) - CGALRS_dyadic_set_prec(rop,mpfr_get_prec(op)); - mpfr_neg(rop,op,GMP_RNDN); - CGAL_assertion( - rop==op|| - (!mpfr_cmpabs(rop,op)&& - ((CGALRS_dyadic_zero(op)&&CGALRS_dyadic_zero(rop))|| - (CGALRS_dyadic_sgn(op)!=CGALRS_dyadic_sgn(rop))))); -} - -// low-level addition: -// add op1 and op2 and reserve b bits for future lowlevel operations -inline void CGALRS_dyadic_ll_add(CGALRS_dyadic_ptr rop, - CGALRS_dyadic_srcptr op1, - CGALRS_dyadic_srcptr op2, - mp_prec_t b){ - mp_exp_t l,r,temp1,temp2; - mp_prec_t rop_prec; - if(mpfr_zero_p(op1)){ - if(rop!=op2) - CGALRS_dyadic_set(rop,op2); - return; - } - if(mpfr_zero_p(op2)){ - if(rop!=op1) - CGALRS_dyadic_set(rop,op1); - return; - } - l=mpfr_get_exp(op1)>mpfr_get_exp(op2)? - mpfr_get_exp(op1): - mpfr_get_exp(op2); - temp1=mpfr_get_exp(op1)-(mp_exp_t)mpfr_get_prec(op1); - temp2=mpfr_get_exp(op2)-(mp_exp_t)mpfr_get_prec(op2); - r=temp1>temp2?temp2:temp1; - CGAL_assertion(l>r); - - rop_prec=b+1+(mp_prec_t)(l-r); - CGAL_assertion(rop_prec>=mpfr_get_prec(op1)&& - rop_prec>=mpfr_get_prec(op2)); - if(rop==op1||rop==op2) - CGALRS_dyadic_prec_round(rop,rop_prec); - else - CGALRS_dyadic_set_prec(rop,rop_prec); - CGAL_assertion_code(int round=) - mpfr_add(rop,op1,op2,GMP_RNDN); - CGAL_assertion(!round); -} - -inline void CGALRS_dyadic_add_z(CGALRS_dyadic_ptr rop, - CGALRS_dyadic_srcptr op1, - mpz_srcptr z){ - mp_exp_t l,r; - mp_prec_t rop_prec; - if(mpfr_zero_p(op1)){ - CGALRS_dyadic_set_z(rop,z); - return; - } - if(!mpz_sgn(z)){ - if(rop!=op1) - CGALRS_dyadic_set(rop,op1); - return; - } - l=mpfr_get_exp(op1)>(mp_exp_t)mpz_sizeinbase(z,2)? - mpfr_get_exp(op1): - mpz_sizeinbase(z,2); - r=mpfr_get_exp(op1)-(mp_exp_t)mpfr_get_prec(op1)<0? - mpfr_get_exp(op1)-(mp_exp_t)mpfr_get_prec(op1): - 0; - CGAL_assertion(l>r); - - rop_prec=1+(mp_prec_t)(l-r); - CGAL_assertion(rop_prec>=mpfr_get_prec(op1)&& - rop_prec>=(mp_prec_t)mpz_sizeinbase(z,2)); - if(rop==op1) - CGALRS_dyadic_prec_round(rop,rop_prec); - else - CGALRS_dyadic_set_prec(rop,rop_prec); - CGAL_assertion_code(int round=) - mpfr_add_z(rop,op1,z,GMP_RNDN); - CGAL_assertion(!round); -} - -// low-level subtraction: -// subtract op2 to op1 and reserve b bits for future lowlevel operations -inline void CGALRS_dyadic_ll_sub(CGALRS_dyadic_ptr rop, - CGALRS_dyadic_srcptr op1, - CGALRS_dyadic_srcptr op2, - mp_prec_t b){ - mp_exp_t l,r,temp1,temp2; - mp_prec_t rop_prec; - if(mpfr_zero_p(op1)){ - CGALRS_dyadic_neg(rop,op2); - return; - } - if(mpfr_zero_p(op2)){ - if(rop!=op1) - CGALRS_dyadic_set(rop,op1); - return; - } - l=mpfr_get_exp(op1)>mpfr_get_exp(op2)? - mpfr_get_exp(op1): - mpfr_get_exp(op2); - temp1=mpfr_get_exp(op1)-(mp_exp_t)mpfr_get_prec(op1); - temp2=mpfr_get_exp(op2)-(mp_exp_t)mpfr_get_prec(op2); - r=temp1>temp2?temp2:temp1; - CGAL_assertion(l>r); - - rop_prec=b+1+(mp_prec_t)(l-r); - CGAL_assertion(rop_prec>=mpfr_get_prec(op1)&& - rop_prec>=mpfr_get_prec(op2)); - if(rop==op1||rop==op2) - CGALRS_dyadic_prec_round(rop,rop_prec); - else - CGALRS_dyadic_set_prec(rop,rop_prec); - CGAL_assertion_code(int round=) - mpfr_sub(rop,op1,op2,GMP_RNDN); - CGAL_assertion(!round); -} - -// low-level multiplication: -// multiply op1 and op2 and reserve b bits for future lowlevel operations -inline void CGALRS_dyadic_ll_mul(CGALRS_dyadic_ptr rop, - CGALRS_dyadic_srcptr op1, - CGALRS_dyadic_srcptr op2, - mp_prec_t b){ - if(rop==op1||rop==op2) - CGALRS_dyadic_prec_round(rop,b+mpfr_get_prec(op1)+mpfr_get_prec(op2)); - else - CGALRS_dyadic_set_prec(rop,b+mpfr_get_prec(op1)+mpfr_get_prec(op2)); - CGAL_assertion_code(int round=) - mpfr_mul(rop,op1,op2,GMP_RNDN); - CGAL_assertion(!round); -} - -inline void CGALRS_dyadic_mul_z(CGALRS_dyadic_ptr rop, - CGALRS_dyadic_srcptr op1, - mpz_srcptr z){ - if(rop==op1) - CGALRS_dyadic_prec_round( - rop, - mpfr_get_prec(op1)+mpz_sizeinbase(z,2)); - else - CGALRS_dyadic_set_prec( - rop, - mpfr_get_prec(op1)+mpz_sizeinbase(z,2)); - CGAL_assertion_code(int round=) - mpfr_mul_z(rop,op1,z,GMP_RNDN); - CGAL_assertion(!round); -} - -inline void CGALRS_dyadic_mul_si(CGALRS_dyadic_ptr rop, - CGALRS_dyadic_srcptr op1, - long s){ - if(rop==op1) - CGALRS_dyadic_prec_round(rop,mpfr_get_prec(op1)+sizeof(long)); - else - CGALRS_dyadic_set_prec(rop,mpfr_get_prec(op1)+sizeof(long)); - CGAL_assertion_code(int round=) - mpfr_mul_si(rop,op1,s,GMP_RNDN); - CGAL_assertion(!round); -} - -inline void CGALRS_dyadic_mul_ui(CGALRS_dyadic_ptr rop, - CGALRS_dyadic_srcptr op1, - unsigned long u){ - if(rop==op1) - CGALRS_dyadic_prec_round( - rop, - mpfr_get_prec(op1)+sizeof(unsigned long)); - else - CGALRS_dyadic_set_prec( - rop, - mpfr_get_prec(op1)+sizeof(unsigned long)); - CGAL_assertion_code(int round=) - mpfr_mul_ui(rop,op1,u,GMP_RNDN); - CGAL_assertion(!round); -} - -inline void CGALRS_dyadic_pow_ui(CGALRS_dyadic_ptr rop, - CGALRS_dyadic_srcptr op1, - unsigned long u){ - if(!u){ - CGAL_assertion_msg(!mpfr_zero_p(op1),"0^0"); - CGALRS_dyadic_set_ui(rop,1); - return; - } - if(u==1){ - if(rop!=op1) - CGALRS_dyadic_set(rop,op1); - return; - } - if(mpfr_zero_p(op1)){ - CGAL_assertion_msg(u!=0,"0^0"); - CGALRS_dyadic_set_ui(rop,0); - return; - } - if(!mpfr_cmp_ui(op1,1)){ - if(rop!=op1) - CGALRS_dyadic_set(rop,op1); - return; - } - if(rop==op1) - CGALRS_dyadic_prec_round(rop,u*mpfr_get_prec(op1)); - else - CGALRS_dyadic_set_prec(rop,u*mpfr_get_prec(op1)); - CGAL_assertion_code(int round=) - mpfr_pow_ui(rop,op1,u,GMP_RNDN); - CGAL_assertion(!round); -} - -inline void CGALRS_dyadic_addmul(CGALRS_dyadic_ptr rop, - CGALRS_dyadic_srcptr op1, - CGALRS_dyadic_srcptr op2){ - CGALRS_dyadic_t temp; - CGALRS_dyadic_init(temp); - CGALRS_dyadic_mul(temp,op1,op2); - CGALRS_dyadic_add(rop,rop,temp); - CGALRS_dyadic_clear(temp); -} - -inline void CGALRS_dyadic_addmul_si(CGALRS_dyadic_ptr rop, - CGALRS_dyadic_srcptr op1, - long op2){ - CGALRS_dyadic_t temp; - CGALRS_dyadic_init(temp); - CGALRS_dyadic_mul_si(temp,op1,op2); - CGALRS_dyadic_add(rop,rop,temp); - CGALRS_dyadic_clear(temp); -} - -inline void CGALRS_dyadic_addmul_ui(CGALRS_dyadic_ptr rop, - CGALRS_dyadic_srcptr op1, - unsigned long u){ - //CGALRS_dyadic_t temp; - //CGALRS_dyadic_init(temp); - //CGALRS_dyadic_mul_ui(temp,op1,u); - //CGALRS_dyadic_add(rop,rop,temp); - //CGALRS_dyadic_clear(temp); - CGALRS_dyadic_t temp; - mp_exp_t l,r,temp1,temp2; - mp_prec_t rop_prec; - if(u==0||mpfr_zero_p(op1)) - return; - if(u==1){ - CGALRS_dyadic_add(rop,rop,op1); - return; - } - // TODO: if(op1==1) - // calculate temp=op1*u - mpfr_init2(temp,mpfr_get_prec(op1)+sizeof(unsigned int)); - CGAL_assertion_code(int round1=) - mpfr_mul_ui(temp,op1,u,GMP_RNDN); - CGAL_assertion(!round1); - // calculate the precision needed for rop - l=mpfr_get_exp(op1)>0?mpfr_get_exp(op1):0; - temp1=mpfr_get_exp(op1)-(mp_exp_t)mpfr_get_prec(op1); - temp2=sizeof(unsigned long); - r=temp1>temp2?temp2:temp1; - CGAL_assertion(l>r); - rop_prec=sizeof(unsigned long)+1+(mp_prec_t)(l-r); - CGAL_assertion(rop_prec>=mpfr_get_prec(op1)&& - rop_prec>=mpfr_get_prec(rop)); - // set precision and add - CGALRS_dyadic_prec_round(rop,rop_prec); - CGAL_assertion_code(int round2=) - mpfr_add(rop,rop,temp,GMP_RNDN); - CGAL_assertion(!round2); -} - -inline void CGALRS_dyadic_mul_2exp(CGALRS_dyadic_ptr rop, - CGALRS_dyadic_srcptr op1, - unsigned long ui){ - // mpfr_mul_2ui does change the mantissa! - if(rop==op1) - CGALRS_dyadic_prec_round( - rop, - sizeof(unsigned long)+mpfr_get_prec(op1)); - else - CGALRS_dyadic_set_prec( - rop, - sizeof(unsigned long)+mpfr_get_prec(op1)); - CGAL_assertion_code(int round=) - mpfr_mul_2ui(rop,op1,ui,GMP_RNDN); - CGAL_assertion(!round); -} - -inline void CGALRS_dyadic_div_2exp(CGALRS_dyadic_ptr rop, - CGALRS_dyadic_srcptr op1, - unsigned long ui){ - // mpfr_div_2ui does not change the mantissa... am I sure? - CGAL_assertion_code(int round=) - mpfr_div_2ui(rop,op1,ui,GMP_RNDN); - CGAL_assertion(!round); -} - -// miscellaneous functions -#define CGALRS_dyadic_midpoint(R,D,E) \ - ( CGALRS_dyadic_ll_add(R,D,E,1) , mpfr_div_2ui(R,R,1,GMP_RNDN) ) -#define CGALRS_dyadic_swap(D,E) mpfr_swap(D,E) - -// I/O functions -#define CGALRS_dyadic_out_str(F,D) mpfr_out_str(F,10,0,D,GMP_RNDN) -#ifdef __cplusplus -inline std::ostream& operator<<(std::ostream &s,CGALRS_dyadic_srcptr op){ - mp_exp_t exponent; - mpz_t mantissa; - mpz_init(mantissa); - exponent=mpfr_get_z_exp(mantissa,op); - s<<"["< - -#ifndef CGAL_RS_EXACT_SIGNAT_1_H -#define CGAL_RS_EXACT_SIGNAT_1_H - -#include -#include "dyadic.h" - -namespace CGAL{ -namespace RS_AK1{ - -template -struct ExactSignat_1{ - typedef Polynomial_ Polynomial; - typedef Bound_ Bound; - typedef CGAL::Polynomial_traits_d PT; - typedef typename PT::Degree Degree; - Polynomial pol; - ExactSignat_1(const Polynomial &p):pol(p){}; - CGAL::Sign operator()(const Bound&)const; -}; // struct ExactSignat_1 - -template <> -inline CGAL::Sign -ExactSignat_1,Gmpfr>::operator()(const Gmpfr &x)const{ - int d=Degree()(pol); - if(d==0) - return pol[0].sign(); - // Construct a Gmpfr containing exactly the leading coefficient. - Gmpfr h(pol[d],pol[d].bit_size()); - CGAL_assertion(h==pol[d]); - // Horner's evaluation. - for(int i=1;i - -#ifndef CGAL_RS_FUNCTORS_1_H -#define CGAL_RS_FUNCTORS_1_H - -#include -#include - -namespace CGAL{ -namespace RS_AK1{ - -template -struct Construct_algebraic_real_1{ - typedef Polynomial_ Polynomial; - typedef Algebraic_ Algebraic; - typedef Bound_ Bound; - typedef Coefficient_ Coefficient; - typedef Isolator_ Isolator; - typedef Algebraic result_type; - - template - Algebraic operator()(const T &a)const{ - return Algebraic(a); - } - - Algebraic operator()(const Polynomial &p,size_t i)const{ - Isolator isol(p); - return Algebraic(p,isol.left_bound(i),isol.right_bound(i)); - } - - Algebraic operator()(const Polynomial &p, - const Bound &l, - const Bound &r)const{ - return Algebraic(p,l,r); - } - -}; // struct Construct_algebraic_1 - -template -struct Compute_polynomial_1: -public CGAL::cpp98::unary_function{ - typedef Polynomial_ Polynomial; - typedef Algebraic_ Algebraic; - Polynomial operator()(const Algebraic &x)const{ - return x.get_pol(); - } -}; // struct Compute_polynomial_1 - -template -struct Is_coprime_1: -public CGAL::cpp98::binary_function{ - typedef Polynomial_ Polynomial; - typedef Ptraits_ Ptraits; - typedef typename Ptraits::Gcd_up_to_constant_factor Gcd; - typedef typename Ptraits::Degree Degree; - inline bool operator()(const Polynomial &p1,const Polynomial &p2)const{ - return Degree()(Gcd()(p1,p2))==0; - } -}; // struct Is_coprime_1 - -template -struct Make_coprime_1{ - typedef Polynomial_ Polynomial; - typedef Ptraits_ Ptraits; - typedef typename Ptraits::Gcd_up_to_constant_factor Gcd; - typedef typename Ptraits::Degree Degree; - typedef typename Ptraits::Integral_division_up_to_constant_factor - IDiv; - bool operator()(const Polynomial &p1, - const Polynomial &p2, - Polynomial &g, - Polynomial &q1, - Polynomial &q2)const{ - g=Gcd()(p1,p2); - q1=IDiv()(p1,g); - q2=IDiv()(p2,g); - return Degree()(Gcd()(p1,p2))==0; - } -}; // struct Make_coprime_1 - -template -struct Solve_1{ - typedef Polynomial_ Polynomial_1; - typedef Bound_ Bound; - typedef Algebraic_ Algebraic; - typedef Isolator_ Isolator; - typedef Signat_ Signat; - typedef Ptraits_ Ptraits; - typedef typename Ptraits::Gcd_up_to_constant_factor Gcd; - typedef typename Ptraits::Square_free_factorize_up_to_constant_factor - Sqfr; - typedef typename Ptraits::Degree Degree; - typedef typename Ptraits::Make_square_free Sfpart; - - template - OutputIterator operator()(const Polynomial_1 &p, - OutputIterator res)const{ - typedef std::pair polmult; - typedef std::vector sqvec; - - Polynomial_1 sfp=Sfpart()(p); - sqvec sfv; - Sqfr()(p,std::back_inserter(sfv)); - Isolator isol(sfp); - int *m=(int*)calloc(isol.number_of_real_roots(),sizeof(int)); - for(typename sqvec::iterator i=sfv.begin();i!=sfv.end();++i){ - int k=Degree()(i->first); - Signat signof(i->first); - for(int j=0;k&&jsecond; - --k; - } - } - } - } - for(int l=0;l - OutputIterator operator()(const Polynomial_1 &p, - bool, - OutputIterator res)const{ - Isolator isol(p); - for(int l=0;l - OutputIterator operator()(const Polynomial_1 &p, - const Bound &l, - const Bound &u, - OutputIterator res)const{ - typedef std::vector RV; - typedef std::pair PM; - typedef std::vector PMV; - typedef typename PMV::iterator PMVI; - CGAL_precondition_msg(l<=u, - "left bound must be <= right bound"); - RV roots; // all roots of the polynomial - this->operator()(p,false,std::back_inserter(roots)); - size_t nb_roots=roots.size(); - // indices of the first and last roots to be reported: - size_t index_l=0,index_u; - while(index_l and match the - // roots in the interval [index_l,index_u) - for(PMVI i=sfv.begin();i!=sfv.end();++i){ - int k=Degree()(i->first); - Signat signof(i->first); - for(size_t j=index_l;k&&jsecond; - --k; - } - } - } - } - for(size_t l=index_l;l - OutputIterator operator()(const Polynomial_1 &p, - bool known_to_be_square_free, - const Bound &l, - const Bound &u, - OutputIterator res)const{ - typedef std::vector RV; - typedef typename RV::iterator RVI; - CGAL_precondition_msg(l<=u, - "left bound must be <= right bound"); - RV roots; - this->operator()(p, - known_to_be_square_free, - std::back_inserter(roots)); - for(RVI it=roots.begin();it!=roots.end();it++) - if(*it>=l&&*it<=u) - *res++=*it; - return res; - } - -}; // struct Solve_1 - -template -class Sign_at_1: -public CGAL::cpp98::binary_function{ - // This implementation will work with any polynomial type whose - // coefficient type is explicit interoperable with Gmpfi. - // TODO: Make this function generic. - public: - typedef Polynomial_ Polynomial_1; - typedef Bound_ Bound; - typedef Algebraic_ Algebraic; - typedef Refiner_ Refiner; - typedef Signat_ Signat; - typedef Ptraits_ Ptraits; - - private: - CGAL::Uncertain eval_interv(const Polynomial_1 &p, - const Bound &l, - const Bound &r)const{ - typedef typename Ptraits::Substitute Subst; - std::vector substitutions; - substitutions.push_back(CGAL::Gmpfi(l,r)); - CGAL::Gmpfi eval=Subst()(p, - substitutions.begin(), - substitutions.end()); - return eval.sign(); - } - - // This function assumes that the sign of the evaluation is not zero, - // it just refines x until having the correct sign. - CGAL::Sign refine_and_return(const Polynomial_1 &p,Algebraic x)const{ - CGAL::Gmpfr xl(x.get_left()); - CGAL::Gmpfr xr(x.get_right()); - CGAL::Uncertain s; - for(;;){ - Refiner()(x.get_pol(), - xl, - xr, - 2*CGAL::max(xl.get_precision(), - xr.get_precision())); - s=eval_interv(p,xl,xr); - if(!s.is_same(Uncertain::indeterminate())){ - x.set_left(xl); - x.set_right(xr); - return s; - } - } - } - - public: - CGAL::Sign operator()(const Polynomial_1 &p,Algebraic x)const{ - typedef typename Ptraits::Gcd_up_to_constant_factor Gcd; - typedef typename Ptraits::Make_square_free Sfpart; - typedef typename Ptraits::Degree Degree; - typedef typename Ptraits::Differentiate Deriv; - CGAL::Uncertain unknown= - Uncertain::indeterminate(); - CGAL::Uncertain s=eval_interv(p, - x.get_left(), - x.get_right()); - if(!s.is_same(unknown)) - return s; - // We are not sure about the sign. We calculate the gcd in - // order to know if both polynomials have common roots. - Polynomial_1 sfpp=Sfpart()(p); - Polynomial_1 gcd=Gcd()(sfpp,Sfpart()(x.get_pol())); - if(Degree()(gcd)==0) - return refine_and_return(p,x); - - // At this point, gcd is not 1; we proceed as follows: - // -we refine x until having p monotonic in x's interval (to be - // sure that p has at most one root on that interval), - // -if the gcd has a root on this interval, both roots are - // equal (we return 0), otherwise, we refine until having a - // result. - - // How to assure that p is monotonic in an interval: when its - // derivative is never zero in that interval. - Polynomial_1 dsfpp=Deriv()(sfpp); - CGAL::Gmpfr xl(x.get_left()); - CGAL::Gmpfr xr(x.get_right()); - while(eval_interv(dsfpp,xl,xr).is_same(unknown)){ - Refiner()(x.get_pol(), - xl, - xr, - 2*CGAL::max(xl.get_precision(), - xr.get_precision())); - } - x.set_left(xl); - x.set_right(xr); - - // How to know that the gcd has a root: evaluate endpoints. - CGAL::Sign sleft,sright; - Signat sign_at_gcd(gcd); - if((sleft=sign_at_gcd(x.get_left()))==CGAL::ZERO|| - (sright=sign_at_gcd(x.get_right()))==CGAL::ZERO|| - (sleft!=sright)) - return CGAL::ZERO; - return refine_and_return(p,x); - } -}; // struct Sign_at_1 - -template -class Is_zero_at_1: -public CGAL::cpp98::binary_function{ - // This implementation will work with any polynomial type whose - // coefficient type is explicit interoperable with Gmpfi. - // TODO: Make this function generic. - public: - typedef Polynomial_ Polynomial_1; - typedef Bound_ Bound; - typedef Algebraic_ Algebraic; - typedef Refiner_ Refiner; - typedef Signat_ Signat; - typedef Ptraits_ Ptraits; - - private: - CGAL::Uncertain eval_interv(const Polynomial_1 &p, - const Bound &l, - const Bound &r)const{ - typedef typename Ptraits::Substitute Subst; - std::vector substitutions; - substitutions.push_back(CGAL::Gmpfi(l,r)); - CGAL::Gmpfi eval=Subst()(p, - substitutions.begin(), - substitutions.end()); - return eval.sign(); - } - - public: - bool operator()(const Polynomial_1 &p,Algebraic x)const{ - typedef typename Ptraits::Gcd_up_to_constant_factor Gcd; - typedef typename Ptraits::Make_square_free Sfpart; - typedef typename Ptraits::Degree Degree; - typedef typename Ptraits::Differentiate Deriv; - CGAL::Uncertain unknown= - Uncertain::indeterminate(); - CGAL::Uncertain s=eval_interv(p, - x.get_left(), - x.get_right()); - if(!s.is_same(unknown)) - return (s==CGAL::ZERO); - // We are not sure about the sign. We calculate the gcd in - // order to know if both polynomials have common roots. - Polynomial_1 sfpp=Sfpart()(p); - Polynomial_1 gcd=Gcd()(sfpp,Sfpart()(x.get_pol())); - if(Degree()(gcd)==0) - return false; - - // At this point, gcd is not 1; we proceed as follows: - // -we refine x until having p monotonic in x's interval (to be - // sure that p has at most one root on that interval), - // -if the gcd has a root on this interval, both roots are - // equal (we return 0), otherwise, we refine until having a - // result. - - // How to assure that p is monotonic in an interval: when its - // derivative is never zero in that interval. - Polynomial_1 dsfpp=Deriv()(sfpp); - CGAL::Gmpfr xl(x.get_left()); - CGAL::Gmpfr xr(x.get_right()); - while(eval_interv(dsfpp,xl,xr).is_same(unknown)){ - Refiner()(x.get_pol(), - xl, - xr, - 2*CGAL::max(xl.get_precision(), - xr.get_precision())); - } - x.set_left(xl); - x.set_right(xr); - - // How to know that the gcd has a root: evaluate endpoints. - CGAL::Sign sleft,sright; - Signat sign_at_gcd(gcd); - return((sleft=sign_at_gcd(x.get_left()))==CGAL::ZERO|| - (sright=sign_at_gcd(x.get_right()))==CGAL::ZERO|| - (sleft!=sright)); - } -}; // class Is_zero_at_1 - -// TODO: it says in the manual that this should return a size_type, but test -// programs assume that this is equal to int -template -struct Number_of_solutions_1: -public CGAL::cpp98::unary_function{ - typedef Polynomial_ Polynomial_1; - typedef Isolator_ Isolator; - size_t operator()(const Polynomial_1 &p)const{ - // TODO: make sure that p is square free (precondition) - Isolator isol(p); - return isol.number_of_real_roots(); - } -}; // struct Number_of_solutions_1 - -// This functor not only compares two algebraic numbers. In case they are -// different, it refines them until they do not overlap. -template -struct Compare_1: -public CGAL::cpp98::binary_function{ - typedef Algebraic_ Algebraic; - typedef Bound_ Bound; - typedef Comparator_ Comparator; - - CGAL::Comparison_result operator()(Algebraic a,Algebraic b)const{ - Bound al=a.get_left(); - Bound ar=a.get_right(); - Bound bl=b.get_left(); - Bound br=b.get_right(); - CGAL::Comparison_result c=Comparator()(a.get_pol(),al,ar, - b.get_pol(),bl,br); - a.set_left(al); - a.set_right(ar); - b.set_left(bl); - b.set_right(br); - return c; - } - - CGAL::Comparison_result operator()(Algebraic a,const Bound &b)const{ - Bound al=a.get_left(); - Bound ar=a.get_right(); - Algebraic balg(b); - CGAL::Comparison_result c=Comparator()(a.get_pol(),al,ar, - balg.get_pol(),b,b); - a.set_left(al); - a.set_right(ar); - return c; - } - - template - CGAL::Comparison_result operator()(Algebraic a,const T &b)const{ - Bound al=a.get_left(); - Bound ar=a.get_right(); - Algebraic balg(b); - CGAL::Comparison_result c=Comparator()(a.get_pol(), - al, - ar, - balg.get_pol(), - balg.get_left(), - balg.get_right()); - a.set_left(al); - a.set_right(ar); - return c; - } - -}; // class Compare_1 - -template -struct Bound_between_1: -public CGAL::cpp98::binary_function{ - typedef Algebraic_ Algebraic; - typedef Bound_ Bound; - typedef Comparator_ Comparator; - - Bound operator()(Algebraic a,Algebraic b)const{ - typedef Compare_1 Compare; - typename Bound::Precision_type prec; - switch(Compare()(a,b)){ - case CGAL::LARGER: - CGAL_assertion(b.get_right() -struct Isolate_1: -public CGAL::cpp98::binary_function >{ - typedef Polynomial_ Polynomial_1; - typedef Bound_ Bound; - typedef Algebraic_ Algebraic; - typedef Isolator_ Isolator; - typedef Comparator_ Comparator; - typedef Signat_ Signat; - typedef Ptraits_ Ptraits; - - std::pair - operator()(const Algebraic &a,const Polynomial_1 &p)const{ - std::vector roots; - std::back_insert_iterator > rit(roots); - typedef Solve_1 Solve; - typedef Compare_1 Compare; - Solve()(p,false,rit); - for(typename std::vector::size_type i=0; - i -struct Approximate_absolute_1: -public CGAL::cpp98::binary_function >{ - typedef Polynomial_ Polynomial_1; - typedef Bound_ Bound; - typedef Algebraic_ Algebraic; - typedef Refiner_ Refiner; - - // This implementation assumes that Bound is Gmpfr. - // TODO: make generic. - std::pair operator()(const Algebraic &x,const int &a)const{ - Bound xl(x.get_left()),xr(x.get_right()); - // refsteps=log2(xl-xr) - mpfr_t temp; - mpfr_init(temp); - mpfr_sub(temp,xr.fr(),xl.fr(),GMP_RNDU); - mpfr_log2(temp,temp,GMP_RNDU); - long refsteps=mpfr_get_si(temp,GMP_RNDU); - mpfr_clear(temp); - Refiner()(x.get_pol(),xl,xr,CGAL::abs(refsteps+a)); - x.set_left(xl); - x.set_right(xr); - CGAL_assertion(a>0? - (xr-xl)*CGAL::ipower(Bound(2),a)<=Bound(1): - (xr-xl)<=CGAL::ipower(Bound(2),-a)); - return std::make_pair(xl,xr); - } -}; // struct Approximate_absolute_1 - -template -struct Approximate_relative_1: -public CGAL::cpp98::binary_function >{ - typedef Polynomial_ Polynomial_1; - typedef Bound_ Bound; - typedef Algebraic_ Algebraic; - typedef Refiner_ Refiner; - - std::pair operator()(const Algebraic &x,const int &a)const{ - if(CGAL::is_zero(x)) - return std::make_pair(Bound(0),Bound(0)); - Bound error=CGAL::ipower(Bound(2),CGAL::abs(a)); - Bound xl(x.get_left()),xr(x.get_right()); - Bound max_b=(CGAL::max)(CGAL::abs(xr),CGAL::abs(xl)); - while(a>0?(xr-xl)*error>max_b:(xr-xl)>error*max_b){ - Refiner()(x.get_pol(), - xl, - xr, - std::max( - CGAL::abs(a), - CGAL::max(xl.get_precision(), - xr.get_precision()))); - max_b=(CGAL::max)(CGAL::abs(xr),CGAL::abs(xl)); - } - x.set_left(xl); - x.set_right(xr); - CGAL_assertion( - a>0? - (xr-xl)*CGAL::ipower(Bound(2),a)<=max_b: - (xr-xl)<=CGAL::ipower(Bound(2),-a)*max_b); - return std::make_pair(xl,xr); - } -}; // struct Approximate_relative_1 - -} // namespace RS_AK1 -} // namespace CGAL - -#endif // CGAL_RS_FUNCTORS_1_H diff --git a/Algebraic_kernel_d/include/CGAL/RS/functors_z_1.h b/Algebraic_kernel_d/include/CGAL/RS/functors_z_1.h deleted file mode 100644 index 56961c92e4f0..000000000000 --- a/Algebraic_kernel_d/include/CGAL/RS/functors_z_1.h +++ /dev/null @@ -1,699 +0,0 @@ -// Copyright (c) 2006-2013 INRIA Nancy-Grand Est (France). All rights reserved. -// -// This file is part of CGAL (www.cgal.org) -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial -// -// Author: Luis Peñaranda - -#ifndef CGAL_RS_FUNCTORS_Z_1_H -#define CGAL_RS_FUNCTORS_Z_1_H - -#include -#include - -namespace CGAL{ -namespace RS_AK1{ - -template -struct Construct_algebraic_real_z_1{ - typedef Polynomial_ Polynomial; - typedef ZPolynomial_ ZPolynomial; - typedef PolConverter_ PolConverter; - typedef Algebraic_ Algebraic; - typedef Bound_ Bound; - typedef Coefficient_ Coefficient; - typedef Isolator_ Isolator; - typedef Algebraic result_type; - - template - Algebraic operator()(const T &a)const{ - return Algebraic(a); - } - - Algebraic operator()(const Polynomial &p,size_t i)const{ - ZPolynomial zp=PolConverter()(p); - Isolator isol(zp); - return Algebraic(p, - zp, - isol.left_bound(i), - isol.right_bound(i)); - } - - Algebraic operator()(const Polynomial &p, - const Bound &l, - const Bound &r)const{ - return Algebraic(p,PolConverter()(p),l,r); - } - -}; // struct Construct_algebraic_real_z_1 - -template -struct Compute_polynomial_z_1: -public CGAL::cpp98::unary_function{ - typedef Polynomial_ Polynomial; - typedef Algebraic_ Algebraic; - Polynomial operator()(const Algebraic &x)const{ - return x.get_pol(); - } -}; // struct Compute_polynomial_z_1 - -template -struct Is_coprime_z_1: -public CGAL::cpp98::binary_function{ - typedef Polynomial_ Polynomial; - typedef Ptraits_ Ptraits; - typedef typename Ptraits::Gcd_up_to_constant_factor Gcd; - typedef typename Ptraits::Degree Degree; - inline bool operator()(const Polynomial &p1,const Polynomial &p2)const{ - return Degree()(Gcd()(p1,p2))==0; - } -}; // struct Is_coprime_z_1 - -template -struct Make_coprime_z_1{ - typedef Polynomial_ Polynomial; - typedef Ptraits_ Ptraits; - typedef typename Ptraits::Gcd_up_to_constant_factor Gcd; - typedef typename Ptraits::Degree Degree; - typedef typename Ptraits::Integral_division_up_to_constant_factor - IDiv; - bool operator()(const Polynomial &p1, - const Polynomial &p2, - Polynomial &g, - Polynomial &q1, - Polynomial &q2)const{ - g=Gcd()(p1,p2); - q1=IDiv()(p1,g); - q2=IDiv()(p2,g); - return Degree()(Gcd()(p1,p2))==0; - } -}; // struct Make_coprime_z_1 - -template -struct Solve_z_1{ - typedef Polynomial_ Polynomial_1; - typedef ZPolynomial_ ZPolynomial_1; - typedef PolConverter_ PolConverter; - typedef Bound_ Bound; - typedef Algebraic_ Algebraic; - typedef Isolator_ Isolator; - typedef Signat_ ZSignat; - typedef Ptraits_ Ptraits; - typedef typename Ptraits::Gcd_up_to_constant_factor Gcd; - typedef typename Ptraits::Square_free_factorize_up_to_constant_factor - Sqfr; - typedef typename Ptraits::Degree Degree; - typedef typename Ptraits::Make_square_free Sfpart; - typedef ZPtraits_ ZPtraits; - typedef typename ZPtraits::Gcd_up_to_constant_factor ZGcd; - typedef typename ZPtraits::Square_free_factorize_up_to_constant_factor - ZSqfr; - typedef typename ZPtraits::Degree ZDegree; - typedef typename ZPtraits::Make_square_free ZSfpart; - - template - OutputIterator operator()(const Polynomial_1 &p, - OutputIterator res)const{ - typedef std::pair zpolmult; - typedef std::vector zsqvec; - - ZPolynomial_1 zp=PolConverter()(p); - Polynomial_1 sfp=Sfpart()(p); - ZPolynomial_1 zsfp=PolConverter()(sfp); - zsqvec zsfv; - ZSqfr()(zp,std::back_inserter(zsfv)); - Isolator isol(zsfp); - int *m=(int*)calloc(isol.number_of_real_roots(),sizeof(int)); - for(typename zsqvec::iterator i=zsfv.begin();i!=zsfv.end();++i){ - int k=ZDegree()(i->first); - ZSignat signof(i->first); - for(int j=0;k&&jsecond; - --k; - } - } - } - } - for(int l=0;l - OutputIterator operator()(const Polynomial_1 &p, - bool, - OutputIterator res)const{ - ZPolynomial_1 zp=PolConverter()(p); - Isolator isol(zp); - for(int l=0;l - OutputIterator operator()(const Polynomial_1 &p, - const Bound &l, - const Bound &u, - OutputIterator res)const{ - typedef std::vector RV; - typedef std::pair PM; - typedef std::vector PMV; - typedef typename PMV::iterator PMVI; - CGAL_precondition_msg(l<=u, - "left bound must be <= right bound"); - RV roots; // all roots of the polynomial - this->operator()(p,false,std::back_inserter(roots)); - size_t nb_roots=roots.size(); - // indices of the first and last roots to be reported: - size_t index_l=0,index_u; - while(index_l and match the - // roots in the interval [index_l,index_u) - for(PMVI i=sfv.begin();i!=sfv.end();++i){ - ZPolynomial_1 zifirst=PolConverter()(i->first); - int k=ZDegree()(zifirst); - ZSignat signof(zifirst); - for(size_t j=index_l;k&&jsecond; - --k; - } - } - } - } - for(size_t l=index_l;l - OutputIterator operator()(const Polynomial_1 &p, - bool known_to_be_square_free, - const Bound &l, - const Bound &u, - OutputIterator res)const{ - typedef std::vector RV; - typedef typename RV::iterator RVI; - CGAL_precondition_msg(l<=u, - "left bound must be <= right bound"); - RV roots; - this->operator()(p, - known_to_be_square_free, - std::back_inserter(roots)); - for(RVI it=roots.begin();it!=roots.end();it++) - if(*it>=l&&*it<=u) - *res++=*it; - return res; - } - -}; // struct Solve_z_1 - -template -class Sign_at_z_1: -public CGAL::cpp98::binary_function{ - // This implementation will work with any polynomial type whose - // coefficient type is explicit interoperable with Gmpfi. - // TODO: Make this function generic. - public: - typedef Polynomial_ Polynomial_1; - typedef ZPolynomial_ ZPolynomial_1; - typedef PolConverter_ PolConverter; - typedef Bound_ Bound; - typedef Algebraic_ Algebraic; - typedef Refiner_ Refiner; - typedef Signat_ ZSignat; - typedef Ptraits_ Ptraits; - typedef ZPtraits_ ZPtraits; - - private: - CGAL::Uncertain eval_interv(const Polynomial_1 &p, - const Bound &l, - const Bound &r)const{ - typedef typename Ptraits::Substitute Subst; - std::vector substitutions; - substitutions.push_back(CGAL::Gmpfi(l,r)); - CGAL::Gmpfi eval=Subst()(p, - substitutions.begin(), - substitutions.end()); - return eval.sign(); - } - - // This function assumes that the sign of the evaluation is not zero, - // it just refines x until having the correct sign. - CGAL::Sign refine_and_return(const Polynomial_1 &p,Algebraic x)const{ - CGAL::Gmpfr xl(x.get_left()); - CGAL::Gmpfr xr(x.get_right()); - CGAL::Uncertain s; - for(;;){ - Refiner()(x.get_zpol(), - xl, - xr, - 2*CGAL::max(xl.get_precision(), - xr.get_precision())); - s=eval_interv(p,xl,xr); - if(!s.is_same(Uncertain::indeterminate())){ - x.set_left(xl); - x.set_right(xr); - return s; - } - } - } - - public: - CGAL::Sign operator()(const Polynomial_1 &p,Algebraic x)const{ - typedef typename Ptraits::Gcd_up_to_constant_factor Gcd; - typedef typename Ptraits::Make_square_free Sfpart; - typedef typename Ptraits::Degree Degree; - typedef typename Ptraits::Differentiate Deriv; - CGAL::Uncertain unknown= - Uncertain::indeterminate(); - CGAL::Uncertain s=eval_interv(p, - x.get_left(), - x.get_right()); - if(!s.is_same(unknown)) - return s; - // We are not sure about the sign. We calculate the gcd in - // order to know if both polynomials have common roots. - Polynomial_1 sfpp=Sfpart()(p); - Polynomial_1 gcd=Gcd()(sfpp,Sfpart()(x.get_pol())); - if(Degree()(gcd)==0) - return refine_and_return(p,x); - - // At this point, gcd is not 1; we proceed as follows: - // -we refine x until having p monotonic in x's interval (to be - // sure that p has at most one root on that interval), - // -if the gcd has a root on this interval, both roots are - // equal (we return 0), otherwise, we refine until having a - // result. - - // How to assure that p is monotonic in an interval: when its - // derivative is never zero in that interval. - Polynomial_1 dsfpp=Deriv()(sfpp); - CGAL::Gmpfr xl(x.get_left()); - CGAL::Gmpfr xr(x.get_right()); - while(eval_interv(dsfpp,xl,xr).is_same(unknown)){ - Refiner()(x.get_zpol(), - xl, - xr, - 2*CGAL::max(xl.get_precision(), - xr.get_precision())); - } - x.set_left(xl); - x.set_right(xr); - - // How to know that the gcd has a root: evaluate endpoints. - CGAL::Sign sleft,sright; - ZSignat sign_at_gcd(PolConverter()(gcd)); - if((sleft=sign_at_gcd(x.get_left()))==CGAL::ZERO|| - (sright=sign_at_gcd(x.get_right()))==CGAL::ZERO|| - (sleft!=sright)) - return CGAL::ZERO; - return refine_and_return(p,x); - } -}; // struct Sign_at_z_1 - -template -class Is_zero_at_z_1: -public CGAL::cpp98::binary_function{ - // This implementation will work with any polynomial type whose - // coefficient type is explicit interoperable with Gmpfi. - // TODO: Make this function generic. - public: - typedef Polynomial_ Polynomial_1; - typedef ZPolynomial_ ZPolynomial_1; - typedef PolConverter_ PolConverter; - typedef Bound_ Bound; - typedef Algebraic_ Algebraic; - typedef Refiner_ Refiner; - typedef Signat_ ZSignat; - typedef Ptraits_ Ptraits; - typedef ZPtraits_ ZPtraits; - - private: - CGAL::Uncertain eval_interv(const Polynomial_1 &p, - const Bound &l, - const Bound &r)const{ - typedef typename Ptraits::Substitute Subst; - std::vector substitutions; - substitutions.push_back(CGAL::Gmpfi(l,r)); - CGAL::Gmpfi eval=Subst()(p, - substitutions.begin(), - substitutions.end()); - return eval.sign(); - } - - public: - bool operator()(const Polynomial_1 &p,Algebraic x)const{ - typedef typename Ptraits::Gcd_up_to_constant_factor Gcd; - typedef typename Ptraits::Make_square_free Sfpart; - typedef typename Ptraits::Degree Degree; - typedef typename Ptraits::Differentiate Deriv; - CGAL::Uncertain unknown= - Uncertain::indeterminate(); - CGAL::Uncertain s=eval_interv(p, - x.get_left(), - x.get_right()); - if(!s.is_same(unknown)) - return (s==CGAL::ZERO); - // We are not sure about the sign. We calculate the gcd in - // order to know if both polynomials have common roots. - Polynomial_1 sfpp=Sfpart()(p); - Polynomial_1 gcd=Gcd()(sfpp,Sfpart()(x.get_pol())); - if(Degree()(gcd)==0) - return false; - - // At this point, gcd is not 1; we proceed as follows: - // -we refine x until having p monotonic in x's interval (to be - // sure that p has at most one root on that interval), - // -if the gcd has a root on this interval, both roots are - // equal (we return 0), otherwise, we refine until having a - // result. - - // How to assure that p is monotonic in an interval: when its - // derivative is never zero in that interval. - Polynomial_1 dsfpp=Deriv()(sfpp); - CGAL::Gmpfr xl(x.get_left()); - CGAL::Gmpfr xr(x.get_right()); - while(eval_interv(dsfpp,xl,xr).is_same(unknown)){ - Refiner()(x.get_zpol(), - xl, - xr, - 2*CGAL::max(xl.get_precision(), - xr.get_precision())); - } - x.set_left(xl); - x.set_right(xr); - - // How to know that the gcd has a root: evaluate endpoints. - CGAL::Sign sleft,sright; - ZSignat sign_at_gcd(PolConverter()(gcd)); - return((sleft=sign_at_gcd(x.get_left()))==CGAL::ZERO|| - (sright=sign_at_gcd(x.get_right()))==CGAL::ZERO|| - (sleft!=sright)); - } -}; // class Is_zero_at_z_1 - -// TODO: it says in the manual that this should return a size_type, but test -// programs assume that this is equal to int -template -struct Number_of_solutions_z_1: -public CGAL::cpp98::unary_function{ - typedef Polynomial_ Polynomial_1; - typedef ZPolynomial_ ZPolynomial_1; - typedef PolConverter_ PolConverter; - typedef Isolator_ Isolator; - size_t operator()(const Polynomial_1 &p)const{ - // TODO: make sure that p is square free (precondition) - Isolator isol(PolConverter()(p)); - return isol.number_of_real_roots(); - } -}; // struct Number_of_solutions_z_1 - -// This functor not only compares two algebraic numbers. In case they are -// different, it refines them until they do not overlap. -template -struct Compare_z_1: -public CGAL::cpp98::binary_function{ - typedef Algebraic_ Algebraic; - typedef Bound_ Bound; - typedef Comparator_ Comparator; - - CGAL::Comparison_result operator()(Algebraic a,Algebraic b)const{ - Bound al=a.get_left(); - Bound ar=a.get_right(); - Bound bl=b.get_left(); - Bound br=b.get_right(); - CGAL::Comparison_result c=Comparator()(a.get_zpol(),al,ar, - b.get_zpol(),bl,br); - a.set_left(al); - a.set_right(ar); - b.set_left(bl); - b.set_right(br); - return c; - } - - CGAL::Comparison_result operator()(Algebraic a,const Bound &b)const{ - Bound al=a.get_left(); - Bound ar=a.get_right(); - Algebraic balg(b); - CGAL::Comparison_result c=Comparator()(a.get_zpol(),al,ar, - balg.get_zpol(),b,b); - a.set_left(al); - a.set_right(ar); - return c; - } - - template - CGAL::Comparison_result operator()(Algebraic a,const T &b)const{ - Bound al=a.get_left(); - Bound ar=a.get_right(); - Algebraic balg(b); - CGAL::Comparison_result c=Comparator()(a.get_zpol(), - al, - ar, - balg.get_zpol(), - balg.get_left(), - balg.get_right()); - a.set_left(al); - a.set_right(ar); - return c; - } - -}; // class Compare_z_1 - -template -struct Bound_between_z_1: -public CGAL::cpp98::binary_function{ - typedef Algebraic_ Algebraic; - typedef Bound_ Bound; - typedef Comparator_ Comparator; - - Bound operator()(Algebraic a,Algebraic b)const{ - typedef Compare_z_1 Compare; - typename Bound::Precision_type prec; - switch(Compare()(a,b)){ - case CGAL::LARGER: - CGAL_assertion(b.get_right() -struct Isolate_z_1: -public CGAL::cpp98::binary_function >{ - typedef Polynomial_ Polynomial_1; - typedef ZPolynomial_ ZPolynomial_1; - typedef PolConverter_ PolConverter; - typedef Bound_ Bound; - typedef Algebraic_ Algebraic; - typedef Isolator_ Isolator; - typedef Comparator_ Comparator; - typedef Signat_ Signat; - typedef Ptraits_ Ptraits; - typedef ZPtraits_ ZPtraits; - - std::pair - operator()(const Algebraic &a,const Polynomial_1 &p)const{ - std::vector roots; - std::back_insert_iterator > rit(roots); - typedef Solve_z_1 Solve; - typedef Compare_z_1 Compare; - Solve()(p,false,rit); - for(typename std::vector::size_type i=0; - i -struct Approximate_absolute_z_1: -public CGAL::cpp98::binary_function >{ - typedef Polynomial_ Polynomial_1; - typedef Bound_ Bound; - typedef Algebraic_ Algebraic; - typedef Refiner_ Refiner; - - // This implementation assumes that Bound is Gmpfr. - // TODO: make generic. - std::pair operator()(const Algebraic &x,const int &a)const{ - Bound xl(x.get_left()),xr(x.get_right()); - // refsteps=log2(xl-xr) - mpfr_t temp; - mpfr_init(temp); - mpfr_sub(temp,xr.fr(),xl.fr(),GMP_RNDU); - mpfr_log2(temp,temp,GMP_RNDU); - long refsteps=mpfr_get_si(temp,GMP_RNDU); - mpfr_clear(temp); - Refiner()(x.get_zpol(),xl,xr,CGAL::abs(refsteps+a)); - x.set_left(xl); - x.set_right(xr); - CGAL_assertion(a>0? - (xr-xl)*CGAL::ipower(Bound(2),a)<=Bound(1): - (xr-xl)<=CGAL::ipower(Bound(2),-a)); - return std::make_pair(xl,xr); - } -}; // struct Approximate_absolute_z_1 - -template -struct Approximate_relative_z_1: -public CGAL::cpp98::binary_function >{ - typedef Polynomial_ Polynomial_1; - typedef Bound_ Bound; - typedef Algebraic_ Algebraic; - typedef Refiner_ Refiner; - - std::pair operator()(const Algebraic &x,const int &a)const{ - if(CGAL::is_zero(x)) - return std::make_pair(Bound(0),Bound(0)); - Bound error=CGAL::ipower(Bound(2),CGAL::abs(a)); - Bound xl(x.get_left()),xr(x.get_right()); - Bound max_b=(CGAL::max)(CGAL::abs(xr),CGAL::abs(xl)); - while(a>0?(xr-xl)*error>max_b:(xr-xl)>error*max_b){ - Refiner()(x.get_zpol(), - xl, - xr, - std::max( - CGAL::abs(a), - CGAL::max(xl.get_precision(), - xr.get_precision()))); - max_b=(CGAL::max)(CGAL::abs(xr),CGAL::abs(xl)); - } - x.set_left(xl); - x.set_right(xr); - CGAL_assertion( - a>0? - (xr-xl)*CGAL::ipower(Bound(2),a)<=max_b: - (xr-xl)<=CGAL::ipower(Bound(2),-a)*max_b); - return std::make_pair(xl,xr); - } -}; // struct Approximate_relative_z_1 - -} // namespace RS_AK1 -} // namespace CGAL - -#endif // CGAL_RS_FUNCTORS_Z_1_H diff --git a/Algebraic_kernel_d/include/CGAL/RS/polynomial_converter_1.h b/Algebraic_kernel_d/include/CGAL/RS/polynomial_converter_1.h deleted file mode 100644 index 97da754f95dc..000000000000 --- a/Algebraic_kernel_d/include/CGAL/RS/polynomial_converter_1.h +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) 2006-2013 INRIA Nancy-Grand Est (France). All rights reserved. -// -// This file is part of CGAL (www.cgal.org) -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial -// -// Author: Luis Peñaranda - -#ifndef CGAL_RS_POLYNOMIAL_CONVERTER_1_H -#define CGAL_RS_POLYNOMIAL_CONVERTER_1_H - -namespace CGAL{ -namespace RS_AK1{ - -template -struct Polynomial_converter_1: -public CGAL::cpp98::unary_function{ - typedef InputPolynomial_ InpPolynomial_1; - typedef OutputPolynomial_ OutPolynomial_1; - OutPolynomial_1 operator()(const InpPolynomial_1&)const; -}; // class Polynomial_converter_1 - -template <> -Polynomial -Polynomial_converter_1,Polynomial >::operator()( - const Polynomial &p)const{ - std::vector outcoeffs; - unsigned degree=p.degree(); - mpz_t lcm; - mpz_init(lcm); - mpz_lcm(lcm,mpq_denref(p[0].mpq()),mpq_denref(p[degree].mpq())); - for(unsigned i=1;i(outcoeffs.begin(),outcoeffs.end()); -} - -} // namespace RS_AK1 -} // namespace CGAL - -#endif // CGAL_RS_POLYNOMIAL_CONVERTER_1_H diff --git a/Algebraic_kernel_d/include/CGAL/RS/rs23_k_isolator_1.h b/Algebraic_kernel_d/include/CGAL/RS/rs23_k_isolator_1.h deleted file mode 100644 index 5f9477290b1f..000000000000 --- a/Algebraic_kernel_d/include/CGAL/RS/rs23_k_isolator_1.h +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright (c) 2006-2013 INRIA Nancy-Grand Est (France). All rights reserved. -// -// This file is part of CGAL (www.cgal.org) -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial -// -// Author: Luis Peñaranda - -#ifndef CGAL_RS_RS23_K_ISOLATOR_1_H -#define CGAL_RS_RS23_K_ISOLATOR_1_H - -// This file includes an isolator. Its particularity is that is isolates the -// roots with RS2, and the refines them until reaching Kantorovich criterion. -// This can take long, but the later refinements will be extremely fast with -// RS3. The functor is not in RS2 neither in RS3 namespace, because it uses -// functions from both. - -#include "rs2_calls.h" -#include "rs3_k_refiner_1.h" -#include -#include - -namespace CGAL{ - -template -class RS23_k_isolator_1{ - public: - typedef Polynomial_ Polynomial; - typedef Bound_ Bound; - private: - typedef Gmpfi Interval; - public: - RS23_k_isolator_1(const Polynomial&); - Polynomial polynomial()const; - int number_of_real_roots()const; - bool is_exact_root(int i)const; - Bound left_bound(int i)const; - Bound right_bound(int i)const; - private: - Polynomial _polynomial; - std::vector _real_roots; -}; - -template -RS23_k_isolator_1:: -RS23_k_isolator_1(const Polynomial_ &){ - CGAL_error_msg("not implemented for these polynomial/bound types"); -} - -template <> -RS23_k_isolator_1,Gmpfr>:: -RS23_k_isolator_1(const CGAL::Polynomial &p):_polynomial(p){ - typedef CGAL::Polynomial Pol; - typedef CGAL::Gmpfr Bound; - typedef CGAL::RS3::RS3_k_refiner_1 KRefiner; - int numsols; - std::vector intervals; - RS2::RS2_calls::init_solver(); - RS2::RS2_calls::create_rs_upoly(p,rs_get_default_up()); - set_rs_precisol(0); - set_rs_verbose(0); - rs_run_algo((char*)"UISOLE"); - RS2::RS2_calls::insert_roots(std::back_inserter(intervals)); - // RS2 computed the isolating intervals. Now, we use RS3 to refine each - // root until reaching Kantorovich criterion, before adding it to the - // root vector. - numsols=intervals.size(); - for(int j=0;j -RS23_k_isolator_1,Gmpfr>:: -RS23_k_isolator_1(const CGAL::Polynomial &qp):_polynomial(qp){ - typedef CGAL::Polynomial ZPol; - typedef CGAL::Gmpfr Bound; - typedef CGAL::RS3::RS3_k_refiner_1 ZKRefiner; - int numsols; - std::vector intervals; - CGAL::Polynomial zp=CGAL::RS_AK1::Polynomial_converter_1< - CGAL::Polynomial, - CGAL::Polynomial >()(qp); - RS2::RS2_calls::init_solver(); - RS2::RS2_calls::create_rs_upoly(zp,rs_get_default_up()); - set_rs_precisol(0); - set_rs_verbose(0); - rs_run_algo((char*)"UISOLE"); - RS2::RS2_calls::insert_roots(std::back_inserter(intervals)); - // RS2 computed the isolating intervals. Now, we use RS3 to refine each - // root until reaching Kantorovich criterion, before adding it to the - // root vector. - numsols=intervals.size(); - for(int j=0;j -Polynomial_ -RS23_k_isolator_1::polynomial()const{ - return _polynomial; -} - -template -int -RS23_k_isolator_1::number_of_real_roots()const{ - return _real_roots.size(); -} - -template -bool -RS23_k_isolator_1::is_exact_root(int i)const{ - return _real_roots[i].inf()==_real_roots[i].sup(); -} - -template -Bound_ -RS23_k_isolator_1::left_bound(int i)const{ - return _real_roots[i].inf(); -} - -template -Bound_ -RS23_k_isolator_1::right_bound(int i)const{ - return _real_roots[i].sup(); -} - -} // namespace CGAL - -#endif // CGAL_RS_RS23_K_ISOLATOR_1_H diff --git a/Algebraic_kernel_d/include/CGAL/RS/rs2_calls.h b/Algebraic_kernel_d/include/CGAL/RS/rs2_calls.h deleted file mode 100644 index 687a6714d747..000000000000 --- a/Algebraic_kernel_d/include/CGAL/RS/rs2_calls.h +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright (c) 2006-2013 INRIA Nancy-Grand Est (France). All rights reserved. -// -// This file is part of CGAL (www.cgal.org) -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial -// -// Author: Luis Peñaranda - -#ifndef CGAL_RS_RS2_CALLS_H -#define CGAL_RS_RS2_CALLS_H - -#include -#include -#include -#include -#include - -#include - -#ifdef CGAL_RS_OLD_INCLUDES -#define CGALRS_PTR(a) long int a -#else -#define CGALRS_PTR(a) void *a -#endif - -// RS3 does not work with MPFR 3.1.3 to 3.1.6. In case RS3 is enabled and -// the version of MPFR is one of those buggy versions, abort the compilation -// and instruct the user to update MPFR or don't use RS3. -#ifdef CGAL_USE_RS3 -static_assert( - MPFR_VERSION_MAJOR!=3 || - MPFR_VERSION_MINOR!=1 || - MPFR_VERSION_PATCHLEVEL<3 || MPFR_VERSION_PATCHLEVEL>6, - "RS3 does not work with MPFR versions 3.1.3 to 3.1.6. " - "Please update MPFR or disable RS3."); -#endif // CGAL_USE_RS3 - -namespace CGAL{ -namespace RS2{ - -struct RS2_calls{ - - static void init_solver(){ - CGAL_STATIC_THREAD_LOCAL_VARIABLE(bool, first,true); - if(first){ - first=false; - rs_init_rs(); - rs_reset_all(); - }else - rs_reset_all(); - } - - static void create_rs_upoly(CGAL::Polynomial poly, - CGALRS_PTR(ident_pol)){ - CGALRS_PTR(ident_mon); - CGALRS_PTR(ident_coeff); - rs_import_uppring((char*)"T"); - for(int i=0;i<=poly.degree();++i) - if(mpz_sgn(poly[i].mpz())){ // don't add if == 0 - ident_mon=rs_export_new_mon_upp_bz(); - ident_coeff=rs_export_new_gmp(); - rs_import_bz_gmp(ident_coeff, - TO_RSPTR_IN(&(poly[i].mpz()))); - rs_dset_mon_upp_bz(ident_mon,ident_coeff,i); - rs_dappend_list_mon_upp_bz(ident_pol, - ident_mon); - } - } - - static int affiche_sols_eqs(mpfi_ptr *x){ - CGALRS_PTR(ident_sols_eqs); - CGALRS_PTR(ident_node); - CGALRS_PTR(ident_vect); - CGALRS_PTR(ident_elt); - int nb_elts; - ident_sols_eqs=rs_get_default_sols_eqs(); - nb_elts=rs_export_list_vect_ibfr_nb(ident_sols_eqs); - ident_node=rs_export_list_vect_ibfr_firstnode(ident_sols_eqs); - mpfi_t *roots=(mpfi_t*)malloc(nb_elts*sizeof(mpfi_t)); - for(int i=0;i - static OutputIterator insert_roots(OutputIterator x){ - CGALRS_PTR(ident_sols_eqs); - CGALRS_PTR(ident_node); - CGALRS_PTR(ident_vect); - CGALRS_PTR(ident_elt); - int nb_elts; - ident_sols_eqs=rs_get_default_sols_eqs(); - nb_elts=rs_export_list_vect_ibfr_nb(ident_sols_eqs); - ident_node=rs_export_list_vect_ibfr_firstnode(ident_sols_eqs); - for(int i=0;ileft),root_prec); - Gmpfr right(&(root_pointer->right),root_prec); - CGAL_assertion(left<=right); - // Copy them, to have the data out of RS memory. - *x++=Gmpfi(left,right,root_prec+1); - ident_node=rs_export_list_vect_ibfr_nextnode - (ident_node); - } - return x; - } - -}; // struct RS2_calls - -} // namespace RS2 -} // namespace CGAL - -#endif // CGAL_RS_RS2_CALLS_H diff --git a/Algebraic_kernel_d/include/CGAL/RS/rs2_isolator_1.h b/Algebraic_kernel_d/include/CGAL/RS/rs2_isolator_1.h deleted file mode 100644 index 671c94600c24..000000000000 --- a/Algebraic_kernel_d/include/CGAL/RS/rs2_isolator_1.h +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright (c) 2006-2013 INRIA Nancy-Grand Est (France). All rights reserved. -// -// This file is part of CGAL (www.cgal.org) -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial -// -// Author: Luis Peñaranda - -#ifndef CGAL_RS_RS2_ISOLATOR_1_H -#define CGAL_RS_RS2_ISOLATOR_1_H - -#include "rs2_calls.h" -#include "polynomial_converter_1.h" -#include -#include - -namespace CGAL{ -namespace RS2{ - -template -class RS2_isolator_1{ - public: - typedef Polynomial_ Polynomial; - typedef Bound_ Bound; - private: - typedef Gmpfi Interval; - public: - RS2_isolator_1(const Polynomial&); - Polynomial polynomial()const; - int number_of_real_roots()const; - bool is_exact_root(int i)const; - Bound left_bound(int i)const; - Bound right_bound(int i)const; - private: - Polynomial _polynomial; - std::vector _real_roots; -}; - -template -RS2_isolator_1:: -RS2_isolator_1(const Polynomial_ &){ - CGAL_error_msg("not implemented for these polynomial/bound types"); -} - -// Isolator of Gmpz polynomials and Gmpfr bounds (the best case for RS). -template <> -RS2_isolator_1,Gmpfr>:: -RS2_isolator_1(const CGAL::Polynomial &p):_polynomial(p){ - //mpz_t *coeffs=(mpz_t*)malloc((degree+1)*sizeof(mpz_t)); - //mpfi_ptr *intervals_mpfi=(mpfi_ptr*)malloc(degree*sizeof(mpfi_ptr)); - //for(unsigned i=0;i<=degree;++i) - // coeffs[i][0]=*(p[i].mpz()); - RS2::RS2_calls::init_solver(); - RS2::RS2_calls::create_rs_upoly(p,rs_get_default_up()); - //free(coeffs); - set_rs_precisol(0); - set_rs_verbose(0); - rs_run_algo((char*)"UISOLE"); - RS2::RS2_calls::insert_roots(std::back_inserter(_real_roots)); -} - -// Isolator of Gmpq polynomials and Gmpfr bounds. The polynomial must be -// converted to a Gmpz one with the same roots. -template <> -RS2_isolator_1,Gmpfr>:: -RS2_isolator_1(const CGAL::Polynomial &p):_polynomial(p){ - RS2::RS2_calls::init_solver(); - RS2::RS2_calls::create_rs_upoly( - CGAL::RS_AK1::Polynomial_converter_1< - CGAL::Polynomial, - CGAL::Polynomial >()(p), - rs_get_default_up()); - set_rs_precisol(0); - set_rs_verbose(0); - rs_run_algo((char*)"UISOLE"); - RS2::RS2_calls::insert_roots(std::back_inserter(_real_roots)); -} - -template -Polynomial_ -RS2_isolator_1::polynomial()const{ - return _polynomial; -} - -template -int -RS2_isolator_1::number_of_real_roots()const{ - return _real_roots.size(); -} - -template -bool -RS2_isolator_1::is_exact_root(int i)const{ - return _real_roots[i].inf()==_real_roots[i].sup(); -} - -template -Bound_ -RS2_isolator_1::left_bound(int i)const{ - return _real_roots[i].inf(); -} - -template -Bound_ -RS2_isolator_1::right_bound(int i)const{ - return _real_roots[i].sup(); -} - -} // namespace RS2 -} // namespace CGAL - -#endif // CGAL_RS_RS2_ISOLATOR_1_H diff --git a/Algebraic_kernel_d/include/CGAL/RS/rs3_k_refiner_1.h b/Algebraic_kernel_d/include/CGAL/RS/rs3_k_refiner_1.h deleted file mode 100644 index 02670d633f77..000000000000 --- a/Algebraic_kernel_d/include/CGAL/RS/rs3_k_refiner_1.h +++ /dev/null @@ -1,157 +0,0 @@ -// Copyright (c) 2006-2013 INRIA Nancy-Grand Est (France). All rights reserved. -// -// This file is part of CGAL (www.cgal.org) -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial -// -// Author: Luis Peñaranda - -#ifndef CGAL_RS_RS3_K_REFINER_1_H -#define CGAL_RS_RS3_K_REFINER_1_H - -#include -#include "polynomial_converter_1.h" -#include "rs2_calls.h" -#include -#include "Gmpfr_make_unique.h" - -// If we want assertions, we need to evaluate. -#ifndef CGAL_NO_PRECONDITIONS -#include "signat_1.h" -#endif - -namespace CGAL{ -namespace RS3{ - -template -struct RS3_k_refiner_1{ - void operator()(const Polynomial_&,Bound_&,Bound_&,int); -}; // class RS3_k_refiner_1 - -template -void -RS3_k_refiner_1:: -operator()(const Polynomial_&,Bound_&,Bound_&,int){ - CGAL_error_msg("RS3 k-refiner not implemented for these types"); - return; -} - -template<> -void -RS3_k_refiner_1,Gmpfr>:: -operator() -(const Polynomial &pol,Gmpfr &left,Gmpfr &right,int prec){ - typedef Polynomial Polynomial; - typedef Polynomial_traits_d Ptraits; - typedef Ptraits::Degree Degree; - CGAL_precondition(left<=right); -#ifndef CGAL_NO_PRECONDITIONS - typedef Ptraits::Make_square_free Sfpart; - typedef CGAL::RS_AK1::Signat_1 - Signat; - Polynomial sfpp=Sfpart()(pol); - Signat signof(sfpp); - CGAL::Sign sl=signof(left); - CGAL_precondition(sl!=signof(right)||(left==right&&sl==ZERO)); -#endif - //std::cout<<"refining ["< -void -RS3_k_refiner_1,Gmpfr>:: -operator() -(const Polynomial &qpol,Gmpfr &left,Gmpfr &right,int prec){ - typedef Polynomial ZPolynomial; - typedef Polynomial_traits_d ZPtraits; - typedef ZPtraits::Degree ZDegree; - CGAL_precondition(left<=right); -#ifndef CGAL_NO_PRECONDITIONS - typedef ZPtraits::Make_square_free ZSfpart; - typedef CGAL::RS_AK1::Signat_1 - Signat; -#endif - //std::cout<<"refining ["< zpol=CGAL::RS_AK1::Polynomial_converter_1< - CGAL::Polynomial, - CGAL::Polynomial >()(qpol); -#ifndef CGAL_NO_PRECONDITIONS - ZPolynomial zsfpp=ZSfpart()(zpol); - Signat signof(zsfpp); - CGAL::Sign sl=signof(left); - CGAL_precondition(sl!=signof(right)||(left==right&&sl==ZERO)); -#endif - int deg=ZDegree()(zpol); - mpz_t* coefficients=(mpz_t*)malloc((deg+1)*sizeof(mpz_t)); - __mpfi_struct interval; - CGAL_RS_GMPFR_MAKE_UNIQUE(left,temp_left); - CGAL_RS_GMPFR_MAKE_UNIQUE(right,temp_right); - interval.left=*(left.fr()); - interval.right=*(right.fr()); - for(int i=0;i<=deg;++i) - coefficients[i][0]=*(zpol[i].mpz()); - RS2::RS2_calls::init_solver(); - rs3_refine_u_root(&interval, - coefficients, - deg, - prec+CGAL::max(left.get_precision(), - right.get_precision()), - 1, - 1); - free(coefficients); - mpfr_clear(left.fr()); - mpfr_clear(right.fr()); - mpfr_custom_init_set(left.fr(), - mpfr_custom_get_kind(&interval.left), - mpfr_custom_get_exp(&interval.left), - mpfr_get_prec(&interval.left), - mpfr_custom_get_mantissa(&interval.left)); - mpfr_custom_init_set(right.fr(), - mpfr_custom_get_kind(&interval.right), - mpfr_custom_get_exp(&interval.right), - mpfr_get_prec(&interval.right), - mpfr_custom_get_mantissa(&interval.right)); - CGAL_postcondition(left<=right); - //std::cout<<"ref root is ["< - -#ifndef CGAL_RS_RS3_REFINER_1_H -#define CGAL_RS_RS3_REFINER_1_H - -#include -#include "rs2_calls.h" -#include -#include "Gmpfr_make_unique.h" - -// If we want assertions, we need to evaluate. -#ifndef CGAL_NO_PRECONDITIONS -#include "signat_1.h" -#endif - -namespace CGAL{ -namespace RS3{ - -template -struct RS3_refiner_1{ - void operator()(const Polynomial_&,Bound_&,Bound_&,int,int=0); -}; // class RS3_refiner_1 - -template -void -RS3_refiner_1:: -operator()(const Polynomial_&,Bound_&,Bound_&,int,int){ - CGAL_error_msg("RS3 refiner not implemented for these types"); - return; -} - -template<> -void -RS3_refiner_1,Gmpfr>:: -operator() -(const Polynomial &pol,Gmpfr &left,Gmpfr &right,int prec,int k){ - typedef Polynomial Polynomial; - typedef Polynomial_traits_d Ptraits; - typedef Ptraits::Degree Degree; - CGAL_precondition(left<=right); -#ifndef CGAL_NO_PRECONDITIONS - typedef Ptraits::Make_square_free Sfpart; - typedef CGAL::RS_AK1::Signat_1 - Signat; - Polynomial sfpp=Sfpart()(pol); - Signat signof(sfpp); - CGAL::Sign sl=signof(left); - CGAL_precondition(sl!=signof(right)||(left==right&&sl==ZERO)); -#endif - //std::cout<<"refining ["< -void -RS3_refiner_1,Gmpfr>:: -operator() -(const Polynomial &qpol,Gmpfr &left,Gmpfr &right,int prec,int k){ - typedef Polynomial ZPolynomial; - typedef Polynomial_traits_d ZPtraits; - typedef ZPtraits::Degree ZDegree; - CGAL_precondition(left<=right); -#ifndef CGAL_NO_PRECONDITIONS - typedef ZPtraits::Make_square_free ZSfpart; - typedef CGAL::RS_AK1::Signat_1 - Signat; -#endif - //std::cout<<"refining ["< zpol=CGAL::RS_AK1::Polynomial_converter_1< - CGAL::Polynomial, - CGAL::Polynomial >()(qpol); -#ifndef CGAL_NO_PRECONDITIONS - ZPolynomial zsfpp=ZSfpart()(zpol); - Signat signof(zsfpp); - CGAL::Sign sl=signof(left); - CGAL_precondition(sl!=signof(right)||(left==right&&sl==ZERO)); -#endif - int deg=ZDegree()(zpol); - mpz_t* coefficients=(mpz_t*)malloc((deg+1)*sizeof(mpz_t)); - __mpfi_struct interval; - // Make sure the endpoints do not share references. - CGAL_RS_GMPFR_MAKE_UNIQUE(left,temp_left); - CGAL_RS_GMPFR_MAKE_UNIQUE(right,temp_right); - // Construct the mpfi_t interval which will be refined. - interval.left=*(left.fr()); - interval.right=*(right.fr()); - // Construct the polynomial which will be refined (copy pointers). - for(int i=0;i<=deg;++i) - coefficients[i][0]=*(zpol[i].mpz()); - // Call RS. - RS2::RS2_calls::init_solver(); - rs3_refine_u_root(&interval, - coefficients, - deg, - prec+CGAL::max(left.get_precision(), - right.get_precision()), - k, - k); - // Clear variables. - free(coefficients); - mpfr_clear(left.fr()); - mpfr_clear(right.fr()); - // Copy results back to the Gmpfr endpoints. - mpfr_custom_init_set(left.fr(), - mpfr_custom_get_kind(&interval.left), - mpfr_custom_get_exp(&interval.left), - mpfr_get_prec(&interval.left), - mpfr_custom_get_mantissa(&interval.left)); - mpfr_custom_init_set(right.fr(), - mpfr_custom_get_kind(&interval.right), - mpfr_custom_get_exp(&interval.right), - mpfr_get_prec(&interval.right), - mpfr_custom_get_mantissa(&interval.right)); - CGAL_postcondition(left<=right); - //std::cout<<"ref root is ["< - -#ifndef CGAL_RS_SIGNAT_1_H -#define CGAL_RS_SIGNAT_1_H - -#include -#include -#include "exact_signat_1.h" -#include - -namespace CGAL{ -namespace RS_AK1{ - -template -struct Signat_1{ - typedef Polynomial_ Polynomial; - typedef Bound_ Bound; - typedef CGAL::Polynomial_traits_d PT; - typedef typename PT::Degree Degree; - Polynomial pol; - Signat_1(const Polynomial &p):pol(p){}; - CGAL::Sign operator()(const Bound&)const; -}; // struct Signat_1 - -template -inline CGAL::Sign -Signat_1::operator()(const Bound_ &x)const{ - typedef Bound_ Bound; - typedef Real_embeddable_traits REtraits; - typedef typename REtraits::Sgn BSign; - //typedef Algebraic_structure_traits AStraits; - // This generic signat works only when Bound_ is an exact type. For - // non-exact types, an implementation must be provided. - //static_assert(std::is_same::value); - int d=Degree()(pol); - Bound h(pol[d]); - for(int i=1;i<=d;++i) - h=h*x+pol[d-i]; - return BSign()(h); -} - -template <> -inline CGAL::Sign -Signat_1,Gmpfr>::operator()(const Gmpfr &x)const{ - // In 32-bit systems, using Gmpfr arithmetic to perform exact - // evaluations can overflow. For that reason, we only use Gmpfr - // arithmetic in 64-bit systems. -#if (GMP_LIMB_BITS==64) - typedef ExactSignat_1 Exact_sign; -#else - typedef Signat_1 Exact_sign; -#endif - // This seems to work faster for small polynomials: - // return Exact_sign(pol)(x); - int d=Degree()(pol); - if(d==0) - return pol[0].sign(); - Gmpfi h(pol[d],x.get_precision()+2*d); - Uncertain indet=Uncertain::indeterminate(); - if(h.sign().is_same(indet)) - return Exact_sign(pol)(x); - for(int i=1;i<=d;++i){ - h*=x; - h+=pol[d-i]; - if(h.sign().is_same(indet)) - return Exact_sign(pol)(x); - } - CGAL_assertion(!h.sign().is_same(indet)); - return h.sign(); -} - -// This is the same code as above. -template <> -inline CGAL::Sign -Signat_1,Gmpfr>::operator()(const Gmpfr &x)const{ - typedef Signat_1 Exact_sign; - int d=Degree()(pol); - if(d==0) - return pol[0].sign(); - Gmpfi h(pol[d],x.get_precision()+2*d); - Uncertain indet=Uncertain::indeterminate(); - if(h.sign().is_same(indet)) - return Exact_sign(pol)(x); - for(int i=1;i<=d;++i){ - h*=x; - h+=pol[d-i]; - if(h.sign().is_same(indet)) - return Exact_sign(pol)(x); - } - CGAL_assertion(!h.sign().is_same(indet)); - return h.sign(); -} - -} // namespace RS_AK1 -} // namespace CGAL - -#endif // CGAL_RS_SIGNAT_1_H diff --git a/Algebraic_kernel_d/test/Algebraic_kernel_d/Algebraic_kernel_rs_gmpq_d_1.cpp b/Algebraic_kernel_d/test/Algebraic_kernel_d/Algebraic_kernel_rs_gmpq_d_1.cpp deleted file mode 100644 index b6443c836a54..000000000000 --- a/Algebraic_kernel_d/test/Algebraic_kernel_d/Algebraic_kernel_rs_gmpq_d_1.cpp +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright (c) 2006-2013 INRIA Nancy-Grand Est (France). All rights reserved. -// -// This file is part of CGAL (www.cgal.org) -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-2.1-only -// -// Author: Luis Peñaranda - -#include - -#if defined(CGAL_USE_GMP) && defined(CGAL_USE_MPFI) && defined(CGAL_USE_RS) - -#include "include/CGAL/_test_algebraic_kernel_1.h" -#ifdef CGAL_RS_TEST_LOG_TIME -#include -#endif - -#include - -template -int test_ak(){ - typedef AK_ AK; - typedef typename AK::Polynomial_1 Polynomial_1; - //typedef typename AK::Coefficient Coefficient; - typedef typename AK::Bound Bound; - typedef typename AK::Algebraic_real_1 Algebraic_real_1; - typedef typename AK::Multiplicity_type Multiplicity_type; - -#ifdef CGAL_RS_TEST_LOG_TIME - clock_t start=clock(); -#endif - - AK ak; // an algebraic kernel object - CGAL::test_algebraic_kernel_1(ak); // we run standard tests first - - typename AK::Solve_1 solve_1 = ak.solve_1_object(); - Polynomial_1 x = CGAL::shift(Polynomial_1(1),1); - int returnvalue=0; - - // variant using a bool indicating a square free polynomial - // multiplicities are not computed - std::vector roots; - solve_1(x*x-2,true, std::back_inserter(roots)); - if(roots.size()!=2){ - returnvalue-=1; - std::cerr<<"error 1: the number of roots of x^2-2 must be 2"<< - std::endl; - } - if(-1.42>=roots[0] || -1.41<=roots[0] || - 1.41>=roots[1] || 1.42<=roots[1]){ - returnvalue-=2; - std::cerr<<"error 2: the roots of x^2-2 are wrong"<=roots[0] || 1.42<=roots[0] || - 1.73>=roots[1] || 1.74<=roots[1]){ - returnvalue-=8; - std::cerr<<"error 4: the roots of (x^2-2)*(x^2-3)"<< - " between 0 and 10 are wrong"< > mroots; - solve_1((x*x-2), std::back_inserter(mroots)); - if(mroots.size()!=2){ - returnvalue-=16; - std::cerr<<"error 5: the number of roots of x^2-2 must be 2"<< - std::endl; - } - if(-1.42>=mroots[0].first || -1.41<=mroots[0].first || - 1.41>=mroots[1].first || 1.42<=mroots[1].first){ - returnvalue-=32; - std::cerr<<"error 6: the roots of x^2-2 are wrong"<=mroots[0].first || 1.42<=mroots[0].first || - 1.73>=mroots[1].first || 1.74<=mroots[1].first){ - returnvalue-=256; - std::cerr<<"error 9: the roots of (x^2-2)*(x^2-3) are wrong"<< - std::endl; - } - if(mroots[0].second!=1 && mroots[1].second!=1){ - returnvalue-=512; - std::cerr<<"error 10: the multiplicities of the roots of"<< - " (x^2-2)*(x^2-3) are wrong"<(); - std::cerr<<"*** result of the tests (should be 0): "< - -#include - -#if defined(CGAL_USE_GMP) && defined(CGAL_USE_MPFI) && defined(CGAL_USE_RS) - -#include "include/CGAL/_test_algebraic_kernel_1.h" -#ifdef CGAL_RS_TEST_LOG_TIME -#include -#endif - -// default RS_AK_1 -#include - -// different isolators -#include -#ifdef CGAL_USE_RS3 -#include -#endif - -// different refiners -#include -#ifdef CGAL_USE_RS3 -#include -#include -#endif - -template -int test_ak(){ - typedef AK_ AK; - typedef typename AK::Polynomial_1 Polynomial_1; - //typedef typename AK::Coefficient Coefficient; - typedef typename AK::Bound Bound; - typedef typename AK::Algebraic_real_1 Algebraic_real_1; - typedef typename AK::Multiplicity_type Multiplicity_type; - -#ifdef CGAL_RS_TEST_LOG_TIME - clock_t start=clock(); -#endif - - AK ak; // an algebraic kernel object - CGAL::test_algebraic_kernel_1(ak); // we run standard tests first - - typename AK::Solve_1 solve_1 = ak.solve_1_object(); - Polynomial_1 x = CGAL::shift(Polynomial_1(1),1); - int returnvalue=0; - - // variant using a bool indicating a square free polynomial - // multiplicities are not computed - std::vector roots; - solve_1(x*x-2,true, std::back_inserter(roots)); - if(roots.size()!=2){ - returnvalue-=1; - std::cerr<<"error 1: the number of roots of x^2-2 must be 2"<< - std::endl; - } - if(-1.42>=roots[0] || -1.41<=roots[0] || - 1.41>=roots[1] || 1.42<=roots[1]){ - returnvalue-=2; - std::cerr<<"error 2: the roots of x^2-2 are wrong"<=roots[0] || 1.42<=roots[0] || - 1.73>=roots[1] || 1.74<=roots[1]){ - returnvalue-=8; - std::cerr<<"error 4: the roots of (x^2-2)*(x^2-3)"<< - " between 0 and 10 are wrong"< > mroots; - solve_1((x*x-2), std::back_inserter(mroots)); - if(mroots.size()!=2){ - returnvalue-=16; - std::cerr<<"error 5: the number of roots of x^2-2 must be 2"<< - std::endl; - } - if(-1.42>=mroots[0].first || -1.41<=mroots[0].first || - 1.41>=mroots[1].first || 1.42<=mroots[1].first){ - returnvalue-=32; - std::cerr<<"error 6: the roots of x^2-2 are wrong"<=mroots[0].first || 1.42<=mroots[0].first || - 1.73>=mroots[1].first || 1.74<=mroots[1].first){ - returnvalue-=256; - std::cerr<<"error 9: the roots of (x^2-2)*(x^2-3) are wrong"<< - std::endl; - } - if(mroots[0].second!=1 && mroots[1].second!=1){ - returnvalue-=512; - std::cerr<<"error 10: the multiplicities of the roots of"<< - " (x^2-2)*(x^2-3) are wrong"< Polynomial; - typedef CGAL::Gmpfr Bound; - - // the RS2-only kernel - typedef CGAL::RS2::RS2_isolator_1 RS2_isolator; - typedef CGAL::Bisection_refiner_1 B_refiner; - typedef CGAL::RS_AK1::Algebraic_kernel_1 AK_RS2; - -#ifdef CGAL_USE_RS3 - // the RS2/RS3 kernel - typedef CGAL::RS23_k_isolator_1 K_isolator; - typedef CGAL::RS3::RS3_k_refiner_1 RS3_k_refiner; - typedef CGAL::RS_AK1::Algebraic_kernel_1 AK_RS2_RS3; -#endif // CGAL_USE_RS3 - - // test all and return the result - long result=0; - std::cerr<<"*** testing default RS AK_1:"; - result+=test_ak(); - std::cerr<<"*** testing RS2 AK_1:"; - result+=(2048*test_ak()); -#ifdef CGAL_USE_RS3 - std::cerr<<"*** testing RS2/RS3 k_AK_1:"; - result+=(4096*test_ak()); -#endif // CGAL_USE_RS3 - std::cerr<<"*** result of the tests (should be 0): "< Date: Tue, 6 Aug 2024 16:53:02 +0100 Subject: [PATCH 2/4] really remove doc --- Documentation/doc/Documentation/Third_party.txt | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/Documentation/doc/Documentation/Third_party.txt b/Documentation/doc/Documentation/Third_party.txt index d2eeb5d9b7e5..d56b8484a159 100644 --- a/Documentation/doc/Documentation/Third_party.txt +++ b/Documentation/doc/Documentation/Third_party.txt @@ -180,19 +180,6 @@ optional: it is used by some models of the \mpfi can be downloaded from `https://gitlab.inria.fr/mpfi/mpfi`. -\subsection thirdpartyRS3 RS and RS3 - -\rs (Real Solutions) is devoted to the study of the real roots of -polynomial systems with a finite number of complex roots (including -univariate polynomials). In \cgal, \rs is used by one model of the -\ref PkgAlgebraicKernelD "Algebraic Kernel". - -\rs is freely distributable for non-commercial use. You can download it -from `http://vegas.loria.fr/rs/`. Actually, the \rs package also includes \rs3, the -successor of \rs, which is used in conjunction with it. - -The libraries \rs and \rs3 need \mpfi, which can be downloaded from -`https://gitlab.inria.fr/mpfi/mpfi`. \subsection thirdpartyNTL NTL Version 5.1 or later From f6d3920cd3fdf2b554f560dbc1c0dae499b64ac4 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 9 Sep 2024 11:57:32 +0100 Subject: [PATCH 3/4] Mention RS in the Implementation History --- .../Algebraic_kernel_d/Algebraic_kernel_d.txt | 7 +++++++ Documentation/doc/biblio/cgal_manual.bib | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/Algebraic_kernel_d/doc/Algebraic_kernel_d/Algebraic_kernel_d.txt b/Algebraic_kernel_d/doc/Algebraic_kernel_d/Algebraic_kernel_d.txt index 46ef18f5a2d8..2d8d1f582b69 100644 --- a/Algebraic_kernel_d/doc/Algebraic_kernel_d/Algebraic_kernel_d.txt +++ b/Algebraic_kernel_d/doc/Algebraic_kernel_d/Algebraic_kernel_d.txt @@ -341,6 +341,13 @@ Michael Hemmer and Michael Kerber, respectively. Notwithstanding, the authors al contribution of all authors of the \exacus project, particularly the contribution of Arno Eigenwillig, Sebastian Limbach and Pavel Emeliyanenko. +In 2010, two univariate kernels that interface the library RS \cgalCite{cgal:r-rs} were +written by Luis Peñaranda and Sylvain Lazard \cgalCite{cgal:2009-ESA}. +Both models interface the library RS \cgalCite{cgal:r-rs} by Fabrice Rouillier. +The authors want to thank Fabrice Rouillier and Elias Tsigaridas for +strong support and many useful discussions that lead to the integration of RS. +Due to lack of maintenance, these kernels have been removed in 2024. + */ } /* namespace CGAL */ diff --git a/Documentation/doc/biblio/cgal_manual.bib b/Documentation/doc/biblio/cgal_manual.bib index 25bb729e33dd..7378480ed0ee 100644 --- a/Documentation/doc/biblio/cgal_manual.bib +++ b/Documentation/doc/biblio/cgal_manual.bib @@ -1583,6 +1583,22 @@ @inproceedings{ cgal:l-vgasa-96 ,update = "98.01 schirra" } +@inproceedings{cgal:2009-ESA, +author = {Lazard, Sylvain and Pe~{n}aranda, Luis and Tsigaridas, Elias}, +title = {Univariate Algebraic Kernel and Application to Arrangements}, +year = {2009}, +isbn = {9783642020100}, +publisher = {Springer-Verlag}, +address = {Berlin, Heidelberg}, +url = {https://doi.org/10.1007/978-3-642-02011-7_20}, +doi = {10.1007/978-3-642-02011-7_20}, +booktitle = {Proceedings of the 8th International Symposium on Experimental Algorithms}, +pages = {209–220}, +numpages = {12}, +location = {Dortmund, Germany}, +series = {SEA '09} +} + @INPROCEEDINGS{cgal:lazard04b, AUTHOR = {Lazard, Sylvain and Pe{\~n}aranda, Luis and Petitjean, Sylvain}, TITLE = {Intersecting Quadrics\,: An Efficient and Exact Implementation}, From 0fa0b00b4fb91a40b7db65d740acc6b421cf96bf Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 21 Oct 2024 13:42:16 +0100 Subject: [PATCH 4/4] Update changes.md --- Installation/CHANGES.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Installation/CHANGES.md b/Installation/CHANGES.md index f1b4b336cc32..a393148dc40c 100644 --- a/Installation/CHANGES.md +++ b/Installation/CHANGES.md @@ -1,5 +1,13 @@ # Release History + +## [Release 6.1](https://github.com/CGAL/cgal/releases/tag/v6.1) + +### [Algebraic Kernel](https://doc.cgal.org/6.1/Manual/packages.html#PkgAlgebraicKernelD) + +- **Breaking change**: Classes based on the RS Library are no longer provided. + + ## [Release 6.0.1](https://github.com/CGAL/cgal/releases/tag/v6.0.1) ### [Poisson Surface Reconstruction](https://doc.cgal.org/6.0.1/Manual/packages.html#PkgPoissonSurfaceReconstruction3)