package Current.popups.Polynomial; import Current.*; import Current.basic.*; import java.applet.Applet; import java.awt.event.*; import java.awt.*; import java.math.*; public class PrecisionFunction { /**These routines are high precision versions of the routines in the Function class, which compute the defining functions for pairs of vertices and words. These routines use the high precision trig package to evaluate sines and cosines when necessary*/ public PrecisionFunction() {} public static BigDecimal power(BigDecimal X,int k) { BigDecimal Y=new BigDecimal(1); for(int i=1;i<=k;++i) Y=Y.multiply(X); return(Y); } /**These routines precompute the list of sines and cosines which arise in our high precision computations*/ public static BigDecimal[] cosPhaseList(int[][] g,BigComplex zz,int fudge) { BigDecimal[] PHASE=new BigDecimal[g[0][0]+1]; for(int i=1;i<=g[0][0];++i) { BigDecimal c2=new BigDecimal(g[1-fudge][i]); BigDecimal c3=new BigDecimal(g[2-fudge][i]); BigDecimal ph1=zz.x.multiply(c2); BigDecimal ph2=zz.y.multiply(c3); BigDecimal phase=ph1.add(ph2); PHASE[i]=PrecisionTrig.mcbCos(phase); } return(PHASE); } public static BigDecimal[] sinPhaseList(int[][] g,BigComplex zz,int fudge) { BigDecimal[] PHASE=new BigDecimal[g[0][0]+1]; for(int i=1;i<=g[0][0];++i) { BigDecimal c2=new BigDecimal(g[1-fudge][i]); BigDecimal c3=new BigDecimal(g[2-fudge][i]); BigDecimal ph1=zz.x.multiply(c2); BigDecimal ph2=zz.y.multiply(c3); BigDecimal phase=ph1.add(ph2); PHASE[i]=PrecisionTrig.mcbSin(phase); } return(PHASE); } public static BigComplex derivative(int[][] g,int a,int b,BigComplex zz) { BigComplex total=new BigComplex(); BigDecimal X=zz.x; BigDecimal Y=zz.y; int cong=(a+b)%4; for(int i=1;i<=g[0][0];++i) { BigDecimal c1=new BigDecimal(g[3][i]); BigDecimal c2=new BigDecimal(g[1][i]); BigDecimal c3=new BigDecimal(g[2][i]); BigDecimal c4=power(c2,a); BigDecimal c5=power(c3,b); BigDecimal coeff=c1.multiply(c4.multiply(c5)); BigDecimal ph1=X.multiply(c2); BigDecimal ph2=Y.multiply(c3); BigDecimal phase=ph1.add(ph2); BigDecimal C=PrecisionTrig.mcbCos(phase); BigDecimal S=PrecisionTrig.mcbSin(phase); C=C.multiply(coeff); S=S.multiply(coeff); if(cong==0) { total.x=total.x.add(C); total.y=total.y.add(S); } if(cong==1) { total.x=total.x.subtract(S); total.y=total.y.add(C); } if(cong==2) { total.x=total.x.subtract(C); total.y=total.y.subtract(S); } if(cong==3) { total.x=total.x.add(S); total.y=total.y.subtract(C); } } return(total); } public static BigDecimal foilDerivative(int[][] g,int a,int b,BigComplex zz) { BigDecimal total=new BigDecimal(0); BigDecimal X=zz.x; BigDecimal Y=zz.y; int cong=(a+b)%4; for(int i=1;i<=g[0][0];++i) { BigDecimal c1=new BigDecimal(g[2][i]); BigDecimal c2=new BigDecimal(g[0][i]); BigDecimal c3=new BigDecimal(g[1][i]); BigDecimal c4=power(c2,a); BigDecimal c5=power(c3,b); BigDecimal coeff=c1.multiply(c4.multiply(c5)); BigDecimal ph1=X.multiply(c2); BigDecimal ph2=Y.multiply(c3); BigDecimal phase=ph1.add(ph2); BigDecimal C=PrecisionTrig.mcbCos(phase); BigDecimal S=PrecisionTrig.mcbSin(phase); C=C.multiply(coeff); S=S.multiply(coeff); if(cong==0) { total=total.add(S); } if(cong==1) { total=total.add(C); } if(cong==2) { total=total.subtract(S); } if(cong==3) { total=total.subtract(C); } } return(total); } /**these routines use precomputed sines and cosines. For our purposes this turns out to be a much faster way to do things.*/ public static BigComplex derivative(PrecisionTrigData DATA,int[][] g,int a,int b,BigComplex zz) { BigComplex total=new BigComplex(); BigDecimal X=zz.x; BigDecimal Y=zz.y; int cong=(a+b)%4; for(int i=1;i<=g[0][0];++i) { BigDecimal c1=new BigDecimal(g[3][i]); BigDecimal c2=new BigDecimal(g[1][i]); BigDecimal c3=new BigDecimal(g[2][i]); BigDecimal c4=power(c2,a); BigDecimal c5=power(c3,b); BigDecimal coeff=c1.multiply(c4.multiply(c5)); BigDecimal C=DATA.A[0][g[1][i]-DATA.offsetX][g[2][i]-DATA.offsetY]; BigDecimal S=DATA.A[1][g[1][i]-DATA.offsetX][g[2][i]-DATA.offsetY]; C=C.multiply(coeff); S=S.multiply(coeff); if(cong==0) { total.x=total.x.add(C); total.y=total.y.add(S); } if(cong==1) { total.x=total.x.subtract(S); total.y=total.y.add(C); } if(cong==2) { total.x=total.x.subtract(C); total.y=total.y.subtract(S); } if(cong==3) { total.x=total.x.add(S); total.y=total.y.subtract(C); } } return(total); } public static BigDecimal foilDerivative(PrecisionTrigData DATA,int[][] g,int a,int b,BigComplex zz) { BigDecimal total=new BigDecimal(0); BigDecimal X=zz.x; BigDecimal Y=zz.y; int cong=(a+b)%4; for(int i=1;i<=g[0][0];++i) { BigDecimal c1=new BigDecimal(g[2][i]); BigDecimal c2=new BigDecimal(g[0][i]); BigDecimal c3=new BigDecimal(g[1][i]); BigDecimal c4=power(c2,a); BigDecimal c5=power(c3,b); BigDecimal coeff=c1.multiply(c4.multiply(c5)); BigDecimal C=DATA.A[0][g[0][i]-DATA.offsetX][g[1][i]-DATA.offsetY]; BigDecimal S=DATA.A[1][g[0][i]-DATA.offsetX][g[1][i]-DATA.offsetY]; C=C.multiply(coeff); S=S.multiply(coeff); if(cong==0) { total=total.add(S); } if(cong==1) { total=total.add(C); } if(cong==2) { total=total.subtract(S); } if(cong==3) { total=total.subtract(C); } } return(total); } }