
(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 (or (<= eps -8e-195) (not (<= eps 1.36e-163))) (/ eps (+ x (sqrt (- (pow x 2.0) eps)))) (- x (sqrt (- (* x x) eps)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -8e-195) || !(eps <= 1.36e-163)) {
tmp = eps / (x + sqrt((pow(x, 2.0) - eps)));
} else {
tmp = x - sqrt(((x * x) - eps));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-8d-195)) .or. (.not. (eps <= 1.36d-163))) then
tmp = eps / (x + sqrt(((x ** 2.0d0) - eps)))
else
tmp = x - sqrt(((x * x) - eps))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -8e-195) || !(eps <= 1.36e-163)) {
tmp = eps / (x + Math.sqrt((Math.pow(x, 2.0) - eps)));
} else {
tmp = x - Math.sqrt(((x * x) - eps));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -8e-195) or not (eps <= 1.36e-163): tmp = eps / (x + math.sqrt((math.pow(x, 2.0) - eps))) else: tmp = x - math.sqrt(((x * x) - eps)) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -8e-195) || !(eps <= 1.36e-163)) tmp = Float64(eps / Float64(x + sqrt(Float64((x ^ 2.0) - eps)))); else tmp = Float64(x - sqrt(Float64(Float64(x * x) - eps))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -8e-195) || ~((eps <= 1.36e-163))) tmp = eps / (x + sqrt(((x ^ 2.0) - eps))); else tmp = x - sqrt(((x * x) - eps)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -8e-195], N[Not[LessEqual[eps, 1.36e-163]], $MachinePrecision]], N[(eps / N[(x + N[Sqrt[N[(N[Power[x, 2.0], $MachinePrecision] - eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[Sqrt[N[(N[(x * x), $MachinePrecision] - eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -8 \cdot 10^{-195} \lor \neg \left(\varepsilon \leq 1.36 \cdot 10^{-163}\right):\\
\;\;\;\;\frac{\varepsilon}{x + \sqrt{{x}^{2} - \varepsilon}}\\
\mathbf{else}:\\
\;\;\;\;x - \sqrt{x \cdot x - \varepsilon}\\
\end{array}
\end{array}
if eps < -8.0000000000000007e-195 or 1.36e-163 < eps Initial program 76.6%
flip--76.6%
div-inv76.4%
add-sqr-sqrt76.4%
associate--r-93.5%
pow293.5%
pow293.5%
sub-neg93.5%
add-sqr-sqrt81.1%
hypot-def81.1%
Applied egg-rr81.1%
+-inverses81.1%
+-lft-identity81.1%
associate-*r/81.1%
associate-/l*81.1%
/-rgt-identity81.1%
Simplified81.1%
hypot-udef81.1%
unpow281.1%
add-sqr-sqrt93.6%
sub-neg93.6%
pow1/293.6%
Applied egg-rr93.6%
unpow1/293.6%
Simplified93.6%
if -8.0000000000000007e-195 < eps < 1.36e-163Initial program 81.8%
Final simplification88.6%
(FPCore (x eps)
:precision binary64
(if (<= eps -4.8e-195)
(/ eps (+ x (hypot x (sqrt (- eps)))))
(if (<= eps 6.2e-163)
(- x (sqrt (- (* x x) eps)))
(/ eps (+ (/ eps (/ x -0.5)) (* x 2.0))))))
double code(double x, double eps) {
double tmp;
if (eps <= -4.8e-195) {
tmp = eps / (x + hypot(x, sqrt(-eps)));
} else if (eps <= 6.2e-163) {
tmp = x - sqrt(((x * x) - eps));
} else {
tmp = eps / ((eps / (x / -0.5)) + (x * 2.0));
}
return tmp;
}
public static double code(double x, double eps) {
double tmp;
if (eps <= -4.8e-195) {
tmp = eps / (x + Math.hypot(x, Math.sqrt(-eps)));
} else if (eps <= 6.2e-163) {
tmp = x - Math.sqrt(((x * x) - eps));
} else {
tmp = eps / ((eps / (x / -0.5)) + (x * 2.0));
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= -4.8e-195: tmp = eps / (x + math.hypot(x, math.sqrt(-eps))) elif eps <= 6.2e-163: tmp = x - math.sqrt(((x * x) - eps)) else: tmp = eps / ((eps / (x / -0.5)) + (x * 2.0)) return tmp
function code(x, eps) tmp = 0.0 if (eps <= -4.8e-195) tmp = Float64(eps / Float64(x + hypot(x, sqrt(Float64(-eps))))); elseif (eps <= 6.2e-163) tmp = Float64(x - sqrt(Float64(Float64(x * x) - eps))); else tmp = Float64(eps / Float64(Float64(eps / Float64(x / -0.5)) + Float64(x * 2.0))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= -4.8e-195) tmp = eps / (x + hypot(x, sqrt(-eps))); elseif (eps <= 6.2e-163) tmp = x - sqrt(((x * x) - eps)); else tmp = eps / ((eps / (x / -0.5)) + (x * 2.0)); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -4.8e-195], N[(eps / N[(x + N[Sqrt[x ^ 2 + N[Sqrt[(-eps)], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 6.2e-163], N[(x - N[Sqrt[N[(N[(x * x), $MachinePrecision] - eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(eps / N[(N[(eps / N[(x / -0.5), $MachinePrecision]), $MachinePrecision] + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -4.8 \cdot 10^{-195}:\\
\;\;\;\;\frac{\varepsilon}{x + \mathsf{hypot}\left(x, \sqrt{-\varepsilon}\right)}\\
\mathbf{elif}\;\varepsilon \leq 6.2 \cdot 10^{-163}:\\
\;\;\;\;x - \sqrt{x \cdot x - \varepsilon}\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon}{\frac{\varepsilon}{\frac{x}{-0.5}} + x \cdot 2}\\
\end{array}
\end{array}
if eps < -4.8e-195Initial program 84.7%
flip--84.6%
div-inv84.4%
add-sqr-sqrt84.2%
associate--r-96.2%
pow296.2%
pow296.2%
sub-neg96.2%
add-sqr-sqrt96.2%
hypot-def96.2%
Applied egg-rr96.2%
+-inverses96.2%
+-lft-identity96.2%
associate-*r/96.3%
associate-/l*96.3%
/-rgt-identity96.3%
Simplified96.3%
if -4.8e-195 < eps < 6.19999999999999949e-163Initial program 81.8%
if 6.19999999999999949e-163 < eps Initial program 33.5%
flip--33.6%
div-inv33.6%
add-sqr-sqrt34.8%
associate--r-78.8%
pow278.8%
pow278.8%
sub-neg78.8%
add-sqr-sqrt0.0%
hypot-def0.0%
Applied egg-rr0.0%
+-inverses0.0%
+-lft-identity0.0%
associate-*r/0.0%
associate-/l*0.0%
/-rgt-identity0.0%
Simplified0.0%
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-sqrt77.6%
associate-*r*77.6%
metadata-eval77.6%
associate-*r/77.6%
*-commutative77.6%
Simplified77.6%
fma-udef77.6%
+-commutative77.6%
associate-*l/77.6%
associate-/l*77.6%
Applied egg-rr77.6%
Final simplification88.4%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- x (sqrt (- eps))))
(t_1 (/ eps (+ (/ eps (/ x -0.5)) (* x 2.0)))))
(if (<= x 1.9e-114)
t_0
(if (<= x 3.2e-91)
t_1
(if (<= x 1.65e-65)
t_0
(if (<= x 30.0)
(- x (+ x (* -0.5 (/ eps x))))
(if (<= x 54000000.0) t_1 (- x x))))))))
double code(double x, double eps) {
double t_0 = x - sqrt(-eps);
double t_1 = eps / ((eps / (x / -0.5)) + (x * 2.0));
double tmp;
if (x <= 1.9e-114) {
tmp = t_0;
} else if (x <= 3.2e-91) {
tmp = t_1;
} else if (x <= 1.65e-65) {
tmp = t_0;
} else if (x <= 30.0) {
tmp = x - (x + (-0.5 * (eps / x)));
} else if (x <= 54000000.0) {
tmp = t_1;
} else {
tmp = x - 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) :: t_1
real(8) :: tmp
t_0 = x - sqrt(-eps)
t_1 = eps / ((eps / (x / (-0.5d0))) + (x * 2.0d0))
if (x <= 1.9d-114) then
tmp = t_0
else if (x <= 3.2d-91) then
tmp = t_1
else if (x <= 1.65d-65) then
tmp = t_0
else if (x <= 30.0d0) then
tmp = x - (x + ((-0.5d0) * (eps / x)))
else if (x <= 54000000.0d0) then
tmp = t_1
else
tmp = x - x
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = x - Math.sqrt(-eps);
double t_1 = eps / ((eps / (x / -0.5)) + (x * 2.0));
double tmp;
if (x <= 1.9e-114) {
tmp = t_0;
} else if (x <= 3.2e-91) {
tmp = t_1;
} else if (x <= 1.65e-65) {
tmp = t_0;
} else if (x <= 30.0) {
tmp = x - (x + (-0.5 * (eps / x)));
} else if (x <= 54000000.0) {
tmp = t_1;
} else {
tmp = x - x;
}
return tmp;
}
def code(x, eps): t_0 = x - math.sqrt(-eps) t_1 = eps / ((eps / (x / -0.5)) + (x * 2.0)) tmp = 0 if x <= 1.9e-114: tmp = t_0 elif x <= 3.2e-91: tmp = t_1 elif x <= 1.65e-65: tmp = t_0 elif x <= 30.0: tmp = x - (x + (-0.5 * (eps / x))) elif x <= 54000000.0: tmp = t_1 else: tmp = x - x return tmp
function code(x, eps) t_0 = Float64(x - sqrt(Float64(-eps))) t_1 = Float64(eps / Float64(Float64(eps / Float64(x / -0.5)) + Float64(x * 2.0))) tmp = 0.0 if (x <= 1.9e-114) tmp = t_0; elseif (x <= 3.2e-91) tmp = t_1; elseif (x <= 1.65e-65) tmp = t_0; elseif (x <= 30.0) tmp = Float64(x - Float64(x + Float64(-0.5 * Float64(eps / x)))); elseif (x <= 54000000.0) tmp = t_1; else tmp = Float64(x - x); end return tmp end
function tmp_2 = code(x, eps) t_0 = x - sqrt(-eps); t_1 = eps / ((eps / (x / -0.5)) + (x * 2.0)); tmp = 0.0; if (x <= 1.9e-114) tmp = t_0; elseif (x <= 3.2e-91) tmp = t_1; elseif (x <= 1.65e-65) tmp = t_0; elseif (x <= 30.0) tmp = x - (x + (-0.5 * (eps / x))); elseif (x <= 54000000.0) tmp = t_1; else tmp = x - x; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(x - N[Sqrt[(-eps)], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(eps / N[(N[(eps / N[(x / -0.5), $MachinePrecision]), $MachinePrecision] + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 1.9e-114], t$95$0, If[LessEqual[x, 3.2e-91], t$95$1, If[LessEqual[x, 1.65e-65], t$95$0, If[LessEqual[x, 30.0], N[(x - N[(x + N[(-0.5 * N[(eps / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 54000000.0], t$95$1, N[(x - x), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x - \sqrt{-\varepsilon}\\
t_1 := \frac{\varepsilon}{\frac{\varepsilon}{\frac{x}{-0.5}} + x \cdot 2}\\
\mathbf{if}\;x \leq 1.9 \cdot 10^{-114}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 3.2 \cdot 10^{-91}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq 1.65 \cdot 10^{-65}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 30:\\
\;\;\;\;x - \left(x + -0.5 \cdot \frac{\varepsilon}{x}\right)\\
\mathbf{elif}\;x \leq 54000000:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;x - x\\
\end{array}
\end{array}
if x < 1.8999999999999999e-114 or 3.19999999999999996e-91 < x < 1.6500000000000001e-65Initial program 93.2%
Taylor expanded in x around 0 86.8%
neg-mul-186.8%
Simplified86.8%
if 1.8999999999999999e-114 < x < 3.19999999999999996e-91 or 30 < x < 5.4e7Initial program 38.1%
flip--38.1%
div-inv38.0%
add-sqr-sqrt38.1%
associate--r-88.0%
pow288.0%
pow288.0%
sub-neg88.0%
add-sqr-sqrt44.5%
hypot-def44.5%
Applied egg-rr44.5%
+-inverses44.5%
+-lft-identity44.5%
associate-*r/44.6%
associate-/l*44.6%
/-rgt-identity44.6%
Simplified44.6%
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-sqrt70.3%
associate-*r*70.3%
metadata-eval70.3%
associate-*r/70.3%
*-commutative70.3%
Simplified70.3%
fma-udef70.3%
+-commutative70.3%
associate-*l/70.3%
associate-/l*70.3%
Applied egg-rr70.3%
if 1.6500000000000001e-65 < x < 30Initial program 69.0%
Taylor expanded in x around inf 57.7%
if 5.4e7 < x Initial program 100.0%
Taylor expanded in x around inf 100.0%
Final simplification75.2%
(FPCore (x eps) :precision binary64 (if (<= eps 2.5e-164) (- x (sqrt (- (* x x) eps))) (/ eps (+ (/ eps (/ x -0.5)) (* x 2.0)))))
double code(double x, double eps) {
double tmp;
if (eps <= 2.5e-164) {
tmp = x - sqrt(((x * x) - 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 (eps <= 2.5d-164) then
tmp = x - sqrt(((x * x) - 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 (eps <= 2.5e-164) {
tmp = x - Math.sqrt(((x * x) - eps));
} else {
tmp = eps / ((eps / (x / -0.5)) + (x * 2.0));
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= 2.5e-164: tmp = x - math.sqrt(((x * x) - eps)) else: tmp = eps / ((eps / (x / -0.5)) + (x * 2.0)) return tmp
function code(x, eps) tmp = 0.0 if (eps <= 2.5e-164) tmp = Float64(x - sqrt(Float64(Float64(x * x) - eps))); else tmp = Float64(eps / Float64(Float64(eps / Float64(x / -0.5)) + Float64(x * 2.0))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= 2.5e-164) tmp = x - sqrt(((x * x) - eps)); else tmp = eps / ((eps / (x / -0.5)) + (x * 2.0)); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, 2.5e-164], N[(x - N[Sqrt[N[(N[(x * x), $MachinePrecision] - eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(eps / N[(N[(eps / N[(x / -0.5), $MachinePrecision]), $MachinePrecision] + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq 2.5 \cdot 10^{-164}:\\
\;\;\;\;x - \sqrt{x \cdot x - \varepsilon}\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon}{\frac{\varepsilon}{\frac{x}{-0.5}} + x \cdot 2}\\
\end{array}
\end{array}
if eps < 2.49999999999999981e-164Initial program 83.3%
if 2.49999999999999981e-164 < eps Initial program 33.5%
flip--33.6%
div-inv33.6%
add-sqr-sqrt34.8%
associate--r-78.8%
pow278.8%
pow278.8%
sub-neg78.8%
add-sqr-sqrt0.0%
hypot-def0.0%
Applied egg-rr0.0%
+-inverses0.0%
+-lft-identity0.0%
associate-*r/0.0%
associate-/l*0.0%
/-rgt-identity0.0%
Simplified0.0%
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-sqrt77.6%
associate-*r*77.6%
metadata-eval77.6%
associate-*r/77.6%
*-commutative77.6%
Simplified77.6%
fma-udef77.6%
+-commutative77.6%
associate-*l/77.6%
associate-/l*77.6%
Applied egg-rr77.6%
Final simplification82.8%
(FPCore (x eps)
:precision binary64
(if (<= eps -1.75e-297)
(/ eps (+ x (sqrt (- eps))))
(if (<= eps 9.5e-166)
(- x (+ x (* -0.5 (/ eps x))))
(/ eps (+ (/ eps (/ x -0.5)) (* x 2.0))))))
double code(double x, double eps) {
double tmp;
if (eps <= -1.75e-297) {
tmp = eps / (x + sqrt(-eps));
} else if (eps <= 9.5e-166) {
tmp = x - (x + (-0.5 * (eps / x)));
} 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 (eps <= (-1.75d-297)) then
tmp = eps / (x + sqrt(-eps))
else if (eps <= 9.5d-166) then
tmp = x - (x + ((-0.5d0) * (eps / x)))
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 (eps <= -1.75e-297) {
tmp = eps / (x + Math.sqrt(-eps));
} else if (eps <= 9.5e-166) {
tmp = x - (x + (-0.5 * (eps / x)));
} else {
tmp = eps / ((eps / (x / -0.5)) + (x * 2.0));
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= -1.75e-297: tmp = eps / (x + math.sqrt(-eps)) elif eps <= 9.5e-166: tmp = x - (x + (-0.5 * (eps / x))) else: tmp = eps / ((eps / (x / -0.5)) + (x * 2.0)) return tmp
function code(x, eps) tmp = 0.0 if (eps <= -1.75e-297) tmp = Float64(eps / Float64(x + sqrt(Float64(-eps)))); elseif (eps <= 9.5e-166) tmp = Float64(x - Float64(x + Float64(-0.5 * Float64(eps / x)))); else tmp = Float64(eps / Float64(Float64(eps / Float64(x / -0.5)) + Float64(x * 2.0))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= -1.75e-297) tmp = eps / (x + sqrt(-eps)); elseif (eps <= 9.5e-166) tmp = x - (x + (-0.5 * (eps / x))); else tmp = eps / ((eps / (x / -0.5)) + (x * 2.0)); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -1.75e-297], N[(eps / N[(x + N[Sqrt[(-eps)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 9.5e-166], N[(x - N[(x + N[(-0.5 * N[(eps / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(eps / N[(N[(eps / N[(x / -0.5), $MachinePrecision]), $MachinePrecision] + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.75 \cdot 10^{-297}:\\
\;\;\;\;\frac{\varepsilon}{x + \sqrt{-\varepsilon}}\\
\mathbf{elif}\;\varepsilon \leq 9.5 \cdot 10^{-166}:\\
\;\;\;\;x - \left(x + -0.5 \cdot \frac{\varepsilon}{x}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon}{\frac{\varepsilon}{\frac{x}{-0.5}} + x \cdot 2}\\
\end{array}
\end{array}
if eps < -1.7499999999999999e-297Initial program 85.9%
flip--85.8%
div-inv85.6%
add-sqr-sqrt85.4%
associate--r-89.8%
pow289.8%
pow289.8%
sub-neg89.8%
add-sqr-sqrt89.8%
hypot-def89.8%
Applied egg-rr89.8%
+-inverses89.8%
+-lft-identity89.8%
associate-*r/89.9%
associate-/l*89.9%
/-rgt-identity89.9%
Simplified89.9%
hypot-udef89.9%
unpow289.9%
add-sqr-sqrt89.9%
sub-neg89.9%
pow1/289.9%
Applied egg-rr89.9%
unpow1/289.9%
Simplified89.9%
Taylor expanded in x around 0 73.9%
neg-mul-173.9%
Simplified73.9%
if -1.7499999999999999e-297 < eps < 9.50000000000000046e-166Initial program 72.7%
Taylor expanded in x around inf 68.4%
if 9.50000000000000046e-166 < eps Initial program 33.5%
flip--33.6%
div-inv33.6%
add-sqr-sqrt34.8%
associate--r-78.8%
pow278.8%
pow278.8%
sub-neg78.8%
add-sqr-sqrt0.0%
hypot-def0.0%
Applied egg-rr0.0%
+-inverses0.0%
+-lft-identity0.0%
associate-*r/0.0%
associate-/l*0.0%
/-rgt-identity0.0%
Simplified0.0%
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-sqrt77.6%
associate-*r*77.6%
metadata-eval77.6%
associate-*r/77.6%
*-commutative77.6%
Simplified77.6%
fma-udef77.6%
+-commutative77.6%
associate-*l/77.6%
associate-/l*77.6%
Applied egg-rr77.6%
Final simplification73.3%
(FPCore (x eps) :precision binary64 (if (or (<= eps -1e-203) (not (<= eps 1.15e-163))) (/ eps (+ (/ eps (/ x -0.5)) (* x 2.0))) (- x (+ x (* -0.5 (/ eps x))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -1e-203) || !(eps <= 1.15e-163)) {
tmp = eps / ((eps / (x / -0.5)) + (x * 2.0));
} else {
tmp = x - (x + (-0.5 * (eps / x)));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-1d-203)) .or. (.not. (eps <= 1.15d-163))) then
tmp = eps / ((eps / (x / (-0.5d0))) + (x * 2.0d0))
else
tmp = x - (x + ((-0.5d0) * (eps / x)))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -1e-203) || !(eps <= 1.15e-163)) {
tmp = eps / ((eps / (x / -0.5)) + (x * 2.0));
} else {
tmp = x - (x + (-0.5 * (eps / x)));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -1e-203) or not (eps <= 1.15e-163): tmp = eps / ((eps / (x / -0.5)) + (x * 2.0)) else: tmp = x - (x + (-0.5 * (eps / x))) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -1e-203) || !(eps <= 1.15e-163)) tmp = Float64(eps / Float64(Float64(eps / Float64(x / -0.5)) + Float64(x * 2.0))); else tmp = Float64(x - Float64(x + Float64(-0.5 * Float64(eps / x)))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -1e-203) || ~((eps <= 1.15e-163))) tmp = eps / ((eps / (x / -0.5)) + (x * 2.0)); else tmp = x - (x + (-0.5 * (eps / x))); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -1e-203], N[Not[LessEqual[eps, 1.15e-163]], $MachinePrecision]], N[(eps / N[(N[(eps / N[(x / -0.5), $MachinePrecision]), $MachinePrecision] + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(x + N[(-0.5 * N[(eps / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1 \cdot 10^{-203} \lor \neg \left(\varepsilon \leq 1.15 \cdot 10^{-163}\right):\\
\;\;\;\;\frac{\varepsilon}{\frac{\varepsilon}{\frac{x}{-0.5}} + x \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;x - \left(x + -0.5 \cdot \frac{\varepsilon}{x}\right)\\
\end{array}
\end{array}
if eps < -1e-203 or 1.15e-163 < eps Initial program 77.4%
flip--77.3%
div-inv77.1%
add-sqr-sqrt77.2%
associate--r-93.7%
pow293.7%
pow293.7%
sub-neg93.7%
add-sqr-sqrt81.7%
hypot-def81.7%
Applied egg-rr81.7%
+-inverses81.7%
+-lft-identity81.7%
associate-*r/81.7%
associate-/l*81.7%
/-rgt-identity81.7%
Simplified81.7%
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-sqrt29.9%
associate-*r*29.9%
metadata-eval29.9%
associate-*r/29.9%
*-commutative29.9%
Simplified29.9%
fma-udef29.9%
+-commutative29.9%
associate-*l/29.9%
associate-/l*29.9%
Applied egg-rr29.9%
if -1e-203 < eps < 1.15e-163Initial program 81.0%
Taylor expanded in x around inf 46.9%
Final simplification36.8%
(FPCore (x eps) :precision binary64 (if (or (<= eps -7.5e-195) (not (<= eps 1.15e-164))) (* (/ eps x) 0.5) (- x (+ x (* -0.5 (/ eps x))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -7.5e-195) || !(eps <= 1.15e-164)) {
tmp = (eps / x) * 0.5;
} else {
tmp = x - (x + (-0.5 * (eps / x)));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-7.5d-195)) .or. (.not. (eps <= 1.15d-164))) then
tmp = (eps / x) * 0.5d0
else
tmp = x - (x + ((-0.5d0) * (eps / x)))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -7.5e-195) || !(eps <= 1.15e-164)) {
tmp = (eps / x) * 0.5;
} else {
tmp = x - (x + (-0.5 * (eps / x)));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -7.5e-195) or not (eps <= 1.15e-164): tmp = (eps / x) * 0.5 else: tmp = x - (x + (-0.5 * (eps / x))) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -7.5e-195) || !(eps <= 1.15e-164)) tmp = Float64(Float64(eps / x) * 0.5); else tmp = Float64(x - Float64(x + Float64(-0.5 * Float64(eps / x)))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -7.5e-195) || ~((eps <= 1.15e-164))) tmp = (eps / x) * 0.5; else tmp = x - (x + (-0.5 * (eps / x))); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -7.5e-195], N[Not[LessEqual[eps, 1.15e-164]], $MachinePrecision]], N[(N[(eps / x), $MachinePrecision] * 0.5), $MachinePrecision], N[(x - N[(x + N[(-0.5 * N[(eps / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -7.5 \cdot 10^{-195} \lor \neg \left(\varepsilon \leq 1.15 \cdot 10^{-164}\right):\\
\;\;\;\;\frac{\varepsilon}{x} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x - \left(x + -0.5 \cdot \frac{\varepsilon}{x}\right)\\
\end{array}
\end{array}
if eps < -7.5e-195 or 1.14999999999999993e-164 < eps Initial program 76.6%
Taylor expanded in x around inf 29.8%
if -7.5e-195 < eps < 1.14999999999999993e-164Initial program 81.8%
Taylor expanded in x around inf 45.0%
Final simplification36.3%
(FPCore (x eps) :precision binary64 (if (or (<= eps -4.6e-216) (not (<= eps 3.6e-165))) (* (/ eps x) 0.5) (- x x)))
double code(double x, double eps) {
double tmp;
if ((eps <= -4.6e-216) || !(eps <= 3.6e-165)) {
tmp = (eps / x) * 0.5;
} else {
tmp = x - x;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-4.6d-216)) .or. (.not. (eps <= 3.6d-165))) then
tmp = (eps / x) * 0.5d0
else
tmp = x - x
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -4.6e-216) || !(eps <= 3.6e-165)) {
tmp = (eps / x) * 0.5;
} else {
tmp = x - x;
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -4.6e-216) or not (eps <= 3.6e-165): tmp = (eps / x) * 0.5 else: tmp = x - x return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -4.6e-216) || !(eps <= 3.6e-165)) tmp = Float64(Float64(eps / x) * 0.5); else tmp = Float64(x - x); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -4.6e-216) || ~((eps <= 3.6e-165))) tmp = (eps / x) * 0.5; else tmp = x - x; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -4.6e-216], N[Not[LessEqual[eps, 3.6e-165]], $MachinePrecision]], N[(N[(eps / x), $MachinePrecision] * 0.5), $MachinePrecision], N[(x - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -4.6 \cdot 10^{-216} \lor \neg \left(\varepsilon \leq 3.6 \cdot 10^{-165}\right):\\
\;\;\;\;\frac{\varepsilon}{x} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x - x\\
\end{array}
\end{array}
if eps < -4.59999999999999993e-216 or 3.59999999999999984e-165 < eps Initial program 78.5%
Taylor expanded in x around inf 27.9%
if -4.59999999999999993e-216 < eps < 3.59999999999999984e-165Initial program 79.4%
Taylor expanded in x around inf 46.9%
Final simplification35.1%
(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 78.9%
flip--78.8%
div-inv78.6%
add-sqr-sqrt78.7%
associate--r-80.5%
pow280.4%
pow280.5%
sub-neg80.5%
add-sqr-sqrt67.6%
hypot-def67.6%
Applied egg-rr67.6%
+-inverses67.6%
+-lft-identity67.6%
associate-*r/67.7%
associate-/l*67.7%
/-rgt-identity67.7%
Simplified67.7%
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-sqrt29.1%
associate-*r*29.1%
metadata-eval29.1%
associate-*r/29.1%
*-commutative29.1%
Simplified29.1%
Taylor expanded in eps around inf 5.6%
*-commutative5.6%
Simplified5.6%
Final simplification5.6%
(FPCore (x eps) :precision binary64 (- x x))
double code(double x, double eps) {
return x - x;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = x - x
end function
public static double code(double x, double eps) {
return x - x;
}
def code(x, eps): return x - x
function code(x, eps) return Float64(x - x) end
function tmp = code(x, eps) tmp = x - x; end
code[x_, eps_] := N[(x - x), $MachinePrecision]
\begin{array}{l}
\\
x - x
\end{array}
Initial program 78.9%
Taylor expanded in x around inf 23.4%
Final simplification23.4%
(FPCore (x eps) :precision binary64 x)
double code(double x, double eps) {
return x;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = x
end function
public static double code(double x, double eps) {
return x;
}
def code(x, eps): return x
function code(x, eps) return x end
function tmp = code(x, eps) tmp = x; end
code[x_, eps_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 78.9%
Taylor expanded in x around 0 52.9%
neg-mul-152.9%
Simplified52.9%
Taylor expanded in x around inf 3.4%
Final simplification3.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 2024031
(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))))