Average Error: 33.6 → 9.9
Time: 23.6s
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.396811349079212 \cdot 10^{+61}:\\ \;\;\;\;\frac{\left(\frac{c}{\frac{b}{a}} - b\right) \cdot 2}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.3659668388152999 \cdot 10^{-67}:\\ \;\;\;\;\frac{\frac{1}{2}}{a} \cdot \left(\sqrt{\mathsf{fma}\left(c, \left(-4 \cdot a\right), \left(b \cdot b\right)\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.396811349079212 \cdot 10^{+61}:\\
\;\;\;\;\frac{\left(\frac{c}{\frac{b}{a}} - b\right) \cdot 2}{a \cdot 2}\\

\mathbf{elif}\;b \le 1.3659668388152999 \cdot 10^{-67}:\\
\;\;\;\;\frac{\frac{1}{2}}{a} \cdot \left(\sqrt{\mathsf{fma}\left(c, \left(-4 \cdot a\right), \left(b \cdot b\right)\right)} - b\right)\\

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

\end{array}
double f(double a, double b, double c) {
        double r1422663 = b;
        double r1422664 = -r1422663;
        double r1422665 = r1422663 * r1422663;
        double r1422666 = 4.0;
        double r1422667 = a;
        double r1422668 = r1422666 * r1422667;
        double r1422669 = c;
        double r1422670 = r1422668 * r1422669;
        double r1422671 = r1422665 - r1422670;
        double r1422672 = sqrt(r1422671);
        double r1422673 = r1422664 + r1422672;
        double r1422674 = 2.0;
        double r1422675 = r1422674 * r1422667;
        double r1422676 = r1422673 / r1422675;
        return r1422676;
}

double f(double a, double b, double c) {
        double r1422677 = b;
        double r1422678 = -3.396811349079212e+61;
        bool r1422679 = r1422677 <= r1422678;
        double r1422680 = c;
        double r1422681 = a;
        double r1422682 = r1422677 / r1422681;
        double r1422683 = r1422680 / r1422682;
        double r1422684 = r1422683 - r1422677;
        double r1422685 = 2.0;
        double r1422686 = r1422684 * r1422685;
        double r1422687 = r1422681 * r1422685;
        double r1422688 = r1422686 / r1422687;
        double r1422689 = 1.3659668388152999e-67;
        bool r1422690 = r1422677 <= r1422689;
        double r1422691 = 0.5;
        double r1422692 = r1422691 / r1422681;
        double r1422693 = -4.0;
        double r1422694 = r1422693 * r1422681;
        double r1422695 = r1422677 * r1422677;
        double r1422696 = fma(r1422680, r1422694, r1422695);
        double r1422697 = sqrt(r1422696);
        double r1422698 = r1422697 - r1422677;
        double r1422699 = r1422692 * r1422698;
        double r1422700 = r1422680 / r1422677;
        double r1422701 = -r1422700;
        double r1422702 = r1422690 ? r1422699 : r1422701;
        double r1422703 = r1422679 ? r1422688 : r1422702;
        return r1422703;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 3 regimes
  2. if b < -3.396811349079212e+61

    1. Initial program 37.6

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

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

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

    if -3.396811349079212e+61 < b < 1.3659668388152999e-67

    1. Initial program 13.9

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

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

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

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

      \[\leadsto \color{blue}{\frac{\sqrt{\mathsf{fma}\left(c, \left(-4 \cdot a\right), \left(b \cdot b\right)\right)} - b}{1} \cdot \frac{\frac{1}{2}}{a}}\]
    7. Simplified14.0

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

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

    if 1.3659668388152999e-67 < b

    1. Initial program 53.0

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -3.396811349079212 \cdot 10^{+61}:\\ \;\;\;\;\frac{\left(\frac{c}{\frac{b}{a}} - b\right) \cdot 2}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.3659668388152999 \cdot 10^{-67}:\\ \;\;\;\;\frac{\frac{1}{2}}{a} \cdot \left(\sqrt{\mathsf{fma}\left(c, \left(-4 \cdot a\right), \left(b \cdot b\right)\right)} - b\right)\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019130 +o rules:numerics
(FPCore (a b c)
  :name "Quadratic roots, full range"
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))