Average Error: 34.0 → 9.3
Time: 6.7s
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 -1.64064137297236348 \cdot 10^{109}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 2.35913236554248808 \cdot 10^{-219}:\\ \;\;\;\;\frac{\frac{4}{\frac{\left({b}^{2} - {b}^{2}\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 3461964491124549:\\ \;\;\;\;\frac{\frac{1}{\sqrt{0} + \sqrt{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}{2} \cdot \frac{1}{\frac{\frac{1 \cdot \left(\sqrt{0} - \sqrt{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\right)}{c}}{4}}\\ \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 -1.64064137297236348 \cdot 10^{109}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

\mathbf{elif}\;b \le 2.35913236554248808 \cdot 10^{-219}:\\
\;\;\;\;\frac{\frac{4}{\frac{\left({b}^{2} - {b}^{2}\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 3461964491124549:\\
\;\;\;\;\frac{\frac{1}{\sqrt{0} + \sqrt{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}{2} \cdot \frac{1}{\frac{\frac{1 \cdot \left(\sqrt{0} - \sqrt{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\right)}{c}}{4}}\\

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

\end{array}
double f(double a, double b, double c) {
        double r102273 = b;
        double r102274 = -r102273;
        double r102275 = r102273 * r102273;
        double r102276 = 4.0;
        double r102277 = a;
        double r102278 = r102276 * r102277;
        double r102279 = c;
        double r102280 = r102278 * r102279;
        double r102281 = r102275 - r102280;
        double r102282 = sqrt(r102281);
        double r102283 = r102274 + r102282;
        double r102284 = 2.0;
        double r102285 = r102284 * r102277;
        double r102286 = r102283 / r102285;
        return r102286;
}

double f(double a, double b, double c) {
        double r102287 = b;
        double r102288 = -1.6406413729723635e+109;
        bool r102289 = r102287 <= r102288;
        double r102290 = 1.0;
        double r102291 = c;
        double r102292 = r102291 / r102287;
        double r102293 = a;
        double r102294 = r102287 / r102293;
        double r102295 = r102292 - r102294;
        double r102296 = r102290 * r102295;
        double r102297 = 2.359132365542488e-219;
        bool r102298 = r102287 <= r102297;
        double r102299 = 4.0;
        double r102300 = 2.0;
        double r102301 = pow(r102287, r102300);
        double r102302 = r102301 - r102301;
        double r102303 = r102293 * r102291;
        double r102304 = r102299 * r102303;
        double r102305 = r102302 + r102304;
        double r102306 = r102305 / r102303;
        double r102307 = r102299 / r102306;
        double r102308 = -r102287;
        double r102309 = r102287 * r102287;
        double r102310 = r102299 * r102293;
        double r102311 = r102310 * r102291;
        double r102312 = r102309 - r102311;
        double r102313 = sqrt(r102312);
        double r102314 = r102308 + r102313;
        double r102315 = r102307 * r102314;
        double r102316 = 2.0;
        double r102317 = r102316 * r102293;
        double r102318 = r102315 / r102317;
        double r102319 = 3461964491124549.0;
        bool r102320 = r102287 <= r102319;
        double r102321 = 1.0;
        double r102322 = 0.0;
        double r102323 = sqrt(r102322);
        double r102324 = r102287 + r102313;
        double r102325 = sqrt(r102324);
        double r102326 = r102323 + r102325;
        double r102327 = r102321 / r102326;
        double r102328 = r102327 / r102316;
        double r102329 = r102323 - r102325;
        double r102330 = r102321 * r102329;
        double r102331 = r102330 / r102291;
        double r102332 = r102331 / r102299;
        double r102333 = r102321 / r102332;
        double r102334 = r102328 * r102333;
        double r102335 = -1.0;
        double r102336 = r102335 * r102292;
        double r102337 = r102320 ? r102334 : r102336;
        double r102338 = r102298 ? r102318 : r102337;
        double r102339 = r102289 ? r102296 : r102338;
        return r102339;
}

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.0
Target20.8
Herbie9.3
\[\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 < -1.6406413729723635e+109

    1. Initial program 49.5

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

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

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

    if -1.6406413729723635e+109 < b < 2.359132365542488e-219

    1. Initial program 9.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-+32.6

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

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

      \[\leadsto \frac{\color{blue}{\frac{4}{\frac{\left({b}^{2} - {b}^{2}\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 2.359132365542488e-219 < b < 3461964491124549.0

    1. Initial program 30.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-+31.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. Simplified16.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 neg-sub016.8

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

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

      \[\leadsto \frac{\frac{0 + 4 \cdot \left(a \cdot c\right)}{0 - \color{blue}{\sqrt{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}}{2 \cdot a}\]
    10. Applied add-sqr-sqrt17.0

      \[\leadsto \frac{\frac{0 + 4 \cdot \left(a \cdot c\right)}{\color{blue}{\sqrt{0} \cdot \sqrt{0}} - \sqrt{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}{2 \cdot a}\]
    11. Applied difference-of-squares17.0

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

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

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

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

      \[\leadsto \frac{\frac{1}{\sqrt{0} + \sqrt{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}{2} \cdot \color{blue}{\frac{4 \cdot \left(a \cdot c\right)}{a \cdot \left(\sqrt{0} - \sqrt{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\right)}}\]
    16. Using strategy rm
    17. Applied clear-num19.8

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

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

    if 3461964491124549.0 < b

    1. Initial program 55.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.64064137297236348 \cdot 10^{109}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 2.35913236554248808 \cdot 10^{-219}:\\ \;\;\;\;\frac{\frac{4}{\frac{\left({b}^{2} - {b}^{2}\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 3461964491124549:\\ \;\;\;\;\frac{\frac{1}{\sqrt{0} + \sqrt{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}{2} \cdot \frac{1}{\frac{\frac{1 \cdot \left(\sqrt{0} - \sqrt{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\right)}{c}}{4}}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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