Average Error: 33.1 → 9.2
Time: 1.3m
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.6124744946043857 \cdot 10^{+143}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 1.754487595174753 \cdot 10^{-113}:\\ \;\;\;\;\frac{\sqrt{\left(c \cdot -4\right) \cdot a + b \cdot b} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 9.873738165909194 \cdot 10^{+16}:\\ \;\;\;\;\frac{a \cdot \left(\left(c \cdot -4\right) \cdot \frac{\frac{1}{2}}{a}\right)}{\sqrt{\left(c \cdot -4\right) \cdot a + b \cdot b} + b}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \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.6124744946043857 \cdot 10^{+143}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r16277122 = b;
        double r16277123 = -r16277122;
        double r16277124 = r16277122 * r16277122;
        double r16277125 = 4.0;
        double r16277126 = a;
        double r16277127 = r16277125 * r16277126;
        double r16277128 = c;
        double r16277129 = r16277127 * r16277128;
        double r16277130 = r16277124 - r16277129;
        double r16277131 = sqrt(r16277130);
        double r16277132 = r16277123 + r16277131;
        double r16277133 = 2.0;
        double r16277134 = r16277133 * r16277126;
        double r16277135 = r16277132 / r16277134;
        return r16277135;
}

double f(double a, double b, double c) {
        double r16277136 = b;
        double r16277137 = -1.6124744946043857e+143;
        bool r16277138 = r16277136 <= r16277137;
        double r16277139 = c;
        double r16277140 = r16277139 / r16277136;
        double r16277141 = a;
        double r16277142 = r16277136 / r16277141;
        double r16277143 = r16277140 - r16277142;
        double r16277144 = 1.754487595174753e-113;
        bool r16277145 = r16277136 <= r16277144;
        double r16277146 = -4.0;
        double r16277147 = r16277139 * r16277146;
        double r16277148 = r16277147 * r16277141;
        double r16277149 = r16277136 * r16277136;
        double r16277150 = r16277148 + r16277149;
        double r16277151 = sqrt(r16277150);
        double r16277152 = r16277151 - r16277136;
        double r16277153 = 2.0;
        double r16277154 = r16277141 * r16277153;
        double r16277155 = r16277152 / r16277154;
        double r16277156 = 9.873738165909194e+16;
        bool r16277157 = r16277136 <= r16277156;
        double r16277158 = 0.5;
        double r16277159 = r16277158 / r16277141;
        double r16277160 = r16277147 * r16277159;
        double r16277161 = r16277141 * r16277160;
        double r16277162 = r16277151 + r16277136;
        double r16277163 = r16277161 / r16277162;
        double r16277164 = -r16277140;
        double r16277165 = r16277157 ? r16277163 : r16277164;
        double r16277166 = r16277145 ? r16277155 : r16277165;
        double r16277167 = r16277138 ? r16277143 : r16277166;
        return r16277167;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original33.1
Target20.2
Herbie9.2
\[\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 < -1.6124744946043857e+143

    1. Initial program 57.1

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

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

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

    if -1.6124744946043857e+143 < b < 1.754487595174753e-113

    1. Initial program 11.1

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

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

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

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

    if 1.754487595174753e-113 < b < 9.873738165909194e+16

    1. Initial program 38.5

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

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

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

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

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

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

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

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

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

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

    if 9.873738165909194e+16 < b

    1. Initial program 54.7

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified54.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 5.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.6124744946043857 \cdot 10^{+143}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 1.754487595174753 \cdot 10^{-113}:\\ \;\;\;\;\frac{\sqrt{\left(c \cdot -4\right) \cdot a + b \cdot b} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 9.873738165909194 \cdot 10^{+16}:\\ \;\;\;\;\frac{a \cdot \left(\left(c \cdot -4\right) \cdot \frac{\frac{1}{2}}{a}\right)}{\sqrt{\left(c \cdot -4\right) \cdot a + b \cdot b} + b}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

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