Average Error: 33.8 → 9.4
Time: 16.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 -3.56950087216670373 \cdot 10^{75}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.4951704352063921 \cdot 10^{-301}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}\\ \mathbf{elif}\;b \le 2.12540180880083329 \cdot 10^{133}:\\ \;\;\;\;\frac{\frac{\left(4 \cdot a\right) \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot 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 -3.56950087216670373 \cdot 10^{75}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r61019 = b;
        double r61020 = -r61019;
        double r61021 = r61019 * r61019;
        double r61022 = 4.0;
        double r61023 = a;
        double r61024 = r61022 * r61023;
        double r61025 = c;
        double r61026 = r61024 * r61025;
        double r61027 = r61021 - r61026;
        double r61028 = sqrt(r61027);
        double r61029 = r61020 + r61028;
        double r61030 = 2.0;
        double r61031 = r61030 * r61023;
        double r61032 = r61029 / r61031;
        return r61032;
}

double f(double a, double b, double c) {
        double r61033 = b;
        double r61034 = -3.5695008721667037e+75;
        bool r61035 = r61033 <= r61034;
        double r61036 = 1.0;
        double r61037 = c;
        double r61038 = r61037 / r61033;
        double r61039 = a;
        double r61040 = r61033 / r61039;
        double r61041 = r61038 - r61040;
        double r61042 = r61036 * r61041;
        double r61043 = 1.495170435206392e-301;
        bool r61044 = r61033 <= r61043;
        double r61045 = 1.0;
        double r61046 = 2.0;
        double r61047 = r61046 * r61039;
        double r61048 = r61033 * r61033;
        double r61049 = 4.0;
        double r61050 = r61049 * r61039;
        double r61051 = r61050 * r61037;
        double r61052 = r61048 - r61051;
        double r61053 = sqrt(r61052);
        double r61054 = r61053 - r61033;
        double r61055 = r61047 / r61054;
        double r61056 = r61045 / r61055;
        double r61057 = 2.1254018088008333e+133;
        bool r61058 = r61033 <= r61057;
        double r61059 = -r61033;
        double r61060 = r61059 - r61053;
        double r61061 = r61051 / r61060;
        double r61062 = r61061 / r61047;
        double r61063 = -1.0;
        double r61064 = r61063 * r61038;
        double r61065 = r61058 ? r61062 : r61064;
        double r61066 = r61044 ? r61056 : r61065;
        double r61067 = r61035 ? r61042 : r61066;
        return r61067;
}

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.8
Target21.2
Herbie9.4
\[\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 < -3.5695008721667037e+75

    1. Initial program 42.1

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Taylor expanded around -inf 4.0

      \[\leadsto \color{blue}{1 \cdot \frac{c}{b} - 1 \cdot \frac{b}{a}}\]
    3. Simplified4.0

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

    if -3.5695008721667037e+75 < b < 1.495170435206392e-301

    1. Initial program 9.4

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

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

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

    if 1.495170435206392e-301 < b < 2.1254018088008333e+133

    1. Initial program 33.6

      \[\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-+33.6

      \[\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. Simplified16.6

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

    if 2.1254018088008333e+133 < b

    1. Initial program 61.9

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Taylor expanded around inf 1.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -3.56950087216670373 \cdot 10^{75}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.4951704352063921 \cdot 10^{-301}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}\\ \mathbf{elif}\;b \le 2.12540180880083329 \cdot 10^{133}:\\ \;\;\;\;\frac{\frac{\left(4 \cdot a\right) \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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

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

  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))