Data.Spline.Key:interpolateKeys from smoothie-0.4.0.2

Percentage Accurate: 99.8% → 99.8%
Time: 3.2s
Alternatives: 5
Speedup: 1.1×

Specification

?
\[\left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right) \]
(FPCore (x)
  :precision binary64
  :pre TRUE
  (* (* x x) (- 3.0 (* x 2.0))))
double code(double x) {
	return (x * x) * (3.0 - (x * 2.0));
}
real(8) function code(x)
use fmin_fmax_functions
    real(8), intent (in) :: x
    code = (x * x) * (3.0d0 - (x * 2.0d0))
end function
public static double code(double x) {
	return (x * x) * (3.0 - (x * 2.0));
}
def code(x):
	return (x * x) * (3.0 - (x * 2.0))
function code(x)
	return Float64(Float64(x * x) * Float64(3.0 - Float64(x * 2.0)))
end
function tmp = code(x)
	tmp = (x * x) * (3.0 - (x * 2.0));
end
code[x_] := N[(N[(x * x), $MachinePrecision] * N[(3.0 - N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
f(x):
	x in [-inf, +inf]
code: THEORY
BEGIN
f(x: real): real =
	(x * x) * ((3) - (x * (2)))
END code
\left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right)

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 5 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 99.8% accurate, 1.0× speedup?

\[\left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right) \]
(FPCore (x)
  :precision binary64
  :pre TRUE
  (* (* x x) (- 3.0 (* x 2.0))))
double code(double x) {
	return (x * x) * (3.0 - (x * 2.0));
}
real(8) function code(x)
use fmin_fmax_functions
    real(8), intent (in) :: x
    code = (x * x) * (3.0d0 - (x * 2.0d0))
end function
public static double code(double x) {
	return (x * x) * (3.0 - (x * 2.0));
}
def code(x):
	return (x * x) * (3.0 - (x * 2.0))
function code(x)
	return Float64(Float64(x * x) * Float64(3.0 - Float64(x * 2.0)))
end
function tmp = code(x)
	tmp = (x * x) * (3.0 - (x * 2.0));
end
code[x_] := N[(N[(x * x), $MachinePrecision] * N[(3.0 - N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
f(x):
	x in [-inf, +inf]
code: THEORY
BEGIN
f(x: real): real =
	(x * x) * ((3) - (x * (2)))
END code
\left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right)

Alternative 1: 99.8% accurate, 1.1× speedup?

\[x \cdot \left(\mathsf{fma}\left(-2, x, 3\right) \cdot x\right) \]
(FPCore (x)
  :precision binary64
  :pre TRUE
  (* x (* (fma -2.0 x 3.0) x)))
double code(double x) {
	return x * (fma(-2.0, x, 3.0) * x);
}
function code(x)
	return Float64(x * Float64(fma(-2.0, x, 3.0) * x))
end
code[x_] := N[(x * N[(N[(-2.0 * x + 3.0), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
f(x):
	x in [-inf, +inf]
code: THEORY
BEGIN
f(x: real): real =
	x * ((((-2) * x) + (3)) * x)
END code
x \cdot \left(\mathsf{fma}\left(-2, x, 3\right) \cdot x\right)
Derivation
  1. Initial program 99.8%

    \[\left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right) \]
  2. Step-by-step derivation
    1. Applied rewrites99.8%

      \[\leadsto x \cdot \left(\mathsf{fma}\left(-2, x, 3\right) \cdot x\right) \]
    2. Add Preprocessing

    Alternative 2: 97.7% accurate, 0.3× speedup?

    \[\begin{array}{l} t_0 := \left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right)\\ t_1 := \left(x \cdot x\right) \cdot \left(-2 \cdot x\right)\\ \mathbf{if}\;t\_0 \leq -400000000:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_0 \leq 4 \cdot 10^{-10}:\\ \;\;\;\;\frac{x}{\frac{1}{3 \cdot x}}\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \]
    (FPCore (x)
      :precision binary64
      :pre TRUE
      (let* ((t_0 (* (* x x) (- 3.0 (* x 2.0))))
           (t_1 (* (* x x) (* -2.0 x))))
      (if (<= t_0 -400000000.0)
        t_1
        (if (<= t_0 4e-10) (/ x (/ 1.0 (* 3.0 x))) t_1))))
    double code(double x) {
    	double t_0 = (x * x) * (3.0 - (x * 2.0));
    	double t_1 = (x * x) * (-2.0 * x);
    	double tmp;
    	if (t_0 <= -400000000.0) {
    		tmp = t_1;
    	} else if (t_0 <= 4e-10) {
    		tmp = x / (1.0 / (3.0 * x));
    	} else {
    		tmp = t_1;
    	}
    	return tmp;
    }
    
    real(8) function code(x)
    use fmin_fmax_functions
        real(8), intent (in) :: x
        real(8) :: t_0
        real(8) :: t_1
        real(8) :: tmp
        t_0 = (x * x) * (3.0d0 - (x * 2.0d0))
        t_1 = (x * x) * ((-2.0d0) * x)
        if (t_0 <= (-400000000.0d0)) then
            tmp = t_1
        else if (t_0 <= 4d-10) then
            tmp = x / (1.0d0 / (3.0d0 * x))
        else
            tmp = t_1
        end if
        code = tmp
    end function
    
    public static double code(double x) {
    	double t_0 = (x * x) * (3.0 - (x * 2.0));
    	double t_1 = (x * x) * (-2.0 * x);
    	double tmp;
    	if (t_0 <= -400000000.0) {
    		tmp = t_1;
    	} else if (t_0 <= 4e-10) {
    		tmp = x / (1.0 / (3.0 * x));
    	} else {
    		tmp = t_1;
    	}
    	return tmp;
    }
    
    def code(x):
    	t_0 = (x * x) * (3.0 - (x * 2.0))
    	t_1 = (x * x) * (-2.0 * x)
    	tmp = 0
    	if t_0 <= -400000000.0:
    		tmp = t_1
    	elif t_0 <= 4e-10:
    		tmp = x / (1.0 / (3.0 * x))
    	else:
    		tmp = t_1
    	return tmp
    
    function code(x)
    	t_0 = Float64(Float64(x * x) * Float64(3.0 - Float64(x * 2.0)))
    	t_1 = Float64(Float64(x * x) * Float64(-2.0 * x))
    	tmp = 0.0
    	if (t_0 <= -400000000.0)
    		tmp = t_1;
    	elseif (t_0 <= 4e-10)
    		tmp = Float64(x / Float64(1.0 / Float64(3.0 * x)));
    	else
    		tmp = t_1;
    	end
    	return tmp
    end
    
    function tmp_2 = code(x)
    	t_0 = (x * x) * (3.0 - (x * 2.0));
    	t_1 = (x * x) * (-2.0 * x);
    	tmp = 0.0;
    	if (t_0 <= -400000000.0)
    		tmp = t_1;
    	elseif (t_0 <= 4e-10)
    		tmp = x / (1.0 / (3.0 * x));
    	else
    		tmp = t_1;
    	end
    	tmp_2 = tmp;
    end
    
    code[x_] := Block[{t$95$0 = N[(N[(x * x), $MachinePrecision] * N[(3.0 - N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x * x), $MachinePrecision] * N[(-2.0 * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -400000000.0], t$95$1, If[LessEqual[t$95$0, 4e-10], N[(x / N[(1.0 / N[(3.0 * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
    
    f(x):
    	x in [-inf, +inf]
    code: THEORY
    BEGIN
    f(x: real): real =
    	LET t_0 = ((x * x) * ((3) - (x * (2)))) IN
    		LET t_1 = ((x * x) * ((-2) * x)) IN
    			LET tmp_1 = IF (t_0 <= (400000000000000014572878926199096631666218826239855843596160411834716796875e-84)) THEN (x / ((1) / ((3) * x))) ELSE t_1 ENDIF IN
    			LET tmp = IF (t_0 <= (-4e8)) THEN t_1 ELSE tmp_1 ENDIF IN
    	tmp
    END code
    \begin{array}{l}
    t_0 := \left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right)\\
    t_1 := \left(x \cdot x\right) \cdot \left(-2 \cdot x\right)\\
    \mathbf{if}\;t\_0 \leq -400000000:\\
    \;\;\;\;t\_1\\
    
    \mathbf{elif}\;t\_0 \leq 4 \cdot 10^{-10}:\\
    \;\;\;\;\frac{x}{\frac{1}{3 \cdot x}}\\
    
    \mathbf{else}:\\
    \;\;\;\;t\_1\\
    
    
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (*.f64 (*.f64 x x) (-.f64 #s(literal 3 binary64) (*.f64 x #s(literal 2 binary64)))) < -4e8 or 4.0000000000000001e-10 < (*.f64 (*.f64 x x) (-.f64 #s(literal 3 binary64) (*.f64 x #s(literal 2 binary64))))

      1. Initial program 99.8%

        \[\left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right) \]
      2. Taylor expanded in x around inf

        \[\leadsto \left(x \cdot x\right) \cdot \left(-2 \cdot x\right) \]
      3. Step-by-step derivation
        1. Applied rewrites75.2%

          \[\leadsto \left(x \cdot x\right) \cdot \left(-2 \cdot x\right) \]

        if -4e8 < (*.f64 (*.f64 x x) (-.f64 #s(literal 3 binary64) (*.f64 x #s(literal 2 binary64)))) < 4.0000000000000001e-10

        1. Initial program 99.8%

          \[\left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right) \]
        2. Step-by-step derivation
          1. Applied rewrites99.8%

            \[\leadsto \left(x \cdot x\right) \cdot \left(\left(3 - x\right) - x\right) \]
          2. Step-by-step derivation
            1. Applied rewrites99.8%

              \[\leadsto \frac{x}{\frac{1}{\mathsf{fma}\left(-2, x, 3\right) \cdot x}} \]
            2. Taylor expanded in x around 0

              \[\leadsto \frac{x}{\frac{1}{3 \cdot x}} \]
            3. Step-by-step derivation
              1. Applied rewrites62.0%

                \[\leadsto \frac{x}{\frac{1}{3 \cdot x}} \]
            4. Recombined 2 regimes into one program.
            5. Add Preprocessing

            Alternative 3: 97.7% accurate, 0.3× speedup?

            \[\begin{array}{l} t_0 := \left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right)\\ t_1 := \left(x \cdot x\right) \cdot \left(-2 \cdot x\right)\\ \mathbf{if}\;t\_0 \leq -400000000:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_0 \leq 4 \cdot 10^{-10}:\\ \;\;\;\;\left(x \cdot x\right) \cdot 3\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \]
            (FPCore (x)
              :precision binary64
              :pre TRUE
              (let* ((t_0 (* (* x x) (- 3.0 (* x 2.0))))
                   (t_1 (* (* x x) (* -2.0 x))))
              (if (<= t_0 -400000000.0)
                t_1
                (if (<= t_0 4e-10) (* (* x x) 3.0) t_1))))
            double code(double x) {
            	double t_0 = (x * x) * (3.0 - (x * 2.0));
            	double t_1 = (x * x) * (-2.0 * x);
            	double tmp;
            	if (t_0 <= -400000000.0) {
            		tmp = t_1;
            	} else if (t_0 <= 4e-10) {
            		tmp = (x * x) * 3.0;
            	} else {
            		tmp = t_1;
            	}
            	return tmp;
            }
            
            real(8) function code(x)
            use fmin_fmax_functions
                real(8), intent (in) :: x
                real(8) :: t_0
                real(8) :: t_1
                real(8) :: tmp
                t_0 = (x * x) * (3.0d0 - (x * 2.0d0))
                t_1 = (x * x) * ((-2.0d0) * x)
                if (t_0 <= (-400000000.0d0)) then
                    tmp = t_1
                else if (t_0 <= 4d-10) then
                    tmp = (x * x) * 3.0d0
                else
                    tmp = t_1
                end if
                code = tmp
            end function
            
            public static double code(double x) {
            	double t_0 = (x * x) * (3.0 - (x * 2.0));
            	double t_1 = (x * x) * (-2.0 * x);
            	double tmp;
            	if (t_0 <= -400000000.0) {
            		tmp = t_1;
            	} else if (t_0 <= 4e-10) {
            		tmp = (x * x) * 3.0;
            	} else {
            		tmp = t_1;
            	}
            	return tmp;
            }
            
            def code(x):
            	t_0 = (x * x) * (3.0 - (x * 2.0))
            	t_1 = (x * x) * (-2.0 * x)
            	tmp = 0
            	if t_0 <= -400000000.0:
            		tmp = t_1
            	elif t_0 <= 4e-10:
            		tmp = (x * x) * 3.0
            	else:
            		tmp = t_1
            	return tmp
            
            function code(x)
            	t_0 = Float64(Float64(x * x) * Float64(3.0 - Float64(x * 2.0)))
            	t_1 = Float64(Float64(x * x) * Float64(-2.0 * x))
            	tmp = 0.0
            	if (t_0 <= -400000000.0)
            		tmp = t_1;
            	elseif (t_0 <= 4e-10)
            		tmp = Float64(Float64(x * x) * 3.0);
            	else
            		tmp = t_1;
            	end
            	return tmp
            end
            
            function tmp_2 = code(x)
            	t_0 = (x * x) * (3.0 - (x * 2.0));
            	t_1 = (x * x) * (-2.0 * x);
            	tmp = 0.0;
            	if (t_0 <= -400000000.0)
            		tmp = t_1;
            	elseif (t_0 <= 4e-10)
            		tmp = (x * x) * 3.0;
            	else
            		tmp = t_1;
            	end
            	tmp_2 = tmp;
            end
            
            code[x_] := Block[{t$95$0 = N[(N[(x * x), $MachinePrecision] * N[(3.0 - N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x * x), $MachinePrecision] * N[(-2.0 * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -400000000.0], t$95$1, If[LessEqual[t$95$0, 4e-10], N[(N[(x * x), $MachinePrecision] * 3.0), $MachinePrecision], t$95$1]]]]
            
            f(x):
            	x in [-inf, +inf]
            code: THEORY
            BEGIN
            f(x: real): real =
            	LET t_0 = ((x * x) * ((3) - (x * (2)))) IN
            		LET t_1 = ((x * x) * ((-2) * x)) IN
            			LET tmp_1 = IF (t_0 <= (400000000000000014572878926199096631666218826239855843596160411834716796875e-84)) THEN ((x * x) * (3)) ELSE t_1 ENDIF IN
            			LET tmp = IF (t_0 <= (-4e8)) THEN t_1 ELSE tmp_1 ENDIF IN
            	tmp
            END code
            \begin{array}{l}
            t_0 := \left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right)\\
            t_1 := \left(x \cdot x\right) \cdot \left(-2 \cdot x\right)\\
            \mathbf{if}\;t\_0 \leq -400000000:\\
            \;\;\;\;t\_1\\
            
            \mathbf{elif}\;t\_0 \leq 4 \cdot 10^{-10}:\\
            \;\;\;\;\left(x \cdot x\right) \cdot 3\\
            
            \mathbf{else}:\\
            \;\;\;\;t\_1\\
            
            
            \end{array}
            
            Derivation
            1. Split input into 2 regimes
            2. if (*.f64 (*.f64 x x) (-.f64 #s(literal 3 binary64) (*.f64 x #s(literal 2 binary64)))) < -4e8 or 4.0000000000000001e-10 < (*.f64 (*.f64 x x) (-.f64 #s(literal 3 binary64) (*.f64 x #s(literal 2 binary64))))

              1. Initial program 99.8%

                \[\left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right) \]
              2. Taylor expanded in x around inf

                \[\leadsto \left(x \cdot x\right) \cdot \left(-2 \cdot x\right) \]
              3. Step-by-step derivation
                1. Applied rewrites75.2%

                  \[\leadsto \left(x \cdot x\right) \cdot \left(-2 \cdot x\right) \]

                if -4e8 < (*.f64 (*.f64 x x) (-.f64 #s(literal 3 binary64) (*.f64 x #s(literal 2 binary64)))) < 4.0000000000000001e-10

                1. Initial program 99.8%

                  \[\left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right) \]
                2. Taylor expanded in x around 0

                  \[\leadsto \left(x \cdot x\right) \cdot 3 \]
                3. Step-by-step derivation
                  1. Applied rewrites62.0%

                    \[\leadsto \left(x \cdot x\right) \cdot 3 \]
                4. Recombined 2 regimes into one program.
                5. Add Preprocessing

                Alternative 4: 62.0% accurate, 1.8× speedup?

                \[\left(x \cdot x\right) \cdot 3 \]
                (FPCore (x)
                  :precision binary64
                  :pre TRUE
                  (* (* x x) 3.0))
                double code(double x) {
                	return (x * x) * 3.0;
                }
                
                real(8) function code(x)
                use fmin_fmax_functions
                    real(8), intent (in) :: x
                    code = (x * x) * 3.0d0
                end function
                
                public static double code(double x) {
                	return (x * x) * 3.0;
                }
                
                def code(x):
                	return (x * x) * 3.0
                
                function code(x)
                	return Float64(Float64(x * x) * 3.0)
                end
                
                function tmp = code(x)
                	tmp = (x * x) * 3.0;
                end
                
                code[x_] := N[(N[(x * x), $MachinePrecision] * 3.0), $MachinePrecision]
                
                f(x):
                	x in [-inf, +inf]
                code: THEORY
                BEGIN
                f(x: real): real =
                	(x * x) * (3)
                END code
                \left(x \cdot x\right) \cdot 3
                
                Derivation
                1. Initial program 99.8%

                  \[\left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right) \]
                2. Taylor expanded in x around 0

                  \[\leadsto \left(x \cdot x\right) \cdot 3 \]
                3. Step-by-step derivation
                  1. Applied rewrites62.0%

                    \[\leadsto \left(x \cdot x\right) \cdot 3 \]
                  2. Add Preprocessing

                  Alternative 5: 62.0% accurate, 1.8× speedup?

                  \[x \cdot \left(3 \cdot x\right) \]
                  (FPCore (x)
                    :precision binary64
                    :pre TRUE
                    (* x (* 3.0 x)))
                  double code(double x) {
                  	return x * (3.0 * x);
                  }
                  
                  real(8) function code(x)
                  use fmin_fmax_functions
                      real(8), intent (in) :: x
                      code = x * (3.0d0 * x)
                  end function
                  
                  public static double code(double x) {
                  	return x * (3.0 * x);
                  }
                  
                  def code(x):
                  	return x * (3.0 * x)
                  
                  function code(x)
                  	return Float64(x * Float64(3.0 * x))
                  end
                  
                  function tmp = code(x)
                  	tmp = x * (3.0 * x);
                  end
                  
                  code[x_] := N[(x * N[(3.0 * x), $MachinePrecision]), $MachinePrecision]
                  
                  f(x):
                  	x in [-inf, +inf]
                  code: THEORY
                  BEGIN
                  f(x: real): real =
                  	x * ((3) * x)
                  END code
                  x \cdot \left(3 \cdot x\right)
                  
                  Derivation
                  1. Initial program 99.8%

                    \[\left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right) \]
                  2. Taylor expanded in x around 0

                    \[\leadsto \left(x \cdot x\right) \cdot 3 \]
                  3. Step-by-step derivation
                    1. Applied rewrites62.0%

                      \[\leadsto \left(x \cdot x\right) \cdot 3 \]
                    2. Step-by-step derivation
                      1. Applied rewrites62.0%

                        \[\leadsto x \cdot \left(3 \cdot x\right) \]
                      2. Add Preprocessing

                      Reproduce

                      ?
                      herbie shell --seed 2026092 
                      (FPCore (x)
                        :name "Data.Spline.Key:interpolateKeys from smoothie-0.4.0.2"
                        :precision binary64
                        (* (* x x) (- 3.0 (* x 2.0))))