Average Error: 20.1 → 0.0
Time: 18.8s
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}\]
\[\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\frac{x + y}{\mathsf{hypot}\left(x, y\right)}}{\frac{\mathsf{hypot}\left(x, y\right)}{x - y}}\right)\right)\right)\right)\]
\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}
\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\frac{x + y}{\mathsf{hypot}\left(x, y\right)}}{\frac{\mathsf{hypot}\left(x, y\right)}{x - y}}\right)\right)\right)\right)
double f(double x, double y) {
        double r87535 = x;
        double r87536 = y;
        double r87537 = r87535 - r87536;
        double r87538 = r87535 + r87536;
        double r87539 = r87537 * r87538;
        double r87540 = r87535 * r87535;
        double r87541 = r87536 * r87536;
        double r87542 = r87540 + r87541;
        double r87543 = r87539 / r87542;
        return r87543;
}

double f(double x, double y) {
        double r87544 = x;
        double r87545 = y;
        double r87546 = r87544 + r87545;
        double r87547 = hypot(r87544, r87545);
        double r87548 = r87546 / r87547;
        double r87549 = r87544 - r87545;
        double r87550 = r87547 / r87549;
        double r87551 = r87548 / r87550;
        double r87552 = expm1(r87551);
        double r87553 = log1p(r87552);
        double r87554 = log1p(r87553);
        double r87555 = expm1(r87554);
        return r87555;
}

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

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

    \[\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.1

    \[\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.2

    \[\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.2

    \[\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{y + x}{\mathsf{hypot}\left(x, y\right)}}\]
  8. Using strategy rm
  9. Applied expm1-log1p-u0.0

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

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

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

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

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

Reproduce

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