?

Average Accuracy: 50.9% → 99.4%
Time: 14.9s
Precision: binary64
Cost: 13508

?

\[\frac{1 - \cos x}{x \cdot x} \]
\[\begin{array}{l} \mathbf{if}\;x \leq -0.5:\\ \;\;\;\;\frac{\tan \left(x \cdot 0.5\right)}{x \cdot x} \cdot \sin x\\ \mathbf{elif}\;x \leq 0.0055:\\ \;\;\;\;0.5 + \left(x \cdot x\right) \cdot -0.041666666666666664\\ \mathbf{else}:\\ \;\;\;\;{x}^{-2} \cdot \left(1 - \cos x\right)\\ \end{array} \]
(FPCore (x) :precision binary64 (/ (- 1.0 (cos x)) (* x x)))
(FPCore (x)
 :precision binary64
 (if (<= x -0.5)
   (* (/ (tan (* x 0.5)) (* x x)) (sin x))
   (if (<= x 0.0055)
     (+ 0.5 (* (* x x) -0.041666666666666664))
     (* (pow x -2.0) (- 1.0 (cos x))))))
double code(double x) {
	return (1.0 - cos(x)) / (x * x);
}
double code(double x) {
	double tmp;
	if (x <= -0.5) {
		tmp = (tan((x * 0.5)) / (x * x)) * sin(x);
	} else if (x <= 0.0055) {
		tmp = 0.5 + ((x * x) * -0.041666666666666664);
	} else {
		tmp = pow(x, -2.0) * (1.0 - cos(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 <= (-0.5d0)) then
        tmp = (tan((x * 0.5d0)) / (x * x)) * sin(x)
    else if (x <= 0.0055d0) then
        tmp = 0.5d0 + ((x * x) * (-0.041666666666666664d0))
    else
        tmp = (x ** (-2.0d0)) * (1.0d0 - cos(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 <= -0.5) {
		tmp = (Math.tan((x * 0.5)) / (x * x)) * Math.sin(x);
	} else if (x <= 0.0055) {
		tmp = 0.5 + ((x * x) * -0.041666666666666664);
	} else {
		tmp = Math.pow(x, -2.0) * (1.0 - Math.cos(x));
	}
	return tmp;
}
def code(x):
	return (1.0 - math.cos(x)) / (x * x)
def code(x):
	tmp = 0
	if x <= -0.5:
		tmp = (math.tan((x * 0.5)) / (x * x)) * math.sin(x)
	elif x <= 0.0055:
		tmp = 0.5 + ((x * x) * -0.041666666666666664)
	else:
		tmp = math.pow(x, -2.0) * (1.0 - math.cos(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 <= -0.5)
		tmp = Float64(Float64(tan(Float64(x * 0.5)) / Float64(x * x)) * sin(x));
	elseif (x <= 0.0055)
		tmp = Float64(0.5 + Float64(Float64(x * x) * -0.041666666666666664));
	else
		tmp = Float64((x ^ -2.0) * Float64(1.0 - cos(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 <= -0.5)
		tmp = (tan((x * 0.5)) / (x * x)) * sin(x);
	elseif (x <= 0.0055)
		tmp = 0.5 + ((x * x) * -0.041666666666666664);
	else
		tmp = (x ^ -2.0) * (1.0 - cos(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, -0.5], N[(N[(N[Tan[N[(x * 0.5), $MachinePrecision]], $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.0055], N[(0.5 + N[(N[(x * x), $MachinePrecision] * -0.041666666666666664), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -2.0], $MachinePrecision] * N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \leq -0.5:\\
\;\;\;\;\frac{\tan \left(x \cdot 0.5\right)}{x \cdot x} \cdot \sin x\\

\mathbf{elif}\;x \leq 0.0055:\\
\;\;\;\;0.5 + \left(x \cdot x\right) \cdot -0.041666666666666664\\

\mathbf{else}:\\
\;\;\;\;{x}^{-2} \cdot \left(1 - \cos x\right)\\


\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.5

    1. Initial program 98.4%

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

      \[\leadsto \frac{\color{blue}{\left(\sin x \cdot \sin x\right) \cdot \frac{1}{1 + \cos x}}}{x \cdot x} \]
      Proof

      [Start]98.4

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

      flip-- [=>]98.1

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

      div-inv [=>]98.0

      \[ \frac{\color{blue}{\left(1 \cdot 1 - \cos x \cdot \cos x\right) \cdot \frac{1}{1 + \cos x}}}{x \cdot x} \]

      metadata-eval [=>]98.0

      \[ \frac{\left(\color{blue}{1} - \cos x \cdot \cos x\right) \cdot \frac{1}{1 + \cos x}}{x \cdot x} \]

      1-sub-cos [=>]98.3

      \[ \frac{\color{blue}{\left(\sin x \cdot \sin x\right)} \cdot \frac{1}{1 + \cos x}}{x \cdot x} \]
    3. Simplified98.8%

      \[\leadsto \frac{\color{blue}{\sin x \cdot \tan \left(\frac{x}{2}\right)}}{x \cdot x} \]
      Proof

      [Start]98.3

      \[ \frac{\left(\sin x \cdot \sin x\right) \cdot \frac{1}{1 + \cos x}}{x \cdot x} \]

      associate-*l* [=>]98.3

      \[ \frac{\color{blue}{\sin x \cdot \left(\sin x \cdot \frac{1}{1 + \cos x}\right)}}{x \cdot x} \]

      associate-*r/ [=>]98.3

      \[ \frac{\sin x \cdot \color{blue}{\frac{\sin x \cdot 1}{1 + \cos x}}}{x \cdot x} \]

      *-rgt-identity [=>]98.3

      \[ \frac{\sin x \cdot \frac{\color{blue}{\sin x}}{1 + \cos x}}{x \cdot x} \]

      hang-0p-tan [=>]98.8

      \[ \frac{\sin x \cdot \color{blue}{\tan \left(\frac{x}{2}\right)}}{x \cdot x} \]
    4. Applied egg-rr98.8%

      \[\leadsto \color{blue}{\frac{\tan \left(x \cdot 0.5\right)}{x \cdot x} \cdot \sin x} \]
      Proof

      [Start]98.8

      \[ \frac{\sin x \cdot \tan \left(\frac{x}{2}\right)}{x \cdot x} \]

      *-commutative [=>]98.8

      \[ \frac{\color{blue}{\tan \left(\frac{x}{2}\right) \cdot \sin x}}{x \cdot x} \]

      associate-/l* [=>]98.8

      \[ \color{blue}{\frac{\tan \left(\frac{x}{2}\right)}{\frac{x \cdot x}{\sin x}}} \]

      associate-/r/ [=>]98.8

      \[ \color{blue}{\frac{\tan \left(\frac{x}{2}\right)}{x \cdot x} \cdot \sin x} \]

      div-inv [=>]98.8

      \[ \frac{\tan \color{blue}{\left(x \cdot \frac{1}{2}\right)}}{x \cdot x} \cdot \sin x \]

      metadata-eval [=>]98.8

      \[ \frac{\tan \left(x \cdot \color{blue}{0.5}\right)}{x \cdot x} \cdot \sin x \]

    if -0.5 < x < 0.0054999999999999997

    1. Initial program 2.6%

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

      \[\leadsto \color{blue}{0.5 + -0.041666666666666664 \cdot {x}^{2}} \]
    3. Simplified99.9%

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

      [Start]99.9

      \[ 0.5 + -0.041666666666666664 \cdot {x}^{2} \]

      unpow2 [=>]99.9

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

    if 0.0054999999999999997 < x

    1. Initial program 98.3%

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

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

      [Start]98.3

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

      div-inv [=>]98.3

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

      *-commutative [=>]98.3

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

      pow2 [=>]98.3

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

      pow-flip [=>]99.2

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

      metadata-eval [=>]99.2

      \[ {x}^{\color{blue}{-2}} \cdot \left(1 - \cos x\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification99.4%

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

Alternatives

Alternative 1
Accuracy99.6%
Cost13448
\[\begin{array}{l} t_0 := 1 - \cos x\\ \mathbf{if}\;x \leq -0.0052:\\ \;\;\;\;\frac{\frac{t_0}{x}}{x}\\ \mathbf{elif}\;x \leq 0.0055:\\ \;\;\;\;0.5 + \left(x \cdot x\right) \cdot -0.041666666666666664\\ \mathbf{else}:\\ \;\;\;\;{x}^{-2} \cdot t_0\\ \end{array} \]
Alternative 2
Accuracy99.2%
Cost7113
\[\begin{array}{l} \mathbf{if}\;x \leq -0.0052 \lor \neg \left(x \leq 0.0055\right):\\ \;\;\;\;\frac{1 - \cos x}{x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;0.5 + \left(x \cdot x\right) \cdot -0.041666666666666664\\ \end{array} \]
Alternative 3
Accuracy99.6%
Cost7113
\[\begin{array}{l} \mathbf{if}\;x \leq -0.0052 \lor \neg \left(x \leq 0.0055\right):\\ \;\;\;\;\frac{\frac{1 - \cos x}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;0.5 + \left(x \cdot x\right) \cdot -0.041666666666666664\\ \end{array} \]
Alternative 4
Accuracy76.0%
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -3.9 \cdot 10^{+76}:\\ \;\;\;\;0\\ \mathbf{elif}\;x \leq 1.25 \cdot 10^{+77}:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
Alternative 5
Accuracy27.8%
Cost64
\[0 \]

Error

Reproduce?

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