Average Error: 28.4 → 16.3
Time: 12.0s
Precision: 64
\[1.053671212772350866701172186984739043147 \cdot 10^{-8} \lt a \lt 94906265.62425155937671661376953125 \land 1.053671212772350866701172186984739043147 \cdot 10^{-8} \lt b \lt 94906265.62425155937671661376953125 \land 1.053671212772350866701172186984739043147 \cdot 10^{-8} \lt c \lt 94906265.62425155937671661376953125\]
\[\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 3559.649612988867374951951205730438232422:\\ \;\;\;\;\frac{\frac{b \cdot b - \mathsf{fma}\left(c, 4 \cdot a, b \cdot b\right)}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\left(-2 \cdot \left(a \cdot c\right)\right) \cdot \frac{1}{\left(2 \cdot a\right) \cdot 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 3559.649612988867374951951205730438232422:\\
\;\;\;\;\frac{\frac{b \cdot b - \mathsf{fma}\left(c, 4 \cdot a, b \cdot b\right)}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b}}{2 \cdot a}\\

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

\end{array}
double f(double a, double b, double c) {
        double r30042 = b;
        double r30043 = -r30042;
        double r30044 = r30042 * r30042;
        double r30045 = 4.0;
        double r30046 = a;
        double r30047 = r30045 * r30046;
        double r30048 = c;
        double r30049 = r30047 * r30048;
        double r30050 = r30044 - r30049;
        double r30051 = sqrt(r30050);
        double r30052 = r30043 + r30051;
        double r30053 = 2.0;
        double r30054 = r30053 * r30046;
        double r30055 = r30052 / r30054;
        return r30055;
}

double f(double a, double b, double c) {
        double r30056 = b;
        double r30057 = 3559.6496129888674;
        bool r30058 = r30056 <= r30057;
        double r30059 = r30056 * r30056;
        double r30060 = c;
        double r30061 = 4.0;
        double r30062 = a;
        double r30063 = r30061 * r30062;
        double r30064 = fma(r30060, r30063, r30059);
        double r30065 = r30059 - r30064;
        double r30066 = r30063 * r30060;
        double r30067 = r30059 - r30066;
        double r30068 = sqrt(r30067);
        double r30069 = r30068 + r30056;
        double r30070 = r30065 / r30069;
        double r30071 = 2.0;
        double r30072 = r30071 * r30062;
        double r30073 = r30070 / r30072;
        double r30074 = -2.0;
        double r30075 = r30062 * r30060;
        double r30076 = r30074 * r30075;
        double r30077 = 1.0;
        double r30078 = r30072 * r30056;
        double r30079 = r30077 / r30078;
        double r30080 = r30076 * r30079;
        double r30081 = r30058 ? r30073 : r30080;
        return r30081;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 2 regimes
  2. if b < 3559.6496129888674

    1. Initial program 18.1

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

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

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

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

    if 3559.6496129888674 < b

    1. Initial program 37.1

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

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

      \[\leadsto \frac{\color{blue}{-2 \cdot \frac{a \cdot c}{b}}}{2 \cdot a}\]
    4. Using strategy rm
    5. Applied associate-*r/15.6

      \[\leadsto \frac{\color{blue}{\frac{-2 \cdot \left(a \cdot c\right)}{b}}}{2 \cdot a}\]
    6. Applied associate-/l/15.6

      \[\leadsto \color{blue}{\frac{-2 \cdot \left(a \cdot c\right)}{\left(2 \cdot a\right) \cdot b}}\]
    7. Using strategy rm
    8. Applied div-inv15.6

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

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

Reproduce

herbie shell --seed 2019208 +o rules:numerics
(FPCore (a b c)
  :name "Quadratic roots, narrow range"
  :precision binary64
  :pre (and (< 1.05367121277235087e-8 a 94906265.6242515594) (< 1.05367121277235087e-8 b 94906265.6242515594) (< 1.05367121277235087e-8 c 94906265.6242515594))
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))