Average Error: 33.1 → 11.0
Time: 34.5s
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 -2.7503548021140933 \cdot 10^{-65}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -5.61762387795767 \cdot 10^{-100}:\\ \;\;\;\;\frac{-\frac{\mathsf{fma}\left(b \cdot b, b, \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)} \cdot \mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)\right)}{\mathsf{fma}\left(\sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}, \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)} - b, b \cdot b\right)}}{2 \cdot a}\\ \mathbf{elif}\;b \le -4.884190020998732 \cdot 10^{-159}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le 7.377921431051488 \cdot 10^{+75}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(a \cdot -4, c, b \cdot b\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) - b}{2 \cdot 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 -2.7503548021140933 \cdot 10^{-65}:\\
\;\;\;\;\frac{-c}{b}\\

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

\mathbf{elif}\;b \le -4.884190020998732 \cdot 10^{-159}:\\
\;\;\;\;\frac{-c}{b}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r2251860 = b;
        double r2251861 = -r2251860;
        double r2251862 = r2251860 * r2251860;
        double r2251863 = 4.0;
        double r2251864 = a;
        double r2251865 = c;
        double r2251866 = r2251864 * r2251865;
        double r2251867 = r2251863 * r2251866;
        double r2251868 = r2251862 - r2251867;
        double r2251869 = sqrt(r2251868);
        double r2251870 = r2251861 - r2251869;
        double r2251871 = 2.0;
        double r2251872 = r2251871 * r2251864;
        double r2251873 = r2251870 / r2251872;
        return r2251873;
}

double f(double a, double b, double c) {
        double r2251874 = b;
        double r2251875 = -2.7503548021140933e-65;
        bool r2251876 = r2251874 <= r2251875;
        double r2251877 = c;
        double r2251878 = -r2251877;
        double r2251879 = r2251878 / r2251874;
        double r2251880 = -5.61762387795767e-100;
        bool r2251881 = r2251874 <= r2251880;
        double r2251882 = r2251874 * r2251874;
        double r2251883 = a;
        double r2251884 = -4.0;
        double r2251885 = r2251883 * r2251884;
        double r2251886 = fma(r2251877, r2251885, r2251882);
        double r2251887 = sqrt(r2251886);
        double r2251888 = r2251887 * r2251886;
        double r2251889 = fma(r2251882, r2251874, r2251888);
        double r2251890 = r2251887 - r2251874;
        double r2251891 = fma(r2251887, r2251890, r2251882);
        double r2251892 = r2251889 / r2251891;
        double r2251893 = -r2251892;
        double r2251894 = 2.0;
        double r2251895 = r2251894 * r2251883;
        double r2251896 = r2251893 / r2251895;
        double r2251897 = -4.884190020998732e-159;
        bool r2251898 = r2251874 <= r2251897;
        double r2251899 = 7.377921431051488e+75;
        bool r2251900 = r2251874 <= r2251899;
        double r2251901 = -r2251874;
        double r2251902 = fma(r2251885, r2251877, r2251882);
        double r2251903 = sqrt(r2251902);
        double r2251904 = r2251901 - r2251903;
        double r2251905 = r2251904 / r2251895;
        double r2251906 = r2251901 - r2251874;
        double r2251907 = r2251906 / r2251895;
        double r2251908 = r2251900 ? r2251905 : r2251907;
        double r2251909 = r2251898 ? r2251879 : r2251908;
        double r2251910 = r2251881 ? r2251896 : r2251909;
        double r2251911 = r2251876 ? r2251879 : r2251910;
        return r2251911;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.1
Target20.8
Herbie11.0
\[\begin{array}{l} \mathbf{if}\;b \lt 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 < -2.7503548021140933e-65 or -5.61762387795767e-100 < b < -4.884190020998732e-159

    1. Initial program 49.6

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

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

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

    if -2.7503548021140933e-65 < b < -5.61762387795767e-100

    1. Initial program 26.8

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

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

      \[\leadsto \frac{\left(-b\right) - \sqrt{\color{blue}{\mathsf{fma}\left(a \cdot -4, c, b \cdot b\right)}}}{2 \cdot a}\]
    4. Using strategy rm
    5. Applied flip3--34.0

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

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

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

    if -4.884190020998732e-159 < b < 7.377921431051488e+75

    1. Initial program 11.2

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

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

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

    if 7.377921431051488e+75 < b

    1. Initial program 39.3

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.7503548021140933 \cdot 10^{-65}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -5.61762387795767 \cdot 10^{-100}:\\ \;\;\;\;\frac{-\frac{\mathsf{fma}\left(b \cdot b, b, \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)} \cdot \mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)\right)}{\mathsf{fma}\left(\sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}, \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)} - b, b \cdot b\right)}}{2 \cdot a}\\ \mathbf{elif}\;b \le -4.884190020998732 \cdot 10^{-159}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le 7.377921431051488 \cdot 10^{+75}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(a \cdot -4, c, b \cdot b\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< b 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)))