Bertini 2 d882924 (2026-10-06 19:56 UTC)
Numerical algebraic geometry library (C++ core)
Loading...
Searching...
No Matches
trig.hpp
Go to the documentation of this file.
1//This file is part of Bertini 2.
2//
3//trig.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//trig.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 trig.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// trig.hpp: Declares the trigonometric operator classes.
23
30
31#ifndef BERTINI_TRIGONOMETRIC_OPERATOR_HPP
32#define BERTINI_TRIGONOMETRIC_OPERATOR_HPP
33
36
37
38
39namespace bertini {
40namespace node{
47 {
48 public:
50
51
52 TrigOperator(const std::shared_ptr<Node> & N) : UnaryOperator(N)
53 {};
54
55 virtual ~TrigOperator() = default;
56
57 protected:
59 private:
61
62 template <typename Archive>
63 void serialize(Archive& ar, const unsigned /*version*/) {
64 ar & boost::serialization::base_object<UnaryOperator>(*this);
65 }
66
67
68 };
69
70
71
72
73
79 class SinOperator : public TrigOperator
80 {
81 public:
83
84 std::shared_ptr<Node> Simplified() const override;
85 std::shared_ptr<Node> Subs(SubstitutionMap const& substitutions) const override;
86 std::shared_ptr<Node> Homogenized(VariableGroup const& vars, std::shared_ptr<Variable> const& homvar) const override;
87
89 template<typename... Ts>
90 static
91 std::shared_ptr<SinOperator> Make(Ts&& ...ts){
92 return std::static_pointer_cast<SinOperator>(Intern(std::shared_ptr<Node>( new SinOperator(ts...) )));
93 }
94
95 private:
96 SinOperator(const std::shared_ptr<Node> & N) : TrigOperator(N)
97 {};
98
99 public:
100
101
102
103 void print(std::ostream & target) const override;
104
105
109 std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const override;
110
111 virtual ~SinOperator() = default;
112
113 protected:
114
115
116
117
118
119
120
121
122 private:
123 SinOperator() = default;
125
126 template <typename Archive>
127 void serialize(Archive& ar, const unsigned /*version*/) {
128 ar & boost::serialization::base_object<TrigOperator>(*this);
129 }
130 };
131
132
138 class ArcSinOperator : public TrigOperator
139 {
140 public:
142
143 std::shared_ptr<Node> Simplified() const override;
144 std::shared_ptr<Node> Subs(SubstitutionMap const& substitutions) const override;
145 std::shared_ptr<Node> Homogenized(VariableGroup const& vars, std::shared_ptr<Variable> const& homvar) const override;
146
148 template<typename... Ts>
149 static
150 std::shared_ptr<ArcSinOperator> Make(Ts&& ...ts){
151 return std::static_pointer_cast<ArcSinOperator>(Intern(std::shared_ptr<Node>( new ArcSinOperator(ts...) )));
152 }
153
154 private:
155 ArcSinOperator(const std::shared_ptr<Node> & N) : TrigOperator(N)
156 {};
157
158 public:
159
160 void print(std::ostream & target) const override;
161
162
166 std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const override;
167
168 virtual ~ArcSinOperator() = default;
169
170 protected:
171
172
173
174
175
176
177
178 private:
179 ArcSinOperator() = default;
181
182
183 template <typename Archive>
184 void serialize(Archive& ar, const unsigned /*version*/) {
185 ar & boost::serialization::base_object<TrigOperator>(*this);
186 }
187 };
188
189
190
191
192
193
194
195
201 class CosOperator : public TrigOperator
202 {
203 public:
205
206 std::shared_ptr<Node> Simplified() const override;
207 std::shared_ptr<Node> Subs(SubstitutionMap const& substitutions) const override;
208 std::shared_ptr<Node> Homogenized(VariableGroup const& vars, std::shared_ptr<Variable> const& homvar) const override;
209
211 template<typename... Ts>
212 static
213 std::shared_ptr<CosOperator> Make(Ts&& ...ts){
214 return std::static_pointer_cast<CosOperator>(Intern(std::shared_ptr<Node>( new CosOperator(ts...) )));
215 }
216
217 private:
218 CosOperator(const std::shared_ptr<Node> & N) : TrigOperator(N)
219 {};
220
221 public:
222
223
224
225 void print(std::ostream & target) const override;
226
227
228
229
233 std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const override;
234
235 virtual ~CosOperator() = default;
236
237 protected:
238
239
240
241
242
243
244
245
246
247 private:
248 CosOperator() = default;
250
251 template <typename Archive>
252 void serialize(Archive& ar, const unsigned /*version*/) {
253 ar & boost::serialization::base_object<TrigOperator>(*this);
254 }
255 };
256
257
263 class ArcCosOperator : public TrigOperator
264 {
265 public:
267
268 std::shared_ptr<Node> Simplified() const override;
269 std::shared_ptr<Node> Subs(SubstitutionMap const& substitutions) const override;
270 std::shared_ptr<Node> Homogenized(VariableGroup const& vars, std::shared_ptr<Variable> const& homvar) const override;
271
273 template<typename... Ts>
274 static
275 std::shared_ptr<ArcCosOperator> Make(Ts&& ...ts){
276 return std::static_pointer_cast<ArcCosOperator>(Intern(std::shared_ptr<Node>( new ArcCosOperator(ts...) )));
277 }
278
279 private:
280 ArcCosOperator(const std::shared_ptr<Node> & N) : TrigOperator(N)
281 {};
282 public:
283
284
285
286 void print(std::ostream & target) const override;
287
288
289
293 std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const override;
294
295
296 virtual ~ArcCosOperator() = default;
297
298 protected:
299
300
301
302
303
304
305
306
307 private:
308 ArcCosOperator() = default;
310
311 template <typename Archive>
312 void serialize(Archive& ar, const unsigned /*version*/) {
313 ar & boost::serialization::base_object<TrigOperator>(*this);
314 }
315 };
316
317
318
319
320
321
322
323
324
325
331 class TanOperator : public TrigOperator
332 {
333 public:
335
336 std::shared_ptr<Node> Simplified() const override;
337 std::shared_ptr<Node> Subs(SubstitutionMap const& substitutions) const override;
338 std::shared_ptr<Node> Homogenized(VariableGroup const& vars, std::shared_ptr<Variable> const& homvar) const override;
339
341 template<typename... Ts>
342 static
343 std::shared_ptr<TanOperator> Make(Ts&& ...ts){
344 return std::static_pointer_cast<TanOperator>(Intern(std::shared_ptr<Node>( new TanOperator(ts...) )));
345 }
346
347 private:
348 TanOperator(const std::shared_ptr<Node> & N) : TrigOperator(N)
349 {};
350 public:
351
352
353
354 void print(std::ostream & target) const override;
355
356
360 std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const override;
361
362 virtual ~TanOperator() = default;
363
364 protected:
365
366
367
368
369
370
371
372
373 private:
374 TanOperator() = default;
376
377
378 template <typename Archive>
379 void serialize(Archive& ar, const unsigned /*version*/) {
380 ar & boost::serialization::base_object<TrigOperator>(*this);
381 }
382 };
383
384
390 class ArcTanOperator : public TrigOperator
391 {
392 public:
394
395 std::shared_ptr<Node> Simplified() const override;
396 std::shared_ptr<Node> Subs(SubstitutionMap const& substitutions) const override;
397 std::shared_ptr<Node> Homogenized(VariableGroup const& vars, std::shared_ptr<Variable> const& homvar) const override;
398
400 template<typename... Ts>
401 static
402 std::shared_ptr<ArcTanOperator> Make(Ts&& ...ts){
403 return std::static_pointer_cast<ArcTanOperator>(Intern(std::shared_ptr<Node>( new ArcTanOperator(ts...) )));
404 }
405
406 private:
407 ArcTanOperator(const std::shared_ptr<Node> & N) : TrigOperator(N)
408 {};
409 public:
410
411
412
413 void print(std::ostream & target) const override;
414
415
419 std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const override;
420
421 virtual ~ArcTanOperator() = default;
422
423 protected:
424
425
426
427
428
429
430
431 private:
432 ArcTanOperator() = default;
434
435 template <typename Archive>
436 void serialize(Archive& ar, const unsigned /*version*/) {
437 ar & boost::serialization::base_object<TrigOperator>(*this);
438 }
439 };
440
441
442 // begin the overload of operators
443
445 inline std::shared_ptr<Node> sin(const std::shared_ptr<Node> & N)
446 {
447 return SinOperator::Make(N);
448 }
449
451 inline std::shared_ptr<Node> asin(const std::shared_ptr<Node> & N)
452 {
453 return ArcSinOperator::Make(N);
454 }
455
456
457
459 inline std::shared_ptr<Node> cos(const std::shared_ptr<Node> & N)
460 {
461 return CosOperator::Make(N);
462 }
463
464
465
467 inline std::shared_ptr<Node> acos(const std::shared_ptr<Node> & N)
468 {
469 return ArcCosOperator::Make(N);
470 }
471
472
473
475 inline std::shared_ptr<Node> tan(const std::shared_ptr<Node> & N)
476 {
477 return TanOperator::Make(N);
478 }
479
480
481
483 inline std::shared_ptr<Node> atan(const std::shared_ptr<Node> & N)
484 {
485 return ArcTanOperator::Make(N);
486 }
487
488
489} // re: namespace node
490} // re: namespace bertini
491
492
493#endif
Provides the artithmetic Node types, such as Sum and Power.
Provides the arc cosine Operator.
Definition trig.hpp:264
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).
std::shared_ptr< Node > Simplified() const override
Functionally simplify this tree, returning a NEW simplified tree.
void print(std::ostream &target) const override
Virtual method for printing Nodes to arbitrary output streams.
virtual ~ArcCosOperator()=default
static std::shared_ptr< ArcCosOperator > Make(Ts &&...ts)
Construct (and intern) a ArcCosOperator node.
Definition trig.hpp:275
friend class boost::serialization::access
Definition trig.hpp:309
std::shared_ptr< Node > Differentiate(std::shared_ptr< Variable > const &v=nullptr) const override
Differentiates the cosine function.
std::shared_ptr< Node > Subs(SubstitutionMap const &substitutions) const override
Symbolically substitute variables, returning a NEW tree.
Provides the inverse sine Operator.
Definition trig.hpp:139
void print(std::ostream &target) const override
Virtual method for printing Nodes to arbitrary output streams.
std::shared_ptr< Node > Differentiate(std::shared_ptr< Variable > const &v=nullptr) const override
Differentiates the sine function.
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).
std::shared_ptr< Node > Simplified() const override
Functionally simplify this tree, returning a NEW simplified tree.
static std::shared_ptr< ArcSinOperator > Make(Ts &&...ts)
Construct (and intern) a ArcSinOperator node.
Definition trig.hpp:150
std::shared_ptr< Node > Subs(SubstitutionMap const &substitutions) const override
Symbolically substitute variables, returning a NEW tree.
friend class boost::serialization::access
Definition trig.hpp:180
virtual ~ArcSinOperator()=default
Provides the inverse tangent Operator.
Definition trig.hpp:391
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).
std::shared_ptr< Node > Differentiate(std::shared_ptr< Variable > const &v=nullptr) const override
Differentiates the tangent function.
virtual ~ArcTanOperator()=default
void print(std::ostream &target) const override
Virtual method for printing Nodes to arbitrary output streams.
std::shared_ptr< Node > Subs(SubstitutionMap const &substitutions) const override
Symbolically substitute variables, returning a NEW tree.
friend class boost::serialization::access
Definition trig.hpp:433
std::shared_ptr< Node > Simplified() const override
Functionally simplify this tree, returning a NEW simplified tree.
static std::shared_ptr< ArcTanOperator > Make(Ts &&...ts)
Construct (and intern) a ArcTanOperator node.
Definition trig.hpp:402
Provides the cosine Operator.
Definition trig.hpp:202
void print(std::ostream &target) const override
Virtual method for printing Nodes to arbitrary output streams.
static std::shared_ptr< CosOperator > Make(Ts &&...ts)
Construct (and intern) a CosOperator node.
Definition trig.hpp:213
virtual ~CosOperator()=default
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).
std::shared_ptr< Node > Simplified() const override
Functionally simplify this tree, returning a NEW simplified tree.
friend class boost::serialization::access
Definition trig.hpp:249
std::shared_ptr< Node > Subs(SubstitutionMap const &substitutions) const override
Symbolically substitute variables, returning a NEW tree.
std::shared_ptr< Node > Differentiate(std::shared_ptr< Variable > const &v=nullptr) const override
Differentiates the cosine function.
An interface for all nodes in a function tree, and for a function object as well.
Definition node.hpp:114
Provides the sine Operator.
Definition trig.hpp:80
std::shared_ptr< Node > Differentiate(std::shared_ptr< Variable > const &v=nullptr) const override
Differentiates the sine function.
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).
std::shared_ptr< Node > Subs(SubstitutionMap const &substitutions) const override
Symbolically substitute variables, returning a NEW tree.
friend class boost::serialization::access
Definition trig.hpp:124
static std::shared_ptr< SinOperator > Make(Ts &&...ts)
Construct (and intern) a SinOperator node.
Definition trig.hpp:91
void print(std::ostream &target) const override
Virtual method for printing Nodes to arbitrary output streams.
virtual ~SinOperator()=default
std::shared_ptr< Node > Simplified() const override
Functionally simplify this tree, returning a NEW simplified tree.
Provides the tangent Operator.
Definition trig.hpp:332
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).
std::shared_ptr< Node > Differentiate(std::shared_ptr< Variable > const &v=nullptr) const override
Differentiates the tangent function.
void print(std::ostream &target) const override
Virtual method for printing Nodes to arbitrary output streams.
std::shared_ptr< Node > Subs(SubstitutionMap const &substitutions) const override
Symbolically substitute variables, returning a NEW tree.
virtual ~TanOperator()=default
static std::shared_ptr< TanOperator > Make(Ts &&...ts)
Construct (and intern) a TanOperator node.
Definition trig.hpp:343
std::shared_ptr< Node > Simplified() const override
Functionally simplify this tree, returning a NEW simplified tree.
friend class boost::serialization::access
Definition trig.hpp:375
Abstract class for trigonometric Operator types.
Definition trig.hpp:47
TrigOperator()
Definition trig.hpp:58
friend class boost::serialization::access
Definition trig.hpp:60
virtual ~TrigOperator()=default
TrigOperator(const std::shared_ptr< Node > &N)
Construct a trigonometric operator over a single operand node.
Definition trig.hpp:52
UnaryOperator(const std::shared_ptr< Node > &n)
Construct a unary operator over a single operand node.
Definition operator.hpp:78
Represents variable leaves in the function tree.
Definition variable.hpp:48
Definition canonical.hpp:56
std::shared_ptr< Node > tan(const std::shared_ptr< Node > &N)
Build a tangent expression-tree node.
Definition trig.hpp:475
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< Node > asin(const std::shared_ptr< Node > &N)
Build a arcsine expression-tree node.
Definition trig.hpp:451
std::shared_ptr< Node > acos(const std::shared_ptr< Node > &N)
Build a arccosine expression-tree node.
Definition trig.hpp:467
std::shared_ptr< Node > cos(const std::shared_ptr< Node > &N)
Build a cosine expression-tree node.
Definition trig.hpp:459
std::shared_ptr< Node > sin(const std::shared_ptr< Node > &N)
Build a sine expression-tree node.
Definition trig.hpp:445
std::shared_ptr< Node > atan(const std::shared_ptr< Node > &N)
Build a arctangent expression-tree node.
Definition trig.hpp:483
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
Provides the abstract Operator Node type.
#define BERTINI_DEFAULT_VISITABLE()
macro for classes which want default Accept implementation, having nothing fancy to do when accepting...
Definition visitable.hpp:121