Average Error: 34.1 → 10.3
Time: 5.5s
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 -8.8665312552031243 \cdot 10^{65}:\\ \;\;\;\;{\left(-1 \cdot \frac{c}{b}\right)}^{1}\\ \mathbf{elif}\;b \le -1519208.93058992573:\\ \;\;\;\;\frac{0 + 1 \cdot \left(4 \cdot \left(a \cdot c\right)\right)}{\left(\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right) \cdot \left(2 \cdot a\right)}\\ \mathbf{elif}\;b \le -2.3901106171036543 \cdot 10^{-123}:\\ \;\;\;\;{\left(-1 \cdot \frac{c}{b}\right)}^{1}\\ \mathbf{elif}\;b \le 1.6414783348607511 \cdot 10^{125}:\\ \;\;\;\;{\left(\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\right)}^{1}\\ \mathbf{else}:\\ \;\;\;\;{\left(1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\right)}^{1}\\ \end{array}\]
\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 -8.8665312552031243 \cdot 10^{65}:\\
\;\;\;\;{\left(-1 \cdot \frac{c}{b}\right)}^{1}\\

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

\mathbf{elif}\;b \le -2.3901106171036543 \cdot 10^{-123}:\\
\;\;\;\;{\left(-1 \cdot \frac{c}{b}\right)}^{1}\\

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

\mathbf{else}:\\
\;\;\;\;{\left(1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\right)}^{1}\\

\end{array}
double f(double a, double b, double c) {
        double r69070 = b;
        double r69071 = -r69070;
        double r69072 = r69070 * r69070;
        double r69073 = 4.0;
        double r69074 = a;
        double r69075 = c;
        double r69076 = r69074 * r69075;
        double r69077 = r69073 * r69076;
        double r69078 = r69072 - r69077;
        double r69079 = sqrt(r69078);
        double r69080 = r69071 - r69079;
        double r69081 = 2.0;
        double r69082 = r69081 * r69074;
        double r69083 = r69080 / r69082;
        return r69083;
}

double f(double a, double b, double c) {
        double r69084 = b;
        double r69085 = -8.866531255203124e+65;
        bool r69086 = r69084 <= r69085;
        double r69087 = -1.0;
        double r69088 = c;
        double r69089 = r69088 / r69084;
        double r69090 = r69087 * r69089;
        double r69091 = 1.0;
        double r69092 = pow(r69090, r69091);
        double r69093 = -1519208.9305899257;
        bool r69094 = r69084 <= r69093;
        double r69095 = 0.0;
        double r69096 = 4.0;
        double r69097 = a;
        double r69098 = r69097 * r69088;
        double r69099 = r69096 * r69098;
        double r69100 = r69091 * r69099;
        double r69101 = r69095 + r69100;
        double r69102 = -r69084;
        double r69103 = r69084 * r69084;
        double r69104 = r69103 - r69099;
        double r69105 = sqrt(r69104);
        double r69106 = r69102 + r69105;
        double r69107 = 2.0;
        double r69108 = r69107 * r69097;
        double r69109 = r69106 * r69108;
        double r69110 = r69101 / r69109;
        double r69111 = -2.3901106171036543e-123;
        bool r69112 = r69084 <= r69111;
        double r69113 = 1.6414783348607511e+125;
        bool r69114 = r69084 <= r69113;
        double r69115 = r69102 - r69105;
        double r69116 = r69115 / r69108;
        double r69117 = pow(r69116, r69091);
        double r69118 = 1.0;
        double r69119 = r69084 / r69097;
        double r69120 = r69089 - r69119;
        double r69121 = r69118 * r69120;
        double r69122 = pow(r69121, r69091);
        double r69123 = r69114 ? r69117 : r69122;
        double r69124 = r69112 ? r69092 : r69123;
        double r69125 = r69094 ? r69110 : r69124;
        double r69126 = r69086 ? r69092 : r69125;
        return r69126;
}

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.1
Target21.2
Herbie10.3
\[\begin{array}{l} \mathbf{if}\;b \lt 0.0:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \mathbf{else}:\\ \;\;\;\;\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 < -8.866531255203124e+65 or -1519208.9305899257 < b < -2.3901106171036543e-123

    1. Initial program 51.6

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

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

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

      \[\leadsto \color{blue}{{\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}^{1}} \cdot {\left(\frac{1}{2 \cdot a}\right)}^{1}\]
    7. Applied pow-prod-down51.6

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

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

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

    if -8.866531255203124e+65 < b < -1519208.9305899257

    1. Initial program 47.1

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

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

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

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

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

    if -2.3901106171036543e-123 < b < 1.6414783348607511e+125

    1. Initial program 11.4

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

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

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

      \[\leadsto \color{blue}{{\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}^{1}} \cdot {\left(\frac{1}{2 \cdot a}\right)}^{1}\]
    7. Applied pow-prod-down11.5

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

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

    if 1.6414783348607511e+125 < b

    1. Initial program 53.5

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

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

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

      \[\leadsto \color{blue}{{\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}^{1}} \cdot {\left(\frac{1}{2 \cdot a}\right)}^{1}\]
    7. Applied pow-prod-down53.5

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

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

      \[\leadsto {\color{blue}{\left(1 \cdot \frac{c}{b} - 1 \cdot \frac{b}{a}\right)}}^{1}\]
    10. Simplified2.6

      \[\leadsto {\color{blue}{\left(1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\right)}}^{1}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification10.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -8.8665312552031243 \cdot 10^{65}:\\ \;\;\;\;{\left(-1 \cdot \frac{c}{b}\right)}^{1}\\ \mathbf{elif}\;b \le -1519208.93058992573:\\ \;\;\;\;\frac{0 + 1 \cdot \left(4 \cdot \left(a \cdot c\right)\right)}{\left(\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right) \cdot \left(2 \cdot a\right)}\\ \mathbf{elif}\;b \le -2.3901106171036543 \cdot 10^{-123}:\\ \;\;\;\;{\left(-1 \cdot \frac{c}{b}\right)}^{1}\\ \mathbf{elif}\;b \le 1.6414783348607511 \cdot 10^{125}:\\ \;\;\;\;{\left(\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\right)}^{1}\\ \mathbf{else}:\\ \;\;\;\;{\left(1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\right)}^{1}\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))

  (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))