Average Error: 20.4 → 5.4
Time: 2.2s
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 -2.80898223204847208 \cdot 10^{153}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.1817900146375154 \cdot 10^{-146}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \mathbf{elif}\;y \le 4.78768032214213612 \cdot 10^{-164}:\\ \;\;\;\;\frac{x - y}{x - y}\\ \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 -2.80898223204847208 \cdot 10^{153}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;y \le 4.78768032214213612 \cdot 10^{-164}:\\
\;\;\;\;\frac{x - y}{x - y}\\

\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 r123077 = x;
        double r123078 = y;
        double r123079 = r123077 - r123078;
        double r123080 = r123077 + r123078;
        double r123081 = r123079 * r123080;
        double r123082 = r123077 * r123077;
        double r123083 = r123078 * r123078;
        double r123084 = r123082 + r123083;
        double r123085 = r123081 / r123084;
        return r123085;
}

double f(double x, double y) {
        double r123086 = y;
        double r123087 = -2.808982232048472e+153;
        bool r123088 = r123086 <= r123087;
        double r123089 = -1.0;
        double r123090 = -1.1817900146375154e-146;
        bool r123091 = r123086 <= r123090;
        double r123092 = x;
        double r123093 = r123092 - r123086;
        double r123094 = r123092 + r123086;
        double r123095 = r123093 * r123094;
        double r123096 = r123092 * r123092;
        double r123097 = r123086 * r123086;
        double r123098 = r123096 + r123097;
        double r123099 = r123095 / r123098;
        double r123100 = 4.787680322142136e-164;
        bool r123101 = r123086 <= r123100;
        double r123102 = r123093 / r123093;
        double r123103 = r123101 ? r123102 : r123099;
        double r123104 = r123091 ? r123099 : r123103;
        double r123105 = r123088 ? r123089 : r123104;
        return r123105;
}

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
Herbie5.4
\[\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 < -2.808982232048472e+153

    1. Initial program 63.7

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

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

    if -2.808982232048472e+153 < y < -1.1817900146375154e-146 or 4.787680322142136e-164 < y

    1. Initial program 0.2

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

    if -1.1817900146375154e-146 < y < 4.787680322142136e-164

    1. Initial program 28.9

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied associate-/l*29.9

      \[\leadsto \color{blue}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{x + y}}}\]
    4. Simplified29.9

      \[\leadsto \frac{x - y}{\color{blue}{\frac{{x}^{2} + {y}^{2}}{x + y}}}\]
    5. Taylor expanded around inf 15.9

      \[\leadsto \frac{x - y}{\color{blue}{x - y}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification5.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -2.80898223204847208 \cdot 10^{153}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.1817900146375154 \cdot 10^{-146}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \mathbf{elif}\;y \le 4.78768032214213612 \cdot 10^{-164}:\\ \;\;\;\;\frac{x - y}{x - y}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \end{array}\]

Reproduce

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