?

Average Error: 30.33% → 0.4%
Time: 12.7s
Precision: binary64
Cost: 13764

?

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

\mathbf{else}:\\
\;\;\;\;\frac{\frac{0.5}{x}}{\sqrt{x}}\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original30.33%
Target1.08%
Herbie0.4%
\[\frac{1}{\left(x + 1\right) \cdot \sqrt{x} + x \cdot \sqrt{x + 1}} \]

Derivation?

  1. Split input into 2 regimes
  2. if x < 2.00000000000000004e64

    1. Initial program 13.4

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

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

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

      [Start]0.46

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

      +-commutative [=>]0.46

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

      +-inverses [=>]0.46

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

      metadata-eval [=>]0.46

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

      +-commutative [=>]0.46

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

      \[\leadsto \frac{1}{\color{blue}{\left({\left(x + 1\right)}^{0.25} \cdot \left({\left(x + 1\right)}^{0.25} \cdot \sqrt{x}\right)\right)} \cdot \left(\sqrt{1 + x} + \sqrt{x}\right)} \]
    5. Applied egg-rr0.45

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

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

      [Start]0.45

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

      fma-udef [=>]0.45

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

      distribute-rgt-out [=>]0.45

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

      +-commutative [=>]0.45

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

      *-commutative [=>]0.45

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

      +-commutative [=>]0.45

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

    if 2.00000000000000004e64 < x

    1. Initial program 55.21

      \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
    2. Applied egg-rr55.21

      \[\leadsto \color{blue}{\frac{\frac{\sqrt{1 + x} - \sqrt{x}}{\sqrt{x}}}{-\sqrt{1 + x}} \cdot -1} \]
    3. Simplified55.21

      \[\leadsto \color{blue}{\frac{1 - \frac{\sqrt{x}}{\sqrt{1 + x}}}{\sqrt{x}}} \]
      Proof

      [Start]55.21

      \[ \frac{\frac{\sqrt{1 + x} - \sqrt{x}}{\sqrt{x}}}{-\sqrt{1 + x}} \cdot -1 \]

      associate-*l/ [=>]55.21

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

      associate-/l* [=>]55.21

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

      metadata-eval [<=]55.21

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

      associate-/l* [<=]55.21

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

      *-commutative [<=]55.21

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

      mul-1-neg [=>]55.21

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

      remove-double-neg [=>]55.21

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

      /-rgt-identity [=>]55.21

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

      associate-/l/ [=>]55.21

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

      associate-/r* [=>]55.21

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

      div-sub [=>]55.21

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

      *-inverses [=>]55.21

      \[ \frac{\color{blue}{1} - \frac{\sqrt{x}}{\sqrt{1 + x}}}{\sqrt{x}} \]
    4. Taylor expanded in x around inf 0.32

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

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

Alternatives

Alternative 1
Error0.34%
Cost26948
\[\begin{array}{l} t_0 := \sqrt{1 + x}\\ \mathbf{if}\;\frac{1}{\sqrt{x}} - \frac{1}{t_0} \leq 5 \cdot 10^{-9}:\\ \;\;\;\;\frac{\frac{1}{x + 0.5}}{\sqrt{x} + t_0}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\ \end{array} \]
Alternative 2
Error1.08%
Cost13632
\[\frac{1}{\left(1 + x\right) \cdot \sqrt{x} + x \cdot \sqrt{1 + x}} \]
Alternative 3
Error0.36%
Cost13380
\[\begin{array}{l} \mathbf{if}\;x \leq 160000:\\ \;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{0.5 + \frac{-0.375}{x}}{x}}{\sqrt{x}}\\ \end{array} \]
Alternative 4
Error1.06%
Cost7172
\[\begin{array}{l} \mathbf{if}\;x \leq 1.42:\\ \;\;\;\;{x}^{-0.5} + \frac{-1}{1 - x \cdot -0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{0.5 + \frac{-0.375}{x}}{x}}{\sqrt{x}}\\ \end{array} \]
Alternative 5
Error1.08%
Cost7108
\[\begin{array}{l} \mathbf{if}\;x \leq 1.1:\\ \;\;\;\;{x}^{-0.5} + \left(-1 - x \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{0.5 + \frac{-0.375}{x}}{x}}{\sqrt{x}}\\ \end{array} \]
Alternative 6
Error1.56%
Cost7044
\[\begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;{x}^{-0.5} + \left(-1 - x \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{0.5}{x}}{\sqrt{x}}\\ \end{array} \]
Alternative 7
Error1.72%
Cost7044
\[\begin{array}{l} \mathbf{if}\;x \leq 1.1:\\ \;\;\;\;{x}^{-0.5} + \left(-1 - x \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5 + \frac{-0.375}{x}}{{x}^{1.5}}\\ \end{array} \]
Alternative 8
Error1.83%
Cost6852
\[\begin{array}{l} \mathbf{if}\;x \leq 0.68:\\ \;\;\;\;{x}^{-0.5} + -1\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{0.5}{x}}{\sqrt{x}}\\ \end{array} \]
Alternative 9
Error46.77%
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq 0.6:\\ \;\;\;\;{x}^{-0.5} + -1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x + 0.5}\\ \end{array} \]
Alternative 10
Error49.2%
Cost6528
\[{x}^{-0.5} \]
Alternative 11
Error92.63%
Cost320
\[\frac{1}{x + 0.5} \]
Alternative 12
Error98.07%
Cost64
\[-1 \]
Alternative 13
Error94.26%
Cost64
\[2 \]

Error

Reproduce?

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