Rosa's Benchmark

Percentage Accurate: 99.8% → 99.8%
Time: 9.9s
Alternatives: 3
Speedup: 1.4×

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 3 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, 1.4× 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.4%

    \[0.954929658551372 \cdot x - 0.12900613773279798 \cdot \left(\left(x \cdot x\right) \cdot x\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. sub-negN/A

      \[\leadsto \color{blue}{\frac{238732414637843}{250000000000000} \cdot x + \left(\mathsf{neg}\left(\frac{6450306886639899}{50000000000000000} \cdot \left(\left(x \cdot x\right) \cdot x\right)\right)\right)} \]
    2. +-commutativeN/A

      \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\frac{6450306886639899}{50000000000000000} \cdot \left(\left(x \cdot x\right) \cdot x\right)\right)\right) + \frac{238732414637843}{250000000000000} \cdot x} \]
    3. associate-*r*N/A

      \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\left(\frac{6450306886639899}{50000000000000000} \cdot \left(x \cdot x\right)\right) \cdot x}\right)\right) + \frac{238732414637843}{250000000000000} \cdot x \]
    4. distribute-lft-neg-inN/A

      \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\frac{6450306886639899}{50000000000000000} \cdot \left(x \cdot x\right)\right)\right) \cdot x} + \frac{238732414637843}{250000000000000} \cdot x \]
    5. distribute-rgt-outN/A

      \[\leadsto \color{blue}{x \cdot \left(\left(\mathsf{neg}\left(\frac{6450306886639899}{50000000000000000} \cdot \left(x \cdot x\right)\right)\right) + \frac{238732414637843}{250000000000000}\right)} \]
    6. *-lowering-*.f64N/A

      \[\leadsto \color{blue}{x \cdot \left(\left(\mathsf{neg}\left(\frac{6450306886639899}{50000000000000000} \cdot \left(x \cdot x\right)\right)\right) + \frac{238732414637843}{250000000000000}\right)} \]
    7. *-commutativeN/A

      \[\leadsto x \cdot \left(\left(\mathsf{neg}\left(\color{blue}{\left(x \cdot x\right) \cdot \frac{6450306886639899}{50000000000000000}}\right)\right) + \frac{238732414637843}{250000000000000}\right) \]
    8. distribute-rgt-neg-inN/A

      \[\leadsto x \cdot \left(\color{blue}{\left(x \cdot x\right) \cdot \left(\mathsf{neg}\left(\frac{6450306886639899}{50000000000000000}\right)\right)} + \frac{238732414637843}{250000000000000}\right) \]
    9. accelerator-lowering-fma.f64N/A

      \[\leadsto x \cdot \color{blue}{\mathsf{fma}\left(x \cdot x, \mathsf{neg}\left(\frac{6450306886639899}{50000000000000000}\right), \frac{238732414637843}{250000000000000}\right)} \]
    10. *-lowering-*.f64N/A

      \[\leadsto x \cdot \mathsf{fma}\left(\color{blue}{x \cdot x}, \mathsf{neg}\left(\frac{6450306886639899}{50000000000000000}\right), \frac{238732414637843}{250000000000000}\right) \]
    11. metadata-eval99.8

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

    \[\leadsto \color{blue}{x \cdot \mathsf{fma}\left(x \cdot x, -0.12900613773279798, 0.954929658551372\right)} \]
  5. Add Preprocessing

Alternative 2: 74.2% accurate, 0.5× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (*.f64 #s(literal 238732414637843/250000000000000 binary64) x) (*.f64 #s(literal 6450306886639899/50000000000000000 binary64) (*.f64 (*.f64 x x) x))) < -2e6

    1. Initial program 98.7%

      \[0.954929658551372 \cdot x - 0.12900613773279798 \cdot \left(\left(x \cdot x\right) \cdot x\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. sub-negN/A

        \[\leadsto \color{blue}{\frac{238732414637843}{250000000000000} \cdot x + \left(\mathsf{neg}\left(\frac{6450306886639899}{50000000000000000} \cdot \left(\left(x \cdot x\right) \cdot x\right)\right)\right)} \]
      2. +-commutativeN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\frac{6450306886639899}{50000000000000000} \cdot \left(\left(x \cdot x\right) \cdot x\right)\right)\right) + \frac{238732414637843}{250000000000000} \cdot x} \]
      3. associate-*r*N/A

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\left(\frac{6450306886639899}{50000000000000000} \cdot \left(x \cdot x\right)\right) \cdot x}\right)\right) + \frac{238732414637843}{250000000000000} \cdot x \]
      4. distribute-lft-neg-inN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\frac{6450306886639899}{50000000000000000} \cdot \left(x \cdot x\right)\right)\right) \cdot x} + \frac{238732414637843}{250000000000000} \cdot x \]
      5. distribute-rgt-outN/A

        \[\leadsto \color{blue}{x \cdot \left(\left(\mathsf{neg}\left(\frac{6450306886639899}{50000000000000000} \cdot \left(x \cdot x\right)\right)\right) + \frac{238732414637843}{250000000000000}\right)} \]
      6. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{x \cdot \left(\left(\mathsf{neg}\left(\frac{6450306886639899}{50000000000000000} \cdot \left(x \cdot x\right)\right)\right) + \frac{238732414637843}{250000000000000}\right)} \]
      7. *-commutativeN/A

        \[\leadsto x \cdot \left(\left(\mathsf{neg}\left(\color{blue}{\left(x \cdot x\right) \cdot \frac{6450306886639899}{50000000000000000}}\right)\right) + \frac{238732414637843}{250000000000000}\right) \]
      8. distribute-rgt-neg-inN/A

        \[\leadsto x \cdot \left(\color{blue}{\left(x \cdot x\right) \cdot \left(\mathsf{neg}\left(\frac{6450306886639899}{50000000000000000}\right)\right)} + \frac{238732414637843}{250000000000000}\right) \]
      9. accelerator-lowering-fma.f64N/A

        \[\leadsto x \cdot \color{blue}{\mathsf{fma}\left(x \cdot x, \mathsf{neg}\left(\frac{6450306886639899}{50000000000000000}\right), \frac{238732414637843}{250000000000000}\right)} \]
      10. *-lowering-*.f64N/A

        \[\leadsto x \cdot \mathsf{fma}\left(\color{blue}{x \cdot x}, \mathsf{neg}\left(\frac{6450306886639899}{50000000000000000}\right), \frac{238732414637843}{250000000000000}\right) \]
      11. metadata-eval99.8

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

      \[\leadsto \color{blue}{x \cdot \mathsf{fma}\left(x \cdot x, -0.12900613773279798, 0.954929658551372\right)} \]
    5. Step-by-step derivation
      1. flip-+N/A

        \[\leadsto x \cdot \color{blue}{\frac{\left(\left(x \cdot x\right) \cdot \frac{-6450306886639899}{50000000000000000}\right) \cdot \left(\left(x \cdot x\right) \cdot \frac{-6450306886639899}{50000000000000000}\right) - \frac{238732414637843}{250000000000000} \cdot \frac{238732414637843}{250000000000000}}{\left(x \cdot x\right) \cdot \frac{-6450306886639899}{50000000000000000} - \frac{238732414637843}{250000000000000}}} \]
      2. clear-numN/A

        \[\leadsto x \cdot \color{blue}{\frac{1}{\frac{\left(x \cdot x\right) \cdot \frac{-6450306886639899}{50000000000000000} - \frac{238732414637843}{250000000000000}}{\left(\left(x \cdot x\right) \cdot \frac{-6450306886639899}{50000000000000000}\right) \cdot \left(\left(x \cdot x\right) \cdot \frac{-6450306886639899}{50000000000000000}\right) - \frac{238732414637843}{250000000000000} \cdot \frac{238732414637843}{250000000000000}}}} \]
      3. un-div-invN/A

        \[\leadsto \color{blue}{\frac{x}{\frac{\left(x \cdot x\right) \cdot \frac{-6450306886639899}{50000000000000000} - \frac{238732414637843}{250000000000000}}{\left(\left(x \cdot x\right) \cdot \frac{-6450306886639899}{50000000000000000}\right) \cdot \left(\left(x \cdot x\right) \cdot \frac{-6450306886639899}{50000000000000000}\right) - \frac{238732414637843}{250000000000000} \cdot \frac{238732414637843}{250000000000000}}}} \]
      4. /-lowering-/.f64N/A

        \[\leadsto \color{blue}{\frac{x}{\frac{\left(x \cdot x\right) \cdot \frac{-6450306886639899}{50000000000000000} - \frac{238732414637843}{250000000000000}}{\left(\left(x \cdot x\right) \cdot \frac{-6450306886639899}{50000000000000000}\right) \cdot \left(\left(x \cdot x\right) \cdot \frac{-6450306886639899}{50000000000000000}\right) - \frac{238732414637843}{250000000000000} \cdot \frac{238732414637843}{250000000000000}}}} \]
      5. swap-sqrN/A

        \[\leadsto \frac{x}{\frac{\left(x \cdot x\right) \cdot \frac{-6450306886639899}{50000000000000000} - \frac{238732414637843}{250000000000000}}{\color{blue}{\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right) \cdot \left(\frac{-6450306886639899}{50000000000000000} \cdot \frac{-6450306886639899}{50000000000000000}\right)} - \frac{238732414637843}{250000000000000} \cdot \frac{238732414637843}{250000000000000}}} \]
      6. metadata-evalN/A

        \[\leadsto \frac{x}{\frac{\left(x \cdot x\right) \cdot \frac{-6450306886639899}{50000000000000000} - \frac{238732414637843}{250000000000000}}{\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right) \cdot \color{blue}{\frac{41606458931834106848498498730201}{2500000000000000000000000000000000}} - \frac{238732414637843}{250000000000000} \cdot \frac{238732414637843}{250000000000000}}} \]
      7. metadata-evalN/A

        \[\leadsto \frac{x}{\frac{\left(x \cdot x\right) \cdot \frac{-6450306886639899}{50000000000000000} - \frac{238732414637843}{250000000000000}}{\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right) \cdot \color{blue}{\left(\frac{6450306886639899}{50000000000000000} \cdot \frac{6450306886639899}{50000000000000000}\right)} - \frac{238732414637843}{250000000000000} \cdot \frac{238732414637843}{250000000000000}}} \]
      8. swap-sqrN/A

        \[\leadsto \frac{x}{\frac{\left(x \cdot x\right) \cdot \frac{-6450306886639899}{50000000000000000} - \frac{238732414637843}{250000000000000}}{\color{blue}{\left(\left(x \cdot x\right) \cdot \frac{6450306886639899}{50000000000000000}\right) \cdot \left(\left(x \cdot x\right) \cdot \frac{6450306886639899}{50000000000000000}\right)} - \frac{238732414637843}{250000000000000} \cdot \frac{238732414637843}{250000000000000}}} \]
      9. associate-*r*N/A

        \[\leadsto \frac{x}{\frac{\left(x \cdot x\right) \cdot \frac{-6450306886639899}{50000000000000000} - \frac{238732414637843}{250000000000000}}{\color{blue}{\left(x \cdot \left(x \cdot \frac{6450306886639899}{50000000000000000}\right)\right)} \cdot \left(\left(x \cdot x\right) \cdot \frac{6450306886639899}{50000000000000000}\right) - \frac{238732414637843}{250000000000000} \cdot \frac{238732414637843}{250000000000000}}} \]
      10. associate-*r*N/A

        \[\leadsto \frac{x}{\frac{\left(x \cdot x\right) \cdot \frac{-6450306886639899}{50000000000000000} - \frac{238732414637843}{250000000000000}}{\left(x \cdot \left(x \cdot \frac{6450306886639899}{50000000000000000}\right)\right) \cdot \color{blue}{\left(x \cdot \left(x \cdot \frac{6450306886639899}{50000000000000000}\right)\right)} - \frac{238732414637843}{250000000000000} \cdot \frac{238732414637843}{250000000000000}}} \]
      11. clear-numN/A

        \[\leadsto \frac{x}{\color{blue}{\frac{1}{\frac{\left(x \cdot \left(x \cdot \frac{6450306886639899}{50000000000000000}\right)\right) \cdot \left(x \cdot \left(x \cdot \frac{6450306886639899}{50000000000000000}\right)\right) - \frac{238732414637843}{250000000000000} \cdot \frac{238732414637843}{250000000000000}}{\left(x \cdot x\right) \cdot \frac{-6450306886639899}{50000000000000000} - \frac{238732414637843}{250000000000000}}}}} \]
    6. Applied egg-rr99.8%

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

      \[\leadsto \frac{x}{\color{blue}{\frac{\frac{-50000000000000000}{6450306886639899}}{{x}^{2}}}} \]
    8. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \frac{x}{\color{blue}{\frac{\frac{-50000000000000000}{6450306886639899}}{{x}^{2}}}} \]
      2. remove-double-negN/A

        \[\leadsto \frac{x}{\frac{\frac{-50000000000000000}{6450306886639899}}{\color{blue}{\mathsf{neg}\left(\left(\mathsf{neg}\left({x}^{2}\right)\right)\right)}}} \]
      3. +-rgt-identityN/A

        \[\leadsto \frac{x}{\frac{\frac{-50000000000000000}{6450306886639899}}{\mathsf{neg}\left(\color{blue}{\left(\left(\mathsf{neg}\left({x}^{2}\right)\right) + 0\right)}\right)}} \]
      4. distribute-neg-inN/A

        \[\leadsto \frac{x}{\frac{\frac{-50000000000000000}{6450306886639899}}{\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left({x}^{2}\right)\right)\right)\right) + \left(\mathsf{neg}\left(0\right)\right)}}} \]
      5. remove-double-negN/A

        \[\leadsto \frac{x}{\frac{\frac{-50000000000000000}{6450306886639899}}{\color{blue}{{x}^{2}} + \left(\mathsf{neg}\left(0\right)\right)}} \]
      6. unpow2N/A

        \[\leadsto \frac{x}{\frac{\frac{-50000000000000000}{6450306886639899}}{\color{blue}{x \cdot x} + \left(\mathsf{neg}\left(0\right)\right)}} \]
      7. metadata-evalN/A

        \[\leadsto \frac{x}{\frac{\frac{-50000000000000000}{6450306886639899}}{x \cdot x + \color{blue}{0}}} \]
      8. accelerator-lowering-fma.f6496.6

        \[\leadsto \frac{x}{\frac{-7.751569170074954}{\color{blue}{\mathsf{fma}\left(x, x, 0\right)}}} \]
    9. Simplified96.6%

      \[\leadsto \frac{x}{\color{blue}{\frac{-7.751569170074954}{\mathsf{fma}\left(x, x, 0\right)}}} \]
    10. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{-6450306886639899}{50000000000000000} \cdot {x}^{3}} \]
    11. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{{x}^{3} \cdot \frac{-6450306886639899}{50000000000000000}} \]
      2. cube-multN/A

        \[\leadsto \color{blue}{\left(x \cdot \left(x \cdot x\right)\right)} \cdot \frac{-6450306886639899}{50000000000000000} \]
      3. unpow2N/A

        \[\leadsto \left(x \cdot \color{blue}{{x}^{2}}\right) \cdot \frac{-6450306886639899}{50000000000000000} \]
      4. associate-*l*N/A

        \[\leadsto \color{blue}{x \cdot \left({x}^{2} \cdot \frac{-6450306886639899}{50000000000000000}\right)} \]
      5. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{x \cdot \left({x}^{2} \cdot \frac{-6450306886639899}{50000000000000000}\right)} \]
      6. unpow2N/A

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

        \[\leadsto x \cdot \color{blue}{\left(x \cdot \left(x \cdot \frac{-6450306886639899}{50000000000000000}\right)\right)} \]
      8. *-lowering-*.f64N/A

        \[\leadsto x \cdot \color{blue}{\left(x \cdot \left(x \cdot \frac{-6450306886639899}{50000000000000000}\right)\right)} \]
      9. *-lowering-*.f6496.6

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

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

    if -2e6 < (-.f64 (*.f64 #s(literal 238732414637843/250000000000000 binary64) x) (*.f64 #s(literal 6450306886639899/50000000000000000 binary64) (*.f64 (*.f64 x x) x)))

    1. Initial program 99.7%

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

      \[\leadsto \color{blue}{\frac{238732414637843}{250000000000000} \cdot x} \]
    4. Step-by-step derivation
      1. metadata-evalN/A

        \[\leadsto \color{blue}{\left(\frac{238732414637843}{250000000000000} \cdot 1\right)} \cdot x \]
      2. lft-mult-inverseN/A

        \[\leadsto \left(\frac{238732414637843}{250000000000000} \cdot \color{blue}{\left(\frac{1}{\mathsf{neg}\left({x}^{2}\right)} \cdot \left(\mathsf{neg}\left({x}^{2}\right)\right)\right)}\right) \cdot x \]
      3. distribute-neg-frac2N/A

        \[\leadsto \left(\frac{238732414637843}{250000000000000} \cdot \left(\color{blue}{\left(\mathsf{neg}\left(\frac{1}{{x}^{2}}\right)\right)} \cdot \left(\mathsf{neg}\left({x}^{2}\right)\right)\right)\right) \cdot x \]
      4. associate-*l*N/A

        \[\leadsto \color{blue}{\left(\left(\frac{238732414637843}{250000000000000} \cdot \left(\mathsf{neg}\left(\frac{1}{{x}^{2}}\right)\right)\right) \cdot \left(\mathsf{neg}\left({x}^{2}\right)\right)\right)} \cdot x \]
      5. distribute-rgt-neg-inN/A

        \[\leadsto \left(\color{blue}{\left(\mathsf{neg}\left(\frac{238732414637843}{250000000000000} \cdot \frac{1}{{x}^{2}}\right)\right)} \cdot \left(\mathsf{neg}\left({x}^{2}\right)\right)\right) \cdot x \]
      6. associate-*r*N/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\frac{238732414637843}{250000000000000} \cdot \frac{1}{{x}^{2}}\right)\right) \cdot \left(\left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot x\right)} \]
      7. distribute-lft-neg-inN/A

        \[\leadsto \left(\mathsf{neg}\left(\frac{238732414637843}{250000000000000} \cdot \frac{1}{{x}^{2}}\right)\right) \cdot \color{blue}{\left(\mathsf{neg}\left({x}^{2} \cdot x\right)\right)} \]
      8. unpow2N/A

        \[\leadsto \left(\mathsf{neg}\left(\frac{238732414637843}{250000000000000} \cdot \frac{1}{{x}^{2}}\right)\right) \cdot \left(\mathsf{neg}\left(\color{blue}{\left(x \cdot x\right)} \cdot x\right)\right) \]
      9. unpow3N/A

        \[\leadsto \left(\mathsf{neg}\left(\frac{238732414637843}{250000000000000} \cdot \frac{1}{{x}^{2}}\right)\right) \cdot \left(\mathsf{neg}\left(\color{blue}{{x}^{3}}\right)\right) \]
      10. mul-1-negN/A

        \[\leadsto \left(\mathsf{neg}\left(\frac{238732414637843}{250000000000000} \cdot \frac{1}{{x}^{2}}\right)\right) \cdot \color{blue}{\left(-1 \cdot {x}^{3}\right)} \]
      11. *-commutativeN/A

        \[\leadsto \color{blue}{\left(-1 \cdot {x}^{3}\right) \cdot \left(\mathsf{neg}\left(\frac{238732414637843}{250000000000000} \cdot \frac{1}{{x}^{2}}\right)\right)} \]
      12. +-rgt-identityN/A

        \[\leadsto \color{blue}{\left(-1 \cdot {x}^{3}\right) \cdot \left(\mathsf{neg}\left(\frac{238732414637843}{250000000000000} \cdot \frac{1}{{x}^{2}}\right)\right) + 0} \]
      13. *-commutativeN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\frac{238732414637843}{250000000000000} \cdot \frac{1}{{x}^{2}}\right)\right) \cdot \left(-1 \cdot {x}^{3}\right)} + 0 \]
    5. Simplified59.3%

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.954929658551372, x, 0\right)} \]
    6. Step-by-step derivation
      1. +-rgt-identityN/A

        \[\leadsto \color{blue}{\frac{238732414637843}{250000000000000} \cdot x} \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{x \cdot \frac{238732414637843}{250000000000000}} \]
      3. *-lowering-*.f6459.3

        \[\leadsto \color{blue}{x \cdot 0.954929658551372} \]
    7. Applied egg-rr59.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot 0.954929658551372 - 0.12900613773279798 \cdot \left(x \cdot \left(x \cdot x\right)\right) \leq -2000000:\\ \;\;\;\;x \cdot \left(x \cdot \left(x \cdot -0.12900613773279798\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 0.954929658551372\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 49.2% accurate, 4.0× 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.4%

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

    \[\leadsto \color{blue}{\frac{238732414637843}{250000000000000} \cdot x} \]
  4. Step-by-step derivation
    1. metadata-evalN/A

      \[\leadsto \color{blue}{\left(\frac{238732414637843}{250000000000000} \cdot 1\right)} \cdot x \]
    2. lft-mult-inverseN/A

      \[\leadsto \left(\frac{238732414637843}{250000000000000} \cdot \color{blue}{\left(\frac{1}{\mathsf{neg}\left({x}^{2}\right)} \cdot \left(\mathsf{neg}\left({x}^{2}\right)\right)\right)}\right) \cdot x \]
    3. distribute-neg-frac2N/A

      \[\leadsto \left(\frac{238732414637843}{250000000000000} \cdot \left(\color{blue}{\left(\mathsf{neg}\left(\frac{1}{{x}^{2}}\right)\right)} \cdot \left(\mathsf{neg}\left({x}^{2}\right)\right)\right)\right) \cdot x \]
    4. associate-*l*N/A

      \[\leadsto \color{blue}{\left(\left(\frac{238732414637843}{250000000000000} \cdot \left(\mathsf{neg}\left(\frac{1}{{x}^{2}}\right)\right)\right) \cdot \left(\mathsf{neg}\left({x}^{2}\right)\right)\right)} \cdot x \]
    5. distribute-rgt-neg-inN/A

      \[\leadsto \left(\color{blue}{\left(\mathsf{neg}\left(\frac{238732414637843}{250000000000000} \cdot \frac{1}{{x}^{2}}\right)\right)} \cdot \left(\mathsf{neg}\left({x}^{2}\right)\right)\right) \cdot x \]
    6. associate-*r*N/A

      \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\frac{238732414637843}{250000000000000} \cdot \frac{1}{{x}^{2}}\right)\right) \cdot \left(\left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot x\right)} \]
    7. distribute-lft-neg-inN/A

      \[\leadsto \left(\mathsf{neg}\left(\frac{238732414637843}{250000000000000} \cdot \frac{1}{{x}^{2}}\right)\right) \cdot \color{blue}{\left(\mathsf{neg}\left({x}^{2} \cdot x\right)\right)} \]
    8. unpow2N/A

      \[\leadsto \left(\mathsf{neg}\left(\frac{238732414637843}{250000000000000} \cdot \frac{1}{{x}^{2}}\right)\right) \cdot \left(\mathsf{neg}\left(\color{blue}{\left(x \cdot x\right)} \cdot x\right)\right) \]
    9. unpow3N/A

      \[\leadsto \left(\mathsf{neg}\left(\frac{238732414637843}{250000000000000} \cdot \frac{1}{{x}^{2}}\right)\right) \cdot \left(\mathsf{neg}\left(\color{blue}{{x}^{3}}\right)\right) \]
    10. mul-1-negN/A

      \[\leadsto \left(\mathsf{neg}\left(\frac{238732414637843}{250000000000000} \cdot \frac{1}{{x}^{2}}\right)\right) \cdot \color{blue}{\left(-1 \cdot {x}^{3}\right)} \]
    11. *-commutativeN/A

      \[\leadsto \color{blue}{\left(-1 \cdot {x}^{3}\right) \cdot \left(\mathsf{neg}\left(\frac{238732414637843}{250000000000000} \cdot \frac{1}{{x}^{2}}\right)\right)} \]
    12. +-rgt-identityN/A

      \[\leadsto \color{blue}{\left(-1 \cdot {x}^{3}\right) \cdot \left(\mathsf{neg}\left(\frac{238732414637843}{250000000000000} \cdot \frac{1}{{x}^{2}}\right)\right) + 0} \]
    13. *-commutativeN/A

      \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\frac{238732414637843}{250000000000000} \cdot \frac{1}{{x}^{2}}\right)\right) \cdot \left(-1 \cdot {x}^{3}\right)} + 0 \]
  5. Simplified42.7%

    \[\leadsto \color{blue}{\mathsf{fma}\left(0.954929658551372, x, 0\right)} \]
  6. Step-by-step derivation
    1. +-rgt-identityN/A

      \[\leadsto \color{blue}{\frac{238732414637843}{250000000000000} \cdot x} \]
    2. *-commutativeN/A

      \[\leadsto \color{blue}{x \cdot \frac{238732414637843}{250000000000000}} \]
    3. *-lowering-*.f6442.7

      \[\leadsto \color{blue}{x \cdot 0.954929658551372} \]
  7. Applied egg-rr42.7%

    \[\leadsto \color{blue}{x \cdot 0.954929658551372} \]
  8. Add Preprocessing

Reproduce

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