Average Error: 29.7 → 0.4
Time: 12.7s
Precision: binary64
\[-1 \leq x \land x \leq 1\]
\[\frac{x - \sin x}{\tan x} \]
\[x \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot -0.06388888888888888, 0.16666666666666666\right)\right) \]
(FPCore (x) :precision binary64 (/ (- x (sin x)) (tan x)))
(FPCore (x)
 :precision binary64
 (* x (* x (fma x (* x -0.06388888888888888) 0.16666666666666666))))
double code(double x) {
	return (x - sin(x)) / tan(x);
}
double code(double x) {
	return x * (x * fma(x, (x * -0.06388888888888888), 0.16666666666666666));
}
function code(x)
	return Float64(Float64(x - sin(x)) / tan(x))
end
function code(x)
	return Float64(x * Float64(x * fma(x, Float64(x * -0.06388888888888888), 0.16666666666666666)))
end
code[x_] := N[(N[(x - N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[Tan[x], $MachinePrecision]), $MachinePrecision]
code[x_] := N[(x * N[(x * N[(x * N[(x * -0.06388888888888888), $MachinePrecision] + 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{x - \sin x}{\tan x}
x \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot -0.06388888888888888, 0.16666666666666666\right)\right)

Error

Bits error versus x

Target

Original29.7
Target0.9
Herbie0.4
\[0.16666666666666666 \cdot \left(x \cdot x\right) \]

Derivation

  1. Initial program 29.7

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

    \[\leadsto \color{blue}{0.16666666666666666 \cdot {x}^{2} - 0.06388888888888888 \cdot {x}^{4}} \]
  3. Applied egg-rr0.5

    \[\leadsto \color{blue}{{\left(x \cdot \sqrt{0.16666666666666666}\right)}^{2}} - 0.06388888888888888 \cdot {x}^{4} \]
  4. Taylor expanded in x around 0 0.4

    \[\leadsto \color{blue}{{\left(\sqrt{0.16666666666666666}\right)}^{2} \cdot {x}^{2} - 0.06388888888888888 \cdot {x}^{4}} \]
  5. Simplified0.4

    \[\leadsto \color{blue}{x \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot -0.06388888888888888, 0.16666666666666666\right)\right)} \]
  6. Final simplification0.4

    \[\leadsto x \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot -0.06388888888888888, 0.16666666666666666\right)\right) \]

Reproduce

herbie shell --seed 2022166 
(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)))