?

Average Error: 20.2 → 0.3
Time: 11.6s
Precision: binary64
Cost: 32704

?

\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
\[\frac{-1}{\mathsf{hypot}\left(x, \sqrt{x}\right)} \cdot \frac{-1}{\sqrt{x} + \mathsf{hypot}\left(1, \sqrt{x}\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))) (/ -1.0 (+ (sqrt x) (hypot 1.0 (sqrt 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))) * (-1.0 / (sqrt(x) + hypot(1.0, sqrt(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))) * (-1.0 / (Math.sqrt(x) + Math.hypot(1.0, Math.sqrt(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))) * (-1.0 / (math.sqrt(x) + math.hypot(1.0, math.sqrt(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(-1.0 / Float64(sqrt(x) + hypot(1.0, sqrt(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))) * (-1.0 / (sqrt(x) + hypot(1.0, sqrt(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[(-1.0 / N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[1.0 ^ 2 + N[Sqrt[x], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\frac{-1}{\mathsf{hypot}\left(x, \sqrt{x}\right)} \cdot \frac{-1}{\sqrt{x} + \mathsf{hypot}\left(1, \sqrt{x}\right)}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation?

  1. Initial program 20.2

    \[\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{\frac{1}{\sqrt{x + x \cdot x}}}{\sqrt{1 + x} + \sqrt{x}}} \]
    Proof

    [Start]5.5

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

    associate-/r* [=>]5.5

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

    +-commutative [=>]5.5

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

    +-inverses [=>]5.5

    \[ \frac{\frac{\color{blue}{0} + 1}{\sqrt{x + x \cdot x}}}{\sqrt{x} + \sqrt{1 + x}} \]

    metadata-eval [=>]5.5

    \[ \frac{\frac{\color{blue}{1}}{\sqrt{x + x \cdot x}}}{\sqrt{x} + \sqrt{1 + x}} \]

    +-commutative [=>]5.5

    \[ \frac{\frac{1}{\sqrt{x + x \cdot x}}}{\color{blue}{\sqrt{1 + x} + \sqrt{x}}} \]
  4. Applied egg-rr0.3

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

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

Alternatives

Alternative 1
Error0.2
Cost27076
\[\begin{array}{l} \mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{x + 1}} \leq 4 \cdot 10^{-8}:\\ \;\;\;\;\frac{\frac{1}{x}}{\sqrt{\frac{1}{x}} \cdot 1.5 + \sqrt{x} \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} - {\left(x + 1\right)}^{-0.5}\\ \end{array} \]
Alternative 2
Error0.3
Cost26948
\[\begin{array}{l} t_0 := \sqrt{x + 1}\\ \mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{t_0} \leq 10^{-11}:\\ \;\;\;\;\frac{\frac{1}{x + 0.5}}{\sqrt{x} + t_0}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} - {\left(x + 1\right)}^{-0.5}\\ \end{array} \]
Alternative 3
Error0.4
Cost26692
\[\begin{array}{l} \mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{x + 1}} \leq 10^{-13}:\\ \;\;\;\;\frac{{x}^{-0.5}}{x \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} - {\left(x + 1\right)}^{-0.5}\\ \end{array} \]
Alternative 4
Error0.4
Cost13696
\[\frac{\frac{1}{x}}{\left(x + 1\right) \cdot {x}^{-0.5} + \sqrt{x + 1}} \]
Alternative 5
Error1.0
Cost7364
\[\begin{array}{l} \mathbf{if}\;x \leq 0.68:\\ \;\;\;\;-1 + \left({x}^{-0.5} + x \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x}}{\left(x + 1\right) \cdot \left(\sqrt{\frac{1}{x}} \cdot 2\right)}\\ \end{array} \]
Alternative 6
Error1.0
Cost7044
\[\begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;-1 + \left({x}^{-0.5} + x \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{{x}^{-0.5}}{x \cdot 2}\\ \end{array} \]
Alternative 7
Error1.2
Cost6916
\[\begin{array}{l} \mathbf{if}\;x \leq 0.68:\\ \;\;\;\;-1 + {x}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{{x}^{-0.5}}{x \cdot 2}\\ \end{array} \]
Alternative 8
Error30.3
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq 0.6:\\ \;\;\;\;-1 + {x}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x} - \frac{0.5}{x \cdot x}\\ \end{array} \]
Alternative 9
Error1.6
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq 0.68:\\ \;\;\;\;-1 + {x}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{{x}^{1.5}}\\ \end{array} \]
Alternative 10
Error31.9
Cost6528
\[{x}^{-0.5} \]
Alternative 11
Error59.2
Cost320
\[\frac{1}{x + 0.5} \]
Alternative 12
Error59.3
Cost192
\[\frac{1}{x} \]
Alternative 13
Error62.8
Cost64
\[-1 \]

Error

Reproduce?

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