Average Error: 33.8 → 6.8
Time: 46.0s
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 -4.3671561050226844 \cdot 10^{+101}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le -2.5255536235408963 \cdot 10^{-284}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}}\\ \mathbf{elif}\;b \le 1.4199128551722248 \cdot 10^{+110}:\\ \;\;\;\;\frac{1}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + b} \cdot \left(-2 \cdot c\right)\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]
double f(double a, double b, double c) {
        double r31020597 = b;
        double r31020598 = -r31020597;
        double r31020599 = r31020597 * r31020597;
        double r31020600 = 4.0;
        double r31020601 = a;
        double r31020602 = r31020600 * r31020601;
        double r31020603 = c;
        double r31020604 = r31020602 * r31020603;
        double r31020605 = r31020599 - r31020604;
        double r31020606 = sqrt(r31020605);
        double r31020607 = r31020598 + r31020606;
        double r31020608 = 2.0;
        double r31020609 = r31020608 * r31020601;
        double r31020610 = r31020607 / r31020609;
        return r31020610;
}

double f(double a, double b, double c) {
        double r31020611 = b;
        double r31020612 = -4.3671561050226844e+101;
        bool r31020613 = r31020611 <= r31020612;
        double r31020614 = c;
        double r31020615 = r31020614 / r31020611;
        double r31020616 = a;
        double r31020617 = r31020611 / r31020616;
        double r31020618 = r31020615 - r31020617;
        double r31020619 = -2.5255536235408963e-284;
        bool r31020620 = r31020611 <= r31020619;
        double r31020621 = 1.0;
        double r31020622 = 2.0;
        double r31020623 = r31020616 * r31020622;
        double r31020624 = r31020611 * r31020611;
        double r31020625 = 4.0;
        double r31020626 = r31020614 * r31020616;
        double r31020627 = r31020625 * r31020626;
        double r31020628 = r31020624 - r31020627;
        double r31020629 = sqrt(r31020628);
        double r31020630 = r31020629 - r31020611;
        double r31020631 = r31020623 / r31020630;
        double r31020632 = r31020621 / r31020631;
        double r31020633 = 1.4199128551722248e+110;
        bool r31020634 = r31020611 <= r31020633;
        double r31020635 = r31020629 + r31020611;
        double r31020636 = r31020621 / r31020635;
        double r31020637 = -2.0;
        double r31020638 = r31020637 * r31020614;
        double r31020639 = r31020636 * r31020638;
        double r31020640 = -r31020615;
        double r31020641 = r31020634 ? r31020639 : r31020640;
        double r31020642 = r31020620 ? r31020632 : r31020641;
        double r31020643 = r31020613 ? r31020618 : r31020642;
        return r31020643;
}

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

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

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

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

\end{array}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.8
Target21.0
Herbie6.8
\[\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 4 regimes
  2. if b < -4.3671561050226844e+101

    1. Initial program 44.7

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{2 \cdot a}}\]
    3. Taylor expanded around -inf 3.8

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

    if -4.3671561050226844e+101 < b < -2.5255536235408963e-284

    1. Initial program 9.0

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied clear-num9.1

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

    if -2.5255536235408963e-284 < b < 1.4199128551722248e+110

    1. Initial program 32.0

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied clear-num32.1

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}}}\]
    5. Using strategy rm
    6. Applied flip--32.2

      \[\leadsto \frac{1}{\frac{2 \cdot a}{\color{blue}{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} \cdot \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b \cdot b}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b}}}}\]
    7. Applied associate-/r/32.2

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

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

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

      \[\leadsto \color{blue}{\frac{0 - \left(c \cdot a\right) \cdot 4}{\frac{a}{\frac{1}{2}}}} \cdot \frac{1}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b}\]
    11. Taylor expanded around -inf 9.3

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

    if 1.4199128551722248e+110 < b

    1. Initial program 59.7

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{2 \cdot a}}\]
    3. Taylor expanded around inf 2.1

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    4. Simplified2.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -4.3671561050226844 \cdot 10^{+101}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le -2.5255536235408963 \cdot 10^{-284}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}}\\ \mathbf{elif}\;b \le 1.4199128551722248 \cdot 10^{+110}:\\ \;\;\;\;\frac{1}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + b} \cdot \left(-2 \cdot c\right)\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

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