MathUtil { public static double[] powerSumsToChebyMoments( double min, double max, double[] powerSums ) { int k = powerSums.length - 1; double r = (max - min) / 2; double xc = (max + min) / 2; double[] scaledPowerSums = MathUtil.shiftPowerSum( powerSums,r,xc ); double count = powerSums[0]; int[][] cCoeffs = MathUtil.getChebyCoefficients(k); double[] scaledChebyMoments = new double[k+1]; for (int i = 0; i <=k; i++) { double sum = 0.0; for (int j = 0; j <= i; j++) { sum += cCoeffs[i][j]*scaledPowerSums[j]; } scaledChebyMoments[i] = sum / count; } return scaledChebyMoments; }  static long[][] getBinomials(int m); static int[][] getChebyCoefficients(int k); static double[] shiftPowerSum(
            double[] powerSums,
            double r,
            double xc
    ); static double[] powerSumsToZerodMoments(
            double[] powerSums,
            double min,
            double max
    ); static double[] powerSumsToChebyMoments(
            double min,
            double max,
            double[] powerSums
    ); static double arrayMean(double[] xs); static void calcPowers(double x, double[] powers); static double entropy(double[] ps); static double getMSE(double[] error);  }
@Test public void testConvertMoments() { double[] uniformPowerSums = {1001,500500,333833500,250500250000L}; double[] convertedChebyshevMoments = MathUtil.powerSumsToChebyMoments(0, 1000, uniformPowerSums); double[] expectedChebyshevMoments = {1.0, 0, -.332, 0}; assertArrayEquals(expectedChebyshevMoments, convertedChebyshevMoments, 1e-14); }