Average Error: 19.8 → 8.0
Time: 15.0s
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.33861703157570726 \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(-b\right) + \left(2 \cdot \frac{a \cdot c}{b} - b\right)}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \le 1.77017414835012383 \cdot 10^{70}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \left|\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}\right| \cdot \sqrt{\sqrt[3]{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}\\ \mathbf{elif}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \left(b - 2 \cdot \left(\left(\frac{a}{\sqrt[3]{b} \cdot \sqrt[3]{b}} \cdot \left(\sqrt[3]{\frac{c}{\sqrt[3]{b}}} \cdot \sqrt[3]{\frac{c}{\sqrt[3]{b}}}\right)\right) \cdot \sqrt[3]{\frac{c}{\sqrt[3]{b}}}\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \frac{\sqrt{{\left(b \cdot b\right)}^{3} - {\left(\left(4 \cdot a\right) \cdot c\right)}^{3}}}{\sqrt{\left(b \cdot b\right) \cdot \left(b \cdot b\right) + \left(\left(\left(4 \cdot a\right) \cdot c\right) \cdot \left(\left(4 \cdot a\right) \cdot c\right) + \left(b \cdot b\right) \cdot \left(\left(4 \cdot a\right) \cdot c\right)\right)}}}{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.33861703157570726 \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(-b\right) + \left(2 \cdot \frac{a \cdot c}{b} - b\right)}{2 \cdot a}\\

\end{array}\\

\mathbf{elif}\;b \le 1.77017414835012383 \cdot 10^{70}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0.0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \left|\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}\right| \cdot \sqrt{\sqrt[3]{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}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r114 = b;
        double r115 = 0.0;
        bool r116 = r114 >= r115;
        double r117 = 2.0;
        double r118 = c;
        double r119 = r117 * r118;
        double r120 = -r114;
        double r121 = r114 * r114;
        double r122 = 4.0;
        double r123 = a;
        double r124 = r122 * r123;
        double r125 = r124 * r118;
        double r126 = r121 - r125;
        double r127 = sqrt(r126);
        double r128 = r120 - r127;
        double r129 = r119 / r128;
        double r130 = r120 + r127;
        double r131 = r117 * r123;
        double r132 = r130 / r131;
        double r133 = r116 ? r129 : r132;
        return r133;
}

double f(double a, double b, double c) {
        double r134 = b;
        double r135 = -1.3386170315757073e+154;
        bool r136 = r134 <= r135;
        double r137 = 0.0;
        bool r138 = r134 >= r137;
        double r139 = 2.0;
        double r140 = c;
        double r141 = r139 * r140;
        double r142 = -r134;
        double r143 = r134 * r134;
        double r144 = 4.0;
        double r145 = a;
        double r146 = r144 * r145;
        double r147 = r146 * r140;
        double r148 = r143 - r147;
        double r149 = sqrt(r148);
        double r150 = r142 - r149;
        double r151 = r141 / r150;
        double r152 = r145 * r140;
        double r153 = r152 / r134;
        double r154 = r139 * r153;
        double r155 = r154 - r134;
        double r156 = r142 + r155;
        double r157 = r139 * r145;
        double r158 = r156 / r157;
        double r159 = r138 ? r151 : r158;
        double r160 = 1.7701741483501238e+70;
        bool r161 = r134 <= r160;
        double r162 = cbrt(r148);
        double r163 = fabs(r162);
        double r164 = sqrt(r162);
        double r165 = r163 * r164;
        double r166 = r142 - r165;
        double r167 = r141 / r166;
        double r168 = r142 + r149;
        double r169 = r168 / r157;
        double r170 = r138 ? r167 : r169;
        double r171 = cbrt(r134);
        double r172 = r171 * r171;
        double r173 = r145 / r172;
        double r174 = r140 / r171;
        double r175 = cbrt(r174);
        double r176 = r175 * r175;
        double r177 = r173 * r176;
        double r178 = r177 * r175;
        double r179 = r139 * r178;
        double r180 = r134 - r179;
        double r181 = r142 - r180;
        double r182 = r141 / r181;
        double r183 = 3.0;
        double r184 = pow(r143, r183);
        double r185 = pow(r147, r183);
        double r186 = r184 - r185;
        double r187 = sqrt(r186);
        double r188 = r143 * r143;
        double r189 = r147 * r147;
        double r190 = r143 * r147;
        double r191 = r189 + r190;
        double r192 = r188 + r191;
        double r193 = sqrt(r192);
        double r194 = r187 / r193;
        double r195 = r142 + r194;
        double r196 = r195 / r157;
        double r197 = r138 ? r182 : r196;
        double r198 = r161 ? r170 : r197;
        double r199 = r136 ? r159 : r198;
        return r199;
}

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.3386170315757073e+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. Taylor expanded around -inf 11.6

      \[\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(-b\right) + \left(2 \cdot \frac{a \cdot c}{b} - b\right)}{2 \cdot a}\\ \end{array}\]

    if -1.3386170315757073e+154 < b < 1.7701741483501238e+70

    1. Initial program 9.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. Using strategy rm
    3. Applied add-cube-cbrt9.2

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\color{blue}{\left(\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \sqrt[3]{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}\]
    4. Applied sqrt-prod9.2

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \color{blue}{\sqrt{\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\sqrt[3]{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}\]
    5. Simplified9.2

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \color{blue}{\left|\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}\right|} \cdot \sqrt{\sqrt[3]{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}\]

    if 1.7701741483501238e+70 < b

    1. Initial program 27.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. Taylor expanded around inf 7.2

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

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

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

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \left(b - 2 \cdot \left(\left(\frac{a}{\sqrt[3]{b} \cdot \sqrt[3]{b}} \cdot \left(\sqrt[3]{\frac{c}{\sqrt[3]{b}}} \cdot \sqrt[3]{\frac{c}{\sqrt[3]{b}}}\right)\right) \cdot \sqrt[3]{\frac{c}{\sqrt[3]{b}}}\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{\frac{{\left(b \cdot b\right)}^{3} - {\left(\left(4 \cdot a\right) \cdot c\right)}^{3}}{\left(b \cdot b\right) \cdot \left(b \cdot b\right) + \left(\left(\left(4 \cdot a\right) \cdot c\right) \cdot \left(\left(4 \cdot a\right) \cdot c\right) + \left(b \cdot b\right) \cdot \left(\left(4 \cdot a\right) \cdot c\right)\right)}}}{2 \cdot a}\\ \end{array}\]
    11. Applied sqrt-div3.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.33861703157570726 \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(-b\right) + \left(2 \cdot \frac{a \cdot c}{b} - b\right)}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \le 1.77017414835012383 \cdot 10^{70}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \left|\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}\right| \cdot \sqrt{\sqrt[3]{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}\\ \mathbf{elif}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \left(b - 2 \cdot \left(\left(\frac{a}{\sqrt[3]{b} \cdot \sqrt[3]{b}} \cdot \left(\sqrt[3]{\frac{c}{\sqrt[3]{b}}} \cdot \sqrt[3]{\frac{c}{\sqrt[3]{b}}}\right)\right) \cdot \sqrt[3]{\frac{c}{\sqrt[3]{b}}}\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \frac{\sqrt{{\left(b \cdot b\right)}^{3} - {\left(\left(4 \cdot a\right) \cdot c\right)}^{3}}}{\sqrt{\left(b \cdot b\right) \cdot \left(b \cdot b\right) + \left(\left(\left(4 \cdot a\right) \cdot c\right) \cdot \left(\left(4 \cdot a\right) \cdot c\right) + \left(b \cdot b\right) \cdot \left(\left(4 \cdot a\right) \cdot c\right)\right)}}}{2 \cdot a}\\ \end{array}\]

Reproduce

herbie shell --seed 2020025 +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))))