?

Average Error: 30.65% → 0.41%
Time: 12.3s
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

Original30.65%
Target1.02%
Herbie0.41%
\[\frac{1}{\left(x + 1\right) \cdot \sqrt{x} + x \cdot \sqrt{x + 1}} \]

Derivation?

  1. Initial program 30.65

    \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
  2. Applied egg-rr8.65

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

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

    [Start]8.65

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

    +-commutative [=>]8.65

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

    +-inverses [=>]8.65

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

    metadata-eval [=>]8.65

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

    +-commutative [=>]8.65

    \[ \frac{1}{\sqrt{x + x \cdot x} \cdot \color{blue}{\left(\sqrt{1 + x} + \sqrt{x}\right)}} \]
  4. Applied egg-rr1.07

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

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{1}{\mathsf{hypot}\left(x, \sqrt{x}\right) \cdot \left(\sqrt{x} + \sqrt{1 + x}\right)}\right)} - 1} \]
  6. Simplified0.41

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

    [Start]34.6

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

    expm1-def [=>]4.47

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

    expm1-log1p [=>]1.03

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

    associate-/r* [=>]0.41

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

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

Alternatives

Alternative 1
Error1.08%
Cost26948
\[\begin{array}{l} t_0 := \sqrt{1 + x}\\ t_1 := \frac{-1}{t_0}\\ \mathbf{if}\;\frac{1}{\sqrt{x}} + t_1 \leq 5 \cdot 10^{-13}:\\ \;\;\;\;\frac{1}{\left(\sqrt{x} + t_0\right) \cdot \left(x + 0.5\right)}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} + t_1\\ \end{array} \]
Alternative 2
Error0.68%
Cost26820
\[\begin{array}{l} t_0 := \sqrt{1 + x}\\ t_1 := \frac{-1}{t_0}\\ \mathbf{if}\;\frac{1}{\sqrt{x}} + t_1 \leq 5 \cdot 10^{-13}:\\ \;\;\;\;\frac{\frac{1}{x}}{\sqrt{x} + t_0}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} + t_1\\ \end{array} \]
Alternative 3
Error0.7%
Cost26756
\[\begin{array}{l} t_0 := \frac{-1}{\sqrt{1 + x}}\\ \mathbf{if}\;\frac{1}{\sqrt{x}} + t_0 \leq 5 \cdot 10^{-13}:\\ \;\;\;\;\frac{1}{x} \cdot \frac{\sqrt{x} \cdot 0.5}{1 + x}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} + t_0\\ \end{array} \]
Alternative 4
Error0.61%
Cost13760
\[\frac{\frac{1}{x}}{\left(1 + x\right) \cdot \left({x}^{-0.5} + {\left(1 + x\right)}^{-0.5}\right)} \]
Alternative 5
Error0.69%
Cost13380
\[\begin{array}{l} \mathbf{if}\;x \leq 60000000:\\ \;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x} \cdot \frac{\sqrt{x} \cdot 0.5}{1 + x}\\ \end{array} \]
Alternative 6
Error1.55%
Cost7236
\[\begin{array}{l} \mathbf{if}\;x \leq 0.68:\\ \;\;\;\;{x}^{-0.5} + \left(-1 + x \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x} \cdot \frac{\sqrt{x} \cdot 0.5}{1 + x}\\ \end{array} \]
Alternative 7
Error31.24%
Cost7172
\[\begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;{x}^{-0.5} + \left(-1 + x \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x \cdot x}}{1 + {x}^{-0.5}}\\ \end{array} \]
Alternative 8
Error32.11%
Cost6916
\[\begin{array}{l} \mathbf{if}\;x \leq 4.6 \cdot 10^{+153}:\\ \;\;\;\;\frac{1}{x + \sqrt{x}}\\ \mathbf{else}:\\ \;\;\;\;-1 + \left(1 - {x}^{-0.5}\right)\\ \end{array} \]
Alternative 9
Error47.35%
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq 0.58:\\ \;\;\;\;{x}^{-0.5} + -1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x + 0.5}\\ \end{array} \]
Alternative 10
Error47.91%
Cost6720
\[\frac{1}{x + \sqrt{x}} \]
Alternative 11
Error92.57%
Cost320
\[\frac{1}{x + 0.5} \]
Alternative 12
Error98.06%
Cost64
\[-1 \]
Alternative 13
Error94.23%
Cost64
\[2 \]

Error

Reproduce?

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