Average Error: 28.7 → 17.5
Time: 24.7s
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 14.42119907524596733594535180600360035896:\\ \;\;\;\;\frac{\frac{\left(b \cdot b - a \cdot \left(c \cdot 4\right)\right) \cdot \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)} - \left(b \cdot b\right) \cdot b}{\mathsf{fma}\left(b, \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)} + b, b \cdot b - a \cdot \left(c \cdot 4\right)\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{a \cdot c}{b} \cdot -2\right) \cdot \frac{1}{2 \cdot a}\\ \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 14.42119907524596733594535180600360035896:\\
\;\;\;\;\frac{\frac{\left(b \cdot b - a \cdot \left(c \cdot 4\right)\right) \cdot \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)} - \left(b \cdot b\right) \cdot b}{\mathsf{fma}\left(b, \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)} + b, b \cdot b - a \cdot \left(c \cdot 4\right)\right)}}{2 \cdot a}\\

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

\end{array}
double f(double a, double b, double c) {
        double r1680705 = b;
        double r1680706 = -r1680705;
        double r1680707 = r1680705 * r1680705;
        double r1680708 = 4.0;
        double r1680709 = a;
        double r1680710 = r1680708 * r1680709;
        double r1680711 = c;
        double r1680712 = r1680710 * r1680711;
        double r1680713 = r1680707 - r1680712;
        double r1680714 = sqrt(r1680713);
        double r1680715 = r1680706 + r1680714;
        double r1680716 = 2.0;
        double r1680717 = r1680716 * r1680709;
        double r1680718 = r1680715 / r1680717;
        return r1680718;
}

double f(double a, double b, double c) {
        double r1680719 = b;
        double r1680720 = 14.421199075245967;
        bool r1680721 = r1680719 <= r1680720;
        double r1680722 = r1680719 * r1680719;
        double r1680723 = a;
        double r1680724 = c;
        double r1680725 = 4.0;
        double r1680726 = r1680724 * r1680725;
        double r1680727 = r1680723 * r1680726;
        double r1680728 = r1680722 - r1680727;
        double r1680729 = sqrt(r1680728);
        double r1680730 = r1680728 * r1680729;
        double r1680731 = r1680722 * r1680719;
        double r1680732 = r1680730 - r1680731;
        double r1680733 = r1680729 + r1680719;
        double r1680734 = fma(r1680719, r1680733, r1680728);
        double r1680735 = r1680732 / r1680734;
        double r1680736 = 2.0;
        double r1680737 = r1680736 * r1680723;
        double r1680738 = r1680735 / r1680737;
        double r1680739 = r1680723 * r1680724;
        double r1680740 = r1680739 / r1680719;
        double r1680741 = -2.0;
        double r1680742 = r1680740 * r1680741;
        double r1680743 = 1.0;
        double r1680744 = r1680743 / r1680737;
        double r1680745 = r1680742 * r1680744;
        double r1680746 = r1680721 ? r1680738 : r1680745;
        return r1680746;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

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

    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{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied flip3--14.0

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

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

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

    if 14.421199075245967 < b

    1. Initial program 33.2

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

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

      \[\leadsto \frac{\color{blue}{-2 \cdot \frac{a \cdot c}{b}}}{2 \cdot a}\]
    4. Using strategy rm
    5. Applied div-inv18.8

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

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

Reproduce

herbie shell --seed 2019200 +o rules:numerics
(FPCore (a b c)
  :name "Quadratic roots, narrow range"
  :pre (and (< 1.0536712127723509e-08 a 94906265.62425156) (< 1.0536712127723509e-08 b 94906265.62425156) (< 1.0536712127723509e-08 c 94906265.62425156))
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))