Data.Spline.Key:interpolateKeys from smoothie-0.4.0.2

Percentage Accurate: 99.8% → 99.8%
Time: 5.4s
Alternatives: 5
Speedup: N/A×

Specification

?
\[\begin{array}{l} \\ \left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right) \end{array} \]
(FPCore (x) :precision binary64 (* (* x x) (- 3.0 (* x 2.0))))
double code(double x) {
	return (x * x) * (3.0 - (x * 2.0));
}
real(8) function code(x)
    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]
\begin{array}{l}

\\
\left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right)
\end{array}

Sampling outcomes in binary64 precision:

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?

\[\begin{array}{l} \\ \left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right) \end{array} \]
(FPCore (x) :precision binary64 (* (* x x) (- 3.0 (* x 2.0))))
double code(double x) {
	return (x * x) * (3.0 - (x * 2.0));
}
real(8) function code(x)
    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]
\begin{array}{l}

\\
\left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right)
\end{array}

Alternative 1: 99.8% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \left(\left(3 - x\right) - x\right) \cdot \left(x \cdot x\right) \end{array} \]
(FPCore (x) :precision binary64 (* (- (- 3.0 x) x) (* x x)))
double code(double x) {
	return ((3.0 - x) - x) * (x * x);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = ((3.0d0 - x) - x) * (x * x)
end function
public static double code(double x) {
	return ((3.0 - x) - x) * (x * x);
}
def code(x):
	return ((3.0 - x) - x) * (x * x)
function code(x)
	return Float64(Float64(Float64(3.0 - x) - x) * Float64(x * x))
end
function tmp = code(x)
	tmp = ((3.0 - x) - x) * (x * x);
end
code[x_] := N[(N[(N[(3.0 - x), $MachinePrecision] - x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(\left(3 - x\right) - x\right) \cdot \left(x \cdot x\right)
\end{array}
Derivation
  1. Initial program 99.8%

    \[\left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift--.f64N/A

      \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{\left(3 - x \cdot 2\right)} \]
    2. lift-*.f64N/A

      \[\leadsto \left(x \cdot x\right) \cdot \left(3 - \color{blue}{x \cdot 2}\right) \]
    3. *-commutativeN/A

      \[\leadsto \left(x \cdot x\right) \cdot \left(3 - \color{blue}{2 \cdot x}\right) \]
    4. count-2-revN/A

      \[\leadsto \left(x \cdot x\right) \cdot \left(3 - \color{blue}{\left(x + x\right)}\right) \]
    5. associate--r+N/A

      \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{\left(\left(3 - x\right) - x\right)} \]
    6. lower--.f64N/A

      \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{\left(\left(3 - x\right) - x\right)} \]
    7. lower--.f6499.8

      \[\leadsto \left(x \cdot x\right) \cdot \left(\color{blue}{\left(3 - x\right)} - x\right) \]
  4. Applied rewrites99.8%

    \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{\left(\left(3 - x\right) - x\right)} \]
  5. Final simplification99.8%

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

Alternative 2: 97.8% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(-2 \cdot x\right) \cdot \left(x \cdot x\right)\\ \mathbf{if}\;x \leq -1.5:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq 1.5:\\ \;\;\;\;\left(3 \cdot x\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (* (* -2.0 x) (* x x))))
   (if (<= x -1.5) t_0 (if (<= x 1.5) (* (* 3.0 x) x) t_0))))
double code(double x) {
	double t_0 = (-2.0 * x) * (x * x);
	double tmp;
	if (x <= -1.5) {
		tmp = t_0;
	} else if (x <= 1.5) {
		tmp = (3.0 * x) * x;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: tmp
    t_0 = ((-2.0d0) * x) * (x * x)
    if (x <= (-1.5d0)) then
        tmp = t_0
    else if (x <= 1.5d0) then
        tmp = (3.0d0 * x) * x
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x) {
	double t_0 = (-2.0 * x) * (x * x);
	double tmp;
	if (x <= -1.5) {
		tmp = t_0;
	} else if (x <= 1.5) {
		tmp = (3.0 * x) * x;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x):
	t_0 = (-2.0 * x) * (x * x)
	tmp = 0
	if x <= -1.5:
		tmp = t_0
	elif x <= 1.5:
		tmp = (3.0 * x) * x
	else:
		tmp = t_0
	return tmp
function code(x)
	t_0 = Float64(Float64(-2.0 * x) * Float64(x * x))
	tmp = 0.0
	if (x <= -1.5)
		tmp = t_0;
	elseif (x <= 1.5)
		tmp = Float64(Float64(3.0 * x) * x);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x)
	t_0 = (-2.0 * x) * (x * x);
	tmp = 0.0;
	if (x <= -1.5)
		tmp = t_0;
	elseif (x <= 1.5)
		tmp = (3.0 * x) * x;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_] := Block[{t$95$0 = N[(N[(-2.0 * x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.5], t$95$0, If[LessEqual[x, 1.5], N[(N[(3.0 * x), $MachinePrecision] * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(-2 \cdot x\right) \cdot \left(x \cdot x\right)\\
\mathbf{if}\;x \leq -1.5:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;x \leq 1.5:\\
\;\;\;\;\left(3 \cdot x\right) \cdot x\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.5 or 1.5 < x

    1. Initial program 99.9%

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

      \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{\left(-2 \cdot x\right)} \]
    4. Step-by-step derivation
      1. lower-*.f6496.8

        \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{\left(-2 \cdot x\right)} \]
    5. Applied rewrites96.8%

      \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{\left(-2 \cdot x\right)} \]

    if -1.5 < x < 1.5

    1. Initial program 99.7%

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

      \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{3} \]
    4. Step-by-step derivation
      1. Applied rewrites98.7%

        \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{3} \]
      2. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot 3} \]
        2. lift-*.f64N/A

          \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot 3 \]
        3. associate-*l*N/A

          \[\leadsto \color{blue}{x \cdot \left(x \cdot 3\right)} \]
        4. *-commutativeN/A

          \[\leadsto \color{blue}{\left(x \cdot 3\right) \cdot x} \]
        5. lower-*.f64N/A

          \[\leadsto \color{blue}{\left(x \cdot 3\right) \cdot x} \]
        6. *-commutativeN/A

          \[\leadsto \color{blue}{\left(3 \cdot x\right)} \cdot x \]
        7. lower-*.f6498.7

          \[\leadsto \color{blue}{\left(3 \cdot x\right)} \cdot x \]
      3. Applied rewrites98.7%

        \[\leadsto \color{blue}{\left(3 \cdot x\right) \cdot x} \]
    5. Recombined 2 regimes into one program.
    6. Final simplification97.7%

      \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.5:\\ \;\;\;\;\left(-2 \cdot x\right) \cdot \left(x \cdot x\right)\\ \mathbf{elif}\;x \leq 1.5:\\ \;\;\;\;\left(3 \cdot x\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(-2 \cdot x\right) \cdot \left(x \cdot x\right)\\ \end{array} \]
    7. Add Preprocessing

    Alternative 3: 76.0% accurate, 1.1× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 1.5:\\ \;\;\;\;\left(3 \cdot x\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(-3 \cdot x\right) \cdot x\\ \end{array} \end{array} \]
    (FPCore (x)
     :precision binary64
     (if (<= x 1.5) (* (* 3.0 x) x) (* (* -3.0 x) x)))
    double code(double x) {
    	double tmp;
    	if (x <= 1.5) {
    		tmp = (3.0 * x) * x;
    	} else {
    		tmp = (-3.0 * x) * x;
    	}
    	return tmp;
    }
    
    real(8) function code(x)
        real(8), intent (in) :: x
        real(8) :: tmp
        if (x <= 1.5d0) then
            tmp = (3.0d0 * x) * x
        else
            tmp = ((-3.0d0) * x) * x
        end if
        code = tmp
    end function
    
    public static double code(double x) {
    	double tmp;
    	if (x <= 1.5) {
    		tmp = (3.0 * x) * x;
    	} else {
    		tmp = (-3.0 * x) * x;
    	}
    	return tmp;
    }
    
    def code(x):
    	tmp = 0
    	if x <= 1.5:
    		tmp = (3.0 * x) * x
    	else:
    		tmp = (-3.0 * x) * x
    	return tmp
    
    function code(x)
    	tmp = 0.0
    	if (x <= 1.5)
    		tmp = Float64(Float64(3.0 * x) * x);
    	else
    		tmp = Float64(Float64(-3.0 * x) * x);
    	end
    	return tmp
    end
    
    function tmp_2 = code(x)
    	tmp = 0.0;
    	if (x <= 1.5)
    		tmp = (3.0 * x) * x;
    	else
    		tmp = (-3.0 * x) * x;
    	end
    	tmp_2 = tmp;
    end
    
    code[x_] := If[LessEqual[x, 1.5], N[(N[(3.0 * x), $MachinePrecision] * x), $MachinePrecision], N[(N[(-3.0 * x), $MachinePrecision] * x), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;x \leq 1.5:\\
    \;\;\;\;\left(3 \cdot x\right) \cdot x\\
    
    \mathbf{else}:\\
    \;\;\;\;\left(-3 \cdot x\right) \cdot x\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if x < 1.5

      1. Initial program 99.7%

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

        \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{3} \]
      4. Step-by-step derivation
        1. Applied rewrites84.9%

          \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{3} \]
        2. Step-by-step derivation
          1. lift-*.f64N/A

            \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot 3} \]
          2. lift-*.f64N/A

            \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot 3 \]
          3. associate-*l*N/A

            \[\leadsto \color{blue}{x \cdot \left(x \cdot 3\right)} \]
          4. *-commutativeN/A

            \[\leadsto \color{blue}{\left(x \cdot 3\right) \cdot x} \]
          5. lower-*.f64N/A

            \[\leadsto \color{blue}{\left(x \cdot 3\right) \cdot x} \]
          6. *-commutativeN/A

            \[\leadsto \color{blue}{\left(3 \cdot x\right)} \cdot x \]
          7. lower-*.f6485.0

            \[\leadsto \color{blue}{\left(3 \cdot x\right)} \cdot x \]
        3. Applied rewrites85.0%

          \[\leadsto \color{blue}{\left(3 \cdot x\right) \cdot x} \]

        if 1.5 < x

        1. Initial program 100.0%

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

          \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{3} \]
        4. Step-by-step derivation
          1. Applied rewrites0.2%

            \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{3} \]
          2. Step-by-step derivation
            1. lift-*.f64N/A

              \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot 3} \]
            2. lift-*.f64N/A

              \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot 3 \]
            3. associate-*l*N/A

              \[\leadsto \color{blue}{x \cdot \left(x \cdot 3\right)} \]
            4. *-commutativeN/A

              \[\leadsto \color{blue}{\left(x \cdot 3\right) \cdot x} \]
            5. lower-*.f64N/A

              \[\leadsto \color{blue}{\left(x \cdot 3\right) \cdot x} \]
            6. *-commutativeN/A

              \[\leadsto \color{blue}{\left(3 \cdot x\right)} \cdot x \]
            7. lower-*.f640.2

              \[\leadsto \color{blue}{\left(3 \cdot x\right)} \cdot x \]
          3. Applied rewrites0.2%

            \[\leadsto \color{blue}{\left(3 \cdot x\right) \cdot x} \]
          4. Step-by-step derivation
            1. lift-*.f64N/A

              \[\leadsto \color{blue}{\left(3 \cdot x\right)} \cdot x \]
            2. unpow1N/A

              \[\leadsto \left(3 \cdot \color{blue}{{x}^{1}}\right) \cdot x \]
            3. remove-double-negN/A

              \[\leadsto \left(3 \cdot {\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right)}}^{1}\right) \cdot x \]
            4. lift-neg.f64N/A

              \[\leadsto \left(3 \cdot {\left(\mathsf{neg}\left(\color{blue}{\left(-x\right)}\right)\right)}^{1}\right) \cdot x \]
            5. neg-mul-1N/A

              \[\leadsto \left(3 \cdot {\color{blue}{\left(-1 \cdot \left(-x\right)\right)}}^{1}\right) \cdot x \]
            6. unpow-prod-downN/A

              \[\leadsto \left(3 \cdot \color{blue}{\left({-1}^{1} \cdot {\left(-x\right)}^{1}\right)}\right) \cdot x \]
            7. metadata-evalN/A

              \[\leadsto \left(3 \cdot \left(\color{blue}{-1} \cdot {\left(-x\right)}^{1}\right)\right) \cdot x \]
            8. metadata-evalN/A

              \[\leadsto \left(3 \cdot \left(-1 \cdot {\left(-x\right)}^{\color{blue}{\left(\frac{2}{2}\right)}}\right)\right) \cdot x \]
            9. sqrt-pow1N/A

              \[\leadsto \left(3 \cdot \left(-1 \cdot \color{blue}{\sqrt{{\left(-x\right)}^{2}}}\right)\right) \cdot x \]
            10. pow2N/A

              \[\leadsto \left(3 \cdot \left(-1 \cdot \sqrt{\color{blue}{\left(-x\right) \cdot \left(-x\right)}}\right)\right) \cdot x \]
            11. lift-neg.f64N/A

              \[\leadsto \left(3 \cdot \left(-1 \cdot \sqrt{\color{blue}{\left(\mathsf{neg}\left(x\right)\right)} \cdot \left(-x\right)}\right)\right) \cdot x \]
            12. lift-neg.f64N/A

              \[\leadsto \left(3 \cdot \left(-1 \cdot \sqrt{\left(\mathsf{neg}\left(x\right)\right) \cdot \color{blue}{\left(\mathsf{neg}\left(x\right)\right)}}\right)\right) \cdot x \]
            13. sqr-neg-revN/A

              \[\leadsto \left(3 \cdot \left(-1 \cdot \sqrt{\color{blue}{x \cdot x}}\right)\right) \cdot x \]
            14. pow2N/A

              \[\leadsto \left(3 \cdot \left(-1 \cdot \sqrt{\color{blue}{{x}^{2}}}\right)\right) \cdot x \]
            15. sqrt-pow1N/A

              \[\leadsto \left(3 \cdot \left(-1 \cdot \color{blue}{{x}^{\left(\frac{2}{2}\right)}}\right)\right) \cdot x \]
            16. metadata-evalN/A

              \[\leadsto \left(3 \cdot \left(-1 \cdot {x}^{\color{blue}{1}}\right)\right) \cdot x \]
            17. unpow1N/A

              \[\leadsto \left(3 \cdot \left(-1 \cdot \color{blue}{x}\right)\right) \cdot x \]
            18. neg-mul-1N/A

              \[\leadsto \left(3 \cdot \color{blue}{\left(\mathsf{neg}\left(x\right)\right)}\right) \cdot x \]
            19. distribute-rgt-neg-outN/A

              \[\leadsto \color{blue}{\left(\mathsf{neg}\left(3 \cdot x\right)\right)} \cdot x \]
            20. lift-*.f64N/A

              \[\leadsto \left(\mathsf{neg}\left(\color{blue}{3 \cdot x}\right)\right) \cdot x \]
            21. lower-neg.f6466.3

              \[\leadsto \color{blue}{\left(-3 \cdot x\right)} \cdot x \]
          5. Applied rewrites66.3%

            \[\leadsto \color{blue}{\left(-3 \cdot x\right)} \cdot x \]
          6. Taylor expanded in x around 0

            \[\leadsto \color{blue}{\left(-3 \cdot x\right)} \cdot x \]
          7. Step-by-step derivation
            1. lower-*.f6466.3

              \[\leadsto \color{blue}{\left(-3 \cdot x\right)} \cdot x \]
          8. Applied rewrites66.3%

            \[\leadsto \color{blue}{\left(-3 \cdot x\right)} \cdot x \]
        5. Recombined 2 regimes into one program.
        6. Add Preprocessing

        Alternative 4: 76.0% accurate, 1.1× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 1.5:\\ \;\;\;\;3 \cdot \left(x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\left(-3 \cdot x\right) \cdot x\\ \end{array} \end{array} \]
        (FPCore (x)
         :precision binary64
         (if (<= x 1.5) (* 3.0 (* x x)) (* (* -3.0 x) x)))
        double code(double x) {
        	double tmp;
        	if (x <= 1.5) {
        		tmp = 3.0 * (x * x);
        	} else {
        		tmp = (-3.0 * x) * x;
        	}
        	return tmp;
        }
        
        real(8) function code(x)
            real(8), intent (in) :: x
            real(8) :: tmp
            if (x <= 1.5d0) then
                tmp = 3.0d0 * (x * x)
            else
                tmp = ((-3.0d0) * x) * x
            end if
            code = tmp
        end function
        
        public static double code(double x) {
        	double tmp;
        	if (x <= 1.5) {
        		tmp = 3.0 * (x * x);
        	} else {
        		tmp = (-3.0 * x) * x;
        	}
        	return tmp;
        }
        
        def code(x):
        	tmp = 0
        	if x <= 1.5:
        		tmp = 3.0 * (x * x)
        	else:
        		tmp = (-3.0 * x) * x
        	return tmp
        
        function code(x)
        	tmp = 0.0
        	if (x <= 1.5)
        		tmp = Float64(3.0 * Float64(x * x));
        	else
        		tmp = Float64(Float64(-3.0 * x) * x);
        	end
        	return tmp
        end
        
        function tmp_2 = code(x)
        	tmp = 0.0;
        	if (x <= 1.5)
        		tmp = 3.0 * (x * x);
        	else
        		tmp = (-3.0 * x) * x;
        	end
        	tmp_2 = tmp;
        end
        
        code[x_] := If[LessEqual[x, 1.5], N[(3.0 * N[(x * x), $MachinePrecision]), $MachinePrecision], N[(N[(-3.0 * x), $MachinePrecision] * x), $MachinePrecision]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;x \leq 1.5:\\
        \;\;\;\;3 \cdot \left(x \cdot x\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;\left(-3 \cdot x\right) \cdot x\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if x < 1.5

          1. Initial program 99.7%

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

            \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{3} \]
          4. Step-by-step derivation
            1. Applied rewrites84.9%

              \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{3} \]

            if 1.5 < x

            1. Initial program 100.0%

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

              \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{3} \]
            4. Step-by-step derivation
              1. Applied rewrites0.2%

                \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{3} \]
              2. Step-by-step derivation
                1. lift-*.f64N/A

                  \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot 3} \]
                2. lift-*.f64N/A

                  \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot 3 \]
                3. associate-*l*N/A

                  \[\leadsto \color{blue}{x \cdot \left(x \cdot 3\right)} \]
                4. *-commutativeN/A

                  \[\leadsto \color{blue}{\left(x \cdot 3\right) \cdot x} \]
                5. lower-*.f64N/A

                  \[\leadsto \color{blue}{\left(x \cdot 3\right) \cdot x} \]
                6. *-commutativeN/A

                  \[\leadsto \color{blue}{\left(3 \cdot x\right)} \cdot x \]
                7. lower-*.f640.2

                  \[\leadsto \color{blue}{\left(3 \cdot x\right)} \cdot x \]
              3. Applied rewrites0.2%

                \[\leadsto \color{blue}{\left(3 \cdot x\right) \cdot x} \]
              4. Step-by-step derivation
                1. lift-*.f64N/A

                  \[\leadsto \color{blue}{\left(3 \cdot x\right)} \cdot x \]
                2. unpow1N/A

                  \[\leadsto \left(3 \cdot \color{blue}{{x}^{1}}\right) \cdot x \]
                3. remove-double-negN/A

                  \[\leadsto \left(3 \cdot {\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right)}}^{1}\right) \cdot x \]
                4. lift-neg.f64N/A

                  \[\leadsto \left(3 \cdot {\left(\mathsf{neg}\left(\color{blue}{\left(-x\right)}\right)\right)}^{1}\right) \cdot x \]
                5. neg-mul-1N/A

                  \[\leadsto \left(3 \cdot {\color{blue}{\left(-1 \cdot \left(-x\right)\right)}}^{1}\right) \cdot x \]
                6. unpow-prod-downN/A

                  \[\leadsto \left(3 \cdot \color{blue}{\left({-1}^{1} \cdot {\left(-x\right)}^{1}\right)}\right) \cdot x \]
                7. metadata-evalN/A

                  \[\leadsto \left(3 \cdot \left(\color{blue}{-1} \cdot {\left(-x\right)}^{1}\right)\right) \cdot x \]
                8. metadata-evalN/A

                  \[\leadsto \left(3 \cdot \left(-1 \cdot {\left(-x\right)}^{\color{blue}{\left(\frac{2}{2}\right)}}\right)\right) \cdot x \]
                9. sqrt-pow1N/A

                  \[\leadsto \left(3 \cdot \left(-1 \cdot \color{blue}{\sqrt{{\left(-x\right)}^{2}}}\right)\right) \cdot x \]
                10. pow2N/A

                  \[\leadsto \left(3 \cdot \left(-1 \cdot \sqrt{\color{blue}{\left(-x\right) \cdot \left(-x\right)}}\right)\right) \cdot x \]
                11. lift-neg.f64N/A

                  \[\leadsto \left(3 \cdot \left(-1 \cdot \sqrt{\color{blue}{\left(\mathsf{neg}\left(x\right)\right)} \cdot \left(-x\right)}\right)\right) \cdot x \]
                12. lift-neg.f64N/A

                  \[\leadsto \left(3 \cdot \left(-1 \cdot \sqrt{\left(\mathsf{neg}\left(x\right)\right) \cdot \color{blue}{\left(\mathsf{neg}\left(x\right)\right)}}\right)\right) \cdot x \]
                13. sqr-neg-revN/A

                  \[\leadsto \left(3 \cdot \left(-1 \cdot \sqrt{\color{blue}{x \cdot x}}\right)\right) \cdot x \]
                14. pow2N/A

                  \[\leadsto \left(3 \cdot \left(-1 \cdot \sqrt{\color{blue}{{x}^{2}}}\right)\right) \cdot x \]
                15. sqrt-pow1N/A

                  \[\leadsto \left(3 \cdot \left(-1 \cdot \color{blue}{{x}^{\left(\frac{2}{2}\right)}}\right)\right) \cdot x \]
                16. metadata-evalN/A

                  \[\leadsto \left(3 \cdot \left(-1 \cdot {x}^{\color{blue}{1}}\right)\right) \cdot x \]
                17. unpow1N/A

                  \[\leadsto \left(3 \cdot \left(-1 \cdot \color{blue}{x}\right)\right) \cdot x \]
                18. neg-mul-1N/A

                  \[\leadsto \left(3 \cdot \color{blue}{\left(\mathsf{neg}\left(x\right)\right)}\right) \cdot x \]
                19. distribute-rgt-neg-outN/A

                  \[\leadsto \color{blue}{\left(\mathsf{neg}\left(3 \cdot x\right)\right)} \cdot x \]
                20. lift-*.f64N/A

                  \[\leadsto \left(\mathsf{neg}\left(\color{blue}{3 \cdot x}\right)\right) \cdot x \]
                21. lower-neg.f6466.3

                  \[\leadsto \color{blue}{\left(-3 \cdot x\right)} \cdot x \]
              5. Applied rewrites66.3%

                \[\leadsto \color{blue}{\left(-3 \cdot x\right)} \cdot x \]
              6. Taylor expanded in x around 0

                \[\leadsto \color{blue}{\left(-3 \cdot x\right)} \cdot x \]
              7. Step-by-step derivation
                1. lower-*.f6466.3

                  \[\leadsto \color{blue}{\left(-3 \cdot x\right)} \cdot x \]
              8. Applied rewrites66.3%

                \[\leadsto \color{blue}{\left(-3 \cdot x\right)} \cdot x \]
            5. Recombined 2 regimes into one program.
            6. Final simplification80.4%

              \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1.5:\\ \;\;\;\;3 \cdot \left(x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\left(-3 \cdot x\right) \cdot x\\ \end{array} \]
            7. Add Preprocessing

            Alternative 5: 38.8% accurate, 1.7× speedup?

            \[\begin{array}{l} \\ -3 \cdot \left(x \cdot x\right) \end{array} \]
            (FPCore (x) :precision binary64 (* -3.0 (* x x)))
            double code(double x) {
            	return -3.0 * (x * x);
            }
            
            real(8) function code(x)
                real(8), intent (in) :: x
                code = (-3.0d0) * (x * x)
            end function
            
            public static double code(double x) {
            	return -3.0 * (x * x);
            }
            
            def code(x):
            	return -3.0 * (x * x)
            
            function code(x)
            	return Float64(-3.0 * Float64(x * x))
            end
            
            function tmp = code(x)
            	tmp = -3.0 * (x * x);
            end
            
            code[x_] := N[(-3.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]
            
            \begin{array}{l}
            
            \\
            -3 \cdot \left(x \cdot x\right)
            \end{array}
            
            Derivation
            1. Initial program 99.8%

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

              \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{3} \]
            4. Step-by-step derivation
              1. Applied rewrites64.1%

                \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{3} \]
              2. Step-by-step derivation
                1. lift-*.f64N/A

                  \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot 3} \]
                2. lift-*.f64N/A

                  \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot 3 \]
                3. associate-*l*N/A

                  \[\leadsto \color{blue}{x \cdot \left(x \cdot 3\right)} \]
                4. *-commutativeN/A

                  \[\leadsto \color{blue}{\left(x \cdot 3\right) \cdot x} \]
                5. lower-*.f64N/A

                  \[\leadsto \color{blue}{\left(x \cdot 3\right) \cdot x} \]
                6. *-commutativeN/A

                  \[\leadsto \color{blue}{\left(3 \cdot x\right)} \cdot x \]
                7. lower-*.f6464.1

                  \[\leadsto \color{blue}{\left(3 \cdot x\right)} \cdot x \]
              3. Applied rewrites64.1%

                \[\leadsto \color{blue}{\left(3 \cdot x\right) \cdot x} \]
              4. Step-by-step derivation
                1. lift-*.f64N/A

                  \[\leadsto \color{blue}{\left(3 \cdot x\right)} \cdot x \]
                2. unpow1N/A

                  \[\leadsto \left(3 \cdot \color{blue}{{x}^{1}}\right) \cdot x \]
                3. remove-double-negN/A

                  \[\leadsto \left(3 \cdot {\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right)}}^{1}\right) \cdot x \]
                4. lift-neg.f64N/A

                  \[\leadsto \left(3 \cdot {\left(\mathsf{neg}\left(\color{blue}{\left(-x\right)}\right)\right)}^{1}\right) \cdot x \]
                5. neg-mul-1N/A

                  \[\leadsto \left(3 \cdot {\color{blue}{\left(-1 \cdot \left(-x\right)\right)}}^{1}\right) \cdot x \]
                6. unpow-prod-downN/A

                  \[\leadsto \left(3 \cdot \color{blue}{\left({-1}^{1} \cdot {\left(-x\right)}^{1}\right)}\right) \cdot x \]
                7. metadata-evalN/A

                  \[\leadsto \left(3 \cdot \left(\color{blue}{-1} \cdot {\left(-x\right)}^{1}\right)\right) \cdot x \]
                8. metadata-evalN/A

                  \[\leadsto \left(3 \cdot \left(-1 \cdot {\left(-x\right)}^{\color{blue}{\left(\frac{2}{2}\right)}}\right)\right) \cdot x \]
                9. sqrt-pow1N/A

                  \[\leadsto \left(3 \cdot \left(-1 \cdot \color{blue}{\sqrt{{\left(-x\right)}^{2}}}\right)\right) \cdot x \]
                10. pow2N/A

                  \[\leadsto \left(3 \cdot \left(-1 \cdot \sqrt{\color{blue}{\left(-x\right) \cdot \left(-x\right)}}\right)\right) \cdot x \]
                11. lift-neg.f64N/A

                  \[\leadsto \left(3 \cdot \left(-1 \cdot \sqrt{\color{blue}{\left(\mathsf{neg}\left(x\right)\right)} \cdot \left(-x\right)}\right)\right) \cdot x \]
                12. lift-neg.f64N/A

                  \[\leadsto \left(3 \cdot \left(-1 \cdot \sqrt{\left(\mathsf{neg}\left(x\right)\right) \cdot \color{blue}{\left(\mathsf{neg}\left(x\right)\right)}}\right)\right) \cdot x \]
                13. sqr-neg-revN/A

                  \[\leadsto \left(3 \cdot \left(-1 \cdot \sqrt{\color{blue}{x \cdot x}}\right)\right) \cdot x \]
                14. pow2N/A

                  \[\leadsto \left(3 \cdot \left(-1 \cdot \sqrt{\color{blue}{{x}^{2}}}\right)\right) \cdot x \]
                15. sqrt-pow1N/A

                  \[\leadsto \left(3 \cdot \left(-1 \cdot \color{blue}{{x}^{\left(\frac{2}{2}\right)}}\right)\right) \cdot x \]
                16. metadata-evalN/A

                  \[\leadsto \left(3 \cdot \left(-1 \cdot {x}^{\color{blue}{1}}\right)\right) \cdot x \]
                17. unpow1N/A

                  \[\leadsto \left(3 \cdot \left(-1 \cdot \color{blue}{x}\right)\right) \cdot x \]
                18. neg-mul-1N/A

                  \[\leadsto \left(3 \cdot \color{blue}{\left(\mathsf{neg}\left(x\right)\right)}\right) \cdot x \]
                19. distribute-rgt-neg-outN/A

                  \[\leadsto \color{blue}{\left(\mathsf{neg}\left(3 \cdot x\right)\right)} \cdot x \]
                20. lift-*.f64N/A

                  \[\leadsto \left(\mathsf{neg}\left(\color{blue}{3 \cdot x}\right)\right) \cdot x \]
                21. lower-neg.f6442.1

                  \[\leadsto \color{blue}{\left(-3 \cdot x\right)} \cdot x \]
              5. Applied rewrites42.1%

                \[\leadsto \color{blue}{\left(-3 \cdot x\right)} \cdot x \]
              6. Taylor expanded in x around 0

                \[\leadsto \color{blue}{-3 \cdot {x}^{2}} \]
              7. Step-by-step derivation
                1. lower-*.f64N/A

                  \[\leadsto \color{blue}{-3 \cdot {x}^{2}} \]
                2. unpow2N/A

                  \[\leadsto -3 \cdot \color{blue}{\left(x \cdot x\right)} \]
                3. lower-*.f6442.1

                  \[\leadsto -3 \cdot \color{blue}{\left(x \cdot x\right)} \]
              8. Applied rewrites42.1%

                \[\leadsto \color{blue}{-3 \cdot \left(x \cdot x\right)} \]
              9. Add Preprocessing

              Developer Target 1: 99.8% accurate, 1.0× speedup?

              \[\begin{array}{l} \\ x \cdot \left(x \cdot \left(3 - x \cdot 2\right)\right) \end{array} \]
              (FPCore (x) :precision binary64 (* x (* x (- 3.0 (* x 2.0)))))
              double code(double x) {
              	return x * (x * (3.0 - (x * 2.0)));
              }
              
              real(8) function code(x)
                  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(x * Float64(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[(x * N[(x * N[(3.0 - N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
              
              \begin{array}{l}
              
              \\
              x \cdot \left(x \cdot \left(3 - x \cdot 2\right)\right)
              \end{array}
              

              Reproduce

              ?
              herbie shell --seed 2024298 
              (FPCore (x)
                :name "Data.Spline.Key:interpolateKeys from smoothie-0.4.0.2"
                :precision binary64
              
                :alt
                (! :herbie-platform default (* x (* x (- 3 (* x 2)))))
              
                (* (* x x) (- 3.0 (* x 2.0))))