Average Error: 34.0 → 30.1
Time: 43.8s
Precision: 64
\[\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 1.599460360788912 \cdot 10^{+41}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(\left(\sqrt{\sqrt{\mathsf{fma}\left(c, \left(-4 \cdot a\right), \left(b \cdot b\right)\right)}}\right), \left(\sqrt{\sqrt{\mathsf{fma}\left(c, \left(-4 \cdot a\right), \left(b \cdot b\right)\right)}}\right), \left(-b\right)\right)}{2}}{a}\\ \mathbf{else}:\\ \;\;\;\;0\\ \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 1.599460360788912 \cdot 10^{+41}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(\left(\sqrt{\sqrt{\mathsf{fma}\left(c, \left(-4 \cdot a\right), \left(b \cdot b\right)\right)}}\right), \left(\sqrt{\sqrt{\mathsf{fma}\left(c, \left(-4 \cdot a\right), \left(b \cdot b\right)\right)}}\right), \left(-b\right)\right)}{2}}{a}\\

\mathbf{else}:\\
\;\;\;\;0\\

\end{array}
double f(double a, double b, double c) {
        double r22242541 = b;
        double r22242542 = -r22242541;
        double r22242543 = r22242541 * r22242541;
        double r22242544 = 4.0;
        double r22242545 = a;
        double r22242546 = r22242544 * r22242545;
        double r22242547 = c;
        double r22242548 = r22242546 * r22242547;
        double r22242549 = r22242543 - r22242548;
        double r22242550 = sqrt(r22242549);
        double r22242551 = r22242542 + r22242550;
        double r22242552 = 2.0;
        double r22242553 = r22242552 * r22242545;
        double r22242554 = r22242551 / r22242553;
        return r22242554;
}

double f(double a, double b, double c) {
        double r22242555 = b;
        double r22242556 = 1.599460360788912e+41;
        bool r22242557 = r22242555 <= r22242556;
        double r22242558 = c;
        double r22242559 = -4.0;
        double r22242560 = a;
        double r22242561 = r22242559 * r22242560;
        double r22242562 = r22242555 * r22242555;
        double r22242563 = fma(r22242558, r22242561, r22242562);
        double r22242564 = sqrt(r22242563);
        double r22242565 = sqrt(r22242564);
        double r22242566 = -r22242555;
        double r22242567 = fma(r22242565, r22242565, r22242566);
        double r22242568 = 2.0;
        double r22242569 = r22242567 / r22242568;
        double r22242570 = r22242569 / r22242560;
        double r22242571 = 0.0;
        double r22242572 = r22242557 ? r22242570 : r22242571;
        return r22242572;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original34.0
Target20.9
Herbie30.1
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}}\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if b < 1.599460360788912e+41

    1. Initial program 24.6

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

      \[\leadsto \color{blue}{\frac{\frac{\sqrt{\mathsf{fma}\left(c, \left(-4 \cdot a\right), \left(b \cdot b\right)\right)} - b}{2}}{a}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt24.9

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

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

    if 1.599460360788912e+41 < b

    1. Initial program 56.3

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

      \[\leadsto \color{blue}{\frac{\frac{\sqrt{\mathsf{fma}\left(c, \left(-4 \cdot a\right), \left(b \cdot b\right)\right)} - b}{2}}{a}}\]
    3. Using strategy rm
    4. Applied div-inv56.4

      \[\leadsto \color{blue}{\frac{\sqrt{\mathsf{fma}\left(c, \left(-4 \cdot a\right), \left(b \cdot b\right)\right)} - b}{2} \cdot \frac{1}{a}}\]
    5. Taylor expanded around 0 42.6

      \[\leadsto \color{blue}{0}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification30.1

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

Reproduce

herbie shell --seed 2019120 +o rules:numerics
(FPCore (a b c)
  :name "The quadratic formula (r1)"

  :herbie-target
  (if (< b 0) (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))))

  (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))