
(FPCore (x eps) :precision binary64 (- x (sqrt (- (* x x) eps))))
double code(double x, double eps) {
return x - sqrt(((x * x) - eps));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = x - sqrt(((x * x) - eps))
end function
public static double code(double x, double eps) {
return x - Math.sqrt(((x * x) - eps));
}
def code(x, eps): return x - math.sqrt(((x * x) - eps))
function code(x, eps) return Float64(x - sqrt(Float64(Float64(x * x) - eps))) end
function tmp = code(x, eps) tmp = x - sqrt(((x * x) - eps)); end
code[x_, eps_] := N[(x - N[Sqrt[N[(N[(x * x), $MachinePrecision] - eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \sqrt{x \cdot x - \varepsilon}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x eps) :precision binary64 (- x (sqrt (- (* x x) eps))))
double code(double x, double eps) {
return x - sqrt(((x * x) - eps));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = x - sqrt(((x * x) - eps))
end function
public static double code(double x, double eps) {
return x - Math.sqrt(((x * x) - eps));
}
def code(x, eps): return x - math.sqrt(((x * x) - eps))
function code(x, eps) return Float64(x - sqrt(Float64(Float64(x * x) - eps))) end
function tmp = code(x, eps) tmp = x - sqrt(((x * x) - eps)); end
code[x_, eps_] := N[(x - N[Sqrt[N[(N[(x * x), $MachinePrecision] - eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \sqrt{x \cdot x - \varepsilon}
\end{array}
(FPCore (x eps) :precision binary64 (if (<= (- x (sqrt (- (* x x) eps))) -2e-153) (- x (sqrt (* eps (fma x (/ x eps) -1.0)))) (/ (fma eps 0.5 (/ (* 0.125 (* eps eps)) (* x x))) x)))
double code(double x, double eps) {
double tmp;
if ((x - sqrt(((x * x) - eps))) <= -2e-153) {
tmp = x - sqrt((eps * fma(x, (x / eps), -1.0)));
} else {
tmp = fma(eps, 0.5, ((0.125 * (eps * eps)) / (x * x))) / x;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (Float64(x - sqrt(Float64(Float64(x * x) - eps))) <= -2e-153) tmp = Float64(x - sqrt(Float64(eps * fma(x, Float64(x / eps), -1.0)))); else tmp = Float64(fma(eps, 0.5, Float64(Float64(0.125 * Float64(eps * eps)) / Float64(x * x))) / x); end return tmp end
code[x_, eps_] := If[LessEqual[N[(x - N[Sqrt[N[(N[(x * x), $MachinePrecision] - eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -2e-153], N[(x - N[Sqrt[N[(eps * N[(x * N[(x / eps), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(eps * 0.5 + N[(N[(0.125 * N[(eps * eps), $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x - \sqrt{x \cdot x - \varepsilon} \leq -2 \cdot 10^{-153}:\\
\;\;\;\;x - \sqrt{\varepsilon \cdot \mathsf{fma}\left(x, \frac{x}{\varepsilon}, -1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\varepsilon, 0.5, \frac{0.125 \cdot \left(\varepsilon \cdot \varepsilon\right)}{x \cdot x}\right)}{x}\\
\end{array}
\end{array}
if (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) < -2.00000000000000008e-153Initial program 98.4%
Taylor expanded in eps around inf
*-lowering-*.f64N/A
sub-negN/A
unpow2N/A
associate-/l*N/A
metadata-evalN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6498.4
Simplified98.4%
if -2.00000000000000008e-153 < (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) Initial program 6.4%
Taylor expanded in x around inf
sub-negN/A
+-commutativeN/A
metadata-evalN/A
distribute-lft-neg-inN/A
distribute-neg-inN/A
/-lowering-/.f64N/A
Simplified99.9%
(FPCore (x eps) :precision binary64 (if (<= (- x (sqrt (- (* x x) eps))) -2e-153) (- x (sqrt (* eps (fma x (/ x eps) -1.0)))) (/ (* eps (fma eps (/ 0.125 (* x x)) 0.5)) x)))
double code(double x, double eps) {
double tmp;
if ((x - sqrt(((x * x) - eps))) <= -2e-153) {
tmp = x - sqrt((eps * fma(x, (x / eps), -1.0)));
} else {
tmp = (eps * fma(eps, (0.125 / (x * x)), 0.5)) / x;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (Float64(x - sqrt(Float64(Float64(x * x) - eps))) <= -2e-153) tmp = Float64(x - sqrt(Float64(eps * fma(x, Float64(x / eps), -1.0)))); else tmp = Float64(Float64(eps * fma(eps, Float64(0.125 / Float64(x * x)), 0.5)) / x); end return tmp end
code[x_, eps_] := If[LessEqual[N[(x - N[Sqrt[N[(N[(x * x), $MachinePrecision] - eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -2e-153], N[(x - N[Sqrt[N[(eps * N[(x * N[(x / eps), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(eps * N[(eps * N[(0.125 / N[(x * x), $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x - \sqrt{x \cdot x - \varepsilon} \leq -2 \cdot 10^{-153}:\\
\;\;\;\;x - \sqrt{\varepsilon \cdot \mathsf{fma}\left(x, \frac{x}{\varepsilon}, -1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon \cdot \mathsf{fma}\left(\varepsilon, \frac{0.125}{x \cdot x}, 0.5\right)}{x}\\
\end{array}
\end{array}
if (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) < -2.00000000000000008e-153Initial program 98.4%
Taylor expanded in eps around inf
*-lowering-*.f64N/A
sub-negN/A
unpow2N/A
associate-/l*N/A
metadata-evalN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6498.4
Simplified98.4%
if -2.00000000000000008e-153 < (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) Initial program 6.4%
sub-negN/A
accelerator-lowering-fma.f64N/A
neg-lowering-neg.f646.5
Applied egg-rr6.5%
Taylor expanded in x around inf
metadata-evalN/A
distribute-lft-neg-inN/A
unsub-negN/A
distribute-neg-inN/A
+-commutativeN/A
/-lowering-/.f64N/A
Simplified99.9%
(FPCore (x eps) :precision binary64 (if (<= (- x (sqrt (- (* x x) eps))) -2e-153) (- x (sqrt (* eps (fma x (/ x eps) -1.0)))) (* (fma eps (/ 0.125 (* x x)) 0.5) (/ eps x))))
double code(double x, double eps) {
double tmp;
if ((x - sqrt(((x * x) - eps))) <= -2e-153) {
tmp = x - sqrt((eps * fma(x, (x / eps), -1.0)));
} else {
tmp = fma(eps, (0.125 / (x * x)), 0.5) * (eps / x);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (Float64(x - sqrt(Float64(Float64(x * x) - eps))) <= -2e-153) tmp = Float64(x - sqrt(Float64(eps * fma(x, Float64(x / eps), -1.0)))); else tmp = Float64(fma(eps, Float64(0.125 / Float64(x * x)), 0.5) * Float64(eps / x)); end return tmp end
code[x_, eps_] := If[LessEqual[N[(x - N[Sqrt[N[(N[(x * x), $MachinePrecision] - eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -2e-153], N[(x - N[Sqrt[N[(eps * N[(x * N[(x / eps), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(eps * N[(0.125 / N[(x * x), $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision] * N[(eps / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x - \sqrt{x \cdot x - \varepsilon} \leq -2 \cdot 10^{-153}:\\
\;\;\;\;x - \sqrt{\varepsilon \cdot \mathsf{fma}\left(x, \frac{x}{\varepsilon}, -1\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\varepsilon, \frac{0.125}{x \cdot x}, 0.5\right) \cdot \frac{\varepsilon}{x}\\
\end{array}
\end{array}
if (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) < -2.00000000000000008e-153Initial program 98.4%
Taylor expanded in eps around inf
*-lowering-*.f64N/A
sub-negN/A
unpow2N/A
associate-/l*N/A
metadata-evalN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6498.4
Simplified98.4%
if -2.00000000000000008e-153 < (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) Initial program 6.4%
sub-negN/A
accelerator-lowering-fma.f64N/A
neg-lowering-neg.f646.5
Applied egg-rr6.5%
Taylor expanded in x around inf
metadata-evalN/A
distribute-lft-neg-inN/A
unsub-negN/A
distribute-neg-inN/A
+-commutativeN/A
/-lowering-/.f64N/A
Simplified99.9%
*-commutativeN/A
associate-/l*N/A
*-lowering-*.f64N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
/-lowering-/.f6499.9
Applied egg-rr99.9%
(FPCore (x eps) :precision binary64 (if (<= (- x (sqrt (- (* x x) eps))) -2e-153) (- x (sqrt (* eps (fma x (/ x eps) -1.0)))) (* eps (/ (fma eps (/ 0.125 (* x x)) 0.5) x))))
double code(double x, double eps) {
double tmp;
if ((x - sqrt(((x * x) - eps))) <= -2e-153) {
tmp = x - sqrt((eps * fma(x, (x / eps), -1.0)));
} else {
tmp = eps * (fma(eps, (0.125 / (x * x)), 0.5) / x);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (Float64(x - sqrt(Float64(Float64(x * x) - eps))) <= -2e-153) tmp = Float64(x - sqrt(Float64(eps * fma(x, Float64(x / eps), -1.0)))); else tmp = Float64(eps * Float64(fma(eps, Float64(0.125 / Float64(x * x)), 0.5) / x)); end return tmp end
code[x_, eps_] := If[LessEqual[N[(x - N[Sqrt[N[(N[(x * x), $MachinePrecision] - eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -2e-153], N[(x - N[Sqrt[N[(eps * N[(x * N[(x / eps), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(eps * N[(N[(eps * N[(0.125 / N[(x * x), $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x - \sqrt{x \cdot x - \varepsilon} \leq -2 \cdot 10^{-153}:\\
\;\;\;\;x - \sqrt{\varepsilon \cdot \mathsf{fma}\left(x, \frac{x}{\varepsilon}, -1\right)}\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \frac{\mathsf{fma}\left(\varepsilon, \frac{0.125}{x \cdot x}, 0.5\right)}{x}\\
\end{array}
\end{array}
if (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) < -2.00000000000000008e-153Initial program 98.4%
Taylor expanded in eps around inf
*-lowering-*.f64N/A
sub-negN/A
unpow2N/A
associate-/l*N/A
metadata-evalN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6498.4
Simplified98.4%
if -2.00000000000000008e-153 < (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) Initial program 6.4%
sub-negN/A
accelerator-lowering-fma.f64N/A
neg-lowering-neg.f646.5
Applied egg-rr6.5%
Taylor expanded in x around inf
metadata-evalN/A
distribute-lft-neg-inN/A
unsub-negN/A
distribute-neg-inN/A
+-commutativeN/A
/-lowering-/.f64N/A
Simplified99.9%
associate-/l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f6499.5
Applied egg-rr99.5%
Final simplification98.9%
(FPCore (x eps) :precision binary64 (if (<= (- x (sqrt (- (* x x) eps))) -2e-153) (- x (sqrt (* eps (fma x (/ x eps) -1.0)))) (/ (* eps 0.5) x)))
double code(double x, double eps) {
double tmp;
if ((x - sqrt(((x * x) - eps))) <= -2e-153) {
tmp = x - sqrt((eps * fma(x, (x / eps), -1.0)));
} else {
tmp = (eps * 0.5) / x;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (Float64(x - sqrt(Float64(Float64(x * x) - eps))) <= -2e-153) tmp = Float64(x - sqrt(Float64(eps * fma(x, Float64(x / eps), -1.0)))); else tmp = Float64(Float64(eps * 0.5) / x); end return tmp end
code[x_, eps_] := If[LessEqual[N[(x - N[Sqrt[N[(N[(x * x), $MachinePrecision] - eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -2e-153], N[(x - N[Sqrt[N[(eps * N[(x * N[(x / eps), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(eps * 0.5), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x - \sqrt{x \cdot x - \varepsilon} \leq -2 \cdot 10^{-153}:\\
\;\;\;\;x - \sqrt{\varepsilon \cdot \mathsf{fma}\left(x, \frac{x}{\varepsilon}, -1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon \cdot 0.5}{x}\\
\end{array}
\end{array}
if (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) < -2.00000000000000008e-153Initial program 98.4%
Taylor expanded in eps around inf
*-lowering-*.f64N/A
sub-negN/A
unpow2N/A
associate-/l*N/A
metadata-evalN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6498.4
Simplified98.4%
if -2.00000000000000008e-153 < (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) Initial program 6.4%
Taylor expanded in x around inf
associate-*r/N/A
metadata-evalN/A
distribute-lft-neg-inN/A
/-lowering-/.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
metadata-evalN/A
*-lowering-*.f6499.3
Simplified99.3%
(FPCore (x eps) :precision binary64 (let* ((t_0 (- x (sqrt (- (* x x) eps))))) (if (<= t_0 -2e-153) t_0 (/ (* eps 0.5) x))))
double code(double x, double eps) {
double t_0 = x - sqrt(((x * x) - eps));
double tmp;
if (t_0 <= -2e-153) {
tmp = t_0;
} else {
tmp = (eps * 0.5) / x;
}
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 - sqrt(((x * x) - eps))
if (t_0 <= (-2d-153)) then
tmp = t_0
else
tmp = (eps * 0.5d0) / x
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = x - Math.sqrt(((x * x) - eps));
double tmp;
if (t_0 <= -2e-153) {
tmp = t_0;
} else {
tmp = (eps * 0.5) / x;
}
return tmp;
}
def code(x, eps): t_0 = x - math.sqrt(((x * x) - eps)) tmp = 0 if t_0 <= -2e-153: tmp = t_0 else: tmp = (eps * 0.5) / x return tmp
function code(x, eps) t_0 = Float64(x - sqrt(Float64(Float64(x * x) - eps))) tmp = 0.0 if (t_0 <= -2e-153) tmp = t_0; else tmp = Float64(Float64(eps * 0.5) / x); end return tmp end
function tmp_2 = code(x, eps) t_0 = x - sqrt(((x * x) - eps)); tmp = 0.0; if (t_0 <= -2e-153) tmp = t_0; else tmp = (eps * 0.5) / x; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(x - N[Sqrt[N[(N[(x * x), $MachinePrecision] - eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e-153], t$95$0, N[(N[(eps * 0.5), $MachinePrecision] / x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x - \sqrt{x \cdot x - \varepsilon}\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{-153}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon \cdot 0.5}{x}\\
\end{array}
\end{array}
if (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) < -2.00000000000000008e-153Initial program 98.4%
if -2.00000000000000008e-153 < (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) Initial program 6.4%
Taylor expanded in x around inf
associate-*r/N/A
metadata-evalN/A
distribute-lft-neg-inN/A
/-lowering-/.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
metadata-evalN/A
*-lowering-*.f6499.3
Simplified99.3%
(FPCore (x eps) :precision binary64 (if (<= (- x (sqrt (- (* x x) eps))) -2e-153) (- x (sqrt (fabs eps))) (/ (* eps 0.5) x)))
double code(double x, double eps) {
double tmp;
if ((x - sqrt(((x * x) - eps))) <= -2e-153) {
tmp = x - sqrt(fabs(eps));
} else {
tmp = (eps * 0.5) / x;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((x - sqrt(((x * x) - eps))) <= (-2d-153)) then
tmp = x - sqrt(abs(eps))
else
tmp = (eps * 0.5d0) / x
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((x - Math.sqrt(((x * x) - eps))) <= -2e-153) {
tmp = x - Math.sqrt(Math.abs(eps));
} else {
tmp = (eps * 0.5) / x;
}
return tmp;
}
def code(x, eps): tmp = 0 if (x - math.sqrt(((x * x) - eps))) <= -2e-153: tmp = x - math.sqrt(math.fabs(eps)) else: tmp = (eps * 0.5) / x return tmp
function code(x, eps) tmp = 0.0 if (Float64(x - sqrt(Float64(Float64(x * x) - eps))) <= -2e-153) tmp = Float64(x - sqrt(abs(eps))); else tmp = Float64(Float64(eps * 0.5) / x); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((x - sqrt(((x * x) - eps))) <= -2e-153) tmp = x - sqrt(abs(eps)); else tmp = (eps * 0.5) / x; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[N[(x - N[Sqrt[N[(N[(x * x), $MachinePrecision] - eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -2e-153], N[(x - N[Sqrt[N[Abs[eps], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(eps * 0.5), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x - \sqrt{x \cdot x - \varepsilon} \leq -2 \cdot 10^{-153}:\\
\;\;\;\;x - \sqrt{\left|\varepsilon\right|}\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon \cdot 0.5}{x}\\
\end{array}
\end{array}
if (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) < -2.00000000000000008e-153Initial program 98.4%
Taylor expanded in x around 0
mul-1-negN/A
neg-lowering-neg.f6495.8
Simplified95.8%
flip--N/A
rem-square-sqrtN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
*-lowering-*.f64N/A
neg-lowering-neg.f64N/A
+-lowering-+.f64N/A
sqrt-lowering-sqrt.f64N/A
neg-lowering-neg.f6495.1
Applied egg-rr95.1%
rem-square-sqrtN/A
flip--N/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
rem-square-sqrtN/A
sqrt-unprodN/A
sqr-negN/A
rem-sqrt-squareN/A
fabs-lowering-fabs.f6495.8
Applied egg-rr95.8%
if -2.00000000000000008e-153 < (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) Initial program 6.4%
Taylor expanded in x around inf
associate-*r/N/A
metadata-evalN/A
distribute-lft-neg-inN/A
/-lowering-/.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
metadata-evalN/A
*-lowering-*.f6499.3
Simplified99.3%
(FPCore (x eps) :precision binary64 (if (<= (- x (sqrt (- (* x x) eps))) -2e-153) (- x (sqrt (fabs eps))) (* eps (/ 0.5 x))))
double code(double x, double eps) {
double tmp;
if ((x - sqrt(((x * x) - eps))) <= -2e-153) {
tmp = x - sqrt(fabs(eps));
} else {
tmp = eps * (0.5 / x);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((x - sqrt(((x * x) - eps))) <= (-2d-153)) then
tmp = x - sqrt(abs(eps))
else
tmp = eps * (0.5d0 / x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((x - Math.sqrt(((x * x) - eps))) <= -2e-153) {
tmp = x - Math.sqrt(Math.abs(eps));
} else {
tmp = eps * (0.5 / x);
}
return tmp;
}
def code(x, eps): tmp = 0 if (x - math.sqrt(((x * x) - eps))) <= -2e-153: tmp = x - math.sqrt(math.fabs(eps)) else: tmp = eps * (0.5 / x) return tmp
function code(x, eps) tmp = 0.0 if (Float64(x - sqrt(Float64(Float64(x * x) - eps))) <= -2e-153) tmp = Float64(x - sqrt(abs(eps))); else tmp = Float64(eps * Float64(0.5 / x)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((x - sqrt(((x * x) - eps))) <= -2e-153) tmp = x - sqrt(abs(eps)); else tmp = eps * (0.5 / x); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[N[(x - N[Sqrt[N[(N[(x * x), $MachinePrecision] - eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -2e-153], N[(x - N[Sqrt[N[Abs[eps], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(eps * N[(0.5 / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x - \sqrt{x \cdot x - \varepsilon} \leq -2 \cdot 10^{-153}:\\
\;\;\;\;x - \sqrt{\left|\varepsilon\right|}\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \frac{0.5}{x}\\
\end{array}
\end{array}
if (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) < -2.00000000000000008e-153Initial program 98.4%
Taylor expanded in x around 0
mul-1-negN/A
neg-lowering-neg.f6495.8
Simplified95.8%
flip--N/A
rem-square-sqrtN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
*-lowering-*.f64N/A
neg-lowering-neg.f64N/A
+-lowering-+.f64N/A
sqrt-lowering-sqrt.f64N/A
neg-lowering-neg.f6495.1
Applied egg-rr95.1%
rem-square-sqrtN/A
flip--N/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
rem-square-sqrtN/A
sqrt-unprodN/A
sqr-negN/A
rem-sqrt-squareN/A
fabs-lowering-fabs.f6495.8
Applied egg-rr95.8%
if -2.00000000000000008e-153 < (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) Initial program 6.4%
Taylor expanded in x around inf
associate-*r/N/A
metadata-evalN/A
distribute-lft-neg-inN/A
/-lowering-/.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
metadata-evalN/A
*-lowering-*.f6499.3
Simplified99.3%
associate-/l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
/-lowering-/.f6498.9
Applied egg-rr98.9%
Final simplification97.0%
(FPCore (x eps) :precision binary64 (if (<= (- x (sqrt (- (* x x) eps))) -2e-153) (- x (sqrt (fabs eps))) (/ eps x)))
double code(double x, double eps) {
double tmp;
if ((x - sqrt(((x * x) - eps))) <= -2e-153) {
tmp = x - sqrt(fabs(eps));
} else {
tmp = eps / x;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((x - sqrt(((x * x) - eps))) <= (-2d-153)) then
tmp = x - sqrt(abs(eps))
else
tmp = eps / x
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((x - Math.sqrt(((x * x) - eps))) <= -2e-153) {
tmp = x - Math.sqrt(Math.abs(eps));
} else {
tmp = eps / x;
}
return tmp;
}
def code(x, eps): tmp = 0 if (x - math.sqrt(((x * x) - eps))) <= -2e-153: tmp = x - math.sqrt(math.fabs(eps)) else: tmp = eps / x return tmp
function code(x, eps) tmp = 0.0 if (Float64(x - sqrt(Float64(Float64(x * x) - eps))) <= -2e-153) tmp = Float64(x - sqrt(abs(eps))); else tmp = Float64(eps / x); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((x - sqrt(((x * x) - eps))) <= -2e-153) tmp = x - sqrt(abs(eps)); else tmp = eps / x; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[N[(x - N[Sqrt[N[(N[(x * x), $MachinePrecision] - eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -2e-153], N[(x - N[Sqrt[N[Abs[eps], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(eps / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x - \sqrt{x \cdot x - \varepsilon} \leq -2 \cdot 10^{-153}:\\
\;\;\;\;x - \sqrt{\left|\varepsilon\right|}\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon}{x}\\
\end{array}
\end{array}
if (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) < -2.00000000000000008e-153Initial program 98.4%
Taylor expanded in x around 0
mul-1-negN/A
neg-lowering-neg.f6495.8
Simplified95.8%
flip--N/A
rem-square-sqrtN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
*-lowering-*.f64N/A
neg-lowering-neg.f64N/A
+-lowering-+.f64N/A
sqrt-lowering-sqrt.f64N/A
neg-lowering-neg.f6495.1
Applied egg-rr95.1%
rem-square-sqrtN/A
flip--N/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
rem-square-sqrtN/A
sqrt-unprodN/A
sqr-negN/A
rem-sqrt-squareN/A
fabs-lowering-fabs.f6495.8
Applied egg-rr95.8%
if -2.00000000000000008e-153 < (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) Initial program 6.4%
Taylor expanded in x around 0
mul-1-negN/A
neg-lowering-neg.f641.1
Simplified1.1%
flip--N/A
rem-square-sqrtN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
*-lowering-*.f64N/A
neg-lowering-neg.f64N/A
+-lowering-+.f64N/A
sqrt-lowering-sqrt.f64N/A
neg-lowering-neg.f641.1
Applied egg-rr1.1%
Taylor expanded in x around 0
Simplified8.6%
Taylor expanded in x around inf
/-lowering-/.f6418.9
Simplified18.9%
(FPCore (x eps) :precision binary64 (if (<= (- x (sqrt (- (* x x) eps))) -2e-153) (- (sqrt (fabs eps))) (/ eps x)))
double code(double x, double eps) {
double tmp;
if ((x - sqrt(((x * x) - eps))) <= -2e-153) {
tmp = -sqrt(fabs(eps));
} else {
tmp = eps / x;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((x - sqrt(((x * x) - eps))) <= (-2d-153)) then
tmp = -sqrt(abs(eps))
else
tmp = eps / x
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((x - Math.sqrt(((x * x) - eps))) <= -2e-153) {
tmp = -Math.sqrt(Math.abs(eps));
} else {
tmp = eps / x;
}
return tmp;
}
def code(x, eps): tmp = 0 if (x - math.sqrt(((x * x) - eps))) <= -2e-153: tmp = -math.sqrt(math.fabs(eps)) else: tmp = eps / x return tmp
function code(x, eps) tmp = 0.0 if (Float64(x - sqrt(Float64(Float64(x * x) - eps))) <= -2e-153) tmp = Float64(-sqrt(abs(eps))); else tmp = Float64(eps / x); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((x - sqrt(((x * x) - eps))) <= -2e-153) tmp = -sqrt(abs(eps)); else tmp = eps / x; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[N[(x - N[Sqrt[N[(N[(x * x), $MachinePrecision] - eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -2e-153], (-N[Sqrt[N[Abs[eps], $MachinePrecision]], $MachinePrecision]), N[(eps / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x - \sqrt{x \cdot x - \varepsilon} \leq -2 \cdot 10^{-153}:\\
\;\;\;\;-\sqrt{\left|\varepsilon\right|}\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon}{x}\\
\end{array}
\end{array}
if (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) < -2.00000000000000008e-153Initial program 98.4%
Taylor expanded in x around 0
mul-1-negN/A
neg-lowering-neg.f6495.8
Simplified95.8%
flip--N/A
rem-square-sqrtN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
*-lowering-*.f64N/A
neg-lowering-neg.f64N/A
+-lowering-+.f64N/A
sqrt-lowering-sqrt.f64N/A
neg-lowering-neg.f6495.1
Applied egg-rr95.1%
rem-square-sqrtN/A
flip--N/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
rem-square-sqrtN/A
sqrt-unprodN/A
sqr-negN/A
rem-sqrt-squareN/A
fabs-lowering-fabs.f6495.8
Applied egg-rr95.8%
Taylor expanded in x around 0
mul-1-negN/A
neg-lowering-neg.f64N/A
sqrt-lowering-sqrt.f64N/A
fabs-lowering-fabs.f6494.8
Simplified94.8%
if -2.00000000000000008e-153 < (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) Initial program 6.4%
Taylor expanded in x around 0
mul-1-negN/A
neg-lowering-neg.f641.1
Simplified1.1%
flip--N/A
rem-square-sqrtN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
*-lowering-*.f64N/A
neg-lowering-neg.f64N/A
+-lowering-+.f64N/A
sqrt-lowering-sqrt.f64N/A
neg-lowering-neg.f641.1
Applied egg-rr1.1%
Taylor expanded in x around 0
Simplified8.6%
Taylor expanded in x around inf
/-lowering-/.f6418.9
Simplified18.9%
(FPCore (x eps) :precision binary64 (/ eps x))
double code(double x, double eps) {
return eps / x;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = eps / x
end function
public static double code(double x, double eps) {
return eps / x;
}
def code(x, eps): return eps / x
function code(x, eps) return Float64(eps / x) end
function tmp = code(x, eps) tmp = eps / x; end
code[x_, eps_] := N[(eps / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{\varepsilon}{x}
\end{array}
Initial program 62.5%
Taylor expanded in x around 0
mul-1-negN/A
neg-lowering-neg.f6458.8
Simplified58.8%
flip--N/A
rem-square-sqrtN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
*-lowering-*.f64N/A
neg-lowering-neg.f64N/A
+-lowering-+.f64N/A
sqrt-lowering-sqrt.f64N/A
neg-lowering-neg.f6458.4
Applied egg-rr58.4%
Taylor expanded in x around 0
Simplified61.6%
Taylor expanded in x around inf
/-lowering-/.f6411.3
Simplified11.3%
(FPCore (x eps) :precision binary64 0.0)
double code(double x, double eps) {
return 0.0;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = 0.0d0
end function
public static double code(double x, double eps) {
return 0.0;
}
def code(x, eps): return 0.0
function code(x, eps) return 0.0 end
function tmp = code(x, eps) tmp = 0.0; end
code[x_, eps_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 62.5%
Taylor expanded in x around inf
Simplified4.4%
+-inverses4.4
Applied egg-rr4.4%
(FPCore (x eps) :precision binary64 (/ eps (+ x (sqrt (- (* x x) eps)))))
double code(double x, double eps) {
return eps / (x + sqrt(((x * x) - eps)));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = eps / (x + sqrt(((x * x) - eps)))
end function
public static double code(double x, double eps) {
return eps / (x + Math.sqrt(((x * x) - eps)));
}
def code(x, eps): return eps / (x + math.sqrt(((x * x) - eps)))
function code(x, eps) return Float64(eps / Float64(x + sqrt(Float64(Float64(x * x) - eps)))) end
function tmp = code(x, eps) tmp = eps / (x + sqrt(((x * x) - eps))); end
code[x_, eps_] := N[(eps / N[(x + N[Sqrt[N[(N[(x * x), $MachinePrecision] - eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\varepsilon}{x + \sqrt{x \cdot x - \varepsilon}}
\end{array}
herbie shell --seed 2024199
(FPCore (x eps)
:name "ENA, Section 1.4, Exercise 4d"
:precision binary64
:pre (and (and (<= 0.0 x) (<= x 1000000000.0)) (and (<= -1.0 eps) (<= eps 1.0)))
:alt
(! :herbie-platform default (/ eps (+ x (sqrt (- (* x x) eps)))))
(- x (sqrt (- (* x x) eps))))