
(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 4 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 (+ x 0.5)) (+ (sqrt x) (sqrt (+ 1.0 x)))))
double code(double x) {
return (1.0 / (x + 0.5)) / (sqrt(x) + sqrt((1.0 + x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / (x + 0.5d0)) / (sqrt(x) + sqrt((1.0d0 + x)))
end function
public static double code(double x) {
return (1.0 / (x + 0.5)) / (Math.sqrt(x) + Math.sqrt((1.0 + x)));
}
def code(x): return (1.0 / (x + 0.5)) / (math.sqrt(x) + math.sqrt((1.0 + x)))
function code(x) return Float64(Float64(1.0 / Float64(x + 0.5)) / Float64(sqrt(x) + sqrt(Float64(1.0 + x)))) end
function tmp = code(x) tmp = (1.0 / (x + 0.5)) / (sqrt(x) + sqrt((1.0 + x))); end
code[x_] := N[(N[(1.0 / N[(x + 0.5), $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{x + 0.5}}{\sqrt{x} + \sqrt{1 + x}}
\end{array}
Initial program 38.6%
frac-sub38.7%
*-rgt-identity38.7%
*-un-lft-identity38.7%
+-commutative38.7%
sqrt-unprod38.7%
+-commutative38.7%
Applied egg-rr38.7%
Taylor expanded in x around inf 38.2%
associate-*r/38.2%
metadata-eval38.2%
Simplified38.2%
flip--38.8%
add-sqr-sqrt22.8%
add-sqr-sqrt39.3%
Applied egg-rr39.3%
associate--l+98.8%
+-inverses98.8%
metadata-eval98.8%
+-commutative98.8%
Simplified98.8%
*-un-lft-identity98.8%
associate-/l/97.8%
Applied egg-rr97.8%
*-lft-identity97.8%
associate-/r*98.8%
distribute-lft-in98.8%
*-rgt-identity98.8%
metadata-eval98.8%
associate-*r/98.8%
*-commutative98.8%
associate-*r*98.8%
rgt-mult-inverse98.8%
metadata-eval98.8%
Simplified98.8%
Final simplification98.8%
(FPCore (x) :precision binary64 (/ (* 0.5 (pow x -1.5)) (+ 1.0 (/ 0.5 x))))
double code(double x) {
return (0.5 * pow(x, -1.5)) / (1.0 + (0.5 / x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (0.5d0 * (x ** (-1.5d0))) / (1.0d0 + (0.5d0 / x))
end function
public static double code(double x) {
return (0.5 * Math.pow(x, -1.5)) / (1.0 + (0.5 / x));
}
def code(x): return (0.5 * math.pow(x, -1.5)) / (1.0 + (0.5 / x))
function code(x) return Float64(Float64(0.5 * (x ^ -1.5)) / Float64(1.0 + Float64(0.5 / x))) end
function tmp = code(x) tmp = (0.5 * (x ^ -1.5)) / (1.0 + (0.5 / x)); end
code[x_] := N[(N[(0.5 * N[Power[x, -1.5], $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[(0.5 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5 \cdot {x}^{-1.5}}{1 + \frac{0.5}{x}}
\end{array}
Initial program 38.6%
frac-sub38.7%
*-rgt-identity38.7%
*-un-lft-identity38.7%
+-commutative38.7%
sqrt-unprod38.7%
+-commutative38.7%
Applied egg-rr38.7%
Taylor expanded in x around inf 38.2%
associate-*r/38.2%
metadata-eval38.2%
Simplified38.2%
Taylor expanded in x around inf 97.9%
*-commutative97.9%
Simplified97.9%
times-frac97.9%
*-un-lft-identity97.9%
inv-pow97.9%
sqrt-pow197.9%
metadata-eval97.9%
*-un-lft-identity97.9%
add-sqr-sqrt97.6%
times-frac97.6%
pow1/297.6%
pow-flip97.6%
metadata-eval97.6%
un-div-inv97.5%
pow1/297.5%
pow-flip97.4%
metadata-eval97.4%
cube-mult97.5%
pow-pow98.2%
metadata-eval98.2%
Applied egg-rr98.2%
*-lft-identity98.2%
*-commutative98.2%
associate-*l/98.2%
Simplified98.2%
Final simplification98.2%
(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 38.6%
Taylor expanded in x around inf 58.1%
pow158.1%
pow-flip59.7%
sqrt-pow198.1%
metadata-eval98.1%
metadata-eval98.1%
Applied egg-rr98.1%
unpow198.1%
Simplified98.1%
Final simplification98.1%
(FPCore (x) :precision binary64 0.0)
double code(double x) {
return 0.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.0d0
end function
public static double code(double x) {
return 0.0;
}
def code(x): return 0.0
function code(x) return 0.0 end
function tmp = code(x) tmp = 0.0; end
code[x_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 38.6%
add-cube-cbrt9.6%
associate-*l*9.6%
frac-2neg9.6%
metadata-eval9.6%
div-inv9.6%
distribute-neg-frac29.6%
prod-diff6.4%
Applied egg-rr6.4%
Simplified6.5%
Taylor expanded in x around inf 36.0%
distribute-rgt1-in36.0%
metadata-eval36.0%
mul0-lft36.0%
Simplified36.0%
Final simplification36.0%
(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 2024059
(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)))))