Average Error: 31.3 → 12.7
Time: 5.3s
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}\;x \le -7.928259414816123188229698239228701594261 \cdot 10^{152}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -1.670806219743054366544845033863121817394 \cdot 10^{-99}:\\ \;\;\;\;\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}\;x \le 3.339425016971985733812234822017933716285 \cdot 10^{-120}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 371427111337525632:\\ \;\;\;\;\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{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}\;x \le -7.928259414816123188229698239228701594261 \cdot 10^{152}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \le -1.670806219743054366544845033863121817394 \cdot 10^{-99}:\\
\;\;\;\;\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}\;x \le 3.339425016971985733812234822017933716285 \cdot 10^{-120}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le 371427111337525632:\\
\;\;\;\;\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{else}:\\
\;\;\;\;1\\

\end{array}
double f(double x, double y) {
        double r867346 = x;
        double r867347 = r867346 * r867346;
        double r867348 = y;
        double r867349 = 4.0;
        double r867350 = r867348 * r867349;
        double r867351 = r867350 * r867348;
        double r867352 = r867347 - r867351;
        double r867353 = r867347 + r867351;
        double r867354 = r867352 / r867353;
        return r867354;
}

double f(double x, double y) {
        double r867355 = x;
        double r867356 = -7.928259414816123e+152;
        bool r867357 = r867355 <= r867356;
        double r867358 = 1.0;
        double r867359 = -1.6708062197430544e-99;
        bool r867360 = r867355 <= r867359;
        double r867361 = r867355 * r867355;
        double r867362 = y;
        double r867363 = 4.0;
        double r867364 = r867362 * r867363;
        double r867365 = r867364 * r867362;
        double r867366 = fma(r867355, r867355, r867365);
        double r867367 = r867361 / r867366;
        double r867368 = r867365 / r867366;
        double r867369 = r867367 - r867368;
        double r867370 = 3.339425016971986e-120;
        bool r867371 = r867355 <= r867370;
        double r867372 = -1.0;
        double r867373 = 3.714271113375256e+17;
        bool r867374 = r867355 <= r867373;
        double r867375 = r867374 ? r867369 : r867358;
        double r867376 = r867371 ? r867372 : r867375;
        double r867377 = r867360 ? r867369 : r867376;
        double r867378 = r867357 ? r867358 : r867377;
        return r867378;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.3
Target31.0
Herbie12.7
\[\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 3 regimes
  2. if x < -7.928259414816123e+152 or 3.714271113375256e+17 < x

    1. Initial program 49.2

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

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

    if -7.928259414816123e+152 < x < -1.6708062197430544e-99 or 3.339425016971986e-120 < x < 3.714271113375256e+17

    1. Initial program 15.6

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Using strategy rm
    3. Applied div-sub15.6

      \[\leadsto \color{blue}{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\]
    4. Simplified15.6

      \[\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}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    5. Simplified15.6

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

    if -1.6708062197430544e-99 < x < 3.339425016971986e-120

    1. Initial program 26.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -7.928259414816123188229698239228701594261 \cdot 10^{152}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -1.670806219743054366544845033863121817394 \cdot 10^{-99}:\\ \;\;\;\;\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}\;x \le 3.339425016971985733812234822017933716285 \cdot 10^{-120}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 371427111337525632:\\ \;\;\;\;\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{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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