cos2 (problem 3.4.1)

Percentage Accurate: 51.3% → 99.8%
Time: 8.2s
Alternatives: 8
Speedup: 5.2×

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 8 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 51.3% 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{\frac{\tan \left(x \cdot 0.5\right)}{x} \cdot \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(Float64(tan(Float64(x * 0.5)) / x) * sin(x)) / x)
end
function tmp = code(x)
	tmp = ((tan((x * 0.5)) / x) * sin(x)) / x;
end
code[x_] := N[(N[(N[(N[Tan[N[(x * 0.5), $MachinePrecision]], $MachinePrecision] / x), $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}

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

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

      \[\leadsto \color{blue}{\frac{1 - \cos x}{x \cdot x}} \]
    2. lift--.f64N/A

      \[\leadsto \frac{\color{blue}{1 - \cos x}}{x \cdot x} \]
    3. flip--N/A

      \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}{x \cdot x} \]
    4. 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)}} \]
    5. metadata-evalN/A

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin x}{x \cdot x} \cdot \color{blue}{\tan \left(\frac{x}{2}\right)} \]
    16. lower-/.f6473.3

      \[\leadsto \frac{\sin x}{x \cdot x} \cdot \tan \color{blue}{\left(\frac{x}{2}\right)} \]
  4. Applied rewrites73.3%

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

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

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

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

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

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

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

      \[\leadsto \frac{\tan \color{blue}{\left(\frac{x}{2}\right)}}{\frac{x \cdot x}{\sin x}} \]
    8. clear-numN/A

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

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

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

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

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

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

      \[\leadsto \frac{\tan \left(\frac{1}{2} \cdot x\right)}{\color{blue}{x \cdot \frac{x}{\sin x}}} \]
    15. lower-/.f6499.3

      \[\leadsto \frac{\tan \left(0.5 \cdot x\right)}{x \cdot \color{blue}{\frac{x}{\sin x}}} \]
  6. Applied rewrites99.3%

    \[\leadsto \color{blue}{\frac{\tan \left(0.5 \cdot x\right)}{x \cdot \frac{x}{\sin x}}} \]
  7. Step-by-step derivation
    1. lift-/.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\frac{\tan \left(x \cdot \frac{1}{2}\right)}{\color{blue}{-x}} \cdot \sin x}{\mathsf{neg}\left(x\right)} \]
    16. lower-neg.f6499.8

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

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

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

Alternative 2: 99.3% accurate, 0.5× speedup?

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

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

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

      \[\leadsto \color{blue}{\frac{1 - \cos x}{x \cdot x}} \]
    2. lift--.f64N/A

      \[\leadsto \frac{\color{blue}{1 - \cos x}}{x \cdot x} \]
    3. flip--N/A

      \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}{x \cdot x} \]
    4. 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)}} \]
    5. metadata-evalN/A

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin x}{x \cdot x} \cdot \color{blue}{\tan \left(\frac{x}{2}\right)} \]
    16. lower-/.f6473.3

      \[\leadsto \frac{\sin x}{x \cdot x} \cdot \tan \color{blue}{\left(\frac{x}{2}\right)} \]
  4. Applied rewrites73.3%

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

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

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

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

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

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

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

      \[\leadsto \frac{\tan \color{blue}{\left(\frac{x}{2}\right)}}{\frac{x \cdot x}{\sin x}} \]
    8. clear-numN/A

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

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

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

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

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

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

      \[\leadsto \frac{\tan \left(\frac{1}{2} \cdot x\right)}{\color{blue}{x \cdot \frac{x}{\sin x}}} \]
    15. lower-/.f6499.3

      \[\leadsto \frac{\tan \left(0.5 \cdot x\right)}{x \cdot \color{blue}{\frac{x}{\sin x}}} \]
  6. Applied rewrites99.3%

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

Alternative 3: 74.1% accurate, 0.6× speedup?

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

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

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


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

    1. Initial program 32.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-2.48015873015873 \cdot 10^{-5}, x \cdot x, 0.001388888888888889\right), x \cdot x, -0.041666666666666664\right), \color{blue}{x \cdot x}, 0.5\right) \]
    5. Applied rewrites69.4%

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

    if 0.095000000000000001 < x

    1. Initial program 98.7%

      \[\frac{1 - \cos x}{x \cdot x} \]
    2. Add Preprocessing
    3. Applied rewrites99.5%

      \[\leadsto \color{blue}{{x}^{-2} \cdot \left(1 - \cos x\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 74.1% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 0.095:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-2.48015873015873 \cdot 10^{-5}, x \cdot x, 0.001388888888888889\right), x \cdot x, -0.041666666666666664\right), x \cdot x, 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1 - \cos x}{x}}{x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 0.095)
   (fma
    (fma
     (fma -2.48015873015873e-5 (* x x) 0.001388888888888889)
     (* x x)
     -0.041666666666666664)
    (* x x)
    0.5)
   (/ (/ (- 1.0 (cos x)) x) x)))
double code(double x) {
	double tmp;
	if (x <= 0.095) {
		tmp = fma(fma(fma(-2.48015873015873e-5, (x * x), 0.001388888888888889), (x * x), -0.041666666666666664), (x * x), 0.5);
	} else {
		tmp = ((1.0 - cos(x)) / x) / x;
	}
	return tmp;
}
function code(x)
	tmp = 0.0
	if (x <= 0.095)
		tmp = fma(fma(fma(-2.48015873015873e-5, Float64(x * x), 0.001388888888888889), Float64(x * x), -0.041666666666666664), Float64(x * x), 0.5);
	else
		tmp = Float64(Float64(Float64(1.0 - cos(x)) / x) / x);
	end
	return tmp
end
code[x_] := If[LessEqual[x, 0.095], N[(N[(N[(-2.48015873015873e-5 * N[(x * x), $MachinePrecision] + 0.001388888888888889), $MachinePrecision] * N[(x * x), $MachinePrecision] + -0.041666666666666664), $MachinePrecision] * N[(x * x), $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.095:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-2.48015873015873 \cdot 10^{-5}, x \cdot x, 0.001388888888888889\right), x \cdot x, -0.041666666666666664\right), x \cdot x, 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.095000000000000001

    1. Initial program 32.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-2.48015873015873 \cdot 10^{-5}, x \cdot x, 0.001388888888888889\right), x \cdot x, -0.041666666666666664\right), \color{blue}{x \cdot x}, 0.5\right) \]
    5. Applied rewrites69.4%

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

    if 0.095000000000000001 < x

    1. Initial program 98.7%

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

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

Alternative 5: 73.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 0.095:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-2.48015873015873 \cdot 10^{-5}, x \cdot x, 0.001388888888888889\right), x \cdot x, -0.041666666666666664\right), x \cdot x, 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1 - \cos x}{x \cdot x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 0.095)
   (fma
    (fma
     (fma -2.48015873015873e-5 (* x x) 0.001388888888888889)
     (* x x)
     -0.041666666666666664)
    (* x x)
    0.5)
   (/ (- 1.0 (cos x)) (* x x))))
double code(double x) {
	double tmp;
	if (x <= 0.095) {
		tmp = fma(fma(fma(-2.48015873015873e-5, (x * x), 0.001388888888888889), (x * x), -0.041666666666666664), (x * x), 0.5);
	} else {
		tmp = (1.0 - cos(x)) / (x * x);
	}
	return tmp;
}
function code(x)
	tmp = 0.0
	if (x <= 0.095)
		tmp = fma(fma(fma(-2.48015873015873e-5, Float64(x * x), 0.001388888888888889), Float64(x * x), -0.041666666666666664), Float64(x * x), 0.5);
	else
		tmp = Float64(Float64(1.0 - cos(x)) / Float64(x * x));
	end
	return tmp
end
code[x_] := If[LessEqual[x, 0.095], N[(N[(N[(-2.48015873015873e-5 * N[(x * x), $MachinePrecision] + 0.001388888888888889), $MachinePrecision] * N[(x * x), $MachinePrecision] + -0.041666666666666664), $MachinePrecision] * N[(x * x), $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.095:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-2.48015873015873 \cdot 10^{-5}, x \cdot x, 0.001388888888888889\right), x \cdot x, -0.041666666666666664\right), x \cdot x, 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.095000000000000001

    1. Initial program 32.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-2.48015873015873 \cdot 10^{-5}, x \cdot x, 0.001388888888888889\right), x \cdot x, -0.041666666666666664\right), \color{blue}{x \cdot x}, 0.5\right) \]
    5. Applied rewrites69.4%

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

    if 0.095000000000000001 < x

    1. Initial program 98.7%

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

Alternative 6: 62.3% accurate, 4.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 2.85 \cdot 10^{+76}:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{1 - 1}{x \cdot x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 2.85e+76) 0.5 (/ (- 1.0 1.0) (* x x))))
double code(double x) {
	double tmp;
	if (x <= 2.85e+76) {
		tmp = 0.5;
	} else {
		tmp = (1.0 - 1.0) / (x * x);
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 2.85d+76) then
        tmp = 0.5d0
    else
        tmp = (1.0d0 - 1.0d0) / (x * x)
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= 2.85e+76) {
		tmp = 0.5;
	} else {
		tmp = (1.0 - 1.0) / (x * x);
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= 2.85e+76:
		tmp = 0.5
	else:
		tmp = (1.0 - 1.0) / (x * x)
	return tmp
function code(x)
	tmp = 0.0
	if (x <= 2.85e+76)
		tmp = 0.5;
	else
		tmp = Float64(Float64(1.0 - 1.0) / Float64(x * x));
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= 2.85e+76)
		tmp = 0.5;
	else
		tmp = (1.0 - 1.0) / (x * x);
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, 2.85e+76], 0.5, N[(N[(1.0 - 1.0), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.85 \cdot 10^{+76}:\\
\;\;\;\;0.5\\

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


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

    1. Initial program 37.7%

      \[\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. Applied rewrites64.8%

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

      if 2.85000000000000002e76 < x

      1. Initial program 98.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. Applied rewrites61.7%

          \[\leadsto \frac{1 - \color{blue}{1}}{x \cdot x} \]
      5. Recombined 2 regimes into one program.
      6. Add Preprocessing

      Alternative 7: 77.3% accurate, 5.2× speedup?

      \[\begin{array}{l} \\ \frac{-1}{\mathsf{fma}\left(-0.16666666666666666, x \cdot x, -2\right)} \end{array} \]
      (FPCore (x)
       :precision binary64
       (/ -1.0 (fma -0.16666666666666666 (* x x) -2.0)))
      double code(double x) {
      	return -1.0 / fma(-0.16666666666666666, (x * x), -2.0);
      }
      
      function code(x)
      	return Float64(-1.0 / fma(-0.16666666666666666, Float64(x * x), -2.0))
      end
      
      code[x_] := N[(-1.0 / N[(-0.16666666666666666 * N[(x * x), $MachinePrecision] + -2.0), $MachinePrecision]), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \frac{-1}{\mathsf{fma}\left(-0.16666666666666666, x \cdot x, -2\right)}
      \end{array}
      
      Derivation
      1. Initial program 50.1%

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

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

        \[\leadsto \frac{-1}{\color{blue}{\frac{-1}{6} \cdot {x}^{2} - 2}} \]
      5. Step-by-step derivation
        1. sub-negN/A

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

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

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

          \[\leadsto \frac{-1}{\mathsf{fma}\left(\frac{-1}{6}, \color{blue}{x \cdot x}, \mathsf{neg}\left(2\right)\right)} \]
        5. metadata-eval76.7

          \[\leadsto \frac{-1}{\mathsf{fma}\left(-0.16666666666666666, x \cdot x, \color{blue}{-2}\right)} \]
      6. Applied rewrites76.7%

        \[\leadsto \frac{-1}{\color{blue}{\mathsf{fma}\left(-0.16666666666666666, x \cdot x, -2\right)}} \]
      7. Add Preprocessing

      Alternative 8: 51.1% accurate, 120.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 50.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. Applied rewrites52.3%

          \[\leadsto \color{blue}{0.5} \]
        2. Add Preprocessing

        Reproduce

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