Bertini 2 d882924 (2026-10-06 19:56 UTC)
Numerical algebraic geometry library (C++ core)
Loading...
Searching...
No Matches
arithmetic.hpp
Go to the documentation of this file.
1//This file is part of Bertini 2.
2//
3//arithmetic.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//arithmetic.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 arithmetic.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// arithmetic.hpp: Declares the arithmetic nodes for bertini2.
23
30
31#ifndef BERTINI_OPERATOR_ARITHMETIC_HPP
32#define BERTINI_OPERATOR_ARITHMETIC_HPP
33
34#include <vector>
35#include <string>
36
38
40
41
42
47
50
51#include <cmath>
52
53
54
55
56
57
58
59
60namespace bertini {
61
62namespace node{
69 class SumOperator : public NaryOperator
70 {
71 public:
73
74 virtual ~SumOperator() = default;
75
76 std::shared_ptr<Node> Simplified() const override;
77
78 std::shared_ptr<Node> Subs(SubstitutionMap const& substitutions) const override;
79
81 template<typename... Ts>
82 static
83 std::shared_ptr<SumOperator> Make(Ts&& ...ts){
84 return std::static_pointer_cast<SumOperator>(Intern(std::shared_ptr<Node>( new SumOperator(ts...) )));
85 }
86
87 private:
88 SumOperator(const std::shared_ptr<Node> & s, bool add_or_sub)
89 {
90 AddOperand(s, add_or_sub);
91 }
92
93 SumOperator(const std::shared_ptr<Node> & left, const std::shared_ptr<Node> & right)
94 {
95 AddOperand(left);
96 AddOperand(right);
97 CanonicalizeNaryOperands(operands_, signs_, false);
98 }
99
100
101 SumOperator(const std::shared_ptr<Node> & left, bool add_or_sub_left, const std::shared_ptr<Node> & right, bool add_or_sub_right)
102 {
103 AddOperand(left, add_or_sub_left);
104 AddOperand(right, add_or_sub_right);
105 CanonicalizeNaryOperands(operands_, signs_, false);
106 }
107
108 // Build a complete sum from a full (term, sign) list. The node is fully constructed
109 // before Make() interns it -- so callers never AddOperand AFTER Make (which, with interning,
110 // could mutate a shared interned node).
111 explicit SumOperator(std::vector<std::pair<std::shared_ptr<Node>, bool>> const& terms)
112 {
113 for (auto const& t : terms)
114 AddOperand(t.first, t.second);
115 CanonicalizeNaryOperands(operands_, signs_, false);
116 }
117
118 public:
119
121 SumOperator& operator+=(const std::shared_ptr<Node> & rhs)
122 {
123 this->AddOperand(rhs);
124 return *this;
125 }
126
128 SumOperator& operator-=(const std::shared_ptr<Node> & rhs)
129 {
130 this->AddOperand(rhs,false);
131 return *this;
132 }
133
134
135
136
137
141 void AddOperand(std::shared_ptr<Node> child) override
142 {
143 NaryOperator::AddOperand(std::move(child));
144 signs_.push_back(true);
145 }
146
147
151 void AddOperand(std::shared_ptr<Node> child, bool sign) // not an override
152 {
153 NaryOperator::AddOperand(std::move(child));
154 signs_.push_back(sign);
155 }
156
157
161 void print(std::ostream & target) const override;
162
163 unsigned Precedence() const override
164 {
165 return PrecSum;
166 }
167
168
169
170
174 std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const override;
175
179 int Degree(std::shared_ptr<Variable> const& v = nullptr) const override;
180
181
182 int Degree(VariableGroup const& vars) const override;
183
187 std::vector<int> MultiDegreeImpl(VariableGroup const& vars) const override;
188
190 inline
191 const auto& GetSigns() const{ return this-> signs_;}
192
193
194
198 std::shared_ptr<Node> Homogenized(VariableGroup const& vars, std::shared_ptr<Variable> const& homvar) const override;
199 std::size_t HashImpl() const override;
200 bool IsSame(Node const& other) const override;
201
202 bool IsHomogeneous(std::shared_ptr<Variable> const& v = nullptr) const override;
203
207 bool IsHomogeneous(VariableGroup const& vars) const override;
208
209
210
211
212
213
214 protected:
215
216
217
218
219
220 private:
221 // Stores the sign of the particular term. There is a one-one
222 // correspondence between elements of signs_ and operand_. This
223 // is enforced by the AddOperand method below, redefined in SumOperator.
224
225 // TODO(JBC): If we add method to delete child, must also delete signs_ entry.
226 std::vector<bool> signs_;
227
228 private:
229
230 SumOperator() = default;
231
233
234 template <typename Archive>
235 void serialize(Archive& ar, const unsigned /*version*/) {
236 ar & boost::serialization::base_object<NaryOperator>(*this);
237 ar & signs_;
238 }
239
240
241 void PrecisionChangeSpecific(unsigned prec) const override
242 {
243 temp_mp_.precision(prec);
244 }
245
246 mutable complex_mp temp_mp_;
247 mutable complex_dbl temp_d_;
248
249 friend MultOperator;
250 };
251
252
253
254
255
256
257
258
259
260
261
262
263
264
270 class NegateOperator : public UnaryOperator
271 {
272 public:
274
275
276 template<typename... Ts>
277 static
278 std::shared_ptr<NegateOperator> Make(Ts&& ...ts){
279 return std::static_pointer_cast<NegateOperator>(Intern(std::shared_ptr<Node>( new NegateOperator(ts...) )));
280 }
281
282 private:
283
284 NegateOperator(const std::shared_ptr<Node> & N) : UnaryOperator(N)
285 {};
286
287 public:
288
289 std::shared_ptr<Node> Simplified() const override;
290
291 std::shared_ptr<Node> Subs(SubstitutionMap const& substitutions) const override;
292 std::shared_ptr<Node> Homogenized(VariableGroup const& vars, std::shared_ptr<Variable> const& homvar) const override;
293
297 void print(std::ostream & target) const override;
298
299 unsigned Precedence() const override
300 {
301 return PrecNegate;
302 }
303
304
308 std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const override;
309
311 int Degree(std::shared_ptr<Variable> const& v = nullptr) const override
312 {
313 return operand_->Degree(v);
314 }
315
318 int Degree(VariableGroup const& vars) const override
319 {
320 return operand_->Degree(vars);
321 }
322
323 bool IsHomogeneous(std::shared_ptr<Variable> const& v = nullptr) const override
324 {
325 return operand_->IsHomogeneous(v);
326 }
327
331 bool IsHomogeneous(VariableGroup const& vars) const override
332 {
333 return operand_->IsHomogeneous(vars);
334 }
335
336 virtual ~NegateOperator() = default;
337
338 protected:
339
340
341
342
343 private:
344
345 NegateOperator() = default;
346
348
349 template <typename Archive>
350 void serialize(Archive& ar, const unsigned /*version*/) {
351 ar & boost::serialization::base_object<UnaryOperator>(*this);
352 }
353 };
354
355
357 inline std::shared_ptr<Node> operator-(const std::shared_ptr<Node> & rhs)
358 {
359 return NegateOperator::Make(rhs);
360 }
361
362
363
364
365
366
367
368
369
370
371
378 class MultOperator : public NaryOperator
379 {
380 public:
382
383 std::shared_ptr<Node> Simplified() const override;
384
385 std::shared_ptr<Node> Subs(SubstitutionMap const& substitutions) const override;
386
387
389 template<typename... Ts>
390 static
391 std::shared_ptr<MultOperator> Make(Ts&& ...ts){
392 return std::static_pointer_cast<MultOperator>(Intern(std::shared_ptr<Node>( new MultOperator(ts...) )));
393 }
394
395 private:
401 MultOperator(std::shared_ptr<Node> const& s)
402 {
403 AddOperand(s);
404 }
405
406 MultOperator(std::shared_ptr<Node> const& left, std::shared_ptr<Node> const& right)
407 {
408 AddOperand(left);
409 AddOperand(right);
410 CanonicalizeNaryOperands(operands_, mult_or_div_, true);
411 }
412
413
414 MultOperator(const std::shared_ptr<Node> & left, bool mult_or_div_left, const std::shared_ptr<Node> & right, bool mult_or_div_right)
415 {
416 AddOperand(left, mult_or_div_left);
417 AddOperand(right, mult_or_div_right);
418 CanonicalizeNaryOperands(operands_, mult_or_div_, true);
419 }
420
421 // Build a complete product from a full (factor, mult-or-div) list -- fully constructed
422 // before Make() interns it, so no post-Make AddOperand on a shared interned node.
423 explicit MultOperator(std::vector<std::pair<std::shared_ptr<Node>, bool>> const& factors)
424 {
425 for (auto const& f : factors)
426 AddOperand(f.first, f.second);
427 CanonicalizeNaryOperands(operands_, mult_or_div_, true);
428 }
429
430 public:
431
432 virtual ~MultOperator() = default;
433
434
435
436
437 //Special Behaviour: by default all factors are in numerator
438 void AddOperand(std::shared_ptr<Node> child) override
439 {
440 NaryOperator::AddOperand(std::move(child));
441 mult_or_div_.push_back(true);
442 }
443
444
445
447 //Special Behaviour: Pass bool to set sign of term: true = mult, false = divide
448 void AddOperand(std::shared_ptr<Node> child, bool mult) // not an override
449 {
450 NaryOperator::AddOperand(std::move(child));
451 mult_or_div_.push_back(mult);
452 }
453
454
458 void print(std::ostream & target) const override;
459
460 unsigned Precedence() const override
461 {
462 return PrecMult;
463 }
464
468 std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const override;
469
473 int Degree(std::shared_ptr<Variable> const& v = nullptr) const override;
474
475
476 int Degree(VariableGroup const& vars) const override;
477
481 std::vector<int> MultiDegreeImpl(VariableGroup const& vars) const override;
482
483
484 std::shared_ptr<Node> Homogenized(VariableGroup const& vars, std::shared_ptr<Variable> const& homvar) const override;
485 std::size_t HashImpl() const override;
486 bool IsSame(Node const& other) const override;
487
488 bool IsHomogeneous(std::shared_ptr<Variable> const& v = nullptr) const override;
489
493 bool IsHomogeneous(VariableGroup const& vars) const override;
494
500 inline
501 const auto& GetMultOrDiv() const{ return this->mult_or_div_;}
502
503 protected:
504
505 // If child_mult_ = true, then multiply, else divide
506
507
508
509
510
511
512
513 private:
514
515 MultOperator() = default;
516
517 // Stores the mult/div of a factor. There is a one-one
518 // correspondence between elements of signs_ and operand_. This
519 // is enforced by the AddOperand method, redefined in MultOperator.
520
521 // TODO(JBC): If we add method to delete child, must also delete children_mult_ entry.
522 std::vector<bool> mult_or_div_;
523
524
525 private:
526
528
529 template <typename Archive>
530 void serialize(Archive& ar, const unsigned /*version*/) {
531 ar & boost::serialization::base_object<NaryOperator>(*this);
532 ar & mult_or_div_;
533 }
534
535 void PrecisionChangeSpecific(unsigned prec) const override
536 {
537 temp_mp_.precision(prec);
538 }
539
540 mutable complex_mp temp_mp_;
541 mutable complex_dbl temp_d_;
542
543 friend SumOperator;
544 };
545
546
547
548
549
558 class PowerOperator : public Operator
559 {
560
561 public:
563
564 std::shared_ptr<Node> Simplified() const override;
565
566 std::shared_ptr<Node> Subs(SubstitutionMap const& substitutions) const override;
567
569 template<typename... Ts>
570 static
571 std::shared_ptr<PowerOperator> Make(Ts&& ...ts){
572 return std::static_pointer_cast<PowerOperator>(Intern(std::shared_ptr<Node>( new PowerOperator(ts...) )));
573 }
574
575
576 private:
577 PowerOperator(const std::shared_ptr<Node> & new_base, const std::shared_ptr<Node> & new_exponent) : base_(new_base), exponent_(new_exponent)
578 {
579 }
580
581 public:
582
583
584
586 void SetBase(std::shared_ptr<Node> new_base)
587 {
588 base_ = new_base;
589 }
590
592 void SetExponent(std::shared_ptr<Node> new_exponent)
593 {
594 exponent_ = new_exponent;
595 }
596
598 std::shared_ptr<Node> GetBase() const
599 {
600 return base_;
601 }
602
604 std::shared_ptr<Node> GetExponent() const
605 {
606 return exponent_;
607 }
608
609
610
611
612 void print(std::ostream & target) const override;
613
614 unsigned Precedence() const override
615 {
616 return PrecPower;
617 }
618
619
620
624 std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const override;
625
629 int Degree(std::shared_ptr<Variable> const& v = nullptr) const override;
630
631 int Degree(VariableGroup const& vars) const override;
632
636 std::vector<int> MultiDegreeImpl(VariableGroup const& vars) const override;
637
638
639
640 std::shared_ptr<Node> Homogenized(VariableGroup const& vars, std::shared_ptr<Variable> const& homvar) const override;
641 std::size_t HashImpl() const override;
642 bool IsSame(Node const& other) const override;
643
644 bool IsHomogeneous(std::shared_ptr<Variable> const& v = nullptr) const override;
645
649 bool IsHomogeneous(VariableGroup const& vars) const override;
650
651 virtual ~PowerOperator() = default;
652
658
659
660
661 protected:
662
663
664
665 private:
666
667 PowerOperator() = default;
668
669 std::shared_ptr<Node> base_;
670 std::shared_ptr<Node> exponent_;
671
672
673
674 private:
675
677
678
679 template <typename Archive>
680 void serialize(Archive& ar, const unsigned /*version*/) {
681 ar & boost::serialization::base_object<Operator>(*this);
682 ar & base_;
683 ar & exponent_;
684 }
685 };
686 // end of the class PowerOperator
687
688
689
690
691
692
693
694
695
696
697
698
699
700
708 class IntegerPowerOperator : public UnaryOperator
709 {
710 public:
712
713 std::shared_ptr<Node> Simplified() const override;
714
715 std::shared_ptr<Node> Subs(SubstitutionMap const& substitutions) const override;
716 std::shared_ptr<Node> Homogenized(VariableGroup const& vars, std::shared_ptr<Variable> const& homvar) const override;
717 std::size_t HashImpl() const override;
718 bool IsSame(Node const& other) const override;
719
723 void print(std::ostream & target) const override;
724
725 unsigned Precedence() const override
726 {
727 return PrecPower;
728 }
729
730
735 {
736 exponent_ = exp;
737 }
738
739
743 int exponent() const
744 {
745 return exponent_;
746 }
747
748
752 std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const override;
753
757 int Degree(std::shared_ptr<Variable> const& v = nullptr) const override;
758
759 int Degree(VariableGroup const& vars) const override;
760
761
762 bool IsHomogeneous(std::shared_ptr<Variable> const& v = nullptr) const override
763 {
764 return operand_->IsHomogeneous(v);
765 }
766
767
771 bool IsHomogeneous(VariableGroup const& vars) const override
772 {
773 return operand_->IsHomogeneous(vars);
774 }
775
776
777 virtual ~IntegerPowerOperator() = default;
778
779
781 template<typename... Ts>
782 static
783 std::shared_ptr<IntegerPowerOperator> Make(Ts&& ...ts){
784 return std::static_pointer_cast<IntegerPowerOperator>(Intern(std::shared_ptr<Node>( new IntegerPowerOperator(ts...) )));
785 }
786
787 private:
791 IntegerPowerOperator(const std::shared_ptr<Node> & N, int p) : UnaryOperator(N), exponent_(p)
792 {}
793
794
795
796
797 protected:
798
799
800
801
802
803
804
805 private:
806
807 IntegerPowerOperator() = default;
808
809
810 int exponent_;
811
813
814 template <typename Archive>
815 void serialize(Archive& ar, const unsigned /*version*/) {
816 ar & boost::serialization::base_object<UnaryOperator>(*this);
817 ar & exponent_;
818 }
819 }; // re: class IntegerPowerOperator
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
846 class SqrtOperator : public UnaryOperator
847 {
848 public:
850
851
852 template<typename... Ts>
853 static
854 std::shared_ptr<SqrtOperator> Make(Ts&& ...ts){
855 return std::static_pointer_cast<SqrtOperator>(Intern(std::shared_ptr<Node>( new SqrtOperator(ts...) )));
856 }
857
858 private:
859 SqrtOperator(const std::shared_ptr<Node> & N) : UnaryOperator(N)
860 {};
861
862 public:
863
864 std::shared_ptr<Node> Simplified() const override;
865
866 std::shared_ptr<Node> Subs(SubstitutionMap const& substitutions) const override;
867 std::shared_ptr<Node> Homogenized(VariableGroup const& vars, std::shared_ptr<Variable> const& homvar) const override;
868
869 void print(std::ostream & target) const override;
870
871
875 std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const override;
876
877
878 virtual ~SqrtOperator() = default;
879
880 protected:
881
882
883
884
885 private:
886
887 SqrtOperator() = default;
888
890
891 template <typename Archive>
892 void serialize(Archive& ar, const unsigned /*version*/) {
893 ar & boost::serialization::base_object<UnaryOperator>(*this);
894 }
895 };
896
897
898
900 inline std::shared_ptr<Node> sqrt(const std::shared_ptr<Node> & N)
901 {
902 return SqrtOperator::Make(N);
903 }
904
905
906
907
913 class ExpOperator : public UnaryOperator
914 {
915 public:
917
918 std::shared_ptr<Node> Simplified() const override;
919
920 std::shared_ptr<Node> Subs(SubstitutionMap const& substitutions) const override;
921 std::shared_ptr<Node> Homogenized(VariableGroup const& vars, std::shared_ptr<Variable> const& homvar) const override;
922
924 template<typename... Ts>
925 static
926 std::shared_ptr<ExpOperator> Make(Ts&& ...ts){
927 return std::static_pointer_cast<ExpOperator>(Intern(std::shared_ptr<Node>( new ExpOperator(ts...) )));
928 }
929
930 private:
931 ExpOperator(const std::shared_ptr<Node> & N) : UnaryOperator(N)
932 {};
933
934 public:
935
936
937
938
939 void print(std::ostream & target) const override;
940
941
945 std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const override;
946
947
948 virtual ~ExpOperator() = default;
949
950 protected:
951
952
953
954 private:
955 ExpOperator() = default;
957
958 template <typename Archive>
959 void serialize(Archive& ar, const unsigned /*version*/) {
960 ar & boost::serialization::base_object<UnaryOperator>(*this);
961 }
962 };
963
964
970 class LogOperator : public UnaryOperator
971 {
972 public:
974
975 std::shared_ptr<Node> Simplified() const override;
976
977 std::shared_ptr<Node> Subs(SubstitutionMap const& substitutions) const override;
978 std::shared_ptr<Node> Homogenized(VariableGroup const& vars, std::shared_ptr<Variable> const& homvar) const override;
979
981 template<typename... Ts>
982 static
983 std::shared_ptr<LogOperator> Make(Ts&& ...ts){
984 return std::static_pointer_cast<LogOperator>(Intern(std::shared_ptr<Node>( new LogOperator(ts...) )));
985 }
986
987 private:
988 LogOperator(const std::shared_ptr<Node> & N) : UnaryOperator(N)
989 {};
990
991 public:
992
993
994
995
996 void print(std::ostream & target) const override;
997
998
1002 std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const override;
1003
1004
1005 virtual ~LogOperator() = default;
1006
1007 protected:
1008
1009
1010
1011 private:
1012 LogOperator() = default;
1014
1015 template <typename Archive>
1016 void serialize(Archive& ar, const unsigned /*version*/) {
1017 ar & boost::serialization::base_object<UnaryOperator>(*this);
1018 }
1019 };
1020
1021
1022
1023
1024 // begin the overload of operators
1025
1027 inline std::shared_ptr<Node> exp(const std::shared_ptr<Node> & N)
1028 {
1029 return ExpOperator::Make(N);
1030 }
1031
1033 inline std::shared_ptr<Node> log(const std::shared_ptr<Node> & N)
1034 {
1035 return LogOperator::Make(N);
1036 }
1037
1039 inline std::shared_ptr<Node> pow(const std::shared_ptr<Node> & N, const std::shared_ptr<Node> & p)
1040 {
1041 return PowerOperator::Make(N,p);
1042 }
1043
1045 inline std::shared_ptr<Node> pow(std::shared_ptr<Node> const& base, int power)
1046 {
1047 return IntegerPowerOperator::Make(base,power);
1048 }
1049
1051 std::shared_ptr<Node> pow(const std::shared_ptr<Node> & N, double p) = delete;
1052
1054 std::shared_ptr<Node> pow(const std::shared_ptr<Node> & N, complex_dbl p) = delete;
1055
1057 inline std::shared_ptr<Node> pow(const std::shared_ptr<Node> & N, real_mp p)
1058 {
1060 }
1061
1063 inline std::shared_ptr<Node> pow(const std::shared_ptr<Node> & N, complex_mp p)
1064 {
1066 }
1067
1069 inline std::shared_ptr<Node> pow(const std::shared_ptr<Node> & N, mpq_rational const& p)
1070 {
1071 return PowerOperator::Make(N,Rational::Make(p,0));
1072 }
1073
1074
1075
1076
1077
1078
1080 //
1081 // SIMPLIFIED-CONSTRUCTION FACTORIES
1082 //
1084
1090 std::shared_ptr<Node> SimplifiedNegate(std::shared_ptr<Node> const& n);
1091
1100 std::shared_ptr<Node> SimplifiedSum(std::vector<std::pair<std::shared_ptr<Node>, bool>> const& terms);
1101
1112 std::shared_ptr<Node> SimplifiedMult(std::vector<std::pair<std::shared_ptr<Node>, bool>> const& factors);
1113
1114
1115
1117 //
1118 // SUM AND DIFFERENCE ARITHMETIC OPERATORS
1119 //
1121
1122
1123
1124
1126 //
1127 // addition operators
1128 //
1130
1131
1133 inline std::shared_ptr<Node>& operator+=(std::shared_ptr<Node> & lhs, const std::shared_ptr<Node> & rhs)
1134 {
1135 std::shared_ptr<Node> temp = SumOperator::Make(lhs,rhs);
1136 lhs.swap(temp);
1137 return lhs;
1138 }
1139
1140
1141
1142
1143
1145 inline std::shared_ptr<Node> operator+(std::shared_ptr<Node> lhs, const std::shared_ptr<Node> & rhs)
1146 {
1147 return SumOperator::Make(lhs,rhs);
1148 }
1149
1151 inline std::shared_ptr<Node> operator+(std::shared_ptr<Node> lhs, real_mp const& rhs)
1152 {
1153 return SumOperator::Make(lhs,Complex::Make(rhs));
1154 }
1155
1157 inline std::shared_ptr<Node> operator+(std::shared_ptr<Node> lhs, complex_mp const& rhs)
1158 {
1159 return SumOperator::Make(lhs,Complex::Make(rhs));
1160 }
1161
1163 inline std::shared_ptr<Node> operator+(real_mp const& lhs, std::shared_ptr<Node> rhs)
1164 {
1165 return SumOperator::Make(Complex::Make(lhs), rhs);
1166 }
1167
1169 inline std::shared_ptr<Node> operator+(complex_mp const& lhs, std::shared_ptr<Node> rhs)
1170 {
1171 return SumOperator::Make(Complex::Make(lhs), rhs);
1172 }
1173
1175 inline std::shared_ptr<Node> operator+(std::shared_ptr<Node> lhs, int rhs)
1176 {
1177 return SumOperator::Make(lhs,Integer::Make(rhs));
1178 }
1179
1181 inline std::shared_ptr<Node> operator+(int lhs, std::shared_ptr<Node> rhs)
1182 {
1183 return SumOperator::Make(Integer::Make(lhs), rhs);
1184 }
1185
1187 inline std::shared_ptr<Node> operator+(std::shared_ptr<Node> lhs, mpz_int const& rhs)
1188 {
1189 return SumOperator::Make(lhs,Integer::Make(rhs));
1190 }
1191
1193 inline std::shared_ptr<Node> operator+(mpz_int const& lhs, std::shared_ptr<Node> rhs)
1194 {
1195 return SumOperator::Make(Integer::Make(lhs), rhs);
1196 }
1197
1199 inline std::shared_ptr<Node> operator+(std::shared_ptr<Node> lhs, mpq_rational const& rhs)
1200 {
1201 return SumOperator::Make(lhs,Rational::Make(rhs,0));
1202 }
1203
1205 inline std::shared_ptr<Node> operator+(mpq_rational const& lhs, std::shared_ptr<Node> rhs)
1206 {
1207 return SumOperator::Make(Rational::Make(lhs,0), rhs);
1208 }
1209
1210
1211
1213 //
1214 // subtraction operators
1215 //
1217
1218
1220 inline std::shared_ptr<Node>& operator-=(std::shared_ptr<Node> & lhs, const std::shared_ptr<Node> & rhs)
1221 {
1222 std::shared_ptr<Node> temp = SumOperator::Make(lhs,true,rhs,false);
1223 lhs.swap(temp);
1224 return lhs;
1225 }
1226
1227
1229 inline std::shared_ptr<Node> operator-(std::shared_ptr<Node> lhs, const std::shared_ptr<Node> & rhs)
1230 {
1231 return SumOperator::Make(lhs,true,rhs,false);
1232 }
1233
1235 inline std::shared_ptr<Node> operator-(std::shared_ptr<Node> lhs, real_mp const& rhs)
1236 {
1237 return SumOperator::Make(lhs, true, Complex::Make(rhs), false);
1238 }
1239
1241 inline std::shared_ptr<Node> operator-(real_mp const& lhs, std::shared_ptr<Node> rhs)
1242 {
1243 return SumOperator::Make(Complex::Make(lhs), true, rhs, false);
1244 }
1245
1247 inline std::shared_ptr<Node> operator-(std::shared_ptr<Node> lhs, complex_mp const& rhs)
1248 {
1249 return SumOperator::Make(lhs, true, Complex::Make(rhs), false);
1250 }
1251
1253 inline std::shared_ptr<Node> operator-(complex_mp const& lhs, std::shared_ptr<Node> rhs)
1254 {
1255 return SumOperator::Make(Complex::Make(lhs), true, rhs, false);
1256 }
1257
1259 inline std::shared_ptr<Node> operator-(std::shared_ptr<Node> lhs, int rhs)
1260 {
1261 return SumOperator::Make(lhs, true, Integer::Make(rhs), false);
1262 }
1263
1265 inline std::shared_ptr<Node> operator-(int lhs, std::shared_ptr<Node> rhs)
1266 {
1267 return SumOperator::Make(Integer::Make(lhs), true, rhs, false);
1268 }
1269
1271 inline std::shared_ptr<Node> operator-(std::shared_ptr<Node> lhs, mpz_int const& rhs)
1272 {
1273 return SumOperator::Make(lhs, true, Integer::Make(rhs), false);
1274 }
1275
1277 inline std::shared_ptr<Node> operator-(mpz_int const& lhs, std::shared_ptr<Node> rhs)
1278 {
1279 return SumOperator::Make(Integer::Make(lhs), true, rhs, false);
1280 }
1281
1283 inline std::shared_ptr<Node> operator-(std::shared_ptr<Node> lhs, mpq_rational const& rhs)
1284 {
1285 return SumOperator::Make(lhs, true, Rational::Make(rhs,0), false);
1286 }
1287
1289 inline std::shared_ptr<Node> operator-(mpq_rational const& lhs, std::shared_ptr<Node> rhs)
1290 {
1291 return SumOperator::Make(Rational::Make(lhs,0), true, rhs, false);
1292 }
1293
1294
1295
1296 /*
1297 multiplication operators
1298 */
1300 inline std::shared_ptr<Node> operator*=(std::shared_ptr<MultOperator> & lhs, const std::shared_ptr<Node> & rhs)
1301 {
1302 lhs->AddOperand(rhs);
1303 return lhs;
1304 }
1305
1306
1308 inline std::shared_ptr<Node> operator*(std::shared_ptr<Node> lhs, real_mp const& rhs)
1309 {
1310 return MultOperator::Make(lhs,Complex::Make(rhs));
1311 }
1312
1314 inline std::shared_ptr<Node> operator*(std::shared_ptr<Node> lhs, complex_mp const& rhs)
1315 {
1316 return MultOperator::Make(lhs,Complex::Make(rhs));
1317 }
1318
1320 inline std::shared_ptr<Node> operator*(real_mp const& lhs, std::shared_ptr<Node> rhs)
1321 {
1322 return MultOperator::Make(Complex::Make(lhs), rhs);
1323 }
1324
1326 inline std::shared_ptr<Node> operator*(complex_mp const& lhs, std::shared_ptr<Node> rhs)
1327 {
1328 return MultOperator::Make(Complex::Make(lhs), rhs);
1329 }
1330
1332 inline std::shared_ptr<Node> operator*(std::shared_ptr<Node> lhs, int rhs)
1333 {
1334 return MultOperator::Make(lhs,Integer::Make(rhs));
1335 }
1336
1338 inline std::shared_ptr<Node> operator*(int lhs, std::shared_ptr<Node> rhs)
1339 {
1340 return MultOperator::Make(Integer::Make(lhs), rhs);
1341 }
1342
1344 inline std::shared_ptr<Node> operator*(std::shared_ptr<Node> lhs, mpz_int const& rhs)
1345 {
1346 return MultOperator::Make(lhs,Integer::Make(rhs));
1347 }
1348
1350 inline std::shared_ptr<Node> operator*(mpz_int const& lhs, std::shared_ptr<Node> rhs)
1351 {
1352 return MultOperator::Make(Integer::Make(lhs), rhs);
1353 }
1354
1356 inline std::shared_ptr<Node> operator*(std::shared_ptr<Node> lhs, mpq_rational const& rhs)
1357 {
1358 return MultOperator::Make(lhs,Rational::Make(rhs,0));
1359 }
1360
1362 inline std::shared_ptr<Node> operator*(mpq_rational const& lhs, std::shared_ptr<Node> rhs)
1363 {
1364 return MultOperator::Make(Rational::Make(lhs,0), rhs);
1365 }
1366
1367
1373 inline std::shared_ptr<Node>& operator*=(std::shared_ptr<Node> & lhs, const std::shared_ptr<Node> & rhs)
1374 {
1375 std::shared_ptr<Node> temp = MultOperator::Make(lhs,rhs);
1376 lhs.swap(temp);
1377 return lhs;
1378 }
1379
1381 inline std::shared_ptr<Node> operator*(std::shared_ptr<Node> lhs, const std::shared_ptr<Node> & rhs)
1382 {
1383 return lhs*=rhs;
1384 }
1385
1386
1387
1388
1389
1390
1391 /*
1392 division operators
1393 */
1394
1395
1397 inline std::shared_ptr<Node>& operator/=(std::shared_ptr<Node> & lhs, const std::shared_ptr<Node> & rhs)
1398 {
1399
1400 // if (std::dynamic_pointer_cast<IntegerPowerOperator>(lhs) && std::dynamic_pointer_cast<IntegerPowerOperator>(rhs))
1401 // {
1402
1403 // auto lhs_as_intpow = std::dynamic_pointer_cast<IntegerPowerOperator>(lhs);
1404 // auto rhs_as_intpow = std::dynamic_pointer_cast<IntegerPowerOperator>(rhs);
1405 // if (lhs_as_intpow->first_child()==rhs_as_intpow->first_child())
1406 // {
1407 // std::shared_ptr<Node> temp = pow(lhs_as_intpow->first_child(),lhs_as_intpow->exponent() - rhs_as_intpow->exponent());
1408 // lhs.swap(temp);
1409 // return lhs;
1410 // }
1411 // }
1412
1413
1414 std::shared_ptr<Node> temp = MultOperator::Make(lhs,true,rhs,false);
1415 lhs.swap(temp);
1416 return lhs;
1417 }
1418
1420 inline std::shared_ptr<Node> operator/=(std::shared_ptr<MultOperator> & lhs, const std::shared_ptr<Node> & rhs)
1421 {
1422 lhs->AddOperand(rhs,false);
1423 return lhs;
1424 }
1425
1426
1427
1429 inline std::shared_ptr<Node> operator/(std::shared_ptr<Node> lhs, const std::shared_ptr<Node> & rhs)
1430 {
1431 return lhs/=rhs;
1432 }
1433
1435 inline std::shared_ptr<Node> operator/(std::shared_ptr<Node> lhs, real_mp rhs)
1436 {
1437 return MultOperator::Make(lhs, true, Complex::Make(rhs), false);
1438 }
1439
1441 inline std::shared_ptr<Node> operator/(std::shared_ptr<Node> lhs, complex_mp rhs)
1442 {
1443 return MultOperator::Make(lhs, true, Complex::Make(rhs), false);
1444 }
1445
1447 inline std::shared_ptr<Node> operator/(real_mp lhs, std::shared_ptr<Node> rhs)
1448 {
1449 return MultOperator::Make(Complex::Make(lhs), true, rhs, false);
1450 }
1451
1453 inline std::shared_ptr<Node> operator/(complex_mp lhs, std::shared_ptr<Node> rhs)
1454 {
1455 return MultOperator::Make(Complex::Make(lhs), true, rhs, false);
1456 }
1457
1459 inline std::shared_ptr<Node> operator/(std::shared_ptr<Node> lhs, int rhs)
1460 {
1461 return MultOperator::Make(lhs, true, Integer::Make(rhs), false);
1462 }
1463
1465 inline std::shared_ptr<Node> operator/(int lhs, std::shared_ptr<Node> rhs)
1466 {
1467 return MultOperator::Make(Integer::Make(lhs), true, rhs, false);
1468 }
1469
1471 inline std::shared_ptr<Node> operator/(std::shared_ptr<Node> lhs, mpz_int const& rhs)
1472 {
1473 return MultOperator::Make(lhs, true, Integer::Make(rhs), false);
1474 }
1475
1477 inline std::shared_ptr<Node> operator/(mpz_int const& lhs, std::shared_ptr<Node> rhs)
1478 {
1479 return MultOperator::Make(Integer::Make(lhs), true, rhs, false);
1480 }
1481
1483 inline std::shared_ptr<Node> operator/(std::shared_ptr<Node> lhs, mpq_rational const& rhs)
1484 {
1485 return MultOperator::Make(lhs, true, Rational::Make(rhs,0), false);
1486 }
1487
1489 inline std::shared_ptr<Node> operator/(mpq_rational const& lhs, std::shared_ptr<Node> rhs)
1490 {
1491 return MultOperator::Make(Rational::Make(lhs,0), true, rhs, false);
1492 }
1493
1494
1495
1496} // re: namespace node
1497} // re: namespace bertini
1498
1499
1500
1501
1502
1503
1504#endif
Canonical ordering of commutative-operator operands (reorder-only).
static std::shared_ptr< Complex > Make(Ts &&...ts)
Construct (and intern) a Complex node.
Definition number.hpp:313
represents the exponential function
Definition arithmetic.hpp:914
std::shared_ptr< Node > Subs(SubstitutionMap const &substitutions) const override
Symbolically substitute variables, returning a NEW tree.
static std::shared_ptr< ExpOperator > Make(Ts &&...ts)
Construct (and intern) a ExpOperator node.
Definition arithmetic.hpp:926
void print(std::ostream &target) const override
Virtual method for printing Nodes to arbitrary output streams.
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 exponential function.
virtual ~ExpOperator()=default
friend class boost::serialization::access
Definition arithmetic.hpp:956
std::shared_ptr< Node > Simplified() const override
Functionally simplify this tree, returning a NEW simplified tree.
This class represents the exponentiation Operator.
Definition arithmetic.hpp:709
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...
Definition arithmetic.hpp:762
bool IsHomogeneous(VariableGroup const &vars) const override
Check for homogeneity, with respect to a variable group.
Definition arithmetic.hpp:771
void print(std::ostream &target) const override
polymorphic method for printing to an arbitrary stream.
int Degree(std::shared_ptr< Variable > const &v=nullptr) const override
Compute the degree of a node.
std::shared_ptr< Node > Differentiate(std::shared_ptr< Variable > const &v=nullptr) const override
Differentiate.
int exponent() const
Get the exponent.
Definition arithmetic.hpp:743
std::shared_ptr< Node > Subs(SubstitutionMap const &substitutions) const override
Symbolically substitute variables, returning a NEW tree.
int Degree(VariableGroup const &vars) const override
Compute the overall degree with respect to a variable group.
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::size_t HashImpl() const override
Compute this node's structural hash.
static std::shared_ptr< IntegerPowerOperator > Make(Ts &&...ts)
Construct (and intern) a IntegerPowerOperator node.
Definition arithmetic.hpp:783
void set_exponent(int exp)
Set the integer exponent of an integer power operator.
Definition arithmetic.hpp:734
friend class boost::serialization::access
Definition arithmetic.hpp:812
bool IsSame(Node const &other) const override
Order-sensitive structural equality, shallow given interned children.
unsigned Precedence() const override
The printing precedence of this node, deciding parenthesization.
Definition arithmetic.hpp:725
std::shared_ptr< Node > Simplified() const override
Functionally simplify this tree, returning a NEW simplified tree.
virtual ~IntegerPowerOperator()=default
static std::shared_ptr< Integer > Make(Ts &&...ts)
Construct (and intern) a Integer node.
Definition number.hpp:198
represents the natural logarithm function
Definition arithmetic.hpp:971
std::shared_ptr< Node > Differentiate(std::shared_ptr< Variable > const &v=nullptr) const override
Differentiates the exponential function.
static std::shared_ptr< LogOperator > Make(Ts &&...ts)
Construct (and intern) a LogOperator node.
Definition arithmetic.hpp:983
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).
virtual ~LogOperator()=default
void print(std::ostream &target) const override
Virtual method for printing Nodes to arbitrary output streams.
std::shared_ptr< Node > Simplified() const override
Functionally simplify this tree, returning a NEW simplified tree.
friend class boost::serialization::access
Definition arithmetic.hpp:1013
std::shared_ptr< Node > Subs(SubstitutionMap const &substitutions) const override
Symbolically substitute variables, returning a NEW tree.
Multiplication and division Operator.
Definition arithmetic.hpp:379
void AddOperand(std::shared_ptr< Node > child, bool mult)
Add a factor; pass the bool to choose multiply (true) or divide (false).
Definition arithmetic.hpp:448
const auto & GetMultOrDiv() const
Get the indicator for which operation is being performed.
Definition arithmetic.hpp:501
void print(std::ostream &target) const override
overridden method for printing to an output stream
bool IsHomogeneous(VariableGroup const &vars) const override
Check for homogeneity, with respect to a variable group.
std::shared_ptr< Node > Simplified() const override
Functionally simplify this tree, returning a NEW simplified tree.
std::size_t HashImpl() const override
Compute this node's structural hash.
int Degree(std::shared_ptr< Variable > const &v=nullptr) const override
Compute the degree of a node.
std::shared_ptr< Node > Differentiate(std::shared_ptr< Variable > const &v=nullptr) const override
Differentiates using the product rule.
unsigned Precedence() const override
The printing precedence of this node, deciding parenthesization.
Definition arithmetic.hpp:460
std::shared_ptr< Node > Subs(SubstitutionMap const &substitutions) const override
Symbolically substitute variables, returning a NEW tree.
virtual ~MultOperator()=default
void AddOperand(std::shared_ptr< Node > child) override
Add an operand (child) onto this operator.
Definition arithmetic.hpp:438
int Degree(VariableGroup const &vars) const override
Compute the overall degree with respect to a variable group.
std::vector< int > MultiDegreeImpl(VariableGroup const &vars) const override
Compute the multidegree with respect to a variable group.
friend class boost::serialization::access
Definition arithmetic.hpp:527
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).
bool IsSame(Node const &other) const override
Order-sensitive structural equality, shallow given interned children.
static std::shared_ptr< MultOperator > Make(Ts &&...ts)
Construct (and intern) a MultOperator node.
Definition arithmetic.hpp:391
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::vector< std::shared_ptr< Node > > operands_
Change the precision of this variable-precision tree node.
Definition operator.hpp:194
virtual void AddOperand(std::shared_ptr< Node > n)
Add an operand (child) onto this operator.
NaryOperator()
Definition operator.hpp:197
The negation Operator.
Definition arithmetic.hpp:271
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...
Definition arithmetic.hpp:323
std::shared_ptr< Node > Subs(SubstitutionMap const &substitutions) const override
Symbolically substitute variables, returning a NEW tree.
int Degree(VariableGroup const &vars) const override
Degree in a variable group: negation preserves its operand's degree.
Definition arithmetic.hpp:318
bool IsHomogeneous(VariableGroup const &vars) const override
Check for homogeneity, with respect to a variable group.
Definition arithmetic.hpp:331
static std::shared_ptr< NegateOperator > Make(Ts &&...ts)
Construct (and intern) a NegateOperator node.
Definition arithmetic.hpp:278
std::shared_ptr< Node > Differentiate(std::shared_ptr< Variable > const &v=nullptr) const override
Returns negative of derivative of child.
virtual ~NegateOperator()=default
void print(std::ostream &target) const override
Print to an arbitrary ostream.
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).
friend class boost::serialization::access
Definition arithmetic.hpp:347
unsigned Precedence() const override
The printing precedence of this node, deciding parenthesization.
Definition arithmetic.hpp:299
int Degree(std::shared_ptr< Variable > const &v=nullptr) const override
Degree in one variable: negation preserves its operand's degree.
Definition arithmetic.hpp:311
std::shared_ptr< Node > Simplified() const override
Functionally simplify this tree, returning a NEW simplified tree.
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
Operator for power functions with arbitrary expressions in the exponent and base.
Definition arithmetic.hpp:559
std::shared_ptr< Node > Subs(SubstitutionMap const &substitutions) const override
Symbolically substitute variables, returning a NEW tree.
virtual ~PowerOperator()=default
std::shared_ptr< Node > Simplified() const override
Functionally simplify this tree, returning a NEW simplified tree.
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.
std::shared_ptr< Node > GetExponent() const
Definition arithmetic.hpp:604
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).
void SetExponent(std::shared_ptr< Node > new_exponent)
Set the exponent of the power.
Definition arithmetic.hpp:592
void SetBase(std::shared_ptr< Node > new_base)
Set the base of the power.
Definition arithmetic.hpp:586
static std::shared_ptr< PowerOperator > Make(Ts &&...ts)
Construct (and intern) a PowerOperator node.
Definition arithmetic.hpp:571
unsigned Precedence() const override
The printing precedence of this node, deciding parenthesization.
Definition arithmetic.hpp:614
std::shared_ptr< Node > GetBase() const
Definition arithmetic.hpp:598
std::vector< int > MultiDegreeImpl(VariableGroup const &vars) const override
Compute the multidegree with respect to a variable group.
int Degree(std::shared_ptr< Variable > const &v=nullptr) const override
Compute the degree of a node.
bool IsHomogeneous(VariableGroup const &vars) const override
Check for homogeneity, with respect to a variable group.
std::shared_ptr< Node > Differentiate(std::shared_ptr< Variable > const &v=nullptr) const override
Differentiates with the power rule.
void print(std::ostream &target) const override
Virtual method for printing Nodes to arbitrary output streams.
int Degree(VariableGroup const &vars) const override
Compute the overall degree with respect to a variable group.
friend class boost::serialization::access
Definition arithmetic.hpp:676
bool IsSame(Node const &other) const override
Order-sensitive structural equality, shallow given interned children.
static std::shared_ptr< Rational > Make(Ts &&...ts)
Construct (and intern) a Rational node.
Definition number.hpp:496
Represents the square root Operator.
Definition arithmetic.hpp:847
std::shared_ptr< Node > Simplified() const override
Functionally simplify this tree, returning a NEW simplified tree.
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.
std::shared_ptr< Node > Differentiate(std::shared_ptr< Variable > const &v=nullptr) const override
Differentiates the square root function.
virtual ~SqrtOperator()=default
friend class boost::serialization::access
Definition arithmetic.hpp:889
static std::shared_ptr< SqrtOperator > Make(Ts &&...ts)
Construct (and intern) a SqrtOperator node.
Definition arithmetic.hpp:854
void print(std::ostream &target) const override
Virtual method for printing Nodes to arbitrary output streams.
Represents summation and difference Operator.
Definition arithmetic.hpp:70
std::shared_ptr< Node > Differentiate(std::shared_ptr< Variable > const &v=nullptr) const override
Return SumOperator whose children are derivatives of the children, omitted as possible.
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...
bool IsHomogeneous(VariableGroup const &vars) const override
Check for homogeneity, with respect to a variable group.
std::shared_ptr< Node > Homogenized(VariableGroup const &vars, std::shared_ptr< Variable > const &homvar) const override
Homogenize a sum, with respect to a variable group, and using a homogenizing variable.
std::size_t HashImpl() const override
Compute this node's structural hash.
void AddOperand(std::shared_ptr< Node > child, bool sign)
Definition arithmetic.hpp:151
unsigned Precedence() const override
The printing precedence of this node, deciding parenthesization.
Definition arithmetic.hpp:163
SumOperator & operator-=(const std::shared_ptr< Node > &rhs)
Subtract a term in place (operand added with negative sign).
Definition arithmetic.hpp:128
int Degree(VariableGroup const &vars) const override
Compute the overall degree with respect to a variable group.
static std::shared_ptr< SumOperator > Make(Ts &&...ts)
Construct (and intern) a SumOperator node.
Definition arithmetic.hpp:83
void AddOperand(std::shared_ptr< Node > child) override
Definition arithmetic.hpp:141
std::vector< int > MultiDegreeImpl(VariableGroup const &vars) const override
Compute the multidegree with respect to a variable group.
SumOperator & operator+=(const std::shared_ptr< Node > &rhs)
Add a term in place (operand added with positive sign).
Definition arithmetic.hpp:121
std::shared_ptr< Node > Simplified() const override
Functionally simplify this tree, returning a NEW simplified tree.
bool IsSame(Node const &other) const override
Order-sensitive structural equality, shallow given interned children.
int Degree(std::shared_ptr< Variable > const &v=nullptr) const override
Compute the degree of a node.
friend class boost::serialization::access
Definition arithmetic.hpp:232
void print(std::ostream &target) const override
Method for printing to output stream.
const auto & GetSigns() const
Definition arithmetic.hpp:191
std::shared_ptr< Node > Subs(SubstitutionMap const &substitutions) const override
Symbolically substitute variables, returning a NEW tree.
Interface for all unary Operator types.
Definition operator.hpp:74
std::shared_ptr< Node > operand_
The single child (operand) of the unary operator.
Definition operator.hpp:136
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
Provides the differential Node class.
Forward declarations for types in the node:: namespace.
Definition canonical.hpp:56
std::shared_ptr< Node > & operator-=(std::shared_ptr< Node > &lhs, const std::shared_ptr< Node > &rhs)
Build a difference expression-tree node from its operands.
Definition arithmetic.hpp:1220
void CanonicalizeNaryOperands(std::vector< std::shared_ptr< Node > > &operands, std::vector< bool > &flags, bool multiplicands_first)
Sort an n-ary operator's (operand, flag) pairs into canonical order, in place.
std::shared_ptr< Node > & operator/=(std::shared_ptr< Node > &lhs, const std::shared_ptr< Node > &rhs)
Build a quotient expression-tree node from its operands.
Definition arithmetic.hpp:1397
std::shared_ptr< Node > operator+(std::shared_ptr< Node > lhs, const std::shared_ptr< Node > &rhs)
Build a sum expression-tree node from its operands.
Definition arithmetic.hpp:1145
std::shared_ptr< Node > operator/(std::shared_ptr< Node > lhs, const std::shared_ptr< Node > &rhs)
Build a quotient expression-tree node from its operands.
Definition arithmetic.hpp:1429
std::shared_ptr< Node > log(const std::shared_ptr< Node > &N)
Build a natural-logarithm expression-tree node.
Definition arithmetic.hpp:1033
std::shared_ptr< Node > SimplifiedMult(std::vector< std::pair< std::shared_ptr< Node >, bool > > const &factors)
Build a product from (factor, mult_or_div) pairs, simplified.
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 > operator*=(std::shared_ptr< MultOperator > &lhs, const std::shared_ptr< Node > &rhs)
Build a product expression-tree node from its operands.
Definition arithmetic.hpp:1300
std::shared_ptr< Node > & operator+=(std::shared_ptr< Node > &lhs, const std::shared_ptr< Node > &rhs)
Build a sum expression-tree node from its operands.
Definition arithmetic.hpp:1133
@ PrecNegate
Definition node.hpp:98
@ PrecPower
Definition node.hpp:100
@ PrecMult
Definition node.hpp:99
@ PrecSum
Definition node.hpp:97
std::shared_ptr< Node > SimplifiedNegate(std::shared_ptr< Node > const &n)
Negation that never builds junk: -0 stays 0.
std::shared_ptr< Node > sqrt(const std::shared_ptr< Node > &N)
Build a square-root expression-tree node.
Definition arithmetic.hpp:900
std::shared_ptr< Node > operator*(std::shared_ptr< Node > lhs, real_mp const &rhs)
Build a product expression-tree node from its operands.
Definition arithmetic.hpp:1308
std::shared_ptr< Node > exp(const std::shared_ptr< Node > &N)
Build an exponential (e raised to the node) expression-tree node.
Definition arithmetic.hpp:1027
std::shared_ptr< Node > pow(const std::shared_ptr< Node > &N, const std::shared_ptr< Node > &p)
Build a power expression-tree node.
Definition arithmetic.hpp:1039
std::shared_ptr< Node > operator-(const std::shared_ptr< Node > &rhs)
Build a difference expression-tree node from its operands.
Definition arithmetic.hpp:357
std::shared_ptr< Node > SimplifiedSum(std::vector< std::pair< std::shared_ptr< Node >, bool > > const &terms)
Build a sum from (term, add_or_sub) pairs, omitting literal zeros.
Definition algorithm_builder.hpp:36
std::complex< double > complex_dbl
The double-precision complex number type.
Definition double_extensions.hpp:47
boost::multiprecision::number< boost::multiprecision::backends::gmp_int, boost::multiprecision::et_on > mpz_int
The arbitrary-precision integer type.
Definition mpfr_extensions.hpp:54
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
bmp::number< mpc_complex_backend< 0 >, bmp::et_on > complex_mp
The arbitrary-precision complex number type.
Definition mpfr_complex.hpp:58
boost::multiprecision::number< boost::multiprecision::mpfr_float_backend< 0 >, boost::multiprecision::et_on > real_mp
The arbitrary-precision real number type.
Definition mpfr_extensions.hpp:53
boost::multiprecision::number< boost::multiprecision::backends::gmp_rational, boost::multiprecision::et_on > mpq_rational
The exact rational number type.
Definition mpfr_extensions.hpp:55
Defines the abstract Node base class.
Provides the Number Node types, including Rational, Complex, and Integer.
Provides the abstract Operator Node type.
Provides the special numbers , , 1, 2, 0, as Nodes.
Provides the Variable Node class.
#define BERTINI_DEFAULT_VISITABLE()
macro for classes which want default Accept implementation, having nothing fancy to do when accepting...
Definition visitable.hpp:121