?

Average Error: 19.5 → 0.3
Time: 10.5s
Precision: binary64
Cost: 26240

?

\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
\[\frac{\frac{1}{\mathsf{hypot}\left(x, \sqrt{x}\right)}}{\sqrt{x} + \sqrt{1 + x}} \]
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
(FPCore (x)
 :precision binary64
 (/ (/ 1.0 (hypot x (sqrt x))) (+ (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))) / (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.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.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))) / Float64(sqrt(x) + sqrt(Float64(1.0 + x))))
end
function tmp = code(x)
	tmp = (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
end
function tmp = code(x)
	tmp = (1.0 / hypot(x, sqrt(x))) / (sqrt(x) + sqrt((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[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\frac{\frac{1}{\mathsf{hypot}\left(x, \sqrt{x}\right)}}{\sqrt{x} + \sqrt{1 + x}}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation?

  1. Initial program 19.5

    \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
  2. Applied egg-rr5.5

    \[\leadsto \color{blue}{\frac{1 + \left(x - x\right)}{\sqrt{x + x \cdot x} \cdot \left(\sqrt{x} + \sqrt{1 + x}\right)}} \]
  3. Simplified5.5

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

    [Start]5.5

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

    +-commutative [=>]5.5

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

    +-inverses [=>]5.5

    \[ \frac{\color{blue}{0} + 1}{\sqrt{x + x \cdot x} \cdot \left(\sqrt{x} + \sqrt{1 + x}\right)} \]

    metadata-eval [=>]5.5

    \[ \frac{\color{blue}{1}}{\sqrt{x + x \cdot x} \cdot \left(\sqrt{x} + \sqrt{1 + x}\right)} \]

    +-commutative [=>]5.5

    \[ \frac{1}{\sqrt{\color{blue}{x \cdot x + x}} \cdot \left(\sqrt{x} + \sqrt{1 + x}\right)} \]

    fma-def [=>]5.5

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

    +-commutative [=>]5.5

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

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

    \[\leadsto \color{blue}{\frac{\frac{1}{\mathsf{hypot}\left(x, \sqrt{x}\right)}}{\sqrt{x} + \sqrt{x + 1}}} \]
    Proof

    [Start]0.9

    \[ {\left(\mathsf{hypot}\left(x, \sqrt{x}\right) \cdot \left(\sqrt{x + 1} + \sqrt{x}\right)\right)}^{-0.5} \cdot {\left(\mathsf{hypot}\left(x, \sqrt{x}\right) \cdot \left(\sqrt{x + 1} + \sqrt{x}\right)\right)}^{-0.5} \]

    pow-sqr [=>]0.7

    \[ \color{blue}{{\left(\mathsf{hypot}\left(x, \sqrt{x}\right) \cdot \left(\sqrt{x + 1} + \sqrt{x}\right)\right)}^{\left(2 \cdot -0.5\right)}} \]

    metadata-eval [=>]0.7

    \[ {\left(\mathsf{hypot}\left(x, \sqrt{x}\right) \cdot \left(\sqrt{x + 1} + \sqrt{x}\right)\right)}^{\color{blue}{-1}} \]

    unpow-1 [=>]0.7

    \[ \color{blue}{\frac{1}{\mathsf{hypot}\left(x, \sqrt{x}\right) \cdot \left(\sqrt{x + 1} + \sqrt{x}\right)}} \]

    associate-/r* [=>]0.3

    \[ \color{blue}{\frac{\frac{1}{\mathsf{hypot}\left(x, \sqrt{x}\right)}}{\sqrt{x + 1} + \sqrt{x}}} \]

    +-commutative [=>]0.3

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

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

Alternatives

Alternative 1
Error0.4
Cost26692
\[\begin{array}{l} \mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{1 + x}} \leq 10^{-17}:\\ \;\;\;\;\frac{\frac{1}{x}}{\left(1 + x\right) \cdot \left(\sqrt{\frac{1}{x}} \cdot 2\right)}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\ \end{array} \]
Alternative 2
Error0.4
Cost13696
\[\frac{\frac{1}{x}}{\sqrt{1 + x} + \left(1 + x\right) \cdot {x}^{-0.5}} \]
Alternative 3
Error1.0
Cost7364
\[\begin{array}{l} \mathbf{if}\;x \leq 1.2:\\ \;\;\;\;{x}^{-0.5} - \frac{1}{1 + x \cdot 0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x}}{\left(1 + x\right) \cdot \left(\sqrt{\frac{1}{x}} \cdot 2\right)}\\ \end{array} \]
Alternative 4
Error1.1
Cost7172
\[\begin{array}{l} \mathbf{if}\;x \leq 1.65:\\ \;\;\;\;{x}^{-0.5} - \frac{1}{1 + x \cdot 0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x}}{\sqrt{x} \cdot 2}\\ \end{array} \]
Alternative 5
Error1.1
Cost7044
\[\begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;{x}^{-0.5} - \left(1 + x \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x}}{\sqrt{x} \cdot 2}\\ \end{array} \]
Alternative 6
Error1.3
Cost6980
\[\begin{array}{l} \mathbf{if}\;x \leq 0.66:\\ \;\;\;\;{x}^{-0.5} + -1\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x}}{\sqrt{x} \cdot 2}\\ \end{array} \]
Alternative 7
Error20.5
Cost6852
\[\begin{array}{l} \mathbf{if}\;x \leq 1.35 \cdot 10^{+154}:\\ \;\;\;\;\frac{1}{x + \sqrt{x}}\\ \mathbf{else}:\\ \;\;\;\;{\left(x \cdot x\right)}^{-0.25}\\ \end{array} \]
Alternative 8
Error20.4
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq 0.8:\\ \;\;\;\;{x}^{-0.5} + -1\\ \mathbf{else}:\\ \;\;\;\;{\left(x \cdot x\right)}^{-0.25}\\ \end{array} \]
Alternative 9
Error21.5
Cost6784
\[\left(1 + {x}^{-0.5}\right) + -1 \]
Alternative 10
Error31.5
Cost6528
\[{x}^{-0.5} \]

Error

Reproduce?

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