Average Error: 34.1 → 6.4
Time: 16.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 -2.46337219442650475190360405115215330559 \cdot 10^{111}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -3.104620340175948664814965097441450913118 \cdot 10^{-300}:\\ \;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{elif}\;b \le 5.732888581164670930257747643857376081135 \cdot 10^{134}:\\ \;\;\;\;\frac{\frac{4 \cdot c}{2}}{\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 -2.46337219442650475190360405115215330559 \cdot 10^{111}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

\mathbf{elif}\;b \le 5.732888581164670930257747643857376081135 \cdot 10^{134}:\\
\;\;\;\;\frac{\frac{4 \cdot c}{2}}{\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 r65563 = b;
        double r65564 = -r65563;
        double r65565 = r65563 * r65563;
        double r65566 = 4.0;
        double r65567 = a;
        double r65568 = r65566 * r65567;
        double r65569 = c;
        double r65570 = r65568 * r65569;
        double r65571 = r65565 - r65570;
        double r65572 = sqrt(r65571);
        double r65573 = r65564 + r65572;
        double r65574 = 2.0;
        double r65575 = r65574 * r65567;
        double r65576 = r65573 / r65575;
        return r65576;
}

double f(double a, double b, double c) {
        double r65577 = b;
        double r65578 = -2.463372194426505e+111;
        bool r65579 = r65577 <= r65578;
        double r65580 = 1.0;
        double r65581 = c;
        double r65582 = r65581 / r65577;
        double r65583 = a;
        double r65584 = r65577 / r65583;
        double r65585 = r65582 - r65584;
        double r65586 = r65580 * r65585;
        double r65587 = -3.1046203401759487e-300;
        bool r65588 = r65577 <= r65587;
        double r65589 = -r65577;
        double r65590 = r65577 * r65577;
        double r65591 = 4.0;
        double r65592 = r65591 * r65583;
        double r65593 = r65592 * r65581;
        double r65594 = r65590 - r65593;
        double r65595 = sqrt(r65594);
        double r65596 = r65589 + r65595;
        double r65597 = 1.0;
        double r65598 = 2.0;
        double r65599 = r65598 * r65583;
        double r65600 = r65597 / r65599;
        double r65601 = r65596 * r65600;
        double r65602 = 5.732888581164671e+134;
        bool r65603 = r65577 <= r65602;
        double r65604 = r65591 * r65581;
        double r65605 = r65604 / r65598;
        double r65606 = r65589 - r65595;
        double r65607 = r65605 / r65606;
        double r65608 = -1.0;
        double r65609 = r65608 * r65582;
        double r65610 = r65603 ? r65607 : r65609;
        double r65611 = r65588 ? r65601 : r65610;
        double r65612 = r65579 ? r65586 : r65611;
        return r65612;
}

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.1
Target21.0
Herbie6.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 < -2.463372194426505e+111

    1. Initial program 48.7

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

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

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

    if -2.463372194426505e+111 < b < -3.1046203401759487e-300

    1. Initial program 8.4

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

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

    if -3.1046203401759487e-300 < b < 5.732888581164671e+134

    1. Initial program 33.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-+33.9

      \[\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}{0 + 4 \cdot \left(c \cdot a\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{0 + 4 \cdot \left(c \cdot a\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(0 + 4 \cdot \left(c \cdot a\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{0 + 4 \cdot \left(c \cdot a\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}{2 \cdot a}\]
    9. Applied associate-/l*16.8

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

      \[\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. Using strategy rm
    12. Applied associate-/l*15.6

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

      \[\leadsto \frac{\frac{1}{1}}{\frac{2}{\color{blue}{\frac{4}{\frac{1}{c}}}} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}\]
    14. Using strategy rm
    15. Applied div-inv9.2

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

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

    if 5.732888581164671e+134 < b

    1. Initial program 62.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.46337219442650475190360405115215330559 \cdot 10^{111}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -3.104620340175948664814965097441450913118 \cdot 10^{-300}:\\ \;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{elif}\;b \le 5.732888581164670930257747643857376081135 \cdot 10^{134}:\\ \;\;\;\;\frac{\frac{4 \cdot c}{2}}{\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 2019326 
(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)))