carl  24.04
Computer ARithmetic Library
RealRoots.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <type_traits>
4 #include <variant>
5 #include <vector>
6 
7 namespace carl {
8 
9 template<typename RAN /*, typename = std::enable_if_t<is_ran_type<RAN>::value> */>
11 
12 public:
13  using roots_t = std::vector<RAN>;
14 
15 private:
16  struct nullified_t {};
17  struct non_univariate_t {};
18  std::variant<roots_t, nullified_t, non_univariate_t> m_data;
19 
21  : m_data(nullified_t{}){};
23  : m_data(non_univariate_t{}){};
25  : m_data(std::move(real_roots)){};
26 
27 public:
29  return RealRootsResult(nullified_t{});
30  }
33  }
35  return RealRootsResult(std::move(real_roots));
36  }
38  return RealRootsResult(std::vector<RAN>({}));
39  }
40 
41  bool is_nullified() const {
42  return std::holds_alternative<nullified_t>(m_data);
43  }
44 
45  bool is_univariate() const {
46  return std::holds_alternative<roots_t>(m_data);
47  }
48 
49  bool is_non_univariate() const {
50  return std::holds_alternative<non_univariate_t>(m_data);
51  }
52 
53  const roots_t& roots() const {
54  return std::get<roots_t>(m_data);
55  }
56 };
57 
58 }
carl is the main namespace for the library.
RealRootsResult< IntRepRealAlgebraicNumber< Number > > real_roots(const UnivariatePolynomial< Coeff > &polynomial, const Interval< Number > &interval=Interval< Number >::unbounded_interval())
Find all real roots of a univariate 'polynomial' with numeric coefficients within a given 'interval'.
Definition: RealRoots.h:25
RealRootsResult(roots_t &&real_roots)
Definition: RealRoots.h:24
std::variant< roots_t, nullified_t, non_univariate_t > m_data
Definition: RealRoots.h:18
RealRootsResult(nullified_t)
Definition: RealRoots.h:20
bool is_nullified() const
Definition: RealRoots.h:41
static RealRootsResult nullified_response()
Definition: RealRoots.h:28
RealRootsResult(non_univariate_t)
Definition: RealRoots.h:22
const roots_t & roots() const
Definition: RealRoots.h:53
static RealRootsResult non_univariate_response()
Definition: RealRoots.h:31
std::vector< RAN > roots_t
Definition: RealRoots.h:13
bool is_non_univariate() const
Definition: RealRoots.h:49
bool is_univariate() const
Definition: RealRoots.h:45
static RealRootsResult roots_response(roots_t &&real_roots)
Definition: RealRoots.h:34
static RealRootsResult no_roots_response()
Definition: RealRoots.h:37