Average Error: 31.6 → 12.8
Time: 10.9s
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 -2.04179898258906648865287012115961201463 \cdot 10^{153}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -3.379561403631358792480741892956065284459 \cdot 10^{-65}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\mathsf{fma}\left(4, \left(-y\right) \cdot y, x \cdot x\right)}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\right)\right)\\ \mathbf{elif}\;y \le 9.959621465941042556551382638800450476793 \cdot 10^{-80}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 2.371593609881423098610405616408534144725 \cdot 10^{60}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\mathsf{fma}\left(4, \left(-y\right) \cdot y, x \cdot x\right)}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\right)\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}\;y \le -2.04179898258906648865287012115961201463 \cdot 10^{153}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -3.379561403631358792480741892956065284459 \cdot 10^{-65}:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\mathsf{fma}\left(4, \left(-y\right) \cdot y, x \cdot x\right)}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\right)\right)\\

\mathbf{elif}\;y \le 9.959621465941042556551382638800450476793 \cdot 10^{-80}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \le 2.371593609881423098610405616408534144725 \cdot 10^{60}:\\
\;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\mathsf{fma}\left(4, \left(-y\right) \cdot y, x \cdot x\right)}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\right)\right)\\

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

\end{array}
double f(double x, double y) {
        double r490099 = x;
        double r490100 = r490099 * r490099;
        double r490101 = y;
        double r490102 = 4.0;
        double r490103 = r490101 * r490102;
        double r490104 = r490103 * r490101;
        double r490105 = r490100 - r490104;
        double r490106 = r490100 + r490104;
        double r490107 = r490105 / r490106;
        return r490107;
}

double f(double x, double y) {
        double r490108 = y;
        double r490109 = -2.0417989825890665e+153;
        bool r490110 = r490108 <= r490109;
        double r490111 = -1.0;
        double r490112 = -3.379561403631359e-65;
        bool r490113 = r490108 <= r490112;
        double r490114 = 4.0;
        double r490115 = -r490108;
        double r490116 = r490115 * r490108;
        double r490117 = x;
        double r490118 = r490117 * r490117;
        double r490119 = fma(r490114, r490116, r490118);
        double r490120 = r490108 * r490114;
        double r490121 = r490120 * r490108;
        double r490122 = fma(r490117, r490117, r490121);
        double r490123 = r490119 / r490122;
        double r490124 = expm1(r490123);
        double r490125 = log1p(r490124);
        double r490126 = 9.959621465941043e-80;
        bool r490127 = r490108 <= r490126;
        double r490128 = 1.0;
        double r490129 = 2.371593609881423e+60;
        bool r490130 = r490108 <= r490129;
        double r490131 = log1p(r490123);
        double r490132 = expm1(r490131);
        double r490133 = r490130 ? r490132 : r490111;
        double r490134 = r490127 ? r490128 : r490133;
        double r490135 = r490113 ? r490125 : r490134;
        double r490136 = r490110 ? r490111 : r490135;
        return r490136;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.6
Target31.3
Herbie12.8
\[\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 < -2.0417989825890665e+153 or 2.371593609881423e+60 < y

    1. Initial program 52.9

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

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

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

    if -2.0417989825890665e+153 < y < -3.379561403631359e-65

    1. Initial program 16.2

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

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

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\mathsf{fma}\left(y \cdot 4, -y, x \cdot x\right)}{\mathsf{fma}\left(y, y \cdot 4, x \cdot x\right)}\right)\right)}\]
    5. Simplified16.2

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

    if -3.379561403631359e-65 < y < 9.959621465941043e-80

    1. Initial program 25.4

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

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

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\mathsf{fma}\left(y \cdot 4, -y, x \cdot x\right)}{\mathsf{fma}\left(y, y \cdot 4, x \cdot x\right)}\right)\right)}\]
    5. Simplified25.6

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

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

    if 9.959621465941043e-80 < y < 2.371593609881423e+60

    1. Initial program 15.9

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

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

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\mathsf{fma}\left(y \cdot 4, -y, x \cdot x\right)}{\mathsf{fma}\left(y, y \cdot 4, x \cdot x\right)}\right)\right)}\]
    5. Simplified15.9

      \[\leadsto \mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(\frac{\mathsf{fma}\left(4, y \cdot \left(-y\right), x \cdot x\right)}{\mathsf{fma}\left(x, x, y \cdot \left(4 \cdot y\right)\right)}\right)}\right)\]
  3. Recombined 4 regimes into one program.
  4. Final simplification12.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -2.04179898258906648865287012115961201463 \cdot 10^{153}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -3.379561403631358792480741892956065284459 \cdot 10^{-65}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\mathsf{fma}\left(4, \left(-y\right) \cdot y, x \cdot x\right)}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\right)\right)\\ \mathbf{elif}\;y \le 9.959621465941042556551382638800450476793 \cdot 10^{-80}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 2.371593609881423098610405616408534144725 \cdot 10^{60}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\mathsf{fma}\left(4, \left(-y\right) \cdot y, x \cdot x\right)}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

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

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

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