Average Error: 33.4 → 10.5
Time: 34.3s
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 -3.4350120867177856 \cdot 10^{+86}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 9.022485597500134 \cdot 10^{-56}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a} \cdot \frac{1}{2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]
double f(double a, double b, double c) {
        double r22974542 = b;
        double r22974543 = -r22974542;
        double r22974544 = r22974542 * r22974542;
        double r22974545 = 4.0;
        double r22974546 = a;
        double r22974547 = r22974545 * r22974546;
        double r22974548 = c;
        double r22974549 = r22974547 * r22974548;
        double r22974550 = r22974544 - r22974549;
        double r22974551 = sqrt(r22974550);
        double r22974552 = r22974543 + r22974551;
        double r22974553 = 2.0;
        double r22974554 = r22974553 * r22974546;
        double r22974555 = r22974552 / r22974554;
        return r22974555;
}

double f(double a, double b, double c) {
        double r22974556 = b;
        double r22974557 = -3.4350120867177856e+86;
        bool r22974558 = r22974556 <= r22974557;
        double r22974559 = c;
        double r22974560 = r22974559 / r22974556;
        double r22974561 = a;
        double r22974562 = r22974556 / r22974561;
        double r22974563 = r22974560 - r22974562;
        double r22974564 = 9.022485597500134e-56;
        bool r22974565 = r22974556 <= r22974564;
        double r22974566 = r22974556 * r22974556;
        double r22974567 = 4.0;
        double r22974568 = r22974567 * r22974561;
        double r22974569 = r22974559 * r22974568;
        double r22974570 = r22974566 - r22974569;
        double r22974571 = sqrt(r22974570);
        double r22974572 = r22974571 - r22974556;
        double r22974573 = r22974572 / r22974561;
        double r22974574 = 0.5;
        double r22974575 = r22974573 * r22974574;
        double r22974576 = -r22974560;
        double r22974577 = r22974565 ? r22974575 : r22974576;
        double r22974578 = r22974558 ? r22974563 : r22974577;
        return r22974578;
}

\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 -3.4350120867177856 \cdot 10^{+86}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

\mathbf{elif}\;b \le 9.022485597500134 \cdot 10^{-56}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a} \cdot \frac{1}{2}\\

\mathbf{else}:\\
\;\;\;\;-\frac{c}{b}\\

\end{array}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.4
Target20.6
Herbie10.5
\[\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 3 regimes
  2. if b < -3.4350120867177856e+86

    1. Initial program 41.4

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Taylor expanded around -inf 4.4

      \[\leadsto \color{blue}{\frac{c}{b} - \frac{b}{a}}\]

    if -3.4350120867177856e+86 < b < 9.022485597500134e-56

    1. Initial program 14.3

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied clear-num14.4

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity14.4

      \[\leadsto \frac{1}{\frac{2 \cdot a}{\left(-b\right) + \color{blue}{1 \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}\]
    6. Applied *-un-lft-identity14.4

      \[\leadsto \frac{1}{\frac{2 \cdot a}{\color{blue}{1 \cdot \left(-b\right)} + 1 \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\]
    7. Applied distribute-lft-out14.4

      \[\leadsto \frac{1}{\frac{2 \cdot a}{\color{blue}{1 \cdot \left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}}\]
    8. Applied times-frac14.4

      \[\leadsto \frac{1}{\color{blue}{\frac{2}{1} \cdot \frac{a}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}\]
    9. Applied add-sqr-sqrt14.4

      \[\leadsto \frac{\color{blue}{\sqrt{1} \cdot \sqrt{1}}}{\frac{2}{1} \cdot \frac{a}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\]
    10. Applied times-frac14.4

      \[\leadsto \color{blue}{\frac{\sqrt{1}}{\frac{2}{1}} \cdot \frac{\sqrt{1}}{\frac{a}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}\]
    11. Simplified14.4

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

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

    if 9.022485597500134e-56 < b

    1. Initial program 53.4

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Taylor expanded around inf 8.5

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    3. Simplified8.5

      \[\leadsto \color{blue}{-\frac{c}{b}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification10.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -3.4350120867177856 \cdot 10^{+86}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 9.022485597500134 \cdot 10^{-56}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a} \cdot \frac{1}{2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019101 
(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)))