Average Error: 31.7 → 12.4
Time: 12.6s
Precision: 64
\[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;\left(y \cdot 4\right) \cdot y \le 1.883987095627688634773256576903935146579 \cdot 10^{-179}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 25951328951665387827625984:\\ \;\;\;\;\left(\sqrt[3]{\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}} \cdot \sqrt[3]{\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\right) \cdot \sqrt[3]{\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 56309717854388472133950898176:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 7.251271519567312889559392701775878259286 \cdot 10^{285}:\\ \;\;\;\;\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \sqrt[3]{{\left(\frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\right)}^{3}}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]
\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\begin{array}{l}
\mathbf{if}\;\left(y \cdot 4\right) \cdot y \le 1.883987095627688634773256576903935146579 \cdot 10^{-179}:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 25951328951665387827625984:\\
\;\;\;\;\left(\sqrt[3]{\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}} \cdot \sqrt[3]{\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\right) \cdot \sqrt[3]{\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 56309717854388472133950898176:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 7.251271519567312889559392701775878259286 \cdot 10^{285}:\\
\;\;\;\;\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \sqrt[3]{{\left(\frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\right)}^{3}}\\

\mathbf{else}:\\
\;\;\;\;-1\\

\end{array}
double f(double x, double y) {
        double r432191 = x;
        double r432192 = r432191 * r432191;
        double r432193 = y;
        double r432194 = 4.0;
        double r432195 = r432193 * r432194;
        double r432196 = r432195 * r432193;
        double r432197 = r432192 - r432196;
        double r432198 = r432192 + r432196;
        double r432199 = r432197 / r432198;
        return r432199;
}

double f(double x, double y) {
        double r432200 = y;
        double r432201 = 4.0;
        double r432202 = r432200 * r432201;
        double r432203 = r432202 * r432200;
        double r432204 = 1.8839870956276886e-179;
        bool r432205 = r432203 <= r432204;
        double r432206 = 1.0;
        double r432207 = 2.5951328951665388e+25;
        bool r432208 = r432203 <= r432207;
        double r432209 = x;
        double r432210 = r432209 * r432209;
        double r432211 = fma(r432209, r432209, r432203);
        double r432212 = r432210 / r432211;
        double r432213 = r432203 / r432211;
        double r432214 = r432212 - r432213;
        double r432215 = cbrt(r432214);
        double r432216 = r432215 * r432215;
        double r432217 = r432216 * r432215;
        double r432218 = 5.630971785438847e+28;
        bool r432219 = r432203 <= r432218;
        double r432220 = 7.251271519567313e+285;
        bool r432221 = r432203 <= r432220;
        double r432222 = 3.0;
        double r432223 = pow(r432213, r432222);
        double r432224 = cbrt(r432223);
        double r432225 = r432212 - r432224;
        double r432226 = -1.0;
        double r432227 = r432221 ? r432225 : r432226;
        double r432228 = r432219 ? r432206 : r432227;
        double r432229 = r432208 ? r432217 : r432228;
        double r432230 = r432205 ? r432206 : r432229;
        return r432230;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.7
Target31.4
Herbie12.4
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \lt 0.9743233849626781184483093056769575923681:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot y\right) \cdot 4} - \frac{\left(y \cdot y\right) \cdot 4}{x \cdot x + \left(y \cdot y\right) \cdot 4}\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{x}{\sqrt{x \cdot x + \left(y \cdot y\right) \cdot 4}}\right)}^{2} - \frac{\left(y \cdot y\right) \cdot 4}{x \cdot x + \left(y \cdot y\right) \cdot 4}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if (* (* y 4.0) y) < 1.8839870956276886e-179 or 2.5951328951665388e+25 < (* (* y 4.0) y) < 5.630971785438847e+28

    1. Initial program 26.3

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Simplified26.3

      \[\leadsto \color{blue}{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    3. Taylor expanded around inf 11.7

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

    if 1.8839870956276886e-179 < (* (* y 4.0) y) < 2.5951328951665388e+25

    1. Initial program 16.4

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

      \[\leadsto \color{blue}{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    3. Using strategy rm
    4. Applied div-sub16.4

      \[\leadsto \color{blue}{\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    5. Using strategy rm
    6. Applied add-cube-cbrt16.4

      \[\leadsto \color{blue}{\left(\sqrt[3]{\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}} \cdot \sqrt[3]{\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\right) \cdot \sqrt[3]{\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}}\]

    if 5.630971785438847e+28 < (* (* y 4.0) y) < 7.251271519567313e+285

    1. Initial program 15.2

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

      \[\leadsto \color{blue}{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    3. Using strategy rm
    4. Applied div-sub15.2

      \[\leadsto \color{blue}{\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    5. Using strategy rm
    6. Applied add-cbrt-cube44.2

      \[\leadsto \frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(y \cdot 4\right) \cdot y}{\color{blue}{\sqrt[3]{\left(\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right) \cdot \mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)\right) \cdot \mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}}\]
    7. Applied add-cbrt-cube45.8

      \[\leadsto \frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(y \cdot 4\right) \cdot \color{blue}{\sqrt[3]{\left(y \cdot y\right) \cdot y}}}{\sqrt[3]{\left(\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right) \cdot \mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)\right) \cdot \mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    8. Applied add-cbrt-cube45.8

      \[\leadsto \frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(y \cdot \color{blue}{\sqrt[3]{\left(4 \cdot 4\right) \cdot 4}}\right) \cdot \sqrt[3]{\left(y \cdot y\right) \cdot y}}{\sqrt[3]{\left(\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right) \cdot \mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)\right) \cdot \mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    9. Applied add-cbrt-cube45.8

      \[\leadsto \frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(\color{blue}{\sqrt[3]{\left(y \cdot y\right) \cdot y}} \cdot \sqrt[3]{\left(4 \cdot 4\right) \cdot 4}\right) \cdot \sqrt[3]{\left(y \cdot y\right) \cdot y}}{\sqrt[3]{\left(\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right) \cdot \mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)\right) \cdot \mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    10. Applied cbrt-unprod45.9

      \[\leadsto \frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\color{blue}{\sqrt[3]{\left(\left(y \cdot y\right) \cdot y\right) \cdot \left(\left(4 \cdot 4\right) \cdot 4\right)}} \cdot \sqrt[3]{\left(y \cdot y\right) \cdot y}}{\sqrt[3]{\left(\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right) \cdot \mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)\right) \cdot \mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    11. Applied cbrt-unprod49.3

      \[\leadsto \frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\color{blue}{\sqrt[3]{\left(\left(\left(y \cdot y\right) \cdot y\right) \cdot \left(\left(4 \cdot 4\right) \cdot 4\right)\right) \cdot \left(\left(y \cdot y\right) \cdot y\right)}}}{\sqrt[3]{\left(\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right) \cdot \mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)\right) \cdot \mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    12. Applied cbrt-undiv49.3

      \[\leadsto \frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \color{blue}{\sqrt[3]{\frac{\left(\left(\left(y \cdot y\right) \cdot y\right) \cdot \left(\left(4 \cdot 4\right) \cdot 4\right)\right) \cdot \left(\left(y \cdot y\right) \cdot y\right)}{\left(\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right) \cdot \mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)\right) \cdot \mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}}\]
    13. Simplified15.2

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

    if 7.251271519567313e+285 < (* (* y 4.0) y)

    1. Initial program 61.2

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

      \[\leadsto \color{blue}{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    3. Taylor expanded around 0 8.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(y \cdot 4\right) \cdot y \le 1.883987095627688634773256576903935146579 \cdot 10^{-179}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 25951328951665387827625984:\\ \;\;\;\;\left(\sqrt[3]{\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}} \cdot \sqrt[3]{\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\right) \cdot \sqrt[3]{\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 56309717854388472133950898176:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 7.251271519567312889559392701775878259286 \cdot 10^{285}:\\ \;\;\;\;\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \sqrt[3]{{\left(\frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\right)}^{3}}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

herbie shell --seed 2019323 +o rules:numerics
(FPCore (x y)
  :name "Diagrams.TwoD.Arc:arcBetween from diagrams-lib-1.3.0.3"
  :precision binary64

  :herbie-target
  (if (< (/ (- (* x x) (* (* y 4) y)) (+ (* x x) (* (* y 4) y))) 0.9743233849626781) (- (/ (* x x) (+ (* x x) (* (* y y) 4))) (/ (* (* y y) 4) (+ (* x x) (* (* y y) 4)))) (- (pow (/ x (sqrt (+ (* x x) (* (* y y) 4)))) 2) (/ (* (* y y) 4) (+ (* x x) (* (* y y) 4)))))

  (/ (- (* x x) (* (* y 4) y)) (+ (* x x) (* (* y 4) y))))