?

Average Error: 20.0 → 0.2
Time: 11.8s
Precision: binary64
Cost: 33732

?

\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
\[\begin{array}{l} t_0 := \sqrt{1 + x}\\ \mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{t_0} \leq 0:\\ \;\;\;\;0.5 \cdot {x}^{-1.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{1 + \left(x - x\right)}{\sqrt{x + x \cdot x} \cdot \left(\sqrt{x} + t_0\right)}\\ \end{array} \]
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (sqrt (+ 1.0 x))))
   (if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 t_0)) 0.0)
     (* 0.5 (pow x -1.5))
     (/ (+ 1.0 (- x x)) (* (sqrt (+ x (* x x))) (+ (sqrt 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((1.0 + x));
	double tmp;
	if (((1.0 / sqrt(x)) + (-1.0 / t_0)) <= 0.0) {
		tmp = 0.5 * pow(x, -1.5);
	} else {
		tmp = (1.0 + (x - x)) / (sqrt((x + (x * x))) * (sqrt(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((1.0d0 + x))
    if (((1.0d0 / sqrt(x)) + ((-1.0d0) / t_0)) <= 0.0d0) then
        tmp = 0.5d0 * (x ** (-1.5d0))
    else
        tmp = (1.0d0 + (x - x)) / (sqrt((x + (x * x))) * (sqrt(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((1.0 + x));
	double tmp;
	if (((1.0 / Math.sqrt(x)) + (-1.0 / t_0)) <= 0.0) {
		tmp = 0.5 * Math.pow(x, -1.5);
	} else {
		tmp = (1.0 + (x - x)) / (Math.sqrt((x + (x * x))) * (Math.sqrt(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((1.0 + x))
	tmp = 0
	if ((1.0 / math.sqrt(x)) + (-1.0 / t_0)) <= 0.0:
		tmp = 0.5 * math.pow(x, -1.5)
	else:
		tmp = (1.0 + (x - x)) / (math.sqrt((x + (x * x))) * (math.sqrt(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 = sqrt(Float64(1.0 + x))
	tmp = 0.0
	if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / t_0)) <= 0.0)
		tmp = Float64(0.5 * (x ^ -1.5));
	else
		tmp = Float64(Float64(1.0 + Float64(x - x)) / Float64(sqrt(Float64(x + Float64(x * x))) * Float64(sqrt(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((1.0 + x));
	tmp = 0.0;
	if (((1.0 / sqrt(x)) + (-1.0 / t_0)) <= 0.0)
		tmp = 0.5 * (x ^ -1.5);
	else
		tmp = (1.0 + (x - x)) / (sqrt((x + (x * x))) * (sqrt(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[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / t$95$0), $MachinePrecision]), $MachinePrecision], 0.0], N[(0.5 * N[Power[x, -1.5], $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(x - x), $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[N[(x + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(N[Sqrt[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\begin{array}{l}
t_0 := \sqrt{1 + x}\\
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{t_0} \leq 0:\\
\;\;\;\;0.5 \cdot {x}^{-1.5}\\

\mathbf{else}:\\
\;\;\;\;\frac{1 + \left(x - x\right)}{\sqrt{x + x \cdot x} \cdot \left(\sqrt{x} + t_0\right)}\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original20.0
Target0.6
Herbie0.2
\[\frac{1}{\left(x + 1\right) \cdot \sqrt{x} + x \cdot \sqrt{x + 1}} \]

Derivation?

  1. Split input into 2 regimes
  2. if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 0.0

    1. Initial program 39.7

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

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

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

      [Start]60.1

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

      sub-neg [=>]60.1

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

      associate-/l/ [=>]60.1

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

      distribute-neg-frac [=>]60.1

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

      metadata-eval [=>]60.1

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

      +-commutative [=>]60.1

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

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{\frac{1}{{x}^{3}}}} \]
    5. Applied egg-rr39.7

      \[\leadsto 0.5 \cdot \color{blue}{\left(\left(1 + {x}^{-1.5}\right) - 1\right)} \]
    6. Simplified0.0

      \[\leadsto 0.5 \cdot \color{blue}{{x}^{-1.5}} \]
      Proof

      [Start]39.7

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

      +-commutative [=>]39.7

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

      associate--l+ [=>]0.0

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

      metadata-eval [=>]0.0

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

      +-rgt-identity [=>]0.0

      \[ 0.5 \cdot \color{blue}{{x}^{-1.5}} \]

    if 0.0 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1))))

    1. Initial program 1.6

      \[\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. Recombined 2 regimes into one program.
  4. Final simplification0.2

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

Alternatives

Alternative 1
Error0.3
Cost27204
\[\begin{array}{l} \mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{1 + x}} \leq 0:\\ \;\;\;\;0.5 \cdot {x}^{-1.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{\left({x}^{-0.5} + {\left(1 + x\right)}^{-0.5}\right) \cdot \left(x \cdot \left(-1 - x\right)\right)}\\ \end{array} \]
Alternative 2
Error0.3
Cost27204
\[\begin{array}{l} \mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{1 + x}} \leq 0:\\ \;\;\;\;0.5 \cdot {x}^{-1.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{-1}{x}}{-1 - x}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}\\ \end{array} \]
Alternative 3
Error0.6
Cost26948
\[\begin{array}{l} t_0 := \sqrt{1 + x}\\ \mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{t_0} \leq 2 \cdot 10^{-8}:\\ \;\;\;\;\frac{1}{\left(\sqrt{x} + t_0\right) \cdot \left(x + 0.5\right)}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\ \end{array} \]
Alternative 4
Error0.3
Cost26240
\[\frac{\frac{1}{\mathsf{hypot}\left(x, \sqrt{x}\right)}}{\sqrt{x} + \sqrt{1 + x}} \]
Alternative 5
Error0.2
Cost20164
\[\begin{array}{l} \mathbf{if}\;x \leq 6 \cdot 10^{+16}:\\ \;\;\;\;\frac{\frac{1}{\sqrt{x + x \cdot x}}}{\sqrt{x} + \sqrt{1 + x}}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot {x}^{-1.5}\\ \end{array} \]
Alternative 6
Error0.3
Cost13892
\[\begin{array}{l} \mathbf{if}\;x \leq 6 \cdot 10^{+16}:\\ \;\;\;\;\frac{\frac{1}{x \cdot \left(1 + x\right)}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot {x}^{-1.5}\\ \end{array} \]
Alternative 7
Error0.4
Cost13380
\[\begin{array}{l} \mathbf{if}\;x \leq 92000000:\\ \;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot {x}^{-1.5}\\ \end{array} \]
Alternative 8
Error0.9
Cost7044
\[\begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;{x}^{-0.5} + \left(-1 + x \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot {x}^{-1.5}\\ \end{array} \]
Alternative 9
Error2.1
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq 0.5:\\ \;\;\;\;{x}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot {x}^{-1.5}\\ \end{array} \]
Alternative 10
Error1.1
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq 0.68:\\ \;\;\;\;-1 + {x}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot {x}^{-1.5}\\ \end{array} \]
Alternative 11
Error32.1
Cost6528
\[{x}^{-0.5} \]

Error

Reproduce?

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