carl  24.04
Computer ARithmetic Library
UnivariateTarskiQuery.h
Go to the documentation of this file.
1 /*
2  * File: TarskiQuery.h
3  * Author: tobias
4  *
5  * Created on 24. ApriU 2016, 20:16
6  */
7 
8 #pragma once
9 
10 #include <carl-arith/core/Sign.h>
12 
13 namespace carl {
14 
15 template<typename Number>
17  if(carl::is_zero(p)) return Sign::ZERO; // check this special case because otherwise lcoeff fires assertion
18  if(p.degree() % 2 == 0) { // even degree
19  return carl::sgn(p.lcoeff());
20  }
21  else { // odd degree
22  return carl::sgn(Number(-p.lcoeff()));
23  }
24 }
25 
26 template<typename Number>
28  if(carl::is_zero(p)) return Sign::ZERO;
29  return carl::sgn(p.lcoeff());
30 }
31 
32 
33 /*
34  * implements the signed remainder sequence tarski query as described in algorithms for real algebraic geometry
35  * TODO: offer version with bounds?
36  */
37 template<typename Number>
39  CARL_LOG_FUNC("carl.thom.tarski", "p = " << p << ", q = " << q << ", der_q = " << der_q);
40  CARL_LOG_ASSERT("carl.thom.tarski", !carl::is_zero(q), "cannot query on an infinite zero set!");
41  auto srs = sturm_sequence(q, der_q * p); // standardSturmSequence is the signed remainder sequence
42  int atMinusInf = int(sign_variations(srs.begin(), srs.end(), [](const UnivariatePolynomial<Number>& p){ return signAtMinusInf(p); }));
43  int atPlusInf = int(sign_variations(srs.begin(), srs.end(), [](const UnivariatePolynomial<Number>& p){ return signAtPlusInf(p); }));
44  return atMinusInf - atPlusInf;
45 }
46 
47 template<typename Number>
49  return univariateTarskiQuery(p, q, q.derivative());
50 }
51 
52 } // namespace carl
#define CARL_LOG_FUNC(channel, args)
Definition: carl-logging.h:46
#define CARL_LOG_ASSERT(channel, condition, msg)
Definition: carl-logging.h:47
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
Sign signAtPlusInf(const UnivariatePolynomial< Number > &p)
std::size_t sign_variations(InputIterator begin, InputIterator end)
Counts the number of sign variations in the given object range.
Definition: Sign.h:69
Sign
This class represents the sign of a number .
Definition: Sign.h:20
@ ZERO
Indicates that .
bool is_zero(const Interval< Number > &i)
Check if this interval is a point-interval containing 0.
Definition: Interval.h:1453
Sign sgn(const Number &n)
Obtain the sign of the given number.
Definition: Sign.h:54
Sign signAtMinusInf(const UnivariatePolynomial< Number > &p)
int univariateTarskiQuery(const UnivariatePolynomial< Number > &p, const UnivariatePolynomial< Number > &q, const UnivariatePolynomial< Number > &der_q)
const Coefficient & lcoeff() const
Returns the leading coefficient.
uint degree() const
Get the maximal exponent of the main variable.