
(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 10 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
(let* ((t_0 (sqrt (/ 1.0 (pow x 7.0)))))
(/
(fma
(pow x -1.5)
-0.3125
(fma
t_0
-0.1904296875
(+
(* t_0 -0.0830078125)
(+
(* (sqrt (/ 1.0 (pow x 5.0))) 0.3125)
(fma (sqrt (/ 1.0 (pow x 3.0))) -0.0625 (* 0.5 (pow x -0.5)))))))
x)))
double code(double x) {
double t_0 = sqrt((1.0 / pow(x, 7.0)));
return fma(pow(x, -1.5), -0.3125, fma(t_0, -0.1904296875, ((t_0 * -0.0830078125) + ((sqrt((1.0 / pow(x, 5.0))) * 0.3125) + fma(sqrt((1.0 / pow(x, 3.0))), -0.0625, (0.5 * pow(x, -0.5))))))) / x;
}
function code(x) t_0 = sqrt(Float64(1.0 / (x ^ 7.0))) return Float64(fma((x ^ -1.5), -0.3125, fma(t_0, -0.1904296875, Float64(Float64(t_0 * -0.0830078125) + Float64(Float64(sqrt(Float64(1.0 / (x ^ 5.0))) * 0.3125) + fma(sqrt(Float64(1.0 / (x ^ 3.0))), -0.0625, Float64(0.5 * (x ^ -0.5))))))) / x) end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(1.0 / N[Power[x, 7.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, N[(N[(N[Power[x, -1.5], $MachinePrecision] * -0.3125 + N[(t$95$0 * -0.1904296875 + N[(N[(t$95$0 * -0.0830078125), $MachinePrecision] + N[(N[(N[Sqrt[N[(1.0 / N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 0.3125), $MachinePrecision] + N[(N[Sqrt[N[(1.0 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * -0.0625 + N[(0.5 * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\frac{1}{{x}^{7}}}\\
\frac{\mathsf{fma}\left({x}^{-1.5}, -0.3125, \mathsf{fma}\left(t\_0, -0.1904296875, t\_0 \cdot -0.0830078125 + \left(\sqrt{\frac{1}{{x}^{5}}} \cdot 0.3125 + \mathsf{fma}\left(\sqrt{\frac{1}{{x}^{3}}}, -0.0625, 0.5 \cdot {x}^{-0.5}\right)\right)\right)\right)}{x}
\end{array}
\end{array}
Initial program 37.6%
frac-2neg37.6%
metadata-eval37.6%
div-inv37.6%
frac-2neg37.6%
metadata-eval37.6%
div-inv37.6%
distribute-neg-frac237.6%
prod-diff37.6%
distribute-neg-frac37.6%
metadata-eval37.6%
+-commutative37.6%
Applied egg-rr31.2%
Simplified31.2%
inv-pow31.6%
sqrt-pow237.7%
metadata-eval37.7%
metadata-eval37.7%
pow-pow22.2%
sqr-pow19.1%
sqr-pow27.1%
difference-of-squares27.0%
metadata-eval27.0%
pow-pow27.0%
metadata-eval27.0%
metadata-eval27.0%
metadata-eval27.0%
pow-pow37.6%
metadata-eval37.6%
metadata-eval37.6%
Applied egg-rr37.6%
Taylor expanded in x around inf 99.1%
Simplified99.1%
*-un-lft-identity99.1%
pow-flip99.1%
sqrt-pow199.1%
metadata-eval99.1%
metadata-eval99.1%
Applied egg-rr99.1%
*-lft-identity99.1%
Simplified99.1%
Final simplification99.1%
(FPCore (x) :precision binary64 (/ (+ (+ (* (sqrt (/ 1.0 (pow x 5.0))) 0.3125) (* 0.5 (pow x -0.5))) (* (sqrt (/ 1.0 (pow x 3.0))) -0.375)) x))
double code(double x) {
return (((sqrt((1.0 / pow(x, 5.0))) * 0.3125) + (0.5 * pow(x, -0.5))) + (sqrt((1.0 / pow(x, 3.0))) * -0.375)) / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (((sqrt((1.0d0 / (x ** 5.0d0))) * 0.3125d0) + (0.5d0 * (x ** (-0.5d0)))) + (sqrt((1.0d0 / (x ** 3.0d0))) * (-0.375d0))) / x
end function
public static double code(double x) {
return (((Math.sqrt((1.0 / Math.pow(x, 5.0))) * 0.3125) + (0.5 * Math.pow(x, -0.5))) + (Math.sqrt((1.0 / Math.pow(x, 3.0))) * -0.375)) / x;
}
def code(x): return (((math.sqrt((1.0 / math.pow(x, 5.0))) * 0.3125) + (0.5 * math.pow(x, -0.5))) + (math.sqrt((1.0 / math.pow(x, 3.0))) * -0.375)) / x
function code(x) return Float64(Float64(Float64(Float64(sqrt(Float64(1.0 / (x ^ 5.0))) * 0.3125) + Float64(0.5 * (x ^ -0.5))) + Float64(sqrt(Float64(1.0 / (x ^ 3.0))) * -0.375)) / x) end
function tmp = code(x) tmp = (((sqrt((1.0 / (x ^ 5.0))) * 0.3125) + (0.5 * (x ^ -0.5))) + (sqrt((1.0 / (x ^ 3.0))) * -0.375)) / x; end
code[x_] := N[(N[(N[(N[(N[Sqrt[N[(1.0 / N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 0.3125), $MachinePrecision] + N[(0.5 * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[N[(1.0 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * -0.375), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(\sqrt{\frac{1}{{x}^{5}}} \cdot 0.3125 + 0.5 \cdot {x}^{-0.5}\right) + \sqrt{\frac{1}{{x}^{3}}} \cdot -0.375}{x}
\end{array}
Initial program 37.6%
frac-2neg37.6%
metadata-eval37.6%
div-inv37.6%
frac-2neg37.6%
metadata-eval37.6%
div-inv37.6%
distribute-neg-frac237.6%
prod-diff37.6%
distribute-neg-frac37.6%
metadata-eval37.6%
+-commutative37.6%
Applied egg-rr31.2%
Simplified31.2%
inv-pow31.6%
sqrt-pow237.7%
metadata-eval37.7%
metadata-eval37.7%
pow-pow22.2%
sqr-pow19.1%
sqr-pow27.1%
difference-of-squares27.0%
metadata-eval27.0%
pow-pow27.0%
metadata-eval27.0%
metadata-eval27.0%
metadata-eval27.0%
pow-pow37.6%
metadata-eval37.6%
metadata-eval37.6%
Applied egg-rr37.6%
Taylor expanded in x around inf 98.9%
Simplified98.9%
Final simplification98.9%
(FPCore (x) :precision binary64 (/ (- (* 0.5 (pow x -0.5)) (* (pow x -0.5) (/ 0.375 x))) x))
double code(double x) {
return ((0.5 * pow(x, -0.5)) - (pow(x, -0.5) * (0.375 / x))) / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((0.5d0 * (x ** (-0.5d0))) - ((x ** (-0.5d0)) * (0.375d0 / x))) / x
end function
public static double code(double x) {
return ((0.5 * Math.pow(x, -0.5)) - (Math.pow(x, -0.5) * (0.375 / x))) / x;
}
def code(x): return ((0.5 * math.pow(x, -0.5)) - (math.pow(x, -0.5) * (0.375 / x))) / x
function code(x) return Float64(Float64(Float64(0.5 * (x ^ -0.5)) - Float64((x ^ -0.5) * Float64(0.375 / x))) / x) end
function tmp = code(x) tmp = ((0.5 * (x ^ -0.5)) - ((x ^ -0.5) * (0.375 / x))) / x; end
code[x_] := N[(N[(N[(0.5 * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision] - N[(N[Power[x, -0.5], $MachinePrecision] * N[(0.375 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5 \cdot {x}^{-0.5} - {x}^{-0.5} \cdot \frac{0.375}{x}}{x}
\end{array}
Initial program 37.6%
Taylor expanded in x around inf 80.2%
*-un-lft-identity80.2%
pow1/280.2%
pow-flip80.2%
pow-pow80.2%
metadata-eval80.2%
metadata-eval80.2%
Applied egg-rr80.2%
*-lft-identity80.2%
Simplified80.2%
Taylor expanded in x around inf 98.5%
Simplified98.5%
Final simplification98.5%
(FPCore (x) :precision binary64 (* (/ (- (pow x -0.5) (sqrt x)) x) (/ -0.5 x)))
double code(double x) {
return ((pow(x, -0.5) - sqrt(x)) / x) * (-0.5 / x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (((x ** (-0.5d0)) - sqrt(x)) / x) * ((-0.5d0) / x)
end function
public static double code(double x) {
return ((Math.pow(x, -0.5) - Math.sqrt(x)) / x) * (-0.5 / x);
}
def code(x): return ((math.pow(x, -0.5) - math.sqrt(x)) / x) * (-0.5 / x)
function code(x) return Float64(Float64(Float64((x ^ -0.5) - sqrt(x)) / x) * Float64(-0.5 / x)) end
function tmp = code(x) tmp = (((x ^ -0.5) - sqrt(x)) / x) * (-0.5 / x); end
code[x_] := N[(N[(N[(N[Power[x, -0.5], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] * N[(-0.5 / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{x}^{-0.5} - \sqrt{x}}{x} \cdot \frac{-0.5}{x}
\end{array}
Initial program 37.6%
Taylor expanded in x around inf 78.5%
distribute-lft-out--78.5%
Simplified78.5%
*-commutative78.5%
unpow278.5%
times-frac96.8%
inv-pow96.8%
sqrt-pow196.8%
metadata-eval96.8%
Applied egg-rr96.8%
Final simplification96.8%
(FPCore (x) :precision binary64 (/ (* -0.5 (- (sqrt x))) (pow x 2.0)))
double code(double x) {
return (-0.5 * -sqrt(x)) / pow(x, 2.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((-0.5d0) * -sqrt(x)) / (x ** 2.0d0)
end function
public static double code(double x) {
return (-0.5 * -Math.sqrt(x)) / Math.pow(x, 2.0);
}
def code(x): return (-0.5 * -math.sqrt(x)) / math.pow(x, 2.0)
function code(x) return Float64(Float64(-0.5 * Float64(-sqrt(x))) / (x ^ 2.0)) end
function tmp = code(x) tmp = (-0.5 * -sqrt(x)) / (x ^ 2.0); end
code[x_] := N[(N[(-0.5 * (-N[Sqrt[x], $MachinePrecision])), $MachinePrecision] / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-0.5 \cdot \left(-\sqrt{x}\right)}{{x}^{2}}
\end{array}
Initial program 37.6%
Taylor expanded in x around inf 78.5%
distribute-lft-out--78.5%
Simplified78.5%
Taylor expanded in x around inf 78.4%
neg-mul-178.4%
Simplified78.4%
Final simplification78.4%
(FPCore (x) :precision binary64 (cbrt (* 0.125 (pow x -4.5))))
double code(double x) {
return cbrt((0.125 * pow(x, -4.5)));
}
public static double code(double x) {
return Math.cbrt((0.125 * Math.pow(x, -4.5)));
}
function code(x) return cbrt(Float64(0.125 * (x ^ -4.5))) end
code[x_] := N[Power[N[(0.125 * N[Power[x, -4.5], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{0.125 \cdot {x}^{-4.5}}
\end{array}
Initial program 37.6%
add-cbrt-cube37.6%
pow337.6%
inv-pow37.6%
sqrt-pow237.6%
metadata-eval37.6%
pow1/237.6%
pow-flip37.7%
+-commutative37.7%
metadata-eval37.7%
Applied egg-rr37.7%
Taylor expanded in x around inf 42.2%
*-un-lft-identity42.2%
pow1/242.2%
pow-flip42.2%
pow-pow52.8%
metadata-eval52.8%
metadata-eval52.8%
Applied egg-rr52.8%
*-lft-identity52.8%
Simplified52.8%
Final simplification52.8%
(FPCore (x) :precision binary64 (* 0.5 (sqrt (pow x -3.0))))
double code(double x) {
return 0.5 * sqrt(pow(x, -3.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.5d0 * sqrt((x ** (-3.0d0)))
end function
public static double code(double x) {
return 0.5 * Math.sqrt(Math.pow(x, -3.0));
}
def code(x): return 0.5 * math.sqrt(math.pow(x, -3.0))
function code(x) return Float64(0.5 * sqrt((x ^ -3.0))) end
function tmp = code(x) tmp = 0.5 * sqrt((x ^ -3.0)); end
code[x_] := N[(0.5 * N[Sqrt[N[Power[x, -3.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{{x}^{-3}}
\end{array}
Initial program 37.6%
Taylor expanded in x around inf 78.5%
distribute-lft-out--78.5%
Simplified78.5%
Taylor expanded in x around inf 62.0%
exp-to-pow59.8%
*-commutative59.8%
rec-exp61.9%
distribute-lft-neg-in61.9%
metadata-eval61.9%
*-commutative61.9%
exp-to-pow64.1%
Simplified64.1%
Final simplification64.1%
(FPCore (x) :precision binary64 (pow (pow x 2.0) -0.25))
double code(double x) {
return pow(pow(x, 2.0), -0.25);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x ** 2.0d0) ** (-0.25d0)
end function
public static double code(double x) {
return Math.pow(Math.pow(x, 2.0), -0.25);
}
def code(x): return math.pow(math.pow(x, 2.0), -0.25)
function code(x) return (x ^ 2.0) ^ -0.25 end
function tmp = code(x) tmp = (x ^ 2.0) ^ -0.25; end
code[x_] := N[Power[N[Power[x, 2.0], $MachinePrecision], -0.25], $MachinePrecision]
\begin{array}{l}
\\
{\left({x}^{2}\right)}^{-0.25}
\end{array}
Initial program 37.6%
Taylor expanded in x around 0 5.7%
inv-pow5.7%
sqrt-pow15.7%
metadata-eval5.7%
sqr-pow5.7%
pow-prod-down34.8%
pow234.8%
metadata-eval34.8%
Applied egg-rr34.8%
Final simplification34.8%
(FPCore (x) :precision binary64 (cbrt (pow x -1.5)))
double code(double x) {
return cbrt(pow(x, -1.5));
}
public static double code(double x) {
return Math.cbrt(Math.pow(x, -1.5));
}
function code(x) return cbrt((x ^ -1.5)) end
code[x_] := N[Power[N[Power[x, -1.5], $MachinePrecision], 1/3], $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{{x}^{-1.5}}
\end{array}
Initial program 37.6%
Taylor expanded in x around 0 5.7%
add-cbrt-cube32.2%
pow1/332.2%
add-sqr-sqrt32.2%
pow132.2%
pow1/232.2%
pow-prod-up32.2%
metadata-eval32.2%
metadata-eval32.2%
pow-pow32.2%
inv-pow32.2%
pow-pow32.2%
metadata-eval32.2%
pow-pow32.2%
metadata-eval32.2%
Applied egg-rr32.2%
unpow1/332.2%
Simplified32.2%
Final simplification32.2%
(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 37.6%
Taylor expanded in x around 0 5.7%
inv-pow5.7%
sqrt-pow15.7%
metadata-eval5.7%
*-un-lft-identity5.7%
Applied egg-rr5.7%
*-lft-identity5.7%
Simplified5.7%
Final simplification5.7%
(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 2024076
(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)))))