Average Error: 31.3 → 0.3
Time: 9.0s
Precision: binary64
Cost: 7432
\[\frac{1 - \cos x}{x \cdot x} \]
\[\begin{array}{l} t_0 := 1 - \cos x\\ \mathbf{if}\;x \leq -3.869469486314109:\\ \;\;\;\;\frac{\frac{t_0}{x}}{x}\\ \mathbf{elif}\;x \leq 0.0010468391165329894:\\ \;\;\;\;0.5 + \left(-0.041666666666666664 \cdot \left(x \cdot x\right) + 0.001388888888888889 \cdot {x}^{4}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x}}{\frac{x}{t_0}}\\ \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 -3.869469486314109)
     (/ (/ t_0 x) x)
     (if (<= x 0.0010468391165329894)
       (+
        0.5
        (+
         (* -0.041666666666666664 (* x x))
         (* 0.001388888888888889 (pow x 4.0))))
       (/ (/ 1.0 x) (/ x t_0))))))
double code(double x) {
	return (1.0 - cos(x)) / (x * x);
}
double code(double x) {
	double t_0 = 1.0 - cos(x);
	double tmp;
	if (x <= -3.869469486314109) {
		tmp = (t_0 / x) / x;
	} else if (x <= 0.0010468391165329894) {
		tmp = 0.5 + ((-0.041666666666666664 * (x * x)) + (0.001388888888888889 * pow(x, 4.0)));
	} else {
		tmp = (1.0 / x) / (x / t_0);
	}
	return tmp;
}
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
    t_0 = 1.0d0 - cos(x)
    if (x <= (-3.869469486314109d0)) then
        tmp = (t_0 / x) / x
    else if (x <= 0.0010468391165329894d0) then
        tmp = 0.5d0 + (((-0.041666666666666664d0) * (x * x)) + (0.001388888888888889d0 * (x ** 4.0d0)))
    else
        tmp = (1.0d0 / x) / (x / t_0)
    end if
    code = tmp
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;
	if (x <= -3.869469486314109) {
		tmp = (t_0 / x) / x;
	} else if (x <= 0.0010468391165329894) {
		tmp = 0.5 + ((-0.041666666666666664 * (x * x)) + (0.001388888888888889 * Math.pow(x, 4.0)));
	} else {
		tmp = (1.0 / x) / (x / t_0);
	}
	return tmp;
}
def code(x):
	return (1.0 - math.cos(x)) / (x * x)
def code(x):
	t_0 = 1.0 - math.cos(x)
	tmp = 0
	if x <= -3.869469486314109:
		tmp = (t_0 / x) / x
	elif x <= 0.0010468391165329894:
		tmp = 0.5 + ((-0.041666666666666664 * (x * x)) + (0.001388888888888889 * math.pow(x, 4.0)))
	else:
		tmp = (1.0 / x) / (x / t_0)
	return tmp
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 = 0.0
	if (x <= -3.869469486314109)
		tmp = Float64(Float64(t_0 / x) / x);
	elseif (x <= 0.0010468391165329894)
		tmp = Float64(0.5 + Float64(Float64(-0.041666666666666664 * Float64(x * x)) + Float64(0.001388888888888889 * (x ^ 4.0))));
	else
		tmp = Float64(Float64(1.0 / x) / Float64(x / t_0));
	end
	return tmp
end
function tmp = code(x)
	tmp = (1.0 - cos(x)) / (x * x);
end
function tmp_2 = code(x)
	t_0 = 1.0 - cos(x);
	tmp = 0.0;
	if (x <= -3.869469486314109)
		tmp = (t_0 / x) / x;
	elseif (x <= 0.0010468391165329894)
		tmp = 0.5 + ((-0.041666666666666664 * (x * x)) + (0.001388888888888889 * (x ^ 4.0)));
	else
		tmp = (1.0 / x) / (x / t_0);
	end
	tmp_2 = tmp;
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, -3.869469486314109], N[(N[(t$95$0 / x), $MachinePrecision] / x), $MachinePrecision], If[LessEqual[x, 0.0010468391165329894], N[(0.5 + N[(N[(-0.041666666666666664 * N[(x * x), $MachinePrecision]), $MachinePrecision] + N[(0.001388888888888889 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / x), $MachinePrecision] / N[(x / t$95$0), $MachinePrecision]), $MachinePrecision]]]]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
t_0 := 1 - \cos x\\
\mathbf{if}\;x \leq -3.869469486314109:\\
\;\;\;\;\frac{\frac{t_0}{x}}{x}\\

\mathbf{elif}\;x \leq 0.0010468391165329894:\\
\;\;\;\;0.5 + \left(-0.041666666666666664 \cdot \left(x \cdot x\right) + 0.001388888888888889 \cdot {x}^{4}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{x}}{\frac{x}{t_0}}\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

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

    1. Initial program 1.0

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

      \[\leadsto \frac{\color{blue}{\log \left(e^{1 - \cos x}\right)}}{x \cdot x} \]
    3. Applied egg-rr1.0

      \[\leadsto \color{blue}{{\left(\frac{x}{\frac{1 - \cos x}{x}}\right)}^{-1}} \]
    4. Applied egg-rr0.4

      \[\leadsto \color{blue}{\frac{\frac{1 - \cos x}{x}}{x}} \]

    if -3.86946948631410903 < x < 0.0010468391165329894

    1. Initial program 62.1

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

      \[\leadsto \color{blue}{0.5 + \left(-0.041666666666666664 \cdot {x}^{2} + 0.001388888888888889 \cdot {x}^{4}\right)} \]
    3. Applied egg-rr0.0

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

    if 0.0010468391165329894 < x

    1. Initial program 0.9

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

      \[\leadsto \frac{\color{blue}{\log \left(e^{1 - \cos x}\right)}}{x \cdot x} \]
    3. Applied egg-rr0.9

      \[\leadsto \color{blue}{{\left(\frac{x}{\frac{1 - \cos x}{x}}\right)}^{-1}} \]
    4. Applied egg-rr0.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.869469486314109:\\ \;\;\;\;\frac{\frac{1 - \cos x}{x}}{x}\\ \mathbf{elif}\;x \leq 0.0010468391165329894:\\ \;\;\;\;0.5 + \left(-0.041666666666666664 \cdot \left(x \cdot x\right) + 0.001388888888888889 \cdot {x}^{4}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x}}{\frac{x}{1 - \cos x}}\\ \end{array} \]

Alternatives

Alternative 1
Error0.3
Cost7240
\[\begin{array}{l} t_0 := 1 - \cos x\\ \mathbf{if}\;x \leq -3.869469486314109:\\ \;\;\;\;\frac{\frac{t_0}{x}}{x}\\ \mathbf{elif}\;x \leq 0.0010468391165329894:\\ \;\;\;\;0.5 + -0.041666666666666664 \cdot \left(x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x}}{\frac{x}{t_0}}\\ \end{array} \]
Alternative 2
Error0.3
Cost7112
\[\begin{array}{l} t_0 := \frac{\frac{1 - \cos x}{x}}{x}\\ \mathbf{if}\;x \leq -3.869469486314109:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.0010468391165329894:\\ \;\;\;\;0.5 + -0.041666666666666664 \cdot \left(x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error13.7
Cost832
\[\frac{1}{x \cdot \left(x \cdot 0.16666666666666666 + \frac{1}{x} \cdot 2\right)} \]
Alternative 4
Error13.6
Cost832
\[\frac{\frac{1}{x}}{x \cdot 0.16666666666666666 + \frac{1}{x} \cdot 2} \]
Alternative 5
Error15.3
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -6.898211937387391 \cdot 10^{+87}:\\ \;\;\;\;0\\ \mathbf{elif}\;x \leq 4.0590004179723275 \cdot 10^{+65}:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
Alternative 6
Error31.1
Cost64
\[0.5 \]

Error

Reproduce

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