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

Error

Target

Original30.6
Target0.7
Herbie0.4
\[0.16666666666666666 \cdot \left(x \cdot x\right) \]

Derivation

  1. Initial program 30.6

    \[\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. Simplified0.4

    \[\leadsto \color{blue}{\mathsf{fma}\left(-0.06388888888888888, {x}^{4}, x \cdot \left(x \cdot 0.16666666666666666\right)\right)} \]
    Proof
    (fma.f64 -23/360 (pow.f64 x 4) (*.f64 x (*.f64 x 1/6))): 0 points increase in error, 0 points decrease in error
    (fma.f64 -23/360 (pow.f64 x 4) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 x x) 1/6))): 28 points increase in error, 20 points decrease in error
    (fma.f64 -23/360 (pow.f64 x 4) (Rewrite<= *-commutative_binary64 (*.f64 1/6 (*.f64 x x)))): 0 points increase in error, 0 points decrease in error
    (fma.f64 -23/360 (pow.f64 x 4) (*.f64 1/6 (Rewrite<= unpow2_binary64 (pow.f64 x 2)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 -23/360 (pow.f64 x 4)) (*.f64 1/6 (pow.f64 x 2)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 1/6 (pow.f64 x 2)) (*.f64 -23/360 (pow.f64 x 4)))): 0 points increase in error, 0 points decrease in error
  4. Applied egg-rr0.4

    \[\leadsto \color{blue}{x \cdot \left(x \cdot 0.16666666666666666\right) + -0.06388888888888888 \cdot {x}^{4}} \]
  5. Applied egg-rr0.4

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

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

Alternatives

Alternative 1
Error0.4
Cost7040
\[-0.06388888888888888 \cdot {x}^{4} + x \cdot \left(x \cdot 0.16666666666666666\right) \]
Alternative 2
Error0.4
Cost6976
\[x \cdot \left(x \cdot \mathsf{fma}\left(-0.06388888888888888, x \cdot x, 0.16666666666666666\right)\right) \]
Alternative 3
Error0.4
Cost704
\[\left(x \cdot x\right) \cdot \left(0.16666666666666666 + x \cdot \left(x \cdot -0.06388888888888888\right)\right) \]
Alternative 4
Error0.7
Cost320
\[0.16666666666666666 \cdot \left(x \cdot x\right) \]
Alternative 5
Error0.7
Cost320
\[x \cdot \left(x \cdot 0.16666666666666666\right) \]

Error

Reproduce

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