?

Average Accuracy: 53.2% → 99.4%
Time: 7.9s
Precision: binary64
Cost: 26308

?

\[\sqrt{x + 1} - \sqrt{x} \]
\[\begin{array}{l} t_0 := \sqrt{1 + x} - \sqrt{x}\\ \mathbf{if}\;t_0 \leq 5 \cdot 10^{-7}:\\ \;\;\;\;{x}^{-0.5} \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
(FPCore (x) :precision binary64 (- (sqrt (+ x 1.0)) (sqrt x)))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (- (sqrt (+ 1.0 x)) (sqrt x))))
   (if (<= t_0 5e-7) (* (pow x -0.5) 0.5) t_0)))
double code(double x) {
	return sqrt((x + 1.0)) - sqrt(x);
}
double code(double x) {
	double t_0 = sqrt((1.0 + x)) - sqrt(x);
	double tmp;
	if (t_0 <= 5e-7) {
		tmp = pow(x, -0.5) * 0.5;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = sqrt((x + 1.0d0)) - sqrt(x)
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)) - sqrt(x)
    if (t_0 <= 5d-7) then
        tmp = (x ** (-0.5d0)) * 0.5d0
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x) {
	return Math.sqrt((x + 1.0)) - Math.sqrt(x);
}
public static double code(double x) {
	double t_0 = Math.sqrt((1.0 + x)) - Math.sqrt(x);
	double tmp;
	if (t_0 <= 5e-7) {
		tmp = Math.pow(x, -0.5) * 0.5;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x):
	return math.sqrt((x + 1.0)) - math.sqrt(x)
def code(x):
	t_0 = math.sqrt((1.0 + x)) - math.sqrt(x)
	tmp = 0
	if t_0 <= 5e-7:
		tmp = math.pow(x, -0.5) * 0.5
	else:
		tmp = t_0
	return tmp
function code(x)
	return Float64(sqrt(Float64(x + 1.0)) - sqrt(x))
end
function code(x)
	t_0 = Float64(sqrt(Float64(1.0 + x)) - sqrt(x))
	tmp = 0.0
	if (t_0 <= 5e-7)
		tmp = Float64((x ^ -0.5) * 0.5);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp = code(x)
	tmp = sqrt((x + 1.0)) - sqrt(x);
end
function tmp_2 = code(x)
	t_0 = sqrt((1.0 + x)) - sqrt(x);
	tmp = 0.0;
	if (t_0 <= 5e-7)
		tmp = (x ^ -0.5) * 0.5;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_] := N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
code[x_] := Block[{t$95$0 = N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 5e-7], N[(N[Power[x, -0.5], $MachinePrecision] * 0.5), $MachinePrecision], t$95$0]]
\sqrt{x + 1} - \sqrt{x}
\begin{array}{l}
t_0 := \sqrt{1 + x} - \sqrt{x}\\
\mathbf{if}\;t_0 \leq 5 \cdot 10^{-7}:\\
\;\;\;\;{x}^{-0.5} \cdot 0.5\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original53.2%
Target99.7%
Herbie99.4%
\[\frac{1}{\sqrt{x + 1} + \sqrt{x}} \]

Derivation?

  1. Split input into 2 regimes
  2. if (-.f64 (sqrt.f64 (+.f64 x 1)) (sqrt.f64 x)) < 4.99999999999999977e-7

    1. Initial program 4.1%

      \[\sqrt{x + 1} - \sqrt{x} \]
    2. Applied egg-rr2.7%

      \[\leadsto \color{blue}{\frac{{\left(x + 1\right)}^{1.5} - {x}^{1.5}}{\left(\left(x + 1\right) + x\right) + \sqrt{\left(x + 1\right) \cdot x}}} \]
      Step-by-step derivation

      [Start]4.1

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

      flip3-- [=>]2.7

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

      sqrt-pow2 [=>]3.3

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

      metadata-eval [=>]3.3

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

      sqrt-pow2 [=>]2.7

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

      metadata-eval [=>]2.7

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

      add-sqr-sqrt [<=]2.7

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

      add-sqr-sqrt [<=]2.7

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

      associate-+r+ [=>]2.7

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

      sqrt-unprod [=>]2.7

      \[ \frac{{\left(x + 1\right)}^{1.5} - {x}^{1.5}}{\left(\left(x + 1\right) + x\right) + \color{blue}{\sqrt{\left(x + 1\right) \cdot x}}} \]
    3. Taylor expanded in x around inf 99.6%

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{\frac{1}{x}}} \]
    4. Simplified99.6%

      \[\leadsto \color{blue}{\sqrt{\frac{1}{x}} \cdot 0.5} \]
      Step-by-step derivation

      [Start]99.6

      \[ 0.5 \cdot \sqrt{\frac{1}{x}} \]

      *-commutative [=>]99.6

      \[ \color{blue}{\sqrt{\frac{1}{x}} \cdot 0.5} \]
    5. Applied egg-rr7.3%

      \[\leadsto \color{blue}{\left(\left(1 + {x}^{-0.5}\right) - 1\right)} \cdot 0.5 \]
      Step-by-step derivation

      [Start]99.6

      \[ \sqrt{\frac{1}{x}} \cdot 0.5 \]

      expm1-log1p-u [=>]99.6

      \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{\frac{1}{x}}\right)\right)} \cdot 0.5 \]

      expm1-udef [=>]7.3

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

      log1p-udef [=>]7.3

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

      add-exp-log [<=]7.3

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

      inv-pow [=>]7.3

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

      sqrt-pow1 [=>]7.3

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

      metadata-eval [=>]7.3

      \[ \left(\left(1 + {x}^{\color{blue}{-0.5}}\right) - 1\right) \cdot 0.5 \]
    6. Simplified99.9%

      \[\leadsto \color{blue}{{x}^{-0.5}} \cdot 0.5 \]
      Step-by-step derivation

      [Start]7.3

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

      +-commutative [=>]7.3

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

      associate--l+ [=>]99.9

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

      metadata-eval [=>]99.9

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

      +-rgt-identity [=>]99.9

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

    if 4.99999999999999977e-7 < (-.f64 (sqrt.f64 (+.f64 x 1)) (sqrt.f64 x))

    1. Initial program 99.7%

      \[\sqrt{x + 1} - \sqrt{x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sqrt{1 + x} - \sqrt{x} \leq 5 \cdot 10^{-7}:\\ \;\;\;\;{x}^{-0.5} \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\sqrt{1 + x} - \sqrt{x}\\ \end{array} \]

Alternatives

Alternative 1
Accuracy99.7%
Cost13248
\[\frac{1}{\sqrt{1 + x} + \sqrt{x}} \]
Alternative 2
Accuracy96.9%
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq 0.25:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} \cdot 0.5\\ \end{array} \]
Alternative 3
Accuracy96.7%
Cost6724
\[\begin{array}{l} \mathbf{if}\;x \leq 0.25:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{\sqrt{x}}\\ \end{array} \]
Alternative 4
Accuracy51.2%
Cost64
\[1 \]

Error

Reproduce?

herbie shell --seed 2023157 
(FPCore (x)
  :name "Main:bigenough3 from C"
  :precision binary64

  :herbie-target
  (/ 1.0 (+ (sqrt (+ x 1.0)) (sqrt x)))

  (- (sqrt (+ x 1.0)) (sqrt x)))