Add files
This commit is contained in:
171
core/include/bertini2/function_tree/symbols/differential.hpp
Normal file
171
core/include/bertini2/function_tree/symbols/differential.hpp
Normal file
@@ -0,0 +1,171 @@
|
||||
//This file is part of Bertini 2.
|
||||
//
|
||||
//differential.hpp is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
//
|
||||
//differential.hpp is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU General Public License for more details.
|
||||
//
|
||||
//You should have received a copy of the GNU General Public License
|
||||
//along with differential.hpp. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright(C) 2015 - 2021 by Bertini2 Development Team
|
||||
//
|
||||
// See <http://www.gnu.org/licenses/> for a copy of the license,
|
||||
// as well as COPYING. Bertini2 is provided with permitted
|
||||
// additional terms in the b2/licenses/ directory.
|
||||
|
||||
// individual authors of this file include:
|
||||
// James Collins
|
||||
// West Texas A&M University
|
||||
// Spring, Summer 2015
|
||||
//
|
||||
// silviana amethyst, university of wisconsin-eau claire
|
||||
//
|
||||
// Created by Collins, James B. on 4/30/15.
|
||||
//
|
||||
//
|
||||
// differential.hpp: Declares the class SpecialNumber.
|
||||
|
||||
/**
|
||||
\file differential.hpp
|
||||
|
||||
\brief Provides the differential Node class.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef BERTINI_NODE_DIFFERENTIAL_HPP
|
||||
#define BERTINI_NODE_DIFFERENTIAL_HPP
|
||||
|
||||
#include <memory>
|
||||
#include "bertini2/function_tree/node.hpp"
|
||||
#include "bertini2/function_tree/symbols/symbol.hpp"
|
||||
#include "bertini2/function_tree/symbols/number.hpp"
|
||||
|
||||
|
||||
|
||||
namespace bertini {
|
||||
namespace node{
|
||||
class Variable;
|
||||
|
||||
|
||||
/**
|
||||
\brief Provides the differential type for differentiation of expression trees.
|
||||
|
||||
This class represents differentials. These are produced in the course of differentiation of a non-constant expression tree.
|
||||
*/
|
||||
class Differential : public virtual NamedSymbol, public virtual EnableSharedFromThisVirtual<Differential>
|
||||
{
|
||||
public:
|
||||
BERTINI_DEFAULT_VISITABLE()
|
||||
|
||||
|
||||
template<typename... Ts>
|
||||
static
|
||||
std::shared_ptr<Differential> Make(Ts&& ...ts){
|
||||
return std::shared_ptr<Differential>( new Differential(ts...) );
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
/**
|
||||
Input shared_ptr to a Variable.
|
||||
*/
|
||||
Differential(std::shared_ptr<const Variable> diff_variable, std::string var_name);
|
||||
|
||||
public:
|
||||
|
||||
void Reset() const override;
|
||||
|
||||
|
||||
const std::shared_ptr<const Variable>& GetVariable() const;
|
||||
|
||||
|
||||
void print(std::ostream & target) const override;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Differentiates a number.
|
||||
*/
|
||||
std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const override;
|
||||
|
||||
virtual ~Differential() = default;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Compute the degree with respect to a single variable. For differentials, the degree is 0.
|
||||
*/
|
||||
int Degree(std::shared_ptr<Variable> const& v = nullptr) const override;
|
||||
|
||||
int Degree(VariableGroup const& vars) const override;
|
||||
|
||||
std::vector<int> MultiDegree(VariableGroup const& vars) const override;
|
||||
|
||||
void Homogenize(VariableGroup const& vars, std::shared_ptr<Variable> const& homvar) override;
|
||||
|
||||
bool IsHomogeneous(std::shared_ptr<Variable> const& v = nullptr) const override;
|
||||
|
||||
/**
|
||||
Check for homogeneity, with respect to a variable group.
|
||||
*/
|
||||
bool IsHomogeneous(VariableGroup const& vars) const override;
|
||||
|
||||
|
||||
/**
|
||||
Change the precision of this variable-precision tree node.
|
||||
|
||||
\param prec the number of digits to change precision to.
|
||||
*/
|
||||
void precision(unsigned int prec) const override;
|
||||
|
||||
|
||||
protected:
|
||||
// This should never be called for a Differential. Only for Jacobians.
|
||||
dbl FreshEval_d(std::shared_ptr<Variable> const& diff_variable) const override;
|
||||
|
||||
void FreshEval_d(dbl& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override;
|
||||
|
||||
|
||||
mpfr_complex FreshEval_mp(std::shared_ptr<Variable> const& diff_variable) const override;
|
||||
|
||||
void FreshEval_mp(mpfr_complex& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override;
|
||||
|
||||
|
||||
|
||||
private:
|
||||
Differential() = default;
|
||||
std::shared_ptr<const Variable> differential_variable_;
|
||||
|
||||
|
||||
friend class boost::serialization::access;
|
||||
|
||||
template<class Archive>
|
||||
void save(Archive & ar, const unsigned int version) const
|
||||
{
|
||||
ar & boost::serialization::base_object<NamedSymbol>(*this);
|
||||
ar & differential_variable_;
|
||||
// ar & const_cast<std::shared_ptr<const Variable> >(differential_variable_);
|
||||
}
|
||||
|
||||
template<class Archive>
|
||||
void load(Archive & ar, const unsigned int version)
|
||||
{
|
||||
ar & boost::serialization::base_object<NamedSymbol>(*this);
|
||||
ar & std::const_pointer_cast<Variable>(differential_variable_);
|
||||
}
|
||||
|
||||
// BOOST_SERIALIZATION_SPLIT_MEMBER()
|
||||
|
||||
};
|
||||
|
||||
} // re: namespace node
|
||||
} // re: namespace bertini
|
||||
|
||||
#endif
|
||||
1126
core/include/bertini2/function_tree/symbols/linear_product.hpp
Normal file
1126
core/include/bertini2/function_tree/symbols/linear_product.hpp
Normal file
File diff suppressed because it is too large
Load Diff
427
core/include/bertini2/function_tree/symbols/number.hpp
Executable file
427
core/include/bertini2/function_tree/symbols/number.hpp
Executable file
@@ -0,0 +1,427 @@
|
||||
//This file is part of Bertini 2.
|
||||
//
|
||||
//number.hpp is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
//
|
||||
//number.hpp is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU General Public License for more details.
|
||||
//
|
||||
//You should have received a copy of the GNU General Public License
|
||||
//along with number.hpp. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright(C) 2015 - 2023 by Bertini2 Development Team
|
||||
//
|
||||
// See <http://www.gnu.org/licenses/> for a copy of the license,
|
||||
// as well as COPYING. Bertini2 is provided with permitted
|
||||
// additional terms in the b2/licenses/ directory.
|
||||
|
||||
// individual authors of this file include:
|
||||
// James Collins
|
||||
// West Texas A&M University
|
||||
// Spring, Summer 2015
|
||||
//
|
||||
//
|
||||
// silviana amethyst
|
||||
// University of Wisconsin - Eau Claire
|
||||
//
|
||||
// Created by Collins, James B. on 4/30/15.
|
||||
//
|
||||
//
|
||||
// number.hpp: Declares the class Number.
|
||||
|
||||
/**
|
||||
\file number.hpp
|
||||
|
||||
\brief Provides the Number Node types, including Rational, Float, and Integer
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#ifndef BERTINI_NODE_NUMBER_HPP
|
||||
#define BERTINI_NODE_NUMBER_HPP
|
||||
|
||||
|
||||
#include "bertini2/function_tree/symbols/symbol.hpp"
|
||||
|
||||
|
||||
|
||||
namespace bertini {
|
||||
namespace node{
|
||||
|
||||
|
||||
/**
|
||||
\brief Abstract Number type from which other Numbers derive.
|
||||
|
||||
This class represents constant leaves to a function tree. FreshEval simply returns
|
||||
the value of the constant.
|
||||
*/
|
||||
class Number : public virtual Symbol
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~Number() = default;
|
||||
|
||||
|
||||
|
||||
void Reset() const override;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
\brief Get the degree of this node.
|
||||
|
||||
The degree of a number is always 0. It's a number.
|
||||
*/
|
||||
inline
|
||||
int Degree(std::shared_ptr<Variable> const& v = nullptr) const override
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Get the degree of this node.
|
||||
|
||||
The degree of a number is always 0. It's a number.
|
||||
*/
|
||||
inline
|
||||
int Degree(VariableGroup const& vars) const override
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
\brief Get the multidegree of this node.
|
||||
|
||||
The degree of a number is always 0. It's a number.
|
||||
*/
|
||||
inline
|
||||
std::vector<int> MultiDegree(VariableGroup const& vars) const override
|
||||
{
|
||||
return std::vector<int>(vars.size(), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Homogenize this node.
|
||||
|
||||
Homogenization of a number is a trivial operation. Don't do anything.
|
||||
*/
|
||||
void Homogenize(VariableGroup const& vars, std::shared_ptr<Variable> const& homvar) override
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Is this node homogeneous?
|
||||
|
||||
Numbers are always homogeneous
|
||||
*/
|
||||
bool IsHomogeneous(std::shared_ptr<Variable> const& v = nullptr) const override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
Check for homogeneity, with respect to a variable group.
|
||||
*/
|
||||
bool IsHomogeneous(VariableGroup const& vars) const override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Change the precision of this variable-precision tree node.
|
||||
|
||||
\param prec the number of digits to change precision to.
|
||||
*/
|
||||
void precision(unsigned int prec) const override;
|
||||
|
||||
/**
|
||||
\brief Differentiate a number.
|
||||
*/
|
||||
std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const override;
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
friend class boost::serialization::access;
|
||||
|
||||
template <typename Archive>
|
||||
void serialize(Archive& ar, const unsigned version) {
|
||||
ar & boost::serialization::base_object<Symbol>(*this);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
\brief Signed real Integer storage in an expression tree.
|
||||
|
||||
Signed real Integer storage in an expression tree. Consider using a Rational type.
|
||||
*/
|
||||
class Integer : public virtual Number, public virtual EnableSharedFromThisVirtual<Integer>
|
||||
{
|
||||
public:
|
||||
BERTINI_DEFAULT_VISITABLE()
|
||||
|
||||
|
||||
|
||||
Integer(Integer const&) = default;
|
||||
|
||||
~Integer() = default;
|
||||
|
||||
|
||||
|
||||
|
||||
void print(std::ostream & target) const override;
|
||||
|
||||
template<typename... Ts>
|
||||
static
|
||||
std::shared_ptr<Integer> Make(Ts&& ...ts){
|
||||
return std::shared_ptr<Integer>( new Integer(ts...) );
|
||||
}
|
||||
|
||||
private:
|
||||
// https://stackoverflow.com/questions/33933550/exception-bad-weak-ptr-while-shared-from-this
|
||||
// struct MakeConstructorPublic;
|
||||
|
||||
explicit
|
||||
Integer(int val) : true_value_(val)
|
||||
{}
|
||||
|
||||
explicit
|
||||
Integer(mpz_int val) : true_value_(val)
|
||||
{}
|
||||
|
||||
explicit
|
||||
Integer(std::string const& val) : true_value_(val)
|
||||
{}
|
||||
|
||||
|
||||
|
||||
// Return value of constant
|
||||
dbl FreshEval_d(std::shared_ptr<Variable> const& diff_variable) const override;
|
||||
|
||||
void FreshEval_d(dbl& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override;
|
||||
|
||||
|
||||
mpfr_complex FreshEval_mp(std::shared_ptr<Variable> const& diff_variable) const override;
|
||||
|
||||
void FreshEval_mp(mpfr_complex& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override;
|
||||
|
||||
|
||||
mpz_int true_value_;
|
||||
|
||||
friend class boost::serialization::access;
|
||||
|
||||
Integer() = default;
|
||||
|
||||
template <typename Archive>
|
||||
void serialize(Archive& ar, const unsigned version) {
|
||||
ar & boost::serialization::base_object<Number>(*this);
|
||||
ar & true_value_;
|
||||
}
|
||||
};
|
||||
|
||||
// struct Integer::MakeConstructorPublic : public Integer {
|
||||
// template <typename... Args>
|
||||
// MakeConstructorPublic(Args&& ...args) : Integer(std::forward<Args>(args)...)
|
||||
// {}
|
||||
// };
|
||||
|
||||
|
||||
|
||||
/**
|
||||
\brief Number type for storing floating point numbers within an expression tree.
|
||||
|
||||
Number type for storing floating point numbers within an expression tree. The number passed in at construct time is stored as the true value, and evaluation down or up samples from this 'true value'. Consider using a Rational or Integer if possible.
|
||||
*/
|
||||
class Float : public virtual Number, public virtual EnableSharedFromThisVirtual<Float>
|
||||
{
|
||||
public:
|
||||
BERTINI_DEFAULT_VISITABLE()
|
||||
|
||||
|
||||
|
||||
~Float() = default;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void print(std::ostream & target) const override;
|
||||
|
||||
|
||||
template<typename... Ts>
|
||||
static
|
||||
std::shared_ptr<Float> Make(Ts&& ...ts){
|
||||
return std::shared_ptr<Float>( new Float(ts...) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
explicit
|
||||
Float(mpfr_complex const& val) : highest_precision_value_(val)
|
||||
{}
|
||||
|
||||
explicit
|
||||
Float(mpfr_float const& rval, mpfr_float const& ival = 0) : highest_precision_value_(rval,ival)
|
||||
{}
|
||||
|
||||
explicit
|
||||
Float(std::string const& val) : highest_precision_value_(val)
|
||||
{}
|
||||
|
||||
explicit
|
||||
Float(std::string const& rval, std::string const& ival) : highest_precision_value_(rval,ival)
|
||||
{}
|
||||
|
||||
dbl FreshEval_d(std::shared_ptr<Variable> const& diff_variable) const override;
|
||||
|
||||
void FreshEval_d(dbl& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override;
|
||||
|
||||
|
||||
mpfr_complex FreshEval_mp(std::shared_ptr<Variable> const& diff_variable) const override;
|
||||
|
||||
void FreshEval_mp(mpfr_complex& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override;
|
||||
|
||||
|
||||
mpfr_complex highest_precision_value_;
|
||||
|
||||
friend class boost::serialization::access;
|
||||
Float() = default;
|
||||
template <typename Archive>
|
||||
void serialize(Archive& ar, const unsigned version) {
|
||||
ar & boost::serialization::base_object<Number>(*this);
|
||||
ar & const_cast<mpfr_complex &>(highest_precision_value_);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
\brief The Rational number type for Bertini2 expression trees.
|
||||
|
||||
The Rational number type for Bertini2 expression trees. The `true value' is stored using two mpq_rational numbers from the Boost.Multiprecision library, and the ratio is converted into a double or a mpfr_complex at evaluate time.
|
||||
*/
|
||||
class Rational : public virtual Number, public virtual EnableSharedFromThisVirtual<Rational>
|
||||
{
|
||||
public:
|
||||
BERTINI_DEFAULT_VISITABLE()
|
||||
|
||||
using mpq_rational = bertini::mpq_rational;
|
||||
|
||||
|
||||
|
||||
|
||||
Rational(int, int) = delete;
|
||||
|
||||
~Rational() = default;
|
||||
|
||||
/**
|
||||
\brief Get a random complex rational node. Numerator and denominator will have about 50 digits.
|
||||
|
||||
\see RandomRat()
|
||||
*/
|
||||
template<unsigned long Digits = 50>
|
||||
static
|
||||
Rational Rand()
|
||||
{
|
||||
return Rational(RandomRat<Digits>(),RandomRat<Digits>());
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Get a random real rational node. Numerator and denominator will have about 50 digits.
|
||||
|
||||
\see RandomRat()
|
||||
*/
|
||||
template<int Digits = 50>
|
||||
static
|
||||
Rational RandReal()
|
||||
{
|
||||
return Rational(RandomRat<Digits>(),0);
|
||||
}
|
||||
|
||||
void print(std::ostream & target) const override;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename... Ts>
|
||||
static
|
||||
std::shared_ptr<Rational> Make(Ts&& ...ts){
|
||||
return std::shared_ptr<Rational>( new Rational(ts...) );
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
explicit
|
||||
Rational(int val) : true_value_real_(val), true_value_imag_(0)
|
||||
{}
|
||||
|
||||
explicit
|
||||
Rational(int val_real_numerator, int val_real_denomenator,
|
||||
int val_imag_numerator, int val_imag_denomenator)
|
||||
:
|
||||
true_value_real_(val_real_numerator,val_real_denomenator), true_value_imag_(val_imag_numerator,val_imag_denomenator)
|
||||
{}
|
||||
|
||||
explicit
|
||||
Rational(std::string val) : true_value_real_(val), true_value_imag_(0)
|
||||
{}
|
||||
|
||||
explicit
|
||||
Rational(std::string val_real, std::string val_imag) : true_value_real_(val_real), true_value_imag_(val_imag)
|
||||
{}
|
||||
|
||||
explicit
|
||||
Rational(mpq_rational const& val_real, mpq_rational const& val_imag = 0) : true_value_real_(val_real), true_value_imag_(val_imag)
|
||||
{}
|
||||
|
||||
|
||||
// Return value of constant
|
||||
dbl FreshEval_d(std::shared_ptr<Variable> const& diff_variable) const override;
|
||||
|
||||
void FreshEval_d(dbl& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override;
|
||||
|
||||
|
||||
mpfr_complex FreshEval_mp(std::shared_ptr<Variable> const& diff_variable) const override;
|
||||
|
||||
void FreshEval_mp(mpfr_complex& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override;
|
||||
|
||||
|
||||
mpq_rational true_value_real_, true_value_imag_;
|
||||
Rational() = default;
|
||||
friend class boost::serialization::access;
|
||||
|
||||
template <typename Archive>
|
||||
void serialize(Archive& ar, const unsigned version) {
|
||||
ar & boost::serialization::base_object<Number>(*this);
|
||||
ar & const_cast<mpq_rational &>(true_value_real_);
|
||||
ar & const_cast<mpq_rational &>(true_value_imag_);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // re: namespace node
|
||||
} // re: namespace bertini
|
||||
|
||||
#endif
|
||||
198
core/include/bertini2/function_tree/symbols/special_number.hpp
Normal file
198
core/include/bertini2/function_tree/symbols/special_number.hpp
Normal file
@@ -0,0 +1,198 @@
|
||||
//This file is part of Bertini 2.
|
||||
//
|
||||
//special_number.hpp is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
//
|
||||
//special_number.hpp is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU General Public License for more details.
|
||||
//
|
||||
//You should have received a copy of the GNU General Public License
|
||||
//along with special_number.hpp. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright(C) 2015 - 2023 by Bertini2 Development Team
|
||||
//
|
||||
// See <http://www.gnu.org/licenses/> for a copy of the license,
|
||||
// as well as COPYING. Bertini2 is provided with permitted
|
||||
// additional terms in the b2/licenses/ directory.
|
||||
|
||||
// individual authors of this file include:
|
||||
// James Collins
|
||||
// West Texas A&M University
|
||||
// Spring, Summer 2015
|
||||
//
|
||||
//
|
||||
// silviana amethyst
|
||||
// University of Wisconsin - Eau Claire
|
||||
//
|
||||
// Created by Collins, James B. on 4/30/15.
|
||||
//
|
||||
//
|
||||
// special_number.hpp: Declares the class SpecialNumber.
|
||||
|
||||
/**
|
||||
\file special_number.hpp
|
||||
|
||||
\brief Provides the special numbers \f$\pi\f$, \f$e\f$, 1, 2, 0, as Nodes
|
||||
|
||||
*/
|
||||
|
||||
#ifndef BERTINI_FUNCTION_TREE_SPECIAL_NUMBER_HPP
|
||||
#define BERTINI_FUNCTION_TREE_SPECIAL_NUMBER_HPP
|
||||
|
||||
|
||||
#include "bertini2/function_tree/symbols/number.hpp"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
|
||||
|
||||
namespace bertini {
|
||||
namespace node{
|
||||
using ::acos;
|
||||
using ::exp;
|
||||
|
||||
|
||||
namespace special_number{
|
||||
|
||||
/**
|
||||
\brief The number \f$\pi\f$.
|
||||
|
||||
The number \f$\pi\f$. Gets its own class because it is such an important number.
|
||||
*/
|
||||
class Pi : public virtual Number, public virtual NamedSymbol, public virtual EnableSharedFromThisVirtual<Pi>
|
||||
{
|
||||
public:
|
||||
BERTINI_DEFAULT_VISITABLE()
|
||||
|
||||
virtual ~Pi() = default;
|
||||
|
||||
template<typename... Ts>
|
||||
static
|
||||
std::shared_ptr<Pi> Make(Ts&& ...ts){
|
||||
return std::shared_ptr<Pi>( new Pi(ts...) );
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
Pi() : NamedSymbol("pi")
|
||||
{}
|
||||
|
||||
// Return value of constant
|
||||
dbl FreshEval_d(std::shared_ptr<Variable> const& diff_variable) const override;
|
||||
|
||||
void FreshEval_d(dbl& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override;
|
||||
|
||||
|
||||
mpfr_complex FreshEval_mp(std::shared_ptr<Variable> const& diff_variable) const override;
|
||||
|
||||
void FreshEval_mp(mpfr_complex& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override;
|
||||
|
||||
|
||||
friend class boost::serialization::access;
|
||||
|
||||
template <typename Archive>
|
||||
void serialize(Archive& ar, const unsigned version) {
|
||||
ar & boost::serialization::base_object<Number>(*this);
|
||||
ar & boost::serialization::base_object<NamedSymbol>(*this);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
\brief The number \f$e\f$.
|
||||
|
||||
The number \f$e\f$. Gets its own class because it is such an important number.
|
||||
*/
|
||||
class E : public virtual Number, public virtual NamedSymbol, public virtual EnableSharedFromThisVirtual<E>
|
||||
{
|
||||
public:
|
||||
BERTINI_DEFAULT_VISITABLE()
|
||||
|
||||
|
||||
|
||||
virtual ~E() = default;
|
||||
|
||||
|
||||
template<typename... Ts>
|
||||
static
|
||||
std::shared_ptr<E> Make(Ts&& ...ts){
|
||||
return std::shared_ptr<E>( new E(ts...) );
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
E() : NamedSymbol("e")
|
||||
{}
|
||||
|
||||
|
||||
// Return value of constant
|
||||
dbl FreshEval_d(std::shared_ptr<Variable> const& diff_variable) const override;
|
||||
|
||||
void FreshEval_d(dbl& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override;
|
||||
|
||||
|
||||
mpfr_complex FreshEval_mp(std::shared_ptr<Variable> const& diff_variable) const override;
|
||||
|
||||
void FreshEval_mp(mpfr_complex& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override;
|
||||
|
||||
|
||||
friend class boost::serialization::access;
|
||||
|
||||
template <typename Archive>
|
||||
void serialize(Archive& ar, const unsigned version) {
|
||||
ar & boost::serialization::base_object<Number>(*this);
|
||||
ar & boost::serialization::base_object<NamedSymbol>(*this);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // re: special_number namespace
|
||||
|
||||
|
||||
/**
|
||||
Construct a shared pointer to \f$\pi\f$.
|
||||
*/
|
||||
std::shared_ptr<Node> Pi();
|
||||
|
||||
/**
|
||||
Construct a shared pointer to \f$e\f$.
|
||||
*/
|
||||
std::shared_ptr<Node> E();
|
||||
|
||||
/**
|
||||
Construct a shared pointer to \f$i\f$.
|
||||
*/
|
||||
std::shared_ptr<Node> I();
|
||||
|
||||
/**
|
||||
Construct a shared pointer to \f$2\f$.
|
||||
*/
|
||||
std::shared_ptr<Node> Two();
|
||||
|
||||
/**
|
||||
Construct a shared pointer to \f$1\f$.
|
||||
*/
|
||||
std::shared_ptr<Node> One();
|
||||
|
||||
/**
|
||||
Construct a shared pointer to \f$0\f$.
|
||||
*/
|
||||
std::shared_ptr<Node> Zero();
|
||||
|
||||
|
||||
} // re: namespace node
|
||||
} // re: namespace bertini
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
133
core/include/bertini2/function_tree/symbols/symbol.hpp
Executable file
133
core/include/bertini2/function_tree/symbols/symbol.hpp
Executable file
@@ -0,0 +1,133 @@
|
||||
//This file is part of Bertini 2.
|
||||
//
|
||||
//symbol.hpp is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
//
|
||||
//symbol.hpp is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU General Public License for more details.
|
||||
//
|
||||
//You should have received a copy of the GNU General Public License
|
||||
//along with symbol.hpp. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright(C) 2015 - 2021 by Bertini2 Development Team
|
||||
//
|
||||
// See <http://www.gnu.org/licenses/> for a copy of the license,
|
||||
// as well as COPYING. Bertini2 is provided with permitted
|
||||
// additional terms in the b2/licenses/ directory.
|
||||
|
||||
// individual authors of this file include:
|
||||
// James Collins
|
||||
// West Texas A&M University
|
||||
// Spring, Summer 2015
|
||||
//
|
||||
// silviana amethyst, university of wisconsin-eau claire
|
||||
//
|
||||
// Created by Collins, James B. on 4/30/15.
|
||||
//
|
||||
//
|
||||
// symbol.hpp: Declares the class Symbol.
|
||||
|
||||
/**
|
||||
\file symbol.hpp
|
||||
|
||||
\brief Defines the abstract Symbol and NamedSymbol classes,
|
||||
|
||||
*/
|
||||
|
||||
#ifndef BERTINI_FUNCTION_TREE_SYMBOL_HPP
|
||||
#define BERTINI_FUNCTION_TREE_SYMBOL_HPP
|
||||
|
||||
|
||||
#include "bertini2/function_tree/node.hpp"
|
||||
|
||||
|
||||
|
||||
namespace bertini {
|
||||
namespace node {
|
||||
/**
|
||||
\brief Abstract symbol class.
|
||||
|
||||
This class is an interface for all non-operators.
|
||||
*/
|
||||
class Symbol : public virtual Node
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
virtual ~Symbol() = default;
|
||||
|
||||
unsigned EliminateZeros() override;
|
||||
unsigned EliminateOnes() override;
|
||||
|
||||
private:
|
||||
friend class boost::serialization::access;
|
||||
|
||||
template <typename Archive>
|
||||
void serialize(Archive& ar, const unsigned version) {
|
||||
ar & boost::serialization::base_object<Node>(*this);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
\brief Symbols which have names are named symbols.
|
||||
|
||||
Symbols which have names are named symbols.
|
||||
*/
|
||||
class NamedSymbol : public virtual Symbol
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
Get the name of the named symbol
|
||||
*/
|
||||
const std::string & name() const;
|
||||
|
||||
/**
|
||||
Get the name of the named symbol
|
||||
*/
|
||||
void name(const std::string & new_name);
|
||||
|
||||
|
||||
/**
|
||||
Parameterized constructor, sets the name of the symbol
|
||||
*/
|
||||
NamedSymbol(const std::string & new_name);
|
||||
|
||||
|
||||
void print(std::ostream& target) const override;
|
||||
|
||||
virtual ~NamedSymbol() = default;
|
||||
|
||||
protected:
|
||||
NamedSymbol() = default;
|
||||
|
||||
std::string name_;
|
||||
|
||||
private:
|
||||
|
||||
friend class boost::serialization::access;
|
||||
|
||||
template <typename Archive>
|
||||
void serialize(Archive& ar, const unsigned version) {
|
||||
ar & boost::serialization::base_object<Symbol>(*this);
|
||||
ar & name_;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // re: namespace node
|
||||
} // re: namespace bertini
|
||||
|
||||
#endif
|
||||
176
core/include/bertini2/function_tree/symbols/variable.hpp
Executable file
176
core/include/bertini2/function_tree/symbols/variable.hpp
Executable file
@@ -0,0 +1,176 @@
|
||||
//This file is part of Bertini 2.
|
||||
//
|
||||
//include/bertini2/function_tree/symbols/variable.hpp is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
//
|
||||
//include/bertini2/function_tree/symbols/variable.hpp is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU General Public License for more details.
|
||||
//
|
||||
//You should have received a copy of the GNU General Public License
|
||||
//along with include/bertini2/function_tree/symbols/variable.hpp. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright(C) 2015 - 2023 by Bertini2 Development Team
|
||||
//
|
||||
// See <http://www.gnu.org/licenses/> for a copy of the license,
|
||||
// as well as COPYING. Bertini2 is provided with permitted
|
||||
// additional terms in the b2/licenses/ directory.
|
||||
|
||||
// individual authors of this file include:
|
||||
// James Collins
|
||||
// West Texas A&M University
|
||||
// Spring, Summer 2015
|
||||
//
|
||||
// silviana amethyst, university of wisconsin-eau claire
|
||||
//
|
||||
// Created by Collins, James B. on 4/30/15.
|
||||
//
|
||||
//
|
||||
// include/bertini2/function_tree/symbols/variable.hpp: Declares the class Variable.
|
||||
|
||||
|
||||
/**
|
||||
\file include/bertini2/function_tree/symbols/variable.hpp
|
||||
|
||||
\brief Provides the Variable Node class.
|
||||
|
||||
*/
|
||||
#ifndef BERTINI_FUNCTION_TREE_VARIABLE_HPP
|
||||
#define BERTINI_FUNCTION_TREE_VARIABLE_HPP
|
||||
|
||||
#include "bertini2/function_tree/symbols/symbol.hpp"
|
||||
#include "bertini2/function_tree/symbols/differential.hpp"
|
||||
|
||||
|
||||
namespace bertini {
|
||||
namespace node{
|
||||
/**
|
||||
\brief Represents variable leaves in the function tree.
|
||||
|
||||
This class represents variable leaves in the function tree. FreshEval returns
|
||||
the current value of the variable.
|
||||
|
||||
When differentiated, produces a differential referring to it.
|
||||
*/
|
||||
class Variable : public virtual NamedSymbol, public virtual EnableSharedFromThisVirtual<Variable>
|
||||
{
|
||||
public:
|
||||
BERTINI_DEFAULT_VISITABLE()
|
||||
|
||||
|
||||
template<typename... Ts>
|
||||
static
|
||||
std::shared_ptr<Variable> Make(Ts&& ...ts){
|
||||
return std::shared_ptr<Variable>( new Variable(ts...) );
|
||||
}
|
||||
|
||||
private:
|
||||
Variable(std::string new_name);
|
||||
|
||||
public:
|
||||
|
||||
|
||||
virtual ~Variable() = default;
|
||||
|
||||
|
||||
|
||||
explicit operator std::string(){return name();}
|
||||
|
||||
|
||||
|
||||
// This sets the value for the variable
|
||||
template <typename T>
|
||||
void set_current_value(T const& val);
|
||||
|
||||
/**
|
||||
\brief Changes the value of the variable to be not-a-number.
|
||||
*/
|
||||
template <typename T>
|
||||
void SetToNan();
|
||||
|
||||
/**
|
||||
\brief Changes the value of the variable to be a random complex number.
|
||||
*/
|
||||
template <typename T>
|
||||
void SetToRand();
|
||||
|
||||
/**
|
||||
\brief Changes the value of the variable to be a random complex number, of magnitude 1.
|
||||
*/
|
||||
template <typename T>
|
||||
void SetToRandUnit();
|
||||
|
||||
/**
|
||||
Differentiates a variable.
|
||||
*/
|
||||
std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const override;
|
||||
|
||||
void Reset() const override;
|
||||
|
||||
/**
|
||||
Compute the degree with respect to a single variable.
|
||||
|
||||
If this is the variable, then the degree is 1. Otherwise, 0.
|
||||
*/
|
||||
int Degree(std::shared_ptr<Variable> const& v = nullptr) const override;
|
||||
|
||||
|
||||
int Degree(VariableGroup const& vars) const override;
|
||||
|
||||
std::vector<int> MultiDegree(VariableGroup const& vars) const override;
|
||||
|
||||
|
||||
void Homogenize(VariableGroup const& vars, std::shared_ptr<Variable> const& homvar) override;
|
||||
|
||||
bool IsHomogeneous(std::shared_ptr<Variable> const& v = nullptr) const override;
|
||||
|
||||
/**
|
||||
Check for homogeneity, with respect to a variable group.
|
||||
*/
|
||||
bool IsHomogeneous(VariableGroup const& vars) const override;
|
||||
|
||||
|
||||
/**
|
||||
Change the precision of this variable-precision tree node.
|
||||
|
||||
\param prec the number of digits to change precision to.
|
||||
*/
|
||||
void precision(unsigned int prec) const override;
|
||||
|
||||
protected:
|
||||
|
||||
// Return current value of the variable.
|
||||
dbl FreshEval_d(std::shared_ptr<Variable> const& diff_variable) const override;
|
||||
|
||||
void FreshEval_d(dbl& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override;
|
||||
|
||||
|
||||
mpfr_complex FreshEval_mp(std::shared_ptr<Variable> const& diff_variable) const override;
|
||||
|
||||
void FreshEval_mp(mpfr_complex& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override;
|
||||
|
||||
Variable();
|
||||
private:
|
||||
|
||||
friend class boost::serialization::access;
|
||||
|
||||
template <typename Archive>
|
||||
void serialize(Archive& ar, const unsigned version) {
|
||||
ar & boost::serialization::base_object<NamedSymbol>(*this);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
} // re: namespace node
|
||||
} // re: namespace bertini
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user