Bertini 2 - C++ Core
Software for Numerical Algebraic Geometry
Loading...
Searching...
No Matches
linear_product.hpp
Go to the documentation of this file.
1//This file is part of Bertini 2.
2//
3//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//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 variable.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 2017
26//
27//
28// silviana amethyst
29// University of Wisconsin - Eau Claire
30//
31// Created by Collins, James B. on 3/6/2017.
32
33
40#ifndef BERTINI_FUNCTION_TREE_LINPRODUCT_HPP
41#define BERTINI_FUNCTION_TREE_LINPRODUCT_HPP
42
44
46
47template<typename NumType> using Mat = bertini::Mat<NumType>;
48
49namespace bertini {
50 namespace node{
59 class LinearProduct : public virtual Symbol, public virtual EnableSharedFromThisVirtual<LinearProduct>
60 {
61 public:
62 BERTINI_DEFAULT_VISITABLE()
63
64 virtual ~LinearProduct() = default;
65
66
67 template<typename... Ts>
68 static
69 std::shared_ptr<LinearProduct> Make(Ts&& ...ts){
70 return std::shared_ptr<LinearProduct>( new LinearProduct(ts...) );
71 }
72
73
74 private:
82 LinearProduct(VariableGroup variables, int num_factors, bool is_hom_vars = false) :
83 variables_(variables), num_factors_(num_factors), is_hom_vars_(is_hom_vars)
84 {
85 // num_variables_ = variables.size(); //Include homogenize variable
86 //
87 // // Resize coeffs matrix
88 Mat<dbl>& coeffs_dbl_ref = std::get<Mat<dbl>>(coeffs_);
89 // coeffs_dbl_ref.resize(num_factors_, num_variables_+1);
90 Mat<mpfr_complex>& coeffs_mpfr_ref = std::get<Mat<mpfr_complex>>(coeffs_);
91 // coeffs_mpfr_ref.resize(num_factors_, num_variables_+1);
92 // // Resize temporary variable holders and fill constant with 1
93 // temp_var_d_.resize(num_variables_ + 1);
94 // temp_var_d_[num_variables_] = dbl(1);
95 // temp_var_mp_.resize(num_variables_ + 1);
96 // temp_var_mp_[num_variables_] = mpfr_complex(1);
97
98 SetupVariables(num_factors, variables);
99 coeffs_rat_real_.resize(num_factors_, num_variables_+1);
100 coeffs_rat_imag_.resize(num_factors_, num_variables_+1);
101
102
103 for (int ii = 0; ii < num_factors_; ++ii)
104 {
105 for (int jj = 0; jj < num_variables_+1; ++jj)
106 {
107 // Generate random constants as mpq_rationals. Then downsample to mpfr_complex and dbl.
108 // TODO: RandomRat() does not generate random numbers. Same each run.
109 coeffs_rat_real_(ii,jj) = RandomRat();
110 coeffs_rat_imag_(ii,jj) = RandomRat();
111 coeffs_dbl_ref(ii,jj).real( static_cast<double>(coeffs_rat_real_(ii,jj)) );
112 coeffs_dbl_ref(ii,jj).imag( static_cast<double>(coeffs_rat_imag_(ii,jj)) );
113 coeffs_mpfr_ref(ii,jj).real( static_cast<mpfr_float>(coeffs_rat_real_(ii,jj)) );
114 coeffs_mpfr_ref(ii,jj).imag( static_cast<mpfr_float>(coeffs_rat_imag_(ii,jj)) );
115 }
116 }
117
118 is_rational_coeffs_ = true;
119
120 // If we are creating a linear product for variable group that is already homogenized,
121 // we do not use the constant(last) column in the coefficient matrix
122 if(is_hom_vars)
123 {
124 is_homogenized_ = true;
125 hom_variable_ = Integer::Make(0);
126 for(int ii = 0; ii < coeffs_mpfr_ref.rows(); ++ii)
127 {
128 coeffs_rat_real_(ii,num_variables_) = mpq_rational(0);
129 coeffs_rat_imag_(ii,num_variables_) = mpq_rational(0);
130 coeffs_dbl_ref(ii,num_variables_) = dbl(0);
131 coeffs_mpfr_ref(ii,num_variables_) = mpfr_complex(0);
132 }
133 }
134
135
136 }
137
138
139
149 LinearProduct(VariableGroup const& variables, Mat<mpfr_complex> const& coeffs_mpfr, bool is_hom_vars = false)
150 : variables_(variables), num_factors_(coeffs_mpfr.rows()), is_hom_vars_(is_hom_vars)
151 {
152 if(variables.size()+1 != coeffs_mpfr.cols())
153 throw std::runtime_error("attempting to construct a linear product manually, not enough columns for the number of variables in the variable group");
154
155
156 // Resize coeffs matrix
157 Mat<dbl>& coeffs_dbl_ref = std::get<Mat<dbl>>(coeffs_);
158 Mat<mpfr_complex>& coeffs_mpfr_ref = std::get<Mat<mpfr_complex>>(coeffs_);
159
160 SetupVariables(num_factors_, variables);
161
162 coeffs_mpfr_ref = coeffs_mpfr;
163
164 // If we are creating a linear product for variable group that is already homogenized,
165 // we do not use the constant(last) column in the coefficient matrix
166 if(is_hom_vars)
167 {
168 is_homogenized_ = true;
169 hom_variable_ = Integer::Make(0);
170 for(int ii = 0; ii < coeffs_mpfr_ref.rows(); ++ii)
171 {
172 coeffs_mpfr_ref(ii,num_variables_) = mpfr_complex(0);
173 }
174 }
175
176 // Set the coefficient matrices with input matrices.
177
178 for(int ii = 0; ii < num_factors_; ++ii)
179 {
180 for(int jj = 0; jj < coeffs_mpfr.cols(); ++jj)
181 {
182 coeffs_dbl_ref(ii,jj) = static_cast<dbl>(coeffs_mpfr_ref(ii,jj));
183 }
184 }
185
186
187 is_rational_coeffs_ = false;
188
189 }
190
191
192
193 public:
194
195
196
197
198
205 // void AddVariable(std::shared_ptr<Node> child) override
206 // {
207 // if(std::dynamic_pointer_cast< std::shared_ptr<Variable> >(child) == nullptr)
208 // {
209 // throw std::runtime_error("Only Variable node types can be children of a LinearProduct node.");
210 // }
211 // }
212
213
214
215
216
217
221 void Reset() const override
222 {
224 for(auto& v : variables_)
225 {
226 v->Reset();
227 }
228 };
229
230
234 void print(std::ostream & target) const override;
235
236
237
238
242 std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const override ;
243
244
245
246
253 int Degree(std::shared_ptr<Variable> const& v = nullptr) const override;
254
255
256
257
265
266 int Degree(VariableGroup const& vars) const override;
267
268
275 std::vector<int> MultiDegree(VariableGroup const& vars) const override;
276
277
278
279
280
281
282
289 void Homogenize(VariableGroup const& vars, std::shared_ptr<Variable> const& homvar) override;
290
291
292
300
301 bool IsHomogeneous(std::shared_ptr<Variable> const& v = nullptr) const override;
302
310 bool IsHomogeneous(VariableGroup const& vars) const override;
311
312
313
319 virtual void precision(unsigned int prec) const override
320 {
321 auto& val_pair = std::get< std::pair<mpfr_complex,bool> >(current_value_);
322 val_pair.first.precision(prec);
323
324 this->PrecisionChangeSpecific(prec);
325
326 for (auto iter : variables_)
327 iter->precision(prec);
328
329 };
330
331
332
333 unsigned EliminateZeros() override { return 0;};
334
335 unsigned EliminateOnes() override {return 0;};
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
357 void GetVariables(VariableGroup& vars) const
358 {
359 vars = variables_;
360 }
361
362
363
364
368 void GetHomVariable(std::shared_ptr<Node>& hom_var) const
369 {
370 hom_var = hom_variable_;
371 }
372
373
374
378 void GetRatCoeffs(Mat<mpq_rational>& coeffs_real, Mat<mpq_rational>& coeffs_imag) const
379 {
380 coeffs_real = coeffs_rat_real_;
381 coeffs_imag = coeffs_rat_imag_;
382 }
383
387 void GetMPFRCoeffs(Mat<mpfr_complex>& coeffs) const
388 {
389 auto& coeffs_mpfr_ref = std::get<Mat<mpfr_complex>>(coeffs_);
390 coeffs = coeffs_mpfr_ref;
391 }
392
397 {
398 return is_rational_coeffs_;
399 }
400
401
402
410 template<typename CType>
411 Vec<CType> GetCoeffs(size_t index)
412 {
413 Vec<CType> coeff_ret(num_variables_ + 1);
414 Mat<CType>& coeff_ref = std::get<Mat<CType>>(coeffs_);
415
416 for(int jj = 0; jj < num_variables_ + 1; ++jj)
417 {
418 coeff_ret(jj) = coeff_ref(index,jj);
419 }
420
421 return coeff_ret;
422 }
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439 protected:
445 dbl FreshEval_d(std::shared_ptr<Variable> const& diff_variable) const override
446 {
447 dbl eval_value;
448
449 this->FreshEval_d(eval_value, diff_variable);
450 return eval_value;
451 }
452
459 void FreshEval_d(dbl& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override
460 {
461 evaluation_value = dbl(1);
462 const Mat<dbl>& coeffs_ref = std::get< Mat<dbl> >(coeffs_);
463
464
465 // Evaluate all afine variables and store
466 for (int jj = 0; jj < num_variables_; ++jj)
467 {
468 variables_[jj]->EvalInPlace<dbl>(temp_var_d_[jj], diff_variable);
469 }
470
471 hom_variable_->EvalInPlace<dbl>(temp_var_d_[num_variables_], diff_variable);
472
473
474
475
476
477
478 // Evaluate the linear product
479 for (int ii = 0; ii < num_factors_; ++ii)
480 {
481 // Add all terms in one linear factor and store in temp_sum_d_
482 temp_sum_d_ = dbl(0);
483 for (int jj = 0; jj < num_variables_ + 1; ++jj)
484 {
485 temp_sum_d_ += coeffs_ref(ii,jj)*temp_var_d_[jj];
486 }// re: loop through variables
487
488
489 // Multiply factors together
490 evaluation_value *= temp_sum_d_;
491 }// re: loop through factors
492 }
493
494
500 mpfr_complex FreshEval_mp(std::shared_ptr<Variable> const& diff_variable) const override
501 {
502 mpfr_complex eval_value;
503
504 this->FreshEval_mp(eval_value, diff_variable);
505 return eval_value;
506 }
507
508
515 void FreshEval_mp(mpfr_complex& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override
516 {
517 evaluation_value = mpfr_complex(1);
518 const Mat<mpfr_complex>& coeffs_ref = std::get< Mat<mpfr_complex> >(coeffs_);
519
520 // Evaluate all afine variables and store
521 for (int jj = 0; jj < num_variables_; ++jj)
522 {
523 variables_[jj]->EvalInPlace<mpfr_complex>(temp_var_mp_[jj], diff_variable);
524 }
525 hom_variable_->EvalInPlace<mpfr_complex>(temp_var_mp_[num_variables_], diff_variable);
526
527
528
529
530
531 for (int ii = 0; ii < num_factors_; ++ii)
532 {
533 // Add all terms in one linear factor and store in temp_sum_d_
534 temp_sum_mp_ = mpfr_complex(0);
535 for (int jj = 0; jj < num_variables_ + 1; ++jj)
536 {
537 temp_sum_mp_ += coeffs_ref(ii,jj)*temp_var_mp_[jj];
538 }
539
540
541 // Multiply factors together
542 evaluation_value *= temp_sum_mp_;
543 }
544 }
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566 private:
567 Mat<mpq_rational> coeffs_rat_real_;
568
569 Mat<mpq_rational> coeffs_rat_imag_;
570
571 std::tuple< Mat<dbl>, Mat<mpfr_complex> > coeffs_;
572
573 VariableGroup variables_;
574
575 std::shared_ptr<Node> hom_variable_;
576
577
578 size_t num_factors_;
579 size_t num_variables_;
580 bool is_rational_coeffs_;
581 bool is_homogenized_ = false;
582 bool is_hom_vars_ = false;
583
584
585 mutable std::vector<dbl> temp_var_d_;
586 mutable std::vector<mpfr_complex> temp_var_mp_;
587 mutable mpfr_complex temp_sum_mp_;
588 mutable dbl temp_sum_d_;
589
590
591
592
593
594
595
596 private:
597
598 LinearProduct() = default;
599
600 LinearProduct(VariableGroup const& variables, std::shared_ptr<Node> const& hom_var,
601 Mat<mpq_rational> const& coeffs_real, Mat<mpq_rational> const& coeffs_imag, bool is_hom_vars) :
602 variables_(variables), num_factors_(coeffs_real.rows()), hom_variable_(hom_var), is_hom_vars_(is_hom_vars)
603 {
604 num_variables_ = variables.size();
605
606 // Resize coeffs matrix
607 Mat<dbl>& coeffs_dbl_ref = std::get<Mat<dbl>>(coeffs_);
608 coeffs_dbl_ref.resize(num_factors_, num_variables_+1);
609 Mat<mpfr_complex>& coeffs_mpfr_ref = std::get<Mat<mpfr_complex>>(coeffs_);
610 coeffs_mpfr_ref.resize(num_factors_, num_variables_+1);
611
612 // Resize temporary variable holders
613 temp_var_d_.resize(num_variables_ + 1);
614 temp_var_d_[num_variables_] = dbl(1);
615 temp_var_mp_.resize(num_variables_ + 1);
616 temp_var_mp_[num_variables_] = mpfr_complex(1);
617
618
619 coeffs_rat_real_ = coeffs_real;
620 coeffs_rat_imag_ = coeffs_imag;
621
622 for (int ii = 0; ii < num_factors_; ++ii)
623 {
624 for (int jj = 0; jj < num_variables_+1; ++jj)
625 {
626 coeffs_dbl_ref(ii,jj).real( static_cast<double>(coeffs_rat_real_(ii,jj)) );
627 coeffs_dbl_ref(ii,jj).imag( static_cast<double>(coeffs_rat_imag_(ii,jj)) );
628 coeffs_mpfr_ref(ii,jj).real( static_cast<mpfr_float>(coeffs_rat_real_(ii,jj)) );
629 coeffs_mpfr_ref(ii,jj).imag( static_cast<mpfr_float>(coeffs_rat_imag_(ii,jj)) );
630 }
631 }
632
633 is_rational_coeffs_ = true;
634
635 if(is_hom_vars)
636 {
637 is_homogenized_ = true;
638 hom_variable_ = Integer::Make(0);
639 }
640
641 }
642
643
644
645 LinearProduct(VariableGroup const& variables, std::shared_ptr<Node> const& hom_var, Mat<mpfr_complex> const& coeffs, bool is_hom_vars) :
646 variables_(variables), num_factors_(coeffs.rows()), hom_variable_(hom_var), is_hom_vars_(is_hom_vars)
647 {
648 num_variables_ = variables.size();
649
650 // Resize coeffs matrix
651 Mat<dbl>& coeffs_dbl_ref = std::get<Mat<dbl>>(coeffs_);
652 coeffs_dbl_ref.resize(num_factors_, num_variables_+1);
653 Mat<mpfr_complex>& coeffs_mpfr_ref = std::get<Mat<mpfr_complex>>(coeffs_);
654 coeffs_mpfr_ref.resize(num_factors_, num_variables_+1);
655
656 // Resize temporary variable holders
657 temp_var_d_.resize(num_variables_ + 1);
658 temp_var_d_[num_variables_] = dbl(1);
659 temp_var_mp_.resize(num_variables_ + 1);
660 temp_var_mp_[num_variables_] = mpfr_complex(1);
661
662 coeffs_mpfr_ref = coeffs;
663
664 for (int ii = 0; ii < num_factors_; ++ii)
665 {
666 for (int jj = 0; jj < num_variables_+1; ++jj)
667 {
668 coeffs_dbl_ref(ii,jj) = static_cast<dbl>(coeffs_mpfr_ref(ii,jj));
669 }
670 }
671
672 is_rational_coeffs_ = false;
673
674 if(is_hom_vars)
675 {
676 is_homogenized_ = true;
677 hom_variable_ = Integer::Make(0);
678 }
679
680 }
681
682
689
690 std::shared_ptr<LinearProduct> GetLinears(size_t index) const;
691
692
693
700
701 std::shared_ptr<LinearProduct> GetLinears(std::vector<size_t> indices) const;
702
703
704
705 void SetupVariables(size_t num_factors, VariableGroup const& variables)
706 {
707 num_variables_ = variables.size();
708
709 // Resize coeffs matrix
710 Mat<dbl>& coeffs_dbl_ref = std::get<Mat<dbl>>(coeffs_);
711 coeffs_dbl_ref.resize(num_factors_, num_variables_+1);
712 Mat<mpfr_complex>& coeffs_mpfr_ref = std::get<Mat<mpfr_complex>>(coeffs_);
713 coeffs_mpfr_ref.resize(num_factors_, num_variables_+1);
714
715 // Resize temporary variable holders
716 temp_var_d_.resize(num_variables_ + 1);
717 temp_var_d_[num_variables_] = dbl(1);
718 temp_var_mp_.resize(num_variables_ + 1);
719 temp_var_mp_[num_variables_] = mpfr_complex(1);
720
721 hom_variable_ = Integer::Make(1);
722 }
723
724
725
726
727 friend class boost::serialization::access;
728
729 template <typename Archive>
730 void serialize(Archive& ar, const unsigned version) {
731 ar & boost::serialization::base_object<Symbol>(*this);
732 }
733
734
735 void PrecisionChangeSpecific(unsigned prec) const
736 {
737 temp_sum_mp_.precision(prec);
738 for(auto& v : temp_var_mp_)
739 {
740 v.precision(prec);
741 }
742
743 Mat<mpfr_complex> coeffs_ref = std::get<Mat<mpfr_complex>>(coeffs_);
744 for(int ii = 0; ii < coeffs_ref.rows(); ++ii)
745 {
746 for(int jj = 0; jj < coeffs_ref.cols(); ++jj)
747 {
748 coeffs_ref(ii,jj).precision(prec);
749 coeffs_ref(ii,jj).real( static_cast<mpfr_float>(coeffs_rat_real_(ii,jj)) );
750 coeffs_ref(ii,jj).imag( static_cast<mpfr_float>(coeffs_rat_imag_(ii,jj)) );
751 }
752 }
753 }
754
755 };
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
779 class DiffLinear : public virtual Symbol, public virtual EnableSharedFromThisVirtual<DiffLinear>
780 {
781 public:
782 BERTINI_DEFAULT_VISITABLE()
783
784 virtual ~DiffLinear() = default;
785
786 template<typename... Ts>
787 static
788 std::shared_ptr<DiffLinear> Make(Ts&& ...ts){
789 return std::shared_ptr<DiffLinear>( new DiffLinear(ts...) );
790 }
791
792 private:
793
800 DiffLinear(std::shared_ptr<LinearProduct> const& linear);
801
802 public:
803
804
805
806
807
808
809
810
811
812
813
814
818 void Reset() const override
819 {
821 };
822
823
827 void print(std::ostream & target) const override;
828
829
830
831
835 std::shared_ptr<Node> Differentiate(std::shared_ptr<Variable> const& v = nullptr) const override
836 {
837 return Integer::Make(0);
838 }
839
840
847 int Degree(std::shared_ptr<Variable> const& v = nullptr) const override
848 {
849 return 0;
850 };
851
852
853
854
862
863 int Degree(VariableGroup const& vars) const override
864 {
865 return 0;
866 };
867
874 std::vector<int> MultiDegree(VariableGroup const& vars) const override
875 {
876 return std::vector<int>(vars.size(),0);
877 }
878
879
880
881
882
889 void Homogenize(VariableGroup const& vars, std::shared_ptr<Variable> const& homvar) override
890 {
891 };
892
893
894 bool IsHomogeneous(std::shared_ptr<Variable> const& v = nullptr) const override
895 {
896 return true;
897 }
898
906 bool IsHomogeneous(VariableGroup const& vars) const override
907 {
908 return true;
909 };
910
911
912
918 virtual void precision(unsigned int prec) const override
919 {
920 auto& val_pair = std::get< std::pair<mpfr_complex,bool> >(current_value_);
921 val_pair.first.precision(prec);
922
923 this->PrecisionChangeSpecific(prec);
924
925 };
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952 protected:
958 dbl FreshEval_d(std::shared_ptr<Variable> const& diff_variable) const override
959 {
960 dbl eval_value;
961
962 this->FreshEval_d(eval_value, diff_variable);
963 return eval_value;
964 }
965
972 void FreshEval_d(dbl& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override
973 {
974 for(int ii = 0; ii < variables_.size(); ++ii)
975 {
976 if(diff_variable == variables_[ii])
977 {
978 auto& coeff_ref = std::get<Mat<dbl>>(coeffs_);
979 evaluation_value = coeff_ref(0,ii);
980 return;
981 }
982 }
983
984 // If not one of the affine variables
985 if(diff_variable == hom_variable_)
986 {
987 auto& coeff_ref = std::get<Mat<dbl>>(coeffs_);
988 evaluation_value = coeff_ref(0,variables_.size()-1);
989 return;
990 }
991
992
993 // If none of the variables
994 evaluation_value = dbl(0);
995 return;
996 }
997
998
1004 mpfr_complex FreshEval_mp(std::shared_ptr<Variable> const& diff_variable) const override
1005 {
1006 mpfr_complex eval_value;
1007
1008 this->FreshEval_mp(eval_value, diff_variable);
1009 return eval_value;
1010 }
1011
1012
1019 void FreshEval_mp(mpfr_complex& evaluation_value, std::shared_ptr<Variable> const& diff_variable) const override
1020 {
1021 for(int ii = 0; ii < variables_.size(); ++ii)
1022 {
1023 if(diff_variable == variables_[ii])
1024 {
1025 auto& coeff_ref = std::get<Mat<mpfr_complex>>(coeffs_);
1026 evaluation_value = coeff_ref(0,ii);
1027 return;
1028 }
1029 }
1030
1031 // If not one of the affine variables
1032 if(diff_variable == hom_variable_)
1033 {
1034 auto& coeff_ref = std::get<Mat<mpfr_complex>>(coeffs_);
1035 evaluation_value = coeff_ref(0,variables_.size()-1);
1036 return;
1037 }
1038
1039
1040 // If none of the variables
1041 evaluation_value = mpfr_complex(0);
1042 return;
1043 }
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065 private:
1066 // std::vector< std::vector< std::tuple<mpq_rational, dbl, mpfr_complex> > > coeffs_;
1067 Mat<mpq_rational> coeffs_rat_real_;
1068
1069 Mat<mpq_rational> coeffs_rat_imag_;
1070
1071 std::tuple< Mat<dbl>, Mat<mpfr_complex> > coeffs_;
1072
1073 VariableGroup variables_;
1074
1075 std::shared_ptr<Node> hom_variable_;
1076
1077
1078 size_t num_variables_;
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088 private:
1089
1090 DiffLinear() = default;
1091
1092
1093
1094 friend class boost::serialization::access;
1095
1096 template <typename Archive>
1097 void serialize(Archive& ar, const unsigned version) {
1098 ar & boost::serialization::base_object<NaryOperator>(*this);
1099 }
1100
1101
1102 void PrecisionChangeSpecific(unsigned prec) const
1103 {
1104 Mat<mpfr_complex> coeffs_ref = std::get<Mat<mpfr_complex>>(coeffs_);
1105 for(int ii = 0; ii < coeffs_ref.rows(); ++ii)
1106 {
1107 for(int jj = 0; jj < coeffs_ref.cols(); ++jj)
1108 {
1109 coeffs_ref(ii,jj).precision(prec);
1110 }
1111 }
1112 }
1113
1114 };
1115
1116
1117
1118
1119
1120 } // re: namespace node
1121} // re: namespace bertini
1122
1123
1124
1125
1126#endif
Represents the differential of a single linear.
Definition linear_product.hpp:780
void print(std::ostream &target) const override
Definition linear_product.cpp:482
void Reset() const override
Reset variable values in this node.
Definition linear_product.hpp:818
std::shared_ptr< Node > Differentiate(std::shared_ptr< Variable > const &v=nullptr) const override
Definition linear_product.hpp:835
virtual void precision(unsigned int prec) const override
Definition linear_product.hpp:918
bool IsHomogeneous(VariableGroup const &vars) const override
Check for homogeneity, with respect to a variable group. If vars is the same variable group as the on...
Definition linear_product.hpp:906
std::vector< int > MultiDegree(VariableGroup const &vars) const override
Compute the multidegree with respect to a variable group. This is for homogenization,...
Definition linear_product.hpp:874
void FreshEval_d(dbl &evaluation_value, std::shared_ptr< Variable > const &diff_variable) const override
Evaluation of linear product node IN PLACE. Returns evaluation value.
Definition linear_product.hpp:972
int Degree(VariableGroup const &vars) const override
Computer the degree for a particular group of variables. If one of the variables is a part of the lin...
Definition linear_product.hpp:863
void Homogenize(VariableGroup const &vars, std::shared_ptr< Variable > const &homvar) override
Homogenize a sum, with respect to a variable group, and using a homogenizing variable.
Definition linear_product.hpp:889
int Degree(std::shared_ptr< Variable > const &v=nullptr) const override
Computes the degree for a particular variable. If that variable is part of the linear product,...
Definition linear_product.hpp:847
void FreshEval_mp(mpfr_complex &evaluation_value, std::shared_ptr< Variable > const &diff_variable) const override
Evaluation of linear product node IN PLACE. Returns evaluation value.
Definition linear_product.hpp:1019
mpfr_complex FreshEval_mp(std::shared_ptr< Variable > const &diff_variable) const override
Evaluation of linear product node. Returns evaluation value.
Definition linear_product.hpp:1004
bool IsHomogeneous(std::shared_ptr< Variable > const &v=nullptr) const override
Definition linear_product.hpp:894
dbl FreshEval_d(std::shared_ptr< Variable > const &diff_variable) const override
Evaluation of linear product node. Returns evaluation value.
Definition linear_product.hpp:958
Represents a product of linears as leaves in the function tree.
Definition linear_product.hpp:60
void FreshEval_mp(mpfr_complex &evaluation_value, std::shared_ptr< Variable > const &diff_variable) const override
Evaluation of linear product node IN PLACE. Returns evaluation value.
Definition linear_product.hpp:515
void GetRatCoeffs(Mat< mpq_rational > &coeffs_real, Mat< mpq_rational > &coeffs_imag) const
Getter for rational coefficients.
Definition linear_product.hpp:378
bool IsHomogeneous(std::shared_ptr< Variable > const &v=nullptr) const override
Check for homogeneity, with respect to a variable. If vars is the same variable group as the one used...
Definition linear_product.cpp:227
void Reset() const override
Accept a variable and add it to the list of variables in linear factors.
Definition linear_product.hpp:221
std::shared_ptr< Node > Differentiate(std::shared_ptr< Variable > const &v=nullptr) const override
Definition linear_product.cpp:60
mpfr_complex FreshEval_mp(std::shared_ptr< Variable > const &diff_variable) const override
Evaluation of linear product node. Returns evaluation value.
Definition linear_product.hpp:500
void Homogenize(VariableGroup const &vars, std::shared_ptr< Variable > const &homvar) override
Homogenize a sum, with respect to a variable group, and using a homogenizing variable.
Definition linear_product.cpp:160
bool IsRationalCoefficients()
Are there rational coefficients?
Definition linear_product.hpp:396
void GetHomVariable(std::shared_ptr< Node > &hom_var) const
Getter for the homogenizing variable.
Definition linear_product.hpp:368
dbl FreshEval_d(std::shared_ptr< Variable > const &diff_variable) const override
Evaluation of linear product node. Returns evaluation value.
Definition linear_product.hpp:445
virtual void precision(unsigned int prec) const override
Definition linear_product.hpp:319
void GetMPFRCoeffs(Mat< mpfr_complex > &coeffs) const
Getter for mpfr_complex coefficients.
Definition linear_product.hpp:387
void FreshEval_d(dbl &evaluation_value, std::shared_ptr< Variable > const &diff_variable) const override
Evaluation of linear product node IN PLACE. Returns evaluation value.
Definition linear_product.hpp:459
Vec< CType > GetCoeffs(size_t index)
Getter for the coefficients of a single linear factor. Constant coefficient is last element of the Ve...
Definition linear_product.hpp:411
unsigned EliminateOnes() override
A transform function, which eliminates nodes from the tree.
Definition linear_product.hpp:335
void GetVariables(VariableGroup &vars) const
Getter for the differential of all variables.
Definition linear_product.hpp:357
std::vector< int > MultiDegree(VariableGroup const &vars) const override
Compute the multidegree with respect to a variable group. This is for homogenization,...
Definition linear_product.cpp:139
unsigned EliminateZeros() override
A transform function, which eliminates nodes from the tree.
Definition linear_product.hpp:333
void print(std::ostream &target) const override
Definition linear_product.cpp:391
int Degree(std::shared_ptr< Variable > const &v=nullptr) const override
Computes the degree for a particular variable. If that variable is part of the linear product,...
Definition linear_product.cpp:102
void ResetStoredValues() const
Abstract symbol class.
Definition symbol.hpp:57
Bertini extensions of the Eigen linear algebra library.
Collects the various header files which define the Bertini2 function tree node types.
mpq_rational RandomRat()
Definition random.hpp:61