Bertini 2 - C++ Core
Software for Numerical Algebraic Geometry
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) 2015 - 2021 by 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// individual authors of this file include:
23// James Collins
24// West Texas A&M University
25// Spring, Summer 2015
26//
27// silviana amethyst, university of wisconsin-eau claire
28//
29//
30//
31// trig.hpp: Declares the trigonometric operator classes.
32
39
40#ifndef BERTINI_TRIGONOMETRIC_OPERATOR_HPP
41#define BERTINI_TRIGONOMETRIC_OPERATOR_HPP
42
45
46
47
48namespace bertini {
49namespace node{
55 class TrigOperator: public virtual UnaryOperator
56 {
57 public:
58 BERTINI_DEFAULT_VISITABLE()
59
60 TrigOperator(const std::shared_ptr<Node> & N) : UnaryOperator(N)
61 {};
62
63 virtual ~TrigOperator() = default;
64
70 int Degree(std::shared_ptr<Variable> const& v = nullptr) const override;
71 protected:
72 TrigOperator(){}
73 private:
74 friend class boost::serialization::access;
75
76 template <typename Archive>
77 void serialize(Archive& ar, const unsigned version) {
78 ar & boost::serialization::base_object<UnaryOperator>(*this);
79 }
80
81
82 };
83
84
85
86
87
94 class SinOperator : public virtual TrigOperator, public virtual EnableSharedFromThisVirtual<SinOperator>
95 {
96 public:
97 BERTINI_DEFAULT_VISITABLE()
98
99 unsigned EliminateZeros() override;
100 unsigned EliminateOnes() override;
101
102 template<typename... Ts>
103 static
104 std::shared_ptr<SinOperator> Make(Ts&& ...ts){
105 return std::shared_ptr<SinOperator>( new SinOperator(ts...) );
106 }
107
108 private:
109 SinOperator(const std::shared_ptr<Node> & N) : TrigOperator(N), UnaryOperator(N)
110 {};
111
112 public:
113
114
115
116 void print(std::ostream & target) const override;
117
118
122 std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const override;
123
124 virtual ~SinOperator() = default;
125
126 protected:
127
128
129 // Specific implementation of FreshEval for negate.
130 dbl FreshEval_d(std::shared_ptr<Variable> const& diff_variable) const override;
131
132 mpfr_complex FreshEval_mp(std::shared_ptr<Variable> const& diff_variable) const override;
133
134
135 void FreshEval_mp(mpfr_complex& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override;
136
137 void FreshEval_d(dbl& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override;
138
139
140 private:
141 SinOperator() = default;
142 friend class boost::serialization::access;
143
144 template <typename Archive>
145 void serialize(Archive& ar, const unsigned version) {
146 ar & boost::serialization::base_object<TrigOperator>(*this);
147 }
148 };
149
150
157 class ArcSinOperator : public virtual TrigOperator, public virtual EnableSharedFromThisVirtual<ArcSinOperator>
158 {
159 public:
160 BERTINI_DEFAULT_VISITABLE()
161
162 unsigned EliminateZeros() override;
163 unsigned EliminateOnes() override;
164
165 template<typename... Ts>
166 static
167 std::shared_ptr<ArcSinOperator> Make(Ts&& ...ts){
168 return std::shared_ptr<ArcSinOperator>( new ArcSinOperator(ts...) );
169 }
170
171 private:
172 ArcSinOperator(const std::shared_ptr<Node> & N) : TrigOperator(N), UnaryOperator(N)
173 {};
174
175 public:
176
177 void print(std::ostream & target) const override;
178
179
183 std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const override;
184
185 virtual ~ArcSinOperator() = default;
186
187 protected:
188
189
190 // Specific implementation of FreshEval for negate.
191 dbl FreshEval_d(std::shared_ptr<Variable> const& diff_variable) const override;
192
193 mpfr_complex FreshEval_mp(std::shared_ptr<Variable> const& diff_variable) const override;
194
195
196 void FreshEval_mp(mpfr_complex& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override;
197
198 void FreshEval_d(dbl& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override;
199
200 private:
201 ArcSinOperator() = default;
202 friend class boost::serialization::access;
203
204
205 template <typename Archive>
206 void serialize(Archive& ar, const unsigned version) {
207 ar & boost::serialization::base_object<TrigOperator>(*this);
208 }
209 };
210
211
212
213
214
215
216
217
224 class CosOperator : public virtual TrigOperator, public virtual EnableSharedFromThisVirtual<CosOperator>
225 {
226 public:
227 BERTINI_DEFAULT_VISITABLE()
228
229 unsigned EliminateZeros() override;
230 unsigned EliminateOnes() override;
231
232 template<typename... Ts>
233 static
234 std::shared_ptr<CosOperator> Make(Ts&& ...ts){
235 return std::shared_ptr<CosOperator>( new CosOperator(ts...) );
236 }
237
238 private:
239 CosOperator(const std::shared_ptr<Node> & N) : TrigOperator(N), UnaryOperator(N)
240 {};
241
242 public:
243
244
245
246 void print(std::ostream & target) const override;
247
248
249
250
254 std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const override;
255
256 virtual ~CosOperator() = default;
257
258 protected:
259
260
261 // Specific implementation of FreshEval for negate.
262 dbl FreshEval_d(std::shared_ptr<Variable> const& diff_variable) const override;
263
264 mpfr_complex FreshEval_mp(std::shared_ptr<Variable> const& diff_variable) const override;
265
266
267 void FreshEval_mp(mpfr_complex& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override;
268
269 void FreshEval_d(dbl& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override;
270
271
272
273 private:
274 CosOperator() = default;
275 friend class boost::serialization::access;
276
277 template <typename Archive>
278 void serialize(Archive& ar, const unsigned version) {
279 ar & boost::serialization::base_object<TrigOperator>(*this);
280 }
281 };
282
283
290 class ArcCosOperator : public virtual TrigOperator, public virtual EnableSharedFromThisVirtual<ArcCosOperator>
291 {
292 public:
293 BERTINI_DEFAULT_VISITABLE()
294
295 unsigned EliminateZeros() override;
296 unsigned EliminateOnes() override;
297
298 template<typename... Ts>
299 static
300 std::shared_ptr<ArcCosOperator> Make(Ts&& ...ts){
301 return std::shared_ptr<ArcCosOperator>( new ArcCosOperator(ts...) );
302 }
303
304 private:
305 ArcCosOperator(const std::shared_ptr<Node> & N) : TrigOperator(N), UnaryOperator(N)
306 {};
307 public:
308
309
310
311 void print(std::ostream & target) const override;
312
313
314
318 std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const override;
319
320
321 virtual ~ArcCosOperator() = default;
322
323 protected:
324
325
326 // Specific implementation of FreshEval for negate.
327 dbl FreshEval_d(std::shared_ptr<Variable> const& diff_variable) const override;
328
329 mpfr_complex FreshEval_mp(std::shared_ptr<Variable> const& diff_variable) const override;
330
331
332 void FreshEval_mp(mpfr_complex& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override;
333
334 void FreshEval_d(dbl& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override;
335
336
337 private:
338 ArcCosOperator() = default;
339 friend class boost::serialization::access;
340
341 template <typename Archive>
342 void serialize(Archive& ar, const unsigned version) {
343 ar & boost::serialization::base_object<TrigOperator>(*this);
344 }
345 };
346
347
348
349
350
351
352
353
354
355
362 class TanOperator : public virtual TrigOperator, public virtual EnableSharedFromThisVirtual<TanOperator>
363 {
364 public:
365 BERTINI_DEFAULT_VISITABLE()
366
367 unsigned EliminateZeros() override;
368 unsigned EliminateOnes() override;
369
370 template<typename... Ts>
371 static
372 std::shared_ptr<TanOperator> Make(Ts&& ...ts){
373 return std::shared_ptr<TanOperator>( new TanOperator(ts...) );
374 }
375
376 private:
377 TanOperator(const std::shared_ptr<Node> & N) : TrigOperator(N), UnaryOperator(N)
378 {};
379 public:
380
381
382
383 void print(std::ostream & target) const override;
384
385
389 std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const override;
390
391 virtual ~TanOperator() = default;
392
393 protected:
394
395
396 // Specific implementation of FreshEval for negate.
397 dbl FreshEval_d(std::shared_ptr<Variable> const& diff_variable) const override;
398
399 mpfr_complex FreshEval_mp(std::shared_ptr<Variable> const& diff_variable) const override;
400
401
402 void FreshEval_mp(mpfr_complex& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override;
403
404 void FreshEval_d(dbl& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override;
405
406
407 private:
408 TanOperator() = default;
409 friend class boost::serialization::access;
410
411
412 template <typename Archive>
413 void serialize(Archive& ar, const unsigned version) {
414 ar & boost::serialization::base_object<TrigOperator>(*this);
415 }
416 };
417
418
425 class ArcTanOperator : public virtual TrigOperator, public virtual EnableSharedFromThisVirtual<ArcTanOperator>
426 {
427 public:
428 BERTINI_DEFAULT_VISITABLE()
429
430 unsigned EliminateZeros() override;
431 unsigned EliminateOnes() override;
432
433 template<typename... Ts>
434 static
435 std::shared_ptr<ArcTanOperator> Make(Ts&& ...ts){
436 return std::shared_ptr<ArcTanOperator>( new ArcTanOperator(ts...) );
437 }
438
439 private:
440 ArcTanOperator(const std::shared_ptr<Node> & N) : TrigOperator(N), UnaryOperator(N)
441 {};
442 public:
443
444
445
446 void print(std::ostream & target) const override;
447
448
452 std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const override;
453
454 virtual ~ArcTanOperator() = default;
455
456 protected:
457
458
459 // Specific implementation of FreshEval for arctangent.
460 dbl FreshEval_d(std::shared_ptr<Variable> const& diff_variable) const override;
461
462 mpfr_complex FreshEval_mp(std::shared_ptr<Variable> const& diff_variable) const override;
463
464
465 void FreshEval_mp(mpfr_complex& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override;
466
467 void FreshEval_d(dbl& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override;
468
469 private:
470 ArcTanOperator() = default;
471 friend class boost::serialization::access;
472
473 template <typename Archive>
474 void serialize(Archive& ar, const unsigned version) {
475 ar & boost::serialization::base_object<TrigOperator>(*this);
476 }
477 };
478
479
480 // begin the overload of operators
481
482 inline std::shared_ptr<Node> sin(const std::shared_ptr<Node> & N)
483 {
484 return SinOperator::Make(N);
485 }
486
487 inline std::shared_ptr<Node> asin(const std::shared_ptr<Node> & N)
488 {
489 return ArcSinOperator::Make(N);
490 }
491
492
493
494 inline std::shared_ptr<Node> cos(const std::shared_ptr<Node> & N)
495 {
496 return CosOperator::Make(N);
497 }
498
499
500
501 inline std::shared_ptr<Node> acos(const std::shared_ptr<Node> & N)
502 {
503 return ArcCosOperator::Make(N);
504 }
505
506
507
508 inline std::shared_ptr<Node> tan(const std::shared_ptr<Node> & N)
509 {
510 return TanOperator::Make(N);
511 }
512
513
514
515 inline std::shared_ptr<Node> atan(const std::shared_ptr<Node> & N)
516 {
517 return ArcTanOperator::Make(N);
518 }
519
520
521} // re: namespace node
522} // re: namespace bertini
523
524
525#endif
Provides the artithmetic Node types, such as Sum and Power.
unsigned EliminateOnes() override
A transform function, which eliminates nodes from the tree.
Definition trig.cpp:187
dbl FreshEval_d(std::shared_ptr< Variable > const &diff_variable) const override
Definition trig.cpp:206
void print(std::ostream &target) const override
Definition trig.cpp:192
std::shared_ptr< Node > Differentiate(std::shared_ptr< Variable > const &v=nullptr) const override
Definition trig.cpp:200
mpfr_complex FreshEval_mp(std::shared_ptr< Variable > const &diff_variable) const override
Definition trig.cpp:211
unsigned EliminateOnes() override
A transform function, which eliminates nodes from the tree.
Definition trig.cpp:96
void print(std::ostream &target) const override
Definition trig.cpp:101
std::shared_ptr< Node > Differentiate(std::shared_ptr< Variable > const &v=nullptr) const override
Definition trig.cpp:108
dbl FreshEval_d(std::shared_ptr< Variable > const &diff_variable) const override
Definition trig.cpp:115
mpfr_complex FreshEval_mp(std::shared_ptr< Variable > const &diff_variable) const override
Definition trig.cpp:120
unsigned EliminateOnes() override
A transform function, which eliminates nodes from the tree.
Definition trig.cpp:279
std::shared_ptr< Node > Differentiate(std::shared_ptr< Variable > const &v=nullptr) const override
Definition trig.cpp:292
void print(std::ostream &target) const override
Definition trig.cpp:284
mpfr_complex FreshEval_mp(std::shared_ptr< Variable > const &diff_variable) const override
Definition trig.cpp:302
dbl FreshEval_d(std::shared_ptr< Variable > const &diff_variable) const override
Definition trig.cpp:297
void print(std::ostream &target) const override
Definition trig.cpp:147
unsigned EliminateOnes() override
A transform function, which eliminates nodes from the tree.
Definition trig.cpp:142
dbl FreshEval_d(std::shared_ptr< Variable > const &diff_variable) const override
Definition trig.cpp:159
mpfr_complex FreshEval_mp(std::shared_ptr< Variable > const &diff_variable) const override
Definition trig.cpp:164
std::shared_ptr< Node > Differentiate(std::shared_ptr< Variable > const &v=nullptr) const override
Definition trig.cpp:154
virtual unsigned EliminateZeros()=0
A transform function, which eliminates nodes from the tree.
std::shared_ptr< Node > Differentiate(std::shared_ptr< Variable > const &v=nullptr) const override
Definition trig.cpp:63
dbl FreshEval_d(std::shared_ptr< Variable > const &diff_variable) const override
Definition trig.cpp:69
mpfr_complex FreshEval_mp(std::shared_ptr< Variable > const &diff_variable) const override
Definition trig.cpp:74
void print(std::ostream &target) const override
Definition trig.cpp:55
unsigned EliminateOnes() override
A transform function, which eliminates nodes from the tree.
Definition trig.cpp:50
dbl FreshEval_d(std::shared_ptr< Variable > const &diff_variable) const override
Definition trig.cpp:251
std::shared_ptr< Node > Differentiate(std::shared_ptr< Variable > const &v=nullptr) const override
Definition trig.cpp:246
void print(std::ostream &target) const override
Definition trig.cpp:239
unsigned EliminateOnes() override
A transform function, which eliminates nodes from the tree.
Definition trig.cpp:234
mpfr_complex FreshEval_mp(std::shared_ptr< Variable > const &diff_variable) const override
Definition trig.cpp:256
int Degree(std::shared_ptr< Variable > const &v=nullptr) const override
Definition trig.cpp:33
Interface for all unary Operator types.
Definition operator.hpp:84
Provides the abstract Operator Node type.