Average Error: 34.1 → 9.3
Time: 5.4s
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.3044033969831823 \cdot 10^{153}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 8.9305277508569929 \cdot 10^{-82}:\\ \;\;\;\;\frac{b - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{-2 \cdot a}\\ \mathbf{elif}\;b \le 4.01993084419163312 \cdot 10^{109}:\\ \;\;\;\;\frac{\frac{1}{\sqrt[3]{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt[3]{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}{\frac{2 \cdot a}{4 \cdot \left(a \cdot c\right)} \cdot \sqrt[3]{\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.3044033969831823 \cdot 10^{153}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

\mathbf{elif}\;b \le 4.01993084419163312 \cdot 10^{109}:\\
\;\;\;\;\frac{\frac{1}{\sqrt[3]{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt[3]{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}{\frac{2 \cdot a}{4 \cdot \left(a \cdot c\right)} \cdot \sqrt[3]{\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 r124634 = b;
        double r124635 = -r124634;
        double r124636 = r124634 * r124634;
        double r124637 = 4.0;
        double r124638 = a;
        double r124639 = r124637 * r124638;
        double r124640 = c;
        double r124641 = r124639 * r124640;
        double r124642 = r124636 - r124641;
        double r124643 = sqrt(r124642);
        double r124644 = r124635 + r124643;
        double r124645 = 2.0;
        double r124646 = r124645 * r124638;
        double r124647 = r124644 / r124646;
        return r124647;
}

double f(double a, double b, double c) {
        double r124648 = b;
        double r124649 = -2.3044033969831823e+153;
        bool r124650 = r124648 <= r124649;
        double r124651 = 1.0;
        double r124652 = c;
        double r124653 = r124652 / r124648;
        double r124654 = a;
        double r124655 = r124648 / r124654;
        double r124656 = r124653 - r124655;
        double r124657 = r124651 * r124656;
        double r124658 = 8.930527750856993e-82;
        bool r124659 = r124648 <= r124658;
        double r124660 = r124648 * r124648;
        double r124661 = 4.0;
        double r124662 = r124661 * r124654;
        double r124663 = r124662 * r124652;
        double r124664 = r124660 - r124663;
        double r124665 = sqrt(r124664);
        double r124666 = r124648 - r124665;
        double r124667 = 2.0;
        double r124668 = r124667 * r124654;
        double r124669 = -r124668;
        double r124670 = r124666 / r124669;
        double r124671 = 4.019930844191633e+109;
        bool r124672 = r124648 <= r124671;
        double r124673 = 1.0;
        double r124674 = -r124648;
        double r124675 = r124674 - r124665;
        double r124676 = cbrt(r124675);
        double r124677 = r124676 * r124676;
        double r124678 = r124673 / r124677;
        double r124679 = r124654 * r124652;
        double r124680 = r124661 * r124679;
        double r124681 = r124668 / r124680;
        double r124682 = r124681 * r124676;
        double r124683 = r124678 / r124682;
        double r124684 = -1.0;
        double r124685 = r124684 * r124653;
        double r124686 = r124672 ? r124683 : r124685;
        double r124687 = r124659 ? r124670 : r124686;
        double r124688 = r124650 ? r124657 : r124687;
        return r124688;
}

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
Target20.7
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 < -2.3044033969831823e+153

    1. Initial program 63.5

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

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

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

    if -2.3044033969831823e+153 < b < 8.930527750856993e-82

    1. Initial program 12.5

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

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

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

    if 8.930527750856993e-82 < b < 4.019930844191633e+109

    1. Initial program 43.0

      \[\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-+43.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. Simplified14.9

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{1}{\sqrt[3]{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt[3]{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}} \cdot \frac{0 + 4 \cdot \left(a \cdot c\right)}{\sqrt[3]{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}}{2 \cdot a}\]
    9. Applied associate-/l*14.3

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

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

    if 4.019930844191633e+109 < b

    1. Initial program 59.9

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

      \[\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 -2.3044033969831823 \cdot 10^{153}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 8.9305277508569929 \cdot 10^{-82}:\\ \;\;\;\;\frac{b - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{-2 \cdot a}\\ \mathbf{elif}\;b \le 4.01993084419163312 \cdot 10^{109}:\\ \;\;\;\;\frac{\frac{1}{\sqrt[3]{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt[3]{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}{\frac{2 \cdot a}{4 \cdot \left(a \cdot c\right)} \cdot \sqrt[3]{\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 2020060 +o rules:numerics
(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)))