Average Error: 19.6 → 0.1
Time: 11.4s
Precision: binary64
Cost: 13700
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
\[\begin{array}{l} \mathbf{if}\;x \leq 2 \cdot 10^{+153}:\\ \;\;\;\;\frac{{x}^{-0.5}}{x + \left(1 + \sqrt{x \cdot \left(x + 1\right)}\right)}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} \cdot \frac{0.5}{x}\\ \end{array} \]
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
(FPCore (x)
 :precision binary64
 (if (<= x 2e+153)
   (/ (pow x -0.5) (+ x (+ 1.0 (sqrt (* x (+ x 1.0))))))
   (* (pow x -0.5) (/ 0.5 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+153) {
		tmp = pow(x, -0.5) / (x + (1.0 + sqrt((x * (x + 1.0)))));
	} else {
		tmp = pow(x, -0.5) * (0.5 / 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+153) then
        tmp = (x ** (-0.5d0)) / (x + (1.0d0 + sqrt((x * (x + 1.0d0)))))
    else
        tmp = (x ** (-0.5d0)) * (0.5d0 / 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+153) {
		tmp = Math.pow(x, -0.5) / (x + (1.0 + Math.sqrt((x * (x + 1.0)))));
	} else {
		tmp = Math.pow(x, -0.5) * (0.5 / 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+153:
		tmp = math.pow(x, -0.5) / (x + (1.0 + math.sqrt((x * (x + 1.0)))))
	else:
		tmp = math.pow(x, -0.5) * (0.5 / 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+153)
		tmp = Float64((x ^ -0.5) / Float64(x + Float64(1.0 + sqrt(Float64(x * Float64(x + 1.0))))));
	else
		tmp = Float64((x ^ -0.5) * Float64(0.5 / 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+153)
		tmp = (x ^ -0.5) / (x + (1.0 + sqrt((x * (x + 1.0)))));
	else
		tmp = (x ^ -0.5) * (0.5 / 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+153], N[(N[Power[x, -0.5], $MachinePrecision] / N[(x + N[(1.0 + N[Sqrt[N[(x * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] * N[(0.5 / x), $MachinePrecision]), $MachinePrecision]]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\begin{array}{l}
\mathbf{if}\;x \leq 2 \cdot 10^{+153}:\\
\;\;\;\;\frac{{x}^{-0.5}}{x + \left(1 + \sqrt{x \cdot \left(x + 1\right)}\right)}\\

\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} \cdot \frac{0.5}{x}\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

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

    1. Initial program 19.1

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

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

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{\sqrt[3]{{\left(1 + x\right)}^{1.5}}}} \]
      Proof

      [Start]19.6

      \[ \frac{1}{\sqrt{x}} - \frac{1}{{\left({\left(1 + x\right)}^{1.5}\right)}^{0.3333333333333333}} \]

      unpow1/3 [=>]19.1

      \[ \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{\sqrt[3]{{\left(1 + x\right)}^{1.5}}}} \]
    4. Applied egg-rr0.2

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

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

      [Start]0.2

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

      +-commutative [=>]0.2

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

      +-inverses [=>]0.2

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

      metadata-eval [=>]0.2

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

      associate-*r/ [=>]0.2

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

      associate-/l/ [=>]0.2

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

      *-lft-identity [=>]0.2

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

      +-commutative [=>]0.2

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

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

    if 2e153 < x

    1. Initial program 21.0

      \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
    2. Applied egg-rr61.4

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{{\left({\left(1 + x\right)}^{1.5}\right)}^{0.3333333333333333}}} \]
    3. Simplified60.7

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{\sqrt[3]{{\left(1 + x\right)}^{1.5}}}} \]
      Proof

      [Start]61.4

      \[ \frac{1}{\sqrt{x}} - \frac{1}{{\left({\left(1 + x\right)}^{1.5}\right)}^{0.3333333333333333}} \]

      unpow1/3 [=>]60.7

      \[ \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{\sqrt[3]{{\left(1 + x\right)}^{1.5}}}} \]
    4. Applied egg-rr0.2

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

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

      [Start]0.2

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

      +-commutative [=>]0.2

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

      +-inverses [=>]0.2

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

      metadata-eval [=>]0.2

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

      associate-*r/ [=>]0.2

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

      associate-/l/ [=>]0.2

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

      *-lft-identity [=>]0.2

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

      +-commutative [=>]0.2

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

      \[\leadsto \color{blue}{{x}^{-0.5} \cdot \frac{1}{\left(x + 1\right) + \sqrt{x \cdot \left(x + 1\right)}}} \]
    7. Taylor expanded in x around inf 0.1

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

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

Alternatives

Alternative 1
Error0.2
Cost26756
\[\begin{array}{l} t_0 := \frac{-1}{\sqrt{x + 1}}\\ \mathbf{if}\;\frac{1}{\sqrt{x}} + t_0 \leq 2 \cdot 10^{-8}:\\ \;\;\;\;{x}^{-0.5} \cdot \frac{1}{1.5 + \left(x \cdot 2 + \frac{-0.125}{x}\right)}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} + t_0\\ \end{array} \]
Alternative 2
Error0.1
Cost19776
\[\frac{{x}^{-0.5}}{x + \left(1 + \mathsf{hypot}\left(x, \sqrt{x}\right)\right)} \]
Alternative 3
Error0.2
Cost13380
\[\begin{array}{l} \mathbf{if}\;x \leq 4200:\\ \;\;\;\;{x}^{-0.5} - {\left(x + 1\right)}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} \cdot \frac{1}{1.5 + \left(x \cdot 2 + \frac{-0.125}{x}\right)}\\ \end{array} \]
Alternative 4
Error0.5
Cost7940
\[\begin{array}{l} \mathbf{if}\;x \leq 0.56:\\ \;\;\;\;{x}^{-0.5} + \frac{-1}{1 + x \cdot 0.5}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} \cdot \frac{1}{\left(x + 1\right) + \left(0.5 + \left(\left(x + \frac{0.0625}{x \cdot x}\right) + \frac{-0.125}{x}\right)\right)}\\ \end{array} \]
Alternative 5
Error0.6
Cost7428
\[\begin{array}{l} \mathbf{if}\;x \leq 0.58:\\ \;\;\;\;{x}^{-0.5} + \frac{-1}{1 + x \cdot 0.5}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} \cdot \frac{1}{1.5 + \left(x \cdot 2 + \frac{-0.125}{x}\right)}\\ \end{array} \]
Alternative 6
Error0.7
Cost7172
\[\begin{array}{l} \mathbf{if}\;x \leq 0.41:\\ \;\;\;\;{x}^{-0.5} + \left(-1 - x \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} \cdot \frac{1}{1.5 + x \cdot 2}\\ \end{array} \]
Alternative 7
Error0.7
Cost7172
\[\begin{array}{l} \mathbf{if}\;x \leq 0.62:\\ \;\;\;\;{x}^{-0.5} + \frac{-1}{1 + x \cdot 0.5}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} \cdot \frac{1}{1.5 + x \cdot 2}\\ \end{array} \]
Alternative 8
Error1.1
Cost7108
\[\begin{array}{l} \mathbf{if}\;x \leq 0.7:\\ \;\;\;\;{x}^{-0.5} + \left(-1 - x \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{x} \cdot \frac{1}{\sqrt{x + 1}}\\ \end{array} \]
Alternative 9
Error1.1
Cost7044
\[\begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;{x}^{-0.5} + \left(-1 - x \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} \cdot \frac{0.5}{x}\\ \end{array} \]
Alternative 10
Error1.3
Cost6916
\[\begin{array}{l} \mathbf{if}\;x \leq 0.66:\\ \;\;\;\;{x}^{-0.5} + -1\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} \cdot \frac{0.5}{x}\\ \end{array} \]
Alternative 11
Error20.3
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq 0.6:\\ \;\;\;\;{x}^{-0.5} + -1\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \left(x - x\right)\right) \cdot \left(\frac{1}{0.25 - x \cdot x} \cdot \left(0.5 - x\right)\right)\\ \end{array} \]
Alternative 12
Error21.2
Cost6660
\[\begin{array}{l} \mathbf{if}\;x \leq 0.092:\\ \;\;\;\;{x}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \left(x - x\right)\right) \cdot \left(\frac{1}{0.25 - x \cdot x} \cdot \left(0.5 - x\right)\right)\\ \end{array} \]
Alternative 13
Error49.4
Cost1088
\[\left(1 + \left(x - x\right)\right) \cdot \left(\frac{1}{0.25 - x \cdot x} \cdot \left(0.5 - x\right)\right) \]
Alternative 14
Error59.3
Cost704
\[\left(1 + \left(x - x\right)\right) \cdot \frac{1}{x + 0.5} \]
Alternative 15
Error59.3
Cost576
\[\left(1 + \left(x - x\right)\right) \cdot \frac{1}{x} \]
Alternative 16
Error60.3
Cost64
\[2 \]

Error

Reproduce

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