?

Average Error: 63.1 → 14.9
Time: 16.1s
Precision: binary64
Cost: 19908

?

\[-1 \leq x \land x \leq 1\]
\[\frac{\cos x - 1}{\cos^{-1} \cos x} \]
\[\begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-311}:\\ \;\;\;\;\frac{-0.5 \cdot \left(x \cdot x\right)}{\left|\left(x \mathsf{rem} \left(2 \cdot \pi\right)\right)\right|}\\ \mathbf{else}:\\ \;\;\;\;x \cdot -0.5 + 0.041666666666666664 \cdot {x}^{3}\\ \end{array} \]
(FPCore (x) :precision binary64 (/ (- (cos x) 1.0) (acos (cos x))))
(FPCore (x)
 :precision binary64
 (if (<= x -5e-311)
   (/ (* -0.5 (* x x)) (fabs (remainder x (* 2.0 PI))))
   (+ (* x -0.5) (* 0.041666666666666664 (pow x 3.0)))))
double code(double x) {
	return (cos(x) - 1.0) / acos(cos(x));
}
double code(double x) {
	double tmp;
	if (x <= -5e-311) {
		tmp = (-0.5 * (x * x)) / fabs(remainder(x, (2.0 * ((double) M_PI))));
	} else {
		tmp = (x * -0.5) + (0.041666666666666664 * pow(x, 3.0));
	}
	return tmp;
}
public static double code(double x) {
	return (Math.cos(x) - 1.0) / Math.acos(Math.cos(x));
}
public static double code(double x) {
	double tmp;
	if (x <= -5e-311) {
		tmp = (-0.5 * (x * x)) / Math.abs(Math.IEEEremainder(x, (2.0 * Math.PI)));
	} else {
		tmp = (x * -0.5) + (0.041666666666666664 * Math.pow(x, 3.0));
	}
	return tmp;
}
def code(x):
	return (math.cos(x) - 1.0) / math.acos(math.cos(x))
def code(x):
	tmp = 0
	if x <= -5e-311:
		tmp = (-0.5 * (x * x)) / math.fabs(math.remainder(x, (2.0 * math.pi)))
	else:
		tmp = (x * -0.5) + (0.041666666666666664 * math.pow(x, 3.0))
	return tmp
code[x_] := N[(N[(N[Cos[x], $MachinePrecision] - 1.0), $MachinePrecision] / N[ArcCos[N[Cos[x], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[x_] := If[LessEqual[x, -5e-311], N[(N[(-0.5 * N[(x * x), $MachinePrecision]), $MachinePrecision] / N[Abs[N[With[{TMP1 = x, TMP2 = N[(2.0 * Pi), $MachinePrecision]}, TMP1 - Round[TMP1 / TMP2] * TMP2], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(x * -0.5), $MachinePrecision] + N[(0.041666666666666664 * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{\cos x - 1}{\cos^{-1} \cos x}
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-311}:\\
\;\;\;\;\frac{-0.5 \cdot \left(x \cdot x\right)}{\left|\left(x \mathsf{rem} \left(2 \cdot \pi\right)\right)\right|}\\

\mathbf{else}:\\
\;\;\;\;x \cdot -0.5 + 0.041666666666666664 \cdot {x}^{3}\\


\end{array}

Error?

Derivation?

  1. Split input into 2 regimes
  2. if x < -5.00000000000023e-311

    1. Initial program 63.0

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

      \[\leadsto \frac{\color{blue}{-0.5 \cdot {x}^{2}}}{\cos^{-1} \cos x} \]
    3. Simplified63.3

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

      [Start]63.3

      \[ \frac{-0.5 \cdot {x}^{2}}{\cos^{-1} \cos x} \]

      unpow2 [=>]63.3

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

      \[\leadsto \frac{-0.5 \cdot \left(x \cdot x\right)}{\color{blue}{\left|\left(x \mathsf{rem} \left(2 \cdot \pi\right)\right)\right|}} \]

    if -5.00000000000023e-311 < x

    1. Initial program 63.1

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

      \[\leadsto \color{blue}{-0.5 \cdot x + 0.041666666666666664 \cdot {x}^{3}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification14.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-311}:\\ \;\;\;\;\frac{-0.5 \cdot \left(x \cdot x\right)}{\left|\left(x \mathsf{rem} \left(2 \cdot \pi\right)\right)\right|}\\ \mathbf{else}:\\ \;\;\;\;x \cdot -0.5 + 0.041666666666666664 \cdot {x}^{3}\\ \end{array} \]

Alternatives

Alternative 1
Error15.2
Cost7108
\[\begin{array}{l} \mathbf{if}\;x \leq -1.6 \cdot 10^{-162}:\\ \;\;\;\;\frac{-0.5 \cdot \left(x \cdot x\right)}{\sqrt{x \cdot x}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot -0.5 + 0.041666666666666664 \cdot {x}^{3}\\ \end{array} \]
Alternative 2
Error31.2
Cost6912
\[x \cdot -0.5 + 0.041666666666666664 \cdot {x}^{3} \]
Alternative 3
Error31.4
Cost192
\[x \cdot -0.5 \]

Error

Reproduce?

herbie shell --seed 1 
(FPCore (x)
  :name "(cos(x) - 1)/acos(cos(x))"
  :precision binary64
  :pre (and (<= -1.0 x) (<= x 1.0))
  (/ (- (cos x) 1.0) (acos (cos x))))