Average Error: 29.9 → 0.2
Time: 7.3s
Precision: binary64
Cost: 26176
\[\sqrt{x + 1} - \sqrt{x} \]
\[\frac{1}{\mathsf{fma}\left({x}^{0.375}, {x}^{0.125}, \sqrt{1 + x}\right)} \]
(FPCore (x) :precision binary64 (- (sqrt (+ x 1.0)) (sqrt x)))
(FPCore (x)
 :precision binary64
 (/ 1.0 (fma (pow x 0.375) (pow x 0.125) (sqrt (+ 1.0 x)))))
double code(double x) {
	return sqrt((x + 1.0)) - sqrt(x);
}
double code(double x) {
	return 1.0 / fma(pow(x, 0.375), pow(x, 0.125), sqrt((1.0 + x)));
}
function code(x)
	return Float64(sqrt(Float64(x + 1.0)) - sqrt(x))
end
function code(x)
	return Float64(1.0 / fma((x ^ 0.375), (x ^ 0.125), sqrt(Float64(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[Power[x, 0.375], $MachinePrecision] * N[Power[x, 0.125], $MachinePrecision] + N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\sqrt{x + 1} - \sqrt{x}
\frac{1}{\mathsf{fma}\left({x}^{0.375}, {x}^{0.125}, \sqrt{1 + x}\right)}

Error

Target

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

Derivation

  1. Initial program 29.9

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

    \[\leadsto \color{blue}{\frac{x + \left(1 - x\right)}{\sqrt{x + 1} + \sqrt{x}}} \]
  3. Taylor expanded in x around 0 0.2

    \[\leadsto \frac{\color{blue}{1}}{\sqrt{x + 1} + \sqrt{x}} \]
  4. Applied egg-rr0.4

    \[\leadsto \frac{1}{\color{blue}{{\left(\mathsf{hypot}\left({x}^{0.25}, {\left(x + 1\right)}^{0.25}\right)\right)}^{2}}} \]
  5. Applied egg-rr0.2

    \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left({x}^{0.375}, {x}^{0.125}, \sqrt{x + 1}\right)}} \]
  6. Final simplification0.2

    \[\leadsto \frac{1}{\mathsf{fma}\left({x}^{0.375}, {x}^{0.125}, \sqrt{1 + x}\right)} \]

Alternatives

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

Error

Reproduce

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