Average Error: 19.2 → 13.0
Time: 56.2s
Precision: 64
\[\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
\[\begin{array}{l} \mathbf{if}\;b \le 8.671690713206293 \cdot 10^{+88}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\sqrt{\mathsf{fma}\left(-4, \left(a \cdot c\right), \left(b \cdot b\right)\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(-4, \left(a \cdot c\right), \left(b \cdot b\right)\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(b + \left(-b\right)\right) + \left(\sqrt{\mathsf{fma}\left(\left(-4 \cdot a\right), c, \left(b \cdot b\right)\right)} - b\right)}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(b + \left(-b\right)\right) + \left(\sqrt{\mathsf{fma}\left(\left(-4 \cdot a\right), c, \left(b \cdot b\right)\right)} - b\right)}{2 \cdot a}\\ \end{array}\]
\begin{array}{l}
\mathbf{if}\;b \ge 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\

\end{array}
\begin{array}{l}
\mathbf{if}\;b \le 8.671690713206293 \cdot 10^{+88}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\sqrt{\mathsf{fma}\left(-4, \left(a \cdot c\right), \left(b \cdot b\right)\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(-4, \left(a \cdot c\right), \left(b \cdot b\right)\right)}}}\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(b + \left(-b\right)\right) + \left(\sqrt{\mathsf{fma}\left(\left(-4 \cdot a\right), c, \left(b \cdot b\right)\right)} - b\right)}{2 \cdot a}\\

\end{array}\\

\mathbf{elif}\;b \ge 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(b + \left(-b\right)\right) + \left(\sqrt{\mathsf{fma}\left(\left(-4 \cdot a\right), c, \left(b \cdot b\right)\right)} - b\right)}{2 \cdot a}\\

\end{array}
double f(double a, double b, double c) {
        double r1340577 = b;
        double r1340578 = 0.0;
        bool r1340579 = r1340577 >= r1340578;
        double r1340580 = 2.0;
        double r1340581 = c;
        double r1340582 = r1340580 * r1340581;
        double r1340583 = -r1340577;
        double r1340584 = r1340577 * r1340577;
        double r1340585 = 4.0;
        double r1340586 = a;
        double r1340587 = r1340585 * r1340586;
        double r1340588 = r1340587 * r1340581;
        double r1340589 = r1340584 - r1340588;
        double r1340590 = sqrt(r1340589);
        double r1340591 = r1340583 - r1340590;
        double r1340592 = r1340582 / r1340591;
        double r1340593 = r1340583 + r1340590;
        double r1340594 = r1340580 * r1340586;
        double r1340595 = r1340593 / r1340594;
        double r1340596 = r1340579 ? r1340592 : r1340595;
        return r1340596;
}

double f(double a, double b, double c) {
        double r1340597 = b;
        double r1340598 = 8.671690713206293e+88;
        bool r1340599 = r1340597 <= r1340598;
        double r1340600 = 0.0;
        bool r1340601 = r1340597 >= r1340600;
        double r1340602 = 2.0;
        double r1340603 = c;
        double r1340604 = r1340602 * r1340603;
        double r1340605 = -r1340597;
        double r1340606 = -4.0;
        double r1340607 = a;
        double r1340608 = r1340607 * r1340603;
        double r1340609 = r1340597 * r1340597;
        double r1340610 = fma(r1340606, r1340608, r1340609);
        double r1340611 = sqrt(r1340610);
        double r1340612 = sqrt(r1340611);
        double r1340613 = r1340612 * r1340612;
        double r1340614 = r1340605 - r1340613;
        double r1340615 = r1340604 / r1340614;
        double r1340616 = r1340597 + r1340605;
        double r1340617 = r1340606 * r1340607;
        double r1340618 = fma(r1340617, r1340603, r1340609);
        double r1340619 = sqrt(r1340618);
        double r1340620 = r1340619 - r1340597;
        double r1340621 = r1340616 + r1340620;
        double r1340622 = r1340602 * r1340607;
        double r1340623 = r1340621 / r1340622;
        double r1340624 = r1340601 ? r1340615 : r1340623;
        double r1340625 = r1340605 - r1340597;
        double r1340626 = r1340604 / r1340625;
        double r1340627 = r1340601 ? r1340626 : r1340623;
        double r1340628 = r1340599 ? r1340624 : r1340627;
        return r1340628;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 2 regimes
  2. if b < 8.671690713206293e+88

    1. Initial program 16.2

      \[\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
    2. Simplified16.2

      \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)} - b}{2 \cdot a}\\ \end{array}}\]
    3. Using strategy rm
    4. Applied *-un-lft-identity16.2

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)} - 1 \cdot b}{2 \cdot a}\\ \end{array}\]
    5. Applied add-cube-cbrt16.5

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\sqrt[3]{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}} \cdot \sqrt[3]{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}}\right) \cdot \sqrt[3]{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}} - 1 \cdot b}{2 \cdot a}\\ \end{array}\]
    6. Applied prod-diff16.5

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\left(\sqrt[3]{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}} \cdot \sqrt[3]{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}}\right), \left(\sqrt[3]{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}}\right), \left(-b \cdot 1\right)\right) + \mathsf{fma}\left(\left(-b\right), 1, \left(b \cdot 1\right)\right)}{2 \cdot a}\\ \end{array}\]
    7. Simplified16.2

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\sqrt{\mathsf{fma}\left(\left(-4 \cdot a\right), c, \left(b \cdot b\right)\right)} - b\right) + \mathsf{fma}\left(\left(-b\right), 1, \left(b \cdot 1\right)\right)}{2 \cdot a}\\ \end{array}\]
    8. Simplified16.2

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\sqrt{\mathsf{fma}\left(\left(-4 \cdot a\right), c, \left(b \cdot b\right)\right)} - b\right) + \left(\left(-b\right) + b\right)}{2 \cdot a}\\ \end{array}\]
    9. Using strategy rm
    10. Applied add-sqr-sqrt16.2

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \color{blue}{\sqrt{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\sqrt{\mathsf{fma}\left(\left(-4 \cdot a\right), c, \left(b \cdot b\right)\right)} - b\right) + \left(\left(-b\right) + b\right)}{2 \cdot a}\\ \end{array}\]

    if 8.671690713206293e+88 < b

    1. Initial program 28.7

      \[\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
    2. Simplified28.6

      \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)} - b}{2 \cdot a}\\ \end{array}}\]
    3. Using strategy rm
    4. Applied *-un-lft-identity28.6

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)} - 1 \cdot b}{2 \cdot a}\\ \end{array}\]
    5. Applied add-cube-cbrt28.6

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\sqrt[3]{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}} \cdot \sqrt[3]{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}}\right) \cdot \sqrt[3]{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}} - 1 \cdot b}{2 \cdot a}\\ \end{array}\]
    6. Applied prod-diff28.6

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\left(\sqrt[3]{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}} \cdot \sqrt[3]{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}}\right), \left(\sqrt[3]{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}}\right), \left(-b \cdot 1\right)\right) + \mathsf{fma}\left(\left(-b\right), 1, \left(b \cdot 1\right)\right)}{2 \cdot a}\\ \end{array}\]
    7. Simplified28.6

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\sqrt{\mathsf{fma}\left(\left(-4 \cdot a\right), c, \left(b \cdot b\right)\right)} - b\right) + \mathsf{fma}\left(\left(-b\right), 1, \left(b \cdot 1\right)\right)}{2 \cdot a}\\ \end{array}\]
    8. Simplified28.6

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\sqrt{\mathsf{fma}\left(\left(-4 \cdot a\right), c, \left(b \cdot b\right)\right)} - b\right) + \left(\left(-b\right) + b\right)}{2 \cdot a}\\ \end{array}\]
    9. Taylor expanded around 0 3.0

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \color{blue}{b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\sqrt{\mathsf{fma}\left(\left(-4 \cdot a\right), c, \left(b \cdot b\right)\right)} - b\right) + \left(\left(-b\right) + b\right)}{2 \cdot a}\\ \end{array}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification13.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le 8.671690713206293 \cdot 10^{+88}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\sqrt{\mathsf{fma}\left(-4, \left(a \cdot c\right), \left(b \cdot b\right)\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(-4, \left(a \cdot c\right), \left(b \cdot b\right)\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(b + \left(-b\right)\right) + \left(\sqrt{\mathsf{fma}\left(\left(-4 \cdot a\right), c, \left(b \cdot b\right)\right)} - b\right)}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(b + \left(-b\right)\right) + \left(\sqrt{\mathsf{fma}\left(\left(-4 \cdot a\right), c, \left(b \cdot b\right)\right)} - b\right)}{2 \cdot a}\\ \end{array}\]

Reproduce

herbie shell --seed 2019107 +o rules:numerics
(FPCore (a b c)
  :name "jeff quadratic root 2"
  (if (>= b 0) (/ (* 2 c) (- (- b) (sqrt (- (* b b) (* (* 4 a) c))))) (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a))))