Average Error: 34.1 → 9.5
Time: 18.3s
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 -4.356959927988237168348139414849710212524 \cdot 10^{-56}:\\ \;\;\;\;\frac{c}{b} \cdot -1\\ \mathbf{elif}\;b \le 3.087668654677018032633364446323411964642 \cdot 10^{130}:\\ \;\;\;\;\left(\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}\right) \cdot \frac{\frac{1}{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 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 -4.356959927988237168348139414849710212524 \cdot 10^{-56}:\\
\;\;\;\;\frac{c}{b} \cdot -1\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r58454 = b;
        double r58455 = -r58454;
        double r58456 = r58454 * r58454;
        double r58457 = 4.0;
        double r58458 = a;
        double r58459 = c;
        double r58460 = r58458 * r58459;
        double r58461 = r58457 * r58460;
        double r58462 = r58456 - r58461;
        double r58463 = sqrt(r58462);
        double r58464 = r58455 - r58463;
        double r58465 = 2.0;
        double r58466 = r58465 * r58458;
        double r58467 = r58464 / r58466;
        return r58467;
}

double f(double a, double b, double c) {
        double r58468 = b;
        double r58469 = -4.356959927988237e-56;
        bool r58470 = r58468 <= r58469;
        double r58471 = c;
        double r58472 = r58471 / r58468;
        double r58473 = -1.0;
        double r58474 = r58472 * r58473;
        double r58475 = 3.087668654677018e+130;
        bool r58476 = r58468 <= r58475;
        double r58477 = -r58468;
        double r58478 = r58468 * r58468;
        double r58479 = 4.0;
        double r58480 = a;
        double r58481 = r58479 * r58480;
        double r58482 = r58471 * r58481;
        double r58483 = r58478 - r58482;
        double r58484 = sqrt(r58483);
        double r58485 = r58477 - r58484;
        double r58486 = 1.0;
        double r58487 = r58486 / r58480;
        double r58488 = 2.0;
        double r58489 = r58487 / r58488;
        double r58490 = r58485 * r58489;
        double r58491 = r58468 / r58480;
        double r58492 = r58472 - r58491;
        double r58493 = 1.0;
        double r58494 = r58492 * r58493;
        double r58495 = r58476 ? r58490 : r58494;
        double r58496 = r58470 ? r58474 : r58495;
        return r58496;
}

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.1
Herbie9.5
\[\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 3 regimes
  2. if b < -4.356959927988237e-56

    1. Initial program 54.0

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied associate-*r*54.0

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

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

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

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

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

    if -4.356959927988237e-56 < b < 3.087668654677018e+130

    1. Initial program 12.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 associate-*r*12.6

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

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

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

    if 3.087668654677018e+130 < b

    1. Initial program 56.2

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied associate-*r*56.2

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -4.356959927988237168348139414849710212524 \cdot 10^{-56}:\\ \;\;\;\;\frac{c}{b} \cdot -1\\ \mathbf{elif}\;b \le 3.087668654677018032633364446323411964642 \cdot 10^{130}:\\ \;\;\;\;\left(\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}\right) \cdot \frac{\frac{1}{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\ \end{array}\]

Reproduce

herbie shell --seed 2019174 +o rules:numerics
(FPCore (a b c)
  :name "The quadratic formula (r2)"

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

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