Average Error: 19.9 → 6.5
Time: 19.3s
Precision: 64
\[\begin{array}{l} \mathbf{if}\;b \ge 0.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 -7.943482039519133630405882994043698433958 \cdot 10^{75}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \mathsf{fma}\left(2, -\frac{c}{\frac{b}{a}}, b\right)}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \end{array}\\ \mathbf{elif}\;b \le 2.620543139740264315993856298302188165155 \cdot 10^{84}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\sqrt{\mathsf{fma}\left(-c, a \cdot 4, b \cdot b\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(-c, a \cdot 4, b \cdot b\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}{a \cdot 2}\\ \end{array}\\ \mathbf{elif}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \mathsf{fma}\left(2, -\frac{c}{\frac{b}{a}}, b\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{b \cdot b - \left(b \cdot b - \left(a \cdot c\right) \cdot 4\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4}}}{a \cdot 2}\\ \end{array}\]
\begin{array}{l}
\mathbf{if}\;b \ge 0.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 -7.943482039519133630405882994043698433958 \cdot 10^{75}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0.0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \mathsf{fma}\left(2, -\frac{c}{\frac{b}{a}}, b\right)}\\

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

\end{array}\\

\mathbf{elif}\;b \le 2.620543139740264315993856298302188165155 \cdot 10^{84}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0.0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\sqrt{\mathsf{fma}\left(-c, a \cdot 4, b \cdot b\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(-c, a \cdot 4, b \cdot b\right)}}}\\

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

\end{array}\\

\mathbf{elif}\;b \ge 0.0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \mathsf{fma}\left(2, -\frac{c}{\frac{b}{a}}, b\right)}\\

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

\end{array}
double f(double a, double b, double c) {
        double r41608 = b;
        double r41609 = 0.0;
        bool r41610 = r41608 >= r41609;
        double r41611 = 2.0;
        double r41612 = c;
        double r41613 = r41611 * r41612;
        double r41614 = -r41608;
        double r41615 = r41608 * r41608;
        double r41616 = 4.0;
        double r41617 = a;
        double r41618 = r41616 * r41617;
        double r41619 = r41618 * r41612;
        double r41620 = r41615 - r41619;
        double r41621 = sqrt(r41620);
        double r41622 = r41614 - r41621;
        double r41623 = r41613 / r41622;
        double r41624 = r41614 + r41621;
        double r41625 = r41611 * r41617;
        double r41626 = r41624 / r41625;
        double r41627 = r41610 ? r41623 : r41626;
        return r41627;
}

double f(double a, double b, double c) {
        double r41628 = b;
        double r41629 = -7.943482039519134e+75;
        bool r41630 = r41628 <= r41629;
        double r41631 = 0.0;
        bool r41632 = r41628 >= r41631;
        double r41633 = 2.0;
        double r41634 = c;
        double r41635 = r41633 * r41634;
        double r41636 = -r41628;
        double r41637 = a;
        double r41638 = r41628 / r41637;
        double r41639 = r41634 / r41638;
        double r41640 = -r41639;
        double r41641 = fma(r41633, r41640, r41628);
        double r41642 = r41636 - r41641;
        double r41643 = r41635 / r41642;
        double r41644 = 1.0;
        double r41645 = r41634 / r41628;
        double r41646 = r41645 - r41638;
        double r41647 = r41644 * r41646;
        double r41648 = r41632 ? r41643 : r41647;
        double r41649 = 2.6205431397402643e+84;
        bool r41650 = r41628 <= r41649;
        double r41651 = -r41634;
        double r41652 = 4.0;
        double r41653 = r41637 * r41652;
        double r41654 = r41628 * r41628;
        double r41655 = fma(r41651, r41653, r41654);
        double r41656 = sqrt(r41655);
        double r41657 = sqrt(r41656);
        double r41658 = r41657 * r41657;
        double r41659 = r41636 - r41658;
        double r41660 = r41635 / r41659;
        double r41661 = r41634 * r41653;
        double r41662 = r41654 - r41661;
        double r41663 = sqrt(r41662);
        double r41664 = r41636 + r41663;
        double r41665 = r41637 * r41633;
        double r41666 = r41664 / r41665;
        double r41667 = r41632 ? r41660 : r41666;
        double r41668 = r41637 * r41634;
        double r41669 = r41668 * r41652;
        double r41670 = r41654 - r41669;
        double r41671 = r41654 - r41670;
        double r41672 = sqrt(r41670);
        double r41673 = r41636 - r41672;
        double r41674 = r41671 / r41673;
        double r41675 = r41674 / r41665;
        double r41676 = r41632 ? r41643 : r41675;
        double r41677 = r41650 ? r41667 : r41676;
        double r41678 = r41630 ? r41648 : r41677;
        return r41678;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 3 regimes
  2. if b < -7.943482039519134e+75

    1. Initial program 42.7

      \[\begin{array}{l} \mathbf{if}\;b \ge 0.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. Taylor expanded around inf 42.7

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \color{blue}{\left(b - 2 \cdot \frac{a \cdot c}{b}\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
    3. Simplified42.7

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \mathsf{fma}\left(2, -\frac{c}{\frac{b}{a}}, b\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \mathsf{fma}\left(\frac{a}{\frac{b}{c}}, 2, -b\right)}{2 \cdot a}\\ \end{array}\]
    6. Taylor expanded around 0 4.2

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \mathsf{fma}\left(2, -\frac{c}{\frac{b}{a}}, b\right)}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \frac{c}{b} - 1 \cdot \frac{b}{a}\\ \end{array}\]
    7. Simplified4.2

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

    if -7.943482039519134e+75 < b < 2.6205431397402643e+84

    1. Initial program 9.0

      \[\begin{array}{l} \mathbf{if}\;b \ge 0.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. Using strategy rm
    3. Applied add-sqr-sqrt9.0

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\color{blue}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \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}\]
    4. Applied sqrt-prod9.1

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \color{blue}{\sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\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}\]
    5. Simplified9.1

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \color{blue}{\sqrt{\sqrt{\mathsf{fma}\left(-c, 4 \cdot a, b \cdot b\right)}}} \cdot \sqrt{\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}\]
    6. Simplified9.1

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

    if 2.6205431397402643e+84 < b

    1. Initial program 27.7

      \[\begin{array}{l} \mathbf{if}\;b \ge 0.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. Taylor expanded around inf 5.8

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

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

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

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

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

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

Reproduce

herbie shell --seed 2019194 +o rules:numerics
(FPCore (a b c)
  :name "jeff quadratic root 2"
  (if (>= b 0.0) (/ (* 2.0 c) (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c))))) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a))))