Average Error: 29.7 → 0.2
Time: 11.0s
Precision: binary64
Cost: 13248
\[\sqrt{x + 1} - \sqrt{x} \]
\[\frac{1}{\sqrt{x} + \sqrt{1 + x}} \]
(FPCore (x) :precision binary64 (- (sqrt (+ x 1.0)) (sqrt x)))
(FPCore (x) :precision binary64 (/ 1.0 (+ (sqrt x) (sqrt (+ 1.0 x)))))
double code(double x) {
	return sqrt((x + 1.0)) - sqrt(x);
}
double code(double x) {
	return 1.0 / (sqrt(x) + sqrt((1.0 + x)));
}
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 = 1.0d0 / (sqrt(x) + sqrt((1.0d0 + x)))
end function
public static double code(double x) {
	return Math.sqrt((x + 1.0)) - Math.sqrt(x);
}
public static double code(double x) {
	return 1.0 / (Math.sqrt(x) + Math.sqrt((1.0 + x)));
}
def code(x):
	return math.sqrt((x + 1.0)) - math.sqrt(x)
def code(x):
	return 1.0 / (math.sqrt(x) + math.sqrt((1.0 + x)))
function code(x)
	return Float64(sqrt(Float64(x + 1.0)) - sqrt(x))
end
function code(x)
	return Float64(1.0 / Float64(sqrt(x) + sqrt(Float64(1.0 + x))))
end
function tmp = code(x)
	tmp = sqrt((x + 1.0)) - sqrt(x);
end
function tmp = code(x)
	tmp = 1.0 / (sqrt(x) + sqrt((1.0 + x)));
end
code[x_] := N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
code[x_] := N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\sqrt{x + 1} - \sqrt{x}
\frac{1}{\sqrt{x} + \sqrt{1 + x}}

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.1

    \[\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

    [Start]29.1

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

    *-commutative [=>]29.1

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

    associate-*l/ [=>]29.1

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

    *-lft-identity [=>]29.1

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

    +-commutative [=>]29.1

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

    associate-+l- [=>]0.2

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

    +-inverses [=>]0.2

    \[ \frac{1 - \color{blue}{0}}{\sqrt{x + 1} + \sqrt{x}} \]

    metadata-eval [=>]0.2

    \[ \frac{\color{blue}{1}}{\sqrt{x + 1} + \sqrt{x}} \]

    +-commutative [=>]0.2

    \[ \frac{1}{\sqrt{\color{blue}{1 + x}} + \sqrt{x}} \]
  4. Final simplification0.2

    \[\leadsto \frac{1}{\sqrt{x} + \sqrt{1 + x}} \]

Alternatives

Alternative 1
Error0.3
Cost26308
\[\begin{array}{l} t_0 := \sqrt{1 + x} - \sqrt{x}\\ \mathbf{if}\;t_0 \leq 2 \cdot 10^{-5}:\\ \;\;\;\;0.5 \cdot {x}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error0.9
Cost7620
\[\begin{array}{l} t_0 := 1 + x \cdot 0.25\\ \mathbf{if}\;x \leq 0.84:\\ \;\;\;\;t_0 + \left(\left(x \cdot 0.25\right) \cdot t_0 - \sqrt{x}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot {x}^{-0.5}\\ \end{array} \]
Alternative 3
Error0.9
Cost7236
\[\begin{array}{l} \mathbf{if}\;x \leq 2.4:\\ \;\;\;\;\frac{1}{\left(2 + \left(\sqrt{x} + x \cdot 0.5\right)\right) + -1}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot {x}^{-0.5}\\ \end{array} \]
Alternative 4
Error0.9
Cost7108
\[\begin{array}{l} \mathbf{if}\;x \leq 2.4:\\ \;\;\;\;\frac{1}{x \cdot 0.5 + \left(1 + \sqrt{x}\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot {x}^{-0.5}\\ \end{array} \]
Alternative 5
Error1.3
Cost6980
\[\begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;\frac{1 - \sqrt{x}}{1 - x}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot {x}^{-0.5}\\ \end{array} \]
Alternative 6
Error1.3
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 7
Error2.0
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq 0.25:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot {x}^{-0.5}\\ \end{array} \]
Alternative 8
Error31.0
Cost64
\[1 \]

Error

Reproduce

herbie shell --seed 2023011 
(FPCore (x)
  :name "2sqrt (example 3.1)"
  :precision binary64

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

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