
(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 (/ (/ (/ 1.0 (+ 1.0 x)) x) (+ (pow x -0.5) (pow (+ 1.0 x) -0.5))))
double code(double x) {
return ((1.0 / (1.0 + x)) / x) / (pow(x, -0.5) + pow((1.0 + x), -0.5));
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((1.0d0 / (1.0d0 + x)) / x) / ((x ** (-0.5d0)) + ((1.0d0 + x) ** (-0.5d0)))
end function
public static double code(double x) {
return ((1.0 / (1.0 + x)) / x) / (Math.pow(x, -0.5) + Math.pow((1.0 + x), -0.5));
}
def code(x): return ((1.0 / (1.0 + x)) / x) / (math.pow(x, -0.5) + math.pow((1.0 + x), -0.5))
function code(x) return Float64(Float64(Float64(1.0 / Float64(1.0 + x)) / x) / Float64((x ^ -0.5) + (Float64(1.0 + x) ^ -0.5))) end
function tmp = code(x) tmp = ((1.0 / (1.0 + x)) / x) / ((x ^ -0.5) + ((1.0 + x) ^ -0.5)); end
code[x_] := N[(N[(N[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] / N[(N[Power[x, -0.5], $MachinePrecision] + N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\frac{1}{1 + x}}{x}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}
\end{array}
Initial program 72.5%
*-un-lft-identity72.5%
clear-num72.5%
associate-/r/72.5%
prod-diff72.5%
*-un-lft-identity72.5%
fma-neg72.5%
*-un-lft-identity72.5%
inv-pow72.5%
sqrt-pow268.1%
metadata-eval68.1%
pow1/268.1%
pow-flip72.7%
+-commutative72.7%
metadata-eval72.7%
Applied egg-rr72.7%
fma-udef72.7%
distribute-lft1-in72.7%
metadata-eval72.7%
mul0-lft72.7%
+-rgt-identity72.7%
Simplified72.7%
metadata-eval72.7%
pow-flip68.1%
+-commutative68.1%
pow1/268.1%
flip--68.0%
pow-prod-up61.2%
metadata-eval61.2%
inv-pow61.2%
frac-times66.2%
metadata-eval66.2%
add-sqr-sqrt72.4%
pow1/272.4%
+-commutative72.4%
pow-flip72.4%
metadata-eval72.4%
+-commutative72.4%
Applied egg-rr72.4%
frac-sub73.6%
*-un-lft-identity73.6%
+-commutative73.6%
+-commutative73.6%
Applied egg-rr73.6%
*-rgt-identity73.6%
associate--l+91.7%
Simplified91.7%
associate-/r*92.6%
+-inverses92.6%
metadata-eval92.6%
+-commutative92.6%
div-inv92.6%
+-commutative92.6%
Applied egg-rr92.6%
associate-*l/92.6%
*-lft-identity92.6%
Simplified92.6%
Final simplification92.6%
(FPCore (x) :precision binary64 (if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 (sqrt (+ 1.0 x)))) 1e-15) (/ (/ 1.0 (+ x (* x x))) (* 2.0 (sqrt (/ 1.0 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)))) <= 1e-15) {
tmp = (1.0 / (x + (x * x))) / (2.0 * sqrt((1.0 / 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)))) <= 1d-15) then
tmp = (1.0d0 / (x + (x * x))) / (2.0d0 * sqrt((1.0d0 / 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)))) <= 1e-15) {
tmp = (1.0 / (x + (x * x))) / (2.0 * Math.sqrt((1.0 / 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)))) <= 1e-15: tmp = (1.0 / (x + (x * x))) / (2.0 * math.sqrt((1.0 / 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)))) <= 1e-15) tmp = Float64(Float64(1.0 / Float64(x + Float64(x * x))) / Float64(2.0 * sqrt(Float64(1.0 / 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)))) <= 1e-15) tmp = (1.0 / (x + (x * x))) / (2.0 * sqrt((1.0 / 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], 1e-15], N[(N[(1.0 / N[(x + N[(x * x), $MachinePrecision]), $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[(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 10^{-15}:\\
\;\;\;\;\frac{\frac{1}{x + x \cdot x}}{2 \cdot \sqrt{\frac{1}{x}}}\\
\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)))) < 1.0000000000000001e-15Initial program 41.7%
*-un-lft-identity41.7%
clear-num41.7%
associate-/r/41.7%
prod-diff41.7%
*-un-lft-identity41.7%
fma-neg41.7%
*-un-lft-identity41.7%
inv-pow41.7%
sqrt-pow232.0%
metadata-eval32.0%
pow1/232.0%
pow-flip41.7%
+-commutative41.7%
metadata-eval41.7%
Applied egg-rr41.7%
fma-udef41.7%
distribute-lft1-in41.7%
metadata-eval41.7%
mul0-lft41.7%
+-rgt-identity41.7%
Simplified41.7%
metadata-eval41.7%
pow-flip32.0%
+-commutative32.0%
pow1/232.0%
flip--31.9%
pow-prod-up18.0%
metadata-eval18.0%
inv-pow18.0%
frac-times28.8%
metadata-eval28.8%
add-sqr-sqrt42.0%
pow1/242.0%
+-commutative42.0%
pow-flip42.0%
metadata-eval42.0%
+-commutative42.0%
Applied egg-rr42.0%
frac-sub44.1%
*-un-lft-identity44.1%
+-commutative44.1%
+-commutative44.1%
Applied egg-rr44.1%
*-rgt-identity44.1%
associate--l+83.1%
+-inverses83.1%
metadata-eval83.1%
distribute-lft-in83.1%
*-rgt-identity83.1%
Simplified83.1%
Taylor expanded in x around inf 82.8%
if 1.0000000000000001e-15 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.2%
*-un-lft-identity99.2%
clear-num99.2%
associate-/r/99.2%
prod-diff99.2%
*-un-lft-identity99.2%
fma-neg99.2%
*-un-lft-identity99.2%
inv-pow99.2%
sqrt-pow299.5%
metadata-eval99.5%
pow1/299.5%
pow-flip99.5%
+-commutative99.5%
metadata-eval99.5%
Applied egg-rr99.5%
fma-udef99.5%
distribute-lft1-in99.5%
metadata-eval99.5%
mul0-lft99.5%
+-rgt-identity99.5%
Simplified99.5%
Final simplification91.8%
(FPCore (x) :precision binary64 (/ (/ 1.0 (+ x (* x x))) (+ (pow x -0.5) (pow (+ 1.0 x) -0.5))))
double code(double x) {
return (1.0 / (x + (x * x))) / (pow(x, -0.5) + pow((1.0 + x), -0.5));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / (x + (x * x))) / ((x ** (-0.5d0)) + ((1.0d0 + x) ** (-0.5d0)))
end function
public static double code(double x) {
return (1.0 / (x + (x * x))) / (Math.pow(x, -0.5) + Math.pow((1.0 + x), -0.5));
}
def code(x): return (1.0 / (x + (x * x))) / (math.pow(x, -0.5) + math.pow((1.0 + x), -0.5))
function code(x) return Float64(Float64(1.0 / Float64(x + Float64(x * x))) / Float64((x ^ -0.5) + (Float64(1.0 + x) ^ -0.5))) end
function tmp = code(x) tmp = (1.0 / (x + (x * x))) / ((x ^ -0.5) + ((1.0 + x) ^ -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[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{x + x \cdot x}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}
\end{array}
Initial program 72.5%
*-un-lft-identity72.5%
clear-num72.5%
associate-/r/72.5%
prod-diff72.5%
*-un-lft-identity72.5%
fma-neg72.5%
*-un-lft-identity72.5%
inv-pow72.5%
sqrt-pow268.1%
metadata-eval68.1%
pow1/268.1%
pow-flip72.7%
+-commutative72.7%
metadata-eval72.7%
Applied egg-rr72.7%
fma-udef72.7%
distribute-lft1-in72.7%
metadata-eval72.7%
mul0-lft72.7%
+-rgt-identity72.7%
Simplified72.7%
metadata-eval72.7%
pow-flip68.1%
+-commutative68.1%
pow1/268.1%
flip--68.0%
pow-prod-up61.2%
metadata-eval61.2%
inv-pow61.2%
frac-times66.2%
metadata-eval66.2%
add-sqr-sqrt72.4%
pow1/272.4%
+-commutative72.4%
pow-flip72.4%
metadata-eval72.4%
+-commutative72.4%
Applied egg-rr72.4%
frac-sub73.6%
*-un-lft-identity73.6%
+-commutative73.6%
+-commutative73.6%
Applied egg-rr73.6%
*-rgt-identity73.6%
associate--l+91.7%
+-inverses91.7%
metadata-eval91.7%
distribute-lft-in91.7%
*-rgt-identity91.7%
Simplified91.7%
Final simplification91.7%
(FPCore (x) :precision binary64 (if (<= x 1.2) (- (pow x -0.5) (/ 1.0 (+ 1.0 (* x 0.5)))) (/ (/ 1.0 (+ x (* x x))) (* 2.0 (sqrt (/ 1.0 x))))))
double code(double x) {
double tmp;
if (x <= 1.2) {
tmp = pow(x, -0.5) - (1.0 / (1.0 + (x * 0.5)));
} else {
tmp = (1.0 / (x + (x * x))) / (2.0 * sqrt((1.0 / x)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.2d0) then
tmp = (x ** (-0.5d0)) - (1.0d0 / (1.0d0 + (x * 0.5d0)))
else
tmp = (1.0d0 / (x + (x * x))) / (2.0d0 * sqrt((1.0d0 / x)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.2) {
tmp = Math.pow(x, -0.5) - (1.0 / (1.0 + (x * 0.5)));
} else {
tmp = (1.0 / (x + (x * x))) / (2.0 * Math.sqrt((1.0 / x)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.2: tmp = math.pow(x, -0.5) - (1.0 / (1.0 + (x * 0.5))) else: tmp = (1.0 / (x + (x * x))) / (2.0 * math.sqrt((1.0 / x))) return tmp
function code(x) tmp = 0.0 if (x <= 1.2) tmp = Float64((x ^ -0.5) - Float64(1.0 / Float64(1.0 + Float64(x * 0.5)))); else tmp = Float64(Float64(1.0 / Float64(x + Float64(x * x))) / Float64(2.0 * sqrt(Float64(1.0 / x)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.2) tmp = (x ^ -0.5) - (1.0 / (1.0 + (x * 0.5))); else tmp = (1.0 / (x + (x * x))) / (2.0 * sqrt((1.0 / x))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.2], N[(N[Power[x, -0.5], $MachinePrecision] - N[(1.0 / N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(x + N[(x * x), $MachinePrecision]), $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 1.2:\\
\;\;\;\;{x}^{-0.5} - \frac{1}{1 + x \cdot 0.5}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{x + x \cdot x}}{2 \cdot \sqrt{\frac{1}{x}}}\\
\end{array}
\end{array}
if x < 1.19999999999999996Initial program 99.7%
inv-pow99.7%
pow1/299.7%
pow-pow100.0%
add-exp-log92.6%
pow-exp92.6%
metadata-eval92.6%
Applied egg-rr92.6%
Taylor expanded in x around 0 91.3%
pow-to-exp98.6%
expm1-log1p-u91.3%
expm1-udef91.3%
Applied egg-rr91.3%
expm1-def91.3%
expm1-log1p98.6%
Simplified98.6%
if 1.19999999999999996 < x Initial program 43.1%
*-un-lft-identity43.1%
clear-num43.1%
associate-/r/43.1%
prod-diff43.1%
*-un-lft-identity43.1%
fma-neg43.1%
*-un-lft-identity43.1%
inv-pow43.1%
sqrt-pow233.6%
metadata-eval33.6%
pow1/233.6%
pow-flip43.1%
+-commutative43.1%
metadata-eval43.1%
Applied egg-rr43.1%
fma-udef43.1%
distribute-lft1-in43.1%
metadata-eval43.1%
mul0-lft43.1%
+-rgt-identity43.1%
Simplified43.1%
metadata-eval43.1%
pow-flip33.6%
+-commutative33.6%
pow1/233.6%
flip--33.6%
pow-prod-up20.1%
metadata-eval20.1%
inv-pow20.1%
frac-times30.6%
metadata-eval30.6%
add-sqr-sqrt43.5%
pow1/243.5%
+-commutative43.5%
pow-flip43.5%
metadata-eval43.5%
+-commutative43.5%
Applied egg-rr43.5%
frac-sub45.9%
*-un-lft-identity45.9%
+-commutative45.9%
+-commutative45.9%
Applied egg-rr45.9%
*-rgt-identity45.9%
associate--l+83.7%
+-inverses83.7%
metadata-eval83.7%
distribute-lft-in83.7%
*-rgt-identity83.7%
Simplified83.7%
Taylor expanded in x around inf 81.3%
Final simplification90.3%
(FPCore (x) :precision binary64 (if (<= x 1.68) (- (pow x -0.5) (/ 1.0 (+ 1.0 (* x 0.5)))) (/ (/ 1.0 (* x x)) (* 2.0 (sqrt (/ 1.0 x))))))
double code(double x) {
double tmp;
if (x <= 1.68) {
tmp = pow(x, -0.5) - (1.0 / (1.0 + (x * 0.5)));
} else {
tmp = (1.0 / (x * x)) / (2.0 * sqrt((1.0 / x)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.68d0) then
tmp = (x ** (-0.5d0)) - (1.0d0 / (1.0d0 + (x * 0.5d0)))
else
tmp = (1.0d0 / (x * x)) / (2.0d0 * sqrt((1.0d0 / x)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.68) {
tmp = Math.pow(x, -0.5) - (1.0 / (1.0 + (x * 0.5)));
} else {
tmp = (1.0 / (x * x)) / (2.0 * Math.sqrt((1.0 / x)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.68: tmp = math.pow(x, -0.5) - (1.0 / (1.0 + (x * 0.5))) else: tmp = (1.0 / (x * x)) / (2.0 * math.sqrt((1.0 / x))) return tmp
function code(x) tmp = 0.0 if (x <= 1.68) tmp = Float64((x ^ -0.5) - Float64(1.0 / Float64(1.0 + Float64(x * 0.5)))); else tmp = Float64(Float64(1.0 / Float64(x * x)) / Float64(2.0 * sqrt(Float64(1.0 / x)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.68) tmp = (x ^ -0.5) - (1.0 / (1.0 + (x * 0.5))); else tmp = (1.0 / (x * x)) / (2.0 * sqrt((1.0 / x))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.68], N[(N[Power[x, -0.5], $MachinePrecision] - N[(1.0 / N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(x * x), $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 1.68:\\
\;\;\;\;{x}^{-0.5} - \frac{1}{1 + x \cdot 0.5}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{x \cdot x}}{2 \cdot \sqrt{\frac{1}{x}}}\\
\end{array}
\end{array}
if x < 1.67999999999999994Initial program 99.7%
inv-pow99.7%
pow1/299.7%
pow-pow100.0%
add-exp-log92.6%
pow-exp92.6%
metadata-eval92.6%
Applied egg-rr92.6%
Taylor expanded in x around 0 91.3%
pow-to-exp98.6%
expm1-log1p-u91.3%
expm1-udef91.3%
Applied egg-rr91.3%
expm1-def91.3%
expm1-log1p98.6%
Simplified98.6%
if 1.67999999999999994 < x Initial program 43.1%
*-un-lft-identity43.1%
clear-num43.1%
associate-/r/43.1%
prod-diff43.1%
*-un-lft-identity43.1%
fma-neg43.1%
*-un-lft-identity43.1%
inv-pow43.1%
sqrt-pow233.6%
metadata-eval33.6%
pow1/233.6%
pow-flip43.1%
+-commutative43.1%
metadata-eval43.1%
Applied egg-rr43.1%
fma-udef43.1%
distribute-lft1-in43.1%
metadata-eval43.1%
mul0-lft43.1%
+-rgt-identity43.1%
Simplified43.1%
metadata-eval43.1%
pow-flip33.6%
+-commutative33.6%
pow1/233.6%
flip--33.6%
pow-prod-up20.1%
metadata-eval20.1%
inv-pow20.1%
frac-times30.6%
metadata-eval30.6%
add-sqr-sqrt43.5%
pow1/243.5%
+-commutative43.5%
pow-flip43.5%
metadata-eval43.5%
+-commutative43.5%
Applied egg-rr43.5%
Taylor expanded in x around inf 41.8%
Taylor expanded in x around inf 81.2%
unpow281.2%
Simplified81.2%
Final simplification90.2%
(FPCore (x) :precision binary64 (if (<= x 5.9e+23) (- (pow x -0.5) (/ 1.0 (+ 1.0 (* x 0.5)))) (pow (* x x) -0.25)))
double code(double x) {
double tmp;
if (x <= 5.9e+23) {
tmp = pow(x, -0.5) - (1.0 / (1.0 + (x * 0.5)));
} else {
tmp = pow((x * x), -0.25);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 5.9d+23) then
tmp = (x ** (-0.5d0)) - (1.0d0 / (1.0d0 + (x * 0.5d0)))
else
tmp = (x * x) ** (-0.25d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 5.9e+23) {
tmp = Math.pow(x, -0.5) - (1.0 / (1.0 + (x * 0.5)));
} else {
tmp = Math.pow((x * x), -0.25);
}
return tmp;
}
def code(x): tmp = 0 if x <= 5.9e+23: tmp = math.pow(x, -0.5) - (1.0 / (1.0 + (x * 0.5))) else: tmp = math.pow((x * x), -0.25) return tmp
function code(x) tmp = 0.0 if (x <= 5.9e+23) tmp = Float64((x ^ -0.5) - Float64(1.0 / Float64(1.0 + Float64(x * 0.5)))); else tmp = Float64(x * x) ^ -0.25; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 5.9e+23) tmp = (x ^ -0.5) - (1.0 / (1.0 + (x * 0.5))); else tmp = (x * x) ^ -0.25; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 5.9e+23], N[(N[Power[x, -0.5], $MachinePrecision] - N[(1.0 / N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[N[(x * x), $MachinePrecision], -0.25], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5.9 \cdot 10^{+23}:\\
\;\;\;\;{x}^{-0.5} - \frac{1}{1 + x \cdot 0.5}\\
\mathbf{else}:\\
\;\;\;\;{\left(x \cdot x\right)}^{-0.25}\\
\end{array}
\end{array}
if x < 5.89999999999999987e23Initial program 95.2%
inv-pow95.2%
pow1/295.2%
pow-pow95.5%
add-exp-log88.6%
pow-exp88.6%
metadata-eval88.6%
Applied egg-rr88.6%
Taylor expanded in x around 0 85.2%
pow-to-exp92.0%
expm1-log1p-u85.3%
expm1-udef85.3%
Applied egg-rr85.3%
expm1-def85.3%
expm1-log1p92.0%
Simplified92.0%
if 5.89999999999999987e23 < x Initial program 43.2%
inv-pow43.2%
pow1/243.2%
pow-pow32.9%
add-exp-log4.4%
pow-exp4.4%
metadata-eval4.4%
Applied egg-rr4.4%
Taylor expanded in x around 0 5.1%
Taylor expanded in x around inf 5.1%
inv-pow5.1%
sqrt-pow15.1%
metadata-eval5.1%
sqr-pow5.1%
pow-prod-down44.0%
metadata-eval44.0%
Applied egg-rr44.0%
Final simplification71.0%
(FPCore (x) :precision binary64 (if (<= x 2.0) (+ (+ (pow x -0.5) (* x 0.5)) -1.0) (pow (* x x) -0.25)))
double code(double x) {
double tmp;
if (x <= 2.0) {
tmp = (pow(x, -0.5) + (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 <= 2.0d0) then
tmp = ((x ** (-0.5d0)) + (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 <= 2.0) {
tmp = (Math.pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = Math.pow((x * x), -0.25);
}
return tmp;
}
def code(x): tmp = 0 if x <= 2.0: tmp = (math.pow(x, -0.5) + (x * 0.5)) + -1.0 else: tmp = math.pow((x * x), -0.25) return tmp
function code(x) tmp = 0.0 if (x <= 2.0) tmp = Float64(Float64((x ^ -0.5) + Float64(x * 0.5)) + -1.0); else tmp = Float64(x * x) ^ -0.25; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 2.0) tmp = ((x ^ -0.5) + (x * 0.5)) + -1.0; else tmp = (x * x) ^ -0.25; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 2.0], N[(N[(N[Power[x, -0.5], $MachinePrecision] + N[(x * 0.5), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[Power[N[(x * x), $MachinePrecision], -0.25], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2:\\
\;\;\;\;\left({x}^{-0.5} + x \cdot 0.5\right) + -1\\
\mathbf{else}:\\
\;\;\;\;{\left(x \cdot x\right)}^{-0.25}\\
\end{array}
\end{array}
if x < 2Initial program 99.7%
*-un-lft-identity99.7%
clear-num99.7%
associate-/r/99.7%
prod-diff99.7%
*-un-lft-identity99.7%
fma-neg99.7%
*-un-lft-identity99.7%
inv-pow99.7%
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.0%
if 2 < x Initial program 42.6%
inv-pow42.6%
pow1/242.6%
pow-pow33.1%
add-exp-log6.9%
pow-exp6.8%
metadata-eval6.8%
Applied egg-rr6.8%
Taylor expanded in x around 0 5.6%
Taylor expanded in x around inf 5.6%
inv-pow5.6%
sqrt-pow15.6%
metadata-eval5.6%
sqr-pow5.6%
pow-prod-down41.3%
metadata-eval41.3%
Applied egg-rr41.3%
Final simplification70.9%
(FPCore (x) :precision binary64 (if (<= x 0.8) (+ (pow x -0.5) -1.0) (pow (* x x) -0.25)))
double code(double x) {
double tmp;
if (x <= 0.8) {
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 <= 0.8d0) 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 <= 0.8) {
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 <= 0.8: 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 <= 0.8) tmp = Float64((x ^ -0.5) + -1.0); else tmp = Float64(x * x) ^ -0.25; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.8) tmp = (x ^ -0.5) + -1.0; else tmp = (x * x) ^ -0.25; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.8], 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 0.8:\\
\;\;\;\;{x}^{-0.5} + -1\\
\mathbf{else}:\\
\;\;\;\;{\left(x \cdot x\right)}^{-0.25}\\
\end{array}
\end{array}
if x < 0.80000000000000004Initial program 99.7%
*-un-lft-identity99.7%
clear-num99.7%
associate-/r/99.7%
prod-diff99.7%
*-un-lft-identity99.7%
fma-neg99.7%
*-un-lft-identity99.7%
inv-pow99.7%
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.1%
if 0.80000000000000004 < x Initial program 43.1%
inv-pow43.1%
pow1/243.1%
pow-pow33.6%
add-exp-log7.6%
pow-exp7.6%
metadata-eval7.6%
Applied egg-rr7.6%
Taylor expanded in x around 0 5.7%
Taylor expanded in x around inf 5.7%
inv-pow5.7%
sqrt-pow15.7%
metadata-eval5.7%
sqr-pow5.7%
pow-prod-down41.1%
metadata-eval41.1%
Applied egg-rr41.1%
Final simplification70.7%
(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 72.5%
inv-pow72.5%
pow1/272.5%
pow-pow68.1%
add-exp-log51.8%
pow-exp51.7%
metadata-eval51.7%
Applied egg-rr51.7%
Taylor expanded in x around 0 50.2%
Taylor expanded in x around inf 52.4%
Final simplification52.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 72.5%
Taylor expanded in x around 0 52.1%
Taylor expanded in x around inf 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 2023252
(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)))))