(FPCore (x) :precision binary64 (+ (+ (/ (- 1.0 (cos x)) (sin x)) (sin 0.01)) (sin (+ x 0.5))))
double code(double x) { return (((1.0 - cos(x)) / sin(x)) + sin(0.01)) + sin((x + 0.5)); }
real(8) function code(x) real(8), intent (in) :: x code = (((1.0d0 - cos(x)) / sin(x)) + sin(0.01d0)) + sin((x + 0.5d0)) end function
public static double code(double x) { return (((1.0 - Math.cos(x)) / Math.sin(x)) + Math.sin(0.01)) + Math.sin((x + 0.5)); }
def code(x): return (((1.0 - math.cos(x)) / math.sin(x)) + math.sin(0.01)) + math.sin((x + 0.5))
function code(x) return Float64(Float64(Float64(Float64(1.0 - cos(x)) / sin(x)) + sin(0.01)) + sin(Float64(x + 0.5))) end
function tmp = code(x) tmp = (((1.0 - cos(x)) / sin(x)) + sin(0.01)) + sin((x + 0.5)); end
code[x_] := N[(N[(N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[Sin[x], $MachinePrecision]), $MachinePrecision] + N[Sin[0.01], $MachinePrecision]), $MachinePrecision] + N[Sin[N[(x + 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \left(\frac{1 - \cos x}{\sin x} + \sin 0.01\right) + \sin \left(x + 0.5\right) \end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
Alternative | Accuracy | Speedup |
---|
(FPCore (x) :precision binary64 (+ (+ (/ (- 1.0 (cos x)) (sin x)) (sin 0.01)) (sin (+ x 0.5))))
double code(double x) { return (((1.0 - cos(x)) / sin(x)) + sin(0.01)) + sin((x + 0.5)); }
real(8) function code(x) real(8), intent (in) :: x code = (((1.0d0 - cos(x)) / sin(x)) + sin(0.01d0)) + sin((x + 0.5d0)) end function
public static double code(double x) { return (((1.0 - Math.cos(x)) / Math.sin(x)) + Math.sin(0.01)) + Math.sin((x + 0.5)); }
def code(x): return (((1.0 - math.cos(x)) / math.sin(x)) + math.sin(0.01)) + math.sin((x + 0.5))
function code(x) return Float64(Float64(Float64(Float64(1.0 - cos(x)) / sin(x)) + sin(0.01)) + sin(Float64(x + 0.5))) end
function tmp = code(x) tmp = (((1.0 - cos(x)) / sin(x)) + sin(0.01)) + sin((x + 0.5)); end
code[x_] := N[(N[(N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[Sin[x], $MachinePrecision]), $MachinePrecision] + N[Sin[0.01], $MachinePrecision]), $MachinePrecision] + N[Sin[N[(x + 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \left(\frac{1 - \cos x}{\sin x} + \sin 0.01\right) + \sin \left(x + 0.5\right) \end{array}
(FPCore (x) :precision binary64 (+ (+ (+ (sin 0.01) (tan (* 0.5 x))) (* (cos 0.5) (sin x))) (* (sin 0.5) (cos x))))
double code(double x) { return ((sin(0.01) + tan((0.5 * x))) + (cos(0.5) * sin(x))) + (sin(0.5) * cos(x)); }
real(8) function code(x) real(8), intent (in) :: x code = ((sin(0.01d0) + tan((0.5d0 * x))) + (cos(0.5d0) * sin(x))) + (sin(0.5d0) * cos(x)) end function
public static double code(double x) { return ((Math.sin(0.01) + Math.tan((0.5 * x))) + (Math.cos(0.5) * Math.sin(x))) + (Math.sin(0.5) * Math.cos(x)); }
def code(x): return ((math.sin(0.01) + math.tan((0.5 * x))) + (math.cos(0.5) * math.sin(x))) + (math.sin(0.5) * math.cos(x))
function code(x) return Float64(Float64(Float64(sin(0.01) + tan(Float64(0.5 * x))) + Float64(cos(0.5) * sin(x))) + Float64(sin(0.5) * cos(x))) end
function tmp = code(x) tmp = ((sin(0.01) + tan((0.5 * x))) + (cos(0.5) * sin(x))) + (sin(0.5) * cos(x)); end
code[x_] := N[(N[(N[(N[Sin[0.01], $MachinePrecision] + N[Tan[N[(0.5 * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[0.5], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sin[0.5], $MachinePrecision] * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \left(\left(\sin 0.01 + \tan \left(0.5 \cdot x\right)\right) + \cos 0.5 \cdot \sin x\right) + \sin 0.5 \cdot \cos x \end{array}
Initial program 98.9%
lift-+.f64
N/A
lift-sin.f64
N/A
lift-+.f64
N/A
sin-sum
N/A
associate-+r+
N/A
lower-+.f64
N/A
Applied rewrites100.0%
(FPCore (x) :precision binary64 (+ (fma (fma (* x x) 0.041666666666666664 0.5) x (sin 0.01)) (sin (+ x 0.5))))
double code(double x) { return fma(fma((x * x), 0.041666666666666664, 0.5), x, sin(0.01)) + sin((x + 0.5)); }
function code(x) return Float64(fma(fma(Float64(x * x), 0.041666666666666664, 0.5), x, sin(0.01)) + sin(Float64(x + 0.5))) end
code[x_] := N[(N[(N[(N[(x * x), $MachinePrecision] * 0.041666666666666664 + 0.5), $MachinePrecision] * x + N[Sin[0.01], $MachinePrecision]), $MachinePrecision] + N[Sin[N[(x + 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.041666666666666664, 0.5\right), x, \sin 0.01\right) + \sin \left(x + 0.5\right) \end{array}
Initial program 98.9%
Taylor expanded in x around 0
+-commutative
N/A
*-commutative
N/A
lower-fma.f64
N/A
+-commutative
N/A
*-commutative
N/A
lower-fma.f64
N/A
unpow2
N/A
lower-*.f64
N/A
lower-sin.f64
100.0
Applied rewrites100.0%
(FPCore (x) :precision binary64 (+ (fma 0.5 x (sin 0.01)) (sin (+ x 0.5))))
double code(double x) { return fma(0.5, x, sin(0.01)) + sin((x + 0.5)); }
function code(x) return Float64(fma(0.5, x, sin(0.01)) + sin(Float64(x + 0.5))) end
code[x_] := N[(N[(0.5 * x + N[Sin[0.01], $MachinePrecision]), $MachinePrecision] + N[Sin[N[(x + 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \mathsf{fma}\left(0.5, x, \sin 0.01\right) + \sin \left(x + 0.5\right) \end{array}
Initial program 98.9%
Taylor expanded in x around 0
+-commutative
N/A
lower-fma.f64
N/A
lower-sin.f64
99.9
Applied rewrites99.9%
(FPCore (x) :precision binary64 (+ (sin 0.01) (sin (+ x 0.5))))
double code(double x) { return sin(0.01) + sin((x + 0.5)); }
real(8) function code(x) real(8), intent (in) :: x code = sin(0.01d0) + sin((x + 0.5d0)) end function
public static double code(double x) { return Math.sin(0.01) + Math.sin((x + 0.5)); }
def code(x): return math.sin(0.01) + math.sin((x + 0.5))
function code(x) return Float64(sin(0.01) + sin(Float64(x + 0.5))) end
function tmp = code(x) tmp = sin(0.01) + sin((x + 0.5)); end
code[x_] := N[(N[Sin[0.01], $MachinePrecision] + N[Sin[N[(x + 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \sin 0.01 + \sin \left(x + 0.5\right) \end{array}
Initial program 98.9%
Taylor expanded in x around 0
lower-sin.f64
98.3
Applied rewrites98.3%
(FPCore (x) :precision binary64 (+ (sin 0.5) (sin 0.01)))
double code(double x) { return sin(0.5) + sin(0.01); }
real(8) function code(x) real(8), intent (in) :: x code = sin(0.5d0) + sin(0.01d0) end function
public static double code(double x) { return Math.sin(0.5) + Math.sin(0.01); }
def code(x): return math.sin(0.5) + math.sin(0.01)
function code(x) return Float64(sin(0.5) + sin(0.01)) end
function tmp = code(x) tmp = sin(0.5) + sin(0.01); end
code[x_] := N[(N[Sin[0.5], $MachinePrecision] + N[Sin[0.01], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \sin 0.5 + \sin 0.01 \end{array}
Initial program 98.9%
Taylor expanded in x around 0
+-commutative
N/A
lower-+.f64
N/A
lower-sin.f64
N/A
lower-sin.f64
98.2
Applied rewrites98.2%
(FPCore (x) :precision binary64 (+ (* 0.5 x) (sin (+ x 0.5))))
double code(double x) { return (0.5 * x) + sin((x + 0.5)); }
real(8) function code(x) real(8), intent (in) :: x code = (0.5d0 * x) + sin((x + 0.5d0)) end function
public static double code(double x) { return (0.5 * x) + Math.sin((x + 0.5)); }
def code(x): return (0.5 * x) + math.sin((x + 0.5))
function code(x) return Float64(Float64(0.5 * x) + sin(Float64(x + 0.5))) end
function tmp = code(x) tmp = (0.5 * x) + sin((x + 0.5)); end
code[x_] := N[(N[(0.5 * x), $MachinePrecision] + N[Sin[N[(x + 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ 0.5 \cdot x + \sin \left(x + 0.5\right) \end{array}
Initial program 98.9%
Taylor expanded in x around 0
+-commutative
N/A
lower-fma.f64
N/A
lower-sin.f64
99.9
Applied rewrites99.9%
Taylor expanded in x around inf
Applied rewrites26.0%
(FPCore (x) :precision binary64 (* (+ (cos 0.5) 0.5) x))
double code(double x) { return (cos(0.5) + 0.5) * x; }
real(8) function code(x) real(8), intent (in) :: x code = (cos(0.5d0) + 0.5d0) * x end function
public static double code(double x) { return (Math.cos(0.5) + 0.5) * x; }
def code(x): return (math.cos(0.5) + 0.5) * x
function code(x) return Float64(Float64(cos(0.5) + 0.5) * x) end
function tmp = code(x) tmp = (cos(0.5) + 0.5) * x; end
code[x_] := N[(N[(N[Cos[0.5], $MachinePrecision] + 0.5), $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l} \\ \left(\cos 0.5 + 0.5\right) \cdot x \end{array}
Initial program 98.9%
Taylor expanded in x around 0
associate-+r+
N/A
+-commutative
N/A
*-commutative
N/A
lower-fma.f64
N/A
+-commutative
N/A
lower-+.f64
N/A
lower-cos.f64
N/A
+-commutative
N/A
lower-+.f64
N/A
lower-sin.f64
N/A
lower-sin.f64
99.5
Applied rewrites99.5%
Taylor expanded in x around inf
Applied rewrites2.3%
herbie shell --seed 1
(FPCore (x)
:name "(1-cos(x))/sin(x) + sin(0.01)+sin(x+0.5)"
:precision binary64
:pre (and (<= -0.001 x) (<= x 0.0))
(+ (+ (/ (- 1.0 (cos x)) (sin x)) (sin 0.01)) (sin (+ x 0.5))))