Average Error: 34.6 → 10.0
Time: 24.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 -1.6581383089037873 \cdot 10^{81}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 2.45811587950602871 \cdot 10^{-136}:\\ \;\;\;\;\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 4.40565710546396028 \cdot 10^{-70}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le 1.1310446734884525 \cdot 10^{-47}:\\ \;\;\;\;\frac{\frac{\left(4 \cdot a\right) \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.155213356860159 \cdot 10^{83}:\\ \;\;\;\;\frac{\left(4 \cdot a\right) \cdot c}{\left(a \cdot 2\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}\\ \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.6581383089037873 \cdot 10^{81}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

\mathbf{elif}\;b \le 2.45811587950602871 \cdot 10^{-136}:\\
\;\;\;\;\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 4.40565710546396028 \cdot 10^{-70}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r138733 = b;
        double r138734 = -r138733;
        double r138735 = r138733 * r138733;
        double r138736 = 4.0;
        double r138737 = a;
        double r138738 = r138736 * r138737;
        double r138739 = c;
        double r138740 = r138738 * r138739;
        double r138741 = r138735 - r138740;
        double r138742 = sqrt(r138741);
        double r138743 = r138734 + r138742;
        double r138744 = 2.0;
        double r138745 = r138744 * r138737;
        double r138746 = r138743 / r138745;
        return r138746;
}

double f(double a, double b, double c) {
        double r138747 = b;
        double r138748 = -1.6581383089037873e+81;
        bool r138749 = r138747 <= r138748;
        double r138750 = 1.0;
        double r138751 = c;
        double r138752 = r138751 / r138747;
        double r138753 = a;
        double r138754 = r138747 / r138753;
        double r138755 = r138752 - r138754;
        double r138756 = r138750 * r138755;
        double r138757 = 2.4581158795060287e-136;
        bool r138758 = r138747 <= r138757;
        double r138759 = -r138747;
        double r138760 = r138747 * r138747;
        double r138761 = 4.0;
        double r138762 = r138761 * r138753;
        double r138763 = r138762 * r138751;
        double r138764 = r138760 - r138763;
        double r138765 = sqrt(r138764);
        double r138766 = r138759 + r138765;
        double r138767 = 1.0;
        double r138768 = 2.0;
        double r138769 = r138768 * r138753;
        double r138770 = r138767 / r138769;
        double r138771 = r138766 * r138770;
        double r138772 = 4.40565710546396e-70;
        bool r138773 = r138747 <= r138772;
        double r138774 = -1.0;
        double r138775 = r138774 * r138752;
        double r138776 = 1.1310446734884525e-47;
        bool r138777 = r138747 <= r138776;
        double r138778 = r138759 - r138765;
        double r138779 = r138763 / r138778;
        double r138780 = r138753 * r138768;
        double r138781 = r138779 / r138780;
        double r138782 = 1.155213356860159e+83;
        bool r138783 = r138747 <= r138782;
        double r138784 = r138780 * r138778;
        double r138785 = r138763 / r138784;
        double r138786 = r138783 ? r138785 : r138775;
        double r138787 = r138777 ? r138781 : r138786;
        double r138788 = r138773 ? r138775 : r138787;
        double r138789 = r138758 ? r138771 : r138788;
        double r138790 = r138749 ? r138756 : r138789;
        return r138790;
}

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.6
Target21.3
Herbie10.0
\[\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 5 regimes
  2. if b < -1.6581383089037873e+81

    1. Initial program 43.9

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

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

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

    if -1.6581383089037873e+81 < b < 2.4581158795060287e-136

    1. Initial program 11.7

      \[\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-inv11.8

      \[\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 2.4581158795060287e-136 < b < 4.40565710546396e-70 or 1.155213356860159e+83 < b

    1. Initial program 53.8

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

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

    if 4.40565710546396e-70 < b < 1.1310446734884525e-47

    1. Initial program 31.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-+31.8

      \[\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. Simplified13.4

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

    if 1.1310446734884525e-47 < b < 1.155213356860159e+83

    1. Initial program 45.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-+45.8

      \[\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.4

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

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

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

      \[\leadsto \frac{0 + \left(4 \cdot a\right) \cdot c}{\color{blue}{\left(a \cdot 2\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}\]
  3. Recombined 5 regimes into one program.
  4. Final simplification10.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.6581383089037873 \cdot 10^{81}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 2.45811587950602871 \cdot 10^{-136}:\\ \;\;\;\;\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 4.40565710546396028 \cdot 10^{-70}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le 1.1310446734884525 \cdot 10^{-47}:\\ \;\;\;\;\frac{\frac{\left(4 \cdot a\right) \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.155213356860159 \cdot 10^{83}:\\ \;\;\;\;\frac{\left(4 \cdot a\right) \cdot c}{\left(a \cdot 2\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019199 +o rules:numerics
(FPCore (a b c)
  :name "The quadratic formula (r1)"

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

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