Average Error: 19.5 → 0.0
Time: 18.6s
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{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{1}{\frac{\mathsf{hypot}\left(x, y\right)}{y + x}}\]
\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}
\frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{1}{\frac{\mathsf{hypot}\left(x, y\right)}{y + x}}
double f(double x, double y) {
        double r3414485 = x;
        double r3414486 = y;
        double r3414487 = r3414485 - r3414486;
        double r3414488 = r3414485 + r3414486;
        double r3414489 = r3414487 * r3414488;
        double r3414490 = r3414485 * r3414485;
        double r3414491 = r3414486 * r3414486;
        double r3414492 = r3414490 + r3414491;
        double r3414493 = r3414489 / r3414492;
        return r3414493;
}

double f(double x, double y) {
        double r3414494 = x;
        double r3414495 = y;
        double r3414496 = r3414494 - r3414495;
        double r3414497 = hypot(r3414494, r3414495);
        double r3414498 = r3414496 / r3414497;
        double r3414499 = 1.0;
        double r3414500 = r3414495 + r3414494;
        double r3414501 = r3414497 / r3414500;
        double r3414502 = r3414499 / r3414501;
        double r3414503 = r3414498 * r3414502;
        return r3414503;
}

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

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

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

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

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

    \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(x, x, y \cdot y\right)}}{x - y} \cdot \frac{\sqrt{\mathsf{fma}\left(x, x, y \cdot y\right)}}{y + x}}}\]
  8. Applied add-cube-cbrt19.5

    \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{\frac{\sqrt{\mathsf{fma}\left(x, x, y \cdot y\right)}}{x - y} \cdot \frac{\sqrt{\mathsf{fma}\left(x, x, y \cdot y\right)}}{y + x}}\]
  9. Applied times-frac19.5

    \[\leadsto \color{blue}{\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{\frac{\sqrt{\mathsf{fma}\left(x, x, y \cdot y\right)}}{x - y}} \cdot \frac{\sqrt[3]{1}}{\frac{\sqrt{\mathsf{fma}\left(x, x, y \cdot y\right)}}{y + x}}}\]
  10. Simplified19.5

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

    \[\leadsto \frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \color{blue}{\frac{y + x}{\mathsf{hypot}\left(x, y\right)}}\]
  12. Using strategy rm
  13. Applied clear-num0.0

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

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

Reproduce

herbie shell --seed 2019158 +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))))