Average Error: 31.9 → 0.3
Time: 13.0s
Precision: binary64
Cost: 13640
\[\frac{1 - \cos x}{x \cdot x} \]
\[\begin{array}{l} t_0 := \frac{\frac{\sin x \cdot \tan \left(x \cdot 0.5\right)}{x}}{x}\\ \mathbf{if}\;x \leq -977.7648518297204:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.004206908263075869:\\ \;\;\;\;\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))) x) x)))
   (if (<= x -977.7648518297204)
     t_0
     (if (<= x 0.004206908263075869)
       (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))) / x) / x;
	double tmp;
	if (x <= -977.7648518297204) {
		tmp = t_0;
	} else if (x <= 0.004206908263075869) {
		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(Float64(Float64(sin(x) * tan(Float64(x * 0.5))) / x) / x)
	tmp = 0.0
	if (x <= -977.7648518297204)
		tmp = t_0;
	elseif (x <= 0.004206908263075869)
		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[(N[(N[Sin[x], $MachinePrecision] * N[Tan[N[(x * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] / x), $MachinePrecision]}, If[LessEqual[x, -977.7648518297204], t$95$0, If[LessEqual[x, 0.004206908263075869], 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 := \frac{\frac{\sin x \cdot \tan \left(x \cdot 0.5\right)}{x}}{x}\\
\mathbf{if}\;x \leq -977.7648518297204:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 0.004206908263075869:\\
\;\;\;\;\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 < -977.764851829720442 or 0.0042069082630758689 < x

    1. Initial program 1.0

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

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

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

      \[\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))): 23 points increase in error, 5 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
      (*.f64 (sin.f64 x) (Rewrite<= associate-/r*_binary64 (/.f64 (sin.f64 x) (*.f64 (+.f64 (cos.f64 x) 1) (pow.f64 x 2))))): 10 points increase in error, 10 points decrease in error
      (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 (sin.f64 x) (sin.f64 x)) (*.f64 (+.f64 (cos.f64 x) 1) (pow.f64 x 2)))): 19 points increase in error, 23 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) (Rewrite=> *-commutative_binary64 (*.f64 (pow.f64 x 2) (+.f64 (cos.f64 x) 1)))): 0 points increase in error, 0 points decrease in error
      (/.f64 (pow.f64 (sin.f64 x) 2) (*.f64 (pow.f64 x 2) (Rewrite=> +-commutative_binary64 (+.f64 1 (cos.f64 x))))): 0 points increase in error, 0 points decrease in error
      (/.f64 (pow.f64 (sin.f64 x) 2) (Rewrite<= *-commutative_binary64 (*.f64 (+.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}} \]

    if -977.764851829720442 < x < 0.0042069082630758689

    1. Initial program 61.8

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

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

      \[\leadsto \frac{\color{blue}{\tan \left(\frac{x}{2}\right) \cdot \sin x}}{x \cdot x} \]
    4. Taylor expanded in x around 0 0.4

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

      \[\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, 1 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, 0 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): 2 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): 6 points increase in error, 6 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): 9 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.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -977.7648518297204:\\ \;\;\;\;\frac{\frac{\sin x \cdot \tan \left(x \cdot 0.5\right)}{x}}{x}\\ \mathbf{elif}\;x \leq 0.004206908263075869:\\ \;\;\;\;\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, 0.001388888888888889, -0.041666666666666664\right), 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\sin x \cdot \tan \left(x \cdot 0.5\right)}{x}}{x}\\ \end{array} \]

Alternatives

Alternative 1
Error0.3
Cost13640
\[\begin{array}{l} t_0 := \frac{\frac{\sin x \cdot \tan \left(x \cdot 0.5\right)}{x}}{x}\\ \mathbf{if}\;x \leq -977.7648518297204:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.004206908263075869:\\ \;\;\;\;\frac{\frac{1}{x}}{0.008333333333333333 \cdot {x}^{3} + \left(x \cdot 0.16666666666666666 + \frac{1}{x} \cdot 2\right)}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error0.4
Cost13376
\[\frac{\sin x}{\frac{x}{\frac{\tan \left(x \cdot 0.5\right)}{x}}} \]
Alternative 3
Error0.5
Cost7816
\[\begin{array}{l} t_0 := 1 - \cos x\\ \mathbf{if}\;x \leq -977.7648518297204:\\ \;\;\;\;\frac{1}{x} \cdot \frac{t_0}{x}\\ \mathbf{elif}\;x \leq 0.004206908263075869:\\ \;\;\;\;\frac{\frac{1}{x}}{0.008333333333333333 \cdot {x}^{3} + \left(x \cdot 0.16666666666666666 + \frac{1}{x} \cdot 2\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{x} \cdot \frac{1}{\frac{-x}{t_0}}\\ \end{array} \]
Alternative 4
Error0.5
Cost7432
\[\begin{array}{l} t_0 := 1 - \cos x\\ \mathbf{if}\;x \leq -977.7648518297204:\\ \;\;\;\;\frac{1}{x} \cdot \frac{t_0}{x}\\ \mathbf{elif}\;x \leq 0.004206908263075869:\\ \;\;\;\;0.5 + \left(x \cdot x\right) \cdot -0.041666666666666664\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{x} \cdot \frac{1}{\frac{-x}{t_0}}\\ \end{array} \]
Alternative 5
Error0.5
Cost7240
\[\begin{array}{l} t_0 := \frac{\frac{1}{x}}{\frac{x}{1 - \cos x}}\\ \mathbf{if}\;x \leq -977.7648518297204:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.004206908263075869:\\ \;\;\;\;0.5 + \left(x \cdot x\right) \cdot -0.041666666666666664\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error0.5
Cost7240
\[\begin{array}{l} t_0 := 1 - \cos x\\ \mathbf{if}\;x \leq -977.7648518297204:\\ \;\;\;\;\frac{1}{x} \cdot \frac{t_0}{x}\\ \mathbf{elif}\;x \leq 0.004206908263075869:\\ \;\;\;\;0.5 + \left(x \cdot x\right) \cdot -0.041666666666666664\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x}}{\frac{x}{t_0}}\\ \end{array} \]
Alternative 7
Error0.5
Cost7112
\[\begin{array}{l} t_0 := \frac{\frac{1 - \cos x}{x}}{x}\\ \mathbf{if}\;x \leq -977.7648518297204:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.004206908263075869:\\ \;\;\;\;0.5 + \left(x \cdot x\right) \cdot -0.041666666666666664\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error13.9
Cost832
\[\frac{\frac{1}{x}}{x \cdot 0.16666666666666666 + \frac{1}{x} \cdot 2} \]
Alternative 9
Error15.6
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -977.7648518297204:\\ \;\;\;\;0\\ \mathbf{elif}\;x \leq 0.004206908263075869:\\ \;\;\;\;0.5 + \left(x \cdot x\right) \cdot -0.041666666666666664\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
Alternative 10
Error15.5
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -2.21145803279371 \cdot 10^{+81}:\\ \;\;\;\;0\\ \mathbf{elif}\;x \leq 7.094759442564294 \cdot 10^{+76}:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
Alternative 11
Error30.5
Cost64
\[0.5 \]

Error

Reproduce

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