
(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 10 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 (+ x 1.0)))) 5e-7)
(/
(pow x -0.5)
(+ (+ x 1.0) (- (+ 0.5 (+ x (/ 0.0625 (* x x)))) (/ 0.125 x))))
(- (pow x -0.5) (pow (+ x 1.0) -0.5))))
double code(double x) {
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / sqrt((x + 1.0)))) <= 5e-7) {
tmp = pow(x, -0.5) / ((x + 1.0) + ((0.5 + (x + (0.0625 / (x * x)))) - (0.125 / x)));
} else {
tmp = pow(x, -0.5) - pow((x + 1.0), -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((x + 1.0d0)))) <= 5d-7) then
tmp = (x ** (-0.5d0)) / ((x + 1.0d0) + ((0.5d0 + (x + (0.0625d0 / (x * x)))) - (0.125d0 / x)))
else
tmp = (x ** (-0.5d0)) - ((x + 1.0d0) ** (-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((x + 1.0)))) <= 5e-7) {
tmp = Math.pow(x, -0.5) / ((x + 1.0) + ((0.5 + (x + (0.0625 / (x * x)))) - (0.125 / x)));
} else {
tmp = Math.pow(x, -0.5) - Math.pow((x + 1.0), -0.5);
}
return tmp;
}
def code(x): tmp = 0 if ((1.0 / math.sqrt(x)) + (-1.0 / math.sqrt((x + 1.0)))) <= 5e-7: tmp = math.pow(x, -0.5) / ((x + 1.0) + ((0.5 + (x + (0.0625 / (x * x)))) - (0.125 / x))) else: tmp = math.pow(x, -0.5) - math.pow((x + 1.0), -0.5) return tmp
function code(x) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / sqrt(Float64(x + 1.0)))) <= 5e-7) tmp = Float64((x ^ -0.5) / Float64(Float64(x + 1.0) + Float64(Float64(0.5 + Float64(x + Float64(0.0625 / Float64(x * x)))) - Float64(0.125 / x)))); else tmp = Float64((x ^ -0.5) - (Float64(x + 1.0) ^ -0.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (((1.0 / sqrt(x)) + (-1.0 / sqrt((x + 1.0)))) <= 5e-7) tmp = (x ^ -0.5) / ((x + 1.0) + ((0.5 + (x + (0.0625 / (x * x)))) - (0.125 / x))); else tmp = (x ^ -0.5) - ((x + 1.0) ^ -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[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e-7], N[(N[Power[x, -0.5], $MachinePrecision] / N[(N[(x + 1.0), $MachinePrecision] + N[(N[(0.5 + N[(x + N[(0.0625 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(0.125 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{x + 1}} \leq 5 \cdot 10^{-7}:\\
\;\;\;\;\frac{{x}^{-0.5}}{\left(x + 1\right) + \left(\left(0.5 + \left(x + \frac{0.0625}{x \cdot x}\right)\right) - \frac{0.125}{x}\right)}\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} - {\left(x + 1\right)}^{-0.5}\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 4.99999999999999977e-7Initial program 36.7%
frac-sub36.8%
div-inv36.8%
*-un-lft-identity36.8%
+-commutative36.8%
*-rgt-identity36.8%
metadata-eval36.8%
frac-times36.8%
un-div-inv36.8%
pow1/236.8%
pow-flip36.8%
metadata-eval36.8%
+-commutative36.8%
Applied egg-rr36.8%
flip--37.4%
add-sqr-sqrt25.4%
add-sqr-sqrt37.8%
Applied egg-rr37.8%
associate--l+99.3%
+-inverses99.3%
metadata-eval99.3%
Simplified99.3%
associate-*r/99.4%
clear-num98.0%
Applied egg-rr98.0%
associate-/r/99.3%
associate-*l/99.4%
*-lft-identity99.4%
times-frac99.5%
*-lft-identity99.5%
distribute-lft-in99.5%
rem-square-sqrt99.6%
Simplified99.6%
Taylor expanded in x around inf 99.8%
+-commutative99.8%
associate-*r/99.8%
metadata-eval99.8%
unpow299.8%
associate-*r/99.8%
metadata-eval99.8%
Simplified99.8%
if 4.99999999999999977e-7 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial 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%
Final simplification99.9%
(FPCore (x) :precision binary64 (/ (pow x -0.5) (+ (+ x 1.0) (* (sqrt (+ x 1.0)) (sqrt x)))))
double code(double x) {
return pow(x, -0.5) / ((x + 1.0) + (sqrt((x + 1.0)) * sqrt(x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x ** (-0.5d0)) / ((x + 1.0d0) + (sqrt((x + 1.0d0)) * sqrt(x)))
end function
public static double code(double x) {
return Math.pow(x, -0.5) / ((x + 1.0) + (Math.sqrt((x + 1.0)) * Math.sqrt(x)));
}
def code(x): return math.pow(x, -0.5) / ((x + 1.0) + (math.sqrt((x + 1.0)) * math.sqrt(x)))
function code(x) return Float64((x ^ -0.5) / Float64(Float64(x + 1.0) + Float64(sqrt(Float64(x + 1.0)) * sqrt(x)))) end
function tmp = code(x) tmp = (x ^ -0.5) / ((x + 1.0) + (sqrt((x + 1.0)) * sqrt(x))); end
code[x_] := N[(N[Power[x, -0.5], $MachinePrecision] / N[(N[(x + 1.0), $MachinePrecision] + N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{x}^{-0.5}}{\left(x + 1\right) + \sqrt{x + 1} \cdot \sqrt{x}}
\end{array}
Initial program 70.4%
frac-sub70.4%
div-inv70.4%
*-un-lft-identity70.4%
+-commutative70.4%
*-rgt-identity70.4%
metadata-eval70.4%
frac-times70.4%
un-div-inv70.4%
pow1/270.4%
pow-flip70.6%
metadata-eval70.6%
+-commutative70.6%
Applied egg-rr70.6%
flip--70.9%
add-sqr-sqrt65.3%
add-sqr-sqrt71.0%
Applied egg-rr71.0%
associate--l+99.7%
+-inverses99.7%
metadata-eval99.7%
Simplified99.7%
associate-*r/99.7%
clear-num98.9%
Applied egg-rr98.9%
associate-/r/99.6%
associate-*l/99.7%
*-lft-identity99.7%
times-frac99.7%
*-lft-identity99.7%
distribute-lft-in99.7%
rem-square-sqrt99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x) :precision binary64 (/ 1.0 (* x (* (+ x 1.0) (+ (pow x -0.5) (pow (+ x 1.0) -0.5))))))
double code(double x) {
return 1.0 / (x * ((x + 1.0) * (pow(x, -0.5) + pow((x + 1.0), -0.5))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (x * ((x + 1.0d0) * ((x ** (-0.5d0)) + ((x + 1.0d0) ** (-0.5d0)))))
end function
public static double code(double x) {
return 1.0 / (x * ((x + 1.0) * (Math.pow(x, -0.5) + Math.pow((x + 1.0), -0.5))));
}
def code(x): return 1.0 / (x * ((x + 1.0) * (math.pow(x, -0.5) + math.pow((x + 1.0), -0.5))))
function code(x) return Float64(1.0 / Float64(x * Float64(Float64(x + 1.0) * Float64((x ^ -0.5) + (Float64(x + 1.0) ^ -0.5))))) end
function tmp = code(x) tmp = 1.0 / (x * ((x + 1.0) * ((x ^ -0.5) + ((x + 1.0) ^ -0.5)))); end
code[x_] := N[(1.0 / N[(x * N[(N[(x + 1.0), $MachinePrecision] * N[(N[Power[x, -0.5], $MachinePrecision] + N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x \cdot \left(\left(x + 1\right) \cdot \left({x}^{-0.5} + {\left(x + 1\right)}^{-0.5}\right)\right)}
\end{array}
Initial program 70.4%
*-un-lft-identity70.4%
clear-num70.4%
associate-/r/70.4%
prod-diff70.4%
*-un-lft-identity70.4%
fma-neg70.4%
*-un-lft-identity70.4%
inv-pow70.4%
sqrt-pow266.5%
metadata-eval66.5%
pow1/266.5%
pow-flip70.6%
+-commutative70.6%
metadata-eval70.6%
Applied egg-rr70.6%
fma-udef70.6%
distribute-lft1-in70.6%
metadata-eval70.6%
mul0-lft70.6%
+-rgt-identity70.6%
Simplified70.6%
flip--70.5%
pow-prod-up62.0%
metadata-eval62.0%
inv-pow62.0%
pow-prod-up70.2%
metadata-eval70.2%
inv-pow70.2%
div-inv70.1%
frac-sub70.6%
frac-times70.7%
*-un-lft-identity70.7%
*-rgt-identity70.7%
+-commutative70.7%
Applied egg-rr70.7%
*-rgt-identity70.7%
associate--l+88.8%
+-inverses88.8%
metadata-eval88.8%
associate-*l*98.7%
+-commutative98.7%
Simplified98.7%
Final simplification98.7%
(FPCore (x)
:precision binary64
(if (<= x 0.43)
(+ (pow x -0.5) (- -1.0 (* x -0.5)))
(/
(pow x -0.5)
(+ (+ x 1.0) (- (+ 0.5 (+ x (/ 0.0625 (* x x)))) (/ 0.125 x))))))
double code(double x) {
double tmp;
if (x <= 0.43) {
tmp = pow(x, -0.5) + (-1.0 - (x * -0.5));
} else {
tmp = pow(x, -0.5) / ((x + 1.0) + ((0.5 + (x + (0.0625 / (x * x)))) - (0.125 / x)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.43d0) then
tmp = (x ** (-0.5d0)) + ((-1.0d0) - (x * (-0.5d0)))
else
tmp = (x ** (-0.5d0)) / ((x + 1.0d0) + ((0.5d0 + (x + (0.0625d0 / (x * x)))) - (0.125d0 / x)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.43) {
tmp = Math.pow(x, -0.5) + (-1.0 - (x * -0.5));
} else {
tmp = Math.pow(x, -0.5) / ((x + 1.0) + ((0.5 + (x + (0.0625 / (x * x)))) - (0.125 / x)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.43: tmp = math.pow(x, -0.5) + (-1.0 - (x * -0.5)) else: tmp = math.pow(x, -0.5) / ((x + 1.0) + ((0.5 + (x + (0.0625 / (x * x)))) - (0.125 / x))) return tmp
function code(x) tmp = 0.0 if (x <= 0.43) tmp = Float64((x ^ -0.5) + Float64(-1.0 - Float64(x * -0.5))); else tmp = Float64((x ^ -0.5) / Float64(Float64(x + 1.0) + Float64(Float64(0.5 + Float64(x + Float64(0.0625 / Float64(x * x)))) - Float64(0.125 / x)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.43) tmp = (x ^ -0.5) + (-1.0 - (x * -0.5)); else tmp = (x ^ -0.5) / ((x + 1.0) + ((0.5 + (x + (0.0625 / (x * x)))) - (0.125 / x))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.43], N[(N[Power[x, -0.5], $MachinePrecision] + N[(-1.0 - N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] / N[(N[(x + 1.0), $MachinePrecision] + N[(N[(0.5 + N[(x + N[(0.0625 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(0.125 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.43:\\
\;\;\;\;{x}^{-0.5} + \left(-1 - x \cdot -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{{x}^{-0.5}}{\left(x + 1\right) + \left(\left(0.5 + \left(x + \frac{0.0625}{x \cdot x}\right)\right) - \frac{0.125}{x}\right)}\\
\end{array}
\end{array}
if x < 0.429999999999999993Initial 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.7%
if 0.429999999999999993 < x Initial program 36.7%
frac-sub36.8%
div-inv36.8%
*-un-lft-identity36.8%
+-commutative36.8%
*-rgt-identity36.8%
metadata-eval36.8%
frac-times36.8%
un-div-inv36.8%
pow1/236.8%
pow-flip36.8%
metadata-eval36.8%
+-commutative36.8%
Applied egg-rr36.8%
flip--37.4%
add-sqr-sqrt25.4%
add-sqr-sqrt37.8%
Applied egg-rr37.8%
associate--l+99.3%
+-inverses99.3%
metadata-eval99.3%
Simplified99.3%
associate-*r/99.4%
clear-num98.0%
Applied egg-rr98.0%
associate-/r/99.3%
associate-*l/99.4%
*-lft-identity99.4%
times-frac99.5%
*-lft-identity99.5%
distribute-lft-in99.5%
rem-square-sqrt99.6%
Simplified99.6%
Taylor expanded in x around inf 99.8%
+-commutative99.8%
associate-*r/99.8%
metadata-eval99.8%
unpow299.8%
associate-*r/99.8%
metadata-eval99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x) :precision binary64 (if (<= x 0.42) (+ (pow x -0.5) (- -1.0 (* x -0.5))) (/ (pow x -0.5) (+ 1.5 (- (* x 2.0) (/ 0.125 x))))))
double code(double x) {
double tmp;
if (x <= 0.42) {
tmp = pow(x, -0.5) + (-1.0 - (x * -0.5));
} else {
tmp = pow(x, -0.5) / (1.5 + ((x * 2.0) - (0.125 / x)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.42d0) then
tmp = (x ** (-0.5d0)) + ((-1.0d0) - (x * (-0.5d0)))
else
tmp = (x ** (-0.5d0)) / (1.5d0 + ((x * 2.0d0) - (0.125d0 / x)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.42) {
tmp = Math.pow(x, -0.5) + (-1.0 - (x * -0.5));
} else {
tmp = Math.pow(x, -0.5) / (1.5 + ((x * 2.0) - (0.125 / x)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.42: tmp = math.pow(x, -0.5) + (-1.0 - (x * -0.5)) else: tmp = math.pow(x, -0.5) / (1.5 + ((x * 2.0) - (0.125 / x))) return tmp
function code(x) tmp = 0.0 if (x <= 0.42) tmp = Float64((x ^ -0.5) + Float64(-1.0 - Float64(x * -0.5))); else tmp = Float64((x ^ -0.5) / Float64(1.5 + Float64(Float64(x * 2.0) - Float64(0.125 / x)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.42) tmp = (x ^ -0.5) + (-1.0 - (x * -0.5)); else tmp = (x ^ -0.5) / (1.5 + ((x * 2.0) - (0.125 / x))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.42], N[(N[Power[x, -0.5], $MachinePrecision] + N[(-1.0 - N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] / N[(1.5 + N[(N[(x * 2.0), $MachinePrecision] - N[(0.125 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.42:\\
\;\;\;\;{x}^{-0.5} + \left(-1 - x \cdot -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{{x}^{-0.5}}{1.5 + \left(x \cdot 2 - \frac{0.125}{x}\right)}\\
\end{array}
\end{array}
if x < 0.419999999999999984Initial 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.7%
if 0.419999999999999984 < x Initial program 36.7%
frac-sub36.8%
div-inv36.8%
*-un-lft-identity36.8%
+-commutative36.8%
*-rgt-identity36.8%
metadata-eval36.8%
frac-times36.8%
un-div-inv36.8%
pow1/236.8%
pow-flip36.8%
metadata-eval36.8%
+-commutative36.8%
Applied egg-rr36.8%
flip--37.4%
add-sqr-sqrt25.4%
add-sqr-sqrt37.8%
Applied egg-rr37.8%
associate--l+99.3%
+-inverses99.3%
metadata-eval99.3%
Simplified99.3%
associate-*r/99.4%
clear-num98.0%
Applied egg-rr98.0%
associate-/r/99.3%
associate-*l/99.4%
*-lft-identity99.4%
times-frac99.5%
*-lft-identity99.5%
distribute-lft-in99.5%
rem-square-sqrt99.6%
Simplified99.6%
Taylor expanded in x around inf 99.7%
associate--l+99.7%
*-commutative99.7%
associate-*r/99.7%
metadata-eval99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (x) :precision binary64 (if (<= x 1.0) (+ (pow x -0.5) (- -1.0 (* x -0.5))) (* 0.5 (pow x -1.5))))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = pow(x, -0.5) + (-1.0 - (x * -0.5));
} else {
tmp = 0.5 * pow(x, -1.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)) + ((-1.0d0) - (x * (-0.5d0)))
else
tmp = 0.5d0 * (x ** (-1.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) + (-1.0 - (x * -0.5));
} else {
tmp = 0.5 * Math.pow(x, -1.5);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = math.pow(x, -0.5) + (-1.0 - (x * -0.5)) else: tmp = 0.5 * math.pow(x, -1.5) return tmp
function code(x) tmp = 0.0 if (x <= 1.0) tmp = Float64((x ^ -0.5) + Float64(-1.0 - Float64(x * -0.5))); else tmp = Float64(0.5 * (x ^ -1.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.0) tmp = (x ^ -0.5) + (-1.0 - (x * -0.5)); else tmp = 0.5 * (x ^ -1.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], N[(N[Power[x, -0.5], $MachinePrecision] + N[(-1.0 - N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Power[x, -1.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;{x}^{-0.5} + \left(-1 - x \cdot -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {x}^{-1.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.7%
if 1 < x Initial program 36.7%
*-un-lft-identity36.7%
clear-num36.7%
associate-/r/36.7%
prod-diff36.7%
*-un-lft-identity36.7%
fma-neg36.7%
*-un-lft-identity36.7%
inv-pow36.7%
sqrt-pow228.0%
metadata-eval28.0%
pow1/228.0%
pow-flip36.7%
+-commutative36.7%
metadata-eval36.7%
Applied egg-rr36.7%
fma-udef36.7%
distribute-lft1-in36.7%
metadata-eval36.7%
mul0-lft36.7%
+-rgt-identity36.7%
Simplified36.7%
Taylor expanded in x around inf 59.6%
*-un-lft-identity59.6%
pow-flip60.3%
sqrt-pow198.4%
metadata-eval98.4%
metadata-eval98.4%
Applied egg-rr98.4%
*-lft-identity98.4%
Simplified98.4%
Final simplification99.1%
(FPCore (x) :precision binary64 (if (<= x 0.4) (+ (pow x -0.5) (- -1.0 (* x -0.5))) (/ (pow x -0.5) (+ 1.5 (* x 2.0)))))
double code(double x) {
double tmp;
if (x <= 0.4) {
tmp = pow(x, -0.5) + (-1.0 - (x * -0.5));
} else {
tmp = pow(x, -0.5) / (1.5 + (x * 2.0));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.4d0) then
tmp = (x ** (-0.5d0)) + ((-1.0d0) - (x * (-0.5d0)))
else
tmp = (x ** (-0.5d0)) / (1.5d0 + (x * 2.0d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.4) {
tmp = Math.pow(x, -0.5) + (-1.0 - (x * -0.5));
} else {
tmp = Math.pow(x, -0.5) / (1.5 + (x * 2.0));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.4: tmp = math.pow(x, -0.5) + (-1.0 - (x * -0.5)) else: tmp = math.pow(x, -0.5) / (1.5 + (x * 2.0)) return tmp
function code(x) tmp = 0.0 if (x <= 0.4) tmp = Float64((x ^ -0.5) + Float64(-1.0 - Float64(x * -0.5))); else tmp = Float64((x ^ -0.5) / Float64(1.5 + Float64(x * 2.0))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.4) tmp = (x ^ -0.5) + (-1.0 - (x * -0.5)); else tmp = (x ^ -0.5) / (1.5 + (x * 2.0)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.4], N[(N[Power[x, -0.5], $MachinePrecision] + N[(-1.0 - N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] / N[(1.5 + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.4:\\
\;\;\;\;{x}^{-0.5} + \left(-1 - x \cdot -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{{x}^{-0.5}}{1.5 + x \cdot 2}\\
\end{array}
\end{array}
if x < 0.40000000000000002Initial 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.7%
if 0.40000000000000002 < x Initial program 36.7%
frac-sub36.8%
div-inv36.8%
*-un-lft-identity36.8%
+-commutative36.8%
*-rgt-identity36.8%
metadata-eval36.8%
frac-times36.8%
un-div-inv36.8%
pow1/236.8%
pow-flip36.8%
metadata-eval36.8%
+-commutative36.8%
Applied egg-rr36.8%
flip--37.4%
add-sqr-sqrt25.4%
add-sqr-sqrt37.8%
Applied egg-rr37.8%
associate--l+99.3%
+-inverses99.3%
metadata-eval99.3%
Simplified99.3%
associate-*r/99.4%
clear-num98.0%
Applied egg-rr98.0%
associate-/r/99.3%
associate-*l/99.4%
*-lft-identity99.4%
times-frac99.5%
*-lft-identity99.5%
distribute-lft-in99.5%
rem-square-sqrt99.6%
Simplified99.6%
Taylor expanded in x around inf 99.3%
+-commutative99.3%
*-commutative99.3%
Simplified99.3%
Final simplification99.6%
(FPCore (x) :precision binary64 (if (<= x 0.66) (+ (pow x -0.5) -1.0) (* 0.5 (pow x -1.5))))
double code(double x) {
double tmp;
if (x <= 0.66) {
tmp = pow(x, -0.5) + -1.0;
} else {
tmp = 0.5 * pow(x, -1.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 ** (-1.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 * Math.pow(x, -1.5);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.66: tmp = math.pow(x, -0.5) + -1.0 else: tmp = 0.5 * math.pow(x, -1.5) return tmp
function code(x) tmp = 0.0 if (x <= 0.66) tmp = Float64((x ^ -0.5) + -1.0); else tmp = Float64(0.5 * (x ^ -1.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 ^ -1.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.66], N[(N[Power[x, -0.5], $MachinePrecision] + -1.0), $MachinePrecision], N[(0.5 * N[Power[x, -1.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.66:\\
\;\;\;\;{x}^{-0.5} + -1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {x}^{-1.5}\\
\end{array}
\end{array}
if x < 0.660000000000000031Initial program 99.6%
Taylor expanded in x around 0 98.9%
add-log-exp4.6%
*-un-lft-identity4.6%
log-prod4.6%
metadata-eval4.6%
add-log-exp98.9%
pow1/298.9%
pow-flip99.4%
metadata-eval99.4%
Applied egg-rr99.4%
+-lft-identity99.4%
Simplified99.4%
if 0.660000000000000031 < x Initial program 36.7%
*-un-lft-identity36.7%
clear-num36.7%
associate-/r/36.7%
prod-diff36.7%
*-un-lft-identity36.7%
fma-neg36.7%
*-un-lft-identity36.7%
inv-pow36.7%
sqrt-pow228.0%
metadata-eval28.0%
pow1/228.0%
pow-flip36.7%
+-commutative36.7%
metadata-eval36.7%
Applied egg-rr36.7%
fma-udef36.7%
distribute-lft1-in36.7%
metadata-eval36.7%
mul0-lft36.7%
+-rgt-identity36.7%
Simplified36.7%
Taylor expanded in x around inf 59.6%
*-un-lft-identity59.6%
pow-flip60.3%
sqrt-pow198.4%
metadata-eval98.4%
metadata-eval98.4%
Applied egg-rr98.4%
*-lft-identity98.4%
Simplified98.4%
Final simplification98.9%
(FPCore (x) :precision binary64 (* 0.5 (pow x -1.5)))
double code(double x) {
return 0.5 * pow(x, -1.5);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.5d0 * (x ** (-1.5d0))
end function
public static double code(double x) {
return 0.5 * Math.pow(x, -1.5);
}
def code(x): return 0.5 * math.pow(x, -1.5)
function code(x) return Float64(0.5 * (x ^ -1.5)) end
function tmp = code(x) tmp = 0.5 * (x ^ -1.5); end
code[x_] := N[(0.5 * N[Power[x, -1.5], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot {x}^{-1.5}
\end{array}
Initial program 70.4%
*-un-lft-identity70.4%
clear-num70.4%
associate-/r/70.4%
prod-diff70.4%
*-un-lft-identity70.4%
fma-neg70.4%
*-un-lft-identity70.4%
inv-pow70.4%
sqrt-pow266.5%
metadata-eval66.5%
pow1/266.5%
pow-flip70.6%
+-commutative70.6%
metadata-eval70.6%
Applied egg-rr70.6%
fma-udef70.6%
distribute-lft1-in70.6%
metadata-eval70.6%
mul0-lft70.6%
+-rgt-identity70.6%
Simplified70.6%
Taylor expanded in x around inf 30.5%
*-un-lft-identity30.5%
pow-flip30.9%
sqrt-pow148.7%
metadata-eval48.7%
metadata-eval48.7%
Applied egg-rr48.7%
*-lft-identity48.7%
Simplified48.7%
Final simplification48.7%
(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.4%
inv-pow70.4%
pow1/270.4%
pow-pow66.4%
add-exp-log56.2%
+-commutative56.2%
log1p-udef56.2%
pow-exp56.2%
metadata-eval56.2%
Applied egg-rr56.2%
Taylor expanded in x around inf 2.1%
mul-1-neg2.1%
Simplified2.1%
inv-pow2.1%
sqrt-pow12.1%
metadata-eval2.1%
expm1-log1p-u2.1%
expm1-udef16.6%
Applied egg-rr16.6%
expm1-def2.1%
expm1-log1p2.1%
Simplified2.1%
Final simplification2.1%
(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 2023274
(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)))))