
(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 6 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 (or (<= x -3.15e-49) (not (<= x 4e-35)))
(*
(pow x 4.0)
(- (* eps 5.0) (* (/ (* (* eps eps) (+ x eps)) (* x x)) -10.0)))
(pow eps 5.0)))
double code(double x, double eps) {
double tmp;
if ((x <= -3.15e-49) || !(x <= 4e-35)) {
tmp = pow(x, 4.0) * ((eps * 5.0) - ((((eps * eps) * (x + eps)) / (x * x)) * -10.0));
} else {
tmp = pow(eps, 5.0);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((x <= (-3.15d-49)) .or. (.not. (x <= 4d-35))) then
tmp = (x ** 4.0d0) * ((eps * 5.0d0) - ((((eps * eps) * (x + eps)) / (x * x)) * (-10.0d0)))
else
tmp = eps ** 5.0d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((x <= -3.15e-49) || !(x <= 4e-35)) {
tmp = Math.pow(x, 4.0) * ((eps * 5.0) - ((((eps * eps) * (x + eps)) / (x * x)) * -10.0));
} else {
tmp = Math.pow(eps, 5.0);
}
return tmp;
}
def code(x, eps): tmp = 0 if (x <= -3.15e-49) or not (x <= 4e-35): tmp = math.pow(x, 4.0) * ((eps * 5.0) - ((((eps * eps) * (x + eps)) / (x * x)) * -10.0)) else: tmp = math.pow(eps, 5.0) return tmp
function code(x, eps) tmp = 0.0 if ((x <= -3.15e-49) || !(x <= 4e-35)) tmp = Float64((x ^ 4.0) * Float64(Float64(eps * 5.0) - Float64(Float64(Float64(Float64(eps * eps) * Float64(x + eps)) / Float64(x * x)) * -10.0))); else tmp = eps ^ 5.0; end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((x <= -3.15e-49) || ~((x <= 4e-35))) tmp = (x ^ 4.0) * ((eps * 5.0) - ((((eps * eps) * (x + eps)) / (x * x)) * -10.0)); else tmp = eps ^ 5.0; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[x, -3.15e-49], N[Not[LessEqual[x, 4e-35]], $MachinePrecision]], N[(N[Power[x, 4.0], $MachinePrecision] * N[(N[(eps * 5.0), $MachinePrecision] - N[(N[(N[(N[(eps * eps), $MachinePrecision] * N[(x + eps), $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision] * -10.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[eps, 5.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.15 \cdot 10^{-49} \lor \neg \left(x \leq 4 \cdot 10^{-35}\right):\\
\;\;\;\;{x}^{4} \cdot \left(\varepsilon \cdot 5 - \frac{\left(\varepsilon \cdot \varepsilon\right) \cdot \left(x + \varepsilon\right)}{x \cdot x} \cdot -10\right)\\
\mathbf{else}:\\
\;\;\;\;{\varepsilon}^{5}\\
\end{array}
\end{array}
if x < -3.1499999999999998e-49 or 4.00000000000000003e-35 < x Initial program 25.8%
Taylor expanded in x around -inf 98.6%
Simplified98.6%
cube-mult98.6%
Applied egg-rr98.6%
Taylor expanded in x around 0 98.6%
distribute-lft-in98.6%
unpow298.6%
associate-/l*98.6%
unpow298.6%
unpow398.6%
distribute-lft-out98.6%
Simplified98.6%
if -3.1499999999999998e-49 < x < 4.00000000000000003e-35Initial program 100.0%
Taylor expanded in x around 0 100.0%
Final simplification99.8%
(FPCore (x eps)
:precision binary64
(if (or (<= x -1.85e-50) (not (<= x 4e-35)))
(*
(-
(* eps 5.0)
(/ (- (* (* eps eps) -10.0) (* (* eps (* eps eps)) (/ 10.0 x))) x))
(* (* x x) (* x x)))
(pow eps 5.0)))
double code(double x, double eps) {
double tmp;
if ((x <= -1.85e-50) || !(x <= 4e-35)) {
tmp = ((eps * 5.0) - ((((eps * eps) * -10.0) - ((eps * (eps * eps)) * (10.0 / x))) / x)) * ((x * x) * (x * x));
} else {
tmp = pow(eps, 5.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.85d-50)) .or. (.not. (x <= 4d-35))) then
tmp = ((eps * 5.0d0) - ((((eps * eps) * (-10.0d0)) - ((eps * (eps * eps)) * (10.0d0 / x))) / x)) * ((x * x) * (x * x))
else
tmp = eps ** 5.0d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((x <= -1.85e-50) || !(x <= 4e-35)) {
tmp = ((eps * 5.0) - ((((eps * eps) * -10.0) - ((eps * (eps * eps)) * (10.0 / x))) / x)) * ((x * x) * (x * x));
} else {
tmp = Math.pow(eps, 5.0);
}
return tmp;
}
def code(x, eps): tmp = 0 if (x <= -1.85e-50) or not (x <= 4e-35): tmp = ((eps * 5.0) - ((((eps * eps) * -10.0) - ((eps * (eps * eps)) * (10.0 / x))) / x)) * ((x * x) * (x * x)) else: tmp = math.pow(eps, 5.0) return tmp
function code(x, eps) tmp = 0.0 if ((x <= -1.85e-50) || !(x <= 4e-35)) tmp = Float64(Float64(Float64(eps * 5.0) - Float64(Float64(Float64(Float64(eps * eps) * -10.0) - Float64(Float64(eps * Float64(eps * eps)) * Float64(10.0 / x))) / x)) * Float64(Float64(x * x) * Float64(x * x))); else tmp = eps ^ 5.0; end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((x <= -1.85e-50) || ~((x <= 4e-35))) tmp = ((eps * 5.0) - ((((eps * eps) * -10.0) - ((eps * (eps * eps)) * (10.0 / x))) / x)) * ((x * x) * (x * x)); else tmp = eps ^ 5.0; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[x, -1.85e-50], N[Not[LessEqual[x, 4e-35]], $MachinePrecision]], N[(N[(N[(eps * 5.0), $MachinePrecision] - N[(N[(N[(N[(eps * eps), $MachinePrecision] * -10.0), $MachinePrecision] - N[(N[(eps * N[(eps * eps), $MachinePrecision]), $MachinePrecision] * N[(10.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[eps, 5.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.85 \cdot 10^{-50} \lor \neg \left(x \leq 4 \cdot 10^{-35}\right):\\
\;\;\;\;\left(\varepsilon \cdot 5 - \frac{\left(\varepsilon \cdot \varepsilon\right) \cdot -10 - \left(\varepsilon \cdot \left(\varepsilon \cdot \varepsilon\right)\right) \cdot \frac{10}{x}}{x}\right) \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;{\varepsilon}^{5}\\
\end{array}
\end{array}
if x < -1.85e-50 or 4.00000000000000003e-35 < x Initial program 25.8%
Taylor expanded in x around -inf 98.6%
Simplified98.6%
*-commutative98.6%
associate-/l*98.6%
cube-mult98.6%
metadata-eval98.6%
pow-prod-up98.4%
pow298.4%
pow298.4%
Applied egg-rr98.4%
if -1.85e-50 < x < 4.00000000000000003e-35Initial program 100.0%
Taylor expanded in x around 0 100.0%
Final simplification99.7%
(FPCore (x eps) :precision binary64 (* (* (* x x) (* x x)) (- (* eps 5.0) (* (/ (* eps eps) x) -10.0))))
double code(double x, double eps) {
return ((x * x) * (x * x)) * ((eps * 5.0) - (((eps * eps) / x) * -10.0));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = ((x * x) * (x * x)) * ((eps * 5.0d0) - (((eps * eps) / x) * (-10.0d0)))
end function
public static double code(double x, double eps) {
return ((x * x) * (x * x)) * ((eps * 5.0) - (((eps * eps) / x) * -10.0));
}
def code(x, eps): return ((x * x) * (x * x)) * ((eps * 5.0) - (((eps * eps) / x) * -10.0))
function code(x, eps) return Float64(Float64(Float64(x * x) * Float64(x * x)) * Float64(Float64(eps * 5.0) - Float64(Float64(Float64(eps * eps) / x) * -10.0))) end
function tmp = code(x, eps) tmp = ((x * x) * (x * x)) * ((eps * 5.0) - (((eps * eps) / x) * -10.0)); end
code[x_, eps_] := N[(N[(N[(x * x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision] * N[(N[(eps * 5.0), $MachinePrecision] - N[(N[(N[(eps * eps), $MachinePrecision] / x), $MachinePrecision] * -10.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right) \cdot \left(\varepsilon \cdot 5 - \frac{\varepsilon \cdot \varepsilon}{x} \cdot -10\right)
\end{array}
Initial program 86.7%
Taylor expanded in x around -inf 86.5%
+-commutative86.5%
associate-+r+86.5%
mul-1-neg86.5%
unsub-neg86.5%
distribute-rgt1-in86.5%
metadata-eval86.5%
*-commutative86.5%
Simplified86.5%
*-commutative86.5%
*-commutative86.5%
*-un-lft-identity86.5%
times-frac86.5%
metadata-eval86.5%
metadata-eval86.5%
pow-prod-up86.5%
pow286.5%
pow286.5%
Applied egg-rr86.5%
Final simplification86.5%
(FPCore (x eps) :precision binary64 (* eps (* (* x x) (* 5.0 (* x x)))))
double code(double x, double eps) {
return eps * ((x * x) * (5.0 * (x * x)));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = eps * ((x * x) * (5.0d0 * (x * x)))
end function
public static double code(double x, double eps) {
return eps * ((x * x) * (5.0 * (x * x)));
}
def code(x, eps): return eps * ((x * x) * (5.0 * (x * x)))
function code(x, eps) return Float64(eps * Float64(Float64(x * x) * Float64(5.0 * Float64(x * x)))) end
function tmp = code(x, eps) tmp = eps * ((x * x) * (5.0 * (x * x))); end
code[x_, eps_] := N[(eps * N[(N[(x * x), $MachinePrecision] * N[(5.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\varepsilon \cdot \left(\left(x \cdot x\right) \cdot \left(5 \cdot \left(x \cdot x\right)\right)\right)
\end{array}
Initial program 86.7%
Taylor expanded in eps around 0 86.3%
*-commutative86.3%
distribute-lft1-in86.3%
metadata-eval86.3%
metadata-eval86.3%
pow-prod-up86.3%
pow286.3%
pow286.3%
Applied egg-rr86.3%
associate-*r*86.3%
Applied egg-rr86.3%
Final simplification86.3%
(FPCore (x eps) :precision binary64 (* eps (* 5.0 (* (* x x) (* x x)))))
double code(double x, double eps) {
return eps * (5.0 * ((x * x) * (x * x)));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = eps * (5.0d0 * ((x * x) * (x * x)))
end function
public static double code(double x, double eps) {
return eps * (5.0 * ((x * x) * (x * x)));
}
def code(x, eps): return eps * (5.0 * ((x * x) * (x * x)))
function code(x, eps) return Float64(eps * Float64(5.0 * Float64(Float64(x * x) * Float64(x * x)))) end
function tmp = code(x, eps) tmp = eps * (5.0 * ((x * x) * (x * x))); end
code[x_, eps_] := N[(eps * N[(5.0 * N[(N[(x * x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\varepsilon \cdot \left(5 \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)\right)
\end{array}
Initial program 86.7%
Taylor expanded in eps around 0 86.3%
*-commutative86.3%
distribute-lft1-in86.3%
metadata-eval86.3%
metadata-eval86.3%
pow-prod-up86.3%
pow286.3%
pow286.3%
Applied egg-rr86.3%
Final simplification86.3%
(FPCore (x eps) :precision binary64 (* x (* (* eps 5.0) (* x (* x x)))))
double code(double x, double eps) {
return x * ((eps * 5.0) * (x * (x * x)));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = x * ((eps * 5.0d0) * (x * (x * x)))
end function
public static double code(double x, double eps) {
return x * ((eps * 5.0) * (x * (x * x)));
}
def code(x, eps): return x * ((eps * 5.0) * (x * (x * x)))
function code(x, eps) return Float64(x * Float64(Float64(eps * 5.0) * Float64(x * Float64(x * x)))) end
function tmp = code(x, eps) tmp = x * ((eps * 5.0) * (x * (x * x))); end
code[x_, eps_] := N[(x * N[(N[(eps * 5.0), $MachinePrecision] * N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(\left(\varepsilon \cdot 5\right) \cdot \left(x \cdot \left(x \cdot x\right)\right)\right)
\end{array}
Initial program 86.7%
Taylor expanded in x around inf 86.3%
distribute-rgt1-in86.3%
metadata-eval86.3%
*-commutative86.3%
Simplified86.3%
metadata-eval86.3%
pow-prod-up86.3%
pow286.3%
pow286.3%
associate-*l*86.2%
Applied egg-rr86.2%
associate-*l*86.3%
Applied egg-rr86.3%
Final simplification86.3%
herbie shell --seed 2024097
(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)))