Average Error: 10.6 → 2.3
Time: 16.9s
Precision: 64
\[b \ne 0.0 \land {b}^{2} - 4 \cdot ac \ge 0.0\]
\[\frac{\left(-b\right) - \sqrt{{b}^{2} - 4 \cdot ac}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -2.200705364914606778947625285426342333691 \cdot 10^{-35}:\\ \;\;\;\;\frac{-2 \cdot \frac{ac}{b}}{2 \cdot a}\\ \mathbf{elif}\;b \le +\infty:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{{b}^{2} - 4 \cdot ac}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot \frac{ac}{b} - 2 \cdot b}{2 \cdot a}\\ \end{array}\]
\frac{\left(-b\right) - \sqrt{{b}^{2} - 4 \cdot ac}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \le -2.200705364914606778947625285426342333691 \cdot 10^{-35}:\\
\;\;\;\;\frac{-2 \cdot \frac{ac}{b}}{2 \cdot a}\\

\mathbf{elif}\;b \le +\infty:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{{b}^{2} - 4 \cdot ac}}{2 \cdot a}\\

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

\end{array}
double f(double b, double ac, double a) {
        double r3554008 = b;
        double r3554009 = -r3554008;
        double r3554010 = 2.0;
        double r3554011 = pow(r3554008, r3554010);
        double r3554012 = 4.0;
        double r3554013 = ac;
        double r3554014 = r3554012 * r3554013;
        double r3554015 = r3554011 - r3554014;
        double r3554016 = sqrt(r3554015);
        double r3554017 = r3554009 - r3554016;
        double r3554018 = a;
        double r3554019 = r3554010 * r3554018;
        double r3554020 = r3554017 / r3554019;
        return r3554020;
}

double f(double b, double ac, double a) {
        double r3554021 = b;
        double r3554022 = -2.2007053649146068e-35;
        bool r3554023 = r3554021 <= r3554022;
        double r3554024 = -2.0;
        double r3554025 = ac;
        double r3554026 = r3554025 / r3554021;
        double r3554027 = r3554024 * r3554026;
        double r3554028 = 2.0;
        double r3554029 = a;
        double r3554030 = r3554028 * r3554029;
        double r3554031 = r3554027 / r3554030;
        double r3554032 = +inf.0;
        bool r3554033 = r3554021 <= r3554032;
        double r3554034 = -r3554021;
        double r3554035 = pow(r3554021, r3554028);
        double r3554036 = 4.0;
        double r3554037 = r3554036 * r3554025;
        double r3554038 = r3554035 - r3554037;
        double r3554039 = sqrt(r3554038);
        double r3554040 = r3554034 - r3554039;
        double r3554041 = r3554040 / r3554030;
        double r3554042 = r3554028 * r3554026;
        double r3554043 = 2.0;
        double r3554044 = r3554043 * r3554021;
        double r3554045 = r3554042 - r3554044;
        double r3554046 = r3554045 / r3554030;
        double r3554047 = r3554033 ? r3554041 : r3554046;
        double r3554048 = r3554023 ? r3554031 : r3554047;
        return r3554048;
}

Error

Bits error versus b

Bits error versus ac

Bits error versus a

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if b < -2.2007053649146068e-35

    1. Initial program 18.5

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

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

    if -2.2007053649146068e-35 < b < +inf.0

    1. Initial program 3.6

      \[\frac{\left(-b\right) - \sqrt{{b}^{2} - 4 \cdot ac}}{2 \cdot a}\]

    if +inf.0 < b

    1. Initial program 10.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.200705364914606778947625285426342333691 \cdot 10^{-35}:\\ \;\;\;\;\frac{-2 \cdot \frac{ac}{b}}{2 \cdot a}\\ \mathbf{elif}\;b \le +\infty:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{{b}^{2} - 4 \cdot ac}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot \frac{ac}{b} - 2 \cdot b}{2 \cdot a}\\ \end{array}\]

Reproduce

herbie shell --seed 1 
(FPCore (b ac a)
  :name "(-b-sqrt(b^2-4ac))/(2a)"
  :precision binary32
  :pre (and (!= b 0.0) (>= (- (pow b 2) (* 4 ac)) 0.0))
  (/ (- (- b) (sqrt (- (pow b 2) (* 4 ac)))) (* 2 a)))