
(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 13 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 90000.0) (- (pow x -0.5) (pow (+ 1.0 x) -0.5)) (/ (/ 1.0 (+ (sqrt (+ 1.0 x)) (sqrt x))) (+ x 0.5))))
double code(double x) {
double tmp;
if (x <= 90000.0) {
tmp = pow(x, -0.5) - pow((1.0 + x), -0.5);
} else {
tmp = (1.0 / (sqrt((1.0 + x)) + sqrt(x))) / (x + 0.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 90000.0d0) then
tmp = (x ** (-0.5d0)) - ((1.0d0 + x) ** (-0.5d0))
else
tmp = (1.0d0 / (sqrt((1.0d0 + x)) + sqrt(x))) / (x + 0.5d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 90000.0) {
tmp = Math.pow(x, -0.5) - Math.pow((1.0 + x), -0.5);
} else {
tmp = (1.0 / (Math.sqrt((1.0 + x)) + Math.sqrt(x))) / (x + 0.5);
}
return tmp;
}
def code(x): tmp = 0 if x <= 90000.0: tmp = math.pow(x, -0.5) - math.pow((1.0 + x), -0.5) else: tmp = (1.0 / (math.sqrt((1.0 + x)) + math.sqrt(x))) / (x + 0.5) return tmp
function code(x) tmp = 0.0 if (x <= 90000.0) tmp = Float64((x ^ -0.5) - (Float64(1.0 + x) ^ -0.5)); else tmp = Float64(Float64(1.0 / Float64(sqrt(Float64(1.0 + x)) + sqrt(x))) / Float64(x + 0.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 90000.0) tmp = (x ^ -0.5) - ((1.0 + x) ^ -0.5); else tmp = (1.0 / (sqrt((1.0 + x)) + sqrt(x))) / (x + 0.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 90000.0], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x + 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 90000:\\
\;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{\sqrt{1 + x} + \sqrt{x}}}{x + 0.5}\\
\end{array}
\end{array}
if x < 9e4Initial 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.9%
metadata-eval99.9%
pow1/299.9%
pow-flip100.0%
+-commutative100.0%
metadata-eval100.0%
Applied egg-rr100.0%
associate-+l-100.0%
expm1-log1p99.9%
expm1-def99.9%
associate--l-99.9%
fma-udef99.9%
distribute-lft1-in99.9%
metadata-eval99.9%
mul0-lft99.9%
metadata-eval99.9%
expm1-def99.9%
expm1-log1p100.0%
Simplified100.0%
if 9e4 < x Initial program 37.2%
frac-sub37.4%
*-un-lft-identity37.4%
*-rgt-identity37.4%
+-commutative37.4%
sqrt-unprod37.4%
+-commutative37.4%
Applied egg-rr37.4%
Taylor expanded in x around inf 37.4%
+-commutative37.4%
Simplified37.4%
flip--38.1%
add-sqr-sqrt25.3%
add-sqr-sqrt38.1%
Applied egg-rr38.1%
associate--l+99.7%
+-inverses99.7%
metadata-eval99.7%
+-commutative99.7%
Simplified99.7%
Final simplification99.8%
(FPCore (x) :precision binary64 (+ (* (/ -1.0 (sqrt (+ 1.0 x))) 0.0) (/ (/ 1.0 (fma x (pow (+ 1.0 x) -0.5) (sqrt x))) (+ 1.0 x))))
double code(double x) {
return ((-1.0 / sqrt((1.0 + x))) * 0.0) + ((1.0 / fma(x, pow((1.0 + x), -0.5), sqrt(x))) / (1.0 + x));
}
function code(x) return Float64(Float64(Float64(-1.0 / sqrt(Float64(1.0 + x))) * 0.0) + Float64(Float64(1.0 / fma(x, (Float64(1.0 + x) ^ -0.5), sqrt(x))) / Float64(1.0 + x))) end
code[x_] := N[(N[(N[(-1.0 / N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 0.0), $MachinePrecision] + N[(N[(1.0 / N[(x * N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision] + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(1.0 + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1}{\sqrt{1 + x}} \cdot 0 + \frac{\frac{1}{\mathsf{fma}\left(x, {\left(1 + x\right)}^{-0.5}, \sqrt{x}\right)}}{1 + x}
\end{array}
Initial program 69.8%
inv-pow69.8%
add-cube-cbrt57.9%
unpow-prod-down57.1%
frac-2neg57.1%
metadata-eval57.1%
div-inv57.1%
metadata-eval57.1%
distribute-neg-frac57.1%
metadata-eval57.1%
frac-2neg57.1%
prod-diff53.5%
Applied egg-rr53.9%
+-commutative53.9%
fma-udef53.9%
distribute-lft-neg-in53.9%
distribute-rgt-neg-in53.9%
metadata-eval53.9%
distribute-lft-out53.9%
metadata-eval53.9%
distribute-rgt-neg-in53.9%
metadata-eval53.9%
unpow-153.9%
unpow-153.9%
*-rgt-identity53.9%
Simplified53.9%
Applied egg-rr69.6%
associate-/l/65.8%
Simplified65.8%
associate-/r*63.7%
clear-num64.7%
frac-sub69.6%
+-commutative69.6%
+-commutative69.6%
+-commutative69.6%
Applied egg-rr69.6%
associate-*r/70.0%
lft-mult-inverse70.1%
remove-double-div70.1%
*-rgt-identity70.1%
associate-/r/70.1%
/-rgt-identity70.1%
associate--l+98.5%
+-inverses98.5%
metadata-eval98.5%
associate-*r*98.5%
Simplified98.7%
expm1-log1p-u95.0%
expm1-udef65.9%
*-commutative65.9%
pow1/265.9%
+-commutative65.9%
*-commutative65.9%
fma-def65.9%
Applied egg-rr65.9%
expm1-def95.0%
expm1-log1p98.7%
*-commutative98.7%
associate-/r*99.6%
+-commutative99.6%
+-commutative99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (x) :precision binary64 (/ 1.0 (* (+ 1.0 x) (+ (pow x 0.5) (* x (pow (+ 1.0 x) -0.5))))))
double code(double x) {
return 1.0 / ((1.0 + x) * (pow(x, 0.5) + (x * pow((1.0 + x), -0.5))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / ((1.0d0 + x) * ((x ** 0.5d0) + (x * ((1.0d0 + x) ** (-0.5d0)))))
end function
public static double code(double x) {
return 1.0 / ((1.0 + x) * (Math.pow(x, 0.5) + (x * Math.pow((1.0 + x), -0.5))));
}
def code(x): return 1.0 / ((1.0 + x) * (math.pow(x, 0.5) + (x * math.pow((1.0 + x), -0.5))))
function code(x) return Float64(1.0 / Float64(Float64(1.0 + x) * Float64((x ^ 0.5) + Float64(x * (Float64(1.0 + x) ^ -0.5))))) end
function tmp = code(x) tmp = 1.0 / ((1.0 + x) * ((x ^ 0.5) + (x * ((1.0 + x) ^ -0.5)))); end
code[x_] := N[(1.0 / N[(N[(1.0 + x), $MachinePrecision] * N[(N[Power[x, 0.5], $MachinePrecision] + N[(x * N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\left(1 + x\right) \cdot \left({x}^{0.5} + x \cdot {\left(1 + x\right)}^{-0.5}\right)}
\end{array}
Initial program 69.8%
inv-pow69.8%
add-cube-cbrt57.9%
unpow-prod-down57.1%
frac-2neg57.1%
metadata-eval57.1%
div-inv57.1%
metadata-eval57.1%
distribute-neg-frac57.1%
metadata-eval57.1%
frac-2neg57.1%
prod-diff53.5%
Applied egg-rr53.9%
+-commutative53.9%
fma-udef53.9%
distribute-lft-neg-in53.9%
distribute-rgt-neg-in53.9%
metadata-eval53.9%
distribute-lft-out53.9%
metadata-eval53.9%
distribute-rgt-neg-in53.9%
metadata-eval53.9%
unpow-153.9%
unpow-153.9%
*-rgt-identity53.9%
Simplified53.9%
Applied egg-rr69.6%
associate-/l/65.8%
Simplified65.8%
associate-/r*63.7%
clear-num64.7%
frac-sub69.6%
+-commutative69.6%
+-commutative69.6%
+-commutative69.6%
Applied egg-rr69.6%
associate-*r/70.0%
lft-mult-inverse70.1%
remove-double-div70.1%
*-rgt-identity70.1%
associate-/r/70.1%
/-rgt-identity70.1%
associate--l+98.5%
+-inverses98.5%
metadata-eval98.5%
associate-*r*98.5%
Simplified98.7%
Taylor expanded in x around 0 98.7%
Final simplification98.7%
(FPCore (x) :precision binary64 (if (<= x 112000000.0) (- (pow x -0.5) (pow (+ 1.0 x) -0.5)) (* 0.5 (sqrt (/ 1.0 (pow x 3.0))))))
double code(double x) {
double tmp;
if (x <= 112000000.0) {
tmp = pow(x, -0.5) - pow((1.0 + x), -0.5);
} else {
tmp = 0.5 * sqrt((1.0 / pow(x, 3.0)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 112000000.0d0) then
tmp = (x ** (-0.5d0)) - ((1.0d0 + x) ** (-0.5d0))
else
tmp = 0.5d0 * sqrt((1.0d0 / (x ** 3.0d0)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 112000000.0) {
tmp = Math.pow(x, -0.5) - Math.pow((1.0 + x), -0.5);
} else {
tmp = 0.5 * Math.sqrt((1.0 / Math.pow(x, 3.0)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 112000000.0: tmp = math.pow(x, -0.5) - math.pow((1.0 + x), -0.5) else: tmp = 0.5 * math.sqrt((1.0 / math.pow(x, 3.0))) return tmp
function code(x) tmp = 0.0 if (x <= 112000000.0) tmp = Float64((x ^ -0.5) - (Float64(1.0 + x) ^ -0.5)); else tmp = Float64(0.5 * sqrt(Float64(1.0 / (x ^ 3.0)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 112000000.0) tmp = (x ^ -0.5) - ((1.0 + x) ^ -0.5); else tmp = 0.5 * sqrt((1.0 / (x ^ 3.0))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 112000000.0], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(1.0 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 112000000:\\
\;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{1}{{x}^{3}}}\\
\end{array}
\end{array}
if x < 1.12e8Initial program 99.3%
*-un-lft-identity99.3%
clear-num99.3%
associate-/r/99.3%
prod-diff99.3%
*-un-lft-identity99.3%
fma-neg99.3%
*-un-lft-identity99.3%
pow1/299.3%
pow-flip99.6%
metadata-eval99.6%
pow1/299.6%
pow-flip99.7%
+-commutative99.7%
metadata-eval99.7%
Applied egg-rr99.7%
associate-+l-99.7%
expm1-log1p99.6%
expm1-def99.5%
associate--l-99.5%
fma-udef99.5%
distribute-lft1-in99.5%
metadata-eval99.5%
mul0-lft99.5%
metadata-eval99.5%
expm1-def99.6%
expm1-log1p99.7%
Simplified99.7%
if 1.12e8 < x Initial program 37.0%
*-un-lft-identity37.0%
clear-num37.0%
associate-/r/37.0%
prod-diff37.0%
*-un-lft-identity37.0%
fma-neg37.0%
*-un-lft-identity37.0%
pow1/237.0%
pow-flip30.7%
metadata-eval30.7%
pow1/230.7%
pow-flip37.1%
+-commutative37.1%
metadata-eval37.1%
Applied egg-rr37.1%
associate-+l-37.1%
expm1-log1p37.1%
expm1-def5.2%
associate--l-5.2%
fma-udef5.2%
distribute-lft1-in5.2%
metadata-eval5.2%
mul0-lft5.2%
metadata-eval5.2%
expm1-def37.1%
expm1-log1p37.1%
Simplified37.1%
Taylor expanded in x around inf 61.3%
Final simplification81.5%
(FPCore (x) :precision binary64 (if (<= x 1.0) (+ (+ (pow x -0.5) (* x 0.5)) -1.0) (* 0.5 (sqrt (/ 1.0 (pow x 3.0))))))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = (pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = 0.5 * sqrt((1.0 / pow(x, 3.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 = 0.5d0 * sqrt((1.0d0 / (x ** 3.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 = 0.5 * Math.sqrt((1.0 / Math.pow(x, 3.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 = 0.5 * math.sqrt((1.0 / math.pow(x, 3.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(0.5 * sqrt(Float64(1.0 / (x ^ 3.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 = 0.5 * sqrt((1.0 / (x ^ 3.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[(0.5 * N[Sqrt[N[(1.0 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]], $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}:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{1}{{x}^{3}}}\\
\end{array}
\end{array}
if x < 1Initial 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.7%
if 1 < x Initial program 38.2%
*-un-lft-identity38.2%
clear-num38.2%
associate-/r/38.2%
prod-diff38.2%
*-un-lft-identity38.2%
fma-neg38.2%
*-un-lft-identity38.2%
pow1/238.2%
pow-flip32.0%
metadata-eval32.0%
pow1/232.0%
pow-flip38.2%
+-commutative38.2%
metadata-eval38.2%
Applied egg-rr38.2%
associate-+l-38.2%
expm1-log1p38.2%
expm1-def6.9%
associate--l-6.9%
fma-udef6.9%
distribute-lft1-in6.9%
metadata-eval6.9%
mul0-lft6.9%
metadata-eval6.9%
expm1-def38.2%
expm1-log1p38.2%
Simplified38.2%
Taylor expanded in x around inf 60.6%
Final simplification80.8%
(FPCore (x) :precision binary64 (if (<= x 1.4) (+ (+ (pow x -0.5) (* x 0.5)) -1.0) (/ 1.0 (sqrt (* x (+ 1.0 x))))))
double code(double x) {
double tmp;
if (x <= 1.4) {
tmp = (pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = 1.0 / sqrt((x * (1.0 + 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)) + (x * 0.5d0)) + (-1.0d0)
else
tmp = 1.0d0 / sqrt((x * (1.0d0 + 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) + (x * 0.5)) + -1.0;
} else {
tmp = 1.0 / Math.sqrt((x * (1.0 + x)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.4: tmp = (math.pow(x, -0.5) + (x * 0.5)) + -1.0 else: tmp = 1.0 / math.sqrt((x * (1.0 + x))) return tmp
function code(x) tmp = 0.0 if (x <= 1.4) tmp = Float64(Float64((x ^ -0.5) + Float64(x * 0.5)) + -1.0); else tmp = Float64(1.0 / sqrt(Float64(x * Float64(1.0 + x)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.4) tmp = ((x ^ -0.5) + (x * 0.5)) + -1.0; else tmp = 1.0 / sqrt((x * (1.0 + x))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.4], N[(N[(N[Power[x, -0.5], $MachinePrecision] + N[(x * 0.5), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(1.0 / N[Sqrt[N[(x * N[(1.0 + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.4:\\
\;\;\;\;\left({x}^{-0.5} + x \cdot 0.5\right) + -1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sqrt{x \cdot \left(1 + x\right)}}\\
\end{array}
\end{array}
if x < 1.3999999999999999Initial 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.7%
if 1.3999999999999999 < x Initial program 38.2%
frac-sub38.4%
*-un-lft-identity38.4%
*-rgt-identity38.4%
+-commutative38.4%
sqrt-unprod38.4%
+-commutative38.4%
Applied egg-rr38.4%
Taylor expanded in x around 0 37.9%
Final simplification69.7%
(FPCore (x) :precision binary64 (if (<= x 0.7) (+ (pow x -0.5) -1.0) (/ 1.0 (sqrt (* x (+ 1.0 x))))))
double code(double x) {
double tmp;
if (x <= 0.7) {
tmp = pow(x, -0.5) + -1.0;
} else {
tmp = 1.0 / sqrt((x * (1.0 + x)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.7d0) then
tmp = (x ** (-0.5d0)) + (-1.0d0)
else
tmp = 1.0d0 / sqrt((x * (1.0d0 + x)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.7) {
tmp = Math.pow(x, -0.5) + -1.0;
} else {
tmp = 1.0 / Math.sqrt((x * (1.0 + x)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.7: tmp = math.pow(x, -0.5) + -1.0 else: tmp = 1.0 / math.sqrt((x * (1.0 + x))) return tmp
function code(x) tmp = 0.0 if (x <= 0.7) tmp = Float64((x ^ -0.5) + -1.0); else tmp = Float64(1.0 / sqrt(Float64(x * Float64(1.0 + x)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.7) tmp = (x ^ -0.5) + -1.0; else tmp = 1.0 / sqrt((x * (1.0 + x))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.7], N[(N[Power[x, -0.5], $MachinePrecision] + -1.0), $MachinePrecision], N[(1.0 / N[Sqrt[N[(x * N[(1.0 + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.7:\\
\;\;\;\;{x}^{-0.5} + -1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sqrt{x \cdot \left(1 + x\right)}}\\
\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 38.2%
frac-sub38.4%
*-un-lft-identity38.4%
*-rgt-identity38.4%
+-commutative38.4%
sqrt-unprod38.4%
+-commutative38.4%
Applied egg-rr38.4%
Taylor expanded in x around 0 37.9%
Final simplification69.3%
(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.9%
if 0.599999999999999978 < x Initial program 38.2%
frac-sub38.4%
*-un-lft-identity38.4%
*-rgt-identity38.4%
+-commutative38.4%
sqrt-unprod38.4%
+-commutative38.4%
Applied egg-rr38.4%
Taylor expanded in x around inf 37.3%
+-commutative37.3%
Simplified37.3%
Taylor expanded in x around 0 7.6%
Final simplification54.7%
(FPCore (x) :precision binary64 (+ (+ 1.0 (pow x -0.5)) -1.0))
double code(double x) {
return (1.0 + pow(x, -0.5)) + -1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 + (x ** (-0.5d0))) + (-1.0d0)
end function
public static double code(double x) {
return (1.0 + Math.pow(x, -0.5)) + -1.0;
}
def code(x): return (1.0 + math.pow(x, -0.5)) + -1.0
function code(x) return Float64(Float64(1.0 + (x ^ -0.5)) + -1.0) end
function tmp = code(x) tmp = (1.0 + (x ^ -0.5)) + -1.0; end
code[x_] := N[(N[(1.0 + N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(1 + {x}^{-0.5}\right) + -1
\end{array}
Initial program 69.8%
*-un-lft-identity69.8%
clear-num69.8%
associate-/r/69.8%
prod-diff69.8%
*-un-lft-identity69.8%
fma-neg69.8%
*-un-lft-identity69.8%
pow1/269.8%
pow-flip67.0%
metadata-eval67.0%
pow1/267.0%
pow-flip70.1%
+-commutative70.1%
metadata-eval70.1%
Applied egg-rr70.1%
associate-+l-70.1%
expm1-log1p70.1%
expm1-def54.9%
associate--l-54.9%
fma-udef54.9%
distribute-lft1-in54.9%
metadata-eval54.9%
mul0-lft54.9%
metadata-eval54.9%
expm1-def70.1%
expm1-log1p70.1%
Simplified70.1%
Applied egg-rr52.8%
associate-*r/52.8%
*-rgt-identity52.8%
Simplified52.8%
Taylor expanded in x around inf 52.2%
inv-pow52.2%
sqrt-pow152.3%
metadata-eval52.3%
expm1-log1p-u48.5%
expm1-udef63.6%
log1p-udef63.6%
add-exp-log67.4%
Applied egg-rr67.4%
Final simplification67.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 69.8%
*-un-lft-identity69.8%
clear-num69.8%
associate-/r/69.8%
prod-diff69.8%
*-un-lft-identity69.8%
fma-neg69.8%
*-un-lft-identity69.8%
pow1/269.8%
pow-flip67.0%
metadata-eval67.0%
pow1/267.0%
pow-flip70.1%
+-commutative70.1%
metadata-eval70.1%
Applied egg-rr70.1%
associate-+l-70.1%
expm1-log1p70.1%
expm1-def54.9%
associate--l-54.9%
fma-udef54.9%
distribute-lft1-in54.9%
metadata-eval54.9%
mul0-lft54.9%
metadata-eval54.9%
expm1-def70.1%
expm1-log1p70.1%
Simplified70.1%
Applied egg-rr52.8%
associate-*r/52.8%
*-rgt-identity52.8%
Simplified52.8%
Taylor expanded in x around 0 53.9%
associate-/r*53.9%
Simplified53.9%
Taylor expanded in x around 0 53.9%
distribute-rgt-in53.9%
*-lft-identity53.9%
pow-plus54.1%
metadata-eval54.1%
unpow1/254.1%
Simplified54.1%
Final simplification54.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 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 69.8%
*-un-lft-identity69.8%
clear-num69.8%
associate-/r/69.8%
prod-diff69.8%
*-un-lft-identity69.8%
fma-neg69.8%
*-un-lft-identity69.8%
pow1/269.8%
pow-flip67.0%
metadata-eval67.0%
pow1/267.0%
pow-flip70.1%
+-commutative70.1%
metadata-eval70.1%
Applied egg-rr70.1%
associate-+l-70.1%
expm1-log1p70.1%
expm1-def54.9%
associate--l-54.9%
fma-udef54.9%
distribute-lft1-in54.9%
metadata-eval54.9%
mul0-lft54.9%
metadata-eval54.9%
expm1-def70.1%
expm1-log1p70.1%
Simplified70.1%
Applied egg-rr52.8%
associate-*r/52.8%
*-rgt-identity52.8%
Simplified52.8%
Taylor expanded in x around inf 52.2%
inv-pow52.2%
sqrt-pow152.3%
metadata-eval52.3%
*-un-lft-identity52.3%
Applied egg-rr52.3%
*-lft-identity52.3%
Simplified52.3%
Final simplification52.3%
(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 69.8%
frac-sub69.9%
*-un-lft-identity69.9%
*-rgt-identity69.9%
+-commutative69.9%
sqrt-unprod69.9%
+-commutative69.9%
Applied egg-rr69.9%
Taylor expanded in x around inf 21.6%
+-commutative21.6%
Simplified21.6%
Taylor expanded in x around 0 7.3%
Final simplification7.3%
(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 69.8%
frac-sub69.9%
*-un-lft-identity69.9%
*-rgt-identity69.9%
+-commutative69.9%
sqrt-unprod69.9%
+-commutative69.9%
Applied egg-rr69.9%
Taylor expanded in x around inf 21.6%
+-commutative21.6%
Simplified21.6%
Taylor expanded in x around 0 5.8%
Final simplification5.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 2023318
(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)))))