Average Error: 20.5 → 0.0
Time: 38.0s
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(\frac{\left(x + y\right) \cdot \left(\frac{x}{\mathsf{hypot}\left(y, x\right)} \cdot \left(\frac{x}{\mathsf{hypot}\left(y, x\right)} \cdot \frac{x}{\mathsf{hypot}\left(y, x\right)}\right) - \frac{y}{\mathsf{hypot}\left(y, x\right)} \cdot \left(\frac{y}{\mathsf{hypot}\left(y, x\right)} \cdot \frac{y}{\mathsf{hypot}\left(y, x\right)}\right)\right)}{\left(\left(\frac{y}{\mathsf{hypot}\left(y, x\right)} \cdot \frac{x}{\mathsf{hypot}\left(y, x\right)} + \frac{y}{\mathsf{hypot}\left(y, x\right)} \cdot \frac{y}{\mathsf{hypot}\left(y, x\right)}\right) + \frac{x}{\mathsf{hypot}\left(y, x\right)} \cdot \frac{x}{\mathsf{hypot}\left(y, x\right)}\right) \cdot \mathsf{hypot}\left(y, x\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(\frac{\left(x + y\right) \cdot \left(\frac{x}{\mathsf{hypot}\left(y, x\right)} \cdot \left(\frac{x}{\mathsf{hypot}\left(y, x\right)} \cdot \frac{x}{\mathsf{hypot}\left(y, x\right)}\right) - \frac{y}{\mathsf{hypot}\left(y, x\right)} \cdot \left(\frac{y}{\mathsf{hypot}\left(y, x\right)} \cdot \frac{y}{\mathsf{hypot}\left(y, x\right)}\right)\right)}{\left(\left(\frac{y}{\mathsf{hypot}\left(y, x\right)} \cdot \frac{x}{\mathsf{hypot}\left(y, x\right)} + \frac{y}{\mathsf{hypot}\left(y, x\right)} \cdot \frac{y}{\mathsf{hypot}\left(y, x\right)}\right) + \frac{x}{\mathsf{hypot}\left(y, x\right)} \cdot \frac{x}{\mathsf{hypot}\left(y, x\right)}\right) \cdot \mathsf{hypot}\left(y, x\right)}\right)\right)
double f(double x, double y) {
        double r4105128 = x;
        double r4105129 = y;
        double r4105130 = r4105128 - r4105129;
        double r4105131 = r4105128 + r4105129;
        double r4105132 = r4105130 * r4105131;
        double r4105133 = r4105128 * r4105128;
        double r4105134 = r4105129 * r4105129;
        double r4105135 = r4105133 + r4105134;
        double r4105136 = r4105132 / r4105135;
        return r4105136;
}

double f(double x, double y) {
        double r4105137 = x;
        double r4105138 = y;
        double r4105139 = r4105137 + r4105138;
        double r4105140 = hypot(r4105138, r4105137);
        double r4105141 = r4105137 / r4105140;
        double r4105142 = r4105141 * r4105141;
        double r4105143 = r4105141 * r4105142;
        double r4105144 = r4105138 / r4105140;
        double r4105145 = r4105144 * r4105144;
        double r4105146 = r4105144 * r4105145;
        double r4105147 = r4105143 - r4105146;
        double r4105148 = r4105139 * r4105147;
        double r4105149 = r4105144 * r4105141;
        double r4105150 = r4105149 + r4105145;
        double r4105151 = r4105150 + r4105142;
        double r4105152 = r4105151 * r4105140;
        double r4105153 = r4105148 / r4105152;
        double r4105154 = expm1(r4105153);
        double r4105155 = log1p(r4105154);
        return r4105155;
}

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

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

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

    \[\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. Using strategy rm
  6. Applied log1p-expm1-u20.5

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

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

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

    \[\leadsto \mathsf{log1p}\left(\mathsf{expm1}\left(\frac{y + x}{\mathsf{hypot}\left(y, x\right)} \cdot \color{blue}{\frac{{\left(\frac{x}{\mathsf{hypot}\left(y, x\right)}\right)}^{3} - {\left(\frac{y}{\mathsf{hypot}\left(y, x\right)}\right)}^{3}}{\frac{x}{\mathsf{hypot}\left(y, x\right)} \cdot \frac{x}{\mathsf{hypot}\left(y, x\right)} + \left(\frac{y}{\mathsf{hypot}\left(y, x\right)} \cdot \frac{y}{\mathsf{hypot}\left(y, x\right)} + \frac{x}{\mathsf{hypot}\left(y, x\right)} \cdot \frac{y}{\mathsf{hypot}\left(y, x\right)}\right)}}\right)\right)\]
  12. Applied frac-times0.0

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

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

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

Reproduce

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