
(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 11 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))) -1e-153)
(/ eps (+ x (hypot x (sqrt (- eps)))))
(/
eps
(+ (+ (/ -0.125 (/ x (pow (/ eps x) 2.0))) (+ x x)) (* (/ eps x) -0.5)))))
double code(double x, double eps) {
double tmp;
if ((x - sqrt(((x * x) - eps))) <= -1e-153) {
tmp = eps / (x + hypot(x, sqrt(-eps)));
} else {
tmp = eps / (((-0.125 / (x / pow((eps / x), 2.0))) + (x + x)) + ((eps / x) * -0.5));
}
return tmp;
}
public static double code(double x, double eps) {
double tmp;
if ((x - Math.sqrt(((x * x) - eps))) <= -1e-153) {
tmp = eps / (x + Math.hypot(x, Math.sqrt(-eps)));
} else {
tmp = eps / (((-0.125 / (x / Math.pow((eps / x), 2.0))) + (x + x)) + ((eps / x) * -0.5));
}
return tmp;
}
def code(x, eps): tmp = 0 if (x - math.sqrt(((x * x) - eps))) <= -1e-153: tmp = eps / (x + math.hypot(x, math.sqrt(-eps))) else: tmp = eps / (((-0.125 / (x / math.pow((eps / x), 2.0))) + (x + x)) + ((eps / x) * -0.5)) return tmp
function code(x, eps) tmp = 0.0 if (Float64(x - sqrt(Float64(Float64(x * x) - eps))) <= -1e-153) tmp = Float64(eps / Float64(x + hypot(x, sqrt(Float64(-eps))))); else tmp = Float64(eps / Float64(Float64(Float64(-0.125 / Float64(x / (Float64(eps / x) ^ 2.0))) + Float64(x + x)) + Float64(Float64(eps / x) * -0.5))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((x - sqrt(((x * x) - eps))) <= -1e-153) tmp = eps / (x + hypot(x, sqrt(-eps))); else tmp = eps / (((-0.125 / (x / ((eps / x) ^ 2.0))) + (x + x)) + ((eps / x) * -0.5)); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[N[(x - N[Sqrt[N[(N[(x * x), $MachinePrecision] - eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -1e-153], N[(eps / N[(x + N[Sqrt[x ^ 2 + N[Sqrt[(-eps)], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(eps / N[(N[(N[(-0.125 / N[(x / N[Power[N[(eps / x), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(x + x), $MachinePrecision]), $MachinePrecision] + N[(N[(eps / x), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x - \sqrt{x \cdot x - \varepsilon} \leq -1 \cdot 10^{-153}:\\
\;\;\;\;\frac{\varepsilon}{x + \mathsf{hypot}\left(x, \sqrt{-\varepsilon}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon}{\left(\frac{-0.125}{\frac{x}{{\left(\frac{\varepsilon}{x}\right)}^{2}}} + \left(x + x\right)\right) + \frac{\varepsilon}{x} \cdot -0.5}\\
\end{array}
\end{array}
if (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) < -1.00000000000000004e-153Initial program 98.7%
flip--98.8%
div-inv98.4%
add-sqr-sqrt98.2%
sub-neg98.2%
add-sqr-sqrt98.2%
hypot-def98.2%
Applied egg-rr98.2%
associate-*r/98.1%
*-rgt-identity98.1%
associate--r-99.2%
+-inverses99.2%
+-lft-identity99.2%
Simplified99.2%
if -1.00000000000000004e-153 < (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) Initial program 8.2%
flip--8.2%
div-inv8.2%
add-sqr-sqrt8.3%
sub-neg8.3%
add-sqr-sqrt2.5%
hypot-def2.5%
Applied egg-rr2.5%
associate-*r/2.5%
*-rgt-identity2.5%
associate--r-43.5%
+-inverses43.5%
+-lft-identity43.5%
Simplified43.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%
unpow20.0%
+-commutative0.0%
*-commutative0.0%
fma-def0.0%
associate-*r/0.0%
Simplified93.0%
fma-udef93.0%
fma-udef93.0%
*-commutative93.0%
count-293.0%
associate-+r+93.0%
clear-num93.0%
un-div-inv93.0%
cube-mult93.0%
associate-/l*100.0%
frac-times100.0%
pow2100.0%
Applied egg-rr100.0%
Final simplification99.5%
(FPCore (x eps)
:precision binary64
(if (<= (- x (sqrt (- (* x x) eps))) -1e-153)
(- x (hypot (sqrt (- eps)) x))
(/
eps
(+ (+ (/ -0.125 (/ x (pow (/ eps x) 2.0))) (+ x x)) (* (/ eps x) -0.5)))))
double code(double x, double eps) {
double tmp;
if ((x - sqrt(((x * x) - eps))) <= -1e-153) {
tmp = x - hypot(sqrt(-eps), x);
} else {
tmp = eps / (((-0.125 / (x / pow((eps / x), 2.0))) + (x + x)) + ((eps / x) * -0.5));
}
return tmp;
}
public static double code(double x, double eps) {
double tmp;
if ((x - Math.sqrt(((x * x) - eps))) <= -1e-153) {
tmp = x - Math.hypot(Math.sqrt(-eps), x);
} else {
tmp = eps / (((-0.125 / (x / Math.pow((eps / x), 2.0))) + (x + x)) + ((eps / x) * -0.5));
}
return tmp;
}
def code(x, eps): tmp = 0 if (x - math.sqrt(((x * x) - eps))) <= -1e-153: tmp = x - math.hypot(math.sqrt(-eps), x) else: tmp = eps / (((-0.125 / (x / math.pow((eps / x), 2.0))) + (x + x)) + ((eps / x) * -0.5)) return tmp
function code(x, eps) tmp = 0.0 if (Float64(x - sqrt(Float64(Float64(x * x) - eps))) <= -1e-153) tmp = Float64(x - hypot(sqrt(Float64(-eps)), x)); else tmp = Float64(eps / Float64(Float64(Float64(-0.125 / Float64(x / (Float64(eps / x) ^ 2.0))) + Float64(x + x)) + Float64(Float64(eps / x) * -0.5))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((x - sqrt(((x * x) - eps))) <= -1e-153) tmp = x - hypot(sqrt(-eps), x); else tmp = eps / (((-0.125 / (x / ((eps / x) ^ 2.0))) + (x + x)) + ((eps / x) * -0.5)); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[N[(x - N[Sqrt[N[(N[(x * x), $MachinePrecision] - eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -1e-153], N[(x - N[Sqrt[N[Sqrt[(-eps)], $MachinePrecision] ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision], N[(eps / N[(N[(N[(-0.125 / N[(x / N[Power[N[(eps / x), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(x + x), $MachinePrecision]), $MachinePrecision] + N[(N[(eps / x), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x - \sqrt{x \cdot x - \varepsilon} \leq -1 \cdot 10^{-153}:\\
\;\;\;\;x - \mathsf{hypot}\left(\sqrt{-\varepsilon}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon}{\left(\frac{-0.125}{\frac{x}{{\left(\frac{\varepsilon}{x}\right)}^{2}}} + \left(x + x\right)\right) + \frac{\varepsilon}{x} \cdot -0.5}\\
\end{array}
\end{array}
if (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) < -1.00000000000000004e-153Initial program 98.7%
sub-neg98.7%
+-commutative98.7%
add-sqr-sqrt98.8%
hypot-def98.8%
Applied egg-rr98.8%
if -1.00000000000000004e-153 < (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) Initial program 8.2%
flip--8.2%
div-inv8.2%
add-sqr-sqrt8.3%
sub-neg8.3%
add-sqr-sqrt2.5%
hypot-def2.5%
Applied egg-rr2.5%
associate-*r/2.5%
*-rgt-identity2.5%
associate--r-43.5%
+-inverses43.5%
+-lft-identity43.5%
Simplified43.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%
unpow20.0%
+-commutative0.0%
*-commutative0.0%
fma-def0.0%
associate-*r/0.0%
Simplified93.0%
fma-udef93.0%
fma-udef93.0%
*-commutative93.0%
count-293.0%
associate-+r+93.0%
clear-num93.0%
un-div-inv93.0%
cube-mult93.0%
associate-/l*100.0%
frac-times100.0%
pow2100.0%
Applied egg-rr100.0%
Final simplification99.3%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- x (sqrt (- (* x x) eps)))))
(if (<= t_0 -1e-153)
t_0
(/
eps
(+
(+ (/ -0.125 (/ x (pow (/ eps x) 2.0))) (+ x x))
(* (/ eps x) -0.5))))))
double code(double x, double eps) {
double t_0 = x - sqrt(((x * x) - eps));
double tmp;
if (t_0 <= -1e-153) {
tmp = t_0;
} else {
tmp = eps / (((-0.125 / (x / pow((eps / x), 2.0))) + (x + x)) + ((eps / x) * -0.5));
}
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 <= (-1d-153)) then
tmp = t_0
else
tmp = eps / ((((-0.125d0) / (x / ((eps / x) ** 2.0d0))) + (x + x)) + ((eps / x) * (-0.5d0)))
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 <= -1e-153) {
tmp = t_0;
} else {
tmp = eps / (((-0.125 / (x / Math.pow((eps / x), 2.0))) + (x + x)) + ((eps / x) * -0.5));
}
return tmp;
}
def code(x, eps): t_0 = x - math.sqrt(((x * x) - eps)) tmp = 0 if t_0 <= -1e-153: tmp = t_0 else: tmp = eps / (((-0.125 / (x / math.pow((eps / x), 2.0))) + (x + x)) + ((eps / x) * -0.5)) return tmp
function code(x, eps) t_0 = Float64(x - sqrt(Float64(Float64(x * x) - eps))) tmp = 0.0 if (t_0 <= -1e-153) tmp = t_0; else tmp = Float64(eps / Float64(Float64(Float64(-0.125 / Float64(x / (Float64(eps / x) ^ 2.0))) + Float64(x + x)) + Float64(Float64(eps / x) * -0.5))); end return tmp end
function tmp_2 = code(x, eps) t_0 = x - sqrt(((x * x) - eps)); tmp = 0.0; if (t_0 <= -1e-153) tmp = t_0; else tmp = eps / (((-0.125 / (x / ((eps / x) ^ 2.0))) + (x + x)) + ((eps / x) * -0.5)); 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, -1e-153], t$95$0, N[(eps / N[(N[(N[(-0.125 / N[(x / N[Power[N[(eps / x), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(x + x), $MachinePrecision]), $MachinePrecision] + N[(N[(eps / x), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x - \sqrt{x \cdot x - \varepsilon}\\
\mathbf{if}\;t_0 \leq -1 \cdot 10^{-153}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon}{\left(\frac{-0.125}{\frac{x}{{\left(\frac{\varepsilon}{x}\right)}^{2}}} + \left(x + x\right)\right) + \frac{\varepsilon}{x} \cdot -0.5}\\
\end{array}
\end{array}
if (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) < -1.00000000000000004e-153Initial program 98.7%
if -1.00000000000000004e-153 < (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) Initial program 8.2%
flip--8.2%
div-inv8.2%
add-sqr-sqrt8.3%
sub-neg8.3%
add-sqr-sqrt2.5%
hypot-def2.5%
Applied egg-rr2.5%
associate-*r/2.5%
*-rgt-identity2.5%
associate--r-43.5%
+-inverses43.5%
+-lft-identity43.5%
Simplified43.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%
unpow20.0%
+-commutative0.0%
*-commutative0.0%
fma-def0.0%
associate-*r/0.0%
Simplified93.0%
fma-udef93.0%
fma-udef93.0%
*-commutative93.0%
count-293.0%
associate-+r+93.0%
clear-num93.0%
un-div-inv93.0%
cube-mult93.0%
associate-/l*100.0%
frac-times100.0%
pow2100.0%
Applied egg-rr100.0%
Final simplification99.3%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- x (sqrt (- (* x x) eps)))))
(if (<= t_0 -1e-153)
t_0
(+ (* (pow (/ eps x) 2.0) (/ 0.125 x)) (* (/ eps x) 0.5)))))
double code(double x, double eps) {
double t_0 = x - sqrt(((x * x) - eps));
double tmp;
if (t_0 <= -1e-153) {
tmp = t_0;
} else {
tmp = (pow((eps / x), 2.0) * (0.125 / x)) + ((eps / x) * 0.5);
}
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 <= (-1d-153)) then
tmp = t_0
else
tmp = (((eps / x) ** 2.0d0) * (0.125d0 / x)) + ((eps / x) * 0.5d0)
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 <= -1e-153) {
tmp = t_0;
} else {
tmp = (Math.pow((eps / x), 2.0) * (0.125 / x)) + ((eps / x) * 0.5);
}
return tmp;
}
def code(x, eps): t_0 = x - math.sqrt(((x * x) - eps)) tmp = 0 if t_0 <= -1e-153: tmp = t_0 else: tmp = (math.pow((eps / x), 2.0) * (0.125 / x)) + ((eps / x) * 0.5) return tmp
function code(x, eps) t_0 = Float64(x - sqrt(Float64(Float64(x * x) - eps))) tmp = 0.0 if (t_0 <= -1e-153) tmp = t_0; else tmp = Float64(Float64((Float64(eps / x) ^ 2.0) * Float64(0.125 / x)) + Float64(Float64(eps / x) * 0.5)); end return tmp end
function tmp_2 = code(x, eps) t_0 = x - sqrt(((x * x) - eps)); tmp = 0.0; if (t_0 <= -1e-153) tmp = t_0; else tmp = (((eps / x) ^ 2.0) * (0.125 / x)) + ((eps / x) * 0.5); 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, -1e-153], t$95$0, N[(N[(N[Power[N[(eps / x), $MachinePrecision], 2.0], $MachinePrecision] * N[(0.125 / x), $MachinePrecision]), $MachinePrecision] + N[(N[(eps / x), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x - \sqrt{x \cdot x - \varepsilon}\\
\mathbf{if}\;t_0 \leq -1 \cdot 10^{-153}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;{\left(\frac{\varepsilon}{x}\right)}^{2} \cdot \frac{0.125}{x} + \frac{\varepsilon}{x} \cdot 0.5\\
\end{array}
\end{array}
if (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) < -1.00000000000000004e-153Initial program 98.7%
if -1.00000000000000004e-153 < (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) Initial program 8.2%
flip--8.2%
div-inv8.2%
add-sqr-sqrt8.3%
sub-neg8.3%
add-sqr-sqrt2.5%
hypot-def2.5%
Applied egg-rr2.5%
associate-*r/2.5%
*-rgt-identity2.5%
associate--r-43.5%
+-inverses43.5%
+-lft-identity43.5%
Simplified43.5%
Taylor expanded in x around inf 0.0%
+-commutative0.0%
fma-def0.0%
associate-/l*0.0%
associate-*r/0.0%
unpow20.0%
rem-square-sqrt92.7%
associate-/l*92.7%
*-commutative92.7%
*-commutative92.7%
associate-*l*92.7%
*-commutative92.7%
associate-*l*92.7%
metadata-eval92.7%
/-rgt-identity92.7%
metadata-eval92.7%
rem-square-sqrt0.0%
unpow20.0%
rem-square-sqrt0.0%
unpow20.0%
pow-sqr0.0%
metadata-eval0.0%
Simplified92.7%
fma-udef92.7%
+-commutative92.7%
associate-*l/92.7%
unpow392.7%
times-frac99.5%
frac-times99.8%
pow299.8%
*-commutative99.8%
Applied egg-rr99.8%
Final simplification99.2%
(FPCore (x eps) :precision binary64 (let* ((t_0 (- x (sqrt (- (* x x) eps))))) (if (<= t_0 -1e-153) t_0 (/ eps (+ (* (/ eps x) -0.5) (* x 2.0))))))
double code(double x, double eps) {
double t_0 = x - sqrt(((x * x) - eps));
double tmp;
if (t_0 <= -1e-153) {
tmp = t_0;
} else {
tmp = eps / (((eps / x) * -0.5) + (x * 2.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 = x - sqrt(((x * x) - eps))
if (t_0 <= (-1d-153)) then
tmp = t_0
else
tmp = eps / (((eps / x) * (-0.5d0)) + (x * 2.0d0))
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 <= -1e-153) {
tmp = t_0;
} else {
tmp = eps / (((eps / x) * -0.5) + (x * 2.0));
}
return tmp;
}
def code(x, eps): t_0 = x - math.sqrt(((x * x) - eps)) tmp = 0 if t_0 <= -1e-153: tmp = t_0 else: tmp = eps / (((eps / x) * -0.5) + (x * 2.0)) return tmp
function code(x, eps) t_0 = Float64(x - sqrt(Float64(Float64(x * x) - eps))) tmp = 0.0 if (t_0 <= -1e-153) tmp = t_0; else tmp = Float64(eps / Float64(Float64(Float64(eps / x) * -0.5) + Float64(x * 2.0))); end return tmp end
function tmp_2 = code(x, eps) t_0 = x - sqrt(((x * x) - eps)); tmp = 0.0; if (t_0 <= -1e-153) tmp = t_0; else tmp = eps / (((eps / x) * -0.5) + (x * 2.0)); 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, -1e-153], t$95$0, N[(eps / N[(N[(N[(eps / x), $MachinePrecision] * -0.5), $MachinePrecision] + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x - \sqrt{x \cdot x - \varepsilon}\\
\mathbf{if}\;t_0 \leq -1 \cdot 10^{-153}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon}{\frac{\varepsilon}{x} \cdot -0.5 + x \cdot 2}\\
\end{array}
\end{array}
if (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) < -1.00000000000000004e-153Initial program 98.7%
if -1.00000000000000004e-153 < (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) Initial program 8.2%
flip--8.2%
div-inv8.2%
add-sqr-sqrt8.3%
sub-neg8.3%
add-sqr-sqrt2.5%
hypot-def2.5%
Applied egg-rr2.5%
associate-*r/2.5%
*-rgt-identity2.5%
associate--r-43.5%
+-inverses43.5%
+-lft-identity43.5%
Simplified43.5%
Taylor expanded in x around inf 0.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt99.8%
associate-*r*99.8%
metadata-eval99.8%
associate-*r/99.8%
*-commutative99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Final simplification99.2%
(FPCore (x eps) :precision binary64 (if (<= x 6.5e-100) (- x (sqrt (- eps))) (/ eps (+ (* (/ eps x) -0.5) (* x 2.0)))))
double code(double x, double eps) {
double tmp;
if (x <= 6.5e-100) {
tmp = x - sqrt(-eps);
} else {
tmp = eps / (((eps / x) * -0.5) + (x * 2.0));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (x <= 6.5d-100) then
tmp = x - sqrt(-eps)
else
tmp = eps / (((eps / x) * (-0.5d0)) + (x * 2.0d0))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (x <= 6.5e-100) {
tmp = x - Math.sqrt(-eps);
} else {
tmp = eps / (((eps / x) * -0.5) + (x * 2.0));
}
return tmp;
}
def code(x, eps): tmp = 0 if x <= 6.5e-100: tmp = x - math.sqrt(-eps) else: tmp = eps / (((eps / x) * -0.5) + (x * 2.0)) return tmp
function code(x, eps) tmp = 0.0 if (x <= 6.5e-100) tmp = Float64(x - sqrt(Float64(-eps))); else tmp = Float64(eps / Float64(Float64(Float64(eps / x) * -0.5) + Float64(x * 2.0))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (x <= 6.5e-100) tmp = x - sqrt(-eps); else tmp = eps / (((eps / x) * -0.5) + (x * 2.0)); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[x, 6.5e-100], N[(x - N[Sqrt[(-eps)], $MachinePrecision]), $MachinePrecision], N[(eps / N[(N[(N[(eps / x), $MachinePrecision] * -0.5), $MachinePrecision] + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 6.5 \cdot 10^{-100}:\\
\;\;\;\;x - \sqrt{-\varepsilon}\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon}{\frac{\varepsilon}{x} \cdot -0.5 + x \cdot 2}\\
\end{array}
\end{array}
if x < 6.50000000000000013e-100Initial program 90.6%
Taylor expanded in x around 0 89.7%
neg-mul-189.7%
Simplified89.7%
if 6.50000000000000013e-100 < x Initial program 26.0%
flip--26.1%
div-inv26.0%
add-sqr-sqrt26.2%
sub-neg26.2%
add-sqr-sqrt21.4%
hypot-def21.4%
Applied egg-rr21.4%
associate-*r/21.4%
*-rgt-identity21.4%
associate--r-54.1%
+-inverses54.1%
+-lft-identity54.1%
Simplified54.1%
Taylor expanded in x around inf 0.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt83.1%
associate-*r*83.1%
metadata-eval83.1%
associate-*r/83.1%
*-commutative83.1%
Simplified83.1%
Taylor expanded in x around 0 83.1%
Final simplification86.4%
(FPCore (x eps) :precision binary64 (/ eps (+ x (+ x (* (/ eps x) -0.5)))))
double code(double x, double eps) {
return eps / (x + (x + ((eps / x) * -0.5)));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = eps / (x + (x + ((eps / x) * (-0.5d0))))
end function
public static double code(double x, double eps) {
return eps / (x + (x + ((eps / x) * -0.5)));
}
def code(x, eps): return eps / (x + (x + ((eps / x) * -0.5)))
function code(x, eps) return Float64(eps / Float64(x + Float64(x + Float64(Float64(eps / x) * -0.5)))) end
function tmp = code(x, eps) tmp = eps / (x + (x + ((eps / x) * -0.5))); end
code[x_, eps_] := N[(eps / N[(x + N[(x + N[(N[(eps / x), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\varepsilon}{x + \left(x + \frac{\varepsilon}{x} \cdot -0.5\right)}
\end{array}
Initial program 58.1%
flip--58.1%
div-inv57.9%
add-sqr-sqrt57.8%
sub-neg57.8%
add-sqr-sqrt55.2%
hypot-def55.2%
Applied egg-rr55.2%
associate-*r/55.2%
*-rgt-identity55.2%
associate--r-74.2%
+-inverses74.2%
+-lft-identity74.2%
Simplified74.2%
Taylor expanded in x around inf 0.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt49.4%
associate-*r*49.4%
metadata-eval49.4%
associate-*r/49.4%
*-commutative49.4%
Simplified49.4%
Final simplification49.4%
(FPCore (x eps) :precision binary64 (/ eps (+ (* (/ eps x) -0.5) (* x 2.0))))
double code(double x, double eps) {
return eps / (((eps / x) * -0.5) + (x * 2.0));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = eps / (((eps / x) * (-0.5d0)) + (x * 2.0d0))
end function
public static double code(double x, double eps) {
return eps / (((eps / x) * -0.5) + (x * 2.0));
}
def code(x, eps): return eps / (((eps / x) * -0.5) + (x * 2.0))
function code(x, eps) return Float64(eps / Float64(Float64(Float64(eps / x) * -0.5) + Float64(x * 2.0))) end
function tmp = code(x, eps) tmp = eps / (((eps / x) * -0.5) + (x * 2.0)); end
code[x_, eps_] := N[(eps / N[(N[(N[(eps / x), $MachinePrecision] * -0.5), $MachinePrecision] + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\varepsilon}{\frac{\varepsilon}{x} \cdot -0.5 + x \cdot 2}
\end{array}
Initial program 58.1%
flip--58.1%
div-inv57.9%
add-sqr-sqrt57.8%
sub-neg57.8%
add-sqr-sqrt55.2%
hypot-def55.2%
Applied egg-rr55.2%
associate-*r/55.2%
*-rgt-identity55.2%
associate--r-74.2%
+-inverses74.2%
+-lft-identity74.2%
Simplified74.2%
Taylor expanded in x around inf 0.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt49.4%
associate-*r*49.4%
metadata-eval49.4%
associate-*r/49.4%
*-commutative49.4%
Simplified49.4%
Taylor expanded in x around 0 49.4%
Final simplification49.4%
(FPCore (x eps) :precision binary64 (* (/ eps x) 0.5))
double code(double x, double eps) {
return (eps / x) * 0.5;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (eps / x) * 0.5d0
end function
public static double code(double x, double eps) {
return (eps / x) * 0.5;
}
def code(x, eps): return (eps / x) * 0.5
function code(x, eps) return Float64(Float64(eps / x) * 0.5) end
function tmp = code(x, eps) tmp = (eps / x) * 0.5; end
code[x_, eps_] := N[(N[(eps / x), $MachinePrecision] * 0.5), $MachinePrecision]
\begin{array}{l}
\\
\frac{\varepsilon}{x} \cdot 0.5
\end{array}
Initial program 58.1%
Taylor expanded in x around inf 48.6%
Final simplification48.6%
(FPCore (x eps) :precision binary64 (/ eps (+ x x)))
double code(double x, double eps) {
return eps / (x + x);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = eps / (x + x)
end function
public static double code(double x, double eps) {
return eps / (x + x);
}
def code(x, eps): return eps / (x + x)
function code(x, eps) return Float64(eps / Float64(x + x)) end
function tmp = code(x, eps) tmp = eps / (x + x); end
code[x_, eps_] := N[(eps / N[(x + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\varepsilon}{x + x}
\end{array}
Initial program 58.1%
flip--58.1%
div-inv57.9%
add-sqr-sqrt57.8%
sub-neg57.8%
add-sqr-sqrt55.2%
hypot-def55.2%
Applied egg-rr55.2%
associate-*r/55.2%
*-rgt-identity55.2%
associate--r-74.2%
+-inverses74.2%
+-lft-identity74.2%
Simplified74.2%
Taylor expanded in x around inf 48.6%
Final simplification48.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 58.1%
flip--58.1%
div-inv57.9%
add-sqr-sqrt57.8%
sub-neg57.8%
add-sqr-sqrt55.2%
hypot-def55.2%
Applied egg-rr55.2%
associate-*r/55.2%
*-rgt-identity55.2%
associate--r-74.2%
+-inverses74.2%
+-lft-identity74.2%
Simplified74.2%
Taylor expanded in x around inf 0.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt49.4%
associate-*r*49.4%
metadata-eval49.4%
associate-*r/49.4%
*-commutative49.4%
Simplified49.4%
Taylor expanded in eps around inf 5.2%
*-commutative5.2%
Simplified5.2%
Final simplification5.2%
(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 2023271
(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))))