Average Error: 30.2 → 0.3
Time: 23.8s
Precision: binary64
Cost: 26688
\[-1 \leq x \land x \leq 1\]
\[\frac{x - \sin x}{\tan x} \]
\[\mathsf{fma}\left(-0.0007275132275132275, {x}^{6}, \mathsf{fma}\left(x \cdot x, \left(x \cdot x\right) \cdot -0.06388888888888888 + 0.16666666666666666, -0.00023644179894179894 \cdot {x}^{8}\right)\right) \]
(FPCore (x) :precision binary64 (/ (- x (sin x)) (tan x)))
(FPCore (x)
 :precision binary64
 (fma
  -0.0007275132275132275
  (pow x 6.0)
  (fma
   (* x x)
   (+ (* (* x x) -0.06388888888888888) 0.16666666666666666)
   (* -0.00023644179894179894 (pow x 8.0)))))
double code(double x) {
	return (x - sin(x)) / tan(x);
}
double code(double x) {
	return fma(-0.0007275132275132275, pow(x, 6.0), fma((x * x), (((x * x) * -0.06388888888888888) + 0.16666666666666666), (-0.00023644179894179894 * pow(x, 8.0))));
}
function code(x)
	return Float64(Float64(x - sin(x)) / tan(x))
end
function code(x)
	return fma(-0.0007275132275132275, (x ^ 6.0), fma(Float64(x * x), Float64(Float64(Float64(x * x) * -0.06388888888888888) + 0.16666666666666666), Float64(-0.00023644179894179894 * (x ^ 8.0))))
end
code[x_] := N[(N[(x - N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[Tan[x], $MachinePrecision]), $MachinePrecision]
code[x_] := N[(-0.0007275132275132275 * N[Power[x, 6.0], $MachinePrecision] + N[(N[(x * x), $MachinePrecision] * N[(N[(N[(x * x), $MachinePrecision] * -0.06388888888888888), $MachinePrecision] + 0.16666666666666666), $MachinePrecision] + N[(-0.00023644179894179894 * N[Power[x, 8.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{x - \sin x}{\tan x}
\mathsf{fma}\left(-0.0007275132275132275, {x}^{6}, \mathsf{fma}\left(x \cdot x, \left(x \cdot x\right) \cdot -0.06388888888888888 + 0.16666666666666666, -0.00023644179894179894 \cdot {x}^{8}\right)\right)

Error

Target

Original30.2
Target0.8
Herbie0.3
\[0.16666666666666666 \cdot \left(x \cdot x\right) \]

Derivation

  1. Initial program 30.2

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

    \[\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.3

    \[\leadsto \color{blue}{\mathsf{fma}\left(-0.0007275132275132275, {x}^{6}, \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, -0.06388888888888888, 0.16666666666666666\right), -0.00023644179894179894 \cdot {x}^{8}\right)\right)} \]
    Proof
    (fma.f64 -11/15120 (pow.f64 x 6) (fma.f64 (*.f64 x x) (fma.f64 (*.f64 x x) -23/360 1/6) (*.f64 -143/604800 (pow.f64 x 8)))): 0 points increase in error, 0 points decrease in error
    (fma.f64 -11/15120 (pow.f64 x 6) (fma.f64 (Rewrite<= unpow2_binary64 (pow.f64 x 2)) (fma.f64 (*.f64 x x) -23/360 1/6) (*.f64 -143/604800 (pow.f64 x 8)))): 0 points increase in error, 0 points decrease in error
    (fma.f64 -11/15120 (pow.f64 x 6) (fma.f64 (pow.f64 x 2) (fma.f64 (Rewrite<= unpow2_binary64 (pow.f64 x 2)) -23/360 1/6) (*.f64 -143/604800 (pow.f64 x 8)))): 0 points increase in error, 0 points decrease in error
    (fma.f64 -11/15120 (pow.f64 x 6) (fma.f64 (pow.f64 x 2) (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (pow.f64 x 2) -23/360) 1/6)) (*.f64 -143/604800 (pow.f64 x 8)))): 0 points increase in error, 0 points decrease in error
    (fma.f64 -11/15120 (pow.f64 x 6) (fma.f64 (pow.f64 x 2) (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 -23/360 (pow.f64 x 2))) 1/6) (*.f64 -143/604800 (pow.f64 x 8)))): 0 points increase in error, 0 points decrease in error
    (fma.f64 -11/15120 (pow.f64 x 6) (fma.f64 (pow.f64 x 2) (Rewrite<= +-commutative_binary64 (+.f64 1/6 (*.f64 -23/360 (pow.f64 x 2)))) (*.f64 -143/604800 (pow.f64 x 8)))): 0 points increase in error, 0 points decrease in error
    (fma.f64 -11/15120 (pow.f64 x 6) (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (pow.f64 x 2) (+.f64 1/6 (*.f64 -23/360 (pow.f64 x 2)))) (*.f64 -143/604800 (pow.f64 x 8))))): 1 points increase in error, 0 points decrease in error
    (fma.f64 -11/15120 (pow.f64 x 6) (+.f64 (Rewrite<= distribute-rgt-out_binary64 (+.f64 (*.f64 1/6 (pow.f64 x 2)) (*.f64 (*.f64 -23/360 (pow.f64 x 2)) (pow.f64 x 2)))) (*.f64 -143/604800 (pow.f64 x 8)))): 4 points increase in error, 0 points decrease in error
    (fma.f64 -11/15120 (pow.f64 x 6) (+.f64 (+.f64 (*.f64 1/6 (pow.f64 x 2)) (Rewrite<= associate-*r*_binary64 (*.f64 -23/360 (*.f64 (pow.f64 x 2) (pow.f64 x 2))))) (*.f64 -143/604800 (pow.f64 x 8)))): 0 points increase in error, 0 points decrease in error
    (fma.f64 -11/15120 (pow.f64 x 6) (+.f64 (+.f64 (*.f64 1/6 (pow.f64 x 2)) (*.f64 -23/360 (Rewrite=> pow-sqr_binary64 (pow.f64 x (*.f64 2 2))))) (*.f64 -143/604800 (pow.f64 x 8)))): 0 points increase in error, 0 points decrease in error
    (fma.f64 -11/15120 (pow.f64 x 6) (+.f64 (+.f64 (*.f64 1/6 (pow.f64 x 2)) (*.f64 -23/360 (pow.f64 x (Rewrite=> metadata-eval 4)))) (*.f64 -143/604800 (pow.f64 x 8)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 -11/15120 (pow.f64 x 6)) (+.f64 (+.f64 (*.f64 1/6 (pow.f64 x 2)) (*.f64 -23/360 (pow.f64 x 4))) (*.f64 -143/604800 (pow.f64 x 8))))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (*.f64 -11/15120 (pow.f64 x 6)) (+.f64 (*.f64 1/6 (pow.f64 x 2)) (*.f64 -23/360 (pow.f64 x 4)))) (*.f64 -143/604800 (pow.f64 x 8)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (*.f64 -11/15120 (pow.f64 x 6)) (Rewrite=> +-commutative_binary64 (+.f64 (*.f64 -23/360 (pow.f64 x 4)) (*.f64 1/6 (pow.f64 x 2))))) (*.f64 -143/604800 (pow.f64 x 8))): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (*.f64 -11/15120 (pow.f64 x 6)) (*.f64 -23/360 (pow.f64 x 4))) (*.f64 1/6 (pow.f64 x 2)))) (*.f64 -143/604800 (pow.f64 x 8))): 0 points increase in error, 3 points decrease in error
    (Rewrite=> associate-+l+_binary64 (+.f64 (+.f64 (*.f64 -11/15120 (pow.f64 x 6)) (*.f64 -23/360 (pow.f64 x 4))) (+.f64 (*.f64 1/6 (pow.f64 x 2)) (*.f64 -143/604800 (pow.f64 x 8))))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 (+.f64 (*.f64 1/6 (pow.f64 x 2)) (*.f64 -143/604800 (pow.f64 x 8))) (+.f64 (*.f64 -11/15120 (pow.f64 x 6)) (*.f64 -23/360 (pow.f64 x 4))))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-+r+_binary64 (+.f64 (*.f64 1/6 (pow.f64 x 2)) (+.f64 (*.f64 -143/604800 (pow.f64 x 8)) (+.f64 (*.f64 -11/15120 (pow.f64 x 6)) (*.f64 -23/360 (pow.f64 x 4)))))): 0 points increase in error, 0 points decrease in error
  4. Applied egg-rr0.3

    \[\leadsto \mathsf{fma}\left(-0.0007275132275132275, {x}^{6}, \mathsf{fma}\left(x \cdot x, \color{blue}{\left(x \cdot x\right) \cdot -0.06388888888888888 + 0.16666666666666666}, -0.00023644179894179894 \cdot {x}^{8}\right)\right) \]
  5. Final simplification0.3

    \[\leadsto \mathsf{fma}\left(-0.0007275132275132275, {x}^{6}, \mathsf{fma}\left(x \cdot x, \left(x \cdot x\right) \cdot -0.06388888888888888 + 0.16666666666666666, -0.00023644179894179894 \cdot {x}^{8}\right)\right) \]

Alternatives

Alternative 1
Error0.3
Cost13696
\[\mathsf{fma}\left(x \cdot x, \left(x \cdot x\right) \cdot -0.06388888888888888 + 0.16666666666666666, -0.0007275132275132275 \cdot {x}^{6}\right) \]
Alternative 2
Error0.4
Cost704
\[x \cdot \left(x \cdot \left(\left(x \cdot x\right) \cdot -0.06388888888888888 + 0.16666666666666666\right)\right) \]
Alternative 3
Error0.8
Cost320
\[x \cdot \left(x \cdot 0.16666666666666666\right) \]

Error

Reproduce

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