ENA, Section 1.4, Mentioned, A

Percentage Accurate: 53.1% → 100.0%
Time: 15.9s
Alternatives: 8
Speedup: 9.5×

Specification

?
\[-0.01 \leq x \land x \leq 0.01\]
\[\begin{array}{l} \\ 1 - \cos x \end{array} \]
(FPCore (x) :precision binary64 (- 1.0 (cos x)))
double code(double x) {
	return 1.0 - cos(x);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 1.0d0 - cos(x)
end function
public static double code(double x) {
	return 1.0 - Math.cos(x);
}
def code(x):
	return 1.0 - math.cos(x)
function code(x)
	return Float64(1.0 - cos(x))
end
function tmp = code(x)
	tmp = 1.0 - cos(x);
end
code[x_] := N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
1 - \cos x
\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: 53.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ 1 - \cos x \end{array} \]
(FPCore (x) :precision binary64 (- 1.0 (cos x)))
double code(double x) {
	return 1.0 - cos(x);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 1.0d0 - cos(x)
end function
public static double code(double x) {
	return 1.0 - Math.cos(x);
}
def code(x):
	return 1.0 - math.cos(x)
function code(x)
	return Float64(1.0 - cos(x))
end
function tmp = code(x)
	tmp = 1.0 - cos(x);
end
code[x_] := N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
1 - \cos x
\end{array}

Alternative 1: 100.0% accurate, 0.8× speedup?

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

\\
\sin x \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, x \cdot 0.004166666666666667, 0.041666666666666664\right), 0.5\right)\right)
\end{array}
Derivation
  1. Initial program 52.0%

    \[1 - \cos x \]
  2. Add Preprocessing
  3. Applied egg-rr100.0%

    \[\leadsto \color{blue}{\sin x \cdot \tan \left(\frac{x}{2}\right)} \]
  4. Taylor expanded in x around 0

    \[\leadsto \sin x \cdot \color{blue}{\left(x \cdot \left(\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{24} + \frac{1}{240} \cdot {x}^{2}\right)\right)\right)} \]
  5. Step-by-step derivation
    1. *-lowering-*.f64N/A

      \[\leadsto \sin x \cdot \color{blue}{\left(x \cdot \left(\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{24} + \frac{1}{240} \cdot {x}^{2}\right)\right)\right)} \]
    2. +-commutativeN/A

      \[\leadsto \sin x \cdot \left(x \cdot \color{blue}{\left({x}^{2} \cdot \left(\frac{1}{24} + \frac{1}{240} \cdot {x}^{2}\right) + \frac{1}{2}\right)}\right) \]
    3. unpow2N/A

      \[\leadsto \sin x \cdot \left(x \cdot \left(\color{blue}{\left(x \cdot x\right)} \cdot \left(\frac{1}{24} + \frac{1}{240} \cdot {x}^{2}\right) + \frac{1}{2}\right)\right) \]
    4. associate-*l*N/A

      \[\leadsto \sin x \cdot \left(x \cdot \left(\color{blue}{x \cdot \left(x \cdot \left(\frac{1}{24} + \frac{1}{240} \cdot {x}^{2}\right)\right)} + \frac{1}{2}\right)\right) \]
    5. *-commutativeN/A

      \[\leadsto \sin x \cdot \left(x \cdot \left(x \cdot \color{blue}{\left(\left(\frac{1}{24} + \frac{1}{240} \cdot {x}^{2}\right) \cdot x\right)} + \frac{1}{2}\right)\right) \]
    6. accelerator-lowering-fma.f64N/A

      \[\leadsto \sin x \cdot \left(x \cdot \color{blue}{\mathsf{fma}\left(x, \left(\frac{1}{24} + \frac{1}{240} \cdot {x}^{2}\right) \cdot x, \frac{1}{2}\right)}\right) \]
    7. *-commutativeN/A

      \[\leadsto \sin x \cdot \left(x \cdot \mathsf{fma}\left(x, \color{blue}{x \cdot \left(\frac{1}{24} + \frac{1}{240} \cdot {x}^{2}\right)}, \frac{1}{2}\right)\right) \]
    8. *-lowering-*.f64N/A

      \[\leadsto \sin x \cdot \left(x \cdot \mathsf{fma}\left(x, \color{blue}{x \cdot \left(\frac{1}{24} + \frac{1}{240} \cdot {x}^{2}\right)}, \frac{1}{2}\right)\right) \]
    9. +-commutativeN/A

      \[\leadsto \sin x \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \color{blue}{\left(\frac{1}{240} \cdot {x}^{2} + \frac{1}{24}\right)}, \frac{1}{2}\right)\right) \]
    10. *-commutativeN/A

      \[\leadsto \sin x \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \left(\color{blue}{{x}^{2} \cdot \frac{1}{240}} + \frac{1}{24}\right), \frac{1}{2}\right)\right) \]
    11. unpow2N/A

      \[\leadsto \sin x \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \left(\color{blue}{\left(x \cdot x\right)} \cdot \frac{1}{240} + \frac{1}{24}\right), \frac{1}{2}\right)\right) \]
    12. associate-*l*N/A

      \[\leadsto \sin x \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \left(\color{blue}{x \cdot \left(x \cdot \frac{1}{240}\right)} + \frac{1}{24}\right), \frac{1}{2}\right)\right) \]
    13. accelerator-lowering-fma.f64N/A

      \[\leadsto \sin x \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \color{blue}{\mathsf{fma}\left(x, x \cdot \frac{1}{240}, \frac{1}{24}\right)}, \frac{1}{2}\right)\right) \]
    14. *-lowering-*.f64100.0

      \[\leadsto \sin x \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, \color{blue}{x \cdot 0.004166666666666667}, 0.041666666666666664\right), 0.5\right)\right) \]
  6. Simplified100.0%

    \[\leadsto \sin x \cdot \color{blue}{\left(x \cdot \mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, x \cdot 0.004166666666666667, 0.041666666666666664\right), 0.5\right)\right)} \]
  7. Add Preprocessing

Alternative 2: 100.0% accurate, 1.7× speedup?

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

\\
\left(x \cdot \mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, x \cdot 0.004166666666666667, 0.041666666666666664\right), 0.5\right)\right) \cdot \left(x \cdot \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x, x \cdot 0.008333333333333333, -0.16666666666666666\right), 1\right)\right)
\end{array}
Derivation
  1. Initial program 52.0%

    \[1 - \cos x \]
  2. Add Preprocessing
  3. Applied egg-rr100.0%

    \[\leadsto \color{blue}{\sin x \cdot \tan \left(\frac{x}{2}\right)} \]
  4. Taylor expanded in x around 0

    \[\leadsto \sin x \cdot \color{blue}{\left(x \cdot \left(\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{24} + \frac{1}{240} \cdot {x}^{2}\right)\right)\right)} \]
  5. Step-by-step derivation
    1. *-lowering-*.f64N/A

      \[\leadsto \sin x \cdot \color{blue}{\left(x \cdot \left(\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{24} + \frac{1}{240} \cdot {x}^{2}\right)\right)\right)} \]
    2. +-commutativeN/A

      \[\leadsto \sin x \cdot \left(x \cdot \color{blue}{\left({x}^{2} \cdot \left(\frac{1}{24} + \frac{1}{240} \cdot {x}^{2}\right) + \frac{1}{2}\right)}\right) \]
    3. unpow2N/A

      \[\leadsto \sin x \cdot \left(x \cdot \left(\color{blue}{\left(x \cdot x\right)} \cdot \left(\frac{1}{24} + \frac{1}{240} \cdot {x}^{2}\right) + \frac{1}{2}\right)\right) \]
    4. associate-*l*N/A

      \[\leadsto \sin x \cdot \left(x \cdot \left(\color{blue}{x \cdot \left(x \cdot \left(\frac{1}{24} + \frac{1}{240} \cdot {x}^{2}\right)\right)} + \frac{1}{2}\right)\right) \]
    5. *-commutativeN/A

      \[\leadsto \sin x \cdot \left(x \cdot \left(x \cdot \color{blue}{\left(\left(\frac{1}{24} + \frac{1}{240} \cdot {x}^{2}\right) \cdot x\right)} + \frac{1}{2}\right)\right) \]
    6. accelerator-lowering-fma.f64N/A

      \[\leadsto \sin x \cdot \left(x \cdot \color{blue}{\mathsf{fma}\left(x, \left(\frac{1}{24} + \frac{1}{240} \cdot {x}^{2}\right) \cdot x, \frac{1}{2}\right)}\right) \]
    7. *-commutativeN/A

      \[\leadsto \sin x \cdot \left(x \cdot \mathsf{fma}\left(x, \color{blue}{x \cdot \left(\frac{1}{24} + \frac{1}{240} \cdot {x}^{2}\right)}, \frac{1}{2}\right)\right) \]
    8. *-lowering-*.f64N/A

      \[\leadsto \sin x \cdot \left(x \cdot \mathsf{fma}\left(x, \color{blue}{x \cdot \left(\frac{1}{24} + \frac{1}{240} \cdot {x}^{2}\right)}, \frac{1}{2}\right)\right) \]
    9. +-commutativeN/A

      \[\leadsto \sin x \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \color{blue}{\left(\frac{1}{240} \cdot {x}^{2} + \frac{1}{24}\right)}, \frac{1}{2}\right)\right) \]
    10. *-commutativeN/A

      \[\leadsto \sin x \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \left(\color{blue}{{x}^{2} \cdot \frac{1}{240}} + \frac{1}{24}\right), \frac{1}{2}\right)\right) \]
    11. unpow2N/A

      \[\leadsto \sin x \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \left(\color{blue}{\left(x \cdot x\right)} \cdot \frac{1}{240} + \frac{1}{24}\right), \frac{1}{2}\right)\right) \]
    12. associate-*l*N/A

      \[\leadsto \sin x \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \left(\color{blue}{x \cdot \left(x \cdot \frac{1}{240}\right)} + \frac{1}{24}\right), \frac{1}{2}\right)\right) \]
    13. accelerator-lowering-fma.f64N/A

      \[\leadsto \sin x \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \color{blue}{\mathsf{fma}\left(x, x \cdot \frac{1}{240}, \frac{1}{24}\right)}, \frac{1}{2}\right)\right) \]
    14. *-lowering-*.f64100.0

      \[\leadsto \sin x \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, \color{blue}{x \cdot 0.004166666666666667}, 0.041666666666666664\right), 0.5\right)\right) \]
  6. Simplified100.0%

    \[\leadsto \sin x \cdot \color{blue}{\left(x \cdot \mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, x \cdot 0.004166666666666667, 0.041666666666666664\right), 0.5\right)\right)} \]
  7. Taylor expanded in x around 0

    \[\leadsto \color{blue}{\left(x \cdot \left(1 + {x}^{2} \cdot \left(\frac{1}{120} \cdot {x}^{2} - \frac{1}{6}\right)\right)\right)} \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, x \cdot \frac{1}{240}, \frac{1}{24}\right), \frac{1}{2}\right)\right) \]
  8. Step-by-step derivation
    1. *-lowering-*.f64N/A

      \[\leadsto \color{blue}{\left(x \cdot \left(1 + {x}^{2} \cdot \left(\frac{1}{120} \cdot {x}^{2} - \frac{1}{6}\right)\right)\right)} \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, x \cdot \frac{1}{240}, \frac{1}{24}\right), \frac{1}{2}\right)\right) \]
    2. +-commutativeN/A

      \[\leadsto \left(x \cdot \color{blue}{\left({x}^{2} \cdot \left(\frac{1}{120} \cdot {x}^{2} - \frac{1}{6}\right) + 1\right)}\right) \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, x \cdot \frac{1}{240}, \frac{1}{24}\right), \frac{1}{2}\right)\right) \]
    3. accelerator-lowering-fma.f64N/A

      \[\leadsto \left(x \cdot \color{blue}{\mathsf{fma}\left({x}^{2}, \frac{1}{120} \cdot {x}^{2} - \frac{1}{6}, 1\right)}\right) \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, x \cdot \frac{1}{240}, \frac{1}{24}\right), \frac{1}{2}\right)\right) \]
    4. unpow2N/A

      \[\leadsto \left(x \cdot \mathsf{fma}\left(\color{blue}{x \cdot x}, \frac{1}{120} \cdot {x}^{2} - \frac{1}{6}, 1\right)\right) \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, x \cdot \frac{1}{240}, \frac{1}{24}\right), \frac{1}{2}\right)\right) \]
    5. *-lowering-*.f64N/A

      \[\leadsto \left(x \cdot \mathsf{fma}\left(\color{blue}{x \cdot x}, \frac{1}{120} \cdot {x}^{2} - \frac{1}{6}, 1\right)\right) \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, x \cdot \frac{1}{240}, \frac{1}{24}\right), \frac{1}{2}\right)\right) \]
    6. sub-negN/A

      \[\leadsto \left(x \cdot \mathsf{fma}\left(x \cdot x, \color{blue}{\frac{1}{120} \cdot {x}^{2} + \left(\mathsf{neg}\left(\frac{1}{6}\right)\right)}, 1\right)\right) \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, x \cdot \frac{1}{240}, \frac{1}{24}\right), \frac{1}{2}\right)\right) \]
    7. *-commutativeN/A

      \[\leadsto \left(x \cdot \mathsf{fma}\left(x \cdot x, \color{blue}{{x}^{2} \cdot \frac{1}{120}} + \left(\mathsf{neg}\left(\frac{1}{6}\right)\right), 1\right)\right) \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, x \cdot \frac{1}{240}, \frac{1}{24}\right), \frac{1}{2}\right)\right) \]
    8. unpow2N/A

      \[\leadsto \left(x \cdot \mathsf{fma}\left(x \cdot x, \color{blue}{\left(x \cdot x\right)} \cdot \frac{1}{120} + \left(\mathsf{neg}\left(\frac{1}{6}\right)\right), 1\right)\right) \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, x \cdot \frac{1}{240}, \frac{1}{24}\right), \frac{1}{2}\right)\right) \]
    9. associate-*l*N/A

      \[\leadsto \left(x \cdot \mathsf{fma}\left(x \cdot x, \color{blue}{x \cdot \left(x \cdot \frac{1}{120}\right)} + \left(\mathsf{neg}\left(\frac{1}{6}\right)\right), 1\right)\right) \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, x \cdot \frac{1}{240}, \frac{1}{24}\right), \frac{1}{2}\right)\right) \]
    10. metadata-evalN/A

      \[\leadsto \left(x \cdot \mathsf{fma}\left(x \cdot x, x \cdot \left(x \cdot \frac{1}{120}\right) + \color{blue}{\frac{-1}{6}}, 1\right)\right) \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, x \cdot \frac{1}{240}, \frac{1}{24}\right), \frac{1}{2}\right)\right) \]
    11. accelerator-lowering-fma.f64N/A

      \[\leadsto \left(x \cdot \mathsf{fma}\left(x \cdot x, \color{blue}{\mathsf{fma}\left(x, x \cdot \frac{1}{120}, \frac{-1}{6}\right)}, 1\right)\right) \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, x \cdot \frac{1}{240}, \frac{1}{24}\right), \frac{1}{2}\right)\right) \]
    12. *-lowering-*.f64100.0

      \[\leadsto \left(x \cdot \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x, \color{blue}{x \cdot 0.008333333333333333}, -0.16666666666666666\right), 1\right)\right) \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, x \cdot 0.004166666666666667, 0.041666666666666664\right), 0.5\right)\right) \]
  9. Simplified100.0%

    \[\leadsto \color{blue}{\left(x \cdot \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x, x \cdot 0.008333333333333333, -0.16666666666666666\right), 1\right)\right)} \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, x \cdot 0.004166666666666667, 0.041666666666666664\right), 0.5\right)\right) \]
  10. Final simplification100.0%

    \[\leadsto \left(x \cdot \mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, x \cdot 0.004166666666666667, 0.041666666666666664\right), 0.5\right)\right) \cdot \left(x \cdot \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x, x \cdot 0.008333333333333333, -0.16666666666666666\right), 1\right)\right) \]
  11. Add Preprocessing

Alternative 3: 100.0% accurate, 3.2× speedup?

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

\\
x \cdot \left(x \cdot \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, 0.001388888888888889, -0.041666666666666664\right), 0.5\right)\right)
\end{array}
Derivation
  1. Initial program 52.0%

    \[1 - \cos x \]
  2. Add Preprocessing
  3. Applied egg-rr100.0%

    \[\leadsto \color{blue}{\sin x \cdot \tan \left(\frac{x}{2}\right)} \]
  4. Taylor expanded in x around 0

    \[\leadsto \color{blue}{{x}^{2} \cdot \left(\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{720} \cdot {x}^{2} - \frac{1}{24}\right)\right)} \]
  5. Step-by-step derivation
    1. unpow2N/A

      \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot \left(\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{720} \cdot {x}^{2} - \frac{1}{24}\right)\right) \]
    2. associate-*l*N/A

      \[\leadsto \color{blue}{x \cdot \left(x \cdot \left(\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{720} \cdot {x}^{2} - \frac{1}{24}\right)\right)\right)} \]
    3. *-commutativeN/A

      \[\leadsto x \cdot \color{blue}{\left(\left(\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{720} \cdot {x}^{2} - \frac{1}{24}\right)\right) \cdot x\right)} \]
    4. *-lowering-*.f64N/A

      \[\leadsto \color{blue}{x \cdot \left(\left(\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{720} \cdot {x}^{2} - \frac{1}{24}\right)\right) \cdot x\right)} \]
    5. *-commutativeN/A

      \[\leadsto x \cdot \color{blue}{\left(x \cdot \left(\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{720} \cdot {x}^{2} - \frac{1}{24}\right)\right)\right)} \]
    6. *-lowering-*.f64N/A

      \[\leadsto x \cdot \color{blue}{\left(x \cdot \left(\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{720} \cdot {x}^{2} - \frac{1}{24}\right)\right)\right)} \]
    7. +-commutativeN/A

      \[\leadsto x \cdot \left(x \cdot \color{blue}{\left({x}^{2} \cdot \left(\frac{1}{720} \cdot {x}^{2} - \frac{1}{24}\right) + \frac{1}{2}\right)}\right) \]
    8. accelerator-lowering-fma.f64N/A

      \[\leadsto x \cdot \left(x \cdot \color{blue}{\mathsf{fma}\left({x}^{2}, \frac{1}{720} \cdot {x}^{2} - \frac{1}{24}, \frac{1}{2}\right)}\right) \]
    9. unpow2N/A

      \[\leadsto x \cdot \left(x \cdot \mathsf{fma}\left(\color{blue}{x \cdot x}, \frac{1}{720} \cdot {x}^{2} - \frac{1}{24}, \frac{1}{2}\right)\right) \]
    10. *-lowering-*.f64N/A

      \[\leadsto x \cdot \left(x \cdot \mathsf{fma}\left(\color{blue}{x \cdot x}, \frac{1}{720} \cdot {x}^{2} - \frac{1}{24}, \frac{1}{2}\right)\right) \]
    11. sub-negN/A

      \[\leadsto x \cdot \left(x \cdot \mathsf{fma}\left(x \cdot x, \color{blue}{\frac{1}{720} \cdot {x}^{2} + \left(\mathsf{neg}\left(\frac{1}{24}\right)\right)}, \frac{1}{2}\right)\right) \]
    12. *-commutativeN/A

      \[\leadsto x \cdot \left(x \cdot \mathsf{fma}\left(x \cdot x, \color{blue}{{x}^{2} \cdot \frac{1}{720}} + \left(\mathsf{neg}\left(\frac{1}{24}\right)\right), \frac{1}{2}\right)\right) \]
    13. metadata-evalN/A

      \[\leadsto x \cdot \left(x \cdot \mathsf{fma}\left(x \cdot x, {x}^{2} \cdot \frac{1}{720} + \color{blue}{\frac{-1}{24}}, \frac{1}{2}\right)\right) \]
    14. accelerator-lowering-fma.f64N/A

      \[\leadsto x \cdot \left(x \cdot \mathsf{fma}\left(x \cdot x, \color{blue}{\mathsf{fma}\left({x}^{2}, \frac{1}{720}, \frac{-1}{24}\right)}, \frac{1}{2}\right)\right) \]
    15. unpow2N/A

      \[\leadsto x \cdot \left(x \cdot \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(\color{blue}{x \cdot x}, \frac{1}{720}, \frac{-1}{24}\right), \frac{1}{2}\right)\right) \]
    16. *-lowering-*.f64100.0

      \[\leadsto x \cdot \left(x \cdot \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(\color{blue}{x \cdot x}, 0.001388888888888889, -0.041666666666666664\right), 0.5\right)\right) \]
  6. Simplified100.0%

    \[\leadsto \color{blue}{x \cdot \left(x \cdot \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, 0.001388888888888889, -0.041666666666666664\right), 0.5\right)\right)} \]
  7. Add Preprocessing

Alternative 4: 99.9% accurate, 3.3× speedup?

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

\\
\mathsf{fma}\left(x \cdot 0.5, x, -0.041666666666666664 \cdot \left(x \cdot \left(x \cdot \left(x \cdot x\right)\right)\right)\right)
\end{array}
Derivation
  1. Initial program 52.0%

    \[1 - \cos x \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0

    \[\leadsto \color{blue}{{x}^{2} \cdot \left(\frac{1}{2} + \frac{-1}{24} \cdot {x}^{2}\right)} \]
  4. Step-by-step derivation
    1. +-rgt-identityN/A

      \[\leadsto {x}^{2} \cdot \color{blue}{\left(\left(\frac{1}{2} + \frac{-1}{24} \cdot {x}^{2}\right) + 0\right)} \]
    2. distribute-lft-inN/A

      \[\leadsto \color{blue}{{x}^{2} \cdot \left(\frac{1}{2} + \frac{-1}{24} \cdot {x}^{2}\right) + {x}^{2} \cdot 0} \]
    3. mul0-rgtN/A

      \[\leadsto {x}^{2} \cdot \left(\frac{1}{2} + \frac{-1}{24} \cdot {x}^{2}\right) + \color{blue}{0} \]
    4. accelerator-lowering-fma.f64N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left({x}^{2}, \frac{1}{2} + \frac{-1}{24} \cdot {x}^{2}, 0\right)} \]
    5. +-rgt-identityN/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{{x}^{2} + 0}, \frac{1}{2} + \frac{-1}{24} \cdot {x}^{2}, 0\right) \]
    6. unpow2N/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot x} + 0, \frac{1}{2} + \frac{-1}{24} \cdot {x}^{2}, 0\right) \]
    7. accelerator-lowering-fma.f64N/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(x, x, 0\right)}, \frac{1}{2} + \frac{-1}{24} \cdot {x}^{2}, 0\right) \]
    8. +-commutativeN/A

      \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(x, x, 0\right), \color{blue}{\frac{-1}{24} \cdot {x}^{2} + \frac{1}{2}}, 0\right) \]
    9. *-commutativeN/A

      \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(x, x, 0\right), \color{blue}{{x}^{2} \cdot \frac{-1}{24}} + \frac{1}{2}, 0\right) \]
    10. accelerator-lowering-fma.f64N/A

      \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(x, x, 0\right), \color{blue}{\mathsf{fma}\left({x}^{2}, \frac{-1}{24}, \frac{1}{2}\right)}, 0\right) \]
    11. +-rgt-identityN/A

      \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(x, x, 0\right), \mathsf{fma}\left(\color{blue}{{x}^{2} + 0}, \frac{-1}{24}, \frac{1}{2}\right), 0\right) \]
    12. unpow2N/A

      \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(x, x, 0\right), \mathsf{fma}\left(\color{blue}{x \cdot x} + 0, \frac{-1}{24}, \frac{1}{2}\right), 0\right) \]
    13. accelerator-lowering-fma.f6499.9

      \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(x, x, 0\right), \mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(x, x, 0\right)}, -0.041666666666666664, 0.5\right), 0\right) \]
  5. Simplified99.9%

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

      \[\leadsto \color{blue}{\left(x \cdot x + 0\right) \cdot \left(\left(x \cdot x + 0\right) \cdot \frac{-1}{24} + \frac{1}{2}\right)} \]
    2. +-rgt-identityN/A

      \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot \left(\left(x \cdot x + 0\right) \cdot \frac{-1}{24} + \frac{1}{2}\right) \]
    3. +-commutativeN/A

      \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{\left(\frac{1}{2} + \left(x \cdot x + 0\right) \cdot \frac{-1}{24}\right)} \]
    4. distribute-rgt-inN/A

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(x \cdot x\right) + \left(\left(x \cdot x + 0\right) \cdot \frac{-1}{24}\right) \cdot \left(x \cdot x\right)} \]
    5. associate-*r*N/A

      \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot x\right) \cdot x} + \left(\left(x \cdot x + 0\right) \cdot \frac{-1}{24}\right) \cdot \left(x \cdot x\right) \]
    6. metadata-evalN/A

      \[\leadsto \left(\color{blue}{\frac{1}{2}} \cdot x\right) \cdot x + \left(\left(x \cdot x + 0\right) \cdot \frac{-1}{24}\right) \cdot \left(x \cdot x\right) \]
    7. associate-/r/N/A

      \[\leadsto \color{blue}{\frac{1}{\frac{2}{x}}} \cdot x + \left(\left(x \cdot x + 0\right) \cdot \frac{-1}{24}\right) \cdot \left(x \cdot x\right) \]
    8. clear-numN/A

      \[\leadsto \color{blue}{\frac{x}{2}} \cdot x + \left(\left(x \cdot x + 0\right) \cdot \frac{-1}{24}\right) \cdot \left(x \cdot x\right) \]
    9. accelerator-lowering-fma.f64N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{2}, x, \left(\left(x \cdot x + 0\right) \cdot \frac{-1}{24}\right) \cdot \left(x \cdot x\right)\right)} \]
    10. div-invN/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot \frac{1}{2}}, x, \left(\left(x \cdot x + 0\right) \cdot \frac{-1}{24}\right) \cdot \left(x \cdot x\right)\right) \]
    11. metadata-evalN/A

      \[\leadsto \mathsf{fma}\left(x \cdot \color{blue}{\frac{1}{2}}, x, \left(\left(x \cdot x + 0\right) \cdot \frac{-1}{24}\right) \cdot \left(x \cdot x\right)\right) \]
    12. *-lowering-*.f64N/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot \frac{1}{2}}, x, \left(\left(x \cdot x + 0\right) \cdot \frac{-1}{24}\right) \cdot \left(x \cdot x\right)\right) \]
    13. +-rgt-identityN/A

      \[\leadsto \mathsf{fma}\left(x \cdot \frac{1}{2}, x, \left(\color{blue}{\left(x \cdot x\right)} \cdot \frac{-1}{24}\right) \cdot \left(x \cdot x\right)\right) \]
    14. *-commutativeN/A

      \[\leadsto \mathsf{fma}\left(x \cdot \frac{1}{2}, x, \color{blue}{\left(\frac{-1}{24} \cdot \left(x \cdot x\right)\right)} \cdot \left(x \cdot x\right)\right) \]
    15. associate-*l*N/A

      \[\leadsto \mathsf{fma}\left(x \cdot \frac{1}{2}, x, \color{blue}{\frac{-1}{24} \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)}\right) \]
    16. --rgt-identityN/A

      \[\leadsto \mathsf{fma}\left(x \cdot \frac{1}{2}, x, \frac{-1}{24} \cdot \color{blue}{\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right) - 0\right)}\right) \]
    17. metadata-evalN/A

      \[\leadsto \mathsf{fma}\left(x \cdot \frac{1}{2}, x, \frac{-1}{24} \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right) - \color{blue}{0 \cdot 0}\right)\right) \]
    18. metadata-evalN/A

      \[\leadsto \mathsf{fma}\left(x \cdot \frac{1}{2}, x, \frac{-1}{24} \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right) - \color{blue}{\left(1 - 1\right)} \cdot 0\right)\right) \]
    19. metadata-evalN/A

      \[\leadsto \mathsf{fma}\left(x \cdot \frac{1}{2}, x, \frac{-1}{24} \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right) - \left(1 - 1\right) \cdot \color{blue}{\left(1 - 1\right)}\right)\right) \]
    20. *-lowering-*.f64N/A

      \[\leadsto \mathsf{fma}\left(x \cdot \frac{1}{2}, x, \color{blue}{\frac{-1}{24} \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right) - \left(1 - 1\right) \cdot \left(1 - 1\right)\right)}\right) \]
  7. Applied egg-rr99.9%

    \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot 0.5, x, -0.041666666666666664 \cdot \mathsf{fma}\left(\mathsf{fma}\left(x, x, 0\right), \mathsf{fma}\left(x, x, 0\right), 0\right)\right)} \]
  8. Taylor expanded in x around 0

    \[\leadsto \mathsf{fma}\left(x \cdot \frac{1}{2}, x, \color{blue}{\frac{-1}{24} \cdot {x}^{4}}\right) \]
  9. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \mathsf{fma}\left(x \cdot \frac{1}{2}, x, \color{blue}{{x}^{4} \cdot \frac{-1}{24}}\right) \]
    2. *-lowering-*.f64N/A

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

      \[\leadsto \mathsf{fma}\left(x \cdot \frac{1}{2}, x, {x}^{\color{blue}{\left(3 + 1\right)}} \cdot \frac{-1}{24}\right) \]
    4. pow-plusN/A

      \[\leadsto \mathsf{fma}\left(x \cdot \frac{1}{2}, x, \color{blue}{\left({x}^{3} \cdot x\right)} \cdot \frac{-1}{24}\right) \]
    5. *-commutativeN/A

      \[\leadsto \mathsf{fma}\left(x \cdot \frac{1}{2}, x, \color{blue}{\left(x \cdot {x}^{3}\right)} \cdot \frac{-1}{24}\right) \]
    6. *-lowering-*.f64N/A

      \[\leadsto \mathsf{fma}\left(x \cdot \frac{1}{2}, x, \color{blue}{\left(x \cdot {x}^{3}\right)} \cdot \frac{-1}{24}\right) \]
    7. cube-multN/A

      \[\leadsto \mathsf{fma}\left(x \cdot \frac{1}{2}, x, \left(x \cdot \color{blue}{\left(x \cdot \left(x \cdot x\right)\right)}\right) \cdot \frac{-1}{24}\right) \]
    8. unpow2N/A

      \[\leadsto \mathsf{fma}\left(x \cdot \frac{1}{2}, x, \left(x \cdot \left(x \cdot \color{blue}{{x}^{2}}\right)\right) \cdot \frac{-1}{24}\right) \]
    9. *-lowering-*.f64N/A

      \[\leadsto \mathsf{fma}\left(x \cdot \frac{1}{2}, x, \left(x \cdot \color{blue}{\left(x \cdot {x}^{2}\right)}\right) \cdot \frac{-1}{24}\right) \]
    10. unpow2N/A

      \[\leadsto \mathsf{fma}\left(x \cdot \frac{1}{2}, x, \left(x \cdot \left(x \cdot \color{blue}{\left(x \cdot x\right)}\right)\right) \cdot \frac{-1}{24}\right) \]
    11. *-lowering-*.f6499.9

      \[\leadsto \mathsf{fma}\left(x \cdot 0.5, x, \left(x \cdot \left(x \cdot \color{blue}{\left(x \cdot x\right)}\right)\right) \cdot -0.041666666666666664\right) \]
  10. Simplified99.9%

    \[\leadsto \mathsf{fma}\left(x \cdot 0.5, x, \color{blue}{\left(x \cdot \left(x \cdot \left(x \cdot x\right)\right)\right) \cdot -0.041666666666666664}\right) \]
  11. Final simplification99.9%

    \[\leadsto \mathsf{fma}\left(x \cdot 0.5, x, -0.041666666666666664 \cdot \left(x \cdot \left(x \cdot \left(x \cdot x\right)\right)\right)\right) \]
  12. Add Preprocessing

Alternative 5: 99.9% accurate, 4.7× speedup?

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

\\
\left(x \cdot x\right) \cdot \mathsf{fma}\left(x, x \cdot -0.041666666666666664, 0.5\right)
\end{array}
Derivation
  1. Initial program 52.0%

    \[1 - \cos x \]
  2. Add Preprocessing
  3. Applied egg-rr100.0%

    \[\leadsto \color{blue}{\sin x \cdot \tan \left(\frac{x}{2}\right)} \]
  4. Taylor expanded in x around 0

    \[\leadsto \sin x \cdot \color{blue}{\left(x \cdot \left(\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{24} + \frac{1}{240} \cdot {x}^{2}\right)\right)\right)} \]
  5. Step-by-step derivation
    1. *-lowering-*.f64N/A

      \[\leadsto \sin x \cdot \color{blue}{\left(x \cdot \left(\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{24} + \frac{1}{240} \cdot {x}^{2}\right)\right)\right)} \]
    2. +-commutativeN/A

      \[\leadsto \sin x \cdot \left(x \cdot \color{blue}{\left({x}^{2} \cdot \left(\frac{1}{24} + \frac{1}{240} \cdot {x}^{2}\right) + \frac{1}{2}\right)}\right) \]
    3. unpow2N/A

      \[\leadsto \sin x \cdot \left(x \cdot \left(\color{blue}{\left(x \cdot x\right)} \cdot \left(\frac{1}{24} + \frac{1}{240} \cdot {x}^{2}\right) + \frac{1}{2}\right)\right) \]
    4. associate-*l*N/A

      \[\leadsto \sin x \cdot \left(x \cdot \left(\color{blue}{x \cdot \left(x \cdot \left(\frac{1}{24} + \frac{1}{240} \cdot {x}^{2}\right)\right)} + \frac{1}{2}\right)\right) \]
    5. *-commutativeN/A

      \[\leadsto \sin x \cdot \left(x \cdot \left(x \cdot \color{blue}{\left(\left(\frac{1}{24} + \frac{1}{240} \cdot {x}^{2}\right) \cdot x\right)} + \frac{1}{2}\right)\right) \]
    6. accelerator-lowering-fma.f64N/A

      \[\leadsto \sin x \cdot \left(x \cdot \color{blue}{\mathsf{fma}\left(x, \left(\frac{1}{24} + \frac{1}{240} \cdot {x}^{2}\right) \cdot x, \frac{1}{2}\right)}\right) \]
    7. *-commutativeN/A

      \[\leadsto \sin x \cdot \left(x \cdot \mathsf{fma}\left(x, \color{blue}{x \cdot \left(\frac{1}{24} + \frac{1}{240} \cdot {x}^{2}\right)}, \frac{1}{2}\right)\right) \]
    8. *-lowering-*.f64N/A

      \[\leadsto \sin x \cdot \left(x \cdot \mathsf{fma}\left(x, \color{blue}{x \cdot \left(\frac{1}{24} + \frac{1}{240} \cdot {x}^{2}\right)}, \frac{1}{2}\right)\right) \]
    9. +-commutativeN/A

      \[\leadsto \sin x \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \color{blue}{\left(\frac{1}{240} \cdot {x}^{2} + \frac{1}{24}\right)}, \frac{1}{2}\right)\right) \]
    10. *-commutativeN/A

      \[\leadsto \sin x \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \left(\color{blue}{{x}^{2} \cdot \frac{1}{240}} + \frac{1}{24}\right), \frac{1}{2}\right)\right) \]
    11. unpow2N/A

      \[\leadsto \sin x \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \left(\color{blue}{\left(x \cdot x\right)} \cdot \frac{1}{240} + \frac{1}{24}\right), \frac{1}{2}\right)\right) \]
    12. associate-*l*N/A

      \[\leadsto \sin x \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \left(\color{blue}{x \cdot \left(x \cdot \frac{1}{240}\right)} + \frac{1}{24}\right), \frac{1}{2}\right)\right) \]
    13. accelerator-lowering-fma.f64N/A

      \[\leadsto \sin x \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \color{blue}{\mathsf{fma}\left(x, x \cdot \frac{1}{240}, \frac{1}{24}\right)}, \frac{1}{2}\right)\right) \]
    14. *-lowering-*.f64100.0

      \[\leadsto \sin x \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, \color{blue}{x \cdot 0.004166666666666667}, 0.041666666666666664\right), 0.5\right)\right) \]
  6. Simplified100.0%

    \[\leadsto \sin x \cdot \color{blue}{\left(x \cdot \mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, x \cdot 0.004166666666666667, 0.041666666666666664\right), 0.5\right)\right)} \]
  7. Step-by-step derivation
    1. distribute-lft-inN/A

      \[\leadsto \sin x \cdot \color{blue}{\left(x \cdot \left(x \cdot \left(x \cdot \left(x \cdot \left(x \cdot \frac{1}{240}\right) + \frac{1}{24}\right)\right)\right) + x \cdot \frac{1}{2}\right)} \]
    2. associate-*r*N/A

      \[\leadsto \sin x \cdot \left(\color{blue}{\left(x \cdot x\right) \cdot \left(x \cdot \left(x \cdot \left(x \cdot \frac{1}{240}\right) + \frac{1}{24}\right)\right)} + x \cdot \frac{1}{2}\right) \]
    3. accelerator-lowering-fma.f64N/A

      \[\leadsto \sin x \cdot \color{blue}{\mathsf{fma}\left(x \cdot x, x \cdot \left(x \cdot \left(x \cdot \frac{1}{240}\right) + \frac{1}{24}\right), x \cdot \frac{1}{2}\right)} \]
    4. +-rgt-identityN/A

      \[\leadsto \sin x \cdot \mathsf{fma}\left(\color{blue}{x \cdot x + 0}, x \cdot \left(x \cdot \left(x \cdot \frac{1}{240}\right) + \frac{1}{24}\right), x \cdot \frac{1}{2}\right) \]
    5. accelerator-lowering-fma.f64N/A

      \[\leadsto \sin x \cdot \mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(x, x, 0\right)}, x \cdot \left(x \cdot \left(x \cdot \frac{1}{240}\right) + \frac{1}{24}\right), x \cdot \frac{1}{2}\right) \]
    6. *-lowering-*.f64N/A

      \[\leadsto \sin x \cdot \mathsf{fma}\left(\mathsf{fma}\left(x, x, 0\right), \color{blue}{x \cdot \left(x \cdot \left(x \cdot \frac{1}{240}\right) + \frac{1}{24}\right)}, x \cdot \frac{1}{2}\right) \]
    7. associate-*r*N/A

      \[\leadsto \sin x \cdot \mathsf{fma}\left(\mathsf{fma}\left(x, x, 0\right), x \cdot \left(\color{blue}{\left(x \cdot x\right) \cdot \frac{1}{240}} + \frac{1}{24}\right), x \cdot \frac{1}{2}\right) \]
    8. *-commutativeN/A

      \[\leadsto \sin x \cdot \mathsf{fma}\left(\mathsf{fma}\left(x, x, 0\right), x \cdot \left(\color{blue}{\frac{1}{240} \cdot \left(x \cdot x\right)} + \frac{1}{24}\right), x \cdot \frac{1}{2}\right) \]
    9. accelerator-lowering-fma.f64N/A

      \[\leadsto \sin x \cdot \mathsf{fma}\left(\mathsf{fma}\left(x, x, 0\right), x \cdot \color{blue}{\mathsf{fma}\left(\frac{1}{240}, x \cdot x, \frac{1}{24}\right)}, x \cdot \frac{1}{2}\right) \]
    10. +-rgt-identityN/A

      \[\leadsto \sin x \cdot \mathsf{fma}\left(\mathsf{fma}\left(x, x, 0\right), x \cdot \mathsf{fma}\left(\frac{1}{240}, \color{blue}{x \cdot x + 0}, \frac{1}{24}\right), x \cdot \frac{1}{2}\right) \]
    11. accelerator-lowering-fma.f64N/A

      \[\leadsto \sin x \cdot \mathsf{fma}\left(\mathsf{fma}\left(x, x, 0\right), x \cdot \mathsf{fma}\left(\frac{1}{240}, \color{blue}{\mathsf{fma}\left(x, x, 0\right)}, \frac{1}{24}\right), x \cdot \frac{1}{2}\right) \]
    12. *-lowering-*.f64100.0

      \[\leadsto \sin x \cdot \mathsf{fma}\left(\mathsf{fma}\left(x, x, 0\right), x \cdot \mathsf{fma}\left(0.004166666666666667, \mathsf{fma}\left(x, x, 0\right), 0.041666666666666664\right), \color{blue}{x \cdot 0.5}\right) \]
  8. Applied egg-rr100.0%

    \[\leadsto \sin x \cdot \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(x, x, 0\right), x \cdot \mathsf{fma}\left(0.004166666666666667, \mathsf{fma}\left(x, x, 0\right), 0.041666666666666664\right), x \cdot 0.5\right)} \]
  9. Taylor expanded in x around 0

    \[\leadsto \color{blue}{{x}^{2} \cdot \left(\frac{1}{2} + \frac{-1}{24} \cdot {x}^{2}\right)} \]
  10. Step-by-step derivation
    1. *-lowering-*.f64N/A

      \[\leadsto \color{blue}{{x}^{2} \cdot \left(\frac{1}{2} + \frac{-1}{24} \cdot {x}^{2}\right)} \]
    2. unpow2N/A

      \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot \left(\frac{1}{2} + \frac{-1}{24} \cdot {x}^{2}\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot \left(\frac{1}{2} + \frac{-1}{24} \cdot {x}^{2}\right) \]
    4. +-commutativeN/A

      \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{\left(\frac{-1}{24} \cdot {x}^{2} + \frac{1}{2}\right)} \]
    5. unpow2N/A

      \[\leadsto \left(x \cdot x\right) \cdot \left(\frac{-1}{24} \cdot \color{blue}{\left(x \cdot x\right)} + \frac{1}{2}\right) \]
    6. associate-*r*N/A

      \[\leadsto \left(x \cdot x\right) \cdot \left(\color{blue}{\left(\frac{-1}{24} \cdot x\right) \cdot x} + \frac{1}{2}\right) \]
    7. *-commutativeN/A

      \[\leadsto \left(x \cdot x\right) \cdot \left(\color{blue}{x \cdot \left(\frac{-1}{24} \cdot x\right)} + \frac{1}{2}\right) \]
    8. accelerator-lowering-fma.f64N/A

      \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{\mathsf{fma}\left(x, \frac{-1}{24} \cdot x, \frac{1}{2}\right)} \]
    9. *-commutativeN/A

      \[\leadsto \left(x \cdot x\right) \cdot \mathsf{fma}\left(x, \color{blue}{x \cdot \frac{-1}{24}}, \frac{1}{2}\right) \]
    10. *-lowering-*.f6499.9

      \[\leadsto \left(x \cdot x\right) \cdot \mathsf{fma}\left(x, \color{blue}{x \cdot -0.041666666666666664}, 0.5\right) \]
  11. Simplified99.9%

    \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot \mathsf{fma}\left(x, x \cdot -0.041666666666666664, 0.5\right)} \]
  12. Add Preprocessing

Alternative 6: 99.9% accurate, 4.7× speedup?

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

\\
x \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot -0.041666666666666664, 0.5\right)\right)
\end{array}
Derivation
  1. Initial program 52.0%

    \[1 - \cos x \]
  2. Add Preprocessing
  3. Applied egg-rr100.0%

    \[\leadsto \color{blue}{\sin x \cdot \tan \left(\frac{x}{2}\right)} \]
  4. Taylor expanded in x around 0

    \[\leadsto \color{blue}{{x}^{2} \cdot \left(\frac{1}{2} + \frac{-1}{24} \cdot {x}^{2}\right)} \]
  5. Step-by-step derivation
    1. unpow2N/A

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

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

      \[\leadsto x \cdot \color{blue}{\left(\left(\frac{1}{2} + \frac{-1}{24} \cdot {x}^{2}\right) \cdot x\right)} \]
    4. *-lowering-*.f64N/A

      \[\leadsto \color{blue}{x \cdot \left(\left(\frac{1}{2} + \frac{-1}{24} \cdot {x}^{2}\right) \cdot x\right)} \]
    5. *-commutativeN/A

      \[\leadsto x \cdot \color{blue}{\left(x \cdot \left(\frac{1}{2} + \frac{-1}{24} \cdot {x}^{2}\right)\right)} \]
    6. *-lowering-*.f64N/A

      \[\leadsto x \cdot \color{blue}{\left(x \cdot \left(\frac{1}{2} + \frac{-1}{24} \cdot {x}^{2}\right)\right)} \]
    7. +-commutativeN/A

      \[\leadsto x \cdot \left(x \cdot \color{blue}{\left(\frac{-1}{24} \cdot {x}^{2} + \frac{1}{2}\right)}\right) \]
    8. *-commutativeN/A

      \[\leadsto x \cdot \left(x \cdot \left(\color{blue}{{x}^{2} \cdot \frac{-1}{24}} + \frac{1}{2}\right)\right) \]
    9. unpow2N/A

      \[\leadsto x \cdot \left(x \cdot \left(\color{blue}{\left(x \cdot x\right)} \cdot \frac{-1}{24} + \frac{1}{2}\right)\right) \]
    10. associate-*l*N/A

      \[\leadsto x \cdot \left(x \cdot \left(\color{blue}{x \cdot \left(x \cdot \frac{-1}{24}\right)} + \frac{1}{2}\right)\right) \]
    11. accelerator-lowering-fma.f64N/A

      \[\leadsto x \cdot \left(x \cdot \color{blue}{\mathsf{fma}\left(x, x \cdot \frac{-1}{24}, \frac{1}{2}\right)}\right) \]
    12. *-lowering-*.f6499.9

      \[\leadsto x \cdot \left(x \cdot \mathsf{fma}\left(x, \color{blue}{x \cdot -0.041666666666666664}, 0.5\right)\right) \]
  6. Simplified99.9%

    \[\leadsto \color{blue}{x \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot -0.041666666666666664, 0.5\right)\right)} \]
  7. Add Preprocessing

Alternative 7: 99.5% accurate, 9.5× speedup?

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

\\
x \cdot \left(x \cdot 0.5\right)
\end{array}
Derivation
  1. Initial program 52.0%

    \[1 - \cos x \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0

    \[\leadsto \color{blue}{\frac{1}{2} \cdot {x}^{2}} \]
  4. Step-by-step derivation
    1. +-rgt-identityN/A

      \[\leadsto \color{blue}{\frac{1}{2} \cdot {x}^{2} + 0} \]
    2. accelerator-lowering-fma.f64N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{2}, {x}^{2}, 0\right)} \]
    3. +-rgt-identityN/A

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \color{blue}{{x}^{2} + 0}, 0\right) \]
    4. unpow2N/A

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \color{blue}{x \cdot x} + 0, 0\right) \]
    5. accelerator-lowering-fma.f6499.2

      \[\leadsto \mathsf{fma}\left(0.5, \color{blue}{\mathsf{fma}\left(x, x, 0\right)}, 0\right) \]
  5. Simplified99.2%

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

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(x \cdot x + 0\right)} \]
    2. +-rgt-identityN/A

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\frac{2}{x}}} \cdot x \]
    6. clear-numN/A

      \[\leadsto \color{blue}{\frac{x}{2}} \cdot x \]
    7. *-lowering-*.f64N/A

      \[\leadsto \color{blue}{\frac{x}{2} \cdot x} \]
    8. div-invN/A

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

      \[\leadsto \left(x \cdot \color{blue}{\frac{1}{2}}\right) \cdot x \]
    10. *-lowering-*.f6499.2

      \[\leadsto \color{blue}{\left(x \cdot 0.5\right)} \cdot x \]
  7. Applied egg-rr99.2%

    \[\leadsto \color{blue}{\left(x \cdot 0.5\right) \cdot x} \]
  8. Final simplification99.2%

    \[\leadsto x \cdot \left(x \cdot 0.5\right) \]
  9. Add Preprocessing

Alternative 8: 52.0% accurate, 104.0× speedup?

\[\begin{array}{l} \\ 0 \end{array} \]
(FPCore (x) :precision binary64 0.0)
double code(double x) {
	return 0.0;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 0.0d0
end function
public static double code(double x) {
	return 0.0;
}
def code(x):
	return 0.0
function code(x)
	return 0.0
end
function tmp = code(x)
	tmp = 0.0;
end
code[x_] := 0.0
\begin{array}{l}

\\
0
\end{array}
Derivation
  1. Initial program 52.0%

    \[1 - \cos x \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0

    \[\leadsto 1 - \color{blue}{1} \]
  4. Step-by-step derivation
    1. Simplified50.7%

      \[\leadsto 1 - \color{blue}{1} \]
    2. Step-by-step derivation
      1. metadata-eval50.7

        \[\leadsto \color{blue}{0} \]
    3. Applied egg-rr50.7%

      \[\leadsto \color{blue}{0} \]
    4. Add Preprocessing

    Developer Target 1: 100.0% accurate, 0.3× speedup?

    \[\begin{array}{l} \\ \frac{\sin x \cdot \sin x}{1 + \cos x} \end{array} \]
    (FPCore (x) :precision binary64 (/ (* (sin x) (sin x)) (+ 1.0 (cos x))))
    double code(double x) {
    	return (sin(x) * sin(x)) / (1.0 + cos(x));
    }
    
    real(8) function code(x)
        real(8), intent (in) :: x
        code = (sin(x) * sin(x)) / (1.0d0 + cos(x))
    end function
    
    public static double code(double x) {
    	return (Math.sin(x) * Math.sin(x)) / (1.0 + Math.cos(x));
    }
    
    def code(x):
    	return (math.sin(x) * math.sin(x)) / (1.0 + math.cos(x))
    
    function code(x)
    	return Float64(Float64(sin(x) * sin(x)) / Float64(1.0 + cos(x)))
    end
    
    function tmp = code(x)
    	tmp = (sin(x) * sin(x)) / (1.0 + cos(x));
    end
    
    code[x_] := N[(N[(N[Sin[x], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \frac{\sin x \cdot \sin x}{1 + \cos x}
    \end{array}
    

    Reproduce

    ?
    herbie shell --seed 2024195 
    (FPCore (x)
      :name "ENA, Section 1.4, Mentioned, A"
      :precision binary64
      :pre (and (<= -0.01 x) (<= x 0.01))
    
      :alt
      (! :herbie-platform default (/ (* (sin x) (sin x)) (+ 1 (cos x))))
    
      (- 1.0 (cos x)))