Average Error: 20.4 → 5.5
Time: 10.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 -1.10892874009979371370858177892837434758 \cdot 10^{154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.236020320932232476704484715088241182396 \cdot 10^{-161}:\\ \;\;\;\;\left(\sqrt[3]{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}} \cdot \sqrt[3]{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}}\right) \cdot \sqrt[3]{\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 -3.640183473874900789883704258602787518783 \cdot 10^{-198}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 2.073039356492311435572177705373562775963 \cdot 10^{-167}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\left(\sqrt[3]{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}} \cdot \sqrt[3]{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}}\right) \cdot \sqrt[3]{\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.10892874009979371370858177892837434758 \cdot 10^{154}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -1.236020320932232476704484715088241182396 \cdot 10^{-161}:\\
\;\;\;\;\left(\sqrt[3]{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}} \cdot \sqrt[3]{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}}\right) \cdot \sqrt[3]{\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 -3.640183473874900789883704258602787518783 \cdot 10^{-198}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le 2.073039356492311435572177705373562775963 \cdot 10^{-167}:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;\left(\sqrt[3]{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}} \cdot \sqrt[3]{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}}\right) \cdot \sqrt[3]{\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 r82184 = x;
        double r82185 = y;
        double r82186 = r82184 - r82185;
        double r82187 = r82184 + r82185;
        double r82188 = r82186 * r82187;
        double r82189 = r82184 * r82184;
        double r82190 = r82185 * r82185;
        double r82191 = r82189 + r82190;
        double r82192 = r82188 / r82191;
        return r82192;
}

double f(double x, double y) {
        double r82193 = y;
        double r82194 = -1.1089287400997937e+154;
        bool r82195 = r82193 <= r82194;
        double r82196 = -1.0;
        double r82197 = -1.2360203209322325e-161;
        bool r82198 = r82193 <= r82197;
        double r82199 = x;
        double r82200 = r82199 - r82193;
        double r82201 = r82199 + r82193;
        double r82202 = r82200 * r82201;
        double r82203 = r82199 * r82199;
        double r82204 = r82193 * r82193;
        double r82205 = r82203 + r82204;
        double r82206 = r82202 / r82205;
        double r82207 = cbrt(r82206);
        double r82208 = r82207 * r82207;
        double r82209 = 3.0;
        double r82210 = pow(r82206, r82209);
        double r82211 = cbrt(r82210);
        double r82212 = cbrt(r82211);
        double r82213 = r82208 * r82212;
        double r82214 = -3.640183473874901e-198;
        bool r82215 = r82193 <= r82214;
        double r82216 = 2.0730393564923114e-167;
        bool r82217 = r82193 <= r82216;
        double r82218 = 1.0;
        double r82219 = r82217 ? r82218 : r82213;
        double r82220 = r82215 ? r82196 : r82219;
        double r82221 = r82198 ? r82213 : r82220;
        double r82222 = r82195 ? r82196 : r82221;
        return r82222;
}

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.5
\[\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.1089287400997937e+154 or -1.2360203209322325e-161 < y < -3.640183473874901e-198

    1. Initial program 57.6

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

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

    if -1.1089287400997937e+154 < y < -1.2360203209322325e-161 or 2.0730393564923114e-167 < y

    1. Initial program 0.3

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied add-cube-cbrt0.4

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

      \[\leadsto \left(\sqrt[3]{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}} \cdot \sqrt[3]{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}}\right) \cdot \sqrt[3]{\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)}}}}\]
    6. Applied add-cbrt-cube37.9

      \[\leadsto \left(\sqrt[3]{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}} \cdot \sqrt[3]{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}}\right) \cdot \sqrt[3]{\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)}}}\]
    7. Applied add-cbrt-cube37.9

      \[\leadsto \left(\sqrt[3]{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}} \cdot \sqrt[3]{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}}\right) \cdot \sqrt[3]{\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)}}}\]
    8. Applied cbrt-unprod37.9

      \[\leadsto \left(\sqrt[3]{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}} \cdot \sqrt[3]{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}}\right) \cdot \sqrt[3]{\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)}}}\]
    9. Applied cbrt-undiv37.8

      \[\leadsto \left(\sqrt[3]{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}} \cdot \sqrt[3]{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}}\right) \cdot \sqrt[3]{\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)}}}}\]
    10. Simplified0.4

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

    if -3.640183473874901e-198 < y < 2.0730393564923114e-167

    1. Initial program 31.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.10892874009979371370858177892837434758 \cdot 10^{154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.236020320932232476704484715088241182396 \cdot 10^{-161}:\\ \;\;\;\;\left(\sqrt[3]{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}} \cdot \sqrt[3]{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}}\right) \cdot \sqrt[3]{\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 -3.640183473874900789883704258602787518783 \cdot 10^{-198}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 2.073039356492311435572177705373562775963 \cdot 10^{-167}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\left(\sqrt[3]{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}} \cdot \sqrt[3]{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}}\right) \cdot \sqrt[3]{\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 2019297 
(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))))