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

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

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

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

\end{array}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r1060724 = b;
        double r1060725 = 0.0;
        bool r1060726 = r1060724 >= r1060725;
        double r1060727 = -r1060724;
        double r1060728 = r1060724 * r1060724;
        double r1060729 = 4.0;
        double r1060730 = a;
        double r1060731 = r1060729 * r1060730;
        double r1060732 = c;
        double r1060733 = r1060731 * r1060732;
        double r1060734 = r1060728 - r1060733;
        double r1060735 = sqrt(r1060734);
        double r1060736 = r1060727 - r1060735;
        double r1060737 = 2.0;
        double r1060738 = r1060737 * r1060730;
        double r1060739 = r1060736 / r1060738;
        double r1060740 = r1060737 * r1060732;
        double r1060741 = r1060727 + r1060735;
        double r1060742 = r1060740 / r1060741;
        double r1060743 = r1060726 ? r1060739 : r1060742;
        return r1060743;
}

double f(double a, double b, double c) {
        double r1060744 = b;
        double r1060745 = 2.3543665697229833e+137;
        bool r1060746 = r1060744 <= r1060745;
        double r1060747 = 0.0;
        bool r1060748 = r1060744 >= r1060747;
        double r1060749 = -r1060744;
        double r1060750 = c;
        double r1060751 = a;
        double r1060752 = -4.0;
        double r1060753 = r1060751 * r1060752;
        double r1060754 = r1060744 * r1060744;
        double r1060755 = fma(r1060750, r1060753, r1060754);
        double r1060756 = sqrt(r1060755);
        double r1060757 = r1060749 - r1060756;
        double r1060758 = 2.0;
        double r1060759 = r1060758 * r1060751;
        double r1060760 = r1060757 / r1060759;
        double r1060761 = cbrt(r1060755);
        double r1060762 = r1060761 * r1060761;
        double r1060763 = sqrt(r1060762);
        double r1060764 = sqrt(r1060761);
        double r1060765 = cbrt(r1060744);
        double r1060766 = -r1060765;
        double r1060767 = r1060765 * r1060765;
        double r1060768 = r1060766 * r1060767;
        double r1060769 = fma(r1060763, r1060764, r1060768);
        double r1060770 = r1060744 - r1060744;
        double r1060771 = r1060769 + r1060770;
        double r1060772 = r1060771 / r1060758;
        double r1060773 = r1060750 / r1060772;
        double r1060774 = r1060748 ? r1060760 : r1060773;
        double r1060775 = r1060749 - r1060744;
        double r1060776 = r1060775 / r1060759;
        double r1060777 = r1060756 - r1060744;
        double r1060778 = r1060777 / r1060758;
        double r1060779 = r1060750 / r1060778;
        double r1060780 = r1060748 ? r1060776 : r1060779;
        double r1060781 = r1060746 ? r1060774 : r1060780;
        return r1060781;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 2 regimes
  2. if b < 2.3543665697229833e+137

    1. Initial program 14.6

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

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

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

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

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

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

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

    if 2.3543665697229833e+137 < b

    1. Initial program 52.8

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

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

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

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

Reproduce

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