
(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
(if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 (sqrt (+ 1.0 x)))) 1e-5)
(*
(-
(+ (/ 0.5 x) (/ 0.3125 (pow x 3.0)))
(+ (/ 0.375 (* x x)) (/ 0.2734375 (pow x 4.0))))
(pow x -0.5))
(* (pow x -0.5) (- 1.0 (sqrt (/ x (+ 1.0 x)))))))
double code(double x) {
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / sqrt((1.0 + x)))) <= 1e-5) {
tmp = (((0.5 / x) + (0.3125 / pow(x, 3.0))) - ((0.375 / (x * x)) + (0.2734375 / pow(x, 4.0)))) * pow(x, -0.5);
} else {
tmp = pow(x, -0.5) * (1.0 - sqrt((x / (1.0 + x))));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (((1.0d0 / sqrt(x)) + ((-1.0d0) / sqrt((1.0d0 + x)))) <= 1d-5) then
tmp = (((0.5d0 / x) + (0.3125d0 / (x ** 3.0d0))) - ((0.375d0 / (x * x)) + (0.2734375d0 / (x ** 4.0d0)))) * (x ** (-0.5d0))
else
tmp = (x ** (-0.5d0)) * (1.0d0 - sqrt((x / (1.0d0 + x))))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (((1.0 / Math.sqrt(x)) + (-1.0 / Math.sqrt((1.0 + x)))) <= 1e-5) {
tmp = (((0.5 / x) + (0.3125 / Math.pow(x, 3.0))) - ((0.375 / (x * x)) + (0.2734375 / Math.pow(x, 4.0)))) * Math.pow(x, -0.5);
} else {
tmp = Math.pow(x, -0.5) * (1.0 - Math.sqrt((x / (1.0 + x))));
}
return tmp;
}
def code(x): tmp = 0 if ((1.0 / math.sqrt(x)) + (-1.0 / math.sqrt((1.0 + x)))) <= 1e-5: tmp = (((0.5 / x) + (0.3125 / math.pow(x, 3.0))) - ((0.375 / (x * x)) + (0.2734375 / math.pow(x, 4.0)))) * math.pow(x, -0.5) else: tmp = math.pow(x, -0.5) * (1.0 - math.sqrt((x / (1.0 + x)))) return tmp
function code(x) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / sqrt(Float64(1.0 + x)))) <= 1e-5) tmp = Float64(Float64(Float64(Float64(0.5 / x) + Float64(0.3125 / (x ^ 3.0))) - Float64(Float64(0.375 / Float64(x * x)) + Float64(0.2734375 / (x ^ 4.0)))) * (x ^ -0.5)); else tmp = Float64((x ^ -0.5) * Float64(1.0 - sqrt(Float64(x / Float64(1.0 + x))))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (((1.0 / sqrt(x)) + (-1.0 / sqrt((1.0 + x)))) <= 1e-5) tmp = (((0.5 / x) + (0.3125 / (x ^ 3.0))) - ((0.375 / (x * x)) + (0.2734375 / (x ^ 4.0)))) * (x ^ -0.5); else tmp = (x ^ -0.5) * (1.0 - sqrt((x / (1.0 + x)))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1e-5], N[(N[(N[(N[(0.5 / x), $MachinePrecision] + N[(0.3125 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(0.375 / N[(x * x), $MachinePrecision]), $MachinePrecision] + N[(0.2734375 / N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] * N[(1.0 - N[Sqrt[N[(x / N[(1.0 + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{1 + x}} \leq 10^{-5}:\\
\;\;\;\;\left(\left(\frac{0.5}{x} + \frac{0.3125}{{x}^{3}}\right) - \left(\frac{0.375}{x \cdot x} + \frac{0.2734375}{{x}^{4}}\right)\right) \cdot {x}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} \cdot \left(1 - \sqrt{\frac{x}{1 + x}}\right)\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 1.00000000000000008e-5Initial program 41.4%
frac-sub41.4%
div-inv41.4%
*-un-lft-identity41.4%
+-commutative41.4%
*-rgt-identity41.4%
metadata-eval41.4%
frac-times41.4%
un-div-inv41.4%
pow1/241.4%
pow-flip41.4%
metadata-eval41.4%
+-commutative41.4%
Applied egg-rr41.4%
associate-*r/41.4%
*-rgt-identity41.4%
times-frac41.4%
div-sub41.4%
*-inverses41.4%
/-rgt-identity41.4%
Simplified41.4%
Taylor expanded in x around inf 99.7%
associate-*r/99.7%
metadata-eval99.7%
associate-*r/99.7%
metadata-eval99.7%
+-commutative99.7%
associate-*r/99.7%
metadata-eval99.7%
unpow299.7%
associate-*r/99.7%
metadata-eval99.7%
Simplified99.7%
if 1.00000000000000008e-5 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.6%
frac-sub99.6%
div-inv99.5%
*-un-lft-identity99.5%
+-commutative99.5%
*-rgt-identity99.5%
metadata-eval99.5%
frac-times99.5%
un-div-inv99.6%
pow1/299.6%
pow-flip99.9%
metadata-eval99.9%
+-commutative99.9%
Applied egg-rr99.9%
associate-*r/99.9%
*-rgt-identity99.9%
times-frac99.9%
div-sub99.9%
*-inverses99.9%
/-rgt-identity99.9%
Simplified99.9%
*-un-lft-identity99.9%
sqrt-undiv99.9%
Applied egg-rr99.9%
*-lft-identity99.9%
Simplified99.9%
Final simplification99.8%
(FPCore (x) :precision binary64 (if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 (sqrt (+ 1.0 x)))) 5e-20) (* (pow x -0.5) (- (/ 0.5 x) (/ 0.375 (* x x)))) (* (pow x -0.5) (- 1.0 (sqrt (/ x (+ 1.0 x)))))))
double code(double x) {
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / sqrt((1.0 + x)))) <= 5e-20) {
tmp = pow(x, -0.5) * ((0.5 / x) - (0.375 / (x * x)));
} else {
tmp = pow(x, -0.5) * (1.0 - sqrt((x / (1.0 + x))));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (((1.0d0 / sqrt(x)) + ((-1.0d0) / sqrt((1.0d0 + x)))) <= 5d-20) then
tmp = (x ** (-0.5d0)) * ((0.5d0 / x) - (0.375d0 / (x * x)))
else
tmp = (x ** (-0.5d0)) * (1.0d0 - sqrt((x / (1.0d0 + x))))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (((1.0 / Math.sqrt(x)) + (-1.0 / Math.sqrt((1.0 + x)))) <= 5e-20) {
tmp = Math.pow(x, -0.5) * ((0.5 / x) - (0.375 / (x * x)));
} else {
tmp = Math.pow(x, -0.5) * (1.0 - Math.sqrt((x / (1.0 + x))));
}
return tmp;
}
def code(x): tmp = 0 if ((1.0 / math.sqrt(x)) + (-1.0 / math.sqrt((1.0 + x)))) <= 5e-20: tmp = math.pow(x, -0.5) * ((0.5 / x) - (0.375 / (x * x))) else: tmp = math.pow(x, -0.5) * (1.0 - math.sqrt((x / (1.0 + x)))) return tmp
function code(x) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / sqrt(Float64(1.0 + x)))) <= 5e-20) tmp = Float64((x ^ -0.5) * Float64(Float64(0.5 / x) - Float64(0.375 / Float64(x * x)))); else tmp = Float64((x ^ -0.5) * Float64(1.0 - sqrt(Float64(x / Float64(1.0 + x))))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (((1.0 / sqrt(x)) + (-1.0 / sqrt((1.0 + x)))) <= 5e-20) tmp = (x ^ -0.5) * ((0.5 / x) - (0.375 / (x * x))); else tmp = (x ^ -0.5) * (1.0 - sqrt((x / (1.0 + x)))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e-20], N[(N[Power[x, -0.5], $MachinePrecision] * N[(N[(0.5 / x), $MachinePrecision] - N[(0.375 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] * N[(1.0 - N[Sqrt[N[(x / N[(1.0 + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{1 + x}} \leq 5 \cdot 10^{-20}:\\
\;\;\;\;{x}^{-0.5} \cdot \left(\frac{0.5}{x} - \frac{0.375}{x \cdot x}\right)\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} \cdot \left(1 - \sqrt{\frac{x}{1 + x}}\right)\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 4.9999999999999999e-20Initial program 41.1%
frac-sub41.1%
div-inv41.1%
*-un-lft-identity41.1%
+-commutative41.1%
*-rgt-identity41.1%
metadata-eval41.1%
frac-times41.1%
un-div-inv41.1%
pow1/241.1%
pow-flip41.1%
metadata-eval41.1%
+-commutative41.1%
Applied egg-rr41.1%
associate-*r/41.1%
*-rgt-identity41.1%
times-frac41.1%
div-sub41.1%
*-inverses41.1%
/-rgt-identity41.1%
Simplified41.1%
Taylor expanded in x around inf 99.8%
associate-*r/99.8%
metadata-eval99.8%
associate-*r/99.8%
metadata-eval99.8%
unpow299.8%
Simplified99.8%
if 4.9999999999999999e-20 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.4%
frac-sub99.4%
div-inv99.4%
*-un-lft-identity99.4%
+-commutative99.4%
*-rgt-identity99.4%
metadata-eval99.4%
frac-times99.4%
un-div-inv99.4%
pow1/299.4%
pow-flip99.8%
metadata-eval99.8%
+-commutative99.8%
Applied egg-rr99.8%
associate-*r/99.7%
*-rgt-identity99.7%
times-frac99.8%
div-sub99.8%
*-inverses99.8%
/-rgt-identity99.8%
Simplified99.8%
*-un-lft-identity99.8%
sqrt-undiv99.8%
Applied egg-rr99.8%
*-lft-identity99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x) :precision binary64 (if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 (sqrt (+ 1.0 x)))) 5e-20) (* (pow x -0.5) (- (/ 0.5 x) (/ 0.375 (* x x)))) (- (pow x -0.5) (pow (+ 1.0 x) -0.5))))
double code(double x) {
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / sqrt((1.0 + x)))) <= 5e-20) {
tmp = pow(x, -0.5) * ((0.5 / x) - (0.375 / (x * x)));
} else {
tmp = pow(x, -0.5) - pow((1.0 + x), -0.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (((1.0d0 / sqrt(x)) + ((-1.0d0) / sqrt((1.0d0 + x)))) <= 5d-20) then
tmp = (x ** (-0.5d0)) * ((0.5d0 / x) - (0.375d0 / (x * x)))
else
tmp = (x ** (-0.5d0)) - ((1.0d0 + x) ** (-0.5d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (((1.0 / Math.sqrt(x)) + (-1.0 / Math.sqrt((1.0 + x)))) <= 5e-20) {
tmp = Math.pow(x, -0.5) * ((0.5 / x) - (0.375 / (x * x)));
} else {
tmp = Math.pow(x, -0.5) - Math.pow((1.0 + x), -0.5);
}
return tmp;
}
def code(x): tmp = 0 if ((1.0 / math.sqrt(x)) + (-1.0 / math.sqrt((1.0 + x)))) <= 5e-20: tmp = math.pow(x, -0.5) * ((0.5 / x) - (0.375 / (x * x))) else: tmp = math.pow(x, -0.5) - math.pow((1.0 + x), -0.5) return tmp
function code(x) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / sqrt(Float64(1.0 + x)))) <= 5e-20) tmp = Float64((x ^ -0.5) * Float64(Float64(0.5 / x) - Float64(0.375 / Float64(x * x)))); else tmp = Float64((x ^ -0.5) - (Float64(1.0 + x) ^ -0.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (((1.0 / sqrt(x)) + (-1.0 / sqrt((1.0 + x)))) <= 5e-20) tmp = (x ^ -0.5) * ((0.5 / x) - (0.375 / (x * x))); else tmp = (x ^ -0.5) - ((1.0 + x) ^ -0.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e-20], N[(N[Power[x, -0.5], $MachinePrecision] * N[(N[(0.5 / x), $MachinePrecision] - N[(0.375 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{1 + x}} \leq 5 \cdot 10^{-20}:\\
\;\;\;\;{x}^{-0.5} \cdot \left(\frac{0.5}{x} - \frac{0.375}{x \cdot x}\right)\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 4.9999999999999999e-20Initial program 41.1%
frac-sub41.1%
div-inv41.1%
*-un-lft-identity41.1%
+-commutative41.1%
*-rgt-identity41.1%
metadata-eval41.1%
frac-times41.1%
un-div-inv41.1%
pow1/241.1%
pow-flip41.1%
metadata-eval41.1%
+-commutative41.1%
Applied egg-rr41.1%
associate-*r/41.1%
*-rgt-identity41.1%
times-frac41.1%
div-sub41.1%
*-inverses41.1%
/-rgt-identity41.1%
Simplified41.1%
Taylor expanded in x around inf 99.8%
associate-*r/99.8%
metadata-eval99.8%
associate-*r/99.8%
metadata-eval99.8%
unpow299.8%
Simplified99.8%
if 4.9999999999999999e-20 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.4%
*-un-lft-identity99.4%
clear-num99.4%
associate-/r/99.4%
prod-diff99.4%
*-un-lft-identity99.4%
fma-neg99.4%
*-un-lft-identity99.4%
inv-pow99.4%
sqrt-pow299.8%
metadata-eval99.8%
pow1/299.8%
pow-flip99.8%
+-commutative99.8%
metadata-eval99.8%
Applied egg-rr99.8%
fma-udef99.8%
distribute-lft1-in99.8%
metadata-eval99.8%
mul0-lft99.8%
+-rgt-identity99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x) :precision binary64 (if (<= x 1.4) (+ (pow x -0.5) (/ -1.0 (+ 1.0 (* x 0.5)))) (* (pow x -0.5) (- (/ 0.5 x) (/ 0.375 (* x x))))))
double code(double x) {
double tmp;
if (x <= 1.4) {
tmp = pow(x, -0.5) + (-1.0 / (1.0 + (x * 0.5)));
} else {
tmp = pow(x, -0.5) * ((0.5 / x) - (0.375 / (x * x)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.4d0) then
tmp = (x ** (-0.5d0)) + ((-1.0d0) / (1.0d0 + (x * 0.5d0)))
else
tmp = (x ** (-0.5d0)) * ((0.5d0 / x) - (0.375d0 / (x * x)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.4) {
tmp = Math.pow(x, -0.5) + (-1.0 / (1.0 + (x * 0.5)));
} else {
tmp = Math.pow(x, -0.5) * ((0.5 / x) - (0.375 / (x * x)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.4: tmp = math.pow(x, -0.5) + (-1.0 / (1.0 + (x * 0.5))) else: tmp = math.pow(x, -0.5) * ((0.5 / x) - (0.375 / (x * x))) return tmp
function code(x) tmp = 0.0 if (x <= 1.4) tmp = Float64((x ^ -0.5) + Float64(-1.0 / Float64(1.0 + Float64(x * 0.5)))); else tmp = Float64((x ^ -0.5) * Float64(Float64(0.5 / x) - Float64(0.375 / Float64(x * x)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.4) tmp = (x ^ -0.5) + (-1.0 / (1.0 + (x * 0.5))); else tmp = (x ^ -0.5) * ((0.5 / x) - (0.375 / (x * x))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.4], N[(N[Power[x, -0.5], $MachinePrecision] + N[(-1.0 / N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] * N[(N[(0.5 / x), $MachinePrecision] - N[(0.375 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.4:\\
\;\;\;\;{x}^{-0.5} + \frac{-1}{1 + x \cdot 0.5}\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} \cdot \left(\frac{0.5}{x} - \frac{0.375}{x \cdot x}\right)\\
\end{array}
\end{array}
if x < 1.3999999999999999Initial program 99.7%
Taylor expanded in x around 0 97.6%
add-log-exp5.5%
*-un-lft-identity5.5%
log-prod5.5%
metadata-eval5.5%
add-log-exp96.5%
pow1/296.5%
pow-flip96.8%
metadata-eval96.8%
Applied egg-rr97.9%
+-lft-identity96.8%
Simplified97.9%
if 1.3999999999999999 < x Initial program 42.2%
frac-sub42.2%
div-inv42.2%
*-un-lft-identity42.2%
+-commutative42.2%
*-rgt-identity42.2%
metadata-eval42.2%
frac-times42.2%
un-div-inv42.2%
pow1/242.2%
pow-flip42.2%
metadata-eval42.2%
+-commutative42.2%
Applied egg-rr42.2%
associate-*r/42.2%
*-rgt-identity42.2%
times-frac42.2%
div-sub42.2%
*-inverses42.2%
/-rgt-identity42.2%
Simplified42.2%
Taylor expanded in x around inf 98.4%
associate-*r/98.4%
metadata-eval98.4%
associate-*r/98.4%
metadata-eval98.4%
unpow298.4%
Simplified98.4%
Final simplification98.1%
(FPCore (x) :precision binary64 (if (<= x 1.7) (+ (pow x -0.5) (/ -1.0 (+ 1.0 (* x 0.5)))) (/ (pow x -0.5) (* x 2.0))))
double code(double x) {
double tmp;
if (x <= 1.7) {
tmp = pow(x, -0.5) + (-1.0 / (1.0 + (x * 0.5)));
} else {
tmp = pow(x, -0.5) / (x * 2.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.7d0) then
tmp = (x ** (-0.5d0)) + ((-1.0d0) / (1.0d0 + (x * 0.5d0)))
else
tmp = (x ** (-0.5d0)) / (x * 2.0d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.7) {
tmp = Math.pow(x, -0.5) + (-1.0 / (1.0 + (x * 0.5)));
} else {
tmp = Math.pow(x, -0.5) / (x * 2.0);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.7: tmp = math.pow(x, -0.5) + (-1.0 / (1.0 + (x * 0.5))) else: tmp = math.pow(x, -0.5) / (x * 2.0) return tmp
function code(x) tmp = 0.0 if (x <= 1.7) tmp = Float64((x ^ -0.5) + Float64(-1.0 / Float64(1.0 + Float64(x * 0.5)))); else tmp = Float64((x ^ -0.5) / Float64(x * 2.0)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.7) tmp = (x ^ -0.5) + (-1.0 / (1.0 + (x * 0.5))); else tmp = (x ^ -0.5) / (x * 2.0); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.7], N[(N[Power[x, -0.5], $MachinePrecision] + N[(-1.0 / N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] / N[(x * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.7:\\
\;\;\;\;{x}^{-0.5} + \frac{-1}{1 + x \cdot 0.5}\\
\mathbf{else}:\\
\;\;\;\;\frac{{x}^{-0.5}}{x \cdot 2}\\
\end{array}
\end{array}
if x < 1.69999999999999996Initial program 99.7%
Taylor expanded in x around 0 97.6%
add-log-exp5.5%
*-un-lft-identity5.5%
log-prod5.5%
metadata-eval5.5%
add-log-exp96.5%
pow1/296.5%
pow-flip96.8%
metadata-eval96.8%
Applied egg-rr97.9%
+-lft-identity96.8%
Simplified97.9%
if 1.69999999999999996 < x Initial program 42.2%
frac-sub42.2%
div-inv42.2%
*-un-lft-identity42.2%
+-commutative42.2%
*-rgt-identity42.2%
metadata-eval42.2%
frac-times42.2%
un-div-inv42.2%
pow1/242.2%
pow-flip42.2%
metadata-eval42.2%
+-commutative42.2%
Applied egg-rr42.2%
associate-*r/42.2%
*-rgt-identity42.2%
times-frac42.2%
div-sub42.2%
*-inverses42.2%
/-rgt-identity42.2%
Simplified42.2%
Taylor expanded in x around inf 97.9%
metadata-eval97.9%
pow-flip97.9%
pow1/297.9%
clear-num97.9%
associate-*l/97.9%
*-un-lft-identity97.9%
inv-pow97.9%
sqrt-pow298.0%
metadata-eval98.0%
div-inv98.0%
metadata-eval98.0%
Applied egg-rr98.0%
Final simplification97.9%
(FPCore (x) :precision binary64 (if (<= x 1.0) (+ (+ (pow x -0.5) (* x 0.5)) -1.0) (/ (pow x -0.5) (* x 2.0))))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = (pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = pow(x, -0.5) / (x * 2.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.0d0) then
tmp = ((x ** (-0.5d0)) + (x * 0.5d0)) + (-1.0d0)
else
tmp = (x ** (-0.5d0)) / (x * 2.0d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = (Math.pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = Math.pow(x, -0.5) / (x * 2.0);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = (math.pow(x, -0.5) + (x * 0.5)) + -1.0 else: tmp = math.pow(x, -0.5) / (x * 2.0) return tmp
function code(x) tmp = 0.0 if (x <= 1.0) tmp = Float64(Float64((x ^ -0.5) + Float64(x * 0.5)) + -1.0); else tmp = Float64((x ^ -0.5) / Float64(x * 2.0)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.0) tmp = ((x ^ -0.5) + (x * 0.5)) + -1.0; else tmp = (x ^ -0.5) / (x * 2.0); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], N[(N[(N[Power[x, -0.5], $MachinePrecision] + N[(x * 0.5), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] / N[(x * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;\left({x}^{-0.5} + x \cdot 0.5\right) + -1\\
\mathbf{else}:\\
\;\;\;\;\frac{{x}^{-0.5}}{x \cdot 2}\\
\end{array}
\end{array}
if x < 1Initial program 99.7%
*-un-lft-identity99.7%
clear-num99.7%
associate-/r/99.7%
prod-diff99.7%
*-un-lft-identity99.7%
fma-neg99.7%
*-un-lft-identity99.7%
inv-pow99.7%
sqrt-pow2100.0%
metadata-eval100.0%
pow1/2100.0%
pow-flip100.0%
+-commutative100.0%
metadata-eval100.0%
Applied egg-rr100.0%
fma-udef100.0%
distribute-lft1-in100.0%
metadata-eval100.0%
mul0-lft100.0%
+-rgt-identity100.0%
Simplified100.0%
Taylor expanded in x around 0 97.8%
if 1 < x Initial program 42.2%
frac-sub42.2%
div-inv42.2%
*-un-lft-identity42.2%
+-commutative42.2%
*-rgt-identity42.2%
metadata-eval42.2%
frac-times42.2%
un-div-inv42.2%
pow1/242.2%
pow-flip42.2%
metadata-eval42.2%
+-commutative42.2%
Applied egg-rr42.2%
associate-*r/42.2%
*-rgt-identity42.2%
times-frac42.2%
div-sub42.2%
*-inverses42.2%
/-rgt-identity42.2%
Simplified42.2%
Taylor expanded in x around inf 97.9%
metadata-eval97.9%
pow-flip97.9%
pow1/297.9%
clear-num97.9%
associate-*l/97.9%
*-un-lft-identity97.9%
inv-pow97.9%
sqrt-pow298.0%
metadata-eval98.0%
div-inv98.0%
metadata-eval98.0%
Applied egg-rr98.0%
Final simplification97.9%
(FPCore (x) :precision binary64 (if (<= x 0.66) (+ (pow x -0.5) -1.0) (* (/ 0.5 x) (pow x -0.5))))
double code(double x) {
double tmp;
if (x <= 0.66) {
tmp = pow(x, -0.5) + -1.0;
} else {
tmp = (0.5 / x) * pow(x, -0.5);
}
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)
else
tmp = (0.5d0 / x) * (x ** (-0.5d0))
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;
} else {
tmp = (0.5 / x) * Math.pow(x, -0.5);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.66: tmp = math.pow(x, -0.5) + -1.0 else: tmp = (0.5 / x) * math.pow(x, -0.5) return tmp
function code(x) tmp = 0.0 if (x <= 0.66) tmp = Float64((x ^ -0.5) + -1.0); else tmp = Float64(Float64(0.5 / x) * (x ^ -0.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.66) tmp = (x ^ -0.5) + -1.0; else tmp = (0.5 / x) * (x ^ -0.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.66], N[(N[Power[x, -0.5], $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(0.5 / x), $MachinePrecision] * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.66:\\
\;\;\;\;{x}^{-0.5} + -1\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{x} \cdot {x}^{-0.5}\\
\end{array}
\end{array}
if x < 0.660000000000000031Initial program 99.7%
Taylor expanded in x around 0 96.5%
add-log-exp5.5%
*-un-lft-identity5.5%
log-prod5.5%
metadata-eval5.5%
add-log-exp96.5%
pow1/296.5%
pow-flip96.8%
metadata-eval96.8%
Applied egg-rr96.8%
+-lft-identity96.8%
Simplified96.8%
if 0.660000000000000031 < x Initial program 42.2%
frac-sub42.2%
div-inv42.2%
*-un-lft-identity42.2%
+-commutative42.2%
*-rgt-identity42.2%
metadata-eval42.2%
frac-times42.2%
un-div-inv42.2%
pow1/242.2%
pow-flip42.2%
metadata-eval42.2%
+-commutative42.2%
Applied egg-rr42.2%
associate-*r/42.2%
*-rgt-identity42.2%
times-frac42.2%
div-sub42.2%
*-inverses42.2%
/-rgt-identity42.2%
Simplified42.2%
Taylor expanded in x around inf 97.9%
Final simplification97.4%
(FPCore (x) :precision binary64 (if (<= x 0.66) (+ (pow x -0.5) -1.0) (/ (pow x -0.5) (* x 2.0))))
double code(double x) {
double tmp;
if (x <= 0.66) {
tmp = pow(x, -0.5) + -1.0;
} else {
tmp = pow(x, -0.5) / (x * 2.0);
}
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)
else
tmp = (x ** (-0.5d0)) / (x * 2.0d0)
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;
} else {
tmp = Math.pow(x, -0.5) / (x * 2.0);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.66: tmp = math.pow(x, -0.5) + -1.0 else: tmp = math.pow(x, -0.5) / (x * 2.0) return tmp
function code(x) tmp = 0.0 if (x <= 0.66) tmp = Float64((x ^ -0.5) + -1.0); else tmp = Float64((x ^ -0.5) / Float64(x * 2.0)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.66) tmp = (x ^ -0.5) + -1.0; else tmp = (x ^ -0.5) / (x * 2.0); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.66], N[(N[Power[x, -0.5], $MachinePrecision] + -1.0), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] / N[(x * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.66:\\
\;\;\;\;{x}^{-0.5} + -1\\
\mathbf{else}:\\
\;\;\;\;\frac{{x}^{-0.5}}{x \cdot 2}\\
\end{array}
\end{array}
if x < 0.660000000000000031Initial program 99.7%
Taylor expanded in x around 0 96.5%
add-log-exp5.5%
*-un-lft-identity5.5%
log-prod5.5%
metadata-eval5.5%
add-log-exp96.5%
pow1/296.5%
pow-flip96.8%
metadata-eval96.8%
Applied egg-rr96.8%
+-lft-identity96.8%
Simplified96.8%
if 0.660000000000000031 < x Initial program 42.2%
frac-sub42.2%
div-inv42.2%
*-un-lft-identity42.2%
+-commutative42.2%
*-rgt-identity42.2%
metadata-eval42.2%
frac-times42.2%
un-div-inv42.2%
pow1/242.2%
pow-flip42.2%
metadata-eval42.2%
+-commutative42.2%
Applied egg-rr42.2%
associate-*r/42.2%
*-rgt-identity42.2%
times-frac42.2%
div-sub42.2%
*-inverses42.2%
/-rgt-identity42.2%
Simplified42.2%
Taylor expanded in x around inf 97.9%
metadata-eval97.9%
pow-flip97.9%
pow1/297.9%
clear-num97.9%
associate-*l/97.9%
*-un-lft-identity97.9%
inv-pow97.9%
sqrt-pow298.0%
metadata-eval98.0%
div-inv98.0%
metadata-eval98.0%
Applied egg-rr98.0%
Final simplification97.4%
(FPCore (x) :precision binary64 (if (<= x 4.0) (+ (pow x -0.5) -1.0) (- (pow (* x x) -0.25))))
double code(double x) {
double tmp;
if (x <= 4.0) {
tmp = pow(x, -0.5) + -1.0;
} else {
tmp = -pow((x * x), -0.25);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 4.0d0) then
tmp = (x ** (-0.5d0)) + (-1.0d0)
else
tmp = -((x * x) ** (-0.25d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 4.0) {
tmp = Math.pow(x, -0.5) + -1.0;
} else {
tmp = -Math.pow((x * x), -0.25);
}
return tmp;
}
def code(x): tmp = 0 if x <= 4.0: tmp = math.pow(x, -0.5) + -1.0 else: tmp = -math.pow((x * x), -0.25) return tmp
function code(x) tmp = 0.0 if (x <= 4.0) tmp = Float64((x ^ -0.5) + -1.0); else tmp = Float64(-(Float64(x * x) ^ -0.25)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 4.0) tmp = (x ^ -0.5) + -1.0; else tmp = -((x * x) ^ -0.25); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 4.0], N[(N[Power[x, -0.5], $MachinePrecision] + -1.0), $MachinePrecision], (-N[Power[N[(x * x), $MachinePrecision], -0.25], $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4:\\
\;\;\;\;{x}^{-0.5} + -1\\
\mathbf{else}:\\
\;\;\;\;-{\left(x \cdot x\right)}^{-0.25}\\
\end{array}
\end{array}
if x < 4Initial program 99.6%
Taylor expanded in x around 0 95.7%
add-log-exp5.5%
*-un-lft-identity5.5%
log-prod5.5%
metadata-eval5.5%
add-log-exp95.7%
pow1/295.7%
pow-flip96.0%
metadata-eval96.0%
Applied egg-rr96.0%
+-lft-identity96.0%
Simplified96.0%
if 4 < x Initial program 41.8%
pow1/241.8%
pow-to-exp6.1%
+-commutative6.1%
log1p-udef6.1%
Applied egg-rr6.1%
Taylor expanded in x around inf 3.3%
mul-1-neg3.3%
Simplified3.3%
inv-pow3.3%
sqrt-pow13.3%
metadata-eval3.3%
sqr-pow3.3%
pow-prod-down39.1%
metadata-eval39.1%
Applied egg-rr39.1%
Final simplification67.1%
(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 70.3%
add-log-exp52.2%
*-un-lft-identity52.2%
log-prod52.2%
metadata-eval52.2%
add-log-exp70.3%
inv-pow70.3%
sqrt-pow266.5%
+-commutative66.5%
metadata-eval66.5%
Applied egg-rr66.5%
+-lft-identity66.5%
Simplified66.5%
Taylor expanded in x around inf 2.2%
mul-1-neg2.2%
unpow1/22.2%
sqr-pow2.2%
sqr-pow2.2%
rem-exp-log2.2%
exp-neg2.2%
exp-prod2.2%
distribute-lft-neg-out2.2%
distribute-rgt-neg-in2.2%
metadata-eval2.2%
exp-to-pow2.2%
Simplified2.2%
Final simplification2.2%
(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 70.3%
frac-sub70.3%
div-inv70.2%
*-un-lft-identity70.2%
+-commutative70.2%
*-rgt-identity70.2%
metadata-eval70.2%
frac-times70.2%
un-div-inv70.2%
pow1/270.3%
pow-flip70.4%
metadata-eval70.4%
+-commutative70.4%
Applied egg-rr70.4%
associate-*r/70.4%
*-rgt-identity70.4%
times-frac70.4%
div-sub70.4%
*-inverses70.4%
/-rgt-identity70.4%
Simplified70.4%
Taylor expanded in x around 0 48.6%
Final simplification48.6%
(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 2023207
(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)))))