123 for (
int i = 0; i < n; i++)
129 for (
int i = 0; i < n; i++)
mWeights[i] /=
s;
138 if (
p != -1)
return p;
139 if (
mMap.find(w) !=
mMap.end())
return -1;
140 int ret =
static_cast<int>(
mPoints.size());
142 mMap.insert(std::pair<Weight, int>(w, ret));
150 for (
auto i = le; i != ri; ++i)
158 assert(n == a.size());
159 for (
int i = 0; i < n; ++i) w +=
mWeights[i] * a[i];
165 assert(n == b.size());
166 for (
int i = 0; i < n; ++i)
167 if (fabs(a[i] - b[i]) >=
mEpsilon)
return false;
172 o <<
"PointArray( " <<
mPoints.size() <<
" points: ";
173 for (
auto i =
mMap.begin(); i !=
mMap.end(); ++i) o << i->second <<
" ";
195#define CCC M2::ConcreteRing<M2::ARingCC>
198 return dynamic_cast<const CCC*
>(R);
203 M2::ARingCC::Element a(C->ring());
204 C->ring().set_from_doubles(a, re, im);
206 C->ring().to_ring_elem(
result, a);
212 M2::ARingCC::Element b(C->ring());
213 C->ring().from_ring_elem(b, a);
270 real = mpfr_get_d(mpfrCC->re, MPFR_RNDN);
271 imag = mpfr_get_d(mpfrCC->im, MPFR_RNDN);
367 snprintf(
s, N,
"(%lf) + i*(%lf)",
real,
imag);
374template <
class Field>
377 for (
int i = 0; i < n; i++, a++) *a = 0.;
380template <
class Field>
382 const typename Field::element_type* a,
383 typename Field::element_type* b)
385 for (
int i = 0; i < n; i++, a++, b++) *b = *a;
388template <
class Field>
391 const typename Field::element_type* a)
393 typename Field::element_type* b =
395 for (
int i = 0; i < n; i++, a++) b[i] = *a;
399template <
class Field>
401 typename Field::element_type* a,
402 const typename Field::element_type b)
404 for (
int i = 0; i < n; i++, a++) *a = *a * b;
407template <
class Field>
409 typename Field::element_type* a,
410 const typename Field::element_type* b)
412 for (
int i = 0; i < n; i++, a++) *a = *a + b[i];
415template <
class Field>
418 for (
int i = 0; i < n; i++, a++) *a = -*a;
421template <
class Field>
423 typename Field::element_type* a)
426 for (
int i = 0; i < n; i++, a++)
427 t += a->getreal() * a->getreal() + a->getimaginary() * a->getimaginary();
433#define libPREFIX "/tmp/slpFN."
434#define slpCOMPILED 100
435#define slpPREDICTOR 101
436#define slpCORRECTOR 102
449#define PROJECTIVE_NEWTON 4
451#define MAX_NUM_SLPs 100
452#define CONST_OFFSET 0x1000
453#define SLP_HEADER_LEN 4
455#define MAX_NUM_PATH_TRACKERS 10
481 std::vector<typename R::ElementType>& values);
483template <
class Field>
677 const complex *x0 = x0t0, *t0 = x0t0 + n;
678 const double t = (*(
double*)t0) *
bigT;
679 slpSxS->evaluate(n, x0, SxS);
680 slpTxT->evaluate(n, x0, TxT);
681 double c = cos(t),
s = sin(t),
683 double mS = c -
productST *
s / sqrt_one_minus_productST_2;
684 double mT =
s / sqrt_one_minus_productST_2;
686 for (j = 0; j < n - 1; j++)
687 for (i = 0; i < n; i++)
689 *(SxS + i * (n - 1) + j) * mS + *(TxT + i * (n - 1) + j) * mT;
691 for (i = 0; i < n; i++) *(Hxt + i * n + j) = (x0 + i)->getconjugate();
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++)
698 *(SxS + i * (n - 1) + j) * mS + *(TxT + i * (n - 1) + j) * mT;
699 *(Hxt + i * n + j) = tt;
701 *(Hxt + n * n + n - 1) =
complex(0.);
706 slpHxt->evaluate(n + 1, x0t0, Hxt);
711 ERROR(
"not implemented");
713 slpHxtH->evaluate(n + 1, x0t0, HxtH);
721 const complex *x0 = x0t0, *t0 = x0t0 + n;
722 const double t = (*(
double*)t0) *
bigT;
723 slpSxS->evaluate(n, x0, SxS);
724 slpTxT->evaluate(n, x0, TxT);
725 double c = cos(t),
s = sin(t),
727 double mS = c -
productST *
s / sqrt_one_minus_productST_2;
728 double mT =
s / sqrt_one_minus_productST_2;
730 for (j = 0; j < n - 1; j++)
731 for (i = 0; i <= n; i++)
733 *(SxS + i * (n - 1) + j) * mS + *(TxT + i * (n - 1) + j) * mT;
735 for (i = 0; i < n; i++) *(HxH + i * n + j) = (x0 + i)->getconjugate();
736 *(HxH + n * n + n - 1) =
complex(0.);
739 slpHxH->evaluate(n + 1, x0t0, HxH);
787 int max_corr_steps_refine = 100);
Engine-boundary C API for the Numerical Algebraic Geometry subsystem.
void zero_complex_array(int n, typename Field::element_type *a)
void print_complex_matrix(int size, const double *A)
gmp_CC toBigComplex(const CCC *C, ring_elem a)
void add_to_complex_array(int n, typename Field::element_type *a, const typename Field::element_type *b)
Field::element_type * make_copy_complex_array(int n, const typename Field::element_type *a)
void multiply_complex_array_scalar(int n, typename Field::element_type *a, const typename Field::element_type b)
int degree_ring_elem(const PolyRing *R, ring_elem re)
ring_elem from_doubles(const CCC *C, double re, double im)
void negate_complex_array(int n, typename Field::element_type *a)
void evaluateSLP(const SLProgram &slp, std::vector< typename R::ElementType > &values)
double norm2_complex_array(int n, typename Field::element_type *a)
void copy_complex_array(int n, const typename Field::element_type *a, typename Field::element_type *b)
const CCC * cast_to_CCC(const Ring *R)
#define MAX_NUM_PATH_TRACKERS
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.
Field-traits tag used as the template parameter of SLP<Field> to pick the complex element type.
std::unique_ptr< PointArray > mPointArray
M2PointArray(PointArray *pa)
gmp_RRorNull getSolutionLastT(int)
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)
int track(const Matrix *)
static PathTracker * catalog[MAX_NUM_PATH_TRACKERS]
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
StraightLineProgram * slpHxH
const PolyRing * homotopy_R
int getSolutionSteps(int)
void evaluate_slpHxt(int n, const complex *x0t0, complex *Hxt)
static PathTracker * make(const Matrix *)
double maxDegreeTo3halves
StraightLineProgram * slpSx
void evaluate_slpHxH(int n, const complex *x0t0, complex *HxH)
static int num_path_trackers
int getSolutionStatus(int)
StraightLineProgram * slpT
gmp_RR dt_decrease_factor
void evaluate_slpHxtH(int n, const complex *x0t0, complex *HxtH)
StraightLineProgram * slpH
StraightLineProgram * slpS
int num_successes_before_increase
Matrix * getAllSolutions()
StraightLineProgram * slpSxS
StraightLineProgram * slpTx
Matrix * refine(const Matrix *sols, gmp_RR tolerance, int max_corr_steps_refine=100)
gmp_RR infinity_threshold
Matrix * getSolution(int)
gmp_RR dt_increase_factor
StraightLineProgram * slpHxtH
gmp_RRorNull getSolutionRcond(int)
StraightLineProgram * slpTxT
void text_out(buffer &o) const
decltype(mMap) ::const_iterator left(Weight key) const
bool are_same(const RealVector &a, const RealVector &b) const
std::vector< RealVector > mPoints
std::vector< double > RealVector
int lookup(const RealVector &a) const
void text_out(buffer &o) const
decltype(mMap) ::const_iterator right(Weight key) const
PointArray(Weight epsilon, int n)
int lookup_or_append(const RealVector &a)
Weight weight(const RealVector &a) const
std::map< Weight, int > mMap
PointArray(Weight epsilon, const RealVector &weights)
Container of numerical points equipped with an -tolerance and a random weight vector used to bucket a...
Concrete PolyRingFlat subclass implementing ordinary commutative polynomial rings K[x_1,...
SLP< Field > * concatenate(const SLP< Field > *slp)
void evaluate(int n, const element_type *values, element_type *out)
void relative_to_absolute(int &aa, int cur_node)
void convert_to_absolute_position()
SLP< Field > * jacobian(bool makeHxH, SLP< Field > *&slpHxH, bool makeHxtH, SLP< Field > *&slpHxtH)
int poly_to_horner_slp(int n, gc_vector< int > &prog, gc_vector< element_type > &consts, Nterm *&f)
void stats_out(buffer &o) const
Field::element_type element_type
static SLP< Field > * make(const PolyRing *, ring_elem)
int diffNodeInput(int n, int v, gc_vector< int > &prog)
static void make_nodes(element_type *&, int size)
static SLP< Field > * catalog[MAX_NUM_SLPs]
void(* compiled_fn)(element_type *, element_type *)
void text_out(buffer &o) const
gc_vector< int > node_index
bool is_relative_position
int diffPartReference(int n, int ref, int v, gc_vector< int > &prog)
A straight-line program: a directed acyclic graph of arithmetic gates over a fixed list of inputs and...
StraightLineProgram * concatenate(const StraightLineProgram *slp)
static StraightLineProgram * make(const PolyRing *R, ring_elem e)
StraightLineProgram * copy()
void evaluate(int n, const element_type *values, element_type *out)
StraightLineProgram * jacobian(bool makeHxH, StraightLineProgram *&slpHxH, bool makeHxtH, StraightLineProgram *&slpHxtH)
void text_out(buffer &o) const
complex operator*(complex)
complex getconjugate() const
complex operator+(complex)
complex operator/(complex)
double getimaginary() const
complex operator-() const
void snprint(char *, int)
complex & operator+=(const complex)
Engine-wide include prelude — a single point of truth for portability shims.
Engine error-reporting primitives: ERROR, INTERNAL_ERROR, error, error_message.
EngineObject / MutableEngineObject — shared bases that supply the hash an M2 interpreter object expec...
VALGRIND_MAKE_MEM_DEFINED & result(result)
struct gmp_CC_struct * gmp_CC
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.
#define newarray_atomic(T, len)
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.
void make(int m, const complex *s_s)
One numerical solution produced by a PathTracker run, with the full per-path diagnostic record.