?

Average Error: 32.3 → 0.1
Time: 1.7min
Precision: binary64
Cost: 13964

?

\[\frac{1 - \cos x}{x \cdot x} \]
\[\begin{array}{l} t_0 := 1 - \cos x\\ \mathbf{if}\;x \leq -0.002:\\ \;\;\;\;\frac{\frac{\begin{array}{l} \mathbf{if}\;2 \ne 0:\\ \;\;\;\;\sin x \cdot \tan \left(\frac{x}{2}\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array}}{x}}{x}\\ \mathbf{elif}\;x \leq 2 \cdot 10^{-7}:\\ \;\;\;\;0.5 + \left(x \cdot -0.041666666666666664\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\frac{\begin{array}{l} \mathbf{if}\;2 \ne 0:\\ \;\;\;\;\sin x \cdot \tan \left(x \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array}}{-x} \cdot \frac{-1}{x}\\ \end{array} \]
(FPCore (x) :precision binary64 (/ (- 1.0 (cos x)) (* x x)))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (- 1.0 (cos x))))
   (if (<= x -0.002)
     (/ (/ (if (!= 2.0 0.0) (* (sin x) (tan (/ x 2.0))) t_0) x) x)
     (if (<= x 2e-7)
       (+ 0.5 (* (* x -0.041666666666666664) x))
       (*
        (/ (if (!= 2.0 0.0) (* (sin x) (tan (* x 0.5))) t_0) (- x))
        (/ -1.0 x))))))
double code(double x) {
	return (1.0 - cos(x)) / (x * x);
}
double code(double x) {
	double t_0 = 1.0 - cos(x);
	double tmp_1;
	if (x <= -0.002) {
		double tmp_2;
		if (2.0 != 0.0) {
			tmp_2 = sin(x) * tan((x / 2.0));
		} else {
			tmp_2 = t_0;
		}
		tmp_1 = (tmp_2 / x) / x;
	} else if (x <= 2e-7) {
		tmp_1 = 0.5 + ((x * -0.041666666666666664) * x);
	} else {
		double tmp_3;
		if (2.0 != 0.0) {
			tmp_3 = sin(x) * tan((x * 0.5));
		} else {
			tmp_3 = t_0;
		}
		tmp_1 = (tmp_3 / -x) * (-1.0 / x);
	}
	return tmp_1;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (1.0d0 - cos(x)) / (x * x)
end function
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: tmp
    real(8) :: tmp_1
    real(8) :: tmp_2
    real(8) :: tmp_3
    t_0 = 1.0d0 - cos(x)
    if (x <= (-0.002d0)) then
        if (2.0d0 /= 0.0d0) then
            tmp_2 = sin(x) * tan((x / 2.0d0))
        else
            tmp_2 = t_0
        end if
        tmp_1 = (tmp_2 / x) / x
    else if (x <= 2d-7) then
        tmp_1 = 0.5d0 + ((x * (-0.041666666666666664d0)) * x)
    else
        if (2.0d0 /= 0.0d0) then
            tmp_3 = sin(x) * tan((x * 0.5d0))
        else
            tmp_3 = t_0
        end if
        tmp_1 = (tmp_3 / -x) * ((-1.0d0) / x)
    end if
    code = tmp_1
end function
public static double code(double x) {
	return (1.0 - Math.cos(x)) / (x * x);
}
public static double code(double x) {
	double t_0 = 1.0 - Math.cos(x);
	double tmp_1;
	if (x <= -0.002) {
		double tmp_2;
		if (2.0 != 0.0) {
			tmp_2 = Math.sin(x) * Math.tan((x / 2.0));
		} else {
			tmp_2 = t_0;
		}
		tmp_1 = (tmp_2 / x) / x;
	} else if (x <= 2e-7) {
		tmp_1 = 0.5 + ((x * -0.041666666666666664) * x);
	} else {
		double tmp_3;
		if (2.0 != 0.0) {
			tmp_3 = Math.sin(x) * Math.tan((x * 0.5));
		} else {
			tmp_3 = t_0;
		}
		tmp_1 = (tmp_3 / -x) * (-1.0 / x);
	}
	return tmp_1;
}
def code(x):
	return (1.0 - math.cos(x)) / (x * x)
def code(x):
	t_0 = 1.0 - math.cos(x)
	tmp_1 = 0
	if x <= -0.002:
		tmp_2 = 0
		if 2.0 != 0.0:
			tmp_2 = math.sin(x) * math.tan((x / 2.0))
		else:
			tmp_2 = t_0
		tmp_1 = (tmp_2 / x) / x
	elif x <= 2e-7:
		tmp_1 = 0.5 + ((x * -0.041666666666666664) * x)
	else:
		tmp_3 = 0
		if 2.0 != 0.0:
			tmp_3 = math.sin(x) * math.tan((x * 0.5))
		else:
			tmp_3 = t_0
		tmp_1 = (tmp_3 / -x) * (-1.0 / x)
	return tmp_1
function code(x)
	return Float64(Float64(1.0 - cos(x)) / Float64(x * x))
end
function code(x)
	t_0 = Float64(1.0 - cos(x))
	tmp_1 = 0.0
	if (x <= -0.002)
		tmp_2 = 0.0
		if (2.0 != 0.0)
			tmp_2 = Float64(sin(x) * tan(Float64(x / 2.0)));
		else
			tmp_2 = t_0;
		end
		tmp_1 = Float64(Float64(tmp_2 / x) / x);
	elseif (x <= 2e-7)
		tmp_1 = Float64(0.5 + Float64(Float64(x * -0.041666666666666664) * x));
	else
		tmp_3 = 0.0
		if (2.0 != 0.0)
			tmp_3 = Float64(sin(x) * tan(Float64(x * 0.5)));
		else
			tmp_3 = t_0;
		end
		tmp_1 = Float64(Float64(tmp_3 / Float64(-x)) * Float64(-1.0 / x));
	end
	return tmp_1
end
function tmp = code(x)
	tmp = (1.0 - cos(x)) / (x * x);
end
function tmp_5 = code(x)
	t_0 = 1.0 - cos(x);
	tmp_2 = 0.0;
	if (x <= -0.002)
		tmp_3 = 0.0;
		if (2.0 ~= 0.0)
			tmp_3 = sin(x) * tan((x / 2.0));
		else
			tmp_3 = t_0;
		end
		tmp_2 = (tmp_3 / x) / x;
	elseif (x <= 2e-7)
		tmp_2 = 0.5 + ((x * -0.041666666666666664) * x);
	else
		tmp_4 = 0.0;
		if (2.0 ~= 0.0)
			tmp_4 = sin(x) * tan((x * 0.5));
		else
			tmp_4 = t_0;
		end
		tmp_2 = (tmp_4 / -x) * (-1.0 / x);
	end
	tmp_5 = tmp_2;
end
code[x_] := N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]
code[x_] := Block[{t$95$0 = N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -0.002], N[(N[(If[Unequal[2.0, 0.0], N[(N[Sin[x], $MachinePrecision] * N[Tan[N[(x / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], t$95$0] / x), $MachinePrecision] / x), $MachinePrecision], If[LessEqual[x, 2e-7], N[(0.5 + N[(N[(x * -0.041666666666666664), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], N[(N[(If[Unequal[2.0, 0.0], N[(N[Sin[x], $MachinePrecision] * N[Tan[N[(x * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], t$95$0] / (-x)), $MachinePrecision] * N[(-1.0 / x), $MachinePrecision]), $MachinePrecision]]]]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
t_0 := 1 - \cos x\\
\mathbf{if}\;x \leq -0.002:\\
\;\;\;\;\frac{\frac{\begin{array}{l}
\mathbf{if}\;2 \ne 0:\\
\;\;\;\;\sin x \cdot \tan \left(\frac{x}{2}\right)\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}}{x}}{x}\\

\mathbf{elif}\;x \leq 2 \cdot 10^{-7}:\\
\;\;\;\;0.5 + \left(x \cdot -0.041666666666666664\right) \cdot x\\

\mathbf{else}:\\
\;\;\;\;\frac{\begin{array}{l}
\mathbf{if}\;2 \ne 0:\\
\;\;\;\;\sin x \cdot \tan \left(x \cdot 0.5\right)\\

\mathbf{else}:\\
\;\;\;\;t_0\\


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


\end{array}

Error?

Derivation?

  1. Split input into 3 regimes
  2. if x < -2e-3

    1. Initial program 1.2

      \[\frac{1 - \cos x}{x \cdot x} \]
    2. Applied egg-rr1.2

      \[\leadsto \frac{\color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;\cos x - -1 \ne 0:\\ \;\;\;\;\frac{{\sin x}^{2}}{\cos x - -1}\\ \mathbf{else}:\\ \;\;\;\;1 - \cos x\\ } \end{array}}}{x \cdot x} \]
    3. Applied egg-rr0.2

      \[\leadsto \color{blue}{\frac{\frac{\begin{array}{l} \mathbf{if}\;\cos x - -1 \ne 0:\\ \;\;\;\;\sin x \cdot \tan \left(\frac{x}{2}\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \cos x\\ \end{array}}{x}}{x}} \]
    4. Taylor expanded in x around 0 0.2

      \[\leadsto \frac{\frac{\begin{array}{l} \mathbf{if}\;\color{blue}{2} \ne 0:\\ \;\;\;\;\sin x \cdot \tan \left(\frac{x}{2}\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \cos x\\ \end{array}}{x}}{x} \]

    if -2e-3 < x < 1.9999999999999999e-7

    1. Initial program 62.8

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

      \[\leadsto \color{blue}{0.5 + -0.041666666666666664 \cdot {x}^{2}} \]
    3. Applied egg-rr0.0

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

    if 1.9999999999999999e-7 < x

    1. Initial program 1.8

      \[\frac{1 - \cos x}{x \cdot x} \]
    2. Applied egg-rr1.3

      \[\leadsto \frac{\color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;\cos x - -1 \ne 0:\\ \;\;\;\;\frac{{\sin x}^{2}}{\cos x - -1}\\ \mathbf{else}:\\ \;\;\;\;1 - \cos x\\ } \end{array}}}{x \cdot x} \]
    3. Applied egg-rr0.2

      \[\leadsto \color{blue}{\frac{\frac{\begin{array}{l} \mathbf{if}\;\cos x - -1 \ne 0:\\ \;\;\;\;\sin x \cdot \tan \left(\frac{x}{2}\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \cos x\\ \end{array}}{x}}{x}} \]
    4. Taylor expanded in x around 0 0.2

      \[\leadsto \frac{\frac{\begin{array}{l} \mathbf{if}\;\color{blue}{2} \ne 0:\\ \;\;\;\;\sin x \cdot \tan \left(\frac{x}{2}\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \cos x\\ \end{array}}{x}}{x} \]
    5. Applied egg-rr0.3

      \[\leadsto \color{blue}{\frac{\begin{array}{l} \mathbf{if}\;2 \ne 0:\\ \;\;\;\;\sin x \cdot \tan \left(x \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \cos x\\ \end{array}}{-x} \cdot \frac{-1}{x}} \]
  3. Recombined 3 regimes into one program.

Alternatives

Alternative 1
Error0.1
Cost13772
\[\begin{array}{l} t_0 := \frac{\frac{\begin{array}{l} \mathbf{if}\;2 \ne 0:\\ \;\;\;\;\sin x \cdot \tan \left(\frac{x}{2}\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \cos x\\ \end{array}}{x}}{x}\\ \mathbf{if}\;x \leq -0.002:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 10^{-7}:\\ \;\;\;\;0.5 + \left(x \cdot -0.041666666666666664\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error0.5
Cost7368
\[\begin{array}{l} \mathbf{if}\;x \leq -0.005:\\ \;\;\;\;\frac{1 - \cos x}{x \cdot x}\\ \mathbf{elif}\;x \leq 0.0054:\\ \;\;\;\;0.5 + \left(x \cdot -0.041666666666666664\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{x - \cos x \cdot x}{x}}{x}}{x}\\ \end{array} \]
Alternative 3
Error0.5
Cost7368
\[\begin{array}{l} \mathbf{if}\;x \leq -0.005:\\ \;\;\;\;-\frac{\frac{x \cdot \left(\cos x + -1\right)}{x}}{x \cdot x}\\ \mathbf{elif}\;x \leq 0.0054:\\ \;\;\;\;0.5 + \left(x \cdot -0.041666666666666664\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{x - \cos x \cdot x}{x}}{x}}{x}\\ \end{array} \]
Alternative 4
Error0.4
Cost7240
\[\begin{array}{l} \mathbf{if}\;x \leq -0.005:\\ \;\;\;\;\frac{1 - \cos x}{x \cdot x}\\ \mathbf{elif}\;x \leq 0.004:\\ \;\;\;\;0.5 + \left(x \cdot -0.041666666666666664\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos x - 1}{x} \cdot \frac{-1}{x}\\ \end{array} \]
Alternative 5
Error0.6
Cost7112
\[\begin{array}{l} t_0 := \frac{1 - \cos x}{x \cdot x}\\ \mathbf{if}\;x \leq -0.005:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.004:\\ \;\;\;\;0.5 + \left(x \cdot -0.041666666666666664\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error0.4
Cost7112
\[\begin{array}{l} t_0 := 1 - \cos x\\ \mathbf{if}\;x \leq -0.005:\\ \;\;\;\;\frac{t_0}{x \cdot x}\\ \mathbf{elif}\;x \leq 0.004:\\ \;\;\;\;0.5 + \left(x \cdot -0.041666666666666664\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{t_0}{x}}{x}\\ \end{array} \]
Alternative 7
Error30.2
Cost64
\[0.5 \]

Error

Reproduce?

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