?

Average Error: 31.2 → 0.5
Time: 16.3s
Precision: binary64
Cost: 47432

?

\[\frac{1 - \cos x}{x \cdot x} \]
\[\begin{array}{l} t_0 := \cos x + -1\\ t_1 := 1 - \cos x\\ t_2 := \frac{1}{t_1} \cdot \left(t_0 \cdot t_0\right)\\ \mathbf{if}\;x \leq -0.098:\\ \;\;\;\;\frac{t_1}{x \cdot x}\\ \mathbf{elif}\;x \leq 0.1:\\ \;\;\;\;\left(0.001388888888888889 \cdot {x}^{4} + -2.48015873015873 \cdot 10^{-5} \cdot {x}^{6}\right) + \left(0.5 + -0.041666666666666664 \cdot {x}^{2}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{t_2 \cdot \left(t_1 \cdot \frac{1}{t_2}\right)}{x \cdot x}\\ \end{array} \]
(FPCore (x) :precision binary64 (/ (- 1.0 (cos x)) (* x x)))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (+ (cos x) -1.0))
        (t_1 (- 1.0 (cos x)))
        (t_2 (* (/ 1.0 t_1) (* t_0 t_0))))
   (if (<= x -0.098)
     (/ t_1 (* x x))
     (if (<= x 0.1)
       (+
        (+
         (* 0.001388888888888889 (pow x 4.0))
         (* -2.48015873015873e-5 (pow x 6.0)))
        (+ 0.5 (* -0.041666666666666664 (pow x 2.0))))
       (/ (* t_2 (* t_1 (/ 1.0 t_2))) (* x x))))))
double code(double x) {
	return (1.0 - cos(x)) / (x * x);
}
double code(double x) {
	double t_0 = cos(x) + -1.0;
	double t_1 = 1.0 - cos(x);
	double t_2 = (1.0 / t_1) * (t_0 * t_0);
	double tmp;
	if (x <= -0.098) {
		tmp = t_1 / (x * x);
	} else if (x <= 0.1) {
		tmp = ((0.001388888888888889 * pow(x, 4.0)) + (-2.48015873015873e-5 * pow(x, 6.0))) + (0.5 + (-0.041666666666666664 * pow(x, 2.0)));
	} else {
		tmp = (t_2 * (t_1 * (1.0 / t_2))) / (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) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = cos(x) + (-1.0d0)
    t_1 = 1.0d0 - cos(x)
    t_2 = (1.0d0 / t_1) * (t_0 * t_0)
    if (x <= (-0.098d0)) then
        tmp = t_1 / (x * x)
    else if (x <= 0.1d0) then
        tmp = ((0.001388888888888889d0 * (x ** 4.0d0)) + ((-2.48015873015873d-5) * (x ** 6.0d0))) + (0.5d0 + ((-0.041666666666666664d0) * (x ** 2.0d0)))
    else
        tmp = (t_2 * (t_1 * (1.0d0 / t_2))) / (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 t_0 = Math.cos(x) + -1.0;
	double t_1 = 1.0 - Math.cos(x);
	double t_2 = (1.0 / t_1) * (t_0 * t_0);
	double tmp;
	if (x <= -0.098) {
		tmp = t_1 / (x * x);
	} else if (x <= 0.1) {
		tmp = ((0.001388888888888889 * Math.pow(x, 4.0)) + (-2.48015873015873e-5 * Math.pow(x, 6.0))) + (0.5 + (-0.041666666666666664 * Math.pow(x, 2.0)));
	} else {
		tmp = (t_2 * (t_1 * (1.0 / t_2))) / (x * x);
	}
	return tmp;
}
def code(x):
	return (1.0 - math.cos(x)) / (x * x)
def code(x):
	t_0 = math.cos(x) + -1.0
	t_1 = 1.0 - math.cos(x)
	t_2 = (1.0 / t_1) * (t_0 * t_0)
	tmp = 0
	if x <= -0.098:
		tmp = t_1 / (x * x)
	elif x <= 0.1:
		tmp = ((0.001388888888888889 * math.pow(x, 4.0)) + (-2.48015873015873e-5 * math.pow(x, 6.0))) + (0.5 + (-0.041666666666666664 * math.pow(x, 2.0)))
	else:
		tmp = (t_2 * (t_1 * (1.0 / t_2))) / (x * x)
	return tmp
function code(x)
	return Float64(Float64(1.0 - cos(x)) / Float64(x * x))
end
function code(x)
	t_0 = Float64(cos(x) + -1.0)
	t_1 = Float64(1.0 - cos(x))
	t_2 = Float64(Float64(1.0 / t_1) * Float64(t_0 * t_0))
	tmp = 0.0
	if (x <= -0.098)
		tmp = Float64(t_1 / Float64(x * x));
	elseif (x <= 0.1)
		tmp = Float64(Float64(Float64(0.001388888888888889 * (x ^ 4.0)) + Float64(-2.48015873015873e-5 * (x ^ 6.0))) + Float64(0.5 + Float64(-0.041666666666666664 * (x ^ 2.0))));
	else
		tmp = Float64(Float64(t_2 * Float64(t_1 * Float64(1.0 / t_2))) / Float64(x * x));
	end
	return tmp
end
function tmp = code(x)
	tmp = (1.0 - cos(x)) / (x * x);
end
function tmp_2 = code(x)
	t_0 = cos(x) + -1.0;
	t_1 = 1.0 - cos(x);
	t_2 = (1.0 / t_1) * (t_0 * t_0);
	tmp = 0.0;
	if (x <= -0.098)
		tmp = t_1 / (x * x);
	elseif (x <= 0.1)
		tmp = ((0.001388888888888889 * (x ^ 4.0)) + (-2.48015873015873e-5 * (x ^ 6.0))) + (0.5 + (-0.041666666666666664 * (x ^ 2.0)));
	else
		tmp = (t_2 * (t_1 * (1.0 / t_2))) / (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_] := Block[{t$95$0 = N[(N[Cos[x], $MachinePrecision] + -1.0), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(1.0 / t$95$1), $MachinePrecision] * N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -0.098], N[(t$95$1 / N[(x * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.1], N[(N[(N[(0.001388888888888889 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] + N[(-2.48015873015873e-5 * N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.5 + N[(-0.041666666666666664 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$2 * N[(t$95$1 * N[(1.0 / t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]]]]]]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
t_0 := \cos x + -1\\
t_1 := 1 - \cos x\\
t_2 := \frac{1}{t_1} \cdot \left(t_0 \cdot t_0\right)\\
\mathbf{if}\;x \leq -0.098:\\
\;\;\;\;\frac{t_1}{x \cdot x}\\

\mathbf{elif}\;x \leq 0.1:\\
\;\;\;\;\left(0.001388888888888889 \cdot {x}^{4} + -2.48015873015873 \cdot 10^{-5} \cdot {x}^{6}\right) + \left(0.5 + -0.041666666666666664 \cdot {x}^{2}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{t_2 \cdot \left(t_1 \cdot \frac{1}{t_2}\right)}{x \cdot 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 < -0.098000000000000004

    1. Initial program 1.1

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

    if -0.098000000000000004 < x < 0.10000000000000001

    1. Initial program 62.2

      \[\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} + \left(-2.48015873015873 \cdot 10^{-5} \cdot {x}^{6} + 0.001388888888888889 \cdot {x}^{4}\right)\right)} \]
    3. Simplified0.0

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

      [Start]0.0

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

      rational_best.json-simplify-43 [=>]0.0

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

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

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

      rational_best.json-simplify-1 [<=]0.0

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

    if 0.10000000000000001 < x

    1. Initial program 0.9

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

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

      \[\leadsto \frac{\left(1 - \cos x\right) \cdot \left(\left(1 - \cos x\right) \cdot \frac{1}{\color{blue}{\frac{1}{1 - \cos x} \cdot \left(\left(\cos x + -1\right) \cdot \left(\cos x + -1\right)\right)}}\right)}{x \cdot x} \]
    4. Applied egg-rr1.0

      \[\leadsto \frac{\color{blue}{\left(\frac{1}{1 - \cos x} \cdot \left(\left(\cos x + -1\right) \cdot \left(\cos x + -1\right)\right)\right)} \cdot \left(\left(1 - \cos x\right) \cdot \frac{1}{\frac{1}{1 - \cos x} \cdot \left(\left(\cos x + -1\right) \cdot \left(\cos x + -1\right)\right)}\right)}{x \cdot x} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.5

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

Alternatives

Alternative 1
Error0.5
Cost20488
\[\begin{array}{l} t_0 := \frac{1 - \cos x}{x \cdot x}\\ \mathbf{if}\;x \leq -0.098:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.105:\\ \;\;\;\;\left(0.001388888888888889 \cdot {x}^{4} + -2.48015873015873 \cdot 10^{-5} \cdot {x}^{6}\right) + \left(0.5 + -0.041666666666666664 \cdot {x}^{2}\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error0.5
Cost13768
\[\begin{array}{l} t_0 := \frac{1 - \cos x}{x \cdot x}\\ \mathbf{if}\;x \leq -0.0305:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.03:\\ \;\;\;\;-0.041666666666666664 \cdot {x}^{2} + \left(0.5 + 0.001388888888888889 \cdot {x}^{4}\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error0.5
Cost13768
\[\begin{array}{l} t_0 := \frac{1 - \cos x}{x \cdot x}\\ \mathbf{if}\;x \leq -0.0305:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.03:\\ \;\;\;\;{x}^{4} \cdot 0.001388888888888889 + \left(0.5 + {x}^{2} \cdot -0.041666666666666664\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error0.6
Cost7112
\[\begin{array}{l} t_0 := \frac{1 - \cos x}{x \cdot x}\\ \mathbf{if}\;x \leq -0.000115:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.000165:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error31.2
Cost64
\[0.5 \]

Error

Reproduce?

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