cos2 (problem 3.4.1)

Percentage Accurate: 51.3% → 99.7%
Time: 9.7s
Alternatives: 10
Speedup: 17.8×

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 10 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.7% accurate, 0.5× speedup?

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{sin.f64}\left(x\right), \mathsf{*.f64}\left(x, x\right)\right), \left(\frac{\sin x}{1 + \cos x}\right)\right) \]
    10. hang-0p-tanN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{sin.f64}\left(x\right), \mathsf{*.f64}\left(x, x\right)\right), \tan \left(\frac{x}{2}\right)\right) \]
    11. tan-lowering-tan.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{sin.f64}\left(x\right), \mathsf{*.f64}\left(x, x\right)\right), \mathsf{tan.f64}\left(\left(\frac{x}{2}\right)\right)\right) \]
    12. /-lowering-/.f6476.2%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{sin.f64}\left(x\right), \mathsf{*.f64}\left(x, x\right)\right), \mathsf{tan.f64}\left(\mathsf{/.f64}\left(x, 2\right)\right)\right) \]
  4. Applied egg-rr76.2%

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

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

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{/.f64}\left(\sin x, x\right), x\right), \mathsf{tan.f64}\left(\mathsf{/.f64}\left(\color{blue}{x}, 2\right)\right)\right) \]
    4. sin-lowering-sin.f6499.7%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{sin.f64}\left(x\right), x\right), x\right), \mathsf{tan.f64}\left(\mathsf{/.f64}\left(x, 2\right)\right)\right) \]
  6. Applied egg-rr99.7%

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

Alternative 2: 74.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 0.032:\\ \;\;\;\;0.5 + \left(x \cdot x\right) \cdot \left(-0.041666666666666664 + \left(x \cdot x\right) \cdot 0.001388888888888889\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1 - \cos x}{x}}{x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 0.032)
   (+
    0.5
    (* (* x x) (+ -0.041666666666666664 (* (* x x) 0.001388888888888889))))
   (/ (/ (- 1.0 (cos x)) x) x)))
double code(double x) {
	double tmp;
	if (x <= 0.032) {
		tmp = 0.5 + ((x * x) * (-0.041666666666666664 + ((x * x) * 0.001388888888888889)));
	} 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.032d0) then
        tmp = 0.5d0 + ((x * x) * ((-0.041666666666666664d0) + ((x * x) * 0.001388888888888889d0)))
    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.032) {
		tmp = 0.5 + ((x * x) * (-0.041666666666666664 + ((x * x) * 0.001388888888888889)));
	} else {
		tmp = ((1.0 - Math.cos(x)) / x) / x;
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= 0.032:
		tmp = 0.5 + ((x * x) * (-0.041666666666666664 + ((x * x) * 0.001388888888888889)))
	else:
		tmp = ((1.0 - math.cos(x)) / x) / x
	return tmp
function code(x)
	tmp = 0.0
	if (x <= 0.032)
		tmp = Float64(0.5 + Float64(Float64(x * x) * Float64(-0.041666666666666664 + Float64(Float64(x * x) * 0.001388888888888889))));
	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.032)
		tmp = 0.5 + ((x * x) * (-0.041666666666666664 + ((x * x) * 0.001388888888888889)));
	else
		tmp = ((1.0 - cos(x)) / x) / x;
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, 0.032], N[(0.5 + N[(N[(x * x), $MachinePrecision] * N[(-0.041666666666666664 + N[(N[(x * x), $MachinePrecision] * 0.001388888888888889), $MachinePrecision]), $MachinePrecision]), $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.032:\\
\;\;\;\;0.5 + \left(x \cdot x\right) \cdot \left(-0.041666666666666664 + \left(x \cdot x\right) \cdot 0.001388888888888889\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.032000000000000001

    1. Initial program 34.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(\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-*.f6468.2%

        \[\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. Simplified68.2%

      \[\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.032000000000000001 < x

    1. Initial program 98.3%

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

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

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

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

        \[\leadsto \mathsf{\_.f64}\left(\mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, x\right)\right), \left(\frac{\cos x}{x \cdot x}\right)\right) \]
      5. associate-/r*N/A

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

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

        \[\leadsto \mathsf{\_.f64}\left(\mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, x\right)\right), \mathsf{/.f64}\left(\mathsf{/.f64}\left(\cos x, x\right), x\right)\right) \]
      8. cos-lowering-cos.f6498.1%

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

      \[\leadsto \color{blue}{\frac{1}{x \cdot x} - \frac{\frac{\cos x}{x}}{x}} \]
    5. Step-by-step derivation
      1. associate-/r*N/A

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

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

        \[\leadsto \frac{1 \cdot \frac{1}{x} - \frac{\cos x}{x}}{x} \]
      4. fmm-defN/A

        \[\leadsto \frac{\mathsf{fma}\left(1, \frac{1}{x}, \mathsf{neg}\left(\frac{\cos x}{x}\right)\right)}{x} \]
      5. clear-numN/A

        \[\leadsto \frac{\mathsf{fma}\left(1, \frac{1}{x}, \mathsf{neg}\left(\frac{1}{\frac{x}{\cos x}}\right)\right)}{x} \]
      6. associate-/r/N/A

        \[\leadsto \frac{\mathsf{fma}\left(1, \frac{1}{x}, \mathsf{neg}\left(\frac{1}{x} \cdot \cos x\right)\right)}{x} \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\mathsf{fma}\left(1, \frac{1}{x}, \mathsf{neg}\left(\frac{1}{x} \cdot \cos x\right)\right)\right), \color{blue}{x}\right) \]
      8. associate-/r/N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\mathsf{fma}\left(1, \frac{1}{x}, \mathsf{neg}\left(\frac{1}{\frac{x}{\cos x}}\right)\right)\right), x\right) \]
      9. clear-numN/A

        \[\leadsto \mathsf{/.f64}\left(\left(\mathsf{fma}\left(1, \frac{1}{x}, \mathsf{neg}\left(\frac{\cos x}{x}\right)\right)\right), x\right) \]
      10. fmm-defN/A

        \[\leadsto \mathsf{/.f64}\left(\left(1 \cdot \frac{1}{x} - \frac{\cos x}{x}\right), x\right) \]
      11. div-invN/A

        \[\leadsto \mathsf{/.f64}\left(\left(\frac{1}{x} - \frac{\cos x}{x}\right), x\right) \]
      12. sub-divN/A

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

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

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{\_.f64}\left(1, \mathsf{cos.f64}\left(x\right)\right), x\right), x\right) \]
    6. Applied egg-rr99.1%

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

Alternative 3: 74.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 0.032:\\ \;\;\;\;0.5 + \left(x \cdot x\right) \cdot \left(-0.041666666666666664 + \left(x \cdot x\right) \cdot 0.001388888888888889\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1 - \cos x}{x \cdot x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 0.032)
   (+
    0.5
    (* (* x x) (+ -0.041666666666666664 (* (* x x) 0.001388888888888889))))
   (/ (- 1.0 (cos x)) (* x x))))
double code(double x) {
	double tmp;
	if (x <= 0.032) {
		tmp = 0.5 + ((x * x) * (-0.041666666666666664 + ((x * x) * 0.001388888888888889)));
	} 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.032d0) then
        tmp = 0.5d0 + ((x * x) * ((-0.041666666666666664d0) + ((x * x) * 0.001388888888888889d0)))
    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.032) {
		tmp = 0.5 + ((x * x) * (-0.041666666666666664 + ((x * x) * 0.001388888888888889)));
	} else {
		tmp = (1.0 - Math.cos(x)) / (x * x);
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= 0.032:
		tmp = 0.5 + ((x * x) * (-0.041666666666666664 + ((x * x) * 0.001388888888888889)))
	else:
		tmp = (1.0 - math.cos(x)) / (x * x)
	return tmp
function code(x)
	tmp = 0.0
	if (x <= 0.032)
		tmp = Float64(0.5 + Float64(Float64(x * x) * Float64(-0.041666666666666664 + Float64(Float64(x * x) * 0.001388888888888889))));
	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.032)
		tmp = 0.5 + ((x * x) * (-0.041666666666666664 + ((x * x) * 0.001388888888888889)));
	else
		tmp = (1.0 - cos(x)) / (x * x);
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, 0.032], N[(0.5 + N[(N[(x * x), $MachinePrecision] * N[(-0.041666666666666664 + N[(N[(x * x), $MachinePrecision] * 0.001388888888888889), $MachinePrecision]), $MachinePrecision]), $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.032:\\
\;\;\;\;0.5 + \left(x \cdot x\right) \cdot \left(-0.041666666666666664 + \left(x \cdot x\right) \cdot 0.001388888888888889\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.032000000000000001

    1. Initial program 34.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(\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-*.f6468.2%

        \[\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. Simplified68.2%

      \[\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.032000000000000001 < x

    1. Initial program 98.3%

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

Alternative 4: 64.9% accurate, 4.5× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\frac{\frac{2}{x}}{x}\\


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

    1. Initial program 34.6%

      \[\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. +-lowering-+.f64N/A

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

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

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

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

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

        \[\leadsto \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \left({x}^{2} \cdot \left(\frac{1}{720} + \frac{-1}{40320} \cdot {x}^{2}\right) + \frac{-1}{24}\right)\right)\right) \]
      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}{{x}^{2} \cdot \left(\frac{1}{720} + \frac{-1}{40320} \cdot {x}^{2}\right)}\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({x}^{2} \cdot \left(\frac{1}{720} + \frac{-1}{40320} \cdot {x}^{2}\right)\right)}\right)\right)\right) \]
      9. unpow2N/A

        \[\leadsto \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{-1}{24}, \left(\left(x \cdot x\right) \cdot \left(\color{blue}{\frac{1}{720}} + \frac{-1}{40320} \cdot {x}^{2}\right)\right)\right)\right)\right) \]
      10. associate-*l*N/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 \cdot \color{blue}{\left(x \cdot \left(\frac{1}{720} + \frac{-1}{40320} \cdot {x}^{2}\right)\right)}\right)\right)\right)\right) \]
      11. *-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 \cdot \left(\left(\frac{1}{720} + \frac{-1}{40320} \cdot {x}^{2}\right) \cdot \color{blue}{x}\right)\right)\right)\right)\right) \]
      12. *-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(x, \color{blue}{\left(\left(\frac{1}{720} + \frac{-1}{40320} \cdot {x}^{2}\right) \cdot x\right)}\right)\right)\right)\right) \]
      13. *-commutativeN/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(x, \left(x \cdot \color{blue}{\left(\frac{1}{720} + \frac{-1}{40320} \cdot {x}^{2}\right)}\right)\right)\right)\right)\right) \]
      14. *-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(x, \mathsf{*.f64}\left(x, \color{blue}{\left(\frac{1}{720} + \frac{-1}{40320} \cdot {x}^{2}\right)}\right)\right)\right)\right)\right) \]
      15. +-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(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{720}, \color{blue}{\left(\frac{-1}{40320} \cdot {x}^{2}\right)}\right)\right)\right)\right)\right)\right) \]
      16. *-commutativeN/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(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{720}, \left({x}^{2} \cdot \color{blue}{\frac{-1}{40320}}\right)\right)\right)\right)\right)\right)\right) \]
      17. *-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(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{720}, \mathsf{*.f64}\left(\left({x}^{2}\right), \color{blue}{\frac{-1}{40320}}\right)\right)\right)\right)\right)\right)\right) \]
      18. 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(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{720}, \mathsf{*.f64}\left(\left(x \cdot x\right), \frac{-1}{40320}\right)\right)\right)\right)\right)\right)\right) \]
      19. *-lowering-*.f6467.9%

        \[\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(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{720}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{-1}{40320}\right)\right)\right)\right)\right)\right)\right) \]
    5. Simplified67.9%

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

    if 4.20000000000000018 < x

    1. Initial program 98.3%

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

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

      \[\leadsto \mathsf{/.f64}\left(\color{blue}{\left(\frac{2}{x}\right)}, x\right) \]
    5. Step-by-step derivation
      1. /-lowering-/.f6460.0%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(2, x\right), x\right) \]
    6. Simplified60.0%

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

Alternative 5: 65.1% accurate, 5.9× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\frac{\frac{2}{x}}{x}\\


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

    1. Initial program 34.6%

      \[\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-*.f6468.1%

        \[\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. Simplified68.1%

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

    if 2.7000000000000002 < x

    1. Initial program 98.3%

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

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

      \[\leadsto \mathsf{/.f64}\left(\color{blue}{\left(\frac{2}{x}\right)}, x\right) \]
    5. Step-by-step derivation
      1. /-lowering-/.f6460.0%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(2, x\right), x\right) \]
    6. Simplified60.0%

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

Alternative 6: 64.8% accurate, 8.9× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\frac{\frac{2}{x}}{x}\\


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

    1. Initial program 34.6%

      \[\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-*.f6467.7%

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

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

    if 2.39999999999999991 < x

    1. Initial program 98.3%

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

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

      \[\leadsto \mathsf{/.f64}\left(\color{blue}{\left(\frac{2}{x}\right)}, x\right) \]
    5. Step-by-step derivation
      1. /-lowering-/.f6460.0%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(2, x\right), x\right) \]
    6. Simplified60.0%

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

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

Alternative 7: 65.2% accurate, 10.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 2:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{2}{x}}{x}\\ \end{array} \end{array} \]
(FPCore (x) :precision binary64 (if (<= x 2.0) 0.5 (/ (/ 2.0 x) x)))
double code(double x) {
	double tmp;
	if (x <= 2.0) {
		tmp = 0.5;
	} else {
		tmp = (2.0 / x) / x;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 2.0d0) then
        tmp = 0.5d0
    else
        tmp = (2.0d0 / x) / x
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= 2.0) {
		tmp = 0.5;
	} else {
		tmp = (2.0 / x) / x;
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= 2.0:
		tmp = 0.5
	else:
		tmp = (2.0 / x) / x
	return tmp
function code(x)
	tmp = 0.0
	if (x <= 2.0)
		tmp = 0.5;
	else
		tmp = Float64(Float64(2.0 / x) / x);
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= 2.0)
		tmp = 0.5;
	else
		tmp = (2.0 / x) / x;
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, 2.0], 0.5, N[(N[(2.0 / x), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}

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

\mathbf{else}:\\
\;\;\;\;\frac{\frac{2}{x}}{x}\\


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

    1. Initial program 34.6%

      \[\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. Simplified68.1%

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

      if 2 < x

      1. Initial program 98.3%

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

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

        \[\leadsto \mathsf{/.f64}\left(\color{blue}{\left(\frac{2}{x}\right)}, x\right) \]
      5. Step-by-step derivation
        1. /-lowering-/.f6460.0%

          \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(2, x\right), x\right) \]
      6. Simplified60.0%

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

    Alternative 8: 65.2% accurate, 10.7× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 2:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{x \cdot x}\\ \end{array} \end{array} \]
    (FPCore (x) :precision binary64 (if (<= x 2.0) 0.5 (/ 2.0 (* x x))))
    double code(double x) {
    	double tmp;
    	if (x <= 2.0) {
    		tmp = 0.5;
    	} else {
    		tmp = 2.0 / (x * x);
    	}
    	return tmp;
    }
    
    real(8) function code(x)
        real(8), intent (in) :: x
        real(8) :: tmp
        if (x <= 2.0d0) then
            tmp = 0.5d0
        else
            tmp = 2.0d0 / (x * x)
        end if
        code = tmp
    end function
    
    public static double code(double x) {
    	double tmp;
    	if (x <= 2.0) {
    		tmp = 0.5;
    	} else {
    		tmp = 2.0 / (x * x);
    	}
    	return tmp;
    }
    
    def code(x):
    	tmp = 0
    	if x <= 2.0:
    		tmp = 0.5
    	else:
    		tmp = 2.0 / (x * x)
    	return tmp
    
    function code(x)
    	tmp = 0.0
    	if (x <= 2.0)
    		tmp = 0.5;
    	else
    		tmp = Float64(2.0 / Float64(x * x));
    	end
    	return tmp
    end
    
    function tmp_2 = code(x)
    	tmp = 0.0;
    	if (x <= 2.0)
    		tmp = 0.5;
    	else
    		tmp = 2.0 / (x * x);
    	end
    	tmp_2 = tmp;
    end
    
    code[x_] := If[LessEqual[x, 2.0], 0.5, N[(2.0 / N[(x * x), $MachinePrecision]), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;x \leq 2:\\
    \;\;\;\;0.5\\
    
    \mathbf{else}:\\
    \;\;\;\;\frac{2}{x \cdot x}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if x < 2

      1. Initial program 34.6%

        \[\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. Simplified68.1%

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

        if 2 < x

        1. Initial program 98.3%

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

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

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

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

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

            \[\leadsto \mathsf{/.f64}\left(2, \mathsf{*.f64}\left(x, \color{blue}{x}\right)\right) \]
        6. Simplified59.9%

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

      Alternative 9: 63.6% accurate, 17.8× speedup?

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

        1. Initial program 39.2%

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

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

          if 8.0000000000000004e76 < x

          1. Initial program 98.1%

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

            \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(1, \color{blue}{1}\right), \mathsf{*.f64}\left(x, x\right)\right) \]
          4. Step-by-step derivation
            1. Simplified68.0%

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

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

                \[\leadsto 0 \]
            3. Applied egg-rr68.0%

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

          Alternative 10: 27.6% accurate, 107.0× speedup?

          \[\begin{array}{l} \\ 0 \end{array} \]
          (FPCore (x) :precision binary64 0.0)
          double code(double x) {
          	return 0.0;
          }
          
          real(8) function code(x)
              real(8), intent (in) :: x
              code = 0.0d0
          end function
          
          public static double code(double x) {
          	return 0.0;
          }
          
          def code(x):
          	return 0.0
          
          function code(x)
          	return 0.0
          end
          
          function tmp = code(x)
          	tmp = 0.0;
          end
          
          code[x_] := 0.0
          
          \begin{array}{l}
          
          \\
          0
          \end{array}
          
          Derivation
          1. Initial program 50.2%

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

            \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(1, \color{blue}{1}\right), \mathsf{*.f64}\left(x, x\right)\right) \]
          4. Step-by-step derivation
            1. Simplified24.7%

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

                \[\leadsto \frac{0}{\color{blue}{x} \cdot x} \]
              2. div025.4%

                \[\leadsto 0 \]
            3. Applied egg-rr25.4%

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

            Reproduce

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