Average Error: 20.7 → 0.0
Time: 3.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{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{x + y}{\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{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{x + y}{\mathsf{hypot}\left(x, y\right)}}\right)
double f(double x, double y) {
        double r85409 = x;
        double r85410 = y;
        double r85411 = r85409 - r85410;
        double r85412 = r85409 + r85410;
        double r85413 = r85411 * r85412;
        double r85414 = r85409 * r85409;
        double r85415 = r85410 * r85410;
        double r85416 = r85414 + r85415;
        double r85417 = r85413 / r85416;
        return r85417;
}

double f(double x, double y) {
        double r85418 = x;
        double r85419 = y;
        double r85420 = r85418 - r85419;
        double r85421 = hypot(r85418, r85419);
        double r85422 = r85420 / r85421;
        double r85423 = r85418 + r85419;
        double r85424 = r85423 / r85421;
        double r85425 = r85422 * r85424;
        double r85426 = exp(r85425);
        double r85427 = log(r85426);
        return r85427;
}

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

    \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
  2. Using strategy rm
  3. Applied add-sqr-sqrt20.7

    \[\leadsto \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}}}\]
  4. Simplified20.7

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

    \[\leadsto \frac{\left(x - y\right) \cdot \left(x + y\right)}{\mathsf{hypot}\left(x, y\right) \cdot \color{blue}{\mathsf{hypot}\left(x, y\right)}}\]
  6. Using strategy rm
  7. Applied times-frac0.0

    \[\leadsto \color{blue}{\frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \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. Final simplification0.0

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

Reproduce

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