Average Error: 34.2 → 8.1
Time: 5.9s
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 -8.55528137777049654 \cdot 10^{140}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 9.52089004516141949 \cdot 10^{-271}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{elif}\;b \le 26039420339585284:\\ \;\;\;\;\frac{\frac{1}{\frac{\frac{\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{4}}{a}}{c}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \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 -8.55528137777049654 \cdot 10^{140}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r114090 = b;
        double r114091 = -r114090;
        double r114092 = r114090 * r114090;
        double r114093 = 4.0;
        double r114094 = a;
        double r114095 = r114093 * r114094;
        double r114096 = c;
        double r114097 = r114095 * r114096;
        double r114098 = r114092 - r114097;
        double r114099 = sqrt(r114098);
        double r114100 = r114091 + r114099;
        double r114101 = 2.0;
        double r114102 = r114101 * r114094;
        double r114103 = r114100 / r114102;
        return r114103;
}

double f(double a, double b, double c) {
        double r114104 = b;
        double r114105 = -8.555281377770497e+140;
        bool r114106 = r114104 <= r114105;
        double r114107 = 1.0;
        double r114108 = c;
        double r114109 = r114108 / r114104;
        double r114110 = a;
        double r114111 = r114104 / r114110;
        double r114112 = r114109 - r114111;
        double r114113 = r114107 * r114112;
        double r114114 = 9.52089004516142e-271;
        bool r114115 = r114104 <= r114114;
        double r114116 = -r114104;
        double r114117 = r114104 * r114104;
        double r114118 = 4.0;
        double r114119 = r114118 * r114110;
        double r114120 = r114119 * r114108;
        double r114121 = r114117 - r114120;
        double r114122 = sqrt(r114121);
        double r114123 = r114116 + r114122;
        double r114124 = 2.0;
        double r114125 = r114124 * r114110;
        double r114126 = r114123 / r114125;
        double r114127 = 26039420339585284.0;
        bool r114128 = r114104 <= r114127;
        double r114129 = 1.0;
        double r114130 = r114116 - r114122;
        double r114131 = r114130 / r114118;
        double r114132 = r114131 / r114110;
        double r114133 = r114132 / r114108;
        double r114134 = r114129 / r114133;
        double r114135 = r114134 / r114125;
        double r114136 = -1.0;
        double r114137 = r114136 * r114109;
        double r114138 = r114128 ? r114135 : r114137;
        double r114139 = r114115 ? r114126 : r114138;
        double r114140 = r114106 ? r114113 : r114139;
        return r114140;
}

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

Original34.2
Target21.2
Herbie8.1
\[\begin{array}{l} \mathbf{if}\;b \lt 0.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 < -8.555281377770497e+140

    1. Initial program 58.5

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

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

      \[\leadsto \frac{\frac{\color{blue}{0 + 4 \cdot \left(a \cdot c\right)}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\]
    5. Using strategy rm
    6. Applied clear-num62.7

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

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

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

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

    if -8.555281377770497e+140 < b < 9.52089004516142e-271

    1. Initial program 9.7

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

    if 9.52089004516142e-271 < b < 26039420339585284.0

    1. Initial program 27.1

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

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

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

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

      \[\leadsto \frac{\frac{1}{\color{blue}{\frac{\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{4}}{a \cdot c}}}}{2 \cdot a}\]
    8. Using strategy rm
    9. Applied associate-/r*14.2

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

    if 26039420339585284.0 < b

    1. Initial program 56.0

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

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

      \[\leadsto \frac{\frac{\color{blue}{0 + 4 \cdot \left(a \cdot c\right)}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\]
    5. Using strategy rm
    6. Applied clear-num26.8

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -8.55528137777049654 \cdot 10^{140}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 9.52089004516141949 \cdot 10^{-271}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{elif}\;b \le 26039420339585284:\\ \;\;\;\;\frac{\frac{1}{\frac{\frac{\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{4}}{a}}{c}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2020046 
(FPCore (a b c)
  :name "The quadratic formula (r1)"
  :precision binary64

  :herbie-target
  (if (< b 0.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)))