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;
}
Exemple #2
0
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;
}
Exemple #3
0
t_data	get_input(int argc, char **argv)
{
	t_data	data;
	int		i;

	data = init_data(data);
	i = 1;
	data = check_bonus(argv, data, i);
	i = i + data.operation_nbr + data.print_piles + data.color
		+ data.final_result + data.list_options;
	data.a = (int*)malloc(sizeof(int) * argc - i);
	data.b = (int*)malloc(sizeof(int) * argc - i);
	data.elem_nbr = argc - i;
	data.a_elem_nbr = data.elem_nbr;
	data = get_piles(argv, i, data);
	if (data.elem_nbr > 3)
		data = solve_1(data);
	else
		data = solve_2(data);
	ft_printf("%c", 8);
	return (data);
}