Average Error: 20.4 → 0.0
Time: 18.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}\]
\[\mathsf{log1p}\left(\mathsf{expm1}\left(\log \left(e^{\frac{x + y}{\mathsf{hypot}\left(y, x\right)} \cdot \frac{x - y}{\mathsf{hypot}\left(y, x\right)}}\right)\right)\right)\]
\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}
\mathsf{log1p}\left(\mathsf{expm1}\left(\log \left(e^{\frac{x + y}{\mathsf{hypot}\left(y, x\right)} \cdot \frac{x - y}{\mathsf{hypot}\left(y, x\right)}}\right)\right)\right)
double f(double x, double y) {
        double r126624 = x;
        double r126625 = y;
        double r126626 = r126624 - r126625;
        double r126627 = r126624 + r126625;
        double r126628 = r126626 * r126627;
        double r126629 = r126624 * r126624;
        double r126630 = r126625 * r126625;
        double r126631 = r126629 + r126630;
        double r126632 = r126628 / r126631;
        return r126632;
}

double f(double x, double y) {
        double r126633 = x;
        double r126634 = y;
        double r126635 = r126633 + r126634;
        double r126636 = hypot(r126634, r126633);
        double r126637 = r126635 / r126636;
        double r126638 = r126633 - r126634;
        double r126639 = r126638 / r126636;
        double r126640 = r126637 * r126639;
        double r126641 = exp(r126640);
        double r126642 = log(r126641);
        double r126643 = expm1(r126642);
        double r126644 = log1p(r126643);
        return r126644;
}

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

    \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(x, x, y \cdot y\right)}}\]
  3. Using strategy rm
  4. Applied add-sqr-sqrt20.6

    \[\leadsto \left(x - y\right) \cdot \frac{x + y}{\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 *-un-lft-identity20.6

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

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

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

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

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

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

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

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

Reproduce

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