carl  24.04
Computer ARithmetic Library
ThomEvaluation.h
Go to the documentation of this file.
1 /*
2  * File: ThomEvaluation.h
3  * Author: tobias
4  *
5  * Created on 29. August 2016, 18:40
6  */
7 
8 #pragma once
9 
10 #include "ran_thom.h"
11 
12 namespace carl {
13 
14 /*
15  * returns the sign (NOT the actual evaluation) of p on the point defined by m as an RAN
16  */
17 template<typename Number>
19  //using Polynomial = MultivariatePolynomial<Number>;
20 
21  CARL_LOG_INFO("carl.thom.evaluation",
22  "\n****************************\n"
23  << "Thom evaluate\n"
24  << "****************************\n"
25  << "p = " << p << "\n"
26  << "m = " << m << "\n"
27  << "****************************\n");
28  for(const auto& entry : m) {
29  assert(entry.second.isThom());
30  assert(entry.first == entry.second.getThomEncoding().main_var());
31  }
32  assert(m.size() > 0);
33 
34  std::map<Variable, RealAlgebraicNumber<Number>>& m_prime(m);
35  auto it = m_prime.begin();
36  while(it != m_prime.end()) {
37  if(!p.has(it->first)) {
38  CARL_LOG_TRACE("carl.thom.evaluation", "removing " << it->first);
39  it = m_prime.erase(it);
40 
41  }
42  else {
43  it++;
44  }
45  }
46 
47  std::map<Variable, ThomEncoding<Number>> mTE;
48  for(const auto& entry : m_prime) {
49  mTE.insert(std::make_pair(entry.first, entry.second.getThomEncoding()));
50  }
51 
52  CARL_LOG_ASSERT("carl.thom.evaluation", variables(p).size() == mTE.size(), "p = " << p << ", mTE = " << mTE);
53 
54  if(mTE.size() == 1) {
55  int sgn = int(mTE.begin()->second.signOnPolynomial(p));
56  CARL_LOG_TRACE("carl.thom.evaluation", "sign of evaluated polynomial is " << sgn);
57  return RealAlgebraicNumber<Number>(Number(sgn), false);
58  }
59 
60  CARL_LOG_TRACE("carl.thom.evaluation", "mTE = " << mTE);
61 
63  int sgn = int(point.signOnPolynomial(p));
64  CARL_LOG_TRACE("carl.thom.", "sign of evaluated polynomial is " << sgn);
65  return RealAlgebraicNumber<Number>(Number(sgn), false);
66 
67 // std::list<Polynomial> polynomials;
68 // std::list<Polynomial> derivatives;
69 // SignCondition sc;
70 // for(const auto& entry : mTE) {
71 // polynomials.push_front(entry.second.polynomial());
72 // std::list<Polynomial> der = entry.second.relevantDerivatives();
73 // derivatives.insert(derivatives.begin(), der.begin(), der.end());
74 // SignCondition relSign = entry.second.relevantSignCondition();
75 // sc.insert(sc.begin(), relSign.begin(), relSign.end());
76 // }
77 //
78 // CARL_LOG_TRACE("carl.thom.evaluation", "polynomials = " << polynomials);
79 // CARL_LOG_TRACE("carl.thom.evaluation", "derivatives = " << derivatives);
80 // CARL_LOG_TRACE("carl.thom.evaluation", "sc = " << sc);
81 //
82 // SignDetermination<Number> sd(polynomials.begin(), polynomials.end());
83 // sd.getSignsAndAddAll(derivatives.rbegin(), derivatives.rend());
84 // std::list<SignCondition> signConditions = sd.getSigns(p);
85 // CARL_LOG_TRACE("carl.thom.evaluation", "signConditions = " << signConditions);
86 // for(const auto sigma : signConditions) {
87 // if(sc.isSuffixOf(sigma)) {
88 // int sgn = (int)sigma.front();
89 // CARL_LOG_TRACE("carl.thom.", "sign of evaluated polynomial is " << sgn);
90 // return RealAlgebraicNumber<Number>((Number)sgn, false);
91 // }
92 // }
93 //
94 // CARL_LOG_ASSERT("carl.thom.evaluation", false, "we should never get here");
95 }
96 
97  /*
98  ThomEncoding<Number> point = std::max_element(m_prime.begin(), m_prime.end(),
99  [](const std::pair<Variable, RealAlgebraicNumber<Number>>& lhs, const std::pair<Variable, RealAlgebraicNumber<Number>>& rhs) {
100  return lhs.second.getThomEncoding().dimension() < rhs.second.getThomEncoding().dimension();
101  }
102  )->second.getThomEncoding();
103 
104  CARL_LOG_TRACE("carl.thom.evaluation", "point with max dimension: " << point);
105 
106  if(m.size() == 1) {
107  RealAlgebraicNumber<Number> ran = m.begin()->second;
108  assert(ran.isThom());
109  int sgn = (int)ran.getThomEncoding().signOnPolynomial(p);
110  CARL_LOG_TRACE("carl.thom.evaluation", "sign of evaluated polynomial is " << sgn);
111  return RealAlgebraicNumber<Number>((Number)sgn, false);
112 
113  }
114  else if(m.size() == 2) {
115  auto it = m.begin();
116  RealAlgebraicNumber<Number> ran1 = it->second;
117  it++;
118  RealAlgebraicNumber<Number> ran2 = it->second;
119  assert(ran1.getThomEncoding().point() == ran2.getThomEncoding());
120  int sgn = (int)ran1.getThomEncoding().signOnPolynomial(p);
121  CARL_LOG_TRACE("carl.thom.", "sign of evaluated polynomial is " << sgn);
122  return RealAlgebraicNumber<Number>((Number)sgn, false);
123  }
124  else {
125  assert(false);
126  return RealAlgebraicNumber<Number>();
127  }
128 } */
129 
130 } // namespace carl;
#define CARL_LOG_TRACE(channel, msg)
Definition: carl-logging.h:44
#define CARL_LOG_ASSERT(channel, condition, msg)
Definition: carl-logging.h:47
#define CARL_LOG_INFO(channel, msg)
Definition: carl-logging.h:42
carl is the main namespace for the library.
RealAlgebraicNumber< Number > evaluateTE(const MultivariatePolynomial< Number > &p, std::map< Variable, RealAlgebraicNumber< Number >> &m)
Sign sgn(const Number &n)
Obtain the sign of the given number.
Definition: Sign.h:54
void variables(const BasicConstraint< Pol > &c, carlVariables &vars)
A Variable represents an algebraic variable that can be used throughout carl.
Definition: Variable.h:85
Sign signOnPolynomial(const Polynomial &p) const
Definition: ThomEncoding.h:166
static ThomEncoding< Number > analyzeTEMap(const std::map< Variable, ThomEncoding< Number >> &m)
Definition: ThomEncoding.h:295