(FPCore (x) :precision binary64 (- (+ (- 1.0 (cos (+ x 0.001))) 1.0) (cos x)))
double code(double x) { return ((1.0 - cos((x + 0.001))) + 1.0) - cos(x); }
real(8) function code(x) real(8), intent (in) :: x code = ((1.0d0 - cos((x + 0.001d0))) + 1.0d0) - cos(x) end function
public static double code(double x) { return ((1.0 - Math.cos((x + 0.001))) + 1.0) - Math.cos(x); }
def code(x): return ((1.0 - math.cos((x + 0.001))) + 1.0) - math.cos(x)
function code(x) return Float64(Float64(Float64(1.0 - cos(Float64(x + 0.001))) + 1.0) - cos(x)) end
function tmp = code(x) tmp = ((1.0 - cos((x + 0.001))) + 1.0) - cos(x); end
code[x_] := N[(N[(N[(1.0 - N[Cos[N[(x + 0.001), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \left(\left(1 - \cos \left(x + 0.001\right)\right) + 1\right) - \cos x \end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
Alternative | Accuracy | Speedup |
---|
(FPCore (x) :precision binary64 (- (+ (- 1.0 (cos (+ x 0.001))) 1.0) (cos x)))
double code(double x) { return ((1.0 - cos((x + 0.001))) + 1.0) - cos(x); }
real(8) function code(x) real(8), intent (in) :: x code = ((1.0d0 - cos((x + 0.001d0))) + 1.0d0) - cos(x) end function
public static double code(double x) { return ((1.0 - Math.cos((x + 0.001))) + 1.0) - Math.cos(x); }
def code(x): return ((1.0 - math.cos((x + 0.001))) + 1.0) - math.cos(x)
function code(x) return Float64(Float64(Float64(1.0 - cos(Float64(x + 0.001))) + 1.0) - cos(x)) end
function tmp = code(x) tmp = ((1.0 - cos((x + 0.001))) + 1.0) - cos(x); end
code[x_] := N[(N[(N[(1.0 - N[Cos[N[(x + 0.001), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \left(\left(1 - \cos \left(x + 0.001\right)\right) + 1\right) - \cos x \end{array}
(FPCore (x) :precision binary64 (fma (fma (fma 0.5 (cos 0.001) 0.5) x (sin 0.001)) x (/ (pow (sin 0.001) 2.0) (+ (cos 0.001) 1.0))))
double code(double x) { return fma(fma(fma(0.5, cos(0.001), 0.5), x, sin(0.001)), x, (pow(sin(0.001), 2.0) / (cos(0.001) + 1.0))); }
function code(x) return fma(fma(fma(0.5, cos(0.001), 0.5), x, sin(0.001)), x, Float64((sin(0.001) ^ 2.0) / Float64(cos(0.001) + 1.0))) end
code[x_] := N[(N[(N[(0.5 * N[Cos[0.001], $MachinePrecision] + 0.5), $MachinePrecision] * x + N[Sin[0.001], $MachinePrecision]), $MachinePrecision] * x + N[(N[Power[N[Sin[0.001], $MachinePrecision], 2.0], $MachinePrecision] / N[(N[Cos[0.001], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.5, \cos 0.001, 0.5\right), x, \sin 0.001\right), x, \frac{{\sin 0.001}^{2}}{\cos 0.001 + 1}\right) \end{array}
Initial program 74.7%
Taylor expanded in x around 0
+-commutative
N/A
associate--l+
N/A
*-commutative
N/A
lower-fma.f64
N/A
+-commutative
N/A
*-commutative
N/A
lower-fma.f64
N/A
sub-neg
N/A
+-commutative
N/A
distribute-lft-neg-in
N/A
metadata-eval
N/A
lower-fma.f64
N/A
lower-cos.f64
N/A
lower-sin.f64
N/A
lower--.f64
N/A
lower-cos.f64
74.7
Applied rewrites74.7%
Applied rewrites100.0%
(FPCore (x) :precision binary64 (let* ((t_0 (sin (+ 0.001 x)))) (fma t_0 (* t_0 (pow (+ (cos (+ 0.001 x)) 1.0) -1.0)) (* (* x x) 0.5))))
double code(double x) { double t_0 = sin((0.001 + x)); return fma(t_0, (t_0 * pow((cos((0.001 + x)) + 1.0), -1.0)), ((x * x) * 0.5)); }
function code(x) t_0 = sin(Float64(0.001 + x)) return fma(t_0, Float64(t_0 * (Float64(cos(Float64(0.001 + x)) + 1.0) ^ -1.0)), Float64(Float64(x * x) * 0.5)) end
code[x_] := Block[{t$95$0 = N[Sin[N[(0.001 + x), $MachinePrecision]], $MachinePrecision]}, N[(t$95$0 * N[(t$95$0 * N[Power[N[(N[Cos[N[(0.001 + x), $MachinePrecision]], $MachinePrecision] + 1.0), $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision] + N[(N[(x * x), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(0.001 + x\right)\\ \mathsf{fma}\left(t\_0, t\_0 \cdot {\left(\cos \left(0.001 + x\right) + 1\right)}^{-1}, \left(x \cdot x\right) \cdot 0.5\right) \end{array} \end{array}
Initial program 74.7%
lift--.f64
N/A
lift-+.f64
N/A
associate--l+
N/A
lift--.f64
N/A
flip--
N/A
div-inv
N/A
metadata-eval
N/A
lift-cos.f64
N/A
lift-cos.f64
N/A
1-sub-cos
N/A
associate-*l*
N/A
lower-fma.f64
N/A
Applied rewrites99.9%
Taylor expanded in x around 0
*-commutative
N/A
lower-*.f64
N/A
unpow2
N/A
lower-*.f64
100.0
Applied rewrites100.0%
(FPCore (x) :precision binary64 (/ (pow (sin 0.001) 2.0) (+ (cos 0.001) 1.0)))
double code(double x) { return pow(sin(0.001), 2.0) / (cos(0.001) + 1.0); }
real(8) function code(x) real(8), intent (in) :: x code = (sin(0.001d0) ** 2.0d0) / (cos(0.001d0) + 1.0d0) end function
public static double code(double x) { return Math.pow(Math.sin(0.001), 2.0) / (Math.cos(0.001) + 1.0); }
def code(x): return math.pow(math.sin(0.001), 2.0) / (math.cos(0.001) + 1.0)
function code(x) return Float64((sin(0.001) ^ 2.0) / Float64(cos(0.001) + 1.0)) end
function tmp = code(x) tmp = (sin(0.001) ^ 2.0) / (cos(0.001) + 1.0); end
code[x_] := N[(N[Power[N[Sin[0.001], $MachinePrecision], 2.0], $MachinePrecision] / N[(N[Cos[0.001], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \frac{{\sin 0.001}^{2}}{\cos 0.001 + 1} \end{array}
Initial program 74.7%
Taylor expanded in x around 0
lower--.f64
N/A
lower-cos.f64
74.5
Applied rewrites74.5%
Applied rewrites99.2%
(FPCore (x) :precision binary64 (fma (sin (+ 0.001 x)) (tan 0.0005) (- 1.0 (cos x))))
double code(double x) { return fma(sin((0.001 + x)), tan(0.0005), (1.0 - cos(x))); }
function code(x) return fma(sin(Float64(0.001 + x)), tan(0.0005), Float64(1.0 - cos(x))) end
code[x_] := N[(N[Sin[N[(0.001 + x), $MachinePrecision]], $MachinePrecision] * N[Tan[0.0005], $MachinePrecision] + N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \mathsf{fma}\left(\sin \left(0.001 + x\right), \tan 0.0005, 1 - \cos x\right) \end{array}
Initial program 74.7%
lift--.f64
N/A
lift-+.f64
N/A
associate--l+
N/A
lift--.f64
N/A
flip--
N/A
div-inv
N/A
metadata-eval
N/A
lift-cos.f64
N/A
lift-cos.f64
N/A
1-sub-cos
N/A
associate-*l*
N/A
lower-fma.f64
N/A
Applied rewrites99.9%
Taylor expanded in x around 0
hang-0p-tan
N/A
lower-tan.f64
N/A
metadata-eval
97.8
Applied rewrites97.8%
(FPCore (x) :precision binary64 (* (sin 0.001) (tan 0.0005)))
double code(double x) { return sin(0.001) * tan(0.0005); }
real(8) function code(x) real(8), intent (in) :: x code = sin(0.001d0) * tan(0.0005d0) end function
public static double code(double x) { return Math.sin(0.001) * Math.tan(0.0005); }
def code(x): return math.sin(0.001) * math.tan(0.0005)
function code(x) return Float64(sin(0.001) * tan(0.0005)) end
function tmp = code(x) tmp = sin(0.001) * tan(0.0005); end
code[x_] := N[(N[Sin[0.001], $MachinePrecision] * N[Tan[0.0005], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \sin 0.001 \cdot \tan 0.0005 \end{array}
Initial program 74.7%
lift--.f64
N/A
lift-+.f64
N/A
associate--l+
N/A
lift--.f64
N/A
flip--
N/A
flip--
N/A
metadata-eval
N/A
lift-cos.f64
N/A
lift-cos.f64
N/A
sqr-sin-b
N/A
frac-add
N/A
lower-/.f64
N/A
Applied rewrites100.0%
Taylor expanded in x around 0
unpow2
N/A
associate-/l*
N/A
lower-*.f64
N/A
lower-sin.f64
N/A
hang-0p-tan
N/A
lower-tan.f64
N/A
metadata-eval
97.7
Applied rewrites97.7%
(FPCore (x) :precision binary64 (- 1.0 (cos (+ 0.001 x))))
double code(double x) { return 1.0 - cos((0.001 + x)); }
real(8) function code(x) real(8), intent (in) :: x code = 1.0d0 - cos((0.001d0 + x)) end function
public static double code(double x) { return 1.0 - Math.cos((0.001 + x)); }
def code(x): return 1.0 - math.cos((0.001 + x))
function code(x) return Float64(1.0 - cos(Float64(0.001 + x))) end
function tmp = code(x) tmp = 1.0 - cos((0.001 + x)); end
code[x_] := N[(1.0 - N[Cos[N[(0.001 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ 1 - \cos \left(0.001 + x\right) \end{array}
Initial program 74.7%
Taylor expanded in x around inf
associate--r+
N/A
lower--.f64
N/A
lower--.f64
N/A
lower-cos.f64
N/A
lower-cos.f64
N/A
lower-+.f64
74.7
Applied rewrites74.7%
Taylor expanded in x around 0
Applied rewrites74.7%
(FPCore (x) :precision binary64 (- 1.0 (cos 0.001)))
double code(double x) { return 1.0 - cos(0.001); }
real(8) function code(x) real(8), intent (in) :: x code = 1.0d0 - cos(0.001d0) end function
public static double code(double x) { return 1.0 - Math.cos(0.001); }
def code(x): return 1.0 - math.cos(0.001)
function code(x) return Float64(1.0 - cos(0.001)) end
function tmp = code(x) tmp = 1.0 - cos(0.001); end
code[x_] := N[(1.0 - N[Cos[0.001], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ 1 - \cos 0.001 \end{array}
Initial program 74.7%
Taylor expanded in x around 0
lower--.f64
N/A
lower-cos.f64
74.5
Applied rewrites74.5%
herbie shell --seed 1
(FPCore (x)
:name "(1-cos(x+0.001)) + 1-cos(x)"
:precision binary64
:pre (and (<= -1e-9 x) (<= x 0.0))
(- (+ (- 1.0 (cos (+ x 0.001))) 1.0) (cos x)))