Average Error: 33.5 → 11.6
Time: 10.0s
Precision: 64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -1.478406535480561669630649836752919254545 \cdot 10^{60}:\\ \;\;\;\;\frac{1}{2} \cdot \mathsf{fma}\left(2, \frac{c}{b}, -2 \cdot \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 2.175674080408202904737521150531781836244 \cdot 10^{-169} \lor \neg \left(b \le 4.731827132847258030366645007940380497628 \cdot 10^{-110}\right) \land b \le 1.846537578115044209159378851836663670838 \cdot 10^{-4}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{\sqrt{{b}^{2} - 4 \cdot \left(a \cdot c\right)} - b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2} \cdot \left(-2 \cdot \frac{c}{b}\right)\\ \end{array}\]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \le -1.478406535480561669630649836752919254545 \cdot 10^{60}:\\
\;\;\;\;\frac{1}{2} \cdot \mathsf{fma}\left(2, \frac{c}{b}, -2 \cdot \frac{b}{a}\right)\\

\mathbf{elif}\;b \le 2.175674080408202904737521150531781836244 \cdot 10^{-169} \lor \neg \left(b \le 4.731827132847258030366645007940380497628 \cdot 10^{-110}\right) \land b \le 1.846537578115044209159378851836663670838 \cdot 10^{-4}:\\
\;\;\;\;\frac{1}{2} \cdot \frac{\sqrt{{b}^{2} - 4 \cdot \left(a \cdot c\right)} - b}{a}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{2} \cdot \left(-2 \cdot \frac{c}{b}\right)\\

\end{array}
double f(double a, double b, double c) {
        double r181712 = b;
        double r181713 = -r181712;
        double r181714 = r181712 * r181712;
        double r181715 = 4.0;
        double r181716 = a;
        double r181717 = r181715 * r181716;
        double r181718 = c;
        double r181719 = r181717 * r181718;
        double r181720 = r181714 - r181719;
        double r181721 = sqrt(r181720);
        double r181722 = r181713 + r181721;
        double r181723 = 2.0;
        double r181724 = r181723 * r181716;
        double r181725 = r181722 / r181724;
        return r181725;
}

double f(double a, double b, double c) {
        double r181726 = b;
        double r181727 = -1.4784065354805617e+60;
        bool r181728 = r181726 <= r181727;
        double r181729 = 1.0;
        double r181730 = 2.0;
        double r181731 = r181729 / r181730;
        double r181732 = c;
        double r181733 = r181732 / r181726;
        double r181734 = -2.0;
        double r181735 = a;
        double r181736 = r181726 / r181735;
        double r181737 = r181734 * r181736;
        double r181738 = fma(r181730, r181733, r181737);
        double r181739 = r181731 * r181738;
        double r181740 = 2.175674080408203e-169;
        bool r181741 = r181726 <= r181740;
        double r181742 = 4.731827132847258e-110;
        bool r181743 = r181726 <= r181742;
        double r181744 = !r181743;
        double r181745 = 0.00018465375781150442;
        bool r181746 = r181726 <= r181745;
        bool r181747 = r181744 && r181746;
        bool r181748 = r181741 || r181747;
        double r181749 = 2.0;
        double r181750 = pow(r181726, r181749);
        double r181751 = 4.0;
        double r181752 = r181735 * r181732;
        double r181753 = r181751 * r181752;
        double r181754 = r181750 - r181753;
        double r181755 = sqrt(r181754);
        double r181756 = r181755 - r181726;
        double r181757 = r181756 / r181735;
        double r181758 = r181731 * r181757;
        double r181759 = -2.0;
        double r181760 = r181759 * r181733;
        double r181761 = r181731 * r181760;
        double r181762 = r181748 ? r181758 : r181761;
        double r181763 = r181728 ? r181739 : r181762;
        return r181763;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

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

Derivation

  1. Split input into 3 regimes
  2. if b < -1.4784065354805617e+60

    1. Initial program 39.0

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified39.0

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{1}{2}} \cdot \frac{\sqrt[3]{1}}{\frac{a}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}\]
    11. Simplified39.0

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

      \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(2 \cdot \frac{c}{b} - 2 \cdot \frac{b}{a}\right)}\]
    13. Simplified5.5

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

    if -1.4784065354805617e+60 < b < 2.175674080408203e-169 or 4.731827132847258e-110 < b < 0.00018465375781150442

    1. Initial program 15.2

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified15.2

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

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

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

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

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

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

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

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

    if 2.175674080408203e-169 < b < 4.731827132847258e-110 or 0.00018465375781150442 < b

    1. Initial program 51.7

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified51.7

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied clear-num51.7

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity51.7

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

      \[\leadsto \frac{1}{\color{blue}{\frac{2}{1} \cdot \frac{a}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}}\]
    8. Applied add-cube-cbrt51.7

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

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

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

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

      \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(-2 \cdot \frac{c}{b}\right)}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification11.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.478406535480561669630649836752919254545 \cdot 10^{60}:\\ \;\;\;\;\frac{1}{2} \cdot \mathsf{fma}\left(2, \frac{c}{b}, -2 \cdot \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 2.175674080408202904737521150531781836244 \cdot 10^{-169} \lor \neg \left(b \le 4.731827132847258030366645007940380497628 \cdot 10^{-110}\right) \land b \le 1.846537578115044209159378851836663670838 \cdot 10^{-4}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{\sqrt{{b}^{2} - 4 \cdot \left(a \cdot c\right)} - b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2} \cdot \left(-2 \cdot \frac{c}{b}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019350 +o rules:numerics
(FPCore (a b c)
  :name "The quadratic formula (r1)"
  :precision binary64

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

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