Average Error: 20.0 → 0.0
Time: 16.4s
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{\frac{1}{\frac{\mathsf{hypot}\left(x, y\right)}{y + x}} \cdot \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{\frac{1}{\frac{\mathsf{hypot}\left(x, y\right)}{y + x}} \cdot \left(x - y\right)}{\mathsf{hypot}\left(x, y\right)}}\right)
double f(double x, double y) {
        double r57394 = x;
        double r57395 = y;
        double r57396 = r57394 - r57395;
        double r57397 = r57394 + r57395;
        double r57398 = r57396 * r57397;
        double r57399 = r57394 * r57394;
        double r57400 = r57395 * r57395;
        double r57401 = r57399 + r57400;
        double r57402 = r57398 / r57401;
        return r57402;
}

double f(double x, double y) {
        double r57403 = 1.0;
        double r57404 = x;
        double r57405 = y;
        double r57406 = hypot(r57404, r57405);
        double r57407 = r57405 + r57404;
        double r57408 = r57406 / r57407;
        double r57409 = r57403 / r57408;
        double r57410 = r57404 - r57405;
        double r57411 = r57409 * r57410;
        double r57412 = r57411 / r57406;
        double r57413 = exp(r57412);
        double r57414 = log(r57413);
        return r57414;
}

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.0
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.0

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

    \[\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 add-sqr-sqrt20.0

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

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

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

    \[\leadsto \frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \color{blue}{\frac{x + y}{\mathsf{hypot}\left(x, y\right)}}\]
  8. Using strategy rm
  9. Applied add-log-exp0.0

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

    \[\leadsto \log \color{blue}{\left({\left(e^{\frac{y + x}{\mathsf{hypot}\left(x, y\right)}}\right)}^{\left(\frac{x - y}{\mathsf{hypot}\left(x, y\right)}\right)}\right)}\]
  11. Using strategy rm
  12. Applied pow-exp0.0

    \[\leadsto \log \color{blue}{\left(e^{\frac{y + x}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{x - y}{\mathsf{hypot}\left(x, y\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. Using strategy rm
  15. Applied clear-num0.0

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

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

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

Reproduce

herbie shell --seed 2019194 +o rules:numerics
(FPCore (x y)
  :name "Kahan p9 Example"
  :pre (and (< 0.0 x 1.0) (< y 1.0))

  :herbie-target
  (if (< 0.5 (fabs (/ x y)) 2.0) (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) (- 1.0 (/ 2.0 (+ 1.0 (* (/ x y) (/ x y))))))

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