Average Error: 33.5 → 11.9
Time: 29.0s
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.3725796156555912 \cdot 10^{+127}:\\ \;\;\;\;\frac{\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 2}{2}\\ \mathbf{elif}\;b \le 3.207624111695675 \cdot 10^{-187}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a} - \frac{b}{a}}{2}\\ \mathbf{elif}\;b \le 4.664677641347216 \cdot 10^{-111}:\\ \;\;\;\;\frac{-2 \cdot \frac{c}{b}}{2}\\ \mathbf{elif}\;b \le 1.922674299151799 \cdot 10^{-16}:\\ \;\;\;\;\frac{\frac{\frac{b \cdot b - \left(\left(4 \cdot a\right) \cdot c + b \cdot b\right)}{a}}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} + b}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2 \cdot \frac{c}{b}}{2}\\ \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.3725796156555912 \cdot 10^{+127}:\\
\;\;\;\;\frac{\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 2}{2}\\

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

\mathbf{elif}\;b \le 4.664677641347216 \cdot 10^{-111}:\\
\;\;\;\;\frac{-2 \cdot \frac{c}{b}}{2}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r2384074 = b;
        double r2384075 = -r2384074;
        double r2384076 = r2384074 * r2384074;
        double r2384077 = 4.0;
        double r2384078 = a;
        double r2384079 = r2384077 * r2384078;
        double r2384080 = c;
        double r2384081 = r2384079 * r2384080;
        double r2384082 = r2384076 - r2384081;
        double r2384083 = sqrt(r2384082);
        double r2384084 = r2384075 + r2384083;
        double r2384085 = 2.0;
        double r2384086 = r2384085 * r2384078;
        double r2384087 = r2384084 / r2384086;
        return r2384087;
}

double f(double a, double b, double c) {
        double r2384088 = b;
        double r2384089 = -1.3725796156555912e+127;
        bool r2384090 = r2384088 <= r2384089;
        double r2384091 = c;
        double r2384092 = r2384091 / r2384088;
        double r2384093 = a;
        double r2384094 = r2384088 / r2384093;
        double r2384095 = r2384092 - r2384094;
        double r2384096 = 2.0;
        double r2384097 = r2384095 * r2384096;
        double r2384098 = r2384097 / r2384096;
        double r2384099 = 3.207624111695675e-187;
        bool r2384100 = r2384088 <= r2384099;
        double r2384101 = r2384088 * r2384088;
        double r2384102 = 4.0;
        double r2384103 = r2384093 * r2384091;
        double r2384104 = r2384102 * r2384103;
        double r2384105 = r2384101 - r2384104;
        double r2384106 = sqrt(r2384105);
        double r2384107 = r2384106 / r2384093;
        double r2384108 = r2384107 - r2384094;
        double r2384109 = r2384108 / r2384096;
        double r2384110 = 4.664677641347216e-111;
        bool r2384111 = r2384088 <= r2384110;
        double r2384112 = -2.0;
        double r2384113 = r2384112 * r2384092;
        double r2384114 = r2384113 / r2384096;
        double r2384115 = 1.922674299151799e-16;
        bool r2384116 = r2384088 <= r2384115;
        double r2384117 = r2384102 * r2384093;
        double r2384118 = r2384117 * r2384091;
        double r2384119 = r2384118 + r2384101;
        double r2384120 = r2384101 - r2384119;
        double r2384121 = r2384120 / r2384093;
        double r2384122 = r2384106 + r2384088;
        double r2384123 = r2384121 / r2384122;
        double r2384124 = r2384123 / r2384096;
        double r2384125 = r2384116 ? r2384124 : r2384114;
        double r2384126 = r2384111 ? r2384114 : r2384125;
        double r2384127 = r2384100 ? r2384109 : r2384126;
        double r2384128 = r2384090 ? r2384098 : r2384127;
        return r2384128;
}

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.5
Target21.2
Herbie11.9
\[\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.3725796156555912e+127

    1. Initial program 51.4

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

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

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

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

    if -1.3725796156555912e+127 < b < 3.207624111695675e-187

    1. Initial program 10.4

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

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

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

    if 3.207624111695675e-187 < b < 4.664677641347216e-111 or 1.922674299151799e-16 < b

    1. Initial program 50.1

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

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

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

    if 4.664677641347216e-111 < b < 1.922674299151799e-16

    1. Initial program 36.3

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\frac{\frac{1}{a}}{\frac{1}{\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}}}}}{2}\]
    13. Applied associate-/r/36.5

      \[\leadsto \frac{\frac{\frac{1}{a}}{\color{blue}{\frac{1}{\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)}}}{2}\]
    14. Applied associate-/r*36.5

      \[\leadsto \frac{\color{blue}{\frac{\frac{\frac{1}{a}}{\frac{1}{\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}}}{2}\]
    15. Simplified36.4

      \[\leadsto \frac{\frac{\color{blue}{\frac{b \cdot b - \left(c \cdot \left(a \cdot 4\right) + b \cdot b\right)}{a}}}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b}}{2}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification11.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.3725796156555912 \cdot 10^{+127}:\\ \;\;\;\;\frac{\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 2}{2}\\ \mathbf{elif}\;b \le 3.207624111695675 \cdot 10^{-187}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a} - \frac{b}{a}}{2}\\ \mathbf{elif}\;b \le 4.664677641347216 \cdot 10^{-111}:\\ \;\;\;\;\frac{-2 \cdot \frac{c}{b}}{2}\\ \mathbf{elif}\;b \le 1.922674299151799 \cdot 10^{-16}:\\ \;\;\;\;\frac{\frac{\frac{b \cdot b - \left(\left(4 \cdot a\right) \cdot c + b \cdot b\right)}{a}}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} + b}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2 \cdot \frac{c}{b}}{2}\\ \end{array}\]

Reproduce

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