Average Error: 20.4 → 0.0
Time: 8.6s
Precision: 64
\[0.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{1}{\frac{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}}{\frac{x - y}{\mathsf{hypot}\left(x, y\right)}}}\]
\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}
\frac{1}{\frac{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}}{\frac{x - y}{\mathsf{hypot}\left(x, y\right)}}}
double f(double x, double y) {
        double r156151 = x;
        double r156152 = y;
        double r156153 = r156151 - r156152;
        double r156154 = r156151 + r156152;
        double r156155 = r156153 * r156154;
        double r156156 = r156151 * r156151;
        double r156157 = r156152 * r156152;
        double r156158 = r156156 + r156157;
        double r156159 = r156155 / r156158;
        return r156159;
}

double f(double x, double y) {
        double r156160 = 1.0;
        double r156161 = x;
        double r156162 = y;
        double r156163 = hypot(r156161, r156162);
        double r156164 = r156161 + r156162;
        double r156165 = r156163 / r156164;
        double r156166 = r156161 - r156162;
        double r156167 = r156166 / r156163;
        double r156168 = r156165 / r156167;
        double r156169 = r156160 / r156168;
        return r156169;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original20.4
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 20.4

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

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

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

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

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

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

    \[\leadsto \frac{x - y}{\mathsf{hypot}\left(x, y\right) \cdot \color{blue}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}}}\]
  9. Using strategy rm
  10. Applied log1p-expm1-u0.1

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

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

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

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

Reproduce

herbie shell --seed 2020033 +o rules:numerics
(FPCore (x y)
  :name "Kahan p9 Example"
  :precision binary64
  :pre (and (< 0.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))))