
(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 5 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 (/ (+ (+ (* 0.5 (sqrt (/ 1.0 x))) (* (pow x -2.5) 0.3125)) (* (sqrt (pow x -3.0)) -0.375)) x))
double code(double x) {
return (((0.5 * sqrt((1.0 / x))) + (pow(x, -2.5) * 0.3125)) + (sqrt(pow(x, -3.0)) * -0.375)) / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (((0.5d0 * sqrt((1.0d0 / x))) + ((x ** (-2.5d0)) * 0.3125d0)) + (sqrt((x ** (-3.0d0))) * (-0.375d0))) / x
end function
public static double code(double x) {
return (((0.5 * Math.sqrt((1.0 / x))) + (Math.pow(x, -2.5) * 0.3125)) + (Math.sqrt(Math.pow(x, -3.0)) * -0.375)) / x;
}
def code(x): return (((0.5 * math.sqrt((1.0 / x))) + (math.pow(x, -2.5) * 0.3125)) + (math.sqrt(math.pow(x, -3.0)) * -0.375)) / x
function code(x) return Float64(Float64(Float64(Float64(0.5 * sqrt(Float64(1.0 / x))) + Float64((x ^ -2.5) * 0.3125)) + Float64(sqrt((x ^ -3.0)) * -0.375)) / x) end
function tmp = code(x) tmp = (((0.5 * sqrt((1.0 / x))) + ((x ^ -2.5) * 0.3125)) + (sqrt((x ^ -3.0)) * -0.375)) / x; end
code[x_] := N[(N[(N[(N[(0.5 * N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(N[Power[x, -2.5], $MachinePrecision] * 0.3125), $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[N[Power[x, -3.0], $MachinePrecision]], $MachinePrecision] * -0.375), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(0.5 \cdot \sqrt{\frac{1}{x}} + {x}^{-2.5} \cdot 0.3125\right) + \sqrt{{x}^{-3}} \cdot -0.375}{x}
\end{array}
Initial program 39.0%
expm1-log1p-u39.0%
expm1-undefine4.7%
inv-pow4.7%
sqrt-pow24.7%
metadata-eval4.7%
Applied egg-rr4.7%
sub-neg4.7%
log1p-undefine4.7%
rem-exp-log4.7%
+-commutative4.7%
metadata-eval4.7%
associate-+l+31.1%
metadata-eval31.1%
+-rgt-identity31.1%
Simplified31.1%
metadata-eval31.1%
pow-pow22.8%
sqr-pow21.7%
add-sqr-sqrt32.1%
difference-of-squares32.1%
metadata-eval32.1%
pow-pow32.1%
metadata-eval32.1%
inv-pow32.1%
+-commutative32.1%
sqrt-pow232.1%
metadata-eval32.1%
sqrt-pow132.1%
metadata-eval32.1%
Applied egg-rr39.1%
Taylor expanded in x around inf 99.4%
Simplified99.4%
*-un-lft-identity99.4%
pow1/299.4%
pow-flip99.4%
pow-pow99.4%
metadata-eval99.4%
metadata-eval99.4%
Applied egg-rr99.4%
*-lft-identity99.4%
Simplified99.4%
Final simplification99.4%
(FPCore (x) :precision binary64 (/ (+ (* 0.5 (sqrt (/ 1.0 x))) (* (sqrt (pow x -3.0)) -0.375)) x))
double code(double x) {
return ((0.5 * sqrt((1.0 / x))) + (sqrt(pow(x, -3.0)) * -0.375)) / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((0.5d0 * sqrt((1.0d0 / x))) + (sqrt((x ** (-3.0d0))) * (-0.375d0))) / x
end function
public static double code(double x) {
return ((0.5 * Math.sqrt((1.0 / x))) + (Math.sqrt(Math.pow(x, -3.0)) * -0.375)) / x;
}
def code(x): return ((0.5 * math.sqrt((1.0 / x))) + (math.sqrt(math.pow(x, -3.0)) * -0.375)) / x
function code(x) return Float64(Float64(Float64(0.5 * sqrt(Float64(1.0 / x))) + Float64(sqrt((x ^ -3.0)) * -0.375)) / x) end
function tmp = code(x) tmp = ((0.5 * sqrt((1.0 / x))) + (sqrt((x ^ -3.0)) * -0.375)) / x; end
code[x_] := N[(N[(N[(0.5 * N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[N[Power[x, -3.0], $MachinePrecision]], $MachinePrecision] * -0.375), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5 \cdot \sqrt{\frac{1}{x}} + \sqrt{{x}^{-3}} \cdot -0.375}{x}
\end{array}
Initial program 39.0%
expm1-log1p-u39.0%
expm1-undefine4.7%
inv-pow4.7%
sqrt-pow24.7%
metadata-eval4.7%
Applied egg-rr4.7%
sub-neg4.7%
log1p-undefine4.7%
rem-exp-log4.7%
+-commutative4.7%
metadata-eval4.7%
associate-+l+31.1%
metadata-eval31.1%
+-rgt-identity31.1%
Simplified31.1%
metadata-eval31.1%
pow-pow22.8%
sqr-pow21.7%
add-sqr-sqrt32.1%
difference-of-squares32.1%
metadata-eval32.1%
pow-pow32.1%
metadata-eval32.1%
inv-pow32.1%
+-commutative32.1%
sqrt-pow232.1%
metadata-eval32.1%
sqrt-pow132.1%
metadata-eval32.1%
Applied egg-rr39.1%
Taylor expanded in x around inf 99.2%
associate-+r+99.2%
+-commutative99.2%
distribute-rgt-out99.2%
exp-to-pow99.2%
*-commutative99.2%
rec-exp99.2%
mul-1-neg99.2%
associate-*r*99.2%
metadata-eval99.2%
*-commutative99.2%
exp-to-pow99.2%
metadata-eval99.2%
Simplified99.2%
Final simplification99.2%
(FPCore (x) :precision binary64 (* -0.5 (- (pow x -2.5) (pow x -1.5))))
double code(double x) {
return -0.5 * (pow(x, -2.5) - pow(x, -1.5));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-0.5d0) * ((x ** (-2.5d0)) - (x ** (-1.5d0)))
end function
public static double code(double x) {
return -0.5 * (Math.pow(x, -2.5) - Math.pow(x, -1.5));
}
def code(x): return -0.5 * (math.pow(x, -2.5) - math.pow(x, -1.5))
function code(x) return Float64(-0.5 * Float64((x ^ -2.5) - (x ^ -1.5))) end
function tmp = code(x) tmp = -0.5 * ((x ^ -2.5) - (x ^ -1.5)); end
code[x_] := N[(-0.5 * N[(N[Power[x, -2.5], $MachinePrecision] - N[Power[x, -1.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-0.5 \cdot \left({x}^{-2.5} - {x}^{-1.5}\right)
\end{array}
Initial program 39.0%
expm1-log1p-u39.0%
expm1-undefine4.7%
inv-pow4.7%
sqrt-pow24.7%
metadata-eval4.7%
Applied egg-rr4.7%
sub-neg4.7%
log1p-undefine4.7%
rem-exp-log4.7%
+-commutative4.7%
metadata-eval4.7%
associate-+l+31.1%
metadata-eval31.1%
+-rgt-identity31.1%
Simplified31.1%
Taylor expanded in x around inf 85.0%
distribute-lft-out--85.0%
associate-/l*85.0%
unpow1/285.0%
exp-to-pow85.0%
log-rec85.0%
distribute-lft-neg-out85.0%
distribute-rgt-neg-in85.0%
metadata-eval85.0%
exp-to-pow85.0%
Simplified85.0%
div-sub85.0%
pow1/285.0%
pow-div98.7%
metadata-eval98.7%
metadata-eval98.7%
sqrt-pow171.3%
pow-div71.3%
metadata-eval71.3%
metadata-eval71.3%
metadata-eval71.3%
sqrt-pow171.3%
pow-flip71.3%
sub-neg71.3%
pow-flip71.3%
sqrt-pow171.3%
metadata-eval71.3%
metadata-eval71.3%
sqrt-pow198.7%
metadata-eval98.7%
Applied egg-rr98.7%
sub-neg98.7%
Simplified98.7%
Final simplification98.7%
(FPCore (x) :precision binary64 (* 0.5 (pow x -1.5)))
double code(double x) {
return 0.5 * pow(x, -1.5);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.5d0 * (x ** (-1.5d0))
end function
public static double code(double x) {
return 0.5 * Math.pow(x, -1.5);
}
def code(x): return 0.5 * math.pow(x, -1.5)
function code(x) return Float64(0.5 * (x ^ -1.5)) end
function tmp = code(x) tmp = 0.5 * (x ^ -1.5); end
code[x_] := N[(0.5 * N[Power[x, -1.5], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot {x}^{-1.5}
\end{array}
Initial program 39.0%
Taylor expanded in x around inf 70.3%
pow170.3%
pow-flip71.2%
sqrt-pow198.6%
metadata-eval98.6%
metadata-eval98.6%
Applied egg-rr98.6%
unpow198.6%
Simplified98.6%
Final simplification98.6%
(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 39.0%
expm1-log1p-u39.0%
expm1-undefine4.7%
inv-pow4.7%
sqrt-pow24.7%
metadata-eval4.7%
Applied egg-rr4.7%
sub-neg4.7%
log1p-undefine4.7%
rem-exp-log4.7%
+-commutative4.7%
metadata-eval4.7%
associate-+l+31.1%
metadata-eval31.1%
+-rgt-identity31.1%
Simplified31.1%
Taylor expanded in x around 0 5.6%
unpow1/25.6%
exp-to-pow5.6%
log-rec5.6%
distribute-lft-neg-out5.6%
distribute-rgt-neg-in5.6%
metadata-eval5.6%
exp-to-pow5.6%
Simplified5.6%
Final simplification5.6%
(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 2024080
(FPCore (x)
:name "2isqrt (example 3.6)"
:precision binary64
:pre (and (> x 1.0) (< x 1e+308))
:alt
(/ 1.0 (+ (* (+ x 1.0) (sqrt x)) (* x (sqrt (+ x 1.0)))))
(- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))