
(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))) -5e-148) (* eps (/ 1.0 (+ x (hypot x (sqrt (- eps)))))) (/ eps (+ (* -0.5 (/ eps x)) (* x 2.0)))))
double code(double x, double eps) {
double tmp;
if ((x - sqrt(((x * x) - eps))) <= -5e-148) {
tmp = eps * (1.0 / (x + hypot(x, sqrt(-eps))));
} else {
tmp = eps / ((-0.5 * (eps / x)) + (x * 2.0));
}
return tmp;
}
public static double code(double x, double eps) {
double tmp;
if ((x - Math.sqrt(((x * x) - eps))) <= -5e-148) {
tmp = eps * (1.0 / (x + Math.hypot(x, Math.sqrt(-eps))));
} else {
tmp = eps / ((-0.5 * (eps / x)) + (x * 2.0));
}
return tmp;
}
def code(x, eps): tmp = 0 if (x - math.sqrt(((x * x) - eps))) <= -5e-148: tmp = eps * (1.0 / (x + math.hypot(x, math.sqrt(-eps)))) else: tmp = eps / ((-0.5 * (eps / x)) + (x * 2.0)) return tmp
function code(x, eps) tmp = 0.0 if (Float64(x - sqrt(Float64(Float64(x * x) - eps))) <= -5e-148) tmp = Float64(eps * Float64(1.0 / Float64(x + hypot(x, sqrt(Float64(-eps)))))); else tmp = Float64(eps / Float64(Float64(-0.5 * Float64(eps / x)) + Float64(x * 2.0))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((x - sqrt(((x * x) - eps))) <= -5e-148) tmp = eps * (1.0 / (x + hypot(x, sqrt(-eps)))); else tmp = eps / ((-0.5 * (eps / x)) + (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], -5e-148], N[(eps * N[(1.0 / N[(x + N[Sqrt[x ^ 2 + N[Sqrt[(-eps)], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(eps / N[(N[(-0.5 * N[(eps / x), $MachinePrecision]), $MachinePrecision] + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x - \sqrt{x \cdot x - \varepsilon} \leq -5 \cdot 10^{-148}:\\
\;\;\;\;\varepsilon \cdot \frac{1}{x + \mathsf{hypot}\left(x, \sqrt{-\varepsilon}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon}{-0.5 \cdot \frac{\varepsilon}{x} + x \cdot 2}\\
\end{array}
\end{array}
if (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) < -4.9999999999999999e-148Initial program 99.0%
flip--98.9%
div-inv98.5%
add-sqr-sqrt98.3%
associate--r-99.1%
pow299.1%
pow299.1%
sub-neg99.1%
add-sqr-sqrt99.1%
hypot-define99.1%
Applied egg-rr99.1%
+-inverses99.1%
+-commutative99.1%
Simplified99.1%
Taylor expanded in eps around 0 99.1%
if -4.9999999999999999e-148 < (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) Initial program 6.8%
flip--6.6%
div-inv6.6%
add-sqr-sqrt6.7%
associate--r-99.6%
pow299.6%
pow299.6%
sub-neg99.6%
add-sqr-sqrt43.0%
hypot-define43.0%
Applied egg-rr43.0%
*-commutative43.0%
+-inverses43.0%
+-lft-identity43.0%
associate-*l/43.1%
*-lft-identity43.1%
Simplified43.1%
Taylor expanded in eps around 0 0.0%
+-commutative0.0%
*-commutative0.0%
fma-define0.0%
*-commutative0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt100.0%
mul-1-neg100.0%
distribute-neg-frac100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-in100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in eps around 0 100.0%
Final simplification99.5%
(FPCore (x eps) :precision binary64 (if (<= (- x (sqrt (- (* x x) eps))) -5e-148) (/ eps (+ x (hypot x (sqrt (- eps))))) (/ eps (+ (* -0.5 (/ eps x)) (* x 2.0)))))
double code(double x, double eps) {
double tmp;
if ((x - sqrt(((x * x) - eps))) <= -5e-148) {
tmp = eps / (x + hypot(x, sqrt(-eps)));
} else {
tmp = eps / ((-0.5 * (eps / x)) + (x * 2.0));
}
return tmp;
}
public static double code(double x, double eps) {
double tmp;
if ((x - Math.sqrt(((x * x) - eps))) <= -5e-148) {
tmp = eps / (x + Math.hypot(x, Math.sqrt(-eps)));
} else {
tmp = eps / ((-0.5 * (eps / x)) + (x * 2.0));
}
return tmp;
}
def code(x, eps): tmp = 0 if (x - math.sqrt(((x * x) - eps))) <= -5e-148: tmp = eps / (x + math.hypot(x, math.sqrt(-eps))) else: tmp = eps / ((-0.5 * (eps / x)) + (x * 2.0)) return tmp
function code(x, eps) tmp = 0.0 if (Float64(x - sqrt(Float64(Float64(x * x) - eps))) <= -5e-148) tmp = Float64(eps / Float64(x + hypot(x, sqrt(Float64(-eps))))); else tmp = Float64(eps / Float64(Float64(-0.5 * Float64(eps / x)) + Float64(x * 2.0))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((x - sqrt(((x * x) - eps))) <= -5e-148) tmp = eps / (x + hypot(x, sqrt(-eps))); else tmp = eps / ((-0.5 * (eps / x)) + (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], -5e-148], N[(eps / N[(x + N[Sqrt[x ^ 2 + N[Sqrt[(-eps)], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(eps / N[(N[(-0.5 * N[(eps / x), $MachinePrecision]), $MachinePrecision] + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x - \sqrt{x \cdot x - \varepsilon} \leq -5 \cdot 10^{-148}:\\
\;\;\;\;\frac{\varepsilon}{x + \mathsf{hypot}\left(x, \sqrt{-\varepsilon}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon}{-0.5 \cdot \frac{\varepsilon}{x} + x \cdot 2}\\
\end{array}
\end{array}
if (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) < -4.9999999999999999e-148Initial program 99.0%
flip--98.9%
div-inv98.5%
add-sqr-sqrt98.3%
associate--r-99.1%
pow299.1%
pow299.1%
sub-neg99.1%
add-sqr-sqrt99.1%
hypot-define99.1%
Applied egg-rr99.1%
*-commutative99.1%
+-inverses99.1%
+-lft-identity99.1%
associate-*l/99.1%
*-lft-identity99.1%
Simplified99.1%
if -4.9999999999999999e-148 < (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) Initial program 6.8%
flip--6.6%
div-inv6.6%
add-sqr-sqrt6.7%
associate--r-99.6%
pow299.6%
pow299.6%
sub-neg99.6%
add-sqr-sqrt43.0%
hypot-define43.0%
Applied egg-rr43.0%
*-commutative43.0%
+-inverses43.0%
+-lft-identity43.0%
associate-*l/43.1%
*-lft-identity43.1%
Simplified43.1%
Taylor expanded in eps around 0 0.0%
+-commutative0.0%
*-commutative0.0%
fma-define0.0%
*-commutative0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt100.0%
mul-1-neg100.0%
distribute-neg-frac100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-in100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in eps around 0 100.0%
Final simplification99.5%
(FPCore (x eps) :precision binary64 (if (<= (- x (sqrt (- (* x x) eps))) -5e-148) (- x (hypot (sqrt (- eps)) x)) (/ eps (+ (* -0.5 (/ eps x)) (* x 2.0)))))
double code(double x, double eps) {
double tmp;
if ((x - sqrt(((x * x) - eps))) <= -5e-148) {
tmp = x - hypot(sqrt(-eps), x);
} else {
tmp = eps / ((-0.5 * (eps / x)) + (x * 2.0));
}
return tmp;
}
public static double code(double x, double eps) {
double tmp;
if ((x - Math.sqrt(((x * x) - eps))) <= -5e-148) {
tmp = x - Math.hypot(Math.sqrt(-eps), x);
} else {
tmp = eps / ((-0.5 * (eps / x)) + (x * 2.0));
}
return tmp;
}
def code(x, eps): tmp = 0 if (x - math.sqrt(((x * x) - eps))) <= -5e-148: tmp = x - math.hypot(math.sqrt(-eps), x) else: tmp = eps / ((-0.5 * (eps / x)) + (x * 2.0)) return tmp
function code(x, eps) tmp = 0.0 if (Float64(x - sqrt(Float64(Float64(x * x) - eps))) <= -5e-148) tmp = Float64(x - hypot(sqrt(Float64(-eps)), x)); else tmp = Float64(eps / Float64(Float64(-0.5 * Float64(eps / x)) + Float64(x * 2.0))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((x - sqrt(((x * x) - eps))) <= -5e-148) tmp = x - hypot(sqrt(-eps), x); else tmp = eps / ((-0.5 * (eps / x)) + (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], -5e-148], N[(x - N[Sqrt[N[Sqrt[(-eps)], $MachinePrecision] ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision], N[(eps / N[(N[(-0.5 * N[(eps / x), $MachinePrecision]), $MachinePrecision] + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x - \sqrt{x \cdot x - \varepsilon} \leq -5 \cdot 10^{-148}:\\
\;\;\;\;x - \mathsf{hypot}\left(\sqrt{-\varepsilon}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon}{-0.5 \cdot \frac{\varepsilon}{x} + x \cdot 2}\\
\end{array}
\end{array}
if (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) < -4.9999999999999999e-148Initial program 99.0%
sub-neg99.0%
+-commutative99.0%
add-sqr-sqrt99.1%
hypot-define99.1%
Applied egg-rr99.1%
if -4.9999999999999999e-148 < (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) Initial program 6.8%
flip--6.6%
div-inv6.6%
add-sqr-sqrt6.7%
associate--r-99.6%
pow299.6%
pow299.6%
sub-neg99.6%
add-sqr-sqrt43.0%
hypot-define43.0%
Applied egg-rr43.0%
*-commutative43.0%
+-inverses43.0%
+-lft-identity43.0%
associate-*l/43.1%
*-lft-identity43.1%
Simplified43.1%
Taylor expanded in eps around 0 0.0%
+-commutative0.0%
*-commutative0.0%
fma-define0.0%
*-commutative0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt100.0%
mul-1-neg100.0%
distribute-neg-frac100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-in100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in eps around 0 100.0%
Final simplification99.4%
(FPCore (x eps) :precision binary64 (let* ((t_0 (- x (sqrt (- (* x x) eps))))) (if (<= t_0 -5e-148) t_0 (/ eps (+ (* -0.5 (/ eps x)) (* x 2.0))))))
double code(double x, double eps) {
double t_0 = x - sqrt(((x * x) - eps));
double tmp;
if (t_0 <= -5e-148) {
tmp = t_0;
} else {
tmp = eps / ((-0.5 * (eps / x)) + (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 <= (-5d-148)) then
tmp = t_0
else
tmp = eps / (((-0.5d0) * (eps / x)) + (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 <= -5e-148) {
tmp = t_0;
} else {
tmp = eps / ((-0.5 * (eps / x)) + (x * 2.0));
}
return tmp;
}
def code(x, eps): t_0 = x - math.sqrt(((x * x) - eps)) tmp = 0 if t_0 <= -5e-148: tmp = t_0 else: tmp = eps / ((-0.5 * (eps / x)) + (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 <= -5e-148) tmp = t_0; else tmp = Float64(eps / Float64(Float64(-0.5 * Float64(eps / x)) + 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 <= -5e-148) tmp = t_0; else tmp = eps / ((-0.5 * (eps / x)) + (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, -5e-148], t$95$0, N[(eps / N[(N[(-0.5 * N[(eps / x), $MachinePrecision]), $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 -5 \cdot 10^{-148}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon}{-0.5 \cdot \frac{\varepsilon}{x} + x \cdot 2}\\
\end{array}
\end{array}
if (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) < -4.9999999999999999e-148Initial program 99.0%
if -4.9999999999999999e-148 < (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) Initial program 6.8%
flip--6.6%
div-inv6.6%
add-sqr-sqrt6.7%
associate--r-99.6%
pow299.6%
pow299.6%
sub-neg99.6%
add-sqr-sqrt43.0%
hypot-define43.0%
Applied egg-rr43.0%
*-commutative43.0%
+-inverses43.0%
+-lft-identity43.0%
associate-*l/43.1%
*-lft-identity43.1%
Simplified43.1%
Taylor expanded in eps around 0 0.0%
+-commutative0.0%
*-commutative0.0%
fma-define0.0%
*-commutative0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt100.0%
mul-1-neg100.0%
distribute-neg-frac100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-in100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in eps around 0 100.0%
Final simplification99.4%
(FPCore (x eps) :precision binary64 (if (<= x 1.4e-74) (- x (sqrt (- eps))) (/ eps (+ (* -0.5 (/ eps x)) (* x 2.0)))))
double code(double x, double eps) {
double tmp;
if (x <= 1.4e-74) {
tmp = x - sqrt(-eps);
} else {
tmp = eps / ((-0.5 * (eps / x)) + (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 <= 1.4d-74) then
tmp = x - sqrt(-eps)
else
tmp = eps / (((-0.5d0) * (eps / x)) + (x * 2.0d0))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (x <= 1.4e-74) {
tmp = x - Math.sqrt(-eps);
} else {
tmp = eps / ((-0.5 * (eps / x)) + (x * 2.0));
}
return tmp;
}
def code(x, eps): tmp = 0 if x <= 1.4e-74: tmp = x - math.sqrt(-eps) else: tmp = eps / ((-0.5 * (eps / x)) + (x * 2.0)) return tmp
function code(x, eps) tmp = 0.0 if (x <= 1.4e-74) tmp = Float64(x - sqrt(Float64(-eps))); else tmp = Float64(eps / Float64(Float64(-0.5 * Float64(eps / x)) + Float64(x * 2.0))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (x <= 1.4e-74) tmp = x - sqrt(-eps); else tmp = eps / ((-0.5 * (eps / x)) + (x * 2.0)); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[x, 1.4e-74], N[(x - N[Sqrt[(-eps)], $MachinePrecision]), $MachinePrecision], N[(eps / N[(N[(-0.5 * N[(eps / x), $MachinePrecision]), $MachinePrecision] + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.4 \cdot 10^{-74}:\\
\;\;\;\;x - \sqrt{-\varepsilon}\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon}{-0.5 \cdot \frac{\varepsilon}{x} + x \cdot 2}\\
\end{array}
\end{array}
if x < 1.39999999999999994e-74Initial program 90.6%
Taylor expanded in x around 0 89.0%
neg-mul-189.0%
Simplified89.0%
if 1.39999999999999994e-74 < x Initial program 18.9%
flip--18.8%
div-inv18.8%
add-sqr-sqrt18.9%
associate--r-99.6%
pow299.6%
pow299.6%
sub-neg99.6%
add-sqr-sqrt53.2%
hypot-define53.2%
Applied egg-rr53.2%
*-commutative53.2%
+-inverses53.2%
+-lft-identity53.2%
associate-*l/53.3%
*-lft-identity53.3%
Simplified53.3%
Taylor expanded in eps around 0 0.0%
+-commutative0.0%
*-commutative0.0%
fma-define0.0%
*-commutative0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt89.1%
mul-1-neg89.1%
distribute-neg-frac89.1%
distribute-lft-neg-in89.1%
distribute-rgt-neg-in89.1%
metadata-eval89.1%
Simplified89.1%
Taylor expanded in eps around 0 89.1%
Final simplification89.1%
(FPCore (x eps) :precision binary64 (/ eps (+ (* -0.5 (/ eps x)) (* x 2.0))))
double code(double x, double eps) {
return eps / ((-0.5 * (eps / x)) + (x * 2.0));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = eps / (((-0.5d0) * (eps / x)) + (x * 2.0d0))
end function
public static double code(double x, double eps) {
return eps / ((-0.5 * (eps / x)) + (x * 2.0));
}
def code(x, eps): return eps / ((-0.5 * (eps / x)) + (x * 2.0))
function code(x, eps) return Float64(eps / Float64(Float64(-0.5 * Float64(eps / x)) + Float64(x * 2.0))) end
function tmp = code(x, eps) tmp = eps / ((-0.5 * (eps / x)) + (x * 2.0)); end
code[x_, eps_] := N[(eps / N[(N[(-0.5 * N[(eps / x), $MachinePrecision]), $MachinePrecision] + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\varepsilon}{-0.5 \cdot \frac{\varepsilon}{x} + x \cdot 2}
\end{array}
Initial program 62.3%
flip--62.1%
div-inv61.9%
add-sqr-sqrt61.8%
associate--r-99.3%
pow299.3%
pow299.3%
sub-neg99.3%
add-sqr-sqrt76.7%
hypot-define76.7%
Applied egg-rr76.7%
*-commutative76.7%
+-inverses76.7%
+-lft-identity76.7%
associate-*l/76.8%
*-lft-identity76.8%
Simplified76.8%
Taylor expanded in eps around 0 0.0%
+-commutative0.0%
*-commutative0.0%
fma-define0.0%
*-commutative0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt44.6%
mul-1-neg44.6%
distribute-neg-frac44.6%
distribute-lft-neg-in44.6%
distribute-rgt-neg-in44.6%
metadata-eval44.6%
Simplified44.6%
Taylor expanded in eps around 0 44.6%
Final simplification44.6%
(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 62.3%
Taylor expanded in x around inf 44.0%
Final simplification44.0%
(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 + -2
\end{array}
Initial program 62.3%
flip--62.1%
div-inv61.9%
add-sqr-sqrt61.8%
associate--r-99.3%
pow299.3%
pow299.3%
sub-neg99.3%
add-sqr-sqrt76.7%
hypot-define76.7%
Applied egg-rr76.7%
+-inverses76.7%
+-commutative76.7%
Simplified76.7%
Taylor expanded in eps around -inf 0.0%
Simplified5.8%
Final simplification5.8%
(FPCore (x eps) :precision binary64 -2.0)
double code(double x, double eps) {
return -2.0;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = -2.0d0
end function
public static double code(double x, double eps) {
return -2.0;
}
def code(x, eps): return -2.0
function code(x, eps) return -2.0 end
function tmp = code(x, eps) tmp = -2.0; end
code[x_, eps_] := -2.0
\begin{array}{l}
\\
-2
\end{array}
Initial program 62.3%
flip--62.1%
div-inv61.9%
add-sqr-sqrt61.8%
associate--r-99.3%
pow299.3%
pow299.3%
sub-neg99.3%
add-sqr-sqrt76.7%
hypot-define76.7%
Applied egg-rr76.7%
+-inverses76.7%
+-commutative76.7%
Simplified76.7%
Taylor expanded in eps around inf 0.0%
Simplified5.8%
(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 2024145
(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)))
:alt
(! :herbie-platform default (/ eps (+ x (sqrt (- (* x x) eps)))))
(- x (sqrt (- (* x x) eps))))