Average Error: 33.1 → 6.6
Time: 44.7s
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 -2.1884247920746475 \cdot 10^{+101}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le -1.6086609448752587 \cdot 10^{-299}:\\ \;\;\;\;\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} \cdot \frac{1}{a \cdot 2} - \frac{b}{a \cdot 2}\\ \mathbf{elif}\;b \le 9.34348145460108 \cdot 10^{+88}:\\ \;\;\;\;\frac{1}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b} \cdot \left(c \cdot -2\right)\\ \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 -2.1884247920746475 \cdot 10^{+101}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r17627045 = b;
        double r17627046 = -r17627045;
        double r17627047 = r17627045 * r17627045;
        double r17627048 = 4.0;
        double r17627049 = a;
        double r17627050 = r17627048 * r17627049;
        double r17627051 = c;
        double r17627052 = r17627050 * r17627051;
        double r17627053 = r17627047 - r17627052;
        double r17627054 = sqrt(r17627053);
        double r17627055 = r17627046 + r17627054;
        double r17627056 = 2.0;
        double r17627057 = r17627056 * r17627049;
        double r17627058 = r17627055 / r17627057;
        return r17627058;
}

double f(double a, double b, double c) {
        double r17627059 = b;
        double r17627060 = -2.1884247920746475e+101;
        bool r17627061 = r17627059 <= r17627060;
        double r17627062 = c;
        double r17627063 = r17627062 / r17627059;
        double r17627064 = a;
        double r17627065 = r17627059 / r17627064;
        double r17627066 = r17627063 - r17627065;
        double r17627067 = -1.6086609448752587e-299;
        bool r17627068 = r17627059 <= r17627067;
        double r17627069 = r17627059 * r17627059;
        double r17627070 = r17627062 * r17627064;
        double r17627071 = 4.0;
        double r17627072 = r17627070 * r17627071;
        double r17627073 = r17627069 - r17627072;
        double r17627074 = sqrt(r17627073);
        double r17627075 = 1.0;
        double r17627076 = 2.0;
        double r17627077 = r17627064 * r17627076;
        double r17627078 = r17627075 / r17627077;
        double r17627079 = r17627074 * r17627078;
        double r17627080 = r17627059 / r17627077;
        double r17627081 = r17627079 - r17627080;
        double r17627082 = 9.34348145460108e+88;
        bool r17627083 = r17627059 <= r17627082;
        double r17627084 = r17627074 + r17627059;
        double r17627085 = r17627075 / r17627084;
        double r17627086 = -2.0;
        double r17627087 = r17627062 * r17627086;
        double r17627088 = r17627085 * r17627087;
        double r17627089 = -r17627062;
        double r17627090 = r17627089 / r17627059;
        double r17627091 = r17627083 ? r17627088 : r17627090;
        double r17627092 = r17627068 ? r17627081 : r17627091;
        double r17627093 = r17627061 ? r17627066 : r17627092;
        return r17627093;
}

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.3
Herbie6.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 4 regimes
  2. if b < -2.1884247920746475e+101

    1. Initial program 44.5

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

      \[\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-sub44.5

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

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

    if -2.1884247920746475e+101 < b < -1.6086609448752587e-299

    1. Initial program 8.7

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

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

      \[\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 div-inv8.8

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

    if -1.6086609448752587e-299 < b < 9.34348145460108e+88

    1. Initial program 31.3

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

      \[\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 *-un-lft-identity31.3

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

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

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

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

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

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

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

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

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

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

    if 9.34348145460108e+88 < b

    1. Initial program 57.8

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    6. Simplified2.8

      \[\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 -2.1884247920746475 \cdot 10^{+101}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le -1.6086609448752587 \cdot 10^{-299}:\\ \;\;\;\;\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} \cdot \frac{1}{a \cdot 2} - \frac{b}{a \cdot 2}\\ \mathbf{elif}\;b \le 9.34348145460108 \cdot 10^{+88}:\\ \;\;\;\;\frac{1}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b} \cdot \left(c \cdot -2\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\]

Reproduce

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