
(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 7 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) (pow (+ 1.0 x) -0.5)))))
double code(double x) {
return (1.0 / x) / ((1.0 + x) * (pow(x, -0.5) + pow((1.0 + x), -0.5)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / x) / ((1.0d0 + x) * ((x ** (-0.5d0)) + ((1.0d0 + x) ** (-0.5d0))))
end function
public static double code(double x) {
return (1.0 / x) / ((1.0 + x) * (Math.pow(x, -0.5) + Math.pow((1.0 + x), -0.5)));
}
def code(x): return (1.0 / x) / ((1.0 + x) * (math.pow(x, -0.5) + math.pow((1.0 + x), -0.5)))
function code(x) return Float64(Float64(1.0 / x) / Float64(Float64(1.0 + x) * Float64((x ^ -0.5) + (Float64(1.0 + x) ^ -0.5)))) end
function tmp = code(x) tmp = (1.0 / x) / ((1.0 + x) * ((x ^ -0.5) + ((1.0 + x) ^ -0.5))); end
code[x_] := N[(N[(1.0 / x), $MachinePrecision] / N[(N[(1.0 + x), $MachinePrecision] * N[(N[Power[x, -0.5], $MachinePrecision] + N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{x}}{\left(1 + x\right) \cdot \left({x}^{-0.5} + {\left(1 + x\right)}^{-0.5}\right)}
\end{array}
Initial program 35.6%
inv-powN/A
pow1/2N/A
pow-powN/A
pow-lowering-pow.f64N/A
metadata-eval27.7%
Applied egg-rr27.7%
pow1/2N/A
+-commutativeN/A
pow-flipN/A
metadata-evalN/A
flip--N/A
pow-prod-upN/A
metadata-evalN/A
inv-powN/A
sub-negN/A
mul-1-negN/A
pow-prod-upN/A
metadata-evalN/A
inv-powN/A
div-invN/A
/-lowering-/.f64N/A
Applied egg-rr80.4%
associate-/r*N/A
associate-/l/N/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
metadata-evalN/A
pow-powN/A
pow2N/A
+-lowering-+.f64N/A
pow-lowering-pow.f64N/A
unpow-prod-downN/A
pow-sqrN/A
metadata-evalN/A
pow-lowering-pow.f64N/A
+-lowering-+.f64N/A
+-lowering-+.f6499.5%
Applied egg-rr99.5%
Final simplification99.5%
(FPCore (x) :precision binary64 (/ (+ (* (pow x -1.5) -0.375) (* (pow x -0.5) 0.5)) x))
double code(double x) {
return ((pow(x, -1.5) * -0.375) + (pow(x, -0.5) * 0.5)) / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (((x ** (-1.5d0)) * (-0.375d0)) + ((x ** (-0.5d0)) * 0.5d0)) / x
end function
public static double code(double x) {
return ((Math.pow(x, -1.5) * -0.375) + (Math.pow(x, -0.5) * 0.5)) / x;
}
def code(x): return ((math.pow(x, -1.5) * -0.375) + (math.pow(x, -0.5) * 0.5)) / x
function code(x) return Float64(Float64(Float64((x ^ -1.5) * -0.375) + Float64((x ^ -0.5) * 0.5)) / x) end
function tmp = code(x) tmp = (((x ^ -1.5) * -0.375) + ((x ^ -0.5) * 0.5)) / x; end
code[x_] := N[(N[(N[(N[Power[x, -1.5], $MachinePrecision] * -0.375), $MachinePrecision] + N[(N[Power[x, -0.5], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{{x}^{-1.5} \cdot -0.375 + {x}^{-0.5} \cdot 0.5}{x}
\end{array}
Initial program 35.6%
Taylor expanded in x around inf
Simplified79.8%
Taylor expanded in x around inf
/-lowering-/.f64N/A
Simplified99.0%
+-commutativeN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
associate-/l/N/A
inv-powN/A
sqrt-pow1N/A
metadata-evalN/A
pow-prod-downN/A
pow-prod-downN/A
cube-multN/A
pow-powN/A
pow-lowering-pow.f64N/A
metadata-evalN/A
inv-powN/A
sqrt-pow1N/A
metadata-evalN/A
*-lowering-*.f64N/A
pow-lowering-pow.f6499.1%
Applied egg-rr99.1%
Final simplification99.1%
(FPCore (x) :precision binary64 (/ (/ (- 0.25 (/ 0.140625 (* x x))) x) (* (+ 0.5 (/ 0.375 x)) (sqrt x))))
double code(double x) {
return ((0.25 - (0.140625 / (x * x))) / x) / ((0.5 + (0.375 / x)) * sqrt(x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((0.25d0 - (0.140625d0 / (x * x))) / x) / ((0.5d0 + (0.375d0 / x)) * sqrt(x))
end function
public static double code(double x) {
return ((0.25 - (0.140625 / (x * x))) / x) / ((0.5 + (0.375 / x)) * Math.sqrt(x));
}
def code(x): return ((0.25 - (0.140625 / (x * x))) / x) / ((0.5 + (0.375 / x)) * math.sqrt(x))
function code(x) return Float64(Float64(Float64(0.25 - Float64(0.140625 / Float64(x * x))) / x) / Float64(Float64(0.5 + Float64(0.375 / x)) * sqrt(x))) end
function tmp = code(x) tmp = ((0.25 - (0.140625 / (x * x))) / x) / ((0.5 + (0.375 / x)) * sqrt(x)); end
code[x_] := N[(N[(N[(0.25 - N[(0.140625 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] / N[(N[(0.5 + N[(0.375 / x), $MachinePrecision]), $MachinePrecision] * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{0.25 - \frac{0.140625}{x \cdot x}}{x}}{\left(0.5 + \frac{0.375}{x}\right) \cdot \sqrt{x}}
\end{array}
Initial program 35.6%
Taylor expanded in x around inf
Simplified79.8%
Taylor expanded in x around inf
/-lowering-/.f64N/A
Simplified99.0%
Applied egg-rr98.7%
/-lowering-/.f64N/A
Applied egg-rr99.0%
(FPCore (x) :precision binary64 (/ (/ 1.0 (/ (/ (+ 0.5 (* -0.375 (/ -1.0 x))) (sqrt x)) (/ 0.25 x))) x))
double code(double x) {
return (1.0 / (((0.5 + (-0.375 * (-1.0 / x))) / sqrt(x)) / (0.25 / x))) / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / (((0.5d0 + ((-0.375d0) * ((-1.0d0) / x))) / sqrt(x)) / (0.25d0 / x))) / x
end function
public static double code(double x) {
return (1.0 / (((0.5 + (-0.375 * (-1.0 / x))) / Math.sqrt(x)) / (0.25 / x))) / x;
}
def code(x): return (1.0 / (((0.5 + (-0.375 * (-1.0 / x))) / math.sqrt(x)) / (0.25 / x))) / x
function code(x) return Float64(Float64(1.0 / Float64(Float64(Float64(0.5 + Float64(-0.375 * Float64(-1.0 / x))) / sqrt(x)) / Float64(0.25 / x))) / x) end
function tmp = code(x) tmp = (1.0 / (((0.5 + (-0.375 * (-1.0 / x))) / sqrt(x)) / (0.25 / x))) / x; end
code[x_] := N[(N[(1.0 / N[(N[(N[(0.5 + N[(-0.375 * N[(-1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] / N[(0.25 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{\frac{\frac{0.5 + -0.375 \cdot \frac{-1}{x}}{\sqrt{x}}}{\frac{0.25}{x}}}}{x}
\end{array}
Initial program 35.6%
Taylor expanded in x around inf
Simplified79.8%
Taylor expanded in x around inf
/-lowering-/.f64N/A
Simplified99.0%
Applied egg-rr98.8%
Taylor expanded in x around inf
/-lowering-/.f6498.9%
Simplified98.9%
Final simplification98.9%
(FPCore (x) :precision binary64 (/ (/ 0.25 x) (* x (/ (+ 0.5 (* -0.375 (/ -1.0 x))) (sqrt x)))))
double code(double x) {
return (0.25 / x) / (x * ((0.5 + (-0.375 * (-1.0 / x))) / sqrt(x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (0.25d0 / x) / (x * ((0.5d0 + ((-0.375d0) * ((-1.0d0) / x))) / sqrt(x)))
end function
public static double code(double x) {
return (0.25 / x) / (x * ((0.5 + (-0.375 * (-1.0 / x))) / Math.sqrt(x)));
}
def code(x): return (0.25 / x) / (x * ((0.5 + (-0.375 * (-1.0 / x))) / math.sqrt(x)))
function code(x) return Float64(Float64(0.25 / x) / Float64(x * Float64(Float64(0.5 + Float64(-0.375 * Float64(-1.0 / x))) / sqrt(x)))) end
function tmp = code(x) tmp = (0.25 / x) / (x * ((0.5 + (-0.375 * (-1.0 / x))) / sqrt(x))); end
code[x_] := N[(N[(0.25 / x), $MachinePrecision] / N[(x * N[(N[(0.5 + N[(-0.375 * N[(-1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{0.25}{x}}{x \cdot \frac{0.5 + -0.375 \cdot \frac{-1}{x}}{\sqrt{x}}}
\end{array}
Initial program 35.6%
Taylor expanded in x around inf
Simplified79.8%
Taylor expanded in x around inf
/-lowering-/.f64N/A
Simplified99.0%
Applied egg-rr98.7%
Taylor expanded in x around inf
/-lowering-/.f6498.9%
Simplified98.9%
Final simplification98.9%
(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 35.6%
Taylor expanded in x around inf
Simplified79.8%
Taylor expanded in x around inf
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
unpow3N/A
unpow2N/A
associate-/r*N/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6464.3%
Simplified64.3%
*-commutativeN/A
*-lowering-*.f64N/A
associate-/l/N/A
inv-powN/A
sqrt-pow1N/A
metadata-evalN/A
pow-prod-downN/A
pow-prod-downN/A
cube-multN/A
pow-powN/A
pow-lowering-pow.f64N/A
metadata-eval98.4%
Applied egg-rr98.4%
(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 35.6%
Taylor expanded in x around 0
sqrt-lowering-sqrt.f64N/A
/-lowering-/.f645.6%
Simplified5.6%
inv-powN/A
sqrt-pow1N/A
metadata-evalN/A
pow-lowering-pow.f645.6%
Applied egg-rr5.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 2024155
(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)))))