32#ifndef BERTINI_NODE_NUMBER_HPP
33#define BERTINI_NODE_NUMBER_HPP
70 int Degree(std::shared_ptr<Variable>
const& =
nullptr)
const override
95 return std::vector<int>(vars.size(), 0);
104 bool IsHomogeneous(std::shared_ptr<Variable>
const& =
nullptr)
const override
121 std::shared_ptr<Node>
Differentiate(std::shared_ptr<Variable>
const& v =
nullptr)
const override;
128 template <
typename Archive>
129 void serialize(Archive& ar,
const unsigned ) {
130 ar & boost::serialization::base_object<Symbol>(*
this);
157 void print(std::ostream & target) const override;
175 return true_value_ == 0;
180 return true_value_ == 1;
185 std::size_t h =
typeid(
Integer).hash_code();
186 HashCombine(h, std::hash<std::string>{}(true_value_.str()));
191 auto o =
dynamic_cast<Integer const*
>(&other);
192 return o && true_value_ == o->true_value_;
196 template<
typename... Ts>
198 std::shared_ptr<Integer>
Make(Ts&& ...ts){
199 return std::static_pointer_cast<Integer>(
Intern(std::shared_ptr<Node>(
new Integer(ts...) )));
207 Integer(
int val) : true_value_(val)
215 Integer(std::string
const& val) : true_value_(val)
228 template <
typename Archive>
229 void serialize(Archive& ar,
const unsigned ) {
230 ar & boost::serialization::base_object<Number>(*
this);
266 void print(std::ostream & target)
const override;
272 if (highest_precision_value_.imag() == 0 && highest_precision_value_.real() < 0)
282 return highest_precision_value_;
287 return highest_precision_value_.real() == 0 && highest_precision_value_.imag() == 0;
292 return highest_precision_value_.real() == 1 && highest_precision_value_.imag() == 0;
297 std::size_t h =
typeid(Complex).hash_code();
298 HashCombine(h, std::hash<std::string>{}(highest_precision_value_.real().str()));
299 HashCombine(h, std::hash<std::string>{}(highest_precision_value_.imag().str()));
304 auto o =
dynamic_cast<Complex const*
>(&other);
306 && highest_precision_value_.real() == o->highest_precision_value_.real()
307 && highest_precision_value_.imag() == o->highest_precision_value_.imag();
311 template<
typename... Ts>
313 std::shared_ptr<Complex>
Make(Ts&& ...ts){
314 return std::static_pointer_cast<Complex>(
Intern(std::shared_ptr<Node>(
new Complex(ts...) )));
324 Complex(
real_mp const& rval,
real_mp const& ival = 0) : highest_precision_value_(rval,ival)
328 Complex(std::string
const& val) : highest_precision_value_(val)
332 Complex(std::string
const& rval, std::string
const& ival) : highest_precision_value_(rval,ival)
346 Complex(std::string
const& rval, std::string
const& ival,
unsigned precision)
348 real_mp const re(rval, precision);
349 real_mp const im(ival, precision);
350 highest_precision_value_.precision(precision);
351 highest_precision_value_.real(re);
352 highest_precision_value_.imag(im);
361 template <
typename Archive>
362 void serialize(Archive& ar,
const unsigned ) {
363 ar & boost::serialization::base_object<Number>(*
this);
364 ar &
const_cast<complex_mp &
>(highest_precision_value_);
397 template<
unsigned long Digits = 50>
409 template<
int Digits = 50>
416 void print(std::ostream & target)
const override;
424 if (true_value_imag_ == 0)
426 if (true_value_real_ < 0)
428 if (denominator(true_value_real_) != 1)
439 return true_value_real_;
447 return true_value_imag_;
458 template<
typename NumT>
461 if constexpr (std::is_same<NumT, complex_dbl>::value)
462 return complex_dbl(
double(true_value_real_),
double(true_value_imag_));
464 return NumT(boost::multiprecision::mpfr_float(true_value_real_,
ThreadPrecision()),
465 boost::multiprecision::mpfr_float(true_value_imag_,
ThreadPrecision()));
470 return true_value_real_ == 0 && true_value_imag_ == 0;
475 return true_value_real_ == 1 && true_value_imag_ == 0;
480 std::size_t h =
typeid(
Rational).hash_code();
481 HashCombine(h, std::hash<std::string>{}(true_value_real_.str()));
482 HashCombine(h, std::hash<std::string>{}(true_value_imag_.str()));
487 auto o =
dynamic_cast<Rational const*
>(&other);
488 return o && true_value_real_ == o->true_value_real_ && true_value_imag_ == o->true_value_imag_;
494 template<
typename... Ts>
496 std::shared_ptr<Rational>
Make(Ts&& ...ts){
497 return std::static_pointer_cast<Rational>(
Intern(std::shared_ptr<Node>(
new Rational(ts...) )));
503 Rational(
int val) : true_value_real_(val), true_value_imag_(0)
507 Rational(
int val_real_numerator,
int val_real_denomenator,
508 int val_imag_numerator,
int val_imag_denomenator)
510 true_value_real_(val_real_numerator,val_real_denomenator), true_value_imag_(val_imag_numerator,val_imag_denomenator)
514 Rational(std::string val) : true_value_real_(val), true_value_imag_(0)
518 Rational(std::string val_real, std::string val_imag) : true_value_real_(val_real), true_value_imag_(val_imag)
532 template <
typename Archive>
533 void serialize(Archive& ar,
const unsigned ) {
534 ar & boost::serialization::base_object<Number>(*
this);
A complex-number literal node in an expression tree.
Definition number.hpp:254
static std::shared_ptr< Complex > Make(Ts &&...ts)
Construct (and intern) a Complex node.
Definition number.hpp:313
complex_mp const & GetValue() const
Get the literal value this node represents, at its stored (highest) precision.
Definition number.hpp:280
bool IsLiteralZero() const override
Is this node the literal constant 0?
Definition number.hpp:285
bool IsSame(Node const &other) const override
Order-sensitive structural equality, shallow given interned children.
Definition number.hpp:302
void print(std::ostream &target) const override
Virtual method for printing Nodes to arbitrary output streams.
unsigned Precedence() const override
The printing precedence of this node, deciding parenthesization.
Definition number.hpp:270
bool IsLiteralOne() const override
Is this node the literal constant 1?
Definition number.hpp:290
friend class boost::serialization::access
Definition number.hpp:359
std::size_t HashImpl() const override
Compute this node's structural hash.
Definition number.hpp:295
static std::shared_ptr< Integer > Make(Ts &&...ts)
Construct (and intern) a Integer node.
Definition number.hpp:198
std::size_t HashImpl() const override
Compute this node's structural hash.
Definition number.hpp:183
mpz_int const & GetValue() const
Get the literal value this node represents.
Definition number.hpp:168
bool IsLiteralOne() const override
Is this node the literal constant 1?
Definition number.hpp:178
unsigned Precedence() const override
The printing precedence of this node, deciding parenthesization.
Definition number.hpp:160
void print(std::ostream &target) const override
Virtual method for printing Nodes to arbitrary output streams.
friend class boost::serialization::access
Definition number.hpp:224
bool IsSame(Node const &other) const override
Order-sensitive structural equality, shallow given interned children.
Definition number.hpp:189
Integer(Integer const &)=default
Defaulted copy constructor.
bool IsLiteralZero() const override
Is this node the literal constant 0?
Definition number.hpp:173
An interface for all nodes in a function tree, and for a function object as well.
Definition node.hpp:114
static void HashCombine(std::size_t &seed, std::size_t value)
Combine an extra value into a running hash (boost::hash_combine recipe).
Definition node.hpp:384
Abstract Number type from which other Numbers derive.
Definition number.hpp:50
int Degree(VariableGroup const &) const override
Get the degree of this node.
Definition number.hpp:81
bool IsHomogeneous(VariableGroup const &) const override
Check for homogeneity, with respect to a variable group.
Definition number.hpp:112
bool IsHomogeneous(std::shared_ptr< Variable > const &=nullptr) const override
Is this node homogeneous?
Definition number.hpp:104
int Degree(std::shared_ptr< Variable > const &=nullptr) const override
Get the degree of this node.
Definition number.hpp:70
std::vector< int > MultiDegreeImpl(VariableGroup const &vars) const override
Get the multidegree of this node.
Definition number.hpp:93
virtual ~Number()=default
friend class boost::serialization::access
Definition number.hpp:126
std::shared_ptr< Node > Differentiate(std::shared_ptr< Variable > const &v=nullptr) const override
Differentiate a number.
void print(std::ostream &target) const override
Virtual method for printing Nodes to arbitrary output streams.
Rational(int, int)=delete
unsigned Precedence() const override
The printing precedence of this node, deciding parenthesization.
Definition number.hpp:422
bool IsLiteralZero() const override
Is this node the literal constant 0?
Definition number.hpp:468
bool IsSame(Node const &other) const override
Order-sensitive structural equality, shallow given interned children.
Definition number.hpp:485
static std::shared_ptr< Rational > Make(Ts &&...ts)
Construct (and intern) a Rational node.
Definition number.hpp:496
std::size_t HashImpl() const override
Compute this node's structural hash.
Definition number.hpp:478
bool IsLiteralOne() const override
Is this node the literal constant 1?
Definition number.hpp:473
friend class boost::serialization::access
Definition number.hpp:530
static Rational Rand()
Get a random complex rational node.
Definition number.hpp:399
mpq_rational const & GetValueReal() const
Get the real part of the literal value this node represents.
Definition number.hpp:437
mpq_rational const & GetValueImag() const
Get the imaginary part of the literal value this node represents.
Definition number.hpp:445
static Rational RandReal()
Get a random real rational node.
Definition number.hpp:411
NumT Value() const
Get this exact constant as a number of type NumT, independent of the evaluation engine.
Definition number.hpp:459
bertini::mpq_rational mpq_rational
The exact rational type this node stores.
Definition number.hpp:383
Abstract symbol class.
Definition symbol.hpp:47
Definition canonical.hpp:56
std::shared_ptr< Node > Intern(std::shared_ptr< Node > const &candidate)
Hash-cons a freshly-built node: return an existing structurally-equal node if one is live,...
@ PrecAtom
Definition node.hpp:101
@ PrecNegate
Definition node.hpp:98
@ PrecMult
Definition node.hpp:99
Definition algorithm_builder.hpp:36
std::complex< double > complex_dbl
The double-precision complex number type.
Definition double_extensions.hpp:47
boost::multiprecision::number< boost::multiprecision::backends::gmp_int, boost::multiprecision::et_on > mpz_int
The arbitrary-precision integer type.
Definition mpfr_extensions.hpp:54
std::vector< std::shared_ptr< node::Variable > > VariableGroup
An ordered group of variables (the unit of homogenization / variable grouping).
Definition node.hpp:69
bmp::number< mpc_complex_backend< 0 >, bmp::et_on > complex_mp
The arbitrary-precision complex number type.
Definition mpfr_complex.hpp:58
boost::multiprecision::number< boost::multiprecision::mpfr_float_backend< 0 >, boost::multiprecision::et_on > real_mp
The arbitrary-precision real number type.
Definition mpfr_extensions.hpp:53
unsigned ThreadPrecision()
Get the current thread's precision (digits).
Definition mpfr_complex.hpp:183
mpq_rational RandomRat()
Generate a random rational number with numerator and denomenator between -10^digits and 10^digits.
Definition random.hpp:141
Defines the abstract Symbol and NamedSymbol classes,.
#define BERTINI_DEFAULT_VISITABLE()
macro for classes which want default Accept implementation, having nothing fancy to do when accepting...
Definition visitable.hpp:121