Average Error: 19.9 → 0.3
Time: 4.3s
Precision: binary64
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
\[\frac{1}{\mathsf{hypot}\left(x, \sqrt{x}\right)} \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{\sqrt{x} + \sqrt{1 + x}}\right)\right) \]
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
(FPCore (x)
 :precision binary64
 (*
  (/ 1.0 (hypot x (sqrt x)))
  (expm1 (log1p (/ 1.0 (+ (sqrt x) (sqrt (+ 1.0 x))))))))
double code(double x) {
	return (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
}
double code(double x) {
	return (1.0 / hypot(x, sqrt(x))) * expm1(log1p((1.0 / (sqrt(x) + sqrt((1.0 + x))))));
}
public static double code(double x) {
	return (1.0 / Math.sqrt(x)) - (1.0 / Math.sqrt((x + 1.0)));
}
public static double code(double x) {
	return (1.0 / Math.hypot(x, Math.sqrt(x))) * Math.expm1(Math.log1p((1.0 / (Math.sqrt(x) + Math.sqrt((1.0 + x))))));
}
def code(x):
	return (1.0 / math.sqrt(x)) - (1.0 / math.sqrt((x + 1.0)))
def code(x):
	return (1.0 / math.hypot(x, math.sqrt(x))) * math.expm1(math.log1p((1.0 / (math.sqrt(x) + math.sqrt((1.0 + x))))))
function code(x)
	return Float64(Float64(1.0 / sqrt(x)) - Float64(1.0 / sqrt(Float64(x + 1.0))))
end
function code(x)
	return Float64(Float64(1.0 / hypot(x, sqrt(x))) * expm1(log1p(Float64(1.0 / Float64(sqrt(x) + sqrt(Float64(1.0 + x)))))))
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]
code[x_] := N[(N[(1.0 / N[Sqrt[x ^ 2 + N[Sqrt[x], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[(Exp[N[Log[1 + N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\frac{1}{\mathsf{hypot}\left(x, \sqrt{x}\right)} \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{\sqrt{x} + \sqrt{1 + x}}\right)\right)

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original19.9
Target0.6
Herbie0.3
\[\frac{1}{\left(x + 1\right) \cdot \sqrt{x} + x \cdot \sqrt{x + 1}} \]

Derivation

  1. Initial program 19.9

    \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
  2. Applied egg-rr19.9

    \[\leadsto \color{blue}{\frac{1}{\frac{\sqrt{x \cdot \left(1 + x\right)}}{\sqrt{1 + x} - \sqrt{x}}}} \]
  3. Applied egg-rr0.6

    \[\leadsto \frac{1}{\color{blue}{\frac{\mathsf{hypot}\left(x, \sqrt{x}\right)}{1 + \left(x - x\right)} \cdot \left(\sqrt{x + 1} + \sqrt{x}\right)}} \]
  4. Applied egg-rr0.3

    \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(x, \sqrt{x}\right)} \cdot {\left(\sqrt{x} + \sqrt{1 + x}\right)}^{-1}} \]
  5. Applied egg-rr0.3

    \[\leadsto \frac{1}{\mathsf{hypot}\left(x, \sqrt{x}\right)} \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{\sqrt{x} + \sqrt{x + 1}}\right)\right)} \]
  6. Final simplification0.3

    \[\leadsto \frac{1}{\mathsf{hypot}\left(x, \sqrt{x}\right)} \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{\sqrt{x} + \sqrt{1 + x}}\right)\right) \]

Reproduce

herbie shell --seed 2022153 
(FPCore (x)
  :name "2isqrt (example 3.6)"
  :precision binary64

  :herbie-target
  (/ 1.0 (+ (* (+ x 1.0) (sqrt x)) (* x (sqrt (+ x 1.0)))))

  (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))