Average Error: 20.0 → 5.2
Time: 7.4s
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 -6.379960110729305952978237513299639776117 \cdot 10^{150}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.501676546694868344414885960149825649924 \cdot 10^{-155}:\\ \;\;\;\;-\frac{y \cdot y - x \cdot x}{x \cdot x + y \cdot y}\\ \mathbf{elif}\;y \le 1.665640808899109568529030107036989846971 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-\frac{y \cdot y - x \cdot x}{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 -6.379960110729305952978237513299639776117 \cdot 10^{150}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -1.501676546694868344414885960149825649924 \cdot 10^{-155}:\\
\;\;\;\;-\frac{y \cdot y - x \cdot x}{x \cdot x + y \cdot y}\\

\mathbf{elif}\;y \le 1.665640808899109568529030107036989846971 \cdot 10^{-162}:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;-\frac{y \cdot y - x \cdot x}{x \cdot x + y \cdot y}\\

\end{array}
double f(double x, double y) {
        double r5803127 = x;
        double r5803128 = y;
        double r5803129 = r5803127 - r5803128;
        double r5803130 = r5803127 + r5803128;
        double r5803131 = r5803129 * r5803130;
        double r5803132 = r5803127 * r5803127;
        double r5803133 = r5803128 * r5803128;
        double r5803134 = r5803132 + r5803133;
        double r5803135 = r5803131 / r5803134;
        return r5803135;
}

double f(double x, double y) {
        double r5803136 = y;
        double r5803137 = -6.379960110729306e+150;
        bool r5803138 = r5803136 <= r5803137;
        double r5803139 = -1.0;
        double r5803140 = -1.5016765466948683e-155;
        bool r5803141 = r5803136 <= r5803140;
        double r5803142 = r5803136 * r5803136;
        double r5803143 = x;
        double r5803144 = r5803143 * r5803143;
        double r5803145 = r5803142 - r5803144;
        double r5803146 = r5803144 + r5803142;
        double r5803147 = r5803145 / r5803146;
        double r5803148 = -r5803147;
        double r5803149 = 1.6656408088991096e-162;
        bool r5803150 = r5803136 <= r5803149;
        double r5803151 = 1.0;
        double r5803152 = r5803150 ? r5803151 : r5803148;
        double r5803153 = r5803141 ? r5803148 : r5803152;
        double r5803154 = r5803138 ? r5803139 : r5803153;
        return r5803154;
}

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.0
Target0.0
Herbie5.2
\[\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 < -6.379960110729306e+150

    1. Initial program 62.9

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

      \[\leadsto \color{blue}{-\frac{y \cdot y - x \cdot x}{x \cdot x + y \cdot y}}\]
    3. Taylor expanded around inf 0

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

    if -6.379960110729306e+150 < y < -1.5016765466948683e-155 or 1.6656408088991096e-162 < y

    1. Initial program 0.0

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

      \[\leadsto \color{blue}{-\frac{y \cdot y - x \cdot x}{x \cdot x + y \cdot y}}\]

    if -1.5016765466948683e-155 < y < 1.6656408088991096e-162

    1. Initial program 29.7

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

      \[\leadsto \color{blue}{-\frac{y \cdot y - x \cdot x}{x \cdot x + y \cdot y}}\]
    3. Taylor expanded around 0 16.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -6.379960110729305952978237513299639776117 \cdot 10^{150}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.501676546694868344414885960149825649924 \cdot 10^{-155}:\\ \;\;\;\;-\frac{y \cdot y - x \cdot x}{x \cdot x + y \cdot y}\\ \mathbf{elif}\;y \le 1.665640808899109568529030107036989846971 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-\frac{y \cdot y - x \cdot x}{x \cdot x + y \cdot y}\\ \end{array}\]

Reproduce

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