Average Error: 34.5 → 8.4
Time: 15.2s
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 -977083.9042033920995891094207763671875:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -1.420918595944750698408112361931616871939 \cdot 10^{-121}:\\ \;\;\;\;\frac{\frac{4}{\frac{\left(b \cdot b - b \cdot b\right) + 4 \cdot \left(a \cdot c\right)}{a \cdot c}} \cdot \left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}{2 \cdot a}\\ \mathbf{elif}\;b \le 2.747556913740804008737179989700009267916 \cdot 10^{103}:\\ \;\;\;\;\frac{\frac{1}{0.5} \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \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 -977083.9042033920995891094207763671875:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

\mathbf{elif}\;b \le 2.747556913740804008737179989700009267916 \cdot 10^{103}:\\
\;\;\;\;\frac{\frac{1}{0.5} \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\

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

\end{array}
double f(double a, double b, double c) {
        double r55970 = b;
        double r55971 = -r55970;
        double r55972 = r55970 * r55970;
        double r55973 = 4.0;
        double r55974 = a;
        double r55975 = r55973 * r55974;
        double r55976 = c;
        double r55977 = r55975 * r55976;
        double r55978 = r55972 - r55977;
        double r55979 = sqrt(r55978);
        double r55980 = r55971 + r55979;
        double r55981 = 2.0;
        double r55982 = r55981 * r55974;
        double r55983 = r55980 / r55982;
        return r55983;
}

double f(double a, double b, double c) {
        double r55984 = b;
        double r55985 = -977083.9042033921;
        bool r55986 = r55984 <= r55985;
        double r55987 = 1.0;
        double r55988 = c;
        double r55989 = r55988 / r55984;
        double r55990 = a;
        double r55991 = r55984 / r55990;
        double r55992 = r55989 - r55991;
        double r55993 = r55987 * r55992;
        double r55994 = -1.4209185959447507e-121;
        bool r55995 = r55984 <= r55994;
        double r55996 = 4.0;
        double r55997 = r55984 * r55984;
        double r55998 = r55997 - r55997;
        double r55999 = r55990 * r55988;
        double r56000 = r55996 * r55999;
        double r56001 = r55998 + r56000;
        double r56002 = r56001 / r55999;
        double r56003 = r55996 / r56002;
        double r56004 = -r55984;
        double r56005 = r55996 * r55990;
        double r56006 = r56005 * r55988;
        double r56007 = r55997 - r56006;
        double r56008 = sqrt(r56007);
        double r56009 = r56004 + r56008;
        double r56010 = r56003 * r56009;
        double r56011 = 2.0;
        double r56012 = r56011 * r55990;
        double r56013 = r56010 / r56012;
        double r56014 = 2.747556913740804e+103;
        bool r56015 = r55984 <= r56014;
        double r56016 = 1.0;
        double r56017 = 0.5;
        double r56018 = r56016 / r56017;
        double r56019 = r56018 * r55988;
        double r56020 = r56004 - r56008;
        double r56021 = r56019 / r56020;
        double r56022 = -1.0;
        double r56023 = r56022 * r55989;
        double r56024 = r56015 ? r56021 : r56023;
        double r56025 = r55995 ? r56013 : r56024;
        double r56026 = r55986 ? r55993 : r56025;
        return r56026;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original34.5
Target21.1
Herbie8.4
\[\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 < -977083.9042033921

    1. Initial program 33.8

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

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

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

    if -977083.9042033921 < b < -1.4209185959447507e-121

    1. Initial program 5.8

      \[\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-+36.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. Simplified36.7

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

      \[\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. Applied associate-/r/36.7

      \[\leadsto \frac{\color{blue}{\frac{0 + 4 \cdot \left(a \cdot c\right)}{\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}} \cdot \left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}{2 \cdot a}\]
    8. Simplified15.8

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

    if -1.4209185959447507e-121 < b < 2.747556913740804e+103

    1. Initial program 27.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-+28.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. Simplified16.4

      \[\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 *-un-lft-identity16.4

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

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

      \[\leadsto \frac{\color{blue}{\frac{1}{1} \cdot \frac{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}\]
    9. Applied associate-/l*16.5

      \[\leadsto \color{blue}{\frac{\frac{1}{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}}}}}\]
    10. Simplified16.0

      \[\leadsto \frac{\frac{1}{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)}}\]
    11. Taylor expanded around 0 11.1

      \[\leadsto \frac{\frac{1}{1}}{\color{blue}{\frac{0.5}{c}} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}\]
    12. Using strategy rm
    13. Applied associate-/r*10.9

      \[\leadsto \color{blue}{\frac{\frac{\frac{1}{1}}{\frac{0.5}{c}}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\]
    14. Simplified10.8

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

    if 2.747556913740804e+103 < b

    1. Initial program 59.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -977083.9042033920995891094207763671875:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -1.420918595944750698408112361931616871939 \cdot 10^{-121}:\\ \;\;\;\;\frac{\frac{4}{\frac{\left(b \cdot b - b \cdot b\right) + 4 \cdot \left(a \cdot c\right)}{a \cdot c}} \cdot \left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}{2 \cdot a}\\ \mathbf{elif}\;b \le 2.747556913740804008737179989700009267916 \cdot 10^{103}:\\ \;\;\;\;\frac{\frac{1}{0.5} \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019291 
(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)))