
(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 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x eps) :precision binary64 (- x (sqrt (- (* x x) eps))))
double code(double x, double eps) {
return x - sqrt(((x * x) - eps));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = x - sqrt(((x * x) - eps))
end function
public static double code(double x, double eps) {
return x - Math.sqrt(((x * x) - eps));
}
def code(x, eps): return x - math.sqrt(((x * x) - eps))
function code(x, eps) return Float64(x - sqrt(Float64(Float64(x * x) - eps))) end
function tmp = code(x, eps) tmp = x - sqrt(((x * x) - eps)); end
code[x_, eps_] := N[(x - N[Sqrt[N[(N[(x * x), $MachinePrecision] - eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \sqrt{x \cdot x - \varepsilon}
\end{array}
(FPCore (x eps)
:precision binary64
(if (<= (- x (sqrt (- (* x x) eps))) -2e-154)
(/ eps (+ x (hypot x (sqrt (- eps)))))
(/
eps
(+
x
(+ x (+ (* -0.125 (pow (/ eps (pow x 1.5)) 2.0)) (* (/ eps x) -0.5)))))))
double code(double x, double eps) {
double tmp;
if ((x - sqrt(((x * x) - eps))) <= -2e-154) {
tmp = eps / (x + hypot(x, sqrt(-eps)));
} else {
tmp = eps / (x + (x + ((-0.125 * pow((eps / pow(x, 1.5)), 2.0)) + ((eps / x) * -0.5))));
}
return tmp;
}
public static double code(double x, double eps) {
double tmp;
if ((x - Math.sqrt(((x * x) - eps))) <= -2e-154) {
tmp = eps / (x + Math.hypot(x, Math.sqrt(-eps)));
} else {
tmp = eps / (x + (x + ((-0.125 * Math.pow((eps / Math.pow(x, 1.5)), 2.0)) + ((eps / x) * -0.5))));
}
return tmp;
}
def code(x, eps): tmp = 0 if (x - math.sqrt(((x * x) - eps))) <= -2e-154: tmp = eps / (x + math.hypot(x, math.sqrt(-eps))) else: tmp = eps / (x + (x + ((-0.125 * math.pow((eps / math.pow(x, 1.5)), 2.0)) + ((eps / x) * -0.5)))) return tmp
function code(x, eps) tmp = 0.0 if (Float64(x - sqrt(Float64(Float64(x * x) - eps))) <= -2e-154) tmp = Float64(eps / Float64(x + hypot(x, sqrt(Float64(-eps))))); else tmp = Float64(eps / Float64(x + Float64(x + Float64(Float64(-0.125 * (Float64(eps / (x ^ 1.5)) ^ 2.0)) + 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))) <= -2e-154) tmp = eps / (x + hypot(x, sqrt(-eps))); else tmp = eps / (x + (x + ((-0.125 * ((eps / (x ^ 1.5)) ^ 2.0)) + ((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], -2e-154], N[(eps / N[(x + N[Sqrt[x ^ 2 + N[Sqrt[(-eps)], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(eps / N[(x + N[(x + N[(N[(-0.125 * N[Power[N[(eps / N[Power[x, 1.5], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + N[(N[(eps / x), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x - \sqrt{x \cdot x - \varepsilon} \leq -2 \cdot 10^{-154}:\\
\;\;\;\;\frac{\varepsilon}{x + \mathsf{hypot}\left(x, \sqrt{-\varepsilon}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon}{x + \left(x + \left(-0.125 \cdot {\left(\frac{\varepsilon}{{x}^{1.5}}\right)}^{2} + \frac{\varepsilon}{x} \cdot -0.5\right)\right)}\\
\end{array}
\end{array}
if (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) < -1.9999999999999999e-154Initial program 99.3%
flip--99.2%
div-inv98.9%
add-sqr-sqrt98.7%
sub-neg98.7%
add-sqr-sqrt98.7%
hypot-def98.7%
Applied egg-rr98.7%
associate-*r/98.7%
*-rgt-identity98.7%
associate--r-99.3%
+-inverses99.3%
+-lft-identity99.3%
Simplified99.3%
if -1.9999999999999999e-154 < (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) Initial program 7.6%
flip--7.6%
div-inv7.6%
add-sqr-sqrt7.7%
sub-neg7.7%
add-sqr-sqrt2.8%
hypot-def2.8%
Applied egg-rr2.8%
associate-*r/2.8%
*-rgt-identity2.8%
associate--r-50.0%
+-inverses50.0%
+-lft-identity50.0%
Simplified50.0%
Taylor expanded in x around inf 0.0%
fma-def0.0%
*-commutative0.0%
metadata-eval0.0%
pow-sqr0.0%
unpow20.0%
rem-square-sqrt0.0%
unpow20.0%
rem-square-sqrt0.0%
metadata-eval0.0%
*-lft-identity0.0%
unpow20.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt95.8%
associate-*r*95.8%
metadata-eval95.8%
associate-*r/95.8%
*-commutative95.8%
Simplified95.8%
fma-udef95.8%
add-sqr-sqrt95.8%
pow295.8%
sqrt-div95.8%
sqrt-prod48.7%
add-sqr-sqrt96.0%
sqrt-pow199.6%
metadata-eval99.6%
Applied egg-rr99.6%
Final simplification99.4%
(FPCore (x eps) :precision binary64 (if (<= (- x (sqrt (- (* x x) eps))) -2e-154) (/ eps (+ x (hypot x (sqrt (- eps))))) (/ eps (+ (* (/ eps x) -0.5) (* x 2.0)))))
double code(double x, double eps) {
double tmp;
if ((x - sqrt(((x * x) - eps))) <= -2e-154) {
tmp = eps / (x + hypot(x, sqrt(-eps)));
} else {
tmp = eps / (((eps / x) * -0.5) + (x * 2.0));
}
return tmp;
}
public static double code(double x, double eps) {
double tmp;
if ((x - Math.sqrt(((x * x) - eps))) <= -2e-154) {
tmp = eps / (x + Math.hypot(x, Math.sqrt(-eps)));
} else {
tmp = eps / (((eps / x) * -0.5) + (x * 2.0));
}
return tmp;
}
def code(x, eps): tmp = 0 if (x - math.sqrt(((x * x) - eps))) <= -2e-154: tmp = eps / (x + math.hypot(x, math.sqrt(-eps))) else: tmp = eps / (((eps / x) * -0.5) + (x * 2.0)) return tmp
function code(x, eps) tmp = 0.0 if (Float64(x - sqrt(Float64(Float64(x * x) - eps))) <= -2e-154) tmp = Float64(eps / Float64(x + hypot(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 - sqrt(((x * x) - eps))) <= -2e-154) tmp = eps / (x + hypot(x, sqrt(-eps))); else tmp = eps / (((eps / x) * -0.5) + (x * 2.0)); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[N[(x - N[Sqrt[N[(N[(x * x), $MachinePrecision] - eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -2e-154], N[(eps / N[(x + N[Sqrt[x ^ 2 + N[Sqrt[(-eps)], $MachinePrecision] ^ 2], $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}\;x - \sqrt{x \cdot x - \varepsilon} \leq -2 \cdot 10^{-154}:\\
\;\;\;\;\frac{\varepsilon}{x + \mathsf{hypot}\left(x, \sqrt{-\varepsilon}\right)}\\
\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.9999999999999999e-154Initial program 99.3%
flip--99.2%
div-inv98.9%
add-sqr-sqrt98.7%
sub-neg98.7%
add-sqr-sqrt98.7%
hypot-def98.7%
Applied egg-rr98.7%
associate-*r/98.7%
*-rgt-identity98.7%
associate--r-99.3%
+-inverses99.3%
+-lft-identity99.3%
Simplified99.3%
if -1.9999999999999999e-154 < (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) Initial program 7.6%
flip--7.6%
div-inv7.6%
add-sqr-sqrt7.7%
sub-neg7.7%
add-sqr-sqrt2.8%
hypot-def2.8%
Applied egg-rr2.8%
associate-*r/2.8%
*-rgt-identity2.8%
associate--r-50.0%
+-inverses50.0%
+-lft-identity50.0%
Simplified50.0%
Taylor expanded in x around inf 0.0%
fma-def0.0%
*-commutative0.0%
metadata-eval0.0%
pow-sqr0.0%
unpow20.0%
rem-square-sqrt0.0%
unpow20.0%
rem-square-sqrt0.0%
metadata-eval0.0%
*-lft-identity0.0%
unpow20.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt95.8%
associate-*r*95.8%
metadata-eval95.8%
associate-*r/95.8%
*-commutative95.8%
Simplified95.8%
Taylor expanded in x around inf 99.1%
Final simplification99.2%
(FPCore (x eps) :precision binary64 (if (<= (- x (sqrt (- (* x x) eps))) -2e-154) (- x (hypot (sqrt (- eps)) x)) (/ eps (+ (* (/ eps x) -0.5) (* x 2.0)))))
double code(double x, double eps) {
double tmp;
if ((x - sqrt(((x * x) - eps))) <= -2e-154) {
tmp = x - hypot(sqrt(-eps), x);
} else {
tmp = eps / (((eps / x) * -0.5) + (x * 2.0));
}
return tmp;
}
public static double code(double x, double eps) {
double tmp;
if ((x - Math.sqrt(((x * x) - eps))) <= -2e-154) {
tmp = x - Math.hypot(Math.sqrt(-eps), x);
} else {
tmp = eps / (((eps / x) * -0.5) + (x * 2.0));
}
return tmp;
}
def code(x, eps): tmp = 0 if (x - math.sqrt(((x * x) - eps))) <= -2e-154: tmp = x - math.hypot(math.sqrt(-eps), x) else: tmp = eps / (((eps / x) * -0.5) + (x * 2.0)) return tmp
function code(x, eps) tmp = 0.0 if (Float64(x - sqrt(Float64(Float64(x * x) - eps))) <= -2e-154) tmp = Float64(x - hypot(sqrt(Float64(-eps)), x)); 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 - sqrt(((x * x) - eps))) <= -2e-154) tmp = x - hypot(sqrt(-eps), x); else tmp = eps / (((eps / x) * -0.5) + (x * 2.0)); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[N[(x - N[Sqrt[N[(N[(x * x), $MachinePrecision] - eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -2e-154], N[(x - N[Sqrt[N[Sqrt[(-eps)], $MachinePrecision] ^ 2 + x ^ 2], $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 - \sqrt{x \cdot x - \varepsilon} \leq -2 \cdot 10^{-154}:\\
\;\;\;\;x - \mathsf{hypot}\left(\sqrt{-\varepsilon}, x\right)\\
\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.9999999999999999e-154Initial program 99.3%
sub-neg99.3%
+-commutative99.3%
add-sqr-sqrt99.2%
hypot-def99.3%
Applied egg-rr99.3%
if -1.9999999999999999e-154 < (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) Initial program 7.6%
flip--7.6%
div-inv7.6%
add-sqr-sqrt7.7%
sub-neg7.7%
add-sqr-sqrt2.8%
hypot-def2.8%
Applied egg-rr2.8%
associate-*r/2.8%
*-rgt-identity2.8%
associate--r-50.0%
+-inverses50.0%
+-lft-identity50.0%
Simplified50.0%
Taylor expanded in x around inf 0.0%
fma-def0.0%
*-commutative0.0%
metadata-eval0.0%
pow-sqr0.0%
unpow20.0%
rem-square-sqrt0.0%
unpow20.0%
rem-square-sqrt0.0%
metadata-eval0.0%
*-lft-identity0.0%
unpow20.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt95.8%
associate-*r*95.8%
metadata-eval95.8%
associate-*r/95.8%
*-commutative95.8%
Simplified95.8%
Taylor expanded in x around inf 99.1%
Final simplification99.2%
(FPCore (x eps) :precision binary64 (let* ((t_0 (- x (sqrt (- (* x x) eps))))) (if (<= t_0 -2e-154) 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 <= -2e-154) {
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 <= (-2d-154)) 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 <= -2e-154) {
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 <= -2e-154: 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 <= -2e-154) 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 <= -2e-154) 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, -2e-154], 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 -2 \cdot 10^{-154}:\\
\;\;\;\;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.9999999999999999e-154Initial program 99.3%
if -1.9999999999999999e-154 < (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) Initial program 7.6%
flip--7.6%
div-inv7.6%
add-sqr-sqrt7.7%
sub-neg7.7%
add-sqr-sqrt2.8%
hypot-def2.8%
Applied egg-rr2.8%
associate-*r/2.8%
*-rgt-identity2.8%
associate--r-50.0%
+-inverses50.0%
+-lft-identity50.0%
Simplified50.0%
Taylor expanded in x around inf 0.0%
fma-def0.0%
*-commutative0.0%
metadata-eval0.0%
pow-sqr0.0%
unpow20.0%
rem-square-sqrt0.0%
unpow20.0%
rem-square-sqrt0.0%
metadata-eval0.0%
*-lft-identity0.0%
unpow20.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt95.8%
associate-*r*95.8%
metadata-eval95.8%
associate-*r/95.8%
*-commutative95.8%
Simplified95.8%
Taylor expanded in x around inf 99.1%
Final simplification99.2%
(FPCore (x eps) :precision binary64 (if (or (<= x 1e-106) (and (not (<= x 6e-103)) (<= x 5.4e-89))) (- x (sqrt (- eps))) (/ eps (+ (* (/ eps x) -0.5) (* x 2.0)))))
double code(double x, double eps) {
double tmp;
if ((x <= 1e-106) || (!(x <= 6e-103) && (x <= 5.4e-89))) {
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 <= 1d-106) .or. (.not. (x <= 6d-103)) .and. (x <= 5.4d-89)) 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 <= 1e-106) || (!(x <= 6e-103) && (x <= 5.4e-89))) {
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 <= 1e-106) or (not (x <= 6e-103) and (x <= 5.4e-89)): 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 <= 1e-106) || (!(x <= 6e-103) && (x <= 5.4e-89))) 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 <= 1e-106) || (~((x <= 6e-103)) && (x <= 5.4e-89))) tmp = x - sqrt(-eps); else tmp = eps / (((eps / x) * -0.5) + (x * 2.0)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[x, 1e-106], And[N[Not[LessEqual[x, 6e-103]], $MachinePrecision], LessEqual[x, 5.4e-89]]], 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 10^{-106} \lor \neg \left(x \leq 6 \cdot 10^{-103}\right) \land x \leq 5.4 \cdot 10^{-89}:\\
\;\;\;\;x - \sqrt{-\varepsilon}\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon}{\frac{\varepsilon}{x} \cdot -0.5 + x \cdot 2}\\
\end{array}
\end{array}
if x < 9.99999999999999941e-107 or 6e-103 < x < 5.39999999999999975e-89Initial program 95.8%
Taylor expanded in x around 0 92.7%
neg-mul-192.7%
Simplified92.7%
if 9.99999999999999941e-107 < x < 6e-103 or 5.39999999999999975e-89 < x Initial program 21.0%
flip--20.9%
div-inv20.9%
add-sqr-sqrt20.9%
sub-neg20.9%
add-sqr-sqrt17.2%
hypot-def17.2%
Applied egg-rr17.2%
associate-*r/17.2%
*-rgt-identity17.2%
associate--r-57.5%
+-inverses57.5%
+-lft-identity57.5%
Simplified57.5%
Taylor expanded in x around inf 0.0%
fma-def0.0%
*-commutative0.0%
metadata-eval0.0%
pow-sqr0.0%
unpow20.0%
rem-square-sqrt0.0%
unpow20.0%
rem-square-sqrt0.0%
metadata-eval0.0%
*-lft-identity0.0%
unpow20.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt85.9%
associate-*r*85.9%
metadata-eval85.9%
associate-*r/85.9%
*-commutative85.9%
Simplified85.9%
Taylor expanded in x around inf 86.5%
Final simplification89.8%
(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 61.3%
flip--61.2%
div-inv61.1%
add-sqr-sqrt61.0%
sub-neg61.0%
add-sqr-sqrt58.9%
hypot-def59.0%
Applied egg-rr59.0%
associate-*r/58.9%
*-rgt-identity58.9%
associate--r-78.9%
+-inverses78.9%
+-lft-identity78.9%
Simplified78.9%
Taylor expanded in x around inf 0.0%
fma-def0.0%
*-commutative0.0%
metadata-eval0.0%
pow-sqr0.0%
unpow20.0%
rem-square-sqrt0.0%
unpow20.0%
rem-square-sqrt0.0%
metadata-eval0.0%
*-lft-identity0.0%
unpow20.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt41.9%
associate-*r*41.9%
metadata-eval41.9%
associate-*r/41.9%
*-commutative41.9%
Simplified41.9%
Taylor expanded in x around inf 45.8%
Final simplification45.8%
(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 61.3%
Taylor expanded in x around inf 45.1%
Final simplification45.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 61.3%
flip--61.2%
div-inv61.1%
add-sqr-sqrt61.0%
sub-neg61.0%
add-sqr-sqrt58.9%
hypot-def59.0%
Applied egg-rr59.0%
associate-*r/58.9%
*-rgt-identity58.9%
associate--r-78.9%
+-inverses78.9%
+-lft-identity78.9%
Simplified78.9%
Taylor expanded in x around inf 0.0%
fma-def0.0%
*-commutative0.0%
metadata-eval0.0%
pow-sqr0.0%
unpow20.0%
rem-square-sqrt0.0%
unpow20.0%
rem-square-sqrt0.0%
metadata-eval0.0%
*-lft-identity0.0%
unpow20.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt41.9%
associate-*r*41.9%
metadata-eval41.9%
associate-*r/41.9%
*-commutative41.9%
Simplified41.9%
Taylor expanded in x around inf 45.8%
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 61.3%
sub-neg61.3%
+-commutative61.3%
add-sqr-sqrt60.6%
distribute-rgt-neg-in60.6%
fma-def60.5%
pow1/260.5%
sqrt-pow160.6%
metadata-eval60.6%
pow1/260.6%
sqrt-pow160.4%
metadata-eval60.4%
Applied egg-rr60.4%
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 2023290
(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))))