
(FPCore (x eps) :precision binary64 (- (pow (+ x eps) 5.0) (pow x 5.0)))
double code(double x, double eps) {
return pow((x + eps), 5.0) - pow(x, 5.0);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = ((x + eps) ** 5.0d0) - (x ** 5.0d0)
end function
public static double code(double x, double eps) {
return Math.pow((x + eps), 5.0) - Math.pow(x, 5.0);
}
def code(x, eps): return math.pow((x + eps), 5.0) - math.pow(x, 5.0)
function code(x, eps) return Float64((Float64(x + eps) ^ 5.0) - (x ^ 5.0)) end
function tmp = code(x, eps) tmp = ((x + eps) ^ 5.0) - (x ^ 5.0); end
code[x_, eps_] := N[(N[Power[N[(x + eps), $MachinePrecision], 5.0], $MachinePrecision] - N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(x + \varepsilon\right)}^{5} - {x}^{5}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x eps) :precision binary64 (- (pow (+ x eps) 5.0) (pow x 5.0)))
double code(double x, double eps) {
return pow((x + eps), 5.0) - pow(x, 5.0);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = ((x + eps) ** 5.0d0) - (x ** 5.0d0)
end function
public static double code(double x, double eps) {
return Math.pow((x + eps), 5.0) - Math.pow(x, 5.0);
}
def code(x, eps): return math.pow((x + eps), 5.0) - math.pow(x, 5.0)
function code(x, eps) return Float64((Float64(x + eps) ^ 5.0) - (x ^ 5.0)) end
function tmp = code(x, eps) tmp = ((x + eps) ^ 5.0) - (x ^ 5.0); end
code[x_, eps_] := N[(N[Power[N[(x + eps), $MachinePrecision], 5.0], $MachinePrecision] - N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(x + \varepsilon\right)}^{5} - {x}^{5}
\end{array}
(FPCore (x eps) :precision binary64 (- (pow (+ x eps) 5.0) (pow x 5.0)))
double code(double x, double eps) {
return pow((x + eps), 5.0) - pow(x, 5.0);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = ((x + eps) ** 5.0d0) - (x ** 5.0d0)
end function
public static double code(double x, double eps) {
return Math.pow((x + eps), 5.0) - Math.pow(x, 5.0);
}
def code(x, eps): return math.pow((x + eps), 5.0) - math.pow(x, 5.0)
function code(x, eps) return Float64((Float64(x + eps) ^ 5.0) - (x ^ 5.0)) end
function tmp = code(x, eps) tmp = ((x + eps) ^ 5.0) - (x ^ 5.0); end
code[x_, eps_] := N[(N[Power[N[(x + eps), $MachinePrecision], 5.0], $MachinePrecision] - N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(x + \varepsilon\right)}^{5} - {x}^{5}
\end{array}
Initial program 86.8%
(FPCore (x eps) :precision binary64 (let* ((t_0 (pow (+ x eps) 5.0))) (if (<= eps -8.8e-94) t_0 (if (<= eps 1.25e-81) (pow t_0 5.0) t_0))))
double code(double x, double eps) {
double t_0 = pow((x + eps), 5.0);
double tmp;
if (eps <= -8.8e-94) {
tmp = t_0;
} else if (eps <= 1.25e-81) {
tmp = pow(t_0, 5.0);
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: tmp
t_0 = (x + eps) ** 5.0d0
if (eps <= (-8.8d-94)) then
tmp = t_0
else if (eps <= 1.25d-81) then
tmp = t_0 ** 5.0d0
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.pow((x + eps), 5.0);
double tmp;
if (eps <= -8.8e-94) {
tmp = t_0;
} else if (eps <= 1.25e-81) {
tmp = Math.pow(t_0, 5.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, eps): t_0 = math.pow((x + eps), 5.0) tmp = 0 if eps <= -8.8e-94: tmp = t_0 elif eps <= 1.25e-81: tmp = math.pow(t_0, 5.0) else: tmp = t_0 return tmp
function code(x, eps) t_0 = Float64(x + eps) ^ 5.0 tmp = 0.0 if (eps <= -8.8e-94) tmp = t_0; elseif (eps <= 1.25e-81) tmp = t_0 ^ 5.0; else tmp = t_0; end return tmp end
function tmp_2 = code(x, eps) t_0 = (x + eps) ^ 5.0; tmp = 0.0; if (eps <= -8.8e-94) tmp = t_0; elseif (eps <= 1.25e-81) tmp = t_0 ^ 5.0; else tmp = t_0; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[Power[N[(x + eps), $MachinePrecision], 5.0], $MachinePrecision]}, If[LessEqual[eps, -8.8e-94], t$95$0, If[LessEqual[eps, 1.25e-81], N[Power[t$95$0, 5.0], $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left(x + \varepsilon\right)}^{5}\\
\mathbf{if}\;\varepsilon \leq -8.8 \cdot 10^{-94}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;\varepsilon \leq 1.25 \cdot 10^{-81}:\\
\;\;\;\;{t\_0}^{5}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if eps < -8.80000000000000004e-94 or 1.24999999999999995e-81 < eps Initial program 84.9%
Taylor expanded in x around 0
Applied rewrites82.5%
if -8.80000000000000004e-94 < eps < 1.24999999999999995e-81Initial program 87.6%
Taylor expanded in x around 0
Applied rewrites75.2%
Taylor expanded in x around 0
Applied rewrites87.0%
(FPCore (x eps) :precision binary64 (pow (+ x eps) 5.0))
double code(double x, double eps) {
return pow((x + eps), 5.0);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (x + eps) ** 5.0d0
end function
public static double code(double x, double eps) {
return Math.pow((x + eps), 5.0);
}
def code(x, eps): return math.pow((x + eps), 5.0)
function code(x, eps) return Float64(x + eps) ^ 5.0 end
function tmp = code(x, eps) tmp = (x + eps) ^ 5.0; end
code[x_, eps_] := N[Power[N[(x + eps), $MachinePrecision], 5.0], $MachinePrecision]
\begin{array}{l}
\\
{\left(x + \varepsilon\right)}^{5}
\end{array}
Initial program 86.8%
Taylor expanded in x around 0
Applied rewrites77.4%
(FPCore (x eps) :precision binary64 (pow x 5.0))
double code(double x, double eps) {
return pow(x, 5.0);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = x ** 5.0d0
end function
public static double code(double x, double eps) {
return Math.pow(x, 5.0);
}
def code(x, eps): return math.pow(x, 5.0)
function code(x, eps) return x ^ 5.0 end
function tmp = code(x, eps) tmp = x ^ 5.0; end
code[x_, eps_] := N[Power[x, 5.0], $MachinePrecision]
\begin{array}{l}
\\
{x}^{5}
\end{array}
Initial program 86.8%
Taylor expanded in x around 0
Applied rewrites62.2%
(FPCore (x eps) :precision binary64 (+ x eps))
double code(double x, double eps) {
return x + eps;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = x + eps
end function
public static double code(double x, double eps) {
return x + eps;
}
def code(x, eps): return x + eps
function code(x, eps) return Float64(x + eps) end
function tmp = code(x, eps) tmp = x + eps; end
code[x_, eps_] := N[(x + eps), $MachinePrecision]
\begin{array}{l}
\\
x + \varepsilon
\end{array}
Initial program 86.8%
Taylor expanded in x around 0
Applied rewrites4.6%
herbie shell --seed 2024321
(FPCore (x eps)
:name "ENA, Section 1.4, Exercise 4b, n=5"
:precision binary64
:pre (and (and (<= -1000000000.0 x) (<= x 1000000000.0)) (and (<= -1.0 eps) (<= eps 1.0)))
(- (pow (+ x eps) 5.0) (pow x 5.0)))