Average Error: 34.0 → 12.1
Time: 26.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 -8.544460916074322 \cdot 10^{-48}:\\ \;\;\;\;\frac{-2 \cdot \frac{c}{b}}{2}\\ \mathbf{elif}\;b \le 1.5983000936606613 \cdot 10^{-121}:\\ \;\;\;\;\frac{\frac{\frac{b \cdot b - \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)} \cdot \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}{\sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)} + \left(-b\right)}}{a}}{2}\\ \mathbf{elif}\;b \le 2.6656023684116586 \cdot 10^{+55}:\\ \;\;\;\;\frac{\frac{-\frac{\mathsf{fma}\left(b \cdot b, b, \mathsf{fma}\left(a, -4 \cdot c, b \cdot b\right) \cdot \sqrt{\mathsf{fma}\left(a, -4 \cdot c, b \cdot b\right)}\right)}{\mathsf{fma}\left(\sqrt{\mathsf{fma}\left(a, -4 \cdot c, b \cdot b\right)}, \sqrt{\mathsf{fma}\left(a, -4 \cdot c, b \cdot b\right)} - b, b \cdot b\right)}}{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{b}{a} \cdot -2}{2}\\ \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 -8.544460916074322 \cdot 10^{-48}:\\
\;\;\;\;\frac{-2 \cdot \frac{c}{b}}{2}\\

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

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

\mathbf{else}:\\
\;\;\;\;\frac{\frac{b}{a} \cdot -2}{2}\\

\end{array}
double f(double a, double b, double c) {
        double r2888912 = b;
        double r2888913 = -r2888912;
        double r2888914 = r2888912 * r2888912;
        double r2888915 = 4.0;
        double r2888916 = a;
        double r2888917 = c;
        double r2888918 = r2888916 * r2888917;
        double r2888919 = r2888915 * r2888918;
        double r2888920 = r2888914 - r2888919;
        double r2888921 = sqrt(r2888920);
        double r2888922 = r2888913 - r2888921;
        double r2888923 = 2.0;
        double r2888924 = r2888923 * r2888916;
        double r2888925 = r2888922 / r2888924;
        return r2888925;
}

double f(double a, double b, double c) {
        double r2888926 = b;
        double r2888927 = -8.544460916074322e-48;
        bool r2888928 = r2888926 <= r2888927;
        double r2888929 = -2.0;
        double r2888930 = c;
        double r2888931 = r2888930 / r2888926;
        double r2888932 = r2888929 * r2888931;
        double r2888933 = 2.0;
        double r2888934 = r2888932 / r2888933;
        double r2888935 = 1.5983000936606613e-121;
        bool r2888936 = r2888926 <= r2888935;
        double r2888937 = r2888926 * r2888926;
        double r2888938 = a;
        double r2888939 = -4.0;
        double r2888940 = r2888938 * r2888939;
        double r2888941 = fma(r2888930, r2888940, r2888937);
        double r2888942 = sqrt(r2888941);
        double r2888943 = r2888942 * r2888942;
        double r2888944 = r2888937 - r2888943;
        double r2888945 = -r2888926;
        double r2888946 = r2888942 + r2888945;
        double r2888947 = r2888944 / r2888946;
        double r2888948 = r2888947 / r2888938;
        double r2888949 = r2888948 / r2888933;
        double r2888950 = 2.6656023684116586e+55;
        bool r2888951 = r2888926 <= r2888950;
        double r2888952 = r2888939 * r2888930;
        double r2888953 = fma(r2888938, r2888952, r2888937);
        double r2888954 = sqrt(r2888953);
        double r2888955 = r2888953 * r2888954;
        double r2888956 = fma(r2888937, r2888926, r2888955);
        double r2888957 = r2888954 - r2888926;
        double r2888958 = fma(r2888954, r2888957, r2888937);
        double r2888959 = r2888956 / r2888958;
        double r2888960 = -r2888959;
        double r2888961 = r2888960 / r2888938;
        double r2888962 = r2888961 / r2888933;
        double r2888963 = r2888926 / r2888938;
        double r2888964 = r2888963 * r2888929;
        double r2888965 = r2888964 / r2888933;
        double r2888966 = r2888951 ? r2888962 : r2888965;
        double r2888967 = r2888936 ? r2888949 : r2888966;
        double r2888968 = r2888928 ? r2888934 : r2888967;
        return r2888968;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original34.0
Target21.3
Herbie12.1
\[\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 < -8.544460916074322e-48

    1. Initial program 54.0

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

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

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

    if -8.544460916074322e-48 < b < 1.5983000936606613e-121

    1. Initial program 19.2

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

      \[\leadsto \color{blue}{\frac{\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(-4 \cdot a, c, b \cdot b\right)}}{a}}{2}}\]
    3. Using strategy rm
    4. Applied *-un-lft-identity19.2

      \[\leadsto \frac{\frac{\left(-b\right) - \color{blue}{1 \cdot \sqrt{\mathsf{fma}\left(-4 \cdot a, c, b \cdot b\right)}}}{a}}{2}\]
    5. Applied *-un-lft-identity19.2

      \[\leadsto \frac{\frac{\color{blue}{1 \cdot \left(-b\right)} - 1 \cdot \sqrt{\mathsf{fma}\left(-4 \cdot a, c, b \cdot b\right)}}{a}}{2}\]
    6. Applied distribute-lft-out--19.2

      \[\leadsto \frac{\frac{\color{blue}{1 \cdot \left(\left(-b\right) - \sqrt{\mathsf{fma}\left(-4 \cdot a, c, b \cdot b\right)}\right)}}{a}}{2}\]
    7. Applied associate-/l*19.3

      \[\leadsto \frac{\color{blue}{\frac{1}{\frac{a}{\left(-b\right) - \sqrt{\mathsf{fma}\left(-4 \cdot a, c, b \cdot b\right)}}}}}{2}\]
    8. Using strategy rm
    9. Applied *-un-lft-identity19.3

      \[\leadsto \frac{\frac{1}{\frac{a}{\left(-b\right) - \color{blue}{1 \cdot \sqrt{\mathsf{fma}\left(-4 \cdot a, c, b \cdot b\right)}}}}}{2}\]
    10. Applied *-un-lft-identity19.3

      \[\leadsto \frac{\frac{1}{\frac{a}{\color{blue}{1 \cdot \left(-b\right)} - 1 \cdot \sqrt{\mathsf{fma}\left(-4 \cdot a, c, b \cdot b\right)}}}}{2}\]
    11. Applied distribute-lft-out--19.3

      \[\leadsto \frac{\frac{1}{\frac{a}{\color{blue}{1 \cdot \left(\left(-b\right) - \sqrt{\mathsf{fma}\left(-4 \cdot a, c, b \cdot b\right)}\right)}}}}{2}\]
    12. Applied *-un-lft-identity19.3

      \[\leadsto \frac{\frac{1}{\frac{\color{blue}{1 \cdot a}}{1 \cdot \left(\left(-b\right) - \sqrt{\mathsf{fma}\left(-4 \cdot a, c, b \cdot b\right)}\right)}}}{2}\]
    13. Applied times-frac19.3

      \[\leadsto \frac{\frac{1}{\color{blue}{\frac{1}{1} \cdot \frac{a}{\left(-b\right) - \sqrt{\mathsf{fma}\left(-4 \cdot a, c, b \cdot b\right)}}}}}{2}\]
    14. Applied *-un-lft-identity19.3

      \[\leadsto \frac{\frac{\color{blue}{1 \cdot 1}}{\frac{1}{1} \cdot \frac{a}{\left(-b\right) - \sqrt{\mathsf{fma}\left(-4 \cdot a, c, b \cdot b\right)}}}}{2}\]
    15. Applied times-frac19.3

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

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

      \[\leadsto \frac{1 \cdot \color{blue}{\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(c, -4 \cdot a, b \cdot b\right)}}{a}}}{2}\]
    18. Using strategy rm
    19. Applied flip--21.1

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

    if 1.5983000936606613e-121 < b < 2.6656023684116586e+55

    1. Initial program 5.8

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

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

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

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

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

    if 2.6656023684116586e+55 < b

    1. Initial program 37.1

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

      \[\leadsto \color{blue}{\frac{\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(-4 \cdot a, c, b \cdot b\right)}}{a}}{2}}\]
    3. Using strategy rm
    4. Applied *-un-lft-identity37.1

      \[\leadsto \frac{\frac{\left(-b\right) - \color{blue}{1 \cdot \sqrt{\mathsf{fma}\left(-4 \cdot a, c, b \cdot b\right)}}}{a}}{2}\]
    5. Applied *-un-lft-identity37.1

      \[\leadsto \frac{\frac{\color{blue}{1 \cdot \left(-b\right)} - 1 \cdot \sqrt{\mathsf{fma}\left(-4 \cdot a, c, b \cdot b\right)}}{a}}{2}\]
    6. Applied distribute-lft-out--37.1

      \[\leadsto \frac{\frac{\color{blue}{1 \cdot \left(\left(-b\right) - \sqrt{\mathsf{fma}\left(-4 \cdot a, c, b \cdot b\right)}\right)}}{a}}{2}\]
    7. Applied associate-/l*37.2

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

      \[\leadsto \frac{\color{blue}{-2 \cdot \frac{b}{a}}}{2}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification12.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -8.544460916074322 \cdot 10^{-48}:\\ \;\;\;\;\frac{-2 \cdot \frac{c}{b}}{2}\\ \mathbf{elif}\;b \le 1.5983000936606613 \cdot 10^{-121}:\\ \;\;\;\;\frac{\frac{\frac{b \cdot b - \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)} \cdot \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}{\sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)} + \left(-b\right)}}{a}}{2}\\ \mathbf{elif}\;b \le 2.6656023684116586 \cdot 10^{+55}:\\ \;\;\;\;\frac{\frac{-\frac{\mathsf{fma}\left(b \cdot b, b, \mathsf{fma}\left(a, -4 \cdot c, b \cdot b\right) \cdot \sqrt{\mathsf{fma}\left(a, -4 \cdot c, b \cdot b\right)}\right)}{\mathsf{fma}\left(\sqrt{\mathsf{fma}\left(a, -4 \cdot c, b \cdot b\right)}, \sqrt{\mathsf{fma}\left(a, -4 \cdot c, b \cdot b\right)} - b, b \cdot b\right)}}{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{b}{a} \cdot -2}{2}\\ \end{array}\]

Reproduce

herbie shell --seed 2019141 +o rules:numerics
(FPCore (a b c)
  :name "The quadratic formula (r2)"

  :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)))