ENA, Section 1.4, Mentioned, A

Percentage Accurate: 53.1% → 100.0%
Time: 10.1s
Alternatives: 7
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 7 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, 2.4× speedup?

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

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

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

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

      \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot \left(\frac{1}{2} + {x}^{2} \cdot \left({x}^{2} \cdot \left(\frac{1}{720} + \frac{-1}{40320} \cdot {x}^{2}\right) - \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({x}^{2} \cdot \left(\frac{1}{720} + \frac{-1}{40320} \cdot {x}^{2}\right) - \frac{1}{24}\right)\right)\right)} \]
    3. lower-*.f64N/A

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

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

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

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

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

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

      \[\leadsto x \cdot \left(x \cdot \color{blue}{\mathsf{fma}\left(x, \left({x}^{2} \cdot \left(\frac{1}{720} + \frac{-1}{40320} \cdot {x}^{2}\right) - \frac{1}{24}\right) \cdot x, \frac{1}{2}\right)}\right) \]
  5. Simplified100.0%

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

Alternative 2: 100.0% accurate, 3.2× speedup?

\[\begin{array}{l} \\ \left(x \cdot x\right) \cdot \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x, x \cdot 0.001388888888888889, -0.041666666666666664\right), 0.5\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(Float64(x * x) * fma(Float64(x * x), fma(x, Float64(x * 0.001388888888888889), -0.041666666666666664), 0.5))
end
code[x_] := N[(N[(x * x), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * N[(x * N[(x * 0.001388888888888889), $MachinePrecision] + -0.041666666666666664), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

    \[1 - \cos x \]
  2. Add Preprocessing
  3. 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)} \]
  4. Step-by-step derivation
    1. lower-*.f64N/A

      \[\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)} \]
    2. 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) \]
    3. lower-*.f64N/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) \]
    4. +-commutativeN/A

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

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

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

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

      \[\leadsto \left(x \cdot x\right) \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) \]
    9. metadata-evalN/A

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

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

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

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

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

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

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

Alternative 3: 99.9% accurate, 3.3× speedup?

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

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

    \[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. lower-*.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. lower-*.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. *-commutativeN/A

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

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

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

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

    \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot \mathsf{fma}\left(x \cdot x, -0.041666666666666664, 0.5\right)} \]
  6. Step-by-step derivation
    1. lift-*.f64N/A

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

      \[\leadsto \left(x \cdot x\right) \cdot \left(\color{blue}{\left(x \cdot x\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\right) \cdot \frac{-1}{24}\right)} \]
    4. distribute-lft-inN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 99.9% accurate, 4.7× speedup?

\[\begin{array}{l} \\ \left(x \cdot x\right) \cdot \mathsf{fma}\left(x \cdot x, -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(Float64(x * x), -0.041666666666666664, 0.5))
end
code[x_] := N[(N[(x * x), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * -0.041666666666666664 + 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

    \[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. lower-*.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. lower-*.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. *-commutativeN/A

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

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

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

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

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

Alternative 5: 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 50.2%

    \[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. lower-*.f64N/A

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

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

      \[\leadsto 0.5 \cdot \color{blue}{\left(x \cdot x\right)} \]
  5. Simplified99.7%

    \[\leadsto \color{blue}{0.5 \cdot \left(x \cdot x\right)} \]
  6. Step-by-step derivation
    1. associate-*r*N/A

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

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

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

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

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

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

Alternative 6: 99.5% accurate, 9.5× speedup?

\[\begin{array}{l} \\ \left(x \cdot x\right) \cdot 0.5 \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(Float64(x * x) * 0.5)
end
function tmp = code(x)
	tmp = (x * x) * 0.5;
end
code[x_] := N[(N[(x * x), $MachinePrecision] * 0.5), $MachinePrecision]
\begin{array}{l}

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

    \[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. lower-*.f64N/A

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

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

      \[\leadsto 0.5 \cdot \color{blue}{\left(x \cdot x\right)} \]
  5. Simplified99.7%

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

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

Alternative 7: 52.2% 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 50.2%

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

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

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

        \[\leadsto \color{blue}{0} \]
    3. Applied egg-rr49.6%

      \[\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 2024208 
    (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)))