Average Error: 32.9 → 10.6
Time: 25.8s
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 -6.1701110130378705 \cdot 10^{+68}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 1.4352467544377554 \cdot 10^{-114}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}} - \frac{b}{a \cdot 2}\\ \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 -6.1701110130378705 \cdot 10^{+68}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r2671127 = b;
        double r2671128 = -r2671127;
        double r2671129 = r2671127 * r2671127;
        double r2671130 = 4.0;
        double r2671131 = a;
        double r2671132 = r2671130 * r2671131;
        double r2671133 = c;
        double r2671134 = r2671132 * r2671133;
        double r2671135 = r2671129 - r2671134;
        double r2671136 = sqrt(r2671135);
        double r2671137 = r2671128 + r2671136;
        double r2671138 = 2.0;
        double r2671139 = r2671138 * r2671131;
        double r2671140 = r2671137 / r2671139;
        return r2671140;
}

double f(double a, double b, double c) {
        double r2671141 = b;
        double r2671142 = -6.1701110130378705e+68;
        bool r2671143 = r2671141 <= r2671142;
        double r2671144 = c;
        double r2671145 = r2671144 / r2671141;
        double r2671146 = a;
        double r2671147 = r2671141 / r2671146;
        double r2671148 = r2671145 - r2671147;
        double r2671149 = 1.4352467544377554e-114;
        bool r2671150 = r2671141 <= r2671149;
        double r2671151 = 1.0;
        double r2671152 = 2.0;
        double r2671153 = r2671146 * r2671152;
        double r2671154 = r2671141 * r2671141;
        double r2671155 = 4.0;
        double r2671156 = r2671144 * r2671146;
        double r2671157 = r2671155 * r2671156;
        double r2671158 = r2671154 - r2671157;
        double r2671159 = sqrt(r2671158);
        double r2671160 = r2671153 / r2671159;
        double r2671161 = r2671151 / r2671160;
        double r2671162 = r2671141 / r2671153;
        double r2671163 = r2671161 - r2671162;
        double r2671164 = -r2671145;
        double r2671165 = r2671150 ? r2671163 : r2671164;
        double r2671166 = r2671143 ? r2671148 : r2671165;
        return r2671166;
}

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

Original32.9
Target20.2
Herbie10.6
\[\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 3 regimes
  2. if b < -6.1701110130378705e+68

    1. Initial program 38.1

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

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

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

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

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

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

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

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

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

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

    if -6.1701110130378705e+68 < b < 1.4352467544377554e-114

    1. Initial program 12.0

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied div-sub12.0

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

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

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

    if 1.4352467544377554e-114 < b

    1. Initial program 50.9

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    14. Simplified11.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -6.1701110130378705 \cdot 10^{+68}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 1.4352467544377554 \cdot 10^{-114}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}} - \frac{b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

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