41 number *_p,
const bool _homog )
42 : n(_n), cn(_cn), maxdeg(_maxdeg),
p(_p), homog(_homog)
70 for (
i= 0;
i <
l;
i++ )
74 for (
j= 0;
j <
n;
j++ )
85 for (
j= 0;
j <
n - 1;
j++ )
110 for (
j= 0;
j <
n+1;
j++ )
exp[
j]=0;
112 for (
i= 0;
i <
l;
i++ )
133 for (
j= 1;
j <
n;
j++ )
162 c= (number *)
omAlloc(
cn *
sizeof(number) );
163 for (
j= 0;
j <
cn;
j++ )
180 for (
i= 1;
i <
cn;
i++ ) {
185 for (
j= (
cn-
i-1);
j <= (
cn-2);
j++) {
193 newnum=
nAdd( xx, c[
cn-1] );
198 for (
i= 0;
i <
cn;
i++ ) {
209 for (
k=
cn-1;
k >= 1;
k-- ) {
265 #define MAXIT (5*MMOD)
305 const int _var,
const int _tdg,
306 const rootType _rt,
const int _anz )
316 for (
i=0;
i <=
tdg;
i++ )
347 for (
i=
tdg;
i >= 0;
i-- )
394 if (! ((
i >= 0) && (
i <
anz+2) ) )
395 WarnS(
"rootContainer::evPointCoord: index out of range");
397 WarnS(
"rootContainer::evPointCoord: ievpoint == NULL");
409 Warn(
"rootContainer::evPointCoord: NULL index %d",
i);
414 Warn(
"rootContainer::evPointCoord: Wrong index %d, found_roots %s",
i,
found_roots?
"true":
"false");
423 if (
found_roots && ( from >= 0) && ( from <
tdg ) && ( to >= 0) && ( to <
tdg ) )
435 Warn(
" rootContainer::changeRoots: Wrong index %d, %d",from,to);
451 for (
i=0;
i <=
tdg;
i++ )
460 WarnS(
"rootContainer::solver: No roots found!");
463 for (
i=0;
i <=
tdg;
i++ )
delete ad[
i];
476 bool ret=
true, isf=
isfloat(a), type=
true;
499 WarnS(
"Laguerre solver: Too many iterations!");
508 WarnS(
"Laguerre solver: Too many iterations in polish!");
513 if ((!type)&&(!((
x.real()==zero)&&(
x.imag()==zero))))
x = o/
x;
514 if (
x.imag() == zero)
546 for (
i=0;
i <=
tdg;
i++ )
delete ad[
i];
559 gmp_complex dx, x1,
b, d,
f,
g,
h, sq,
gp, gm, g2;
560 gmp_float frac_g[
MR+1] = { 0.0, 0.5, 0.25, 0.75, 0.125, 0.375, 0.625, 0.875, 1.0 };
578 if ((fabs==zero) || (
abs(d)==zero))
return;
585 h= g2 - (((
f+
f) /
b ));
586 sq=
sqrt(( (
h * deg ) - g2 ) * (deg - one));
595 if((
gp.real()==zero)&&(
gp.imag()==zero))
608 if (*
x == x1)
goto ende;
612 if (
j %
MT ) *
x= x1;
613 else *
x -= ( dx * frac_g[
j /
MT ] );
633 for (
int i=
tdg;
i >= 0;
i-- )
649 for (
i=
j-1;
i > 0;
i-- )
650 *a[
i] += (*a[
i+1]*
x);
651 for (
i= 0;
i <
j;
i++ )
657 for (
i= 1;
i <
j;
i++)
658 *a[
i] += (*a[
i-1]*
y);
666 q((
x.real()*
x.real())+(
x.imag()*
x.imag()));
670 *a[
j-1] += (*a[
j]*
p);
671 for (
i=
j-2;
i > 1;
i-- )
672 *a[
i] += ((*a[
i+1]*
p)-(*a[
i+2]*q));
673 for (
i= 0;
i <
j-1;
i++ )
681 for (
i= 2;
i <
j-1;
i++)
682 *a[
i] += ((*a[
i-1]*
p)-(*a[
i-2]*q));
691 &&((!(*a[2]).real().
isZero())||(!(*a[2]).imag().
isZero())))
694 gmp_complex h1(*a[1]/(*a[2] + *a[2])), h2(*a[0] / *a[2]);
698 if (disk.
real()<zero)
724 if (((*a[1]).real().
isZero()) && ((*a[1]).imag().isZero()))
726 WerrorS(
"precision lost, try again with higher precision");
765 for (
i=
l+inc;
i<=u;
i+=inc)
767 if (r[
i]->real()<
x->real())
777 for (
i=pos;
i>
l;
i--)
784 for (
i=pos+1;
i+1>
l;
i--)
786 if (
x->imag()>
y->imag())
798 else if ((inc==2)&&(
x->imag()<r[
l+1]->
imag()))
817 for (
k=
m-1;
k >= 0;
k-- )
819 f2 = (
x * f2 ) + f1;
820 f1 = (
x * f1 ) + f0;
821 f0 = (
x * f0 ) + *a[
k];
822 ef =
abs( f0 ) + ( ex * ef );
838 for (
k= 1;
k <=
m;
k++ )
840 f2 = (
x * f2 ) + f1;
841 f1 = (
x * f1 ) + f0;
842 f0 = (
x * f0 ) + *a[
k];
843 ef =
abs( f0 ) + ( ex * ef );
854 const int _howclean )
855 : roots(_roots),
mu(_mu), howclean(_howclean)
869 for (
i= 0;
i <
rc;
i++ )
877 for (
i= 0;
i <
mc;
i++ )
892 int xkoord, r, rtest, xk, mtest;
896 for ( xkoord= 0; xkoord < anzm; xkoord++ ) {
898 for ( r= 0; r < anzr; r++ ) {
902 for ( xk =0; xk <= xkoord; xk++ )
904 tmp -= (*
roots[xk])[r] *
mu[xkoord]->evPointCoord(xk+1);
908 for ( rtest= r; rtest < anzr; rtest++ ) {
909 zwerg = tmp - (*
roots[xk])[rtest] *
mu[xkoord]->evPointCoord(xk+1);
910 for ( mtest= 0; mtest < anzr; mtest++ )
914 if ( ((zwerg.
real() <= (*
mu[xkoord])[mtest].real() + mprec) &&
915 (zwerg.
real() >= (*
mu[xkoord])[mtest].real() - mprec)) &&
916 ((zwerg.
imag() <= (*
mu[xkoord])[mtest].imag() + mprec) &&
917 (zwerg.
imag() >= (*
mu[xkoord])[mtest].imag() - mprec)) )
927 WarnS(
"rootArranger::arrange: precision lost");
934 Warn(
"rootArranger::arrange: No match? coord %d, root %d.",xkoord,r);
936 WarnS(
"One of these ...");
937 for ( rtest= r; rtest < anzr; rtest++ )
940 for ( xk =0; xk <= xkoord; xk++ )
942 tmp-= (*
roots[xk])[r] *
mu[xkoord]->evPointCoord(xk+1);
944 tmp-= (*
roots[xk])[rtest] *
mu[xkoord]->evPointCoord(xk+1);
947 WarnS(
" ... must match to one of these:");
948 for ( mtest= 0; mtest < anzr; mtest++ )
972 #define MAXPOINTS 1000
977 : LiPM_cols(cols), LiPM_rows(rows)
1081 for (
i= 1;
i <=
m;
i++ )
1092 for (
i= 1;
i <=
n;
i++ )
1101 int i,ip,ir,is,
k,kh,kp,m12,nl1,nl2;
1108 error(
WarnS(
"simplex::compute: Bad input constraint counts!");)
1113 l1= (
int *)
omAlloc0( (
n+1) *
sizeof(int) );
1114 l2= (
int *)
omAlloc0( (
m+1) *
sizeof(int) );
1115 l3= (
int *)
omAlloc0( (
m+1) *
sizeof(int) );
1120 for (
i=1;
i<=
m;
i++ )
1122 if (
LiPM[
i+1][1] < 0.0 )
1125 error(
WarnS(
"simplex::compute: Bad input tableau!");)
1126 error(
Warn(
"simplex::compute: in input Matrix row %d, column 1, value %f",
i+1,
LiPM[
i+1][1]);)
1137 for (
i=1;
i<=
m2;
i++) l3[
i]= 1;
1142 for (
k=1;
k <= (
n+1);
k++ )
1166 for ( ip= m12; ip <=
m; ip++ )
1168 if (
iposv[ip] == (ip+
n) )
1179 for (
i=
m1+1;
i <= m12;
i++ )
1180 if ( l3[
i-
m1] == 1 )
1181 for (
k=1;
k <=
n+1;
k++ )
1204 for (
k= 1;
k <= nl1;
k++ )
1205 if ( l1[
k] == kp )
break;
1207 for ( is=
k; is <= nl1; is++ ) l1[is]= l1[is+1];
1208 ++(
LiPM[
m+2][kp+1]);
1219 ++(
LiPM[
m+2][kp+1]);
1220 for (
i=1;
i<=
m+2;
i++ )
1278 *bmax=a[mm+1][*kp+1];
1279 for (
k=2;
k<=nll;
k++)
1283 test=a[mm+1][ll[
k]+1]-(*bmax);
1286 *bmax=a[mm+1][ll[
k]+1];
1292 test=fabs(a[mm+1][ll[
k]+1])-fabs(*bmax);
1295 *bmax=a[mm+1][ll[
k]+1];
1308 for (
i=1;
i <= nl2;
i++ )
1312 *q1= -a[l2[
i]+1][1] / a[l2[
i]+1][kp+1];
1314 for (
i=
i+1;
i <= nl2;
i++ )
1319 q= -a[ii+1][1] / a[ii+1][kp+1];
1327 for (
k=1;
k<= nn;
k++ )
1329 qp= -a[*ip+1][
k+1]/a[*ip+1][kp+1];
1330 q0= -a[ii+1][
k+1]/a[ii+1][kp+1];
1331 if ( q0 != qp )
break;
1333 if ( q0 < qp ) *ip= ii;
1346 piv= 1.0 / a[ip+1][kp+1];
1347 for ( ii=1; ii <= i1+1; ii++ )
1352 for ( kk=1; kk <= k1+1; kk++ )
1354 a[ii][kk] -= a[ip+1][kk] * a[ii][kp+1];
1357 for ( kk=1; kk<= k1+1; kk++ )
1358 if ( kk-1 != kp ) a[ip+1][kk] *= -piv;
Rational pow(const Rational &a, int e)
Rational abs(const Rational &a)
void mu(int **points, int sizePoints)
gmp_complex numbers based on
const mpf_t * mpfp() const
rootArranger(rootContainer **_roots, rootContainer **_mu, const int _howclean=PM_CORRUPT)
complex root finder for univariate polynomials based on laguers algorithm
void sortre(gmp_complex **r, int l, int u, int inc)
bool laguer_driver(gmp_complex **a, gmp_complex **roots, bool polish=true)
Given the degree tdg and the tdg+1 complex coefficients ad0..tdg of the polynomial this routine succe...
void computegx(gmp_complex **a, gmp_complex x, int m, gmp_complex &f0, gmp_complex &f1, gmp_complex &f2, gmp_float &ex, gmp_float &ef)
void fillContainer(number *_coeffs, number *_ievpoint, const int _var, const int _tdg, const rootType _rt, const int _anz)
void laguer(gmp_complex **a, int m, gmp_complex *x, int *its, bool type)
Given the degree m and the m+1 complex coefficients a[0..m] of the polynomial, and given the complex ...
void divlin(gmp_complex **a, gmp_complex x, int j)
void sortroots(gmp_complex **roots, int r, int c, bool isf)
void divquad(gmp_complex **a, gmp_complex x, int j)
bool swapRoots(const int from, const int to)
void computefx(gmp_complex **a, gmp_complex x, int m, gmp_complex &f0, gmp_complex &f1, gmp_complex &f2, gmp_float &ex, gmp_float &ef)
void solvequad(gmp_complex **a, gmp_complex **r, int &k, int &j)
gmp_complex & evPointCoord(const int i)
bool isfloat(gmp_complex **a)
void checkimag(gmp_complex *x, gmp_float &e)
bool solver(const int polishmode=PM_NONE)
BOOLEAN mapFromMatrix(matrix m)
simplex(int rows, int cols)
#rows should be >= m+2, #cols >= n+1
void simp2(mprfloat **a, int n, int l2[], int nl2, int *ip, int kp, mprfloat *q1)
void simp3(mprfloat **a, int i1, int k1, int ip, int kp)
void simp1(mprfloat **a, int mm, int ll[], int nll, int iabf, int *kp, mprfloat *bmax)
matrix mapToMatrix(matrix m)
poly numvec2poly(const number *q)
vandermonde(const long _cn, const long _n, const long _maxdeg, number *_p, const bool _homog=true)
number * interpolateDense(const number *q)
Solves the Vandermode linear system \sum_{i=1}^{n} x_i^k-1 w_i = q_k, k=1,..,n.
const CanonicalForm int s
const CanonicalForm int const CFList const Variable & y
bool isZero(const CFArray &A)
checks if entries of A are zero
void WerrorS(const char *s)
#define IMATELEM(M, I, J)
#define MATELEM(mat, i, j)
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy
gmp_float sin(const gmp_float &a)
gmp_float sqrt(const gmp_float &a)
gmp_float exp(const gmp_float &a)
gmp_float cos(const gmp_float &a)
char * complexToStr(gmp_complex &c, const unsigned int oprec, const coeffs src)
gmp_complex numberToComplex(number num, const coeffs r)
#define mprSTICKYPROT(msg)
The main handler for Singular numbers which are suitable for Singular polynomials.
#define nPower(a, b, res)
#define omFreeSize(addr, size)
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Compatiblity layer for legacy polynomial operations (over currRing)
#define pSortAdd(p)
sorts p, p may have equal monomials
#define pSetCoeff(p, n)
deletes old coeff before setting the new one