
(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 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
double code(double x) {
return (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / sqrt(x)) - (1.0d0 / sqrt((x + 1.0d0)))
end function
public static double code(double x) {
return (1.0 / Math.sqrt(x)) - (1.0 / Math.sqrt((x + 1.0)));
}
def code(x): return (1.0 / math.sqrt(x)) - (1.0 / math.sqrt((x + 1.0)))
function code(x) return Float64(Float64(1.0 / sqrt(x)) - Float64(1.0 / sqrt(Float64(x + 1.0)))) end
function tmp = code(x) tmp = (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0))); end
code[x_] := N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] - N[(1.0 / N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\end{array}
(FPCore (x) :precision binary64 (if (<= (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ 1.0 x)))) 1e-12) (* (pow x -0.5) (/ (- 0.5 (/ 0.375 x)) x)) (- (pow x -0.5) (pow (+ 1.0 x) -0.5))))
double code(double x) {
double tmp;
if (((1.0 / sqrt(x)) - (1.0 / sqrt((1.0 + x)))) <= 1e-12) {
tmp = pow(x, -0.5) * ((0.5 - (0.375 / x)) / x);
} else {
tmp = pow(x, -0.5) - pow((1.0 + x), -0.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (((1.0d0 / sqrt(x)) - (1.0d0 / sqrt((1.0d0 + x)))) <= 1d-12) then
tmp = (x ** (-0.5d0)) * ((0.5d0 - (0.375d0 / x)) / x)
else
tmp = (x ** (-0.5d0)) - ((1.0d0 + x) ** (-0.5d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (((1.0 / Math.sqrt(x)) - (1.0 / Math.sqrt((1.0 + x)))) <= 1e-12) {
tmp = Math.pow(x, -0.5) * ((0.5 - (0.375 / x)) / x);
} else {
tmp = Math.pow(x, -0.5) - Math.pow((1.0 + x), -0.5);
}
return tmp;
}
def code(x): tmp = 0 if ((1.0 / math.sqrt(x)) - (1.0 / math.sqrt((1.0 + x)))) <= 1e-12: tmp = math.pow(x, -0.5) * ((0.5 - (0.375 / x)) / x) else: tmp = math.pow(x, -0.5) - math.pow((1.0 + x), -0.5) return tmp
function code(x) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) - Float64(1.0 / sqrt(Float64(1.0 + x)))) <= 1e-12) tmp = Float64((x ^ -0.5) * Float64(Float64(0.5 - Float64(0.375 / x)) / x)); else tmp = Float64((x ^ -0.5) - (Float64(1.0 + x) ^ -0.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (((1.0 / sqrt(x)) - (1.0 / sqrt((1.0 + x)))) <= 1e-12) tmp = (x ^ -0.5) * ((0.5 - (0.375 / x)) / x); else tmp = (x ^ -0.5) - ((1.0 + x) ^ -0.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] - N[(1.0 / N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1e-12], N[(N[Power[x, -0.5], $MachinePrecision] * N[(N[(0.5 - N[(0.375 / x), $MachinePrecision]), $MachinePrecision] / x), $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^{-12}:\\
\;\;\;\;{x}^{-0.5} \cdot \frac{0.5 - \frac{0.375}{x}}{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)))) < 9.9999999999999998e-13Initial program 41.5%
frac-sub41.5%
div-inv41.5%
*-un-lft-identity41.5%
+-commutative41.5%
*-rgt-identity41.5%
metadata-eval41.5%
frac-times41.5%
un-div-inv41.5%
pow1/241.5%
pow-flip41.5%
metadata-eval41.5%
+-commutative41.5%
Applied egg-rr41.5%
associate-*r/41.5%
*-rgt-identity41.5%
times-frac41.5%
div-sub41.5%
*-inverses41.5%
/-rgt-identity41.5%
Simplified41.5%
Taylor expanded in x around inf 99.6%
associate-*r/99.6%
metadata-eval99.6%
associate-*r/99.6%
metadata-eval99.6%
unpow299.6%
Simplified99.6%
expm1-log1p-u99.6%
expm1-udef41.2%
*-commutative41.2%
associate-/r*41.2%
sub-div41.2%
Applied egg-rr41.2%
expm1-def99.6%
expm1-log1p99.6%
Simplified99.6%
if 9.9999999999999998e-13 < (-.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.8%
metadata-eval99.8%
pow1/299.8%
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 simplification99.8%
(FPCore (x) :precision binary64 (if (<= x 1.1) (+ (+ (pow x -0.5) (* x 0.5)) -1.0) (* (pow x -0.5) (/ (- 0.5 (/ 0.375 x)) x))))
double code(double x) {
double tmp;
if (x <= 1.1) {
tmp = (pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = pow(x, -0.5) * ((0.5 - (0.375 / x)) / x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.1d0) then
tmp = ((x ** (-0.5d0)) + (x * 0.5d0)) + (-1.0d0)
else
tmp = (x ** (-0.5d0)) * ((0.5d0 - (0.375d0 / x)) / x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.1) {
tmp = (Math.pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = Math.pow(x, -0.5) * ((0.5 - (0.375 / x)) / x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.1: tmp = (math.pow(x, -0.5) + (x * 0.5)) + -1.0 else: tmp = math.pow(x, -0.5) * ((0.5 - (0.375 / x)) / x) return tmp
function code(x) tmp = 0.0 if (x <= 1.1) tmp = Float64(Float64((x ^ -0.5) + Float64(x * 0.5)) + -1.0); else tmp = Float64((x ^ -0.5) * Float64(Float64(0.5 - Float64(0.375 / x)) / x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.1) tmp = ((x ^ -0.5) + (x * 0.5)) + -1.0; else tmp = (x ^ -0.5) * ((0.5 - (0.375 / x)) / x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.1], N[(N[(N[Power[x, -0.5], $MachinePrecision] + N[(x * 0.5), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] * N[(N[(0.5 - N[(0.375 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.1:\\
\;\;\;\;\left({x}^{-0.5} + x \cdot 0.5\right) + -1\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} \cdot \frac{0.5 - \frac{0.375}{x}}{x}\\
\end{array}
\end{array}
if x < 1.1000000000000001Initial program 99.6%
sub-neg99.6%
+-commutative99.6%
add-cube-cbrt99.6%
distribute-lft-neg-in99.6%
fma-def99.6%
Applied egg-rr100.0%
Taylor expanded in x around 0 99.2%
if 1.1000000000000001 < x Initial program 42.7%
frac-sub42.7%
div-inv42.7%
*-un-lft-identity42.7%
+-commutative42.7%
*-rgt-identity42.7%
metadata-eval42.7%
frac-times42.7%
un-div-inv42.7%
pow1/242.7%
pow-flip42.7%
metadata-eval42.7%
+-commutative42.7%
Applied egg-rr42.7%
associate-*r/42.7%
*-rgt-identity42.7%
times-frac42.7%
div-sub42.7%
*-inverses42.7%
/-rgt-identity42.7%
Simplified42.7%
Taylor expanded in x around inf 98.1%
associate-*r/98.1%
metadata-eval98.1%
associate-*r/98.1%
metadata-eval98.1%
unpow298.1%
Simplified98.1%
expm1-log1p-u98.1%
expm1-udef41.0%
*-commutative41.0%
associate-/r*41.0%
sub-div41.0%
Applied egg-rr41.0%
expm1-def98.1%
expm1-log1p98.1%
Simplified98.1%
Final simplification98.6%
(FPCore (x) :precision binary64 (if (<= x 1.0) (+ (+ (pow x -0.5) (* x 0.5)) -1.0) (/ (* (pow x -0.5) 0.5) x)))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = (pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = (pow(x, -0.5) * 0.5) / x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.0d0) then
tmp = ((x ** (-0.5d0)) + (x * 0.5d0)) + (-1.0d0)
else
tmp = ((x ** (-0.5d0)) * 0.5d0) / x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = (Math.pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = (Math.pow(x, -0.5) * 0.5) / x;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = (math.pow(x, -0.5) + (x * 0.5)) + -1.0 else: tmp = (math.pow(x, -0.5) * 0.5) / x return tmp
function code(x) tmp = 0.0 if (x <= 1.0) tmp = Float64(Float64((x ^ -0.5) + Float64(x * 0.5)) + -1.0); else tmp = Float64(Float64((x ^ -0.5) * 0.5) / x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.0) tmp = ((x ^ -0.5) + (x * 0.5)) + -1.0; else tmp = ((x ^ -0.5) * 0.5) / x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], N[(N[(N[Power[x, -0.5], $MachinePrecision] + N[(x * 0.5), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(N[Power[x, -0.5], $MachinePrecision] * 0.5), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;\left({x}^{-0.5} + x \cdot 0.5\right) + -1\\
\mathbf{else}:\\
\;\;\;\;\frac{{x}^{-0.5} \cdot 0.5}{x}\\
\end{array}
\end{array}
if x < 1Initial program 99.6%
sub-neg99.6%
+-commutative99.6%
add-cube-cbrt99.6%
distribute-lft-neg-in99.6%
fma-def99.6%
Applied egg-rr100.0%
Taylor expanded in x around 0 99.2%
if 1 < x Initial program 42.7%
frac-sub42.7%
div-inv42.7%
*-un-lft-identity42.7%
+-commutative42.7%
*-rgt-identity42.7%
metadata-eval42.7%
frac-times42.7%
un-div-inv42.7%
pow1/242.7%
pow-flip42.7%
metadata-eval42.7%
+-commutative42.7%
Applied egg-rr42.7%
associate-*r/42.7%
*-rgt-identity42.7%
times-frac42.7%
div-sub42.7%
*-inverses42.7%
/-rgt-identity42.7%
Simplified42.7%
Taylor expanded in x around inf 97.6%
associate-*l/97.7%
Applied egg-rr97.7%
Final simplification98.4%
(FPCore (x) :precision binary64 (if (<= x 0.68) (+ (pow x -0.5) -1.0) (* (pow x -0.5) (/ 0.5 x))))
double code(double x) {
double tmp;
if (x <= 0.68) {
tmp = pow(x, -0.5) + -1.0;
} else {
tmp = pow(x, -0.5) * (0.5 / 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 = (x ** (-0.5d0)) * (0.5d0 / 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 = Math.pow(x, -0.5) * (0.5 / x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.68: tmp = math.pow(x, -0.5) + -1.0 else: tmp = math.pow(x, -0.5) * (0.5 / x) return tmp
function code(x) tmp = 0.0 if (x <= 0.68) tmp = Float64((x ^ -0.5) + -1.0); else tmp = Float64((x ^ -0.5) * Float64(0.5 / 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 = (x ^ -0.5) * (0.5 / 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[Power[x, -0.5], $MachinePrecision] * N[(0.5 / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.68:\\
\;\;\;\;{x}^{-0.5} + -1\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} \cdot \frac{0.5}{x}\\
\end{array}
\end{array}
if x < 0.680000000000000049Initial program 99.6%
sub-neg99.6%
+-commutative99.6%
add-cube-cbrt99.6%
distribute-lft-neg-in99.6%
fma-def99.6%
Applied egg-rr100.0%
Taylor expanded in x around 0 98.7%
if 0.680000000000000049 < x Initial program 42.7%
frac-sub42.7%
div-inv42.7%
*-un-lft-identity42.7%
+-commutative42.7%
*-rgt-identity42.7%
metadata-eval42.7%
frac-times42.7%
un-div-inv42.7%
pow1/242.7%
pow-flip42.7%
metadata-eval42.7%
+-commutative42.7%
Applied egg-rr42.7%
associate-*r/42.7%
*-rgt-identity42.7%
times-frac42.7%
div-sub42.7%
*-inverses42.7%
/-rgt-identity42.7%
Simplified42.7%
Taylor expanded in x around inf 97.6%
Final simplification98.1%
(FPCore (x) :precision binary64 (if (<= x 0.68) (+ (pow x -0.5) -1.0) (/ (* (pow x -0.5) 0.5) x)))
double code(double x) {
double tmp;
if (x <= 0.68) {
tmp = pow(x, -0.5) + -1.0;
} else {
tmp = (pow(x, -0.5) * 0.5) / 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 = ((x ** (-0.5d0)) * 0.5d0) / 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 = (Math.pow(x, -0.5) * 0.5) / x;
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.68: tmp = math.pow(x, -0.5) + -1.0 else: tmp = (math.pow(x, -0.5) * 0.5) / x return tmp
function code(x) tmp = 0.0 if (x <= 0.68) tmp = Float64((x ^ -0.5) + -1.0); else tmp = Float64(Float64((x ^ -0.5) * 0.5) / 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 = ((x ^ -0.5) * 0.5) / 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[(N[Power[x, -0.5], $MachinePrecision] * 0.5), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.68:\\
\;\;\;\;{x}^{-0.5} + -1\\
\mathbf{else}:\\
\;\;\;\;\frac{{x}^{-0.5} \cdot 0.5}{x}\\
\end{array}
\end{array}
if x < 0.680000000000000049Initial program 99.6%
sub-neg99.6%
+-commutative99.6%
add-cube-cbrt99.6%
distribute-lft-neg-in99.6%
fma-def99.6%
Applied egg-rr100.0%
Taylor expanded in x around 0 98.7%
if 0.680000000000000049 < x Initial program 42.7%
frac-sub42.7%
div-inv42.7%
*-un-lft-identity42.7%
+-commutative42.7%
*-rgt-identity42.7%
metadata-eval42.7%
frac-times42.7%
un-div-inv42.7%
pow1/242.7%
pow-flip42.7%
metadata-eval42.7%
+-commutative42.7%
Applied egg-rr42.7%
associate-*r/42.7%
*-rgt-identity42.7%
times-frac42.7%
div-sub42.7%
*-inverses42.7%
/-rgt-identity42.7%
Simplified42.7%
Taylor expanded in x around inf 97.6%
associate-*l/97.7%
Applied egg-rr97.7%
Final simplification98.2%
(FPCore (x) :precision binary64 (if (<= x 1.35e+154) (pow x -0.5) (- (pow (* x x) -0.25))))
double code(double x) {
double tmp;
if (x <= 1.35e+154) {
tmp = pow(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 <= 1.35d+154) then
tmp = 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 <= 1.35e+154) {
tmp = Math.pow(x, -0.5);
} else {
tmp = -Math.pow((x * x), -0.25);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.35e+154: tmp = math.pow(x, -0.5) else: tmp = -math.pow((x * x), -0.25) return tmp
function code(x) tmp = 0.0 if (x <= 1.35e+154) tmp = x ^ -0.5; else tmp = Float64(-(Float64(x * x) ^ -0.25)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.35e+154) tmp = x ^ -0.5; else tmp = -((x * x) ^ -0.25); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.35e+154], N[Power[x, -0.5], $MachinePrecision], (-N[Power[N[(x * x), $MachinePrecision], -0.25], $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;{x}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;-{\left(x \cdot x\right)}^{-0.25}\\
\end{array}
\end{array}
if x < 1.35000000000000003e154Initial program 68.8%
frac-sub68.8%
div-inv68.8%
*-un-lft-identity68.8%
+-commutative68.8%
*-rgt-identity68.8%
metadata-eval68.8%
frac-times68.8%
un-div-inv68.8%
pow1/268.8%
pow-flip69.0%
metadata-eval69.0%
+-commutative69.0%
Applied egg-rr69.0%
associate-*r/69.1%
*-rgt-identity69.1%
times-frac69.0%
div-sub69.1%
*-inverses69.1%
/-rgt-identity69.1%
Simplified69.1%
Taylor expanded in x around 0 65.7%
if 1.35000000000000003e154 < x Initial program 72.5%
inv-pow72.5%
pow1/272.5%
pow-pow54.5%
add-exp-log4.4%
+-commutative4.4%
log1p-udef4.4%
pow-exp4.4%
metadata-eval4.4%
Applied egg-rr4.4%
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-down72.5%
metadata-eval72.5%
Applied egg-rr72.5%
Final simplification67.5%
(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 69.8%
frac-sub69.8%
div-inv69.8%
*-un-lft-identity69.8%
+-commutative69.8%
*-rgt-identity69.8%
metadata-eval69.8%
frac-times69.8%
un-div-inv69.8%
pow1/269.8%
pow-flip70.0%
metadata-eval70.0%
+-commutative70.0%
Applied egg-rr70.0%
associate-*r/70.0%
*-rgt-identity70.0%
times-frac70.0%
div-sub70.0%
*-inverses70.0%
/-rgt-identity70.0%
Simplified70.0%
Taylor expanded in x around 0 48.9%
Final simplification48.9%
(FPCore (x) :precision binary64 (+ (* x 0.5) -1.0))
double code(double x) {
return (x * 0.5) + -1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * 0.5d0) + (-1.0d0)
end function
public static double code(double x) {
return (x * 0.5) + -1.0;
}
def code(x): return (x * 0.5) + -1.0
function code(x) return Float64(Float64(x * 0.5) + -1.0) end
function tmp = code(x) tmp = (x * 0.5) + -1.0; end
code[x_] := N[(N[(x * 0.5), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.5 + -1
\end{array}
Initial program 69.8%
sub-neg69.8%
+-commutative69.8%
add-cube-cbrt54.0%
distribute-lft-neg-in54.0%
fma-def51.3%
Applied egg-rr51.6%
Taylor expanded in x around 0 49.0%
Taylor expanded in x around inf 2.3%
*-commutative2.3%
Simplified2.3%
Final simplification2.3%
(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 2023194
(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)))))