Average Error: 19.1 → 12.8
Time: 46.1s
Precision: 64
\[\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
\[\begin{array}{l} \mathbf{if}\;b \le 1.5386020478423979 \cdot 10^{+121}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(\left(-\sqrt{b}\right), \left(\sqrt{b}\right), \left(\sqrt{\sqrt{\mathsf{fma}\left(-4, \left(a \cdot c\right), \left(b \cdot b\right)\right)}} \cdot \left(-\sqrt{\sqrt{\mathsf{fma}\left(-4, \left(a \cdot c\right), \left(b \cdot b\right)\right)}}\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4, \left(a \cdot c\right), \left(b \cdot b\right)\right)} - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4, \left(a \cdot c\right), \left(b \cdot b\right)\right)} - b}{2 \cdot a}\\ \end{array}\]
\begin{array}{l}
\mathbf{if}\;b \ge 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\

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

\end{array}
\begin{array}{l}
\mathbf{if}\;b \le 1.5386020478423979 \cdot 10^{+121}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0:\\
\;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(\left(-\sqrt{b}\right), \left(\sqrt{b}\right), \left(\sqrt{\sqrt{\mathsf{fma}\left(-4, \left(a \cdot c\right), \left(b \cdot b\right)\right)}} \cdot \left(-\sqrt{\sqrt{\mathsf{fma}\left(-4, \left(a \cdot c\right), \left(b \cdot b\right)\right)}}\right)\right)\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4, \left(a \cdot c\right), \left(b \cdot b\right)\right)} - b}{2 \cdot a}\\

\end{array}\\

\mathbf{elif}\;b \ge 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\

\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4, \left(a \cdot c\right), \left(b \cdot b\right)\right)} - b}{2 \cdot a}\\

\end{array}
double f(double a, double b, double c) {
        double r1411952 = b;
        double r1411953 = 0.0;
        bool r1411954 = r1411952 >= r1411953;
        double r1411955 = 2.0;
        double r1411956 = c;
        double r1411957 = r1411955 * r1411956;
        double r1411958 = -r1411952;
        double r1411959 = r1411952 * r1411952;
        double r1411960 = 4.0;
        double r1411961 = a;
        double r1411962 = r1411960 * r1411961;
        double r1411963 = r1411962 * r1411956;
        double r1411964 = r1411959 - r1411963;
        double r1411965 = sqrt(r1411964);
        double r1411966 = r1411958 - r1411965;
        double r1411967 = r1411957 / r1411966;
        double r1411968 = r1411958 + r1411965;
        double r1411969 = r1411955 * r1411961;
        double r1411970 = r1411968 / r1411969;
        double r1411971 = r1411954 ? r1411967 : r1411970;
        return r1411971;
}

double f(double a, double b, double c) {
        double r1411972 = b;
        double r1411973 = 1.5386020478423979e+121;
        bool r1411974 = r1411972 <= r1411973;
        double r1411975 = 0.0;
        bool r1411976 = r1411972 >= r1411975;
        double r1411977 = 2.0;
        double r1411978 = c;
        double r1411979 = r1411977 * r1411978;
        double r1411980 = sqrt(r1411972);
        double r1411981 = -r1411980;
        double r1411982 = -4.0;
        double r1411983 = a;
        double r1411984 = r1411983 * r1411978;
        double r1411985 = r1411972 * r1411972;
        double r1411986 = fma(r1411982, r1411984, r1411985);
        double r1411987 = sqrt(r1411986);
        double r1411988 = sqrt(r1411987);
        double r1411989 = -r1411988;
        double r1411990 = r1411988 * r1411989;
        double r1411991 = fma(r1411981, r1411980, r1411990);
        double r1411992 = r1411979 / r1411991;
        double r1411993 = r1411987 - r1411972;
        double r1411994 = r1411977 * r1411983;
        double r1411995 = r1411993 / r1411994;
        double r1411996 = r1411976 ? r1411992 : r1411995;
        double r1411997 = -r1411972;
        double r1411998 = r1411997 - r1411972;
        double r1411999 = r1411979 / r1411998;
        double r1412000 = r1411976 ? r1411999 : r1411995;
        double r1412001 = r1411974 ? r1411996 : r1412000;
        return r1412001;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 2 regimes
  2. if b < 1.5386020478423979e+121

    1. Initial program 15.4

      \[\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
    2. Simplified15.4

      \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)} - b}{2 \cdot a}\\ \end{array}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt15.5

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \color{blue}{\sqrt{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)} - b}{2 \cdot a}\\ \end{array}\]
    5. Applied add-sqr-sqrt15.5

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-\color{blue}{\sqrt{b} \cdot \sqrt{b}}\right) - \sqrt{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)} - b}{2 \cdot a}\\ \end{array}\]
    6. Applied distribute-lft-neg-in15.5

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\color{blue}{\left(-\sqrt{b}\right) \cdot \sqrt{b}} - \sqrt{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)} - b}{2 \cdot a}\\ \end{array}\]
    7. Applied prod-diff15.6

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\color{blue}{\mathsf{fma}\left(\left(-\sqrt{b}\right), \left(\sqrt{b}\right), \left(-\sqrt{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}}\right)\right) + \mathsf{fma}\left(\left(-\sqrt{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}}\right), \left(\sqrt{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}}\right), \left(\sqrt{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}}\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)} - b}{2 \cdot a}\\ \end{array}\]
    8. Simplified15.5

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

    if 1.5386020478423979e+121 < b

    1. Initial program 32.8

      \[\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
    2. Simplified32.8

      \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)} - b}{2 \cdot a}\\ \end{array}}\]
    3. Taylor expanded around 0 2.5

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \color{blue}{b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)} - b}{2 \cdot a}\\ \end{array}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification12.8

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

Reproduce

herbie shell --seed 2019128 +o rules:numerics
(FPCore (a b c)
  :name "jeff quadratic root 2"
  (if (>= b 0) (/ (* 2 c) (- (- b) (sqrt (- (* b b) (* (* 4 a) c))))) (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a))))