Average Error: 19.6 → 8.3
Time: 23.5s
Precision: 64
\[\begin{array}{l} \mathbf{if}\;b \ge 0.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 -1.367002129773412099713675796535889049973 \cdot 10^{154}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(2 \cdot \frac{a \cdot c}{b} - b\right) - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \le 17754385347718217013022045448400749461500:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{2 \cdot \left(\left(\frac{a}{\sqrt[3]{b} \cdot \sqrt[3]{b}} \cdot \frac{\sqrt[3]{c} \cdot \sqrt[3]{c}}{\sqrt[3]{\sqrt{b}}}\right) \cdot \frac{\sqrt[3]{c}}{\sqrt[3]{\sqrt{b}}}\right) - 2 \cdot b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}\\ \end{array}\]
\begin{array}{l}
\mathbf{if}\;b \ge 0.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 -1.367002129773412099713675796535889049973 \cdot 10^{154}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0.0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\

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

\end{array}\\

\mathbf{elif}\;b \le 17754385347718217013022045448400749461500:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0.0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\\

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

\end{array}\\

\mathbf{elif}\;b \ge 0.0:\\
\;\;\;\;\frac{2 \cdot c}{2 \cdot \left(\left(\frac{a}{\sqrt[3]{b} \cdot \sqrt[3]{b}} \cdot \frac{\sqrt[3]{c} \cdot \sqrt[3]{c}}{\sqrt[3]{\sqrt{b}}}\right) \cdot \frac{\sqrt[3]{c}}{\sqrt[3]{\sqrt{b}}}\right) - 2 \cdot b}\\

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

\end{array}
double f(double a, double b, double c) {
        double r33668 = b;
        double r33669 = 0.0;
        bool r33670 = r33668 >= r33669;
        double r33671 = 2.0;
        double r33672 = c;
        double r33673 = r33671 * r33672;
        double r33674 = -r33668;
        double r33675 = r33668 * r33668;
        double r33676 = 4.0;
        double r33677 = a;
        double r33678 = r33676 * r33677;
        double r33679 = r33678 * r33672;
        double r33680 = r33675 - r33679;
        double r33681 = sqrt(r33680);
        double r33682 = r33674 - r33681;
        double r33683 = r33673 / r33682;
        double r33684 = r33674 + r33681;
        double r33685 = r33671 * r33677;
        double r33686 = r33684 / r33685;
        double r33687 = r33670 ? r33683 : r33686;
        return r33687;
}

double f(double a, double b, double c) {
        double r33688 = b;
        double r33689 = -1.367002129773412e+154;
        bool r33690 = r33688 <= r33689;
        double r33691 = 0.0;
        bool r33692 = r33688 >= r33691;
        double r33693 = 2.0;
        double r33694 = c;
        double r33695 = r33693 * r33694;
        double r33696 = -r33688;
        double r33697 = r33688 * r33688;
        double r33698 = 4.0;
        double r33699 = a;
        double r33700 = r33698 * r33699;
        double r33701 = r33700 * r33694;
        double r33702 = r33697 - r33701;
        double r33703 = sqrt(r33702);
        double r33704 = r33696 - r33703;
        double r33705 = r33695 / r33704;
        double r33706 = r33699 * r33694;
        double r33707 = r33706 / r33688;
        double r33708 = r33693 * r33707;
        double r33709 = r33708 - r33688;
        double r33710 = r33709 - r33688;
        double r33711 = r33693 * r33699;
        double r33712 = r33710 / r33711;
        double r33713 = r33692 ? r33705 : r33712;
        double r33714 = 1.7754385347718217e+40;
        bool r33715 = r33688 <= r33714;
        double r33716 = sqrt(r33703);
        double r33717 = r33716 * r33716;
        double r33718 = r33696 - r33717;
        double r33719 = r33695 / r33718;
        double r33720 = r33703 - r33688;
        double r33721 = r33720 / r33711;
        double r33722 = r33692 ? r33719 : r33721;
        double r33723 = cbrt(r33688);
        double r33724 = r33723 * r33723;
        double r33725 = r33699 / r33724;
        double r33726 = cbrt(r33694);
        double r33727 = r33726 * r33726;
        double r33728 = sqrt(r33688);
        double r33729 = cbrt(r33728);
        double r33730 = r33727 / r33729;
        double r33731 = r33725 * r33730;
        double r33732 = r33726 / r33729;
        double r33733 = r33731 * r33732;
        double r33734 = r33693 * r33733;
        double r33735 = 2.0;
        double r33736 = r33735 * r33688;
        double r33737 = r33734 - r33736;
        double r33738 = r33695 / r33737;
        double r33739 = r33692 ? r33738 : r33721;
        double r33740 = r33715 ? r33722 : r33739;
        double r33741 = r33690 ? r33713 : r33740;
        return r33741;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if b < -1.367002129773412e+154

    1. Initial program 64.0

      \[\begin{array}{l} \mathbf{if}\;b \ge 0.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. Simplified64.0

      \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}\\ \end{array}}\]
    3. Taylor expanded around -inf 11.5

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

    if -1.367002129773412e+154 < b < 1.7754385347718217e+40

    1. Initial program 9.6

      \[\begin{array}{l} \mathbf{if}\;b \ge 0.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. Simplified9.6

      \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}\\ \end{array}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt9.6

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\color{blue}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}\\ \end{array}\]
    5. Applied sqrt-prod9.7

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

    if 1.7754385347718217e+40 < b

    1. Initial program 24.0

      \[\begin{array}{l} \mathbf{if}\;b \ge 0.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. Simplified24.0

      \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}\\ \end{array}}\]
    3. Taylor expanded around inf 7.5

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\color{blue}{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}\\ \end{array}\]
    4. Using strategy rm
    5. Applied add-cube-cbrt7.5

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{2 \cdot \frac{a \cdot c}{\color{blue}{\left(\sqrt[3]{b} \cdot \sqrt[3]{b}\right) \cdot \sqrt[3]{b}}} - 2 \cdot b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}\\ \end{array}\]
    6. Applied times-frac4.5

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{2 \cdot \color{blue}{\left(\frac{a}{\sqrt[3]{b} \cdot \sqrt[3]{b}} \cdot \frac{c}{\sqrt[3]{b}}\right)} - 2 \cdot b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}\\ \end{array}\]
    7. Using strategy rm
    8. Applied add-sqr-sqrt4.5

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{2 \cdot \left(\frac{a}{\sqrt[3]{b} \cdot \sqrt[3]{b}} \cdot \frac{c}{\sqrt[3]{\color{blue}{\sqrt{b} \cdot \sqrt{b}}}}\right) - 2 \cdot b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}\\ \end{array}\]
    9. Applied cbrt-prod4.5

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{2 \cdot \left(\frac{a}{\sqrt[3]{b} \cdot \sqrt[3]{b}} \cdot \frac{c}{\color{blue}{\sqrt[3]{\sqrt{b}} \cdot \sqrt[3]{\sqrt{b}}}}\right) - 2 \cdot b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}\\ \end{array}\]
    10. Applied add-cube-cbrt4.5

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{2 \cdot \left(\frac{a}{\sqrt[3]{b} \cdot \sqrt[3]{b}} \cdot \frac{\color{blue}{\left(\sqrt[3]{c} \cdot \sqrt[3]{c}\right) \cdot \sqrt[3]{c}}}{\sqrt[3]{\sqrt{b}} \cdot \sqrt[3]{\sqrt{b}}}\right) - 2 \cdot b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}\\ \end{array}\]
    11. Applied times-frac4.5

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{2 \cdot \left(\frac{a}{\sqrt[3]{b} \cdot \sqrt[3]{b}} \cdot \color{blue}{\left(\frac{\sqrt[3]{c} \cdot \sqrt[3]{c}}{\sqrt[3]{\sqrt{b}}} \cdot \frac{\sqrt[3]{c}}{\sqrt[3]{\sqrt{b}}}\right)}\right) - 2 \cdot b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}\\ \end{array}\]
    12. Applied associate-*r*4.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.367002129773412099713675796535889049973 \cdot 10^{154}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(2 \cdot \frac{a \cdot c}{b} - b\right) - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \le 17754385347718217013022045448400749461500:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{2 \cdot \left(\left(\frac{a}{\sqrt[3]{b} \cdot \sqrt[3]{b}} \cdot \frac{\sqrt[3]{c} \cdot \sqrt[3]{c}}{\sqrt[3]{\sqrt{b}}}\right) \cdot \frac{\sqrt[3]{c}}{\sqrt[3]{\sqrt{b}}}\right) - 2 \cdot b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}\\ \end{array}\]

Reproduce

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