Average Error: 20.0 → 0.2
Time: 9.2s
Precision: binary64
Cost: 33476
\[\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{\frac{1}{\sqrt{x} + t_0}}{\sqrt{x + x \cdot x}}\\ \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 (+ (sqrt x) t_0)) (sqrt (+ x (* x x)))))))
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 / (sqrt(x) + t_0)) / sqrt((x + (x * 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) :: 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 / (sqrt(x) + t_0)) / sqrt((x + (x * 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 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 / (Math.sqrt(x) + t_0)) / Math.sqrt((x + (x * x)));
	}
	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 / (math.sqrt(x) + t_0)) / math.sqrt((x + (x * 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)
	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(sqrt(x) + t_0)) / sqrt(Float64(x + Float64(x * 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)
	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 / (sqrt(x) + t_0)) / sqrt((x + (x * 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_] := 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[(N[Sqrt[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(x + N[(x * x), $MachinePrecision]), $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{\frac{1}{\sqrt{x} + t_0}}{\sqrt{x + x \cdot x}}\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original20.0
Target0.7
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 40.7

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

      \[\leadsto \color{blue}{\left({x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\right) + \mathsf{fma}\left(-1, {\left(1 + x\right)}^{-0.5}, {\left(1 + x\right)}^{-0.5}\right)} \]
    3. Simplified40.6

      \[\leadsto \color{blue}{{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}} \]
      Proof
      (-.f64 (pow.f64 x -1/2) (pow.f64 (+.f64 1 x) -1/2)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= +-rgt-identity_binary64 (+.f64 (-.f64 (pow.f64 x -1/2) (pow.f64 (+.f64 1 x) -1/2)) 0)): 0 points increase in error, 0 points decrease in error
      (+.f64 (-.f64 (pow.f64 x -1/2) (pow.f64 (+.f64 1 x) -1/2)) (Rewrite<= mul0-lft_binary64 (*.f64 0 (pow.f64 (+.f64 1 x) -1/2)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (-.f64 (pow.f64 x -1/2) (pow.f64 (+.f64 1 x) -1/2)) (*.f64 (Rewrite<= metadata-eval (+.f64 -1 1)) (pow.f64 (+.f64 1 x) -1/2))): 0 points increase in error, 0 points decrease in error
      (+.f64 (-.f64 (pow.f64 x -1/2) (pow.f64 (+.f64 1 x) -1/2)) (Rewrite<= distribute-lft1-in_binary64 (+.f64 (*.f64 -1 (pow.f64 (+.f64 1 x) -1/2)) (pow.f64 (+.f64 1 x) -1/2)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (-.f64 (pow.f64 x -1/2) (pow.f64 (+.f64 1 x) -1/2)) (Rewrite<= fma-udef_binary64 (fma.f64 -1 (pow.f64 (+.f64 1 x) -1/2) (pow.f64 (+.f64 1 x) -1/2)))): 0 points increase in error, 0 points decrease in error
    4. Taylor expanded in x around inf 22.1

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{\frac{1}{{x}^{3}}}} \]
    5. Applied egg-rr40.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
      (pow.f64 x -3/2): 0 points increase in error, 0 points decrease in error
      (Rewrite<= +-rgt-identity_binary64 (+.f64 (pow.f64 x -3/2) 0)): 0 points increase in error, 0 points decrease in error
      (+.f64 (pow.f64 x -3/2) (Rewrite<= metadata-eval (-.f64 1 1))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate--l+_binary64 (-.f64 (+.f64 (pow.f64 x -3/2) 1) 1)): 95 points increase in error, 1 points decrease in error
      (-.f64 (Rewrite<= +-commutative_binary64 (+.f64 1 (pow.f64 x -3/2))) 1): 0 points increase in error, 0 points decrease in error

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

    1. Initial program 1.5

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

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

      \[\leadsto \color{blue}{\frac{\sqrt{1 + x} - \sqrt{x}}{\sqrt{x + x \cdot x}}} \]
      Proof
      (/.f64 (-.f64 (sqrt.f64 (+.f64 1 x)) (sqrt.f64 x)) (sqrt.f64 (+.f64 x (*.f64 x x)))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 (sqrt.f64 (+.f64 1 x)) (sqrt.f64 x)) (sqrt.f64 (+.f64 (Rewrite<= *-rgt-identity_binary64 (*.f64 x 1)) (*.f64 x x)))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 (sqrt.f64 (+.f64 1 x)) (sqrt.f64 x)) (sqrt.f64 (Rewrite<= distribute-lft-in_binary64 (*.f64 x (+.f64 1 x))))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= *-lft-identity_binary64 (*.f64 1 (-.f64 (sqrt.f64 (+.f64 1 x)) (sqrt.f64 x)))) (sqrt.f64 (*.f64 x (+.f64 1 x)))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 1 (sqrt.f64 (*.f64 x (+.f64 1 x)))) (-.f64 (sqrt.f64 (+.f64 1 x)) (sqrt.f64 x)))): 4 points increase in error, 1 points decrease in error
      (Rewrite<= associate-/r/_binary64 (/.f64 1 (/.f64 (sqrt.f64 (*.f64 x (+.f64 1 x))) (-.f64 (sqrt.f64 (+.f64 1 x)) (sqrt.f64 x))))): 3 points increase in error, 3 points decrease in error
    4. Applied egg-rr0.3

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

      \[\leadsto \frac{\color{blue}{\frac{1}{\sqrt{x} + \sqrt{x + 1}}}}{\sqrt{x + x \cdot x}} \]
      Proof
      (/.f64 1 (+.f64 (sqrt.f64 x) (sqrt.f64 (+.f64 x 1)))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= metadata-eval (-.f64 1 0)) (+.f64 (sqrt.f64 x) (sqrt.f64 (+.f64 x 1)))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 1 (Rewrite<= +-inverses_binary64 (-.f64 x x))) (+.f64 (sqrt.f64 x) (sqrt.f64 (+.f64 x 1)))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= associate-+l-_binary64 (+.f64 (-.f64 1 x) x)) (+.f64 (sqrt.f64 x) (sqrt.f64 (+.f64 x 1)))): 53 points increase in error, 75 points decrease in error
      (/.f64 (Rewrite<= +-commutative_binary64 (+.f64 x (-.f64 1 x))) (+.f64 (sqrt.f64 x) (sqrt.f64 (+.f64 x 1)))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= *-rgt-identity_binary64 (*.f64 (+.f64 x (-.f64 1 x)) 1)) (+.f64 (sqrt.f64 x) (sqrt.f64 (+.f64 x 1)))): 0 points increase in error, 0 points decrease in error
      (/.f64 (*.f64 (+.f64 x (-.f64 1 x)) 1) (Rewrite<= +-commutative_binary64 (+.f64 (sqrt.f64 (+.f64 x 1)) (sqrt.f64 x)))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-*r/_binary64 (*.f64 (+.f64 x (-.f64 1 x)) (/.f64 1 (+.f64 (sqrt.f64 (+.f64 x 1)) (sqrt.f64 x))))): 0 points increase in error, 0 points decrease in error
  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{\frac{1}{\sqrt{x} + \sqrt{1 + x}}}{\sqrt{x + x \cdot x}}\\ \end{array} \]

Alternatives

Alternative 1
Error0.2
Cost27204
\[\begin{array}{l} t_0 := \sqrt{1 + x}\\ \mathbf{if}\;\frac{1}{\sqrt{x}} - \frac{1}{t_0} \leq 5 \cdot 10^{-10}:\\ \;\;\;\;\frac{\frac{1}{\sqrt{x} + t_0}}{\left(x + 0.5\right) + \frac{-0.125}{x}}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\ \end{array} \]
Alternative 2
Error0.2
Cost26948
\[\begin{array}{l} t_0 := \sqrt{1 + x}\\ \mathbf{if}\;\frac{1}{\sqrt{x}} - \frac{1}{t_0} \leq 5 \cdot 10^{-10}:\\ \;\;\;\;\frac{\frac{1}{\sqrt{x} + t_0}}{x + 0.5}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\ \end{array} \]
Alternative 3
Error0.7
Cost26692
\[\begin{array}{l} \mathbf{if}\;\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{1 + x}} \leq 0:\\ \;\;\;\;0.5 \cdot {x}^{-1.5}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\ \end{array} \]
Alternative 4
Error1.0
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 5
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 6
Error1.1
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq 0.68:\\ \;\;\;\;{x}^{-0.5} + -1\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot {x}^{-1.5}\\ \end{array} \]
Alternative 7
Error31.4
Cost6528
\[{x}^{-0.5} \]

Error

Reproduce

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