Bertini 2 d882924 (2026-10-06 19:56 UTC)
Numerical algebraic geometry library (C++ core)
Loading...
Searching...
No Matches
variable.hpp
Go to the documentation of this file.
1//This file is part of Bertini 2.
2//
3//include/bertini2/function_tree/symbols/variable.hpp is free software: you can redistribute it and/or modify
4//it under the terms of the GNU General Public License as published by
5//the Free Software Foundation, either version 3 of the License, or
6//(at your option) any later version.
7//
8//include/bertini2/function_tree/symbols/variable.hpp is distributed in the hope that it will be useful,
9//but WITHOUT ANY WARRANTY; without even the implied warranty of
10//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11//GNU General Public License for more details.
12//
13//You should have received a copy of the GNU General Public License
14//along with include/bertini2/function_tree/symbols/variable.hpp. If not, see <http://www.gnu.org/licenses/>.
15//
16// Copyright(C) Bertini2 Development Team
17//
18// See <http://www.gnu.org/licenses/> for a copy of the license,
19// as well as COPYING. Bertini2 is provided with permitted
20// additional terms in the b2/licenses/ directory.
21
22// include/bertini2/function_tree/symbols/variable.hpp: Declares the class Variable.
23
24
31#ifndef BERTINI_FUNCTION_TREE_VARIABLE_HPP
32#define BERTINI_FUNCTION_TREE_VARIABLE_HPP
33
36
37
38namespace bertini {
39namespace node{
47 class Variable : public NamedSymbol
48 {
49 public:
51
52
53
54 template<typename... Ts>
55 static
56 std::shared_ptr<Variable> Make(Ts&& ...ts){
57 return std::static_pointer_cast<Variable>(Intern(std::shared_ptr<Node>( new Variable(ts...) )));
58 }
59
60 private:
61 Variable(std::string new_name);
62
63 public:
64
65
66 virtual ~Variable() = default;
67
68 // variables are canonical BY NAME -- Make("x") interns to a single shared x,
69 // so system1's x IS system2's x. (Value/eval-state lives on that shared node until C2
70 // moves it into a per-thread eval context.)
71 std::size_t HashImpl() const override
72 {
73 std::size_t h = typeid(Variable).hash_code();
74 HashCombine(h, std::hash<std::string>{}(name()));
75 return h;
76 }
77 bool IsSame(Node const& other) const override
78 {
79 auto o = dynamic_cast<Variable const*>(&other);
80 return o && name() == o->name();
81 }
82
83
85 explicit operator std::string(){return name();}
86
87
88
92 std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const override;
93
102 std::shared_ptr<Node> Subs(SubstitutionMap const& substitutions) const override;
103
109 int Degree(std::shared_ptr<Variable> const& v = nullptr) const override;
110
111
112 int Degree(VariableGroup const& vars) const override;
113
114 std::vector<int> MultiDegreeImpl(VariableGroup const& vars) const override;
115
116
117 bool IsHomogeneous(std::shared_ptr<Variable> const& v = nullptr) const override;
118
122 bool IsHomogeneous(VariableGroup const& vars) const override;
123
124 protected:
125
127 private:
128
130
131 template <typename Archive>
132 void serialize(Archive& ar, const unsigned /*version*/) {
133 ar & boost::serialization::base_object<NamedSymbol>(*this);
134 }
135
136 };
137
138
139
140
141} // re: namespace node
142} // re: namespace bertini
143
144
145
146
147#endif
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
int Degree(VariableGroup const &vars) const override
Compute the overall degree with respect to a variable group.
bool IsHomogeneous(VariableGroup const &vars) const override
Check for homogeneity, with respect to a variable group.
int Degree(std::shared_ptr< Variable > const &v=nullptr) const override
Compute the degree with respect to a single variable.
std::shared_ptr< Node > Differentiate(std::shared_ptr< Variable > const &v=nullptr) const override
Differentiates a variable.
virtual ~Variable()=default
std::shared_ptr< Node > Subs(SubstitutionMap const &substitutions) const override
Substitutes this variable: if its name is a key in substitutions, returns the associated replacement ...
friend class boost::serialization::access
Definition variable.hpp:129
static std::shared_ptr< Variable > Make(Ts &&...ts)
Construct (and intern) a Variable node.
Definition variable.hpp:56
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...
std::size_t HashImpl() const override
Compute this node's structural hash.
Definition variable.hpp:71
bool IsSame(Node const &other) const override
Order-sensitive structural equality, shallow given interned children.
Definition variable.hpp:77
std::vector< int > MultiDegreeImpl(VariableGroup const &vars) const override
Per-node-type multidegree.
Provides the differential Node class.
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,...
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