
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
double code(double x) {
return (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / sqrt(x)) - (1.0d0 / sqrt((x + 1.0d0)))
end function
public static double code(double x) {
return (1.0 / Math.sqrt(x)) - (1.0 / Math.sqrt((x + 1.0)));
}
def code(x): return (1.0 / math.sqrt(x)) - (1.0 / math.sqrt((x + 1.0)))
function code(x) return Float64(Float64(1.0 / sqrt(x)) - Float64(1.0 / sqrt(Float64(x + 1.0)))) end
function tmp = code(x) tmp = (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0))); end
code[x_] := N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] - N[(1.0 / N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
double code(double x) {
return (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / sqrt(x)) - (1.0d0 / sqrt((x + 1.0d0)))
end function
public static double code(double x) {
return (1.0 / Math.sqrt(x)) - (1.0 / Math.sqrt((x + 1.0)));
}
def code(x): return (1.0 / math.sqrt(x)) - (1.0 / math.sqrt((x + 1.0)))
function code(x) return Float64(Float64(1.0 / sqrt(x)) - Float64(1.0 / sqrt(Float64(x + 1.0)))) end
function tmp = code(x) tmp = (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0))); end
code[x_] := N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] - N[(1.0 / N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\end{array}
(FPCore (x) :precision binary64 (let* ((t_0 (+ (pow x -0.5) (pow (+ 1.0 x) -0.5)))) (if (<= x 2e+116) (/ (/ (/ 1.0 x) (+ 1.0 x)) t_0) (/ (/ (/ 1.0 t_0) x) x))))
double code(double x) {
double t_0 = pow(x, -0.5) + pow((1.0 + x), -0.5);
double tmp;
if (x <= 2e+116) {
tmp = ((1.0 / x) / (1.0 + x)) / t_0;
} else {
tmp = ((1.0 / t_0) / x) / x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = (x ** (-0.5d0)) + ((1.0d0 + x) ** (-0.5d0))
if (x <= 2d+116) then
tmp = ((1.0d0 / x) / (1.0d0 + x)) / t_0
else
tmp = ((1.0d0 / t_0) / x) / x
end if
code = tmp
end function
public static double code(double x) {
double t_0 = Math.pow(x, -0.5) + Math.pow((1.0 + x), -0.5);
double tmp;
if (x <= 2e+116) {
tmp = ((1.0 / x) / (1.0 + x)) / t_0;
} else {
tmp = ((1.0 / t_0) / x) / x;
}
return tmp;
}
def code(x): t_0 = math.pow(x, -0.5) + math.pow((1.0 + x), -0.5) tmp = 0 if x <= 2e+116: tmp = ((1.0 / x) / (1.0 + x)) / t_0 else: tmp = ((1.0 / t_0) / x) / x return tmp
function code(x) t_0 = Float64((x ^ -0.5) + (Float64(1.0 + x) ^ -0.5)) tmp = 0.0 if (x <= 2e+116) tmp = Float64(Float64(Float64(1.0 / x) / Float64(1.0 + x)) / t_0); else tmp = Float64(Float64(Float64(1.0 / t_0) / x) / x); end return tmp end
function tmp_2 = code(x) t_0 = (x ^ -0.5) + ((1.0 + x) ^ -0.5); tmp = 0.0; if (x <= 2e+116) tmp = ((1.0 / x) / (1.0 + x)) / t_0; else tmp = ((1.0 / t_0) / x) / x; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(N[Power[x, -0.5], $MachinePrecision] + N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 2e+116], N[(N[(N[(1.0 / x), $MachinePrecision] / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision], N[(N[(N[(1.0 / t$95$0), $MachinePrecision] / x), $MachinePrecision] / x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{-0.5} + {\left(1 + x\right)}^{-0.5}\\
\mathbf{if}\;x \leq 2 \cdot 10^{+116}:\\
\;\;\;\;\frac{\frac{\frac{1}{x}}{1 + x}}{t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\frac{1}{t\_0}}{x}}{x}\\
\end{array}
\end{array}
if x < 2.00000000000000003e116Initial program 12.2%
flip--12.1%
div-inv12.1%
frac-times12.3%
metadata-eval12.3%
add-sqr-sqrt12.5%
frac-times12.6%
metadata-eval12.6%
add-sqr-sqrt12.5%
+-commutative12.5%
inv-pow12.5%
sqrt-pow212.5%
metadata-eval12.5%
pow1/212.5%
pow-flip12.5%
+-commutative12.5%
metadata-eval12.5%
Applied egg-rr12.5%
*-commutative12.5%
frac-sub16.8%
frac-times16.8%
*-un-lft-identity16.8%
*-un-lft-identity16.8%
*-rgt-identity16.8%
distribute-lft-in16.8%
*-rgt-identity16.8%
pow216.8%
Applied egg-rr16.8%
*-commutative16.8%
associate-/r*16.8%
associate--l+99.5%
+-inverses99.5%
metadata-eval99.5%
+-commutative99.5%
unpow299.5%
fma-define99.6%
Simplified99.6%
metadata-eval99.6%
fma-undefine99.5%
*-rgt-identity99.5%
distribute-lft-in99.6%
+-commutative99.6%
frac-times99.3%
inv-pow99.3%
metadata-eval99.3%
pow-prod-up99.3%
associate-*l*99.3%
Applied egg-rr99.3%
associate-*r*99.3%
pow-sqr99.3%
metadata-eval99.3%
unpow-199.3%
associate-*r/99.5%
*-rgt-identity99.5%
Simplified99.5%
if 2.00000000000000003e116 < x Initial program 53.2%
flip--53.2%
div-inv53.2%
frac-times30.0%
metadata-eval30.0%
add-sqr-sqrt24.7%
frac-times35.5%
metadata-eval35.5%
add-sqr-sqrt53.2%
+-commutative53.2%
inv-pow53.2%
sqrt-pow253.2%
metadata-eval53.2%
pow1/253.2%
pow-flip53.2%
+-commutative53.2%
metadata-eval53.2%
Applied egg-rr53.2%
Taylor expanded in x around inf 75.5%
associate-*l/75.6%
*-un-lft-identity75.6%
unpow275.6%
associate-/r*99.7%
Applied egg-rr99.7%
Final simplification99.6%
(FPCore (x) :precision binary64 (let* ((t_0 (/ 1.0 (hypot x (sqrt x))))) (* t_0 (* t_0 (/ 1.0 (+ (pow x -0.5) (pow (+ 1.0 x) -0.5)))))))
double code(double x) {
double t_0 = 1.0 / hypot(x, sqrt(x));
return t_0 * (t_0 * (1.0 / (pow(x, -0.5) + pow((1.0 + x), -0.5))));
}
public static double code(double x) {
double t_0 = 1.0 / Math.hypot(x, Math.sqrt(x));
return t_0 * (t_0 * (1.0 / (Math.pow(x, -0.5) + Math.pow((1.0 + x), -0.5))));
}
def code(x): t_0 = 1.0 / math.hypot(x, math.sqrt(x)) return t_0 * (t_0 * (1.0 / (math.pow(x, -0.5) + math.pow((1.0 + x), -0.5))))
function code(x) t_0 = Float64(1.0 / hypot(x, sqrt(x))) return Float64(t_0 * Float64(t_0 * Float64(1.0 / Float64((x ^ -0.5) + (Float64(1.0 + x) ^ -0.5))))) end
function tmp = code(x) t_0 = 1.0 / hypot(x, sqrt(x)); tmp = t_0 * (t_0 * (1.0 / ((x ^ -0.5) + ((1.0 + x) ^ -0.5)))); end
code[x_] := Block[{t$95$0 = N[(1.0 / N[Sqrt[x ^ 2 + N[Sqrt[x], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]}, N[(t$95$0 * N[(t$95$0 * N[(1.0 / N[(N[Power[x, -0.5], $MachinePrecision] + N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\mathsf{hypot}\left(x, \sqrt{x}\right)}\\
t\_0 \cdot \left(t\_0 \cdot \frac{1}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}\right)
\end{array}
\end{array}
Initial program 36.4%
flip--36.4%
div-inv36.4%
frac-times22.8%
metadata-eval22.8%
add-sqr-sqrt19.7%
frac-times26.1%
metadata-eval26.1%
add-sqr-sqrt36.5%
+-commutative36.5%
inv-pow36.5%
sqrt-pow236.5%
metadata-eval36.5%
pow1/236.5%
pow-flip36.5%
+-commutative36.5%
metadata-eval36.5%
Applied egg-rr36.5%
*-commutative36.5%
frac-sub38.3%
frac-times38.3%
*-un-lft-identity38.3%
*-un-lft-identity38.3%
*-rgt-identity38.3%
distribute-lft-in38.3%
*-rgt-identity38.3%
pow238.3%
Applied egg-rr38.3%
*-commutative38.3%
associate-/r*38.3%
associate--l+85.4%
+-inverses85.4%
metadata-eval85.4%
+-commutative85.4%
unpow285.4%
fma-define85.4%
Simplified85.4%
div-inv85.3%
add-sqr-sqrt85.2%
associate-*l*85.1%
sqrt-div85.2%
metadata-eval85.2%
fma-undefine85.2%
add-sqr-sqrt85.2%
hypot-define85.2%
sqrt-div85.1%
metadata-eval85.1%
fma-undefine85.1%
add-sqr-sqrt85.1%
hypot-define99.3%
Applied egg-rr99.3%
Final simplification99.3%
(FPCore (x) :precision binary64 (if (<= x 2e+113) (/ (/ (/ 1.0 x) (+ 1.0 x)) (+ (pow x -0.5) (pow (+ 1.0 x) -0.5))) (* (/ 1.0 (hypot x (sqrt x))) (* 0.5 (sqrt (/ 1.0 x))))))
double code(double x) {
double tmp;
if (x <= 2e+113) {
tmp = ((1.0 / x) / (1.0 + x)) / (pow(x, -0.5) + pow((1.0 + x), -0.5));
} else {
tmp = (1.0 / hypot(x, sqrt(x))) * (0.5 * sqrt((1.0 / x)));
}
return tmp;
}
public static double code(double x) {
double tmp;
if (x <= 2e+113) {
tmp = ((1.0 / x) / (1.0 + x)) / (Math.pow(x, -0.5) + Math.pow((1.0 + x), -0.5));
} else {
tmp = (1.0 / Math.hypot(x, Math.sqrt(x))) * (0.5 * Math.sqrt((1.0 / x)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 2e+113: tmp = ((1.0 / x) / (1.0 + x)) / (math.pow(x, -0.5) + math.pow((1.0 + x), -0.5)) else: tmp = (1.0 / math.hypot(x, math.sqrt(x))) * (0.5 * math.sqrt((1.0 / x))) return tmp
function code(x) tmp = 0.0 if (x <= 2e+113) tmp = Float64(Float64(Float64(1.0 / x) / Float64(1.0 + x)) / Float64((x ^ -0.5) + (Float64(1.0 + x) ^ -0.5))); else tmp = Float64(Float64(1.0 / hypot(x, sqrt(x))) * Float64(0.5 * sqrt(Float64(1.0 / x)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 2e+113) tmp = ((1.0 / x) / (1.0 + x)) / ((x ^ -0.5) + ((1.0 + x) ^ -0.5)); else tmp = (1.0 / hypot(x, sqrt(x))) * (0.5 * sqrt((1.0 / x))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 2e+113], N[(N[(N[(1.0 / x), $MachinePrecision] / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] / N[(N[Power[x, -0.5], $MachinePrecision] + N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[Sqrt[x ^ 2 + N[Sqrt[x], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[(0.5 * N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2 \cdot 10^{+113}:\\
\;\;\;\;\frac{\frac{\frac{1}{x}}{1 + x}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(x, \sqrt{x}\right)} \cdot \left(0.5 \cdot \sqrt{\frac{1}{x}}\right)\\
\end{array}
\end{array}
if x < 2e113Initial program 12.5%
flip--12.5%
div-inv12.5%
frac-times12.7%
metadata-eval12.7%
add-sqr-sqrt12.9%
frac-times13.1%
metadata-eval13.1%
add-sqr-sqrt12.9%
+-commutative12.9%
inv-pow12.9%
sqrt-pow212.9%
metadata-eval12.9%
pow1/212.9%
pow-flip12.9%
+-commutative12.9%
metadata-eval12.9%
Applied egg-rr12.9%
*-commutative12.9%
frac-sub17.4%
frac-times17.4%
*-un-lft-identity17.4%
*-un-lft-identity17.4%
*-rgt-identity17.4%
distribute-lft-in17.4%
*-rgt-identity17.4%
pow217.4%
Applied egg-rr17.4%
*-commutative17.4%
associate-/r*17.4%
associate--l+99.6%
+-inverses99.6%
metadata-eval99.6%
+-commutative99.6%
unpow299.6%
fma-define99.6%
Simplified99.6%
metadata-eval99.6%
fma-undefine99.6%
*-rgt-identity99.6%
distribute-lft-in99.6%
+-commutative99.6%
frac-times99.3%
inv-pow99.3%
metadata-eval99.3%
pow-prod-up99.3%
associate-*l*99.3%
Applied egg-rr99.3%
associate-*r*99.3%
pow-sqr99.3%
metadata-eval99.3%
unpow-199.3%
associate-*r/99.5%
*-rgt-identity99.5%
Simplified99.5%
if 2e113 < x Initial program 51.7%
flip--51.7%
div-inv51.7%
frac-times29.2%
metadata-eval29.2%
add-sqr-sqrt24.0%
frac-times34.5%
metadata-eval34.5%
add-sqr-sqrt51.7%
+-commutative51.7%
inv-pow51.7%
sqrt-pow251.7%
metadata-eval51.7%
pow1/251.7%
pow-flip51.7%
+-commutative51.7%
metadata-eval51.7%
Applied egg-rr51.7%
*-commutative51.7%
frac-sub51.7%
frac-times51.7%
*-un-lft-identity51.7%
*-un-lft-identity51.7%
*-rgt-identity51.7%
distribute-lft-in51.7%
*-rgt-identity51.7%
pow251.7%
Applied egg-rr51.7%
*-commutative51.7%
associate-/r*51.7%
associate--l+76.3%
+-inverses76.3%
metadata-eval76.3%
+-commutative76.3%
unpow276.3%
fma-define76.3%
Simplified76.3%
div-inv76.3%
add-sqr-sqrt76.2%
associate-*l*76.2%
sqrt-div76.2%
metadata-eval76.2%
fma-undefine76.2%
add-sqr-sqrt76.2%
hypot-define76.2%
sqrt-div76.2%
metadata-eval76.2%
fma-undefine76.2%
add-sqr-sqrt76.2%
hypot-define99.4%
Applied egg-rr99.4%
Taylor expanded in x around inf 99.7%
Final simplification99.6%
(FPCore (x) :precision binary64 (/ 1.0 (* x (fma (pow x -0.5) (+ 1.0 x) (pow (+ 1.0 x) 0.5)))))
double code(double x) {
return 1.0 / (x * fma(pow(x, -0.5), (1.0 + x), pow((1.0 + x), 0.5)));
}
function code(x) return Float64(1.0 / Float64(x * fma((x ^ -0.5), Float64(1.0 + x), (Float64(1.0 + x) ^ 0.5)))) end
code[x_] := N[(1.0 / N[(x * N[(N[Power[x, -0.5], $MachinePrecision] * N[(1.0 + x), $MachinePrecision] + N[Power[N[(1.0 + x), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x \cdot \mathsf{fma}\left({x}^{-0.5}, 1 + x, {\left(1 + x\right)}^{0.5}\right)}
\end{array}
Initial program 36.4%
flip--36.4%
div-inv36.4%
frac-times22.8%
metadata-eval22.8%
add-sqr-sqrt19.7%
frac-times26.1%
metadata-eval26.1%
add-sqr-sqrt36.5%
+-commutative36.5%
inv-pow36.5%
sqrt-pow236.5%
metadata-eval36.5%
pow1/236.5%
pow-flip36.5%
+-commutative36.5%
metadata-eval36.5%
Applied egg-rr36.5%
*-commutative36.5%
frac-sub38.3%
frac-times38.3%
*-un-lft-identity38.3%
*-un-lft-identity38.3%
*-rgt-identity38.3%
distribute-lft-in38.3%
*-rgt-identity38.3%
pow238.3%
Applied egg-rr38.3%
*-commutative38.3%
associate-/r*38.3%
associate--l+85.4%
+-inverses85.4%
metadata-eval85.4%
+-commutative85.4%
unpow285.4%
fma-define85.4%
Simplified85.4%
div-inv85.3%
add-sqr-sqrt85.2%
associate-*l*85.1%
sqrt-div85.2%
metadata-eval85.2%
fma-undefine85.2%
add-sqr-sqrt85.2%
hypot-define85.2%
sqrt-div85.1%
metadata-eval85.1%
fma-undefine85.1%
add-sqr-sqrt85.1%
hypot-define99.3%
Applied egg-rr99.3%
*-commutative99.3%
frac-times99.5%
metadata-eval99.5%
frac-times98.7%
metadata-eval98.7%
Applied egg-rr98.7%
*-commutative98.7%
associate-*r*85.3%
hypot-undefine85.3%
hypot-undefine85.3%
rem-square-sqrt85.3%
rem-square-sqrt85.3%
fma-undefine85.3%
fma-undefine85.3%
*-rgt-identity85.3%
distribute-lft-in85.3%
+-commutative85.3%
associate-*l*98.7%
distribute-rgt-in98.7%
fma-define98.7%
pow-plus98.7%
metadata-eval98.7%
Simplified98.7%
Final simplification98.7%
(FPCore (x) :precision binary64 (/ (/ (/ 1.0 (+ (pow x -0.5) (pow (+ 1.0 x) -0.5))) x) x))
double code(double x) {
return ((1.0 / (pow(x, -0.5) + pow((1.0 + x), -0.5))) / x) / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((1.0d0 / ((x ** (-0.5d0)) + ((1.0d0 + x) ** (-0.5d0)))) / x) / x
end function
public static double code(double x) {
return ((1.0 / (Math.pow(x, -0.5) + Math.pow((1.0 + x), -0.5))) / x) / x;
}
def code(x): return ((1.0 / (math.pow(x, -0.5) + math.pow((1.0 + x), -0.5))) / x) / x
function code(x) return Float64(Float64(Float64(1.0 / Float64((x ^ -0.5) + (Float64(1.0 + x) ^ -0.5))) / x) / x) end
function tmp = code(x) tmp = ((1.0 / ((x ^ -0.5) + ((1.0 + x) ^ -0.5))) / x) / x; end
code[x_] := N[(N[(N[(1.0 / N[(N[Power[x, -0.5], $MachinePrecision] + N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\frac{1}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}}{x}}{x}
\end{array}
Initial program 36.4%
flip--36.4%
div-inv36.4%
frac-times22.8%
metadata-eval22.8%
add-sqr-sqrt19.7%
frac-times26.1%
metadata-eval26.1%
add-sqr-sqrt36.5%
+-commutative36.5%
inv-pow36.5%
sqrt-pow236.5%
metadata-eval36.5%
pow1/236.5%
pow-flip36.5%
+-commutative36.5%
metadata-eval36.5%
Applied egg-rr36.5%
Taylor expanded in x around inf 82.9%
associate-*l/82.9%
*-un-lft-identity82.9%
unpow282.9%
associate-/r*97.1%
Applied egg-rr97.1%
Final simplification97.1%
(FPCore (x) :precision binary64 (/ (/ (/ 1.0 x) (+ 1.0 x)) (* (sqrt (/ 1.0 x)) 2.0)))
double code(double x) {
return ((1.0 / x) / (1.0 + x)) / (sqrt((1.0 / x)) * 2.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((1.0d0 / x) / (1.0d0 + x)) / (sqrt((1.0d0 / x)) * 2.0d0)
end function
public static double code(double x) {
return ((1.0 / x) / (1.0 + x)) / (Math.sqrt((1.0 / x)) * 2.0);
}
def code(x): return ((1.0 / x) / (1.0 + x)) / (math.sqrt((1.0 / x)) * 2.0)
function code(x) return Float64(Float64(Float64(1.0 / x) / Float64(1.0 + x)) / Float64(sqrt(Float64(1.0 / x)) * 2.0)) end
function tmp = code(x) tmp = ((1.0 / x) / (1.0 + x)) / (sqrt((1.0 / x)) * 2.0); end
code[x_] := N[(N[(N[(1.0 / x), $MachinePrecision] / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\frac{1}{x}}{1 + x}}{\sqrt{\frac{1}{x}} \cdot 2}
\end{array}
Initial program 36.4%
flip--36.4%
div-inv36.4%
frac-times22.8%
metadata-eval22.8%
add-sqr-sqrt19.7%
frac-times26.1%
metadata-eval26.1%
add-sqr-sqrt36.5%
+-commutative36.5%
inv-pow36.5%
sqrt-pow236.5%
metadata-eval36.5%
pow1/236.5%
pow-flip36.5%
+-commutative36.5%
metadata-eval36.5%
Applied egg-rr36.5%
*-commutative36.5%
frac-sub38.3%
frac-times38.3%
*-un-lft-identity38.3%
*-un-lft-identity38.3%
*-rgt-identity38.3%
distribute-lft-in38.3%
*-rgt-identity38.3%
pow238.3%
Applied egg-rr38.3%
*-commutative38.3%
associate-/r*38.3%
associate--l+85.4%
+-inverses85.4%
metadata-eval85.4%
+-commutative85.4%
unpow285.4%
fma-define85.4%
Simplified85.4%
Taylor expanded in x around inf 83.1%
metadata-eval85.4%
fma-undefine85.4%
*-rgt-identity85.4%
distribute-lft-in85.4%
+-commutative85.4%
frac-times85.9%
inv-pow85.9%
metadata-eval85.9%
pow-prod-up85.9%
associate-*l*85.9%
Applied egg-rr83.6%
associate-*r*85.9%
pow-sqr85.9%
metadata-eval85.9%
unpow-185.9%
associate-*r/86.0%
*-rgt-identity86.0%
Simplified83.7%
Final simplification83.7%
(FPCore (x) :precision binary64 (if (<= x 4.6e+153) (/ 1.0 (+ x (pow x 0.5))) 0.0))
double code(double x) {
double tmp;
if (x <= 4.6e+153) {
tmp = 1.0 / (x + pow(x, 0.5));
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 4.6d+153) then
tmp = 1.0d0 / (x + (x ** 0.5d0))
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 4.6e+153) {
tmp = 1.0 / (x + Math.pow(x, 0.5));
} else {
tmp = 0.0;
}
return tmp;
}
def code(x): tmp = 0 if x <= 4.6e+153: tmp = 1.0 / (x + math.pow(x, 0.5)) else: tmp = 0.0 return tmp
function code(x) tmp = 0.0 if (x <= 4.6e+153) tmp = Float64(1.0 / Float64(x + (x ^ 0.5))); else tmp = 0.0; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 4.6e+153) tmp = 1.0 / (x + (x ^ 0.5)); else tmp = 0.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 4.6e+153], N[(1.0 / N[(x + N[Power[x, 0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4.6 \cdot 10^{+153}:\\
\;\;\;\;\frac{1}{x + {x}^{0.5}}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < 4.6000000000000003e153Initial program 10.5%
flip--10.5%
div-inv10.5%
frac-times10.4%
metadata-eval10.4%
add-sqr-sqrt10.5%
frac-times10.8%
metadata-eval10.8%
add-sqr-sqrt10.8%
+-commutative10.8%
inv-pow10.8%
sqrt-pow210.8%
metadata-eval10.8%
pow1/210.8%
pow-flip10.8%
+-commutative10.8%
metadata-eval10.8%
Applied egg-rr10.8%
Taylor expanded in x around 0 8.4%
distribute-rgt-in8.4%
*-lft-identity8.4%
pow-plus8.4%
metadata-eval8.4%
Simplified8.4%
if 4.6000000000000003e153 < x Initial program 67.6%
Taylor expanded in x around inf 67.6%
Final simplification35.2%
(FPCore (x) :precision binary64 (* (/ -1.0 (* x (- -1.0 x))) (* (sqrt x) 0.5)))
double code(double x) {
return (-1.0 / (x * (-1.0 - x))) * (sqrt(x) * 0.5);
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((-1.0d0) / (x * ((-1.0d0) - x))) * (sqrt(x) * 0.5d0)
end function
public static double code(double x) {
return (-1.0 / (x * (-1.0 - x))) * (Math.sqrt(x) * 0.5);
}
def code(x): return (-1.0 / (x * (-1.0 - x))) * (math.sqrt(x) * 0.5)
function code(x) return Float64(Float64(-1.0 / Float64(x * Float64(-1.0 - x))) * Float64(sqrt(x) * 0.5)) end
function tmp = code(x) tmp = (-1.0 / (x * (-1.0 - x))) * (sqrt(x) * 0.5); end
code[x_] := N[(N[(-1.0 / N[(x * N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[Sqrt[x], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1}{x \cdot \left(-1 - x\right)} \cdot \left(\sqrt{x} \cdot 0.5\right)
\end{array}
Initial program 36.4%
flip--36.4%
div-inv36.4%
frac-times22.8%
metadata-eval22.8%
add-sqr-sqrt19.7%
frac-times26.1%
metadata-eval26.1%
add-sqr-sqrt36.5%
+-commutative36.5%
inv-pow36.5%
sqrt-pow236.5%
metadata-eval36.5%
pow1/236.5%
pow-flip36.5%
+-commutative36.5%
metadata-eval36.5%
Applied egg-rr36.5%
Taylor expanded in x around inf 35.2%
frac-2neg35.2%
metadata-eval35.2%
frac-sub36.0%
*-un-lft-identity36.0%
Applied egg-rr36.0%
Taylor expanded in x around 0 83.1%
Final simplification83.1%
(FPCore (x) :precision binary64 0.0)
double code(double x) {
return 0.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.0d0
end function
public static double code(double x) {
return 0.0;
}
def code(x): return 0.0
function code(x) return 0.0 end
function tmp = code(x) tmp = 0.0; end
code[x_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 36.4%
Taylor expanded in x around inf 33.0%
Final simplification33.0%
(FPCore (x) :precision binary64 (/ 1.0 (+ (* (+ x 1.0) (sqrt x)) (* x (sqrt (+ x 1.0))))))
double code(double x) {
return 1.0 / (((x + 1.0) * sqrt(x)) + (x * sqrt((x + 1.0))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (((x + 1.0d0) * sqrt(x)) + (x * sqrt((x + 1.0d0))))
end function
public static double code(double x) {
return 1.0 / (((x + 1.0) * Math.sqrt(x)) + (x * Math.sqrt((x + 1.0))));
}
def code(x): return 1.0 / (((x + 1.0) * math.sqrt(x)) + (x * math.sqrt((x + 1.0))))
function code(x) return Float64(1.0 / Float64(Float64(Float64(x + 1.0) * sqrt(x)) + Float64(x * sqrt(Float64(x + 1.0))))) end
function tmp = code(x) tmp = 1.0 / (((x + 1.0) * sqrt(x)) + (x * sqrt((x + 1.0)))); end
code[x_] := N[(1.0 / N[(N[(N[(x + 1.0), $MachinePrecision] * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(x * N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\left(x + 1\right) \cdot \sqrt{x} + x \cdot \sqrt{x + 1}}
\end{array}
herbie shell --seed 2024052
(FPCore (x)
:name "2isqrt (example 3.6)"
:precision binary64
:pre (and (> x 1.0) (< x 1e+308))
:herbie-target
(/ 1.0 (+ (* (+ x 1.0) (sqrt x)) (* x (sqrt (+ x 1.0)))))
(- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))