ENA, Section 1.4, Mentioned, A

Percentage Accurate: 53.0% → 100.0%
Time: 14.1s
Alternatives: 6
Speedup: 20.6×

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 6 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.0% 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, 6.1× speedup?

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

\\
x \cdot \left(x \cdot \left(0.5 + \left(x \cdot x\right) \cdot \left(-0.041666666666666664 + \left(x \cdot x\right) \cdot 0.001388888888888889\right)\right)\right)
\end{array}
Derivation
  1. Initial program 53.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 \left(x \cdot x\right) \cdot \left(\color{blue}{\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 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)} \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \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)}\right) \]
    4. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \color{blue}{\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)\right) \]
    5. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \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)\right)}\right)\right)\right) \]
    6. *-lowering-*.f64N/A

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

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

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

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

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \left({x}^{2} \cdot \left(\frac{1}{720} + \frac{-1}{40320} \cdot {x}^{2}\right) + \frac{-1}{24}\right)\right)\right)\right)\right) \]
    11. +-commutativeN/A

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{x \cdot \left(x \cdot \left(0.5 + \left(x \cdot x\right) \cdot \left(-0.041666666666666664 + x \cdot \left(x \cdot \left(0.001388888888888889 + \left(x \cdot x\right) \cdot -2.48015873015873 \cdot 10^{-5}\right)\right)\right)\right)\right)} \]
  6. 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)} \]
  7. Step-by-step derivation
    1. unpow2N/A

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

      \[\leadsto \mathsf{*.f64}\left(x, \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)}\right) \]
    4. *-lowering-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{-1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{1}{720}\right)\right)\right)\right)\right)\right) \]
  8. Simplified100.0%

    \[\leadsto \color{blue}{x \cdot \left(x \cdot \left(0.5 + \left(x \cdot x\right) \cdot \left(-0.041666666666666664 + \left(x \cdot x\right) \cdot 0.001388888888888889\right)\right)\right)} \]
  9. Add Preprocessing

Alternative 2: 99.9% accurate, 6.9× speedup?

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

\\
\left(x \cdot x\right) \cdot \left(x \cdot \left(x \cdot -0.041666666666666664\right)\right) + x \cdot \left(x \cdot 0.5\right)
\end{array}
Derivation
  1. Initial program 53.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. unpow2N/A

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

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

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

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

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

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

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \left(\left(x \cdot x\right) \cdot \frac{-1}{24}\right)\right)\right)\right) \]
    8. associate-*l*N/A

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

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

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \color{blue}{\frac{-1}{24}}\right)\right)\right)\right)\right) \]
  5. Simplified99.9%

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

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

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

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

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

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(x, \left(x \cdot \frac{-1}{24}\right)\right), \left(x \cdot x\right)\right), \left(\frac{1}{2} \cdot \left(x \cdot x\right)\right)\right) \]
    7. *-lowering-*.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \frac{-1}{24}\right)\right), \left(x \cdot x\right)\right), \left(\frac{1}{2} \cdot \left(x \cdot x\right)\right)\right) \]
    8. *-lowering-*.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \frac{-1}{24}\right)\right), \mathsf{*.f64}\left(x, x\right)\right), \left(\frac{1}{2} \cdot \left(x \cdot x\right)\right)\right) \]
    9. associate-*r*N/A

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

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

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \frac{-1}{24}\right)\right), \mathsf{*.f64}\left(x, x\right)\right), \mathsf{*.f64}\left(x, \left(x \cdot \color{blue}{\frac{1}{2}}\right)\right)\right) \]
    13. *-lowering-*.f64100.0%

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \frac{-1}{24}\right)\right), \mathsf{*.f64}\left(x, x\right)\right), \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \color{blue}{\frac{1}{2}}\right)\right)\right) \]
  7. Applied egg-rr100.0%

    \[\leadsto \color{blue}{\left(x \cdot \left(x \cdot -0.041666666666666664\right)\right) \cdot \left(x \cdot x\right) + x \cdot \left(x \cdot 0.5\right)} \]
  8. Final simplification100.0%

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

Alternative 3: 99.9% accurate, 9.4× speedup?

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

\\
x \cdot \left(x \cdot \left(0.5 + x \cdot \left(x \cdot -0.041666666666666664\right)\right)\right)
\end{array}
Derivation
  1. Initial program 53.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. unpow2N/A

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

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

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

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

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

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

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \left(\left(x \cdot x\right) \cdot \frac{-1}{24}\right)\right)\right)\right) \]
    8. associate-*l*N/A

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

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

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \color{blue}{\frac{-1}{24}}\right)\right)\right)\right)\right) \]
  5. Simplified99.9%

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

Alternative 4: 99.5% accurate, 20.6× 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 53.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. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \color{blue}{\left({x}^{2}\right)}\right) \]
    2. unpow2N/A

      \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \left(x \cdot \color{blue}{x}\right)\right) \]
    3. *-lowering-*.f6499.1%

      \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \color{blue}{x}\right)\right) \]
  5. Simplified99.1%

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

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

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

      \[\leadsto \mathsf{*.f64}\left(\left(x \cdot \frac{1}{2}\right), x\right) \]
    4. *-lowering-*.f6499.2%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, \frac{1}{2}\right), x\right) \]
  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 5: 99.5% accurate, 20.6× speedup?

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

\\
0.5 \cdot \left(x \cdot x\right)
\end{array}
Derivation
  1. Initial program 53.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. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \color{blue}{\left({x}^{2}\right)}\right) \]
    2. unpow2N/A

      \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \left(x \cdot \color{blue}{x}\right)\right) \]
    3. *-lowering-*.f6499.1%

      \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \color{blue}{x}\right)\right) \]
  5. Simplified99.1%

    \[\leadsto \color{blue}{0.5 \cdot \left(x \cdot x\right)} \]
  6. Add Preprocessing

Alternative 6: 52.2% accurate, 103.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 53.2%

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

    \[\leadsto \mathsf{\_.f64}\left(1, \color{blue}{1}\right) \]
  4. Step-by-step derivation
    1. Simplified51.6%

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

        \[\leadsto 0 \]
    3. Applied egg-rr51.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 2024141 
    (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)))