?

Average Error: 19.9 → 0.1
Time: 11.4s
Precision: binary64
Cost: 13828

?

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

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{x}}{\sqrt{x} \cdot 2}\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original19.9
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 < 6.5000000000000003e35

    1. Initial program 4.9

      \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
    2. Applied egg-rr4.9

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{e^{\mathsf{log1p}\left(x\right) \cdot 0.5}}} \]
    3. Applied egg-rr0.1

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

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

      [Start]0.1

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

      associate-*r/ [=>]0.1

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

      +-commutative [=>]0.1

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

      +-inverses [=>]0.1

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

      metadata-eval [=>]0.1

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

      associate-/l/ [=>]0.1

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

      *-lft-identity [=>]0.1

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

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

    if 6.5000000000000003e35 < x

    1. Initial program 38.3

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

      \[\leadsto \color{blue}{\frac{1}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}} \cdot \left(\frac{1}{x} + \frac{-1}{1 + x}\right)} \]
    3. Applied egg-rr12.1

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

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

      [Start]12.1

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

      associate-*r/ [<=]12.1

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

      associate-/r* [=>]12.1

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

      associate-/l* [<=]12.1

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

      *-commutative [<=]12.1

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

      associate-/l* [=>]12.1

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

      associate-/r/ [=>]12.1

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

      times-frac [<=]12.1

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

      associate-/r* [=>]12.1

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

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

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

Alternatives

Alternative 1
Error0.4
Cost26756
\[\begin{array}{l} t_0 := \sqrt{x + 1}\\ \mathbf{if}\;\frac{1}{\sqrt{x}} - \frac{1}{t_0} \leq 5 \cdot 10^{-13}:\\ \;\;\;\;\frac{{x}^{-0.5}}{x + \left(x + 1\right)}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} + \frac{-1}{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.4
Cost13760
\[\frac{\frac{1}{x}}{\left(x + 1\right) \cdot \left({x}^{-0.5} + {\left(x + 1\right)}^{-0.5}\right)} \]
Alternative 4
Error0.1
Cost13700
\[\begin{array}{l} \mathbf{if}\;x \leq 4 \cdot 10^{+42}:\\ \;\;\;\;\frac{{x}^{-0.5}}{x + \left(1 + \sqrt{x + x \cdot x}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x}}{\sqrt{x} \cdot 2}\\ \end{array} \]
Alternative 5
Error0.4
Cost13380
\[\begin{array}{l} \mathbf{if}\;x \leq 35000000:\\ \;\;\;\;{x}^{-0.5} - {\left(x + 1\right)}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{{x}^{-0.5}}{x + \left(x + 1\right)}\\ \end{array} \]
Alternative 6
Error0.9
Cost7172
\[\begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;{x}^{-0.5} - \frac{1}{1 + x \cdot 0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{{x}^{-0.5}}{x + \left(x + 1\right)}\\ \end{array} \]
Alternative 7
Error1.0
Cost7044
\[\begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;{x}^{-0.5} + \left(-1 + x \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x}}{\sqrt{x} \cdot 2}\\ \end{array} \]
Alternative 8
Error0.9
Cost7044
\[\begin{array}{l} \mathbf{if}\;x \leq 0.58:\\ \;\;\;\;{x}^{-0.5} + \left(-1 + x \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{{x}^{-0.5}}{x + \left(x + 1\right)}\\ \end{array} \]
Alternative 9
Error1.1
Cost6980
\[\begin{array}{l} \mathbf{if}\;x \leq 0.68:\\ \;\;\;\;{x}^{-0.5} + -1\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x}}{\sqrt{x} \cdot 2}\\ \end{array} \]
Alternative 10
Error20.7
Cost6916
\[\begin{array}{l} \mathbf{if}\;x \leq 4.6 \cdot 10^{+153}:\\ \;\;\;\;\frac{1}{x + \sqrt{x}}\\ \mathbf{else}:\\ \;\;\;\;\left({x}^{-0.5} + 1\right) + -1\\ \end{array} \]
Alternative 11
Error20.7
Cost6916
\[\begin{array}{l} \mathbf{if}\;x \leq 4.6 \cdot 10^{+153}:\\ \;\;\;\;\frac{1}{x + {x}^{0.5}}\\ \mathbf{else}:\\ \;\;\;\;\left({x}^{-0.5} + 1\right) + -1\\ \end{array} \]
Alternative 12
Error1.1
Cost6916
\[\begin{array}{l} \mathbf{if}\;x \leq 0.68:\\ \;\;\;\;{x}^{-0.5} + -1\\ \mathbf{else}:\\ \;\;\;\;\frac{{x}^{-0.5}}{x \cdot 2}\\ \end{array} \]
Alternative 13
Error30.2
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq 0.82:\\ \;\;\;\;{x}^{-0.5} + -1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x}\\ \end{array} \]
Alternative 14
Error30.5
Cost6720
\[\frac{1}{x + \sqrt{x}} \]
Alternative 15
Error31.8
Cost6528
\[{x}^{-0.5} \]
Alternative 16
Error61.5
Cost192
\[x \cdot 0.5 \]
Alternative 17
Error59.3
Cost192
\[\frac{1}{x} \]

Error

Reproduce?

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