Average Error: 34.4 → 8.9
Time: 15.6s
Precision: 64
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -7.890025456402396757167722705339283465851 \cdot 10^{59}:\\ \;\;\;\;\frac{c}{b} \cdot -1\\ \mathbf{elif}\;b \le -2.017941049755905363108562665772563431093 \cdot 10^{-147}:\\ \;\;\;\;\frac{\frac{\frac{\left(b \cdot b - b \cdot b\right) + a \cdot \left(c \cdot 4\right)}{a}}{2}}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + \left(-b\right)}\\ \mathbf{elif}\;b \le 3.424685282990076228564514143307324629132 \cdot 10^{98}:\\ \;\;\;\;-\frac{\sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)} + b}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\ \end{array}\]
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \le -7.890025456402396757167722705339283465851 \cdot 10^{59}:\\
\;\;\;\;\frac{c}{b} \cdot -1\\

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

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

\mathbf{else}:\\
\;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\

\end{array}
double f(double a, double b, double c) {
        double r73505 = b;
        double r73506 = -r73505;
        double r73507 = r73505 * r73505;
        double r73508 = 4.0;
        double r73509 = a;
        double r73510 = c;
        double r73511 = r73509 * r73510;
        double r73512 = r73508 * r73511;
        double r73513 = r73507 - r73512;
        double r73514 = sqrt(r73513);
        double r73515 = r73506 - r73514;
        double r73516 = 2.0;
        double r73517 = r73516 * r73509;
        double r73518 = r73515 / r73517;
        return r73518;
}

double f(double a, double b, double c) {
        double r73519 = b;
        double r73520 = -7.890025456402397e+59;
        bool r73521 = r73519 <= r73520;
        double r73522 = c;
        double r73523 = r73522 / r73519;
        double r73524 = -1.0;
        double r73525 = r73523 * r73524;
        double r73526 = -2.0179410497559054e-147;
        bool r73527 = r73519 <= r73526;
        double r73528 = r73519 * r73519;
        double r73529 = r73528 - r73528;
        double r73530 = a;
        double r73531 = 4.0;
        double r73532 = r73522 * r73531;
        double r73533 = r73530 * r73532;
        double r73534 = r73529 + r73533;
        double r73535 = r73534 / r73530;
        double r73536 = 2.0;
        double r73537 = r73535 / r73536;
        double r73538 = r73522 * r73530;
        double r73539 = r73531 * r73538;
        double r73540 = r73528 - r73539;
        double r73541 = sqrt(r73540);
        double r73542 = -r73519;
        double r73543 = r73541 + r73542;
        double r73544 = r73537 / r73543;
        double r73545 = 3.424685282990076e+98;
        bool r73546 = r73519 <= r73545;
        double r73547 = r73528 - r73533;
        double r73548 = sqrt(r73547);
        double r73549 = r73548 + r73519;
        double r73550 = r73536 * r73530;
        double r73551 = r73549 / r73550;
        double r73552 = -r73551;
        double r73553 = r73519 / r73530;
        double r73554 = r73523 - r73553;
        double r73555 = 1.0;
        double r73556 = r73554 * r73555;
        double r73557 = r73546 ? r73552 : r73556;
        double r73558 = r73527 ? r73544 : r73557;
        double r73559 = r73521 ? r73525 : r73558;
        return r73559;
}

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.4
Target21.0
Herbie8.9
\[\begin{array}{l} \mathbf{if}\;b \lt 0.0:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if b < -7.890025456402397e+59

    1. Initial program 57.6

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

      \[\leadsto \color{blue}{\frac{\left(-b\right) - \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied clear-num57.6

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

      \[\leadsto \frac{1}{\color{blue}{\left(2 \cdot a\right) \cdot \frac{1}{\left(-b\right) - \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}}}}\]
    7. Applied add-cube-cbrt57.6

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{\left(2 \cdot a\right) \cdot \frac{1}{\left(-b\right) - \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}}}\]
    8. Applied times-frac57.6

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

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

      \[\leadsto \frac{1}{a \cdot 2} \cdot \color{blue}{\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}\right)}\]
    11. Using strategy rm
    12. Applied associate-*l/57.6

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

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

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

      \[\leadsto \color{blue}{\frac{c}{b} \cdot -1}\]

    if -7.890025456402397e+59 < b < -2.0179410497559054e-147

    1. Initial program 37.7

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

      \[\leadsto \color{blue}{\frac{\left(-b\right) - \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied clear-num37.7

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

      \[\leadsto \frac{1}{\color{blue}{\left(2 \cdot a\right) \cdot \frac{1}{\left(-b\right) - \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}}}}\]
    7. Applied add-cube-cbrt37.8

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{\left(2 \cdot a\right) \cdot \frac{1}{\left(-b\right) - \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}}}\]
    8. Applied times-frac37.8

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

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

      \[\leadsto \frac{1}{a \cdot 2} \cdot \color{blue}{\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}\right)}\]
    11. Using strategy rm
    12. Applied flip--37.7

      \[\leadsto \frac{1}{a \cdot 2} \cdot \color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} \cdot \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}}\]
    13. Applied associate-*r/37.8

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

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

    if -2.0179410497559054e-147 < b < 3.424685282990076e+98

    1. Initial program 11.7

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

      \[\leadsto \color{blue}{\frac{\left(-b\right) - \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied clear-num11.9

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

      \[\leadsto \frac{1}{\color{blue}{\left(2 \cdot a\right) \cdot \frac{1}{\left(-b\right) - \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}}}}\]
    7. Applied add-cube-cbrt11.9

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{\left(2 \cdot a\right) \cdot \frac{1}{\left(-b\right) - \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}}}\]
    8. Applied times-frac11.9

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

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

      \[\leadsto \frac{1}{a \cdot 2} \cdot \color{blue}{\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}\right)}\]
    11. Using strategy rm
    12. Applied associate-*l/11.7

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

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

    if 3.424685282990076e+98 < b

    1. Initial program 47.8

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

      \[\leadsto \color{blue}{\frac{\left(-b\right) - \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied clear-num47.9

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

      \[\leadsto \frac{1}{\color{blue}{\left(2 \cdot a\right) \cdot \frac{1}{\left(-b\right) - \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}}}}\]
    7. Applied add-cube-cbrt47.9

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{\left(2 \cdot a\right) \cdot \frac{1}{\left(-b\right) - \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}}}\]
    8. Applied times-frac47.9

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

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

      \[\leadsto \frac{1}{a \cdot 2} \cdot \color{blue}{\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}\right)}\]
    11. Using strategy rm
    12. Applied associate-*l/47.8

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

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

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

      \[\leadsto \color{blue}{\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification8.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -7.890025456402396757167722705339283465851 \cdot 10^{59}:\\ \;\;\;\;\frac{c}{b} \cdot -1\\ \mathbf{elif}\;b \le -2.017941049755905363108562665772563431093 \cdot 10^{-147}:\\ \;\;\;\;\frac{\frac{\frac{\left(b \cdot b - b \cdot b\right) + a \cdot \left(c \cdot 4\right)}{a}}{2}}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + \left(-b\right)}\\ \mathbf{elif}\;b \le 3.424685282990076228564514143307324629132 \cdot 10^{98}:\\ \;\;\;\;-\frac{\sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)} + b}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\ \end{array}\]

Reproduce

herbie shell --seed 2019195 
(FPCore (a b c)
  :name "The quadratic formula (r2)"

  :herbie-target
  (if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))

  (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))