(FPCore (x) :precision binary64 (- (sin (+ x 1e-6)) (sin x)))
double code(double x) { return sin((x + 1e-6)) - sin(x); }
real(8) function code(x) real(8), intent (in) :: x code = sin((x + 1d-6)) - sin(x) end function
public static double code(double x) { return Math.sin((x + 1e-6)) - Math.sin(x); }
def code(x): return math.sin((x + 1e-6)) - math.sin(x)
function code(x) return Float64(sin(Float64(x + 1e-6)) - sin(x)) end
function tmp = code(x) tmp = sin((x + 1e-6)) - sin(x); end
code[x_] := N[(N[Sin[N[(x + 1e-6), $MachinePrecision]], $MachinePrecision] - N[Sin[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \sin \left(x + 10^{-6}\right) - \sin x \end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
Alternative | Accuracy | Speedup |
---|
(FPCore (x) :precision binary64 (- (sin (+ x 1e-6)) (sin x)))
double code(double x) { return sin((x + 1e-6)) - sin(x); }
real(8) function code(x) real(8), intent (in) :: x code = sin((x + 1d-6)) - sin(x) end function
public static double code(double x) { return Math.sin((x + 1e-6)) - Math.sin(x); }
def code(x): return math.sin((x + 1e-6)) - math.sin(x)
function code(x) return Float64(sin(Float64(x + 1e-6)) - sin(x)) end
function tmp = code(x) tmp = sin((x + 1e-6)) - sin(x); end
code[x_] := N[(N[Sin[N[(x + 1e-6), $MachinePrecision]], $MachinePrecision] - N[Sin[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \sin \left(x + 10^{-6}\right) - \sin x \end{array}
(FPCore (x) :precision binary64 (* (* (sin 5e-7) 2.0) (cos (- -5e-7 x))))
double code(double x) { return (sin(5e-7) * 2.0) * cos((-5e-7 - x)); }
real(8) function code(x) real(8), intent (in) :: x code = (sin(5d-7) * 2.0d0) * cos(((-5d-7) - x)) end function
public static double code(double x) { return (Math.sin(5e-7) * 2.0) * Math.cos((-5e-7 - x)); }
def code(x): return (math.sin(5e-7) * 2.0) * math.cos((-5e-7 - x))
function code(x) return Float64(Float64(sin(5e-7) * 2.0) * cos(Float64(-5e-7 - x))) end
function tmp = code(x) tmp = (sin(5e-7) * 2.0) * cos((-5e-7 - x)); end
code[x_] := N[(N[(N[Sin[5e-7], $MachinePrecision] * 2.0), $MachinePrecision] * N[Cos[N[(-5e-7 - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \left(\sin \left( 5 \cdot 10^{-7} \right) \cdot 2\right) \cdot \cos \left(-5 \cdot 10^{-7} - x\right) \end{array}
Initial program 60.2%
lift--.f64
N/A
lift-sin.f64
N/A
lift-sin.f64
N/A
diff-sin
N/A
associate-*r*
N/A
lower-*.f64
N/A
*-commutative
N/A
lower-*.f64
N/A
lower-sin.f64
N/A
lift-+.f64
N/A
+-commutative
N/A
associate--l+
N/A
+-inverses
N/A
metadata-eval
N/A
metadata-eval
N/A
frac-2neg
N/A
distribute-frac-neg
N/A
cos-neg
N/A
lower-cos.f64
N/A
lower-/.f64
N/A
Applied rewrites89.1%
Taylor expanded in x around 0
metadata-eval
N/A
lft-mult-inverse
N/A
associate-*l*
N/A
*-commutative
N/A
unsub-neg
N/A
+-commutative
N/A
mul-1-neg
N/A
sub-neg
N/A
lower--.f64
N/A
*-commutative
N/A
associate-*l*
N/A
lft-mult-inverse
N/A
metadata-eval
N/A
metadata-eval
89.1
Applied rewrites89.1%
(FPCore (x) :precision binary64 (if (<= (- (sin (+ x 1e-6)) (sin x)) -2e-10) (- (sin 1e-6) (sin x)) (sin 1e-6)))
double code(double x) { double tmp; if ((sin((x + 1e-6)) - sin(x)) <= -2e-10) { tmp = sin(1e-6) - sin(x); } else { tmp = sin(1e-6); } return tmp; }
real(8) function code(x) real(8), intent (in) :: x real(8) :: tmp if ((sin((x + 1d-6)) - sin(x)) <= (-2d-10)) then tmp = sin(1d-6) - sin(x) else tmp = sin(1d-6) end if code = tmp end function
public static double code(double x) { double tmp; if ((Math.sin((x + 1e-6)) - Math.sin(x)) <= -2e-10) { tmp = Math.sin(1e-6) - Math.sin(x); } else { tmp = Math.sin(1e-6); } return tmp; }
def code(x): tmp = 0 if (math.sin((x + 1e-6)) - math.sin(x)) <= -2e-10: tmp = math.sin(1e-6) - math.sin(x) else: tmp = math.sin(1e-6) return tmp
function code(x) tmp = 0.0 if (Float64(sin(Float64(x + 1e-6)) - sin(x)) <= -2e-10) tmp = Float64(sin(1e-6) - sin(x)); else tmp = sin(1e-6); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((sin((x + 1e-6)) - sin(x)) <= -2e-10) tmp = sin(1e-6) - sin(x); else tmp = sin(1e-6); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(N[Sin[N[(x + 1e-6), $MachinePrecision]], $MachinePrecision] - N[Sin[x], $MachinePrecision]), $MachinePrecision], -2e-10], N[(N[Sin[1e-6], $MachinePrecision] - N[Sin[x], $MachinePrecision]), $MachinePrecision], N[Sin[1e-6], $MachinePrecision]]
\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin \left(x + 10^{-6}\right) - \sin x \leq -2 \cdot 10^{-10}:\\ \;\;\;\;\sin \left( 10^{-6} \right) - \sin x\\ \mathbf{else}:\\ \;\;\;\;\sin \left( 10^{-6} \right)\\ \end{array} \end{array}
if (-.f64 (sin.f64 (+.f64 x #s(literal 4722366482869645/4722366482869645213696 binary64))) (sin.f64 x)) < -2.00000000000000007e-10
Initial program 60.2%
Taylor expanded in x around 0
Applied rewrites11.2%
if -2.00000000000000007e-10 < (-.f64 (sin.f64 (+.f64 x #s(literal 4722366482869645/4722366482869645213696 binary64))) (sin.f64 x))
Initial program 60.3%
Taylor expanded in x around 0
lower-sin.f64
14.0
Applied rewrites14.0%
(FPCore (x) :precision binary64 (- (sin (+ x 1e-6)) (sin x)))
double code(double x) { return sin((x + 1e-6)) - sin(x); }
real(8) function code(x) real(8), intent (in) :: x code = sin((x + 1d-6)) - sin(x) end function
public static double code(double x) { return Math.sin((x + 1e-6)) - Math.sin(x); }
def code(x): return math.sin((x + 1e-6)) - math.sin(x)
function code(x) return Float64(sin(Float64(x + 1e-6)) - sin(x)) end
function tmp = code(x) tmp = sin((x + 1e-6)) - sin(x); end
code[x_] := N[(N[Sin[N[(x + 1e-6), $MachinePrecision]], $MachinePrecision] - N[Sin[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \sin \left(x + 10^{-6}\right) - \sin x \end{array}
Initial program 60.2%
(FPCore (x) :precision binary64 (sin 1e-6))
double code(double x) { return sin(1e-6); }
real(8) function code(x) real(8), intent (in) :: x code = sin(1d-6) end function
public static double code(double x) { return Math.sin(1e-6); }
def code(x): return math.sin(1e-6)
function code(x) return sin(1e-6) end
function tmp = code(x) tmp = sin(1e-6); end
code[x_] := N[Sin[1e-6], $MachinePrecision]
\begin{array}{l} \\ \sin \left( 10^{-6} \right) \end{array}
Initial program 60.2%
Taylor expanded in x around 0
lower-sin.f64
8.5
Applied rewrites8.5%
herbie shell --seed 1
(FPCore (x)
:name "sin(x+1e-6)-sin(x)"
:precision binary64
:pre (and (<= 1.56 x) (<= x 1.58))
(- (sin (+ x 1e-6)) (sin x)))