Average Error: 20.3 → 0.7
Time: 9.8s
Precision: binary64
Cost: 26240
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
\[\frac{1}{\mathsf{fma}\left(x, \sqrt{1 + x}, {x}^{1.5} + \sqrt{x}\right)} \]
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
(FPCore (x)
 :precision binary64
 (/ 1.0 (fma x (sqrt (+ 1.0 x)) (+ (pow x 1.5) (sqrt x)))))
double code(double x) {
	return (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
}
double code(double x) {
	return 1.0 / fma(x, sqrt((1.0 + x)), (pow(x, 1.5) + sqrt(x)));
}
function code(x)
	return Float64(Float64(1.0 / sqrt(x)) - Float64(1.0 / sqrt(Float64(x + 1.0))))
end
function code(x)
	return Float64(1.0 / fma(x, sqrt(Float64(1.0 + x)), Float64((x ^ 1.5) + sqrt(x))))
end
code[x_] := N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] - N[(1.0 / N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := N[(1.0 / N[(x * N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] + N[(N[Power[x, 1.5], $MachinePrecision] + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\frac{1}{\mathsf{fma}\left(x, \sqrt{1 + x}, {x}^{1.5} + \sqrt{x}\right)}

Error

Target

Original20.3
Target0.7
Herbie0.7
\[\frac{1}{\left(x + 1\right) \cdot \sqrt{x} + x \cdot \sqrt{x + 1}} \]

Derivation

  1. Initial program 20.3

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

    \[\leadsto \color{blue}{\left(\frac{1}{x} - \frac{1}{1 + x}\right) \cdot \frac{1}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}} \]
  3. Applied egg-rr5.7

    \[\leadsto \color{blue}{\frac{\frac{1 + \left(x - x\right)}{x}}{1 + x}} \cdot \frac{1}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}} \]
  4. Applied egg-rr22.8

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\frac{\frac{1}{x}}{1 + x}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}\right)} - 1} \]
  5. Simplified0.7

    \[\leadsto \color{blue}{\frac{1}{\mathsf{fma}\left(x, \sqrt{1 + x}, \left(1 + x\right) \cdot \sqrt{x}\right)}} \]
    Proof
    (/.f64 1 (fma.f64 x (sqrt.f64 (+.f64 1 x)) (*.f64 (+.f64 1 x) (sqrt.f64 x)))): 0 points increase in error, 0 points decrease in error
    (/.f64 1 (fma.f64 x (Rewrite<= unpow1/2_binary64 (pow.f64 (+.f64 1 x) 1/2)) (*.f64 (+.f64 1 x) (sqrt.f64 x)))): 0 points increase in error, 0 points decrease in error
    (/.f64 1 (fma.f64 x (pow.f64 (+.f64 1 x) (Rewrite<= metadata-eval (+.f64 -1/2 1))) (*.f64 (+.f64 1 x) (sqrt.f64 x)))): 0 points increase in error, 0 points decrease in error
    (/.f64 1 (fma.f64 x (Rewrite<= pow-plus_binary64 (*.f64 (pow.f64 (+.f64 1 x) -1/2) (+.f64 1 x))) (*.f64 (+.f64 1 x) (sqrt.f64 x)))): 7 points increase in error, 6 points decrease in error
    (/.f64 1 (fma.f64 x (Rewrite<= *-commutative_binary64 (*.f64 (+.f64 1 x) (pow.f64 (+.f64 1 x) -1/2))) (*.f64 (+.f64 1 x) (sqrt.f64 x)))): 0 points increase in error, 0 points decrease in error
    (/.f64 1 (fma.f64 x (*.f64 (+.f64 1 x) (pow.f64 (+.f64 1 x) -1/2)) (*.f64 (+.f64 1 x) (Rewrite<= unpow1/2_binary64 (pow.f64 x 1/2))))): 0 points increase in error, 0 points decrease in error
    (/.f64 1 (fma.f64 x (*.f64 (+.f64 1 x) (pow.f64 (+.f64 1 x) -1/2)) (*.f64 (+.f64 1 x) (pow.f64 x (Rewrite<= metadata-eval (+.f64 -1/2 1)))))): 0 points increase in error, 0 points decrease in error
    (/.f64 1 (fma.f64 x (*.f64 (+.f64 1 x) (pow.f64 (+.f64 1 x) -1/2)) (*.f64 (+.f64 1 x) (Rewrite<= pow-plus_binary64 (*.f64 (pow.f64 x -1/2) x))))): 46 points increase in error, 2 points decrease in error
    (/.f64 1 (fma.f64 x (*.f64 (+.f64 1 x) (pow.f64 (+.f64 1 x) -1/2)) (*.f64 (+.f64 1 x) (Rewrite<= *-commutative_binary64 (*.f64 x (pow.f64 x -1/2)))))): 0 points increase in error, 0 points decrease in error
    (/.f64 1 (fma.f64 x (*.f64 (+.f64 1 x) (pow.f64 (+.f64 1 x) -1/2)) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 (+.f64 1 x) x) (pow.f64 x -1/2))))): 42 points increase in error, 12 points decrease in error
    (/.f64 1 (fma.f64 x (*.f64 (+.f64 1 x) (pow.f64 (+.f64 1 x) -1/2)) (*.f64 (Rewrite<= *-commutative_binary64 (*.f64 x (+.f64 1 x))) (pow.f64 x -1/2)))): 0 points increase in error, 0 points decrease in error
    (/.f64 1 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 x (*.f64 (+.f64 1 x) (pow.f64 (+.f64 1 x) -1/2))) (*.f64 (*.f64 x (+.f64 1 x)) (pow.f64 x -1/2))))): 5 points increase in error, 4 points decrease in error
    (/.f64 1 (+.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 x (+.f64 1 x)) (pow.f64 (+.f64 1 x) -1/2))) (*.f64 (*.f64 x (+.f64 1 x)) (pow.f64 x -1/2)))): 4 points increase in error, 4 points decrease in error
    (/.f64 1 (Rewrite<= distribute-lft-in_binary64 (*.f64 (*.f64 x (+.f64 1 x)) (+.f64 (pow.f64 (+.f64 1 x) -1/2) (pow.f64 x -1/2))))): 2 points increase in error, 4 points decrease in error
    (/.f64 1 (*.f64 (*.f64 x (+.f64 1 x)) (Rewrite<= +-commutative_binary64 (+.f64 (pow.f64 x -1/2) (pow.f64 (+.f64 1 x) -1/2))))): 0 points increase in error, 0 points decrease in error
    (Rewrite=> associate-/r*_binary64 (/.f64 (/.f64 1 (*.f64 x (+.f64 1 x))) (+.f64 (pow.f64 x -1/2) (pow.f64 (+.f64 1 x) -1/2)))): 30 points increase in error, 31 points decrease in error
    (/.f64 (Rewrite=> associate-/r*_binary64 (/.f64 (/.f64 1 x) (+.f64 1 x))) (+.f64 (pow.f64 x -1/2) (pow.f64 (+.f64 1 x) -1/2))): 8 points increase in error, 22 points decrease in error
    (Rewrite<= expm1-log1p_binary64 (expm1.f64 (log1p.f64 (/.f64 (/.f64 (/.f64 1 x) (+.f64 1 x)) (+.f64 (pow.f64 x -1/2) (pow.f64 (+.f64 1 x) -1/2)))))): 114 points increase in error, 1 points decrease in error
    (Rewrite<= expm1-def_binary64 (-.f64 (exp.f64 (log1p.f64 (/.f64 (/.f64 (/.f64 1 x) (+.f64 1 x)) (+.f64 (pow.f64 x -1/2) (pow.f64 (+.f64 1 x) -1/2))))) 1)): 85 points increase in error, 7 points decrease in error
  6. Applied egg-rr0.7

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

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

Alternatives

Alternative 1
Error0.7
Cost19968
\[\frac{1}{\left({x}^{1.5} + \sqrt{x}\right) + x \cdot \sqrt{1 + x}} \]
Alternative 2
Error0.7
Cost19904
\[\frac{1}{\mathsf{fma}\left(x, \sqrt{1 + x}, \left(1 + x\right) \cdot \sqrt{x}\right)} \]
Alternative 3
Error0.8
Cost13760
\[\frac{1}{x \cdot \left(\left(1 + x\right) \cdot \left({x}^{-0.5} + {\left(1 + x\right)}^{-0.5}\right)\right)} \]
Alternative 4
Error0.4
Cost13760
\[\frac{\frac{1}{x}}{\left(1 + x\right) \cdot \left({x}^{-0.5} + {\left(1 + x\right)}^{-0.5}\right)} \]
Alternative 5
Error32.0
Cost13248
\[{x}^{-0.5} + {\left(1 + x\right)}^{-0.5} \]
Alternative 6
Error20.2
Cost13248
\[{x}^{-0.5} - {\left(1 + x\right)}^{-0.5} \]

Error

Reproduce

herbie shell --seed 2022334 
(FPCore (x)
  :name "2isqrt (example 3.6)"
  :precision binary64

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

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