Average Error: 31.9 → 12.9
Time: 10.7s
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 -1.287656836218587817843721098850935729447 \cdot 10^{137}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -1.530862185462861244589348861406538600327 \cdot 10^{-62}:\\ \;\;\;\;\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 1.637752758454048808996152623221730747955 \cdot 10^{-55}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 3.168622066814080755323424526904394535226 \cdot 10^{74}:\\ \;\;\;\;\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 -1.287656836218587817843721098850935729447 \cdot 10^{137}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \le -1.530862185462861244589348861406538600327 \cdot 10^{-62}:\\
\;\;\;\;\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 1.637752758454048808996152623221730747955 \cdot 10^{-55}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le 3.168622066814080755323424526904394535226 \cdot 10^{74}:\\
\;\;\;\;\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 r490450 = x;
        double r490451 = r490450 * r490450;
        double r490452 = y;
        double r490453 = 4.0;
        double r490454 = r490452 * r490453;
        double r490455 = r490454 * r490452;
        double r490456 = r490451 - r490455;
        double r490457 = r490451 + r490455;
        double r490458 = r490456 / r490457;
        return r490458;
}

double f(double x, double y) {
        double r490459 = x;
        double r490460 = -1.2876568362185878e+137;
        bool r490461 = r490459 <= r490460;
        double r490462 = 1.0;
        double r490463 = -1.5308621854628612e-62;
        bool r490464 = r490459 <= r490463;
        double r490465 = r490459 * r490459;
        double r490466 = y;
        double r490467 = 4.0;
        double r490468 = r490466 * r490467;
        double r490469 = r490468 * r490466;
        double r490470 = fma(r490459, r490459, r490469);
        double r490471 = r490465 / r490470;
        double r490472 = r490469 / r490470;
        double r490473 = r490471 - r490472;
        double r490474 = 1.6377527584540488e-55;
        bool r490475 = r490459 <= r490474;
        double r490476 = -1.0;
        double r490477 = 3.168622066814081e+74;
        bool r490478 = r490459 <= r490477;
        double r490479 = r490478 ? r490473 : r490462;
        double r490480 = r490475 ? r490476 : r490479;
        double r490481 = r490464 ? r490473 : r490480;
        double r490482 = r490461 ? r490462 : r490481;
        return r490482;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.9
Target31.6
Herbie12.9
\[\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 < -1.2876568362185878e+137 or 3.168622066814081e+74 < x

    1. Initial program 52.3

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

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

    if -1.2876568362185878e+137 < x < -1.5308621854628612e-62 or 1.6377527584540488e-55 < x < 3.168622066814081e+74

    1. Initial program 15.7

      \[\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.5308621854628612e-62 < x < 1.6377527584540488e-55

    1. Initial program 25.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.287656836218587817843721098850935729447 \cdot 10^{137}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -1.530862185462861244589348861406538600327 \cdot 10^{-62}:\\ \;\;\;\;\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 1.637752758454048808996152623221730747955 \cdot 10^{-55}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 3.168622066814080755323424526904394535226 \cdot 10^{74}:\\ \;\;\;\;\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 2019304 +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.974323384962678118) (- (/ (* 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))))