
(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 4 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 (* x 2.0))))
double code(double x, double eps) {
return eps * (eps + (x * 2.0));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = eps * (eps + (x * 2.0d0))
end function
public static double code(double x, double eps) {
return eps * (eps + (x * 2.0));
}
def code(x, eps): return eps * (eps + (x * 2.0))
function code(x, eps) return Float64(eps * Float64(eps + Float64(x * 2.0))) end
function tmp = code(x, eps) tmp = eps * (eps + (x * 2.0)); end
code[x_, eps_] := N[(eps * N[(eps + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\varepsilon \cdot \left(\varepsilon + x \cdot 2\right)
\end{array}
Initial program 72.6%
+-commutative72.6%
unpow272.6%
unpow272.6%
difference-of-squares72.5%
sub-neg72.5%
distribute-lft-in72.5%
+-commutative72.5%
distribute-lft-in72.5%
+-commutative72.5%
sub-neg72.5%
associate--l+100.0%
+-inverses100.0%
+-rgt-identity100.0%
*-commutative100.0%
associate-+l+100.0%
count-2100.0%
*-commutative100.0%
Simplified100.0%
(FPCore (x eps) :precision binary64 (if (or (<= x -1.8e-74) (not (<= x 4e-111))) (* x (* eps 2.0)) (* eps eps)))
double code(double x, double eps) {
double tmp;
if ((x <= -1.8e-74) || !(x <= 4e-111)) {
tmp = x * (eps * 2.0);
} 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 <= (-1.8d-74)) .or. (.not. (x <= 4d-111))) then
tmp = x * (eps * 2.0d0)
else
tmp = eps * eps
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((x <= -1.8e-74) || !(x <= 4e-111)) {
tmp = x * (eps * 2.0);
} else {
tmp = eps * eps;
}
return tmp;
}
def code(x, eps): tmp = 0 if (x <= -1.8e-74) or not (x <= 4e-111): tmp = x * (eps * 2.0) else: tmp = eps * eps return tmp
function code(x, eps) tmp = 0.0 if ((x <= -1.8e-74) || !(x <= 4e-111)) tmp = Float64(x * Float64(eps * 2.0)); else tmp = Float64(eps * eps); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((x <= -1.8e-74) || ~((x <= 4e-111))) tmp = x * (eps * 2.0); else tmp = eps * eps; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[x, -1.8e-74], N[Not[LessEqual[x, 4e-111]], $MachinePrecision]], N[(x * N[(eps * 2.0), $MachinePrecision]), $MachinePrecision], N[(eps * eps), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.8 \cdot 10^{-74} \lor \neg \left(x \leq 4 \cdot 10^{-111}\right):\\
\;\;\;\;x \cdot \left(\varepsilon \cdot 2\right)\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \varepsilon\\
\end{array}
\end{array}
if x < -1.8000000000000001e-74 or 4.00000000000000035e-111 < x Initial program 32.1%
+-commutative32.1%
unpow232.1%
unpow232.1%
difference-of-squares32.0%
sub-neg32.0%
distribute-lft-in32.0%
+-commutative32.0%
distribute-lft-in32.0%
+-commutative32.0%
sub-neg32.0%
associate--l+100.0%
+-inverses100.0%
+-rgt-identity100.0%
*-commutative100.0%
associate-+l+100.0%
count-2100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
*-commutative100.0%
unpow2100.0%
associate-/l*100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in eps around 0 88.4%
if -1.8000000000000001e-74 < x < 4.00000000000000035e-111Initial program 96.0%
+-commutative96.0%
unpow296.0%
unpow296.0%
difference-of-squares96.0%
sub-neg96.0%
distribute-lft-in96.0%
+-commutative96.0%
distribute-lft-in96.0%
+-commutative96.0%
sub-neg96.0%
associate--l+100.0%
+-inverses100.0%
+-rgt-identity100.0%
*-commutative100.0%
associate-+l+100.0%
count-2100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in eps around inf 94.2%
Final simplification92.1%
(FPCore (x eps) :precision binary64 (if (or (<= x -1.6e-74) (not (<= x 7e-110))) (* 2.0 (* eps x)) (* eps eps)))
double code(double x, double eps) {
double tmp;
if ((x <= -1.6e-74) || !(x <= 7e-110)) {
tmp = 2.0 * (eps * x);
} 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 <= (-1.6d-74)) .or. (.not. (x <= 7d-110))) then
tmp = 2.0d0 * (eps * x)
else
tmp = eps * eps
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((x <= -1.6e-74) || !(x <= 7e-110)) {
tmp = 2.0 * (eps * x);
} else {
tmp = eps * eps;
}
return tmp;
}
def code(x, eps): tmp = 0 if (x <= -1.6e-74) or not (x <= 7e-110): tmp = 2.0 * (eps * x) else: tmp = eps * eps return tmp
function code(x, eps) tmp = 0.0 if ((x <= -1.6e-74) || !(x <= 7e-110)) tmp = Float64(2.0 * Float64(eps * x)); else tmp = Float64(eps * eps); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((x <= -1.6e-74) || ~((x <= 7e-110))) tmp = 2.0 * (eps * x); else tmp = eps * eps; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[x, -1.6e-74], N[Not[LessEqual[x, 7e-110]], $MachinePrecision]], N[(2.0 * N[(eps * x), $MachinePrecision]), $MachinePrecision], N[(eps * eps), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{-74} \lor \neg \left(x \leq 7 \cdot 10^{-110}\right):\\
\;\;\;\;2 \cdot \left(\varepsilon \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \varepsilon\\
\end{array}
\end{array}
if x < -1.5999999999999999e-74 or 6.99999999999999947e-110 < x Initial program 32.1%
+-commutative32.1%
unpow232.1%
unpow232.1%
difference-of-squares32.0%
sub-neg32.0%
distribute-lft-in32.0%
+-commutative32.0%
distribute-lft-in32.0%
+-commutative32.0%
sub-neg32.0%
associate--l+100.0%
+-inverses100.0%
+-rgt-identity100.0%
*-commutative100.0%
associate-+l+100.0%
count-2100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in eps around 0 88.3%
*-commutative88.3%
Simplified88.3%
if -1.5999999999999999e-74 < x < 6.99999999999999947e-110Initial program 96.0%
+-commutative96.0%
unpow296.0%
unpow296.0%
difference-of-squares96.0%
sub-neg96.0%
distribute-lft-in96.0%
+-commutative96.0%
distribute-lft-in96.0%
+-commutative96.0%
sub-neg96.0%
associate--l+100.0%
+-inverses100.0%
+-rgt-identity100.0%
*-commutative100.0%
associate-+l+100.0%
count-2100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in eps around inf 94.2%
Final simplification92.0%
(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 72.6%
+-commutative72.6%
unpow272.6%
unpow272.6%
difference-of-squares72.5%
sub-neg72.5%
distribute-lft-in72.5%
+-commutative72.5%
distribute-lft-in72.5%
+-commutative72.5%
sub-neg72.5%
associate--l+100.0%
+-inverses100.0%
+-rgt-identity100.0%
*-commutative100.0%
associate-+l+100.0%
count-2100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in eps around inf 69.7%
herbie shell --seed 2024137
(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)))