
(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 9 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 -4e-320) (not (<= t_0 0.0)))
t_0
(fma
(fma 10.0 (/ (* eps eps) x) (* 4.0 eps))
(pow x 4.0)
(* eps (pow x 4.0))))))
double code(double x, double eps) {
double t_0 = pow((x + eps), 5.0) - pow(x, 5.0);
double tmp;
if ((t_0 <= -4e-320) || !(t_0 <= 0.0)) {
tmp = t_0;
} else {
tmp = fma(fma(10.0, ((eps * eps) / x), (4.0 * eps)), pow(x, 4.0), (eps * pow(x, 4.0)));
}
return tmp;
}
function code(x, eps) t_0 = Float64((Float64(x + eps) ^ 5.0) - (x ^ 5.0)) tmp = 0.0 if ((t_0 <= -4e-320) || !(t_0 <= 0.0)) tmp = t_0; else tmp = fma(fma(10.0, Float64(Float64(eps * eps) / x), Float64(4.0 * eps)), (x ^ 4.0), Float64(eps * (x ^ 4.0))); end return 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, -4e-320], N[Not[LessEqual[t$95$0, 0.0]], $MachinePrecision]], t$95$0, N[(N[(10.0 * N[(N[(eps * eps), $MachinePrecision] / x), $MachinePrecision] + N[(4.0 * eps), $MachinePrecision]), $MachinePrecision] * N[Power[x, 4.0], $MachinePrecision] + N[(eps * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left(x + \varepsilon\right)}^{5} - {x}^{5}\\
\mathbf{if}\;t\_0 \leq -4 \cdot 10^{-320} \lor \neg \left(t\_0 \leq 0\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(10, \frac{\varepsilon \cdot \varepsilon}{x}, 4 \cdot \varepsilon\right), {x}^{4}, \varepsilon \cdot {x}^{4}\right)\\
\end{array}
\end{array}
if (-.f64 (pow.f64 (+.f64 x eps) #s(literal 5 binary64)) (pow.f64 x #s(literal 5 binary64))) < -3.99996e-320 or 0.0 < (-.f64 (pow.f64 (+.f64 x eps) #s(literal 5 binary64)) (pow.f64 x #s(literal 5 binary64))) Initial program 96.6%
if -3.99996e-320 < (-.f64 (pow.f64 (+.f64 x eps) #s(literal 5 binary64)) (pow.f64 x #s(literal 5 binary64))) < 0.0Initial program 84.5%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
associate-+r+N/A
distribute-rgt-outN/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
metadata-evalN/A
lower-*.f64N/A
lower-pow.f6499.9
Applied rewrites99.9%
Applied rewrites100.0%
Final simplification99.3%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (pow (+ x eps) 5.0) (pow x 5.0))))
(if (or (<= t_0 -4e-320) (not (<= t_0 0.0)))
t_0
(* (* (pow x 4.0) eps) 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 <= -4e-320) || !(t_0 <= 0.0)) {
tmp = t_0;
} else {
tmp = (pow(x, 4.0) * eps) * 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 <= (-4d-320)) .or. (.not. (t_0 <= 0.0d0))) then
tmp = t_0
else
tmp = ((x ** 4.0d0) * eps) * 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 <= -4e-320) || !(t_0 <= 0.0)) {
tmp = t_0;
} else {
tmp = (Math.pow(x, 4.0) * eps) * 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 <= -4e-320) or not (t_0 <= 0.0): tmp = t_0 else: tmp = (math.pow(x, 4.0) * eps) * 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 <= -4e-320) || !(t_0 <= 0.0)) tmp = t_0; else tmp = Float64(Float64((x ^ 4.0) * eps) * 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 <= -4e-320) || ~((t_0 <= 0.0))) tmp = t_0; else tmp = ((x ^ 4.0) * eps) * 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, -4e-320], N[Not[LessEqual[t$95$0, 0.0]], $MachinePrecision]], t$95$0, N[(N[(N[Power[x, 4.0], $MachinePrecision] * eps), $MachinePrecision] * 5.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left(x + \varepsilon\right)}^{5} - {x}^{5}\\
\mathbf{if}\;t\_0 \leq -4 \cdot 10^{-320} \lor \neg \left(t\_0 \leq 0\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\left({x}^{4} \cdot \varepsilon\right) \cdot 5\\
\end{array}
\end{array}
if (-.f64 (pow.f64 (+.f64 x eps) #s(literal 5 binary64)) (pow.f64 x #s(literal 5 binary64))) < -3.99996e-320 or 0.0 < (-.f64 (pow.f64 (+.f64 x eps) #s(literal 5 binary64)) (pow.f64 x #s(literal 5 binary64))) Initial program 96.6%
if -3.99996e-320 < (-.f64 (pow.f64 (+.f64 x eps) #s(literal 5 binary64)) (pow.f64 x #s(literal 5 binary64))) < 0.0Initial program 84.5%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
distribute-lft1-inN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lower-pow.f64N/A
lower-pow.f6484.5
Applied rewrites84.5%
Taylor expanded in x around inf
distribute-rgt1-inN/A
metadata-evalN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-pow.f6499.9
Applied rewrites99.9%
Final simplification99.3%
(FPCore (x eps)
:precision binary64
(if (<= x -1.5e-64)
(* (* (* x (fma 10.0 eps (* 5.0 x))) eps) (* x x))
(if (<= x 1.32e-64)
(* (fma (/ x eps) 5.0 1.0) (pow eps 5.0))
(* (* (* (* x (fma (/ eps x) 10.0 5.0)) (* eps x)) x) x))))
double code(double x, double eps) {
double tmp;
if (x <= -1.5e-64) {
tmp = ((x * fma(10.0, eps, (5.0 * x))) * eps) * (x * x);
} else if (x <= 1.32e-64) {
tmp = fma((x / eps), 5.0, 1.0) * pow(eps, 5.0);
} else {
tmp = (((x * fma((eps / x), 10.0, 5.0)) * (eps * x)) * x) * x;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -1.5e-64) tmp = Float64(Float64(Float64(x * fma(10.0, eps, Float64(5.0 * x))) * eps) * Float64(x * x)); elseif (x <= 1.32e-64) tmp = Float64(fma(Float64(x / eps), 5.0, 1.0) * (eps ^ 5.0)); else tmp = Float64(Float64(Float64(Float64(x * fma(Float64(eps / x), 10.0, 5.0)) * Float64(eps * x)) * x) * x); end return tmp end
code[x_, eps_] := If[LessEqual[x, -1.5e-64], N[(N[(N[(x * N[(10.0 * eps + N[(5.0 * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * eps), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.32e-64], N[(N[(N[(x / eps), $MachinePrecision] * 5.0 + 1.0), $MachinePrecision] * N[Power[eps, 5.0], $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(x * N[(N[(eps / x), $MachinePrecision] * 10.0 + 5.0), $MachinePrecision]), $MachinePrecision] * N[(eps * x), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \cdot 10^{-64}:\\
\;\;\;\;\left(\left(x \cdot \mathsf{fma}\left(10, \varepsilon, 5 \cdot x\right)\right) \cdot \varepsilon\right) \cdot \left(x \cdot x\right)\\
\mathbf{elif}\;x \leq 1.32 \cdot 10^{-64}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{\varepsilon}, 5, 1\right) \cdot {\varepsilon}^{5}\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(x \cdot \mathsf{fma}\left(\frac{\varepsilon}{x}, 10, 5\right)\right) \cdot \left(\varepsilon \cdot x\right)\right) \cdot x\right) \cdot x\\
\end{array}
\end{array}
if x < -1.5e-64Initial program 61.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
associate-+r+N/A
distribute-rgt-outN/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
metadata-evalN/A
lower-*.f64N/A
lower-pow.f6492.3
Applied rewrites92.3%
Applied rewrites92.2%
Taylor expanded in x around 0
Applied rewrites92.4%
if -1.5e-64 < x < 1.32e-64Initial program 100.0%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
distribute-lft1-inN/A
metadata-evalN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-pow.f64100.0
Applied rewrites100.0%
if 1.32e-64 < x Initial program 35.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
associate-+r+N/A
distribute-rgt-outN/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
metadata-evalN/A
lower-*.f64N/A
lower-pow.f6499.5
Applied rewrites99.5%
Applied rewrites99.1%
Taylor expanded in x around inf
Applied rewrites99.3%
Applied rewrites99.6%
(FPCore (x eps)
:precision binary64
(if (<= x -1.5e-64)
(* (* (* x (fma 10.0 eps (* 5.0 x))) eps) (* x x))
(if (<= x 1.32e-64)
(* (fma 5.0 x eps) (pow eps 4.0))
(* (* (* (* x (fma (/ eps x) 10.0 5.0)) (* eps x)) x) x))))
double code(double x, double eps) {
double tmp;
if (x <= -1.5e-64) {
tmp = ((x * fma(10.0, eps, (5.0 * x))) * eps) * (x * x);
} else if (x <= 1.32e-64) {
tmp = fma(5.0, x, eps) * pow(eps, 4.0);
} else {
tmp = (((x * fma((eps / x), 10.0, 5.0)) * (eps * x)) * x) * x;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -1.5e-64) tmp = Float64(Float64(Float64(x * fma(10.0, eps, Float64(5.0 * x))) * eps) * Float64(x * x)); elseif (x <= 1.32e-64) tmp = Float64(fma(5.0, x, eps) * (eps ^ 4.0)); else tmp = Float64(Float64(Float64(Float64(x * fma(Float64(eps / x), 10.0, 5.0)) * Float64(eps * x)) * x) * x); end return tmp end
code[x_, eps_] := If[LessEqual[x, -1.5e-64], N[(N[(N[(x * N[(10.0 * eps + N[(5.0 * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * eps), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.32e-64], N[(N[(5.0 * x + eps), $MachinePrecision] * N[Power[eps, 4.0], $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(x * N[(N[(eps / x), $MachinePrecision] * 10.0 + 5.0), $MachinePrecision]), $MachinePrecision] * N[(eps * x), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \cdot 10^{-64}:\\
\;\;\;\;\left(\left(x \cdot \mathsf{fma}\left(10, \varepsilon, 5 \cdot x\right)\right) \cdot \varepsilon\right) \cdot \left(x \cdot x\right)\\
\mathbf{elif}\;x \leq 1.32 \cdot 10^{-64}:\\
\;\;\;\;\mathsf{fma}\left(5, x, \varepsilon\right) \cdot {\varepsilon}^{4}\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(x \cdot \mathsf{fma}\left(\frac{\varepsilon}{x}, 10, 5\right)\right) \cdot \left(\varepsilon \cdot x\right)\right) \cdot x\right) \cdot x\\
\end{array}
\end{array}
if x < -1.5e-64Initial program 61.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
associate-+r+N/A
distribute-rgt-outN/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
metadata-evalN/A
lower-*.f64N/A
lower-pow.f6492.3
Applied rewrites92.3%
Applied rewrites92.2%
Taylor expanded in x around 0
Applied rewrites92.4%
if -1.5e-64 < x < 1.32e-64Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
distribute-lft1-inN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lower-pow.f64N/A
lower-pow.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
distribute-lft1-inN/A
metadata-evalN/A
associate-*r*N/A
*-commutativeN/A
metadata-evalN/A
pow-plusN/A
*-commutativeN/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
lower-pow.f6499.9
Applied rewrites99.9%
if 1.32e-64 < x Initial program 35.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
associate-+r+N/A
distribute-rgt-outN/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
metadata-evalN/A
lower-*.f64N/A
lower-pow.f6499.5
Applied rewrites99.5%
Applied rewrites99.1%
Taylor expanded in x around inf
Applied rewrites99.3%
Applied rewrites99.6%
(FPCore (x eps)
:precision binary64
(if (<= x -1.5e-64)
(* (* (* x (fma 10.0 eps (* 5.0 x))) eps) (* x x))
(if (<= x 1.32e-64)
(* (* (* (* (fma 5.0 x eps) eps) eps) eps) eps)
(* (* (* (* x (fma (/ eps x) 10.0 5.0)) (* eps x)) x) x))))
double code(double x, double eps) {
double tmp;
if (x <= -1.5e-64) {
tmp = ((x * fma(10.0, eps, (5.0 * x))) * eps) * (x * x);
} else if (x <= 1.32e-64) {
tmp = (((fma(5.0, x, eps) * eps) * eps) * eps) * eps;
} else {
tmp = (((x * fma((eps / x), 10.0, 5.0)) * (eps * x)) * x) * x;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -1.5e-64) tmp = Float64(Float64(Float64(x * fma(10.0, eps, Float64(5.0 * x))) * eps) * Float64(x * x)); elseif (x <= 1.32e-64) tmp = Float64(Float64(Float64(Float64(fma(5.0, x, eps) * eps) * eps) * eps) * eps); else tmp = Float64(Float64(Float64(Float64(x * fma(Float64(eps / x), 10.0, 5.0)) * Float64(eps * x)) * x) * x); end return tmp end
code[x_, eps_] := If[LessEqual[x, -1.5e-64], N[(N[(N[(x * N[(10.0 * eps + N[(5.0 * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * eps), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.32e-64], N[(N[(N[(N[(N[(5.0 * x + eps), $MachinePrecision] * eps), $MachinePrecision] * eps), $MachinePrecision] * eps), $MachinePrecision] * eps), $MachinePrecision], N[(N[(N[(N[(x * N[(N[(eps / x), $MachinePrecision] * 10.0 + 5.0), $MachinePrecision]), $MachinePrecision] * N[(eps * x), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \cdot 10^{-64}:\\
\;\;\;\;\left(\left(x \cdot \mathsf{fma}\left(10, \varepsilon, 5 \cdot x\right)\right) \cdot \varepsilon\right) \cdot \left(x \cdot x\right)\\
\mathbf{elif}\;x \leq 1.32 \cdot 10^{-64}:\\
\;\;\;\;\left(\left(\left(\mathsf{fma}\left(5, x, \varepsilon\right) \cdot \varepsilon\right) \cdot \varepsilon\right) \cdot \varepsilon\right) \cdot \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(x \cdot \mathsf{fma}\left(\frac{\varepsilon}{x}, 10, 5\right)\right) \cdot \left(\varepsilon \cdot x\right)\right) \cdot x\right) \cdot x\\
\end{array}
\end{array}
if x < -1.5e-64Initial program 61.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
associate-+r+N/A
distribute-rgt-outN/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
metadata-evalN/A
lower-*.f64N/A
lower-pow.f6492.3
Applied rewrites92.3%
Applied rewrites92.2%
Taylor expanded in x around 0
Applied rewrites92.4%
if -1.5e-64 < x < 1.32e-64Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
distribute-lft1-inN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lower-pow.f64N/A
lower-pow.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
distribute-lft1-inN/A
metadata-evalN/A
associate-*r*N/A
*-commutativeN/A
metadata-evalN/A
pow-plusN/A
*-commutativeN/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
lower-pow.f6499.9
Applied rewrites99.9%
Applied rewrites99.8%
Applied rewrites99.9%
if 1.32e-64 < x Initial program 35.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
associate-+r+N/A
distribute-rgt-outN/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
metadata-evalN/A
lower-*.f64N/A
lower-pow.f6499.5
Applied rewrites99.5%
Applied rewrites99.1%
Taylor expanded in x around inf
Applied rewrites99.3%
Applied rewrites99.6%
(FPCore (x eps) :precision binary64 (if (or (<= x -1.5e-64) (not (<= x 1.32e-64))) (* (* (* x (fma 10.0 eps (* 5.0 x))) eps) (* x x)) (* (* (* (* (fma 5.0 x eps) eps) eps) eps) eps)))
double code(double x, double eps) {
double tmp;
if ((x <= -1.5e-64) || !(x <= 1.32e-64)) {
tmp = ((x * fma(10.0, eps, (5.0 * x))) * eps) * (x * x);
} else {
tmp = (((fma(5.0, x, eps) * eps) * eps) * eps) * eps;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if ((x <= -1.5e-64) || !(x <= 1.32e-64)) tmp = Float64(Float64(Float64(x * fma(10.0, eps, Float64(5.0 * x))) * eps) * Float64(x * x)); else tmp = Float64(Float64(Float64(Float64(fma(5.0, x, eps) * eps) * eps) * eps) * eps); end return tmp end
code[x_, eps_] := If[Or[LessEqual[x, -1.5e-64], N[Not[LessEqual[x, 1.32e-64]], $MachinePrecision]], N[(N[(N[(x * N[(10.0 * eps + N[(5.0 * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * eps), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(N[(5.0 * x + eps), $MachinePrecision] * eps), $MachinePrecision] * eps), $MachinePrecision] * eps), $MachinePrecision] * eps), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \cdot 10^{-64} \lor \neg \left(x \leq 1.32 \cdot 10^{-64}\right):\\
\;\;\;\;\left(\left(x \cdot \mathsf{fma}\left(10, \varepsilon, 5 \cdot x\right)\right) \cdot \varepsilon\right) \cdot \left(x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(\mathsf{fma}\left(5, x, \varepsilon\right) \cdot \varepsilon\right) \cdot \varepsilon\right) \cdot \varepsilon\right) \cdot \varepsilon\\
\end{array}
\end{array}
if x < -1.5e-64 or 1.32e-64 < x Initial program 47.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
associate-+r+N/A
distribute-rgt-outN/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
metadata-evalN/A
lower-*.f64N/A
lower-pow.f6496.1
Applied rewrites96.1%
Applied rewrites95.9%
Taylor expanded in x around 0
Applied rewrites96.1%
if -1.5e-64 < x < 1.32e-64Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
distribute-lft1-inN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lower-pow.f64N/A
lower-pow.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
distribute-lft1-inN/A
metadata-evalN/A
associate-*r*N/A
*-commutativeN/A
metadata-evalN/A
pow-plusN/A
*-commutativeN/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
lower-pow.f6499.9
Applied rewrites99.9%
Applied rewrites99.8%
Applied rewrites99.9%
Final simplification98.9%
(FPCore (x eps)
:precision binary64
(if (<= x -4.8e-64)
(* (* (* (* 5.0 eps) x) x) (* x x))
(if (<= x 1.32e-64)
(* (* (* (* (fma 5.0 x eps) eps) eps) eps) eps)
(* (* (* (* eps x) 5.0) x) (* x x)))))
double code(double x, double eps) {
double tmp;
if (x <= -4.8e-64) {
tmp = (((5.0 * eps) * x) * x) * (x * x);
} else if (x <= 1.32e-64) {
tmp = (((fma(5.0, x, eps) * eps) * eps) * eps) * eps;
} else {
tmp = (((eps * x) * 5.0) * x) * (x * x);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -4.8e-64) tmp = Float64(Float64(Float64(Float64(5.0 * eps) * x) * x) * Float64(x * x)); elseif (x <= 1.32e-64) tmp = Float64(Float64(Float64(Float64(fma(5.0, x, eps) * eps) * eps) * eps) * eps); else tmp = Float64(Float64(Float64(Float64(eps * x) * 5.0) * x) * Float64(x * x)); end return tmp end
code[x_, eps_] := If[LessEqual[x, -4.8e-64], N[(N[(N[(N[(5.0 * eps), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.32e-64], N[(N[(N[(N[(N[(5.0 * x + eps), $MachinePrecision] * eps), $MachinePrecision] * eps), $MachinePrecision] * eps), $MachinePrecision] * eps), $MachinePrecision], N[(N[(N[(N[(eps * x), $MachinePrecision] * 5.0), $MachinePrecision] * x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.8 \cdot 10^{-64}:\\
\;\;\;\;\left(\left(\left(5 \cdot \varepsilon\right) \cdot x\right) \cdot x\right) \cdot \left(x \cdot x\right)\\
\mathbf{elif}\;x \leq 1.32 \cdot 10^{-64}:\\
\;\;\;\;\left(\left(\left(\mathsf{fma}\left(5, x, \varepsilon\right) \cdot \varepsilon\right) \cdot \varepsilon\right) \cdot \varepsilon\right) \cdot \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(\varepsilon \cdot x\right) \cdot 5\right) \cdot x\right) \cdot \left(x \cdot x\right)\\
\end{array}
\end{array}
if x < -4.79999999999999997e-64Initial program 59.7%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
associate-+r+N/A
distribute-rgt-outN/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
metadata-evalN/A
lower-*.f64N/A
lower-pow.f6492.8
Applied rewrites92.8%
Applied rewrites92.7%
Taylor expanded in x around inf
Applied rewrites92.8%
Taylor expanded in x around inf
Applied rewrites91.5%
if -4.79999999999999997e-64 < x < 1.32e-64Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
distribute-lft1-inN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
lower-pow.f64N/A
lower-pow.f6499.9
Applied rewrites99.9%
Taylor expanded in x around 0
distribute-lft1-inN/A
metadata-evalN/A
associate-*r*N/A
*-commutativeN/A
metadata-evalN/A
pow-plusN/A
*-commutativeN/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
lower-pow.f6499.8
Applied rewrites99.8%
Applied rewrites99.7%
Applied rewrites99.8%
if 1.32e-64 < x Initial program 35.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
associate-+r+N/A
distribute-rgt-outN/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
metadata-evalN/A
lower-*.f64N/A
lower-pow.f6499.5
Applied rewrites99.5%
Applied rewrites99.1%
Taylor expanded in x around inf
Applied rewrites99.3%
Taylor expanded in x around inf
Applied rewrites98.0%
(FPCore (x eps) :precision binary64 (* (* (* (* 5.0 eps) x) x) (* x x)))
double code(double x, double eps) {
return (((5.0 * eps) * x) * x) * (x * x);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (((5.0d0 * eps) * x) * x) * (x * x)
end function
public static double code(double x, double eps) {
return (((5.0 * eps) * x) * x) * (x * x);
}
def code(x, eps): return (((5.0 * eps) * x) * x) * (x * x)
function code(x, eps) return Float64(Float64(Float64(Float64(5.0 * eps) * x) * x) * Float64(x * x)) end
function tmp = code(x, eps) tmp = (((5.0 * eps) * x) * x) * (x * x); end
code[x_, eps_] := N[(N[(N[(N[(5.0 * eps), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\left(5 \cdot \varepsilon\right) \cdot x\right) \cdot x\right) \cdot \left(x \cdot x\right)
\end{array}
Initial program 86.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
associate-+r+N/A
distribute-rgt-outN/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
metadata-evalN/A
lower-*.f64N/A
lower-pow.f6483.5
Applied rewrites83.5%
Applied rewrites83.5%
Taylor expanded in x around inf
Applied rewrites83.5%
Taylor expanded in x around inf
Applied rewrites83.2%
(FPCore (x eps) :precision binary64 (* (* (* (* eps x) 5.0) x) (* x x)))
double code(double x, double eps) {
return (((eps * x) * 5.0) * x) * (x * x);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (((eps * x) * 5.0d0) * x) * (x * x)
end function
public static double code(double x, double eps) {
return (((eps * x) * 5.0) * x) * (x * x);
}
def code(x, eps): return (((eps * x) * 5.0) * x) * (x * x)
function code(x, eps) return Float64(Float64(Float64(Float64(eps * x) * 5.0) * x) * Float64(x * x)) end
function tmp = code(x, eps) tmp = (((eps * x) * 5.0) * x) * (x * x); end
code[x_, eps_] := N[(N[(N[(N[(eps * x), $MachinePrecision] * 5.0), $MachinePrecision] * x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\left(\varepsilon \cdot x\right) \cdot 5\right) \cdot x\right) \cdot \left(x \cdot x\right)
\end{array}
Initial program 86.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
associate-+r+N/A
distribute-rgt-outN/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
metadata-evalN/A
lower-*.f64N/A
lower-pow.f6483.5
Applied rewrites83.5%
Applied rewrites83.5%
Taylor expanded in x around inf
Applied rewrites83.5%
Taylor expanded in x around inf
Applied rewrites83.2%
herbie shell --seed 2024317
(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)))