cos2 (problem 3.4.1)

Percentage Accurate: 50.7% → 99.8%
Time: 13.5s
Alternatives: 6
Speedup: 107.0×

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

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

    \[\frac{1 - \cos x}{x \cdot x} \]
  2. Step-by-step derivation
    1. flip--52.5%

      \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}{x \cdot x} \]
    2. associate-/r*52.5%

      \[\leadsto \color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)}} \]
    3. div-inv52.4%

      \[\leadsto \color{blue}{\left(1 \cdot 1 - \cos x \cdot \cos x\right) \cdot \frac{1}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)}} \]
    4. metadata-eval52.4%

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

      \[\leadsto \color{blue}{\left(\sin x \cdot \sin x\right)} \cdot \frac{1}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
    6. pow274.6%

      \[\leadsto \color{blue}{{\sin x}^{2}} \cdot \frac{1}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
    7. *-commutative74.6%

      \[\leadsto {\sin x}^{2} \cdot \frac{1}{\color{blue}{\left(x \cdot x\right) \cdot \left(1 + \cos x\right)}} \]
    8. associate-*l*74.7%

      \[\leadsto {\sin x}^{2} \cdot \frac{1}{\color{blue}{x \cdot \left(x \cdot \left(1 + \cos x\right)\right)}} \]
    9. +-commutative74.7%

      \[\leadsto {\sin x}^{2} \cdot \frac{1}{x \cdot \left(x \cdot \color{blue}{\left(\cos x + 1\right)}\right)} \]
    10. distribute-lft-in74.6%

      \[\leadsto {\sin x}^{2} \cdot \frac{1}{x \cdot \color{blue}{\left(x \cdot \cos x + x \cdot 1\right)}} \]
    11. *-commutative74.6%

      \[\leadsto {\sin x}^{2} \cdot \frac{1}{x \cdot \left(x \cdot \cos x + \color{blue}{1 \cdot x}\right)} \]
    12. fma-def74.7%

      \[\leadsto {\sin x}^{2} \cdot \frac{1}{x \cdot \color{blue}{\mathsf{fma}\left(x, \cos x, 1 \cdot x\right)}} \]
    13. *-lft-identity74.7%

      \[\leadsto {\sin x}^{2} \cdot \frac{1}{x \cdot \mathsf{fma}\left(x, \cos x, \color{blue}{x}\right)} \]
  3. Applied egg-rr74.7%

    \[\leadsto \color{blue}{{\sin x}^{2} \cdot \frac{1}{x \cdot \mathsf{fma}\left(x, \cos x, x\right)}} \]
  4. Step-by-step derivation
    1. associate-*r/75.5%

      \[\leadsto \color{blue}{\frac{{\sin x}^{2} \cdot 1}{x \cdot \mathsf{fma}\left(x, \cos x, x\right)}} \]
    2. times-frac76.3%

      \[\leadsto \color{blue}{\frac{{\sin x}^{2}}{x} \cdot \frac{1}{\mathsf{fma}\left(x, \cos x, x\right)}} \]
    3. fma-udef76.3%

      \[\leadsto \frac{{\sin x}^{2}}{x} \cdot \frac{1}{\color{blue}{x \cdot \cos x + x}} \]
    4. *-rgt-identity76.3%

      \[\leadsto \frac{{\sin x}^{2}}{x} \cdot \frac{1}{x \cdot \cos x + \color{blue}{x \cdot 1}} \]
    5. distribute-lft-in76.3%

      \[\leadsto \frac{{\sin x}^{2}}{x} \cdot \frac{1}{\color{blue}{x \cdot \left(\cos x + 1\right)}} \]
    6. +-commutative76.3%

      \[\leadsto \frac{{\sin x}^{2}}{x} \cdot \frac{1}{x \cdot \color{blue}{\left(1 + \cos x\right)}} \]
    7. associate-/l/76.3%

      \[\leadsto \frac{{\sin x}^{2}}{x} \cdot \color{blue}{\frac{\frac{1}{1 + \cos x}}{x}} \]
    8. associate-*l/76.3%

      \[\leadsto \color{blue}{\frac{{\sin x}^{2} \cdot \frac{\frac{1}{1 + \cos x}}{x}}{x}} \]
    9. associate-*r/76.3%

      \[\leadsto \frac{\color{blue}{\frac{{\sin x}^{2} \cdot \frac{1}{1 + \cos x}}{x}}}{x} \]
    10. associate-*r/76.3%

      \[\leadsto \frac{\frac{\color{blue}{\frac{{\sin x}^{2} \cdot 1}{1 + \cos x}}}{x}}{x} \]
    11. *-rgt-identity76.3%

      \[\leadsto \frac{\frac{\frac{\color{blue}{{\sin x}^{2}}}{1 + \cos x}}{x}}{x} \]
    12. unpow276.3%

      \[\leadsto \frac{\frac{\frac{\color{blue}{\sin x \cdot \sin x}}{1 + \cos x}}{x}}{x} \]
    13. associate-*l/76.3%

      \[\leadsto \frac{\frac{\color{blue}{\frac{\sin x}{1 + \cos x} \cdot \sin x}}{x}}{x} \]
    14. hang-0p-tan76.5%

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

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

      \[\leadsto \color{blue}{\tan \left(\frac{x}{2}\right) \cdot \frac{\sin x}{x \cdot x}} \]
  5. Simplified75.7%

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

      \[\leadsto \color{blue}{\frac{\sin x \cdot \tan \left(\frac{x}{2}\right)}{x \cdot x}} \]
    2. times-frac99.8%

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

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

      \[\leadsto \frac{\sin x \cdot \frac{\tan \color{blue}{\left(x \cdot \frac{1}{2}\right)}}{x}}{x} \]
    5. metadata-eval99.8%

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

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

    \[\leadsto \frac{\sin x \cdot \frac{\tan \left(x \cdot 0.5\right)}{x}}{x} \]

Alternative 2: 87.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 0.029:\\ \;\;\;\;\frac{--1}{\left(x \cdot x\right) \cdot \left(0.16666666666666666 + x \cdot \left(x \cdot 0.008333333333333333\right)\right) + 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x}}{x} \cdot \left(1 - \cos x\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 0.029)
   (/
    (- -1.0)
    (+
     (* (* x x) (+ 0.16666666666666666 (* x (* x 0.008333333333333333))))
     2.0))
   (* (/ (/ 1.0 x) x) (- 1.0 (cos x)))))
double code(double x) {
	double tmp;
	if (x <= 0.029) {
		tmp = -(-1.0) / (((x * x) * (0.16666666666666666 + (x * (x * 0.008333333333333333)))) + 2.0);
	} else {
		tmp = ((1.0 / x) / x) * (1.0 - cos(x));
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 0.029d0) then
        tmp = -(-1.0d0) / (((x * x) * (0.16666666666666666d0 + (x * (x * 0.008333333333333333d0)))) + 2.0d0)
    else
        tmp = ((1.0d0 / x) / x) * (1.0d0 - cos(x))
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= 0.029) {
		tmp = -(-1.0) / (((x * x) * (0.16666666666666666 + (x * (x * 0.008333333333333333)))) + 2.0);
	} else {
		tmp = ((1.0 / x) / x) * (1.0 - Math.cos(x));
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= 0.029:
		tmp = -(-1.0) / (((x * x) * (0.16666666666666666 + (x * (x * 0.008333333333333333)))) + 2.0)
	else:
		tmp = ((1.0 / x) / x) * (1.0 - math.cos(x))
	return tmp
function code(x)
	tmp = 0.0
	if (x <= 0.029)
		tmp = Float64(Float64(-(-1.0)) / Float64(Float64(Float64(x * x) * Float64(0.16666666666666666 + Float64(x * Float64(x * 0.008333333333333333)))) + 2.0));
	else
		tmp = Float64(Float64(Float64(1.0 / x) / x) * Float64(1.0 - cos(x)));
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= 0.029)
		tmp = -(-1.0) / (((x * x) * (0.16666666666666666 + (x * (x * 0.008333333333333333)))) + 2.0);
	else
		tmp = ((1.0 / x) / x) * (1.0 - cos(x));
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, 0.029], N[((--1.0) / N[(N[(N[(x * x), $MachinePrecision] * N[(0.16666666666666666 + N[(x * N[(x * 0.008333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(1.0 / x), $MachinePrecision] / x), $MachinePrecision] * N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.029:\\
\;\;\;\;\frac{--1}{\left(x \cdot x\right) \cdot \left(0.16666666666666666 + x \cdot \left(x \cdot 0.008333333333333333\right)\right) + 2}\\

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


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

    1. Initial program 36.6%

      \[\frac{1 - \cos x}{x \cdot x} \]
    2. Step-by-step derivation
      1. remove-double-div36.6%

        \[\leadsto \frac{\color{blue}{\frac{1}{\frac{1}{1 - \cos x}}}}{x \cdot x} \]
    3. Applied egg-rr36.6%

      \[\leadsto \frac{\color{blue}{\frac{1}{\frac{1}{1 - \cos x}}}}{x \cdot x} \]
    4. Taylor expanded in x around 0 50.2%

      \[\leadsto \frac{\frac{1}{\color{blue}{0.16666666666666666 + \left(0.008333333333333333 \cdot {x}^{2} + 2 \cdot \frac{1}{{x}^{2}}\right)}}}{x \cdot x} \]
    5. Step-by-step derivation
      1. fma-def50.2%

        \[\leadsto \frac{\frac{1}{0.16666666666666666 + \color{blue}{\mathsf{fma}\left(0.008333333333333333, {x}^{2}, 2 \cdot \frac{1}{{x}^{2}}\right)}}}{x \cdot x} \]
      2. unpow250.2%

        \[\leadsto \frac{\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, \color{blue}{x \cdot x}, 2 \cdot \frac{1}{{x}^{2}}\right)}}{x \cdot x} \]
      3. unpow250.2%

        \[\leadsto \frac{\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, 2 \cdot \frac{1}{\color{blue}{x \cdot x}}\right)}}{x \cdot x} \]
      4. associate-*r/50.2%

        \[\leadsto \frac{\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \color{blue}{\frac{2 \cdot 1}{x \cdot x}}\right)}}{x \cdot x} \]
      5. metadata-eval50.2%

        \[\leadsto \frac{\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{\color{blue}{2}}{x \cdot x}\right)}}{x \cdot x} \]
    6. Simplified50.2%

      \[\leadsto \frac{\frac{1}{\color{blue}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}}}{x \cdot x} \]
    7. Step-by-step derivation
      1. frac-2neg50.2%

        \[\leadsto \color{blue}{\frac{-\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}}{-x \cdot x}} \]
      2. distribute-frac-neg50.2%

        \[\leadsto \color{blue}{-\frac{\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}}{-x \cdot x}} \]
      3. remove-double-neg50.2%

        \[\leadsto -\frac{\color{blue}{-\left(-\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}\right)}}{-x \cdot x} \]
      4. neg-mul-150.2%

        \[\leadsto -\frac{\color{blue}{-1 \cdot \left(-\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}\right)}}{-x \cdot x} \]
      5. metadata-eval50.2%

        \[\leadsto -\frac{\color{blue}{\left(-1\right)} \cdot \left(-\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}\right)}{-x \cdot x} \]
      6. associate-/l*50.2%

        \[\leadsto -\color{blue}{\frac{-1}{\frac{-x \cdot x}{-\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}}}} \]
      7. metadata-eval50.2%

        \[\leadsto -\frac{\color{blue}{-1}}{\frac{-x \cdot x}{-\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}}} \]
      8. frac-2neg50.2%

        \[\leadsto -\frac{-1}{\color{blue}{\frac{x \cdot x}{\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}}}} \]
      9. div-inv50.3%

        \[\leadsto -\frac{-1}{\color{blue}{\left(x \cdot x\right) \cdot \frac{1}{\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}}}} \]
      10. remove-double-div50.3%

        \[\leadsto -\frac{-1}{\left(x \cdot x\right) \cdot \color{blue}{\left(0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)\right)}} \]
      11. fma-udef50.3%

        \[\leadsto -\frac{-1}{\left(x \cdot x\right) \cdot \left(0.16666666666666666 + \color{blue}{\left(0.008333333333333333 \cdot \left(x \cdot x\right) + \frac{2}{x \cdot x}\right)}\right)} \]
      12. associate-+r+50.3%

        \[\leadsto -\frac{-1}{\left(x \cdot x\right) \cdot \color{blue}{\left(\left(0.16666666666666666 + 0.008333333333333333 \cdot \left(x \cdot x\right)\right) + \frac{2}{x \cdot x}\right)}} \]
      13. distribute-lft-in33.0%

        \[\leadsto -\frac{-1}{\color{blue}{\left(x \cdot x\right) \cdot \left(0.16666666666666666 + 0.008333333333333333 \cdot \left(x \cdot x\right)\right) + \left(x \cdot x\right) \cdot \frac{2}{x \cdot x}}} \]
    8. Applied egg-rr82.9%

      \[\leadsto \color{blue}{-\frac{-1}{\left(x \cdot x\right) \cdot \left(0.16666666666666666 + x \cdot \left(x \cdot 0.008333333333333333\right)\right) + 2}} \]

    if 0.0290000000000000015 < x

    1. Initial program 98.5%

      \[\frac{1 - \cos x}{x \cdot x} \]
    2. Step-by-step derivation
      1. flip--98.2%

        \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}{x \cdot x} \]
      2. div-inv98.1%

        \[\leadsto \frac{\color{blue}{\left(1 \cdot 1 - \cos x \cdot \cos x\right) \cdot \frac{1}{1 + \cos x}}}{x \cdot x} \]
      3. times-frac99.1%

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{x} \cdot \frac{\frac{1}{1 + \cos x}}{x}} \]
      4. metadata-eval99.1%

        \[\leadsto \frac{\color{blue}{1} - \cos x \cdot \cos x}{x} \cdot \frac{\frac{1}{1 + \cos x}}{x} \]
      5. 1-sub-cos99.0%

        \[\leadsto \frac{\color{blue}{\sin x \cdot \sin x}}{x} \cdot \frac{\frac{1}{1 + \cos x}}{x} \]
      6. pow299.0%

        \[\leadsto \frac{\color{blue}{{\sin x}^{2}}}{x} \cdot \frac{\frac{1}{1 + \cos x}}{x} \]
    3. Applied egg-rr99.0%

      \[\leadsto \color{blue}{\frac{{\sin x}^{2}}{x} \cdot \frac{\frac{1}{1 + \cos x}}{x}} \]
    4. Step-by-step derivation
      1. frac-times97.9%

        \[\leadsto \color{blue}{\frac{{\sin x}^{2} \cdot \frac{1}{1 + \cos x}}{x \cdot x}} \]
      2. div-inv97.9%

        \[\leadsto \frac{\color{blue}{\frac{{\sin x}^{2}}{1 + \cos x}}}{x \cdot x} \]
      3. unpow297.9%

        \[\leadsto \frac{\frac{\color{blue}{\sin x \cdot \sin x}}{1 + \cos x}}{x \cdot x} \]
      4. 1-sub-cos98.2%

        \[\leadsto \frac{\frac{\color{blue}{1 - \cos x \cdot \cos x}}{1 + \cos x}}{x \cdot x} \]
      5. metadata-eval98.2%

        \[\leadsto \frac{\frac{\color{blue}{1 \cdot 1} - \cos x \cdot \cos x}{1 + \cos x}}{x \cdot x} \]
      6. flip--98.5%

        \[\leadsto \frac{\color{blue}{1 - \cos x}}{x \cdot x} \]
      7. remove-double-div98.5%

        \[\leadsto \frac{\color{blue}{\frac{1}{\frac{1}{1 - \cos x}}}}{x \cdot x} \]
      8. clear-num98.5%

        \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot x}{\frac{1}{\frac{1}{1 - \cos x}}}}} \]
      9. associate-*r/98.5%

        \[\leadsto \frac{1}{\color{blue}{x \cdot \frac{x}{\frac{1}{\frac{1}{1 - \cos x}}}}} \]
      10. remove-double-div98.6%

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

      \[\leadsto \color{blue}{\frac{1}{x \cdot \frac{x}{1 - \cos x}}} \]
    6. Step-by-step derivation
      1. associate-/r*99.4%

        \[\leadsto \color{blue}{\frac{\frac{1}{x}}{\frac{x}{1 - \cos x}}} \]
      2. associate-/r/99.5%

        \[\leadsto \color{blue}{\frac{\frac{1}{x}}{x} \cdot \left(1 - \cos x\right)} \]
    7. Simplified99.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 0.029:\\ \;\;\;\;\frac{--1}{\left(x \cdot x\right) \cdot \left(0.16666666666666666 + x \cdot \left(x \cdot 0.008333333333333333\right)\right) + 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x}}{x} \cdot \left(1 - \cos x\right)\\ \end{array} \]

Alternative 3: 87.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 0.029:\\ \;\;\;\;\frac{--1}{\left(x \cdot x\right) \cdot \left(0.16666666666666666 + x \cdot \left(x \cdot 0.008333333333333333\right)\right) + 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1 - \cos x}{x \cdot x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 0.029)
   (/
    (- -1.0)
    (+
     (* (* x x) (+ 0.16666666666666666 (* x (* x 0.008333333333333333))))
     2.0))
   (/ (- 1.0 (cos x)) (* x x))))
double code(double x) {
	double tmp;
	if (x <= 0.029) {
		tmp = -(-1.0) / (((x * x) * (0.16666666666666666 + (x * (x * 0.008333333333333333)))) + 2.0);
	} else {
		tmp = (1.0 - cos(x)) / (x * x);
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 0.029d0) then
        tmp = -(-1.0d0) / (((x * x) * (0.16666666666666666d0 + (x * (x * 0.008333333333333333d0)))) + 2.0d0)
    else
        tmp = (1.0d0 - cos(x)) / (x * x)
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= 0.029) {
		tmp = -(-1.0) / (((x * x) * (0.16666666666666666 + (x * (x * 0.008333333333333333)))) + 2.0);
	} else {
		tmp = (1.0 - Math.cos(x)) / (x * x);
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= 0.029:
		tmp = -(-1.0) / (((x * x) * (0.16666666666666666 + (x * (x * 0.008333333333333333)))) + 2.0)
	else:
		tmp = (1.0 - math.cos(x)) / (x * x)
	return tmp
function code(x)
	tmp = 0.0
	if (x <= 0.029)
		tmp = Float64(Float64(-(-1.0)) / Float64(Float64(Float64(x * x) * Float64(0.16666666666666666 + Float64(x * Float64(x * 0.008333333333333333)))) + 2.0));
	else
		tmp = Float64(Float64(1.0 - cos(x)) / Float64(x * x));
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= 0.029)
		tmp = -(-1.0) / (((x * x) * (0.16666666666666666 + (x * (x * 0.008333333333333333)))) + 2.0);
	else
		tmp = (1.0 - cos(x)) / (x * x);
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, 0.029], N[((--1.0) / N[(N[(N[(x * x), $MachinePrecision] * N[(0.16666666666666666 + N[(x * N[(x * 0.008333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 2.0), $MachinePrecision]), $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.029:\\
\;\;\;\;\frac{--1}{\left(x \cdot x\right) \cdot \left(0.16666666666666666 + x \cdot \left(x \cdot 0.008333333333333333\right)\right) + 2}\\

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


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

    1. Initial program 36.6%

      \[\frac{1 - \cos x}{x \cdot x} \]
    2. Step-by-step derivation
      1. remove-double-div36.6%

        \[\leadsto \frac{\color{blue}{\frac{1}{\frac{1}{1 - \cos x}}}}{x \cdot x} \]
    3. Applied egg-rr36.6%

      \[\leadsto \frac{\color{blue}{\frac{1}{\frac{1}{1 - \cos x}}}}{x \cdot x} \]
    4. Taylor expanded in x around 0 50.2%

      \[\leadsto \frac{\frac{1}{\color{blue}{0.16666666666666666 + \left(0.008333333333333333 \cdot {x}^{2} + 2 \cdot \frac{1}{{x}^{2}}\right)}}}{x \cdot x} \]
    5. Step-by-step derivation
      1. fma-def50.2%

        \[\leadsto \frac{\frac{1}{0.16666666666666666 + \color{blue}{\mathsf{fma}\left(0.008333333333333333, {x}^{2}, 2 \cdot \frac{1}{{x}^{2}}\right)}}}{x \cdot x} \]
      2. unpow250.2%

        \[\leadsto \frac{\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, \color{blue}{x \cdot x}, 2 \cdot \frac{1}{{x}^{2}}\right)}}{x \cdot x} \]
      3. unpow250.2%

        \[\leadsto \frac{\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, 2 \cdot \frac{1}{\color{blue}{x \cdot x}}\right)}}{x \cdot x} \]
      4. associate-*r/50.2%

        \[\leadsto \frac{\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \color{blue}{\frac{2 \cdot 1}{x \cdot x}}\right)}}{x \cdot x} \]
      5. metadata-eval50.2%

        \[\leadsto \frac{\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{\color{blue}{2}}{x \cdot x}\right)}}{x \cdot x} \]
    6. Simplified50.2%

      \[\leadsto \frac{\frac{1}{\color{blue}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}}}{x \cdot x} \]
    7. Step-by-step derivation
      1. frac-2neg50.2%

        \[\leadsto \color{blue}{\frac{-\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}}{-x \cdot x}} \]
      2. distribute-frac-neg50.2%

        \[\leadsto \color{blue}{-\frac{\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}}{-x \cdot x}} \]
      3. remove-double-neg50.2%

        \[\leadsto -\frac{\color{blue}{-\left(-\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}\right)}}{-x \cdot x} \]
      4. neg-mul-150.2%

        \[\leadsto -\frac{\color{blue}{-1 \cdot \left(-\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}\right)}}{-x \cdot x} \]
      5. metadata-eval50.2%

        \[\leadsto -\frac{\color{blue}{\left(-1\right)} \cdot \left(-\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}\right)}{-x \cdot x} \]
      6. associate-/l*50.2%

        \[\leadsto -\color{blue}{\frac{-1}{\frac{-x \cdot x}{-\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}}}} \]
      7. metadata-eval50.2%

        \[\leadsto -\frac{\color{blue}{-1}}{\frac{-x \cdot x}{-\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}}} \]
      8. frac-2neg50.2%

        \[\leadsto -\frac{-1}{\color{blue}{\frac{x \cdot x}{\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}}}} \]
      9. div-inv50.3%

        \[\leadsto -\frac{-1}{\color{blue}{\left(x \cdot x\right) \cdot \frac{1}{\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}}}} \]
      10. remove-double-div50.3%

        \[\leadsto -\frac{-1}{\left(x \cdot x\right) \cdot \color{blue}{\left(0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)\right)}} \]
      11. fma-udef50.3%

        \[\leadsto -\frac{-1}{\left(x \cdot x\right) \cdot \left(0.16666666666666666 + \color{blue}{\left(0.008333333333333333 \cdot \left(x \cdot x\right) + \frac{2}{x \cdot x}\right)}\right)} \]
      12. associate-+r+50.3%

        \[\leadsto -\frac{-1}{\left(x \cdot x\right) \cdot \color{blue}{\left(\left(0.16666666666666666 + 0.008333333333333333 \cdot \left(x \cdot x\right)\right) + \frac{2}{x \cdot x}\right)}} \]
      13. distribute-lft-in33.0%

        \[\leadsto -\frac{-1}{\color{blue}{\left(x \cdot x\right) \cdot \left(0.16666666666666666 + 0.008333333333333333 \cdot \left(x \cdot x\right)\right) + \left(x \cdot x\right) \cdot \frac{2}{x \cdot x}}} \]
    8. Applied egg-rr82.9%

      \[\leadsto \color{blue}{-\frac{-1}{\left(x \cdot x\right) \cdot \left(0.16666666666666666 + x \cdot \left(x \cdot 0.008333333333333333\right)\right) + 2}} \]

    if 0.0290000000000000015 < x

    1. Initial program 98.5%

      \[\frac{1 - \cos x}{x \cdot x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification86.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 0.029:\\ \;\;\;\;\frac{--1}{\left(x \cdot x\right) \cdot \left(0.16666666666666666 + x \cdot \left(x \cdot 0.008333333333333333\right)\right) + 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1 - \cos x}{x \cdot x}\\ \end{array} \]

Alternative 4: 87.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 0.029:\\ \;\;\;\;\frac{--1}{\left(x \cdot x\right) \cdot \left(0.16666666666666666 + x \cdot \left(x \cdot 0.008333333333333333\right)\right) + 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1 - \cos x}{x}}{x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 0.029)
   (/
    (- -1.0)
    (+
     (* (* x x) (+ 0.16666666666666666 (* x (* x 0.008333333333333333))))
     2.0))
   (/ (/ (- 1.0 (cos x)) x) x)))
double code(double x) {
	double tmp;
	if (x <= 0.029) {
		tmp = -(-1.0) / (((x * x) * (0.16666666666666666 + (x * (x * 0.008333333333333333)))) + 2.0);
	} else {
		tmp = ((1.0 - cos(x)) / x) / x;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 0.029d0) then
        tmp = -(-1.0d0) / (((x * x) * (0.16666666666666666d0 + (x * (x * 0.008333333333333333d0)))) + 2.0d0)
    else
        tmp = ((1.0d0 - cos(x)) / x) / x
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= 0.029) {
		tmp = -(-1.0) / (((x * x) * (0.16666666666666666 + (x * (x * 0.008333333333333333)))) + 2.0);
	} else {
		tmp = ((1.0 - Math.cos(x)) / x) / x;
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= 0.029:
		tmp = -(-1.0) / (((x * x) * (0.16666666666666666 + (x * (x * 0.008333333333333333)))) + 2.0)
	else:
		tmp = ((1.0 - math.cos(x)) / x) / x
	return tmp
function code(x)
	tmp = 0.0
	if (x <= 0.029)
		tmp = Float64(Float64(-(-1.0)) / Float64(Float64(Float64(x * x) * Float64(0.16666666666666666 + Float64(x * Float64(x * 0.008333333333333333)))) + 2.0));
	else
		tmp = Float64(Float64(Float64(1.0 - cos(x)) / x) / x);
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= 0.029)
		tmp = -(-1.0) / (((x * x) * (0.16666666666666666 + (x * (x * 0.008333333333333333)))) + 2.0);
	else
		tmp = ((1.0 - cos(x)) / x) / x;
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, 0.029], N[((--1.0) / N[(N[(N[(x * x), $MachinePrecision] * N[(0.16666666666666666 + N[(x * N[(x * 0.008333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 2.0), $MachinePrecision]), $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.029:\\
\;\;\;\;\frac{--1}{\left(x \cdot x\right) \cdot \left(0.16666666666666666 + x \cdot \left(x \cdot 0.008333333333333333\right)\right) + 2}\\

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


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

    1. Initial program 36.6%

      \[\frac{1 - \cos x}{x \cdot x} \]
    2. Step-by-step derivation
      1. remove-double-div36.6%

        \[\leadsto \frac{\color{blue}{\frac{1}{\frac{1}{1 - \cos x}}}}{x \cdot x} \]
    3. Applied egg-rr36.6%

      \[\leadsto \frac{\color{blue}{\frac{1}{\frac{1}{1 - \cos x}}}}{x \cdot x} \]
    4. Taylor expanded in x around 0 50.2%

      \[\leadsto \frac{\frac{1}{\color{blue}{0.16666666666666666 + \left(0.008333333333333333 \cdot {x}^{2} + 2 \cdot \frac{1}{{x}^{2}}\right)}}}{x \cdot x} \]
    5. Step-by-step derivation
      1. fma-def50.2%

        \[\leadsto \frac{\frac{1}{0.16666666666666666 + \color{blue}{\mathsf{fma}\left(0.008333333333333333, {x}^{2}, 2 \cdot \frac{1}{{x}^{2}}\right)}}}{x \cdot x} \]
      2. unpow250.2%

        \[\leadsto \frac{\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, \color{blue}{x \cdot x}, 2 \cdot \frac{1}{{x}^{2}}\right)}}{x \cdot x} \]
      3. unpow250.2%

        \[\leadsto \frac{\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, 2 \cdot \frac{1}{\color{blue}{x \cdot x}}\right)}}{x \cdot x} \]
      4. associate-*r/50.2%

        \[\leadsto \frac{\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \color{blue}{\frac{2 \cdot 1}{x \cdot x}}\right)}}{x \cdot x} \]
      5. metadata-eval50.2%

        \[\leadsto \frac{\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{\color{blue}{2}}{x \cdot x}\right)}}{x \cdot x} \]
    6. Simplified50.2%

      \[\leadsto \frac{\frac{1}{\color{blue}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}}}{x \cdot x} \]
    7. Step-by-step derivation
      1. frac-2neg50.2%

        \[\leadsto \color{blue}{\frac{-\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}}{-x \cdot x}} \]
      2. distribute-frac-neg50.2%

        \[\leadsto \color{blue}{-\frac{\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}}{-x \cdot x}} \]
      3. remove-double-neg50.2%

        \[\leadsto -\frac{\color{blue}{-\left(-\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}\right)}}{-x \cdot x} \]
      4. neg-mul-150.2%

        \[\leadsto -\frac{\color{blue}{-1 \cdot \left(-\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}\right)}}{-x \cdot x} \]
      5. metadata-eval50.2%

        \[\leadsto -\frac{\color{blue}{\left(-1\right)} \cdot \left(-\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}\right)}{-x \cdot x} \]
      6. associate-/l*50.2%

        \[\leadsto -\color{blue}{\frac{-1}{\frac{-x \cdot x}{-\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}}}} \]
      7. metadata-eval50.2%

        \[\leadsto -\frac{\color{blue}{-1}}{\frac{-x \cdot x}{-\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}}} \]
      8. frac-2neg50.2%

        \[\leadsto -\frac{-1}{\color{blue}{\frac{x \cdot x}{\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}}}} \]
      9. div-inv50.3%

        \[\leadsto -\frac{-1}{\color{blue}{\left(x \cdot x\right) \cdot \frac{1}{\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}}}} \]
      10. remove-double-div50.3%

        \[\leadsto -\frac{-1}{\left(x \cdot x\right) \cdot \color{blue}{\left(0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)\right)}} \]
      11. fma-udef50.3%

        \[\leadsto -\frac{-1}{\left(x \cdot x\right) \cdot \left(0.16666666666666666 + \color{blue}{\left(0.008333333333333333 \cdot \left(x \cdot x\right) + \frac{2}{x \cdot x}\right)}\right)} \]
      12. associate-+r+50.3%

        \[\leadsto -\frac{-1}{\left(x \cdot x\right) \cdot \color{blue}{\left(\left(0.16666666666666666 + 0.008333333333333333 \cdot \left(x \cdot x\right)\right) + \frac{2}{x \cdot x}\right)}} \]
      13. distribute-lft-in33.0%

        \[\leadsto -\frac{-1}{\color{blue}{\left(x \cdot x\right) \cdot \left(0.16666666666666666 + 0.008333333333333333 \cdot \left(x \cdot x\right)\right) + \left(x \cdot x\right) \cdot \frac{2}{x \cdot x}}} \]
    8. Applied egg-rr82.9%

      \[\leadsto \color{blue}{-\frac{-1}{\left(x \cdot x\right) \cdot \left(0.16666666666666666 + x \cdot \left(x \cdot 0.008333333333333333\right)\right) + 2}} \]

    if 0.0290000000000000015 < x

    1. Initial program 98.5%

      \[\frac{1 - \cos x}{x \cdot x} \]
    2. Step-by-step derivation
      1. flip--98.2%

        \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}{x \cdot x} \]
      2. div-inv98.1%

        \[\leadsto \frac{\color{blue}{\left(1 \cdot 1 - \cos x \cdot \cos x\right) \cdot \frac{1}{1 + \cos x}}}{x \cdot x} \]
      3. times-frac99.1%

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{x} \cdot \frac{\frac{1}{1 + \cos x}}{x}} \]
      4. metadata-eval99.1%

        \[\leadsto \frac{\color{blue}{1} - \cos x \cdot \cos x}{x} \cdot \frac{\frac{1}{1 + \cos x}}{x} \]
      5. 1-sub-cos99.0%

        \[\leadsto \frac{\color{blue}{\sin x \cdot \sin x}}{x} \cdot \frac{\frac{1}{1 + \cos x}}{x} \]
      6. pow299.0%

        \[\leadsto \frac{\color{blue}{{\sin x}^{2}}}{x} \cdot \frac{\frac{1}{1 + \cos x}}{x} \]
    3. Applied egg-rr99.0%

      \[\leadsto \color{blue}{\frac{{\sin x}^{2}}{x} \cdot \frac{\frac{1}{1 + \cos x}}{x}} \]
    4. Step-by-step derivation
      1. associate-*r/99.0%

        \[\leadsto \color{blue}{\frac{\frac{{\sin x}^{2}}{x} \cdot \frac{1}{1 + \cos x}}{x}} \]
      2. associate-*l/99.0%

        \[\leadsto \frac{\color{blue}{\frac{{\sin x}^{2} \cdot \frac{1}{1 + \cos x}}{x}}}{x} \]
      3. div-inv99.1%

        \[\leadsto \frac{\frac{\color{blue}{\frac{{\sin x}^{2}}{1 + \cos x}}}{x}}{x} \]
      4. unpow299.1%

        \[\leadsto \frac{\frac{\frac{\color{blue}{\sin x \cdot \sin x}}{1 + \cos x}}{x}}{x} \]
      5. 1-sub-cos99.3%

        \[\leadsto \frac{\frac{\frac{\color{blue}{1 - \cos x \cdot \cos x}}{1 + \cos x}}{x}}{x} \]
      6. metadata-eval99.3%

        \[\leadsto \frac{\frac{\frac{\color{blue}{1 \cdot 1} - \cos x \cdot \cos x}{1 + \cos x}}{x}}{x} \]
      7. flip--99.5%

        \[\leadsto \frac{\frac{\color{blue}{1 - \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. Final simplification87.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 0.029:\\ \;\;\;\;\frac{--1}{\left(x \cdot x\right) \cdot \left(0.16666666666666666 + x \cdot \left(x \cdot 0.008333333333333333\right)\right) + 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1 - \cos x}{x}}{x}\\ \end{array} \]

Alternative 5: 78.1% accurate, 10.7× speedup?

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

\\
\frac{--1}{2 + x \cdot \left(x \cdot 0.16666666666666666\right)}
\end{array}
Derivation
  1. Initial program 52.6%

    \[\frac{1 - \cos x}{x \cdot x} \]
  2. Step-by-step derivation
    1. remove-double-div52.5%

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

    \[\leadsto \frac{\color{blue}{\frac{1}{\frac{1}{1 - \cos x}}}}{x \cdot x} \]
  4. Taylor expanded in x around 0 52.0%

    \[\leadsto \frac{\frac{1}{\color{blue}{0.16666666666666666 + \left(0.008333333333333333 \cdot {x}^{2} + 2 \cdot \frac{1}{{x}^{2}}\right)}}}{x \cdot x} \]
  5. Step-by-step derivation
    1. fma-def52.0%

      \[\leadsto \frac{\frac{1}{0.16666666666666666 + \color{blue}{\mathsf{fma}\left(0.008333333333333333, {x}^{2}, 2 \cdot \frac{1}{{x}^{2}}\right)}}}{x \cdot x} \]
    2. unpow252.0%

      \[\leadsto \frac{\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, \color{blue}{x \cdot x}, 2 \cdot \frac{1}{{x}^{2}}\right)}}{x \cdot x} \]
    3. unpow252.0%

      \[\leadsto \frac{\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, 2 \cdot \frac{1}{\color{blue}{x \cdot x}}\right)}}{x \cdot x} \]
    4. associate-*r/52.0%

      \[\leadsto \frac{\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \color{blue}{\frac{2 \cdot 1}{x \cdot x}}\right)}}{x \cdot x} \]
    5. metadata-eval52.0%

      \[\leadsto \frac{\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{\color{blue}{2}}{x \cdot x}\right)}}{x \cdot x} \]
  6. Simplified52.0%

    \[\leadsto \frac{\frac{1}{\color{blue}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}}}{x \cdot x} \]
  7. Step-by-step derivation
    1. frac-2neg52.0%

      \[\leadsto \color{blue}{\frac{-\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}}{-x \cdot x}} \]
    2. distribute-frac-neg52.0%

      \[\leadsto \color{blue}{-\frac{\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}}{-x \cdot x}} \]
    3. remove-double-neg52.0%

      \[\leadsto -\frac{\color{blue}{-\left(-\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}\right)}}{-x \cdot x} \]
    4. neg-mul-152.0%

      \[\leadsto -\frac{\color{blue}{-1 \cdot \left(-\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}\right)}}{-x \cdot x} \]
    5. metadata-eval52.0%

      \[\leadsto -\frac{\color{blue}{\left(-1\right)} \cdot \left(-\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}\right)}{-x \cdot x} \]
    6. associate-/l*51.9%

      \[\leadsto -\color{blue}{\frac{-1}{\frac{-x \cdot x}{-\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}}}} \]
    7. metadata-eval51.9%

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

      \[\leadsto -\frac{-1}{\color{blue}{\frac{x \cdot x}{\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}}}} \]
    9. div-inv52.0%

      \[\leadsto -\frac{-1}{\color{blue}{\left(x \cdot x\right) \cdot \frac{1}{\frac{1}{0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)}}}} \]
    10. remove-double-div52.0%

      \[\leadsto -\frac{-1}{\left(x \cdot x\right) \cdot \color{blue}{\left(0.16666666666666666 + \mathsf{fma}\left(0.008333333333333333, x \cdot x, \frac{2}{x \cdot x}\right)\right)}} \]
    11. fma-udef52.0%

      \[\leadsto -\frac{-1}{\left(x \cdot x\right) \cdot \left(0.16666666666666666 + \color{blue}{\left(0.008333333333333333 \cdot \left(x \cdot x\right) + \frac{2}{x \cdot x}\right)}\right)} \]
    12. associate-+r+52.0%

      \[\leadsto -\frac{-1}{\left(x \cdot x\right) \cdot \color{blue}{\left(\left(0.16666666666666666 + 0.008333333333333333 \cdot \left(x \cdot x\right)\right) + \frac{2}{x \cdot x}\right)}} \]
    13. distribute-lft-in25.4%

      \[\leadsto -\frac{-1}{\color{blue}{\left(x \cdot x\right) \cdot \left(0.16666666666666666 + 0.008333333333333333 \cdot \left(x \cdot x\right)\right) + \left(x \cdot x\right) \cdot \frac{2}{x \cdot x}}} \]
  8. Applied egg-rr76.2%

    \[\leadsto \color{blue}{-\frac{-1}{\left(x \cdot x\right) \cdot \left(0.16666666666666666 + x \cdot \left(x \cdot 0.008333333333333333\right)\right) + 2}} \]
  9. Taylor expanded in x around 0 78.3%

    \[\leadsto -\frac{-1}{\color{blue}{0.16666666666666666 \cdot {x}^{2}} + 2} \]
  10. Step-by-step derivation
    1. *-commutative78.3%

      \[\leadsto -\frac{-1}{\color{blue}{{x}^{2} \cdot 0.16666666666666666} + 2} \]
    2. unpow278.3%

      \[\leadsto -\frac{-1}{\color{blue}{\left(x \cdot x\right)} \cdot 0.16666666666666666 + 2} \]
    3. associate-*r*78.3%

      \[\leadsto -\frac{-1}{\color{blue}{x \cdot \left(x \cdot 0.16666666666666666\right)} + 2} \]
  11. Simplified78.3%

    \[\leadsto -\frac{-1}{\color{blue}{x \cdot \left(x \cdot 0.16666666666666666\right)} + 2} \]
  12. Final simplification78.3%

    \[\leadsto \frac{--1}{2 + x \cdot \left(x \cdot 0.16666666666666666\right)} \]

Alternative 6: 51.7% accurate, 107.0× speedup?

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

\\
0.5
\end{array}
Derivation
  1. Initial program 52.6%

    \[\frac{1 - \cos x}{x \cdot x} \]
  2. Taylor expanded in x around 0 49.6%

    \[\leadsto \color{blue}{0.5} \]
  3. Final simplification49.6%

    \[\leadsto 0.5 \]

Reproduce

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