Average Error: 29.6 → 0.4
Time: 15.6s
Precision: binary64
Cost: 704
\[-1 \leq x \land x \leq 1\]
\[\frac{x - \sin x}{\tan x} \]
\[x \cdot \left(x \cdot \left(x \cdot \left(x \cdot -0.06388888888888888\right) + 0.16666666666666666\right)\right) \]
(FPCore (x) :precision binary64 (/ (- x (sin x)) (tan x)))
(FPCore (x)
 :precision binary64
 (* x (* x (+ (* x (* x -0.06388888888888888)) 0.16666666666666666))))
double code(double x) {
	return (x - sin(x)) / tan(x);
}
double code(double x) {
	return x * (x * ((x * (x * -0.06388888888888888)) + 0.16666666666666666));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (x - sin(x)) / tan(x)
end function
real(8) function code(x)
    real(8), intent (in) :: x
    code = x * (x * ((x * (x * (-0.06388888888888888d0))) + 0.16666666666666666d0))
end function
public static double code(double x) {
	return (x - Math.sin(x)) / Math.tan(x);
}
public static double code(double x) {
	return x * (x * ((x * (x * -0.06388888888888888)) + 0.16666666666666666));
}
def code(x):
	return (x - math.sin(x)) / math.tan(x)
def code(x):
	return x * (x * ((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 * Float64(Float64(x * Float64(x * -0.06388888888888888)) + 0.16666666666666666)))
end
function tmp = code(x)
	tmp = (x - sin(x)) / tan(x);
end
function tmp = code(x)
	tmp = x * (x * ((x * (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[(N[(x * N[(x * -0.06388888888888888), $MachinePrecision]), $MachinePrecision] + 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{x - \sin x}{\tan x}
x \cdot \left(x \cdot \left(x \cdot \left(x \cdot -0.06388888888888888\right) + 0.16666666666666666\right)\right)

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Initial program 29.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))): 26 points increase in error, 23 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. Taylor expanded in x around 0 0.4

    \[\leadsto \color{blue}{0.16666666666666666 \cdot {x}^{2} + -0.06388888888888888 \cdot {x}^{4}} \]
  6. Simplified0.4

    \[\leadsto \color{blue}{x \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot -0.06388888888888888, 0.16666666666666666\right)\right)} \]
    Proof
    (*.f64 x (*.f64 x (fma.f64 x (*.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 x -23/360)) 1/6)))): 0 points increase in error, 0 points decrease in error
    (*.f64 x (*.f64 x (+.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 x x) -23/360)) 1/6))): 0 points increase in error, 0 points decrease in error
    (*.f64 x (*.f64 x (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 -23/360 (*.f64 x x))) 1/6))): 0 points increase in error, 0 points decrease in error
    (*.f64 x (*.f64 x (Rewrite=> +-commutative_binary64 (+.f64 1/6 (*.f64 -23/360 (*.f64 x x)))))): 0 points increase in error, 0 points decrease in error
    (*.f64 x (Rewrite<= distribute-rgt-out_binary64 (+.f64 (*.f64 1/6 x) (*.f64 (*.f64 -23/360 (*.f64 x x)) x)))): 0 points increase in error, 0 points decrease in error
    (*.f64 x (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 x 1/6)) (*.f64 (*.f64 -23/360 (*.f64 x x)) x))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= distribute-rgt-out_binary64 (+.f64 (*.f64 (*.f64 x 1/6) x) (*.f64 (*.f64 (*.f64 -23/360 (*.f64 x x)) x) x))): 1 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (*.f64 x 1/6) x) (Rewrite<= associate-*r*_binary64 (*.f64 (*.f64 -23/360 (*.f64 x x)) (*.f64 x x)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (*.f64 x 1/6) x) (Rewrite=> associate-*l*_binary64 (*.f64 -23/360 (*.f64 (*.f64 x x) (*.f64 x x))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (*.f64 x 1/6) x) (*.f64 -23/360 (Rewrite=> associate-*r*_binary64 (*.f64 (*.f64 (*.f64 x x) x) x)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (*.f64 x 1/6) x) (*.f64 -23/360 (*.f64 (Rewrite<= unpow3_binary64 (pow.f64 x 3)) x))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (*.f64 x 1/6) x) (*.f64 -23/360 (Rewrite=> pow-plus_binary64 (pow.f64 x (+.f64 3 1))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (*.f64 x 1/6) x) (*.f64 -23/360 (pow.f64 x (Rewrite=> metadata-eval 4)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 x (*.f64 x 1/6))) (*.f64 -23/360 (pow.f64 x 4))): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite=> associate-*r*_binary64 (*.f64 (*.f64 x x) 1/6)) (*.f64 -23/360 (pow.f64 x 4))): 26 points increase in error, 23 points decrease in error
    (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 1/6 (*.f64 x x))) (*.f64 -23/360 (pow.f64 x 4))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 1/6 (Rewrite<= unpow2_binary64 (pow.f64 x 2))) (*.f64 -23/360 (pow.f64 x 4))): 0 points increase in error, 0 points decrease in error
  7. Applied egg-rr0.4

    \[\leadsto x \cdot \left(x \cdot \color{blue}{\left(x \cdot \left(x \cdot -0.06388888888888888\right) + 0.16666666666666666\right)}\right) \]
  8. Final simplification0.4

    \[\leadsto x \cdot \left(x \cdot \left(x \cdot \left(x \cdot -0.06388888888888888\right) + 0.16666666666666666\right)\right) \]

Alternatives

Alternative 1
Error0.7
Cost320
\[0.16666666666666666 \cdot \left(x \cdot x\right) \]
Alternative 2
Error0.7
Cost320
\[x \cdot \left(x \cdot 0.16666666666666666\right) \]

Error

Reproduce

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