?

Average Error: 31.2 → 0.5
Time: 21.1s
Precision: binary64
Cost: 13768

?

\[\frac{1 - \cos x}{x \cdot x} \]
\[\begin{array}{l} t_0 := \frac{1 - \cos x}{x \cdot x}\\ \mathbf{if}\;x \leq -0.03:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.035:\\ \;\;\;\;-0.041666666666666664 \cdot {x}^{2} + \left(0.5 + 0.001388888888888889 \cdot {x}^{4}\right)\\ \mathbf{else}:\\ \;\;\;\;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)) (* x x))))
   (if (<= x -0.03)
     t_0
     (if (<= x 0.035)
       (+
        (* -0.041666666666666664 (pow x 2.0))
        (+ 0.5 (* 0.001388888888888889 (pow x 4.0))))
       t_0))))
double code(double x) {
	return (1.0 - cos(x)) / (x * x);
}
double code(double x) {
	double t_0 = (1.0 - cos(x)) / (x * x);
	double tmp;
	if (x <= -0.03) {
		tmp = t_0;
	} else if (x <= 0.035) {
		tmp = (-0.041666666666666664 * pow(x, 2.0)) + (0.5 + (0.001388888888888889 * pow(x, 4.0)));
	} else {
		tmp = 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)) / (x * x)
    if (x <= (-0.03d0)) then
        tmp = t_0
    else if (x <= 0.035d0) then
        tmp = ((-0.041666666666666664d0) * (x ** 2.0d0)) + (0.5d0 + (0.001388888888888889d0 * (x ** 4.0d0)))
    else
        tmp = 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)) / (x * x);
	double tmp;
	if (x <= -0.03) {
		tmp = t_0;
	} else if (x <= 0.035) {
		tmp = (-0.041666666666666664 * Math.pow(x, 2.0)) + (0.5 + (0.001388888888888889 * Math.pow(x, 4.0)));
	} else {
		tmp = 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)) / (x * x)
	tmp = 0
	if x <= -0.03:
		tmp = t_0
	elif x <= 0.035:
		tmp = (-0.041666666666666664 * math.pow(x, 2.0)) + (0.5 + (0.001388888888888889 * math.pow(x, 4.0)))
	else:
		tmp = t_0
	return tmp
function code(x)
	return Float64(Float64(1.0 - cos(x)) / Float64(x * x))
end
function code(x)
	t_0 = Float64(Float64(1.0 - cos(x)) / Float64(x * x))
	tmp = 0.0
	if (x <= -0.03)
		tmp = t_0;
	elseif (x <= 0.035)
		tmp = Float64(Float64(-0.041666666666666664 * (x ^ 2.0)) + Float64(0.5 + Float64(0.001388888888888889 * (x ^ 4.0))));
	else
		tmp = 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)) / (x * x);
	tmp = 0.0;
	if (x <= -0.03)
		tmp = t_0;
	elseif (x <= 0.035)
		tmp = (-0.041666666666666664 * (x ^ 2.0)) + (0.5 + (0.001388888888888889 * (x ^ 4.0)));
	else
		tmp = 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[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -0.03], t$95$0, If[LessEqual[x, 0.035], N[(N[(-0.041666666666666664 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision] + N[(0.5 + N[(0.001388888888888889 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
t_0 := \frac{1 - \cos x}{x \cdot x}\\
\mathbf{if}\;x \leq -0.03:\\
\;\;\;\;t_0\\

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

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Split input into 2 regimes
  2. if x < -0.029999999999999999 or 0.035000000000000003 < x

    1. Initial program 0.9

      \[\frac{1 - \cos x}{x \cdot x} \]

    if -0.029999999999999999 < x < 0.035000000000000003

    1. Initial program 62.3

      \[\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. Simplified0.0

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

      [Start]0.0

      \[ 0.5 + \left(-0.041666666666666664 \cdot {x}^{2} + 0.001388888888888889 \cdot {x}^{4}\right) \]

      rational.json-simplify-41 [=>]0.0

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

      rational.json-simplify-1 [=>]0.0

      \[ -0.041666666666666664 \cdot {x}^{2} + \color{blue}{\left(0.5 + 0.001388888888888889 \cdot {x}^{4}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.5

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

Alternatives

Alternative 1
Error0.5
Cost7112
\[\begin{array}{l} t_0 := \frac{1 - \cos x}{x \cdot x}\\ \mathbf{if}\;x \leq -0.0048:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.0046:\\ \;\;\;\;0.5 + -0.041666666666666664 \cdot {x}^{2}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error16.1
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -1.02 \cdot 10^{+77}:\\ \;\;\;\;0\\ \mathbf{elif}\;x \leq 1.06 \cdot 10^{+77}:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
Alternative 3
Error46.8
Cost64
\[0 \]

Error

Reproduce?

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