Average Error: 19.9 → 7.8
Time: 11.0s
Precision: 64
\[\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]
\[\begin{array}{l} \mathbf{if}\;b \le -1.333300421862763794492150706903049815887 \cdot 10^{154}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(2, \frac{a \cdot c}{b}, -2 \cdot b\right)}\\ \end{array}\\ \mathbf{elif}\;b \le 1.160883915256953043937503703321280239271 \cdot 10^{-293}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\frac{\left(a \cdot c\right) \cdot 4}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}\\ \end{array}\\ \mathbf{elif}\;b \le 1.191203142513164639216663918436976252985 \cdot 10^{117}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(2, \frac{a \cdot c}{b}, -2 \cdot b\right)}\\ \end{array}\\ \mathbf{elif}\;b \ge 0.0:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(\sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}, \sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}, -b\right)}\\ \end{array}\]
\begin{array}{l}
\mathbf{if}\;b \ge 0.0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\

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

\end{array}
\begin{array}{l}
\mathbf{if}\;b \le -1.333300421862763794492150706903049815887 \cdot 10^{154}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0.0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\

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

\end{array}\\

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

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

\end{array}\\

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

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

\end{array}\\

\mathbf{elif}\;b \ge 0.0:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

\end{array}
double f(double a, double b, double c) {
        double r44033 = b;
        double r44034 = 0.0;
        bool r44035 = r44033 >= r44034;
        double r44036 = -r44033;
        double r44037 = r44033 * r44033;
        double r44038 = 4.0;
        double r44039 = a;
        double r44040 = r44038 * r44039;
        double r44041 = c;
        double r44042 = r44040 * r44041;
        double r44043 = r44037 - r44042;
        double r44044 = sqrt(r44043);
        double r44045 = r44036 - r44044;
        double r44046 = 2.0;
        double r44047 = r44046 * r44039;
        double r44048 = r44045 / r44047;
        double r44049 = r44046 * r44041;
        double r44050 = r44036 + r44044;
        double r44051 = r44049 / r44050;
        double r44052 = r44035 ? r44048 : r44051;
        return r44052;
}

double f(double a, double b, double c) {
        double r44053 = b;
        double r44054 = -1.3333004218627638e+154;
        bool r44055 = r44053 <= r44054;
        double r44056 = 0.0;
        bool r44057 = r44053 >= r44056;
        double r44058 = -r44053;
        double r44059 = r44053 * r44053;
        double r44060 = 4.0;
        double r44061 = a;
        double r44062 = r44060 * r44061;
        double r44063 = c;
        double r44064 = r44062 * r44063;
        double r44065 = r44059 - r44064;
        double r44066 = sqrt(r44065);
        double r44067 = r44058 - r44066;
        double r44068 = 2.0;
        double r44069 = r44068 * r44061;
        double r44070 = r44067 / r44069;
        double r44071 = r44068 * r44063;
        double r44072 = r44061 * r44063;
        double r44073 = r44072 / r44053;
        double r44074 = -2.0;
        double r44075 = r44074 * r44053;
        double r44076 = fma(r44068, r44073, r44075);
        double r44077 = r44071 / r44076;
        double r44078 = r44057 ? r44070 : r44077;
        double r44079 = 1.160883915256953e-293;
        bool r44080 = r44053 <= r44079;
        double r44081 = r44072 * r44060;
        double r44082 = r44066 - r44053;
        double r44083 = r44081 / r44082;
        double r44084 = r44083 / r44069;
        double r44085 = r44071 / r44082;
        double r44086 = r44057 ? r44084 : r44085;
        double r44087 = 1.1912031425131646e+117;
        bool r44088 = r44053 <= r44087;
        double r44089 = 1.0;
        double r44090 = r44063 / r44053;
        double r44091 = r44053 / r44061;
        double r44092 = r44090 - r44091;
        double r44093 = r44089 * r44092;
        double r44094 = cbrt(r44066);
        double r44095 = r44094 * r44094;
        double r44096 = fma(r44095, r44094, r44058);
        double r44097 = r44071 / r44096;
        double r44098 = r44057 ? r44093 : r44097;
        double r44099 = r44088 ? r44078 : r44098;
        double r44100 = r44080 ? r44086 : r44099;
        double r44101 = r44055 ? r44078 : r44100;
        return r44101;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 3 regimes
  2. if b < -1.3333004218627638e+154 or 1.160883915256953e-293 < b < 1.1912031425131646e+117

    1. Initial program 19.7

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

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

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

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

    if -1.3333004218627638e+154 < b < 1.160883915256953e-293

    1. Initial program 8.7

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

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

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

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

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

    if 1.1912031425131646e+117 < b

    1. Initial program 50.7

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.333300421862763794492150706903049815887 \cdot 10^{154}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(2, \frac{a \cdot c}{b}, -2 \cdot b\right)}\\ \end{array}\\ \mathbf{elif}\;b \le 1.160883915256953043937503703321280239271 \cdot 10^{-293}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\frac{\left(a \cdot c\right) \cdot 4}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}\\ \end{array}\\ \mathbf{elif}\;b \le 1.191203142513164639216663918436976252985 \cdot 10^{117}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(2, \frac{a \cdot c}{b}, -2 \cdot b\right)}\\ \end{array}\\ \mathbf{elif}\;b \ge 0.0:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(\sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}, \sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}, -b\right)}\\ \end{array}\]

Reproduce

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