
(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 10 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 (if (<= x 1e+17) (/ (/ 1.0 (fma x x x)) (+ (pow x -0.5) (pow (+ x 1.0) -0.5))) (* (pow x -1.5) 0.5)))
double code(double x) {
double tmp;
if (x <= 1e+17) {
tmp = (1.0 / fma(x, x, x)) / (pow(x, -0.5) + pow((x + 1.0), -0.5));
} else {
tmp = pow(x, -1.5) * 0.5;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 1e+17) tmp = Float64(Float64(1.0 / fma(x, x, x)) / Float64((x ^ -0.5) + (Float64(x + 1.0) ^ -0.5))); else tmp = Float64((x ^ -1.5) * 0.5); end return tmp end
code[x_] := If[LessEqual[x, 1e+17], N[(N[(1.0 / N[(x * x + x), $MachinePrecision]), $MachinePrecision] / N[(N[Power[x, -0.5], $MachinePrecision] + N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -1.5], $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 10^{+17}:\\
\;\;\;\;\frac{\frac{1}{\mathsf{fma}\left(x, x, x\right)}}{{x}^{-0.5} + {\left(x + 1\right)}^{-0.5}}\\
\mathbf{else}:\\
\;\;\;\;{x}^{-1.5} \cdot 0.5\\
\end{array}
\end{array}
if x < 1e17Initial program 62.1%
flip--62.7%
div-inv62.7%
frac-times63.4%
metadata-eval63.4%
add-sqr-sqrt63.1%
frac-times63.2%
metadata-eval63.2%
add-sqr-sqrt65.7%
+-commutative65.7%
inv-pow65.7%
sqrt-pow265.7%
metadata-eval65.7%
pow1/265.7%
pow-flip65.7%
+-commutative65.7%
metadata-eval65.7%
Applied egg-rr65.7%
associate-*r/65.7%
*-rgt-identity65.7%
Simplified65.7%
frac-sub94.8%
*-un-lft-identity94.8%
distribute-rgt-in94.6%
*-un-lft-identity94.6%
unpow294.6%
Applied egg-rr94.6%
*-rgt-identity94.6%
associate--l+99.2%
+-inverses99.2%
metadata-eval99.2%
+-commutative99.2%
unpow299.2%
fma-define99.4%
Simplified99.4%
if 1e17 < x Initial program 38.9%
flip--38.9%
div-inv38.9%
frac-times23.2%
metadata-eval23.2%
add-sqr-sqrt20.1%
frac-times25.5%
metadata-eval25.5%
add-sqr-sqrt38.9%
+-commutative38.9%
inv-pow38.9%
sqrt-pow238.9%
metadata-eval38.9%
pow1/238.9%
pow-flip38.9%
+-commutative38.9%
metadata-eval38.9%
Applied egg-rr38.9%
associate-*r/38.9%
*-rgt-identity38.9%
Simplified38.9%
Taylor expanded in x around inf 69.5%
*-commutative69.5%
exp-to-pow66.6%
*-commutative66.6%
exp-neg67.4%
distribute-lft-neg-in67.4%
metadata-eval67.4%
*-commutative67.4%
exp-to-pow70.4%
Simplified70.4%
*-un-lft-identity70.4%
sqrt-pow1100.0%
metadata-eval100.0%
Applied egg-rr100.0%
*-lft-identity100.0%
Simplified100.0%
Final simplification99.9%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (+ x 1.0))))
(if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 t_0)) 0.0)
(* (pow x -1.5) 0.5)
(/ 1.0 (* (+ (sqrt x) t_0) (+ x 0.5))))))
double code(double x) {
double t_0 = sqrt((x + 1.0));
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / t_0)) <= 0.0) {
tmp = pow(x, -1.5) * 0.5;
} else {
tmp = 1.0 / ((sqrt(x) + t_0) * (x + 0.5));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt((x + 1.0d0))
if (((1.0d0 / sqrt(x)) + ((-1.0d0) / t_0)) <= 0.0d0) then
tmp = (x ** (-1.5d0)) * 0.5d0
else
tmp = 1.0d0 / ((sqrt(x) + t_0) * (x + 0.5d0))
end if
code = tmp
end function
public static double code(double x) {
double t_0 = Math.sqrt((x + 1.0));
double tmp;
if (((1.0 / Math.sqrt(x)) + (-1.0 / t_0)) <= 0.0) {
tmp = Math.pow(x, -1.5) * 0.5;
} else {
tmp = 1.0 / ((Math.sqrt(x) + t_0) * (x + 0.5));
}
return tmp;
}
def code(x): t_0 = math.sqrt((x + 1.0)) tmp = 0 if ((1.0 / math.sqrt(x)) + (-1.0 / t_0)) <= 0.0: tmp = math.pow(x, -1.5) * 0.5 else: tmp = 1.0 / ((math.sqrt(x) + t_0) * (x + 0.5)) return tmp
function code(x) t_0 = sqrt(Float64(x + 1.0)) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / t_0)) <= 0.0) tmp = Float64((x ^ -1.5) * 0.5); else tmp = Float64(1.0 / Float64(Float64(sqrt(x) + t_0) * Float64(x + 0.5))); end return tmp end
function tmp_2 = code(x) t_0 = sqrt((x + 1.0)); tmp = 0.0; if (((1.0 / sqrt(x)) + (-1.0 / t_0)) <= 0.0) tmp = (x ^ -1.5) * 0.5; else tmp = 1.0 / ((sqrt(x) + t_0) * (x + 0.5)); end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / t$95$0), $MachinePrecision]), $MachinePrecision], 0.0], N[(N[Power[x, -1.5], $MachinePrecision] * 0.5), $MachinePrecision], N[(1.0 / N[(N[(N[Sqrt[x], $MachinePrecision] + t$95$0), $MachinePrecision] * N[(x + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{x + 1}\\
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{t\_0} \leq 0:\\
\;\;\;\;{x}^{-1.5} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(\sqrt{x} + t\_0\right) \cdot \left(x + 0.5\right)}\\
\end{array}
\end{array}
if (-.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 x)) (/.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) < 0.0Initial program 38.7%
flip--38.7%
div-inv38.7%
frac-times23.1%
metadata-eval23.1%
add-sqr-sqrt20.0%
frac-times25.4%
metadata-eval25.4%
add-sqr-sqrt38.7%
+-commutative38.7%
inv-pow38.7%
sqrt-pow238.7%
metadata-eval38.7%
pow1/238.7%
pow-flip38.7%
+-commutative38.7%
metadata-eval38.7%
Applied egg-rr38.7%
associate-*r/38.7%
*-rgt-identity38.7%
Simplified38.7%
Taylor expanded in x around inf 69.6%
*-commutative69.6%
exp-to-pow66.7%
*-commutative66.7%
exp-neg67.6%
distribute-lft-neg-in67.6%
metadata-eval67.6%
*-commutative67.6%
exp-to-pow70.5%
Simplified70.5%
*-un-lft-identity70.5%
sqrt-pow1100.0%
metadata-eval100.0%
Applied egg-rr100.0%
*-lft-identity100.0%
Simplified100.0%
if 0.0 < (-.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 x)) (/.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) Initial program 65.0%
frac-sub66.1%
*-rgt-identity66.1%
*-un-lft-identity66.1%
+-commutative66.1%
sqrt-unprod66.1%
+-commutative66.1%
Applied egg-rr66.1%
Taylor expanded in x around inf 52.5%
distribute-lft-in52.5%
*-rgt-identity52.5%
*-commutative52.5%
associate-*r*52.5%
rgt-mult-inverse52.5%
metadata-eval52.5%
Simplified52.5%
flip--73.1%
add-sqr-sqrt85.9%
add-sqr-sqrt99.4%
add-sqr-sqrt99.3%
hypot-1-def99.2%
Applied egg-rr78.4%
associate--l+99.2%
+-inverses99.2%
metadata-eval99.2%
+-commutative99.2%
hypot-undefine99.3%
metadata-eval99.3%
rem-square-sqrt99.4%
Simplified78.5%
*-un-lft-identity78.5%
associate-/l/78.4%
*-commutative78.4%
Applied egg-rr78.4%
*-lft-identity78.4%
Simplified78.4%
Final simplification98.3%
(FPCore (x)
:precision binary64
(let* ((t_0 (/ 1.0 (sqrt x))))
(if (<= (+ t_0 (/ -1.0 (sqrt (+ x 1.0)))) 2e-14)
(* (pow x -1.5) 0.5)
(- t_0 (sqrt (/ 1.0 (+ x 1.0)))))))
double code(double x) {
double t_0 = 1.0 / sqrt(x);
double tmp;
if ((t_0 + (-1.0 / sqrt((x + 1.0)))) <= 2e-14) {
tmp = pow(x, -1.5) * 0.5;
} else {
tmp = t_0 - sqrt((1.0 / (x + 1.0)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = 1.0d0 / sqrt(x)
if ((t_0 + ((-1.0d0) / sqrt((x + 1.0d0)))) <= 2d-14) then
tmp = (x ** (-1.5d0)) * 0.5d0
else
tmp = t_0 - sqrt((1.0d0 / (x + 1.0d0)))
end if
code = tmp
end function
public static double code(double x) {
double t_0 = 1.0 / Math.sqrt(x);
double tmp;
if ((t_0 + (-1.0 / Math.sqrt((x + 1.0)))) <= 2e-14) {
tmp = Math.pow(x, -1.5) * 0.5;
} else {
tmp = t_0 - Math.sqrt((1.0 / (x + 1.0)));
}
return tmp;
}
def code(x): t_0 = 1.0 / math.sqrt(x) tmp = 0 if (t_0 + (-1.0 / math.sqrt((x + 1.0)))) <= 2e-14: tmp = math.pow(x, -1.5) * 0.5 else: tmp = t_0 - math.sqrt((1.0 / (x + 1.0))) return tmp
function code(x) t_0 = Float64(1.0 / sqrt(x)) tmp = 0.0 if (Float64(t_0 + Float64(-1.0 / sqrt(Float64(x + 1.0)))) <= 2e-14) tmp = Float64((x ^ -1.5) * 0.5); else tmp = Float64(t_0 - sqrt(Float64(1.0 / Float64(x + 1.0)))); end return tmp end
function tmp_2 = code(x) t_0 = 1.0 / sqrt(x); tmp = 0.0; if ((t_0 + (-1.0 / sqrt((x + 1.0)))) <= 2e-14) tmp = (x ^ -1.5) * 0.5; else tmp = t_0 - sqrt((1.0 / (x + 1.0))); end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$0 + N[(-1.0 / N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2e-14], N[(N[Power[x, -1.5], $MachinePrecision] * 0.5), $MachinePrecision], N[(t$95$0 - N[Sqrt[N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\sqrt{x}}\\
\mathbf{if}\;t\_0 + \frac{-1}{\sqrt{x + 1}} \leq 2 \cdot 10^{-14}:\\
\;\;\;\;{x}^{-1.5} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;t\_0 - \sqrt{\frac{1}{x + 1}}\\
\end{array}
\end{array}
if (-.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 x)) (/.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) < 2e-14Initial program 38.9%
flip--38.9%
div-inv38.9%
frac-times23.8%
metadata-eval23.8%
add-sqr-sqrt20.8%
frac-times26.1%
metadata-eval26.1%
add-sqr-sqrt39.0%
+-commutative39.0%
inv-pow39.0%
sqrt-pow239.0%
metadata-eval39.0%
pow1/239.0%
pow-flip39.0%
+-commutative39.0%
metadata-eval39.0%
Applied egg-rr39.0%
associate-*r/39.0%
*-rgt-identity39.0%
Simplified39.0%
Taylor expanded in x around inf 69.8%
*-commutative69.8%
exp-to-pow67.0%
*-commutative67.0%
exp-neg67.8%
distribute-lft-neg-in67.8%
metadata-eval67.8%
*-commutative67.8%
exp-to-pow70.6%
Simplified70.6%
*-un-lft-identity70.6%
sqrt-pow199.2%
metadata-eval99.2%
Applied egg-rr99.2%
*-lft-identity99.2%
Simplified99.2%
if 2e-14 < (-.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 x)) (/.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) Initial program 79.3%
add-sqr-sqrt78.1%
sqrt-unprod79.3%
frac-times79.1%
metadata-eval79.1%
add-sqr-sqrt79.8%
+-commutative79.8%
Applied egg-rr79.8%
Final simplification98.2%
(FPCore (x) :precision binary64 (if (<= x 8e+15) (/ (/ 1.0 (+ (sqrt x) (sqrt (+ x 1.0)))) (sqrt (* x (+ x 1.0)))) (* (pow x -1.5) 0.5)))
double code(double x) {
double tmp;
if (x <= 8e+15) {
tmp = (1.0 / (sqrt(x) + sqrt((x + 1.0)))) / sqrt((x * (x + 1.0)));
} else {
tmp = pow(x, -1.5) * 0.5;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 8d+15) then
tmp = (1.0d0 / (sqrt(x) + sqrt((x + 1.0d0)))) / sqrt((x * (x + 1.0d0)))
else
tmp = (x ** (-1.5d0)) * 0.5d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 8e+15) {
tmp = (1.0 / (Math.sqrt(x) + Math.sqrt((x + 1.0)))) / Math.sqrt((x * (x + 1.0)));
} else {
tmp = Math.pow(x, -1.5) * 0.5;
}
return tmp;
}
def code(x): tmp = 0 if x <= 8e+15: tmp = (1.0 / (math.sqrt(x) + math.sqrt((x + 1.0)))) / math.sqrt((x * (x + 1.0))) else: tmp = math.pow(x, -1.5) * 0.5 return tmp
function code(x) tmp = 0.0 if (x <= 8e+15) tmp = Float64(Float64(1.0 / Float64(sqrt(x) + sqrt(Float64(x + 1.0)))) / sqrt(Float64(x * Float64(x + 1.0)))); else tmp = Float64((x ^ -1.5) * 0.5); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 8e+15) tmp = (1.0 / (sqrt(x) + sqrt((x + 1.0)))) / sqrt((x * (x + 1.0))); else tmp = (x ^ -1.5) * 0.5; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 8e+15], N[(N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(x * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -1.5], $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 8 \cdot 10^{+15}:\\
\;\;\;\;\frac{\frac{1}{\sqrt{x} + \sqrt{x + 1}}}{\sqrt{x \cdot \left(x + 1\right)}}\\
\mathbf{else}:\\
\;\;\;\;{x}^{-1.5} \cdot 0.5\\
\end{array}
\end{array}
if x < 8e15Initial program 65.0%
frac-sub66.1%
*-rgt-identity66.1%
*-un-lft-identity66.1%
+-commutative66.1%
sqrt-unprod66.1%
+-commutative66.1%
Applied egg-rr66.1%
flip--73.1%
add-sqr-sqrt85.9%
add-sqr-sqrt99.4%
add-sqr-sqrt99.3%
hypot-1-def99.2%
Applied egg-rr99.2%
associate--l+99.2%
+-inverses99.2%
metadata-eval99.2%
+-commutative99.2%
hypot-undefine99.3%
metadata-eval99.3%
rem-square-sqrt99.4%
Simplified99.4%
if 8e15 < x Initial program 38.7%
flip--38.7%
div-inv38.7%
frac-times23.1%
metadata-eval23.1%
add-sqr-sqrt20.0%
frac-times25.4%
metadata-eval25.4%
add-sqr-sqrt38.7%
+-commutative38.7%
inv-pow38.7%
sqrt-pow238.7%
metadata-eval38.7%
pow1/238.7%
pow-flip38.7%
+-commutative38.7%
metadata-eval38.7%
Applied egg-rr38.7%
associate-*r/38.7%
*-rgt-identity38.7%
Simplified38.7%
Taylor expanded in x around inf 69.6%
*-commutative69.6%
exp-to-pow66.7%
*-commutative66.7%
exp-neg67.6%
distribute-lft-neg-in67.6%
metadata-eval67.6%
*-commutative67.6%
exp-to-pow70.5%
Simplified70.5%
*-un-lft-identity70.5%
sqrt-pow1100.0%
metadata-eval100.0%
Applied egg-rr100.0%
*-lft-identity100.0%
Simplified100.0%
Final simplification99.9%
(FPCore (x) :precision binary64 (if (<= x 90000000.0) (- (pow x -0.5) (sqrt (/ 1.0 (+ x 1.0)))) (* (pow x -1.5) 0.5)))
double code(double x) {
double tmp;
if (x <= 90000000.0) {
tmp = pow(x, -0.5) - sqrt((1.0 / (x + 1.0)));
} else {
tmp = pow(x, -1.5) * 0.5;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 90000000.0d0) then
tmp = (x ** (-0.5d0)) - sqrt((1.0d0 / (x + 1.0d0)))
else
tmp = (x ** (-1.5d0)) * 0.5d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 90000000.0) {
tmp = Math.pow(x, -0.5) - Math.sqrt((1.0 / (x + 1.0)));
} else {
tmp = Math.pow(x, -1.5) * 0.5;
}
return tmp;
}
def code(x): tmp = 0 if x <= 90000000.0: tmp = math.pow(x, -0.5) - math.sqrt((1.0 / (x + 1.0))) else: tmp = math.pow(x, -1.5) * 0.5 return tmp
function code(x) tmp = 0.0 if (x <= 90000000.0) tmp = Float64((x ^ -0.5) - sqrt(Float64(1.0 / Float64(x + 1.0)))); else tmp = Float64((x ^ -1.5) * 0.5); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 90000000.0) tmp = (x ^ -0.5) - sqrt((1.0 / (x + 1.0))); else tmp = (x ^ -1.5) * 0.5; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 90000000.0], N[(N[Power[x, -0.5], $MachinePrecision] - N[Sqrt[N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -1.5], $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 90000000:\\
\;\;\;\;{x}^{-0.5} - \sqrt{\frac{1}{x + 1}}\\
\mathbf{else}:\\
\;\;\;\;{x}^{-1.5} \cdot 0.5\\
\end{array}
\end{array}
if x < 9e7Initial program 79.3%
sub-neg79.3%
inv-pow79.3%
sqrt-pow279.3%
metadata-eval79.3%
distribute-neg-frac79.3%
metadata-eval79.3%
+-commutative79.3%
Applied egg-rr79.3%
*-rgt-identity79.3%
cancel-sign-sub79.3%
distribute-lft-neg-in79.3%
*-rgt-identity79.3%
distribute-neg-frac79.3%
metadata-eval79.3%
unpow1/279.3%
exp-to-pow78.0%
log1p-undefine78.0%
*-commutative78.0%
exp-neg78.2%
*-commutative78.2%
distribute-rgt-neg-in78.2%
log1p-undefine78.2%
metadata-eval78.2%
exp-to-pow79.4%
Simplified79.4%
add-sqr-sqrt78.4%
sqrt-unprod79.4%
pow-prod-up79.8%
metadata-eval79.8%
Applied egg-rr79.8%
unpow-179.8%
Simplified79.8%
if 9e7 < x Initial program 38.9%
flip--38.9%
div-inv38.9%
frac-times23.8%
metadata-eval23.8%
add-sqr-sqrt20.8%
frac-times26.1%
metadata-eval26.1%
add-sqr-sqrt39.0%
+-commutative39.0%
inv-pow39.0%
sqrt-pow239.0%
metadata-eval39.0%
pow1/239.0%
pow-flip39.0%
+-commutative39.0%
metadata-eval39.0%
Applied egg-rr39.0%
associate-*r/39.0%
*-rgt-identity39.0%
Simplified39.0%
Taylor expanded in x around inf 69.8%
*-commutative69.8%
exp-to-pow67.0%
*-commutative67.0%
exp-neg67.8%
distribute-lft-neg-in67.8%
metadata-eval67.8%
*-commutative67.8%
exp-to-pow70.6%
Simplified70.6%
*-un-lft-identity70.6%
sqrt-pow199.2%
metadata-eval99.2%
Applied egg-rr99.2%
*-lft-identity99.2%
Simplified99.2%
Final simplification98.2%
(FPCore (x) :precision binary64 (if (<= x 90000000.0) (- (/ 1.0 (sqrt x)) (pow (+ x 1.0) -0.5)) (* (pow x -1.5) 0.5)))
double code(double x) {
double tmp;
if (x <= 90000000.0) {
tmp = (1.0 / sqrt(x)) - pow((x + 1.0), -0.5);
} else {
tmp = pow(x, -1.5) * 0.5;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 90000000.0d0) then
tmp = (1.0d0 / sqrt(x)) - ((x + 1.0d0) ** (-0.5d0))
else
tmp = (x ** (-1.5d0)) * 0.5d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 90000000.0) {
tmp = (1.0 / Math.sqrt(x)) - Math.pow((x + 1.0), -0.5);
} else {
tmp = Math.pow(x, -1.5) * 0.5;
}
return tmp;
}
def code(x): tmp = 0 if x <= 90000000.0: tmp = (1.0 / math.sqrt(x)) - math.pow((x + 1.0), -0.5) else: tmp = math.pow(x, -1.5) * 0.5 return tmp
function code(x) tmp = 0.0 if (x <= 90000000.0) tmp = Float64(Float64(1.0 / sqrt(x)) - (Float64(x + 1.0) ^ -0.5)); else tmp = Float64((x ^ -1.5) * 0.5); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 90000000.0) tmp = (1.0 / sqrt(x)) - ((x + 1.0) ^ -0.5); else tmp = (x ^ -1.5) * 0.5; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 90000000.0], N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] - N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -1.5], $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 90000000:\\
\;\;\;\;\frac{1}{\sqrt{x}} - {\left(x + 1\right)}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;{x}^{-1.5} \cdot 0.5\\
\end{array}
\end{array}
if x < 9e7Initial program 79.3%
frac-2neg79.3%
metadata-eval79.3%
div-inv79.3%
frac-2neg79.3%
metadata-eval79.3%
div-inv79.3%
distribute-neg-frac279.3%
prod-diff79.3%
distribute-neg-frac79.3%
metadata-eval79.3%
+-commutative79.3%
Applied egg-rr79.4%
Simplified79.4%
if 9e7 < x Initial program 38.9%
flip--38.9%
div-inv38.9%
frac-times23.8%
metadata-eval23.8%
add-sqr-sqrt20.8%
frac-times26.1%
metadata-eval26.1%
add-sqr-sqrt39.0%
+-commutative39.0%
inv-pow39.0%
sqrt-pow239.0%
metadata-eval39.0%
pow1/239.0%
pow-flip39.0%
+-commutative39.0%
metadata-eval39.0%
Applied egg-rr39.0%
associate-*r/39.0%
*-rgt-identity39.0%
Simplified39.0%
Taylor expanded in x around inf 69.8%
*-commutative69.8%
exp-to-pow67.0%
*-commutative67.0%
exp-neg67.8%
distribute-lft-neg-in67.8%
metadata-eval67.8%
*-commutative67.8%
exp-to-pow70.6%
Simplified70.6%
*-un-lft-identity70.6%
sqrt-pow199.2%
metadata-eval99.2%
Applied egg-rr99.2%
*-lft-identity99.2%
Simplified99.2%
Final simplification98.2%
(FPCore (x) :precision binary64 (if (<= x 90000000.0) (- (pow x -0.5) (pow (+ x 1.0) -0.5)) (* (pow x -1.5) 0.5)))
double code(double x) {
double tmp;
if (x <= 90000000.0) {
tmp = pow(x, -0.5) - pow((x + 1.0), -0.5);
} else {
tmp = pow(x, -1.5) * 0.5;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 90000000.0d0) then
tmp = (x ** (-0.5d0)) - ((x + 1.0d0) ** (-0.5d0))
else
tmp = (x ** (-1.5d0)) * 0.5d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 90000000.0) {
tmp = Math.pow(x, -0.5) - Math.pow((x + 1.0), -0.5);
} else {
tmp = Math.pow(x, -1.5) * 0.5;
}
return tmp;
}
def code(x): tmp = 0 if x <= 90000000.0: tmp = math.pow(x, -0.5) - math.pow((x + 1.0), -0.5) else: tmp = math.pow(x, -1.5) * 0.5 return tmp
function code(x) tmp = 0.0 if (x <= 90000000.0) tmp = Float64((x ^ -0.5) - (Float64(x + 1.0) ^ -0.5)); else tmp = Float64((x ^ -1.5) * 0.5); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 90000000.0) tmp = (x ^ -0.5) - ((x + 1.0) ^ -0.5); else tmp = (x ^ -1.5) * 0.5; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 90000000.0], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -1.5], $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 90000000:\\
\;\;\;\;{x}^{-0.5} - {\left(x + 1\right)}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;{x}^{-1.5} \cdot 0.5\\
\end{array}
\end{array}
if x < 9e7Initial program 79.3%
sub-neg79.3%
inv-pow79.3%
sqrt-pow279.3%
metadata-eval79.3%
distribute-neg-frac79.3%
metadata-eval79.3%
+-commutative79.3%
Applied egg-rr79.3%
*-rgt-identity79.3%
cancel-sign-sub79.3%
distribute-lft-neg-in79.3%
*-rgt-identity79.3%
distribute-neg-frac79.3%
metadata-eval79.3%
unpow1/279.3%
exp-to-pow78.0%
log1p-undefine78.0%
*-commutative78.0%
exp-neg78.2%
*-commutative78.2%
distribute-rgt-neg-in78.2%
log1p-undefine78.2%
metadata-eval78.2%
exp-to-pow79.4%
Simplified79.4%
if 9e7 < x Initial program 38.9%
flip--38.9%
div-inv38.9%
frac-times23.8%
metadata-eval23.8%
add-sqr-sqrt20.8%
frac-times26.1%
metadata-eval26.1%
add-sqr-sqrt39.0%
+-commutative39.0%
inv-pow39.0%
sqrt-pow239.0%
metadata-eval39.0%
pow1/239.0%
pow-flip39.0%
+-commutative39.0%
metadata-eval39.0%
Applied egg-rr39.0%
associate-*r/39.0%
*-rgt-identity39.0%
Simplified39.0%
Taylor expanded in x around inf 69.8%
*-commutative69.8%
exp-to-pow67.0%
*-commutative67.0%
exp-neg67.8%
distribute-lft-neg-in67.8%
metadata-eval67.8%
*-commutative67.8%
exp-to-pow70.6%
Simplified70.6%
*-un-lft-identity70.6%
sqrt-pow199.2%
metadata-eval99.2%
Applied egg-rr99.2%
*-lft-identity99.2%
Simplified99.2%
Final simplification98.2%
(FPCore (x) :precision binary64 (/ (/ 1.0 (+ (sqrt x) (sqrt (+ x 1.0)))) (+ x 0.5)))
double code(double x) {
return (1.0 / (sqrt(x) + sqrt((x + 1.0)))) / (x + 0.5);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / (sqrt(x) + sqrt((x + 1.0d0)))) / (x + 0.5d0)
end function
public static double code(double x) {
return (1.0 / (Math.sqrt(x) + Math.sqrt((x + 1.0)))) / (x + 0.5);
}
def code(x): return (1.0 / (math.sqrt(x) + math.sqrt((x + 1.0)))) / (x + 0.5)
function code(x) return Float64(Float64(1.0 / Float64(sqrt(x) + sqrt(Float64(x + 1.0)))) / Float64(x + 0.5)) end
function tmp = code(x) tmp = (1.0 / (sqrt(x) + sqrt((x + 1.0)))) / (x + 0.5); end
code[x_] := N[(N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x + 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{\sqrt{x} + \sqrt{x + 1}}}{x + 0.5}
\end{array}
Initial program 40.8%
frac-sub40.9%
*-rgt-identity40.9%
*-un-lft-identity40.9%
+-commutative40.9%
sqrt-unprod40.9%
+-commutative40.9%
Applied egg-rr40.9%
Taylor expanded in x around inf 39.8%
distribute-lft-in39.8%
*-rgt-identity39.8%
*-commutative39.8%
associate-*r*39.8%
rgt-mult-inverse39.8%
metadata-eval39.8%
Simplified39.8%
flip--41.4%
add-sqr-sqrt42.6%
add-sqr-sqrt43.5%
add-sqr-sqrt43.5%
hypot-1-def43.5%
Applied egg-rr41.8%
associate--l+83.9%
+-inverses83.9%
metadata-eval83.9%
+-commutative83.9%
hypot-undefine83.9%
metadata-eval83.9%
rem-square-sqrt83.9%
Simplified97.9%
Final simplification97.9%
(FPCore (x) :precision binary64 (* (pow x -1.5) 0.5))
double code(double x) {
return pow(x, -1.5) * 0.5;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x ** (-1.5d0)) * 0.5d0
end function
public static double code(double x) {
return Math.pow(x, -1.5) * 0.5;
}
def code(x): return math.pow(x, -1.5) * 0.5
function code(x) return Float64((x ^ -1.5) * 0.5) end
function tmp = code(x) tmp = (x ^ -1.5) * 0.5; end
code[x_] := N[(N[Power[x, -1.5], $MachinePrecision] * 0.5), $MachinePrecision]
\begin{array}{l}
\\
{x}^{-1.5} \cdot 0.5
\end{array}
Initial program 40.8%
flip--40.8%
div-inv40.8%
frac-times26.5%
metadata-eval26.5%
add-sqr-sqrt23.6%
frac-times28.6%
metadata-eval28.6%
add-sqr-sqrt41.1%
+-commutative41.1%
inv-pow41.1%
sqrt-pow241.1%
metadata-eval41.1%
pow1/241.1%
pow-flip41.1%
+-commutative41.1%
metadata-eval41.1%
Applied egg-rr41.1%
associate-*r/41.1%
*-rgt-identity41.1%
Simplified41.1%
Taylor expanded in x around inf 68.4%
*-commutative68.4%
exp-to-pow65.7%
*-commutative65.7%
exp-neg66.5%
distribute-lft-neg-in66.5%
metadata-eval66.5%
*-commutative66.5%
exp-to-pow69.2%
Simplified69.2%
*-un-lft-identity69.2%
sqrt-pow196.4%
metadata-eval96.4%
Applied egg-rr96.4%
*-lft-identity96.4%
Simplified96.4%
(FPCore (x) :precision binary64 (pow x -0.5))
double code(double x) {
return pow(x, -0.5);
}
real(8) function code(x)
real(8), intent (in) :: x
code = x ** (-0.5d0)
end function
public static double code(double x) {
return Math.pow(x, -0.5);
}
def code(x): return math.pow(x, -0.5)
function code(x) return x ^ -0.5 end
function tmp = code(x) tmp = x ^ -0.5; end
code[x_] := N[Power[x, -0.5], $MachinePrecision]
\begin{array}{l}
\\
{x}^{-0.5}
\end{array}
Initial program 40.8%
flip--40.8%
div-inv40.8%
frac-times26.5%
metadata-eval26.5%
add-sqr-sqrt23.6%
frac-times28.6%
metadata-eval28.6%
add-sqr-sqrt41.1%
+-commutative41.1%
inv-pow41.1%
sqrt-pow241.1%
metadata-eval41.1%
pow1/241.1%
pow-flip41.1%
+-commutative41.1%
metadata-eval41.1%
Applied egg-rr41.1%
associate-*r/41.1%
*-rgt-identity41.1%
Simplified41.1%
Taylor expanded in x around 0 5.8%
unpow1/25.8%
rem-exp-log5.8%
exp-neg5.8%
exp-prod5.8%
distribute-lft-neg-out5.8%
distribute-rgt-neg-in5.8%
metadata-eval5.8%
exp-to-pow5.8%
Simplified5.8%
(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 2024137
(FPCore (x)
:name "2isqrt (example 3.6)"
:precision binary64
:pre (and (> x 1.0) (< x 1e+308))
:alt
(! :herbie-platform default (/ 1 (+ (* (+ x 1) (sqrt x)) (* x (sqrt (+ x 1))))))
(- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))