?

Average Error: 20.1 → 0.7
Time: 6.6s
Precision: binary64
Cost: 26816

?

\[-1000 < x \land x < 1000\]
\[\sin x - x \]
\[0.008333333333333333 \cdot {x}^{5} + \left(-0.16666666666666666 \cdot {x}^{3} + \left(-0.0001984126984126984 \cdot {x}^{7} + 2.7557319223985893 \cdot 10^{-6} \cdot {x}^{9}\right)\right) \]
(FPCore (x) :precision binary64 (- (sin x) x))
(FPCore (x)
 :precision binary64
 (+
  (* 0.008333333333333333 (pow x 5.0))
  (+
   (* -0.16666666666666666 (pow x 3.0))
   (+
    (* -0.0001984126984126984 (pow x 7.0))
    (* 2.7557319223985893e-6 (pow x 9.0))))))
double code(double x) {
	return sin(x) - x;
}
double code(double x) {
	return (0.008333333333333333 * pow(x, 5.0)) + ((-0.16666666666666666 * pow(x, 3.0)) + ((-0.0001984126984126984 * pow(x, 7.0)) + (2.7557319223985893e-6 * pow(x, 9.0))));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = sin(x) - x
end function
real(8) function code(x)
    real(8), intent (in) :: x
    code = (0.008333333333333333d0 * (x ** 5.0d0)) + (((-0.16666666666666666d0) * (x ** 3.0d0)) + (((-0.0001984126984126984d0) * (x ** 7.0d0)) + (2.7557319223985893d-6 * (x ** 9.0d0))))
end function
public static double code(double x) {
	return Math.sin(x) - x;
}
public static double code(double x) {
	return (0.008333333333333333 * Math.pow(x, 5.0)) + ((-0.16666666666666666 * Math.pow(x, 3.0)) + ((-0.0001984126984126984 * Math.pow(x, 7.0)) + (2.7557319223985893e-6 * Math.pow(x, 9.0))));
}
def code(x):
	return math.sin(x) - x
def code(x):
	return (0.008333333333333333 * math.pow(x, 5.0)) + ((-0.16666666666666666 * math.pow(x, 3.0)) + ((-0.0001984126984126984 * math.pow(x, 7.0)) + (2.7557319223985893e-6 * math.pow(x, 9.0))))
function code(x)
	return Float64(sin(x) - x)
end
function code(x)
	return Float64(Float64(0.008333333333333333 * (x ^ 5.0)) + Float64(Float64(-0.16666666666666666 * (x ^ 3.0)) + Float64(Float64(-0.0001984126984126984 * (x ^ 7.0)) + Float64(2.7557319223985893e-6 * (x ^ 9.0)))))
end
function tmp = code(x)
	tmp = sin(x) - x;
end
function tmp = code(x)
	tmp = (0.008333333333333333 * (x ^ 5.0)) + ((-0.16666666666666666 * (x ^ 3.0)) + ((-0.0001984126984126984 * (x ^ 7.0)) + (2.7557319223985893e-6 * (x ^ 9.0))));
end
code[x_] := N[(N[Sin[x], $MachinePrecision] - x), $MachinePrecision]
code[x_] := N[(N[(0.008333333333333333 * N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision] + N[(N[(-0.16666666666666666 * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(-0.0001984126984126984 * N[Power[x, 7.0], $MachinePrecision]), $MachinePrecision] + N[(2.7557319223985893e-6 * N[Power[x, 9.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\sin x - x
0.008333333333333333 \cdot {x}^{5} + \left(-0.16666666666666666 \cdot {x}^{3} + \left(-0.0001984126984126984 \cdot {x}^{7} + 2.7557319223985893 \cdot 10^{-6} \cdot {x}^{9}\right)\right)

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original20.1
Target0.1
Herbie0.7
\[\begin{array}{l} \mathbf{if}\;\left|x\right| < 0.07:\\ \;\;\;\;-\left(\left(\frac{{x}^{3}}{6} - \frac{{x}^{5}}{120}\right) + \frac{{x}^{7}}{5040}\right)\\ \mathbf{else}:\\ \;\;\;\;\sin x - x\\ \end{array} \]

Derivation?

  1. Initial program 20.1

    \[\sin x - x \]
  2. Taylor expanded in x around 0 0.7

    \[\leadsto \color{blue}{-0.16666666666666666 \cdot {x}^{3} + \left(2.7557319223985893 \cdot 10^{-6} \cdot {x}^{9} + \left(0.008333333333333333 \cdot {x}^{5} + -0.0001984126984126984 \cdot {x}^{7}\right)\right)} \]
  3. Simplified0.7

    \[\leadsto \color{blue}{0.008333333333333333 \cdot {x}^{5} + \left(-0.16666666666666666 \cdot {x}^{3} + \left(-0.0001984126984126984 \cdot {x}^{7} + 2.7557319223985893 \cdot 10^{-6} \cdot {x}^{9}\right)\right)} \]
    Proof

    [Start]0.7

    \[ -0.16666666666666666 \cdot {x}^{3} + \left(2.7557319223985893 \cdot 10^{-6} \cdot {x}^{9} + \left(0.008333333333333333 \cdot {x}^{5} + -0.0001984126984126984 \cdot {x}^{7}\right)\right) \]

    rational_best_oopsla_all_46_json_45_simplify-82 [=>]0.7

    \[ -0.16666666666666666 \cdot {x}^{3} + \color{blue}{\left(0.008333333333333333 \cdot {x}^{5} + \left(2.7557319223985893 \cdot 10^{-6} \cdot {x}^{9} + -0.0001984126984126984 \cdot {x}^{7}\right)\right)} \]

    rational_best_oopsla_all_46_json_45_simplify-82 [=>]0.7

    \[ \color{blue}{0.008333333333333333 \cdot {x}^{5} + \left(-0.16666666666666666 \cdot {x}^{3} + \left(2.7557319223985893 \cdot 10^{-6} \cdot {x}^{9} + -0.0001984126984126984 \cdot {x}^{7}\right)\right)} \]

    rational_best_oopsla_all_46_json_45_simplify-35 [=>]0.7

    \[ 0.008333333333333333 \cdot {x}^{5} + \left(-0.16666666666666666 \cdot {x}^{3} + \color{blue}{\left(-0.0001984126984126984 \cdot {x}^{7} + 2.7557319223985893 \cdot 10^{-6} \cdot {x}^{9}\right)}\right) \]
  4. Final simplification0.7

    \[\leadsto 0.008333333333333333 \cdot {x}^{5} + \left(-0.16666666666666666 \cdot {x}^{3} + \left(-0.0001984126984126984 \cdot {x}^{7} + 2.7557319223985893 \cdot 10^{-6} \cdot {x}^{9}\right)\right) \]

Alternatives

Alternative 1
Error0.9
Cost13376
\[-0.16666666666666666 \cdot {x}^{3} + 0.008333333333333333 \cdot {x}^{5} \]
Alternative 2
Error1.2
Cost6656
\[-0.16666666666666666 \cdot {x}^{3} \]
Alternative 3
Error20.1
Cost6592
\[\sin x - x \]
Alternative 4
Error59.9
Cost128
\[-x \]

Error

Reproduce?

herbie shell --seed 2023090 
(FPCore (x)
  :name "bug500 (missed optimization)"
  :precision binary64
  :pre (and (< -1000.0 x) (< x 1000.0))

  :herbie-target
  (if (< (fabs x) 0.07) (- (+ (- (/ (pow x 3.0) 6.0) (/ (pow x 5.0) 120.0)) (/ (pow x 7.0) 5040.0))) (- (sin x) x))

  (- (sin x) x))