cos2 (problem 3.4.1)

Percentage Accurate: 50.6% → 99.6%
Time: 19.4s
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.6% 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.6% accurate, 1.0× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;x\_m \leq 0.028:\\ \;\;\;\;0.5 + \left(x\_m \cdot x\_m\right) \cdot \left(-0.041666666666666664 + \left(x\_m \cdot x\_m\right) \cdot 0.001388888888888889\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1 - \cos x\_m}{x\_m}}{x\_m}\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m)
 :precision binary64
 (if (<= x_m 0.028)
   (+
    0.5
    (*
     (* x_m x_m)
     (+ -0.041666666666666664 (* (* x_m x_m) 0.001388888888888889))))
   (/ (/ (- 1.0 (cos x_m)) x_m) x_m)))
x_m = fabs(x);
double code(double x_m) {
	double tmp;
	if (x_m <= 0.028) {
		tmp = 0.5 + ((x_m * x_m) * (-0.041666666666666664 + ((x_m * x_m) * 0.001388888888888889)));
	} else {
		tmp = ((1.0 - cos(x_m)) / x_m) / x_m;
	}
	return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
    real(8), intent (in) :: x_m
    real(8) :: tmp
    if (x_m <= 0.028d0) then
        tmp = 0.5d0 + ((x_m * x_m) * ((-0.041666666666666664d0) + ((x_m * x_m) * 0.001388888888888889d0)))
    else
        tmp = ((1.0d0 - cos(x_m)) / x_m) / x_m
    end if
    code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
	double tmp;
	if (x_m <= 0.028) {
		tmp = 0.5 + ((x_m * x_m) * (-0.041666666666666664 + ((x_m * x_m) * 0.001388888888888889)));
	} else {
		tmp = ((1.0 - Math.cos(x_m)) / x_m) / x_m;
	}
	return tmp;
}
x_m = math.fabs(x)
def code(x_m):
	tmp = 0
	if x_m <= 0.028:
		tmp = 0.5 + ((x_m * x_m) * (-0.041666666666666664 + ((x_m * x_m) * 0.001388888888888889)))
	else:
		tmp = ((1.0 - math.cos(x_m)) / x_m) / x_m
	return tmp
x_m = abs(x)
function code(x_m)
	tmp = 0.0
	if (x_m <= 0.028)
		tmp = Float64(0.5 + Float64(Float64(x_m * x_m) * Float64(-0.041666666666666664 + Float64(Float64(x_m * x_m) * 0.001388888888888889))));
	else
		tmp = Float64(Float64(Float64(1.0 - cos(x_m)) / x_m) / x_m);
	end
	return tmp
end
x_m = abs(x);
function tmp_2 = code(x_m)
	tmp = 0.0;
	if (x_m <= 0.028)
		tmp = 0.5 + ((x_m * x_m) * (-0.041666666666666664 + ((x_m * x_m) * 0.001388888888888889)));
	else
		tmp = ((1.0 - cos(x_m)) / x_m) / x_m;
	end
	tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := If[LessEqual[x$95$m, 0.028], N[(0.5 + N[(N[(x$95$m * x$95$m), $MachinePrecision] * N[(-0.041666666666666664 + N[(N[(x$95$m * x$95$m), $MachinePrecision] * 0.001388888888888889), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(1.0 - N[Cos[x$95$m], $MachinePrecision]), $MachinePrecision] / x$95$m), $MachinePrecision] / x$95$m), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 0.028:\\
\;\;\;\;0.5 + \left(x\_m \cdot x\_m\right) \cdot \left(-0.041666666666666664 + \left(x\_m \cdot x\_m\right) \cdot 0.001388888888888889\right)\\

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


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

    1. Initial program 33.1%

      \[\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(\frac{1}{720} \cdot {x}^{2} - \frac{1}{24}\right)} \]
    4. Step-by-step derivation
      1. +-lowering-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.0280000000000000006 < x

    1. Initial program 98.7%

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

      \[\leadsto \color{blue}{\frac{1 - \cos x}{{x}^{2}}} \]
    4. Step-by-step derivation
      1. unpow2N/A

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

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

        \[\leadsto \mathsf{/.f64}\left(\left(\frac{1 - \cos x}{x}\right), \color{blue}{x}\right) \]
      4. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\left(1 - \cos x\right), x\right), x\right) \]
      5. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{\_.f64}\left(1, \cos x\right), x\right), x\right) \]
      6. cos-lowering-cos.f6499.2%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{\_.f64}\left(1, \mathsf{cos.f64}\left(x\right)\right), x\right), x\right) \]
    5. Simplified99.2%

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

Alternative 2: 99.2% accurate, 1.0× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;x\_m \leq 0.028:\\ \;\;\;\;0.5 + \left(x\_m \cdot x\_m\right) \cdot \left(-0.041666666666666664 + \left(x\_m \cdot x\_m\right) \cdot 0.001388888888888889\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1 - \cos x\_m}{x\_m \cdot x\_m}\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m)
 :precision binary64
 (if (<= x_m 0.028)
   (+
    0.5
    (*
     (* x_m x_m)
     (+ -0.041666666666666664 (* (* x_m x_m) 0.001388888888888889))))
   (/ (- 1.0 (cos x_m)) (* x_m x_m))))
x_m = fabs(x);
double code(double x_m) {
	double tmp;
	if (x_m <= 0.028) {
		tmp = 0.5 + ((x_m * x_m) * (-0.041666666666666664 + ((x_m * x_m) * 0.001388888888888889)));
	} else {
		tmp = (1.0 - cos(x_m)) / (x_m * x_m);
	}
	return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
    real(8), intent (in) :: x_m
    real(8) :: tmp
    if (x_m <= 0.028d0) then
        tmp = 0.5d0 + ((x_m * x_m) * ((-0.041666666666666664d0) + ((x_m * x_m) * 0.001388888888888889d0)))
    else
        tmp = (1.0d0 - cos(x_m)) / (x_m * x_m)
    end if
    code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
	double tmp;
	if (x_m <= 0.028) {
		tmp = 0.5 + ((x_m * x_m) * (-0.041666666666666664 + ((x_m * x_m) * 0.001388888888888889)));
	} else {
		tmp = (1.0 - Math.cos(x_m)) / (x_m * x_m);
	}
	return tmp;
}
x_m = math.fabs(x)
def code(x_m):
	tmp = 0
	if x_m <= 0.028:
		tmp = 0.5 + ((x_m * x_m) * (-0.041666666666666664 + ((x_m * x_m) * 0.001388888888888889)))
	else:
		tmp = (1.0 - math.cos(x_m)) / (x_m * x_m)
	return tmp
x_m = abs(x)
function code(x_m)
	tmp = 0.0
	if (x_m <= 0.028)
		tmp = Float64(0.5 + Float64(Float64(x_m * x_m) * Float64(-0.041666666666666664 + Float64(Float64(x_m * x_m) * 0.001388888888888889))));
	else
		tmp = Float64(Float64(1.0 - cos(x_m)) / Float64(x_m * x_m));
	end
	return tmp
end
x_m = abs(x);
function tmp_2 = code(x_m)
	tmp = 0.0;
	if (x_m <= 0.028)
		tmp = 0.5 + ((x_m * x_m) * (-0.041666666666666664 + ((x_m * x_m) * 0.001388888888888889)));
	else
		tmp = (1.0 - cos(x_m)) / (x_m * x_m);
	end
	tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := If[LessEqual[x$95$m, 0.028], N[(0.5 + N[(N[(x$95$m * x$95$m), $MachinePrecision] * N[(-0.041666666666666664 + N[(N[(x$95$m * x$95$m), $MachinePrecision] * 0.001388888888888889), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - N[Cos[x$95$m], $MachinePrecision]), $MachinePrecision] / N[(x$95$m * x$95$m), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 0.028:\\
\;\;\;\;0.5 + \left(x\_m \cdot x\_m\right) \cdot \left(-0.041666666666666664 + \left(x\_m \cdot x\_m\right) \cdot 0.001388888888888889\right)\\

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


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

    1. Initial program 33.1%

      \[\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(\frac{1}{720} \cdot {x}^{2} - \frac{1}{24}\right)} \]
    4. Step-by-step derivation
      1. +-lowering-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.0280000000000000006 < 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 3: 78.8% accurate, 8.9× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;x\_m \leq 3.2:\\ \;\;\;\;0.5 + \left(x\_m \cdot x\_m\right) \cdot -0.041666666666666664\\ \mathbf{else}:\\ \;\;\;\;\frac{6}{x\_m \cdot x\_m}\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m)
 :precision binary64
 (if (<= x_m 3.2)
   (+ 0.5 (* (* x_m x_m) -0.041666666666666664))
   (/ 6.0 (* x_m x_m))))
x_m = fabs(x);
double code(double x_m) {
	double tmp;
	if (x_m <= 3.2) {
		tmp = 0.5 + ((x_m * x_m) * -0.041666666666666664);
	} else {
		tmp = 6.0 / (x_m * x_m);
	}
	return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
    real(8), intent (in) :: x_m
    real(8) :: tmp
    if (x_m <= 3.2d0) then
        tmp = 0.5d0 + ((x_m * x_m) * (-0.041666666666666664d0))
    else
        tmp = 6.0d0 / (x_m * x_m)
    end if
    code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
	double tmp;
	if (x_m <= 3.2) {
		tmp = 0.5 + ((x_m * x_m) * -0.041666666666666664);
	} else {
		tmp = 6.0 / (x_m * x_m);
	}
	return tmp;
}
x_m = math.fabs(x)
def code(x_m):
	tmp = 0
	if x_m <= 3.2:
		tmp = 0.5 + ((x_m * x_m) * -0.041666666666666664)
	else:
		tmp = 6.0 / (x_m * x_m)
	return tmp
x_m = abs(x)
function code(x_m)
	tmp = 0.0
	if (x_m <= 3.2)
		tmp = Float64(0.5 + Float64(Float64(x_m * x_m) * -0.041666666666666664));
	else
		tmp = Float64(6.0 / Float64(x_m * x_m));
	end
	return tmp
end
x_m = abs(x);
function tmp_2 = code(x_m)
	tmp = 0.0;
	if (x_m <= 3.2)
		tmp = 0.5 + ((x_m * x_m) * -0.041666666666666664);
	else
		tmp = 6.0 / (x_m * x_m);
	end
	tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := If[LessEqual[x$95$m, 3.2], N[(0.5 + N[(N[(x$95$m * x$95$m), $MachinePrecision] * -0.041666666666666664), $MachinePrecision]), $MachinePrecision], N[(6.0 / N[(x$95$m * x$95$m), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 3.2:\\
\;\;\;\;0.5 + \left(x\_m \cdot x\_m\right) \cdot -0.041666666666666664\\

\mathbf{else}:\\
\;\;\;\;\frac{6}{x\_m \cdot x\_m}\\


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

    1. Initial program 33.1%

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

      \[\leadsto \color{blue}{\frac{1}{2} + \frac{-1}{24} \cdot {x}^{2}} \]
    4. Step-by-step derivation
      1. +-lowering-+.f64N/A

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

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

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

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

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

    if 3.2000000000000002 < x

    1. Initial program 98.7%

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

      \[\leadsto \color{blue}{\frac{1 - \cos x}{{x}^{2}}} \]
    4. Step-by-step derivation
      1. unpow2N/A

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

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

        \[\leadsto \mathsf{/.f64}\left(\left(\frac{1 - \cos x}{x}\right), \color{blue}{x}\right) \]
      4. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\left(1 - \cos x\right), x\right), x\right) \]
      5. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{\_.f64}\left(1, \cos x\right), x\right), x\right) \]
      6. cos-lowering-cos.f6499.2%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{\_.f64}\left(1, \mathsf{cos.f64}\left(x\right)\right), x\right), x\right) \]
    5. Simplified99.2%

      \[\leadsto \color{blue}{\frac{\frac{1 - \cos x}{x}}{x}} \]
    6. Step-by-step derivation
      1. associate-/l/N/A

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

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

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

        \[\leadsto \frac{\frac{1}{x} \cdot \left(x \cdot x\right) - x \cdot \cos x}{\color{blue}{x \cdot \left(x \cdot x\right)}} \]
      5. cube-unmultN/A

        \[\leadsto \frac{\frac{1}{x} \cdot \left(x \cdot x\right) - x \cdot \cos x}{{x}^{\color{blue}{3}}} \]
      6. clear-numN/A

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

        \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{{x}^{3}}{\frac{1}{x} \cdot \left(x \cdot x\right) - x \cdot \cos x}\right)}\right) \]
      8. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\left({x}^{3}\right), \color{blue}{\left(\frac{1}{x} \cdot \left(x \cdot x\right) - x \cdot \cos x\right)}\right)\right) \]
      9. cube-unmultN/A

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

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

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, x\right)\right), \left(\frac{1}{x} \cdot \color{blue}{\left(x \cdot x\right)} - x \cdot \cos x\right)\right)\right) \]
      12. inv-powN/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, x\right)\right), \left({x}^{-1} \cdot \left(x \cdot x\right) - x \cdot \cos x\right)\right)\right) \]
      13. pow2N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, x\right)\right), \left({x}^{-1} \cdot {x}^{2} - x \cdot \cos x\right)\right)\right) \]
      14. pow-prod-upN/A

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

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, x\right)\right), \left({x}^{1} - x \cdot \cos x\right)\right)\right) \]
      16. unpow1N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, x\right)\right), \left(x - \color{blue}{x} \cdot \cos x\right)\right)\right) \]
      17. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, x\right)\right), \mathsf{\_.f64}\left(x, \color{blue}{\left(x \cdot \cos x\right)}\right)\right)\right) \]
      18. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, x\right)\right), \mathsf{\_.f64}\left(x, \mathsf{*.f64}\left(x, \color{blue}{\cos x}\right)\right)\right)\right) \]
      19. cos-lowering-cos.f6486.5%

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, x\right)\right), \mathsf{\_.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{cos.f64}\left(x\right)\right)\right)\right)\right) \]
    7. Applied egg-rr86.5%

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

      \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(2 + \frac{1}{6} \cdot {x}^{2}\right)}\right) \]
    9. Step-by-step derivation
      1. +-lowering-+.f64N/A

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

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

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

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{+.f64}\left(2, \mathsf{*.f64}\left(\left(x \cdot x\right), \frac{1}{6}\right)\right)\right) \]
      5. *-lowering-*.f6456.1%

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{+.f64}\left(2, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{1}{6}\right)\right)\right) \]
    10. Simplified56.1%

      \[\leadsto \frac{1}{\color{blue}{2 + \left(x \cdot x\right) \cdot 0.16666666666666666}} \]
    11. Taylor expanded in x around inf

      \[\leadsto \color{blue}{\frac{6}{{x}^{2}}} \]
    12. Step-by-step derivation
      1. /-lowering-/.f64N/A

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

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

        \[\leadsto \mathsf{/.f64}\left(6, \mathsf{*.f64}\left(x, \color{blue}{x}\right)\right) \]
    13. Simplified56.1%

      \[\leadsto \color{blue}{\frac{6}{x \cdot x}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification65.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 3.2:\\ \;\;\;\;0.5 + \left(x \cdot x\right) \cdot -0.041666666666666664\\ \mathbf{else}:\\ \;\;\;\;\frac{6}{x \cdot x}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 78.5% accurate, 10.7× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;x\_m \leq 3.5:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{6}{x\_m \cdot x\_m}\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m) :precision binary64 (if (<= x_m 3.5) 0.5 (/ 6.0 (* x_m x_m))))
x_m = fabs(x);
double code(double x_m) {
	double tmp;
	if (x_m <= 3.5) {
		tmp = 0.5;
	} else {
		tmp = 6.0 / (x_m * x_m);
	}
	return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
    real(8), intent (in) :: x_m
    real(8) :: tmp
    if (x_m <= 3.5d0) then
        tmp = 0.5d0
    else
        tmp = 6.0d0 / (x_m * x_m)
    end if
    code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
	double tmp;
	if (x_m <= 3.5) {
		tmp = 0.5;
	} else {
		tmp = 6.0 / (x_m * x_m);
	}
	return tmp;
}
x_m = math.fabs(x)
def code(x_m):
	tmp = 0
	if x_m <= 3.5:
		tmp = 0.5
	else:
		tmp = 6.0 / (x_m * x_m)
	return tmp
x_m = abs(x)
function code(x_m)
	tmp = 0.0
	if (x_m <= 3.5)
		tmp = 0.5;
	else
		tmp = Float64(6.0 / Float64(x_m * x_m));
	end
	return tmp
end
x_m = abs(x);
function tmp_2 = code(x_m)
	tmp = 0.0;
	if (x_m <= 3.5)
		tmp = 0.5;
	else
		tmp = 6.0 / (x_m * x_m);
	end
	tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := If[LessEqual[x$95$m, 3.5], 0.5, N[(6.0 / N[(x$95$m * x$95$m), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 3.5:\\
\;\;\;\;0.5\\

\mathbf{else}:\\
\;\;\;\;\frac{6}{x\_m \cdot x\_m}\\


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

    1. Initial program 33.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. Simplified69.4%

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

      if 3.5 < x

      1. Initial program 98.7%

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

        \[\leadsto \color{blue}{\frac{1 - \cos x}{{x}^{2}}} \]
      4. Step-by-step derivation
        1. unpow2N/A

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

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

          \[\leadsto \mathsf{/.f64}\left(\left(\frac{1 - \cos x}{x}\right), \color{blue}{x}\right) \]
        4. /-lowering-/.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\left(1 - \cos x\right), x\right), x\right) \]
        5. --lowering--.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{\_.f64}\left(1, \cos x\right), x\right), x\right) \]
        6. cos-lowering-cos.f6499.2%

          \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{\_.f64}\left(1, \mathsf{cos.f64}\left(x\right)\right), x\right), x\right) \]
      5. Simplified99.2%

        \[\leadsto \color{blue}{\frac{\frac{1 - \cos x}{x}}{x}} \]
      6. Step-by-step derivation
        1. associate-/l/N/A

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

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

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

          \[\leadsto \frac{\frac{1}{x} \cdot \left(x \cdot x\right) - x \cdot \cos x}{\color{blue}{x \cdot \left(x \cdot x\right)}} \]
        5. cube-unmultN/A

          \[\leadsto \frac{\frac{1}{x} \cdot \left(x \cdot x\right) - x \cdot \cos x}{{x}^{\color{blue}{3}}} \]
        6. clear-numN/A

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

          \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{{x}^{3}}{\frac{1}{x} \cdot \left(x \cdot x\right) - x \cdot \cos x}\right)}\right) \]
        8. /-lowering-/.f64N/A

          \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\left({x}^{3}\right), \color{blue}{\left(\frac{1}{x} \cdot \left(x \cdot x\right) - x \cdot \cos x\right)}\right)\right) \]
        9. cube-unmultN/A

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

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

          \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, x\right)\right), \left(\frac{1}{x} \cdot \color{blue}{\left(x \cdot x\right)} - x \cdot \cos x\right)\right)\right) \]
        12. inv-powN/A

          \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, x\right)\right), \left({x}^{-1} \cdot \left(x \cdot x\right) - x \cdot \cos x\right)\right)\right) \]
        13. pow2N/A

          \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, x\right)\right), \left({x}^{-1} \cdot {x}^{2} - x \cdot \cos x\right)\right)\right) \]
        14. pow-prod-upN/A

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

          \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, x\right)\right), \left({x}^{1} - x \cdot \cos x\right)\right)\right) \]
        16. unpow1N/A

          \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, x\right)\right), \left(x - \color{blue}{x} \cdot \cos x\right)\right)\right) \]
        17. --lowering--.f64N/A

          \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, x\right)\right), \mathsf{\_.f64}\left(x, \color{blue}{\left(x \cdot \cos x\right)}\right)\right)\right) \]
        18. *-lowering-*.f64N/A

          \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, x\right)\right), \mathsf{\_.f64}\left(x, \mathsf{*.f64}\left(x, \color{blue}{\cos x}\right)\right)\right)\right) \]
        19. cos-lowering-cos.f6486.5%

          \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, x\right)\right), \mathsf{\_.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{cos.f64}\left(x\right)\right)\right)\right)\right) \]
      7. Applied egg-rr86.5%

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

        \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(2 + \frac{1}{6} \cdot {x}^{2}\right)}\right) \]
      9. Step-by-step derivation
        1. +-lowering-+.f64N/A

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

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

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

          \[\leadsto \mathsf{/.f64}\left(1, \mathsf{+.f64}\left(2, \mathsf{*.f64}\left(\left(x \cdot x\right), \frac{1}{6}\right)\right)\right) \]
        5. *-lowering-*.f6456.1%

          \[\leadsto \mathsf{/.f64}\left(1, \mathsf{+.f64}\left(2, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{1}{6}\right)\right)\right) \]
      10. Simplified56.1%

        \[\leadsto \frac{1}{\color{blue}{2 + \left(x \cdot x\right) \cdot 0.16666666666666666}} \]
      11. Taylor expanded in x around inf

        \[\leadsto \color{blue}{\frac{6}{{x}^{2}}} \]
      12. Step-by-step derivation
        1. /-lowering-/.f64N/A

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

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

          \[\leadsto \mathsf{/.f64}\left(6, \mathsf{*.f64}\left(x, \color{blue}{x}\right)\right) \]
      13. Simplified56.1%

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

    Alternative 5: 78.8% accurate, 11.9× speedup?

    \[\begin{array}{l} x_m = \left|x\right| \\ \frac{1}{2 + \left(x\_m \cdot x\_m\right) \cdot 0.16666666666666666} \end{array} \]
    x_m = (fabs.f64 x)
    (FPCore (x_m)
     :precision binary64
     (/ 1.0 (+ 2.0 (* (* x_m x_m) 0.16666666666666666))))
    x_m = fabs(x);
    double code(double x_m) {
    	return 1.0 / (2.0 + ((x_m * x_m) * 0.16666666666666666));
    }
    
    x_m = abs(x)
    real(8) function code(x_m)
        real(8), intent (in) :: x_m
        code = 1.0d0 / (2.0d0 + ((x_m * x_m) * 0.16666666666666666d0))
    end function
    
    x_m = Math.abs(x);
    public static double code(double x_m) {
    	return 1.0 / (2.0 + ((x_m * x_m) * 0.16666666666666666));
    }
    
    x_m = math.fabs(x)
    def code(x_m):
    	return 1.0 / (2.0 + ((x_m * x_m) * 0.16666666666666666))
    
    x_m = abs(x)
    function code(x_m)
    	return Float64(1.0 / Float64(2.0 + Float64(Float64(x_m * x_m) * 0.16666666666666666)))
    end
    
    x_m = abs(x);
    function tmp = code(x_m)
    	tmp = 1.0 / (2.0 + ((x_m * x_m) * 0.16666666666666666));
    end
    
    x_m = N[Abs[x], $MachinePrecision]
    code[x$95$m_] := N[(1.0 / N[(2.0 + N[(N[(x$95$m * x$95$m), $MachinePrecision] * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
    
    \begin{array}{l}
    x_m = \left|x\right|
    
    \\
    \frac{1}{2 + \left(x\_m \cdot x\_m\right) \cdot 0.16666666666666666}
    \end{array}
    
    Derivation
    1. Initial program 52.3%

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

      \[\leadsto \color{blue}{\frac{1 - \cos x}{{x}^{2}}} \]
    4. Step-by-step derivation
      1. unpow2N/A

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

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

        \[\leadsto \mathsf{/.f64}\left(\left(\frac{1 - \cos x}{x}\right), \color{blue}{x}\right) \]
      4. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\left(1 - \cos x\right), x\right), x\right) \]
      5. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{\_.f64}\left(1, \cos x\right), x\right), x\right) \]
      6. cos-lowering-cos.f6453.5%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{\_.f64}\left(1, \mathsf{cos.f64}\left(x\right)\right), x\right), x\right) \]
    5. Simplified53.5%

      \[\leadsto \color{blue}{\frac{\frac{1 - \cos x}{x}}{x}} \]
    6. Step-by-step derivation
      1. associate-/l/N/A

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

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

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

        \[\leadsto \frac{\frac{1}{x} \cdot \left(x \cdot x\right) - x \cdot \cos x}{\color{blue}{x \cdot \left(x \cdot x\right)}} \]
      5. cube-unmultN/A

        \[\leadsto \frac{\frac{1}{x} \cdot \left(x \cdot x\right) - x \cdot \cos x}{{x}^{\color{blue}{3}}} \]
      6. clear-numN/A

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

        \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{{x}^{3}}{\frac{1}{x} \cdot \left(x \cdot x\right) - x \cdot \cos x}\right)}\right) \]
      8. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\left({x}^{3}\right), \color{blue}{\left(\frac{1}{x} \cdot \left(x \cdot x\right) - x \cdot \cos x\right)}\right)\right) \]
      9. cube-unmultN/A

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

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

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, x\right)\right), \left(\frac{1}{x} \cdot \color{blue}{\left(x \cdot x\right)} - x \cdot \cos x\right)\right)\right) \]
      12. inv-powN/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, x\right)\right), \left({x}^{-1} \cdot \left(x \cdot x\right) - x \cdot \cos x\right)\right)\right) \]
      13. pow2N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, x\right)\right), \left({x}^{-1} \cdot {x}^{2} - x \cdot \cos x\right)\right)\right) \]
      14. pow-prod-upN/A

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

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, x\right)\right), \left({x}^{1} - x \cdot \cos x\right)\right)\right) \]
      16. unpow1N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, x\right)\right), \left(x - \color{blue}{x} \cdot \cos x\right)\right)\right) \]
      17. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, x\right)\right), \mathsf{\_.f64}\left(x, \color{blue}{\left(x \cdot \cos x\right)}\right)\right)\right) \]
      18. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, x\right)\right), \mathsf{\_.f64}\left(x, \mathsf{*.f64}\left(x, \color{blue}{\cos x}\right)\right)\right)\right) \]
      19. cos-lowering-cos.f6445.5%

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, x\right)\right), \mathsf{\_.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{cos.f64}\left(x\right)\right)\right)\right)\right) \]
    7. Applied egg-rr45.5%

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

      \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(2 + \frac{1}{6} \cdot {x}^{2}\right)}\right) \]
    9. Step-by-step derivation
      1. +-lowering-+.f64N/A

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

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

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

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{+.f64}\left(2, \mathsf{*.f64}\left(\left(x \cdot x\right), \frac{1}{6}\right)\right)\right) \]
      5. *-lowering-*.f6475.6%

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{+.f64}\left(2, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{1}{6}\right)\right)\right) \]
    10. Simplified75.6%

      \[\leadsto \frac{1}{\color{blue}{2 + \left(x \cdot x\right) \cdot 0.16666666666666666}} \]
    11. Add Preprocessing

    Alternative 6: 51.8% accurate, 107.0× speedup?

    \[\begin{array}{l} x_m = \left|x\right| \\ 0.5 \end{array} \]
    x_m = (fabs.f64 x)
    (FPCore (x_m) :precision binary64 0.5)
    x_m = fabs(x);
    double code(double x_m) {
    	return 0.5;
    }
    
    x_m = abs(x)
    real(8) function code(x_m)
        real(8), intent (in) :: x_m
        code = 0.5d0
    end function
    
    x_m = Math.abs(x);
    public static double code(double x_m) {
    	return 0.5;
    }
    
    x_m = math.fabs(x)
    def code(x_m):
    	return 0.5
    
    x_m = abs(x)
    function code(x_m)
    	return 0.5
    end
    
    x_m = abs(x);
    function tmp = code(x_m)
    	tmp = 0.5;
    end
    
    x_m = N[Abs[x], $MachinePrecision]
    code[x$95$m_] := 0.5
    
    \begin{array}{l}
    x_m = \left|x\right|
    
    \\
    0.5
    \end{array}
    
    Derivation
    1. Initial program 52.3%

      \[\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. Simplified50.3%

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

      Reproduce

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