Average Error: 19.8 → 5.4
Time: 3.3s
Precision: binary64
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
\[\frac{-1}{\left(-\sqrt{x + 1}\right) - \sqrt{x}} \cdot \frac{1}{\sqrt{x \cdot \left(x + 1\right)}} \]
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
(FPCore (x)
 :precision binary64
 (* (/ -1.0 (- (- (sqrt (+ x 1.0))) (sqrt x))) (/ 1.0 (sqrt (* x (+ x 1.0))))))
double code(double x) {
	return (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 / sqrt((x * (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
real(8) function code(x)
    real(8), intent (in) :: x
    code = ((-1.0d0) / (-sqrt((x + 1.0d0)) - sqrt(x))) * (1.0d0 / sqrt((x * (x + 1.0d0))))
end function
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.sqrt((x + 1.0)) - Math.sqrt(x))) * (1.0 / Math.sqrt((x * (x + 1.0))));
}
def code(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 / math.sqrt((x * (x + 1.0))))
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 / Float64(Float64(-sqrt(Float64(x + 1.0))) - sqrt(x))) * Float64(1.0 / sqrt(Float64(x * Float64(x + 1.0)))))
end
function tmp = code(x)
	tmp = (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
end
function tmp = code(x)
	tmp = (-1.0 / (-sqrt((x + 1.0)) - sqrt(x))) * (1.0 / sqrt((x * (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]
code[x_] := N[(N[(-1.0 / N[((-N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]) - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[Sqrt[N[(x * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\frac{-1}{\left(-\sqrt{x + 1}\right) - \sqrt{x}} \cdot \frac{1}{\sqrt{x \cdot \left(x + 1\right)}}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original19.8
Target0.7
Herbie5.4
\[\frac{1}{\left(x + 1\right) \cdot \sqrt{x} + x \cdot \sqrt{x + 1}} \]

Derivation

  1. Initial program 19.8

    \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
  2. Simplified19.8

    \[\leadsto \color{blue}{\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{1 + x}}} \]
  3. Applied egg-rr19.8

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

    \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\sqrt{x} \cdot -1, \sqrt{x} \cdot -1, -\left(x + 1\right)\right)}{\sqrt{x} \cdot -1 - \sqrt{x + 1}}} \cdot \frac{1}{\sqrt{x \cdot \left(1 + x\right)}} \]
  5. Taylor expanded in x around 0 5.4

    \[\leadsto \frac{\color{blue}{-1}}{\sqrt{x} \cdot -1 - \sqrt{x + 1}} \cdot \frac{1}{\sqrt{x \cdot \left(1 + x\right)}} \]
  6. Final simplification5.4

    \[\leadsto \frac{-1}{\left(-\sqrt{x + 1}\right) - \sqrt{x}} \cdot \frac{1}{\sqrt{x \cdot \left(x + 1\right)}} \]

Reproduce

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