Average Error: 34.0 → 11.2
Time: 6.3s
Precision: 64
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -5.87486430558009272 \cdot 10^{54}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le -9.8475017814633646 \cdot 10^{24}:\\ \;\;\;\;\frac{\frac{\frac{\mathsf{fma}\left(b, b, -\left(b \cdot b - 4 \cdot \left(a \cdot c\right)\right)\right)}{a}}{2}}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}\\ \mathbf{elif}\;b \le -3.1369770416067291 \cdot 10^{-74}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le 1.05775171304890479 \cdot 10^{130}:\\ \;\;\;\;{\left(\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\right)}^{1}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{b}{a}\\ \end{array}\]
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \le -5.87486430558009272 \cdot 10^{54}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\

\mathbf{elif}\;b \le -9.8475017814633646 \cdot 10^{24}:\\
\;\;\;\;\frac{\frac{\frac{\mathsf{fma}\left(b, b, -\left(b \cdot b - 4 \cdot \left(a \cdot c\right)\right)\right)}{a}}{2}}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}\\

\mathbf{elif}\;b \le -3.1369770416067291 \cdot 10^{-74}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\

\mathbf{elif}\;b \le 1.05775171304890479 \cdot 10^{130}:\\
\;\;\;\;{\left(\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\right)}^{1}\\

\mathbf{else}:\\
\;\;\;\;-1 \cdot \frac{b}{a}\\

\end{array}
double f(double a, double b, double c) {
        double r72582 = b;
        double r72583 = -r72582;
        double r72584 = r72582 * r72582;
        double r72585 = 4.0;
        double r72586 = a;
        double r72587 = c;
        double r72588 = r72586 * r72587;
        double r72589 = r72585 * r72588;
        double r72590 = r72584 - r72589;
        double r72591 = sqrt(r72590);
        double r72592 = r72583 - r72591;
        double r72593 = 2.0;
        double r72594 = r72593 * r72586;
        double r72595 = r72592 / r72594;
        return r72595;
}

double f(double a, double b, double c) {
        double r72596 = b;
        double r72597 = -5.874864305580093e+54;
        bool r72598 = r72596 <= r72597;
        double r72599 = -1.0;
        double r72600 = c;
        double r72601 = r72600 / r72596;
        double r72602 = r72599 * r72601;
        double r72603 = -9.847501781463365e+24;
        bool r72604 = r72596 <= r72603;
        double r72605 = r72596 * r72596;
        double r72606 = 4.0;
        double r72607 = a;
        double r72608 = r72607 * r72600;
        double r72609 = r72606 * r72608;
        double r72610 = r72605 - r72609;
        double r72611 = -r72610;
        double r72612 = fma(r72596, r72596, r72611);
        double r72613 = r72612 / r72607;
        double r72614 = 2.0;
        double r72615 = r72613 / r72614;
        double r72616 = -r72596;
        double r72617 = sqrt(r72610);
        double r72618 = r72616 + r72617;
        double r72619 = r72615 / r72618;
        double r72620 = -3.136977041606729e-74;
        bool r72621 = r72596 <= r72620;
        double r72622 = 1.0577517130489048e+130;
        bool r72623 = r72596 <= r72622;
        double r72624 = r72616 - r72617;
        double r72625 = r72614 * r72607;
        double r72626 = r72624 / r72625;
        double r72627 = 1.0;
        double r72628 = pow(r72626, r72627);
        double r72629 = r72596 / r72607;
        double r72630 = r72599 * r72629;
        double r72631 = r72623 ? r72628 : r72630;
        double r72632 = r72621 ? r72602 : r72631;
        double r72633 = r72604 ? r72619 : r72632;
        double r72634 = r72598 ? r72602 : r72633;
        return r72634;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original34.0
Target21.3
Herbie11.2
\[\begin{array}{l} \mathbf{if}\;b \lt 0.0:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if b < -5.874864305580093e+54 or -9.847501781463365e+24 < b < -3.136977041606729e-74

    1. Initial program 54.2

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Taylor expanded around -inf 8.6

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]

    if -5.874864305580093e+54 < b < -9.847501781463365e+24

    1. Initial program 43.9

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied div-inv43.9

      \[\leadsto \color{blue}{\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{1}{2 \cdot a}}\]
    4. Using strategy rm
    5. Applied flip--43.9

      \[\leadsto \color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} \cdot \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}} \cdot \frac{1}{2 \cdot a}\]
    6. Applied associate-*l/43.9

      \[\leadsto \color{blue}{\frac{\left(\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} \cdot \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{1}{2 \cdot a}}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}\]
    7. Simplified49.9

      \[\leadsto \frac{\color{blue}{\frac{\frac{\mathsf{fma}\left(b, b, -\left(b \cdot b - 4 \cdot \left(a \cdot c\right)\right)\right)}{a}}{2}}}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}\]

    if -3.136977041606729e-74 < b < 1.0577517130489048e+130

    1. Initial program 12.8

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied div-inv12.9

      \[\leadsto \color{blue}{\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{1}{2 \cdot a}}\]
    4. Using strategy rm
    5. Applied pow112.9

      \[\leadsto \left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right) \cdot \color{blue}{{\left(\frac{1}{2 \cdot a}\right)}^{1}}\]
    6. Applied pow112.9

      \[\leadsto \color{blue}{{\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}^{1}} \cdot {\left(\frac{1}{2 \cdot a}\right)}^{1}\]
    7. Applied pow-prod-down12.9

      \[\leadsto \color{blue}{{\left(\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{1}{2 \cdot a}\right)}^{1}}\]
    8. Simplified12.8

      \[\leadsto {\color{blue}{\left(\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\right)}}^{1}\]

    if 1.0577517130489048e+130 < b

    1. Initial program 55.7

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied clear-num55.8

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}\]
    4. Taylor expanded around 0 3.2

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification11.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -5.87486430558009272 \cdot 10^{54}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le -9.8475017814633646 \cdot 10^{24}:\\ \;\;\;\;\frac{\frac{\frac{\mathsf{fma}\left(b, b, -\left(b \cdot b - 4 \cdot \left(a \cdot c\right)\right)\right)}{a}}{2}}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}\\ \mathbf{elif}\;b \le -3.1369770416067291 \cdot 10^{-74}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le 1.05775171304890479 \cdot 10^{130}:\\ \;\;\;\;{\left(\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\right)}^{1}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{b}{a}\\ \end{array}\]

Reproduce

herbie shell --seed 2020034 +o rules:numerics
(FPCore (a b c)
  :name "quadm (p42, negative)"
  :precision binary64

  :herbie-target
  (if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))

  (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))