
(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 14 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 (* (/ (pow x -0.5) (+ (pow x -0.5) (pow (+ x 1.0) -0.5))) (/ (pow x -0.5) (+ x 1.0))))
double code(double x) {
return (pow(x, -0.5) / (pow(x, -0.5) + pow((x + 1.0), -0.5))) * (pow(x, -0.5) / (x + 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((x ** (-0.5d0)) / ((x ** (-0.5d0)) + ((x + 1.0d0) ** (-0.5d0)))) * ((x ** (-0.5d0)) / (x + 1.0d0))
end function
public static double code(double x) {
return (Math.pow(x, -0.5) / (Math.pow(x, -0.5) + Math.pow((x + 1.0), -0.5))) * (Math.pow(x, -0.5) / (x + 1.0));
}
def code(x): return (math.pow(x, -0.5) / (math.pow(x, -0.5) + math.pow((x + 1.0), -0.5))) * (math.pow(x, -0.5) / (x + 1.0))
function code(x) return Float64(Float64((x ^ -0.5) / Float64((x ^ -0.5) + (Float64(x + 1.0) ^ -0.5))) * Float64((x ^ -0.5) / Float64(x + 1.0))) end
function tmp = code(x) tmp = ((x ^ -0.5) / ((x ^ -0.5) + ((x + 1.0) ^ -0.5))) * ((x ^ -0.5) / (x + 1.0)); end
code[x_] := N[(N[(N[Power[x, -0.5], $MachinePrecision] / N[(N[Power[x, -0.5], $MachinePrecision] + N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[Power[x, -0.5], $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{x}^{-0.5}}{{x}^{-0.5} + {\left(x + 1\right)}^{-0.5}} \cdot \frac{{x}^{-0.5}}{x + 1}
\end{array}
Initial program 68.9%
flip--68.9%
div-inv68.8%
frac-times59.5%
metadata-eval59.5%
add-sqr-sqrt59.6%
frac-times60.9%
metadata-eval60.9%
add-sqr-sqrt68.7%
+-commutative68.7%
pow1/268.7%
pow-flip68.7%
metadata-eval68.7%
inv-pow68.7%
sqrt-pow268.7%
+-commutative68.7%
metadata-eval68.7%
Applied egg-rr68.7%
associate-*r/68.7%
*-rgt-identity68.7%
Simplified68.7%
frac-sub69.4%
*-un-lft-identity69.4%
Applied egg-rr69.4%
*-rgt-identity69.4%
associate--l+90.2%
+-inverses90.2%
metadata-eval90.2%
associate-/r*90.9%
Simplified90.9%
associate-/l/99.3%
inv-pow99.3%
metadata-eval99.3%
pow-prod-up99.7%
times-frac99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x) :precision binary64 (if (<= (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))) 1e-15) (/ (/ (/ 1.0 x) (+ x 1.0)) (* 2.0 (sqrt (/ 1.0 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)))) <= 1e-15) {
tmp = ((1.0 / x) / (x + 1.0)) / (2.0 * sqrt((1.0 / 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)))) <= 1d-15) then
tmp = ((1.0d0 / x) / (x + 1.0d0)) / (2.0d0 * sqrt((1.0d0 / 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)))) <= 1e-15) {
tmp = ((1.0 / x) / (x + 1.0)) / (2.0 * Math.sqrt((1.0 / 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)))) <= 1e-15: tmp = ((1.0 / x) / (x + 1.0)) / (2.0 * math.sqrt((1.0 / 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)))) <= 1e-15) tmp = Float64(Float64(Float64(1.0 / x) / Float64(x + 1.0)) / Float64(2.0 * sqrt(Float64(1.0 / 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)))) <= 1e-15) tmp = ((1.0 / x) / (x + 1.0)) / (2.0 * sqrt((1.0 / 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], 1e-15], N[(N[(N[(1.0 / x), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] / N[(2.0 * N[Sqrt[N[(1.0 / 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 10^{-15}:\\
\;\;\;\;\frac{\frac{\frac{1}{x}}{x + 1}}{2 \cdot \sqrt{\frac{1}{x}}}\\
\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)))) < 1.0000000000000001e-15Initial program 37.3%
flip--37.3%
div-inv37.3%
frac-times18.6%
metadata-eval18.6%
add-sqr-sqrt18.8%
frac-times21.4%
metadata-eval21.4%
add-sqr-sqrt37.4%
+-commutative37.4%
pow1/237.4%
pow-flip37.4%
metadata-eval37.4%
inv-pow37.4%
sqrt-pow237.4%
+-commutative37.4%
metadata-eval37.4%
Applied egg-rr37.4%
associate-*r/37.4%
*-rgt-identity37.4%
Simplified37.4%
frac-sub38.7%
*-un-lft-identity38.7%
Applied egg-rr38.7%
*-rgt-identity38.7%
associate--l+81.0%
+-inverses81.0%
metadata-eval81.0%
associate-/r*82.4%
Simplified82.4%
Taylor expanded in x around inf 82.0%
if 1.0000000000000001e-15 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial 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%
inv-pow99.5%
sqrt-pow299.9%
metadata-eval99.9%
pow1/299.9%
pow-flip99.9%
+-commutative99.9%
metadata-eval99.9%
Applied egg-rr99.9%
fma-udef99.9%
distribute-lft1-in99.9%
metadata-eval99.9%
mul0-lft99.9%
+-rgt-identity99.9%
Simplified99.9%
Final simplification91.1%
(FPCore (x) :precision binary64 (/ (/ 1.0 x) (fma (pow x -0.5) (+ x 1.0) (pow (+ x 1.0) 0.5))))
double code(double x) {
return (1.0 / x) / fma(pow(x, -0.5), (x + 1.0), pow((x + 1.0), 0.5));
}
function code(x) return Float64(Float64(1.0 / x) / fma((x ^ -0.5), Float64(x + 1.0), (Float64(x + 1.0) ^ 0.5))) end
code[x_] := N[(N[(1.0 / x), $MachinePrecision] / N[(N[Power[x, -0.5], $MachinePrecision] * N[(x + 1.0), $MachinePrecision] + N[Power[N[(x + 1.0), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{x}}{\mathsf{fma}\left({x}^{-0.5}, x + 1, {\left(x + 1\right)}^{0.5}\right)}
\end{array}
Initial program 68.9%
flip--68.9%
div-inv68.8%
frac-times59.5%
metadata-eval59.5%
add-sqr-sqrt59.6%
frac-times60.9%
metadata-eval60.9%
add-sqr-sqrt68.7%
+-commutative68.7%
pow1/268.7%
pow-flip68.7%
metadata-eval68.7%
inv-pow68.7%
sqrt-pow268.7%
+-commutative68.7%
metadata-eval68.7%
Applied egg-rr68.7%
associate-*r/68.7%
*-rgt-identity68.7%
Simplified68.7%
frac-sub69.4%
*-un-lft-identity69.4%
Applied egg-rr69.4%
*-rgt-identity69.4%
associate--l+90.2%
+-inverses90.2%
metadata-eval90.2%
associate-/r*90.9%
Simplified90.9%
expm1-log1p-u87.7%
expm1-udef65.0%
div-inv65.0%
clear-num65.0%
frac-times65.0%
metadata-eval65.0%
div-inv65.0%
clear-num65.0%
/-rgt-identity65.0%
*-commutative65.0%
Applied egg-rr65.0%
expm1-def86.9%
expm1-log1p90.2%
associate-*l*99.1%
associate-/r*99.3%
distribute-rgt-in99.3%
fma-def99.3%
pow-plus99.4%
metadata-eval99.4%
Simplified99.4%
Final simplification99.4%
(FPCore (x) :precision binary64 (* (/ 1.0 x) (/ 1.0 (* (+ x 1.0) (+ (pow x -0.5) (pow (+ x 1.0) -0.5))))))
double code(double x) {
return (1.0 / x) * (1.0 / ((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) * (1.0d0 / ((x + 1.0d0) * ((x ** (-0.5d0)) + ((x + 1.0d0) ** (-0.5d0)))))
end function
public static double code(double x) {
return (1.0 / x) * (1.0 / ((x + 1.0) * (Math.pow(x, -0.5) + Math.pow((x + 1.0), -0.5))));
}
def code(x): return (1.0 / x) * (1.0 / ((x + 1.0) * (math.pow(x, -0.5) + math.pow((x + 1.0), -0.5))))
function code(x) return Float64(Float64(1.0 / x) * Float64(1.0 / Float64(Float64(x + 1.0) * Float64((x ^ -0.5) + (Float64(x + 1.0) ^ -0.5))))) end
function tmp = code(x) tmp = (1.0 / x) * (1.0 / ((x + 1.0) * ((x ^ -0.5) + ((x + 1.0) ^ -0.5)))); end
code[x_] := N[(N[(1.0 / x), $MachinePrecision] * N[(1.0 / 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 \frac{1}{\left(x + 1\right) \cdot \left({x}^{-0.5} + {\left(x + 1\right)}^{-0.5}\right)}
\end{array}
Initial program 68.9%
flip--68.9%
div-inv68.8%
frac-times59.5%
metadata-eval59.5%
add-sqr-sqrt59.6%
frac-times60.9%
metadata-eval60.9%
add-sqr-sqrt68.7%
+-commutative68.7%
pow1/268.7%
pow-flip68.7%
metadata-eval68.7%
inv-pow68.7%
sqrt-pow268.7%
+-commutative68.7%
metadata-eval68.7%
Applied egg-rr68.7%
associate-*r/68.7%
*-rgt-identity68.7%
Simplified68.7%
frac-sub69.4%
*-un-lft-identity69.4%
Applied egg-rr69.4%
*-rgt-identity69.4%
associate--l+90.2%
+-inverses90.2%
metadata-eval90.2%
associate-/r*90.9%
Simplified90.9%
associate-/l/99.3%
div-inv99.3%
*-commutative99.3%
Applied egg-rr99.3%
Final simplification99.3%
(FPCore (x) :precision binary64 (/ (/ 1.0 (+ x (* x x))) (+ (pow x -0.5) (pow (+ x 1.0) -0.5))))
double code(double x) {
return (1.0 / (x + (x * x))) / (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 * x))) / ((x ** (-0.5d0)) + ((x + 1.0d0) ** (-0.5d0)))
end function
public static double code(double x) {
return (1.0 / (x + (x * x))) / (Math.pow(x, -0.5) + Math.pow((x + 1.0), -0.5));
}
def code(x): return (1.0 / (x + (x * x))) / (math.pow(x, -0.5) + math.pow((x + 1.0), -0.5))
function code(x) return Float64(Float64(1.0 / Float64(x + Float64(x * x))) / Float64((x ^ -0.5) + (Float64(x + 1.0) ^ -0.5))) end
function tmp = code(x) tmp = (1.0 / (x + (x * x))) / ((x ^ -0.5) + ((x + 1.0) ^ -0.5)); end
code[x_] := N[(N[(1.0 / N[(x + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[Power[x, -0.5], $MachinePrecision] + N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{x + x \cdot x}}{{x}^{-0.5} + {\left(x + 1\right)}^{-0.5}}
\end{array}
Initial program 68.9%
flip--68.9%
div-inv68.8%
frac-times59.5%
metadata-eval59.5%
add-sqr-sqrt59.6%
frac-times60.9%
metadata-eval60.9%
add-sqr-sqrt68.7%
+-commutative68.7%
pow1/268.7%
pow-flip68.7%
metadata-eval68.7%
inv-pow68.7%
sqrt-pow268.7%
+-commutative68.7%
metadata-eval68.7%
Applied egg-rr68.7%
associate-*r/68.7%
*-rgt-identity68.7%
Simplified68.7%
frac-sub69.4%
*-un-lft-identity69.4%
Applied egg-rr69.4%
*-rgt-identity69.4%
associate--l+90.2%
+-inverses90.2%
metadata-eval90.2%
associate-/r*90.9%
Simplified90.9%
expm1-log1p-u87.0%
expm1-udef64.2%
associate-/l/64.2%
*-commutative64.2%
Applied egg-rr64.2%
expm1-def86.2%
expm1-log1p90.2%
*-commutative90.2%
+-commutative90.2%
distribute-rgt1-in90.2%
Simplified90.2%
Final simplification90.2%
(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(Float64(Float64(1.0 / x) / 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[(N[(N[(1.0 / x), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] / N[(N[Power[x, -0.5], $MachinePrecision] + N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\frac{1}{x}}{x + 1}}{{x}^{-0.5} + {\left(x + 1\right)}^{-0.5}}
\end{array}
Initial program 68.9%
flip--68.9%
div-inv68.8%
frac-times59.5%
metadata-eval59.5%
add-sqr-sqrt59.6%
frac-times60.9%
metadata-eval60.9%
add-sqr-sqrt68.7%
+-commutative68.7%
pow1/268.7%
pow-flip68.7%
metadata-eval68.7%
inv-pow68.7%
sqrt-pow268.7%
+-commutative68.7%
metadata-eval68.7%
Applied egg-rr68.7%
associate-*r/68.7%
*-rgt-identity68.7%
Simplified68.7%
frac-sub69.4%
*-un-lft-identity69.4%
Applied egg-rr69.4%
*-rgt-identity69.4%
associate--l+90.2%
+-inverses90.2%
metadata-eval90.2%
associate-/r*90.9%
Simplified90.9%
Final simplification90.9%
(FPCore (x) :precision binary64 (if (<= x 0.68) (- (pow x -0.5) (+ 1.0 (* x -0.5))) (/ (/ (/ 1.0 x) (+ x 1.0)) (* 2.0 (sqrt (/ 1.0 x))))))
double code(double x) {
double tmp;
if (x <= 0.68) {
tmp = pow(x, -0.5) - (1.0 + (x * -0.5));
} else {
tmp = ((1.0 / x) / (x + 1.0)) / (2.0 * sqrt((1.0 / 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 + (x * (-0.5d0)))
else
tmp = ((1.0d0 / x) / (x + 1.0d0)) / (2.0d0 * sqrt((1.0d0 / 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 + (x * -0.5));
} else {
tmp = ((1.0 / x) / (x + 1.0)) / (2.0 * Math.sqrt((1.0 / x)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.68: tmp = math.pow(x, -0.5) - (1.0 + (x * -0.5)) else: tmp = ((1.0 / x) / (x + 1.0)) / (2.0 * math.sqrt((1.0 / x))) return tmp
function code(x) tmp = 0.0 if (x <= 0.68) tmp = Float64((x ^ -0.5) - Float64(1.0 + Float64(x * -0.5))); else tmp = Float64(Float64(Float64(1.0 / x) / Float64(x + 1.0)) / Float64(2.0 * sqrt(Float64(1.0 / x)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.68) tmp = (x ^ -0.5) - (1.0 + (x * -0.5)); else tmp = ((1.0 / x) / (x + 1.0)) / (2.0 * sqrt((1.0 / x))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.68], N[(N[Power[x, -0.5], $MachinePrecision] - N[(1.0 + N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(1.0 / x), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] / N[(2.0 * N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.68:\\
\;\;\;\;{x}^{-0.5} - \left(1 + x \cdot -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\frac{1}{x}}{x + 1}}{2 \cdot \sqrt{\frac{1}{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%
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.5%
if 0.680000000000000049 < x Initial program 38.3%
flip--38.2%
div-inv38.2%
frac-times19.7%
metadata-eval19.7%
add-sqr-sqrt20.0%
frac-times22.6%
metadata-eval22.6%
add-sqr-sqrt38.3%
+-commutative38.3%
pow1/238.3%
pow-flip38.3%
metadata-eval38.3%
inv-pow38.3%
sqrt-pow238.3%
+-commutative38.3%
metadata-eval38.3%
Applied egg-rr38.3%
associate-*r/38.3%
*-rgt-identity38.3%
Simplified38.3%
frac-sub39.7%
*-un-lft-identity39.7%
Applied egg-rr39.7%
*-rgt-identity39.7%
associate--l+81.3%
+-inverses81.3%
metadata-eval81.3%
associate-/r*82.7%
Simplified82.7%
Taylor expanded in x around inf 81.2%
Final simplification90.3%
(FPCore (x) :precision binary64 (if (<= x 0.68) (- (pow x -0.5) (+ 1.0 (* x -0.5))) (/ (/ (/ 1.0 x) (+ x 1.0)) (* (pow x -0.5) 2.0))))
double code(double x) {
double tmp;
if (x <= 0.68) {
tmp = pow(x, -0.5) - (1.0 + (x * -0.5));
} else {
tmp = ((1.0 / x) / (x + 1.0)) / (pow(x, -0.5) * 2.0);
}
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 + (x * (-0.5d0)))
else
tmp = ((1.0d0 / x) / (x + 1.0d0)) / ((x ** (-0.5d0)) * 2.0d0)
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 + (x * -0.5));
} else {
tmp = ((1.0 / x) / (x + 1.0)) / (Math.pow(x, -0.5) * 2.0);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.68: tmp = math.pow(x, -0.5) - (1.0 + (x * -0.5)) else: tmp = ((1.0 / x) / (x + 1.0)) / (math.pow(x, -0.5) * 2.0) return tmp
function code(x) tmp = 0.0 if (x <= 0.68) tmp = Float64((x ^ -0.5) - Float64(1.0 + Float64(x * -0.5))); else tmp = Float64(Float64(Float64(1.0 / x) / Float64(x + 1.0)) / Float64((x ^ -0.5) * 2.0)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.68) tmp = (x ^ -0.5) - (1.0 + (x * -0.5)); else tmp = ((1.0 / x) / (x + 1.0)) / ((x ^ -0.5) * 2.0); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.68], N[(N[Power[x, -0.5], $MachinePrecision] - N[(1.0 + N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(1.0 / x), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] / N[(N[Power[x, -0.5], $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.68:\\
\;\;\;\;{x}^{-0.5} - \left(1 + x \cdot -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\frac{1}{x}}{x + 1}}{{x}^{-0.5} \cdot 2}\\
\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%
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.5%
if 0.680000000000000049 < x Initial program 38.3%
flip--38.2%
div-inv38.2%
frac-times19.7%
metadata-eval19.7%
add-sqr-sqrt20.0%
frac-times22.6%
metadata-eval22.6%
add-sqr-sqrt38.3%
+-commutative38.3%
pow1/238.3%
pow-flip38.3%
metadata-eval38.3%
inv-pow38.3%
sqrt-pow238.3%
+-commutative38.3%
metadata-eval38.3%
Applied egg-rr38.3%
associate-*r/38.3%
*-rgt-identity38.3%
Simplified38.3%
frac-sub39.7%
*-un-lft-identity39.7%
Applied egg-rr39.7%
*-rgt-identity39.7%
associate--l+81.3%
+-inverses81.3%
metadata-eval81.3%
associate-/r*82.7%
Simplified82.7%
Taylor expanded in x around inf 81.2%
unpow1/281.2%
rem-exp-log78.6%
exp-neg78.6%
exp-prod78.6%
distribute-lft-neg-out78.6%
distribute-rgt-neg-in78.6%
metadata-eval78.6%
exp-to-pow81.1%
Simplified81.1%
Final simplification90.3%
(FPCore (x) :precision binary64 (/ (- x (sqrt x)) (- (* x x) x)))
double code(double x) {
return (x - sqrt(x)) / ((x * x) - x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x - sqrt(x)) / ((x * x) - x)
end function
public static double code(double x) {
return (x - Math.sqrt(x)) / ((x * x) - x);
}
def code(x): return (x - math.sqrt(x)) / ((x * x) - x)
function code(x) return Float64(Float64(x - sqrt(x)) / Float64(Float64(x * x) - x)) end
function tmp = code(x) tmp = (x - sqrt(x)) / ((x * x) - x); end
code[x_] := N[(N[(x - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - \sqrt{x}}{x \cdot x - x}
\end{array}
Initial program 68.9%
flip--68.9%
div-inv68.8%
frac-times59.5%
metadata-eval59.5%
add-sqr-sqrt59.6%
frac-times60.9%
metadata-eval60.9%
add-sqr-sqrt68.7%
+-commutative68.7%
pow1/268.7%
pow-flip68.7%
metadata-eval68.7%
inv-pow68.7%
sqrt-pow268.7%
+-commutative68.7%
metadata-eval68.7%
Applied egg-rr68.7%
associate-*r/68.7%
*-rgt-identity68.7%
Simplified68.7%
Taylor expanded in x around 0 53.0%
*-commutative53.0%
+-commutative53.0%
distribute-rgt-in53.0%
*-lft-identity53.0%
Simplified53.0%
flip-+68.1%
associate-/r/68.0%
pow-plus68.1%
pow-plus68.0%
pow-sqr68.2%
metadata-eval68.2%
metadata-eval68.2%
pow168.2%
fma-neg68.2%
pow-plus68.1%
metadata-eval68.1%
pow1/268.1%
Applied egg-rr68.1%
associate-*l/68.3%
*-lft-identity68.3%
fma-neg68.3%
Simplified68.3%
Final simplification68.3%
(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 98.5%
if 4 < x Initial program 37.8%
add-sqr-sqrt20.2%
pow220.2%
inv-pow20.2%
sqrt-pow217.8%
+-commutative17.8%
metadata-eval17.8%
Applied egg-rr17.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-down35.2%
metadata-eval35.2%
Applied egg-rr35.2%
Final simplification67.1%
(FPCore (x) :precision binary64 (if (<= x 1.32e+154) (/ 1.0 (+ x (sqrt x))) (- (pow (* x x) -0.25))))
double code(double x) {
double tmp;
if (x <= 1.32e+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.32d+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.32e+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.32e+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.32e+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.32e+154) tmp = 1.0 / (x + sqrt(x)); else tmp = -((x * x) ^ -0.25); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.32e+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.32 \cdot 10^{+154}:\\
\;\;\;\;\frac{1}{x + \sqrt{x}}\\
\mathbf{else}:\\
\;\;\;\;-{\left(x \cdot x\right)}^{-0.25}\\
\end{array}
\end{array}
if x < 1.31999999999999998e154Initial program 70.4%
flip--70.3%
div-inv70.2%
frac-times70.1%
metadata-eval70.1%
add-sqr-sqrt70.3%
frac-times70.4%
metadata-eval70.4%
add-sqr-sqrt70.2%
+-commutative70.2%
pow1/270.2%
pow-flip70.1%
metadata-eval70.1%
inv-pow70.1%
sqrt-pow270.1%
+-commutative70.1%
metadata-eval70.1%
Applied egg-rr70.1%
associate-*r/70.1%
*-rgt-identity70.1%
Simplified70.1%
frac-sub71.0%
*-un-lft-identity71.0%
Applied egg-rr71.0%
*-rgt-identity71.0%
associate--l+99.2%
+-inverses99.2%
metadata-eval99.2%
associate-/r*99.2%
Simplified99.2%
Taylor expanded in x around 0 69.3%
distribute-lft1-in69.2%
pow-plus69.5%
metadata-eval69.5%
unpow1/269.5%
+-commutative69.5%
Simplified69.5%
if 1.31999999999999998e154 < x Initial program 64.7%
add-sqr-sqrt31.1%
pow231.1%
inv-pow31.1%
sqrt-pow226.7%
+-commutative26.7%
metadata-eval26.7%
Applied egg-rr26.7%
Taylor expanded in x around inf 4.1%
mul-1-neg4.1%
Simplified4.1%
inv-pow4.1%
sqrt-pow14.1%
metadata-eval4.1%
sqr-pow4.1%
pow-prod-down64.7%
metadata-eval64.7%
Applied egg-rr64.7%
Final simplification68.3%
(FPCore (x) :precision binary64 (if (<= x 0.8) (+ (pow x -0.5) -1.0) (/ 1.0 x)))
double code(double x) {
double tmp;
if (x <= 0.8) {
tmp = pow(x, -0.5) + -1.0;
} else {
tmp = 1.0 / x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.8d0) then
tmp = (x ** (-0.5d0)) + (-1.0d0)
else
tmp = 1.0d0 / x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.8) {
tmp = Math.pow(x, -0.5) + -1.0;
} else {
tmp = 1.0 / x;
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.8: tmp = math.pow(x, -0.5) + -1.0 else: tmp = 1.0 / x return tmp
function code(x) tmp = 0.0 if (x <= 0.8) tmp = Float64((x ^ -0.5) + -1.0); else tmp = Float64(1.0 / x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.8) tmp = (x ^ -0.5) + -1.0; else tmp = 1.0 / x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.8], N[(N[Power[x, -0.5], $MachinePrecision] + -1.0), $MachinePrecision], N[(1.0 / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.8:\\
\;\;\;\;{x}^{-0.5} + -1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x}\\
\end{array}
\end{array}
if x < 0.80000000000000004Initial 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.2%
if 0.80000000000000004 < x Initial program 38.3%
flip--38.2%
div-inv38.2%
frac-times19.7%
metadata-eval19.7%
add-sqr-sqrt20.0%
frac-times22.6%
metadata-eval22.6%
add-sqr-sqrt38.3%
+-commutative38.3%
pow1/238.3%
pow-flip38.3%
metadata-eval38.3%
inv-pow38.3%
sqrt-pow238.3%
+-commutative38.3%
metadata-eval38.3%
Applied egg-rr38.3%
associate-*r/38.3%
*-rgt-identity38.3%
Simplified38.3%
Taylor expanded in x around 0 7.9%
*-commutative7.9%
+-commutative7.9%
distribute-rgt-in7.9%
*-lft-identity7.9%
Simplified7.9%
Taylor expanded in x around inf 7.9%
Final simplification53.6%
(FPCore (x) :precision binary64 (/ 1.0 x))
double code(double x) {
return 1.0 / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / x
end function
public static double code(double x) {
return 1.0 / x;
}
def code(x): return 1.0 / x
function code(x) return Float64(1.0 / x) end
function tmp = code(x) tmp = 1.0 / x; end
code[x_] := N[(1.0 / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x}
\end{array}
Initial program 68.9%
flip--68.9%
div-inv68.8%
frac-times59.5%
metadata-eval59.5%
add-sqr-sqrt59.6%
frac-times60.9%
metadata-eval60.9%
add-sqr-sqrt68.7%
+-commutative68.7%
pow1/268.7%
pow-flip68.7%
metadata-eval68.7%
inv-pow68.7%
sqrt-pow268.7%
+-commutative68.7%
metadata-eval68.7%
Applied egg-rr68.7%
associate-*r/68.7%
*-rgt-identity68.7%
Simplified68.7%
Taylor expanded in x around 0 53.0%
*-commutative53.0%
+-commutative53.0%
distribute-rgt-in53.0%
*-lft-identity53.0%
Simplified53.0%
Taylor expanded in x around inf 7.4%
Final simplification7.4%
(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 68.9%
inv-pow68.9%
add-cube-cbrt54.4%
unpow-prod-down53.3%
fma-neg52.0%
cbrt-prod52.5%
add-sqr-sqrt52.5%
inv-pow52.5%
inv-pow52.5%
metadata-eval52.5%
cbrt-div52.4%
pow1/252.4%
pow-flip52.5%
metadata-eval52.5%
distribute-neg-frac52.5%
metadata-eval52.5%
+-commutative52.5%
Applied egg-rr52.5%
Taylor expanded in x around 0 1.9%
Final simplification1.9%
(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 2023173
(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)))))