
(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 12 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)))) 4e-9) (* (- (+ (/ 0.5 x) (/ 0.3125 (pow x 3.0))) (/ 0.375 (* x x))) (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)))) <= 4e-9) {
tmp = (((0.5 / x) + (0.3125 / pow(x, 3.0))) - (0.375 / (x * x))) * 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)))) <= 4d-9) then
tmp = (((0.5d0 / x) + (0.3125d0 / (x ** 3.0d0))) - (0.375d0 / (x * x))) * (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)))) <= 4e-9) {
tmp = (((0.5 / x) + (0.3125 / Math.pow(x, 3.0))) - (0.375 / (x * x))) * 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)))) <= 4e-9: tmp = (((0.5 / x) + (0.3125 / math.pow(x, 3.0))) - (0.375 / (x * x))) * 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)))) <= 4e-9) tmp = Float64(Float64(Float64(Float64(0.5 / x) + Float64(0.3125 / (x ^ 3.0))) - Float64(0.375 / Float64(x * x))) * (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)))) <= 4e-9) tmp = (((0.5 / x) + (0.3125 / (x ^ 3.0))) - (0.375 / (x * x))) * (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], 4e-9], N[(N[(N[(N[(0.5 / x), $MachinePrecision] + N[(0.3125 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(0.375 / N[(x * x), $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 4 \cdot 10^{-9}:\\
\;\;\;\;\left(\left(\frac{0.5}{x} + \frac{0.3125}{{x}^{3}}\right) - \frac{0.375}{x \cdot x}\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)))) < 4.00000000000000025e-9Initial program 36.4%
frac-sub36.5%
div-inv36.5%
*-un-lft-identity36.5%
+-commutative36.5%
*-rgt-identity36.5%
metadata-eval36.5%
frac-times36.5%
un-div-inv36.5%
pow1/236.5%
pow-flip36.5%
metadata-eval36.5%
+-commutative36.5%
Applied egg-rr36.5%
associate-*r/36.5%
*-rgt-identity36.5%
times-frac36.5%
div-sub36.5%
*-inverses36.5%
/-rgt-identity36.5%
Simplified36.5%
Taylor expanded in x around inf 99.5%
associate-*r/99.5%
metadata-eval99.5%
associate-*r/99.5%
metadata-eval99.5%
associate-*r/99.5%
metadata-eval99.5%
unpow299.5%
Simplified99.5%
if 4.00000000000000025e-9 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.3%
frac-sub99.3%
div-inv99.3%
*-un-lft-identity99.3%
+-commutative99.3%
*-rgt-identity99.3%
metadata-eval99.3%
frac-times99.3%
un-div-inv99.3%
pow1/299.3%
pow-flip99.7%
metadata-eval99.7%
+-commutative99.7%
Applied egg-rr99.7%
associate-*r/99.7%
*-rgt-identity99.7%
times-frac99.7%
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.7%
(FPCore (x) :precision binary64 (if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 (sqrt (+ 1.0 x)))) 4e-9) (* (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)))) <= 4e-9) {
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)))) <= 4d-9) 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)))) <= 4e-9) {
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)))) <= 4e-9: 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)))) <= 4e-9) 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)))) <= 4e-9) 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], 4e-9], 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 4 \cdot 10^{-9}:\\
\;\;\;\;{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.00000000000000025e-9Initial program 36.4%
frac-sub36.5%
div-inv36.5%
*-un-lft-identity36.5%
+-commutative36.5%
*-rgt-identity36.5%
metadata-eval36.5%
frac-times36.5%
un-div-inv36.5%
pow1/236.5%
pow-flip36.5%
metadata-eval36.5%
+-commutative36.5%
Applied egg-rr36.5%
associate-*r/36.5%
*-rgt-identity36.5%
times-frac36.5%
div-sub36.5%
*-inverses36.5%
/-rgt-identity36.5%
Simplified36.5%
Taylor expanded in x around inf 99.3%
associate-*r/99.3%
metadata-eval99.3%
associate-*r/99.3%
metadata-eval99.3%
unpow299.3%
Simplified99.3%
if 4.00000000000000025e-9 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.3%
frac-sub99.3%
div-inv99.3%
*-un-lft-identity99.3%
+-commutative99.3%
*-rgt-identity99.3%
metadata-eval99.3%
frac-times99.3%
un-div-inv99.3%
pow1/299.3%
pow-flip99.7%
metadata-eval99.7%
+-commutative99.7%
Applied egg-rr99.7%
associate-*r/99.7%
*-rgt-identity99.7%
times-frac99.7%
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.6%
(FPCore (x) :precision binary64 (if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 (sqrt (+ 1.0 x)))) 4e-9) (* (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)))) <= 4e-9) {
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)))) <= 4d-9) 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)))) <= 4e-9) {
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)))) <= 4e-9: 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)))) <= 4e-9) 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)))) <= 4e-9) 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], 4e-9], 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 4 \cdot 10^{-9}:\\
\;\;\;\;{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.00000000000000025e-9Initial program 36.4%
frac-sub36.5%
div-inv36.5%
*-un-lft-identity36.5%
+-commutative36.5%
*-rgt-identity36.5%
metadata-eval36.5%
frac-times36.5%
un-div-inv36.5%
pow1/236.5%
pow-flip36.5%
metadata-eval36.5%
+-commutative36.5%
Applied egg-rr36.5%
associate-*r/36.5%
*-rgt-identity36.5%
times-frac36.5%
div-sub36.5%
*-inverses36.5%
/-rgt-identity36.5%
Simplified36.5%
Taylor expanded in x around inf 99.3%
associate-*r/99.3%
metadata-eval99.3%
associate-*r/99.3%
metadata-eval99.3%
unpow299.3%
Simplified99.3%
if 4.00000000000000025e-9 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial 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%
inv-pow99.3%
sqrt-pow299.7%
metadata-eval99.7%
pow1/299.7%
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.5%
(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.6%
Taylor expanded in x around 0 99.4%
add-log-exp4.4%
*-un-lft-identity4.4%
log-prod4.4%
metadata-eval4.4%
add-log-exp99.4%
pow1/299.4%
pow-flip99.8%
metadata-eval99.8%
Applied egg-rr99.8%
+-lft-identity99.8%
Simplified99.8%
if 1.3999999999999999 < x Initial program 38.1%
frac-sub38.1%
div-inv38.1%
*-un-lft-identity38.1%
+-commutative38.1%
*-rgt-identity38.1%
metadata-eval38.1%
frac-times38.1%
un-div-inv38.1%
pow1/238.1%
pow-flip38.1%
metadata-eval38.1%
+-commutative38.1%
Applied egg-rr38.1%
associate-*r/38.1%
*-rgt-identity38.1%
times-frac38.1%
div-sub38.1%
*-inverses38.1%
/-rgt-identity38.1%
Simplified38.1%
Taylor expanded in x around inf 97.4%
associate-*r/97.4%
metadata-eval97.4%
associate-*r/97.4%
metadata-eval97.4%
unpow297.4%
Simplified97.4%
Final simplification98.6%
(FPCore (x) :precision binary64 (if (<= x 1.7) (+ (pow x -0.5) (/ -1.0 (+ 1.0 (* x 0.5)))) (* (/ 0.5 x) (pow x -0.5))))
double code(double x) {
double tmp;
if (x <= 1.7) {
tmp = pow(x, -0.5) + (-1.0 / (1.0 + (x * 0.5)));
} 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 <= 1.7d0) then
tmp = (x ** (-0.5d0)) + ((-1.0d0) / (1.0d0 + (x * 0.5d0)))
else
tmp = (0.5d0 / x) * (x ** (-0.5d0))
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 = (0.5 / x) * Math.pow(x, -0.5);
}
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 = (0.5 / x) * math.pow(x, -0.5) 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(Float64(0.5 / x) * (x ^ -0.5)); 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 = (0.5 / x) * (x ^ -0.5); 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[(0.5 / x), $MachinePrecision] * N[Power[x, -0.5], $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{0.5}{x} \cdot {x}^{-0.5}\\
\end{array}
\end{array}
if x < 1.69999999999999996Initial program 99.6%
Taylor expanded in x around 0 99.4%
add-log-exp4.4%
*-un-lft-identity4.4%
log-prod4.4%
metadata-eval4.4%
add-log-exp99.4%
pow1/299.4%
pow-flip99.8%
metadata-eval99.8%
Applied egg-rr99.8%
+-lft-identity99.8%
Simplified99.8%
if 1.69999999999999996 < x Initial program 38.1%
frac-sub38.1%
div-inv38.1%
*-un-lft-identity38.1%
+-commutative38.1%
*-rgt-identity38.1%
metadata-eval38.1%
frac-times38.1%
un-div-inv38.1%
pow1/238.1%
pow-flip38.1%
metadata-eval38.1%
+-commutative38.1%
Applied egg-rr38.1%
associate-*r/38.1%
*-rgt-identity38.1%
times-frac38.1%
div-sub38.1%
*-inverses38.1%
/-rgt-identity38.1%
Simplified38.1%
Taylor expanded in x around inf 96.2%
Final simplification97.9%
(FPCore (x) :precision binary64 (if (<= x 1.0) (+ (+ (pow x -0.5) (* x 0.5)) -1.0) (* (/ 0.5 x) (pow x -0.5))))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = (pow(x, -0.5) + (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 <= 1.0d0) then
tmp = ((x ** (-0.5d0)) + (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 <= 1.0) {
tmp = (Math.pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = (0.5 / x) * Math.pow(x, -0.5);
}
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 / x) * math.pow(x, -0.5) 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(Float64(0.5 / x) * (x ^ -0.5)); 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 / x) * (x ^ -0.5); 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[(0.5 / x), $MachinePrecision] * N[Power[x, -0.5], $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{0.5}{x} \cdot {x}^{-0.5}\\
\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%
inv-pow99.6%
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 99.8%
if 1 < x Initial program 38.1%
frac-sub38.1%
div-inv38.1%
*-un-lft-identity38.1%
+-commutative38.1%
*-rgt-identity38.1%
metadata-eval38.1%
frac-times38.1%
un-div-inv38.1%
pow1/238.1%
pow-flip38.1%
metadata-eval38.1%
+-commutative38.1%
Applied egg-rr38.1%
associate-*r/38.1%
*-rgt-identity38.1%
times-frac38.1%
div-sub38.1%
*-inverses38.1%
/-rgt-identity38.1%
Simplified38.1%
Taylor expanded in x around inf 96.2%
Final simplification97.9%
(FPCore (x) :precision binary64 (if (<= x 0.67) (+ (pow x -0.5) -1.0) (* (/ 0.5 x) (pow x -0.5))))
double code(double x) {
double tmp;
if (x <= 0.67) {
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.67d0) 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.67) {
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.67: 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.67) 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.67) 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.67], 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.67:\\
\;\;\;\;{x}^{-0.5} + -1\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{x} \cdot {x}^{-0.5}\\
\end{array}
\end{array}
if x < 0.67000000000000004Initial 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%
inv-pow99.6%
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 99.4%
if 0.67000000000000004 < x Initial program 38.1%
frac-sub38.1%
div-inv38.1%
*-un-lft-identity38.1%
+-commutative38.1%
*-rgt-identity38.1%
metadata-eval38.1%
frac-times38.1%
un-div-inv38.1%
pow1/238.1%
pow-flip38.1%
metadata-eval38.1%
+-commutative38.1%
Applied egg-rr38.1%
associate-*r/38.1%
*-rgt-identity38.1%
times-frac38.1%
div-sub38.1%
*-inverses38.1%
/-rgt-identity38.1%
Simplified38.1%
Taylor expanded in x around inf 96.2%
Final simplification97.7%
(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%
*-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%
inv-pow99.6%
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 99.4%
if 4 < x Initial program 38.1%
pow1/238.1%
pow-to-exp8.8%
+-commutative8.8%
log1p-udef8.8%
Applied egg-rr8.8%
Taylor expanded in x around inf 3.2%
mul-1-neg3.2%
Simplified3.2%
inv-pow3.2%
sqrt-pow13.2%
metadata-eval3.2%
sqr-pow3.2%
pow-prod-down32.4%
metadata-eval32.4%
Applied egg-rr32.4%
Final simplification64.6%
(FPCore (x) :precision binary64 (if (<= x 1.35e+154) (/ 1.0 (+ x (sqrt x))) (- (pow (* x x) -0.25))))
double code(double x) {
double tmp;
if (x <= 1.35e+154) {
tmp = 1.0 / (x + sqrt(x));
} else {
tmp = -pow((x * x), -0.25);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.35d+154) then
tmp = 1.0d0 / (x + sqrt(x))
else
tmp = -((x * x) ** (-0.25d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.35e+154) {
tmp = 1.0 / (x + Math.sqrt(x));
} else {
tmp = -Math.pow((x * x), -0.25);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.35e+154: tmp = 1.0 / (x + math.sqrt(x)) else: tmp = -math.pow((x * x), -0.25) return tmp
function code(x) tmp = 0.0 if (x <= 1.35e+154) tmp = Float64(1.0 / Float64(x + sqrt(x))); else tmp = Float64(-(Float64(x * x) ^ -0.25)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.35e+154) tmp = 1.0 / (x + sqrt(x)); else tmp = -((x * x) ^ -0.25); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.35e+154], N[(1.0 / N[(x + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-N[Power[N[(x * x), $MachinePrecision], -0.25], $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\frac{1}{x + \sqrt{x}}\\
\mathbf{else}:\\
\;\;\;\;-{\left(x \cdot x\right)}^{-0.25}\\
\end{array}
\end{array}
if x < 1.35000000000000003e154Initial program 71.0%
*-un-lft-identity71.0%
clear-num71.0%
associate-/r/71.0%
prod-diff71.0%
*-un-lft-identity71.0%
fma-neg71.0%
*-un-lft-identity71.0%
inv-pow71.0%
sqrt-pow271.2%
metadata-eval71.2%
pow1/271.2%
pow-flip71.4%
+-commutative71.4%
metadata-eval71.4%
Applied egg-rr71.4%
fma-udef71.4%
distribute-lft1-in71.4%
metadata-eval71.4%
mul0-lft71.4%
+-rgt-identity71.4%
Simplified71.4%
Applied egg-rr67.7%
associate-*r/67.7%
*-rgt-identity67.7%
Simplified67.7%
add-sqr-sqrt67.7%
metadata-eval67.7%
+-commutative67.7%
add-sqr-sqrt67.7%
frac-times67.7%
sqrt-unprod0.0%
add-sqr-sqrt71.0%
div-inv71.0%
pow1/271.0%
+-commutative71.0%
pow-flip70.8%
metadata-eval70.8%
neg-mul-170.8%
inv-pow70.8%
sqrt-pow170.8%
metadata-eval70.8%
cancel-sign-sub-inv70.8%
Applied egg-rr73.6%
div-sub71.0%
mul-1-neg71.0%
distribute-neg-in71.0%
metadata-eval71.0%
remove-double-neg71.0%
distribute-rgt-in71.0%
mul-1-neg71.0%
remove-double-neg71.0%
sqr-neg71.0%
*-commutative71.0%
mul-1-neg71.0%
remove-double-neg71.0%
distribute-rgt-in71.1%
mul-1-neg71.1%
remove-double-neg71.1%
sqr-neg71.1%
div-sub73.6%
Simplified99.3%
Taylor expanded in x around 0 68.2%
*-commutative68.2%
+-commutative68.2%
distribute-rgt-in68.2%
*-lft-identity68.2%
pow-plus68.5%
metadata-eval68.5%
unpow1/268.5%
Simplified68.5%
if 1.35000000000000003e154 < x Initial program 58.7%
pow1/258.7%
pow-to-exp4.2%
+-commutative4.2%
log1p-udef4.2%
Applied egg-rr4.2%
Taylor expanded in x around inf 4.0%
mul-1-neg4.0%
Simplified4.0%
inv-pow4.0%
sqrt-pow14.0%
metadata-eval4.0%
sqr-pow4.0%
pow-prod-down58.7%
metadata-eval58.7%
Applied egg-rr58.7%
Final simplification65.8%
(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.6%
pow1/267.6%
pow-to-exp52.4%
+-commutative52.4%
log1p-udef52.4%
Applied egg-rr52.4%
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-udef17.7%
Applied egg-rr17.7%
expm1-def2.2%
expm1-log1p2.2%
Simplified2.2%
Final simplification2.2%
(FPCore (x) :precision binary64 (sqrt (/ 1.0 x)))
double code(double x) {
return sqrt((1.0 / x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt((1.0d0 / x))
end function
public static double code(double x) {
return Math.sqrt((1.0 / x));
}
def code(x): return math.sqrt((1.0 / x))
function code(x) return sqrt(Float64(1.0 / x)) end
function tmp = code(x) tmp = sqrt((1.0 / x)); end
code[x_] := N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{1}{x}}
\end{array}
Initial program 67.6%
*-un-lft-identity67.6%
clear-num67.6%
associate-/r/67.6%
prod-diff67.6%
*-un-lft-identity67.6%
fma-neg67.6%
*-un-lft-identity67.6%
inv-pow67.6%
sqrt-pow263.1%
metadata-eval63.1%
pow1/263.1%
pow-flip67.9%
+-commutative67.9%
metadata-eval67.9%
Applied egg-rr67.9%
fma-udef67.9%
distribute-lft1-in67.9%
metadata-eval67.9%
mul0-lft67.9%
+-rgt-identity67.9%
Simplified67.9%
Applied egg-rr50.1%
associate-*r/50.2%
*-rgt-identity50.2%
Simplified50.2%
Taylor expanded in x around inf 49.4%
Final simplification49.4%
(FPCore (x) :precision binary64 (pow x -0.5))
double code(double x) {
return pow(x, -0.5);
}
real(8) function code(x)
real(8), intent (in) :: x
code = x ** (-0.5d0)
end function
public static double code(double x) {
return Math.pow(x, -0.5);
}
def code(x): return math.pow(x, -0.5)
function code(x) return x ^ -0.5 end
function tmp = code(x) tmp = x ^ -0.5; end
code[x_] := N[Power[x, -0.5], $MachinePrecision]
\begin{array}{l}
\\
{x}^{-0.5}
\end{array}
Initial program 67.6%
frac-sub67.7%
div-inv67.7%
*-un-lft-identity67.7%
+-commutative67.7%
*-rgt-identity67.7%
metadata-eval67.7%
frac-times67.7%
un-div-inv67.7%
pow1/267.7%
pow-flip67.9%
metadata-eval67.9%
+-commutative67.9%
Applied egg-rr67.9%
associate-*r/67.8%
*-rgt-identity67.8%
times-frac67.8%
div-sub67.9%
*-inverses67.9%
/-rgt-identity67.9%
Simplified67.9%
Taylor expanded in x around 0 49.5%
Final simplification49.5%
(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 2023264
(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)))))