Macaulay2 Engine
Loading...
Searching...
No Matches
NAG.hpp
Go to the documentation of this file.
1// Copyright 2008 Anton Leykin and Mike Stillman
2
3// Anton Leykin's code in this file is in the public domain.
4
5#ifndef _nag_
6#define _nag_
7
44
45#include "engine-includes.hpp"
46
47#include <algorithm>
48#include <assert.h>
49#include <map>
50#include <math.h>
51#include <memory>
52#include <stdio.h>
53#include <stdlib.h>
54#include <string.h>
55#include <sys/types.h>
56#include <utility>
57#include <vector>
58
59#include "interface/NAG.h"
60#include "matrix.hpp"
61#include "SLP.hpp"
62#include "aring-CC.hpp"
63#include "aring-glue.hpp"
64#include "aring.hpp"
65#include "buffer.hpp"
66#include "error.h"
67#include "hash.hpp"
68#include "newdelete.hpp"
69#include "ring.hpp"
70#include "ringelem.hpp"
71
72class Matrix;
73class PointArray;
74class PolyRing;
75class SLProgram;
76
88{
89 std::unique_ptr<PointArray> mPointArray;
90public:
92
94};
95
110// PointArray
112{
113 public:
114 using RealVector = std::vector<double>;
115 using Weight = double;
116 PointArray(Weight epsilon, const RealVector& weights)
117 : mEpsilon(epsilon), mWeights(weights)
118 {
119 }
120 PointArray(Weight epsilon, int n) : mEpsilon(epsilon)
121 {
122 double s = 0;
123 for (int i = 0; i < n; i++)
124 {
125 double r = rand();
126 s += r;
127 mWeights.push_back(r);
128 }
129 for (int i = 0; i < n; i++) mWeights[i] /= s;
130 }
131 virtual ~PointArray() {
132 // std::cerr << "entering ~PointArray()" << std::endl;
133 }
135 {
136 Weight w = weight(a);
137 int p = lookup(a);
138 if (p != -1) return p;
139 if (mMap.find(w) != mMap.end()) return -1;
140 int ret = static_cast<int>(mPoints.size());
141 mPoints.push_back(a);
142 mMap.insert(std::pair<Weight, int>(w, ret));
143 return ret;
144 }
145 int lookup(const RealVector& a) const
146 {
147 Weight w = weight(a);
148 auto le = left(w);
149 auto ri = right(w);
150 for (auto i = le; i != ri; ++i)
151 if (are_same(mPoints[i->second], a)) return i->second;
152 return -1;
153 }
154 Weight weight(const RealVector& a) const
155 {
156 Weight w = 0;
157 auto n = mWeights.size();
158 assert(n == a.size());
159 for (int i = 0; i < n; ++i) w += mWeights[i] * a[i];
160 return w;
161 }
162 bool are_same(const RealVector& a, const RealVector& b) const
163 {
164 auto n = a.size();
165 assert(n == b.size());
166 for (int i = 0; i < n; ++i)
167 if (fabs(a[i] - b[i]) >= mEpsilon) return false;
168 return true;
169 }
170 void text_out(buffer& o) const
171 {
172 o << "PointArray( " << mPoints.size() << " points: ";
173 for (auto i = mMap.begin(); i != mMap.end(); ++i) o << i->second << " ";
174 o << ")" << newline;
175 }
176
177 private:
178 std::map<Weight, int> mMap;
179 std::vector<RealVector> mPoints;
180 Weight mEpsilon; // tolerance
181 RealVector mWeights; // random positive numbers summing up to 1
182
183 decltype(mMap)::const_iterator left(Weight key) const
184 {
185 return mMap.lower_bound(key - mEpsilon);
186 }
187 decltype(mMap)::const_iterator right(Weight key) const
188 {
189 return mMap.upper_bound(key + mEpsilon);
190 }
191};
192
193// patching defs and functions: /////////////////////////////////////////
194// switching from CCC to ConcreteRing<ARingCC> /////////////////////////
195#define CCC M2::ConcreteRing<M2::ARingCC>
196inline const CCC* cast_to_CCC(const Ring* R)
197{
198 return dynamic_cast<const CCC*>(R);
199}
200
201inline ring_elem from_doubles(const CCC* C, double re, double im)
202{
203 M2::ARingCC::Element a(C->ring());
204 C->ring().set_from_doubles(a, re, im);
206 C->ring().to_ring_elem(result, a);
207 return result;
208}
209
210inline gmp_CC toBigComplex(const CCC* C, ring_elem a)
211{
212 M2::ARingCC::Element b(C->ring());
213 C->ring().from_ring_elem(b, a);
214 gmp_CC result = C->ring().toBigComplex(b);
215 return result;
216}
217
218
219// Simple complex number class
221{
222 private:
223 double real; // Real Part
224 double imag; // Imaginary Part
225 public:
226 complex();
227 complex(double);
228 complex(double, double);
229 complex(const complex&);
233 complex operator-() const;
236 complex& operator+=(const complex);
237 complex getconjugate() const;
239 double getmodulus();
240 double getreal() const;
241 double getimaginary() const;
242 bool operator==(complex);
243 void operator=(complex);
244 void snprint(char*, int);
245};
246
247// CONSTRUCTOR
249inline complex::complex(double r)
250{
251 real = r;
252 imag = 0;
253}
254
255inline complex::complex(double r, double im)
256{
257 real = r;
258 imag = im;
259}
260
261// COPY CONSTRUCTOR
262inline complex::complex(const complex& c)
263{
264 this->real = c.real;
265 this->imag = c.imag;
266}
267
269{
270 real = mpfr_get_d(mpfrCC->re, MPFR_RNDN);
271 imag = mpfr_get_d(mpfrCC->im, MPFR_RNDN);
272}
273
275{
276 real = c.real;
277 imag = c.imag;
278}
279
281{
282 complex tmp;
283 tmp.real = this->real + c.real;
284 tmp.imag = this->imag + c.imag;
285 return tmp;
286}
287
289{
290 this->real += c.real;
291 this->imag += c.imag;
292 return *this;
293}
294
296{
297 complex tmp;
298 tmp.real = this->real - c.real;
299 tmp.imag = this->imag - c.imag;
300 return tmp;
301}
302
304{
305 complex tmp;
306 tmp.real = -this->real;
307 tmp.imag = -this->imag;
308 return tmp;
309}
310
312{
313 complex tmp;
314 tmp.real = (real * c.real) - (imag * c.imag);
315 tmp.imag = (real * c.imag) + (imag * c.real);
316 return tmp;
317}
318
320{
321 double div = (c.real * c.real) + (c.imag * c.imag);
322 complex tmp;
323 tmp.real = (real * c.real) + (imag * c.imag);
324 tmp.real /= div;
325 tmp.imag = (imag * c.real) - (real * c.imag);
326 tmp.imag /= div;
327 return tmp;
328}
329
331{
332 complex tmp;
333 tmp.real = this->real;
334 tmp.imag = this->imag * -1;
335 return tmp;
336}
337
339{
340 complex t;
341 t.real = real;
342 t.imag = imag * -1;
343 double div;
344 div = (real * real) + (imag * imag);
345 t.real /= div;
346 t.imag /= div;
347 return t;
348}
349
350inline double complex::getmodulus()
351{
352 double z;
353 z = (real * real) + (imag * imag);
354 z = sqrt(z);
355 return z;
356}
357
358inline double complex::getreal() const { return real; }
359inline double complex::getimaginary() const { return imag; }
361{
362 return (real == c.real) && (imag == c.imag) ? 1 : 0;
363}
364
365inline void complex::snprint(char* s, int N)
366{
367 snprintf(s, N, "(%lf) + i*(%lf)", real, imag);
368}
369
370
374template <class Field>
375void zero_complex_array(int n, typename Field::element_type* a)
376{
377 for (int i = 0; i < n; i++, a++) *a = 0.;
378}
379
380template <class Field>
382 const typename Field::element_type* a,
383 typename Field::element_type* b)
384{
385 for (int i = 0; i < n; i++, a++, b++) *b = *a;
386}
387
388template <class Field>
389typename Field::element_type* make_copy_complex_array(
390 int n,
391 const typename Field::element_type* a)
392{
393 typename Field::element_type* b =
394 newarray_atomic(typename Field::element_type, n);
395 for (int i = 0; i < n; i++, a++) b[i] = *a;
396 return b;
397}
398
399template <class Field>
401 typename Field::element_type* a,
402 const typename Field::element_type b)
403{
404 for (int i = 0; i < n; i++, a++) *a = *a * b;
405}
406
407template <class Field>
409 typename Field::element_type* a,
410 const typename Field::element_type* b)
411{
412 for (int i = 0; i < n; i++, a++) *a = *a + b[i];
413}
414
415template <class Field>
416void negate_complex_array(int n, typename Field::element_type* a)
417{
418 for (int i = 0; i < n; i++, a++) *a = -*a;
419}
420
421template <class Field>
423 typename Field::element_type* a) // square of 2-norm
424{
425 double t = 0;
426 for (int i = 0; i < n; i++, a++)
427 t += a->getreal() * a->getreal() + a->getimaginary() * a->getimaginary();
428 return t;
429}
430
431// see ../packages/NAG.m2 for the description of the structure of SLPs
432
433#define libPREFIX "/tmp/slpFN."
434#define slpCOMPILED 100
435#define slpPREDICTOR 101
436#define slpCORRECTOR 102
437#define slpEND 0
438#define slpCOPY 1
439#define slpMULTIsum 2
440#define slpPRODUCT 3
441
442#define ZERO_CONST -1
443#define ONE_CONST -2
444
445// types of predictors
446#define RUNGE_KUTTA 1
447#define TANGENT 2
448#define EULER 3
449#define PROJECTIVE_NEWTON 4
450
451#define MAX_NUM_SLPs 100
452#define CONST_OFFSET 0x1000
453#define SLP_HEADER_LEN 4
454
455#define MAX_NUM_PATH_TRACKERS 10
456
457/* Conventions in relative_position SLPs:
458 nodes are referred via negative integers;
459 i-th input --> i;
460 i-th constant --> i + CONST_OFFSET. */
461
474{
475 public:
477};
478
479template <typename R>
480void evaluateSLP(const SLProgram& slp,
481 std::vector<typename R::ElementType>& values);
482
483template <class Field>
485{
486 Field F; // F->add(a,b,c)
487 public:
488 typedef typename Field::element_type element_type;
489
490 private:
491 const CCC* C; // ConcreteRing<ARingCCC>*
492 friend class PathTracker;
493
494 static SLP<Field>* catalog[MAX_NUM_SLPs]; // get rid of... !!!
495 static int num_slps;
496
497 bool is_relative_position; // can use relative or absolute addressing
498 M2_arrayint program; // std::vector???
499 element_type* nodes; // array of CCs
500 gc_vector<int> node_index; // points to position in program (rel. to start)
501 // of operation corresponding to a node
503
504 void* handle; // dynamic library handle
506 clock_t eval_time; // accumulates time spent in evaluation
507 int n_calls; // number of times called
508
509 SLP();
510
511 static void make_nodes(element_type*&, int size);
512 int poly_to_horner_slp(int n,
513 gc_vector<int>& prog,
515 Nterm*& f); // used by make
516
517 int diffNodeInput(int n, int v, gc_vector<int>& prog); // used by jacobian
518 int diffPartReference(int n,
519 int ref,
520 int v,
521 gc_vector<int>& prog); // used by diffNodeInput
522
523 /* obsolete!!!
524 void predictor(); // evaluates a predictor
525 void corrector(); // evaluates a corrector
526 */
527
529 int& aa,
530 int cur_node) // used by convert_to_absolute_position
531 {
532 if (aa < 0)
533 aa = cur_node + aa;
534 else if (aa < CONST_OFFSET)
535 aa = num_consts + aa; // an input
536 else
537 aa -= CONST_OFFSET; // a constant
538 }
540
541 public:
542 int num_out() { return rows_out * cols_out; }
543 SLP<Field> /* or null */* copy();
544 SLP<Field> /* or null */* jacobian(bool makeHxH,
545 SLP<Field>*& slpHxH,
546 bool makeHxtH,
547 SLP<Field>*& slpHxtH);
548 SLP<Field> /* or null */* concatenate(const SLP<Field>* slp);
549 static SLP<Field> /* or null */* make(const PolyRing*, ring_elem);
550 static SLP<Field> /* or null */* make(const Matrix* consts,
552 virtual ~SLP();
553
554 void text_out(buffer& o) const;
555 void stats_out(buffer& o) const;
556 void evaluate(int n, const element_type* values, element_type* out);
557 Matrix* evaluate(const Matrix* vals);
558};
559
562class StraightLineProgram : public SLP<ComplexField>
563{
564 public:
565 static StraightLineProgram /* or null */* make(const PolyRing* R,
566 ring_elem e);
567 static StraightLineProgram /* or null */* make(const Matrix* consts,
569
571 {
572 return static_cast<StraightLineProgram*>(
574 }
575
576 StraightLineProgram /* or null */* jacobian(bool makeHxH,
577 StraightLineProgram*& slpHxH,
578 bool makeHxtH,
579 StraightLineProgram*& slpHxtH)
580 {
581 SLP<ComplexField> *SLP1, *SLP2;
582 StraightLineProgram* ret = static_cast<StraightLineProgram*>(
583 SLP<ComplexField>::jacobian(makeHxH, SLP1, makeHxtH, SLP2));
584 slpHxH = static_cast<StraightLineProgram*>(SLP1);
585 slpHxtH = static_cast<StraightLineProgram*>(SLP2);
586 return ret;
587 }
588
589 StraightLineProgram /* or null */* copy()
590 {
591 return static_cast<StraightLineProgram*>(SLP<ComplexField>::copy());
592 }
593
594 void text_out(buffer& o) const;
595 // void stats_out(buffer& o) const;
596 void evaluate(int n, const element_type* values, element_type* out);
597 Matrix* evaluate(const Matrix* vals);
598};
599
616// enum SolutionStatus { ... defined in SLP-imp.hpp ... };
618{
619 int n; // number of coordinates
620 complex* x; // array of n coordinates
621 double t; // last value of parameter t used
622 complex* start_x; // start of the path that produced x
623 double cond; // reverse condition number of Hx
625 int num_steps; // number of steps taken along the path
626
628 void make(int m, const complex* s_s);
630 void release()
631 {
632 freemem(x);
634 }
635};
636
654{
657
658 int number; // trackers are enumerated
659
661 const Matrix *H, *S, *T; // homotopy, start, target
663 *slpHxH, // slps for evaluating H, H_{x,t}, H_{x,t}|H, H_{x}|H
665 *slpTxT; // slps for S and T, needed if is_projective
666 double productST, // real part of the Bombieri-Weyl (hermitian) product <S,T>
667 bigT; // length of arc between S and T
668 double* DMforPN; // multipliers used in ProjectiveNewton
669 double maxDegreeTo3halves; // max(degree of equation)^{3/2}
670 // inline functions needed by track
671 void evaluate_slpHxt(int n, const complex* x0t0, complex* Hxt)
672 {
673 if (is_projective)
674 {
675 complex* SxS = newarray_atomic(complex, (n + 1) * (n - 1));
676 complex* TxT = newarray_atomic(complex, (n + 1) * (n - 1));
677 const complex *x0 = x0t0, *t0 = x0t0 + n;
678 const double t = (*(double*)t0) * bigT; // t0 should be real
679 slpSxS->evaluate(n, x0, SxS);
680 slpTxT->evaluate(n, x0, TxT);
681 double c = cos(t), s = sin(t),
682 sqrt_one_minus_productST_2 = sqrt(1 - productST * productST);
683 double mS = c - productST * s / sqrt_one_minus_productST_2;
684 double mT = s / sqrt_one_minus_productST_2;
685 int j, i;
686 for (j = 0; j < n - 1; j++)
687 for (i = 0; i < n; i++)
688 *(Hxt + i * n + j) =
689 *(SxS + i * (n - 1) + j) * mS + *(TxT + i * (n - 1) + j) * mT;
690 j = n - 1; // last column
691 for (i = 0; i < n; i++) *(Hxt + i * n + j) = (x0 + i)->getconjugate();
692 i = n; // last row = H_t
693 mS = -s - productST * c / sqrt_one_minus_productST_2;
694 mT = c / sqrt_one_minus_productST_2;
695 for (j = 0; j < n - 1; j++)
696 {
697 complex tt =
698 *(SxS + i * (n - 1) + j) * mS + *(TxT + i * (n - 1) + j) * mT;
699 *(Hxt + i * n + j) = tt;
700 }
701 *(Hxt + n * n + n - 1) = complex(0.); // last row and column
702 freemem(SxS);
703 freemem(TxT);
704 }
705 else
706 slpHxt->evaluate(n + 1, x0t0, Hxt);
707 }
708 void evaluate_slpHxtH(int n, const complex* x0t0, complex* HxtH)
709 {
710 if (is_projective)
711 ERROR("not implemented");
712 else
713 slpHxtH->evaluate(n + 1, x0t0, HxtH);
714 }
715 void evaluate_slpHxH(int n, const complex* x0t0, complex* HxH)
716 {
717 if (is_projective)
718 {
719 complex* SxS = newarray_atomic(complex, (n + 1) * (n - 1));
720 complex* TxT = newarray_atomic(complex, (n + 1) * (n - 1));
721 const complex *x0 = x0t0, *t0 = x0t0 + n;
722 const double t = (*(double*)t0) * bigT; // t0 should be real
723 slpSxS->evaluate(n, x0, SxS);
724 slpTxT->evaluate(n, x0, TxT);
725 double c = cos(t), s = sin(t),
726 sqrt_one_minus_productST_2 = sqrt(1 - productST * productST);
727 double mS = c - productST * s / sqrt_one_minus_productST_2;
728 double mT = s / sqrt_one_minus_productST_2;
729 int j, i;
730 for (j = 0; j < n - 1; j++)
731 for (i = 0; i <= n; i++)
732 *(HxH + i * n + j) =
733 *(SxS + i * (n - 1) + j) * mS + *(TxT + i * (n - 1) + j) * mT;
734 j = n - 1; // last column
735 for (i = 0; i < n; i++) *(HxH + i * n + j) = (x0 + i)->getconjugate();
736 *(HxH + n * n + n - 1) = complex(0.); // last row and column
737 }
738 else
739 slpHxH->evaluate(n + 1, x0t0, HxH);
740 }
741
742 const CCC* C; // coefficient field (complex numbers)
743 const PolyRing* homotopy_R; // polynomial ring where homotopy lives (does not
744 // include t if is_projective)
747 Solution* raw_solutions; // solutions + stats
748 Matrix* solutions; // Matrix of solutions passed to top level
749
750 // parameters
760
761 void make_slps(); // creates slpHxt and alpHxH
762
763 PathTracker();
764
765 public:
766 static PathTracker /* or null */* make(const Matrix*); // from homotopy
767 static PathTracker /* or null */* make(
768 const Matrix* S,
769 const Matrix* T,
770 gmp_RR productST); // from start/target systems
771 static PathTracker /* or null */* make(
772 StraightLineProgram* slp_pred,
773 StraightLineProgram* slp_corr); // precookedSLPs
774 virtual ~PathTracker();
775
776 void text_out(buffer& o) const;
777 Matrix /* or null */* getSolution(int);
778 Matrix /* or null */* getAllSolutions();
779 int getSolutionStatus(int);
780 int getSolutionSteps(int);
783 int track(const Matrix*);
784 Matrix /* or null */* refine(
785 const Matrix* sols,
786 gmp_RR tolerance,
787 int max_corr_steps_refine = 100); // refine solutions such that (error
788 // estimate)/norm(solution) < tolerance
789
790 // raw "friends"
791 friend void rawSetParametersPT(PathTracker* PT,
799 int max_corr_steps,
802 int pred_type);
803 friend const Matrix /* or null */* rawTrackPaths(
804 StraightLineProgram* slp_pred,
805 StraightLineProgram* slp_corr,
806 const Matrix* start_sols,
810 gmp_RR max_dt,
815 int max_corr_steps,
816 int pred_type);
817};
818
819// ------------ service functions
820// --------------------------------------------------
821int degree_ring_elem(const PolyRing* R, ring_elem re);
822void print_complex_matrix(int size, const double* A);
823
824#endif
825
826// Local Variables:
827// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
828// indent-tabs-mode: nil
829// End:
Engine-boundary C API for the Numerical Algebraic Geometry subsystem.
#define CONST_OFFSET
Definition NAG.hpp:452
#define MAX_NUM_SLPs
Definition NAG.hpp:451
void zero_complex_array(int n, typename Field::element_type *a)
Definition NAG.hpp:375
void print_complex_matrix(int size, const double *A)
Definition NAG.cpp:2205
gmp_CC toBigComplex(const CCC *C, ring_elem a)
Definition NAG.hpp:210
void add_to_complex_array(int n, typename Field::element_type *a, const typename Field::element_type *b)
Definition NAG.hpp:408
Field::element_type * make_copy_complex_array(int n, const typename Field::element_type *a)
Definition NAG.hpp:389
void multiply_complex_array_scalar(int n, typename Field::element_type *a, const typename Field::element_type b)
Definition NAG.hpp:400
int degree_ring_elem(const PolyRing *R, ring_elem re)
Definition NAG.cpp:2196
ring_elem from_doubles(const CCC *C, double re, double im)
Definition NAG.hpp:201
#define CCC
Definition NAG.hpp:195
void negate_complex_array(int n, typename Field::element_type *a)
Definition NAG.hpp:416
void evaluateSLP(const SLProgram &slp, std::vector< typename R::ElementType > &values)
double norm2_complex_array(int n, typename Field::element_type *a)
Definition NAG.hpp:422
void copy_complex_array(int n, const typename Field::element_type *a, typename Field::element_type *b)
Definition NAG.hpp:381
const CCC * cast_to_CCC(const Ring *R)
Definition NAG.hpp:196
#define MAX_NUM_PATH_TRACKERS
Definition NAG.hpp:455
SolutionStatus
Definition SLP-imp.hpp:353
@ UNDETERMINED
Definition SLP-imp.hpp:354
Public umbrella header for the templated straight-line-program evaluator (SLProgram / SLEvaluatorConc...
M2::ARingCC — machine-precision complex numbers (pair of doubles).
ConcreteRing<RingType> — the templated bridge between aring and the legacy Ring API.
Shared base of the aring framework (namespace M2) that unifies the engine's coefficient rings.
Append-only GC-backed byte buffer used throughout the engine for text output.
complex element_type
Definition NAG.hpp:476
Field-traits tag used as the template parameter of SLP<Field> to pick the complex element type.
Definition NAG.hpp:474
PointArray & value()
Definition NAG.hpp:93
std::unique_ptr< PointArray > mPointArray
Definition NAG.hpp:89
M2PointArray(PointArray *pa)
Definition NAG.hpp:91
M2_bool is_projective
Definition NAG.hpp:751
gmp_RRorNull getSolutionLastT(int)
Definition NAG.cpp:2140
const Matrix * H
Definition NAG.hpp:661
friend void rawSetParametersPT(PathTracker *PT, M2_bool is_projective, gmp_RR init_dt, gmp_RR min_dt, gmp_RR dt_increase_factor, gmp_RR dt_decrease_factor, int num_successes_before_increase, gmp_RR epsilon, int max_corr_steps, gmp_RR end_zone_factor, gmp_RR infinity_threshold, int pred_type)
Definition NAG.cpp:1571
int track(const Matrix *)
Definition NAG.cpp:1640
Matrix * solutions
Definition NAG.hpp:748
static PathTracker * catalog[MAX_NUM_PATH_TRACKERS]
Definition NAG.hpp:655
gmp_RR end_zone_factor
Definition NAG.hpp:757
friend const Matrix * rawTrackPaths(StraightLineProgram *slp_pred, StraightLineProgram *slp_corr, const Matrix *start_sols, M2_bool is_projective, gmp_RR init_dt, gmp_RR min_dt, gmp_RR max_dt, gmp_RR dt_increase_factor, gmp_RR dt_decrease_factor, int num_successes_before_increase, gmp_RR epsilon, int max_corr_steps, int pred_type)
StraightLineProgram * slpHxt
Definition NAG.hpp:662
int max_corr_steps
Definition NAG.hpp:756
StraightLineProgram * slpHxH
Definition NAG.hpp:663
const PolyRing * homotopy_R
Definition NAG.hpp:743
int getSolutionSteps(int)
Definition NAG.cpp:2134
void evaluate_slpHxt(int n, const complex *x0t0, complex *Hxt)
Definition NAG.hpp:671
static PathTracker * make(const Matrix *)
Definition NAG.cpp:1516
double maxDegreeTo3halves
Definition NAG.hpp:669
const Matrix * T
Definition NAG.hpp:661
gmp_RR init_dt
Definition NAG.hpp:752
int n_coords
Definition NAG.hpp:745
const Matrix * S
Definition NAG.hpp:661
int number
Definition NAG.hpp:658
virtual ~PathTracker()
Definition NAG.cpp:1425
StraightLineProgram * slpSx
Definition NAG.hpp:664
void evaluate_slpHxH(int n, const complex *x0t0, complex *HxH)
Definition NAG.hpp:715
void make_slps()
PathTracker()
Definition NAG.cpp:1418
int n_sols
Definition NAG.hpp:746
int pred_type
Definition NAG.hpp:759
static int num_path_trackers
Definition NAG.hpp:656
int getSolutionStatus(int)
Definition NAG.cpp:2128
StraightLineProgram * slpT
Definition NAG.hpp:664
gmp_RR dt_decrease_factor
Definition NAG.hpp:753
double productST
Definition NAG.hpp:666
void evaluate_slpHxtH(int n, const complex *x0t0, complex *HxtH)
Definition NAG.hpp:708
gmp_RR epsilon
Definition NAG.hpp:755
StraightLineProgram * slpH
Definition NAG.hpp:662
StraightLineProgram * slpS
Definition NAG.hpp:664
int num_successes_before_increase
Definition NAG.hpp:754
Matrix * getAllSolutions()
Definition NAG.cpp:2100
Matrix * target
Definition NAG.hpp:660
StraightLineProgram * slpSxS
Definition NAG.hpp:664
StraightLineProgram * slpTx
Definition NAG.hpp:664
const CCC * C
Definition NAG.hpp:742
Solution * raw_solutions
Definition NAG.hpp:747
gmp_RR min_dt
Definition NAG.hpp:752
Matrix * refine(const Matrix *sols, gmp_RR tolerance, int max_corr_steps_refine=100)
Definition NAG.cpp:1978
double * DMforPN
Definition NAG.hpp:668
double bigT
Definition NAG.hpp:667
gmp_RR infinity_threshold
Definition NAG.hpp:758
Matrix * getSolution(int)
Definition NAG.cpp:2074
gmp_RR dt_increase_factor
Definition NAG.hpp:753
StraightLineProgram * slpHxtH
Definition NAG.hpp:662
gmp_RRorNull getSolutionRcond(int)
Definition NAG.cpp:2149
StraightLineProgram * slpTxT
Definition NAG.hpp:665
void text_out(buffer &o) const
Definition NAG.cpp:2158
decltype(mMap) ::const_iterator left(Weight key) const
Definition NAG.hpp:183
bool are_same(const RealVector &a, const RealVector &b) const
Definition NAG.hpp:162
std::vector< RealVector > mPoints
Definition NAG.hpp:179
std::vector< double > RealVector
Definition NAG.hpp:114
int lookup(const RealVector &a) const
Definition NAG.hpp:145
virtual ~PointArray()
Definition NAG.hpp:131
Weight mEpsilon
Definition NAG.hpp:180
void text_out(buffer &o) const
Definition NAG.hpp:170
decltype(mMap) ::const_iterator right(Weight key) const
Definition NAG.hpp:187
PointArray(Weight epsilon, int n)
Definition NAG.hpp:120
double Weight
Definition NAG.hpp:115
int lookup_or_append(const RealVector &a)
Definition NAG.hpp:134
Weight weight(const RealVector &a) const
Definition NAG.hpp:154
RealVector mWeights
Definition NAG.hpp:181
std::map< Weight, int > mMap
Definition NAG.hpp:178
PointArray(Weight epsilon, const RealVector &weights)
Definition NAG.hpp:116
Container of numerical points equipped with an -tolerance and a random weight vector used to bucket a...
Definition NAG.hpp:112
Concrete PolyRingFlat subclass implementing ordinary commutative polynomial rings K[x_1,...
Definition poly.hpp:64
xxx xxx xxx
Definition ring.hpp:102
SLP< Field > * concatenate(const SLP< Field > *slp)
Definition NAG.cpp:353
void evaluate(int n, const element_type *values, element_type *out)
Definition NAG.cpp:713
void relative_to_absolute(int &aa, int cur_node)
Definition NAG.hpp:528
virtual ~SLP()
Definition NAG.cpp:72
int rows_out
Definition NAG.hpp:502
SLP()
Definition NAG.cpp:62
void convert_to_absolute_position()
Definition NAG.cpp:914
int cols_out
Definition NAG.hpp:502
SLP< Field > * jacobian(bool makeHxH, SLP< Field > *&slpHxH, bool makeHxtH, SLP< Field > *&slpHxtH)
Definition NAG.cpp:612
static int num_slps
Definition NAG.hpp:495
int num_operations
Definition NAG.hpp:502
clock_t eval_time
Definition NAG.hpp:506
int num_out()
Definition NAG.hpp:542
void * handle
Definition NAG.hpp:504
int poly_to_horner_slp(int n, gc_vector< int > &prog, gc_vector< element_type > &consts, Nterm *&f)
Definition NAG.cpp:237
M2_arrayint program
Definition NAG.hpp:498
void stats_out(buffer &o) const
Definition NAG.cpp:950
SLP< Field > * copy()
Definition NAG.cpp:168
Field::element_type element_type
Definition NAG.hpp:488
static SLP< Field > * make(const PolyRing *, ring_elem)
Definition NAG.cpp:289
int n_calls
Definition NAG.hpp:507
int diffNodeInput(int n, int v, gc_vector< int > &prog)
Definition NAG.cpp:450
static void make_nodes(element_type *&, int size)
Definition NAG.cpp:162
int num_inputs
Definition NAG.hpp:502
element_type * nodes
Definition NAG.hpp:499
friend class PathTracker
Definition NAG.hpp:492
static SLP< Field > * catalog[MAX_NUM_SLPs]
Definition NAG.hpp:494
void(* compiled_fn)(element_type *, element_type *)
Definition NAG.hpp:505
Field F
Definition NAG.hpp:486
int num_consts
Definition NAG.hpp:502
void text_out(buffer &o) const
Definition NAG.cpp:958
gc_vector< int > node_index
Definition NAG.hpp:500
bool is_relative_position
Definition NAG.hpp:497
int diffPartReference(int n, int ref, int v, gc_vector< int > &prog)
Definition NAG.cpp:434
const CCC * C
Definition NAG.hpp:491
Definition NAG.hpp:485
A straight-line program: a directed acyclic graph of arithmetic gates over a fixed list of inputs and...
Definition SLP-defs.hpp:89
StraightLineProgram * concatenate(const StraightLineProgram *slp)
Definition NAG.hpp:570
static StraightLineProgram * make(const PolyRing *R, ring_elem e)
Definition NAG.cpp:31
StraightLineProgram * copy()
Definition NAG.hpp:589
void evaluate(int n, const element_type *values, element_type *out)
Definition NAG.cpp:50
StraightLineProgram * jacobian(bool makeHxH, StraightLineProgram *&slpHxH, bool makeHxtH, StraightLineProgram *&slpHxtH)
Definition NAG.hpp:576
void text_out(buffer &o) const
Definition NAG.cpp:46
double getreal() const
Definition NAG.hpp:358
double imag
Definition NAG.hpp:224
complex operator*(complex)
Definition NAG.hpp:311
complex()
Definition NAG.hpp:248
complex getconjugate() const
Definition NAG.hpp:330
double getmodulus()
Definition NAG.hpp:350
void operator=(complex)
Definition NAG.hpp:274
complex operator+(complex)
Definition NAG.hpp:280
complex operator/(complex)
Definition NAG.hpp:319
double real
Definition NAG.hpp:223
double getimaginary() const
Definition NAG.hpp:359
complex operator-() const
Definition NAG.hpp:303
void snprint(char *, int)
Definition NAG.hpp:365
complex getreciprocal()
Definition NAG.hpp:338
bool operator==(complex)
Definition NAG.hpp:360
complex & operator+=(const complex)
Definition NAG.hpp:288
Engine-wide include prelude — a single point of truth for portability shims.
Engine error-reporting primitives: ERROR, INTERNAL_ERROR, error, error_message.
#define Matrix
Definition factory.cpp:14
int p
EngineObject / MutableEngineObject — shared bases that supply the hash an M2 interpreter object expec...
void freemem(void *s)
Definition m2-mem.cpp:103
void size_t s
Definition m2-mem.cpp:271
const int ERROR
Definition m2-mem.cpp:55
VALGRIND_MAKE_MEM_DEFINED & result(result)
char newline[]
Definition m2-types.cpp:49
mpfr_srcptr gmp_RR
Definition m2-types.h:148
struct gmp_CC_struct * gmp_CC
Definition m2-types.h:156
mpfr_srcptr gmp_RRorNull
Definition m2-types.h:149
char M2_bool
Definition m2-types.h:82
Matrix — the engine's immutable homomorphism F -> G between free modules.
typename std::vector< T, gc_allocator< T > > gc_vector
a version of the STL vector, which allocates its backing memory with gc.
Definition newdelete.hpp:76
#define newarray_atomic(T, len)
Definition newdelete.hpp:91
our_new_delete — per-class opt-in routing of new / delete through bdwgc.
Ring — the legacy abstract base class for every coefficient and polynomial ring.
ring_elem — the universal value type carried by every Ring* in the engine.
Singly linked-list node carrying one term of a polynomial-ring element.
Definition ringelem.hpp:156
complex * x
Definition NAG.hpp:620
double cond
Definition NAG.hpp:623
~Solution()
Definition NAG.hpp:629
SolutionStatus status
Definition NAG.hpp:624
double t
Definition NAG.hpp:621
complex * start_x
Definition NAG.hpp:622
void release()
Definition NAG.hpp:630
void make(int m, const complex *s_s)
Definition NAG.cpp:2188
Solution()
Definition NAG.hpp:627
int n
Definition NAG.hpp:619
int num_steps
Definition NAG.hpp:625
One numerical solution produced by a PathTracker run, with the full per-path diagnostic record.
Definition NAG.hpp:618