Average Error: 32.3 → 13.6
Time: 6.4s
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}\;y \le -7.71073899284975746 \cdot 10^{142}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.38415960656676321 \cdot 10^{-97}:\\ \;\;\;\;\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}\;y \le 1.1196094733529732 \cdot 10^{-55}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 28161126.972837694:\\ \;\;\;\;\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}\;y \le 4.01162503157803517 \cdot 10^{38}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 2.16201455188241352 \cdot 10^{107}:\\ \;\;\;\;\log \left(e^{\frac{\mathsf{fma}\left(x, x, -\left(y \cdot 4\right) \cdot y\right)}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\right)\\ \mathbf{elif}\;y \le 4.36744780112662469 \cdot 10^{128}:\\ \;\;\;\;1\\ \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}\;y \le -7.71073899284975746 \cdot 10^{142}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -1.38415960656676321 \cdot 10^{-97}:\\
\;\;\;\;\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}\;y \le 1.1196094733529732 \cdot 10^{-55}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \le 28161126.972837694:\\
\;\;\;\;\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}\;y \le 4.01162503157803517 \cdot 10^{38}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \le 2.16201455188241352 \cdot 10^{107}:\\
\;\;\;\;\log \left(e^{\frac{\mathsf{fma}\left(x, x, -\left(y \cdot 4\right) \cdot y\right)}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\right)\\

\mathbf{elif}\;y \le 4.36744780112662469 \cdot 10^{128}:\\
\;\;\;\;1\\

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

\end{array}
double f(double x, double y) {
        double r644484 = x;
        double r644485 = r644484 * r644484;
        double r644486 = y;
        double r644487 = 4.0;
        double r644488 = r644486 * r644487;
        double r644489 = r644488 * r644486;
        double r644490 = r644485 - r644489;
        double r644491 = r644485 + r644489;
        double r644492 = r644490 / r644491;
        return r644492;
}

double f(double x, double y) {
        double r644493 = y;
        double r644494 = -7.710738992849757e+142;
        bool r644495 = r644493 <= r644494;
        double r644496 = -1.0;
        double r644497 = -1.3841596065667632e-97;
        bool r644498 = r644493 <= r644497;
        double r644499 = x;
        double r644500 = r644499 * r644499;
        double r644501 = 4.0;
        double r644502 = r644493 * r644501;
        double r644503 = r644502 * r644493;
        double r644504 = fma(r644499, r644499, r644503);
        double r644505 = r644500 / r644504;
        double r644506 = r644503 / r644504;
        double r644507 = r644505 - r644506;
        double r644508 = 1.1196094733529732e-55;
        bool r644509 = r644493 <= r644508;
        double r644510 = 1.0;
        double r644511 = 28161126.972837694;
        bool r644512 = r644493 <= r644511;
        double r644513 = 4.011625031578035e+38;
        bool r644514 = r644493 <= r644513;
        double r644515 = 2.1620145518824135e+107;
        bool r644516 = r644493 <= r644515;
        double r644517 = -r644503;
        double r644518 = fma(r644499, r644499, r644517);
        double r644519 = r644518 / r644504;
        double r644520 = exp(r644519);
        double r644521 = log(r644520);
        double r644522 = 4.367447801126625e+128;
        bool r644523 = r644493 <= r644522;
        double r644524 = r644523 ? r644510 : r644496;
        double r644525 = r644516 ? r644521 : r644524;
        double r644526 = r644514 ? r644510 : r644525;
        double r644527 = r644512 ? r644507 : r644526;
        double r644528 = r644509 ? r644510 : r644527;
        double r644529 = r644498 ? r644507 : r644528;
        double r644530 = r644495 ? r644496 : r644529;
        return r644530;
}

Error

Bits error versus x

Bits error versus y

Target

Original32.3
Target32.0
Herbie13.6
\[\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.974323384962678118:\\ \;\;\;\;\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 < -7.710738992849757e+142 or 4.367447801126625e+128 < y

    1. Initial program 59.1

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

      \[\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.6

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

    if -7.710738992849757e+142 < y < -1.3841596065667632e-97 or 1.1196094733529732e-55 < y < 28161126.972837694

    1. Initial program 17.4

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Simplified17.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-sub17.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)}}\]

    if -1.3841596065667632e-97 < y < 1.1196094733529732e-55 or 28161126.972837694 < y < 4.011625031578035e+38 or 2.1620145518824135e+107 < y < 4.367447801126625e+128

    1. Initial program 25.0

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

      \[\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 14.8

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

    if 4.011625031578035e+38 < y < 2.1620145518824135e+107

    1. Initial program 13.9

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

      \[\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 fma-neg13.9

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

      \[\leadsto \color{blue}{\log \left(e^{\frac{\mathsf{fma}\left(x, x, -\left(y \cdot 4\right) \cdot y\right)}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\right)}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification13.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -7.71073899284975746 \cdot 10^{142}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.38415960656676321 \cdot 10^{-97}:\\ \;\;\;\;\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}\;y \le 1.1196094733529732 \cdot 10^{-55}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 28161126.972837694:\\ \;\;\;\;\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}\;y \le 4.01162503157803517 \cdot 10^{38}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 2.16201455188241352 \cdot 10^{107}:\\ \;\;\;\;\log \left(e^{\frac{\mathsf{fma}\left(x, x, -\left(y \cdot 4\right) \cdot y\right)}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\right)\\ \mathbf{elif}\;y \le 4.36744780112662469 \cdot 10^{128}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

herbie shell --seed 2020047 +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))))