Average Error: 20.4 → 0.0
Time: 26.8s
Precision: 64
\[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(\frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{x + y}{\mathsf{hypot}\left(x, y\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(\frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{x + y}{\mathsf{hypot}\left(x, y\right)}\right)\right)
double f(double x, double y) {
        double r1979914 = x;
        double r1979915 = y;
        double r1979916 = r1979914 - r1979915;
        double r1979917 = r1979914 + r1979915;
        double r1979918 = r1979916 * r1979917;
        double r1979919 = r1979914 * r1979914;
        double r1979920 = r1979915 * r1979915;
        double r1979921 = r1979919 + r1979920;
        double r1979922 = r1979918 / r1979921;
        return r1979922;
}

double f(double x, double y) {
        double r1979923 = x;
        double r1979924 = y;
        double r1979925 = r1979923 - r1979924;
        double r1979926 = hypot(r1979923, r1979924);
        double r1979927 = r1979925 / r1979926;
        double r1979928 = r1979923 + r1979924;
        double r1979929 = r1979928 / r1979926;
        double r1979930 = r1979927 * r1979929;
        double r1979931 = log1p(r1979930);
        double r1979932 = expm1(r1979931);
        return r1979932;
}

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. Using strategy rm
  3. Applied clear-num20.4

    \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}}\]
  4. Simplified20.4

    \[\leadsto \frac{1}{\color{blue}{\frac{\mathsf{fma}\left(x, x, y \cdot y\right)}{x \cdot x - y \cdot y}}}\]
  5. Using strategy rm
  6. Applied difference-of-squares20.4

    \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(x, x, y \cdot y\right)}{\color{blue}{\left(x + y\right) \cdot \left(x - y\right)}}}\]
  7. Applied add-sqr-sqrt20.4

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

    \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(x, x, y \cdot y\right)}}{x + y} \cdot \frac{\sqrt{\mathsf{fma}\left(x, x, y \cdot y\right)}}{x - y}}}\]
  9. Applied add-cube-cbrt20.4

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

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

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

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

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

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

Reproduce

herbie shell --seed 2019138 +o rules:numerics
(FPCore (x y)
  :name "Kahan p9 Example"
  :pre (and (< 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))))