
(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)))) 2e-15) (fma -0.25 (* (pow x -1.5) (/ 1.5 x)) (* (pow x -1.5) 0.5)) (- (pow x -0.5) (cbrt (pow (+ 1.0 x) -1.5)))))
double code(double x) {
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / sqrt((1.0 + x)))) <= 2e-15) {
tmp = fma(-0.25, (pow(x, -1.5) * (1.5 / x)), (pow(x, -1.5) * 0.5));
} else {
tmp = pow(x, -0.5) - cbrt(pow((1.0 + x), -1.5));
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / sqrt(Float64(1.0 + x)))) <= 2e-15) tmp = fma(-0.25, Float64((x ^ -1.5) * Float64(1.5 / x)), Float64((x ^ -1.5) * 0.5)); else tmp = Float64((x ^ -0.5) - cbrt((Float64(1.0 + x) ^ -1.5))); end return 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], 2e-15], N[(-0.25 * N[(N[Power[x, -1.5], $MachinePrecision] * N[(1.5 / x), $MachinePrecision]), $MachinePrecision] + N[(N[Power[x, -1.5], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[Power[N[(1.0 + x), $MachinePrecision], -1.5], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{1 + x}} \leq 2 \cdot 10^{-15}:\\
\;\;\;\;\mathsf{fma}\left(-0.25, {x}^{-1.5} \cdot \frac{1.5}{x}, {x}^{-1.5} \cdot 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} - \sqrt[3]{{\left(1 + x\right)}^{-1.5}}\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 2.0000000000000002e-15Initial program 42.4%
flip--42.4%
frac-times25.8%
metadata-eval25.8%
add-sqr-sqrt21.3%
frac-times27.5%
metadata-eval27.5%
add-sqr-sqrt42.5%
+-commutative42.5%
pow1/242.5%
pow-flip42.5%
metadata-eval42.5%
inv-pow42.5%
sqrt-pow242.5%
+-commutative42.5%
metadata-eval42.5%
Applied egg-rr42.5%
frac-sub43.1%
associate-/r*43.1%
*-un-lft-identity43.1%
+-commutative43.1%
*-rgt-identity43.1%
associate--l+43.1%
+-commutative43.1%
Applied egg-rr43.1%
Taylor expanded in x around inf 66.3%
Simplified100.0%
if 2.0000000000000002e-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%
pow1/299.5%
pow-flip99.8%
metadata-eval99.8%
pow1/299.8%
pow-flip99.8%
+-commutative99.8%
metadata-eval99.8%
Applied egg-rr99.8%
associate-+l-99.8%
expm1-log1p99.8%
expm1-def99.7%
associate--l-99.7%
fma-udef99.7%
distribute-lft1-in99.7%
metadata-eval99.7%
mul0-lft99.7%
metadata-eval99.7%
expm1-def99.8%
expm1-log1p99.8%
Simplified99.8%
metadata-eval99.8%
pow-flip99.8%
+-commutative99.8%
pow1/299.8%
add-cbrt-cube99.8%
pow399.8%
pow1/299.8%
+-commutative99.8%
pow-flip99.8%
metadata-eval99.8%
pow-pow99.8%
+-commutative99.8%
metadata-eval99.8%
Applied egg-rr99.8%
Final simplification99.9%
(FPCore (x) :precision binary64 (if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 (sqrt (+ 1.0 x)))) 2e-15) (* (pow x -1.5) 0.5) (- (pow x -0.5) (cbrt (pow (+ 1.0 x) -1.5)))))
double code(double x) {
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / sqrt((1.0 + x)))) <= 2e-15) {
tmp = pow(x, -1.5) * 0.5;
} else {
tmp = pow(x, -0.5) - cbrt(pow((1.0 + x), -1.5));
}
return tmp;
}
public static double code(double x) {
double tmp;
if (((1.0 / Math.sqrt(x)) + (-1.0 / Math.sqrt((1.0 + x)))) <= 2e-15) {
tmp = Math.pow(x, -1.5) * 0.5;
} else {
tmp = Math.pow(x, -0.5) - Math.cbrt(Math.pow((1.0 + x), -1.5));
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / sqrt(Float64(1.0 + x)))) <= 2e-15) tmp = Float64((x ^ -1.5) * 0.5); else tmp = Float64((x ^ -0.5) - cbrt((Float64(1.0 + x) ^ -1.5))); end return 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], 2e-15], N[(N[Power[x, -1.5], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[Power[N[(1.0 + x), $MachinePrecision], -1.5], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{1 + x}} \leq 2 \cdot 10^{-15}:\\
\;\;\;\;{x}^{-1.5} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} - \sqrt[3]{{\left(1 + x\right)}^{-1.5}}\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 2.0000000000000002e-15Initial program 42.4%
flip--42.4%
frac-times25.8%
metadata-eval25.8%
add-sqr-sqrt21.3%
frac-times27.5%
metadata-eval27.5%
add-sqr-sqrt42.5%
+-commutative42.5%
pow1/242.5%
pow-flip42.5%
metadata-eval42.5%
inv-pow42.5%
sqrt-pow242.5%
+-commutative42.5%
metadata-eval42.5%
Applied egg-rr42.5%
frac-sub43.1%
associate-/r*43.1%
*-un-lft-identity43.1%
+-commutative43.1%
*-rgt-identity43.1%
associate--l+43.1%
+-commutative43.1%
Applied egg-rr43.1%
Taylor expanded in x around inf 65.9%
unpow-165.9%
exp-to-pow63.9%
*-commutative63.9%
exp-prod64.1%
*-commutative64.1%
associate-*r*64.1%
metadata-eval64.1%
*-commutative64.1%
exp-to-pow66.1%
metadata-eval66.1%
pow-sqr66.2%
rem-sqrt-square99.6%
rem-square-sqrt99.2%
fabs-sqr99.2%
rem-square-sqrt99.6%
Simplified99.6%
if 2.0000000000000002e-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%
pow1/299.5%
pow-flip99.8%
metadata-eval99.8%
pow1/299.8%
pow-flip99.8%
+-commutative99.8%
metadata-eval99.8%
Applied egg-rr99.8%
associate-+l-99.8%
expm1-log1p99.8%
expm1-def99.7%
associate--l-99.7%
fma-udef99.7%
distribute-lft1-in99.7%
metadata-eval99.7%
mul0-lft99.7%
metadata-eval99.7%
expm1-def99.8%
expm1-log1p99.8%
Simplified99.8%
metadata-eval99.8%
pow-flip99.8%
+-commutative99.8%
pow1/299.8%
add-cbrt-cube99.8%
pow399.8%
pow1/299.8%
+-commutative99.8%
pow-flip99.8%
metadata-eval99.8%
pow-pow99.8%
+-commutative99.8%
metadata-eval99.8%
Applied egg-rr99.8%
Final simplification99.7%
(FPCore (x) :precision binary64 (if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 (sqrt (+ 1.0 x)))) 2e-15) (* (pow x -1.5) 0.5) (- (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)))) <= 2e-15) {
tmp = pow(x, -1.5) * 0.5;
} 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)))) <= 2d-15) then
tmp = (x ** (-1.5d0)) * 0.5d0
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)))) <= 2e-15) {
tmp = Math.pow(x, -1.5) * 0.5;
} 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)))) <= 2e-15: tmp = math.pow(x, -1.5) * 0.5 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)))) <= 2e-15) tmp = Float64((x ^ -1.5) * 0.5); 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)))) <= 2e-15) tmp = (x ^ -1.5) * 0.5; 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], 2e-15], N[(N[Power[x, -1.5], $MachinePrecision] * 0.5), $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 2 \cdot 10^{-15}:\\
\;\;\;\;{x}^{-1.5} \cdot 0.5\\
\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)))) < 2.0000000000000002e-15Initial program 42.4%
flip--42.4%
frac-times25.8%
metadata-eval25.8%
add-sqr-sqrt21.3%
frac-times27.5%
metadata-eval27.5%
add-sqr-sqrt42.5%
+-commutative42.5%
pow1/242.5%
pow-flip42.5%
metadata-eval42.5%
inv-pow42.5%
sqrt-pow242.5%
+-commutative42.5%
metadata-eval42.5%
Applied egg-rr42.5%
frac-sub43.1%
associate-/r*43.1%
*-un-lft-identity43.1%
+-commutative43.1%
*-rgt-identity43.1%
associate--l+43.1%
+-commutative43.1%
Applied egg-rr43.1%
Taylor expanded in x around inf 65.9%
unpow-165.9%
exp-to-pow63.9%
*-commutative63.9%
exp-prod64.1%
*-commutative64.1%
associate-*r*64.1%
metadata-eval64.1%
*-commutative64.1%
exp-to-pow66.1%
metadata-eval66.1%
pow-sqr66.2%
rem-sqrt-square99.6%
rem-square-sqrt99.2%
fabs-sqr99.2%
rem-square-sqrt99.6%
Simplified99.6%
if 2.0000000000000002e-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%
pow1/299.5%
pow-flip99.8%
metadata-eval99.8%
pow1/299.8%
pow-flip99.8%
+-commutative99.8%
metadata-eval99.8%
Applied egg-rr99.8%
associate-+l-99.8%
expm1-log1p99.8%
expm1-def99.7%
associate--l-99.7%
fma-udef99.7%
distribute-lft1-in99.7%
metadata-eval99.7%
mul0-lft99.7%
metadata-eval99.7%
expm1-def99.8%
expm1-log1p99.8%
Simplified99.8%
Final simplification99.7%
(FPCore (x) :precision binary64 (if (<= x 1.0) (+ (+ (pow x -0.5) (* x 0.5)) -1.0) (* (pow x -1.5) 0.5)))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = (pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = pow(x, -1.5) * 0.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)) + (x * 0.5d0)) + (-1.0d0)
else
tmp = (x ** (-1.5d0)) * 0.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) + (x * 0.5)) + -1.0;
} else {
tmp = Math.pow(x, -1.5) * 0.5;
}
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, -1.5) * 0.5 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((x ^ -1.5) * 0.5); 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 ^ -1.5) * 0.5; 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[Power[x, -1.5], $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;\left({x}^{-0.5} + x \cdot 0.5\right) + -1\\
\mathbf{else}:\\
\;\;\;\;{x}^{-1.5} \cdot 0.5\\
\end{array}
\end{array}
if x < 1Initial 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%
pow1/299.7%
pow-flip100.0%
metadata-eval100.0%
pow1/2100.0%
pow-flip100.0%
+-commutative100.0%
metadata-eval100.0%
Applied egg-rr100.0%
associate-+l-100.0%
expm1-log1p100.0%
expm1-def100.0%
associate--l-100.0%
fma-udef100.0%
distribute-lft1-in100.0%
metadata-eval100.0%
mul0-lft100.0%
metadata-eval100.0%
expm1-def100.0%
expm1-log1p100.0%
Simplified100.0%
Taylor expanded in x around 0 99.6%
if 1 < x Initial program 43.0%
flip--43.0%
frac-times26.6%
metadata-eval26.6%
add-sqr-sqrt22.3%
frac-times28.4%
metadata-eval28.4%
add-sqr-sqrt43.2%
+-commutative43.2%
pow1/243.2%
pow-flip43.2%
metadata-eval43.2%
inv-pow43.2%
sqrt-pow243.2%
+-commutative43.2%
metadata-eval43.2%
Applied egg-rr43.2%
frac-sub43.9%
associate-/r*44.0%
*-un-lft-identity44.0%
+-commutative44.0%
*-rgt-identity44.0%
associate--l+44.0%
+-commutative44.0%
Applied egg-rr44.0%
Taylor expanded in x around inf 65.5%
unpow-165.5%
exp-to-pow63.5%
*-commutative63.5%
exp-prod63.7%
*-commutative63.7%
associate-*r*63.7%
metadata-eval63.7%
*-commutative63.7%
exp-to-pow65.7%
metadata-eval65.7%
pow-sqr65.7%
rem-sqrt-square98.7%
rem-square-sqrt98.3%
fabs-sqr98.3%
rem-square-sqrt98.7%
Simplified98.7%
Final simplification99.1%
(FPCore (x) :precision binary64 (if (<= x 0.5) (pow x -0.5) (* (pow x -1.5) 0.5)))
double code(double x) {
double tmp;
if (x <= 0.5) {
tmp = pow(x, -0.5);
} else {
tmp = pow(x, -1.5) * 0.5;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.5d0) then
tmp = x ** (-0.5d0)
else
tmp = (x ** (-1.5d0)) * 0.5d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.5) {
tmp = Math.pow(x, -0.5);
} else {
tmp = Math.pow(x, -1.5) * 0.5;
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.5: tmp = math.pow(x, -0.5) else: tmp = math.pow(x, -1.5) * 0.5 return tmp
function code(x) tmp = 0.0 if (x <= 0.5) tmp = x ^ -0.5; else tmp = Float64((x ^ -1.5) * 0.5); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.5) tmp = x ^ -0.5; else tmp = (x ^ -1.5) * 0.5; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.5], N[Power[x, -0.5], $MachinePrecision], N[(N[Power[x, -1.5], $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.5:\\
\;\;\;\;{x}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;{x}^{-1.5} \cdot 0.5\\
\end{array}
\end{array}
if x < 0.5Initial program 99.7%
inv-pow99.7%
add-sqr-sqrt99.2%
unpow-prod-down98.9%
pow1/298.9%
sqrt-pow199.1%
metadata-eval99.1%
pow1/299.1%
sqrt-pow199.0%
metadata-eval99.0%
Applied egg-rr99.0%
pow-sqr99.2%
metadata-eval99.2%
Simplified99.2%
Taylor expanded in x around inf 96.3%
inv-pow96.3%
sqrt-pow196.5%
metadata-eval96.5%
expm1-log1p-u89.0%
expm1-udef89.0%
Applied egg-rr89.0%
expm1-def89.0%
expm1-log1p96.5%
Simplified96.5%
if 0.5 < x Initial program 43.0%
flip--43.0%
frac-times26.6%
metadata-eval26.6%
add-sqr-sqrt22.3%
frac-times28.4%
metadata-eval28.4%
add-sqr-sqrt43.2%
+-commutative43.2%
pow1/243.2%
pow-flip43.2%
metadata-eval43.2%
inv-pow43.2%
sqrt-pow243.2%
+-commutative43.2%
metadata-eval43.2%
Applied egg-rr43.2%
frac-sub43.9%
associate-/r*44.0%
*-un-lft-identity44.0%
+-commutative44.0%
*-rgt-identity44.0%
associate--l+44.0%
+-commutative44.0%
Applied egg-rr44.0%
Taylor expanded in x around inf 65.5%
unpow-165.5%
exp-to-pow63.5%
*-commutative63.5%
exp-prod63.7%
*-commutative63.7%
associate-*r*63.7%
metadata-eval63.7%
*-commutative63.7%
exp-to-pow65.7%
metadata-eval65.7%
pow-sqr65.7%
rem-sqrt-square98.7%
rem-square-sqrt98.3%
fabs-sqr98.3%
rem-square-sqrt98.7%
Simplified98.7%
Final simplification97.7%
(FPCore (x) :precision binary64 (if (<= x 0.68) (+ (pow x -0.5) -1.0) (* (pow x -1.5) 0.5)))
double code(double x) {
double tmp;
if (x <= 0.68) {
tmp = pow(x, -0.5) + -1.0;
} else {
tmp = pow(x, -1.5) * 0.5;
}
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 ** (-1.5d0)) * 0.5d0
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, -1.5) * 0.5;
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.68: tmp = math.pow(x, -0.5) + -1.0 else: tmp = math.pow(x, -1.5) * 0.5 return tmp
function code(x) tmp = 0.0 if (x <= 0.68) tmp = Float64((x ^ -0.5) + -1.0); else tmp = Float64((x ^ -1.5) * 0.5); 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 ^ -1.5) * 0.5; 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, -1.5], $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.68:\\
\;\;\;\;{x}^{-0.5} + -1\\
\mathbf{else}:\\
\;\;\;\;{x}^{-1.5} \cdot 0.5\\
\end{array}
\end{array}
if x < 0.680000000000000049Initial 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%
pow1/299.7%
pow-flip100.0%
metadata-eval100.0%
pow1/2100.0%
pow-flip100.0%
+-commutative100.0%
metadata-eval100.0%
Applied egg-rr100.0%
associate-+l-100.0%
expm1-log1p100.0%
expm1-def100.0%
associate--l-100.0%
fma-udef100.0%
distribute-lft1-in100.0%
metadata-eval100.0%
mul0-lft100.0%
metadata-eval100.0%
expm1-def100.0%
expm1-log1p100.0%
Simplified100.0%
Taylor expanded in x around 0 99.2%
if 0.680000000000000049 < x Initial program 43.0%
flip--43.0%
frac-times26.6%
metadata-eval26.6%
add-sqr-sqrt22.3%
frac-times28.4%
metadata-eval28.4%
add-sqr-sqrt43.2%
+-commutative43.2%
pow1/243.2%
pow-flip43.2%
metadata-eval43.2%
inv-pow43.2%
sqrt-pow243.2%
+-commutative43.2%
metadata-eval43.2%
Applied egg-rr43.2%
frac-sub43.9%
associate-/r*44.0%
*-un-lft-identity44.0%
+-commutative44.0%
*-rgt-identity44.0%
associate--l+44.0%
+-commutative44.0%
Applied egg-rr44.0%
Taylor expanded in x around inf 65.5%
unpow-165.5%
exp-to-pow63.5%
*-commutative63.5%
exp-prod63.7%
*-commutative63.7%
associate-*r*63.7%
metadata-eval63.7%
*-commutative63.7%
exp-to-pow65.7%
metadata-eval65.7%
pow-sqr65.7%
rem-sqrt-square98.7%
rem-square-sqrt98.3%
fabs-sqr98.3%
rem-square-sqrt98.7%
Simplified98.7%
Final simplification98.9%
(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 68.9%
inv-pow68.9%
add-sqr-sqrt61.0%
unpow-prod-down55.5%
pow1/255.5%
sqrt-pow155.8%
metadata-eval55.8%
pow1/255.8%
sqrt-pow154.9%
metadata-eval54.9%
Applied egg-rr54.9%
pow-sqr56.1%
metadata-eval56.1%
Simplified56.1%
Taylor expanded in x around inf 47.0%
inv-pow47.0%
sqrt-pow147.0%
metadata-eval47.0%
expm1-log1p-u43.6%
expm1-udef63.3%
Applied egg-rr63.3%
expm1-def43.6%
expm1-log1p47.0%
Simplified47.0%
Final simplification47.0%
(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 68.9%
inv-pow68.9%
add-sqr-sqrt61.0%
unpow-prod-down55.5%
pow1/255.5%
sqrt-pow155.8%
metadata-eval55.8%
pow1/255.8%
sqrt-pow154.9%
metadata-eval54.9%
Applied egg-rr54.9%
pow-sqr56.1%
metadata-eval56.1%
Simplified56.1%
Taylor expanded in x around 0 47.2%
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 2024018
(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)))))