Bertini 2 d882924 (2026-10-06 19:56 UTC)
Numerical algebraic geometry library (C++ core)
Loading...
Searching...
No Matches
operator.hpp
Go to the documentation of this file.
1//This file is part of Bertini 2.
2//
3//operator.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//operator.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 operator.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// operator.hpp: Declares the class Operator.
23
30
31#ifndef BERTINI_OPERATOR_HPP
32#define BERTINI_OPERATOR_HPP
33
35
36#include <vector>
37
38
39namespace bertini {
40namespace node{
41
47 class Operator : public Node
48 {
49
50 public:
51
52 virtual ~Operator() = default;
53
54 private:
55
57
58 template <typename Archive>
59 void serialize(Archive& ar, const unsigned /*version*/) {
60 ar & boost::serialization::base_object<Node>(*this);
61 }
62 };
63
64
65
73 class UnaryOperator : public Operator
74 {
75 public:
76
78 UnaryOperator(const std::shared_ptr<Node> & n) : operand_(n)
79 {}
80
81
82
83 virtual ~UnaryOperator() = default;
84
85 // Structural hash/equality for every unary op (typeid distinguishes Sin/Cos/Exp/...);
86 // IntegerPowerOperator overrides to fold in its exponent.
87 std::size_t HashImpl() const override;
88 bool IsSame(Node const& other) const override;
89
90
91
93 void SetOperand(std::shared_ptr<Node> n);
94
95
96
98 std::shared_ptr<Node> Operand() const;
99
100
101
110 int Degree(std::shared_ptr<Variable> const& v = nullptr) const override;
111
113 int Degree(VariableGroup const& vars) const override;
114
115
119 std::vector<int> MultiDegreeImpl(VariableGroup const& vars) const override;
120
121 bool IsHomogeneous(std::shared_ptr<Variable> const& v = nullptr) const override;
122
123
127 bool IsHomogeneous(VariableGroup const& vars) const override;
128
129
130
131
132
133
134 protected:
135 //Stores the single child of the unary operator
136 std::shared_ptr<Node> operand_;
138 private:
140
141 template <typename Archive>
142 void serialize(Archive& ar, const unsigned /*version*/) {
143 ar & boost::serialization::base_object<Operator>(*this);
144 ar & operand_;
145 }
146 };
147
148
149
150
158 class NaryOperator : public Operator
159 {
160 public:
161
162 virtual ~NaryOperator() = default;
163
164
165
167 virtual void AddOperand(std::shared_ptr<Node> n);
168
169
171 size_t NumOperands() const;
172
174 inline auto const& Operands() const{
175 return operands_;
176 }
177
178
180 std::shared_ptr<Node> FirstOperand() const;
181
187
188
189
190 protected:
191
192 //Stores all children for this operator node.
193 //This is an NaryOperator and can have any number of children.
194 std::vector< std::shared_ptr<Node> > operands_;
195
196 // constructor is protected to help prevent instantiating empty operators
198
199 private:
200
201 virtual void PrecisionChangeSpecific(unsigned prec) const;
202
203
205
206 template <typename Archive>
207 void serialize(Archive& ar, const unsigned /*version*/) {
208 ar & boost::serialization::base_object<Operator>(*this);
209 ar & operands_;
210 }
211
212 };
213
214
215} // re: namespace node
216} // re: namespace bertini
217
218
219#endif
std::shared_ptr< Node > FirstOperand() const
std::vector< std::shared_ptr< Node > > operands_
Change the precision of this variable-precision tree node.
Definition operator.hpp:194
auto const & Operands() const
Definition operator.hpp:174
virtual void AddOperand(std::shared_ptr< Node > n)
Add an operand (child) onto this operator.
virtual ~NaryOperator()=default
friend class boost::serialization::access
Definition operator.hpp:204
NaryOperator()
Definition operator.hpp:197
An interface for all nodes in a function tree, and for a function object as well.
Definition node.hpp:114
Abstract Node type from which all Operators inherit.
Definition operator.hpp:48
virtual ~Operator()=default
friend class boost::serialization::access
Definition operator.hpp:56
std::shared_ptr< Node > operand_
The single child (operand) of the unary operator.
Definition operator.hpp:136
bool IsHomogeneous(VariableGroup const &vars) const override
Check for homogeneity, with respect to a variable group.
virtual ~UnaryOperator()=default
int Degree(VariableGroup const &vars) const override
Degree with respect to a variable group, by the same rule as the one-variable form.
std::shared_ptr< Node > Operand() const
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 SetOperand(std::shared_ptr< Node > n)
Set the single child (operand) of this unary operator.
UnaryOperator(const std::shared_ptr< Node > &n)
Construct a unary operator over a single operand node.
Definition operator.hpp:78
std::size_t HashImpl() const override
Compute this node's structural hash.
friend class boost::serialization::access
Definition operator.hpp:139
int Degree(std::shared_ptr< Variable > const &v=nullptr) const override
Degree with respect to one variable (all variables when v is null).
std::vector< int > MultiDegreeImpl(VariableGroup const &vars) const override
Compute the multidegree with respect to a variable group.
bool IsSame(Node const &other) const override
Order-sensitive structural equality, shallow given interned children.
UnaryOperator()
Definition operator.hpp:137
Definition canonical.hpp:56
Definition algorithm_builder.hpp:36
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 Node base class.