Average Error: 34.5 → 9.6
Time: 36.1s
Precision: 64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4.0 \cdot a\right) \cdot c}}{2.0 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -2.3213399824345094 \cdot 10^{+149}:\\ \;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1.0\\ \mathbf{elif}\;b \le 1.1804820682342164 \cdot 10^{-93}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot 4.0\right) \cdot a} - b}{a \cdot 2.0}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -1.0\\ \end{array}\]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4.0 \cdot a\right) \cdot c}}{2.0 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \le -2.3213399824345094 \cdot 10^{+149}:\\
\;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1.0\\

\mathbf{elif}\;b \le 1.1804820682342164 \cdot 10^{-93}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot 4.0\right) \cdot a} - b}{a \cdot 2.0}\\

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

\end{array}
double f(double a, double b, double c) {
        double r6610113 = b;
        double r6610114 = -r6610113;
        double r6610115 = r6610113 * r6610113;
        double r6610116 = 4.0;
        double r6610117 = a;
        double r6610118 = r6610116 * r6610117;
        double r6610119 = c;
        double r6610120 = r6610118 * r6610119;
        double r6610121 = r6610115 - r6610120;
        double r6610122 = sqrt(r6610121);
        double r6610123 = r6610114 + r6610122;
        double r6610124 = 2.0;
        double r6610125 = r6610124 * r6610117;
        double r6610126 = r6610123 / r6610125;
        return r6610126;
}

double f(double a, double b, double c) {
        double r6610127 = b;
        double r6610128 = -2.3213399824345094e+149;
        bool r6610129 = r6610127 <= r6610128;
        double r6610130 = c;
        double r6610131 = r6610130 / r6610127;
        double r6610132 = a;
        double r6610133 = r6610127 / r6610132;
        double r6610134 = r6610131 - r6610133;
        double r6610135 = 1.0;
        double r6610136 = r6610134 * r6610135;
        double r6610137 = 1.1804820682342164e-93;
        bool r6610138 = r6610127 <= r6610137;
        double r6610139 = r6610127 * r6610127;
        double r6610140 = 4.0;
        double r6610141 = r6610130 * r6610140;
        double r6610142 = r6610141 * r6610132;
        double r6610143 = r6610139 - r6610142;
        double r6610144 = sqrt(r6610143);
        double r6610145 = r6610144 - r6610127;
        double r6610146 = 2.0;
        double r6610147 = r6610132 * r6610146;
        double r6610148 = r6610145 / r6610147;
        double r6610149 = -1.0;
        double r6610150 = r6610131 * r6610149;
        double r6610151 = r6610138 ? r6610148 : r6610150;
        double r6610152 = r6610129 ? r6610136 : r6610151;
        return r6610152;
}

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
Target20.9
Herbie9.6
\[\begin{array}{l} \mathbf{if}\;b \lt 0.0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4.0 \cdot a\right) \cdot c}}{2.0 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(4.0 \cdot a\right) \cdot c}}{2.0 \cdot a}}\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if b < -2.3213399824345094e+149

    1. Initial program 62.6

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4.0 \cdot a\right) \cdot c}}{2.0 \cdot a}\]
    2. Using strategy rm
    3. Applied div-inv62.6

      \[\leadsto \color{blue}{\left(\left(-b\right) + \sqrt{b \cdot b - \left(4.0 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2.0 \cdot a}}\]
    4. Using strategy rm
    5. Applied associate-*r/62.6

      \[\leadsto \color{blue}{\frac{\left(\left(-b\right) + \sqrt{b \cdot b - \left(4.0 \cdot a\right) \cdot c}\right) \cdot 1}{2.0 \cdot a}}\]
    6. Simplified62.6

      \[\leadsto \frac{\color{blue}{\sqrt{b \cdot b - a \cdot \left(c \cdot 4.0\right)} - b}}{2.0 \cdot a}\]
    7. Taylor expanded around -inf 2.8

      \[\leadsto \color{blue}{1.0 \cdot \frac{c}{b} - 1.0 \cdot \frac{b}{a}}\]
    8. Simplified2.8

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

    if -2.3213399824345094e+149 < b < 1.1804820682342164e-93

    1. Initial program 11.6

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4.0 \cdot a\right) \cdot c}}{2.0 \cdot a}\]
    2. Using strategy rm
    3. Applied div-inv11.8

      \[\leadsto \color{blue}{\left(\left(-b\right) + \sqrt{b \cdot b - \left(4.0 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2.0 \cdot a}}\]
    4. Using strategy rm
    5. Applied associate-*r/11.6

      \[\leadsto \color{blue}{\frac{\left(\left(-b\right) + \sqrt{b \cdot b - \left(4.0 \cdot a\right) \cdot c}\right) \cdot 1}{2.0 \cdot a}}\]
    6. Simplified11.6

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

    if 1.1804820682342164e-93 < b

    1. Initial program 52.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.3213399824345094 \cdot 10^{+149}:\\ \;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1.0\\ \mathbf{elif}\;b \le 1.1804820682342164 \cdot 10^{-93}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot 4.0\right) \cdot a} - b}{a \cdot 2.0}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -1.0\\ \end{array}\]

Reproduce

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