
(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 (<= eps -5e-310)
(/ eps (+ x (hypot x (sqrt (- eps)))))
(/
1.0
(fma -0.125 (/ (/ eps (pow x 2.0)) x) (fma 2.0 (/ x eps) (/ -0.5 x))))))
double code(double x, double eps) {
double tmp;
if (eps <= -5e-310) {
tmp = eps / (x + hypot(x, sqrt(-eps)));
} else {
tmp = 1.0 / fma(-0.125, ((eps / pow(x, 2.0)) / x), fma(2.0, (x / eps), (-0.5 / x)));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (eps <= -5e-310) tmp = Float64(eps / Float64(x + hypot(x, sqrt(Float64(-eps))))); else tmp = Float64(1.0 / fma(-0.125, Float64(Float64(eps / (x ^ 2.0)) / x), fma(2.0, Float64(x / eps), Float64(-0.5 / x)))); end return tmp end
code[x_, eps_] := If[LessEqual[eps, -5e-310], N[(eps / N[(x + N[Sqrt[x ^ 2 + N[Sqrt[(-eps)], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(-0.125 * N[(N[(eps / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] + N[(2.0 * N[(x / eps), $MachinePrecision] + N[(-0.5 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{\varepsilon}{x + \mathsf{hypot}\left(x, \sqrt{-\varepsilon}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(-0.125, \frac{\frac{\varepsilon}{{x}^{2}}}{x}, \mathsf{fma}\left(2, \frac{x}{\varepsilon}, \frac{-0.5}{x}\right)\right)}\\
\end{array}
\end{array}
if eps < -4.999999999999985e-310Initial program 73.4%
flip--73.4%
div-inv73.2%
add-sqr-sqrt73.0%
associate--r-99.3%
pow299.3%
pow299.3%
sub-neg99.3%
add-sqr-sqrt99.4%
hypot-def99.4%
Applied egg-rr99.4%
+-inverses99.4%
+-lft-identity99.4%
associate-*r/99.4%
associate-/l*99.4%
/-rgt-identity99.4%
Simplified99.4%
if -4.999999999999985e-310 < eps Initial program 12.6%
flip--12.7%
div-inv12.7%
add-sqr-sqrt12.7%
associate--r-99.6%
pow299.6%
pow299.6%
sub-neg99.6%
add-sqr-sqrt0.0%
hypot-def0.0%
Applied egg-rr0.0%
*-commutative0.0%
associate-/r/0.0%
+-inverses0.0%
+-commutative0.0%
Simplified0.0%
Taylor expanded in x around inf 0.0%
fma-def0.0%
metadata-eval0.0%
pow-sqr0.0%
unpow20.0%
rem-square-sqrt0.0%
unpow20.0%
rem-square-sqrt0.0%
metadata-eval0.0%
*-rgt-identity0.0%
+-commutative0.0%
fma-def0.0%
associate-*r/0.0%
unpow20.0%
rem-square-sqrt93.2%
metadata-eval93.2%
Simplified93.2%
*-un-lft-identity93.2%
cube-mult93.2%
unpow293.2%
times-frac96.7%
Applied egg-rr96.7%
associate-*l/96.7%
*-lft-identity96.7%
Simplified96.7%
Final simplification98.8%
(FPCore (x eps) :precision binary64 (if (<= (- x (sqrt (- (* x x) eps))) -2e-151) (/ 1.0 (/ (+ x (hypot x (sqrt (- eps)))) eps)) (/ eps (+ (* x 2.0) (* eps (/ -0.5 x))))))
double code(double x, double eps) {
double tmp;
if ((x - sqrt(((x * x) - eps))) <= -2e-151) {
tmp = 1.0 / ((x + hypot(x, sqrt(-eps))) / eps);
} else {
tmp = eps / ((x * 2.0) + (eps * (-0.5 / x)));
}
return tmp;
}
public static double code(double x, double eps) {
double tmp;
if ((x - Math.sqrt(((x * x) - eps))) <= -2e-151) {
tmp = 1.0 / ((x + Math.hypot(x, Math.sqrt(-eps))) / eps);
} else {
tmp = eps / ((x * 2.0) + (eps * (-0.5 / x)));
}
return tmp;
}
def code(x, eps): tmp = 0 if (x - math.sqrt(((x * x) - eps))) <= -2e-151: tmp = 1.0 / ((x + math.hypot(x, math.sqrt(-eps))) / eps) else: tmp = eps / ((x * 2.0) + (eps * (-0.5 / x))) return tmp
function code(x, eps) tmp = 0.0 if (Float64(x - sqrt(Float64(Float64(x * x) - eps))) <= -2e-151) tmp = Float64(1.0 / Float64(Float64(x + hypot(x, sqrt(Float64(-eps)))) / eps)); else tmp = Float64(eps / Float64(Float64(x * 2.0) + 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-151) tmp = 1.0 / ((x + hypot(x, sqrt(-eps))) / eps); else tmp = eps / ((x * 2.0) + (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-151], N[(1.0 / N[(N[(x + N[Sqrt[x ^ 2 + N[Sqrt[(-eps)], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] / eps), $MachinePrecision]), $MachinePrecision], N[(eps / N[(N[(x * 2.0), $MachinePrecision] + N[(eps * N[(-0.5 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x - \sqrt{x \cdot x - \varepsilon} \leq -2 \cdot 10^{-151}:\\
\;\;\;\;\frac{1}{\frac{x + \mathsf{hypot}\left(x, \sqrt{-\varepsilon}\right)}{\varepsilon}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon}{x \cdot 2 + \varepsilon \cdot \frac{-0.5}{x}}\\
\end{array}
\end{array}
if (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) < -1.9999999999999999e-151Initial program 98.3%
flip--98.2%
div-inv98.0%
add-sqr-sqrt97.7%
associate--r-99.2%
pow299.2%
pow299.2%
sub-neg99.2%
add-sqr-sqrt99.3%
hypot-def99.3%
Applied egg-rr99.3%
*-commutative99.3%
associate-/r/99.3%
+-inverses99.3%
+-commutative99.3%
Simplified99.3%
if -1.9999999999999999e-151 < (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) Initial program 9.5%
flip--9.5%
div-inv9.6%
add-sqr-sqrt9.6%
associate--r-99.6%
pow299.6%
pow299.6%
sub-neg99.6%
add-sqr-sqrt50.7%
hypot-def50.7%
Applied egg-rr50.7%
+-inverses50.7%
+-lft-identity50.7%
associate-*r/50.9%
associate-/l*50.9%
/-rgt-identity50.9%
Simplified50.9%
Taylor expanded in x around inf 0.0%
+-commutative0.0%
*-commutative0.0%
fma-def0.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt98.0%
associate-*r*98.0%
metadata-eval98.0%
associate-*r/98.0%
*-commutative98.0%
Simplified98.0%
fma-udef98.0%
associate-*l/98.0%
associate-/l*98.0%
div-inv98.0%
clear-num98.0%
Applied egg-rr98.0%
Final simplification98.7%
(FPCore (x eps) :precision binary64 (if (<= (- x (sqrt (- (* x x) eps))) -2e-151) (/ eps (+ x (hypot x (sqrt (- eps))))) (/ eps (+ (* x 2.0) (* eps (/ -0.5 x))))))
double code(double x, double eps) {
double tmp;
if ((x - sqrt(((x * x) - eps))) <= -2e-151) {
tmp = eps / (x + hypot(x, sqrt(-eps)));
} else {
tmp = eps / ((x * 2.0) + (eps * (-0.5 / x)));
}
return tmp;
}
public static double code(double x, double eps) {
double tmp;
if ((x - Math.sqrt(((x * x) - eps))) <= -2e-151) {
tmp = eps / (x + Math.hypot(x, Math.sqrt(-eps)));
} else {
tmp = eps / ((x * 2.0) + (eps * (-0.5 / x)));
}
return tmp;
}
def code(x, eps): tmp = 0 if (x - math.sqrt(((x * x) - eps))) <= -2e-151: tmp = eps / (x + math.hypot(x, math.sqrt(-eps))) else: tmp = eps / ((x * 2.0) + (eps * (-0.5 / x))) return tmp
function code(x, eps) tmp = 0.0 if (Float64(x - sqrt(Float64(Float64(x * x) - eps))) <= -2e-151) tmp = Float64(eps / Float64(x + hypot(x, sqrt(Float64(-eps))))); else tmp = Float64(eps / Float64(Float64(x * 2.0) + 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-151) tmp = eps / (x + hypot(x, sqrt(-eps))); else tmp = eps / ((x * 2.0) + (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-151], N[(eps / N[(x + N[Sqrt[x ^ 2 + N[Sqrt[(-eps)], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(eps / N[(N[(x * 2.0), $MachinePrecision] + N[(eps * N[(-0.5 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x - \sqrt{x \cdot x - \varepsilon} \leq -2 \cdot 10^{-151}:\\
\;\;\;\;\frac{\varepsilon}{x + \mathsf{hypot}\left(x, \sqrt{-\varepsilon}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon}{x \cdot 2 + \varepsilon \cdot \frac{-0.5}{x}}\\
\end{array}
\end{array}
if (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) < -1.9999999999999999e-151Initial program 98.3%
flip--98.2%
div-inv98.0%
add-sqr-sqrt97.7%
associate--r-99.2%
pow299.2%
pow299.2%
sub-neg99.2%
add-sqr-sqrt99.3%
hypot-def99.3%
Applied egg-rr99.3%
+-inverses99.3%
+-lft-identity99.3%
associate-*r/99.2%
associate-/l*99.2%
/-rgt-identity99.2%
Simplified99.2%
if -1.9999999999999999e-151 < (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) Initial program 9.5%
flip--9.5%
div-inv9.6%
add-sqr-sqrt9.6%
associate--r-99.6%
pow299.6%
pow299.6%
sub-neg99.6%
add-sqr-sqrt50.7%
hypot-def50.7%
Applied egg-rr50.7%
+-inverses50.7%
+-lft-identity50.7%
associate-*r/50.9%
associate-/l*50.9%
/-rgt-identity50.9%
Simplified50.9%
Taylor expanded in x around inf 0.0%
+-commutative0.0%
*-commutative0.0%
fma-def0.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt98.0%
associate-*r*98.0%
metadata-eval98.0%
associate-*r/98.0%
*-commutative98.0%
Simplified98.0%
fma-udef98.0%
associate-*l/98.0%
associate-/l*98.0%
div-inv98.0%
clear-num98.0%
Applied egg-rr98.0%
Final simplification98.7%
(FPCore (x eps) :precision binary64 (if (<= (- x (sqrt (- (* x x) eps))) -2e-151) (- x (sqrt (fma x x (- eps)))) (/ eps (+ (* x 2.0) (* eps (/ -0.5 x))))))
double code(double x, double eps) {
double tmp;
if ((x - sqrt(((x * x) - eps))) <= -2e-151) {
tmp = x - sqrt(fma(x, x, -eps));
} else {
tmp = eps / ((x * 2.0) + (eps * (-0.5 / x)));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (Float64(x - sqrt(Float64(Float64(x * x) - eps))) <= -2e-151) tmp = Float64(x - sqrt(fma(x, x, Float64(-eps)))); else tmp = Float64(eps / Float64(Float64(x * 2.0) + Float64(eps * Float64(-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-151], N[(x - N[Sqrt[N[(x * x + (-eps)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(eps / N[(N[(x * 2.0), $MachinePrecision] + N[(eps * N[(-0.5 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x - \sqrt{x \cdot x - \varepsilon} \leq -2 \cdot 10^{-151}:\\
\;\;\;\;x - \sqrt{\mathsf{fma}\left(x, x, -\varepsilon\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon}{x \cdot 2 + \varepsilon \cdot \frac{-0.5}{x}}\\
\end{array}
\end{array}
if (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) < -1.9999999999999999e-151Initial program 98.3%
fma-neg98.3%
Applied egg-rr98.3%
if -1.9999999999999999e-151 < (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) Initial program 9.5%
flip--9.5%
div-inv9.6%
add-sqr-sqrt9.6%
associate--r-99.6%
pow299.6%
pow299.6%
sub-neg99.6%
add-sqr-sqrt50.7%
hypot-def50.7%
Applied egg-rr50.7%
+-inverses50.7%
+-lft-identity50.7%
associate-*r/50.9%
associate-/l*50.9%
/-rgt-identity50.9%
Simplified50.9%
Taylor expanded in x around inf 0.0%
+-commutative0.0%
*-commutative0.0%
fma-def0.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt98.0%
associate-*r*98.0%
metadata-eval98.0%
associate-*r/98.0%
*-commutative98.0%
Simplified98.0%
fma-udef98.0%
associate-*l/98.0%
associate-/l*98.0%
div-inv98.0%
clear-num98.0%
Applied egg-rr98.0%
Final simplification98.2%
(FPCore (x eps) :precision binary64 (let* ((t_0 (- x (sqrt (- (* x x) eps))))) (if (<= t_0 -2e-151) t_0 (/ eps (+ (* x 2.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-151) {
tmp = t_0;
} else {
tmp = eps / ((x * 2.0) + (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-151)) then
tmp = t_0
else
tmp = eps / ((x * 2.0d0) + (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-151) {
tmp = t_0;
} else {
tmp = eps / ((x * 2.0) + (eps * (-0.5 / x)));
}
return tmp;
}
def code(x, eps): t_0 = x - math.sqrt(((x * x) - eps)) tmp = 0 if t_0 <= -2e-151: tmp = t_0 else: tmp = eps / ((x * 2.0) + (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-151) tmp = t_0; else tmp = Float64(eps / Float64(Float64(x * 2.0) + Float64(eps * Float64(-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-151) tmp = t_0; else tmp = eps / ((x * 2.0) + (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-151], t$95$0, N[(eps / N[(N[(x * 2.0), $MachinePrecision] + N[(eps * N[(-0.5 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x - \sqrt{x \cdot x - \varepsilon}\\
\mathbf{if}\;t_0 \leq -2 \cdot 10^{-151}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon}{x \cdot 2 + \varepsilon \cdot \frac{-0.5}{x}}\\
\end{array}
\end{array}
if (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) < -1.9999999999999999e-151Initial program 98.3%
if -1.9999999999999999e-151 < (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) Initial program 9.5%
flip--9.5%
div-inv9.6%
add-sqr-sqrt9.6%
associate--r-99.6%
pow299.6%
pow299.6%
sub-neg99.6%
add-sqr-sqrt50.7%
hypot-def50.7%
Applied egg-rr50.7%
+-inverses50.7%
+-lft-identity50.7%
associate-*r/50.9%
associate-/l*50.9%
/-rgt-identity50.9%
Simplified50.9%
Taylor expanded in x around inf 0.0%
+-commutative0.0%
*-commutative0.0%
fma-def0.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt98.0%
associate-*r*98.0%
metadata-eval98.0%
associate-*r/98.0%
*-commutative98.0%
Simplified98.0%
fma-udef98.0%
associate-*l/98.0%
associate-/l*98.0%
div-inv98.0%
clear-num98.0%
Applied egg-rr98.0%
Final simplification98.2%
(FPCore (x eps) :precision binary64 (if (or (<= x 3.05e-109) (and (not (<= x 1.02e-102)) (<= x 3.2e-92))) (- x (sqrt (- eps))) (/ eps (+ (* x 2.0) (* eps (/ -0.5 x))))))
double code(double x, double eps) {
double tmp;
if ((x <= 3.05e-109) || (!(x <= 1.02e-102) && (x <= 3.2e-92))) {
tmp = x - sqrt(-eps);
} else {
tmp = eps / ((x * 2.0) + (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 <= 3.05d-109) .or. (.not. (x <= 1.02d-102)) .and. (x <= 3.2d-92)) then
tmp = x - sqrt(-eps)
else
tmp = eps / ((x * 2.0d0) + (eps * ((-0.5d0) / x)))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((x <= 3.05e-109) || (!(x <= 1.02e-102) && (x <= 3.2e-92))) {
tmp = x - Math.sqrt(-eps);
} else {
tmp = eps / ((x * 2.0) + (eps * (-0.5 / x)));
}
return tmp;
}
def code(x, eps): tmp = 0 if (x <= 3.05e-109) or (not (x <= 1.02e-102) and (x <= 3.2e-92)): tmp = x - math.sqrt(-eps) else: tmp = eps / ((x * 2.0) + (eps * (-0.5 / x))) return tmp
function code(x, eps) tmp = 0.0 if ((x <= 3.05e-109) || (!(x <= 1.02e-102) && (x <= 3.2e-92))) tmp = Float64(x - sqrt(Float64(-eps))); else tmp = Float64(eps / Float64(Float64(x * 2.0) + Float64(eps * Float64(-0.5 / x)))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((x <= 3.05e-109) || (~((x <= 1.02e-102)) && (x <= 3.2e-92))) tmp = x - sqrt(-eps); else tmp = eps / ((x * 2.0) + (eps * (-0.5 / x))); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[x, 3.05e-109], And[N[Not[LessEqual[x, 1.02e-102]], $MachinePrecision], LessEqual[x, 3.2e-92]]], N[(x - N[Sqrt[(-eps)], $MachinePrecision]), $MachinePrecision], N[(eps / N[(N[(x * 2.0), $MachinePrecision] + N[(eps * N[(-0.5 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.05 \cdot 10^{-109} \lor \neg \left(x \leq 1.02 \cdot 10^{-102}\right) \land x \leq 3.2 \cdot 10^{-92}:\\
\;\;\;\;x - \sqrt{-\varepsilon}\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon}{x \cdot 2 + \varepsilon \cdot \frac{-0.5}{x}}\\
\end{array}
\end{array}
if x < 3.0499999999999998e-109 or 1.01999999999999996e-102 < x < 3.1999999999999997e-92Initial program 96.9%
Taylor expanded in x around 0 93.4%
neg-mul-193.4%
Simplified93.4%
if 3.0499999999999998e-109 < x < 1.01999999999999996e-102 or 3.1999999999999997e-92 < x Initial program 21.9%
flip--21.9%
div-inv21.9%
add-sqr-sqrt21.9%
associate--r-99.5%
pow299.5%
pow299.5%
sub-neg99.5%
add-sqr-sqrt59.1%
hypot-def59.1%
Applied egg-rr59.1%
+-inverses59.1%
+-lft-identity59.1%
associate-*r/59.2%
associate-/l*59.2%
/-rgt-identity59.2%
Simplified59.2%
Taylor expanded in x around inf 0.0%
+-commutative0.0%
*-commutative0.0%
fma-def0.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt86.1%
associate-*r*86.1%
metadata-eval86.1%
associate-*r/86.1%
*-commutative86.1%
Simplified86.1%
fma-udef86.1%
associate-*l/86.1%
associate-/l*86.1%
div-inv86.1%
clear-num86.1%
Applied egg-rr86.1%
Final simplification89.9%
(FPCore (x eps) :precision binary64 (/ 1.0 (- (* 2.0 (/ x eps)) (/ 0.5 x))))
double code(double x, double eps) {
return 1.0 / ((2.0 * (x / eps)) - (0.5 / x));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = 1.0d0 / ((2.0d0 * (x / eps)) - (0.5d0 / x))
end function
public static double code(double x, double eps) {
return 1.0 / ((2.0 * (x / eps)) - (0.5 / x));
}
def code(x, eps): return 1.0 / ((2.0 * (x / eps)) - (0.5 / x))
function code(x, eps) return Float64(1.0 / Float64(Float64(2.0 * Float64(x / eps)) - Float64(0.5 / x))) end
function tmp = code(x, eps) tmp = 1.0 / ((2.0 * (x / eps)) - (0.5 / x)); end
code[x_, eps_] := N[(1.0 / N[(N[(2.0 * N[(x / eps), $MachinePrecision]), $MachinePrecision] - N[(0.5 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{2 \cdot \frac{x}{\varepsilon} - \frac{0.5}{x}}
\end{array}
Initial program 60.9%
flip--60.8%
div-inv60.7%
add-sqr-sqrt60.5%
associate--r-99.4%
pow299.4%
pow299.4%
sub-neg99.4%
add-sqr-sqrt78.8%
hypot-def78.8%
Applied egg-rr78.8%
*-commutative78.8%
associate-/r/78.5%
+-inverses78.5%
+-commutative78.5%
Simplified78.5%
Taylor expanded in x around inf 0.0%
fma-def0.0%
metadata-eval0.0%
pow-sqr0.0%
unpow20.0%
rem-square-sqrt0.0%
unpow20.0%
rem-square-sqrt0.0%
metadata-eval0.0%
*-rgt-identity0.0%
+-commutative0.0%
fma-def0.0%
associate-*r/0.0%
unpow20.0%
rem-square-sqrt43.3%
metadata-eval43.3%
Simplified43.3%
fma-udef43.3%
fma-udef43.3%
associate-+r+43.3%
*-commutative43.3%
div-inv41.8%
pow-flip41.8%
metadata-eval41.8%
Applied egg-rr41.8%
Taylor expanded in eps around 0 46.2%
associate-*r/46.2%
metadata-eval46.2%
Simplified46.2%
Final simplification46.2%
(FPCore (x eps) :precision binary64 (/ eps (+ (* x 2.0) (* eps (/ -0.5 x)))))
double code(double x, double eps) {
return eps / ((x * 2.0) + (eps * (-0.5 / x)));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = eps / ((x * 2.0d0) + (eps * ((-0.5d0) / x)))
end function
public static double code(double x, double eps) {
return eps / ((x * 2.0) + (eps * (-0.5 / x)));
}
def code(x, eps): return eps / ((x * 2.0) + (eps * (-0.5 / x)))
function code(x, eps) return Float64(eps / Float64(Float64(x * 2.0) + Float64(eps * Float64(-0.5 / x)))) end
function tmp = code(x, eps) tmp = eps / ((x * 2.0) + (eps * (-0.5 / x))); end
code[x_, eps_] := N[(eps / N[(N[(x * 2.0), $MachinePrecision] + N[(eps * N[(-0.5 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\varepsilon}{x \cdot 2 + \varepsilon \cdot \frac{-0.5}{x}}
\end{array}
Initial program 60.9%
flip--60.8%
div-inv60.7%
add-sqr-sqrt60.5%
associate--r-99.4%
pow299.4%
pow299.4%
sub-neg99.4%
add-sqr-sqrt78.8%
hypot-def78.8%
Applied egg-rr78.8%
+-inverses78.8%
+-lft-identity78.8%
associate-*r/78.8%
associate-/l*78.8%
/-rgt-identity78.8%
Simplified78.8%
Taylor expanded in x around inf 0.0%
+-commutative0.0%
*-commutative0.0%
fma-def0.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt46.6%
associate-*r*46.6%
metadata-eval46.6%
associate-*r/46.6%
*-commutative46.6%
Simplified46.6%
fma-udef46.6%
associate-*l/46.6%
associate-/l*46.6%
div-inv46.6%
clear-num46.6%
Applied egg-rr46.6%
Final simplification46.6%
(FPCore (x eps) :precision binary64 (* eps (/ 0.5 x)))
double code(double x, double eps) {
return eps * (0.5 / x);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = eps * (0.5d0 / x)
end function
public static double code(double x, double eps) {
return eps * (0.5 / x);
}
def code(x, eps): return eps * (0.5 / x)
function code(x, eps) return Float64(eps * Float64(0.5 / x)) end
function tmp = code(x, eps) tmp = eps * (0.5 / x); end
code[x_, eps_] := N[(eps * N[(0.5 / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\varepsilon \cdot \frac{0.5}{x}
\end{array}
Initial program 60.9%
flip--60.8%
div-inv60.7%
add-sqr-sqrt60.5%
associate--r-99.4%
pow299.4%
pow299.4%
sub-neg99.4%
add-sqr-sqrt78.8%
hypot-def78.8%
Applied egg-rr78.8%
+-inverses78.8%
+-lft-identity78.8%
associate-*r/78.8%
associate-/l*78.8%
/-rgt-identity78.8%
Simplified78.8%
Taylor expanded in eps around 0 45.6%
associate-*r/45.6%
associate-/l*45.2%
Simplified45.2%
associate-/r/45.5%
Applied egg-rr45.5%
Final simplification45.5%
(FPCore (x eps) :precision binary64 (/ (* eps 0.5) x))
double code(double x, double eps) {
return (eps * 0.5) / x;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (eps * 0.5d0) / x
end function
public static double code(double x, double eps) {
return (eps * 0.5) / x;
}
def code(x, eps): return (eps * 0.5) / x
function code(x, eps) return Float64(Float64(eps * 0.5) / x) end
function tmp = code(x, eps) tmp = (eps * 0.5) / x; end
code[x_, eps_] := N[(N[(eps * 0.5), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{\varepsilon \cdot 0.5}{x}
\end{array}
Initial program 60.9%
Taylor expanded in x around inf 45.6%
*-commutative45.6%
associate-*l/45.6%
Simplified45.6%
Final simplification45.6%
(FPCore (x eps) :precision binary64 (* x -2.0))
double code(double x, double eps) {
return x * -2.0;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = x * (-2.0d0)
end function
public static double code(double x, double eps) {
return x * -2.0;
}
def code(x, eps): return x * -2.0
function code(x, eps) return Float64(x * -2.0) end
function tmp = code(x, eps) tmp = x * -2.0; end
code[x_, eps_] := N[(x * -2.0), $MachinePrecision]
\begin{array}{l}
\\
x \cdot -2
\end{array}
Initial program 60.9%
flip--60.8%
div-inv60.7%
add-sqr-sqrt60.5%
associate--r-99.4%
pow299.4%
pow299.4%
sub-neg99.4%
add-sqr-sqrt78.8%
hypot-def78.8%
Applied egg-rr78.8%
+-inverses78.8%
+-lft-identity78.8%
associate-*r/78.8%
associate-/l*78.8%
/-rgt-identity78.8%
Simplified78.8%
Taylor expanded in x around inf 0.0%
+-commutative0.0%
*-commutative0.0%
fma-def0.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt46.6%
associate-*r*46.6%
metadata-eval46.6%
associate-*r/46.6%
*-commutative46.6%
Simplified46.6%
Taylor expanded in eps around inf 5.4%
*-commutative5.4%
Simplified5.4%
Final simplification5.4%
(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 60.9%
sub-neg60.9%
+-commutative60.9%
add-sqr-sqrt60.3%
distribute-rgt-neg-in60.3%
fma-def60.0%
pow1/260.0%
sqrt-pow160.2%
pow260.2%
metadata-eval60.2%
pow1/260.2%
sqrt-pow160.0%
pow260.0%
metadata-eval60.0%
Applied egg-rr60.0%
Taylor expanded in x around inf 4.4%
distribute-rgt1-in4.4%
metadata-eval4.4%
mul0-lft4.4%
Simplified4.4%
Final simplification4.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 2024020
(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)))
:herbie-target
(/ eps (+ x (sqrt (- (* x x) eps))))
(- x (sqrt (- (* x x) eps))))