?

Average Error: 30.1 → 0.3
Time: 9.4s
Precision: binary64
Cost: 26308

?

\[\sqrt{x + 1} - \sqrt{x} \]
\[\begin{array}{l} t_0 := \sqrt{1 + x} - \sqrt{x}\\ \mathbf{if}\;t_0 \leq 4 \cdot 10^{-5}:\\ \;\;\;\;0.5 \cdot {x}^{-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 4e-5) (* 0.5 (pow x -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 <= 4e-5) {
		tmp = 0.5 * pow(x, -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 <= 4d-5) then
        tmp = 0.5d0 * (x ** (-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 <= 4e-5) {
		tmp = 0.5 * Math.pow(x, -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 <= 4e-5:
		tmp = 0.5 * math.pow(x, -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 <= 4e-5)
		tmp = Float64(0.5 * (x ^ -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 <= 4e-5)
		tmp = 0.5 * (x ^ -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, 4e-5], N[(0.5 * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision], t$95$0]]
\sqrt{x + 1} - \sqrt{x}
\begin{array}{l}
t_0 := \sqrt{1 + x} - \sqrt{x}\\
\mathbf{if}\;t_0 \leq 4 \cdot 10^{-5}:\\
\;\;\;\;0.5 \cdot {x}^{-0.5}\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original30.1
Target0.2
Herbie0.3
\[\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.00000000000000033e-5

    1. Initial program 60.9

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

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

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{\frac{1}{x}}} \]
    4. Applied egg-rr59.2

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

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

      [Start]59.2

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

      +-commutative [=>]59.2

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

      associate--l+ [=>]0.4

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

      metadata-eval [=>]0.4

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

      +-rgt-identity [=>]0.4

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

      unpow-1 [<=]0.4

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

      metadata-eval [<=]0.4

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

      pow-sqr [<=]0.3

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

      rem-sqrt-square [=>]0.3

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

      sqr-pow [=>]0.8

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

      fabs-sqr [=>]0.8

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

      sqr-pow [<=]0.3

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

    if 4.00000000000000033e-5 < (-.f64 (sqrt.f64 (+.f64 x 1)) (sqrt.f64 x))

    1. Initial program 0.4

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

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

Alternatives

Alternative 1
Error0.2
Cost13248
\[\frac{1}{\sqrt{1 + x} + \sqrt{x}} \]
Alternative 2
Error1.0
Cost6980
\[\begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;1 + \left(x \cdot 0.5 - \sqrt{x}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot {x}^{-0.5}\\ \end{array} \]
Alternative 3
Error1.0
Cost6980
\[\begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;\left(1 + x \cdot 0.5\right) - \sqrt{x}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot {x}^{-0.5}\\ \end{array} \]
Alternative 4
Error1.4
Cost6852
\[\begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;\frac{1}{1 + \sqrt{x}}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot {x}^{-0.5}\\ \end{array} \]
Alternative 5
Error2.1
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq 0.31:\\ \;\;\;\;1 + x \cdot -2\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot {x}^{-0.5}\\ \end{array} \]
Alternative 6
Error31.5
Cost448
\[\frac{1}{x + \left(1 + x\right)} \]
Alternative 7
Error31.5
Cost64
\[1 \]

Error

Reproduce?

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