Average Error: 33.8 → 6.7
Time: 9.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 -3.12428337420519208 \cdot 10^{57}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -1.273959369302109 \cdot 10^{-247}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{elif}\;b \le 4.1445535679869069 \cdot 10^{60}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{4 \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 -3.12428337420519208 \cdot 10^{57}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

\mathbf{elif}\;b \le 4.1445535679869069 \cdot 10^{60}:\\
\;\;\;\;\frac{1}{2} \cdot \frac{4 \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 r169143 = b;
        double r169144 = -r169143;
        double r169145 = r169143 * r169143;
        double r169146 = 4.0;
        double r169147 = a;
        double r169148 = r169146 * r169147;
        double r169149 = c;
        double r169150 = r169148 * r169149;
        double r169151 = r169145 - r169150;
        double r169152 = sqrt(r169151);
        double r169153 = r169144 + r169152;
        double r169154 = 2.0;
        double r169155 = r169154 * r169147;
        double r169156 = r169153 / r169155;
        return r169156;
}

double f(double a, double b, double c) {
        double r169157 = b;
        double r169158 = -3.124283374205192e+57;
        bool r169159 = r169157 <= r169158;
        double r169160 = 1.0;
        double r169161 = c;
        double r169162 = r169161 / r169157;
        double r169163 = a;
        double r169164 = r169157 / r169163;
        double r169165 = r169162 - r169164;
        double r169166 = r169160 * r169165;
        double r169167 = -1.273959369302109e-247;
        bool r169168 = r169157 <= r169167;
        double r169169 = -r169157;
        double r169170 = r169157 * r169157;
        double r169171 = 4.0;
        double r169172 = r169171 * r169163;
        double r169173 = r169172 * r169161;
        double r169174 = r169170 - r169173;
        double r169175 = sqrt(r169174);
        double r169176 = r169169 + r169175;
        double r169177 = 2.0;
        double r169178 = r169177 * r169163;
        double r169179 = r169176 / r169178;
        double r169180 = 4.144553567986907e+60;
        bool r169181 = r169157 <= r169180;
        double r169182 = 1.0;
        double r169183 = r169182 / r169177;
        double r169184 = r169171 * r169161;
        double r169185 = r169169 - r169175;
        double r169186 = r169184 / r169185;
        double r169187 = r169183 * r169186;
        double r169188 = -1.0;
        double r169189 = r169188 * r169162;
        double r169190 = r169181 ? r169187 : r169189;
        double r169191 = r169168 ? r169179 : r169190;
        double r169192 = r169159 ? r169166 : r169191;
        return r169192;
}

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

Original33.8
Target20.4
Herbie6.7
\[\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.124283374205192e+57

    1. Initial program 39.5

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

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

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

    if -3.124283374205192e+57 < b < -1.273959369302109e-247

    1. Initial program 8.1

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

    if -1.273959369302109e-247 < b < 4.144553567986907e+60

    1. Initial program 28.1

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

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

      \[\leadsto \frac{\frac{\color{blue}{b \cdot \left(b - b\right) + 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.6

      \[\leadsto \frac{\frac{b \cdot \left(b - b\right) + 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.6

      \[\leadsto \frac{\frac{\color{blue}{1 \cdot \left(b \cdot \left(b - b\right) + 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.6

      \[\leadsto \frac{\color{blue}{\frac{1}{1} \cdot \frac{b \cdot \left(b - b\right) + 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 times-frac16.6

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

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

      \[\leadsto \frac{1}{2} \cdot \color{blue}{\frac{\frac{4 \cdot \left(a \cdot c\right) + 0}{a}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\]
    12. Taylor expanded around 0 9.7

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

    if 4.144553567986907e+60 < b

    1. Initial program 58.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -3.12428337420519208 \cdot 10^{57}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -1.273959369302109 \cdot 10^{-247}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{elif}\;b \le 4.1445535679869069 \cdot 10^{60}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{4 \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 2020045 
(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)))