Rosa's Benchmark

Percentage Accurate: 99.8% → 99.8%
Time: 8.2s
Alternatives: 8
Speedup: 1.2×

Specification

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

\\
0.954929658551372 \cdot x - 0.12900613773279798 \cdot \left(\left(x \cdot x\right) \cdot x\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 8 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} \\ 0.954929658551372 \cdot x - 0.12900613773279798 \cdot \left(\left(x \cdot x\right) \cdot x\right) \end{array} \]
(FPCore (x)
 :precision binary64
 (- (* 0.954929658551372 x) (* 0.12900613773279798 (* (* x x) x))))
double code(double x) {
	return (0.954929658551372 * x) - (0.12900613773279798 * ((x * x) * x));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (0.954929658551372d0 * x) - (0.12900613773279798d0 * ((x * x) * x))
end function
public static double code(double x) {
	return (0.954929658551372 * x) - (0.12900613773279798 * ((x * x) * x));
}
def code(x):
	return (0.954929658551372 * x) - (0.12900613773279798 * ((x * x) * x))
function code(x)
	return Float64(Float64(0.954929658551372 * x) - Float64(0.12900613773279798 * Float64(Float64(x * x) * x)))
end
function tmp = code(x)
	tmp = (0.954929658551372 * x) - (0.12900613773279798 * ((x * x) * x));
end
code[x_] := N[(N[(0.954929658551372 * x), $MachinePrecision] - N[(0.12900613773279798 * N[(N[(x * x), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
0.954929658551372 \cdot x - 0.12900613773279798 \cdot \left(\left(x \cdot x\right) \cdot x\right)
\end{array}

Alternative 1: 99.8% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(0.954929658551372, x, {x}^{3} \cdot -0.12900613773279798\right) \end{array} \]
(FPCore (x)
 :precision binary64
 (fma 0.954929658551372 x (* (pow x 3.0) -0.12900613773279798)))
double code(double x) {
	return fma(0.954929658551372, x, (pow(x, 3.0) * -0.12900613773279798));
}
function code(x)
	return fma(0.954929658551372, x, Float64((x ^ 3.0) * -0.12900613773279798))
end
code[x_] := N[(0.954929658551372 * x + N[(N[Power[x, 3.0], $MachinePrecision] * -0.12900613773279798), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(0.954929658551372, x, {x}^{3} \cdot -0.12900613773279798\right)
\end{array}
Derivation
  1. Initial program 99.8%

    \[0.954929658551372 \cdot x - 0.12900613773279798 \cdot \left(\left(x \cdot x\right) \cdot x\right) \]
  2. Step-by-step derivation
    1. fma-neg99.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.954929658551372, x, -0.12900613773279798 \cdot \left(\left(x \cdot x\right) \cdot x\right)\right)} \]
    2. *-commutative99.8%

      \[\leadsto \mathsf{fma}\left(0.954929658551372, x, -\color{blue}{\left(\left(x \cdot x\right) \cdot x\right) \cdot 0.12900613773279798}\right) \]
    3. distribute-rgt-neg-in99.8%

      \[\leadsto \mathsf{fma}\left(0.954929658551372, x, \color{blue}{\left(\left(x \cdot x\right) \cdot x\right) \cdot \left(-0.12900613773279798\right)}\right) \]
    4. unpow399.9%

      \[\leadsto \mathsf{fma}\left(0.954929658551372, x, \color{blue}{{x}^{3}} \cdot \left(-0.12900613773279798\right)\right) \]
    5. metadata-eval99.9%

      \[\leadsto \mathsf{fma}\left(0.954929658551372, x, {x}^{3} \cdot \color{blue}{-0.12900613773279798}\right) \]
  3. Simplified99.9%

    \[\leadsto \color{blue}{\mathsf{fma}\left(0.954929658551372, x, {x}^{3} \cdot -0.12900613773279798\right)} \]
  4. Final simplification99.9%

    \[\leadsto \mathsf{fma}\left(0.954929658551372, x, {x}^{3} \cdot -0.12900613773279798\right) \]

Alternative 2: 99.8% accurate, 0.1× speedup?

\[\begin{array}{l} \\ x \cdot \mathsf{fma}\left(x \cdot x, -0.12900613773279798, 0.954929658551372\right) \end{array} \]
(FPCore (x)
 :precision binary64
 (* x (fma (* x x) -0.12900613773279798 0.954929658551372)))
double code(double x) {
	return x * fma((x * x), -0.12900613773279798, 0.954929658551372);
}
function code(x)
	return Float64(x * fma(Float64(x * x), -0.12900613773279798, 0.954929658551372))
end
code[x_] := N[(x * N[(N[(x * x), $MachinePrecision] * -0.12900613773279798 + 0.954929658551372), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot \mathsf{fma}\left(x \cdot x, -0.12900613773279798, 0.954929658551372\right)
\end{array}
Derivation
  1. Initial program 99.8%

    \[0.954929658551372 \cdot x - 0.12900613773279798 \cdot \left(\left(x \cdot x\right) \cdot x\right) \]
  2. Step-by-step derivation
    1. associate-*r*99.8%

      \[\leadsto 0.954929658551372 \cdot x - \color{blue}{\left(0.12900613773279798 \cdot \left(x \cdot x\right)\right) \cdot x} \]
    2. distribute-rgt-out--99.8%

      \[\leadsto \color{blue}{x \cdot \left(0.954929658551372 - 0.12900613773279798 \cdot \left(x \cdot x\right)\right)} \]
    3. sub-neg99.8%

      \[\leadsto x \cdot \color{blue}{\left(0.954929658551372 + \left(-0.12900613773279798 \cdot \left(x \cdot x\right)\right)\right)} \]
    4. +-commutative99.8%

      \[\leadsto x \cdot \color{blue}{\left(\left(-0.12900613773279798 \cdot \left(x \cdot x\right)\right) + 0.954929658551372\right)} \]
    5. *-commutative99.8%

      \[\leadsto x \cdot \left(\left(-\color{blue}{\left(x \cdot x\right) \cdot 0.12900613773279798}\right) + 0.954929658551372\right) \]
    6. distribute-rgt-neg-in99.8%

      \[\leadsto x \cdot \left(\color{blue}{\left(x \cdot x\right) \cdot \left(-0.12900613773279798\right)} + 0.954929658551372\right) \]
    7. fma-def99.8%

      \[\leadsto x \cdot \color{blue}{\mathsf{fma}\left(x \cdot x, -0.12900613773279798, 0.954929658551372\right)} \]
    8. metadata-eval99.8%

      \[\leadsto x \cdot \mathsf{fma}\left(x \cdot x, \color{blue}{-0.12900613773279798}, 0.954929658551372\right) \]
  3. Simplified99.8%

    \[\leadsto \color{blue}{x \cdot \mathsf{fma}\left(x \cdot x, -0.12900613773279798, 0.954929658551372\right)} \]
  4. Final simplification99.8%

    \[\leadsto x \cdot \mathsf{fma}\left(x \cdot x, -0.12900613773279798, 0.954929658551372\right) \]

Alternative 3: 98.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -2.7 \lor \neg \left(x \leq 2.7\right):\\ \;\;\;\;x \cdot \left(-0.12900613773279798 \cdot \left(x \cdot x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0.954929658551372 \cdot x\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (or (<= x -2.7) (not (<= x 2.7)))
   (* x (* -0.12900613773279798 (* x x)))
   (* 0.954929658551372 x)))
double code(double x) {
	double tmp;
	if ((x <= -2.7) || !(x <= 2.7)) {
		tmp = x * (-0.12900613773279798 * (x * x));
	} else {
		tmp = 0.954929658551372 * x;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if ((x <= (-2.7d0)) .or. (.not. (x <= 2.7d0))) then
        tmp = x * ((-0.12900613773279798d0) * (x * x))
    else
        tmp = 0.954929658551372d0 * x
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if ((x <= -2.7) || !(x <= 2.7)) {
		tmp = x * (-0.12900613773279798 * (x * x));
	} else {
		tmp = 0.954929658551372 * x;
	}
	return tmp;
}
def code(x):
	tmp = 0
	if (x <= -2.7) or not (x <= 2.7):
		tmp = x * (-0.12900613773279798 * (x * x))
	else:
		tmp = 0.954929658551372 * x
	return tmp
function code(x)
	tmp = 0.0
	if ((x <= -2.7) || !(x <= 2.7))
		tmp = Float64(x * Float64(-0.12900613773279798 * Float64(x * x)));
	else
		tmp = Float64(0.954929658551372 * x);
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if ((x <= -2.7) || ~((x <= 2.7)))
		tmp = x * (-0.12900613773279798 * (x * x));
	else
		tmp = 0.954929658551372 * x;
	end
	tmp_2 = tmp;
end
code[x_] := If[Or[LessEqual[x, -2.7], N[Not[LessEqual[x, 2.7]], $MachinePrecision]], N[(x * N[(-0.12900613773279798 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.954929658551372 * x), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.7 \lor \neg \left(x \leq 2.7\right):\\
\;\;\;\;x \cdot \left(-0.12900613773279798 \cdot \left(x \cdot x\right)\right)\\

\mathbf{else}:\\
\;\;\;\;0.954929658551372 \cdot x\\


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

    1. Initial program 99.8%

      \[0.954929658551372 \cdot x - 0.12900613773279798 \cdot \left(\left(x \cdot x\right) \cdot x\right) \]
    2. Step-by-step derivation
      1. associate-*r*99.8%

        \[\leadsto 0.954929658551372 \cdot x - \color{blue}{\left(0.12900613773279798 \cdot \left(x \cdot x\right)\right) \cdot x} \]
      2. distribute-rgt-out--99.8%

        \[\leadsto \color{blue}{x \cdot \left(0.954929658551372 - 0.12900613773279798 \cdot \left(x \cdot x\right)\right)} \]
      3. sub-neg99.8%

        \[\leadsto x \cdot \color{blue}{\left(0.954929658551372 + \left(-0.12900613773279798 \cdot \left(x \cdot x\right)\right)\right)} \]
      4. +-commutative99.8%

        \[\leadsto x \cdot \color{blue}{\left(\left(-0.12900613773279798 \cdot \left(x \cdot x\right)\right) + 0.954929658551372\right)} \]
      5. *-commutative99.8%

        \[\leadsto x \cdot \left(\left(-\color{blue}{\left(x \cdot x\right) \cdot 0.12900613773279798}\right) + 0.954929658551372\right) \]
      6. distribute-rgt-neg-in99.8%

        \[\leadsto x \cdot \left(\color{blue}{\left(x \cdot x\right) \cdot \left(-0.12900613773279798\right)} + 0.954929658551372\right) \]
      7. fma-def99.8%

        \[\leadsto x \cdot \color{blue}{\mathsf{fma}\left(x \cdot x, -0.12900613773279798, 0.954929658551372\right)} \]
      8. metadata-eval99.8%

        \[\leadsto x \cdot \mathsf{fma}\left(x \cdot x, \color{blue}{-0.12900613773279798}, 0.954929658551372\right) \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{x \cdot \mathsf{fma}\left(x \cdot x, -0.12900613773279798, 0.954929658551372\right)} \]
    4. Taylor expanded in x around inf 99.0%

      \[\leadsto x \cdot \color{blue}{\left(-0.12900613773279798 \cdot {x}^{2}\right)} \]
    5. Step-by-step derivation
      1. unpow299.0%

        \[\leadsto x \cdot \left(-0.12900613773279798 \cdot \color{blue}{\left(x \cdot x\right)}\right) \]
    6. Simplified99.0%

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

    if -2.7000000000000002 < x < 2.7000000000000002

    1. Initial program 99.8%

      \[0.954929658551372 \cdot x - 0.12900613773279798 \cdot \left(\left(x \cdot x\right) \cdot x\right) \]
    2. Step-by-step derivation
      1. associate-*r*99.8%

        \[\leadsto 0.954929658551372 \cdot x - \color{blue}{\left(0.12900613773279798 \cdot \left(x \cdot x\right)\right) \cdot x} \]
      2. distribute-rgt-out--99.8%

        \[\leadsto \color{blue}{x \cdot \left(0.954929658551372 - 0.12900613773279798 \cdot \left(x \cdot x\right)\right)} \]
      3. sub-neg99.8%

        \[\leadsto x \cdot \color{blue}{\left(0.954929658551372 + \left(-0.12900613773279798 \cdot \left(x \cdot x\right)\right)\right)} \]
      4. +-commutative99.8%

        \[\leadsto x \cdot \color{blue}{\left(\left(-0.12900613773279798 \cdot \left(x \cdot x\right)\right) + 0.954929658551372\right)} \]
      5. *-commutative99.8%

        \[\leadsto x \cdot \left(\left(-\color{blue}{\left(x \cdot x\right) \cdot 0.12900613773279798}\right) + 0.954929658551372\right) \]
      6. distribute-rgt-neg-in99.8%

        \[\leadsto x \cdot \left(\color{blue}{\left(x \cdot x\right) \cdot \left(-0.12900613773279798\right)} + 0.954929658551372\right) \]
      7. fma-def99.8%

        \[\leadsto x \cdot \color{blue}{\mathsf{fma}\left(x \cdot x, -0.12900613773279798, 0.954929658551372\right)} \]
      8. metadata-eval99.8%

        \[\leadsto x \cdot \mathsf{fma}\left(x \cdot x, \color{blue}{-0.12900613773279798}, 0.954929658551372\right) \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{x \cdot \mathsf{fma}\left(x \cdot x, -0.12900613773279798, 0.954929658551372\right)} \]
    4. Taylor expanded in x around 0 99.8%

      \[\leadsto x \cdot \color{blue}{0.954929658551372} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.7 \lor \neg \left(x \leq 2.7\right):\\ \;\;\;\;x \cdot \left(-0.12900613773279798 \cdot \left(x \cdot x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0.954929658551372 \cdot x\\ \end{array} \]

Alternative 4: 98.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -2.7:\\ \;\;\;\;x \cdot \left(x \cdot \left(x \cdot -0.12900613773279798\right)\right)\\ \mathbf{elif}\;x \leq 2.7:\\ \;\;\;\;0.954929658551372 \cdot x\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(-0.12900613773279798 \cdot \left(x \cdot x\right)\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x -2.7)
   (* x (* x (* x -0.12900613773279798)))
   (if (<= x 2.7)
     (* 0.954929658551372 x)
     (* x (* -0.12900613773279798 (* x x))))))
double code(double x) {
	double tmp;
	if (x <= -2.7) {
		tmp = x * (x * (x * -0.12900613773279798));
	} else if (x <= 2.7) {
		tmp = 0.954929658551372 * x;
	} else {
		tmp = x * (-0.12900613773279798 * (x * x));
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= (-2.7d0)) then
        tmp = x * (x * (x * (-0.12900613773279798d0)))
    else if (x <= 2.7d0) then
        tmp = 0.954929658551372d0 * x
    else
        tmp = x * ((-0.12900613773279798d0) * (x * x))
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= -2.7) {
		tmp = x * (x * (x * -0.12900613773279798));
	} else if (x <= 2.7) {
		tmp = 0.954929658551372 * x;
	} else {
		tmp = x * (-0.12900613773279798 * (x * x));
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= -2.7:
		tmp = x * (x * (x * -0.12900613773279798))
	elif x <= 2.7:
		tmp = 0.954929658551372 * x
	else:
		tmp = x * (-0.12900613773279798 * (x * x))
	return tmp
function code(x)
	tmp = 0.0
	if (x <= -2.7)
		tmp = Float64(x * Float64(x * Float64(x * -0.12900613773279798)));
	elseif (x <= 2.7)
		tmp = Float64(0.954929658551372 * x);
	else
		tmp = Float64(x * Float64(-0.12900613773279798 * Float64(x * x)));
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= -2.7)
		tmp = x * (x * (x * -0.12900613773279798));
	elseif (x <= 2.7)
		tmp = 0.954929658551372 * x;
	else
		tmp = x * (-0.12900613773279798 * (x * x));
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, -2.7], N[(x * N[(x * N[(x * -0.12900613773279798), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.7], N[(0.954929658551372 * x), $MachinePrecision], N[(x * N[(-0.12900613773279798 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.7:\\
\;\;\;\;x \cdot \left(x \cdot \left(x \cdot -0.12900613773279798\right)\right)\\

\mathbf{elif}\;x \leq 2.7:\\
\;\;\;\;0.954929658551372 \cdot x\\

\mathbf{else}:\\
\;\;\;\;x \cdot \left(-0.12900613773279798 \cdot \left(x \cdot x\right)\right)\\


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

    1. Initial program 99.8%

      \[0.954929658551372 \cdot x - 0.12900613773279798 \cdot \left(\left(x \cdot x\right) \cdot x\right) \]
    2. Step-by-step derivation
      1. associate-*r*99.8%

        \[\leadsto 0.954929658551372 \cdot x - \color{blue}{\left(0.12900613773279798 \cdot \left(x \cdot x\right)\right) \cdot x} \]
      2. distribute-rgt-out--99.8%

        \[\leadsto \color{blue}{x \cdot \left(0.954929658551372 - 0.12900613773279798 \cdot \left(x \cdot x\right)\right)} \]
      3. sub-neg99.8%

        \[\leadsto x \cdot \color{blue}{\left(0.954929658551372 + \left(-0.12900613773279798 \cdot \left(x \cdot x\right)\right)\right)} \]
      4. +-commutative99.8%

        \[\leadsto x \cdot \color{blue}{\left(\left(-0.12900613773279798 \cdot \left(x \cdot x\right)\right) + 0.954929658551372\right)} \]
      5. *-commutative99.8%

        \[\leadsto x \cdot \left(\left(-\color{blue}{\left(x \cdot x\right) \cdot 0.12900613773279798}\right) + 0.954929658551372\right) \]
      6. distribute-rgt-neg-in99.8%

        \[\leadsto x \cdot \left(\color{blue}{\left(x \cdot x\right) \cdot \left(-0.12900613773279798\right)} + 0.954929658551372\right) \]
      7. fma-def99.8%

        \[\leadsto x \cdot \color{blue}{\mathsf{fma}\left(x \cdot x, -0.12900613773279798, 0.954929658551372\right)} \]
      8. metadata-eval99.8%

        \[\leadsto x \cdot \mathsf{fma}\left(x \cdot x, \color{blue}{-0.12900613773279798}, 0.954929658551372\right) \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{x \cdot \mathsf{fma}\left(x \cdot x, -0.12900613773279798, 0.954929658551372\right)} \]
    4. Taylor expanded in x around inf 98.4%

      \[\leadsto x \cdot \color{blue}{\left(-0.12900613773279798 \cdot {x}^{2}\right)} \]
    5. Step-by-step derivation
      1. unpow298.4%

        \[\leadsto x \cdot \left(-0.12900613773279798 \cdot \color{blue}{\left(x \cdot x\right)}\right) \]
    6. Simplified98.4%

      \[\leadsto x \cdot \color{blue}{\left(-0.12900613773279798 \cdot \left(x \cdot x\right)\right)} \]
    7. Taylor expanded in x around 0 98.4%

      \[\leadsto x \cdot \color{blue}{\left(-0.12900613773279798 \cdot {x}^{2}\right)} \]
    8. Step-by-step derivation
      1. unpow298.4%

        \[\leadsto x \cdot \left(-0.12900613773279798 \cdot \color{blue}{\left(x \cdot x\right)}\right) \]
      2. *-commutative98.4%

        \[\leadsto x \cdot \color{blue}{\left(\left(x \cdot x\right) \cdot -0.12900613773279798\right)} \]
      3. associate-*l*98.4%

        \[\leadsto x \cdot \color{blue}{\left(x \cdot \left(x \cdot -0.12900613773279798\right)\right)} \]
    9. Simplified98.4%

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

    if -2.7000000000000002 < x < 2.7000000000000002

    1. Initial program 99.8%

      \[0.954929658551372 \cdot x - 0.12900613773279798 \cdot \left(\left(x \cdot x\right) \cdot x\right) \]
    2. Step-by-step derivation
      1. associate-*r*99.8%

        \[\leadsto 0.954929658551372 \cdot x - \color{blue}{\left(0.12900613773279798 \cdot \left(x \cdot x\right)\right) \cdot x} \]
      2. distribute-rgt-out--99.8%

        \[\leadsto \color{blue}{x \cdot \left(0.954929658551372 - 0.12900613773279798 \cdot \left(x \cdot x\right)\right)} \]
      3. sub-neg99.8%

        \[\leadsto x \cdot \color{blue}{\left(0.954929658551372 + \left(-0.12900613773279798 \cdot \left(x \cdot x\right)\right)\right)} \]
      4. +-commutative99.8%

        \[\leadsto x \cdot \color{blue}{\left(\left(-0.12900613773279798 \cdot \left(x \cdot x\right)\right) + 0.954929658551372\right)} \]
      5. *-commutative99.8%

        \[\leadsto x \cdot \left(\left(-\color{blue}{\left(x \cdot x\right) \cdot 0.12900613773279798}\right) + 0.954929658551372\right) \]
      6. distribute-rgt-neg-in99.8%

        \[\leadsto x \cdot \left(\color{blue}{\left(x \cdot x\right) \cdot \left(-0.12900613773279798\right)} + 0.954929658551372\right) \]
      7. fma-def99.8%

        \[\leadsto x \cdot \color{blue}{\mathsf{fma}\left(x \cdot x, -0.12900613773279798, 0.954929658551372\right)} \]
      8. metadata-eval99.8%

        \[\leadsto x \cdot \mathsf{fma}\left(x \cdot x, \color{blue}{-0.12900613773279798}, 0.954929658551372\right) \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{x \cdot \mathsf{fma}\left(x \cdot x, -0.12900613773279798, 0.954929658551372\right)} \]
    4. Taylor expanded in x around 0 99.8%

      \[\leadsto x \cdot \color{blue}{0.954929658551372} \]

    if 2.7000000000000002 < x

    1. Initial program 99.9%

      \[0.954929658551372 \cdot x - 0.12900613773279798 \cdot \left(\left(x \cdot x\right) \cdot x\right) \]
    2. Step-by-step derivation
      1. associate-*r*99.8%

        \[\leadsto 0.954929658551372 \cdot x - \color{blue}{\left(0.12900613773279798 \cdot \left(x \cdot x\right)\right) \cdot x} \]
      2. distribute-rgt-out--99.8%

        \[\leadsto \color{blue}{x \cdot \left(0.954929658551372 - 0.12900613773279798 \cdot \left(x \cdot x\right)\right)} \]
      3. sub-neg99.8%

        \[\leadsto x \cdot \color{blue}{\left(0.954929658551372 + \left(-0.12900613773279798 \cdot \left(x \cdot x\right)\right)\right)} \]
      4. +-commutative99.8%

        \[\leadsto x \cdot \color{blue}{\left(\left(-0.12900613773279798 \cdot \left(x \cdot x\right)\right) + 0.954929658551372\right)} \]
      5. *-commutative99.8%

        \[\leadsto x \cdot \left(\left(-\color{blue}{\left(x \cdot x\right) \cdot 0.12900613773279798}\right) + 0.954929658551372\right) \]
      6. distribute-rgt-neg-in99.8%

        \[\leadsto x \cdot \left(\color{blue}{\left(x \cdot x\right) \cdot \left(-0.12900613773279798\right)} + 0.954929658551372\right) \]
      7. fma-def99.8%

        \[\leadsto x \cdot \color{blue}{\mathsf{fma}\left(x \cdot x, -0.12900613773279798, 0.954929658551372\right)} \]
      8. metadata-eval99.8%

        \[\leadsto x \cdot \mathsf{fma}\left(x \cdot x, \color{blue}{-0.12900613773279798}, 0.954929658551372\right) \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{x \cdot \mathsf{fma}\left(x \cdot x, -0.12900613773279798, 0.954929658551372\right)} \]
    4. Taylor expanded in x around inf 99.8%

      \[\leadsto x \cdot \color{blue}{\left(-0.12900613773279798 \cdot {x}^{2}\right)} \]
    5. Step-by-step derivation
      1. unpow299.8%

        \[\leadsto x \cdot \left(-0.12900613773279798 \cdot \color{blue}{\left(x \cdot x\right)}\right) \]
    6. Simplified99.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.7:\\ \;\;\;\;x \cdot \left(x \cdot \left(x \cdot -0.12900613773279798\right)\right)\\ \mathbf{elif}\;x \leq 2.7:\\ \;\;\;\;0.954929658551372 \cdot x\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(-0.12900613773279798 \cdot \left(x \cdot x\right)\right)\\ \end{array} \]

Alternative 5: 99.8% accurate, 1.0× speedup?

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

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

    \[0.954929658551372 \cdot x - 0.12900613773279798 \cdot \left(\left(x \cdot x\right) \cdot x\right) \]
  2. Final simplification99.8%

    \[\leadsto 0.954929658551372 \cdot x - 0.12900613773279798 \cdot \left(x \cdot \left(x \cdot x\right)\right) \]

Alternative 6: 99.8% accurate, 1.2× speedup?

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

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

    \[0.954929658551372 \cdot x - 0.12900613773279798 \cdot \left(\left(x \cdot x\right) \cdot x\right) \]
  2. Step-by-step derivation
    1. associate-*r*99.8%

      \[\leadsto 0.954929658551372 \cdot x - \color{blue}{\left(0.12900613773279798 \cdot \left(x \cdot x\right)\right) \cdot x} \]
    2. distribute-rgt-out--99.8%

      \[\leadsto \color{blue}{x \cdot \left(0.954929658551372 - 0.12900613773279798 \cdot \left(x \cdot x\right)\right)} \]
    3. sub-neg99.8%

      \[\leadsto x \cdot \color{blue}{\left(0.954929658551372 + \left(-0.12900613773279798 \cdot \left(x \cdot x\right)\right)\right)} \]
    4. +-commutative99.8%

      \[\leadsto x \cdot \color{blue}{\left(\left(-0.12900613773279798 \cdot \left(x \cdot x\right)\right) + 0.954929658551372\right)} \]
    5. *-commutative99.8%

      \[\leadsto x \cdot \left(\left(-\color{blue}{\left(x \cdot x\right) \cdot 0.12900613773279798}\right) + 0.954929658551372\right) \]
    6. distribute-rgt-neg-in99.8%

      \[\leadsto x \cdot \left(\color{blue}{\left(x \cdot x\right) \cdot \left(-0.12900613773279798\right)} + 0.954929658551372\right) \]
    7. fma-def99.8%

      \[\leadsto x \cdot \color{blue}{\mathsf{fma}\left(x \cdot x, -0.12900613773279798, 0.954929658551372\right)} \]
    8. metadata-eval99.8%

      \[\leadsto x \cdot \mathsf{fma}\left(x \cdot x, \color{blue}{-0.12900613773279798}, 0.954929658551372\right) \]
  3. Simplified99.8%

    \[\leadsto \color{blue}{x \cdot \mathsf{fma}\left(x \cdot x, -0.12900613773279798, 0.954929658551372\right)} \]
  4. Step-by-step derivation
    1. fma-udef99.8%

      \[\leadsto x \cdot \color{blue}{\left(\left(x \cdot x\right) \cdot -0.12900613773279798 + 0.954929658551372\right)} \]
    2. associate-*l*99.8%

      \[\leadsto x \cdot \left(\color{blue}{x \cdot \left(x \cdot -0.12900613773279798\right)} + 0.954929658551372\right) \]
  5. Applied egg-rr99.8%

    \[\leadsto x \cdot \color{blue}{\left(x \cdot \left(x \cdot -0.12900613773279798\right) + 0.954929658551372\right)} \]
  6. Final simplification99.8%

    \[\leadsto x \cdot \left(0.954929658551372 + x \cdot \left(x \cdot -0.12900613773279798\right)\right) \]

Alternative 7: 5.0% accurate, 3.7× speedup?

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

\\
x \cdot -0.954929658551372
\end{array}
Derivation
  1. Initial program 99.8%

    \[0.954929658551372 \cdot x - 0.12900613773279798 \cdot \left(\left(x \cdot x\right) \cdot x\right) \]
  2. Step-by-step derivation
    1. associate-*r*99.8%

      \[\leadsto 0.954929658551372 \cdot x - \color{blue}{\left(0.12900613773279798 \cdot \left(x \cdot x\right)\right) \cdot x} \]
    2. distribute-rgt-out--99.8%

      \[\leadsto \color{blue}{x \cdot \left(0.954929658551372 - 0.12900613773279798 \cdot \left(x \cdot x\right)\right)} \]
    3. sub-neg99.8%

      \[\leadsto x \cdot \color{blue}{\left(0.954929658551372 + \left(-0.12900613773279798 \cdot \left(x \cdot x\right)\right)\right)} \]
    4. +-commutative99.8%

      \[\leadsto x \cdot \color{blue}{\left(\left(-0.12900613773279798 \cdot \left(x \cdot x\right)\right) + 0.954929658551372\right)} \]
    5. *-commutative99.8%

      \[\leadsto x \cdot \left(\left(-\color{blue}{\left(x \cdot x\right) \cdot 0.12900613773279798}\right) + 0.954929658551372\right) \]
    6. distribute-rgt-neg-in99.8%

      \[\leadsto x \cdot \left(\color{blue}{\left(x \cdot x\right) \cdot \left(-0.12900613773279798\right)} + 0.954929658551372\right) \]
    7. fma-def99.8%

      \[\leadsto x \cdot \color{blue}{\mathsf{fma}\left(x \cdot x, -0.12900613773279798, 0.954929658551372\right)} \]
    8. metadata-eval99.8%

      \[\leadsto x \cdot \mathsf{fma}\left(x \cdot x, \color{blue}{-0.12900613773279798}, 0.954929658551372\right) \]
  3. Simplified99.8%

    \[\leadsto \color{blue}{x \cdot \mathsf{fma}\left(x \cdot x, -0.12900613773279798, 0.954929658551372\right)} \]
  4. Taylor expanded in x around 0 48.9%

    \[\leadsto x \cdot \color{blue}{0.954929658551372} \]
  5. Step-by-step derivation
    1. add-sqr-sqrt23.0%

      \[\leadsto \color{blue}{\sqrt{x \cdot 0.954929658551372} \cdot \sqrt{x \cdot 0.954929658551372}} \]
    2. sqrt-unprod29.8%

      \[\leadsto \color{blue}{\sqrt{\left(x \cdot 0.954929658551372\right) \cdot \left(x \cdot 0.954929658551372\right)}} \]
    3. *-commutative29.8%

      \[\leadsto \sqrt{\left(x \cdot 0.954929658551372\right) \cdot \color{blue}{\left(0.954929658551372 \cdot x\right)}} \]
    4. *-commutative29.8%

      \[\leadsto \sqrt{\color{blue}{\left(0.954929658551372 \cdot x\right)} \cdot \left(0.954929658551372 \cdot x\right)} \]
    5. swap-sqr29.8%

      \[\leadsto \sqrt{\color{blue}{\left(0.954929658551372 \cdot 0.954929658551372\right) \cdot \left(x \cdot x\right)}} \]
    6. metadata-eval29.8%

      \[\leadsto \sqrt{\color{blue}{0.9118906527810399} \cdot \left(x \cdot x\right)} \]
  6. Applied egg-rr29.8%

    \[\leadsto \color{blue}{\sqrt{0.9118906527810399 \cdot \left(x \cdot x\right)}} \]
  7. Step-by-step derivation
    1. *-commutative29.8%

      \[\leadsto \sqrt{\color{blue}{\left(x \cdot x\right) \cdot 0.9118906527810399}} \]
    2. associate-*l*29.8%

      \[\leadsto \sqrt{\color{blue}{x \cdot \left(x \cdot 0.9118906527810399\right)}} \]
  8. Simplified29.8%

    \[\leadsto \color{blue}{\sqrt{x \cdot \left(x \cdot 0.9118906527810399\right)}} \]
  9. Taylor expanded in x around -inf 4.9%

    \[\leadsto \color{blue}{-0.954929658551372 \cdot x} \]
  10. Step-by-step derivation
    1. *-commutative4.9%

      \[\leadsto \color{blue}{x \cdot -0.954929658551372} \]
  11. Simplified4.9%

    \[\leadsto \color{blue}{x \cdot -0.954929658551372} \]
  12. Final simplification4.9%

    \[\leadsto x \cdot -0.954929658551372 \]

Alternative 8: 50.3% accurate, 3.7× speedup?

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

\\
0.954929658551372 \cdot x
\end{array}
Derivation
  1. Initial program 99.8%

    \[0.954929658551372 \cdot x - 0.12900613773279798 \cdot \left(\left(x \cdot x\right) \cdot x\right) \]
  2. Step-by-step derivation
    1. associate-*r*99.8%

      \[\leadsto 0.954929658551372 \cdot x - \color{blue}{\left(0.12900613773279798 \cdot \left(x \cdot x\right)\right) \cdot x} \]
    2. distribute-rgt-out--99.8%

      \[\leadsto \color{blue}{x \cdot \left(0.954929658551372 - 0.12900613773279798 \cdot \left(x \cdot x\right)\right)} \]
    3. sub-neg99.8%

      \[\leadsto x \cdot \color{blue}{\left(0.954929658551372 + \left(-0.12900613773279798 \cdot \left(x \cdot x\right)\right)\right)} \]
    4. +-commutative99.8%

      \[\leadsto x \cdot \color{blue}{\left(\left(-0.12900613773279798 \cdot \left(x \cdot x\right)\right) + 0.954929658551372\right)} \]
    5. *-commutative99.8%

      \[\leadsto x \cdot \left(\left(-\color{blue}{\left(x \cdot x\right) \cdot 0.12900613773279798}\right) + 0.954929658551372\right) \]
    6. distribute-rgt-neg-in99.8%

      \[\leadsto x \cdot \left(\color{blue}{\left(x \cdot x\right) \cdot \left(-0.12900613773279798\right)} + 0.954929658551372\right) \]
    7. fma-def99.8%

      \[\leadsto x \cdot \color{blue}{\mathsf{fma}\left(x \cdot x, -0.12900613773279798, 0.954929658551372\right)} \]
    8. metadata-eval99.8%

      \[\leadsto x \cdot \mathsf{fma}\left(x \cdot x, \color{blue}{-0.12900613773279798}, 0.954929658551372\right) \]
  3. Simplified99.8%

    \[\leadsto \color{blue}{x \cdot \mathsf{fma}\left(x \cdot x, -0.12900613773279798, 0.954929658551372\right)} \]
  4. Taylor expanded in x around 0 48.9%

    \[\leadsto x \cdot \color{blue}{0.954929658551372} \]
  5. Final simplification48.9%

    \[\leadsto 0.954929658551372 \cdot x \]

Reproduce

?
herbie shell --seed 2023178 
(FPCore (x)
  :name "Rosa's Benchmark"
  :precision binary64
  (- (* 0.954929658551372 x) (* 0.12900613773279798 (* (* x x) x))))