package ec.app.regression.testcases;

/**
 * Quintic or Koza-2 test case factory.
 *
 * @author Tomasz Pawlak
 */
public class Koza02Factory extends FunctionFactory {

    @Override
    protected int arity() {
        return 1;
    }

    @Override
    protected double function(final Double... x) {
        // x * x * x * x * x - 2.0 * x * x * x + x
        assert Math.abs((x[0] * x[0] * x[0] * x[0] * x[0] - 2.0 * x[0] * x[0] * x[0] + x[0]) - (x[0] * (x[0] * x[0] * (x[0] * x[0] - 2.0) + 1))) < 1E-10;
        return x[0] * (x[0] * x[0] * (x[0] * x[0] - 2.0) + 1);
    }

    @Override
    public String getSymbolicRepresentation() {
        return "x0 * (x0 * x0 * (x0 * x0 - 2.0) + 1)";
    }
}
