Average Error: 33.8 → 9.6
Time: 16.8s
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 -3.0775171197265305 \cdot 10^{+143}:\\ \;\;\;\;\frac{\frac{-2 \cdot b}{2}}{a}\\ \mathbf{elif}\;b \le 1.3635892865650846 \cdot 10^{-93}:\\ \;\;\;\;\frac{\frac{1}{2}}{a} \cdot \left(\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b\right)\\ \mathbf{else}:\\ \;\;\;\;-\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 -3.0775171197265305 \cdot 10^{+143}:\\
\;\;\;\;\frac{\frac{-2 \cdot b}{2}}{a}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r3211679 = b;
        double r3211680 = -r3211679;
        double r3211681 = r3211679 * r3211679;
        double r3211682 = 4.0;
        double r3211683 = a;
        double r3211684 = r3211682 * r3211683;
        double r3211685 = c;
        double r3211686 = r3211684 * r3211685;
        double r3211687 = r3211681 - r3211686;
        double r3211688 = sqrt(r3211687);
        double r3211689 = r3211680 + r3211688;
        double r3211690 = 2.0;
        double r3211691 = r3211690 * r3211683;
        double r3211692 = r3211689 / r3211691;
        return r3211692;
}

double f(double a, double b, double c) {
        double r3211693 = b;
        double r3211694 = -3.0775171197265305e+143;
        bool r3211695 = r3211693 <= r3211694;
        double r3211696 = -2.0;
        double r3211697 = r3211696 * r3211693;
        double r3211698 = 2.0;
        double r3211699 = r3211697 / r3211698;
        double r3211700 = a;
        double r3211701 = r3211699 / r3211700;
        double r3211702 = 1.3635892865650846e-93;
        bool r3211703 = r3211693 <= r3211702;
        double r3211704 = 0.5;
        double r3211705 = r3211704 / r3211700;
        double r3211706 = r3211693 * r3211693;
        double r3211707 = 4.0;
        double r3211708 = c;
        double r3211709 = r3211708 * r3211700;
        double r3211710 = r3211707 * r3211709;
        double r3211711 = r3211706 - r3211710;
        double r3211712 = sqrt(r3211711);
        double r3211713 = r3211712 - r3211693;
        double r3211714 = r3211705 * r3211713;
        double r3211715 = r3211708 / r3211693;
        double r3211716 = -r3211715;
        double r3211717 = r3211703 ? r3211714 : r3211716;
        double r3211718 = r3211695 ? r3211701 : r3211717;
        return r3211718;
}

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

Original33.8
Target20.5
Herbie9.6
\[\begin{array}{l} \mathbf{if}\;b \lt 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 3 regimes
  2. if b < -3.0775171197265305e+143

    1. Initial program 56.9

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

      \[\leadsto \color{blue}{\frac{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{2}}{a}}\]
    3. Using strategy rm
    4. Applied flip3--62.1

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

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

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

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

    if -3.0775171197265305e+143 < b < 1.3635892865650846e-93

    1. Initial program 11.5

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

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

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

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

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

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

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

    if 1.3635892865650846e-93 < b

    1. Initial program 52.4

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

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

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

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

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

Reproduce

herbie shell --seed 2019165 
(FPCore (a b c)
  :name "The quadratic formula (r1)"

  :herbie-target
  (if (< b 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)))