CMakeLists.txt
cmake_minimum_required(VERSION 3.1...3.15)
project(CGAL_Test)
find_package(CGAL REQUIRED)
create_single_source_cgal_program( "main.cpp" ) #defined in CGAL_CreateSingleSourceCGALProgram.cmake
Use basic functions for number computing.
#include <iostream>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/number_utils.h>
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
int main()
{
auto gcd_result = CGAL::gcd( 20, 30 );
std::cout << gcd_result << std::endl; // 10
int a = 64;
auto kth_root_result = CGAL::kth_root<float>( 6, a );
// equal to the following code.
// CGAL::Algebraic_structure_traits< float >::Kth_root kth_root;
// auto kth_root_result = kth_root( 6, a );
std::cout << kth_root_result << std::endl; // 2
int q, r;
CGAL::div_mod<int,int>( a, 10, q, r );
std::cout << q << ", " << r << std::endl; // 6, 4
auto mod_result = CGAL::mod( a, 3 );
std::cout << mod_result << std::endl; // 1
auto inverse_result = CGAL::inverse<float>( 2 );
std::cout << inverse_result << std::endl; // 0.5
auto is_zero_result = CGAL::is_zero( 1e-5 );
std::cout << is_zero_result << std::endl; // 0
auto compare_result = CGAL::compare( -1e-5, 0 );
std::cout << compare_result << std::endl; // -1
return 0;
}
Demo code about Polynomial.
#include <CGAL/Polynomial.h>
#include <CGAL/Polynomial_traits_d.h>
#include <CGAL/Polynomial_type_generator.h>
int main()
{
CGAL::set_pretty_mode(std::cout);
typedef CGAL::Polynomial_type_generator<int,2>::Type Poly_2;
typedef CGAL::Polynomial_traits_d<Poly_2> PT_2;
// -----------------------------------------------------------------------
//construction using shift
/* PT_2::Shift shift;
Poly_2 x = shift(Poly_2(1),1,0); // 'multiply' 1 by x_0^1
Poly_2 y = shift(Poly_2(1),1,1); // 'multiply' 1 by x_1^1
Poly_2 H = 5 * x * y + 3 * y * y; // = 3*y^2 + (5*x)*y
std::cout << "The bivariate polynomial H: " << H << std::endl; */
// -----------------------------------------------------------------------
//construction using shift
Poly_2 x = PT_2::Shift()(Poly_2(1),1,0); // = x^1
Poly_2 y = PT_2::Shift()(Poly_2(1),1,1); // = y^1
Poly_2 F // = (11*x^2 + 5*x)*y^4 + (7*x^2)*y^3
= 11 * CGAL::ipower(y,4) * CGAL::ipower(x,2)
+ 5 * CGAL::ipower(y,4) * CGAL::ipower(x,1)
+ 7 * CGAL::ipower(y,3) * CGAL::ipower(x,2);
std::cout << "The bivariate polynomial F: " << F <<"\n"<< std::endl;
PT_2::Get_coefficient get_coefficient;
std::cout << "Coefficient of y^0: "<< get_coefficient(F,0) << std::endl;
std::cout << "Coefficient of y^1: "<< get_coefficient(F,1) << std::endl;
std::cout << "Coefficient of y^2: "<< get_coefficient(F,2) << std::endl;
std::cout << "Coefficient of y^3: "<< get_coefficient(F,3) << std::endl;
std::cout << "Coefficient of y^4: "<< get_coefficient(F,4) << std::endl;
std::cout << "Coefficient of y^5: "<< get_coefficient(F,5) << std::endl;
std::cout << std::endl;
PT_2::Leading_coefficient lcoeff;
std::cout << "Leading coefficient with respect to y: "
<< lcoeff(F) // = 11*x^2 + 5*x
<< std::endl;
PT_2::Get_innermost_coefficient get_icoeff;
std::cout << "Innermost coefficient of monomial x^1y^4: "
<< get_icoeff(F,CGAL::Exponent_vector(1,4)) // = 5
<< std::endl;
PT_2::Degree degree;
PT_2::Total_degree total_degree;
PT_2::Degree_vector degree_vector;
std::cout << "The degree of F with respect to y: "<< degree(F) // = 4
<< std::endl;
std::cout << "The degree of F with respect to x: "<< degree(F,0) // = 2
<< std::endl;
std::cout << "The total degree of F : "<< total_degree(F) // = 6
<< std::endl;
std::cout << "The degree vector of F : "<< degree_vector(F)// = (2,4)
<< std::endl;
return 0;
}
#include <CGAL/Polynomial.h>
#include <CGAL/Polynomial_traits_d.h>
#include <CGAL/Polynomial_type_generator.h>
int main()
{
CGAL::set_pretty_mode(std::cout);
typedef CGAL::Polynomial_type_generator<int,2>::Type Poly_2;
typedef CGAL::Polynomial_traits_d<Poly_2> PT_2;
//construction using shift
Poly_2 x = PT_2::Shift()(Poly_2(1),1,0); // x^1
Poly_2 y = PT_2::Shift()(Poly_2(1),1,1); // y^1
Poly_2 F = 2*x*x + 2*CGAL::ipower(y,3);
std::cout << "The bivariate polynomial F: " << F << std::endl << std::endl; // 2*y^3 + (2*x^2)
PT_2::Evaluate evaluate;
PT_2::Evaluate_homogeneous hevaluate;
std::cout << "F(5): " << evaluate(F,5) << std::endl; // = 2*x^2 + 250
return 0;
}