
(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 (/ (+ (* (pow x -0.5) 0.5) (/ -0.375 (pow x 1.5))) x))
double code(double x) {
return ((pow(x, -0.5) * 0.5) + (-0.375 / pow(x, 1.5))) / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (((x ** (-0.5d0)) * 0.5d0) + ((-0.375d0) / (x ** 1.5d0))) / x
end function
public static double code(double x) {
return ((Math.pow(x, -0.5) * 0.5) + (-0.375 / Math.pow(x, 1.5))) / x;
}
def code(x): return ((math.pow(x, -0.5) * 0.5) + (-0.375 / math.pow(x, 1.5))) / x
function code(x) return Float64(Float64(Float64((x ^ -0.5) * 0.5) + Float64(-0.375 / (x ^ 1.5))) / x) end
function tmp = code(x) tmp = (((x ^ -0.5) * 0.5) + (-0.375 / (x ^ 1.5))) / x; end
code[x_] := N[(N[(N[(N[Power[x, -0.5], $MachinePrecision] * 0.5), $MachinePrecision] + N[(-0.375 / N[Power[x, 1.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{{x}^{-0.5} \cdot 0.5 + \frac{-0.375}{{x}^{1.5}}}{x}
\end{array}
Initial program 35.8%
Taylor expanded in x around inf
Simplified84.1%
Taylor expanded in x around inf
/-lowering-/.f64N/A
Simplified98.8%
*-commutativeN/A
*-lowering-*.f64N/A
inv-powN/A
sqrt-pow1N/A
metadata-evalN/A
pow-lowering-pow.f6498.8%
Applied egg-rr98.8%
*-commutativeN/A
sqrt-divN/A
metadata-evalN/A
un-div-invN/A
/-lowering-/.f64N/A
cube-unmultN/A
sqrt-pow1N/A
pow-lowering-pow.f64N/A
metadata-eval98.8%
Applied egg-rr98.8%
(FPCore (x) :precision binary64 (/ (+ (/ -0.375 (pow x 1.5)) (/ 0.5 (sqrt x))) x))
double code(double x) {
return ((-0.375 / pow(x, 1.5)) + (0.5 / sqrt(x))) / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (((-0.375d0) / (x ** 1.5d0)) + (0.5d0 / sqrt(x))) / x
end function
public static double code(double x) {
return ((-0.375 / Math.pow(x, 1.5)) + (0.5 / Math.sqrt(x))) / x;
}
def code(x): return ((-0.375 / math.pow(x, 1.5)) + (0.5 / math.sqrt(x))) / x
function code(x) return Float64(Float64(Float64(-0.375 / (x ^ 1.5)) + Float64(0.5 / sqrt(x))) / x) end
function tmp = code(x) tmp = ((-0.375 / (x ^ 1.5)) + (0.5 / sqrt(x))) / x; end
code[x_] := N[(N[(N[(-0.375 / N[Power[x, 1.5], $MachinePrecision]), $MachinePrecision] + N[(0.5 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{-0.375}{{x}^{1.5}} + \frac{0.5}{\sqrt{x}}}{x}
\end{array}
Initial program 35.8%
Taylor expanded in x around inf
Simplified84.1%
Taylor expanded in x around inf
/-lowering-/.f64N/A
Simplified98.8%
/-lowering-/.f64N/A
+-lowering-+.f64N/A
sqrt-divN/A
metadata-evalN/A
un-div-invN/A
/-lowering-/.f64N/A
sqrt-lowering-sqrt.f64N/A
*-commutativeN/A
sqrt-divN/A
metadata-evalN/A
un-div-invN/A
/-lowering-/.f64N/A
cube-unmultN/A
sqrt-pow1N/A
metadata-evalN/A
metadata-evalN/A
pow-lowering-pow.f64N/A
metadata-eval98.7%
Applied egg-rr98.7%
Final simplification98.7%
(FPCore (x) :precision binary64 (* (/ -0.5 x) (* (- 1.0 x) (pow x -1.5))))
double code(double x) {
return (-0.5 / x) * ((1.0 - x) * pow(x, -1.5));
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((-0.5d0) / x) * ((1.0d0 - x) * (x ** (-1.5d0)))
end function
public static double code(double x) {
return (-0.5 / x) * ((1.0 - x) * Math.pow(x, -1.5));
}
def code(x): return (-0.5 / x) * ((1.0 - x) * math.pow(x, -1.5))
function code(x) return Float64(Float64(-0.5 / x) * Float64(Float64(1.0 - x) * (x ^ -1.5))) end
function tmp = code(x) tmp = (-0.5 / x) * ((1.0 - x) * (x ^ -1.5)); end
code[x_] := N[(N[(-0.5 / x), $MachinePrecision] * N[(N[(1.0 - x), $MachinePrecision] * N[Power[x, -1.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-0.5}{x} \cdot \left(\left(1 - x\right) \cdot {x}^{-1.5}\right)
\end{array}
Initial program 35.8%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-commutativeN/A
associate-/l*N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
/-lowering-/.f64N/A
sqrt-lowering-sqrt.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6483.2%
Simplified83.2%
associate-*r/N/A
*-commutativeN/A
clear-numN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
sqrt-divN/A
metadata-evalN/A
/-rgt-identityN/A
frac-subN/A
metadata-evalN/A
rem-square-sqrtN/A
metadata-evalN/A
div-invN/A
/-rgt-identityN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f6483.2%
Applied egg-rr83.2%
inv-powN/A
times-fracN/A
unpow-prod-downN/A
inv-powN/A
clear-numN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
div-invN/A
clear-numN/A
unpow-prod-downN/A
inv-powN/A
inv-powN/A
clear-numN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f6497.7%
Applied egg-rr97.7%
*-commutativeN/A
clear-numN/A
associate-/r/N/A
pow1/2N/A
pow-flipN/A
metadata-evalN/A
*-commutativeN/A
associate-*l*N/A
inv-powN/A
pow-prod-upN/A
metadata-evalN/A
metadata-evalN/A
pow-powN/A
cube-unmultN/A
metadata-evalN/A
sqrt-pow1N/A
inv-powN/A
*-lowering-*.f64N/A
--lowering--.f64N/A
inv-powN/A
sqrt-pow1N/A
cube-unmultN/A
metadata-evalN/A
Applied egg-rr98.1%
(FPCore (x) :precision binary64 (* (/ -0.5 x) (- (/ 0.0 x) (pow x -0.5))))
double code(double x) {
return (-0.5 / x) * ((0.0 / x) - pow(x, -0.5));
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((-0.5d0) / x) * ((0.0d0 / x) - (x ** (-0.5d0)))
end function
public static double code(double x) {
return (-0.5 / x) * ((0.0 / x) - Math.pow(x, -0.5));
}
def code(x): return (-0.5 / x) * ((0.0 / x) - math.pow(x, -0.5))
function code(x) return Float64(Float64(-0.5 / x) * Float64(Float64(0.0 / x) - (x ^ -0.5))) end
function tmp = code(x) tmp = (-0.5 / x) * ((0.0 / x) - (x ^ -0.5)); end
code[x_] := N[(N[(-0.5 / x), $MachinePrecision] * N[(N[(0.0 / x), $MachinePrecision] - N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-0.5}{x} \cdot \left(\frac{0}{x} - {x}^{-0.5}\right)
\end{array}
Initial program 35.8%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-commutativeN/A
associate-/l*N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
/-lowering-/.f64N/A
sqrt-lowering-sqrt.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6483.2%
Simplified83.2%
Taylor expanded in x around inf
mul-1-negN/A
neg-sub0N/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f6483.1%
Simplified83.1%
sub0-negN/A
associate-*r/N/A
times-fracN/A
*-lowering-*.f64N/A
Applied egg-rr97.9%
Final simplification97.9%
(FPCore (x) :precision binary64 (/ (/ (* -0.5 (sqrt x)) x) (- 0.0 x)))
double code(double x) {
return ((-0.5 * sqrt(x)) / x) / (0.0 - x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (((-0.5d0) * sqrt(x)) / x) / (0.0d0 - x)
end function
public static double code(double x) {
return ((-0.5 * Math.sqrt(x)) / x) / (0.0 - x);
}
def code(x): return ((-0.5 * math.sqrt(x)) / x) / (0.0 - x)
function code(x) return Float64(Float64(Float64(-0.5 * sqrt(x)) / x) / Float64(0.0 - x)) end
function tmp = code(x) tmp = ((-0.5 * sqrt(x)) / x) / (0.0 - x); end
code[x_] := N[(N[(N[(-0.5 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] / N[(0.0 - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{-0.5 \cdot \sqrt{x}}{x}}{0 - x}
\end{array}
Initial program 35.8%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-commutativeN/A
associate-/l*N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
/-lowering-/.f64N/A
sqrt-lowering-sqrt.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6483.2%
Simplified83.2%
Taylor expanded in x around inf
mul-1-negN/A
neg-sub0N/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f6483.1%
Simplified83.1%
sub0-negN/A
associate-*r/N/A
associate-/r*N/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
distribute-lft-neg-outN/A
neg-lowering-neg.f64N/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f6497.9%
Applied egg-rr97.9%
Final simplification97.9%
(FPCore (x) :precision binary64 (/ (* 0.5 (sqrt (/ 1.0 x))) x))
double code(double x) {
return (0.5 * sqrt((1.0 / x))) / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (0.5d0 * sqrt((1.0d0 / x))) / x
end function
public static double code(double x) {
return (0.5 * Math.sqrt((1.0 / x))) / x;
}
def code(x): return (0.5 * math.sqrt((1.0 / x))) / x
function code(x) return Float64(Float64(0.5 * sqrt(Float64(1.0 / x))) / x) end
function tmp = code(x) tmp = (0.5 * sqrt((1.0 / x))) / x; end
code[x_] := N[(N[(0.5 * N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5 \cdot \sqrt{\frac{1}{x}}}{x}
\end{array}
Initial program 35.8%
Taylor expanded in x around inf
Simplified84.1%
Taylor expanded in x around inf
/-lowering-/.f64N/A
Simplified98.8%
Taylor expanded in x around inf
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
/-lowering-/.f6497.9%
Simplified97.9%
(FPCore (x) :precision binary64 (* (/ (sqrt x) x) (/ 0.5 x)))
double code(double x) {
return (sqrt(x) / x) * (0.5 / x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (sqrt(x) / x) * (0.5d0 / x)
end function
public static double code(double x) {
return (Math.sqrt(x) / x) * (0.5 / x);
}
def code(x): return (math.sqrt(x) / x) * (0.5 / x)
function code(x) return Float64(Float64(sqrt(x) / x) * Float64(0.5 / x)) end
function tmp = code(x) tmp = (sqrt(x) / x) * (0.5 / x); end
code[x_] := N[(N[(N[Sqrt[x], $MachinePrecision] / x), $MachinePrecision] * N[(0.5 / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{x}}{x} \cdot \frac{0.5}{x}
\end{array}
Initial program 35.8%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-commutativeN/A
associate-/l*N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
/-lowering-/.f64N/A
sqrt-lowering-sqrt.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6483.2%
Simplified83.2%
Taylor expanded in x around inf
mul-1-negN/A
neg-sub0N/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f6483.1%
Simplified83.1%
sub0-negN/A
associate-*r/N/A
associate-/r*N/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
distribute-lft-neg-outN/A
neg-lowering-neg.f64N/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f6497.9%
Applied egg-rr97.9%
associate-/l/N/A
distribute-rgt-neg-inN/A
metadata-evalN/A
times-fracN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
sqrt-lowering-sqrt.f64N/A
/-lowering-/.f6497.9%
Applied egg-rr97.9%
(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 35.8%
Taylor expanded in x around inf
sqrt-lowering-sqrt.f64N/A
/-lowering-/.f6423.9%
Simplified23.9%
metadata-evalN/A
sqrt-divN/A
+-inverses33.4%
Applied egg-rr33.4%
(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 2024150
(FPCore (x)
:name "2isqrt (example 3.6)"
:precision binary64
:pre (and (> x 1.0) (< x 1e+308))
:alt
(! :herbie-platform default (/ 1 (+ (* (+ x 1) (sqrt x)) (* x (sqrt (+ x 1))))))
(- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))