
(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 (/ (/ -1.0 (- -1.0 x)) (* x (+ (pow (+ x 1.0) -0.5) (pow x -0.5)))))
double code(double x) {
return (-1.0 / (-1.0 - x)) / (x * (pow((x + 1.0), -0.5) + pow(x, -0.5)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((-1.0d0) / ((-1.0d0) - x)) / (x * (((x + 1.0d0) ** (-0.5d0)) + (x ** (-0.5d0))))
end function
public static double code(double x) {
return (-1.0 / (-1.0 - x)) / (x * (Math.pow((x + 1.0), -0.5) + Math.pow(x, -0.5)));
}
def code(x): return (-1.0 / (-1.0 - x)) / (x * (math.pow((x + 1.0), -0.5) + math.pow(x, -0.5)))
function code(x) return Float64(Float64(-1.0 / Float64(-1.0 - x)) / Float64(x * Float64((Float64(x + 1.0) ^ -0.5) + (x ^ -0.5)))) end
function tmp = code(x) tmp = (-1.0 / (-1.0 - x)) / (x * (((x + 1.0) ^ -0.5) + (x ^ -0.5))); end
code[x_] := N[(N[(-1.0 / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision] / N[(x * N[(N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision] + N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{-1}{-1 - x}}{x \cdot \left({\left(x + 1\right)}^{-0.5} + {x}^{-0.5}\right)}
\end{array}
Initial program 33.0%
flip--33.0%
div-inv33.0%
frac-times19.1%
metadata-eval19.1%
add-sqr-sqrt17.0%
frac-times24.5%
metadata-eval24.5%
add-sqr-sqrt33.1%
+-commutative33.1%
pow1/233.1%
pow-flip33.1%
metadata-eval33.1%
inv-pow33.1%
sqrt-pow233.1%
+-commutative33.1%
metadata-eval33.1%
Applied egg-rr33.1%
frac-2neg33.1%
metadata-eval33.1%
frac-sub34.5%
*-un-lft-identity34.5%
distribute-neg-in34.5%
metadata-eval34.5%
distribute-neg-in34.5%
metadata-eval34.5%
Applied egg-rr34.5%
associate-/r*34.6%
associate--l+81.2%
*-commutative81.2%
neg-mul-181.2%
+-inverses81.2%
metadata-eval81.2%
unsub-neg81.2%
Simplified81.2%
associate-/l/80.5%
associate-*l/80.5%
sub-neg80.5%
metadata-eval80.5%
distribute-neg-in80.5%
distribute-lft-neg-in80.5%
associate-*l/80.5%
metadata-eval80.5%
frac-2neg80.5%
*-commutative80.5%
associate-/r*81.2%
frac-times99.6%
*-un-lft-identity99.6%
frac-2neg99.6%
metadata-eval99.6%
distribute-neg-in99.6%
metadata-eval99.6%
sub-neg99.6%
Applied egg-rr99.6%
Final simplification99.6%
(FPCore (x) :precision binary64 (/ (/ -1.0 (- -1.0 x)) (+ (* x (pow (+ x 1.0) -0.5)) (sqrt x))))
double code(double x) {
return (-1.0 / (-1.0 - x)) / ((x * pow((x + 1.0), -0.5)) + sqrt(x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((-1.0d0) / ((-1.0d0) - x)) / ((x * ((x + 1.0d0) ** (-0.5d0))) + sqrt(x))
end function
public static double code(double x) {
return (-1.0 / (-1.0 - x)) / ((x * Math.pow((x + 1.0), -0.5)) + Math.sqrt(x));
}
def code(x): return (-1.0 / (-1.0 - x)) / ((x * math.pow((x + 1.0), -0.5)) + math.sqrt(x))
function code(x) return Float64(Float64(-1.0 / Float64(-1.0 - x)) / Float64(Float64(x * (Float64(x + 1.0) ^ -0.5)) + sqrt(x))) end
function tmp = code(x) tmp = (-1.0 / (-1.0 - x)) / ((x * ((x + 1.0) ^ -0.5)) + sqrt(x)); end
code[x_] := N[(N[(-1.0 / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision] / N[(N[(x * N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision] + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{-1}{-1 - x}}{x \cdot {\left(x + 1\right)}^{-0.5} + \sqrt{x}}
\end{array}
Initial program 33.0%
flip--33.0%
div-inv33.0%
frac-times19.1%
metadata-eval19.1%
add-sqr-sqrt17.0%
frac-times24.5%
metadata-eval24.5%
add-sqr-sqrt33.1%
+-commutative33.1%
pow1/233.1%
pow-flip33.1%
metadata-eval33.1%
inv-pow33.1%
sqrt-pow233.1%
+-commutative33.1%
metadata-eval33.1%
Applied egg-rr33.1%
frac-2neg33.1%
metadata-eval33.1%
frac-sub34.5%
*-un-lft-identity34.5%
distribute-neg-in34.5%
metadata-eval34.5%
distribute-neg-in34.5%
metadata-eval34.5%
Applied egg-rr34.5%
associate-/r*34.6%
associate--l+81.2%
*-commutative81.2%
neg-mul-181.2%
+-inverses81.2%
metadata-eval81.2%
unsub-neg81.2%
Simplified81.2%
associate-/l/80.5%
associate-*l/80.5%
sub-neg80.5%
metadata-eval80.5%
distribute-neg-in80.5%
distribute-lft-neg-in80.5%
associate-*l/80.5%
metadata-eval80.5%
frac-2neg80.5%
*-commutative80.5%
associate-/r*81.2%
frac-times99.6%
*-un-lft-identity99.6%
frac-2neg99.6%
metadata-eval99.6%
distribute-neg-in99.6%
metadata-eval99.6%
sub-neg99.6%
Applied egg-rr99.6%
*-commutative99.6%
distribute-rgt-in99.6%
pow-plus99.6%
metadata-eval99.6%
pow1/299.6%
Applied egg-rr99.6%
Final simplification99.6%
(FPCore (x) :precision binary64 (/ (/ -1.0 (- -1.0 x)) (* x (* 2.0 (sqrt (/ 1.0 x))))))
double code(double x) {
return (-1.0 / (-1.0 - x)) / (x * (2.0 * sqrt((1.0 / x))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((-1.0d0) / ((-1.0d0) - x)) / (x * (2.0d0 * sqrt((1.0d0 / x))))
end function
public static double code(double x) {
return (-1.0 / (-1.0 - x)) / (x * (2.0 * Math.sqrt((1.0 / x))));
}
def code(x): return (-1.0 / (-1.0 - x)) / (x * (2.0 * math.sqrt((1.0 / x))))
function code(x) return Float64(Float64(-1.0 / Float64(-1.0 - x)) / Float64(x * Float64(2.0 * sqrt(Float64(1.0 / x))))) end
function tmp = code(x) tmp = (-1.0 / (-1.0 - x)) / (x * (2.0 * sqrt((1.0 / x)))); end
code[x_] := N[(N[(-1.0 / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision] / N[(x * N[(2.0 * N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{-1}{-1 - x}}{x \cdot \left(2 \cdot \sqrt{\frac{1}{x}}\right)}
\end{array}
Initial program 33.0%
flip--33.0%
div-inv33.0%
frac-times19.1%
metadata-eval19.1%
add-sqr-sqrt17.0%
frac-times24.5%
metadata-eval24.5%
add-sqr-sqrt33.1%
+-commutative33.1%
pow1/233.1%
pow-flip33.1%
metadata-eval33.1%
inv-pow33.1%
sqrt-pow233.1%
+-commutative33.1%
metadata-eval33.1%
Applied egg-rr33.1%
frac-2neg33.1%
metadata-eval33.1%
frac-sub34.5%
*-un-lft-identity34.5%
distribute-neg-in34.5%
metadata-eval34.5%
distribute-neg-in34.5%
metadata-eval34.5%
Applied egg-rr34.5%
associate-/r*34.6%
associate--l+81.2%
*-commutative81.2%
neg-mul-181.2%
+-inverses81.2%
metadata-eval81.2%
unsub-neg81.2%
Simplified81.2%
associate-/l/80.5%
associate-*l/80.5%
sub-neg80.5%
metadata-eval80.5%
distribute-neg-in80.5%
distribute-lft-neg-in80.5%
associate-*l/80.5%
metadata-eval80.5%
frac-2neg80.5%
*-commutative80.5%
associate-/r*81.2%
frac-times99.6%
*-un-lft-identity99.6%
frac-2neg99.6%
metadata-eval99.6%
distribute-neg-in99.6%
metadata-eval99.6%
sub-neg99.6%
Applied egg-rr99.6%
Taylor expanded in x around inf 98.8%
Final simplification98.8%
(FPCore (x) :precision binary64 (/ (/ -1.0 (- -1.0 x)) (* (sqrt x) 2.0)))
double code(double x) {
return (-1.0 / (-1.0 - x)) / (sqrt(x) * 2.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((-1.0d0) / ((-1.0d0) - x)) / (sqrt(x) * 2.0d0)
end function
public static double code(double x) {
return (-1.0 / (-1.0 - x)) / (Math.sqrt(x) * 2.0);
}
def code(x): return (-1.0 / (-1.0 - x)) / (math.sqrt(x) * 2.0)
function code(x) return Float64(Float64(-1.0 / Float64(-1.0 - x)) / Float64(sqrt(x) * 2.0)) end
function tmp = code(x) tmp = (-1.0 / (-1.0 - x)) / (sqrt(x) * 2.0); end
code[x_] := N[(N[(-1.0 / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[x], $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{-1}{-1 - x}}{\sqrt{x} \cdot 2}
\end{array}
Initial program 33.0%
flip--33.0%
div-inv33.0%
frac-times19.1%
metadata-eval19.1%
add-sqr-sqrt17.0%
frac-times24.5%
metadata-eval24.5%
add-sqr-sqrt33.1%
+-commutative33.1%
pow1/233.1%
pow-flip33.1%
metadata-eval33.1%
inv-pow33.1%
sqrt-pow233.1%
+-commutative33.1%
metadata-eval33.1%
Applied egg-rr33.1%
frac-2neg33.1%
metadata-eval33.1%
frac-sub34.5%
*-un-lft-identity34.5%
distribute-neg-in34.5%
metadata-eval34.5%
distribute-neg-in34.5%
metadata-eval34.5%
Applied egg-rr34.5%
associate-/r*34.6%
associate--l+81.2%
*-commutative81.2%
neg-mul-181.2%
+-inverses81.2%
metadata-eval81.2%
unsub-neg81.2%
Simplified81.2%
associate-/l/80.5%
associate-*l/80.5%
sub-neg80.5%
metadata-eval80.5%
distribute-neg-in80.5%
distribute-lft-neg-in80.5%
associate-*l/80.5%
metadata-eval80.5%
frac-2neg80.5%
*-commutative80.5%
associate-/r*81.2%
frac-times99.6%
*-un-lft-identity99.6%
frac-2neg99.6%
metadata-eval99.6%
distribute-neg-in99.6%
metadata-eval99.6%
sub-neg99.6%
Applied egg-rr99.6%
Taylor expanded in x around inf 98.7%
Final simplification98.7%
(FPCore (x) :precision binary64 (/ 1.0 (sqrt (* x (+ x 1.0)))))
double code(double x) {
return 1.0 / sqrt((x * (x + 1.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / sqrt((x * (x + 1.0d0)))
end function
public static double code(double x) {
return 1.0 / Math.sqrt((x * (x + 1.0)));
}
def code(x): return 1.0 / math.sqrt((x * (x + 1.0)))
function code(x) return Float64(1.0 / sqrt(Float64(x * Float64(x + 1.0)))) end
function tmp = code(x) tmp = 1.0 / sqrt((x * (x + 1.0))); end
code[x_] := N[(1.0 / N[Sqrt[N[(x * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{x \cdot \left(x + 1\right)}}
\end{array}
Initial program 33.0%
frac-sub33.1%
*-un-lft-identity33.1%
+-commutative33.1%
*-rgt-identity33.1%
sqrt-unprod33.1%
+-commutative33.1%
Applied egg-rr33.1%
Taylor expanded in x around 0 33.5%
Final simplification33.5%
(FPCore (x) :precision binary64 (/ 1.0 (+ x (sqrt x))))
double code(double x) {
return 1.0 / (x + sqrt(x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (x + sqrt(x))
end function
public static double code(double x) {
return 1.0 / (x + Math.sqrt(x));
}
def code(x): return 1.0 / (x + math.sqrt(x))
function code(x) return Float64(1.0 / Float64(x + sqrt(x))) end
function tmp = code(x) tmp = 1.0 / (x + sqrt(x)); end
code[x_] := N[(1.0 / N[(x + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x + \sqrt{x}}
\end{array}
Initial program 33.0%
flip--33.0%
div-inv33.0%
frac-times19.1%
metadata-eval19.1%
add-sqr-sqrt17.0%
frac-times24.5%
metadata-eval24.5%
add-sqr-sqrt33.1%
+-commutative33.1%
pow1/233.1%
pow-flip33.1%
metadata-eval33.1%
inv-pow33.1%
sqrt-pow233.1%
+-commutative33.1%
metadata-eval33.1%
Applied egg-rr33.1%
Taylor expanded in x around 0 7.8%
distribute-rgt-in7.8%
*-un-lft-identity7.8%
pow-plus7.8%
metadata-eval7.8%
pow1/27.8%
+-commutative7.8%
Applied egg-rr7.8%
Final simplification7.8%
(FPCore (x) :precision binary64 (- (pow x -0.5)))
double code(double x) {
return -pow(x, -0.5);
}
real(8) function code(x)
real(8), intent (in) :: x
code = -(x ** (-0.5d0))
end function
public static double code(double x) {
return -Math.pow(x, -0.5);
}
def code(x): return -math.pow(x, -0.5)
function code(x) return Float64(-(x ^ -0.5)) end
function tmp = code(x) tmp = -(x ^ -0.5); end
code[x_] := (-N[Power[x, -0.5], $MachinePrecision])
\begin{array}{l}
\\
-{x}^{-0.5}
\end{array}
Initial program 33.0%
expm1-log1p-u33.0%
expm1-udef6.0%
inv-pow6.0%
sqrt-pow26.0%
+-commutative6.0%
metadata-eval6.0%
Applied egg-rr6.0%
expm1-def26.1%
expm1-log1p26.1%
Simplified26.1%
Taylor expanded in x around inf 3.1%
mul-1-neg3.1%
rem-exp-log3.1%
exp-neg3.1%
unpow1/23.1%
exp-prod3.1%
distribute-lft-neg-out3.1%
distribute-rgt-neg-in3.1%
metadata-eval3.1%
exp-to-pow3.1%
Simplified3.1%
Final simplification3.1%
(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 33.0%
*-un-lft-identity33.0%
inv-pow33.0%
add-cube-cbrt12.2%
unpow-prod-down12.8%
prod-diff6.2%
Applied egg-rr6.2%
+-commutative6.2%
fma-udef6.2%
*-lft-identity6.2%
Simplified15.4%
Taylor expanded in x around inf 5.5%
Final simplification5.5%
(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 2024039
(FPCore (x)
:name "2isqrt (example 3.6)"
:precision binary64
:pre (and (> x 1.0) (< x 1e+308))
:herbie-target
(/ 1.0 (+ (* (+ x 1.0) (sqrt x)) (* x (sqrt (+ x 1.0)))))
(- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))