
(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
(let* ((t_0 (- (pow (+ x eps) 5.0) (pow x 5.0))))
(if (or (<= t_0 -1e-304) (not (<= t_0 0.0)))
t_0
(* eps (* (* x x) (* x (* x 5.0)))))))
double code(double x, double eps) {
double t_0 = pow((x + eps), 5.0) - pow(x, 5.0);
double tmp;
if ((t_0 <= -1e-304) || !(t_0 <= 0.0)) {
tmp = t_0;
} else {
tmp = eps * ((x * x) * (x * (x * 5.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) - (x ** 5.0d0)
if ((t_0 <= (-1d-304)) .or. (.not. (t_0 <= 0.0d0))) then
tmp = t_0
else
tmp = eps * ((x * x) * (x * (x * 5.0d0)))
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.pow((x + eps), 5.0) - Math.pow(x, 5.0);
double tmp;
if ((t_0 <= -1e-304) || !(t_0 <= 0.0)) {
tmp = t_0;
} else {
tmp = eps * ((x * x) * (x * (x * 5.0)));
}
return tmp;
}
def code(x, eps): t_0 = math.pow((x + eps), 5.0) - math.pow(x, 5.0) tmp = 0 if (t_0 <= -1e-304) or not (t_0 <= 0.0): tmp = t_0 else: tmp = eps * ((x * x) * (x * (x * 5.0))) return tmp
function code(x, eps) t_0 = Float64((Float64(x + eps) ^ 5.0) - (x ^ 5.0)) tmp = 0.0 if ((t_0 <= -1e-304) || !(t_0 <= 0.0)) tmp = t_0; else tmp = Float64(eps * Float64(Float64(x * x) * Float64(x * Float64(x * 5.0)))); end return tmp end
function tmp_2 = code(x, eps) t_0 = ((x + eps) ^ 5.0) - (x ^ 5.0); tmp = 0.0; if ((t_0 <= -1e-304) || ~((t_0 <= 0.0))) tmp = t_0; else tmp = eps * ((x * x) * (x * (x * 5.0))); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Power[N[(x + eps), $MachinePrecision], 5.0], $MachinePrecision] - N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -1e-304], N[Not[LessEqual[t$95$0, 0.0]], $MachinePrecision]], t$95$0, N[(eps * N[(N[(x * x), $MachinePrecision] * N[(x * N[(x * 5.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left(x + \varepsilon\right)}^{5} - {x}^{5}\\
\mathbf{if}\;t_0 \leq -1 \cdot 10^{-304} \lor \neg \left(t_0 \leq 0\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot \left(x \cdot 5\right)\right)\right)\\
\end{array}
\end{array}
if (-.f64 (pow.f64 (+.f64 x eps) 5) (pow.f64 x 5)) < -9.99999999999999971e-305 or 0.0 < (-.f64 (pow.f64 (+.f64 x eps) 5) (pow.f64 x 5)) Initial program 96.9%
if -9.99999999999999971e-305 < (-.f64 (pow.f64 (+.f64 x eps) 5) (pow.f64 x 5)) < 0.0Initial program 87.1%
Taylor expanded in x around inf 99.9%
*-commutative99.9%
distribute-rgt1-in99.9%
metadata-eval99.9%
*-commutative99.9%
associate-*r*99.9%
Simplified99.9%
add-sqr-sqrt99.9%
sqrt-unprod99.6%
*-commutative99.6%
*-commutative99.6%
swap-sqr99.6%
pow-prod-up99.6%
metadata-eval99.6%
metadata-eval99.6%
Applied egg-rr99.6%
sqrt-prod99.6%
metadata-eval99.6%
sqrt-pow199.9%
metadata-eval99.9%
metadata-eval99.9%
pow-sqr99.9%
pow299.9%
pow299.9%
add-sqr-sqrt99.8%
swap-sqr99.8%
unpow299.8%
associate-*l*99.9%
unpow-prod-down99.9%
pow299.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 99.8%
unpow299.8%
associate-*l*99.8%
unpow299.8%
rem-square-sqrt99.9%
Simplified99.9%
Final simplification99.4%
(FPCore (x eps) :precision binary64 (if (<= x -3.8e-46) (* eps (* (* x x) (* x (* x 5.0)))) (if (<= x 4.6e-43) (pow eps 5.0) (* eps (sqrt (* (pow x 8.0) 25.0))))))
double code(double x, double eps) {
double tmp;
if (x <= -3.8e-46) {
tmp = eps * ((x * x) * (x * (x * 5.0)));
} else if (x <= 4.6e-43) {
tmp = pow(eps, 5.0);
} else {
tmp = eps * sqrt((pow(x, 8.0) * 25.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.8d-46)) then
tmp = eps * ((x * x) * (x * (x * 5.0d0)))
else if (x <= 4.6d-43) then
tmp = eps ** 5.0d0
else
tmp = eps * sqrt(((x ** 8.0d0) * 25.0d0))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (x <= -3.8e-46) {
tmp = eps * ((x * x) * (x * (x * 5.0)));
} else if (x <= 4.6e-43) {
tmp = Math.pow(eps, 5.0);
} else {
tmp = eps * Math.sqrt((Math.pow(x, 8.0) * 25.0));
}
return tmp;
}
def code(x, eps): tmp = 0 if x <= -3.8e-46: tmp = eps * ((x * x) * (x * (x * 5.0))) elif x <= 4.6e-43: tmp = math.pow(eps, 5.0) else: tmp = eps * math.sqrt((math.pow(x, 8.0) * 25.0)) return tmp
function code(x, eps) tmp = 0.0 if (x <= -3.8e-46) tmp = Float64(eps * Float64(Float64(x * x) * Float64(x * Float64(x * 5.0)))); elseif (x <= 4.6e-43) tmp = eps ^ 5.0; else tmp = Float64(eps * sqrt(Float64((x ^ 8.0) * 25.0))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (x <= -3.8e-46) tmp = eps * ((x * x) * (x * (x * 5.0))); elseif (x <= 4.6e-43) tmp = eps ^ 5.0; else tmp = eps * sqrt(((x ^ 8.0) * 25.0)); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[x, -3.8e-46], N[(eps * N[(N[(x * x), $MachinePrecision] * N[(x * N[(x * 5.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 4.6e-43], N[Power[eps, 5.0], $MachinePrecision], N[(eps * N[Sqrt[N[(N[Power[x, 8.0], $MachinePrecision] * 25.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.8 \cdot 10^{-46}:\\
\;\;\;\;\varepsilon \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot \left(x \cdot 5\right)\right)\right)\\
\mathbf{elif}\;x \leq 4.6 \cdot 10^{-43}:\\
\;\;\;\;{\varepsilon}^{5}\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \sqrt{{x}^{8} \cdot 25}\\
\end{array}
\end{array}
if x < -3.7999999999999997e-46Initial program 30.9%
Taylor expanded in x around inf 89.6%
*-commutative89.6%
distribute-rgt1-in89.6%
metadata-eval89.6%
*-commutative89.6%
associate-*r*89.6%
Simplified89.6%
add-sqr-sqrt89.4%
sqrt-unprod86.1%
*-commutative86.1%
*-commutative86.1%
swap-sqr86.3%
pow-prod-up86.5%
metadata-eval86.5%
metadata-eval86.5%
Applied egg-rr86.5%
sqrt-prod86.2%
metadata-eval86.2%
sqrt-pow189.6%
metadata-eval89.6%
metadata-eval89.6%
pow-sqr89.3%
pow289.3%
pow289.3%
add-sqr-sqrt88.8%
swap-sqr89.1%
unpow289.1%
associate-*l*89.5%
unpow-prod-down89.2%
pow289.2%
Applied egg-rr89.2%
Taylor expanded in x around 0 88.9%
unpow288.9%
associate-*l*88.9%
unpow288.9%
rem-square-sqrt89.7%
Simplified89.7%
if -3.7999999999999997e-46 < x < 4.5999999999999998e-43Initial program 100.0%
Taylor expanded in x around 0 100.0%
if 4.5999999999999998e-43 < x Initial program 33.1%
Taylor expanded in x around inf 99.7%
*-commutative99.7%
distribute-rgt1-in99.7%
metadata-eval99.7%
*-commutative99.7%
associate-*r*99.7%
Simplified99.7%
add-sqr-sqrt99.4%
sqrt-unprod99.7%
*-commutative99.7%
*-commutative99.7%
swap-sqr99.6%
pow-prod-up99.8%
metadata-eval99.8%
metadata-eval99.8%
Applied egg-rr99.8%
Final simplification99.1%
(FPCore (x eps) :precision binary64 (if (<= x -4.8e-47) (* eps (* (* x x) (* x (* x 5.0)))) (if (<= x 1.4e-43) (pow eps 5.0) (* eps (* 5.0 (pow x 4.0))))))
double code(double x, double eps) {
double tmp;
if (x <= -4.8e-47) {
tmp = eps * ((x * x) * (x * (x * 5.0)));
} else if (x <= 1.4e-43) {
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 <= (-4.8d-47)) then
tmp = eps * ((x * x) * (x * (x * 5.0d0)))
else if (x <= 1.4d-43) 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 <= -4.8e-47) {
tmp = eps * ((x * x) * (x * (x * 5.0)));
} else if (x <= 1.4e-43) {
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 <= -4.8e-47: tmp = eps * ((x * x) * (x * (x * 5.0))) elif x <= 1.4e-43: 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 <= -4.8e-47) tmp = Float64(eps * Float64(Float64(x * x) * Float64(x * Float64(x * 5.0)))); elseif (x <= 1.4e-43) 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 <= -4.8e-47) tmp = eps * ((x * x) * (x * (x * 5.0))); elseif (x <= 1.4e-43) tmp = eps ^ 5.0; else tmp = eps * (5.0 * (x ^ 4.0)); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[x, -4.8e-47], N[(eps * N[(N[(x * x), $MachinePrecision] * N[(x * N[(x * 5.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.4e-43], 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 -4.8 \cdot 10^{-47}:\\
\;\;\;\;\varepsilon \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot \left(x \cdot 5\right)\right)\right)\\
\mathbf{elif}\;x \leq 1.4 \cdot 10^{-43}:\\
\;\;\;\;{\varepsilon}^{5}\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(5 \cdot {x}^{4}\right)\\
\end{array}
\end{array}
if x < -4.7999999999999999e-47Initial program 30.9%
Taylor expanded in x around inf 89.6%
*-commutative89.6%
distribute-rgt1-in89.6%
metadata-eval89.6%
*-commutative89.6%
associate-*r*89.6%
Simplified89.6%
add-sqr-sqrt89.4%
sqrt-unprod86.1%
*-commutative86.1%
*-commutative86.1%
swap-sqr86.3%
pow-prod-up86.5%
metadata-eval86.5%
metadata-eval86.5%
Applied egg-rr86.5%
sqrt-prod86.2%
metadata-eval86.2%
sqrt-pow189.6%
metadata-eval89.6%
metadata-eval89.6%
pow-sqr89.3%
pow289.3%
pow289.3%
add-sqr-sqrt88.8%
swap-sqr89.1%
unpow289.1%
associate-*l*89.5%
unpow-prod-down89.2%
pow289.2%
Applied egg-rr89.2%
Taylor expanded in x around 0 88.9%
unpow288.9%
associate-*l*88.9%
unpow288.9%
rem-square-sqrt89.7%
Simplified89.7%
if -4.7999999999999999e-47 < x < 1.3999999999999999e-43Initial program 100.0%
Taylor expanded in x around 0 100.0%
if 1.3999999999999999e-43 < x Initial program 33.1%
Taylor expanded in x around inf 99.7%
*-commutative99.7%
distribute-rgt1-in99.7%
metadata-eval99.7%
*-commutative99.7%
associate-*r*99.7%
Simplified99.7%
Final simplification99.1%
(FPCore (x eps) :precision binary64 (if (or (<= x -8e-47) (not (<= x 4.8e-44))) (* eps (* (* x x) (* x (* x 5.0)))) (pow eps 5.0)))
double code(double x, double eps) {
double tmp;
if ((x <= -8e-47) || !(x <= 4.8e-44)) {
tmp = eps * ((x * x) * (x * (x * 5.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 <= (-8d-47)) .or. (.not. (x <= 4.8d-44))) then
tmp = eps * ((x * x) * (x * (x * 5.0d0)))
else
tmp = eps ** 5.0d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((x <= -8e-47) || !(x <= 4.8e-44)) {
tmp = eps * ((x * x) * (x * (x * 5.0)));
} else {
tmp = Math.pow(eps, 5.0);
}
return tmp;
}
def code(x, eps): tmp = 0 if (x <= -8e-47) or not (x <= 4.8e-44): tmp = eps * ((x * x) * (x * (x * 5.0))) else: tmp = math.pow(eps, 5.0) return tmp
function code(x, eps) tmp = 0.0 if ((x <= -8e-47) || !(x <= 4.8e-44)) tmp = Float64(eps * Float64(Float64(x * x) * Float64(x * Float64(x * 5.0)))); else tmp = eps ^ 5.0; end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((x <= -8e-47) || ~((x <= 4.8e-44))) tmp = eps * ((x * x) * (x * (x * 5.0))); else tmp = eps ^ 5.0; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[x, -8e-47], N[Not[LessEqual[x, 4.8e-44]], $MachinePrecision]], N[(eps * N[(N[(x * x), $MachinePrecision] * N[(x * N[(x * 5.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[eps, 5.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8 \cdot 10^{-47} \lor \neg \left(x \leq 4.8 \cdot 10^{-44}\right):\\
\;\;\;\;\varepsilon \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot \left(x \cdot 5\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;{\varepsilon}^{5}\\
\end{array}
\end{array}
if x < -7.9999999999999998e-47 or 4.80000000000000017e-44 < x Initial program 32.0%
Taylor expanded in x around inf 94.6%
*-commutative94.6%
distribute-rgt1-in94.6%
metadata-eval94.6%
*-commutative94.6%
associate-*r*94.7%
Simplified94.7%
add-sqr-sqrt94.4%
sqrt-unprod92.9%
*-commutative92.9%
*-commutative92.9%
swap-sqr93.0%
pow-prod-up93.1%
metadata-eval93.1%
metadata-eval93.1%
Applied egg-rr93.1%
sqrt-prod93.0%
metadata-eval93.0%
sqrt-pow194.7%
metadata-eval94.7%
metadata-eval94.7%
pow-sqr94.4%
pow294.4%
pow294.4%
add-sqr-sqrt94.0%
swap-sqr94.3%
unpow294.3%
associate-*l*94.3%
unpow-prod-down94.3%
pow294.3%
Applied egg-rr94.3%
Taylor expanded in x around 0 94.0%
unpow294.0%
associate-*l*94.1%
unpow294.1%
rem-square-sqrt94.7%
Simplified94.7%
if -7.9999999999999998e-47 < x < 4.80000000000000017e-44Initial program 100.0%
Taylor expanded in x around 0 100.0%
Final simplification99.1%
(FPCore (x eps) :precision binary64 (* eps (* (* x x) (* x (* x 5.0)))))
double code(double x, double eps) {
return eps * ((x * x) * (x * (x * 5.0)));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = eps * ((x * x) * (x * (x * 5.0d0)))
end function
public static double code(double x, double eps) {
return eps * ((x * x) * (x * (x * 5.0)));
}
def code(x, eps): return eps * ((x * x) * (x * (x * 5.0)))
function code(x, eps) return Float64(eps * Float64(Float64(x * x) * Float64(x * Float64(x * 5.0)))) end
function tmp = code(x, eps) tmp = eps * ((x * x) * (x * (x * 5.0))); end
code[x_, eps_] := N[(eps * N[(N[(x * x), $MachinePrecision] * N[(x * N[(x * 5.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\varepsilon \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot \left(x \cdot 5\right)\right)\right)
\end{array}
Initial program 88.8%
Taylor expanded in x around inf 84.1%
*-commutative84.1%
distribute-rgt1-in84.1%
metadata-eval84.1%
*-commutative84.1%
associate-*r*84.1%
Simplified84.1%
add-sqr-sqrt84.1%
sqrt-unprod83.8%
*-commutative83.8%
*-commutative83.8%
swap-sqr83.8%
pow-prod-up83.8%
metadata-eval83.8%
metadata-eval83.8%
Applied egg-rr83.8%
sqrt-prod83.8%
metadata-eval83.8%
sqrt-pow184.1%
metadata-eval84.1%
metadata-eval84.1%
pow-sqr84.1%
pow284.1%
pow284.1%
add-sqr-sqrt84.0%
swap-sqr84.0%
unpow284.0%
associate-*l*84.0%
unpow-prod-down84.0%
pow284.0%
Applied egg-rr84.0%
Taylor expanded in x around 0 84.0%
unpow284.0%
associate-*l*84.0%
unpow284.0%
rem-square-sqrt84.1%
Simplified84.1%
Final simplification84.1%
herbie shell --seed 2023271
(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)))