50 number *_p,
const bool _homog )
51 :
n(_n), cn(_cn), maxdeg(_maxdeg),
p(_p), homog(_homog)
56 for ( j= 0; j <
cn; j++ )
x[j]=
nInit(1);
77 for ( j= 0; j <
n; j++ ) exp[j]=0;
79 for ( i= 0; i <
l; i++ )
83 for ( j= 0; j <
n; j++ )
94 for ( j= 0; j < n - 1; j++ )
119 for ( j= 0; j <
n+1; j++ ) exp[j]=0;
121 for ( i= 0; i <
l; i++ )
142 for ( j= 1; j <
n; j++ )
154 omFreeSize( (
void *) exp, (n+1) *
sizeof(
int) );
170 w= (number *)
omAlloc(
cn *
sizeof(number) );
171 c= (number *)
omAlloc(
cn *
sizeof(number) );
172 for ( j= 0; j <
cn; j++ )
189 for ( i= 1; i <
cn; i++ ) {
194 for ( j= (cn-i-1); j <= (cn-2); j++) {
196 tmp1=
nMult( xx, c[j+1] );
197 newnum=
nAdd( c[j], tmp1 );
202 newnum=
nAdd( xx, c[cn-1] );
207 for ( i= 0; i <
cn; i++ ) {
218 for ( k= cn-1; k >= 1; k-- ) {
220 tmp1=
nMult( xx, b );
222 b=
nAdd( c[k], tmp1 );
225 tmp1=
nMult( q[k-1], b );
226 newnum=
nAdd( s, tmp1 );
231 tmp1=
nMult( xx, t );
232 newnum=
nAdd( tmp1, b );
250 for ( j= 0; j <
cn; j++ )
nDelete( c+j );
251 omFreeSize( (
void *)c, cn *
sizeof( number ) );
271 #define MR 8 // never change this value
274 #define MAXIT (5*MMOD) // max number of iterations in laguer root finder
314 const int _var,
const int _tdg,
315 const rootType _rt,
const int _anz )
325 for ( i=0; i <=
tdg; i++ )
356 for ( i=
tdg; i >= 0; i-- )
403 if (! ((i >= 0) && (i <
anz+2) ) )
404 WarnS(
"rootContainer::evPointCoord: index out of range");
406 WarnS(
"rootContainer::evPointCoord: ievpoint == NULL");
418 Warn(
"rootContainer::evPointCoord: NULL index %d",i);
423 Warn(
"rootContainer::evPointCoord: Wrong index %d, found_roots %s",i,
found_roots?
"true":
"false");
432 if (
found_roots && ( from >= 0) && ( from <
tdg ) && ( to >= 0) && ( to <
tdg ) )
444 Warn(
" rootContainer::changeRoots: Wrong index %d, %d",from,to);
460 for ( i=0; i <=
tdg; i++ )
469 WarnS(
"rootContainer::solver: No roots found!");
472 for ( i=0; i <=
tdg; i++ )
delete ad[i];
485 bool ret=
true, isf=
isfloat(a), type=
true;
508 WarnS(
"Laguerre solver: Too many iterations!");
517 WarnS(
"Laguerre solver: Too many iterations in polish!");
522 if ((!type)&&(!((
x.real()==zero)&&(
x.imag()==zero))))
x = o/
x;
523 if (
x.imag() == zero)
555 for ( i=0; i <=
tdg; i++ )
delete ad[i];
568 gmp_complex dx, x1,
b, d,
f,
g,
h, sq,
gp, gm, g2;
569 gmp_float frac_g[
MR+1] = { 0.0, 0.5, 0.25, 0.75, 0.125, 0.375, 0.625, 0.875, 1.0 };
574 for ( iter= 1; iter <=
MAXIT; iter++ )
587 if ((fabs==zero) || (
abs(d)==zero))
return;
594 h= g2 - (((f+
f) / b ));
595 sq=
sqrt(( ( h * deg ) - g2 ) * (deg - one));
604 if((gp.
real()==zero)&&(gp.
imag()==zero))
617 if (*x == x1)
goto ende;
621 if ( j %
MT ) *x= x1;
622 else *x -= ( dx * frac_g[ j /
MT ] );
642 for (
int i=
tdg;
i >= 0;
i-- )
658 for (i= j-1; i > 0; i-- )
659 *a[i] += (*a[i+1]*x);
660 for (i= 0; i <
j; i++ )
666 for (i= 1; i <
j; i++)
667 *a[i] += (*a[i-1]*y);
679 *a[j-1] += (*a[
j]*
p);
680 for (i= j-2; i > 1; i-- )
681 *a[i] += ((*a[i+1]*p)-(*a[i+2]*q));
682 for (i= 0; i < j-1; i++ )
690 for (i= 2; i < j-1; i++)
691 *a[i] += ((*a[i-1]*p)-(*a[i-2]*q));
700 &&((!(*a[2]).real().
isZero())||(!(*a[2]).imag().
isZero())))
703 gmp_complex h1(*a[1]/(*a[2] + *a[2])), h2(*a[0] / *a[2]);
707 if (disk.
real()<zero)
733 if (((*a[1]).real().
isZero()) && ((*a[1]).imag().isZero()))
735 WerrorS(
"precision lost, try again with higher precision");
757 for (j=c; j+2<
tdg; j+=2)
762 for (j=c; j+1<
tdg; j++)
774 for (i=l+inc; i<=u; i+=inc)
776 if (r[i]->real()<x->
real())
786 for (i=pos; i>
l; i--)
793 for (i=pos+1; i+1>
l; i--)
807 else if ((inc==2)&&(x->
imag()<r[l+1]->
imag()))
826 for ( k= m-1; k >= 0; k-- )
828 f2 = ( x * f2 ) + f1;
829 f1 = ( x * f1 ) + f0;
830 f0 = ( x * f0 ) + *a[k];
831 ef =
abs( f0 ) + ( ex * ef );
847 for ( k= 1; k <=
m; k++ )
849 f2 = ( x * f2 ) + f1;
850 f1 = ( x * f1 ) + f0;
851 f0 = ( x * f0 ) + *a[k];
852 ef =
abs( f0 ) + ( ex * ef );
863 const int _howclean )
864 : roots(_roots),
mu(_mu), howclean(_howclean)
878 for ( i= 0; i <
rc; i++ )
886 for ( i= 0; i <
mc; i++ )
901 int xkoord,
r, rtest, xk, mtest;
905 for ( xkoord= 0; xkoord < anzm; xkoord++ ) {
907 for ( r= 0; r < anzr; r++ ) {
911 for ( xk =0; xk <= xkoord; xk++ )
913 tmp -= (*
roots[xk])[r] *
mu[xkoord]->evPointCoord(xk+1);
917 for ( rtest= r; rtest < anzr; rtest++ ) {
918 zwerg = tmp - (*
roots[xk])[rtest] *
mu[xkoord]->evPointCoord(xk+1);
919 for ( mtest= 0; mtest < anzr; mtest++ )
923 if ( ((zwerg.
real() <= (*
mu[xkoord])[mtest].real() + mprec) &&
924 (zwerg.
real() >= (*
mu[xkoord])[mtest].real() - mprec)) &&
925 ((zwerg.
imag() <= (*
mu[xkoord])[mtest].imag() + mprec) &&
926 (zwerg.
imag() >= (*
mu[xkoord])[mtest].imag() - mprec)) )
936 WarnS(
"rootArranger::arrange: precision lost");
943 Warn(
"rootArranger::arrange: No match? coord %d, root %d.",xkoord,r);
945 WarnS(
"One of these ...");
946 for ( rtest= r; rtest < anzr; rtest++ )
949 for ( xk =0; xk <= xkoord; xk++ )
951 tmp-= (*
roots[xk])[r] *
mu[xkoord]->evPointCoord(xk+1);
953 tmp-= (*
roots[xk])[rtest] *
mu[xkoord]->evPointCoord(xk+1);
956 WarnS(
" ... must match to one of these:");
957 for ( mtest= 0; mtest < anzr; mtest++ )
981 #define MAXPOINTS 1000
986 : LiPM_cols(cols), LiPM_rows(rows)
1033 for ( i= 1; i <=
MATROWS( mm ); i++ )
1035 for ( j= 1; j <=
MATCOLS( mm ); j++ )
1065 for ( i= 1; i <=
MATROWS( mm ); i++ )
1067 for ( j= 1; j <=
MATCOLS( mm ); j++ )
1072 if (
LiPM[i][j] != 0.0 )
1090 for ( i= 1; i <=
m; i++ )
1101 for ( i= 1; i <=
n; i++ )
1110 int i,ip,ir,is,
k,kh,kp,m12,nl1,nl2;
1117 error(
WarnS(
"simplex::compute: Bad input constraint counts!");)
1122 l1= (
int *)
omAlloc0( (
n+1) *
sizeof(int) );
1123 l2= (
int *)
omAlloc0( (
m+1) *
sizeof(int) );
1124 l3= (
int *)
omAlloc0( (
m+1) *
sizeof(int) );
1127 for ( k=1; k<=
n; k++ ) l1[k]=
izrov[k]=k;
1129 for ( i=1; i<=
m; i++ )
1131 if (
LiPM[i+1][1] < 0.0 )
1134 error(
WarnS(
"simplex::compute: Bad input tableau!");)
1135 error(
Warn(
"simplex::compute: in input Matrix row %d, column 1, value %f",i+1,
LiPM[i+1][1]);)
1146 for ( i=1; i<=
m2; i++) l3[i]= 1;
1151 for ( k=1; k <= (
n+1); k++ )
1154 for ( i=
m1+1; i <=
m; i++ ) q1+=
LiPM[i+1][k];
1175 for ( ip= m12; ip <=
m; ip++ )
1177 if (
iposv[ip] == (ip+
n) )
1188 for ( i=
m1+1; i <= m12; i++ )
1189 if ( l3[i-
m1] == 1 )
1190 for ( k=1; k <=
n+1; k++ )
1213 for ( k= 1; k <= nl1; k++ )
1214 if ( l1[k] == kp )
break;
1216 for ( is=k; is <= nl1; is++ ) l1[is]= l1[is+1];
1217 ++(
LiPM[
m+2][kp+1]);
1218 for ( i= 1; i <=
m+2; i++ )
LiPM[i][kp+1] = -(
LiPM[i][kp+1]);
1228 ++(
LiPM[
m+2][kp+1]);
1229 for ( i=1; i<=
m+2; i++ )
1287 *bmax=a[mm+1][*kp+1];
1288 for (k=2;k<=nll;k++)
1292 test=a[mm+1][ll[
k]+1]-(*bmax);
1295 *bmax=a[mm+1][ll[
k]+1];
1301 test=fabs(a[mm+1][ll[k]+1])-fabs(*bmax);
1304 *bmax=a[mm+1][ll[
k]+1];
1317 for ( i=1; i <= nl2; i++ )
1321 *q1= -a[l2[
i]+1][1] / a[l2[
i]+1][kp+1];
1323 for ( i= i+1; i <= nl2; i++ )
1328 q= -a[ii+1][1] / a[ii+1][kp+1];
1336 for ( k=1; k<= nn; k++ )
1338 qp= -a[*ip+1][k+1]/a[*ip+1][kp+1];
1339 q0= -a[ii+1][k+1]/a[ii+1][kp+1];
1340 if ( q0 != qp )
break;
1342 if ( q0 < qp ) *ip= ii;
1355 piv= 1.0 / a[ip+1][kp+1];
1356 for ( ii=1; ii <= i1+1; ii++ )
1361 for ( kk=1; kk <= k1+1; kk++ )
1363 a[ii][kk] -= a[ip+1][kk] * a[ii][kp+1];
1366 for ( kk=1; kk<= k1+1; kk++ )
1367 if ( kk-1 != kp ) a[ip+1][kk] *= -piv;
#define mprSTICKYPROT(msg)
const mpf_t * mpfp() const
complex root finder for univariate polynomials based on laguers algorithm
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)
const CanonicalForm int s
const CanonicalForm int const CFList const Variable & y
number * interpolateDense(const number *q)
Solves the Vandermode linear system {i=1}^{n} x_i^k-1 w_i = q_k, k=1,..,n.
matrix mapToMatrix(matrix m)
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)
bool swapRoots(const int from, const int to)
void sortre(gmp_complex **r, int l, int u, int inc)
void mu(int **points, int sizePoints)
Compatiblity layer for legacy polynomial operations (over currRing)
#define nPower(a, b, res)
#define omFreeSize(addr, size)
const CanonicalForm CFMap CFMap int &both_non_zero int n
void checkimag(gmp_complex *x, gmp_float &e)
bool isfloat(gmp_complex **a)
bool solver(const int polishmode=PM_NONE)
void WerrorS(const char *s)
gmp_complex numbers based on
simplex(int rows, int cols)
#rows should be >= m+2, #cols >= n+1
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy ...
poly numvec2poly(const number *q)
gmp_complex & evPointCoord(const int i)
Rational abs(const Rational &a)
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
BOOLEAN mapFromMatrix(matrix m)
gmp_complex numberToComplex(number num, const coeffs r)
The main handler for Singular numbers which are suitable for Singular polynomials.
void divquad(gmp_complex **a, gmp_complex x, int j)
void sortroots(gmp_complex **roots, int r, int c, bool isf)
gmp_float sqrt(const gmp_float &a)
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 fillContainer(number *_coeffs, number *_ievpoint, const int _var, const int _tdg, const rootType _rt, const int _anz)
void simp2(mprfloat **a, int n, int l2[], int nl2, int *ip, int kp, mprfloat *q1)
gmp_float cos(const gmp_float &a)
#define pSortAdd(p)
sorts p, p may have equal monomials
rootArranger(rootContainer **_roots, rootContainer **_mu, const int _howclean=PM_CORRUPT)
void solvequad(gmp_complex **a, gmp_complex **r, int &k, int &j)
bool isZero(const CFArray &A)
checks if entries of A are zero
char * complexToStr(gmp_complex &c, const unsigned int oprec, const coeffs src)
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 simp1(mprfloat **a, int mm, int ll[], int nll, int iabf, int *kp, mprfloat *bmax)
Rational pow(const Rational &a, int e)
#define IMATELEM(M, I, J)
gmp_float sin(const gmp_float &a)
#define pSetCoeff(p, n)
deletes old coeff before setting the new one
void simp3(mprfloat **a, int i1, int k1, int ip, int kp)
void divlin(gmp_complex **a, gmp_complex x, int j)
#define MATELEM(mat, i, j)
vandermonde(const long _cn, const long _n, const long _maxdeg, number *_p, const bool _homog=true)