Average Error: 20.2 → 0.0
Time: 3.9s
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}\]
\[\log \left(e^{\frac{\left(x + y\right) \cdot \frac{x - y}{\mathsf{hypot}\left(x, y\right)}}{\mathsf{hypot}\left(x, y\right)}}\right)\]
\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}
\log \left(e^{\frac{\left(x + y\right) \cdot \frac{x - y}{\mathsf{hypot}\left(x, y\right)}}{\mathsf{hypot}\left(x, y\right)}}\right)
double f(double x, double y) {
        double r85243 = x;
        double r85244 = y;
        double r85245 = r85243 - r85244;
        double r85246 = r85243 + r85244;
        double r85247 = r85245 * r85246;
        double r85248 = r85243 * r85243;
        double r85249 = r85244 * r85244;
        double r85250 = r85248 + r85249;
        double r85251 = r85247 / r85250;
        return r85251;
}

double f(double x, double y) {
        double r85252 = x;
        double r85253 = y;
        double r85254 = r85252 + r85253;
        double r85255 = r85252 - r85253;
        double r85256 = hypot(r85252, r85253);
        double r85257 = r85255 / r85256;
        double r85258 = r85254 * r85257;
        double r85259 = r85258 / r85256;
        double r85260 = exp(r85259);
        double r85261 = log(r85260);
        return r85261;
}

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.2
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 20.2

    \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
  2. Using strategy rm
  3. Applied log1p-expm1-u20.2

    \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\right)\right)}\]
  4. Using strategy rm
  5. Applied log1p-udef20.2

    \[\leadsto \color{blue}{\log \left(1 + \mathsf{expm1}\left(\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\right)\right)}\]
  6. Using strategy rm
  7. Applied add-sqr-sqrt20.2

    \[\leadsto \log \left(1 + \mathsf{expm1}\left(\frac{\left(x - y\right) \cdot \left(x + y\right)}{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}}}\right)\right)\]
  8. Applied times-frac20.2

    \[\leadsto \log \left(1 + \mathsf{expm1}\left(\color{blue}{\frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}}\right)\right)\]
  9. Simplified20.2

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

    \[\leadsto \log \left(1 + \mathsf{expm1}\left(\frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \color{blue}{\frac{\frac{x + y}{1}}{\mathsf{hypot}\left(x, y\right)}}\right)\right)\]
  11. Using strategy rm
  12. Applied add-exp-log0.0

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

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

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

Reproduce

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