26#ifndef BERTINI_NAMED_EXPRESSION_HPP
27#define BERTINI_NAMED_EXPRESSION_HPP
55 template<
typename... Ts>
57 std::shared_ptr<NamedExpression>
Make(Ts&& ...ts){
58 return std::static_pointer_cast<NamedExpression>(
Intern(std::shared_ptr<Node>(
new NamedExpression(ts...) )));
62 void print(std::ostream & target)
const override
79 return o &&
name() == o->name() &&
EntryNode().get() == o->EntryNode().get();
91 std::shared_ptr<Node>
Differentiate(std::shared_ptr<Variable>
const& v =
nullptr)
const override;
94 int Degree(std::shared_ptr<Variable>
const& v =
nullptr)
const override;
103 bool IsHomogeneous(std::shared_ptr<Variable>
const& v =
nullptr)
const override;
123 template <
typename Archive>
124 void serialize(Archive& ar,
const unsigned ) {
125 ar & boost::serialization::base_object<NamedSymbol>(*
this);
132 inline std::shared_ptr<NamedExpression>
Named(std::shared_ptr<Node>
const& expr, std::string
const& name)
bool IsSame(Node const &other) const override
Order-sensitive structural equality, shallow given interned children.
Definition named_expression.hpp:75
void print(std::ostream &target) const override
Prints as just the name (the expansion is shown by the System's Describe).
Definition named_expression.hpp:62
int Degree(std::shared_ptr< Variable > const &v=nullptr) const override
the degree is the degree of the wrapped expression
std::shared_ptr< Node > Homogenized(VariableGroup const &vars, std::shared_ptr< Variable > const &homvar) const override
Homogenize a tree, returning a NEW homogenized tree (functional / non-mutating).
const std::shared_ptr< Node > & EntryNode() const
flips the fresh-eval bit back to fresh (downward through the wrapped expression)
NamedExpression()=default
bool IsHomogeneous(std::shared_ptr< Variable > const &v=nullptr) const override
Check for homogeneity, absolutely with respect to all variables, including path variables and all oth...
void EnsureNotEmpty() const
throws a runtime error if the entry node is nullptr
std::shared_ptr< Node > Subs(SubstitutionMap const &substitutions) const override
Symbolically substitute variables, returning a NEW tree.
virtual ~NamedExpression()=default
change the precision of this variable-precision tree node
static std::shared_ptr< NamedExpression > Make(Ts &&...ts)
Construct (and intern) a NamedExpression node.
Definition named_expression.hpp:57
std::vector< int > MultiDegreeImpl(VariableGroup const &vars) const override
Per-node-type multidegree.
friend class boost::serialization::access
Definition named_expression.hpp:121
bool IsHomogeneous(VariableGroup const &vars) const override
Check for homogeneity, with respect to a variable group.
std::size_t HashImpl() const override
Compute this node's structural hash.
Definition named_expression.hpp:68
std::shared_ptr< Node > Differentiate(std::shared_ptr< Variable > const &v=nullptr) const override
differentiate the wrapped expression
int Degree(VariableGroup const &vars) const override
Compute the overall degree with respect to a variable group.
std::shared_ptr< Node > entry_node_
The root node of the named expression.
Definition named_expression.hpp:114
NamedSymbol(const std::string &new_name)
Parameterized constructor, sets the name of the symbol.
const std::string & name() const
Get the name of the named symbol.
An interface for all nodes in a function tree, and for a function object as well.
Definition node.hpp:114
static void HashCombine(std::size_t &seed, std::size_t value)
Combine an extra value into a running hash (boost::hash_combine recipe).
Definition node.hpp:384
std::size_t Hash() const
Memoized structural hash of this node.
Definition canonical.hpp:56
std::shared_ptr< Node > Intern(std::shared_ptr< Node > const &candidate)
Hash-cons a freshly-built node: return an existing structurally-equal node if one is live,...
std::shared_ptr< NamedExpression > Named(std::shared_ptr< Node > const &expr, std::string const &name)
Give an expression a name: Named(x*x + y*y, "a").
Definition named_expression.hpp:132
Definition algorithm_builder.hpp:36
std::map< std::string, std::shared_ptr< node::Node > > SubstitutionMap
A substitution request for Node::Subs: variable name -> the node to put in its place.
Definition node.hpp:72
std::vector< std::shared_ptr< node::Variable > > VariableGroup
An ordered group of variables (the unit of homogenization / variable grouping).
Definition node.hpp:69
Defines the abstract Symbol and NamedSymbol classes,.
#define BERTINI_DEFAULT_VISITABLE()
macro for classes which want default Accept implementation, having nothing fancy to do when accepting...
Definition visitable.hpp:121