
(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 14 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 (sqrt (+ x 1.0))))
(if (<= (- (/ 1.0 (sqrt x)) (/ 1.0 t_0)) 1e-9)
(/ (/ 1.0 (+ (sqrt x) t_0)) (+ x 0.5))
(- (pow x -0.5) (pow (+ x 1.0) -0.5)))))
double code(double x) {
double t_0 = sqrt((x + 1.0));
double tmp;
if (((1.0 / sqrt(x)) - (1.0 / t_0)) <= 1e-9) {
tmp = (1.0 / (sqrt(x) + t_0)) / (x + 0.5);
} else {
tmp = pow(x, -0.5) - pow((x + 1.0), -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)) <= 1d-9) then
tmp = (1.0d0 / (sqrt(x) + t_0)) / (x + 0.5d0)
else
tmp = (x ** (-0.5d0)) - ((x + 1.0d0) ** (-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)) <= 1e-9) {
tmp = (1.0 / (Math.sqrt(x) + t_0)) / (x + 0.5);
} else {
tmp = Math.pow(x, -0.5) - Math.pow((x + 1.0), -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)) <= 1e-9: tmp = (1.0 / (math.sqrt(x) + t_0)) / (x + 0.5) else: tmp = math.pow(x, -0.5) - math.pow((x + 1.0), -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)) <= 1e-9) tmp = Float64(Float64(1.0 / Float64(sqrt(x) + t_0)) / Float64(x + 0.5)); else tmp = Float64((x ^ -0.5) - (Float64(x + 1.0) ^ -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)) <= 1e-9) tmp = (1.0 / (sqrt(x) + t_0)) / (x + 0.5); else tmp = (x ^ -0.5) - ((x + 1.0) ^ -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], 1e-9], N[(N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision] / N[(x + 0.5), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{x + 1}\\
\mathbf{if}\;\frac{1}{\sqrt{x}} - \frac{1}{t_0} \leq 10^{-9}:\\
\;\;\;\;\frac{\frac{1}{\sqrt{x} + t_0}}{x + 0.5}\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} - {\left(x + 1\right)}^{-0.5}\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 1.00000000000000006e-9Initial program 35.7%
frac-sub35.7%
*-un-lft-identity35.7%
+-commutative35.7%
*-rgt-identity35.7%
sqrt-unprod35.7%
+-commutative35.7%
Applied egg-rr35.7%
Taylor expanded in x around inf 35.7%
flip--36.1%
div-inv36.1%
add-sqr-sqrt20.1%
add-sqr-sqrt37.7%
associate--l+99.5%
Applied egg-rr99.5%
+-inverses99.5%
metadata-eval99.5%
*-lft-identity99.5%
+-commutative99.5%
Simplified99.5%
if 1.00000000000000006e-9 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.5%
*-un-lft-identity99.5%
clear-num99.5%
associate-/r/99.5%
prod-diff99.5%
*-un-lft-identity99.5%
fma-neg99.5%
*-un-lft-identity99.5%
pow1/299.5%
pow-flip99.8%
metadata-eval99.8%
pow1/299.8%
pow-flip99.8%
+-commutative99.8%
metadata-eval99.8%
Applied egg-rr99.8%
associate-+l-99.8%
expm1-log1p99.8%
expm1-def99.7%
associate--l-99.7%
fma-udef99.7%
distribute-lft1-in99.7%
metadata-eval99.7%
mul0-lft99.7%
metadata-eval99.7%
expm1-def99.8%
expm1-log1p99.8%
Simplified99.8%
Final simplification99.7%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (+ x 1.0))))
(if (<= (- (/ 1.0 (sqrt x)) (/ 1.0 t_0)) 2e-14)
(/ (/ 0.5 x) t_0)
(- (pow x -0.5) (pow (+ x 1.0) -0.5)))))
double code(double x) {
double t_0 = sqrt((x + 1.0));
double tmp;
if (((1.0 / sqrt(x)) - (1.0 / t_0)) <= 2e-14) {
tmp = (0.5 / x) / t_0;
} else {
tmp = pow(x, -0.5) - pow((x + 1.0), -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)) <= 2d-14) then
tmp = (0.5d0 / x) / t_0
else
tmp = (x ** (-0.5d0)) - ((x + 1.0d0) ** (-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)) <= 2e-14) {
tmp = (0.5 / x) / t_0;
} else {
tmp = Math.pow(x, -0.5) - Math.pow((x + 1.0), -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)) <= 2e-14: tmp = (0.5 / x) / t_0 else: tmp = math.pow(x, -0.5) - math.pow((x + 1.0), -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)) <= 2e-14) tmp = Float64(Float64(0.5 / x) / t_0); else tmp = Float64((x ^ -0.5) - (Float64(x + 1.0) ^ -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)) <= 2e-14) tmp = (0.5 / x) / t_0; else tmp = (x ^ -0.5) - ((x + 1.0) ^ -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], 2e-14], N[(N[(0.5 / x), $MachinePrecision] / t$95$0), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{x + 1}\\
\mathbf{if}\;\frac{1}{\sqrt{x}} - \frac{1}{t_0} \leq 2 \cdot 10^{-14}:\\
\;\;\;\;\frac{\frac{0.5}{x}}{t_0}\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} - {\left(x + 1\right)}^{-0.5}\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 2e-14Initial program 35.4%
frac-sub35.4%
associate-/r*35.4%
*-un-lft-identity35.4%
+-commutative35.4%
*-rgt-identity35.4%
+-commutative35.4%
Applied egg-rr35.4%
flip--35.9%
div-inv35.9%
add-sqr-sqrt19.6%
add-sqr-sqrt37.4%
associate--l+99.6%
Applied egg-rr99.3%
+-inverses99.6%
metadata-eval99.6%
*-lft-identity99.6%
+-commutative99.6%
Simplified99.3%
Taylor expanded in x around inf 99.1%
if 2e-14 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.2%
*-un-lft-identity99.2%
clear-num99.2%
associate-/r/99.2%
prod-diff99.2%
*-un-lft-identity99.2%
fma-neg99.2%
*-un-lft-identity99.2%
pow1/299.2%
pow-flip99.6%
metadata-eval99.6%
pow1/299.6%
pow-flip99.6%
+-commutative99.6%
metadata-eval99.6%
Applied egg-rr99.6%
associate-+l-99.6%
expm1-log1p99.6%
expm1-def99.4%
associate--l-99.4%
fma-udef99.4%
distribute-lft1-in99.4%
metadata-eval99.4%
mul0-lft99.4%
metadata-eval99.4%
expm1-def99.6%
expm1-log1p99.6%
Simplified99.6%
Final simplification99.4%
(FPCore (x) :precision binary64 (/ (pow (+ x 1.0) -0.5) (+ x (hypot x (sqrt x)))))
double code(double x) {
return pow((x + 1.0), -0.5) / (x + hypot(x, sqrt(x)));
}
public static double code(double x) {
return Math.pow((x + 1.0), -0.5) / (x + Math.hypot(x, Math.sqrt(x)));
}
def code(x): return math.pow((x + 1.0), -0.5) / (x + math.hypot(x, math.sqrt(x)))
function code(x) return Float64((Float64(x + 1.0) ^ -0.5) / Float64(x + hypot(x, sqrt(x)))) end
function tmp = code(x) tmp = ((x + 1.0) ^ -0.5) / (x + hypot(x, sqrt(x))); end
code[x_] := N[(N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision] / N[(x + N[Sqrt[x ^ 2 + N[Sqrt[x], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\left(x + 1\right)}^{-0.5}}{x + \mathsf{hypot}\left(x, \sqrt{x}\right)}
\end{array}
Initial program 68.3%
frac-sub68.3%
associate-/r*68.3%
*-un-lft-identity68.3%
+-commutative68.3%
*-rgt-identity68.3%
+-commutative68.3%
Applied egg-rr68.3%
flip--21.6%
div-inv21.6%
add-sqr-sqrt13.8%
add-sqr-sqrt22.4%
associate--l+52.6%
Applied egg-rr99.4%
+-inverses52.6%
metadata-eval52.6%
*-lft-identity52.6%
+-commutative52.6%
Simplified99.4%
expm1-log1p-u96.0%
expm1-udef64.3%
Applied egg-rr64.3%
expm1-def87.5%
expm1-log1p90.9%
+-commutative90.9%
+-commutative90.9%
distribute-lft-in91.0%
*-rgt-identity91.0%
rem-square-sqrt91.0%
hypot-def99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (x) :precision binary64 (if (<= x 1.15) (+ (pow x -0.5) (/ -1.0 (+ 1.0 (* x 0.5)))) (/ (/ 0.5 x) (sqrt (+ x 1.0)))))
double code(double x) {
double tmp;
if (x <= 1.15) {
tmp = pow(x, -0.5) + (-1.0 / (1.0 + (x * 0.5)));
} else {
tmp = (0.5 / x) / sqrt((x + 1.0));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.15d0) then
tmp = (x ** (-0.5d0)) + ((-1.0d0) / (1.0d0 + (x * 0.5d0)))
else
tmp = (0.5d0 / x) / sqrt((x + 1.0d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.15) {
tmp = Math.pow(x, -0.5) + (-1.0 / (1.0 + (x * 0.5)));
} else {
tmp = (0.5 / x) / Math.sqrt((x + 1.0));
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.15: tmp = math.pow(x, -0.5) + (-1.0 / (1.0 + (x * 0.5))) else: tmp = (0.5 / x) / math.sqrt((x + 1.0)) return tmp
function code(x) tmp = 0.0 if (x <= 1.15) tmp = Float64((x ^ -0.5) + Float64(-1.0 / Float64(1.0 + Float64(x * 0.5)))); else tmp = Float64(Float64(0.5 / x) / sqrt(Float64(x + 1.0))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.15) tmp = (x ^ -0.5) + (-1.0 / (1.0 + (x * 0.5))); else tmp = (0.5 / x) / sqrt((x + 1.0)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.15], N[(N[Power[x, -0.5], $MachinePrecision] + N[(-1.0 / N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 / x), $MachinePrecision] / N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.15:\\
\;\;\;\;{x}^{-0.5} + \frac{-1}{1 + x \cdot 0.5}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{0.5}{x}}{\sqrt{x + 1}}\\
\end{array}
\end{array}
if x < 1.1499999999999999Initial program 99.6%
Taylor expanded in x around 0 98.6%
*-commutative98.6%
Simplified98.6%
expm1-log1p-u91.7%
expm1-udef91.7%
pow1/291.7%
pow-flip91.7%
metadata-eval91.7%
Applied egg-rr91.7%
expm1-def91.7%
expm1-log1p99.0%
Simplified99.0%
if 1.1499999999999999 < x Initial program 36.5%
frac-sub36.6%
associate-/r*36.6%
*-un-lft-identity36.6%
+-commutative36.6%
*-rgt-identity36.6%
+-commutative36.6%
Applied egg-rr36.6%
flip--36.3%
div-inv36.3%
add-sqr-sqrt20.5%
add-sqr-sqrt37.9%
associate--l+98.7%
Applied egg-rr99.3%
+-inverses98.7%
metadata-eval98.7%
*-lft-identity98.7%
+-commutative98.7%
Simplified99.3%
Taylor expanded in x around inf 97.7%
Final simplification98.3%
(FPCore (x) :precision binary64 (if (<= x 0.7) (+ (+ (pow x -0.5) (* x 0.5)) -1.0) (/ (/ 0.5 x) (sqrt (+ x 1.0)))))
double code(double x) {
double tmp;
if (x <= 0.7) {
tmp = (pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = (0.5 / x) / sqrt((x + 1.0));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.7d0) then
tmp = ((x ** (-0.5d0)) + (x * 0.5d0)) + (-1.0d0)
else
tmp = (0.5d0 / x) / sqrt((x + 1.0d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.7) {
tmp = (Math.pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = (0.5 / x) / Math.sqrt((x + 1.0));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.7: tmp = (math.pow(x, -0.5) + (x * 0.5)) + -1.0 else: tmp = (0.5 / x) / math.sqrt((x + 1.0)) return tmp
function code(x) tmp = 0.0 if (x <= 0.7) tmp = Float64(Float64((x ^ -0.5) + Float64(x * 0.5)) + -1.0); else tmp = Float64(Float64(0.5 / x) / sqrt(Float64(x + 1.0))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.7) tmp = ((x ^ -0.5) + (x * 0.5)) + -1.0; else tmp = (0.5 / x) / sqrt((x + 1.0)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.7], N[(N[(N[Power[x, -0.5], $MachinePrecision] + N[(x * 0.5), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(0.5 / x), $MachinePrecision] / N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.7:\\
\;\;\;\;\left({x}^{-0.5} + x \cdot 0.5\right) + -1\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{0.5}{x}}{\sqrt{x + 1}}\\
\end{array}
\end{array}
if x < 0.69999999999999996Initial program 99.6%
*-un-lft-identity99.6%
clear-num99.6%
associate-/r/99.6%
prod-diff99.6%
*-un-lft-identity99.6%
fma-neg99.6%
*-un-lft-identity99.6%
pow1/299.6%
pow-flip100.0%
metadata-eval100.0%
pow1/2100.0%
pow-flip100.0%
+-commutative100.0%
metadata-eval100.0%
Applied egg-rr100.0%
associate-+l-100.0%
expm1-log1p100.0%
expm1-def100.0%
associate--l-100.0%
fma-udef100.0%
distribute-lft1-in100.0%
metadata-eval100.0%
mul0-lft100.0%
metadata-eval100.0%
expm1-def100.0%
expm1-log1p100.0%
Simplified100.0%
Taylor expanded in x around 0 98.9%
if 0.69999999999999996 < x Initial program 36.5%
frac-sub36.6%
associate-/r*36.6%
*-un-lft-identity36.6%
+-commutative36.6%
*-rgt-identity36.6%
+-commutative36.6%
Applied egg-rr36.6%
flip--36.3%
div-inv36.3%
add-sqr-sqrt20.5%
add-sqr-sqrt37.9%
associate--l+98.7%
Applied egg-rr99.3%
+-inverses98.7%
metadata-eval98.7%
*-lft-identity98.7%
+-commutative98.7%
Simplified99.3%
Taylor expanded in x around inf 97.7%
Final simplification98.3%
(FPCore (x) :precision binary64 (if (<= x 0.68) (+ (pow x -0.5) -1.0) (/ 1.0 (sqrt (* x (+ x 1.0))))))
double code(double x) {
double tmp;
if (x <= 0.68) {
tmp = pow(x, -0.5) + -1.0;
} else {
tmp = 1.0 / sqrt((x * (x + 1.0)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.68d0) then
tmp = (x ** (-0.5d0)) + (-1.0d0)
else
tmp = 1.0d0 / sqrt((x * (x + 1.0d0)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.68) {
tmp = Math.pow(x, -0.5) + -1.0;
} else {
tmp = 1.0 / Math.sqrt((x * (x + 1.0)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.68: tmp = math.pow(x, -0.5) + -1.0 else: tmp = 1.0 / math.sqrt((x * (x + 1.0))) return tmp
function code(x) tmp = 0.0 if (x <= 0.68) tmp = Float64((x ^ -0.5) + -1.0); else tmp = Float64(1.0 / sqrt(Float64(x * Float64(x + 1.0)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.68) tmp = (x ^ -0.5) + -1.0; else tmp = 1.0 / sqrt((x * (x + 1.0))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.68], N[(N[Power[x, -0.5], $MachinePrecision] + -1.0), $MachinePrecision], N[(1.0 / N[Sqrt[N[(x * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.68:\\
\;\;\;\;{x}^{-0.5} + -1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sqrt{x \cdot \left(x + 1\right)}}\\
\end{array}
\end{array}
if x < 0.680000000000000049Initial program 99.6%
*-un-lft-identity99.6%
clear-num99.6%
associate-/r/99.6%
prod-diff99.6%
*-un-lft-identity99.6%
fma-neg99.6%
*-un-lft-identity99.6%
pow1/299.6%
pow-flip100.0%
metadata-eval100.0%
pow1/2100.0%
pow-flip100.0%
+-commutative100.0%
metadata-eval100.0%
Applied egg-rr100.0%
associate-+l-100.0%
expm1-log1p100.0%
expm1-def100.0%
associate--l-100.0%
fma-udef100.0%
distribute-lft1-in100.0%
metadata-eval100.0%
mul0-lft100.0%
metadata-eval100.0%
expm1-def100.0%
expm1-log1p100.0%
Simplified100.0%
Taylor expanded in x around 0 98.3%
if 0.680000000000000049 < x Initial program 36.5%
frac-sub36.6%
*-un-lft-identity36.6%
+-commutative36.6%
*-rgt-identity36.6%
sqrt-unprod36.6%
+-commutative36.6%
Applied egg-rr36.6%
Taylor expanded in x around 0 35.5%
Final simplification67.1%
(FPCore (x) :precision binary64 (if (<= x 0.48) (+ (pow x -0.5) -1.0) (/ (/ 0.5 x) (sqrt (+ x 1.0)))))
double code(double x) {
double tmp;
if (x <= 0.48) {
tmp = pow(x, -0.5) + -1.0;
} else {
tmp = (0.5 / x) / sqrt((x + 1.0));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.48d0) then
tmp = (x ** (-0.5d0)) + (-1.0d0)
else
tmp = (0.5d0 / x) / sqrt((x + 1.0d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.48) {
tmp = Math.pow(x, -0.5) + -1.0;
} else {
tmp = (0.5 / x) / Math.sqrt((x + 1.0));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.48: tmp = math.pow(x, -0.5) + -1.0 else: tmp = (0.5 / x) / math.sqrt((x + 1.0)) return tmp
function code(x) tmp = 0.0 if (x <= 0.48) tmp = Float64((x ^ -0.5) + -1.0); else tmp = Float64(Float64(0.5 / x) / sqrt(Float64(x + 1.0))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.48) tmp = (x ^ -0.5) + -1.0; else tmp = (0.5 / x) / sqrt((x + 1.0)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.48], N[(N[Power[x, -0.5], $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(0.5 / x), $MachinePrecision] / N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.48:\\
\;\;\;\;{x}^{-0.5} + -1\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{0.5}{x}}{\sqrt{x + 1}}\\
\end{array}
\end{array}
if x < 0.47999999999999998Initial program 99.6%
*-un-lft-identity99.6%
clear-num99.6%
associate-/r/99.6%
prod-diff99.6%
*-un-lft-identity99.6%
fma-neg99.6%
*-un-lft-identity99.6%
pow1/299.6%
pow-flip100.0%
metadata-eval100.0%
pow1/2100.0%
pow-flip100.0%
+-commutative100.0%
metadata-eval100.0%
Applied egg-rr100.0%
associate-+l-100.0%
expm1-log1p100.0%
expm1-def100.0%
associate--l-100.0%
fma-udef100.0%
distribute-lft1-in100.0%
metadata-eval100.0%
mul0-lft100.0%
metadata-eval100.0%
expm1-def100.0%
expm1-log1p100.0%
Simplified100.0%
Taylor expanded in x around 0 98.3%
if 0.47999999999999998 < x Initial program 36.5%
frac-sub36.6%
associate-/r*36.6%
*-un-lft-identity36.6%
+-commutative36.6%
*-rgt-identity36.6%
+-commutative36.6%
Applied egg-rr36.6%
flip--36.3%
div-inv36.3%
add-sqr-sqrt20.5%
add-sqr-sqrt37.9%
associate--l+98.7%
Applied egg-rr99.3%
+-inverses98.7%
metadata-eval98.7%
*-lft-identity98.7%
+-commutative98.7%
Simplified99.3%
Taylor expanded in x around inf 97.7%
Final simplification98.0%
(FPCore (x) :precision binary64 (if (<= x 0.6) (+ (pow x -0.5) -1.0) (/ 1.0 (+ x 0.5))))
double code(double x) {
double tmp;
if (x <= 0.6) {
tmp = pow(x, -0.5) + -1.0;
} else {
tmp = 1.0 / (x + 0.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.6d0) then
tmp = (x ** (-0.5d0)) + (-1.0d0)
else
tmp = 1.0d0 / (x + 0.5d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.6) {
tmp = Math.pow(x, -0.5) + -1.0;
} else {
tmp = 1.0 / (x + 0.5);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.6: tmp = math.pow(x, -0.5) + -1.0 else: tmp = 1.0 / (x + 0.5) return tmp
function code(x) tmp = 0.0 if (x <= 0.6) tmp = Float64((x ^ -0.5) + -1.0); else tmp = Float64(1.0 / Float64(x + 0.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.6) tmp = (x ^ -0.5) + -1.0; else tmp = 1.0 / (x + 0.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.6], N[(N[Power[x, -0.5], $MachinePrecision] + -1.0), $MachinePrecision], N[(1.0 / N[(x + 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.6:\\
\;\;\;\;{x}^{-0.5} + -1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x + 0.5}\\
\end{array}
\end{array}
if x < 0.599999999999999978Initial program 99.6%
*-un-lft-identity99.6%
clear-num99.6%
associate-/r/99.6%
prod-diff99.6%
*-un-lft-identity99.6%
fma-neg99.6%
*-un-lft-identity99.6%
pow1/299.6%
pow-flip100.0%
metadata-eval100.0%
pow1/2100.0%
pow-flip100.0%
+-commutative100.0%
metadata-eval100.0%
Applied egg-rr100.0%
associate-+l-100.0%
expm1-log1p100.0%
expm1-def100.0%
associate--l-100.0%
fma-udef100.0%
distribute-lft1-in100.0%
metadata-eval100.0%
mul0-lft100.0%
metadata-eval100.0%
expm1-def100.0%
expm1-log1p100.0%
Simplified100.0%
Taylor expanded in x around 0 98.3%
if 0.599999999999999978 < x Initial program 36.5%
frac-sub36.6%
*-un-lft-identity36.6%
+-commutative36.6%
*-rgt-identity36.6%
sqrt-unprod36.6%
+-commutative36.6%
Applied egg-rr36.6%
Taylor expanded in x around inf 35.8%
Taylor expanded in x around 0 7.8%
Final simplification53.4%
(FPCore (x) :precision binary64 (/ 1.0 (+ x (sqrt x))))
double code(double x) {
return 1.0 / (x + sqrt(x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (x + sqrt(x))
end function
public static double code(double x) {
return 1.0 / (x + Math.sqrt(x));
}
def code(x): return 1.0 / (x + math.sqrt(x))
function code(x) return Float64(1.0 / Float64(x + sqrt(x))) end
function tmp = code(x) tmp = 1.0 / (x + sqrt(x)); end
code[x_] := N[(1.0 / N[(x + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x + \sqrt{x}}
\end{array}
Initial program 68.3%
*-un-lft-identity68.3%
clear-num68.3%
associate-/r/68.3%
prod-diff68.3%
*-un-lft-identity68.3%
fma-neg68.3%
*-un-lft-identity68.3%
pow1/268.3%
pow-flip62.5%
metadata-eval62.5%
pow1/262.5%
pow-flip68.5%
+-commutative68.5%
metadata-eval68.5%
Applied egg-rr68.5%
associate-+l-68.5%
expm1-log1p68.5%
expm1-def53.9%
associate--l-53.9%
fma-udef53.9%
distribute-lft1-in53.9%
metadata-eval53.9%
mul0-lft53.9%
metadata-eval53.9%
expm1-def68.5%
expm1-log1p68.5%
Simplified68.5%
Applied egg-rr51.3%
associate-*r/51.3%
*-rgt-identity51.3%
Simplified51.3%
Taylor expanded in x around 0 52.4%
distribute-rgt-in52.4%
*-lft-identity52.4%
pow-plus52.6%
metadata-eval52.6%
Simplified52.6%
expm1-log1p-u49.2%
expm1-udef62.3%
pow1/262.3%
Applied egg-rr62.3%
expm1-def49.2%
expm1-log1p52.6%
Simplified52.6%
Final simplification52.6%
(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 68.3%
*-un-lft-identity68.3%
clear-num68.3%
associate-/r/68.3%
prod-diff68.3%
*-un-lft-identity68.3%
fma-neg68.3%
*-un-lft-identity68.3%
pow1/268.3%
pow-flip62.5%
metadata-eval62.5%
pow1/262.5%
pow-flip68.5%
+-commutative68.5%
metadata-eval68.5%
Applied egg-rr68.5%
associate-+l-68.5%
expm1-log1p68.5%
expm1-def53.9%
associate--l-53.9%
fma-udef53.9%
distribute-lft1-in53.9%
metadata-eval53.9%
mul0-lft53.9%
metadata-eval53.9%
expm1-def68.5%
expm1-log1p68.5%
Simplified68.5%
Applied egg-rr51.3%
associate-*r/51.3%
*-rgt-identity51.3%
Simplified51.3%
Taylor expanded in x around inf 50.0%
unpow1/250.0%
rem-exp-log46.7%
exp-neg46.7%
exp-prod46.7%
distribute-lft-neg-out46.7%
distribute-rgt-neg-in46.7%
metadata-eval46.7%
exp-to-pow50.1%
Simplified50.1%
Final simplification50.1%
(FPCore (x) :precision binary64 (/ 1.0 (+ x 0.5)))
double code(double x) {
return 1.0 / (x + 0.5);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (x + 0.5d0)
end function
public static double code(double x) {
return 1.0 / (x + 0.5);
}
def code(x): return 1.0 / (x + 0.5)
function code(x) return Float64(1.0 / Float64(x + 0.5)) end
function tmp = code(x) tmp = 1.0 / (x + 0.5); end
code[x_] := N[(1.0 / N[(x + 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x + 0.5}
\end{array}
Initial program 68.3%
frac-sub68.3%
*-un-lft-identity68.3%
+-commutative68.3%
*-rgt-identity68.3%
sqrt-unprod68.3%
+-commutative68.3%
Applied egg-rr68.3%
Taylor expanded in x around inf 21.4%
Taylor expanded in x around 0 7.5%
Final simplification7.5%
(FPCore (x) :precision binary64 (/ 1.0 x))
double code(double x) {
return 1.0 / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / x
end function
public static double code(double x) {
return 1.0 / x;
}
def code(x): return 1.0 / x
function code(x) return Float64(1.0 / x) end
function tmp = code(x) tmp = 1.0 / x; end
code[x_] := N[(1.0 / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x}
\end{array}
Initial program 68.3%
*-un-lft-identity68.3%
clear-num68.3%
associate-/r/68.3%
prod-diff68.3%
*-un-lft-identity68.3%
fma-neg68.3%
*-un-lft-identity68.3%
pow1/268.3%
pow-flip62.5%
metadata-eval62.5%
pow1/262.5%
pow-flip68.5%
+-commutative68.5%
metadata-eval68.5%
Applied egg-rr68.5%
associate-+l-68.5%
expm1-log1p68.5%
expm1-def53.9%
associate--l-53.9%
fma-udef53.9%
distribute-lft1-in53.9%
metadata-eval53.9%
mul0-lft53.9%
metadata-eval53.9%
expm1-def68.5%
expm1-log1p68.5%
Simplified68.5%
Applied egg-rr51.3%
associate-*r/51.3%
*-rgt-identity51.3%
Simplified51.3%
Taylor expanded in x around 0 52.4%
distribute-rgt-in52.4%
*-lft-identity52.4%
pow-plus52.6%
metadata-eval52.6%
Simplified52.6%
Taylor expanded in x around inf 7.5%
Final simplification7.5%
(FPCore (x) :precision binary64 -1.0)
double code(double x) {
return -1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = -1.0d0
end function
public static double code(double x) {
return -1.0;
}
def code(x): return -1.0
function code(x) return -1.0 end
function tmp = code(x) tmp = -1.0; end
code[x_] := -1.0
\begin{array}{l}
\\
-1
\end{array}
Initial program 68.3%
Taylor expanded in x around 0 50.6%
Taylor expanded in x around inf 1.9%
Final simplification1.9%
(FPCore (x) :precision binary64 2.0)
double code(double x) {
return 2.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0
end function
public static double code(double x) {
return 2.0;
}
def code(x): return 2.0
function code(x) return 2.0 end
function tmp = code(x) tmp = 2.0; end
code[x_] := 2.0
\begin{array}{l}
\\
2
\end{array}
Initial program 68.3%
frac-sub68.3%
*-un-lft-identity68.3%
+-commutative68.3%
*-rgt-identity68.3%
sqrt-unprod68.3%
+-commutative68.3%
Applied egg-rr68.3%
Taylor expanded in x around inf 21.4%
Taylor expanded in x around 0 5.9%
Final simplification5.9%
(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 2024021
(FPCore (x)
:name "2isqrt (example 3.6)"
:precision binary64
:herbie-target
(/ 1.0 (+ (* (+ x 1.0) (sqrt x)) (* x (sqrt (+ x 1.0)))))
(- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))