
(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 (fma (* eps 2.0) x (* eps eps)))
double code(double x, double eps) {
return fma((eps * 2.0), x, (eps * eps));
}
function code(x, eps) return fma(Float64(eps * 2.0), x, Float64(eps * eps)) end
code[x_, eps_] := N[(N[(eps * 2.0), $MachinePrecision] * x + N[(eps * eps), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\varepsilon \cdot 2, x, \varepsilon \cdot \varepsilon\right)
\end{array}
Initial program 72.3%
unpow2N/A
unpow2N/A
difference-of-squaresN/A
*-commutativeN/A
+-commutativeN/A
associate--l+N/A
+-inversesN/A
+-rgt-identityN/A
*-lowering-*.f64N/A
+-commutativeN/A
associate-+l+N/A
--rgt-identityN/A
associate-+l-N/A
neg-sub0N/A
--lowering--.f64N/A
count-2N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-eval100.0%
Simplified100.0%
sub-negN/A
distribute-rgt-inN/A
distribute-lft-neg-outN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
distribute-lft-neg-outN/A
*-commutativeN/A
distribute-lft-neg-inN/A
metadata-evalN/A
associate-*l*N/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f64100.0%
Applied egg-rr100.0%
+-commutativeN/A
associate-*r*N/A
fma-defineN/A
fma-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f64100.0%
Applied egg-rr100.0%
(FPCore (x eps) :precision binary64 (let* ((t_0 (* eps (* 2.0 x)))) (if (<= x -3.4e-130) t_0 (if (<= x 7.5e-120) (* eps eps) t_0))))
double code(double x, double eps) {
double t_0 = eps * (2.0 * x);
double tmp;
if (x <= -3.4e-130) {
tmp = t_0;
} else if (x <= 7.5e-120) {
tmp = eps * eps;
} else {
tmp = t_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 = eps * (2.0d0 * x)
if (x <= (-3.4d-130)) then
tmp = t_0
else if (x <= 7.5d-120) then
tmp = eps * eps
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = eps * (2.0 * x);
double tmp;
if (x <= -3.4e-130) {
tmp = t_0;
} else if (x <= 7.5e-120) {
tmp = eps * eps;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, eps): t_0 = eps * (2.0 * x) tmp = 0 if x <= -3.4e-130: tmp = t_0 elif x <= 7.5e-120: tmp = eps * eps else: tmp = t_0 return tmp
function code(x, eps) t_0 = Float64(eps * Float64(2.0 * x)) tmp = 0.0 if (x <= -3.4e-130) tmp = t_0; elseif (x <= 7.5e-120) tmp = Float64(eps * eps); else tmp = t_0; end return tmp end
function tmp_2 = code(x, eps) t_0 = eps * (2.0 * x); tmp = 0.0; if (x <= -3.4e-130) tmp = t_0; elseif (x <= 7.5e-120) tmp = eps * eps; else tmp = t_0; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(eps * N[(2.0 * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -3.4e-130], t$95$0, If[LessEqual[x, 7.5e-120], N[(eps * eps), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \varepsilon \cdot \left(2 \cdot x\right)\\
\mathbf{if}\;x \leq -3.4 \cdot 10^{-130}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 7.5 \cdot 10^{-120}:\\
\;\;\;\;\varepsilon \cdot \varepsilon\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -3.40000000000000005e-130 or 7.5000000000000004e-120 < x Initial program 39.9%
unpow2N/A
unpow2N/A
difference-of-squaresN/A
*-commutativeN/A
+-commutativeN/A
associate--l+N/A
+-inversesN/A
+-rgt-identityN/A
*-lowering-*.f64N/A
+-commutativeN/A
associate-+l+N/A
--rgt-identityN/A
associate-+l-N/A
neg-sub0N/A
--lowering--.f64N/A
count-2N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-eval100.0%
Simplified100.0%
Taylor expanded in eps around 0
*-lowering-*.f6483.9%
Simplified83.9%
if -3.40000000000000005e-130 < x < 7.5000000000000004e-120Initial program 98.8%
unpow2N/A
unpow2N/A
difference-of-squaresN/A
*-commutativeN/A
+-commutativeN/A
associate--l+N/A
+-inversesN/A
+-rgt-identityN/A
*-lowering-*.f64N/A
+-commutativeN/A
associate-+l+N/A
--rgt-identityN/A
associate-+l-N/A
neg-sub0N/A
--lowering--.f64N/A
count-2N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-eval100.0%
Simplified100.0%
Taylor expanded in eps around inf
unpow2N/A
*-lowering-*.f6498.0%
Simplified98.0%
(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.3%
unpow2N/A
unpow2N/A
difference-of-squaresN/A
*-commutativeN/A
+-commutativeN/A
associate--l+N/A
+-inversesN/A
+-rgt-identityN/A
*-lowering-*.f64N/A
+-commutativeN/A
associate-+l+N/A
--rgt-identityN/A
associate-+l-N/A
neg-sub0N/A
--lowering--.f64N/A
count-2N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-eval100.0%
Simplified100.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.3%
unpow2N/A
unpow2N/A
difference-of-squaresN/A
*-commutativeN/A
+-commutativeN/A
associate--l+N/A
+-inversesN/A
+-rgt-identityN/A
*-lowering-*.f64N/A
+-commutativeN/A
associate-+l+N/A
--rgt-identityN/A
associate-+l-N/A
neg-sub0N/A
--lowering--.f64N/A
count-2N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-eval100.0%
Simplified100.0%
Taylor expanded in eps around inf
unpow2N/A
*-lowering-*.f6469.8%
Simplified69.8%
herbie shell --seed 2024152
(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)))