Average Error: 33.4 → 10.5
Time: 49.3s
Precision: 64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{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 r4942988 = b;
        double r4942989 = -r4942988;
        double r4942990 = r4942988 * r4942988;
        double r4942991 = 4.0;
        double r4942992 = a;
        double r4942993 = c;
        double r4942994 = r4942992 * r4942993;
        double r4942995 = r4942991 * r4942994;
        double r4942996 = r4942990 - r4942995;
        double r4942997 = sqrt(r4942996);
        double r4942998 = r4942989 + r4942997;
        double r4942999 = 2.0;
        double r4943000 = r4942999 * r4942992;
        double r4943001 = r4942998 / r4943000;
        return r4943001;
}

double f(double a, double b, double c) {
        double r4943002 = b;
        double r4943003 = -3.4350120867177856e+86;
        bool r4943004 = r4943002 <= r4943003;
        double r4943005 = c;
        double r4943006 = r4943005 / r4943002;
        double r4943007 = a;
        double r4943008 = r4943002 / r4943007;
        double r4943009 = r4943006 - r4943008;
        double r4943010 = 9.022485597500134e-56;
        bool r4943011 = r4943002 <= r4943010;
        double r4943012 = r4943002 * r4943002;
        double r4943013 = 4.0;
        double r4943014 = r4943013 * r4943007;
        double r4943015 = r4943005 * r4943014;
        double r4943016 = r4943012 - r4943015;
        double r4943017 = sqrt(r4943016);
        double r4943018 = r4943017 - r4943002;
        double r4943019 = r4943018 / r4943007;
        double r4943020 = 0.5;
        double r4943021 = r4943019 * r4943020;
        double r4943022 = -r4943006;
        double r4943023 = r4943011 ? r4943021 : r4943022;
        double r4943024 = r4943004 ? r4943009 : r4943023;
        return r4943024;
}

\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{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 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{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 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Simplified41.4

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}}\]
    3. 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 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Simplified14.3

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

      \[\leadsto \frac{\color{blue}{1 \cdot \left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right)}}{2 \cdot a}\]
    5. Applied associate-/l*14.4

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

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

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

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

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

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

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

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

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

    if 9.022485597500134e-56 < b

    1. Initial program 53.4

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    4. 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 "quadp (p42, positive)"

  :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)))