
(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 8 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 (/ eps (+ x (sqrt (- (pow x 2.0) eps)))))
double code(double x, double eps) {
return eps / (x + sqrt((pow(x, 2.0) - eps)));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = eps / (x + sqrt(((x ** 2.0d0) - eps)))
end function
public static double code(double x, double eps) {
return eps / (x + Math.sqrt((Math.pow(x, 2.0) - eps)));
}
def code(x, eps): return eps / (x + math.sqrt((math.pow(x, 2.0) - eps)))
function code(x, eps) return Float64(eps / Float64(x + sqrt(Float64((x ^ 2.0) - eps)))) end
function tmp = code(x, eps) tmp = eps / (x + sqrt(((x ^ 2.0) - eps))); end
code[x_, eps_] := N[(eps / N[(x + N[Sqrt[N[(N[Power[x, 2.0], $MachinePrecision] - eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\varepsilon}{x + \sqrt{{x}^{2} - \varepsilon}}
\end{array}
Initial program 64.9%
add-sqr-sqrt64.4%
pow264.4%
pow1/264.4%
sqrt-pow164.4%
pow264.4%
metadata-eval64.4%
Applied egg-rr64.4%
flip--64.4%
div-inv64.3%
unpow264.3%
pow-pow64.6%
metadata-eval64.6%
pow-pow64.3%
metadata-eval64.3%
pow-prod-up64.3%
metadata-eval64.3%
pow164.3%
pow-pow64.4%
metadata-eval64.4%
pow1/264.4%
Applied egg-rr64.4%
associate-*r/64.5%
*-rgt-identity64.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x eps) :precision binary64 (if (<= (- x (sqrt (- (* x x) eps))) -1e-154) (- 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))) <= -1e-154) {
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))) <= -1e-154) {
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))) <= -1e-154: 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))) <= -1e-154) 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))) <= -1e-154) 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], -1e-154], 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 -1 \cdot 10^{-154}:\\
\;\;\;\;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))) < -9.9999999999999997e-155Initial program 99.5%
sub-neg99.5%
+-commutative99.5%
add-sqr-sqrt99.5%
hypot-define99.5%
Applied egg-rr99.5%
if -9.9999999999999997e-155 < (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) Initial program 10.9%
flip--10.9%
div-inv10.9%
add-sqr-sqrt11.0%
associate--r-99.6%
pow299.6%
pow299.6%
sub-neg99.6%
add-sqr-sqrt43.8%
hypot-define43.8%
Applied egg-rr43.8%
*-commutative43.8%
+-inverses43.8%
+-lft-identity43.8%
associate-*l/44.0%
*-lft-identity44.0%
Simplified44.0%
Taylor expanded in eps around 0 0.0%
+-commutative0.0%
*-commutative0.0%
fma-define0.0%
associate-*r/0.0%
*-commutative0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt98.4%
neg-mul-198.4%
associate-*r/98.4%
distribute-lft-neg-in98.4%
distribute-rgt-neg-in98.4%
distribute-neg-frac98.4%
metadata-eval98.4%
Simplified98.4%
Taylor expanded in eps around 0 98.4%
Final simplification99.1%
(FPCore (x eps) :precision binary64 (let* ((t_0 (- x (sqrt (- (* x x) eps))))) (if (<= t_0 -1e-154) 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 <= -1e-154) {
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 <= (-1d-154)) 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 <= -1e-154) {
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 <= -1e-154: 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 <= -1e-154) 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 <= -1e-154) 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, -1e-154], 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 -1 \cdot 10^{-154}:\\
\;\;\;\;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))) < -9.9999999999999997e-155Initial program 99.5%
if -9.9999999999999997e-155 < (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) Initial program 10.9%
flip--10.9%
div-inv10.9%
add-sqr-sqrt11.0%
associate--r-99.6%
pow299.6%
pow299.6%
sub-neg99.6%
add-sqr-sqrt43.8%
hypot-define43.8%
Applied egg-rr43.8%
*-commutative43.8%
+-inverses43.8%
+-lft-identity43.8%
associate-*l/44.0%
*-lft-identity44.0%
Simplified44.0%
Taylor expanded in eps around 0 0.0%
+-commutative0.0%
*-commutative0.0%
fma-define0.0%
associate-*r/0.0%
*-commutative0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt98.4%
neg-mul-198.4%
associate-*r/98.4%
distribute-lft-neg-in98.4%
distribute-rgt-neg-in98.4%
distribute-neg-frac98.4%
metadata-eval98.4%
Simplified98.4%
Taylor expanded in eps around 0 98.4%
Final simplification99.1%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sqrt (- eps))))
(if (<= x 9.2e-122)
(- x t_0)
(if (or (<= x 9.5e-99) (not (<= x 1.55e-87)))
(/ eps (+ (* -0.5 (/ eps x)) (* x 2.0)))
(/ eps (+ x t_0))))))
double code(double x, double eps) {
double t_0 = sqrt(-eps);
double tmp;
if (x <= 9.2e-122) {
tmp = x - t_0;
} else if ((x <= 9.5e-99) || !(x <= 1.55e-87)) {
tmp = eps / ((-0.5 * (eps / x)) + (x * 2.0));
} else {
tmp = eps / (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 = sqrt(-eps)
if (x <= 9.2d-122) then
tmp = x - t_0
else if ((x <= 9.5d-99) .or. (.not. (x <= 1.55d-87))) then
tmp = eps / (((-0.5d0) * (eps / x)) + (x * 2.0d0))
else
tmp = eps / (x + t_0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.sqrt(-eps);
double tmp;
if (x <= 9.2e-122) {
tmp = x - t_0;
} else if ((x <= 9.5e-99) || !(x <= 1.55e-87)) {
tmp = eps / ((-0.5 * (eps / x)) + (x * 2.0));
} else {
tmp = eps / (x + t_0);
}
return tmp;
}
def code(x, eps): t_0 = math.sqrt(-eps) tmp = 0 if x <= 9.2e-122: tmp = x - t_0 elif (x <= 9.5e-99) or not (x <= 1.55e-87): tmp = eps / ((-0.5 * (eps / x)) + (x * 2.0)) else: tmp = eps / (x + t_0) return tmp
function code(x, eps) t_0 = sqrt(Float64(-eps)) tmp = 0.0 if (x <= 9.2e-122) tmp = Float64(x - t_0); elseif ((x <= 9.5e-99) || !(x <= 1.55e-87)) tmp = Float64(eps / Float64(Float64(-0.5 * Float64(eps / x)) + Float64(x * 2.0))); else tmp = Float64(eps / Float64(x + t_0)); end return tmp end
function tmp_2 = code(x, eps) t_0 = sqrt(-eps); tmp = 0.0; if (x <= 9.2e-122) tmp = x - t_0; elseif ((x <= 9.5e-99) || ~((x <= 1.55e-87))) tmp = eps / ((-0.5 * (eps / x)) + (x * 2.0)); else tmp = eps / (x + t_0); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[Sqrt[(-eps)], $MachinePrecision]}, If[LessEqual[x, 9.2e-122], N[(x - t$95$0), $MachinePrecision], If[Or[LessEqual[x, 9.5e-99], N[Not[LessEqual[x, 1.55e-87]], $MachinePrecision]], N[(eps / N[(N[(-0.5 * N[(eps / x), $MachinePrecision]), $MachinePrecision] + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(eps / N[(x + t$95$0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{-\varepsilon}\\
\mathbf{if}\;x \leq 9.2 \cdot 10^{-122}:\\
\;\;\;\;x - t\_0\\
\mathbf{elif}\;x \leq 9.5 \cdot 10^{-99} \lor \neg \left(x \leq 1.55 \cdot 10^{-87}\right):\\
\;\;\;\;\frac{\varepsilon}{-0.5 \cdot \frac{\varepsilon}{x} + x \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon}{x + t\_0}\\
\end{array}
\end{array}
if x < 9.20000000000000028e-122Initial program 98.1%
Taylor expanded in x around 0 97.5%
neg-mul-197.5%
Simplified97.5%
if 9.20000000000000028e-122 < x < 9.5000000000000008e-99 or 1.54999999999999999e-87 < x Initial program 31.1%
flip--31.1%
div-inv31.0%
add-sqr-sqrt31.0%
associate--r-99.5%
pow299.5%
pow299.5%
sub-neg99.5%
add-sqr-sqrt56.6%
hypot-define56.6%
Applied egg-rr56.6%
*-commutative56.6%
+-inverses56.6%
+-lft-identity56.6%
associate-*l/56.8%
*-lft-identity56.8%
Simplified56.8%
Taylor expanded in eps around 0 0.0%
+-commutative0.0%
*-commutative0.0%
fma-define0.0%
associate-*r/0.0%
*-commutative0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt78.7%
neg-mul-178.7%
associate-*r/78.7%
distribute-lft-neg-in78.7%
distribute-rgt-neg-in78.7%
distribute-neg-frac78.7%
metadata-eval78.7%
Simplified78.7%
Taylor expanded in eps around 0 78.7%
if 9.5000000000000008e-99 < x < 1.54999999999999999e-87Initial program 73.9%
add-sqr-sqrt73.9%
pow273.9%
pow1/273.9%
sqrt-pow173.9%
pow273.9%
metadata-eval73.9%
Applied egg-rr73.9%
flip--73.9%
div-inv74.0%
unpow274.0%
pow-pow74.2%
metadata-eval74.2%
pow-pow73.8%
metadata-eval73.8%
pow-prod-up73.1%
metadata-eval73.1%
pow173.1%
pow-pow73.1%
metadata-eval73.1%
pow1/273.1%
Applied egg-rr73.1%
associate-*r/73.2%
*-rgt-identity73.2%
Simplified99.3%
Taylor expanded in x around 0 77.1%
neg-mul-177.1%
Simplified77.1%
Final simplification87.6%
(FPCore (x eps) :precision binary64 (if (or (<= x 9.2e-122) (and (not (<= x 2.15e-92)) (<= x 2.1e-87))) (- x (sqrt (- eps))) (/ eps (+ (* -0.5 (/ eps x)) (* x 2.0)))))
double code(double x, double eps) {
double tmp;
if ((x <= 9.2e-122) || (!(x <= 2.15e-92) && (x <= 2.1e-87))) {
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 <= 9.2d-122) .or. (.not. (x <= 2.15d-92)) .and. (x <= 2.1d-87)) 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 <= 9.2e-122) || (!(x <= 2.15e-92) && (x <= 2.1e-87))) {
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 <= 9.2e-122) or (not (x <= 2.15e-92) and (x <= 2.1e-87)): 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 <= 9.2e-122) || (!(x <= 2.15e-92) && (x <= 2.1e-87))) 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 <= 9.2e-122) || (~((x <= 2.15e-92)) && (x <= 2.1e-87))) tmp = x - sqrt(-eps); else tmp = eps / ((-0.5 * (eps / x)) + (x * 2.0)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[x, 9.2e-122], And[N[Not[LessEqual[x, 2.15e-92]], $MachinePrecision], LessEqual[x, 2.1e-87]]], 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 9.2 \cdot 10^{-122} \lor \neg \left(x \leq 2.15 \cdot 10^{-92}\right) \land x \leq 2.1 \cdot 10^{-87}:\\
\;\;\;\;x - \sqrt{-\varepsilon}\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon}{-0.5 \cdot \frac{\varepsilon}{x} + x \cdot 2}\\
\end{array}
\end{array}
if x < 9.20000000000000028e-122 or 2.15000000000000007e-92 < x < 2.10000000000000007e-87Initial program 97.5%
Taylor expanded in x around 0 96.9%
neg-mul-196.9%
Simplified96.9%
if 9.20000000000000028e-122 < x < 2.15000000000000007e-92 or 2.10000000000000007e-87 < x Initial program 31.8%
flip--31.7%
div-inv31.6%
add-sqr-sqrt31.6%
associate--r-99.5%
pow299.5%
pow299.5%
sub-neg99.5%
add-sqr-sqrt57.9%
hypot-define57.9%
Applied egg-rr57.9%
*-commutative57.9%
+-inverses57.9%
+-lft-identity57.9%
associate-*l/58.1%
*-lft-identity58.1%
Simplified58.1%
Taylor expanded in eps around 0 0.0%
+-commutative0.0%
*-commutative0.0%
fma-define0.0%
associate-*r/0.0%
*-commutative0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt77.9%
neg-mul-177.9%
associate-*r/77.9%
distribute-lft-neg-in77.9%
distribute-rgt-neg-in77.9%
distribute-neg-frac77.9%
metadata-eval77.9%
Simplified77.9%
Taylor expanded in eps around 0 77.9%
Final simplification87.5%
(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 64.9%
flip--64.8%
div-inv64.6%
add-sqr-sqrt64.4%
associate--r-99.3%
pow299.3%
pow299.3%
sub-neg99.3%
add-sqr-sqrt77.5%
hypot-define77.5%
Applied egg-rr77.5%
*-commutative77.5%
+-inverses77.5%
+-lft-identity77.5%
associate-*l/77.7%
*-lft-identity77.7%
Simplified77.7%
Taylor expanded in eps around 0 0.0%
+-commutative0.0%
*-commutative0.0%
fma-define0.0%
associate-*r/0.0%
*-commutative0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt42.9%
neg-mul-142.9%
associate-*r/42.9%
distribute-lft-neg-in42.9%
distribute-rgt-neg-in42.9%
distribute-neg-frac42.9%
metadata-eval42.9%
Simplified42.9%
Taylor expanded in eps around 0 42.9%
Final simplification42.9%
(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 64.9%
Taylor expanded in x around inf 41.7%
Final simplification41.7%
(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 64.9%
flip--64.8%
div-inv64.6%
add-sqr-sqrt64.4%
associate--r-99.3%
pow299.3%
pow299.3%
sub-neg99.3%
add-sqr-sqrt77.5%
hypot-define77.5%
Applied egg-rr77.5%
*-commutative77.5%
+-inverses77.5%
+-lft-identity77.5%
associate-*l/77.7%
*-lft-identity77.7%
Simplified77.7%
Taylor expanded in eps around 0 0.0%
+-commutative0.0%
*-commutative0.0%
fma-define0.0%
associate-*r/0.0%
*-commutative0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt42.9%
neg-mul-142.9%
associate-*r/42.9%
distribute-lft-neg-in42.9%
distribute-rgt-neg-in42.9%
distribute-neg-frac42.9%
metadata-eval42.9%
Simplified42.9%
Taylor expanded in eps around inf 5.3%
*-commutative5.3%
Simplified5.3%
Final simplification5.3%
(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 2024079
(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
(/ eps (+ x (sqrt (- (* x x) eps))))
(- x (sqrt (- (* x x) eps))))