Average Error: 31.3 → 0.9
Time: 9.6s
Precision: binary64
Cost: 13768
\[\frac{1 - \cos x}{x \cdot x} \]
\[\begin{array}{l} \mathbf{if}\;x \leq -2354790321086377.5:\\ \;\;\;\;{x}^{-2} \cdot \left(1 - \cos x\right)\\ \mathbf{elif}\;x \leq 0.0017706247697189237:\\ \;\;\;\;0.5 + \left(-0.041666666666666664 \cdot {x}^{2} + 0.001388888888888889 \cdot {x}^{4}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\tan \left(x \cdot 0.5\right) \cdot \sin x}{x}}{x}\\ \end{array} \]
(FPCore (x) :precision binary64 (/ (- 1.0 (cos x)) (* x x)))
(FPCore (x)
 :precision binary64
 (if (<= x -2354790321086377.5)
   (* (pow x -2.0) (- 1.0 (cos x)))
   (if (<= x 0.0017706247697189237)
     (+
      0.5
      (+
       (* -0.041666666666666664 (pow x 2.0))
       (* 0.001388888888888889 (pow x 4.0))))
     (/ (/ (* (tan (* x 0.5)) (sin x)) x) x))))
double code(double x) {
	return (1.0 - cos(x)) / (x * x);
}
double code(double x) {
	double tmp;
	if (x <= -2354790321086377.5) {
		tmp = pow(x, -2.0) * (1.0 - cos(x));
	} else if (x <= 0.0017706247697189237) {
		tmp = 0.5 + ((-0.041666666666666664 * pow(x, 2.0)) + (0.001388888888888889 * pow(x, 4.0)));
	} else {
		tmp = ((tan((x * 0.5)) * sin(x)) / x) / x;
	}
	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) :: tmp
    if (x <= (-2354790321086377.5d0)) then
        tmp = (x ** (-2.0d0)) * (1.0d0 - cos(x))
    else if (x <= 0.0017706247697189237d0) then
        tmp = 0.5d0 + (((-0.041666666666666664d0) * (x ** 2.0d0)) + (0.001388888888888889d0 * (x ** 4.0d0)))
    else
        tmp = ((tan((x * 0.5d0)) * sin(x)) / x) / x
    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 tmp;
	if (x <= -2354790321086377.5) {
		tmp = Math.pow(x, -2.0) * (1.0 - Math.cos(x));
	} else if (x <= 0.0017706247697189237) {
		tmp = 0.5 + ((-0.041666666666666664 * Math.pow(x, 2.0)) + (0.001388888888888889 * Math.pow(x, 4.0)));
	} else {
		tmp = ((Math.tan((x * 0.5)) * Math.sin(x)) / x) / x;
	}
	return tmp;
}
def code(x):
	return (1.0 - math.cos(x)) / (x * x)
def code(x):
	tmp = 0
	if x <= -2354790321086377.5:
		tmp = math.pow(x, -2.0) * (1.0 - math.cos(x))
	elif x <= 0.0017706247697189237:
		tmp = 0.5 + ((-0.041666666666666664 * math.pow(x, 2.0)) + (0.001388888888888889 * math.pow(x, 4.0)))
	else:
		tmp = ((math.tan((x * 0.5)) * math.sin(x)) / x) / x
	return tmp
function code(x)
	return Float64(Float64(1.0 - cos(x)) / Float64(x * x))
end
function code(x)
	tmp = 0.0
	if (x <= -2354790321086377.5)
		tmp = Float64((x ^ -2.0) * Float64(1.0 - cos(x)));
	elseif (x <= 0.0017706247697189237)
		tmp = Float64(0.5 + Float64(Float64(-0.041666666666666664 * (x ^ 2.0)) + Float64(0.001388888888888889 * (x ^ 4.0))));
	else
		tmp = Float64(Float64(Float64(tan(Float64(x * 0.5)) * sin(x)) / x) / x);
	end
	return tmp
end
function tmp = code(x)
	tmp = (1.0 - cos(x)) / (x * x);
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= -2354790321086377.5)
		tmp = (x ^ -2.0) * (1.0 - cos(x));
	elseif (x <= 0.0017706247697189237)
		tmp = 0.5 + ((-0.041666666666666664 * (x ^ 2.0)) + (0.001388888888888889 * (x ^ 4.0)));
	else
		tmp = ((tan((x * 0.5)) * sin(x)) / x) / x;
	end
	tmp_2 = tmp;
end
code[x_] := N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]
code[x_] := If[LessEqual[x, -2354790321086377.5], N[(N[Power[x, -2.0], $MachinePrecision] * N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.0017706247697189237], N[(0.5 + N[(N[(-0.041666666666666664 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision] + N[(0.001388888888888889 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Tan[N[(x * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] / x), $MachinePrecision]]]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \leq -2354790321086377.5:\\
\;\;\;\;{x}^{-2} \cdot \left(1 - \cos x\right)\\

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

\mathbf{else}:\\
\;\;\;\;\frac{\frac{\tan \left(x \cdot 0.5\right) \cdot \sin x}{x}}{x}\\


\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 < -2354790321086377.5

    1. Initial program 1.1

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

      \[\leadsto \color{blue}{{x}^{-2} \cdot \left(1 - \cos x\right)} \]

    if -2354790321086377.5 < x < 0.0017706247697189237

    1. Initial program 60.8

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

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

    if 0.0017706247697189237 < x

    1. Initial program 1.1

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

      \[\leadsto \frac{\color{blue}{\frac{1}{\frac{1 + \cos x}{\sin x \cdot \sin x}}}}{x \cdot x} \]
    3. Taylor expanded in x around inf 1.2

      \[\leadsto \color{blue}{\frac{{\sin x}^{2}}{\left(1 + \cos x\right) \cdot {x}^{2}}} \]
    4. Simplified0.8

      \[\leadsto \color{blue}{\sin x \cdot \frac{\tan \left(\frac{x}{2}\right)}{x \cdot x}} \]
      Proof
      (*.f64 (sin.f64 x) (/.f64 (tan.f64 (/.f64 x 2)) (*.f64 x x))): 0 points increase in error, 0 points decrease in error
      (*.f64 (sin.f64 x) (/.f64 (Rewrite<= hang-0p-tan_binary64 (/.f64 (sin.f64 x) (+.f64 1 (cos.f64 x)))) (*.f64 x x))): 16 points increase in error, 3 points decrease in error
      (*.f64 (sin.f64 x) (/.f64 (/.f64 (sin.f64 x) (Rewrite<= +-commutative_binary64 (+.f64 (cos.f64 x) 1))) (*.f64 x x))): 0 points increase in error, 0 points decrease in error
      (*.f64 (sin.f64 x) (/.f64 (/.f64 (sin.f64 x) (+.f64 (cos.f64 x) 1)) (Rewrite<= unpow2_binary64 (pow.f64 x 2)))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= *-commutative_binary64 (*.f64 (/.f64 (/.f64 (sin.f64 x) (+.f64 (cos.f64 x) 1)) (pow.f64 x 2)) (sin.f64 x))): 0 points increase in error, 0 points decrease in error
      (*.f64 (Rewrite<= associate-/r*_binary64 (/.f64 (sin.f64 x) (*.f64 (+.f64 (cos.f64 x) 1) (pow.f64 x 2)))) (sin.f64 x)): 8 points increase in error, 6 points decrease in error
      (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 (sin.f64 x) (sin.f64 x)) (*.f64 (+.f64 (cos.f64 x) 1) (pow.f64 x 2)))): 5 points increase in error, 28 points decrease in error
      (/.f64 (Rewrite<= unpow2_binary64 (pow.f64 (sin.f64 x) 2)) (*.f64 (+.f64 (cos.f64 x) 1) (pow.f64 x 2))): 0 points increase in error, 0 points decrease in error
      (/.f64 (pow.f64 (sin.f64 x) 2) (*.f64 (Rewrite=> +-commutative_binary64 (+.f64 1 (cos.f64 x))) (pow.f64 x 2))): 0 points increase in error, 0 points decrease in error
    5. Applied egg-rr0.2

      \[\leadsto \color{blue}{\frac{\frac{\tan \left(x \cdot 0.5\right) \cdot \sin x}{x}}{x}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.9

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

Alternatives

Alternative 1
Error1.0
Cost13640
\[\begin{array}{l} \mathbf{if}\;x \leq -2354790321086377.5:\\ \;\;\;\;{x}^{-2} \cdot \left(1 - \cos x\right)\\ \mathbf{elif}\;x \leq 1.704046130785219 \cdot 10^{-56}:\\ \;\;\;\;0.5 + -0.041666666666666664 \cdot \left(x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\tan \left(x \cdot 0.5\right) \cdot \sin x}{x}}{x}\\ \end{array} \]
Alternative 2
Error1.1
Cost13576
\[\begin{array}{l} \mathbf{if}\;x \leq -2354790321086377.5:\\ \;\;\;\;{x}^{-2} \cdot \left(1 - \cos x\right)\\ \mathbf{elif}\;x \leq 0.0017706247697189237:\\ \;\;\;\;0.5 + -0.041666666666666664 \cdot \left(x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;{x}^{-2} - \frac{\frac{\cos x}{x}}{x}\\ \end{array} \]
Alternative 3
Error1.1
Cost13316
\[\begin{array}{l} t_0 := 1 - \cos x\\ \mathbf{if}\;x \leq -2354790321086377.5:\\ \;\;\;\;{x}^{-2} \cdot t_0\\ \mathbf{elif}\;x \leq 0.0017706247697189237:\\ \;\;\;\;0.5 + -0.041666666666666664 \cdot \left(x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x}}{\frac{x}{t_0}}\\ \end{array} \]
Alternative 4
Error1.1
Cost7240
\[\begin{array}{l} t_0 := 1 - \cos x\\ \mathbf{if}\;x \leq -2354790321086377.5:\\ \;\;\;\;\frac{1}{x} \cdot \frac{t_0}{x}\\ \mathbf{elif}\;x \leq 0.0017706247697189237:\\ \;\;\;\;0.5 + -0.041666666666666664 \cdot \left(x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x}}{\frac{x}{t_0}}\\ \end{array} \]
Alternative 5
Error1.0
Cost7112
\[\begin{array}{l} t_0 := \frac{\frac{1 - \cos x}{x}}{x}\\ \mathbf{if}\;x \leq -2354790321086377.5:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.0017706247697189237:\\ \;\;\;\;0.5 + -0.041666666666666664 \cdot \left(x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error1.1
Cost7112
\[\begin{array}{l} t_0 := \frac{1 - \cos x}{x}\\ \mathbf{if}\;x \leq -2354790321086377.5:\\ \;\;\;\;\frac{1}{x} \cdot t_0\\ \mathbf{elif}\;x \leq 0.0017706247697189237:\\ \;\;\;\;0.5 + -0.041666666666666664 \cdot \left(x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0}{x}\\ \end{array} \]
Alternative 7
Error14.3
Cost832
\[\frac{\frac{1}{x}}{x \cdot 0.16666666666666666 + 2 \cdot \frac{1}{x}} \]
Alternative 8
Error31.2
Cost64
\[0.5 \]

Error

Reproduce

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