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; }
int main(){ AK ak; AK::Construct_algebraic_real_1 construct_algreal_1 = ak.construct_algebraic_real_1_object(); 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; }
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; }
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; }