#include "base/cvc5config.h"
#include "util/real_algebraic_number.h"
-#ifndef CVC5_POLY_IMP // Make sure this comes after base/cvc5config.h
-#error "This source should only ever be built if CVC5_POLY_IMP is on!"
-#endif /* CVC5_POLY_IMP */
-
+#ifdef CVC5_POLY_IMP
#include <poly/polyxx.h>
+#endif
#include <limits>
namespace cvc5 {
+#ifdef CVC5_POLY_IMP
RealAlgebraicNumber::RealAlgebraicNumber(poly::AlgebraicNumber&& an)
: d_value(std::move(an))
{
}
+#endif
RealAlgebraicNumber::RealAlgebraicNumber(const Integer& i)
+#ifdef CVC5_POLY_IMP
: d_value(poly::DyadicRational(poly_utils::toInteger(i)))
+#endif
{
+#ifndef CVC5_POLY_IMP
+ RAN_UNREACHABLE;
+#endif
}
RealAlgebraicNumber::RealAlgebraicNumber(const Rational& r)
{
+#ifdef CVC5_POLY_IMP
poly::Rational pr = poly_utils::toRational(r);
auto dr = poly_utils::toDyadicRational(r);
if (dr)
poly::UPolynomial({numerator(pr), -denominator(pr)}),
poly::DyadicInterval(floor(pr), ceil(pr)));
}
+#else
+ RAN_UNREACHABLE;
+#endif
}
RealAlgebraicNumber::RealAlgebraicNumber(const std::vector<long>& coefficients,
"constructor based on Integer instead.";
}
#endif
+#ifdef CVC5_POLY_IMP
d_value = poly::AlgebraicNumber(poly::UPolynomial(coefficients),
poly::DyadicInterval(lower, upper));
+#else
+ RAN_UNREACHABLE;
+#endif
}
RealAlgebraicNumber::RealAlgebraicNumber(
const Rational& lower,
const Rational& upper)
{
+#ifdef CVC5_POLY_IMP
*this = poly_utils::toRanWithRefinement(
poly::UPolynomial(poly_utils::toInteger(coefficients)), lower, upper);
+#endif
}
RealAlgebraicNumber::RealAlgebraicNumber(
const std::vector<Rational>& coefficients,
const Rational& lower,
const Rational& upper)
{
+#ifdef CVC5_POLY_IMP
Integer factor = Integer(1);
for (const auto& c : coefficients)
{
}
*this = poly_utils::toRanWithRefinement(
poly::UPolynomial(std::move(coeffs)), lower, upper);
+#else
+ RAN_UNREACHABLE;
+#endif
}
bool RealAlgebraicNumber::isRational() const
std::ostream& operator<<(std::ostream& os, const RealAlgebraicNumber& ran)
{
+#ifdef CVC5_POLY_IMP
return os << ran.getValue();
+#else
+ RAN_UNREACHABLE;
+ return os;
+#endif
}
bool operator==(const RealAlgebraicNumber& lhs, const RealAlgebraicNumber& rhs)
{
+#ifdef CVC5_POLY_IMP
return lhs.getValue() == rhs.getValue();
+#else
+ RAN_UNREACHABLE;
+ return true;
+#endif
}
bool operator!=(const RealAlgebraicNumber& lhs, const RealAlgebraicNumber& rhs)
{
+#ifdef CVC5_POLY_IMP
return lhs.getValue() != rhs.getValue();
+#else
+ RAN_UNREACHABLE;
+ return false;
+#endif
}
bool operator<(const RealAlgebraicNumber& lhs, const RealAlgebraicNumber& rhs)
{
+#ifdef CVC5_POLY_IMP
return lhs.getValue() < rhs.getValue();
+#else
+ RAN_UNREACHABLE;
+ return false;
+#endif
}
bool operator<=(const RealAlgebraicNumber& lhs, const RealAlgebraicNumber& rhs)
{
+#ifdef CVC5_POLY_IMP
return lhs.getValue() <= rhs.getValue();
+#else
+ RAN_UNREACHABLE;
+ return true;
+#endif
}
bool operator>(const RealAlgebraicNumber& lhs, const RealAlgebraicNumber& rhs)
{
+#ifdef CVC5_POLY_IMP
return lhs.getValue() > rhs.getValue();
+#else
+ RAN_UNREACHABLE;
+ return false;
+#endif
}
bool operator>=(const RealAlgebraicNumber& lhs, const RealAlgebraicNumber& rhs)
{
+#ifdef CVC5_POLY_IMP
return lhs.getValue() >= rhs.getValue();
+#else
+ RAN_UNREACHABLE;
+ return true;
+#endif
}
RealAlgebraicNumber operator+(const RealAlgebraicNumber& lhs,
const RealAlgebraicNumber& rhs)
{
+#ifdef CVC5_POLY_IMP
return lhs.getValue() + rhs.getValue();
+#else
+ RAN_UNREACHABLE;
+ return lhs;
+#endif
}
RealAlgebraicNumber operator-(const RealAlgebraicNumber& lhs,
const RealAlgebraicNumber& rhs)
{
+#ifdef CVC5_POLY_IMP
return lhs.getValue() - rhs.getValue();
+#else
+ RAN_UNREACHABLE;
+ return lhs;
+#endif
}
RealAlgebraicNumber operator-(const RealAlgebraicNumber& ran)
{
+#ifdef CVC5_POLY_IMP
return -ran.getValue();
+#else
+ RAN_UNREACHABLE;
+ return ran;
+#endif
}
RealAlgebraicNumber operator*(const RealAlgebraicNumber& lhs,
const RealAlgebraicNumber& rhs)
{
+#ifdef CVC5_POLY_IMP
return lhs.getValue() * rhs.getValue();
+#else
+ RAN_UNREACHABLE;
+ return lhs;
+#endif
}
RealAlgebraicNumber operator/(const RealAlgebraicNumber& lhs,
const RealAlgebraicNumber& rhs)
RealAlgebraicNumber& operator+=(RealAlgebraicNumber& lhs,
const RealAlgebraicNumber& rhs)
{
+#ifdef CVC5_POLY_IMP
lhs.getValue() = lhs.getValue() + rhs.getValue();
+#else
+ RAN_UNREACHABLE;
+#endif
return lhs;
}
RealAlgebraicNumber& operator-=(RealAlgebraicNumber& lhs,
const RealAlgebraicNumber& rhs)
{
+#ifdef CVC5_POLY_IMP
lhs.getValue() = lhs.getValue() - rhs.getValue();
+#else
+ RAN_UNREACHABLE;
+#endif
return lhs;
}
RealAlgebraicNumber& operator*=(RealAlgebraicNumber& lhs,
const RealAlgebraicNumber& rhs)
{
+#ifdef CVC5_POLY_IMP
lhs.getValue() = lhs.getValue() * rhs.getValue();
+#else
+ RAN_UNREACHABLE;
+#endif
return lhs;
}
-int sgn(const RealAlgebraicNumber& ran) { return sgn(ran.getValue()); }
-bool isZero(const RealAlgebraicNumber& ran) { return is_zero(ran.getValue()); }
-bool isOne(const RealAlgebraicNumber& ran) { return is_one(ran.getValue()); }
+int sgn(const RealAlgebraicNumber& ran) {
+#ifdef CVC5_POLY_IMP
+ return sgn(ran.getValue());
+#else
+ RAN_UNREACHABLE;
+ return ran;
+#endif
+}
+bool isZero(const RealAlgebraicNumber& ran) {
+#ifdef CVC5_POLY_IMP
+ return is_zero(ran.getValue());
+#else
+ return ran;
+#endif
+}
+bool isOne(const RealAlgebraicNumber& ran) {
+#ifdef CVC5_POLY_IMP
+ return is_one(ran.getValue());
+#else
+ RAN_UNREACHABLE;
+ return ran;
+#endif
+}
RealAlgebraicNumber inverse(const RealAlgebraicNumber& ran)
{
#ifdef CVC5_POLY_IMP
#include <vector>
+#ifdef CVC5_POLY_IMP
#include <poly/polyxx.h>
+#endif
#include "util/integer.h"
#include "util/rational.h"
public:
/** Construct as zero. */
RealAlgebraicNumber() = default;
+#ifdef CVC5_POLY_IMP
/** Move from a poly::AlgebraicNumber type. */
RealAlgebraicNumber(poly::AlgebraicNumber&& an);
+#endif
/** Copy from an Integer. */
RealAlgebraicNumber(const Integer& i);
/** Copy from a Rational. */
/** Move assignment. */
RealAlgebraicNumber& operator=(RealAlgebraicNumber&& ran) = default;
+#ifdef CVC5_POLY_IMP
/** Get the internal value as a const reference. */
const poly::AlgebraicNumber& getValue() const { return d_value; }
/** Get the internal value as a non-const reference. */
poly::AlgebraicNumber& getValue() { return d_value; }
+#endif
/**
* Check if this real algebraic number is actually rational.
/**
* Stores the actual real algebraic number.
*/
+#ifdef CVC5_POLY_IMP
poly::AlgebraicNumber d_value;
+#endif
}; /* class RealAlgebraicNumber */
/** Stream a real algebraic number to an output stream. */