Average Error: 34.5 → 6.3
Time: 33.1s
Precision: 64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4.0 \cdot a\right) \cdot c}}{2.0 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -3.0775171197265305 \cdot 10^{+143}:\\ \;\;\;\;\frac{\frac{-2 \cdot b}{2.0}}{a}\\ \mathbf{elif}\;b \le -6.459611810046018 \cdot 10^{-256}:\\ \;\;\;\;\left(\sqrt{b \cdot b - 4.0 \cdot \left(a \cdot c\right)} - b\right) \cdot \frac{\frac{1}{2.0}}{a}\\ \mathbf{elif}\;b \le 5.413497103300552 \cdot 10^{+144}:\\ \;\;\;\;\frac{c \cdot -2.0}{\sqrt{b \cdot b - 4.0 \cdot \left(a \cdot c\right)} + b}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -1.0\\ \end{array}\]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4.0 \cdot a\right) \cdot c}}{2.0 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \le -3.0775171197265305 \cdot 10^{+143}:\\
\;\;\;\;\frac{\frac{-2 \cdot b}{2.0}}{a}\\

\mathbf{elif}\;b \le -6.459611810046018 \cdot 10^{-256}:\\
\;\;\;\;\left(\sqrt{b \cdot b - 4.0 \cdot \left(a \cdot c\right)} - b\right) \cdot \frac{\frac{1}{2.0}}{a}\\

\mathbf{elif}\;b \le 5.413497103300552 \cdot 10^{+144}:\\
\;\;\;\;\frac{c \cdot -2.0}{\sqrt{b \cdot b - 4.0 \cdot \left(a \cdot c\right)} + b}\\

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

\end{array}
double f(double a, double b, double c) {
        double r5698708 = b;
        double r5698709 = -r5698708;
        double r5698710 = r5698708 * r5698708;
        double r5698711 = 4.0;
        double r5698712 = a;
        double r5698713 = r5698711 * r5698712;
        double r5698714 = c;
        double r5698715 = r5698713 * r5698714;
        double r5698716 = r5698710 - r5698715;
        double r5698717 = sqrt(r5698716);
        double r5698718 = r5698709 + r5698717;
        double r5698719 = 2.0;
        double r5698720 = r5698719 * r5698712;
        double r5698721 = r5698718 / r5698720;
        return r5698721;
}

double f(double a, double b, double c) {
        double r5698722 = b;
        double r5698723 = -3.0775171197265305e+143;
        bool r5698724 = r5698722 <= r5698723;
        double r5698725 = -2.0;
        double r5698726 = r5698725 * r5698722;
        double r5698727 = 2.0;
        double r5698728 = r5698726 / r5698727;
        double r5698729 = a;
        double r5698730 = r5698728 / r5698729;
        double r5698731 = -6.459611810046018e-256;
        bool r5698732 = r5698722 <= r5698731;
        double r5698733 = r5698722 * r5698722;
        double r5698734 = 4.0;
        double r5698735 = c;
        double r5698736 = r5698729 * r5698735;
        double r5698737 = r5698734 * r5698736;
        double r5698738 = r5698733 - r5698737;
        double r5698739 = sqrt(r5698738);
        double r5698740 = r5698739 - r5698722;
        double r5698741 = 1.0;
        double r5698742 = r5698741 / r5698727;
        double r5698743 = r5698742 / r5698729;
        double r5698744 = r5698740 * r5698743;
        double r5698745 = 5.413497103300552e+144;
        bool r5698746 = r5698722 <= r5698745;
        double r5698747 = -2.0;
        double r5698748 = r5698735 * r5698747;
        double r5698749 = r5698739 + r5698722;
        double r5698750 = r5698748 / r5698749;
        double r5698751 = r5698735 / r5698722;
        double r5698752 = -1.0;
        double r5698753 = r5698751 * r5698752;
        double r5698754 = r5698746 ? r5698750 : r5698753;
        double r5698755 = r5698732 ? r5698744 : r5698754;
        double r5698756 = r5698724 ? r5698730 : r5698755;
        return r5698756;
}

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.5
Target20.9
Herbie6.3
\[\begin{array}{l} \mathbf{if}\;b \lt 0.0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4.0 \cdot a\right) \cdot c}}{2.0 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(4.0 \cdot a\right) \cdot c}}{2.0 \cdot a}}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if b < -3.0775171197265305e+143

    1. Initial program 59.8

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4.0 \cdot a\right) \cdot c}}{2.0 \cdot a}\]
    2. Simplified59.8

      \[\leadsto \color{blue}{\frac{\frac{\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} - b}{2.0}}{a}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt59.8

      \[\leadsto \frac{\frac{\sqrt{\color{blue}{\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} \cdot \sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)}}} - b}{2.0}}{a}\]
    5. Applied sqrt-prod59.8

      \[\leadsto \frac{\frac{\color{blue}{\sqrt{\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)}} \cdot \sqrt{\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)}}} - b}{2.0}}{a}\]
    6. Applied fma-neg59.8

      \[\leadsto \frac{\frac{\color{blue}{\mathsf{fma}\left(\sqrt{\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)}}, \sqrt{\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)}}, -b\right)}}{2.0}}{a}\]
    7. Taylor expanded around -inf 3.0

      \[\leadsto \frac{\frac{\color{blue}{-2 \cdot b}}{2.0}}{a}\]
    8. Simplified3.0

      \[\leadsto \frac{\frac{\color{blue}{-2 \cdot b}}{2.0}}{a}\]

    if -3.0775171197265305e+143 < b < -6.459611810046018e-256

    1. Initial program 8.0

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4.0 \cdot a\right) \cdot c}}{2.0 \cdot a}\]
    2. Simplified7.9

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

      \[\leadsto \frac{\frac{\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} - b}{2.0}}{\color{blue}{1 \cdot a}}\]
    5. Applied div-inv7.9

      \[\leadsto \frac{\color{blue}{\left(\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} - b\right) \cdot \frac{1}{2.0}}}{1 \cdot a}\]
    6. Applied times-frac8.1

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} - b}{1} \cdot \frac{\frac{1}{2.0}}{a}}\]
    7. Simplified8.1

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

    if -6.459611810046018e-256 < b < 5.413497103300552e+144

    1. Initial program 33.1

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4.0 \cdot a\right) \cdot c}}{2.0 \cdot a}\]
    2. Simplified33.1

      \[\leadsto \color{blue}{\frac{\frac{\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} - b}{2.0}}{a}}\]
    3. Using strategy rm
    4. Applied *-un-lft-identity33.1

      \[\leadsto \frac{\frac{\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} - b}{2.0}}{\color{blue}{1 \cdot a}}\]
    5. Applied div-inv33.1

      \[\leadsto \frac{\color{blue}{\left(\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} - b\right) \cdot \frac{1}{2.0}}}{1 \cdot a}\]
    6. Applied times-frac33.1

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} - b}{1} \cdot \frac{\frac{1}{2.0}}{a}}\]
    7. Simplified33.1

      \[\leadsto \color{blue}{\left(\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} - b\right)} \cdot \frac{\frac{1}{2.0}}{a}\]
    8. Using strategy rm
    9. Applied flip--33.2

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} \cdot \sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} - b \cdot b}{\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} + b}} \cdot \frac{\frac{1}{2.0}}{a}\]
    10. Applied associate-*l/33.2

      \[\leadsto \color{blue}{\frac{\left(\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} \cdot \sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} - b \cdot b\right) \cdot \frac{\frac{1}{2.0}}{a}}{\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} + b}}\]
    11. Simplified13.6

      \[\leadsto \frac{\color{blue}{\frac{\left(b \cdot b - b \cdot b\right) - 4.0 \cdot \left(c \cdot a\right)}{a \cdot 2.0}}}{\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} + b}\]
    12. Taylor expanded around 0 8.3

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

    if 5.413497103300552e+144 < b

    1. Initial program 62.8

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4.0 \cdot a\right) \cdot c}}{2.0 \cdot a}\]
    2. Simplified62.8

      \[\leadsto \color{blue}{\frac{\frac{\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} - b}{2.0}}{a}}\]
    3. Taylor expanded around inf 1.4

      \[\leadsto \color{blue}{-1.0 \cdot \frac{c}{b}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification6.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -3.0775171197265305 \cdot 10^{+143}:\\ \;\;\;\;\frac{\frac{-2 \cdot b}{2.0}}{a}\\ \mathbf{elif}\;b \le -6.459611810046018 \cdot 10^{-256}:\\ \;\;\;\;\left(\sqrt{b \cdot b - 4.0 \cdot \left(a \cdot c\right)} - b\right) \cdot \frac{\frac{1}{2.0}}{a}\\ \mathbf{elif}\;b \le 5.413497103300552 \cdot 10^{+144}:\\ \;\;\;\;\frac{c \cdot -2.0}{\sqrt{b \cdot b - 4.0 \cdot \left(a \cdot c\right)} + b}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -1.0\\ \end{array}\]

Reproduce

herbie shell --seed 2019165 +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)))