Average Error: 34.1 → 9.0
Time: 17.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 -2.122942397323538653087473965252285768999 \cdot 10^{137}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le -3.408354642852288642375909774932644593067 \cdot 10^{-45}:\\ \;\;\;\;\frac{\frac{\frac{\left(b \cdot b - b \cdot b\right) + 4 \cdot \left(c \cdot a\right)}{2}}{a}}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + \left(-b\right)}\\ \mathbf{elif}\;b \le -5.546621280225112292650318866994441138678 \cdot 10^{-56}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le 2.823335453796603439248590818149160856749 \cdot 10^{131}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a}}{a \cdot 2}\\ \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 -2.122942397323538653087473965252285768999 \cdot 10^{137}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\

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

\mathbf{elif}\;b \le -5.546621280225112292650318866994441138678 \cdot 10^{-56}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r4918751 = b;
        double r4918752 = -r4918751;
        double r4918753 = r4918751 * r4918751;
        double r4918754 = 4.0;
        double r4918755 = a;
        double r4918756 = c;
        double r4918757 = r4918755 * r4918756;
        double r4918758 = r4918754 * r4918757;
        double r4918759 = r4918753 - r4918758;
        double r4918760 = sqrt(r4918759);
        double r4918761 = r4918752 - r4918760;
        double r4918762 = 2.0;
        double r4918763 = r4918762 * r4918755;
        double r4918764 = r4918761 / r4918763;
        return r4918764;
}

double f(double a, double b, double c) {
        double r4918765 = b;
        double r4918766 = -2.1229423973235387e+137;
        bool r4918767 = r4918765 <= r4918766;
        double r4918768 = -1.0;
        double r4918769 = c;
        double r4918770 = r4918769 / r4918765;
        double r4918771 = r4918768 * r4918770;
        double r4918772 = -3.4083546428522886e-45;
        bool r4918773 = r4918765 <= r4918772;
        double r4918774 = r4918765 * r4918765;
        double r4918775 = r4918774 - r4918774;
        double r4918776 = 4.0;
        double r4918777 = a;
        double r4918778 = r4918769 * r4918777;
        double r4918779 = r4918776 * r4918778;
        double r4918780 = r4918775 + r4918779;
        double r4918781 = 2.0;
        double r4918782 = r4918780 / r4918781;
        double r4918783 = r4918782 / r4918777;
        double r4918784 = r4918774 - r4918779;
        double r4918785 = sqrt(r4918784);
        double r4918786 = -r4918765;
        double r4918787 = r4918785 + r4918786;
        double r4918788 = r4918783 / r4918787;
        double r4918789 = -5.546621280225112e-56;
        bool r4918790 = r4918765 <= r4918789;
        double r4918791 = 2.8233354537966034e+131;
        bool r4918792 = r4918765 <= r4918791;
        double r4918793 = r4918776 * r4918769;
        double r4918794 = r4918793 * r4918777;
        double r4918795 = r4918774 - r4918794;
        double r4918796 = sqrt(r4918795);
        double r4918797 = r4918786 - r4918796;
        double r4918798 = r4918777 * r4918781;
        double r4918799 = r4918797 / r4918798;
        double r4918800 = 1.0;
        double r4918801 = r4918765 / r4918777;
        double r4918802 = r4918770 - r4918801;
        double r4918803 = r4918800 * r4918802;
        double r4918804 = r4918792 ? r4918799 : r4918803;
        double r4918805 = r4918790 ? r4918771 : r4918804;
        double r4918806 = r4918773 ? r4918788 : r4918805;
        double r4918807 = r4918767 ? r4918771 : r4918806;
        return r4918807;
}

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.0
\[\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 < -2.1229423973235387e+137 or -3.4083546428522886e-45 < b < -5.546621280225112e-56

    1. Initial program 61.6

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

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

    if -2.1229423973235387e+137 < b < -3.4083546428522886e-45

    1. Initial program 45.3

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

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

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

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

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

    if -5.546621280225112e-56 < b < 2.8233354537966034e+131

    1. Initial program 12.6

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied associate-*r*12.6

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

      \[\leadsto \frac{\left(-b\right) - \sqrt{b \cdot b - \color{blue}{\left(\sqrt[3]{\left(4 \cdot a\right) \cdot c} \cdot \sqrt[3]{\left(4 \cdot a\right) \cdot c}\right) \cdot \sqrt[3]{\left(4 \cdot a\right) \cdot c}}}}{2 \cdot a}\]
    6. Using strategy rm
    7. Applied *-un-lft-identity12.9

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

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

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

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

    if 2.8233354537966034e+131 < b

    1. Initial program 56.4

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.122942397323538653087473965252285768999 \cdot 10^{137}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le -3.408354642852288642375909774932644593067 \cdot 10^{-45}:\\ \;\;\;\;\frac{\frac{\frac{\left(b \cdot b - b \cdot b\right) + 4 \cdot \left(c \cdot a\right)}{2}}{a}}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + \left(-b\right)}\\ \mathbf{elif}\;b \le -5.546621280225112292650318866994441138678 \cdot 10^{-56}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le 2.823335453796603439248590818149160856749 \cdot 10^{131}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019174 
(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)))