
(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 8 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 -9.5e-58)
(* (* (* x x) (* x x)) (fma 5.0 eps (/ (* -10.0 (* eps eps)) (- x))))
(if (<= x 1.25e-51)
(pow eps 5.0)
(* (* (* (* (fma x 5.0 (* 10.0 eps)) x) eps) x) x))))
double code(double x, double eps) {
double tmp;
if (x <= -9.5e-58) {
tmp = ((x * x) * (x * x)) * fma(5.0, eps, ((-10.0 * (eps * eps)) / -x));
} else if (x <= 1.25e-51) {
tmp = pow(eps, 5.0);
} else {
tmp = (((fma(x, 5.0, (10.0 * eps)) * x) * eps) * x) * x;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -9.5e-58) tmp = Float64(Float64(Float64(x * x) * Float64(x * x)) * fma(5.0, eps, Float64(Float64(-10.0 * Float64(eps * eps)) / Float64(-x)))); elseif (x <= 1.25e-51) tmp = eps ^ 5.0; else tmp = Float64(Float64(Float64(Float64(fma(x, 5.0, Float64(10.0 * eps)) * x) * eps) * x) * x); end return tmp end
code[x_, eps_] := If[LessEqual[x, -9.5e-58], N[(N[(N[(x * x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision] * N[(5.0 * eps + N[(N[(-10.0 * N[(eps * eps), $MachinePrecision]), $MachinePrecision] / (-x)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.25e-51], N[Power[eps, 5.0], $MachinePrecision], N[(N[(N[(N[(N[(x * 5.0 + N[(10.0 * eps), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision] * eps), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.5 \cdot 10^{-58}:\\
\;\;\;\;\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right) \cdot \mathsf{fma}\left(5, \varepsilon, \frac{-10 \cdot \left(\varepsilon \cdot \varepsilon\right)}{-x}\right)\\
\mathbf{elif}\;x \leq 1.25 \cdot 10^{-51}:\\
\;\;\;\;{\varepsilon}^{5}\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(\mathsf{fma}\left(x, 5, 10 \cdot \varepsilon\right) \cdot x\right) \cdot \varepsilon\right) \cdot x\right) \cdot x\\
\end{array}
\end{array}
if x < -9.4999999999999994e-58Initial program 41.2%
Taylor expanded in x around -inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.6%
Applied rewrites99.7%
if -9.4999999999999994e-58 < x < 1.25000000000000001e-51Initial program 100.0%
Taylor expanded in eps around inf
lower-pow.f64100.0
Applied rewrites100.0%
if 1.25000000000000001e-51 < x Initial program 26.1%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites97.1%
Applied rewrites96.9%
Applied rewrites97.1%
Final simplification99.7%
(FPCore (x eps) :precision binary64 (* (* (* x x) (* x x)) (fma 5.0 eps (/ (* -10.0 (* eps eps)) (- x)))))
double code(double x, double eps) {
return ((x * x) * (x * x)) * fma(5.0, eps, ((-10.0 * (eps * eps)) / -x));
}
function code(x, eps) return Float64(Float64(Float64(x * x) * Float64(x * x)) * fma(5.0, eps, Float64(Float64(-10.0 * Float64(eps * eps)) / Float64(-x)))) end
code[x_, eps_] := N[(N[(N[(x * x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision] * N[(5.0 * eps + N[(N[(-10.0 * N[(eps * eps), $MachinePrecision]), $MachinePrecision] / (-x)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right) \cdot \mathsf{fma}\left(5, \varepsilon, \frac{-10 \cdot \left(\varepsilon \cdot \varepsilon\right)}{-x}\right)
\end{array}
Initial program 87.4%
Taylor expanded in x around -inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites85.0%
Applied rewrites85.0%
Final simplification85.0%
(FPCore (x eps) :precision binary64 (* (* (* (* (fma x 5.0 (* 10.0 eps)) x) eps) x) x))
double code(double x, double eps) {
return (((fma(x, 5.0, (10.0 * eps)) * x) * eps) * x) * x;
}
function code(x, eps) return Float64(Float64(Float64(Float64(fma(x, 5.0, Float64(10.0 * eps)) * x) * eps) * x) * x) end
code[x_, eps_] := N[(N[(N[(N[(N[(x * 5.0 + N[(10.0 * eps), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision] * eps), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\left(\mathsf{fma}\left(x, 5, 10 \cdot \varepsilon\right) \cdot x\right) \cdot \varepsilon\right) \cdot x\right) \cdot x
\end{array}
Initial program 87.4%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites85.0%
Applied rewrites85.0%
Applied rewrites85.0%
Final simplification85.0%
(FPCore (x eps) :precision binary64 (* (* (* (* 5.0 x) x) (* x x)) eps))
double code(double x, double eps) {
return (((5.0 * x) * x) * (x * x)) * eps;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (((5.0d0 * x) * x) * (x * x)) * eps
end function
public static double code(double x, double eps) {
return (((5.0 * x) * x) * (x * x)) * eps;
}
def code(x, eps): return (((5.0 * x) * x) * (x * x)) * eps
function code(x, eps) return Float64(Float64(Float64(Float64(5.0 * x) * x) * Float64(x * x)) * eps) end
function tmp = code(x, eps) tmp = (((5.0 * x) * x) * (x * x)) * eps; end
code[x_, eps_] := N[(N[(N[(N[(5.0 * x), $MachinePrecision] * x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision] * eps), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\left(5 \cdot x\right) \cdot x\right) \cdot \left(x \cdot x\right)\right) \cdot \varepsilon
\end{array}
Initial program 87.4%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites85.0%
Applied rewrites85.0%
Taylor expanded in eps around 0
Applied rewrites84.9%
Final simplification84.9%
(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(Float64(Float64(eps * x) * x) * Float64(Float64(x * x) * 5.0)) end
function tmp = code(x, eps) tmp = ((eps * x) * x) * ((x * x) * 5.0); end
code[x_, eps_] := N[(N[(N[(eps * x), $MachinePrecision] * x), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * 5.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\varepsilon \cdot x\right) \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot 5\right)
\end{array}
Initial program 87.4%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
distribute-lft1-inN/A
metadata-evalN/A
lower-*.f64N/A
lower-pow.f6484.8
Applied rewrites84.8%
Applied rewrites84.8%
Applied rewrites84.8%
Final simplification84.8%
(FPCore (x eps) :precision binary64 (* (* (* x x) eps) (* (* x x) 5.0)))
double code(double x, double eps) {
return ((x * x) * eps) * ((x * x) * 5.0);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = ((x * x) * eps) * ((x * x) * 5.0d0)
end function
public static double code(double x, double eps) {
return ((x * x) * eps) * ((x * x) * 5.0);
}
def code(x, eps): return ((x * x) * eps) * ((x * x) * 5.0)
function code(x, eps) return Float64(Float64(Float64(x * x) * eps) * Float64(Float64(x * x) * 5.0)) end
function tmp = code(x, eps) tmp = ((x * x) * eps) * ((x * x) * 5.0); end
code[x_, eps_] := N[(N[(N[(x * x), $MachinePrecision] * eps), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * 5.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x \cdot x\right) \cdot \varepsilon\right) \cdot \left(\left(x \cdot x\right) \cdot 5\right)
\end{array}
Initial program 87.4%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
distribute-lft1-inN/A
metadata-evalN/A
lower-*.f64N/A
lower-pow.f6484.8
Applied rewrites84.8%
Applied rewrites84.8%
Final simplification84.8%
(FPCore (x eps) :precision binary64 (* (* (* (* x x) (* x x)) 5.0) eps))
double code(double x, double eps) {
return (((x * x) * (x * x)) * 5.0) * eps;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (((x * x) * (x * x)) * 5.0d0) * eps
end function
public static double code(double x, double eps) {
return (((x * x) * (x * x)) * 5.0) * eps;
}
def code(x, eps): return (((x * x) * (x * x)) * 5.0) * eps
function code(x, eps) return Float64(Float64(Float64(Float64(x * x) * Float64(x * x)) * 5.0) * eps) end
function tmp = code(x, eps) tmp = (((x * x) * (x * x)) * 5.0) * eps; end
code[x_, eps_] := N[(N[(N[(N[(x * x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision] * 5.0), $MachinePrecision] * eps), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right) \cdot 5\right) \cdot \varepsilon
\end{array}
Initial program 87.4%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
distribute-lft1-inN/A
metadata-evalN/A
lower-*.f64N/A
lower-pow.f6484.8
Applied rewrites84.8%
Applied rewrites84.8%
Final simplification84.8%
(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(Float64(eps * x) * 5.0) * x) * x) * x) end
function tmp = code(x, eps) tmp = ((((eps * x) * 5.0) * x) * x) * x; end
code[x_, eps_] := N[(N[(N[(N[(N[(eps * x), $MachinePrecision] * 5.0), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\left(\left(\varepsilon \cdot x\right) \cdot 5\right) \cdot x\right) \cdot x\right) \cdot x
\end{array}
Initial program 87.4%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites85.0%
Applied rewrites85.0%
Applied rewrites85.0%
Taylor expanded in eps around 0
Applied rewrites84.8%
Final simplification84.8%
herbie shell --seed 2024255
(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)))