1 #include <CGAL/Polynomial.h>
2 #include <CGAL/Polynomial_traits_d.h>
3 #include <CGAL/Polynomial_type_generator.h>
4
main()5 int main(){
6 CGAL::IO::set_pretty_mode(std::cout);
7 typedef CGAL::Polynomial_type_generator<int,2>::Type Poly_2;
8 typedef CGAL::Polynomial_traits_d<Poly_2> PT_2;
9
10 //construction using shift
11 Poly_2 x = PT_2::Shift()(Poly_2(1),1,0); // x^1
12 Poly_2 y = PT_2::Shift()(Poly_2(1),1,1); // y^1
13
14
15 Poly_2 F = 2*x*y + 3*CGAL::ipower(y,3);
16 std::cout << "The bivariate polynomial F: " << F // = 3*y^3 + (2*x)*y
17 << std::endl << std::endl;
18
19 PT_2::Evaluate evaluate;
20 PT_2::Evaluate_homogeneous hevaluate;
21
22 // Evaluation considers a polynomials as univariate:
23 std::cout << "F(5): " << evaluate(F,5) // = 10*x + 375
24 << std::endl;
25 // Evaluate_homogeneous considers F as a homogeneous polynomial in
26 // the outermost variable only, that is, F is interpreted as
27 // F(u,v) = 2*x*u*v^2 + 3 * u^3
28 std::cout << "F(5,7): " << hevaluate(F,5,7) // = 490*x + 375
29 << std::endl << std::endl;
30
31
32 PT_2::Substitute substitute;
33 PT_2::Substitute_homogeneous hsubstitute;
34
35 // Substitute considers a polynomials as multivariate, that is, the
36 // new values for the variables are given by an iterator range
37 // Note that the value type only has to be interoperable with the innermost
38 // coefficient
39 std::list<Poly_2> replacements;
40 replacements.push_back(x-1); // replace x by x-1
41 replacements.push_back(y); // replace y by y, i.e., do nothing
42
43 std::cout << "The bivariate polynomial F: " << F // = 3*y^3 + (2*x)*y
44 << std::endl;
45 std::cout << "F(x-1,y): " // = 3*y^3 + (2*x + (-2))*y
46 << substitute(F,replacements.begin(),replacements.end())
47 << std::endl;
48 // Substitute_homogeneous considers F as a homogeneous polynomial in
49 // all variable, that is, F is interpreted as
50 // F(x,y,w) = 2*x*y*w + 3 * y^3
51 replacements.push_back(y); // replace z by y
52
53 std::cout << "F(x-1,y,y): " // = 3*y^3 + (2*x + (-2))*y^2
54 << hsubstitute(F,replacements.begin(),replacements.end())
55 << std::endl;
56 }
57