Average Error: 33.8 → 6.6
Time: 50.6s
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 -4.1061641587957725 \cdot 10^{+142}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 5.6646816643665726 \cdot 10^{-285}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a} \cdot \frac{1}{2}\\ \mathbf{elif}\;b \le 1.4653326993720654 \cdot 10^{+110}:\\ \;\;\;\;\frac{c \cdot -2}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]
double f(double a, double b, double c) {
        double r4225075 = b;
        double r4225076 = -r4225075;
        double r4225077 = r4225075 * r4225075;
        double r4225078 = 4.0;
        double r4225079 = a;
        double r4225080 = c;
        double r4225081 = r4225079 * r4225080;
        double r4225082 = r4225078 * r4225081;
        double r4225083 = r4225077 - r4225082;
        double r4225084 = sqrt(r4225083);
        double r4225085 = r4225076 + r4225084;
        double r4225086 = 2.0;
        double r4225087 = r4225086 * r4225079;
        double r4225088 = r4225085 / r4225087;
        return r4225088;
}

double f(double a, double b, double c) {
        double r4225089 = b;
        double r4225090 = -4.1061641587957725e+142;
        bool r4225091 = r4225089 <= r4225090;
        double r4225092 = c;
        double r4225093 = r4225092 / r4225089;
        double r4225094 = a;
        double r4225095 = r4225089 / r4225094;
        double r4225096 = r4225093 - r4225095;
        double r4225097 = 5.6646816643665726e-285;
        bool r4225098 = r4225089 <= r4225097;
        double r4225099 = r4225089 * r4225089;
        double r4225100 = 4.0;
        double r4225101 = r4225100 * r4225094;
        double r4225102 = r4225092 * r4225101;
        double r4225103 = r4225099 - r4225102;
        double r4225104 = sqrt(r4225103);
        double r4225105 = r4225104 - r4225089;
        double r4225106 = r4225105 / r4225094;
        double r4225107 = 0.5;
        double r4225108 = r4225106 * r4225107;
        double r4225109 = 1.4653326993720654e+110;
        bool r4225110 = r4225089 <= r4225109;
        double r4225111 = -2.0;
        double r4225112 = r4225092 * r4225111;
        double r4225113 = r4225092 * r4225094;
        double r4225114 = r4225113 * r4225100;
        double r4225115 = r4225099 - r4225114;
        double r4225116 = sqrt(r4225115);
        double r4225117 = r4225116 + r4225089;
        double r4225118 = r4225112 / r4225117;
        double r4225119 = -r4225093;
        double r4225120 = r4225110 ? r4225118 : r4225119;
        double r4225121 = r4225098 ? r4225108 : r4225120;
        double r4225122 = r4225091 ? r4225096 : r4225121;
        return r4225122;
}

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

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

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

\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.6
\[\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 4 regimes
  2. if b < -4.1061641587957725e+142

    1. Initial program 56.5

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

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

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

    if -4.1061641587957725e+142 < b < 5.6646816643665726e-285

    1. Initial program 9.1

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

      \[\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 clear-num9.3

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

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

      \[\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}}\]
    8. Applied distribute-lft-out--9.3

      \[\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)}}}\]
    9. Applied times-frac9.3

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

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

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

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

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

    if 5.6646816643665726e-285 < b < 1.4653326993720654e+110

    1. Initial program 33.5

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

      \[\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 clear-num33.6

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(-2 \cdot c\right)} \cdot \frac{1}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + b}\]
    13. Using strategy rm
    14. Applied un-div-inv8.6

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

    if 1.4653326993720654e+110 < b

    1. Initial program 59.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -4.1061641587957725 \cdot 10^{+142}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 5.6646816643665726 \cdot 10^{-285}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a} \cdot \frac{1}{2}\\ \mathbf{elif}\;b \le 1.4653326993720654 \cdot 10^{+110}:\\ \;\;\;\;\frac{c \cdot -2}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

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