File: Compare_1.cpp

package info (click to toggle)
cgal 3.6.1-2
  • links: PTS
  • area: non-free
  • in suites: squeeze
  • size: 62,184 kB
  • ctags: 95,782
  • sloc: cpp: 453,758; ansic: 96,821; sh: 226; makefile: 120; xml: 2
file content (54 lines) | stat: -rw-r--r-- 3,087 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.6-branch/Algebraic_kernel_d/examples/Algebraic_kernel_d/Compare_1.cpp $
// $Id: Compare_1.cpp 53386 2009-12-11 11:22:11Z penarand $

#include <CGAL/Algebraic_kernel_d_1_RS_Gmpz.h>
#include <vector>

typedef CGAL::Algebraic_kernel_d_1_RS_Gmpz              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;
  }