Average Error: 19.8 → 0.0
Time: 17.4s
Precision: 64
\[0 \lt x \lt 1 \land y \lt 1\]
\[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
\[\frac{y + x}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{1}{\frac{\mathsf{hypot}\left(y, x\right)}{x - y}}\]
\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}
\frac{y + x}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{1}{\frac{\mathsf{hypot}\left(y, x\right)}{x - y}}
double f(double x, double y) {
        double r3426289 = x;
        double r3426290 = y;
        double r3426291 = r3426289 - r3426290;
        double r3426292 = r3426289 + r3426290;
        double r3426293 = r3426291 * r3426292;
        double r3426294 = r3426289 * r3426289;
        double r3426295 = r3426290 * r3426290;
        double r3426296 = r3426294 + r3426295;
        double r3426297 = r3426293 / r3426296;
        return r3426297;
}

double f(double x, double y) {
        double r3426298 = y;
        double r3426299 = x;
        double r3426300 = r3426298 + r3426299;
        double r3426301 = hypot(r3426299, r3426298);
        double r3426302 = r3426300 / r3426301;
        double r3426303 = 1.0;
        double r3426304 = hypot(r3426298, r3426299);
        double r3426305 = r3426299 - r3426298;
        double r3426306 = r3426304 / r3426305;
        double r3426307 = r3426303 / r3426306;
        double r3426308 = r3426302 * r3426307;
        return r3426308;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original19.8
Target0.0
Herbie0.0
\[\begin{array}{l} \mathbf{if}\;0.5 \lt \left|\frac{x}{y}\right| \lt 2:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{2}{1 + \frac{x}{y} \cdot \frac{x}{y}}\\ \end{array}\]

Derivation

  1. Initial program 19.8

    \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
  2. Simplified19.8

    \[\leadsto \color{blue}{\frac{\left(x + y\right) \cdot \left(x - y\right)}{\mathsf{fma}\left(y, y, x \cdot x\right)}}\]
  3. Using strategy rm
  4. Applied add-log-exp19.8

    \[\leadsto \color{blue}{\log \left(e^{\frac{\left(x + y\right) \cdot \left(x - y\right)}{\mathsf{fma}\left(y, y, x \cdot x\right)}}\right)}\]
  5. Using strategy rm
  6. Applied add-sqr-sqrt19.8

    \[\leadsto \log \left(e^{\frac{\left(x + y\right) \cdot \left(x - y\right)}{\color{blue}{\sqrt{\mathsf{fma}\left(y, y, x \cdot x\right)} \cdot \sqrt{\mathsf{fma}\left(y, y, x \cdot x\right)}}}}\right)\]
  7. Applied times-frac19.8

    \[\leadsto \log \left(e^{\color{blue}{\frac{x + y}{\sqrt{\mathsf{fma}\left(y, y, x \cdot x\right)}} \cdot \frac{x - y}{\sqrt{\mathsf{fma}\left(y, y, x \cdot x\right)}}}}\right)\]
  8. Applied exp-prod19.8

    \[\leadsto \log \color{blue}{\left({\left(e^{\frac{x + y}{\sqrt{\mathsf{fma}\left(y, y, x \cdot x\right)}}}\right)}^{\left(\frac{x - y}{\sqrt{\mathsf{fma}\left(y, y, x \cdot x\right)}}\right)}\right)}\]
  9. Applied log-pow19.8

    \[\leadsto \color{blue}{\frac{x - y}{\sqrt{\mathsf{fma}\left(y, y, x \cdot x\right)}} \cdot \log \left(e^{\frac{x + y}{\sqrt{\mathsf{fma}\left(y, y, x \cdot x\right)}}}\right)}\]
  10. Simplified19.8

    \[\leadsto \frac{x - y}{\sqrt{\mathsf{fma}\left(y, y, x \cdot x\right)}} \cdot \color{blue}{\frac{y + x}{\mathsf{hypot}\left(x, y\right)}}\]
  11. Using strategy rm
  12. Applied *-un-lft-identity19.8

    \[\leadsto \frac{\color{blue}{1 \cdot \left(x - y\right)}}{\sqrt{\mathsf{fma}\left(y, y, x \cdot x\right)}} \cdot \frac{y + x}{\mathsf{hypot}\left(x, y\right)}\]
  13. Applied associate-/l*19.8

    \[\leadsto \color{blue}{\frac{1}{\frac{\sqrt{\mathsf{fma}\left(y, y, x \cdot x\right)}}{x - y}}} \cdot \frac{y + x}{\mathsf{hypot}\left(x, y\right)}\]
  14. Simplified0.0

    \[\leadsto \frac{1}{\color{blue}{\frac{\mathsf{hypot}\left(y, x\right)}{x - y}}} \cdot \frac{y + x}{\mathsf{hypot}\left(x, y\right)}\]
  15. Final simplification0.0

    \[\leadsto \frac{y + x}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{1}{\frac{\mathsf{hypot}\left(y, x\right)}{x - y}}\]

Reproduce

herbie shell --seed 2019144 +o rules:numerics
(FPCore (x y)
  :name "Kahan p9 Example"
  :pre (and (< 0 x 1) (< y 1))

  :herbie-target
  (if (< 0.5 (fabs (/ x y)) 2) (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) (- 1 (/ 2 (+ 1 (* (/ x y) (/ x y))))))

  (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))