carl  24.04
Computer ARithmetic Library
SturmSequence.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Derivative.h"
4 #include "Remainder.h"
5 
6 #include "../UnivariatePolynomial.h"
7 
8 namespace carl {
9 
10 
11 /**
12  * Computes the sturm sequence of two polynomials.
13  * Compared to the regular sturm sequence, we use the second polynomial as p_1.
14  */
15 template<typename Coeff>
16 std::vector<UnivariatePolynomial<Coeff>> sturm_sequence(const UnivariatePolynomial<Coeff>& p, const UnivariatePolynomial<Coeff>& q) {
17  std::vector<UnivariatePolynomial<Coeff>> seq({ p, q });
18  if (is_zero(p) || is_zero(q)) return seq;
19 
20  for (std::size_t k = 2; ; ++k) {
21  auto tmp = - remainder(seq[k-2], seq[k-1]);
22  if (is_zero(tmp)) return seq;
23  seq.emplace_back(std::move(tmp));
24  }
25 }
26 
27 /**
28  * Computes the sturm sequence of a polynomial as defined at @cite GCL92, page 333, example 22.
29  * The sturm sequence of p is defined as:
30  * - p_0 = p
31  * - p_1 = p'
32  * - p_k = -rem(p_{k-2}, p_{k-1})
33  */
34 template<typename Coeff>
35 std::vector<UnivariatePolynomial<Coeff>> sturm_sequence(const UnivariatePolynomial<Coeff>& p) {
36  return sturm_sequence(p, derivative(p));
37 }
38 
39 }
carl is the main namespace for the library.
std::vector< UnivariatePolynomial< Coeff > > sturm_sequence(const UnivariatePolynomial< Coeff > &p, const UnivariatePolynomial< Coeff > &q)
Computes the sturm sequence of two polynomials.
Definition: SturmSequence.h:16
const T & derivative(const T &t, Variable, std::size_t n=1)
Computes the n'th derivative of a number, which is either the number itself (for n = 0) or zero.
Definition: Derivative.h:23
bool is_zero(const Interval< Number > &i)
Check if this interval is a point-interval containing 0.
Definition: Interval.h:1453
cln::cl_I remainder(const cln::cl_I &a, const cln::cl_I &b)
Calculate the remainder of the integer division.
Definition: operations.h:526
This class represents a univariate polynomial with coefficients of an arbitrary type.