
(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 11 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 (/ (/ 1.0 (+ (sqrt x) (sqrt (+ 1.0 x)))) (hypot x (sqrt x))))
double code(double x) {
return (1.0 / (sqrt(x) + sqrt((1.0 + x)))) / hypot(x, sqrt(x));
}
public static double code(double x) {
return (1.0 / (Math.sqrt(x) + Math.sqrt((1.0 + x)))) / Math.hypot(x, Math.sqrt(x));
}
def code(x): return (1.0 / (math.sqrt(x) + math.sqrt((1.0 + x)))) / math.hypot(x, math.sqrt(x))
function code(x) return Float64(Float64(1.0 / Float64(sqrt(x) + sqrt(Float64(1.0 + x)))) / hypot(x, sqrt(x))) end
function tmp = code(x) tmp = (1.0 / (sqrt(x) + sqrt((1.0 + x)))) / hypot(x, sqrt(x)); end
code[x_] := N[(N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[x ^ 2 + N[Sqrt[x], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{\sqrt{x} + \sqrt{1 + x}}}{\mathsf{hypot}\left(x, \sqrt{x}\right)}
\end{array}
Initial program 67.9%
frac-sub67.9%
div-inv67.9%
*-un-lft-identity67.9%
*-rgt-identity67.9%
+-commutative67.9%
sqrt-unprod67.9%
+-commutative67.9%
Applied egg-rr67.9%
associate-*r/67.9%
*-rgt-identity67.9%
+-commutative67.9%
distribute-lft-in67.9%
*-rgt-identity67.9%
unpow167.9%
sqr-pow67.9%
hypot-def67.9%
metadata-eval67.9%
unpow1/267.9%
Simplified67.9%
flip--68.4%
div-inv68.4%
add-sqr-sqrt58.5%
add-sqr-sqrt68.8%
associate--l+99.6%
Applied egg-rr99.6%
+-inverses99.6%
metadata-eval99.6%
*-lft-identity99.6%
+-commutative99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (+ 1.0 x))))
(if (<= (- (/ 1.0 (sqrt x)) (/ 1.0 t_0)) 5e-14)
(/ (/ (/ -1.0 x) (- -1.0 x)) (* 2.0 (sqrt (/ 1.0 x))))
(+ (pow x -0.5) (/ -1.0 t_0)))))
double code(double x) {
double t_0 = sqrt((1.0 + x));
double tmp;
if (((1.0 / sqrt(x)) - (1.0 / t_0)) <= 5e-14) {
tmp = ((-1.0 / x) / (-1.0 - x)) / (2.0 * sqrt((1.0 / x)));
} else {
tmp = pow(x, -0.5) + (-1.0 / t_0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt((1.0d0 + x))
if (((1.0d0 / sqrt(x)) - (1.0d0 / t_0)) <= 5d-14) then
tmp = (((-1.0d0) / x) / ((-1.0d0) - x)) / (2.0d0 * sqrt((1.0d0 / x)))
else
tmp = (x ** (-0.5d0)) + ((-1.0d0) / t_0)
end if
code = tmp
end function
public static double code(double x) {
double t_0 = Math.sqrt((1.0 + x));
double tmp;
if (((1.0 / Math.sqrt(x)) - (1.0 / t_0)) <= 5e-14) {
tmp = ((-1.0 / x) / (-1.0 - x)) / (2.0 * Math.sqrt((1.0 / x)));
} else {
tmp = Math.pow(x, -0.5) + (-1.0 / t_0);
}
return tmp;
}
def code(x): t_0 = math.sqrt((1.0 + x)) tmp = 0 if ((1.0 / math.sqrt(x)) - (1.0 / t_0)) <= 5e-14: tmp = ((-1.0 / x) / (-1.0 - x)) / (2.0 * math.sqrt((1.0 / x))) else: tmp = math.pow(x, -0.5) + (-1.0 / t_0) return tmp
function code(x) t_0 = sqrt(Float64(1.0 + x)) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) - Float64(1.0 / t_0)) <= 5e-14) tmp = Float64(Float64(Float64(-1.0 / x) / Float64(-1.0 - x)) / Float64(2.0 * sqrt(Float64(1.0 / x)))); else tmp = Float64((x ^ -0.5) + Float64(-1.0 / t_0)); end return tmp end
function tmp_2 = code(x) t_0 = sqrt((1.0 + x)); tmp = 0.0; if (((1.0 / sqrt(x)) - (1.0 / t_0)) <= 5e-14) tmp = ((-1.0 / x) / (-1.0 - x)) / (2.0 * sqrt((1.0 / x))); else tmp = (x ^ -0.5) + (-1.0 / t_0); end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] - N[(1.0 / t$95$0), $MachinePrecision]), $MachinePrecision], 5e-14], N[(N[(N[(-1.0 / x), $MachinePrecision] / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision] / N[(2.0 * N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] + N[(-1.0 / t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{1 + x}\\
\mathbf{if}\;\frac{1}{\sqrt{x}} - \frac{1}{t_0} \leq 5 \cdot 10^{-14}:\\
\;\;\;\;\frac{\frac{\frac{-1}{x}}{-1 - x}}{2 \cdot \sqrt{\frac{1}{x}}}\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} + \frac{-1}{t_0}\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 5.0000000000000002e-14Initial program 37.8%
flip--37.8%
frac-times25.9%
metadata-eval25.9%
add-sqr-sqrt19.7%
frac-times21.7%
metadata-eval21.7%
add-sqr-sqrt37.8%
+-commutative37.8%
pow1/237.8%
pow-flip37.8%
metadata-eval37.8%
inv-pow37.8%
sqrt-pow237.8%
+-commutative37.8%
metadata-eval37.8%
Applied egg-rr37.8%
Taylor expanded in x around inf 37.8%
frac-2neg37.8%
metadata-eval37.8%
frac-sub37.9%
*-un-lft-identity37.9%
distribute-neg-in37.9%
metadata-eval37.9%
distribute-neg-in37.9%
metadata-eval37.9%
Applied egg-rr37.9%
associate-/r*37.9%
associate--l+83.6%
*-commutative83.6%
neg-mul-183.6%
+-inverses83.6%
metadata-eval83.6%
unsub-neg83.6%
Simplified83.6%
if 5.0000000000000002e-14 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 98.5%
expm1-log1p-u91.9%
expm1-udef91.3%
pow1/291.3%
pow-flip91.3%
metadata-eval91.3%
Applied egg-rr91.3%
expm1-def91.8%
expm1-log1p98.8%
Simplified98.8%
Final simplification91.1%
(FPCore (x) :precision binary64 (/ 1.0 (* (+ (sqrt x) (sqrt (+ 1.0 x))) (hypot x (sqrt x)))))
double code(double x) {
return 1.0 / ((sqrt(x) + sqrt((1.0 + x))) * hypot(x, sqrt(x)));
}
public static double code(double x) {
return 1.0 / ((Math.sqrt(x) + Math.sqrt((1.0 + x))) * Math.hypot(x, Math.sqrt(x)));
}
def code(x): return 1.0 / ((math.sqrt(x) + math.sqrt((1.0 + x))) * math.hypot(x, math.sqrt(x)))
function code(x) return Float64(1.0 / Float64(Float64(sqrt(x) + sqrt(Float64(1.0 + x))) * hypot(x, sqrt(x)))) end
function tmp = code(x) tmp = 1.0 / ((sqrt(x) + sqrt((1.0 + x))) * hypot(x, sqrt(x))); end
code[x_] := N[(1.0 / N[(N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sqrt[x ^ 2 + N[Sqrt[x], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\left(\sqrt{x} + \sqrt{1 + x}\right) \cdot \mathsf{hypot}\left(x, \sqrt{x}\right)}
\end{array}
Initial program 67.9%
frac-sub67.9%
div-inv67.9%
*-un-lft-identity67.9%
*-rgt-identity67.9%
+-commutative67.9%
sqrt-unprod67.9%
+-commutative67.9%
Applied egg-rr67.9%
associate-*r/67.9%
*-rgt-identity67.9%
+-commutative67.9%
distribute-lft-in67.9%
*-rgt-identity67.9%
unpow167.9%
sqr-pow67.9%
hypot-def67.9%
metadata-eval67.9%
unpow1/267.9%
Simplified67.9%
flip--68.4%
div-inv68.4%
add-sqr-sqrt58.5%
add-sqr-sqrt68.8%
associate--l+99.6%
Applied egg-rr99.6%
+-inverses99.6%
metadata-eval99.6%
*-lft-identity99.6%
+-commutative99.6%
Simplified99.6%
expm1-log1p-u96.3%
expm1-udef64.0%
associate-/l/64.0%
*-commutative64.0%
Applied egg-rr64.0%
expm1-def95.5%
expm1-log1p98.9%
Simplified98.9%
Final simplification98.9%
(FPCore (x) :precision binary64 (/ (/ (/ -1.0 x) (- -1.0 x)) (+ (pow x -0.5) (pow (+ 1.0 x) -0.5))))
double code(double x) {
return ((-1.0 / x) / (-1.0 - x)) / (pow(x, -0.5) + pow((1.0 + x), -0.5));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (((-1.0d0) / x) / ((-1.0d0) - x)) / ((x ** (-0.5d0)) + ((1.0d0 + x) ** (-0.5d0)))
end function
public static double code(double x) {
return ((-1.0 / x) / (-1.0 - x)) / (Math.pow(x, -0.5) + Math.pow((1.0 + x), -0.5));
}
def code(x): return ((-1.0 / x) / (-1.0 - x)) / (math.pow(x, -0.5) + math.pow((1.0 + x), -0.5))
function code(x) return Float64(Float64(Float64(-1.0 / x) / Float64(-1.0 - x)) / Float64((x ^ -0.5) + (Float64(1.0 + x) ^ -0.5))) end
function tmp = code(x) tmp = ((-1.0 / x) / (-1.0 - x)) / ((x ^ -0.5) + ((1.0 + x) ^ -0.5)); end
code[x_] := 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]
\begin{array}{l}
\\
\frac{\frac{\frac{-1}{x}}{-1 - x}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}
\end{array}
Initial program 67.9%
flip--67.9%
frac-times61.7%
metadata-eval61.7%
add-sqr-sqrt58.6%
frac-times59.6%
metadata-eval59.6%
add-sqr-sqrt67.8%
+-commutative67.8%
pow1/267.8%
pow-flip67.7%
metadata-eval67.7%
inv-pow67.7%
sqrt-pow267.7%
+-commutative67.7%
metadata-eval67.7%
Applied egg-rr67.7%
frac-2neg29.0%
metadata-eval29.0%
frac-sub29.1%
*-un-lft-identity29.1%
distribute-neg-in29.1%
metadata-eval29.1%
distribute-neg-in29.1%
metadata-eval29.1%
Applied egg-rr68.6%
associate-/r*29.1%
associate--l+52.1%
*-commutative52.1%
neg-mul-152.1%
+-inverses52.1%
metadata-eval52.1%
unsub-neg52.1%
Simplified91.5%
Final simplification91.5%
(FPCore (x) :precision binary64 (if (<= x 36000000.0) (- (pow x -0.5) (pow (+ 1.0 x) -0.5)) (/ (/ (/ -1.0 x) (- -1.0 x)) (* 2.0 (sqrt (/ 1.0 x))))))
double code(double x) {
double tmp;
if (x <= 36000000.0) {
tmp = pow(x, -0.5) - pow((1.0 + x), -0.5);
} else {
tmp = ((-1.0 / x) / (-1.0 - x)) / (2.0 * sqrt((1.0 / x)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 36000000.0d0) then
tmp = (x ** (-0.5d0)) - ((1.0d0 + x) ** (-0.5d0))
else
tmp = (((-1.0d0) / x) / ((-1.0d0) - x)) / (2.0d0 * sqrt((1.0d0 / x)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 36000000.0) {
tmp = Math.pow(x, -0.5) - Math.pow((1.0 + x), -0.5);
} else {
tmp = ((-1.0 / x) / (-1.0 - x)) / (2.0 * Math.sqrt((1.0 / x)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 36000000.0: tmp = math.pow(x, -0.5) - math.pow((1.0 + x), -0.5) else: tmp = ((-1.0 / x) / (-1.0 - x)) / (2.0 * math.sqrt((1.0 / x))) return tmp
function code(x) tmp = 0.0 if (x <= 36000000.0) tmp = Float64((x ^ -0.5) - (Float64(1.0 + x) ^ -0.5)); else tmp = Float64(Float64(Float64(-1.0 / x) / Float64(-1.0 - x)) / Float64(2.0 * sqrt(Float64(1.0 / x)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 36000000.0) tmp = (x ^ -0.5) - ((1.0 + x) ^ -0.5); else tmp = ((-1.0 / x) / (-1.0 - x)) / (2.0 * sqrt((1.0 / x))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 36000000.0], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision], N[(N[(N[(-1.0 / x), $MachinePrecision] / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision] / N[(2.0 * N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 36000000:\\
\;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\frac{-1}{x}}{-1 - x}}{2 \cdot \sqrt{\frac{1}{x}}}\\
\end{array}
\end{array}
if x < 3.6e7Initial program 99.1%
*-un-lft-identity99.1%
clear-num99.1%
associate-/r/99.1%
prod-diff99.1%
*-un-lft-identity99.1%
fma-neg99.1%
*-un-lft-identity99.1%
pow1/299.1%
pow-flip99.4%
metadata-eval99.4%
pow1/299.4%
pow-flip99.4%
+-commutative99.4%
metadata-eval99.4%
Applied egg-rr99.4%
associate-+l-99.4%
expm1-log1p99.4%
expm1-def99.1%
associate--l-99.1%
fma-udef99.1%
distribute-lft1-in99.1%
metadata-eval99.1%
mul0-lft99.1%
metadata-eval99.1%
expm1-def99.4%
expm1-log1p99.4%
Simplified99.4%
if 3.6e7 < x Initial program 38.1%
flip--38.2%
frac-times26.4%
metadata-eval26.4%
add-sqr-sqrt20.3%
frac-times22.3%
metadata-eval22.3%
add-sqr-sqrt38.2%
+-commutative38.2%
pow1/238.2%
pow-flip38.2%
metadata-eval38.2%
inv-pow38.2%
sqrt-pow238.2%
+-commutative38.2%
metadata-eval38.2%
Applied egg-rr38.2%
Taylor expanded in x around inf 38.2%
frac-2neg38.2%
metadata-eval38.2%
frac-sub38.3%
*-un-lft-identity38.3%
distribute-neg-in38.3%
metadata-eval38.3%
distribute-neg-in38.3%
metadata-eval38.3%
Applied egg-rr38.3%
associate-/r*38.3%
associate--l+83.2%
*-commutative83.2%
neg-mul-183.2%
+-inverses83.2%
metadata-eval83.2%
unsub-neg83.2%
Simplified83.2%
Final simplification91.1%
(FPCore (x) :precision binary64 (if (<= x 0.74) (+ -1.0 (+ (* -0.375 (* x x)) (+ (pow x -0.5) (* x 0.5)))) (/ (/ (/ -1.0 x) (- -1.0 x)) (* 2.0 (sqrt (/ 1.0 x))))))
double code(double x) {
double tmp;
if (x <= 0.74) {
tmp = -1.0 + ((-0.375 * (x * x)) + (pow(x, -0.5) + (x * 0.5)));
} else {
tmp = ((-1.0 / x) / (-1.0 - x)) / (2.0 * sqrt((1.0 / x)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.74d0) then
tmp = (-1.0d0) + (((-0.375d0) * (x * x)) + ((x ** (-0.5d0)) + (x * 0.5d0)))
else
tmp = (((-1.0d0) / x) / ((-1.0d0) - x)) / (2.0d0 * sqrt((1.0d0 / x)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.74) {
tmp = -1.0 + ((-0.375 * (x * x)) + (Math.pow(x, -0.5) + (x * 0.5)));
} else {
tmp = ((-1.0 / x) / (-1.0 - x)) / (2.0 * Math.sqrt((1.0 / x)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.74: tmp = -1.0 + ((-0.375 * (x * x)) + (math.pow(x, -0.5) + (x * 0.5))) else: tmp = ((-1.0 / x) / (-1.0 - x)) / (2.0 * math.sqrt((1.0 / x))) return tmp
function code(x) tmp = 0.0 if (x <= 0.74) tmp = Float64(-1.0 + Float64(Float64(-0.375 * Float64(x * x)) + Float64((x ^ -0.5) + Float64(x * 0.5)))); else tmp = Float64(Float64(Float64(-1.0 / x) / Float64(-1.0 - x)) / Float64(2.0 * sqrt(Float64(1.0 / x)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.74) tmp = -1.0 + ((-0.375 * (x * x)) + ((x ^ -0.5) + (x * 0.5))); else tmp = ((-1.0 / x) / (-1.0 - x)) / (2.0 * sqrt((1.0 / x))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.74], N[(-1.0 + N[(N[(-0.375 * N[(x * x), $MachinePrecision]), $MachinePrecision] + N[(N[Power[x, -0.5], $MachinePrecision] + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(-1.0 / x), $MachinePrecision] / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision] / N[(2.0 * N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.74:\\
\;\;\;\;-1 + \left(-0.375 \cdot \left(x \cdot x\right) + \left({x}^{-0.5} + x \cdot 0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\frac{-1}{x}}{-1 - x}}{2 \cdot \sqrt{\frac{1}{x}}}\\
\end{array}
\end{array}
if x < 0.73999999999999999Initial 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 100.0%
unpow2100.0%
Applied egg-rr100.0%
if 0.73999999999999999 < x Initial program 39.4%
flip--39.5%
frac-times28.1%
metadata-eval28.1%
add-sqr-sqrt22.2%
frac-times24.1%
metadata-eval24.1%
add-sqr-sqrt39.6%
+-commutative39.6%
pow1/239.6%
pow-flip39.6%
metadata-eval39.6%
inv-pow39.6%
sqrt-pow239.6%
+-commutative39.6%
metadata-eval39.6%
Applied egg-rr39.6%
Taylor expanded in x around inf 38.2%
frac-2neg38.2%
metadata-eval38.2%
frac-sub38.3%
*-un-lft-identity38.3%
distribute-neg-in38.3%
metadata-eval38.3%
distribute-neg-in38.3%
metadata-eval38.3%
Applied egg-rr38.3%
associate-/r*38.3%
associate--l+81.9%
*-commutative81.9%
neg-mul-181.9%
+-inverses81.9%
metadata-eval81.9%
unsub-neg81.9%
Simplified81.9%
Final simplification90.5%
(FPCore (x) :precision binary64 (if (<= x 0.66) (- (pow x -0.5) (+ 1.0 (* x -0.5))) (* (sqrt x) (* 0.5 (+ (/ 1.0 x) (/ -1.0 (+ 1.0 x)))))))
double code(double x) {
double tmp;
if (x <= 0.66) {
tmp = pow(x, -0.5) - (1.0 + (x * -0.5));
} else {
tmp = sqrt(x) * (0.5 * ((1.0 / x) + (-1.0 / (1.0 + x))));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.66d0) then
tmp = (x ** (-0.5d0)) - (1.0d0 + (x * (-0.5d0)))
else
tmp = sqrt(x) * (0.5d0 * ((1.0d0 / x) + ((-1.0d0) / (1.0d0 + x))))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.66) {
tmp = Math.pow(x, -0.5) - (1.0 + (x * -0.5));
} else {
tmp = Math.sqrt(x) * (0.5 * ((1.0 / x) + (-1.0 / (1.0 + x))));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.66: tmp = math.pow(x, -0.5) - (1.0 + (x * -0.5)) else: tmp = math.sqrt(x) * (0.5 * ((1.0 / x) + (-1.0 / (1.0 + x)))) return tmp
function code(x) tmp = 0.0 if (x <= 0.66) tmp = Float64((x ^ -0.5) - Float64(1.0 + Float64(x * -0.5))); else tmp = Float64(sqrt(x) * Float64(0.5 * Float64(Float64(1.0 / x) + Float64(-1.0 / Float64(1.0 + x))))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.66) tmp = (x ^ -0.5) - (1.0 + (x * -0.5)); else tmp = sqrt(x) * (0.5 * ((1.0 / x) + (-1.0 / (1.0 + x)))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.66], N[(N[Power[x, -0.5], $MachinePrecision] - N[(1.0 + N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[x], $MachinePrecision] * N[(0.5 * N[(N[(1.0 / x), $MachinePrecision] + N[(-1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.66:\\
\;\;\;\;{x}^{-0.5} - \left(1 + x \cdot -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x} \cdot \left(0.5 \cdot \left(\frac{1}{x} + \frac{-1}{1 + x}\right)\right)\\
\end{array}
\end{array}
if x < 0.660000000000000031Initial 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 99.9%
*-commutative99.9%
Simplified99.9%
if 0.660000000000000031 < x Initial program 39.4%
flip--39.5%
frac-times28.1%
metadata-eval28.1%
add-sqr-sqrt22.2%
frac-times24.1%
metadata-eval24.1%
add-sqr-sqrt39.6%
+-commutative39.6%
pow1/239.6%
pow-flip39.6%
metadata-eval39.6%
inv-pow39.6%
sqrt-pow239.6%
+-commutative39.6%
metadata-eval39.6%
Applied egg-rr39.6%
Taylor expanded in x around inf 38.2%
expm1-log1p-u38.2%
expm1-udef37.4%
sub-neg37.4%
distribute-neg-frac37.4%
metadata-eval37.4%
sqrt-div37.4%
metadata-eval37.4%
un-div-inv37.4%
Applied egg-rr37.4%
expm1-def38.2%
expm1-log1p38.2%
associate-/r/38.2%
metadata-eval38.2%
associate-/l*38.2%
/-rgt-identity38.2%
*-commutative38.2%
*-commutative38.2%
Simplified38.2%
Final simplification67.4%
(FPCore (x) :precision binary64 (if (<= x 0.66) (- (pow x -0.5) (+ 1.0 (* x -0.5))) (/ (/ (/ -1.0 x) (- -1.0 x)) (* 2.0 (sqrt (/ 1.0 x))))))
double code(double x) {
double tmp;
if (x <= 0.66) {
tmp = pow(x, -0.5) - (1.0 + (x * -0.5));
} else {
tmp = ((-1.0 / x) / (-1.0 - x)) / (2.0 * sqrt((1.0 / x)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.66d0) then
tmp = (x ** (-0.5d0)) - (1.0d0 + (x * (-0.5d0)))
else
tmp = (((-1.0d0) / x) / ((-1.0d0) - x)) / (2.0d0 * sqrt((1.0d0 / x)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.66) {
tmp = Math.pow(x, -0.5) - (1.0 + (x * -0.5));
} else {
tmp = ((-1.0 / x) / (-1.0 - x)) / (2.0 * Math.sqrt((1.0 / x)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.66: tmp = math.pow(x, -0.5) - (1.0 + (x * -0.5)) else: tmp = ((-1.0 / x) / (-1.0 - x)) / (2.0 * math.sqrt((1.0 / x))) return tmp
function code(x) tmp = 0.0 if (x <= 0.66) tmp = Float64((x ^ -0.5) - Float64(1.0 + Float64(x * -0.5))); else tmp = Float64(Float64(Float64(-1.0 / x) / Float64(-1.0 - x)) / Float64(2.0 * sqrt(Float64(1.0 / x)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.66) tmp = (x ^ -0.5) - (1.0 + (x * -0.5)); else tmp = ((-1.0 / x) / (-1.0 - x)) / (2.0 * sqrt((1.0 / x))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.66], N[(N[Power[x, -0.5], $MachinePrecision] - N[(1.0 + N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(-1.0 / x), $MachinePrecision] / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision] / N[(2.0 * N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.66:\\
\;\;\;\;{x}^{-0.5} - \left(1 + x \cdot -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\frac{-1}{x}}{-1 - x}}{2 \cdot \sqrt{\frac{1}{x}}}\\
\end{array}
\end{array}
if x < 0.660000000000000031Initial 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 99.9%
*-commutative99.9%
Simplified99.9%
if 0.660000000000000031 < x Initial program 39.4%
flip--39.5%
frac-times28.1%
metadata-eval28.1%
add-sqr-sqrt22.2%
frac-times24.1%
metadata-eval24.1%
add-sqr-sqrt39.6%
+-commutative39.6%
pow1/239.6%
pow-flip39.6%
metadata-eval39.6%
inv-pow39.6%
sqrt-pow239.6%
+-commutative39.6%
metadata-eval39.6%
Applied egg-rr39.6%
Taylor expanded in x around inf 38.2%
frac-2neg38.2%
metadata-eval38.2%
frac-sub38.3%
*-un-lft-identity38.3%
distribute-neg-in38.3%
metadata-eval38.3%
distribute-neg-in38.3%
metadata-eval38.3%
Applied egg-rr38.3%
associate-/r*38.3%
associate--l+81.9%
*-commutative81.9%
neg-mul-181.9%
+-inverses81.9%
metadata-eval81.9%
unsub-neg81.9%
Simplified81.9%
Final simplification90.4%
(FPCore (x) :precision binary64 (/ 1.0 (+ x (pow x 0.5))))
double code(double x) {
return 1.0 / (x + pow(x, 0.5));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (x + (x ** 0.5d0))
end function
public static double code(double x) {
return 1.0 / (x + Math.pow(x, 0.5));
}
def code(x): return 1.0 / (x + math.pow(x, 0.5))
function code(x) return Float64(1.0 / Float64(x + (x ^ 0.5))) end
function tmp = code(x) tmp = 1.0 / (x + (x ^ 0.5)); end
code[x_] := N[(1.0 / N[(x + N[Power[x, 0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x + {x}^{0.5}}
\end{array}
Initial program 67.9%
flip--67.9%
frac-times61.7%
metadata-eval61.7%
add-sqr-sqrt58.6%
frac-times59.6%
metadata-eval59.6%
add-sqr-sqrt67.8%
+-commutative67.8%
pow1/267.8%
pow-flip67.7%
metadata-eval67.7%
inv-pow67.7%
sqrt-pow267.7%
+-commutative67.7%
metadata-eval67.7%
Applied egg-rr67.7%
Taylor expanded in x around 0 50.5%
distribute-rgt-in50.5%
*-lft-identity50.5%
pow-plus50.6%
metadata-eval50.6%
Simplified50.6%
Final simplification50.6%
(FPCore (x) :precision binary64 (+ -1.0 (pow x -0.5)))
double code(double x) {
return -1.0 + pow(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 + Math.pow(x, -0.5);
}
def code(x): return -1.0 + math.pow(x, -0.5)
function code(x) return Float64(-1.0 + (x ^ -0.5)) end
function tmp = code(x) tmp = -1.0 + (x ^ -0.5); end
code[x_] := N[(-1.0 + N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-1 + {x}^{-0.5}
\end{array}
Initial program 67.9%
*-un-lft-identity67.9%
clear-num67.9%
associate-/r/67.9%
prod-diff67.9%
*-un-lft-identity67.9%
fma-neg67.9%
*-un-lft-identity67.9%
pow1/267.9%
pow-flip62.3%
metadata-eval62.3%
pow1/262.3%
pow-flip68.0%
+-commutative68.0%
metadata-eval68.0%
Applied egg-rr68.0%
associate-+l-68.0%
expm1-log1p68.0%
expm1-def51.6%
associate--l-51.6%
fma-udef51.6%
distribute-lft1-in51.6%
metadata-eval51.6%
mul0-lft51.6%
metadata-eval51.6%
expm1-def68.0%
expm1-log1p68.0%
Simplified68.0%
Taylor expanded in x around 0 48.4%
Final simplification48.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 Float64(-(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 67.9%
pow1/267.9%
pow-to-exp51.5%
+-commutative51.5%
log1p-udef51.5%
Applied egg-rr51.5%
Taylor expanded in x around inf 2.2%
mul-1-neg2.2%
Simplified2.2%
inv-pow2.2%
sqrt-pow12.2%
metadata-eval2.2%
expm1-log1p-u2.2%
expm1-udef19.1%
Applied egg-rr19.1%
expm1-def2.2%
expm1-log1p2.2%
Simplified2.2%
Final simplification2.2%
(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 2023339
(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)))))