Average Error: 20.1 → 0.3
Time: 7.7s
Precision: binary64
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
\[\begin{array}{l} t_0 := \sqrt{1 + x}\\ \frac{\frac{1}{\mathsf{fma}\left(t_0, \sqrt{x}, x\right)}}{t_0} \end{array} \]
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (sqrt (+ 1.0 x)))) (/ (/ 1.0 (fma t_0 (sqrt x) x)) t_0)))
double code(double x) {
	return (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
}
double code(double x) {
	double t_0 = sqrt((1.0 + x));
	return (1.0 / fma(t_0, sqrt(x), x)) / t_0;
}
function code(x)
	return Float64(Float64(1.0 / sqrt(x)) - Float64(1.0 / sqrt(Float64(x + 1.0))))
end
function code(x)
	t_0 = sqrt(Float64(1.0 + x))
	return Float64(Float64(1.0 / fma(t_0, sqrt(x), x)) / t_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]
code[x_] := Block[{t$95$0 = N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]}, N[(N[(1.0 / N[(t$95$0 * N[Sqrt[x], $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision]]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\begin{array}{l}
t_0 := \sqrt{1 + x}\\
\frac{\frac{1}{\mathsf{fma}\left(t_0, \sqrt{x}, x\right)}}{t_0}
\end{array}

Error

Bits error versus x

Target

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

Derivation

  1. Initial program 20.1

    \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
  2. Applied frac-sub_binary6420.1

    \[\leadsto \color{blue}{\frac{1 \cdot \sqrt{x + 1} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{x + 1}}} \]
  3. Simplified20.1

    \[\leadsto \frac{\color{blue}{\sqrt{1 + x} - \sqrt{x}}}{\sqrt{x} \cdot \sqrt{x + 1}} \]
  4. Simplified20.1

    \[\leadsto \frac{\sqrt{1 + x} - \sqrt{x}}{\color{blue}{\sqrt{x} \cdot \sqrt{1 + x}}} \]
  5. Applied flip--_binary6419.9

    \[\leadsto \frac{\color{blue}{\frac{\sqrt{1 + x} \cdot \sqrt{1 + x} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{1 + x} + \sqrt{x}}}}{\sqrt{x} \cdot \sqrt{1 + x}} \]
  6. Simplified0.4

    \[\leadsto \frac{\frac{\color{blue}{1}}{\sqrt{1 + x} + \sqrt{x}}}{\sqrt{x} \cdot \sqrt{1 + x}} \]
  7. Applied associate-/r*_binary640.4

    \[\leadsto \color{blue}{\frac{\frac{\frac{1}{\sqrt{1 + x} + \sqrt{x}}}{\sqrt{x}}}{\sqrt{1 + x}}} \]
  8. Simplified0.3

    \[\leadsto \frac{\color{blue}{\frac{1}{\mathsf{fma}\left(\sqrt{1 + x}, \sqrt{x}, x\right)}}}{\sqrt{1 + x}} \]
  9. Final simplification0.3

    \[\leadsto \frac{\frac{1}{\mathsf{fma}\left(\sqrt{1 + x}, \sqrt{x}, x\right)}}{\sqrt{1 + x}} \]

Reproduce

herbie shell --seed 2022131 
(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)))))