Average Error: 20.6 → 5.7
Time: 8.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}\]
\[\begin{array}{l} \mathbf{if}\;y \le -4.180993516479930184353022703940201658048 \cdot 10^{152}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -5.039947627179522745962986651517339206836 \cdot 10^{-162}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \mathbf{elif}\;y \le 2.881049684470391573094051391443920012389 \cdot 10^{-221}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 1.729127969171910189982886028946831796286 \cdot 10^{-195}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \end{array}\]
\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}
\begin{array}{l}
\mathbf{if}\;y \le -4.180993516479930184353022703940201658048 \cdot 10^{152}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -5.039947627179522745962986651517339206836 \cdot 10^{-162}:\\
\;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\

\mathbf{elif}\;y \le 2.881049684470391573094051391443920012389 \cdot 10^{-221}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \le 1.729127969171910189982886028946831796286 \cdot 10^{-195}:\\
\;\;\;\;-1\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\

\end{array}
double f(double x, double y) {
        double r54567 = x;
        double r54568 = y;
        double r54569 = r54567 - r54568;
        double r54570 = r54567 + r54568;
        double r54571 = r54569 * r54570;
        double r54572 = r54567 * r54567;
        double r54573 = r54568 * r54568;
        double r54574 = r54572 + r54573;
        double r54575 = r54571 / r54574;
        return r54575;
}

double f(double x, double y) {
        double r54576 = y;
        double r54577 = -4.18099351647993e+152;
        bool r54578 = r54576 <= r54577;
        double r54579 = -1.0;
        double r54580 = -5.039947627179523e-162;
        bool r54581 = r54576 <= r54580;
        double r54582 = x;
        double r54583 = r54582 - r54576;
        double r54584 = r54582 + r54576;
        double r54585 = r54583 * r54584;
        double r54586 = r54582 * r54582;
        double r54587 = r54576 * r54576;
        double r54588 = r54586 + r54587;
        double r54589 = r54585 / r54588;
        double r54590 = 2.8810496844703916e-221;
        bool r54591 = r54576 <= r54590;
        double r54592 = 1.0;
        double r54593 = 1.72912796917191e-195;
        bool r54594 = r54576 <= r54593;
        double r54595 = r54594 ? r54579 : r54589;
        double r54596 = r54591 ? r54592 : r54595;
        double r54597 = r54581 ? r54589 : r54596;
        double r54598 = r54578 ? r54579 : r54597;
        return r54598;
}

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.6
Target0.1
Herbie5.7
\[\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. Split input into 3 regimes
  2. if y < -4.18099351647993e+152 or 2.8810496844703916e-221 < y < 1.72912796917191e-195

    1. Initial program 59.5

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Taylor expanded around 0 5.1

      \[\leadsto \color{blue}{-1}\]

    if -4.18099351647993e+152 < y < -5.039947627179523e-162 or 1.72912796917191e-195 < y

    1. Initial program 2.2

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]

    if -5.039947627179523e-162 < y < 2.8810496844703916e-221

    1. Initial program 30.7

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Taylor expanded around inf 13.9

      \[\leadsto \color{blue}{1}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification5.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -4.180993516479930184353022703940201658048 \cdot 10^{152}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -5.039947627179522745962986651517339206836 \cdot 10^{-162}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \mathbf{elif}\;y \le 2.881049684470391573094051391443920012389 \cdot 10^{-221}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 1.729127969171910189982886028946831796286 \cdot 10^{-195}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \end{array}\]

Reproduce

herbie shell --seed 2019291 
(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))))