?

Average Error: 20.3 → 0.3
Time: 12.1s
Precision: binary64
Cost: 20164

?

\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
\[\begin{array}{l} t_0 := \sqrt{x} + \sqrt{1 + x}\\ \mathbf{if}\;x \leq 2 \cdot 10^{+133}:\\ \;\;\;\;\frac{1}{t_0 \cdot \sqrt{x + x \cdot x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x}}{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 x) (sqrt (+ 1.0 x)))))
   (if (<= x 2e+133) (/ 1.0 (* t_0 (sqrt (+ x (* x x))))) (/ (/ 1.0 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(x) + sqrt((1.0 + x));
	double tmp;
	if (x <= 2e+133) {
		tmp = 1.0 / (t_0 * sqrt((x + (x * x))));
	} else {
		tmp = (1.0 / x) / t_0;
	}
	return tmp;
}
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
    real(8) :: t_0
    real(8) :: tmp
    t_0 = sqrt(x) + sqrt((1.0d0 + x))
    if (x <= 2d+133) then
        tmp = 1.0d0 / (t_0 * sqrt((x + (x * x))))
    else
        tmp = (1.0d0 / x) / t_0
    end if
    code = tmp
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) {
	double t_0 = Math.sqrt(x) + Math.sqrt((1.0 + x));
	double tmp;
	if (x <= 2e+133) {
		tmp = 1.0 / (t_0 * Math.sqrt((x + (x * x))));
	} else {
		tmp = (1.0 / x) / t_0;
	}
	return tmp;
}
def code(x):
	return (1.0 / math.sqrt(x)) - (1.0 / math.sqrt((x + 1.0)))
def code(x):
	t_0 = math.sqrt(x) + math.sqrt((1.0 + x))
	tmp = 0
	if x <= 2e+133:
		tmp = 1.0 / (t_0 * math.sqrt((x + (x * x))))
	else:
		tmp = (1.0 / x) / t_0
	return tmp
function code(x)
	return Float64(Float64(1.0 / sqrt(x)) - Float64(1.0 / sqrt(Float64(x + 1.0))))
end
function code(x)
	t_0 = Float64(sqrt(x) + sqrt(Float64(1.0 + x)))
	tmp = 0.0
	if (x <= 2e+133)
		tmp = Float64(1.0 / Float64(t_0 * sqrt(Float64(x + Float64(x * x)))));
	else
		tmp = Float64(Float64(1.0 / x) / t_0);
	end
	return tmp
end
function tmp = code(x)
	tmp = (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
end
function tmp_2 = code(x)
	t_0 = sqrt(x) + sqrt((1.0 + x));
	tmp = 0.0;
	if (x <= 2e+133)
		tmp = 1.0 / (t_0 * sqrt((x + (x * x))));
	else
		tmp = (1.0 / x) / t_0;
	end
	tmp_2 = tmp;
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[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 2e+133], N[(1.0 / N[(t$95$0 * N[Sqrt[N[(x + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / x), $MachinePrecision] / t$95$0), $MachinePrecision]]]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\begin{array}{l}
t_0 := \sqrt{x} + \sqrt{1 + x}\\
\mathbf{if}\;x \leq 2 \cdot 10^{+133}:\\
\;\;\;\;\frac{1}{t_0 \cdot \sqrt{x + x \cdot x}}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{x}}{t_0}\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation?

  1. Split input into 2 regimes
  2. if x < 2e133

    1. Initial program 17.8

      \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
    2. Applied egg-rr0.3

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

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

      [Start]0.3

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

      +-commutative [=>]0.3

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

      +-inverses [=>]0.3

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

      metadata-eval [=>]0.3

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

      +-commutative [=>]0.3

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

    if 2e133 < x

    1. Initial program 26.5

      \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
    2. Applied egg-rr19.7

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

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

      [Start]19.7

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

      +-commutative [=>]19.7

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

      +-inverses [=>]19.7

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

      metadata-eval [=>]19.7

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

      +-commutative [=>]19.7

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

      \[\leadsto \frac{1}{\sqrt{x + x \cdot x} \cdot \color{blue}{\frac{1}{\frac{1}{\sqrt{x + 1} + \sqrt{x}}}}} \]
    5. Applied egg-rr1.7

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

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

      [Start]1.7

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

      pow-sqr [=>]1.7

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

      metadata-eval [=>]1.7

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

      unpow-1 [=>]1.7

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

      associate-/r* [=>]0.1

      \[ \color{blue}{\frac{\frac{1}{\mathsf{hypot}\left(x, \sqrt{x}\right)}}{\sqrt{1 + x} + \sqrt{x}}} \]
    7. Taylor expanded in x around inf 0.1

      \[\leadsto \frac{\color{blue}{\frac{1}{x}}}{\sqrt{1 + x} + \sqrt{x}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 2 \cdot 10^{+133}:\\ \;\;\;\;\frac{1}{\left(\sqrt{x} + \sqrt{1 + x}\right) \cdot \sqrt{x + x \cdot x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x}}{\sqrt{x} + \sqrt{1 + x}}\\ \end{array} \]

Alternatives

Alternative 1
Error0.4
Cost26820
\[\begin{array}{l} t_0 := \sqrt{1 + x}\\ \mathbf{if}\;\frac{1}{\sqrt{x}} - \frac{1}{t_0} \leq 2 \cdot 10^{-13}:\\ \;\;\;\;\frac{\frac{1}{x}}{\sqrt{x} + t_0}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} + \frac{-1}{t_0}\\ \end{array} \]
Alternative 2
Error0.9
Cost26756
\[\begin{array}{l} t_0 := \sqrt{1 + x}\\ \mathbf{if}\;\frac{1}{\sqrt{x}} - \frac{1}{t_0} \leq 2 \cdot 10^{-13}:\\ \;\;\;\;\frac{1}{\frac{t_0}{\frac{0.5}{x}}}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} + \frac{-1}{t_0}\\ \end{array} \]
Alternative 3
Error0.3
Cost26240
\[\frac{\frac{1}{\mathsf{hypot}\left(x, \sqrt{x}\right)}}{\sqrt{x} + \sqrt{1 + x}} \]
Alternative 4
Error0.9
Cost13508
\[\begin{array}{l} t_0 := \sqrt{1 + x}\\ \mathbf{if}\;x \leq 95000000:\\ \;\;\;\;{x}^{-0.5} + \frac{-1}{t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x \cdot \left(\sqrt{x} + t_0\right)}\\ \end{array} \]
Alternative 5
Error0.9
Cost13380
\[\begin{array}{l} \mathbf{if}\;x \leq 35000000:\\ \;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{\sqrt{1 + x}}{\frac{0.5}{x}}}\\ \end{array} \]
Alternative 6
Error1.5
Cost7172
\[\begin{array}{l} \mathbf{if}\;x \leq 1.15:\\ \;\;\;\;{x}^{-0.5} + \frac{-1}{1 - x \cdot -0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{\sqrt{1 + x}}{\frac{0.5}{x}}}\\ \end{array} \]
Alternative 7
Error1.5
Cost7108
\[\begin{array}{l} \mathbf{if}\;x \leq 0.72:\\ \;\;\;\;{x}^{-0.5} + \left(-1 + x \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{\sqrt{1 + x}}{\frac{0.5}{x}}}\\ \end{array} \]
Alternative 8
Error18.4
Cost7044
\[\begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;{x}^{-0.5} + \left(-1 + x \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x \cdot \left(1 + \sqrt{x}\right)}\\ \end{array} \]
Alternative 9
Error18.6
Cost6980
\[\begin{array}{l} \mathbf{if}\;x \leq 0.64:\\ \;\;\;\;{x}^{-0.5} + -1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x \cdot \left(1 + \sqrt{x}\right)}\\ \end{array} \]
Alternative 10
Error20.8
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq 0.48:\\ \;\;\;\;{x}^{-0.5} + -1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x \cdot \left(x + 2\right)}\\ \end{array} \]
Alternative 11
Error21.7
Cost6660
\[\begin{array}{l} \mathbf{if}\;x \leq 0.21:\\ \;\;\;\;{x}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x \cdot \left(x + 2\right)}\\ \end{array} \]
Alternative 12
Error49.9
Cost448
\[\frac{1}{x \cdot \left(x + 2\right)} \]
Alternative 13
Error59.3
Cost192
\[\frac{0.5}{x} \]

Error

Reproduce?

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