Average Error: 29.5 → 0.3
Time: 21.3s
Precision: binary64
Cost: 13632
\[-1 \leq x \land x \leq 1\]
\[\frac{x - \sin x}{\tan x} \]
\[x \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, x \cdot -0.0007275132275132275, -0.06388888888888888\right), 0.16666666666666666\right)\right) \]
(FPCore (x) :precision binary64 (/ (- x (sin x)) (tan x)))
(FPCore (x)
 :precision binary64
 (*
  x
  (*
   x
   (fma
    x
    (* x (fma x (* x -0.0007275132275132275) -0.06388888888888888))
    0.16666666666666666))))
double code(double x) {
	return (x - sin(x)) / tan(x);
}
double code(double x) {
	return x * (x * fma(x, (x * fma(x, (x * -0.0007275132275132275), -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 * fma(x, Float64(x * -0.0007275132275132275), -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 * N[(x * N[(x * -0.0007275132275132275), $MachinePrecision] + -0.06388888888888888), $MachinePrecision]), $MachinePrecision] + 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{x - \sin x}{\tan x}
x \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, x \cdot -0.0007275132275132275, -0.06388888888888888\right), 0.16666666666666666\right)\right)

Error

Target

Original29.5
Target0.8
Herbie0.3
\[0.16666666666666666 \cdot \left(x \cdot x\right) \]

Derivation

  1. Initial program 29.5

    \[\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.0007275132275132275 \cdot {x}^{6} + -0.06388888888888888 \cdot {x}^{4}\right)} \]
  3. Simplified0.3

    \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, -0.06388888888888888, 0.16666666666666666\right), -0.0007275132275132275 \cdot {x}^{6}\right)} \]
    Proof
    (fma.f64 (*.f64 x x) (fma.f64 (*.f64 x x) -23/360 1/6) (*.f64 -11/15120 (pow.f64 x 6))): 0 points increase in error, 0 points decrease in error
    (fma.f64 (Rewrite<= unpow2_binary64 (pow.f64 x 2)) (fma.f64 (*.f64 x x) -23/360 1/6) (*.f64 -11/15120 (pow.f64 x 6))): 1 points increase in error, 0 points decrease in error
    (fma.f64 (pow.f64 x 2) (fma.f64 (Rewrite<= unpow2_binary64 (pow.f64 x 2)) -23/360 1/6) (*.f64 -11/15120 (pow.f64 x 6))): 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) -23/360) 1/6)) (*.f64 -11/15120 (pow.f64 x 6))): 0 points increase in error, 0 points decrease in error
    (fma.f64 (pow.f64 x 2) (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 -23/360 (pow.f64 x 2))) 1/6) (*.f64 -11/15120 (pow.f64 x 6))): 0 points increase in error, 0 points decrease in error
    (fma.f64 (pow.f64 x 2) (Rewrite<= +-commutative_binary64 (+.f64 1/6 (*.f64 -23/360 (pow.f64 x 2)))) (*.f64 -11/15120 (pow.f64 x 6))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (pow.f64 x 2) (+.f64 1/6 (*.f64 -23/360 (pow.f64 x 2)))) (*.f64 -11/15120 (pow.f64 x 6)))): 2 points increase in error, 0 points decrease in error
    (+.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 -11/15120 (pow.f64 x 6))): 1 points increase in error, 1 points decrease in error
    (+.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 -11/15120 (pow.f64 x 6))): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (*.f64 1/6 (pow.f64 x 2)) (*.f64 -23/360 (Rewrite=> pow-sqr_binary64 (pow.f64 x (*.f64 2 2))))) (*.f64 -11/15120 (pow.f64 x 6))): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (*.f64 1/6 (pow.f64 x 2)) (*.f64 -23/360 (pow.f64 x (Rewrite=> metadata-eval 4)))) (*.f64 -11/15120 (pow.f64 x 6))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-+r+_binary64 (+.f64 (*.f64 1/6 (pow.f64 x 2)) (+.f64 (*.f64 -23/360 (pow.f64 x 4)) (*.f64 -11/15120 (pow.f64 x 6))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 1/6 (pow.f64 x 2)) (Rewrite<= +-commutative_binary64 (+.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(x \cdot x, \color{blue}{x \cdot \left(x \cdot -0.06388888888888888\right) + 0.16666666666666666}, -0.0007275132275132275 \cdot {x}^{6}\right) \]
  5. Taylor expanded in x around 0 0.3

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

    \[\leadsto \color{blue}{x \cdot \left(x \cdot \mathsf{fma}\left(x, \mathsf{fma}\left(x, -0.06388888888888888, -0.0007275132275132275 \cdot {x}^{3}\right), 0.16666666666666666\right)\right)} \]
    Proof
    (*.f64 x (*.f64 x (fma.f64 x (fma.f64 x -23/360 (*.f64 -11/15120 (pow.f64 x 3))) 1/6))): 0 points increase in error, 0 points decrease in error
    (*.f64 x (*.f64 x (fma.f64 x (fma.f64 x -23/360 (*.f64 -11/15120 (pow.f64 x (Rewrite<= metadata-eval (/.f64 6 2))))) 1/6))): 0 points increase in error, 0 points decrease in error
    (*.f64 x (*.f64 x (fma.f64 x (fma.f64 x -23/360 (Rewrite<= *-commutative_binary64 (*.f64 (pow.f64 x (/.f64 6 2)) -11/15120))) 1/6))): 0 points increase in error, 0 points decrease in error
    (*.f64 x (*.f64 x (fma.f64 x (Rewrite<= fma-def_binary64 (+.f64 (*.f64 x -23/360) (*.f64 (pow.f64 x (/.f64 6 2)) -11/15120))) 1/6))): 0 points increase in error, 0 points decrease in error
    (*.f64 x (*.f64 x (fma.f64 x (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 (pow.f64 x (/.f64 6 2)) -11/15120) (*.f64 x -23/360))) 1/6))): 0 points increase in error, 0 points decrease in error
    (*.f64 x (*.f64 x (Rewrite<= fma-def_binary64 (+.f64 (*.f64 x (+.f64 (*.f64 (pow.f64 x (/.f64 6 2)) -11/15120) (*.f64 x -23/360))) 1/6)))): 0 points increase in error, 0 points decrease in error
    (*.f64 x (*.f64 x (+.f64 (*.f64 x (Rewrite=> +-commutative_binary64 (+.f64 (*.f64 x -23/360) (*.f64 (pow.f64 x (/.f64 6 2)) -11/15120)))) 1/6))): 0 points increase in error, 0 points decrease in error
    (*.f64 x (*.f64 x (+.f64 (Rewrite<= distribute-lft-out_binary64 (+.f64 (*.f64 x (*.f64 x -23/360)) (*.f64 x (*.f64 (pow.f64 x (/.f64 6 2)) -11/15120)))) 1/6))): 0 points increase in error, 0 points decrease in error
    (*.f64 x (*.f64 x (+.f64 (+.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 x x) -23/360)) (*.f64 x (*.f64 (pow.f64 x (/.f64 6 2)) -11/15120))) 1/6))): 0 points increase in error, 0 points decrease in error
    (*.f64 x (*.f64 x (+.f64 (+.f64 (*.f64 (Rewrite<= unpow2_binary64 (pow.f64 x 2)) -23/360) (*.f64 x (*.f64 (pow.f64 x (/.f64 6 2)) -11/15120))) 1/6))): 0 points increase in error, 0 points decrease in error
    (*.f64 x (*.f64 x (+.f64 (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 -23/360 (pow.f64 x 2))) (*.f64 x (*.f64 (pow.f64 x (/.f64 6 2)) -11/15120))) 1/6))): 0 points increase in error, 0 points decrease in error
    (*.f64 x (*.f64 x (Rewrite<= +-commutative_binary64 (+.f64 1/6 (+.f64 (*.f64 -23/360 (pow.f64 x 2)) (*.f64 x (*.f64 (pow.f64 x (/.f64 6 2)) -11/15120))))))): 0 points increase in error, 0 points decrease in error
    (*.f64 x (*.f64 x (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 1/6 (*.f64 -23/360 (pow.f64 x 2))) (*.f64 x (*.f64 (pow.f64 x (/.f64 6 2)) -11/15120)))))): 1 points increase in error, 1 points decrease in error
    (*.f64 x (*.f64 x (Rewrite=> associate-+l+_binary64 (+.f64 1/6 (+.f64 (*.f64 -23/360 (pow.f64 x 2)) (*.f64 x (*.f64 (pow.f64 x (/.f64 6 2)) -11/15120))))))): 1 points increase in error, 1 points decrease in error
    (*.f64 x (Rewrite<= distribute-lft-out_binary64 (+.f64 (*.f64 x 1/6) (*.f64 x (+.f64 (*.f64 -23/360 (pow.f64 x 2)) (*.f64 x (*.f64 (pow.f64 x (/.f64 6 2)) -11/15120))))))): 1 points increase in error, 1 points decrease in error
    (*.f64 x (+.f64 (*.f64 x 1/6) (Rewrite<= distribute-rgt-out_binary64 (+.f64 (*.f64 (*.f64 -23/360 (pow.f64 x 2)) x) (*.f64 (*.f64 x (*.f64 (pow.f64 x (/.f64 6 2)) -11/15120)) x))))): 0 points increase in error, 0 points decrease in error
    (*.f64 x (+.f64 (*.f64 x 1/6) (+.f64 (*.f64 (*.f64 -23/360 (pow.f64 x 2)) x) (*.f64 (Rewrite<= *-commutative_binary64 (*.f64 (*.f64 (pow.f64 x (/.f64 6 2)) -11/15120) x)) x)))): 0 points increase in error, 0 points decrease in error
    (*.f64 x (+.f64 (*.f64 x 1/6) (+.f64 (*.f64 (*.f64 -23/360 (pow.f64 x 2)) x) (Rewrite<= associate-*r*_binary64 (*.f64 (*.f64 (pow.f64 x (/.f64 6 2)) -11/15120) (*.f64 x x)))))): 0 points increase in error, 0 points decrease in error
    (*.f64 x (+.f64 (*.f64 x 1/6) (+.f64 (*.f64 (*.f64 -23/360 (pow.f64 x 2)) x) (*.f64 (Rewrite=> *-commutative_binary64 (*.f64 -11/15120 (pow.f64 x (/.f64 6 2)))) (*.f64 x x))))): 0 points increase in error, 0 points decrease in error
    (*.f64 x (+.f64 (*.f64 x 1/6) (+.f64 (*.f64 (*.f64 -23/360 (pow.f64 x 2)) x) (*.f64 (*.f64 -11/15120 (pow.f64 x (/.f64 6 2))) (Rewrite<= unpow2_binary64 (pow.f64 x 2)))))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= distribute-lft-out_binary64 (+.f64 (*.f64 x (*.f64 x 1/6)) (*.f64 x (+.f64 (*.f64 (*.f64 -23/360 (pow.f64 x 2)) x) (*.f64 (*.f64 -11/15120 (pow.f64 x (/.f64 6 2))) (pow.f64 x 2)))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 x x) 1/6)) (*.f64 x (+.f64 (*.f64 (*.f64 -23/360 (pow.f64 x 2)) x) (*.f64 (*.f64 -11/15120 (pow.f64 x (/.f64 6 2))) (pow.f64 x 2))))): 29 points increase in error, 21 points decrease in error
    (+.f64 (*.f64 (Rewrite<= unpow2_binary64 (pow.f64 x 2)) 1/6) (*.f64 x (+.f64 (*.f64 (*.f64 -23/360 (pow.f64 x 2)) x) (*.f64 (*.f64 -11/15120 (pow.f64 x (/.f64 6 2))) (pow.f64 x 2))))): 1 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 1/6 (pow.f64 x 2))) (*.f64 x (+.f64 (*.f64 (*.f64 -23/360 (pow.f64 x 2)) x) (*.f64 (*.f64 -11/15120 (pow.f64 x (/.f64 6 2))) (pow.f64 x 2))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 1/6 (pow.f64 x 2)) (Rewrite<= distribute-rgt-out_binary64 (+.f64 (*.f64 (*.f64 (*.f64 -23/360 (pow.f64 x 2)) x) x) (*.f64 (*.f64 (*.f64 -11/15120 (pow.f64 x (/.f64 6 2))) (pow.f64 x 2)) x)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 1/6 (pow.f64 x 2)) (+.f64 (Rewrite<= associate-*r*_binary64 (*.f64 (*.f64 -23/360 (pow.f64 x 2)) (*.f64 x x))) (*.f64 (*.f64 (*.f64 -11/15120 (pow.f64 x (/.f64 6 2))) (pow.f64 x 2)) x))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 1/6 (pow.f64 x 2)) (+.f64 (*.f64 (*.f64 -23/360 (pow.f64 x 2)) (Rewrite<= unpow2_binary64 (pow.f64 x 2))) (*.f64 (*.f64 (*.f64 -11/15120 (pow.f64 x (/.f64 6 2))) (pow.f64 x 2)) x))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 1/6 (pow.f64 x 2)) (+.f64 (Rewrite<= associate-*r*_binary64 (*.f64 -23/360 (*.f64 (pow.f64 x 2) (pow.f64 x 2)))) (*.f64 (*.f64 (*.f64 -11/15120 (pow.f64 x (/.f64 6 2))) (pow.f64 x 2)) x))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 1/6 (pow.f64 x 2)) (+.f64 (*.f64 -23/360 (Rewrite=> pow-sqr_binary64 (pow.f64 x (*.f64 2 2)))) (*.f64 (*.f64 (*.f64 -11/15120 (pow.f64 x (/.f64 6 2))) (pow.f64 x 2)) x))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 1/6 (pow.f64 x 2)) (+.f64 (*.f64 -23/360 (pow.f64 x (Rewrite=> metadata-eval 4))) (*.f64 (*.f64 (*.f64 -11/15120 (pow.f64 x (/.f64 6 2))) (pow.f64 x 2)) x))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 1/6 (pow.f64 x 2)) (+.f64 (*.f64 -23/360 (pow.f64 x 4)) (Rewrite<= associate-*r*_binary64 (*.f64 (*.f64 -11/15120 (pow.f64 x (/.f64 6 2))) (*.f64 (pow.f64 x 2) x))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 1/6 (pow.f64 x 2)) (+.f64 (*.f64 -23/360 (pow.f64 x 4)) (*.f64 (*.f64 -11/15120 (pow.f64 x (/.f64 6 2))) (*.f64 (Rewrite=> unpow2_binary64 (*.f64 x x)) x)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 1/6 (pow.f64 x 2)) (+.f64 (*.f64 -23/360 (pow.f64 x 4)) (*.f64 (*.f64 -11/15120 (pow.f64 x (/.f64 6 2))) (Rewrite<= unpow3_binary64 (pow.f64 x 3))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 1/6 (pow.f64 x 2)) (+.f64 (*.f64 -23/360 (pow.f64 x 4)) (*.f64 (*.f64 -11/15120 (pow.f64 x (/.f64 6 2))) (pow.f64 x (Rewrite<= metadata-eval (/.f64 6 2)))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 1/6 (pow.f64 x 2)) (+.f64 (*.f64 -23/360 (pow.f64 x 4)) (Rewrite<= associate-*r*_binary64 (*.f64 -11/15120 (*.f64 (pow.f64 x (/.f64 6 2)) (pow.f64 x (/.f64 6 2))))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 1/6 (pow.f64 x 2)) (+.f64 (*.f64 -23/360 (pow.f64 x 4)) (*.f64 -11/15120 (Rewrite<= sqr-pow_binary64 (pow.f64 x 6))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 1/6 (pow.f64 x 2)) (Rewrite<= +-commutative_binary64 (+.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
  7. Taylor expanded in x around 0 0.3

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

    \[\leadsto x \cdot \left(x \cdot \mathsf{fma}\left(x, \color{blue}{x \cdot \mathsf{fma}\left(x, x \cdot -0.0007275132275132275, -0.06388888888888888\right)}, 0.16666666666666666\right)\right) \]
    Proof
    (*.f64 x (fma.f64 x (*.f64 x -11/15120) -23/360)): 0 points increase in error, 0 points decrease in error
    (*.f64 x (Rewrite<= fma-def_binary64 (+.f64 (*.f64 x (*.f64 x -11/15120)) -23/360))): 0 points increase in error, 0 points decrease in error
    (*.f64 x (+.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 x x) -11/15120)) -23/360)): 0 points increase in error, 0 points decrease in error
    (*.f64 x (+.f64 (*.f64 (Rewrite<= unpow2_binary64 (pow.f64 x 2)) -11/15120) -23/360)): 0 points increase in error, 0 points decrease in error
    (*.f64 x (+.f64 (Rewrite=> *-commutative_binary64 (*.f64 -11/15120 (pow.f64 x 2))) -23/360)): 0 points increase in error, 0 points decrease in error
    (Rewrite<= distribute-rgt-out_binary64 (+.f64 (*.f64 (*.f64 -11/15120 (pow.f64 x 2)) x) (*.f64 -23/360 x))): 0 points increase in error, 2 points decrease in error
    (+.f64 (Rewrite<= associate-*r*_binary64 (*.f64 -11/15120 (*.f64 (pow.f64 x 2) x))) (*.f64 -23/360 x)): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 -11/15120 (*.f64 (Rewrite=> unpow2_binary64 (*.f64 x x)) x)) (*.f64 -23/360 x)): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 -11/15120 (Rewrite<= unpow3_binary64 (pow.f64 x 3))) (*.f64 -23/360 x)): 0 points increase in error, 0 points decrease in error
  9. Final simplification0.3

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

Alternatives

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

Error

Reproduce

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