
(FPCore (x eps) :precision binary64 (- (pow (+ x eps) 2.0) (pow x 2.0)))
double code(double x, double eps) {
return pow((x + eps), 2.0) - pow(x, 2.0);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = ((x + eps) ** 2.0d0) - (x ** 2.0d0)
end function
public static double code(double x, double eps) {
return Math.pow((x + eps), 2.0) - Math.pow(x, 2.0);
}
def code(x, eps): return math.pow((x + eps), 2.0) - math.pow(x, 2.0)
function code(x, eps) return Float64((Float64(x + eps) ^ 2.0) - (x ^ 2.0)) end
function tmp = code(x, eps) tmp = ((x + eps) ^ 2.0) - (x ^ 2.0); end
code[x_, eps_] := N[(N[Power[N[(x + eps), $MachinePrecision], 2.0], $MachinePrecision] - N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(x + \varepsilon\right)}^{2} - {x}^{2}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x eps) :precision binary64 (- (pow (+ x eps) 2.0) (pow x 2.0)))
double code(double x, double eps) {
return pow((x + eps), 2.0) - pow(x, 2.0);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = ((x + eps) ** 2.0d0) - (x ** 2.0d0)
end function
public static double code(double x, double eps) {
return Math.pow((x + eps), 2.0) - Math.pow(x, 2.0);
}
def code(x, eps): return math.pow((x + eps), 2.0) - math.pow(x, 2.0)
function code(x, eps) return Float64((Float64(x + eps) ^ 2.0) - (x ^ 2.0)) end
function tmp = code(x, eps) tmp = ((x + eps) ^ 2.0) - (x ^ 2.0); end
code[x_, eps_] := N[(N[Power[N[(x + eps), $MachinePrecision], 2.0], $MachinePrecision] - N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(x + \varepsilon\right)}^{2} - {x}^{2}
\end{array}
(FPCore (x eps) :precision binary64 (+ (* eps eps) (* (* 2.0 x) eps)))
double code(double x, double eps) {
return (eps * eps) + ((2.0 * x) * eps);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (eps * eps) + ((2.0d0 * x) * eps)
end function
public static double code(double x, double eps) {
return (eps * eps) + ((2.0 * x) * eps);
}
def code(x, eps): return (eps * eps) + ((2.0 * x) * eps)
function code(x, eps) return Float64(Float64(eps * eps) + Float64(Float64(2.0 * x) * eps)) end
function tmp = code(x, eps) tmp = (eps * eps) + ((2.0 * x) * eps); end
code[x_, eps_] := N[(N[(eps * eps), $MachinePrecision] + N[(N[(2.0 * x), $MachinePrecision] * eps), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\varepsilon \cdot \varepsilon + \left(2 \cdot x\right) \cdot \varepsilon
\end{array}
Initial program 73.9%
unpow273.9%
unpow273.9%
difference-of-squares73.9%
*-commutative73.9%
+-commutative73.9%
associate--l+100.0%
+-inverses100.0%
+-rgt-identity100.0%
+-commutative100.0%
associate-+r+100.0%
count-2100.0%
fma-def100.0%
Simplified100.0%
fma-udef100.0%
distribute-rgt-in100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x eps) :precision binary64 (if (or (<= x -7.6e-115) (not (<= x 7.2e-107))) (* (* 2.0 x) eps) (* eps eps)))
double code(double x, double eps) {
double tmp;
if ((x <= -7.6e-115) || !(x <= 7.2e-107)) {
tmp = (2.0 * x) * eps;
} else {
tmp = eps * eps;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((x <= (-7.6d-115)) .or. (.not. (x <= 7.2d-107))) then
tmp = (2.0d0 * x) * eps
else
tmp = eps * eps
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((x <= -7.6e-115) || !(x <= 7.2e-107)) {
tmp = (2.0 * x) * eps;
} else {
tmp = eps * eps;
}
return tmp;
}
def code(x, eps): tmp = 0 if (x <= -7.6e-115) or not (x <= 7.2e-107): tmp = (2.0 * x) * eps else: tmp = eps * eps return tmp
function code(x, eps) tmp = 0.0 if ((x <= -7.6e-115) || !(x <= 7.2e-107)) tmp = Float64(Float64(2.0 * x) * eps); else tmp = Float64(eps * eps); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((x <= -7.6e-115) || ~((x <= 7.2e-107))) tmp = (2.0 * x) * eps; else tmp = eps * eps; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[x, -7.6e-115], N[Not[LessEqual[x, 7.2e-107]], $MachinePrecision]], N[(N[(2.0 * x), $MachinePrecision] * eps), $MachinePrecision], N[(eps * eps), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.6 \cdot 10^{-115} \lor \neg \left(x \leq 7.2 \cdot 10^{-107}\right):\\
\;\;\;\;\left(2 \cdot x\right) \cdot \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \varepsilon\\
\end{array}
\end{array}
if x < -7.59999999999999984e-115 or 7.19999999999999953e-107 < x Initial program 38.6%
unpow238.6%
unpow238.6%
difference-of-squares38.6%
*-commutative38.6%
+-commutative38.6%
associate--l+100.0%
+-inverses100.0%
+-rgt-identity100.0%
+-commutative100.0%
associate-+r+100.0%
count-2100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in eps around 0 86.2%
*-commutative86.2%
associate-*l*86.3%
*-commutative86.3%
Simplified86.3%
if -7.59999999999999984e-115 < x < 7.19999999999999953e-107Initial program 97.3%
unpow297.3%
unpow297.3%
difference-of-squares97.3%
*-commutative97.3%
+-commutative97.3%
associate--l+100.0%
+-inverses100.0%
+-rgt-identity100.0%
+-commutative100.0%
associate-+r+100.0%
count-2100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in eps around inf 95.9%
unpow295.9%
Simplified95.9%
Final simplification92.1%
(FPCore (x eps) :precision binary64 (* eps eps))
double code(double x, double eps) {
return eps * eps;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = eps * eps
end function
public static double code(double x, double eps) {
return eps * eps;
}
def code(x, eps): return eps * eps
function code(x, eps) return Float64(eps * eps) end
function tmp = code(x, eps) tmp = eps * eps; end
code[x_, eps_] := N[(eps * eps), $MachinePrecision]
\begin{array}{l}
\\
\varepsilon \cdot \varepsilon
\end{array}
Initial program 73.9%
unpow273.9%
unpow273.9%
difference-of-squares73.9%
*-commutative73.9%
+-commutative73.9%
associate--l+100.0%
+-inverses100.0%
+-rgt-identity100.0%
+-commutative100.0%
associate-+r+100.0%
count-2100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in eps around inf 71.5%
unpow271.5%
Simplified71.5%
Final simplification71.5%
herbie shell --seed 2023244
(FPCore (x eps)
:name "ENA, Section 1.4, Exercise 4b, n=2"
:precision binary64
:pre (and (and (<= -1000000000.0 x) (<= x 1000000000.0)) (and (<= -1.0 eps) (<= eps 1.0)))
(- (pow (+ x eps) 2.0) (pow x 2.0)))