Average Error: 20.6 → 5.3
Time: 2.3s
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 -1.070030759127226 \cdot 10^{151}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -6.1699005892544436 \cdot 10^{-170}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\right)}^{3}}\\ \mathbf{elif}\;y \le -5.28163054182752652 \cdot 10^{-193}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 1.45312618291428704 \cdot 10^{-160}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\right)}^{3}}\\ \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 -1.070030759127226 \cdot 10^{151}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -6.1699005892544436 \cdot 10^{-170}:\\
\;\;\;\;\sqrt[3]{{\left(\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\right)}^{3}}\\

\mathbf{elif}\;y \le -5.28163054182752652 \cdot 10^{-193}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le 1.45312618291428704 \cdot 10^{-160}:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;\sqrt[3]{{\left(\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\right)}^{3}}\\

\end{array}
double f(double x, double y) {
        double r99824 = x;
        double r99825 = y;
        double r99826 = r99824 - r99825;
        double r99827 = r99824 + r99825;
        double r99828 = r99826 * r99827;
        double r99829 = r99824 * r99824;
        double r99830 = r99825 * r99825;
        double r99831 = r99829 + r99830;
        double r99832 = r99828 / r99831;
        return r99832;
}

double f(double x, double y) {
        double r99833 = y;
        double r99834 = -1.070030759127226e+151;
        bool r99835 = r99833 <= r99834;
        double r99836 = -1.0;
        double r99837 = -6.1699005892544436e-170;
        bool r99838 = r99833 <= r99837;
        double r99839 = x;
        double r99840 = r99839 - r99833;
        double r99841 = r99839 + r99833;
        double r99842 = r99840 * r99841;
        double r99843 = r99839 * r99839;
        double r99844 = r99833 * r99833;
        double r99845 = r99843 + r99844;
        double r99846 = r99842 / r99845;
        double r99847 = 3.0;
        double r99848 = pow(r99846, r99847);
        double r99849 = cbrt(r99848);
        double r99850 = -5.281630541827527e-193;
        bool r99851 = r99833 <= r99850;
        double r99852 = 1.453126182914287e-160;
        bool r99853 = r99833 <= r99852;
        double r99854 = 1.0;
        double r99855 = r99853 ? r99854 : r99849;
        double r99856 = r99851 ? r99836 : r99855;
        double r99857 = r99838 ? r99849 : r99856;
        double r99858 = r99835 ? r99836 : r99857;
        return r99858;
}

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.0
Herbie5.3
\[\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 < -1.070030759127226e+151 or -6.1699005892544436e-170 < y < -5.281630541827527e-193

    1. Initial program 58.8

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

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

    if -1.070030759127226e+151 < y < -6.1699005892544436e-170 or 1.453126182914287e-160 < y

    1. Initial program 0.4

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied add-cbrt-cube38.1

      \[\leadsto \frac{\left(x - y\right) \cdot \left(x + y\right)}{\color{blue}{\sqrt[3]{\left(\left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x + y \cdot y\right)\right) \cdot \left(x \cdot x + y \cdot y\right)}}}\]
    4. Applied add-cbrt-cube38.3

      \[\leadsto \frac{\left(x - y\right) \cdot \color{blue}{\sqrt[3]{\left(\left(x + y\right) \cdot \left(x + y\right)\right) \cdot \left(x + y\right)}}}{\sqrt[3]{\left(\left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x + y \cdot y\right)\right) \cdot \left(x \cdot x + y \cdot y\right)}}\]
    5. Applied add-cbrt-cube38.4

      \[\leadsto \frac{\color{blue}{\sqrt[3]{\left(\left(x - y\right) \cdot \left(x - y\right)\right) \cdot \left(x - y\right)}} \cdot \sqrt[3]{\left(\left(x + y\right) \cdot \left(x + y\right)\right) \cdot \left(x + y\right)}}{\sqrt[3]{\left(\left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x + y \cdot y\right)\right) \cdot \left(x \cdot x + y \cdot y\right)}}\]
    6. Applied cbrt-unprod38.1

      \[\leadsto \frac{\color{blue}{\sqrt[3]{\left(\left(\left(x - y\right) \cdot \left(x - y\right)\right) \cdot \left(x - y\right)\right) \cdot \left(\left(\left(x + y\right) \cdot \left(x + y\right)\right) \cdot \left(x + y\right)\right)}}}{\sqrt[3]{\left(\left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x + y \cdot y\right)\right) \cdot \left(x \cdot x + y \cdot y\right)}}\]
    7. Applied cbrt-undiv38.0

      \[\leadsto \color{blue}{\sqrt[3]{\frac{\left(\left(\left(x - y\right) \cdot \left(x - y\right)\right) \cdot \left(x - y\right)\right) \cdot \left(\left(\left(x + y\right) \cdot \left(x + y\right)\right) \cdot \left(x + y\right)\right)}{\left(\left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x + y \cdot y\right)\right) \cdot \left(x \cdot x + y \cdot y\right)}}}\]
    8. Simplified0.4

      \[\leadsto \sqrt[3]{\color{blue}{{\left(\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\right)}^{3}}}\]

    if -5.281630541827527e-193 < y < 1.453126182914287e-160

    1. Initial program 30.5

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied add-log-exp30.5

      \[\leadsto \color{blue}{\log \left(e^{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}}\right)}\]
    4. Taylor expanded around inf 14.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.070030759127226 \cdot 10^{151}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -6.1699005892544436 \cdot 10^{-170}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\right)}^{3}}\\ \mathbf{elif}\;y \le -5.28163054182752652 \cdot 10^{-193}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 1.45312618291428704 \cdot 10^{-160}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\right)}^{3}}\\ \end{array}\]

Reproduce

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