
(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 (* (+ 1.0 x) (pow x -0.5))) (* x (sqrt (+ 1.0 x))))))
double code(double x) {
return 1.0 / ((x * ((1.0 + x) * pow(x, -0.5))) + (x * sqrt((1.0 + x))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / ((x * ((1.0d0 + x) * (x ** (-0.5d0)))) + (x * sqrt((1.0d0 + x))))
end function
public static double code(double x) {
return 1.0 / ((x * ((1.0 + x) * Math.pow(x, -0.5))) + (x * Math.sqrt((1.0 + x))));
}
def code(x): return 1.0 / ((x * ((1.0 + x) * math.pow(x, -0.5))) + (x * math.sqrt((1.0 + x))))
function code(x) return Float64(1.0 / Float64(Float64(x * Float64(Float64(1.0 + x) * (x ^ -0.5))) + Float64(x * sqrt(Float64(1.0 + x))))) end
function tmp = code(x) tmp = 1.0 / ((x * ((1.0 + x) * (x ^ -0.5))) + (x * sqrt((1.0 + x)))); end
code[x_] := N[(1.0 / N[(N[(x * N[(N[(1.0 + x), $MachinePrecision] * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(x * N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x \cdot \left(\left(1 + x\right) \cdot {x}^{-0.5}\right) + x \cdot \sqrt{1 + x}}
\end{array}
Initial program 34.9%
sub-neg34.9%
inv-pow34.9%
sqrt-pow227.5%
metadata-eval27.5%
distribute-neg-frac27.5%
metadata-eval27.5%
+-commutative27.5%
Applied egg-rr27.5%
*-rgt-identity27.5%
cancel-sign-sub27.5%
distribute-lft-neg-in27.5%
*-rgt-identity27.5%
distribute-neg-frac27.5%
metadata-eval27.5%
unpow1/227.5%
exp-to-pow7.5%
log1p-undefine7.5%
*-commutative7.5%
exp-neg7.5%
*-commutative7.5%
distribute-rgt-neg-in7.5%
log1p-undefine7.5%
metadata-eval7.5%
exp-to-pow35.0%
Simplified35.0%
flip--35.0%
pow-prod-up22.3%
metadata-eval22.3%
inv-pow21.9%
pow-prod-up34.7%
metadata-eval34.7%
inv-pow35.1%
div-inv35.1%
frac-sub36.9%
frac-times36.9%
*-un-lft-identity36.9%
Applied egg-rr36.9%
*-rgt-identity36.9%
*-rgt-identity36.9%
associate--l+81.7%
+-inverses81.7%
metadata-eval81.7%
associate-*l*98.4%
Simplified98.4%
distribute-lft-in98.4%
pow198.4%
pow-prod-up98.4%
metadata-eval98.4%
pow1/298.4%
distribute-rgt-in98.4%
Applied egg-rr98.4%
Final simplification98.4%
(FPCore (x) :precision binary64 (/ 1.0 (* x (+ (* (+ 1.0 x) (pow x -0.5)) (sqrt (+ 1.0 x))))))
double code(double x) {
return 1.0 / (x * (((1.0 + x) * pow(x, -0.5)) + sqrt((1.0 + x))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (x * (((1.0d0 + x) * (x ** (-0.5d0))) + sqrt((1.0d0 + x))))
end function
public static double code(double x) {
return 1.0 / (x * (((1.0 + x) * Math.pow(x, -0.5)) + Math.sqrt((1.0 + x))));
}
def code(x): return 1.0 / (x * (((1.0 + x) * math.pow(x, -0.5)) + math.sqrt((1.0 + x))))
function code(x) return Float64(1.0 / Float64(x * Float64(Float64(Float64(1.0 + x) * (x ^ -0.5)) + sqrt(Float64(1.0 + x))))) end
function tmp = code(x) tmp = 1.0 / (x * (((1.0 + x) * (x ^ -0.5)) + sqrt((1.0 + x)))); end
code[x_] := N[(1.0 / N[(x * N[(N[(N[(1.0 + x), $MachinePrecision] * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision] + N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x \cdot \left(\left(1 + x\right) \cdot {x}^{-0.5} + \sqrt{1 + x}\right)}
\end{array}
Initial program 34.9%
sub-neg34.9%
inv-pow34.9%
sqrt-pow227.5%
metadata-eval27.5%
distribute-neg-frac27.5%
metadata-eval27.5%
+-commutative27.5%
Applied egg-rr27.5%
*-rgt-identity27.5%
cancel-sign-sub27.5%
distribute-lft-neg-in27.5%
*-rgt-identity27.5%
distribute-neg-frac27.5%
metadata-eval27.5%
unpow1/227.5%
exp-to-pow7.5%
log1p-undefine7.5%
*-commutative7.5%
exp-neg7.5%
*-commutative7.5%
distribute-rgt-neg-in7.5%
log1p-undefine7.5%
metadata-eval7.5%
exp-to-pow35.0%
Simplified35.0%
flip--35.0%
pow-prod-up22.3%
metadata-eval22.3%
inv-pow21.9%
pow-prod-up34.7%
metadata-eval34.7%
inv-pow35.1%
div-inv35.1%
frac-sub36.9%
frac-times36.9%
*-un-lft-identity36.9%
Applied egg-rr36.9%
*-rgt-identity36.9%
*-rgt-identity36.9%
associate--l+81.7%
+-inverses81.7%
metadata-eval81.7%
associate-*l*98.4%
Simplified98.4%
distribute-lft-in98.4%
pow198.4%
pow-prod-up98.4%
metadata-eval98.4%
pow1/298.4%
Applied egg-rr98.4%
(FPCore (x) :precision binary64 (* (pow x -1.5) 0.5))
double code(double x) {
return pow(x, -1.5) * 0.5;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x ** (-1.5d0)) * 0.5d0
end function
public static double code(double x) {
return Math.pow(x, -1.5) * 0.5;
}
def code(x): return math.pow(x, -1.5) * 0.5
function code(x) return Float64((x ^ -1.5) * 0.5) end
function tmp = code(x) tmp = (x ^ -1.5) * 0.5; end
code[x_] := N[(N[Power[x, -1.5], $MachinePrecision] * 0.5), $MachinePrecision]
\begin{array}{l}
\\
{x}^{-1.5} \cdot 0.5
\end{array}
Initial program 34.9%
add-cube-cbrt34.9%
pow334.9%
inv-pow34.9%
sqrt-pow227.5%
metadata-eval27.5%
inv-pow27.5%
sqrt-pow235.0%
+-commutative35.0%
metadata-eval35.0%
Applied egg-rr35.0%
Taylor expanded in x around inf 96.6%
unpow-prod-down96.7%
pow396.7%
add-sqr-sqrt96.7%
sqrt-div96.6%
metadata-eval96.6%
clear-num96.6%
frac-times95.5%
/-rgt-identity95.5%
add-sqr-sqrt95.5%
sqrt-unprod79.1%
sqrt-prod65.3%
unpow365.3%
metadata-eval65.3%
metadata-eval65.3%
sqrt-div65.3%
pow-flip65.8%
sqrt-pow196.5%
metadata-eval96.5%
metadata-eval96.5%
rem-cube-cbrt97.8%
Applied egg-rr97.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 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 34.9%
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%
(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 2024103
(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)))))