Average Error: 34.7 → 11.0
Time: 7.1s
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 -5.87486430558009272 \cdot 10^{54}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -9.8475017814633646 \cdot 10^{24}:\\ \;\;\;\;\frac{\frac{0 + 4 \cdot \left(a \cdot c\right)}{\frac{\mathsf{fma}\left(b, b, -\left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)\right)}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}}{2 \cdot a}\\ \mathbf{elif}\;b \le -3.09798512605357415 \cdot 10^{-61}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 6.9721274759377412 \cdot 10^{134}:\\ \;\;\;\;1 \cdot \frac{\frac{1}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{\frac{\frac{2}{4} \cdot 1}{c}}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(-1 \cdot \frac{c}{b}\right)\\ \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 -5.87486430558009272 \cdot 10^{54}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

\mathbf{elif}\;b \le -3.09798512605357415 \cdot 10^{-61}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

\mathbf{elif}\;b \le 6.9721274759377412 \cdot 10^{134}:\\
\;\;\;\;1 \cdot \frac{\frac{1}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{\frac{\frac{2}{4} \cdot 1}{c}}\\

\mathbf{else}:\\
\;\;\;\;1 \cdot \left(-1 \cdot \frac{c}{b}\right)\\

\end{array}
double f(double a, double b, double c) {
        double r75854 = b;
        double r75855 = -r75854;
        double r75856 = r75854 * r75854;
        double r75857 = 4.0;
        double r75858 = a;
        double r75859 = r75857 * r75858;
        double r75860 = c;
        double r75861 = r75859 * r75860;
        double r75862 = r75856 - r75861;
        double r75863 = sqrt(r75862);
        double r75864 = r75855 + r75863;
        double r75865 = 2.0;
        double r75866 = r75865 * r75858;
        double r75867 = r75864 / r75866;
        return r75867;
}

double f(double a, double b, double c) {
        double r75868 = b;
        double r75869 = -5.874864305580093e+54;
        bool r75870 = r75868 <= r75869;
        double r75871 = 1.0;
        double r75872 = c;
        double r75873 = r75872 / r75868;
        double r75874 = a;
        double r75875 = r75868 / r75874;
        double r75876 = r75873 - r75875;
        double r75877 = r75871 * r75876;
        double r75878 = -9.847501781463365e+24;
        bool r75879 = r75868 <= r75878;
        double r75880 = 0.0;
        double r75881 = 4.0;
        double r75882 = r75874 * r75872;
        double r75883 = r75881 * r75882;
        double r75884 = r75880 + r75883;
        double r75885 = r75868 * r75868;
        double r75886 = r75881 * r75874;
        double r75887 = r75886 * r75872;
        double r75888 = r75885 - r75887;
        double r75889 = -r75888;
        double r75890 = fma(r75868, r75868, r75889);
        double r75891 = sqrt(r75888);
        double r75892 = r75891 - r75868;
        double r75893 = r75890 / r75892;
        double r75894 = r75884 / r75893;
        double r75895 = 2.0;
        double r75896 = r75895 * r75874;
        double r75897 = r75894 / r75896;
        double r75898 = -3.097985126053574e-61;
        bool r75899 = r75868 <= r75898;
        double r75900 = 6.972127475937741e+134;
        bool r75901 = r75868 <= r75900;
        double r75902 = 1.0;
        double r75903 = -r75868;
        double r75904 = r75903 - r75891;
        double r75905 = r75902 / r75904;
        double r75906 = r75895 / r75881;
        double r75907 = r75906 * r75902;
        double r75908 = r75907 / r75872;
        double r75909 = r75905 / r75908;
        double r75910 = r75902 * r75909;
        double r75911 = -1.0;
        double r75912 = r75911 * r75873;
        double r75913 = r75902 * r75912;
        double r75914 = r75901 ? r75910 : r75913;
        double r75915 = r75899 ? r75877 : r75914;
        double r75916 = r75879 ? r75897 : r75915;
        double r75917 = r75870 ? r75877 : r75916;
        return r75917;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original34.7
Target21.9
Herbie11.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 < -5.874864305580093e+54 or -9.847501781463365e+24 < b < -3.097985126053574e-61

    1. Initial program 32.6

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

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

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

    if -5.874864305580093e+54 < b < -9.847501781463365e+24

    1. Initial program 5.2

      \[\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-+50.9

      \[\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. Simplified50.9

      \[\leadsto \frac{\frac{\color{blue}{0 + 4 \cdot \left(a \cdot c\right)}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\]
    5. Using strategy rm
    6. Applied flip--50.9

      \[\leadsto \frac{\frac{0 + 4 \cdot \left(a \cdot c\right)}{\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}\]
    7. Simplified49.3

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

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

    if -3.097985126053574e-61 < b < 6.972127475937741e+134

    1. Initial program 26.9

      \[\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.7

      \[\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. Simplified17.8

      \[\leadsto \frac{\frac{\color{blue}{0 + 4 \cdot \left(a \cdot c\right)}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\]
    5. Using strategy rm
    6. Applied clear-num17.9

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

      \[\leadsto \frac{1}{\color{blue}{\frac{2 \cdot a}{4 \cdot \left(a \cdot c\right)} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}\]
    8. Using strategy rm
    9. Applied div-inv17.0

      \[\leadsto \color{blue}{1 \cdot \frac{1}{\frac{2 \cdot a}{4 \cdot \left(a \cdot c\right)} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}\]
    10. Simplified12.8

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

    if 6.972127475937741e+134 < b

    1. Initial program 62.0

      \[\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-+62.0

      \[\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. Simplified37.2

      \[\leadsto \frac{\frac{\color{blue}{0 + 4 \cdot \left(a \cdot c\right)}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\]
    5. Using strategy rm
    6. Applied clear-num37.2

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

      \[\leadsto \frac{1}{\color{blue}{\frac{2 \cdot a}{4 \cdot \left(a \cdot c\right)} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}\]
    8. Using strategy rm
    9. Applied div-inv36.7

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

      \[\leadsto 1 \cdot \color{blue}{\frac{\frac{1}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{\frac{\frac{2}{4} \cdot 1}{c}}}\]
    11. Taylor expanded around inf 2.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -5.87486430558009272 \cdot 10^{54}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -9.8475017814633646 \cdot 10^{24}:\\ \;\;\;\;\frac{\frac{0 + 4 \cdot \left(a \cdot c\right)}{\frac{\mathsf{fma}\left(b, b, -\left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)\right)}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}}{2 \cdot a}\\ \mathbf{elif}\;b \le -3.09798512605357415 \cdot 10^{-61}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 6.9721274759377412 \cdot 10^{134}:\\ \;\;\;\;1 \cdot \frac{\frac{1}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{\frac{\frac{2}{4} \cdot 1}{c}}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(-1 \cdot \frac{c}{b}\right)\\ \end{array}\]

Reproduce

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

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

  (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))