Average Error: 31.2 → 0.1
Time: 11.8s
Precision: binary64
Cost: 19976
\[\frac{1 - \cos x}{x \cdot x} \]
\[\begin{array}{l} t_0 := \sin x \cdot \left(\tan \left(x \cdot 0.5\right) \cdot {x}^{-2}\right)\\ \mathbf{if}\;x \leq -0.030539271847426327:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 2.479060632992062 \cdot 10^{-23}:\\ \;\;\;\;\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, 0.001388888888888889, -0.041666666666666664\right), 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
(FPCore (x) :precision binary64 (/ (- 1.0 (cos x)) (* x x)))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (* (sin x) (* (tan (* x 0.5)) (pow x -2.0)))))
   (if (<= x -0.030539271847426327)
     t_0
     (if (<= x 2.479060632992062e-23)
       (fma
        (* x x)
        (fma (* x x) 0.001388888888888889 -0.041666666666666664)
        0.5)
       t_0))))
double code(double x) {
	return (1.0 - cos(x)) / (x * x);
}
double code(double x) {
	double t_0 = sin(x) * (tan((x * 0.5)) * pow(x, -2.0));
	double tmp;
	if (x <= -0.030539271847426327) {
		tmp = t_0;
	} else if (x <= 2.479060632992062e-23) {
		tmp = fma((x * x), fma((x * x), 0.001388888888888889, -0.041666666666666664), 0.5);
	} 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(sin(x) * Float64(tan(Float64(x * 0.5)) * (x ^ -2.0)))
	tmp = 0.0
	if (x <= -0.030539271847426327)
		tmp = t_0;
	elseif (x <= 2.479060632992062e-23)
		tmp = fma(Float64(x * x), fma(Float64(x * x), 0.001388888888888889, -0.041666666666666664), 0.5);
	else
		tmp = t_0;
	end
	return 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[Sin[x], $MachinePrecision] * N[(N[Tan[N[(x * 0.5), $MachinePrecision]], $MachinePrecision] * N[Power[x, -2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -0.030539271847426327], t$95$0, If[LessEqual[x, 2.479060632992062e-23], N[(N[(x * x), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * 0.001388888888888889 + -0.041666666666666664), $MachinePrecision] + 0.5), $MachinePrecision], t$95$0]]]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
t_0 := \sin x \cdot \left(\tan \left(x \cdot 0.5\right) \cdot {x}^{-2}\right)\\
\mathbf{if}\;x \leq -0.030539271847426327:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 2.479060632992062 \cdot 10^{-23}:\\
\;\;\;\;\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, 0.001388888888888889, -0.041666666666666664\right), 0.5\right)\\

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


\end{array}

Error

Derivation

  1. Split input into 2 regimes
  2. if x < -0.0305392718474263268 or 2.479060632992062e-23 < x

    1. Initial program 2.4

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

      \[\leadsto \frac{\color{blue}{\frac{\sin x \cdot \sin x}{1 + \cos x}}}{x \cdot x} \]
    3. Applied egg-rr0.7

      \[\leadsto \frac{\color{blue}{\tan \left(\frac{x}{2}\right) \cdot \sin x}}{x \cdot x} \]
    4. Applied egg-rr0.3

      \[\leadsto \color{blue}{\sin x \cdot \left(\tan \left(x \cdot 0.5\right) \cdot {x}^{-2}\right)} \]

    if -0.0305392718474263268 < x < 2.479060632992062e-23

    1. Initial program 62.7

      \[\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}{\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, 0.001388888888888889, -0.041666666666666664\right), 0.5\right)} \]
      Proof
      (fma.f64 (*.f64 x x) (fma.f64 (*.f64 x x) 1/720 -1/24) 1/2): 0 points increase in error, 0 points decrease in error
      (fma.f64 (Rewrite<= unpow2_binary64 (pow.f64 x 2)) (fma.f64 (*.f64 x x) 1/720 -1/24) 1/2): 0 points increase in error, 0 points decrease in error
      (fma.f64 (pow.f64 x 2) (fma.f64 (Rewrite<= unpow2_binary64 (pow.f64 x 2)) 1/720 -1/24) 1/2): 0 points increase in error, 0 points decrease in error
      (fma.f64 (pow.f64 x 2) (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (pow.f64 x 2) 1/720) -1/24)) 1/2): 0 points increase in error, 0 points decrease in error
      (fma.f64 (pow.f64 x 2) (Rewrite=> +-commutative_binary64 (+.f64 -1/24 (*.f64 (pow.f64 x 2) 1/720))) 1/2): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (pow.f64 x 2) (+.f64 -1/24 (*.f64 (pow.f64 x 2) 1/720))) 1/2)): 0 points increase in error, 1 points decrease in error
      (+.f64 (*.f64 (pow.f64 x 2) (+.f64 -1/24 (Rewrite=> *-commutative_binary64 (*.f64 1/720 (pow.f64 x 2))))) 1/2): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= distribute-rgt-out_binary64 (+.f64 (*.f64 -1/24 (pow.f64 x 2)) (*.f64 (*.f64 1/720 (pow.f64 x 2)) (pow.f64 x 2)))) 1/2): 1 points increase in error, 0 points decrease in error
      (+.f64 (+.f64 (*.f64 -1/24 (pow.f64 x 2)) (Rewrite<= associate-*r*_binary64 (*.f64 1/720 (*.f64 (pow.f64 x 2) (pow.f64 x 2))))) 1/2): 9 points increase in error, 3 points decrease in error
      (+.f64 (+.f64 (*.f64 -1/24 (pow.f64 x 2)) (*.f64 1/720 (Rewrite=> pow-sqr_binary64 (pow.f64 x (*.f64 2 2))))) 1/2): 5 points increase in error, 6 points decrease in error
      (+.f64 (+.f64 (*.f64 -1/24 (pow.f64 x 2)) (*.f64 1/720 (pow.f64 x (Rewrite=> metadata-eval 4)))) 1/2): 0 points increase in error, 0 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 1/2 (+.f64 (*.f64 -1/24 (pow.f64 x 2)) (*.f64 1/720 (pow.f64 x 4))))): 0 points increase in error, 0 points decrease in error
  3. Recombined 2 regimes into one program.
  4. Final simplification0.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.030539271847426327:\\ \;\;\;\;\sin x \cdot \left(\tan \left(x \cdot 0.5\right) \cdot {x}^{-2}\right)\\ \mathbf{elif}\;x \leq 2.479060632992062 \cdot 10^{-23}:\\ \;\;\;\;\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, 0.001388888888888889, -0.041666666666666664\right), 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\sin x \cdot \left(\tan \left(x \cdot 0.5\right) \cdot {x}^{-2}\right)\\ \end{array} \]

Alternatives

Alternative 1
Error1.0
Cost7240
\[\begin{array}{l} t_0 := \frac{\frac{1 - \cos x}{x}}{x}\\ \mathbf{if}\;x \leq -0.030539271847426327:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 4.259081342341926 \cdot 10^{-23}:\\ \;\;\;\;\left(1 + \mathsf{fma}\left(x, x \cdot -0.041666666666666664, 0.5\right)\right) + -1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error14.9
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -97919.52281259478:\\ \;\;\;\;\frac{6}{x \cdot x}\\ \mathbf{elif}\;x \leq 4.259081342341926 \cdot 10^{-23}:\\ \;\;\;\;0.5 + x \cdot \left(x \cdot -0.041666666666666664\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x \cdot \left(x \cdot 0.16666666666666666\right)}\\ \end{array} \]
Alternative 3
Error14.0
Cost576
\[\frac{1}{\left(x \cdot x\right) \cdot 0.16666666666666666 + 2} \]
Alternative 4
Error15.7
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -7.14495020679171 \cdot 10^{+77}:\\ \;\;\;\;0\\ \mathbf{elif}\;x \leq 2.0905127883141194 \cdot 10^{+76}:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
Alternative 5
Error31.2
Cost64
\[0.5 \]

Error

Reproduce

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