Average Error: 34.1 → 9.4
Time: 14.7s
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 -4.356959927988237168348139414849710212524 \cdot 10^{-56}:\\ \;\;\;\;\frac{c \cdot -1}{b}\\ \mathbf{elif}\;b \le 3.087668654677018032633364446323411964642 \cdot 10^{130}:\\ \;\;\;\;\frac{\frac{-\left(\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b\right)}{2}}{a}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \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 -4.356959927988237168348139414849710212524 \cdot 10^{-56}:\\
\;\;\;\;\frac{c \cdot -1}{b}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r85540 = b;
        double r85541 = -r85540;
        double r85542 = r85540 * r85540;
        double r85543 = 4.0;
        double r85544 = a;
        double r85545 = c;
        double r85546 = r85544 * r85545;
        double r85547 = r85543 * r85546;
        double r85548 = r85542 - r85547;
        double r85549 = sqrt(r85548);
        double r85550 = r85541 - r85549;
        double r85551 = 2.0;
        double r85552 = r85551 * r85544;
        double r85553 = r85550 / r85552;
        return r85553;
}

double f(double a, double b, double c) {
        double r85554 = b;
        double r85555 = -4.356959927988237e-56;
        bool r85556 = r85554 <= r85555;
        double r85557 = c;
        double r85558 = -1.0;
        double r85559 = r85557 * r85558;
        double r85560 = r85559 / r85554;
        double r85561 = 3.087668654677018e+130;
        bool r85562 = r85554 <= r85561;
        double r85563 = r85554 * r85554;
        double r85564 = a;
        double r85565 = r85557 * r85564;
        double r85566 = 4.0;
        double r85567 = r85565 * r85566;
        double r85568 = r85563 - r85567;
        double r85569 = sqrt(r85568);
        double r85570 = r85569 + r85554;
        double r85571 = -r85570;
        double r85572 = 2.0;
        double r85573 = r85571 / r85572;
        double r85574 = r85573 / r85564;
        double r85575 = 1.0;
        double r85576 = r85557 / r85554;
        double r85577 = r85554 / r85564;
        double r85578 = r85576 - r85577;
        double r85579 = r85575 * r85578;
        double r85580 = r85562 ? r85574 : r85579;
        double r85581 = r85556 ? r85560 : r85580;
        return r85581;
}

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.1
Herbie9.4
\[\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 3 regimes
  2. if b < -4.356959927988237e-56

    1. Initial program 54.0

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

      \[\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 div-inv54.0

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

      \[\leadsto \left(\left(-b\right) - \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}\right) \cdot \color{blue}{\frac{\frac{1}{2}}{a}}\]
    6. Using strategy rm
    7. Applied associate-*r/54.0

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    10. Simplified7.7

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

    if -4.356959927988237e-56 < b < 3.087668654677018e+130

    1. Initial program 12.6

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Simplified12.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 div-inv12.8

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

      \[\leadsto \left(\left(-b\right) - \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}\right) \cdot \color{blue}{\frac{\frac{1}{2}}{a}}\]
    6. Using strategy rm
    7. Applied associate-*r/12.6

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

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

    if 3.087668654677018e+130 < b

    1. Initial program 56.2

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

      \[\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 div-inv56.2

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

      \[\leadsto \left(\left(-b\right) - \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}\right) \cdot \color{blue}{\frac{\frac{1}{2}}{a}}\]
    6. Using strategy rm
    7. Applied associate-*r/56.2

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -4.356959927988237168348139414849710212524 \cdot 10^{-56}:\\ \;\;\;\;\frac{c \cdot -1}{b}\\ \mathbf{elif}\;b \le 3.087668654677018032633364446323411964642 \cdot 10^{130}:\\ \;\;\;\;\frac{\frac{-\left(\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b\right)}{2}}{a}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019174 
(FPCore (a b c)
  :name "quadm (p42, negative)"

  :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)))