Average Error: 34.6 → 7.0
Time: 14.3s
Precision: 64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -3995085856351435358208:\\ \;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\ \mathbf{elif}\;b \le -3.157831273622663951144423397678142349188 \cdot 10^{-243}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\sqrt[3]{b} \cdot \sqrt[3]{b}, -\sqrt[3]{b}, \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}\right)}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.721977985627455758133160718776844978069 \cdot 10^{83}:\\ \;\;\;\;\frac{4 \cdot c}{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, \left(4 \cdot c\right) \cdot \left(-a\right)\right)}} \cdot \frac{1}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -1\\ \end{array}\]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \le -3995085856351435358208:\\
\;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\

\mathbf{elif}\;b \le -3.157831273622663951144423397678142349188 \cdot 10^{-243}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\sqrt[3]{b} \cdot \sqrt[3]{b}, -\sqrt[3]{b}, \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}\right)}{a \cdot 2}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{c}{b} \cdot -1\\

\end{array}
double f(double a, double b, double c) {
        double r114854 = b;
        double r114855 = -r114854;
        double r114856 = r114854 * r114854;
        double r114857 = 4.0;
        double r114858 = a;
        double r114859 = r114857 * r114858;
        double r114860 = c;
        double r114861 = r114859 * r114860;
        double r114862 = r114856 - r114861;
        double r114863 = sqrt(r114862);
        double r114864 = r114855 + r114863;
        double r114865 = 2.0;
        double r114866 = r114865 * r114858;
        double r114867 = r114864 / r114866;
        return r114867;
}

double f(double a, double b, double c) {
        double r114868 = b;
        double r114869 = -3.9950858563514354e+21;
        bool r114870 = r114868 <= r114869;
        double r114871 = c;
        double r114872 = r114871 / r114868;
        double r114873 = a;
        double r114874 = r114868 / r114873;
        double r114875 = r114872 - r114874;
        double r114876 = 1.0;
        double r114877 = r114875 * r114876;
        double r114878 = -3.157831273622664e-243;
        bool r114879 = r114868 <= r114878;
        double r114880 = cbrt(r114868);
        double r114881 = r114880 * r114880;
        double r114882 = -r114880;
        double r114883 = r114868 * r114868;
        double r114884 = 4.0;
        double r114885 = r114873 * r114884;
        double r114886 = r114871 * r114885;
        double r114887 = r114883 - r114886;
        double r114888 = sqrt(r114887);
        double r114889 = fma(r114881, r114882, r114888);
        double r114890 = 2.0;
        double r114891 = r114873 * r114890;
        double r114892 = r114889 / r114891;
        double r114893 = 1.7219779856274558e+83;
        bool r114894 = r114868 <= r114893;
        double r114895 = r114884 * r114871;
        double r114896 = -r114868;
        double r114897 = -r114873;
        double r114898 = r114895 * r114897;
        double r114899 = fma(r114868, r114868, r114898);
        double r114900 = sqrt(r114899);
        double r114901 = r114896 - r114900;
        double r114902 = r114895 / r114901;
        double r114903 = 1.0;
        double r114904 = r114903 / r114890;
        double r114905 = r114902 * r114904;
        double r114906 = -1.0;
        double r114907 = r114872 * r114906;
        double r114908 = r114894 ? r114905 : r114907;
        double r114909 = r114879 ? r114892 : r114908;
        double r114910 = r114870 ? r114877 : r114909;
        return r114910;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original34.6
Target21.0
Herbie7.0
\[\begin{array}{l} \mathbf{if}\;b \lt 0.0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if b < -3.9950858563514354e+21

    1. Initial program 35.4

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

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

      \[\leadsto \color{blue}{1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)}\]

    if -3.9950858563514354e+21 < b < -3.157831273622664e-243

    1. Initial program 9.4

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied add-cube-cbrt9.7

      \[\leadsto \frac{\left(-\color{blue}{\left(\sqrt[3]{b} \cdot \sqrt[3]{b}\right) \cdot \sqrt[3]{b}}\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    4. Applied distribute-rgt-neg-in9.7

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{b} \cdot \sqrt[3]{b}\right) \cdot \left(-\sqrt[3]{b}\right)} + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    5. Applied fma-def9.7

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

    if -3.157831273622664e-243 < b < 1.7219779856274558e+83

    1. Initial program 29.5

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied flip-+29.6

      \[\leadsto \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}\]
    4. Simplified16.0

      \[\leadsto \frac{\frac{\color{blue}{0 + \left(4 \cdot c\right) \cdot a}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\]
    5. Simplified16.0

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

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

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

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

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

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

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

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

    if 1.7219779856274558e+83 < b

    1. Initial program 59.0

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification7.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -3995085856351435358208:\\ \;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\ \mathbf{elif}\;b \le -3.157831273622663951144423397678142349188 \cdot 10^{-243}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\sqrt[3]{b} \cdot \sqrt[3]{b}, -\sqrt[3]{b}, \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}\right)}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.721977985627455758133160718776844978069 \cdot 10^{83}:\\ \;\;\;\;\frac{4 \cdot c}{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, \left(4 \cdot c\right) \cdot \left(-a\right)\right)}} \cdot \frac{1}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -1\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))))

  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))