//package com.polytechnik.utils;
/*
* (C) Vladislav Malyshkin 2010
* This file is under GPL version 3.
*
*/
/** Polynomial root.
* @version $Id: PolynomialRoot.java,v 1.105 2012/08/18 00:00:05 mal Exp $
* @author Vladislav Malyshkin mal@gromco.com
*/
/**
* @test
* @bug 8005956
* @summary C2: assert(!def_outside->member(r)) failed: Use of external LRG overlaps the same LRG defined in this block
*
* @run main PolynomialRoot
*/
public class PolynomialRoot {
public static int findPolynomialRoots(final int n,
final double [] p,
final double [] re_root,
final double [] im_root)
{
if(n==4)
{
}
else if(n==3)
{
}
else if(n==2)
{
}
else if(n==1)
{
}
else
{
}
}
private static final boolean PRINT_DEBUG=false;
{
final double vs=p[4];
{
return -1;
}
/* zsolve_quartic.c - finds the complex roots of
* x^4 + a x^3 + b x^2 + c x + d = 0
*/
final int mt;
/* Deal easily with the cases where the quartic is degenerate. The
* ordering of solutions is done explicitly. */
if (0 == b && 0 == c)
{
if (0 == d)
{
re_root[0]=-a;
return 4;
}
else if (0 == a)
{
if (d > 0)
{
}
else
{
}
return 4;
}
}
if (0.0 == c && 0.0 == d)
{
return 4;
}
final double [] u=new double[3];
/* For non-degenerate solutions, proceed by constructing and
* solving the resolvent cubic */
final double aa = a * a;
if(PRINT_DEBUG) System.err.println("aa="+aa+" pp="+pp+" qq="+qq+" rr="+rr+" rc="+rc+" sc="+sc+" tc="+tc);
final boolean flag_realroots;
/* This code solves the resolvent cubic in a convenient fashion
* for this implementation of the quartic. If there are three real
* roots, then they are placed directly into u[]. If two are
* complex, then the real root is put into u[0] and the real
* and imaginary part of the complex roots are placed into
* u[1] and u[2], respectively. */
{
final double Q = qcub / 9;
final double R = rcub / 54;
final double Q3 = Q * Q * Q;
final double R2 = R * R;
if (0 == R && 0 == Q)
{
flag_realroots=true;
u[0] = -rc3;
u[1] = -rc3;
u[2] = -rc3;
}
{
flag_realroots=true;
if (R > 0)
{
}
else
{
}
}
{
flag_realroots=true;
}
else
{
flag_realroots=false;
final double B = Q / A;
u[0] = A + B - rc3;
}
if(PRINT_DEBUG) System.err.println("u[0]="+u[0]+" u[1]="+u[1]+" u[2]="+u[2]+" qq="+qq+" disc="+((CR2 - CQ3) / 2125764.0));
}
/* End of solution to resolvent cubic */
/* Combine the square roots of the roots of the cubic
* resolvent appropriately. Also, calculate 'mt' which
* designates the nature of the roots:
* mt=1 : 4 real roots
* mt=2 : 0 real roots
* mt=3 : 2 real roots
*/
if (flag_realroots)
{
mod_w1w2=-1;
mt = 2;
int jmin=0;
for(int j=1;j<3;j++)
{
{
jmin=j;
}
}
if(u1>=0)
{
w1_im=0;
}
else
{
w1_re=0;
}
if(u2>=0)
{
w2_im=0;
}
else
{
w2_re=0;
}
}
else
{
mt = 3;
if(w_mod2_sq<=0)
{
}
else
{
// calculate square root of a complex number (u[1],u[2])
// the result is in the (w1_re,w1_im)
{
}
else
{
}
if(u[1]>=0)
{
w1_re=w;
}
else
{
}
}
{
}
else
{
mod_w1w2=-1;
if(u[0]>=0)
{
w2_im=0;
}
else
{
w2_re=0;
}
}
if(PRINT_DEBUG) System.err.println("u[0]="+u[0]+"u[1]="+u[1]+" u[2]="+u[2]+" absu0="+absu0+" w_mod="+w_mod+" w_mod2="+w_mod2);
}
/* Solve the quadratic in order to obtain the roots
* to the quartic */
if(mod_w1w2>0)
{
// a shorcut to reduce rounding error
w3_im=0;
}
else if(mod_w1w2_squared>0)
{
// regular path
}
else
{
// typically occur when qq==0
}
final double h = r4 * a;
if(PRINT_DEBUG) System.err.println("w1_re="+w1_re+" w1_im="+w1_im+" w2_re="+w2_re+" w2_im="+w2_im+" w3_re="+w3_re+" w3_im="+w3_im+" h="+h);
return 4;
}
{
if(r.nextDouble()<0.1)
{
// integer coefficiens
for(int j=0;j<p.length;j++)
{
if(j<=n)
{
}
else
{
p[j]=0;
}
}
}
else
{
// real coefficiens
for(int j=0;j<p.length;j++)
{
if(j<=n)
{
}
else
{
p[j]=0;
}
}
}
{
}
}
static void checkValues(final double [] p,
final int n,
final double rex,
final double imx,
final double eps,
{
for(int k=n;k>=0;k--)
{
}
:
{
throw new RuntimeException(
getPolinomTXT(p)+"\n"+
" sabs="+sabs+
" "+txt);
}
}
{
for(int k=0;k<p.length;k++)
{
}
}
{
for(int k=0;k<nr;k++)
{
}
}
static void testRoots(final int n,
final int n_tests,
final double eps)
{
final double [] p=new double [n+1];
for(int i=0;i<n_tests;i++)
{
{
{
setRandomP(p,n,rn);
for(int j=0;j<=dg;j++)
{
p[j]=0;
}
if(dr==0)
{
}
else if(dr==1)
{
p[0]=p[1]=0;
}
for(int j=0;j<n;j++)
{
//System.err.println("j="+j);
}
}
}
}
}
{
{
return -1;
}
return 1;
}
{
{
return -1;
}
if(d>=0)
{
if(b2<0)
{
}
else if(b2>0)
{
}
else
{
}
}
else
{
}
return 2;
}
{
final double vs=p[3];
{
return -1;
}
/* zsolve_cubic.c - finds the complex roots of x^3 + a x^2 + b x + c = 0
*/
final double q = (a * a - 3 * b);
final double r = (a*(2 * a * a - 9 * b) + 27 * c);
final double Q = q / 9;
final double R = r / 54;
final double Q3 = Q * Q * Q;
final double R2 = R * R;
final double CR2 = 729 * r * r;
final double CQ3 = 2916 * q * q * q;
final double a3=a/3;
if (R == 0 && Q == 0)
{
return 3;
}
{
/* this test is actually R2 == Q3, written in a form suitable
for exact computation with integers */
/* Due to finite precision some double roots may be missed, and
will be considered to be a pair of complex roots z = x +/-
epsilon i close to the real axis. */
if (R > 0)
{
}
else
{
}
return 3;
}
{
return 3;
}
else
{
final double B = Q / A;
return 3;
}
}
{
{
final double v=p[3],
a=p[2]/v,b=p[1]/v,c=p[0]/v,
if(Q<0)
{
// three real roots
//System.err.println("3r");
}
else
{
// one real & two complex roots
// real root
// complex roots
//System.err.println("1r2c");
}
}
else
{
}
}
static void printSpecialValues()
{
{
//final double [] p=new double []{8,1,3,3.6,1};
final double [] p;
final int n;
if(st<=3)
{
if(st<=0)
{
p=new double []{2,-4,6,-4,1};
//p=new double []{-6,6,-6,8,-2};
}
else if(st==1)
{
p=new double []{0,-4,8,3,-9};
}
else if(st==2)
{
p=new double []{-1,0,2,0,-1};
}
else
{
p=new double []{-5,2,8,-2,-3};
}
n=4;
}
else
{
p=new double []{0,2,0,1};
if(st==4)
{
p[1]=-p[1];
}
n=3;
}
for(int i=0;i<=n;i++)
{
if(i<n)
{
p[i]+"\t"+
re_root[i]+"\t"+
im_root[i]);
}
else
{
}
}
}
}
{
final double eps=1e-6;
//checkRoots();
final int n_tests=10000000;
//testRoots(2,n_tests,r,eps);
//testRoots(3,n_tests,r,eps);
System.err.println("PolynomialRoot.main: "+n_tests+" tests OK done in "+(t1-t0)+" milliseconds. ver=$Id: PolynomialRoot.java,v 1.105 2012/08/18 00:00:05 mal Exp $");
}
}