
(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 (<= x 2e+105) (/ (pow x -0.5) (+ (+ 1.0 x) (sqrt (* x (+ 1.0 x))))) (* (/ 0.5 x) (pow (+ 1.0 x) -0.5))))
double code(double x) {
double tmp;
if (x <= 2e+105) {
tmp = pow(x, -0.5) / ((1.0 + x) + sqrt((x * (1.0 + x))));
} else {
tmp = (0.5 / x) * pow((1.0 + x), -0.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 2d+105) then
tmp = (x ** (-0.5d0)) / ((1.0d0 + x) + sqrt((x * (1.0d0 + x))))
else
tmp = (0.5d0 / x) * ((1.0d0 + x) ** (-0.5d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 2e+105) {
tmp = Math.pow(x, -0.5) / ((1.0 + x) + Math.sqrt((x * (1.0 + x))));
} else {
tmp = (0.5 / x) * Math.pow((1.0 + x), -0.5);
}
return tmp;
}
def code(x): tmp = 0 if x <= 2e+105: tmp = math.pow(x, -0.5) / ((1.0 + x) + math.sqrt((x * (1.0 + x)))) else: tmp = (0.5 / x) * math.pow((1.0 + x), -0.5) return tmp
function code(x) tmp = 0.0 if (x <= 2e+105) tmp = Float64((x ^ -0.5) / Float64(Float64(1.0 + x) + sqrt(Float64(x * Float64(1.0 + x))))); else tmp = Float64(Float64(0.5 / x) * (Float64(1.0 + x) ^ -0.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 2e+105) tmp = (x ^ -0.5) / ((1.0 + x) + sqrt((x * (1.0 + x)))); else tmp = (0.5 / x) * ((1.0 + x) ^ -0.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 2e+105], N[(N[Power[x, -0.5], $MachinePrecision] / N[(N[(1.0 + x), $MachinePrecision] + N[Sqrt[N[(x * N[(1.0 + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 / x), $MachinePrecision] * N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2 \cdot 10^{+105}:\\
\;\;\;\;\frac{{x}^{-0.5}}{\left(1 + x\right) + \sqrt{x \cdot \left(1 + x\right)}}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{x} \cdot {\left(1 + x\right)}^{-0.5}\\
\end{array}
\end{array}
if x < 1.9999999999999999e105Initial program 71.4%
frac-sub71.5%
*-un-lft-identity71.5%
+-commutative71.5%
*-rgt-identity71.5%
sqrt-unprod71.5%
+-commutative71.5%
Applied egg-rr71.5%
flip--72.1%
add-sqr-sqrt71.9%
add-sqr-sqrt72.5%
+-commutative72.5%
+-commutative72.5%
Applied egg-rr72.5%
div-inv72.5%
+-commutative72.5%
sqrt-prod72.4%
times-frac72.4%
associate--l+72.4%
Applied egg-rr72.4%
associate-+r-72.4%
+-commutative72.4%
associate-+r-99.2%
+-inverses99.2%
metadata-eval99.2%
associate-*l/99.3%
*-lft-identity99.3%
associate-/l/99.3%
distribute-lft-in99.3%
rem-square-sqrt99.5%
+-commutative99.5%
+-commutative99.5%
Simplified99.5%
div-inv99.4%
+-commutative99.4%
+-commutative99.4%
sqrt-unprod99.5%
+-commutative99.5%
pow1/299.5%
pow-flip99.8%
metadata-eval99.8%
Applied egg-rr99.8%
associate-*l/99.8%
*-lft-identity99.8%
+-commutative99.8%
+-commutative99.8%
*-commutative99.8%
+-commutative99.8%
Simplified99.8%
if 1.9999999999999999e105 < x Initial program 50.3%
frac-sub50.3%
associate-/r*50.3%
*-un-lft-identity50.3%
+-commutative50.3%
*-rgt-identity50.3%
+-commutative50.3%
Applied egg-rr50.3%
div-sub50.3%
sqrt-undiv50.3%
+-commutative50.3%
*-inverses50.3%
Applied egg-rr50.3%
Taylor expanded in x around inf 50.3%
associate-*r/50.3%
metadata-eval50.3%
Simplified50.3%
div-inv50.3%
add-exp-log50.3%
log1p-udef50.3%
expm1-udef99.6%
expm1-log1p-u99.6%
pow1/299.6%
+-commutative99.6%
pow-flip99.7%
+-commutative99.7%
metadata-eval99.7%
Applied egg-rr99.7%
+-commutative99.7%
Simplified99.7%
Final simplification99.8%
(FPCore (x) :precision binary64 (/ (/ 1.0 (+ (* (sqrt (+ 1.0 x)) (sqrt x)) (+ 1.0 x))) (sqrt x)))
double code(double x) {
return (1.0 / ((sqrt((1.0 + x)) * sqrt(x)) + (1.0 + x))) / sqrt(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / ((sqrt((1.0d0 + x)) * sqrt(x)) + (1.0d0 + x))) / sqrt(x)
end function
public static double code(double x) {
return (1.0 / ((Math.sqrt((1.0 + x)) * Math.sqrt(x)) + (1.0 + x))) / Math.sqrt(x);
}
def code(x): return (1.0 / ((math.sqrt((1.0 + x)) * math.sqrt(x)) + (1.0 + x))) / math.sqrt(x)
function code(x) return Float64(Float64(1.0 / Float64(Float64(sqrt(Float64(1.0 + x)) * sqrt(x)) + Float64(1.0 + x))) / sqrt(x)) end
function tmp = code(x) tmp = (1.0 / ((sqrt((1.0 + x)) * sqrt(x)) + (1.0 + x))) / sqrt(x); end
code[x_] := N[(N[(1.0 / N[(N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(1.0 + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{\sqrt{1 + x} \cdot \sqrt{x} + \left(1 + x\right)}}{\sqrt{x}}
\end{array}
Initial program 64.0%
frac-sub64.0%
*-un-lft-identity64.0%
+-commutative64.0%
*-rgt-identity64.0%
sqrt-unprod64.0%
+-commutative64.0%
Applied egg-rr64.0%
flip--64.5%
add-sqr-sqrt64.2%
add-sqr-sqrt64.7%
+-commutative64.7%
+-commutative64.7%
Applied egg-rr64.7%
div-inv64.7%
+-commutative64.7%
sqrt-prod64.7%
times-frac64.7%
associate--l+64.7%
Applied egg-rr64.7%
associate-+r-64.7%
+-commutative64.7%
associate-+r-99.3%
+-inverses99.3%
metadata-eval99.3%
associate-*l/99.3%
*-lft-identity99.3%
associate-/l/99.3%
distribute-lft-in99.3%
rem-square-sqrt99.5%
+-commutative99.5%
+-commutative99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x) :precision binary64 (if (<= x 3550.0) (- (pow x -0.5) (pow (+ 1.0 x) -0.5)) (/ (/ 1.0 (+ 1.5 (- (* x 2.0) (/ 0.125 x)))) (sqrt x))))
double code(double x) {
double tmp;
if (x <= 3550.0) {
tmp = pow(x, -0.5) - pow((1.0 + x), -0.5);
} else {
tmp = (1.0 / (1.5 + ((x * 2.0) - (0.125 / x)))) / sqrt(x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 3550.0d0) then
tmp = (x ** (-0.5d0)) - ((1.0d0 + x) ** (-0.5d0))
else
tmp = (1.0d0 / (1.5d0 + ((x * 2.0d0) - (0.125d0 / x)))) / sqrt(x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 3550.0) {
tmp = Math.pow(x, -0.5) - Math.pow((1.0 + x), -0.5);
} else {
tmp = (1.0 / (1.5 + ((x * 2.0) - (0.125 / x)))) / Math.sqrt(x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 3550.0: tmp = math.pow(x, -0.5) - math.pow((1.0 + x), -0.5) else: tmp = (1.0 / (1.5 + ((x * 2.0) - (0.125 / x)))) / math.sqrt(x) return tmp
function code(x) tmp = 0.0 if (x <= 3550.0) tmp = Float64((x ^ -0.5) - (Float64(1.0 + x) ^ -0.5)); else tmp = Float64(Float64(1.0 / Float64(1.5 + Float64(Float64(x * 2.0) - Float64(0.125 / x)))) / sqrt(x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 3550.0) tmp = (x ^ -0.5) - ((1.0 + x) ^ -0.5); else tmp = (1.0 / (1.5 + ((x * 2.0) - (0.125 / x)))) / sqrt(x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 3550.0], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(1.5 + N[(N[(x * 2.0), $MachinePrecision] - N[(0.125 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3550:\\
\;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{1.5 + \left(x \cdot 2 - \frac{0.125}{x}\right)}}{\sqrt{x}}\\
\end{array}
\end{array}
if x < 3550Initial 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%
+-commutative100.0%
sub-neg100.0%
fma-udef100.0%
distribute-lft1-in100.0%
metadata-eval100.0%
mul0-lft100.0%
+-commutative100.0%
associate-+r+100.0%
sub-neg100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
if 3550 < x Initial program 35.4%
frac-sub35.5%
*-un-lft-identity35.5%
+-commutative35.5%
*-rgt-identity35.5%
sqrt-unprod35.5%
+-commutative35.5%
Applied egg-rr35.5%
flip--36.3%
add-sqr-sqrt35.9%
add-sqr-sqrt36.7%
+-commutative36.7%
+-commutative36.7%
Applied egg-rr36.7%
div-inv36.7%
+-commutative36.7%
sqrt-prod36.7%
times-frac36.7%
associate--l+36.7%
Applied egg-rr36.7%
associate-+r-36.7%
+-commutative36.7%
associate-+r-99.1%
+-inverses99.1%
metadata-eval99.1%
associate-*l/99.2%
*-lft-identity99.2%
associate-/l/99.2%
distribute-lft-in99.2%
rem-square-sqrt99.4%
+-commutative99.4%
+-commutative99.4%
Simplified99.4%
Taylor expanded in x around inf 99.5%
associate--l+99.5%
*-commutative99.5%
associate-*r/99.5%
metadata-eval99.5%
Simplified99.5%
Final simplification99.7%
(FPCore (x) :precision binary64 (if (<= x 0.51) (+ (/ 1.0 (sqrt x)) (- -1.0 (* x (+ -0.5 (* x 0.375))))) (/ (/ 1.0 (+ 1.5 (* x 2.0))) (sqrt x))))
double code(double x) {
double tmp;
if (x <= 0.51) {
tmp = (1.0 / sqrt(x)) + (-1.0 - (x * (-0.5 + (x * 0.375))));
} else {
tmp = (1.0 / (1.5 + (x * 2.0))) / sqrt(x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.51d0) then
tmp = (1.0d0 / sqrt(x)) + ((-1.0d0) - (x * ((-0.5d0) + (x * 0.375d0))))
else
tmp = (1.0d0 / (1.5d0 + (x * 2.0d0))) / sqrt(x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.51) {
tmp = (1.0 / Math.sqrt(x)) + (-1.0 - (x * (-0.5 + (x * 0.375))));
} else {
tmp = (1.0 / (1.5 + (x * 2.0))) / Math.sqrt(x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.51: tmp = (1.0 / math.sqrt(x)) + (-1.0 - (x * (-0.5 + (x * 0.375)))) else: tmp = (1.0 / (1.5 + (x * 2.0))) / math.sqrt(x) return tmp
function code(x) tmp = 0.0 if (x <= 0.51) tmp = Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 - Float64(x * Float64(-0.5 + Float64(x * 0.375))))); else tmp = Float64(Float64(1.0 / Float64(1.5 + Float64(x * 2.0))) / sqrt(x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.51) tmp = (1.0 / sqrt(x)) + (-1.0 - (x * (-0.5 + (x * 0.375)))); else tmp = (1.0 / (1.5 + (x * 2.0))) / sqrt(x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.51], N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 - N[(x * N[(-0.5 + N[(x * 0.375), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(1.5 + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.51:\\
\;\;\;\;\frac{1}{\sqrt{x}} + \left(-1 - x \cdot \left(-0.5 + x \cdot 0.375\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{1.5 + x \cdot 2}}{\sqrt{x}}\\
\end{array}
\end{array}
if x < 0.51000000000000001Initial program 99.6%
Taylor expanded in x around 0 98.0%
*-commutative98.0%
*-commutative98.0%
unpow298.0%
associate-*l*98.0%
distribute-lft-out98.0%
Simplified98.0%
if 0.51000000000000001 < x Initial program 35.4%
frac-sub35.5%
*-un-lft-identity35.5%
+-commutative35.5%
*-rgt-identity35.5%
sqrt-unprod35.5%
+-commutative35.5%
Applied egg-rr35.5%
flip--36.3%
add-sqr-sqrt35.9%
add-sqr-sqrt36.7%
+-commutative36.7%
+-commutative36.7%
Applied egg-rr36.7%
div-inv36.7%
+-commutative36.7%
sqrt-prod36.7%
times-frac36.7%
associate--l+36.7%
Applied egg-rr36.7%
associate-+r-36.7%
+-commutative36.7%
associate-+r-99.1%
+-inverses99.1%
metadata-eval99.1%
associate-*l/99.2%
*-lft-identity99.2%
associate-/l/99.2%
distribute-lft-in99.2%
rem-square-sqrt99.4%
+-commutative99.4%
+-commutative99.4%
Simplified99.4%
Taylor expanded in x around inf 99.2%
*-commutative99.2%
Simplified99.2%
Final simplification98.7%
(FPCore (x) :precision binary64 (if (<= x 0.51) (+ (/ 1.0 (sqrt x)) (- -1.0 (* x (+ -0.5 (* x 0.375))))) (/ (/ 1.0 (+ 1.5 (- (* x 2.0) (/ 0.125 x)))) (sqrt x))))
double code(double x) {
double tmp;
if (x <= 0.51) {
tmp = (1.0 / sqrt(x)) + (-1.0 - (x * (-0.5 + (x * 0.375))));
} else {
tmp = (1.0 / (1.5 + ((x * 2.0) - (0.125 / x)))) / sqrt(x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.51d0) then
tmp = (1.0d0 / sqrt(x)) + ((-1.0d0) - (x * ((-0.5d0) + (x * 0.375d0))))
else
tmp = (1.0d0 / (1.5d0 + ((x * 2.0d0) - (0.125d0 / x)))) / sqrt(x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.51) {
tmp = (1.0 / Math.sqrt(x)) + (-1.0 - (x * (-0.5 + (x * 0.375))));
} else {
tmp = (1.0 / (1.5 + ((x * 2.0) - (0.125 / x)))) / Math.sqrt(x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.51: tmp = (1.0 / math.sqrt(x)) + (-1.0 - (x * (-0.5 + (x * 0.375)))) else: tmp = (1.0 / (1.5 + ((x * 2.0) - (0.125 / x)))) / math.sqrt(x) return tmp
function code(x) tmp = 0.0 if (x <= 0.51) tmp = Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 - Float64(x * Float64(-0.5 + Float64(x * 0.375))))); else tmp = Float64(Float64(1.0 / Float64(1.5 + Float64(Float64(x * 2.0) - Float64(0.125 / x)))) / sqrt(x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.51) tmp = (1.0 / sqrt(x)) + (-1.0 - (x * (-0.5 + (x * 0.375)))); else tmp = (1.0 / (1.5 + ((x * 2.0) - (0.125 / x)))) / sqrt(x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.51], N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 - N[(x * N[(-0.5 + N[(x * 0.375), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(1.5 + N[(N[(x * 2.0), $MachinePrecision] - N[(0.125 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.51:\\
\;\;\;\;\frac{1}{\sqrt{x}} + \left(-1 - x \cdot \left(-0.5 + x \cdot 0.375\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{1.5 + \left(x \cdot 2 - \frac{0.125}{x}\right)}}{\sqrt{x}}\\
\end{array}
\end{array}
if x < 0.51000000000000001Initial program 99.6%
Taylor expanded in x around 0 98.0%
*-commutative98.0%
*-commutative98.0%
unpow298.0%
associate-*l*98.0%
distribute-lft-out98.0%
Simplified98.0%
if 0.51000000000000001 < x Initial program 35.4%
frac-sub35.5%
*-un-lft-identity35.5%
+-commutative35.5%
*-rgt-identity35.5%
sqrt-unprod35.5%
+-commutative35.5%
Applied egg-rr35.5%
flip--36.3%
add-sqr-sqrt35.9%
add-sqr-sqrt36.7%
+-commutative36.7%
+-commutative36.7%
Applied egg-rr36.7%
div-inv36.7%
+-commutative36.7%
sqrt-prod36.7%
times-frac36.7%
associate--l+36.7%
Applied egg-rr36.7%
associate-+r-36.7%
+-commutative36.7%
associate-+r-99.1%
+-inverses99.1%
metadata-eval99.1%
associate-*l/99.2%
*-lft-identity99.2%
associate-/l/99.2%
distribute-lft-in99.2%
rem-square-sqrt99.4%
+-commutative99.4%
+-commutative99.4%
Simplified99.4%
Taylor expanded in x around inf 99.5%
associate--l+99.5%
*-commutative99.5%
associate-*r/99.5%
metadata-eval99.5%
Simplified99.5%
Final simplification98.8%
(FPCore (x) :precision binary64 (if (<= x 0.41) (+ (+ (pow x -0.5) (* x 0.5)) -1.0) (/ (/ 1.0 (+ 1.5 (* x 2.0))) (sqrt x))))
double code(double x) {
double tmp;
if (x <= 0.41) {
tmp = (pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = (1.0 / (1.5 + (x * 2.0))) / sqrt(x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.41d0) then
tmp = ((x ** (-0.5d0)) + (x * 0.5d0)) + (-1.0d0)
else
tmp = (1.0d0 / (1.5d0 + (x * 2.0d0))) / sqrt(x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.41) {
tmp = (Math.pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = (1.0 / (1.5 + (x * 2.0))) / Math.sqrt(x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.41: tmp = (math.pow(x, -0.5) + (x * 0.5)) + -1.0 else: tmp = (1.0 / (1.5 + (x * 2.0))) / math.sqrt(x) return tmp
function code(x) tmp = 0.0 if (x <= 0.41) tmp = Float64(Float64((x ^ -0.5) + Float64(x * 0.5)) + -1.0); else tmp = Float64(Float64(1.0 / Float64(1.5 + Float64(x * 2.0))) / sqrt(x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.41) tmp = ((x ^ -0.5) + (x * 0.5)) + -1.0; else tmp = (1.0 / (1.5 + (x * 2.0))) / sqrt(x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.41], N[(N[(N[Power[x, -0.5], $MachinePrecision] + N[(x * 0.5), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(1.0 / N[(1.5 + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.41:\\
\;\;\;\;\left({x}^{-0.5} + x \cdot 0.5\right) + -1\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{1.5 + x \cdot 2}}{\sqrt{x}}\\
\end{array}
\end{array}
if x < 0.409999999999999976Initial 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%
+-commutative100.0%
sub-neg100.0%
fma-udef100.0%
distribute-lft1-in100.0%
metadata-eval100.0%
mul0-lft100.0%
+-commutative100.0%
associate-+r+100.0%
sub-neg100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 97.5%
if 0.409999999999999976 < x Initial program 35.4%
frac-sub35.5%
*-un-lft-identity35.5%
+-commutative35.5%
*-rgt-identity35.5%
sqrt-unprod35.5%
+-commutative35.5%
Applied egg-rr35.5%
flip--36.3%
add-sqr-sqrt35.9%
add-sqr-sqrt36.7%
+-commutative36.7%
+-commutative36.7%
Applied egg-rr36.7%
div-inv36.7%
+-commutative36.7%
sqrt-prod36.7%
times-frac36.7%
associate--l+36.7%
Applied egg-rr36.7%
associate-+r-36.7%
+-commutative36.7%
associate-+r-99.1%
+-inverses99.1%
metadata-eval99.1%
associate-*l/99.2%
*-lft-identity99.2%
associate-/l/99.2%
distribute-lft-in99.2%
rem-square-sqrt99.4%
+-commutative99.4%
+-commutative99.4%
Simplified99.4%
Taylor expanded in x around inf 99.2%
*-commutative99.2%
Simplified99.2%
Final simplification98.4%
(FPCore (x) :precision binary64 (if (<= x 0.7) (+ (+ (pow x -0.5) (* x 0.5)) -1.0) (/ (/ 0.5 x) (sqrt (+ 1.0 x)))))
double code(double x) {
double tmp;
if (x <= 0.7) {
tmp = (pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = (0.5 / x) / sqrt((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)) + (x * 0.5d0)) + (-1.0d0)
else
tmp = (0.5d0 / x) / sqrt((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) + (x * 0.5)) + -1.0;
} else {
tmp = (0.5 / x) / Math.sqrt((1.0 + x));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.7: tmp = (math.pow(x, -0.5) + (x * 0.5)) + -1.0 else: tmp = (0.5 / x) / math.sqrt((1.0 + x)) return tmp
function code(x) tmp = 0.0 if (x <= 0.7) tmp = Float64(Float64((x ^ -0.5) + Float64(x * 0.5)) + -1.0); else tmp = Float64(Float64(0.5 / x) / sqrt(Float64(1.0 + x))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.7) tmp = ((x ^ -0.5) + (x * 0.5)) + -1.0; else tmp = (0.5 / x) / sqrt((1.0 + x)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.7], N[(N[(N[Power[x, -0.5], $MachinePrecision] + N[(x * 0.5), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(0.5 / x), $MachinePrecision] / N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.7:\\
\;\;\;\;\left({x}^{-0.5} + x \cdot 0.5\right) + -1\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{0.5}{x}}{\sqrt{1 + x}}\\
\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%
+-commutative100.0%
sub-neg100.0%
fma-udef100.0%
distribute-lft1-in100.0%
metadata-eval100.0%
mul0-lft100.0%
+-commutative100.0%
associate-+r+100.0%
sub-neg100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 97.5%
if 0.69999999999999996 < x Initial program 35.4%
frac-sub35.5%
associate-/r*35.5%
*-un-lft-identity35.5%
+-commutative35.5%
*-rgt-identity35.5%
+-commutative35.5%
Applied egg-rr35.5%
div-sub35.5%
sqrt-undiv35.5%
+-commutative35.5%
*-inverses35.5%
Applied egg-rr35.5%
Taylor expanded in x around inf 98.1%
Final simplification97.8%
(FPCore (x) :precision binary64 (if (<= x 0.48) (+ (pow x -0.5) -1.0) (/ (/ 0.5 x) (sqrt (+ 1.0 x)))))
double code(double x) {
double tmp;
if (x <= 0.48) {
tmp = pow(x, -0.5) + -1.0;
} else {
tmp = (0.5 / x) / sqrt((1.0 + x));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.48d0) then
tmp = (x ** (-0.5d0)) + (-1.0d0)
else
tmp = (0.5d0 / x) / sqrt((1.0d0 + x))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.48) {
tmp = Math.pow(x, -0.5) + -1.0;
} else {
tmp = (0.5 / x) / Math.sqrt((1.0 + x));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.48: tmp = math.pow(x, -0.5) + -1.0 else: tmp = (0.5 / x) / math.sqrt((1.0 + x)) return tmp
function code(x) tmp = 0.0 if (x <= 0.48) tmp = Float64((x ^ -0.5) + -1.0); else tmp = Float64(Float64(0.5 / x) / sqrt(Float64(1.0 + x))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.48) tmp = (x ^ -0.5) + -1.0; else tmp = (0.5 / x) / sqrt((1.0 + x)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.48], N[(N[Power[x, -0.5], $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(0.5 / x), $MachinePrecision] / N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.48:\\
\;\;\;\;{x}^{-0.5} + -1\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{0.5}{x}}{\sqrt{1 + x}}\\
\end{array}
\end{array}
if x < 0.47999999999999998Initial program 99.6%
*-un-lft-identity99.6%
clear-num99.6%
associate-/r/99.6%
prod-diff99.6%
*-un-lft-identity99.6%
fma-neg99.6%
*-un-lft-identity99.6%
pow1/299.6%
pow-flip100.0%
metadata-eval100.0%
pow1/2100.0%
pow-flip100.0%
+-commutative100.0%
metadata-eval100.0%
Applied egg-rr100.0%
+-commutative100.0%
sub-neg100.0%
fma-udef100.0%
distribute-lft1-in100.0%
metadata-eval100.0%
mul0-lft100.0%
+-commutative100.0%
associate-+r+100.0%
sub-neg100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 96.2%
if 0.47999999999999998 < x Initial program 35.4%
frac-sub35.5%
associate-/r*35.5%
*-un-lft-identity35.5%
+-commutative35.5%
*-rgt-identity35.5%
+-commutative35.5%
Applied egg-rr35.5%
div-sub35.5%
sqrt-undiv35.5%
+-commutative35.5%
*-inverses35.5%
Applied egg-rr35.5%
Taylor expanded in x around inf 98.1%
Final simplification97.3%
(FPCore (x) :precision binary64 (if (<= x 0.68) (+ (pow x -0.5) -1.0) (/ (/ 0.5 x) (sqrt x))))
double code(double x) {
double tmp;
if (x <= 0.68) {
tmp = pow(x, -0.5) + -1.0;
} else {
tmp = (0.5 / x) / sqrt(x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.68d0) then
tmp = (x ** (-0.5d0)) + (-1.0d0)
else
tmp = (0.5d0 / x) / sqrt(x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.68) {
tmp = Math.pow(x, -0.5) + -1.0;
} else {
tmp = (0.5 / x) / Math.sqrt(x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.68: tmp = math.pow(x, -0.5) + -1.0 else: tmp = (0.5 / x) / math.sqrt(x) return tmp
function code(x) tmp = 0.0 if (x <= 0.68) tmp = Float64((x ^ -0.5) + -1.0); else tmp = Float64(Float64(0.5 / x) / sqrt(x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.68) tmp = (x ^ -0.5) + -1.0; else tmp = (0.5 / x) / sqrt(x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.68], N[(N[Power[x, -0.5], $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(0.5 / x), $MachinePrecision] / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.68:\\
\;\;\;\;{x}^{-0.5} + -1\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{0.5}{x}}{\sqrt{x}}\\
\end{array}
\end{array}
if x < 0.680000000000000049Initial program 99.6%
*-un-lft-identity99.6%
clear-num99.6%
associate-/r/99.6%
prod-diff99.6%
*-un-lft-identity99.6%
fma-neg99.6%
*-un-lft-identity99.6%
pow1/299.6%
pow-flip100.0%
metadata-eval100.0%
pow1/2100.0%
pow-flip100.0%
+-commutative100.0%
metadata-eval100.0%
Applied egg-rr100.0%
+-commutative100.0%
sub-neg100.0%
fma-udef100.0%
distribute-lft1-in100.0%
metadata-eval100.0%
mul0-lft100.0%
+-commutative100.0%
associate-+r+100.0%
sub-neg100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 96.2%
if 0.680000000000000049 < x Initial program 35.4%
frac-sub35.5%
*-un-lft-identity35.5%
+-commutative35.5%
*-rgt-identity35.5%
sqrt-unprod35.5%
+-commutative35.5%
Applied egg-rr35.5%
flip--36.3%
add-sqr-sqrt35.9%
add-sqr-sqrt36.7%
+-commutative36.7%
+-commutative36.7%
Applied egg-rr36.7%
div-inv36.7%
+-commutative36.7%
sqrt-prod36.7%
times-frac36.7%
associate--l+36.7%
Applied egg-rr36.7%
associate-+r-36.7%
+-commutative36.7%
associate-+r-99.1%
+-inverses99.1%
metadata-eval99.1%
associate-*l/99.2%
*-lft-identity99.2%
associate-/l/99.2%
distribute-lft-in99.2%
rem-square-sqrt99.4%
+-commutative99.4%
+-commutative99.4%
Simplified99.4%
Taylor expanded in x around inf 98.0%
Final simplification97.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 64.0%
add-cube-cbrt51.1%
pow351.0%
pow1/251.0%
pow-flip51.5%
metadata-eval51.5%
Applied egg-rr51.5%
Taylor expanded in x around inf 44.5%
expm1-log1p-u41.4%
expm1-udef57.1%
inv-pow57.1%
sqrt-pow157.1%
metadata-eval57.1%
Applied egg-rr57.1%
expm1-def41.4%
expm1-log1p44.6%
Simplified44.6%
Final simplification44.6%
(FPCore (x) :precision binary64 -1.0)
double code(double x) {
return -1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = -1.0d0
end function
public static double code(double x) {
return -1.0;
}
def code(x): return -1.0
function code(x) return -1.0 end
function tmp = code(x) tmp = -1.0; end
code[x_] := -1.0
\begin{array}{l}
\\
-1
\end{array}
Initial program 64.0%
Taylor expanded in x around 0 44.1%
Taylor expanded in x around inf 2.0%
Final simplification2.0%
(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 64.0%
frac-sub64.0%
*-un-lft-identity64.0%
+-commutative64.0%
*-rgt-identity64.0%
sqrt-unprod64.0%
+-commutative64.0%
Applied egg-rr64.0%
Taylor expanded in x around inf 22.9%
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 2024020
(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)))))