Add files

This commit is contained in:
2025-01-14 01:15:48 +01:00
commit 2f9fcec55b
406 changed files with 87154 additions and 0 deletions

View File

@@ -0,0 +1,128 @@
//This file is part of Bertini 2.
//
//include/bertini2/function_tree/forward_declares.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/forward_declares.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/forward_declares.hpp. If not, see <http://www.gnu.org/licenses/>.
//
// Copyright(C) 2016 - 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:
// silviana amethyst, university of wisconsin-eau claire
/**
\file include/bertini2/function_tree/forward_declares.hpp
\brief Forward declarations for types in the node:: namespace
*/
#pragma once
namespace bertini {
namespace node{
class Node;
}
namespace node{
class Variable;
class Integer;
class Float;
class Rational;
class Function;
class Jacobian;
class Differential;
}
namespace node{
class Operator;
class UnaryOperator;
class NaryOperator;
class SumOperator;
class MultOperator;
class IntegerPowerOperator;
class PowerOperator;
class ExpOperator;
class LogOperator;
class NegateOperator;
class SqrtOperator;
class LinearProduct;
class DiffLinear;
}
namespace node{
class TrigOperator;
class SinOperator;
class ArcSinOperator;
class CosOperator;
class ArcCosOperator;
class TanOperator;
class ArcTanOperator;
}
namespace node{
namespace special_number{
class Pi;
class E;
}
}
namespace node{
template <typename Archive>
void register_derived_node_types(Archive& ar)
{
ar.template register_type<bertini::node::Variable>();
ar.template register_type<bertini::node::Integer>();
ar.template register_type<bertini::node::Float>();
ar.template register_type<bertini::node::Rational>();
ar.template register_type<bertini::node::Function>();
ar.template register_type<bertini::node::Jacobian>();
ar.template register_type<bertini::node::Differential>();
// ar.template register_type<bertini::node::Operator>(); // abstract type
// ar.template register_type<bertini::node::UnaryOperator>(); // abstract type
// ar.template register_type<bertini::node::NaryOperator>(); // abstract type
ar.template register_type<bertini::node::SumOperator>();
ar.template register_type<bertini::node::MultOperator>();
ar.template register_type<bertini::node::IntegerPowerOperator>();
ar.template register_type<bertini::node::PowerOperator>();
ar.template register_type<bertini::node::ExpOperator>();
ar.template register_type<bertini::node::LogOperator>();
ar.template register_type<bertini::node::NegateOperator>();
ar.template register_type<bertini::node::SqrtOperator>();
ar.template register_type<bertini::node::LinearProduct>();
// ar.template register_type<bertini::node::TrigOperator>(); // abstract type
ar.template register_type<bertini::node::SinOperator>();
ar.template register_type<bertini::node::ArcSinOperator>();
ar.template register_type<bertini::node::CosOperator>();
ar.template register_type<bertini::node::ArcCosOperator>();
ar.template register_type<bertini::node::TanOperator>();
ar.template register_type<bertini::node::ArcTanOperator>();
ar.template register_type<bertini::node::special_number::Pi>();
ar.template register_type<bertini::node::special_number::E>();
}
}
}// namespace bertini

View File

@@ -0,0 +1,451 @@
//This file is part of Bertini 2.
//
//node.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.
//
//node.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 node.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.
/**
\file node.hpp
\brief Defines the abstract Node base class.
*/
#ifndef BERTINI_NODE_BASE_HPP
#define BERTINI_NODE_BASE_HPP
#include <iostream>
#include <string>
#include <tuple>
#include <boost/type_index.hpp>
#include "bertini2/num_traits.hpp"
#include "bertini2/detail/visitable.hpp"
#include "bertini2/function_tree/forward_declares.hpp"
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/export.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/tracking.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/nvp.hpp>
namespace bertini {
namespace node{
class Variable;
}
using VariableGroup = std::vector< std::shared_ptr<node::Variable> >;
enum class VariableGroupType
{
Homogeneous,
Affine,
Ungrouped
};
namespace node{
namespace detail{
template<typename T>
struct FreshEvalSelector
{};
template<>
struct FreshEvalSelector<dbl>
{
template<typename N>
static dbl Run(N const& n, std::shared_ptr<Variable> const& diff_variable)
{
return n.FreshEval_d(diff_variable);
}
template<typename N>
static void RunInPlace(dbl& evaluation_value, N const& n, std::shared_ptr<Variable> const& diff_variable)
{
n.FreshEval_d(evaluation_value, diff_variable);
}
};
template<>
struct FreshEvalSelector<mpfr_complex>
{
template<typename N>
static mpfr_complex Run(N const& n, std::shared_ptr<Variable> const& diff_variable)
{
return n.FreshEval_mp(diff_variable);
}
template<typename N>
static void RunInPlace(mpfr_complex& evaluation_value, N const& n, std::shared_ptr<Variable> const& diff_variable)
{
n.FreshEval_mp(evaluation_value, diff_variable);
}
};
}
/**
An interface for all nodes in a function tree, and for a function object as well. Almost all
methods that will be called on a node must be declared in this class. The main evaluation method is
defined in this class.
Bertini function trees are created using std::shared_ptr's to Node base class, generally.
\brief Abstract base class for the Bertini hybrid-precision (double-multiple) expression tree.
*/
class Node : public virtual VisitableBase<>, public std::enable_shared_from_this<Node>
{
friend detail::FreshEvalSelector<dbl>;
friend detail::FreshEvalSelector<mpfr_complex>;
public:
virtual ~Node() = default;
///////// PUBLIC PURE METHODS /////////////////
/**
Tells code to run a fresh eval on node next time.
*/
virtual void Reset() const = 0;
///////// END PUBLIC PURE METHODS /////////////////
public:
/**
Evaluate the node. If flag false, just return value, if flag true
run the specific FreshEval of the node, then set flag to false.
Template type is type of value you want returned.
\return The value of the node.
\tparam T The number type for return. Must be one of the types stored in the Node class, currently dbl and mpfr_complex.
*/
template<typename T>
T Eval(std::shared_ptr<Variable> const& diff_variable = nullptr) const
{
T result;
EvalInPlace(result, diff_variable);
return result;
}
/**
Evaluate the node in place. If flag false, just return value, if flag true
run the specific FreshEval of the node, then set flag to false.
Template type is type of value you want returned.
\return The value of the node.
\tparam T The number type for return. Must be one of the types stored in the Node class, currently dbl and mpfr_complex.
*/
template<typename T>
void EvalInPlace(T& eval_value, std::shared_ptr<Variable> const& diff_variable = nullptr) const;
///////// PUBLIC PURE METHODS /////////////////
/**
\brief A transform function, which eliminates nodes from the tree
A better implementation of this would use a generic Transform. If you know how to do this, please rewrite the Nodes so they can transform to our whim, and submit a PR.
\return The number of nodes eliminated
\see EliminateZeros
*/
virtual unsigned EliminateOnes() = 0;
/**
\brief A transform function, which eliminates nodes from the tree
A better implementation of this would use a generic Transform. If you know how to do this, please rewrite the Nodes so they can transform to our whim, and submit a PR.
\return The number of nodes eliminated
\see EliminateOnes
*/
virtual unsigned EliminateZeros() = 0;
/**
\brief A mutating function which finds ways to reduce the depth of the tree
\note The default implementation is empty, and does literally nothing.
*/
virtual unsigned ReduceDepth();
/**
Virtual method for printing Nodes to arbitrary output streams.
*/
virtual void print(std::ostream& target) const = 0;
/**
\brief Compute the derivative with respect to a single variable.
Virtual method for differentiating the node. If no variable is passed, produces a Jacobian tree when all is said and done, which is used for evaluating the Jacobian.
\return The result of differentiation. Jacobian or regular Node depending on what you passed in.
*/
virtual std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const = 0;
/**
Compute the degree, optionally with respect to a single variable.
\param v Shared pointer to variable with respect to which you want to compute the degree of the Node.
\return The degree. Will be negative if the Node is non-polynomial.
*/
virtual int Degree(std::shared_ptr<Variable> const& v = nullptr) const = 0;
/**
Compute the multidegree with respect to a variable group. This is for homogenization, and testing for homogeneity.
\return A vector containing the degrees. Negative entries indicate non-polynomiality.
*/
virtual std::vector<int> MultiDegree(VariableGroup const& vars) const = 0;
/**
Compute the overall degree with respect to a variable group.
\param vars A group of variables.
\return The degree. Will be negative if the Node is non-polynomial.
*/
virtual int Degree(VariableGroup const& vars) const = 0;
/**
Homogenize a tree, inputting a variable group holding the non-homogeneous variables, and the new homogenizing variable. The homvar may be an element of the variable group, that's perfectly ok.
\param homvar The homogenizing variable, which is multiplied against terms with degree deficiency with repect to other terms.
\param vars A group of variables, with respect to which you wish to homogenize.
*/
virtual void Homogenize(VariableGroup const& vars, std::shared_ptr<Variable> const& homvar) = 0;
/**
Check for homogeneity, absolutely with respect to all variables, including path variables and all other variable types, or with respect to a single varaible, if passed.
\return True if it is homogeneous, false if not.
*/
virtual bool IsHomogeneous(std::shared_ptr<Variable> const& v = nullptr) const = 0;
/**
Check for homogeneity, with respect to a variable group.
\return True if it is homogeneous, false if not.
*/
virtual bool IsHomogeneous(VariableGroup const& vars) const = 0;
/**
Change the precision of this variable-precision tree node.
\param prec the number of digits to change precision to.
*/
virtual void precision(unsigned int prec) const = 0;
unsigned precision() const;
///////// PUBLIC PURE METHODS /////////////////
/**
Check if a Node is polynomial -- it has degree at least 0. Negative degrees indicate non-polynomial.
\return True if it is polynomial, false if not.
*/
bool IsPolynomial(std::shared_ptr<Variable> const&v = nullptr) const;
/**
Check if a Node is polynomial -- it has degree at least 0. Negative degrees indicate non-polynomial.
\return True if it is polynomial, false if not.
*/
bool IsPolynomial(VariableGroup const&v) const;
protected:
//Stores the current value of the node in all required types
//We must hard code in all types that we want here.
//TODO: Initialize this to some default value, second = false
mutable std::tuple< std::pair<dbl,bool>, std::pair<mpfr_complex,bool> > current_value_;
///////// PRIVATE PURE METHODS /////////////////
/**
Overridden code for specific node types, for how to evaluate themselves. Called from the wrapper Eval<>() call from Node, if so required (by resetting, etc).
If we had the ability to use template virtual functions, we would have. However, this is impossible with current C++ without using experimental libraries, so we have two copies -- because there are two number types for Nodes, dbl and mpfr_complex.
*/
virtual dbl FreshEval_d(std::shared_ptr<Variable> const&) const = 0;
/**
Overridden code for specific node types, for how to evaluate themselves. Called from the wrapper EvalInPlace<>() call from Node, if so required (by resetting, etc).
If we had the ability to use template virtual functions, we would have. However, this is impossible with current C++ without using experimental libraries, so we have two copies -- because there are two number types for Nodes, dbl and mpfr_complex.
*/
virtual void FreshEval_d(dbl& evaluation_value, std::shared_ptr<Variable> const&) const = 0;
/**
Overridden code for specific node types, for how to evaluate themselves. Called from the wrapper Eval<>() call from Node, if so required (by resetting, etc).
If we had the ability to use template virtual functions, we would have. However, this is impossible with current C++ without using experimental libraries, so we have two copies -- because there are two number types for Nodes, dbl and mpfr_complex.
*/
virtual mpfr_complex FreshEval_mp(std::shared_ptr<Variable> const&) const = 0;
/**
Overridden code for specific node types, for how to evaluate themselves. Called from the wrapper Eval<>() call from Node, if so required (by resetting, etc).
If we had the ability to use template virtual functions, we would have. However, this is impossible with current C++ without using experimental libraries, so we have two copies -- because there are two number types for Nodes, dbl and mpfr_complex.
*/
virtual void FreshEval_mp(mpfr_complex& evaluation_value, std::shared_ptr<Variable> const&) const = 0;
///////// END PRIVATE PURE METHODS /////////////////
/**
Set the stored values for the Node to indicate a fresh eval on the next pass. This is so that Nodes which are referred to more than once, are only evaluated once. The first evaluation is fresh, and then the indicator for fresh/stored is set to stored. Subsequent evaluation calls simply return the stored number.
*/
void ResetStoredValues() const;
Node();
private:
friend std::ostream& operator<<(std::ostream & out, const Node& N);
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive& ar, const unsigned version) {
register_derived_node_types(ar);
}
}; // re: class node
/**
a single layer of indirection, though which to call the overridden virtual print() method which must be defined for each non-abstract Node type.
*/
inline std::ostream& operator<<(std::ostream & out, const Node& N)
{
N.print(out);
return out;
}
inline std::ostream& operator<<(std::ostream & out, const std::shared_ptr<Node>& N)
{
N->print(out);
return out;
}
// inherit from this to get a nice method of producing shared pointers to specific type, solving the diamond problem
//
// T is a derived type
//
// I adapted from:
// https://stackoverflow.com/questions/16082785/use-of-enable-shared-from-this-with-multiple-inheritance
//
template<typename T>
struct EnableSharedFromThisVirtual: public virtual Node
{
public:
std::shared_ptr<T> shared_from_this() {
return std::dynamic_pointer_cast<T>(Node::shared_from_this());
}
std::shared_ptr<const T> shared_from_this() const{
return std::dynamic_pointer_cast<const T>(Node::shared_from_this());
}
template <class ThisT>
std::shared_ptr<ThisT> downcast_shared_from_this(){
return std::dynamic_pointer_cast<ThisT>(Node::shared_from_this());
}
template <class ThisT>
std::shared_ptr<const ThisT> downcast_shared_from_this() const{
return std::dynamic_pointer_cast<const ThisT>(Node::shared_from_this());
}
};
} // re: namespace node
} // re: namespace bertini
#endif
/* defined(BERTINI_NODE_BASE_HPP) */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,228 @@
//This file is part of Bertini 2.
//
//operator.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.
//
//operator.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 operator.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.
//
//
// operator.hpp: Declares the class Operator.
/**
\file operator.hpp
\brief Provides the abstract Operator Node type.
*/
#ifndef BERTINI_OPERATOR_HPP
#define BERTINI_OPERATOR_HPP
#include "bertini2/function_tree/node.hpp"
#include <vector>
namespace bertini {
namespace node{
/**
\brief Abstract Node type from which all Operators inherit.
This class is an interface for all operators in the Bertini2 function tree.
*/
class Operator : public virtual Node
{
public:
virtual ~Operator() = default;
private:
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive& ar, const unsigned version) {
ar & boost::serialization::base_object<Node>(*this);
}
};
/**
\brief Interface for all unary Operator types.
This class is an interface for all unary operators, such as negation.
The sole child is stored in a shared_ptr.
*/
class UnaryOperator : public virtual Operator
{
public:
UnaryOperator(const std::shared_ptr<Node> & n) : operand_(n)
{}
virtual ~UnaryOperator() = default;
void Reset() const override;
void SetOperand(std::shared_ptr<Node> n);
//Return the only child for the unary operator
std::shared_ptr<Node> Operand() const;
/**
Compute the degree of a node. For trig functions, the degree is 0 if the argument is constant, otherwise it's undefined, and we return nan.
*/
int Degree(std::shared_ptr<Variable> const& v = nullptr) const override;
int Degree(VariableGroup const& vars) const override;
/**
Compute the multidegree with respect to a variable group. This is for homogenization, and testing for homogeneity.
*/
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:
//Stores the single child of the unary operator
std::shared_ptr<Node> operand_;
UnaryOperator(){}
private:
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive& ar, const unsigned version) {
ar & boost::serialization::base_object<Operator>(*this);
ar & operand_;
}
};
/**
\brief Abstract interface for n-ary Operator types.
This class is an interface for all n-ary operators, such as summation and multiplication.
Operands of the operator are stored in a vector and methods to add and access operands are available
in this interface.
*/
class NaryOperator : public virtual Operator
{
public:
virtual ~NaryOperator() = default;
void Reset() const override;
// Add an operand onto the container for this operator
virtual void AddOperand(std::shared_ptr<Node> n);
size_t NumOperands() const;
inline auto const& Operands() const{
return operands_;
}
std::shared_ptr<Node> FirstOperand() const;
/**
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:
//Stores all children for this operator node.
//This is an NaryOperator and can have any number of children.
std::vector< std::shared_ptr<Node> > operands_;
// constructor is protected to help prevent instantiating empty operators
NaryOperator(){}
private:
virtual void PrecisionChangeSpecific(unsigned prec) const;
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive& ar, const unsigned version) {
ar & boost::serialization::base_object<Operator>(*this);
ar & operands_;
}
};
} // re: namespace node
} // re: namespace bertini
#endif

View File

@@ -0,0 +1,525 @@
//This file is part of Bertini 2.
//
//trig.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.
//
//trig.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 trig.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
//
//
//
// trig.hpp: Declares the trigonometric operator classes.
/**
\file trig.hpp
\brief Provides the abstract TrigOperator, and the concrete types such as SinOperator.
*/
#ifndef BERTINI_TRIGONOMETRIC_OPERATOR_HPP
#define BERTINI_TRIGONOMETRIC_OPERATOR_HPP
#include "bertini2/function_tree/operators/operator.hpp"
#include "bertini2/function_tree/operators/arithmetic.hpp"
namespace bertini {
namespace node{
/**
\brief Abstract class for trigonometric Operator types.
Abstract class for trigonometric Operator types.
*/
class TrigOperator: public virtual UnaryOperator
{
public:
BERTINI_DEFAULT_VISITABLE()
TrigOperator(const std::shared_ptr<Node> & N) : UnaryOperator(N)
{};
virtual ~TrigOperator() = default;
/**
Compute the degree with respect to a single variable.
For transcendental functions, the degree is 0 if the argument is constant, otherwise it's undefined, and we return -1.
*/
int Degree(std::shared_ptr<Variable> const& v = nullptr) const override;
protected:
TrigOperator(){}
private:
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive& ar, const unsigned version) {
ar & boost::serialization::base_object<UnaryOperator>(*this);
}
};
/**
\brief Provides the sine Operator.
This class represents the sine function. FreshEval method
is defined for sine and takes the sine of the child node.
*/
class SinOperator : public virtual TrigOperator, public virtual EnableSharedFromThisVirtual<SinOperator>
{
public:
BERTINI_DEFAULT_VISITABLE()
unsigned EliminateZeros() override;
unsigned EliminateOnes() override;
template<typename... Ts>
static
std::shared_ptr<SinOperator> Make(Ts&& ...ts){
return std::shared_ptr<SinOperator>( new SinOperator(ts...) );
}
private:
SinOperator(const std::shared_ptr<Node> & N) : TrigOperator(N), UnaryOperator(N)
{};
public:
void print(std::ostream & target) const override;
/**
Differentiates the sine function.
*/
std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const override;
virtual ~SinOperator() = default;
protected:
// Specific implementation of FreshEval for negate.
dbl FreshEval_d(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;
void FreshEval_d(dbl& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override;
private:
SinOperator() = default;
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive& ar, const unsigned version) {
ar & boost::serialization::base_object<TrigOperator>(*this);
}
};
/**
\brief Provides the inverse sine Operator.
This class represents the inverse sine function. FreshEval method
is defined for arcsine and takes the sine of the child node.
*/
class ArcSinOperator : public virtual TrigOperator, public virtual EnableSharedFromThisVirtual<ArcSinOperator>
{
public:
BERTINI_DEFAULT_VISITABLE()
unsigned EliminateZeros() override;
unsigned EliminateOnes() override;
template<typename... Ts>
static
std::shared_ptr<ArcSinOperator> Make(Ts&& ...ts){
return std::shared_ptr<ArcSinOperator>( new ArcSinOperator(ts...) );
}
private:
ArcSinOperator(const std::shared_ptr<Node> & N) : TrigOperator(N), UnaryOperator(N)
{};
public:
void print(std::ostream & target) const override;
/**
Differentiates the sine function.
*/
std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const override;
virtual ~ArcSinOperator() = default;
protected:
// Specific implementation of FreshEval for negate.
dbl FreshEval_d(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;
void FreshEval_d(dbl& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override;
private:
ArcSinOperator() = default;
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive& ar, const unsigned version) {
ar & boost::serialization::base_object<TrigOperator>(*this);
}
};
/**
\brief Provides the cosine Operator.
This class represents the cosine function. FreshEval method
is defined for cosine and takes the cosine of the child node.
*/
class CosOperator : public virtual TrigOperator, public virtual EnableSharedFromThisVirtual<CosOperator>
{
public:
BERTINI_DEFAULT_VISITABLE()
unsigned EliminateZeros() override;
unsigned EliminateOnes() override;
template<typename... Ts>
static
std::shared_ptr<CosOperator> Make(Ts&& ...ts){
return std::shared_ptr<CosOperator>( new CosOperator(ts...) );
}
private:
CosOperator(const std::shared_ptr<Node> & N) : TrigOperator(N), UnaryOperator(N)
{};
public:
void print(std::ostream & target) const override;
/**
Differentiates the cosine function.
*/
std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const override;
virtual ~CosOperator() = default;
protected:
// Specific implementation of FreshEval for negate.
dbl FreshEval_d(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;
void FreshEval_d(dbl& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override;
private:
CosOperator() = default;
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive& ar, const unsigned version) {
ar & boost::serialization::base_object<TrigOperator>(*this);
}
};
/**
\brief Provides the arc cosine Operator.
This class represents the inverse cosine function. FreshEval method
is defined for arccosine and takes the arccosine of the child node.
*/
class ArcCosOperator : public virtual TrigOperator, public virtual EnableSharedFromThisVirtual<ArcCosOperator>
{
public:
BERTINI_DEFAULT_VISITABLE()
unsigned EliminateZeros() override;
unsigned EliminateOnes() override;
template<typename... Ts>
static
std::shared_ptr<ArcCosOperator> Make(Ts&& ...ts){
return std::shared_ptr<ArcCosOperator>( new ArcCosOperator(ts...) );
}
private:
ArcCosOperator(const std::shared_ptr<Node> & N) : TrigOperator(N), UnaryOperator(N)
{};
public:
void print(std::ostream & target) const override;
/**
Differentiates the cosine function.
*/
std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const override;
virtual ~ArcCosOperator() = default;
protected:
// Specific implementation of FreshEval for negate.
dbl FreshEval_d(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;
void FreshEval_d(dbl& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override;
private:
ArcCosOperator() = default;
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive& ar, const unsigned version) {
ar & boost::serialization::base_object<TrigOperator>(*this);
}
};
/**
\brief Provides the tangent Operator.
This class represents the tangent function. FreshEval method
is defined for tangent and takes the tangent of the child node.
*/
class TanOperator : public virtual TrigOperator, public virtual EnableSharedFromThisVirtual<TanOperator>
{
public:
BERTINI_DEFAULT_VISITABLE()
unsigned EliminateZeros() override;
unsigned EliminateOnes() override;
template<typename... Ts>
static
std::shared_ptr<TanOperator> Make(Ts&& ...ts){
return std::shared_ptr<TanOperator>( new TanOperator(ts...) );
}
private:
TanOperator(const std::shared_ptr<Node> & N) : TrigOperator(N), UnaryOperator(N)
{};
public:
void print(std::ostream & target) const override;
/**
Differentiates the tangent function.
*/
std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const override;
virtual ~TanOperator() = default;
protected:
// Specific implementation of FreshEval for negate.
dbl FreshEval_d(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;
void FreshEval_d(dbl& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override;
private:
TanOperator() = default;
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive& ar, const unsigned version) {
ar & boost::serialization::base_object<TrigOperator>(*this);
}
};
/**
\brief Provides the inverse tangent Operator.
This class represents the inverse tangent function. FreshEval method
is defined for arctangent and takes the arc tangent of the child node.
*/
class ArcTanOperator : public virtual TrigOperator, public virtual EnableSharedFromThisVirtual<ArcTanOperator>
{
public:
BERTINI_DEFAULT_VISITABLE()
unsigned EliminateZeros() override;
unsigned EliminateOnes() override;
template<typename... Ts>
static
std::shared_ptr<ArcTanOperator> Make(Ts&& ...ts){
return std::shared_ptr<ArcTanOperator>( new ArcTanOperator(ts...) );
}
private:
ArcTanOperator(const std::shared_ptr<Node> & N) : TrigOperator(N), UnaryOperator(N)
{};
public:
void print(std::ostream & target) const override;
/**
Differentiates the tangent function.
*/
std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const override;
virtual ~ArcTanOperator() = default;
protected:
// Specific implementation of FreshEval for arctangent.
dbl FreshEval_d(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;
void FreshEval_d(dbl& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override;
private:
ArcTanOperator() = default;
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive& ar, const unsigned version) {
ar & boost::serialization::base_object<TrigOperator>(*this);
}
};
// begin the overload of operators
inline std::shared_ptr<Node> sin(const std::shared_ptr<Node> & N)
{
return SinOperator::Make(N);
}
inline std::shared_ptr<Node> asin(const std::shared_ptr<Node> & N)
{
return ArcSinOperator::Make(N);
}
inline std::shared_ptr<Node> cos(const std::shared_ptr<Node> & N)
{
return CosOperator::Make(N);
}
inline std::shared_ptr<Node> acos(const std::shared_ptr<Node> & N)
{
return ArcCosOperator::Make(N);
}
inline std::shared_ptr<Node> tan(const std::shared_ptr<Node> & N)
{
return TanOperator::Make(N);
}
inline std::shared_ptr<Node> atan(const std::shared_ptr<Node> & N)
{
return ArcTanOperator::Make(N);
}
} // re: namespace node
} // re: namespace bertini
#endif

View File

@@ -0,0 +1,274 @@
//This file is part of Bertini 2.
//
//bertini2/function_tree/roots/function.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.
//
//bertini2/function_tree/roots/function.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 bertini2/function_tree/roots/function.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
//
// silviana amethyst
// UWEC
// Spring 2018
//
// Created by Collins, James B. on 4/30/15.
//
//
// bertini2/function_tree/roots/function.hpp: Declares the class Function.
/**
\file bertini2/function_tree/roots/function.hpp
\brief Provides the Function Node type, a NamedSymbol.
*/
#ifndef BERTINI_FUNCTION_NODE_HPP
#define BERTINI_FUNCTION_NODE_HPP
#include "bertini2/function_tree/symbols/symbol.hpp"
namespace bertini {
namespace node{
class Handle : public virtual NamedSymbol
{
BERTINI_DEFAULT_VISITABLE()
public:
/**
overridden function for piping the tree to an output stream.
*/
void print(std::ostream & target) const override;
Handle(std::string const& new_name);
/**
Constructor defines entry node at construct time.
*/
Handle(const std::shared_ptr<Node> & entry, std::string const& name = "unnamed_function");
protected:
Handle() = default;
public:
/**
Add a child onto the container for this operator
*/
void SetRoot(std::shared_ptr<Node> const& entry);
/**
throws a runtime error if the root node is nullptr
*/
void EnsureNotEmpty() const;
/**
The function which flips the fresh eval bit back to fresh.
*/
void Reset() const override;
/**
Get the pointer to the entry node for this function.
*/
const std::shared_ptr<Node>& EntryNode() const;
/**
Calls Differentiate on the entry node and returns differentiated entry node.
*/
std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const override;
/**
Compute the degree of a node. For functions, the degree is the degree of the entry node.
*/
int Degree(std::shared_ptr<Variable> const& v = nullptr) const override;
int Degree(VariableGroup const& vars) const override;
/**
Compute the multidegree with respect to a variable group. This is for homogenization, and testing for homogeneity.
*/
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:
/**
Calls FreshEval on the entry node to the tree.
*/
dbl FreshEval_d(std::shared_ptr<Variable> const& diff_variable) const override;
/**
Calls FreshEval in place on the entry node to the tree.
*/
void FreshEval_d(dbl& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override;
/**
Calls FreshEval on the entry node to the tree.
*/
mpfr_complex FreshEval_mp(std::shared_ptr<Variable> const& diff_variable) const override;
/**
Calls FreshEval in place on the entry node to the tree.
*/
void FreshEval_mp(mpfr_complex& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override;
std::shared_ptr<Node> entry_node_ = nullptr;
private:
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive& ar, const unsigned version) {
ar & boost::serialization::base_object<NamedSymbol>(*this);
ar & entry_node_;
}
}; // class Function
}} // namespaces
namespace bertini {
namespace node{
/**
\brief Formal entry point into an expression tree.
This class defines a function. It stores the entry node for a particular functions tree.
*/
class Function : public virtual Handle, public virtual EnableSharedFromThisVirtual<Function>
{
public:
BERTINI_DEFAULT_VISITABLE()
template<typename... Ts>
static
std::shared_ptr<Function> Make(Ts&& ...ts){
return std::shared_ptr<Function>( new Function(ts...) );
}
template<typename... Ts>
static
std::shared_ptr<Function> MakeInPlace(Function* ptr, Ts&& ...ts){
return std::shared_ptr<Function>( new(ptr) Function(ts...) );
}
private:
Function(std::string const& new_name);
/**
Constructor defines entry node at construct time.
*/
Function(const std::shared_ptr<Node> & entry, std::string const& name = "unnamed_function");
public:
virtual ~Function() = default;
protected:
Function() = default;
private:
friend class boost::serialization::access;
// template<class Archive> friend void boost::serialization::load_construct_data(Archive & ar, Function * t, const unsigned int file_version);
// template<class Archive> friend void boost::serialization::save_construct_data(Archive & ar, const Function * t, const unsigned int file_version);
template <typename Archive>
void serialize(Archive& ar, const unsigned version) {
ar & boost::serialization::base_object<Handle>(*this);
}
};
} // re: namespace node
} // re: namespace bertini
#endif

View File

@@ -0,0 +1,131 @@
//This file is part of Bertini 2.
//
//jacobian.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.
//
//jacobian.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 jacobian.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
//
// silviana amethyst
// UWEC
// Spring 2018
//
// Created by Collins, James B. on 6/11/15.
//
//
// jacobian.hpp: Declares the class Jacobian.
/**
\file jacobian.hpp
\brief Provides the Jacobian node type.
*/
#ifndef BERTINI_JACOBIAN_NODE_HPP
#define BERTINI_JACOBIAN_NODE_HPP
#include "bertini2/function_tree/node.hpp"
#include "bertini2/function_tree/roots/function.hpp"
#include "bertini2/function_tree/symbols/variable.hpp"
namespace bertini {
namespace node{
/**
\brief Defines the entry point into a Jacobian tree.
This class defines a Jacobian tree. It stores the entry node for a particular functions tree.
*/
class Jacobian : public virtual Handle, public virtual EnableSharedFromThisVirtual<Jacobian>
{
friend detail::FreshEvalSelector<dbl>;
friend detail::FreshEvalSelector<mpfr_complex>;
public:
BERTINI_DEFAULT_VISITABLE()
template<typename... Ts>
static
std::shared_ptr<Jacobian> Make(Ts&& ...ts){
return std::shared_ptr<Jacobian>( new Jacobian(ts...) );
}
private:
/**
*/
Jacobian(const std::shared_ptr<Node> & entry);
public:
/**
Jacobians must be evaluated with EvalJ, so that when current_diff_variable changes
the Jacobian is reevaluated.
*/
template<typename T>
T Eval(std::shared_ptr<Variable> const& diff_variable = nullptr) const = delete;
// Evaluate the node. If flag false, just return value, if flag true
// run the specific FreshEval of the node, then set flag to false.
template<typename T>
T EvalJ(std::shared_ptr<Variable> const& diff_variable) const;
// Evaluate the node. If flag false, just return value, if flag true
// run the specific FreshEval of the node, then set flag to false.
template<typename T>
void EvalJInPlace(T& eval_value, std::shared_ptr<Variable> const& diff_variable) const;
virtual ~Jacobian() = default;
/**
\brief Default construction of a Jacobian node is forbidden
*/
Jacobian() = default;
private:
mutable std::shared_ptr<Variable> current_diff_variable_;
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive& ar, const unsigned version) {
ar & boost::serialization::base_object<Handle>(*this);
}
};
} // re: namespace node
} // re: namespace bertini
#endif

View File

@@ -0,0 +1,48 @@
//This file is part of Bertini 2.
//
//b2/core/include/bertini2/function_tree/simplify.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.
//
//b2/core/include/bertini2/function_tree/simplify.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 b2/core/include/bertini2/function_tree/simplify.hpp. If not, see <http://www.gnu.org/licenses/>.
//
// Copyright(C) 2017-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:
// silviana amethyst, university of wisconsin-eau claire
/**
\file include/bertini2/function_tree/simplify.hpp
\brief simplification methods for nodal functions
General methods exploting polymorphism, for simplifying a Node, and all subnodes
*/
#ifndef BERTINI_FUNCTION_TREE_SIMPLIFY_HPP
#define BERTINI_FUNCTION_TREE_SIMPLIFY_HPP
#pragma once
#include "bertini2/function_tree/node.hpp"
namespace bertini {
unsigned Simplify(std::shared_ptr<bertini::node::Node> const& n);
} // namespace bertini
#endif //include guards

View 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

File diff suppressed because it is too large Load Diff

View 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

View 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

View 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

View 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