?

Average Error: 47.57% → 0.48%
Time: 39.1s
Precision: binary64

?

\[-1 \leq x \land x \leq 1\]
\[\frac{x - \sin x}{\tan x} \]
\[\begin{array}{l} t_0 := \left(0.16666666666666666 \cdot x\right) \cdot x\\ t_1 := \mathsf{fma}\left(-0.00023644179894179894, {x}^{8}, \mathsf{fma}\left(-0.0007275132275132275, {x}^{6}, {x}^{4} \cdot -0.06388888888888888\right)\right)\\ \mathbf{if}\;t_0 \ne 0:\\ \;\;\;\;t_0 \cdot \left(1 + \frac{t_1}{t_0}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(0.16666666666666666, {x}^{2}, t_1\right)\\ \end{array} \]
(FPCore (x) :precision binary64 (/ (- x (sin x)) (tan x)))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (* (* 0.16666666666666666 x) x))
        (t_1
         (fma
          -0.00023644179894179894
          (pow x 8.0)
          (fma
           -0.0007275132275132275
           (pow x 6.0)
           (* (pow x 4.0) -0.06388888888888888)))))
   (if (!= t_0 0.0)
     (* t_0 (+ 1.0 (/ t_1 t_0)))
     (fma 0.16666666666666666 (pow x 2.0) t_1))))
double code(double x) {
	return (x - sin(x)) / tan(x);
}
double code(double x) {
	double t_0 = (0.16666666666666666 * x) * x;
	double t_1 = fma(-0.00023644179894179894, pow(x, 8.0), fma(-0.0007275132275132275, pow(x, 6.0), (pow(x, 4.0) * -0.06388888888888888)));
	double tmp;
	if (t_0 != 0.0) {
		tmp = t_0 * (1.0 + (t_1 / t_0));
	} else {
		tmp = fma(0.16666666666666666, pow(x, 2.0), t_1);
	}
	return tmp;
}
function code(x)
	return Float64(Float64(x - sin(x)) / tan(x))
end
function code(x)
	t_0 = Float64(Float64(0.16666666666666666 * x) * x)
	t_1 = fma(-0.00023644179894179894, (x ^ 8.0), fma(-0.0007275132275132275, (x ^ 6.0), Float64((x ^ 4.0) * -0.06388888888888888)))
	tmp = 0.0
	if (t_0 != 0.0)
		tmp = Float64(t_0 * Float64(1.0 + Float64(t_1 / t_0)));
	else
		tmp = fma(0.16666666666666666, (x ^ 2.0), t_1);
	end
	return tmp
end
code[x_] := N[(N[(x - N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[Tan[x], $MachinePrecision]), $MachinePrecision]
code[x_] := Block[{t$95$0 = N[(N[(0.16666666666666666 * x), $MachinePrecision] * x), $MachinePrecision]}, Block[{t$95$1 = N[(-0.00023644179894179894 * N[Power[x, 8.0], $MachinePrecision] + N[(-0.0007275132275132275 * N[Power[x, 6.0], $MachinePrecision] + N[(N[Power[x, 4.0], $MachinePrecision] * -0.06388888888888888), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Unequal[t$95$0, 0.0], N[(t$95$0 * N[(1.0 + N[(t$95$1 / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.16666666666666666 * N[Power[x, 2.0], $MachinePrecision] + t$95$1), $MachinePrecision]]]]
\frac{x - \sin x}{\tan x}
\begin{array}{l}
t_0 := \left(0.16666666666666666 \cdot x\right) \cdot x\\
t_1 := \mathsf{fma}\left(-0.00023644179894179894, {x}^{8}, \mathsf{fma}\left(-0.0007275132275132275, {x}^{6}, {x}^{4} \cdot -0.06388888888888888\right)\right)\\
\mathbf{if}\;t_0 \ne 0:\\
\;\;\;\;t_0 \cdot \left(1 + \frac{t_1}{t_0}\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.16666666666666666, {x}^{2}, t_1\right)\\


\end{array}

Error?

Target

Original47.57%
Target1.39%
Herbie0.48%
\[0.16666666666666666 \cdot \left(x \cdot x\right) \]

Derivation?

  1. Initial program 47.57

    \[\frac{x - \sin x}{\tan x} \]
  2. Taylor expanded in x around 0 0.51

    \[\leadsto \color{blue}{0.16666666666666666 \cdot {x}^{2} + \left(-0.00023644179894179894 \cdot {x}^{8} + \left(-0.0007275132275132275 \cdot {x}^{6} + -0.06388888888888888 \cdot {x}^{4}\right)\right)} \]
  3. Simplified0.51

    \[\leadsto \color{blue}{\mathsf{fma}\left(0.16666666666666666, {x}^{2}, \mathsf{fma}\left(-0.00023644179894179894, {x}^{8}, \mathsf{fma}\left(-0.0007275132275132275, {x}^{6}, -0.06388888888888888 \cdot {x}^{4}\right)\right)\right)} \]
    Proof
  4. Applied egg-rr0.48

    \[\leadsto \color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;\left(0.16666666666666666 \cdot x\right) \cdot x \ne 0:\\ \;\;\;\;\left(\left(0.16666666666666666 \cdot x\right) \cdot x\right) \cdot \left(1 + \frac{\mathsf{fma}\left(-0.00023644179894179894, {x}^{8}, \mathsf{fma}\left(-0.0007275132275132275, {x}^{6}, {x}^{4} \cdot -0.06388888888888888\right)\right)}{\left(0.16666666666666666 \cdot x\right) \cdot x}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(0.16666666666666666, {x}^{2}, \mathsf{fma}\left(-0.00023644179894179894, {x}^{8}, \mathsf{fma}\left(-0.0007275132275132275, {x}^{6}, {x}^{4} \cdot -0.06388888888888888\right)\right)\right)\\ } \end{array}} \]

Reproduce?

herbie shell --seed 2023136 
(FPCore (x)
  :name "ENA, Section 1.4, Exercise 4a"
  :precision binary64
  :pre (and (<= -1.0 x) (<= x 1.0))

  :herbie-target
  (* 0.16666666666666666 (* x x))

  (/ (- x (sin x)) (tan x)))