cos2 (problem 3.4.1)

Percentage Accurate: 51.2% → 99.8%
Time: 10.8s
Alternatives: 7
Speedup: 17.1×

Specification

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

\\
\frac{1 - \cos x}{x \cdot 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: 51.2% accurate, 1.0× speedup?

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

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

Alternative 1: 99.8% accurate, 0.5× speedup?

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

\\
\frac{\tan \left(x \cdot 0.5\right)}{x} \cdot \frac{\sin x}{x}
\end{array}
Derivation
  1. Initial program 50.5%

    \[\frac{1 - \cos x}{x \cdot x} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. flip--N/A

      \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}{x \cdot x} \]
    2. associate-/l/N/A

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

      \[\leadsto \frac{\color{blue}{1} - \cos x \cdot \cos x}{\left(x \cdot x\right) \cdot \left(1 + \cos x\right)} \]
    4. 1-sub-cosN/A

      \[\leadsto \frac{\color{blue}{\sin x \cdot \sin x}}{\left(x \cdot x\right) \cdot \left(1 + \cos x\right)} \]
    5. times-fracN/A

      \[\leadsto \color{blue}{\frac{\sin x}{x \cdot x} \cdot \frac{\sin x}{1 + \cos x}} \]
    6. *-lowering-*.f64N/A

      \[\leadsto \color{blue}{\frac{\sin x}{x \cdot x} \cdot \frac{\sin x}{1 + \cos x}} \]
    7. /-lowering-/.f64N/A

      \[\leadsto \color{blue}{\frac{\sin x}{x \cdot x}} \cdot \frac{\sin x}{1 + \cos x} \]
    8. sin-lowering-sin.f64N/A

      \[\leadsto \frac{\color{blue}{\sin x}}{x \cdot x} \cdot \frac{\sin x}{1 + \cos x} \]
    9. *-lowering-*.f64N/A

      \[\leadsto \frac{\sin x}{\color{blue}{x \cdot x}} \cdot \frac{\sin x}{1 + \cos x} \]
    10. hang-0p-tanN/A

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

      \[\leadsto \frac{\sin x}{x \cdot x} \cdot \color{blue}{\tan \left(\frac{x}{2}\right)} \]
    12. /-lowering-/.f6478.6

      \[\leadsto \frac{\sin x}{x \cdot x} \cdot \tan \color{blue}{\left(\frac{x}{2}\right)} \]
  4. Applied egg-rr78.6%

    \[\leadsto \color{blue}{\frac{\sin x}{x \cdot x} \cdot \tan \left(\frac{x}{2}\right)} \]
  5. Step-by-step derivation
    1. *-commutativeN/A

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

      \[\leadsto \color{blue}{\frac{\tan \left(\frac{x}{2}\right) \cdot \sin x}{x \cdot x}} \]
    3. times-fracN/A

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

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

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

      \[\leadsto \frac{\color{blue}{\tan \left(\frac{x}{2}\right)}}{x} \cdot \frac{\sin x}{x} \]
    7. div-invN/A

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

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

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

      \[\leadsto \frac{\tan \left(x \cdot \frac{1}{2}\right)}{x} \cdot \color{blue}{\frac{\sin x}{x}} \]
    11. sin-lowering-sin.f6499.8

      \[\leadsto \frac{\tan \left(x \cdot 0.5\right)}{x} \cdot \frac{\color{blue}{\sin x}}{x} \]
  6. Applied egg-rr99.8%

    \[\leadsto \color{blue}{\frac{\tan \left(x \cdot 0.5\right)}{x} \cdot \frac{\sin x}{x}} \]
  7. Add Preprocessing

Alternative 2: 75.2% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 0.031:\\ \;\;\;\;\mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, x \cdot 0.001388888888888889, -0.041666666666666664\right), 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1 - \cos x}{x}}{x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 0.031)
   (fma x (* x (fma x (* x 0.001388888888888889) -0.041666666666666664)) 0.5)
   (/ (/ (- 1.0 (cos x)) x) x)))
double code(double x) {
	double tmp;
	if (x <= 0.031) {
		tmp = fma(x, (x * fma(x, (x * 0.001388888888888889), -0.041666666666666664)), 0.5);
	} else {
		tmp = ((1.0 - cos(x)) / x) / x;
	}
	return tmp;
}
function code(x)
	tmp = 0.0
	if (x <= 0.031)
		tmp = fma(x, Float64(x * fma(x, Float64(x * 0.001388888888888889), -0.041666666666666664)), 0.5);
	else
		tmp = Float64(Float64(Float64(1.0 - cos(x)) / x) / x);
	end
	return tmp
end
code[x_] := If[LessEqual[x, 0.031], N[(x * N[(x * N[(x * N[(x * 0.001388888888888889), $MachinePrecision] + -0.041666666666666664), $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision], N[(N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.031:\\
\;\;\;\;\mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, x \cdot 0.001388888888888889, -0.041666666666666664\right), 0.5\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1 - \cos x}{x}}{x}\\


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

    1. Initial program 36.6%

      \[\frac{1 - \cos x}{x \cdot x} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. flip--N/A

        \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}{x \cdot x} \]
      2. associate-/l/N/A

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

        \[\leadsto \frac{\color{blue}{1} - \cos x \cdot \cos x}{\left(x \cdot x\right) \cdot \left(1 + \cos x\right)} \]
      4. 1-sub-cosN/A

        \[\leadsto \frac{\color{blue}{\sin x \cdot \sin x}}{\left(x \cdot x\right) \cdot \left(1 + \cos x\right)} \]
      5. times-fracN/A

        \[\leadsto \color{blue}{\frac{\sin x}{x \cdot x} \cdot \frac{\sin x}{1 + \cos x}} \]
      6. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{\frac{\sin x}{x \cdot x} \cdot \frac{\sin x}{1 + \cos x}} \]
      7. /-lowering-/.f64N/A

        \[\leadsto \color{blue}{\frac{\sin x}{x \cdot x}} \cdot \frac{\sin x}{1 + \cos x} \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \frac{\color{blue}{\sin x}}{x \cdot x} \cdot \frac{\sin x}{1 + \cos x} \]
      9. *-lowering-*.f64N/A

        \[\leadsto \frac{\sin x}{\color{blue}{x \cdot x}} \cdot \frac{\sin x}{1 + \cos x} \]
      10. hang-0p-tanN/A

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

        \[\leadsto \frac{\sin x}{x \cdot x} \cdot \color{blue}{\tan \left(\frac{x}{2}\right)} \]
      12. /-lowering-/.f6472.8

        \[\leadsto \frac{\sin x}{x \cdot x} \cdot \tan \color{blue}{\left(\frac{x}{2}\right)} \]
    4. Applied egg-rr72.8%

      \[\leadsto \color{blue}{\frac{\sin x}{x \cdot x} \cdot \tan \left(\frac{x}{2}\right)} \]
    5. Step-by-step derivation
      1. associate-*l/N/A

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\tan \left(\frac{x}{2}\right)}}{x \cdot x} \cdot \sin x \]
      7. div-invN/A

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

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

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

        \[\leadsto \frac{\tan \left(x \cdot \frac{1}{2}\right)}{\color{blue}{x \cdot x}} \cdot \sin x \]
      11. sin-lowering-sin.f6472.8

        \[\leadsto \frac{\tan \left(x \cdot 0.5\right)}{x \cdot x} \cdot \color{blue}{\sin x} \]
    6. Applied egg-rr72.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.031 < x

    1. Initial program 98.0%

      \[\frac{1 - \cos x}{x \cdot x} \]
    2. Add Preprocessing
    3. Applied egg-rr97.9%

      \[\leadsto \color{blue}{\frac{-1}{x \cdot x} \cdot \left(\cos x + -1\right)} \]
    4. Step-by-step derivation
      1. associate-*l/N/A

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

        \[\leadsto \color{blue}{\frac{-1}{x} \cdot \frac{\cos x + -1}{x}} \]
      3. *-commutativeN/A

        \[\leadsto \color{blue}{\frac{\cos x + -1}{x} \cdot \frac{-1}{x}} \]
      4. associate-*r/N/A

        \[\leadsto \color{blue}{\frac{\frac{\cos x + -1}{x} \cdot -1}{x}} \]
      5. /-lowering-/.f64N/A

        \[\leadsto \color{blue}{\frac{\frac{\cos x + -1}{x} \cdot -1}{x}} \]
      6. associate-*l/N/A

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

        \[\leadsto \frac{\frac{\color{blue}{-1 \cdot \left(\cos x + -1\right)}}{x}}{x} \]
      8. neg-mul-1N/A

        \[\leadsto \frac{\frac{\color{blue}{\mathsf{neg}\left(\left(\cos x + -1\right)\right)}}{x}}{x} \]
      9. +-commutativeN/A

        \[\leadsto \frac{\frac{\mathsf{neg}\left(\color{blue}{\left(-1 + \cos x\right)}\right)}{x}}{x} \]
      10. distribute-neg-inN/A

        \[\leadsto \frac{\frac{\color{blue}{\left(\mathsf{neg}\left(-1\right)\right) + \left(\mathsf{neg}\left(\cos x\right)\right)}}{x}}{x} \]
      11. metadata-evalN/A

        \[\leadsto \frac{\frac{\color{blue}{1} + \left(\mathsf{neg}\left(\cos x\right)\right)}{x}}{x} \]
      12. sub-negN/A

        \[\leadsto \frac{\frac{\color{blue}{1 - \cos x}}{x}}{x} \]
      13. /-lowering-/.f64N/A

        \[\leadsto \frac{\color{blue}{\frac{1 - \cos x}{x}}}{x} \]
      14. --lowering--.f64N/A

        \[\leadsto \frac{\frac{\color{blue}{1 - \cos x}}{x}}{x} \]
      15. cos-lowering-cos.f6499.5

        \[\leadsto \frac{\frac{1 - \color{blue}{\cos x}}{x}}{x} \]
    5. Applied egg-rr99.5%

      \[\leadsto \color{blue}{\frac{\frac{1 - \cos x}{x}}{x}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 3: 75.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 0.031:\\ \;\;\;\;\mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, x \cdot 0.001388888888888889, -0.041666666666666664\right), 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1 - \cos x}{x \cdot x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 0.031)
   (fma x (* x (fma x (* x 0.001388888888888889) -0.041666666666666664)) 0.5)
   (/ (- 1.0 (cos x)) (* x x))))
double code(double x) {
	double tmp;
	if (x <= 0.031) {
		tmp = fma(x, (x * fma(x, (x * 0.001388888888888889), -0.041666666666666664)), 0.5);
	} else {
		tmp = (1.0 - cos(x)) / (x * x);
	}
	return tmp;
}
function code(x)
	tmp = 0.0
	if (x <= 0.031)
		tmp = fma(x, Float64(x * fma(x, Float64(x * 0.001388888888888889), -0.041666666666666664)), 0.5);
	else
		tmp = Float64(Float64(1.0 - cos(x)) / Float64(x * x));
	end
	return tmp
end
code[x_] := If[LessEqual[x, 0.031], N[(x * N[(x * N[(x * N[(x * 0.001388888888888889), $MachinePrecision] + -0.041666666666666664), $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision], N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.031:\\
\;\;\;\;\mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, x \cdot 0.001388888888888889, -0.041666666666666664\right), 0.5\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{1 - \cos x}{x \cdot x}\\


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

    1. Initial program 36.6%

      \[\frac{1 - \cos x}{x \cdot x} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. flip--N/A

        \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}{x \cdot x} \]
      2. associate-/l/N/A

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

        \[\leadsto \frac{\color{blue}{1} - \cos x \cdot \cos x}{\left(x \cdot x\right) \cdot \left(1 + \cos x\right)} \]
      4. 1-sub-cosN/A

        \[\leadsto \frac{\color{blue}{\sin x \cdot \sin x}}{\left(x \cdot x\right) \cdot \left(1 + \cos x\right)} \]
      5. times-fracN/A

        \[\leadsto \color{blue}{\frac{\sin x}{x \cdot x} \cdot \frac{\sin x}{1 + \cos x}} \]
      6. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{\frac{\sin x}{x \cdot x} \cdot \frac{\sin x}{1 + \cos x}} \]
      7. /-lowering-/.f64N/A

        \[\leadsto \color{blue}{\frac{\sin x}{x \cdot x}} \cdot \frac{\sin x}{1 + \cos x} \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \frac{\color{blue}{\sin x}}{x \cdot x} \cdot \frac{\sin x}{1 + \cos x} \]
      9. *-lowering-*.f64N/A

        \[\leadsto \frac{\sin x}{\color{blue}{x \cdot x}} \cdot \frac{\sin x}{1 + \cos x} \]
      10. hang-0p-tanN/A

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

        \[\leadsto \frac{\sin x}{x \cdot x} \cdot \color{blue}{\tan \left(\frac{x}{2}\right)} \]
      12. /-lowering-/.f6472.8

        \[\leadsto \frac{\sin x}{x \cdot x} \cdot \tan \color{blue}{\left(\frac{x}{2}\right)} \]
    4. Applied egg-rr72.8%

      \[\leadsto \color{blue}{\frac{\sin x}{x \cdot x} \cdot \tan \left(\frac{x}{2}\right)} \]
    5. Step-by-step derivation
      1. associate-*l/N/A

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\tan \left(\frac{x}{2}\right)}}{x \cdot x} \cdot \sin x \]
      7. div-invN/A

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

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

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

        \[\leadsto \frac{\tan \left(x \cdot \frac{1}{2}\right)}{\color{blue}{x \cdot x}} \cdot \sin x \]
      11. sin-lowering-sin.f6472.8

        \[\leadsto \frac{\tan \left(x \cdot 0.5\right)}{x \cdot x} \cdot \color{blue}{\sin x} \]
    6. Applied egg-rr72.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.031 < x

    1. Initial program 98.0%

      \[\frac{1 - \cos x}{x \cdot x} \]
    2. Add Preprocessing
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 63.4% accurate, 2.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 1.5 \cdot 10^{+29}:\\ \;\;\;\;\mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, x \cdot 0.001388888888888889, -0.041666666666666664\right), 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{1}{x \cdot x}, x, \frac{-1}{x}\right)}{x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 1.5e+29)
   (fma x (* x (fma x (* x 0.001388888888888889) -0.041666666666666664)) 0.5)
   (/ (fma (/ 1.0 (* x x)) x (/ -1.0 x)) x)))
double code(double x) {
	double tmp;
	if (x <= 1.5e+29) {
		tmp = fma(x, (x * fma(x, (x * 0.001388888888888889), -0.041666666666666664)), 0.5);
	} else {
		tmp = fma((1.0 / (x * x)), x, (-1.0 / x)) / x;
	}
	return tmp;
}
function code(x)
	tmp = 0.0
	if (x <= 1.5e+29)
		tmp = fma(x, Float64(x * fma(x, Float64(x * 0.001388888888888889), -0.041666666666666664)), 0.5);
	else
		tmp = Float64(fma(Float64(1.0 / Float64(x * x)), x, Float64(-1.0 / x)) / x);
	end
	return tmp
end
code[x_] := If[LessEqual[x, 1.5e+29], N[(x * N[(x * N[(x * N[(x * 0.001388888888888889), $MachinePrecision] + -0.041666666666666664), $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision], N[(N[(N[(1.0 / N[(x * x), $MachinePrecision]), $MachinePrecision] * x + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.5 \cdot 10^{+29}:\\
\;\;\;\;\mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, x \cdot 0.001388888888888889, -0.041666666666666664\right), 0.5\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{1}{x \cdot x}, x, \frac{-1}{x}\right)}{x}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 1.5e29

    1. Initial program 38.8%

      \[\frac{1 - \cos x}{x \cdot x} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. flip--N/A

        \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}{x \cdot x} \]
      2. associate-/l/N/A

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

        \[\leadsto \frac{\color{blue}{1} - \cos x \cdot \cos x}{\left(x \cdot x\right) \cdot \left(1 + \cos x\right)} \]
      4. 1-sub-cosN/A

        \[\leadsto \frac{\color{blue}{\sin x \cdot \sin x}}{\left(x \cdot x\right) \cdot \left(1 + \cos x\right)} \]
      5. times-fracN/A

        \[\leadsto \color{blue}{\frac{\sin x}{x \cdot x} \cdot \frac{\sin x}{1 + \cos x}} \]
      6. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{\frac{\sin x}{x \cdot x} \cdot \frac{\sin x}{1 + \cos x}} \]
      7. /-lowering-/.f64N/A

        \[\leadsto \color{blue}{\frac{\sin x}{x \cdot x}} \cdot \frac{\sin x}{1 + \cos x} \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \frac{\color{blue}{\sin x}}{x \cdot x} \cdot \frac{\sin x}{1 + \cos x} \]
      9. *-lowering-*.f64N/A

        \[\leadsto \frac{\sin x}{\color{blue}{x \cdot x}} \cdot \frac{\sin x}{1 + \cos x} \]
      10. hang-0p-tanN/A

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

        \[\leadsto \frac{\sin x}{x \cdot x} \cdot \color{blue}{\tan \left(\frac{x}{2}\right)} \]
      12. /-lowering-/.f6473.7

        \[\leadsto \frac{\sin x}{x \cdot x} \cdot \tan \color{blue}{\left(\frac{x}{2}\right)} \]
    4. Applied egg-rr73.7%

      \[\leadsto \color{blue}{\frac{\sin x}{x \cdot x} \cdot \tan \left(\frac{x}{2}\right)} \]
    5. Step-by-step derivation
      1. associate-*l/N/A

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\tan \left(\frac{x}{2}\right)}}{x \cdot x} \cdot \sin x \]
      7. div-invN/A

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

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

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

        \[\leadsto \frac{\tan \left(x \cdot \frac{1}{2}\right)}{\color{blue}{x \cdot x}} \cdot \sin x \]
      11. sin-lowering-sin.f6473.7

        \[\leadsto \frac{\tan \left(x \cdot 0.5\right)}{x \cdot x} \cdot \color{blue}{\sin x} \]
    6. Applied egg-rr73.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.5e29 < x

    1. Initial program 97.8%

      \[\frac{1 - \cos x}{x \cdot x} \]
    2. Add Preprocessing
    3. Applied egg-rr97.7%

      \[\leadsto \color{blue}{\frac{-1}{x \cdot x} \cdot \left(\cos x + -1\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

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

        \[\leadsto \color{blue}{\frac{-1}{x \cdot x} \cdot -1 + \frac{-1}{x \cdot x} \cdot \cos x} \]
      3. associate-*l/N/A

        \[\leadsto \color{blue}{\frac{-1 \cdot -1}{x \cdot x}} + \frac{-1}{x \cdot x} \cdot \cos x \]
      4. metadata-evalN/A

        \[\leadsto \frac{\color{blue}{1}}{x \cdot x} + \frac{-1}{x \cdot x} \cdot \cos x \]
      5. /-rgt-identityN/A

        \[\leadsto \color{blue}{\frac{\frac{1}{x \cdot x}}{1}} + \frac{-1}{x \cdot x} \cdot \cos x \]
      6. associate-/r*N/A

        \[\leadsto \frac{\frac{1}{x \cdot x}}{1} + \color{blue}{\frac{\frac{-1}{x}}{x}} \cdot \cos x \]
      7. associate-*l/N/A

        \[\leadsto \frac{\frac{1}{x \cdot x}}{1} + \color{blue}{\frac{\frac{-1}{x} \cdot \cos x}{x}} \]
      8. frac-addN/A

        \[\leadsto \color{blue}{\frac{\frac{1}{x \cdot x} \cdot x + 1 \cdot \left(\frac{-1}{x} \cdot \cos x\right)}{1 \cdot x}} \]
      9. *-lft-identityN/A

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

        \[\leadsto \color{blue}{\frac{\frac{1}{x \cdot x} \cdot x + 1 \cdot \left(\frac{-1}{x} \cdot \cos x\right)}{x}} \]
    5. Applied egg-rr97.6%

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

      \[\leadsto \frac{\mathsf{fma}\left(\frac{1}{x \cdot x}, x, \mathsf{neg}\left(\color{blue}{\frac{1}{x}}\right)\right)}{x} \]
    7. Step-by-step derivation
      1. /-lowering-/.f6455.9

        \[\leadsto \frac{\mathsf{fma}\left(\frac{1}{x \cdot x}, x, -\color{blue}{\frac{1}{x}}\right)}{x} \]
    8. Simplified55.9%

      \[\leadsto \frac{\mathsf{fma}\left(\frac{1}{x \cdot x}, x, -\color{blue}{\frac{1}{x}}\right)}{x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification62.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1.5 \cdot 10^{+29}:\\ \;\;\;\;\mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, x \cdot 0.001388888888888889, -0.041666666666666664\right), 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{1}{x \cdot x}, x, \frac{-1}{x}\right)}{x}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 63.3% accurate, 4.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 6.5 \cdot 10^{+38}:\\ \;\;\;\;\mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, x \cdot 0.001388888888888889, -0.041666666666666664\right), 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 6.5e+38)
   (fma x (* x (fma x (* x 0.001388888888888889) -0.041666666666666664)) 0.5)
   0.0))
double code(double x) {
	double tmp;
	if (x <= 6.5e+38) {
		tmp = fma(x, (x * fma(x, (x * 0.001388888888888889), -0.041666666666666664)), 0.5);
	} else {
		tmp = 0.0;
	}
	return tmp;
}
function code(x)
	tmp = 0.0
	if (x <= 6.5e+38)
		tmp = fma(x, Float64(x * fma(x, Float64(x * 0.001388888888888889), -0.041666666666666664)), 0.5);
	else
		tmp = 0.0;
	end
	return tmp
end
code[x_] := If[LessEqual[x, 6.5e+38], N[(x * N[(x * N[(x * N[(x * 0.001388888888888889), $MachinePrecision] + -0.041666666666666664), $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision], 0.0]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 6.5 \cdot 10^{+38}:\\
\;\;\;\;\mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, x \cdot 0.001388888888888889, -0.041666666666666664\right), 0.5\right)\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 6.5e38

    1. Initial program 39.4%

      \[\frac{1 - \cos x}{x \cdot x} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. flip--N/A

        \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}{x \cdot x} \]
      2. associate-/l/N/A

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

        \[\leadsto \frac{\color{blue}{1} - \cos x \cdot \cos x}{\left(x \cdot x\right) \cdot \left(1 + \cos x\right)} \]
      4. 1-sub-cosN/A

        \[\leadsto \frac{\color{blue}{\sin x \cdot \sin x}}{\left(x \cdot x\right) \cdot \left(1 + \cos x\right)} \]
      5. times-fracN/A

        \[\leadsto \color{blue}{\frac{\sin x}{x \cdot x} \cdot \frac{\sin x}{1 + \cos x}} \]
      6. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{\frac{\sin x}{x \cdot x} \cdot \frac{\sin x}{1 + \cos x}} \]
      7. /-lowering-/.f64N/A

        \[\leadsto \color{blue}{\frac{\sin x}{x \cdot x}} \cdot \frac{\sin x}{1 + \cos x} \]
      8. sin-lowering-sin.f64N/A

        \[\leadsto \frac{\color{blue}{\sin x}}{x \cdot x} \cdot \frac{\sin x}{1 + \cos x} \]
      9. *-lowering-*.f64N/A

        \[\leadsto \frac{\sin x}{\color{blue}{x \cdot x}} \cdot \frac{\sin x}{1 + \cos x} \]
      10. hang-0p-tanN/A

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

        \[\leadsto \frac{\sin x}{x \cdot x} \cdot \color{blue}{\tan \left(\frac{x}{2}\right)} \]
      12. /-lowering-/.f6474.0

        \[\leadsto \frac{\sin x}{x \cdot x} \cdot \tan \color{blue}{\left(\frac{x}{2}\right)} \]
    4. Applied egg-rr74.0%

      \[\leadsto \color{blue}{\frac{\sin x}{x \cdot x} \cdot \tan \left(\frac{x}{2}\right)} \]
    5. Step-by-step derivation
      1. associate-*l/N/A

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\tan \left(\frac{x}{2}\right)}}{x \cdot x} \cdot \sin x \]
      7. div-invN/A

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

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

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

        \[\leadsto \frac{\tan \left(x \cdot \frac{1}{2}\right)}{\color{blue}{x \cdot x}} \cdot \sin x \]
      11. sin-lowering-sin.f6474.0

        \[\leadsto \frac{\tan \left(x \cdot 0.5\right)}{x \cdot x} \cdot \color{blue}{\sin x} \]
    6. Applied egg-rr74.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 6.5e38 < x

    1. Initial program 97.7%

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

      \[\leadsto \frac{1 - \color{blue}{1}}{x \cdot x} \]
    4. Step-by-step derivation
      1. Simplified57.5%

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

          \[\leadsto \frac{\color{blue}{0}}{x \cdot x} \]
        2. div057.5

          \[\leadsto \color{blue}{0} \]
      3. Applied egg-rr57.5%

        \[\leadsto \color{blue}{0} \]
    5. Recombined 2 regimes into one program.
    6. Add Preprocessing

    Alternative 6: 63.5% accurate, 17.1× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 8.5 \cdot 10^{+76}:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \end{array} \]
    (FPCore (x) :precision binary64 (if (<= x 8.5e+76) 0.5 0.0))
    double code(double x) {
    	double tmp;
    	if (x <= 8.5e+76) {
    		tmp = 0.5;
    	} else {
    		tmp = 0.0;
    	}
    	return tmp;
    }
    
    real(8) function code(x)
        real(8), intent (in) :: x
        real(8) :: tmp
        if (x <= 8.5d+76) then
            tmp = 0.5d0
        else
            tmp = 0.0d0
        end if
        code = tmp
    end function
    
    public static double code(double x) {
    	double tmp;
    	if (x <= 8.5e+76) {
    		tmp = 0.5;
    	} else {
    		tmp = 0.0;
    	}
    	return tmp;
    }
    
    def code(x):
    	tmp = 0
    	if x <= 8.5e+76:
    		tmp = 0.5
    	else:
    		tmp = 0.0
    	return tmp
    
    function code(x)
    	tmp = 0.0
    	if (x <= 8.5e+76)
    		tmp = 0.5;
    	else
    		tmp = 0.0;
    	end
    	return tmp
    end
    
    function tmp_2 = code(x)
    	tmp = 0.0;
    	if (x <= 8.5e+76)
    		tmp = 0.5;
    	else
    		tmp = 0.0;
    	end
    	tmp_2 = tmp;
    end
    
    code[x_] := If[LessEqual[x, 8.5e+76], 0.5, 0.0]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;x \leq 8.5 \cdot 10^{+76}:\\
    \;\;\;\;0.5\\
    
    \mathbf{else}:\\
    \;\;\;\;0\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if x < 8.49999999999999992e76

      1. Initial program 42.1%

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

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

          \[\leadsto \color{blue}{0.5} \]

        if 8.49999999999999992e76 < x

        1. Initial program 97.4%

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

          \[\leadsto \frac{1 - \color{blue}{1}}{x \cdot x} \]
        4. Step-by-step derivation
          1. Simplified71.2%

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

              \[\leadsto \frac{\color{blue}{0}}{x \cdot x} \]
            2. div071.2

              \[\leadsto \color{blue}{0} \]
          3. Applied egg-rr71.2%

            \[\leadsto \color{blue}{0} \]
        5. Recombined 2 regimes into one program.
        6. Add Preprocessing

        Alternative 7: 28.0% accurate, 120.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.5%

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

          \[\leadsto \frac{1 - \color{blue}{1}}{x \cdot x} \]
        4. Step-by-step derivation
          1. Simplified26.5%

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

              \[\leadsto \frac{\color{blue}{0}}{x \cdot x} \]
            2. div027.1

              \[\leadsto \color{blue}{0} \]
          3. Applied egg-rr27.1%

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

          Reproduce

          ?
          herbie shell --seed 2024194 
          (FPCore (x)
            :name "cos2 (problem 3.4.1)"
            :precision binary64
            (/ (- 1.0 (cos x)) (* x x)))