Average Error: 29.7 → 0.2
Time: 5.6s
Precision: binary64
Cost: 26048
\[\sqrt{x + 1} - \sqrt{x} \]
\[{\left({\left(\sqrt{1 + x} + \sqrt{x}\right)}^{2}\right)}^{-0.5} \]
(FPCore (x) :precision binary64 (- (sqrt (+ x 1.0)) (sqrt x)))
(FPCore (x)
 :precision binary64
 (pow (pow (+ (sqrt (+ 1.0 x)) (sqrt x)) 2.0) -0.5))
double code(double x) {
	return sqrt((x + 1.0)) - sqrt(x);
}
double code(double x) {
	return pow(pow((sqrt((1.0 + x)) + sqrt(x)), 2.0), -0.5);
}
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
    code = ((sqrt((1.0d0 + x)) + sqrt(x)) ** 2.0d0) ** (-0.5d0)
end function
public static double code(double x) {
	return Math.sqrt((x + 1.0)) - Math.sqrt(x);
}
public static double code(double x) {
	return Math.pow(Math.pow((Math.sqrt((1.0 + x)) + Math.sqrt(x)), 2.0), -0.5);
}
def code(x):
	return math.sqrt((x + 1.0)) - math.sqrt(x)
def code(x):
	return math.pow(math.pow((math.sqrt((1.0 + x)) + math.sqrt(x)), 2.0), -0.5)
function code(x)
	return Float64(sqrt(Float64(x + 1.0)) - sqrt(x))
end
function code(x)
	return (Float64(sqrt(Float64(1.0 + x)) + sqrt(x)) ^ 2.0) ^ -0.5
end
function tmp = code(x)
	tmp = sqrt((x + 1.0)) - sqrt(x);
end
function tmp = code(x)
	tmp = ((sqrt((1.0 + x)) + sqrt(x)) ^ 2.0) ^ -0.5;
end
code[x_] := N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
code[x_] := N[Power[N[Power[N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] + N[Sqrt[x], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], -0.5], $MachinePrecision]
\sqrt{x + 1} - \sqrt{x}
{\left({\left(\sqrt{1 + x} + \sqrt{x}\right)}^{2}\right)}^{-0.5}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original29.7
Target0.2
Herbie0.2
\[\frac{1}{\sqrt{x + 1} + \sqrt{x}} \]

Derivation

  1. Initial program 29.7

    \[\sqrt{x + 1} - \sqrt{x} \]
  2. Applied egg-rr29.0

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

    \[\leadsto \color{blue}{\frac{1}{\sqrt{1 + x} + \sqrt{x}}} \]
    Proof
    (/.f64 1 (+.f64 (sqrt.f64 (+.f64 1 x)) (sqrt.f64 x))): 0 points increase in error, 0 points decrease in error
    (/.f64 (Rewrite<= metadata-eval (+.f64 1 0)) (+.f64 (sqrt.f64 (+.f64 1 x)) (sqrt.f64 x))): 0 points increase in error, 0 points decrease in error
    (/.f64 (+.f64 1 (Rewrite<= +-inverses_binary64 (-.f64 x x))) (+.f64 (sqrt.f64 (+.f64 1 x)) (sqrt.f64 x))): 0 points increase in error, 0 points decrease in error
    (/.f64 (Rewrite<= associate--l+_binary64 (-.f64 (+.f64 1 x) x)) (+.f64 (sqrt.f64 (+.f64 1 x)) (sqrt.f64 x))): 107 points increase in error, 0 points decrease in error
    (/.f64 (-.f64 (Rewrite<= +-commutative_binary64 (+.f64 x 1)) x) (+.f64 (sqrt.f64 (+.f64 1 x)) (sqrt.f64 x))): 0 points increase in error, 0 points decrease in error
    (/.f64 (-.f64 (+.f64 x 1) (Rewrite<= rem-square-sqrt_binary64 (*.f64 (sqrt.f64 x) (sqrt.f64 x)))) (+.f64 (sqrt.f64 (+.f64 1 x)) (sqrt.f64 x))): 36 points increase in error, 16 points decrease in error
    (/.f64 (-.f64 (+.f64 x 1) (Rewrite<= sqr-neg_binary64 (*.f64 (neg.f64 (sqrt.f64 x)) (neg.f64 (sqrt.f64 x))))) (+.f64 (sqrt.f64 (+.f64 1 x)) (sqrt.f64 x))): 0 points increase in error, 0 points decrease in error
    (/.f64 (-.f64 (+.f64 x 1) (*.f64 (neg.f64 (sqrt.f64 x)) (neg.f64 (sqrt.f64 x)))) (+.f64 (sqrt.f64 (Rewrite<= +-commutative_binary64 (+.f64 x 1))) (sqrt.f64 x))): 0 points increase in error, 0 points decrease in error
    (/.f64 (-.f64 (+.f64 x 1) (*.f64 (neg.f64 (sqrt.f64 x)) (neg.f64 (sqrt.f64 x)))) (+.f64 (sqrt.f64 (+.f64 x 1)) (Rewrite<= remove-double-neg_binary64 (neg.f64 (neg.f64 (sqrt.f64 x)))))): 0 points increase in error, 0 points decrease in error
    (/.f64 (-.f64 (+.f64 x 1) (*.f64 (neg.f64 (sqrt.f64 x)) (neg.f64 (sqrt.f64 x)))) (Rewrite<= sub-neg_binary64 (-.f64 (sqrt.f64 (+.f64 x 1)) (neg.f64 (sqrt.f64 x))))): 0 points increase in error, 0 points decrease in error
    (Rewrite=> div-sub_binary64 (-.f64 (/.f64 (+.f64 x 1) (-.f64 (sqrt.f64 (+.f64 x 1)) (neg.f64 (sqrt.f64 x)))) (/.f64 (*.f64 (neg.f64 (sqrt.f64 x)) (neg.f64 (sqrt.f64 x))) (-.f64 (sqrt.f64 (+.f64 x 1)) (neg.f64 (sqrt.f64 x)))))): 35 points increase in error, 25 points decrease in error
    (-.f64 (/.f64 (+.f64 x 1) (-.f64 (sqrt.f64 (+.f64 x 1)) (neg.f64 (sqrt.f64 x)))) (/.f64 (Rewrite=> sqr-neg_binary64 (*.f64 (sqrt.f64 x) (sqrt.f64 x))) (-.f64 (sqrt.f64 (+.f64 x 1)) (neg.f64 (sqrt.f64 x))))): 0 points increase in error, 0 points decrease in error
    (-.f64 (/.f64 (+.f64 x 1) (-.f64 (sqrt.f64 (+.f64 x 1)) (neg.f64 (sqrt.f64 x)))) (/.f64 (Rewrite=> rem-square-sqrt_binary64 x) (-.f64 (sqrt.f64 (+.f64 x 1)) (neg.f64 (sqrt.f64 x))))): 16 points increase in error, 34 points decrease in error
    (Rewrite<= div-sub_binary64 (/.f64 (-.f64 (+.f64 x 1) x) (-.f64 (sqrt.f64 (+.f64 x 1)) (neg.f64 (sqrt.f64 x))))): 1 points increase in error, 11 points decrease in error
    (/.f64 (-.f64 (+.f64 x 1) x) (Rewrite=> sub-neg_binary64 (+.f64 (sqrt.f64 (+.f64 x 1)) (neg.f64 (neg.f64 (sqrt.f64 x)))))): 0 points increase in error, 0 points decrease in error
    (/.f64 (-.f64 (+.f64 x 1) x) (+.f64 (sqrt.f64 (+.f64 x 1)) (Rewrite=> remove-double-neg_binary64 (sqrt.f64 x)))): 0 points increase in error, 0 points decrease in error
    (/.f64 (Rewrite<= associate-+r-_binary64 (+.f64 x (-.f64 1 x))) (+.f64 (sqrt.f64 (+.f64 x 1)) (sqrt.f64 x))): 0 points increase in error, 2 points decrease in error
    (/.f64 (Rewrite<= *-rgt-identity_binary64 (*.f64 (+.f64 x (-.f64 1 x)) 1)) (+.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
  4. Applied egg-rr0.2

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

    \[\leadsto \color{blue}{{\left({\left(\sqrt{1 + x} + \sqrt{x}\right)}^{2}\right)}^{-0.5}} \]
  6. Final simplification0.2

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

Alternatives

Alternative 1
Error0.3
Cost13252
\[\begin{array}{l} \mathbf{if}\;x \leq 59000000:\\ \;\;\;\;\sqrt{1 + x} - \sqrt{x}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot {x}^{-0.5}\\ \end{array} \]
Alternative 2
Error0.2
Cost13248
\[\frac{1}{\sqrt{1 + x} + \sqrt{x}} \]
Alternative 3
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 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.25:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot {x}^{-0.5}\\ \end{array} \]
Alternative 6
Error31.1
Cost64
\[1 \]

Error

Reproduce

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