
(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 (<= eps 3.7e-78)
(- x (sqrt (- (* x x) eps)))
(/
eps
(+
x
(/
(sqrt (- (pow x 6.0) (pow eps 3.0)))
(sqrt (+ (pow x 4.0) (fma eps eps (* eps (pow x 2.0))))))))))
double code(double x, double eps) {
double tmp;
if (eps <= 3.7e-78) {
tmp = x - sqrt(((x * x) - eps));
} else {
tmp = eps / (x + (sqrt((pow(x, 6.0) - pow(eps, 3.0))) / sqrt((pow(x, 4.0) + fma(eps, eps, (eps * pow(x, 2.0)))))));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (eps <= 3.7e-78) tmp = Float64(x - sqrt(Float64(Float64(x * x) - eps))); else tmp = Float64(eps / Float64(x + Float64(sqrt(Float64((x ^ 6.0) - (eps ^ 3.0))) / sqrt(Float64((x ^ 4.0) + fma(eps, eps, Float64(eps * (x ^ 2.0)))))))); end return tmp end
code[x_, eps_] := If[LessEqual[eps, 3.7e-78], N[(x - N[Sqrt[N[(N[(x * x), $MachinePrecision] - eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(eps / N[(x + N[(N[Sqrt[N[(N[Power[x, 6.0], $MachinePrecision] - N[Power[eps, 3.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[Power[x, 4.0], $MachinePrecision] + N[(eps * eps + N[(eps * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq 3.7 \cdot 10^{-78}:\\
\;\;\;\;x - \sqrt{x \cdot x - \varepsilon}\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon}{x + \frac{\sqrt{{x}^{6} - {\varepsilon}^{3}}}{\sqrt{{x}^{4} + \mathsf{fma}\left(\varepsilon, \varepsilon, \varepsilon \cdot {x}^{2}\right)}}}\\
\end{array}
\end{array}
if eps < 3.70000000000000006e-78Initial program 91.1%
if 3.70000000000000006e-78 < eps Initial program 21.5%
flip--22.0%
div-inv22.0%
add-sqr-sqrt24.8%
associate--r-99.6%
pow299.6%
pow299.6%
sub-neg99.6%
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%
hypot-udef0.0%
unpow20.0%
add-sqr-sqrt99.8%
sub-neg99.8%
flip3--99.8%
sqrt-div99.6%
pow-pow99.8%
metadata-eval99.8%
pow-prod-up99.8%
metadata-eval99.8%
fma-def99.8%
Applied egg-rr99.8%
Final simplification91.4%
(FPCore (x eps)
:precision binary64
(if (<= eps 1.4e-77)
(- x (sqrt (- (* x x) eps)))
(/
eps
(+ x (/ (sqrt (- (pow x 4.0) (pow eps 2.0))) (hypot x (sqrt eps)))))))
double code(double x, double eps) {
double tmp;
if (eps <= 1.4e-77) {
tmp = x - sqrt(((x * x) - eps));
} else {
tmp = eps / (x + (sqrt((pow(x, 4.0) - pow(eps, 2.0))) / hypot(x, sqrt(eps))));
}
return tmp;
}
public static double code(double x, double eps) {
double tmp;
if (eps <= 1.4e-77) {
tmp = x - Math.sqrt(((x * x) - eps));
} else {
tmp = eps / (x + (Math.sqrt((Math.pow(x, 4.0) - Math.pow(eps, 2.0))) / Math.hypot(x, Math.sqrt(eps))));
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= 1.4e-77: tmp = x - math.sqrt(((x * x) - eps)) else: tmp = eps / (x + (math.sqrt((math.pow(x, 4.0) - math.pow(eps, 2.0))) / math.hypot(x, math.sqrt(eps)))) return tmp
function code(x, eps) tmp = 0.0 if (eps <= 1.4e-77) tmp = Float64(x - sqrt(Float64(Float64(x * x) - eps))); else tmp = Float64(eps / Float64(x + Float64(sqrt(Float64((x ^ 4.0) - (eps ^ 2.0))) / hypot(x, sqrt(eps))))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= 1.4e-77) tmp = x - sqrt(((x * x) - eps)); else tmp = eps / (x + (sqrt(((x ^ 4.0) - (eps ^ 2.0))) / hypot(x, sqrt(eps)))); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, 1.4e-77], N[(x - N[Sqrt[N[(N[(x * x), $MachinePrecision] - eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(eps / N[(x + N[(N[Sqrt[N[(N[Power[x, 4.0], $MachinePrecision] - N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[x ^ 2 + N[Sqrt[eps], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq 1.4 \cdot 10^{-77}:\\
\;\;\;\;x - \sqrt{x \cdot x - \varepsilon}\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon}{x + \frac{\sqrt{{x}^{4} - {\varepsilon}^{2}}}{\mathsf{hypot}\left(x, \sqrt{\varepsilon}\right)}}\\
\end{array}
\end{array}
if eps < 1.4e-77Initial program 91.1%
if 1.4e-77 < eps Initial program 21.5%
flip--22.0%
div-inv22.0%
add-sqr-sqrt24.8%
associate--r-99.6%
pow299.6%
pow299.6%
sub-neg99.6%
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%
hypot-udef0.0%
unpow20.0%
add-sqr-sqrt99.8%
sub-neg99.8%
flip--99.8%
sqrt-div99.8%
pow-prod-up99.6%
metadata-eval99.6%
pow299.6%
unpow299.6%
add-sqr-sqrt99.6%
sqrt-unprod99.6%
sqr-neg99.6%
sqrt-unprod0.0%
hypot-udef0.0%
add-sqr-sqrt0.0%
sqrt-unprod99.6%
sqr-neg99.6%
sqrt-unprod99.6%
add-sqr-sqrt99.6%
Applied egg-rr99.6%
Final simplification91.4%
(FPCore (x eps)
:precision binary64
(if (<= eps 5.4e-78)
(- x (sqrt (- (* x x) eps)))
(/
eps
(+ x (+ x (fma -0.125 (/ (pow (/ eps x) 2.0) x) (* (/ eps x) (- 0.5))))))))
double code(double x, double eps) {
double tmp;
if (eps <= 5.4e-78) {
tmp = x - sqrt(((x * x) - eps));
} else {
tmp = eps / (x + (x + fma(-0.125, (pow((eps / x), 2.0) / x), ((eps / x) * -0.5))));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (eps <= 5.4e-78) tmp = Float64(x - sqrt(Float64(Float64(x * x) - eps))); else tmp = Float64(eps / Float64(x + Float64(x + fma(-0.125, Float64((Float64(eps / x) ^ 2.0) / x), Float64(Float64(eps / x) * Float64(-0.5)))))); end return tmp end
code[x_, eps_] := If[LessEqual[eps, 5.4e-78], N[(x - N[Sqrt[N[(N[(x * x), $MachinePrecision] - eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(eps / N[(x + N[(x + N[(-0.125 * N[(N[Power[N[(eps / x), $MachinePrecision], 2.0], $MachinePrecision] / x), $MachinePrecision] + N[(N[(eps / x), $MachinePrecision] * (-0.5)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq 5.4 \cdot 10^{-78}:\\
\;\;\;\;x - \sqrt{x \cdot x - \varepsilon}\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon}{x + \left(x + \mathsf{fma}\left(-0.125, \frac{{\left(\frac{\varepsilon}{x}\right)}^{2}}{x}, \frac{\varepsilon}{x} \cdot \left(-0.5\right)\right)\right)}\\
\end{array}
\end{array}
if eps < 5.39999999999999987e-78Initial program 91.1%
if 5.39999999999999987e-78 < eps Initial program 21.5%
flip--22.0%
div-inv22.0%
add-sqr-sqrt24.8%
associate--r-99.6%
pow299.6%
pow299.6%
sub-neg99.6%
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%
fma-def0.0%
unpow20.0%
metadata-eval0.0%
pow-sqr0.0%
unpow20.0%
rem-square-sqrt0.0%
unpow20.0%
rem-square-sqrt0.0%
metadata-eval0.0%
metadata-eval0.0%
swap-sqr0.0%
*-rgt-identity0.0%
*-rgt-identity0.0%
unpow20.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt98.4%
mul-1-neg98.4%
Simplified98.4%
*-un-lft-identity98.4%
cube-mult98.4%
unpow298.4%
times-frac98.4%
unpow298.4%
unpow298.4%
frac-times98.4%
pow298.4%
Applied egg-rr98.4%
associate-*l/98.4%
*-lft-identity98.4%
Simplified98.4%
Final simplification91.3%
(FPCore (x eps) :precision binary64 (if (or (<= x 1.9e-114) (and (not (<= x 3.7e-91)) (<= x 9.8e-66))) (- x (sqrt (- eps))) (- x (+ x (* (/ eps x) -0.5)))))
double code(double x, double eps) {
double tmp;
if ((x <= 1.9e-114) || (!(x <= 3.7e-91) && (x <= 9.8e-66))) {
tmp = x - sqrt(-eps);
} else {
tmp = 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) :: tmp
if ((x <= 1.9d-114) .or. (.not. (x <= 3.7d-91)) .and. (x <= 9.8d-66)) then
tmp = x - sqrt(-eps)
else
tmp = x - (x + ((eps / x) * (-0.5d0)))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((x <= 1.9e-114) || (!(x <= 3.7e-91) && (x <= 9.8e-66))) {
tmp = x - Math.sqrt(-eps);
} else {
tmp = x - (x + ((eps / x) * -0.5));
}
return tmp;
}
def code(x, eps): tmp = 0 if (x <= 1.9e-114) or (not (x <= 3.7e-91) and (x <= 9.8e-66)): tmp = x - math.sqrt(-eps) else: tmp = x - (x + ((eps / x) * -0.5)) return tmp
function code(x, eps) tmp = 0.0 if ((x <= 1.9e-114) || (!(x <= 3.7e-91) && (x <= 9.8e-66))) tmp = Float64(x - sqrt(Float64(-eps))); else tmp = Float64(x - Float64(x + Float64(Float64(eps / x) * -0.5))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((x <= 1.9e-114) || (~((x <= 3.7e-91)) && (x <= 9.8e-66))) tmp = x - sqrt(-eps); else tmp = x - (x + ((eps / x) * -0.5)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[x, 1.9e-114], And[N[Not[LessEqual[x, 3.7e-91]], $MachinePrecision], LessEqual[x, 9.8e-66]]], N[(x - N[Sqrt[(-eps)], $MachinePrecision]), $MachinePrecision], N[(x - N[(x + N[(N[(eps / x), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.9 \cdot 10^{-114} \lor \neg \left(x \leq 3.7 \cdot 10^{-91}\right) \land x \leq 9.8 \cdot 10^{-66}:\\
\;\;\;\;x - \sqrt{-\varepsilon}\\
\mathbf{else}:\\
\;\;\;\;x - \left(x + \frac{\varepsilon}{x} \cdot -0.5\right)\\
\end{array}
\end{array}
if x < 1.8999999999999999e-114 or 3.7000000000000002e-91 < x < 9.8000000000000001e-66Initial program 94.6%
Taylor expanded in x around 0 86.8%
neg-mul-186.8%
Simplified86.8%
if 1.8999999999999999e-114 < x < 3.7000000000000002e-91 or 9.8000000000000001e-66 < x Initial program 82.1%
Taylor expanded in x around inf 69.2%
Final simplification78.8%
(FPCore (x eps) :precision binary64 (if (<= eps 1.15e-77) (- x (sqrt (- (* x x) eps))) (/ eps (+ (* (/ eps x) -0.5) (* x 2.0)))))
double code(double x, double eps) {
double tmp;
if (eps <= 1.15e-77) {
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 <= 1.15d-77) 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 <= 1.15e-77) {
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 <= 1.15e-77: 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 <= 1.15e-77) tmp = Float64(x - sqrt(Float64(Float64(x * x) - 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 (eps <= 1.15e-77) 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, 1.15e-77], N[(x - N[Sqrt[N[(N[(x * x), $MachinePrecision] - eps), $MachinePrecision]], $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}\;\varepsilon \leq 1.15 \cdot 10^{-77}:\\
\;\;\;\;x - \sqrt{x \cdot x - \varepsilon}\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon}{\frac{\varepsilon}{x} \cdot -0.5 + x \cdot 2}\\
\end{array}
\end{array}
if eps < 1.14999999999999999e-77Initial program 91.1%
if 1.14999999999999999e-77 < eps Initial program 21.5%
flip--22.0%
div-inv22.0%
add-sqr-sqrt24.8%
associate--r-99.6%
pow299.6%
pow299.6%
sub-neg99.6%
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%
unpow20.0%
rem-square-sqrt95.7%
mul-1-neg95.7%
Simplified95.7%
Taylor expanded in x around 0 95.7%
Final simplification91.2%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (* (/ eps x) -0.5)))
(if (or (<= eps -6e-96) (not (<= eps 4.6e-78)))
(/ eps (+ t_0 (* x 2.0)))
(- x (+ x t_0)))))
double code(double x, double eps) {
double t_0 = (eps / x) * -0.5;
double tmp;
if ((eps <= -6e-96) || !(eps <= 4.6e-78)) {
tmp = eps / (t_0 + (x * 2.0));
} else {
tmp = x - (x + t_0);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: tmp
t_0 = (eps / x) * (-0.5d0)
if ((eps <= (-6d-96)) .or. (.not. (eps <= 4.6d-78))) then
tmp = eps / (t_0 + (x * 2.0d0))
else
tmp = x - (x + t_0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = (eps / x) * -0.5;
double tmp;
if ((eps <= -6e-96) || !(eps <= 4.6e-78)) {
tmp = eps / (t_0 + (x * 2.0));
} else {
tmp = x - (x + t_0);
}
return tmp;
}
def code(x, eps): t_0 = (eps / x) * -0.5 tmp = 0 if (eps <= -6e-96) or not (eps <= 4.6e-78): tmp = eps / (t_0 + (x * 2.0)) else: tmp = x - (x + t_0) return tmp
function code(x, eps) t_0 = Float64(Float64(eps / x) * -0.5) tmp = 0.0 if ((eps <= -6e-96) || !(eps <= 4.6e-78)) tmp = Float64(eps / Float64(t_0 + Float64(x * 2.0))); else tmp = Float64(x - Float64(x + t_0)); end return tmp end
function tmp_2 = code(x, eps) t_0 = (eps / x) * -0.5; tmp = 0.0; if ((eps <= -6e-96) || ~((eps <= 4.6e-78))) tmp = eps / (t_0 + (x * 2.0)); else tmp = x - (x + t_0); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[(eps / x), $MachinePrecision] * -0.5), $MachinePrecision]}, If[Or[LessEqual[eps, -6e-96], N[Not[LessEqual[eps, 4.6e-78]], $MachinePrecision]], N[(eps / N[(t$95$0 + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(x + t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\varepsilon}{x} \cdot -0.5\\
\mathbf{if}\;\varepsilon \leq -6 \cdot 10^{-96} \lor \neg \left(\varepsilon \leq 4.6 \cdot 10^{-78}\right):\\
\;\;\;\;\frac{\varepsilon}{t\_0 + x \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;x - \left(x + t\_0\right)\\
\end{array}
\end{array}
if eps < -6e-96 or 4.6000000000000004e-78 < eps Initial program 84.0%
flip--84.0%
div-inv83.7%
add-sqr-sqrt83.8%
associate--r-96.8%
pow296.8%
pow296.8%
sub-neg96.8%
add-sqr-sqrt86.6%
hypot-def86.6%
Applied egg-rr86.6%
+-inverses86.6%
+-lft-identity86.6%
associate-*r/86.6%
associate-/l*86.6%
/-rgt-identity86.6%
Simplified86.6%
Taylor expanded in x around inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt23.8%
mul-1-neg23.8%
Simplified23.8%
Taylor expanded in x around 0 23.8%
if -6e-96 < eps < 4.6000000000000004e-78Initial program 91.1%
Taylor expanded in x around inf 48.6%
Final simplification41.0%
(FPCore (x eps) :precision binary64 (if (or (<= eps -1.1e-96) (not (<= eps 6.2e-78))) (* (/ eps x) 0.5) (- x x)))
double code(double x, double eps) {
double tmp;
if ((eps <= -1.1e-96) || !(eps <= 6.2e-78)) {
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 <= (-1.1d-96)) .or. (.not. (eps <= 6.2d-78))) 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 <= -1.1e-96) || !(eps <= 6.2e-78)) {
tmp = (eps / x) * 0.5;
} else {
tmp = x - x;
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -1.1e-96) or not (eps <= 6.2e-78): tmp = (eps / x) * 0.5 else: tmp = x - x return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -1.1e-96) || !(eps <= 6.2e-78)) 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 <= -1.1e-96) || ~((eps <= 6.2e-78))) tmp = (eps / x) * 0.5; else tmp = x - x; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -1.1e-96], N[Not[LessEqual[eps, 6.2e-78]], $MachinePrecision]], N[(N[(eps / x), $MachinePrecision] * 0.5), $MachinePrecision], N[(x - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.1 \cdot 10^{-96} \lor \neg \left(\varepsilon \leq 6.2 \cdot 10^{-78}\right):\\
\;\;\;\;\frac{\varepsilon}{x} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x - x\\
\end{array}
\end{array}
if eps < -1.0999999999999999e-96 or 6.20000000000000035e-78 < eps Initial program 84.2%
Taylor expanded in x around inf 22.6%
if -1.0999999999999999e-96 < eps < 6.20000000000000035e-78Initial program 91.0%
Taylor expanded in x around inf 45.8%
Final simplification38.6%
(FPCore (x eps) :precision binary64 (if (<= eps 1.45e-77) (- x (+ x (* (/ eps x) -0.5))) (* (/ eps x) 0.5)))
double code(double x, double eps) {
double tmp;
if (eps <= 1.45e-77) {
tmp = x - (x + ((eps / x) * -0.5));
} else {
tmp = (eps / x) * 0.5;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (eps <= 1.45d-77) then
tmp = x - (x + ((eps / x) * (-0.5d0)))
else
tmp = (eps / x) * 0.5d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (eps <= 1.45e-77) {
tmp = x - (x + ((eps / x) * -0.5));
} else {
tmp = (eps / x) * 0.5;
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= 1.45e-77: tmp = x - (x + ((eps / x) * -0.5)) else: tmp = (eps / x) * 0.5 return tmp
function code(x, eps) tmp = 0.0 if (eps <= 1.45e-77) tmp = Float64(x - Float64(x + Float64(Float64(eps / x) * -0.5))); else tmp = Float64(Float64(eps / x) * 0.5); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= 1.45e-77) tmp = x - (x + ((eps / x) * -0.5)); else tmp = (eps / x) * 0.5; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, 1.45e-77], N[(x - N[(x + N[(N[(eps / x), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(eps / x), $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq 1.45 \cdot 10^{-77}:\\
\;\;\;\;x - \left(x + \frac{\varepsilon}{x} \cdot -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon}{x} \cdot 0.5\\
\end{array}
\end{array}
if eps < 1.4499999999999999e-77Initial program 91.1%
Taylor expanded in x around inf 37.5%
if 1.4499999999999999e-77 < eps Initial program 21.5%
Taylor expanded in x around inf 89.4%
Final simplification39.2%
(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 88.9%
flip--88.9%
div-inv88.7%
add-sqr-sqrt88.8%
associate--r-70.5%
pow270.4%
pow270.5%
sub-neg70.5%
add-sqr-sqrt61.7%
hypot-def61.7%
Applied egg-rr61.7%
+-inverses61.7%
+-lft-identity61.7%
associate-*r/61.7%
associate-/l*61.7%
/-rgt-identity61.7%
Simplified61.7%
Taylor expanded in x around inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt19.0%
mul-1-neg19.0%
Simplified19.0%
Taylor expanded in eps around inf 5.5%
*-commutative5.5%
Simplified5.5%
Final simplification5.5%
(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 88.9%
Taylor expanded in x around inf 33.4%
Final simplification33.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 88.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))))