
(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 7 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
(if (<= x 2.8e-42)
(- (pow (+ x eps) 5.0) (pow x 5.0))
(fma
eps
(* 5.0 (pow x 4.0))
(fma
(pow eps 2.0)
(* (pow x 3.0) 10.0)
(* x (+ (* x (* 10.0 (pow eps 3.0))) (* 5.0 (pow eps 4.0))))))))
double code(double x, double eps) {
double tmp;
if (x <= 2.8e-42) {
tmp = pow((x + eps), 5.0) - pow(x, 5.0);
} else {
tmp = fma(eps, (5.0 * pow(x, 4.0)), fma(pow(eps, 2.0), (pow(x, 3.0) * 10.0), (x * ((x * (10.0 * pow(eps, 3.0))) + (5.0 * pow(eps, 4.0))))));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= 2.8e-42) tmp = Float64((Float64(x + eps) ^ 5.0) - (x ^ 5.0)); else tmp = fma(eps, Float64(5.0 * (x ^ 4.0)), fma((eps ^ 2.0), Float64((x ^ 3.0) * 10.0), Float64(x * Float64(Float64(x * Float64(10.0 * (eps ^ 3.0))) + Float64(5.0 * (eps ^ 4.0)))))); end return tmp end
code[x_, eps_] := If[LessEqual[x, 2.8e-42], N[(N[Power[N[(x + eps), $MachinePrecision], 5.0], $MachinePrecision] - N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision], N[(eps * N[(5.0 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] + N[(N[Power[eps, 2.0], $MachinePrecision] * N[(N[Power[x, 3.0], $MachinePrecision] * 10.0), $MachinePrecision] + N[(x * N[(N[(x * N[(10.0 * N[Power[eps, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(5.0 * N[Power[eps, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.8 \cdot 10^{-42}:\\
\;\;\;\;{\left(x + \varepsilon\right)}^{5} - {x}^{5}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\varepsilon, 5 \cdot {x}^{4}, \mathsf{fma}\left({\varepsilon}^{2}, {x}^{3} \cdot 10, x \cdot \left(x \cdot \left(10 \cdot {\varepsilon}^{3}\right) + 5 \cdot {\varepsilon}^{4}\right)\right)\right)\\
\end{array}
\end{array}
if x < 2.79999999999999998e-42Initial program 96.8%
if 2.79999999999999998e-42 < x Initial program 44.3%
Taylor expanded in x around inf 94.9%
Simplified95.2%
Final simplification96.6%
(FPCore (x eps)
:precision binary64
(if (<= x 1.6e-43)
(- (pow (+ x eps) 5.0) (pow x 5.0))
(fma
eps
(* 5.0 (pow x 4.0))
(* (* (pow eps 2.0) 10.0) (* (+ x eps) (pow x 2.0))))))
double code(double x, double eps) {
double tmp;
if (x <= 1.6e-43) {
tmp = pow((x + eps), 5.0) - pow(x, 5.0);
} else {
tmp = fma(eps, (5.0 * pow(x, 4.0)), ((pow(eps, 2.0) * 10.0) * ((x + eps) * pow(x, 2.0))));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= 1.6e-43) tmp = Float64((Float64(x + eps) ^ 5.0) - (x ^ 5.0)); else tmp = fma(eps, Float64(5.0 * (x ^ 4.0)), Float64(Float64((eps ^ 2.0) * 10.0) * Float64(Float64(x + eps) * (x ^ 2.0)))); end return tmp end
code[x_, eps_] := If[LessEqual[x, 1.6e-43], N[(N[Power[N[(x + eps), $MachinePrecision], 5.0], $MachinePrecision] - N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision], N[(eps * N[(5.0 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Power[eps, 2.0], $MachinePrecision] * 10.0), $MachinePrecision] * N[(N[(x + eps), $MachinePrecision] * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.6 \cdot 10^{-43}:\\
\;\;\;\;{\left(x + \varepsilon\right)}^{5} - {x}^{5}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\varepsilon, 5 \cdot {x}^{4}, \left({\varepsilon}^{2} \cdot 10\right) \cdot \left(\left(x + \varepsilon\right) \cdot {x}^{2}\right)\right)\\
\end{array}
\end{array}
if x < 1.59999999999999992e-43Initial program 96.8%
if 1.59999999999999992e-43 < x Initial program 44.3%
Taylor expanded in x around inf 94.5%
Simplified94.8%
expm1-log1p-u94.8%
expm1-udef92.0%
+-commutative92.0%
associate-*r*92.0%
distribute-rgt-out92.0%
Applied egg-rr92.0%
expm1-def94.8%
expm1-log1p94.8%
associate-*r*94.8%
*-commutative94.8%
cube-mult94.8%
unpow294.8%
distribute-rgt-out94.8%
Simplified94.8%
Final simplification96.6%
(FPCore (x eps) :precision binary64 (if (<= x 1.5e-43) (- (pow (+ x eps) 5.0) (pow x 5.0)) (* eps (+ (* 5.0 (pow x 4.0)) (* eps (* (pow x 3.0) 10.0))))))
double code(double x, double eps) {
double tmp;
if (x <= 1.5e-43) {
tmp = pow((x + eps), 5.0) - pow(x, 5.0);
} else {
tmp = eps * ((5.0 * pow(x, 4.0)) + (eps * (pow(x, 3.0) * 10.0)));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (x <= 1.5d-43) then
tmp = ((x + eps) ** 5.0d0) - (x ** 5.0d0)
else
tmp = eps * ((5.0d0 * (x ** 4.0d0)) + (eps * ((x ** 3.0d0) * 10.0d0)))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (x <= 1.5e-43) {
tmp = Math.pow((x + eps), 5.0) - Math.pow(x, 5.0);
} else {
tmp = eps * ((5.0 * Math.pow(x, 4.0)) + (eps * (Math.pow(x, 3.0) * 10.0)));
}
return tmp;
}
def code(x, eps): tmp = 0 if x <= 1.5e-43: tmp = math.pow((x + eps), 5.0) - math.pow(x, 5.0) else: tmp = eps * ((5.0 * math.pow(x, 4.0)) + (eps * (math.pow(x, 3.0) * 10.0))) return tmp
function code(x, eps) tmp = 0.0 if (x <= 1.5e-43) tmp = Float64((Float64(x + eps) ^ 5.0) - (x ^ 5.0)); else tmp = Float64(eps * Float64(Float64(5.0 * (x ^ 4.0)) + Float64(eps * Float64((x ^ 3.0) * 10.0)))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (x <= 1.5e-43) tmp = ((x + eps) ^ 5.0) - (x ^ 5.0); else tmp = eps * ((5.0 * (x ^ 4.0)) + (eps * ((x ^ 3.0) * 10.0))); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[x, 1.5e-43], N[(N[Power[N[(x + eps), $MachinePrecision], 5.0], $MachinePrecision] - N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision], N[(eps * N[(N[(5.0 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] + N[(eps * N[(N[Power[x, 3.0], $MachinePrecision] * 10.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.5 \cdot 10^{-43}:\\
\;\;\;\;{\left(x + \varepsilon\right)}^{5} - {x}^{5}\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(5 \cdot {x}^{4} + \varepsilon \cdot \left({x}^{3} \cdot 10\right)\right)\\
\end{array}
\end{array}
if x < 1.50000000000000002e-43Initial program 96.8%
if 1.50000000000000002e-43 < x Initial program 44.3%
Taylor expanded in x around inf 93.0%
Simplified93.4%
Final simplification96.5%
(FPCore (x eps) :precision binary64 (if (<= x 1.1e-43) (- (pow (+ x eps) 5.0) (pow x 5.0)) (* eps (* 5.0 (pow x 4.0)))))
double code(double x, double eps) {
double tmp;
if (x <= 1.1e-43) {
tmp = pow((x + eps), 5.0) - pow(x, 5.0);
} else {
tmp = eps * (5.0 * pow(x, 4.0));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (x <= 1.1d-43) then
tmp = ((x + eps) ** 5.0d0) - (x ** 5.0d0)
else
tmp = eps * (5.0d0 * (x ** 4.0d0))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (x <= 1.1e-43) {
tmp = Math.pow((x + eps), 5.0) - Math.pow(x, 5.0);
} else {
tmp = eps * (5.0 * Math.pow(x, 4.0));
}
return tmp;
}
def code(x, eps): tmp = 0 if x <= 1.1e-43: tmp = math.pow((x + eps), 5.0) - math.pow(x, 5.0) else: tmp = eps * (5.0 * math.pow(x, 4.0)) return tmp
function code(x, eps) tmp = 0.0 if (x <= 1.1e-43) tmp = Float64((Float64(x + eps) ^ 5.0) - (x ^ 5.0)); else tmp = Float64(eps * Float64(5.0 * (x ^ 4.0))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (x <= 1.1e-43) tmp = ((x + eps) ^ 5.0) - (x ^ 5.0); else tmp = eps * (5.0 * (x ^ 4.0)); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[x, 1.1e-43], N[(N[Power[N[(x + eps), $MachinePrecision], 5.0], $MachinePrecision] - N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision], N[(eps * N[(5.0 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.1 \cdot 10^{-43}:\\
\;\;\;\;{\left(x + \varepsilon\right)}^{5} - {x}^{5}\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(5 \cdot {x}^{4}\right)\\
\end{array}
\end{array}
if x < 1.09999999999999999e-43Initial program 96.8%
if 1.09999999999999999e-43 < x Initial program 44.3%
Taylor expanded in x around inf 91.7%
*-commutative91.7%
distribute-rgt1-in91.7%
metadata-eval91.7%
*-commutative91.7%
associate-*r*92.0%
Simplified92.0%
Final simplification96.4%
(FPCore (x eps) :precision binary64 (if (<= x 8.2e-44) (pow eps 5.0) (* 5.0 (* eps (pow x 4.0)))))
double code(double x, double eps) {
double tmp;
if (x <= 8.2e-44) {
tmp = pow(eps, 5.0);
} else {
tmp = 5.0 * (eps * pow(x, 4.0));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (x <= 8.2d-44) then
tmp = eps ** 5.0d0
else
tmp = 5.0d0 * (eps * (x ** 4.0d0))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (x <= 8.2e-44) {
tmp = Math.pow(eps, 5.0);
} else {
tmp = 5.0 * (eps * Math.pow(x, 4.0));
}
return tmp;
}
def code(x, eps): tmp = 0 if x <= 8.2e-44: tmp = math.pow(eps, 5.0) else: tmp = 5.0 * (eps * math.pow(x, 4.0)) return tmp
function code(x, eps) tmp = 0.0 if (x <= 8.2e-44) tmp = eps ^ 5.0; else tmp = Float64(5.0 * Float64(eps * (x ^ 4.0))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (x <= 8.2e-44) tmp = eps ^ 5.0; else tmp = 5.0 * (eps * (x ^ 4.0)); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[x, 8.2e-44], N[Power[eps, 5.0], $MachinePrecision], N[(5.0 * N[(eps * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 8.2 \cdot 10^{-44}:\\
\;\;\;\;{\varepsilon}^{5}\\
\mathbf{else}:\\
\;\;\;\;5 \cdot \left(\varepsilon \cdot {x}^{4}\right)\\
\end{array}
\end{array}
if x < 8.19999999999999984e-44Initial program 96.8%
Taylor expanded in x around 0 94.9%
if 8.19999999999999984e-44 < x Initial program 44.3%
add-cube-cbrt44.4%
pow244.4%
Applied egg-rr44.4%
Taylor expanded in x around inf 91.7%
*-commutative91.7%
distribute-rgt1-in91.7%
metadata-eval91.7%
associate-*l*91.7%
Simplified91.7%
Final simplification94.7%
(FPCore (x eps) :precision binary64 (if (<= x 8.5e-44) (pow eps 5.0) (* eps (* 5.0 (pow x 4.0)))))
double code(double x, double eps) {
double tmp;
if (x <= 8.5e-44) {
tmp = pow(eps, 5.0);
} else {
tmp = eps * (5.0 * pow(x, 4.0));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (x <= 8.5d-44) then
tmp = eps ** 5.0d0
else
tmp = eps * (5.0d0 * (x ** 4.0d0))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (x <= 8.5e-44) {
tmp = Math.pow(eps, 5.0);
} else {
tmp = eps * (5.0 * Math.pow(x, 4.0));
}
return tmp;
}
def code(x, eps): tmp = 0 if x <= 8.5e-44: tmp = math.pow(eps, 5.0) else: tmp = eps * (5.0 * math.pow(x, 4.0)) return tmp
function code(x, eps) tmp = 0.0 if (x <= 8.5e-44) tmp = eps ^ 5.0; else tmp = Float64(eps * Float64(5.0 * (x ^ 4.0))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (x <= 8.5e-44) tmp = eps ^ 5.0; else tmp = eps * (5.0 * (x ^ 4.0)); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[x, 8.5e-44], N[Power[eps, 5.0], $MachinePrecision], N[(eps * N[(5.0 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 8.5 \cdot 10^{-44}:\\
\;\;\;\;{\varepsilon}^{5}\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(5 \cdot {x}^{4}\right)\\
\end{array}
\end{array}
if x < 8.5000000000000002e-44Initial program 96.8%
Taylor expanded in x around 0 94.9%
if 8.5000000000000002e-44 < x Initial program 44.3%
Taylor expanded in x around inf 91.7%
*-commutative91.7%
distribute-rgt1-in91.7%
metadata-eval91.7%
*-commutative91.7%
associate-*r*92.0%
Simplified92.0%
Final simplification94.7%
(FPCore (x eps) :precision binary64 (pow eps 5.0))
double code(double x, double eps) {
return pow(eps, 5.0);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = eps ** 5.0d0
end function
public static double code(double x, double eps) {
return Math.pow(eps, 5.0);
}
def code(x, eps): return math.pow(eps, 5.0)
function code(x, eps) return eps ^ 5.0 end
function tmp = code(x, eps) tmp = eps ^ 5.0; end
code[x_, eps_] := N[Power[eps, 5.0], $MachinePrecision]
\begin{array}{l}
\\
{\varepsilon}^{5}
\end{array}
Initial program 92.9%
Taylor expanded in x around 0 90.6%
Final simplification90.6%
herbie shell --seed 2024031
(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)))