Average Error: 20.3 → 0.1
Time: 24.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{\frac{x - y}{\mathsf{hypot}\left(y, x\right)}}{\log \left(e^{\frac{\mathsf{hypot}\left(y, x\right)}{y + x}}\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{\frac{x - y}{\mathsf{hypot}\left(y, x\right)}}{\log \left(e^{\frac{\mathsf{hypot}\left(y, x\right)}{y + x}}\right)}\right)\right)
double f(double x, double y) {
        double r2031848 = x;
        double r2031849 = y;
        double r2031850 = r2031848 - r2031849;
        double r2031851 = r2031848 + r2031849;
        double r2031852 = r2031850 * r2031851;
        double r2031853 = r2031848 * r2031848;
        double r2031854 = r2031849 * r2031849;
        double r2031855 = r2031853 + r2031854;
        double r2031856 = r2031852 / r2031855;
        return r2031856;
}

double f(double x, double y) {
        double r2031857 = x;
        double r2031858 = y;
        double r2031859 = r2031857 - r2031858;
        double r2031860 = hypot(r2031858, r2031857);
        double r2031861 = r2031859 / r2031860;
        double r2031862 = r2031858 + r2031857;
        double r2031863 = r2031860 / r2031862;
        double r2031864 = exp(r2031863);
        double r2031865 = log(r2031864);
        double r2031866 = r2031861 / r2031865;
        double r2031867 = log1p(r2031866);
        double r2031868 = expm1(r2031867);
        return r2031868;
}

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.3
Target0.0
Herbie0.1
\[\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.3

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

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

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

    \[\leadsto \color{blue}{\frac{x + y}{\sqrt{\mathsf{fma}\left(y, y, x \cdot x\right)}} \cdot \frac{x - y}{\sqrt{\mathsf{fma}\left(y, y, x \cdot x\right)}}}\]
  6. Using strategy rm
  7. Applied expm1-log1p-u20.6

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

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

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

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

Reproduce

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