-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Algebraic kernel d examples fixes akobel #1374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
akobel
wants to merge
4
commits into
CGAL:master
Choose a base branch
from
akobel:Algebraic_kernel_d_examples-fixes-akobel
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
618d91f
add missing USE_MPFI in CMakeLists; add examples for the RS AK
akobel 7e6534c
request MPFI, LEDA, RS, RS3 in AK_d testsuite
akobel dc622f4
change Boost and MPFI from REQUIRED to QUIET
akobel 8b73d43
revert Boost dependency to REQUIRED
akobel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
62 changes: 44 additions & 18 deletions
62
Algebraic_kernel_d/examples/Algebraic_kernel_d/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,57 @@ | ||
# Created by the script cgal_create_cmake_script | ||
# This is the CMake script for compiling a CGAL application. | ||
# Created by the script cgal_create_CMakeLists | ||
# This is the CMake script for compiling a set of CGAL applications. | ||
|
||
project( Algebraic_kernel_d_examples ) | ||
|
||
project( Algebraic_kernel_d_test ) | ||
|
||
cmake_minimum_required(VERSION 2.8.11) | ||
|
||
# CGAL and its components | ||
find_package( CGAL QUIET COMPONENTS Core ) | ||
|
||
find_package(CGAL QUIET COMPONENTS Core MPFI) | ||
if ( NOT CGAL_FOUND ) | ||
message(STATUS "This project requires the CGAL library, and will not be compiled.") | ||
return() | ||
endif() | ||
|
||
# include helper file | ||
include( ${CGAL_USE_FILE} ) | ||
|
||
if ( CGAL_FOUND ) | ||
|
||
include( ${CGAL_USE_FILE} ) | ||
include( CGAL_CreateSingleSourceCGALProgram ) | ||
include( CGAL_VersionUtils ) | ||
# Boost and its components | ||
find_package( Boost REQUIRED ) | ||
if ( NOT Boost_FOUND ) | ||
message(STATUS "This project requires the Boost library, and will not be compiled.") | ||
return() | ||
endif() | ||
|
||
find_package( MPFI QUIET ) | ||
if( MPFI_FOUND ) | ||
include( ${MPFI_USE_FILE} ) | ||
endif() | ||
|
||
include_directories (BEFORE ../../include) | ||
include_directories( BEFORE ../../include ) | ||
|
||
create_single_source_cgal_program( "Compare_1.cpp" ) | ||
create_single_source_cgal_program( "Construct_algebraic_real_1.cpp" ) | ||
create_single_source_cgal_program( "Isolate_1.cpp" ) | ||
create_single_source_cgal_program( "Sign_at_1.cpp" ) | ||
create_single_source_cgal_program( "Solve_1.cpp" ) | ||
include( CGAL_CreateSingleSourceCGALProgram ) | ||
|
||
|
||
create_single_source_cgal_program( "Compare_1.cpp" ) | ||
create_single_source_cgal_program( "Construct_algebraic_real_1.cpp" ) | ||
create_single_source_cgal_program( "Isolate_1.cpp" ) | ||
create_single_source_cgal_program( "Sign_at_1.cpp" ) | ||
create_single_source_cgal_program( "Solve_1.cpp" ) | ||
|
||
|
||
find_package( RS ) | ||
find_package( RS3 ) | ||
if ( NOT RS3_FOUND ) | ||
message(STATUS "Parts of this project require the RS libraries, and will not be compiled.") | ||
else() | ||
|
||
message(STATUS "This program requires the CGAL library, and will not be compiled.") | ||
|
||
include( ${RS_USE_FILE} ) | ||
include( ${RS3_USE_FILE} ) | ||
create_single_source_cgal_program( "RS_Compare_1.cpp" ) | ||
create_single_source_cgal_program( "RS_Construct_algebraic_real_1.cpp" ) | ||
create_single_source_cgal_program( "RS_Isolate_1.cpp" ) | ||
create_single_source_cgal_program( "RS_Sign_at_1.cpp" ) | ||
create_single_source_cgal_program( "RS_Solve_1.cpp" ) | ||
endif() | ||
|
63 changes: 63 additions & 0 deletions
63
Algebraic_kernel_d/examples/Algebraic_kernel_d/RS_Compare_1.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// $URL$ | ||
// $Id$ | ||
|
||
#include <CGAL/basic.h> | ||
#ifdef CGAL_USE_RS | ||
#include <CGAL/Algebraic_kernel_rs_gmpz_d_1.h> | ||
#include <CGAL/Gmpz.h> | ||
#include <vector> | ||
|
||
typedef CGAL::Algebraic_kernel_rs_gmpz_d_1 AK; | ||
typedef AK::Coefficient Coefficient; | ||
typedef AK::Polynomial_1 Polynomial_1; | ||
typedef AK::Algebraic_real_1 Algebraic_real_1; | ||
typedef AK::Bound Bound; | ||
typedef std::pair<Bound,Bound> Interval; | ||
|
||
int main(){ | ||
AK ak; | ||
|
||
AK::Construct_algebraic_real_1 construct_algebraic_real_1 = ak.construct_algebraic_real_1_object(); | ||
Polynomial_1 x = CGAL::shift(AK::Polynomial_1(1),1); // the monomial x | ||
Algebraic_real_1 a = construct_algebraic_real_1(x*x-2,1); // sqrt(2) | ||
Algebraic_real_1 b = construct_algebraic_real_1(x*x-3,1); // sqrt(3) | ||
|
||
// Algebraic_real_1 is RealEmbeddable (just some functions:) | ||
std::cout << "sign of a is : " << CGAL::sign(a) << "\n"; | ||
std::cout << "double approximation of a is : " << CGAL::to_double(a) << "\n"; | ||
std::cout << "double approximation of b is : " << CGAL::to_double(b) << "\n"; | ||
std::cout << "double lower bound of a : " << CGAL::to_interval(a).first << "\n"; | ||
std::cout << "double upper bound of a : " << CGAL::to_interval(a).second << "\n"; | ||
std::cout << "LessThanComparable (a<b) : " << (a<b) << "\n\n"; | ||
|
||
// use compare_1 with int, Bound, Coefficient, Algebraic_real_1 | ||
AK::Compare_1 compare_1 = ak.compare_1_object(); | ||
std::cout << " compare with an int : " << compare_1(a ,int(2)) << "\n"; | ||
std::cout << " compare with an Coefficient : " << compare_1(a ,Coefficient(2)) << "\n"; | ||
std::cout << " compare with an Bound : " << compare_1(a ,Bound(2)) << "\n"; | ||
std::cout << " compare with another Algebraic_real_1: " << compare_1(a ,b) << "\n\n"; | ||
|
||
// get a value between two roots | ||
AK::Bound_between_1 bound_between_1 = ak.bound_between_1_object(); | ||
std::cout << " value between sqrt(2) and sqrt(3) " << bound_between_1(a,b) << "\n"; | ||
std::cout << " is larger than sqrt(2) " << compare_1(bound_between_1(a,b),a) << "\n"; | ||
std::cout << " is less than sqrt(3) " << compare_1(bound_between_1(a,b),b) << "\n\n"; | ||
|
||
// approximate with relative precision | ||
AK::Approximate_relative_1 approx_r = ak.approximate_relative_1_object(); | ||
std::cout << " lower bound of a with at least 100 bits: "<< approx_r(a,100).first << "\n"; | ||
std::cout << " upper bound of a with at least 100 bits: "<< approx_r(a,100).second << "\n\n"; | ||
|
||
// approximate with absolute error | ||
AK::Approximate_absolute_1 approx_a = ak.approximate_absolute_1_object(); | ||
std::cout << " lower bound of b with error less than 2^-100: "<< approx_a(b,100).first << "\n"; | ||
std::cout << " upper bound of b with error less than 2^-100: "<< approx_a(b,100).second << "\n\n"; | ||
|
||
return 0; | ||
} | ||
#else | ||
int main(){ | ||
std::cout << "This example requires CGAL to be configured with library RS." << std::endl; | ||
return 0; | ||
} | ||
#endif |
41 changes: 41 additions & 0 deletions
41
Algebraic_kernel_d/examples/Algebraic_kernel_d/RS_Construct_algebraic_real_1.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// $URL$ | ||
// $Id$ | ||
|
||
#include <CGAL/basic.h> | ||
#ifdef CGAL_USE_RS | ||
#include <CGAL/Algebraic_kernel_rs_gmpz_d_1.h> | ||
#include <CGAL/Gmpz.h> | ||
#include <vector> | ||
#include <iostream> | ||
|
||
typedef CGAL::Algebraic_kernel_rs_gmpz_d_1 AK; | ||
typedef AK::Polynomial_1 Polynomial_1; | ||
typedef AK::Algebraic_real_1 Algebraic_real_1; | ||
typedef AK::Coefficient Coefficient; | ||
typedef AK::Bound Bound; | ||
typedef AK::Multiplicity_type Multiplicity_type; | ||
|
||
int main(){ | ||
AK ak; // an object of | ||
AK::Construct_algebraic_real_1 construct_algreal_1 = ak.construct_algebraic_real_1_object(); | ||
|
||
std::cout << "Construct from int : " << construct_algreal_1(int(2)) << "\n"; | ||
std::cout << "Construct from Coefficient : " << construct_algreal_1(Coefficient(2)) << "\n"; | ||
std::cout << "Construct from Bound : " << construct_algreal_1(Bound(2)) << "\n\n"; | ||
|
||
Polynomial_1 x = CGAL::shift(AK::Polynomial_1(1),1); // the monomial x | ||
std::cout << "Construct by index : " | ||
<< construct_algreal_1(x*x-2,1) << "\n" | ||
<< to_double(construct_algreal_1(x*x-2,1)) << "\n"; | ||
std::cout << "Construct by isolating interval : " | ||
<< construct_algreal_1(x*x-2,Bound(0),Bound(2)) << "\n" | ||
<< to_double(construct_algreal_1(x*x-2,Bound(0),Bound(2))) << "\n\n"; | ||
|
||
return 0; | ||
} | ||
#else | ||
int main(){ | ||
std::cout << "This example requires CGAL to be configured with library RS." << std::endl; | ||
return 0; | ||
} | ||
#endif |
57 changes: 57 additions & 0 deletions
57
Algebraic_kernel_d/examples/Algebraic_kernel_d/RS_Isolate_1.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// $URL$ | ||
// $Id$ | ||
|
||
#include <CGAL/basic.h> | ||
#ifdef CGAL_USE_RS | ||
#include <CGAL/Algebraic_kernel_rs_gmpz_d_1.h> | ||
#include <CGAL/Gmpz.h> | ||
#include <vector> | ||
|
||
typedef CGAL::Algebraic_kernel_rs_gmpz_d_1 AK; | ||
typedef AK::Polynomial_1 Polynomial_1; | ||
typedef AK::Algebraic_real_1 Algebraic_real_1; | ||
typedef AK::Coefficient Coefficient; | ||
typedef AK::Bound Bound; | ||
typedef AK::Multiplicity_type Multiplicity_type; | ||
|
||
int main(){ | ||
AK ak; // an object of | ||
AK::Construct_algebraic_real_1 construct_algreal_1 = ak.construct_algebraic_real_1_object(); | ||
AK::Isolate_1 isolate_1 = ak.isolate_1_object(); | ||
AK::Compute_polynomial_1 compute_polynomial_1 = ak.compute_polynomial_1_object(); | ||
|
||
// construct an algebraic number from an integer | ||
Algebraic_real_1 frominteger=construct_algreal_1(int(2)); | ||
std::cout << "Construct from int: " << frominteger << "\n"; | ||
|
||
// the constructed algebraic number is root of a polynomial | ||
Polynomial_1 pol=compute_polynomial_1(frominteger); | ||
std::cout << "The constructed number is root of: " << pol << "\n"; | ||
|
||
// construct an algebraic number from a polynomial and an isolating interval | ||
Polynomial_1 x = CGAL::shift(AK::Polynomial_1(1),1); // the monomial x | ||
Algebraic_real_1 frominterval=construct_algreal_1(x*x-2,Bound(0),Bound(2)); | ||
std::cout << "Construct from isolating interval: " << frominterval << "\n"; | ||
|
||
// isolate the second algebraic number from the first: this is to say, | ||
// isolating the second algebraic number with respect to the polynomial | ||
// of which the first constructed number is root | ||
std::pair<Bound,Bound> isolation1 = isolate_1(frominterval,pol); | ||
std::cout << "Isolating the second algebraic number gives: [" | ||
<< isolation1.first << "," << isolation1.second << "]\n"; | ||
|
||
// isolate again the same algebraic number, this time with respect to | ||
// the polynomial 10*x-14 (which has root 1.4, close to this algebraic | ||
// number) | ||
std::pair<Bound,Bound> isolation2 = isolate_1(frominterval,10*x-14); | ||
std::cout << "Isolating again the second algebraic number gives: [" | ||
<< isolation2.first << "," << isolation2.second << "]\n"; | ||
|
||
return 0; | ||
} | ||
#else | ||
int main(){ | ||
std::cout << "This example requires CGAL to be configured with library RS." << std::endl; | ||
return 0; | ||
} | ||
#endif |
55 changes: 55 additions & 0 deletions
55
Algebraic_kernel_d/examples/Algebraic_kernel_d/RS_Sign_at_1.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// $URL$ | ||
// $Id$ | ||
|
||
#include <CGAL/basic.h> | ||
#ifdef CGAL_USE_RS | ||
#include <CGAL/Algebraic_kernel_rs_gmpz_d_1.h> | ||
#include <CGAL/Gmpz.h> | ||
#include <vector> | ||
|
||
typedef CGAL::Algebraic_kernel_rs_gmpz_d_1 AK; | ||
typedef AK::Polynomial_1 Polynomial_1; | ||
typedef AK::Algebraic_real_1 Algebraic_real_1; | ||
typedef AK::Coefficient Coefficient; | ||
typedef AK::Bound Bound; | ||
typedef AK::Multiplicity_type Multiplicity_type; | ||
|
||
int main(){ | ||
AK ak; | ||
AK::Solve_1 solve_1 = ak.solve_1_object(); | ||
AK::Sign_at_1 sign_at_1 = ak.sign_at_1_object(); | ||
AK::Is_zero_at_1 is_zero_at_1 = ak.is_zero_at_1_object(); | ||
|
||
// construct the polynomials p=x^2-5 and q=x-2 | ||
Polynomial_1 x = CGAL::shift(AK::Polynomial_1(1),1); // the monomial x | ||
Polynomial_1 p = x*x-5; | ||
std::cout << "Polynomial p: " << p << "\n"; | ||
Polynomial_1 q = x-2; | ||
std::cout << "Polynomial q: " << q << "\n"; | ||
|
||
// find the roots of p (it has two roots) and q (one root) | ||
std::vector<Algebraic_real_1> roots_p,roots_q; | ||
solve_1(p,true, std::back_inserter(roots_p)); | ||
solve_1(q,true, std::back_inserter(roots_q)); | ||
|
||
// evaluate the second root of p in q | ||
std::cout << "Sign of the evaluation of root 2 of p in q: " | ||
<< sign_at_1(q,roots_p[1]) << "\n"; | ||
|
||
// evaluate the root of q in p | ||
std::cout << "Sign of the evaluation of root 1 of q in p: " | ||
<< sign_at_1(p,roots_q[0]) << "\n"; | ||
|
||
// check whether the evaluation of the first root of p in p is zero | ||
std::cout << "Is zero the evaluation of root 1 of p in p? " | ||
<< is_zero_at_1(p,roots_p[0]) << "\n"; | ||
|
||
return 0; | ||
} | ||
|
||
#else | ||
int main(){ | ||
std::cout << "This example requires CGAL to be configured with library RS." << std::endl; | ||
return 0; | ||
} | ||
#endif |
62 changes: 62 additions & 0 deletions
62
Algebraic_kernel_d/examples/Algebraic_kernel_d/RS_Solve_1.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// $URL$ | ||
// $Id$ | ||
|
||
#include <CGAL/basic.h> | ||
#ifdef CGAL_USE_RS | ||
#include <CGAL/Algebraic_kernel_rs_gmpz_d_1.h> | ||
#include <CGAL/Gmpz.h> | ||
#include <vector> | ||
|
||
typedef CGAL::Algebraic_kernel_rs_gmpz_d_1 AK; | ||
typedef AK::Polynomial_1 Polynomial_1; | ||
typedef AK::Algebraic_real_1 Algebraic_real_1; | ||
typedef AK::Bound Bound; | ||
typedef AK::Multiplicity_type Multiplicity_type; | ||
|
||
int main(){ | ||
AK ak; // an object of | ||
AK::Solve_1 solve_1 = ak.solve_1_object(); | ||
Polynomial_1 x = CGAL::shift(AK::Polynomial_1(1),1); // the monomial x | ||
|
||
|
||
// variant using a bool indicating a square free polynomial | ||
// multiplicities are not computed | ||
std::vector<Algebraic_real_1> roots; | ||
solve_1(x*x-2,true, std::back_inserter(roots)); | ||
std::cout << "Number of roots is : " << roots.size() << "\n"; | ||
std::cout << "First root should be -sqrt(2): " << CGAL::to_double(roots[0]) << "\n"; | ||
std::cout << "Second root should be sqrt(2): " << CGAL::to_double(roots[1]) << "\n\n"; | ||
roots.clear(); | ||
|
||
// variant for roots in a given range of a square free polynomial | ||
solve_1((x*x-2)*(x*x-3),true, Bound(0),Bound(10),std::back_inserter(roots)); | ||
std::cout << "Number of roots is : " << roots.size() << "\n"; | ||
std::cout << "First root should be sqrt(2): " << CGAL::to_double(roots[0]) << "\n"; | ||
std::cout << "Second root should be sqrt(3): " << CGAL::to_double(roots[1]) << "\n\n"; | ||
roots.clear(); | ||
|
||
// variant computing all roots with multiplicities | ||
std::vector<std::pair<Algebraic_real_1,Multiplicity_type> > mroots; | ||
solve_1((x*x-2), std::back_inserter(mroots)); | ||
std::cout << "Number of roots is : " << mroots.size() << "\n"; | ||
std::cout << "First root should be -sqrt(2): " << CGAL::to_double(mroots[0].first) << "" | ||
<< " with multiplicity " << mroots[0].second << "\n"; | ||
std::cout << "Second root should be sqrt(2): " << CGAL::to_double(mroots[1].first) << "" | ||
<< " with multiplicity " << mroots[1].second << "\n\n"; | ||
mroots.clear(); | ||
|
||
// variant computing roots with multiplicities for a range | ||
solve_1((x*x-2)*(x*x-3),Bound(0),Bound(10),std::back_inserter(mroots)); | ||
std::cout << "Number of roots is : " << mroots.size() << "\n"; | ||
std::cout << "First root should be sqrt(2): " << CGAL::to_double(mroots[0].first) << "" | ||
<< " with multiplicity " << mroots[0].second << "\n"; | ||
std::cout << "Second root should be sqrt(3): " << CGAL::to_double(mroots[1].first) << "" | ||
<< " with multiplicity " << mroots[1].second << "\n\n"; | ||
return 0; | ||
} | ||
#else | ||
int main(){ | ||
std::cout << "This example requires CGAL to be configured with library RS." << std::endl; | ||
return 0; | ||
} | ||
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lrineau Is it expected that CMake behaves differently when I leave out line 28 (separate find_package call for MPFI) and add MPFI in line 10? In that case, at least on my setup, the MPFI_USE_FILE is not loaded AFAICS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, nobody in the CGAL project now understands what should happen when non-CGAL components are listed in the
find_package(CGAL .. )
command. It was a feature added in our CMake scripts by Eric and Philipp, and they both left, without documenting that feature correctly.It was the "small" feature
Features/Small_Features/CMake-Installation-Manual
(link for CGAL developers only).I plan to remove the CMake code about those pre-configured third party libraries pretty soon (next week).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. It partially works - e.g., it is certainly useful if paths to 3rd-party libs in non-standard places can be preconfigured once and for all, and the generic CMakeLists.txt with a default CMake invocation just works.
It is certainly incomplete, e.g., not all environment variables in the build process are translated to the proper CMake variables (e.g., RS{,3}_{INC,LIB}_DIR are not acknowledged for some reason, and I already bugged Eric about that while he was still around).
But if noone understands the scripts anymore, that's more or less academic - if noone can maintain it, it's doomed anyway.