Average Error: 34.6 → 10.7
Time: 31.6s
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.766818940874854722177248139872145176232 \cdot 10^{100}:\\ \;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\ \mathbf{elif}\;b \le 7.923524897992036987166355557663274472861 \cdot 10^{-153}:\\ \;\;\;\;\frac{\frac{1}{a \cdot 2}}{\frac{1}{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -1\\ \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.766818940874854722177248139872145176232 \cdot 10^{100}:\\
\;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r5408604 = b;
        double r5408605 = -r5408604;
        double r5408606 = r5408604 * r5408604;
        double r5408607 = 4.0;
        double r5408608 = a;
        double r5408609 = r5408607 * r5408608;
        double r5408610 = c;
        double r5408611 = r5408609 * r5408610;
        double r5408612 = r5408606 - r5408611;
        double r5408613 = sqrt(r5408612);
        double r5408614 = r5408605 + r5408613;
        double r5408615 = 2.0;
        double r5408616 = r5408615 * r5408608;
        double r5408617 = r5408614 / r5408616;
        return r5408617;
}

double f(double a, double b, double c) {
        double r5408618 = b;
        double r5408619 = -2.7668189408748547e+100;
        bool r5408620 = r5408618 <= r5408619;
        double r5408621 = c;
        double r5408622 = r5408621 / r5408618;
        double r5408623 = a;
        double r5408624 = r5408618 / r5408623;
        double r5408625 = r5408622 - r5408624;
        double r5408626 = 1.0;
        double r5408627 = r5408625 * r5408626;
        double r5408628 = 7.923524897992037e-153;
        bool r5408629 = r5408618 <= r5408628;
        double r5408630 = 1.0;
        double r5408631 = 2.0;
        double r5408632 = r5408623 * r5408631;
        double r5408633 = r5408630 / r5408632;
        double r5408634 = r5408618 * r5408618;
        double r5408635 = 4.0;
        double r5408636 = r5408623 * r5408635;
        double r5408637 = r5408636 * r5408621;
        double r5408638 = r5408634 - r5408637;
        double r5408639 = sqrt(r5408638);
        double r5408640 = r5408639 - r5408618;
        double r5408641 = r5408630 / r5408640;
        double r5408642 = r5408633 / r5408641;
        double r5408643 = -1.0;
        double r5408644 = r5408622 * r5408643;
        double r5408645 = r5408629 ? r5408642 : r5408644;
        double r5408646 = r5408620 ? r5408627 : r5408645;
        return r5408646;
}

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.6
Target21.1
Herbie10.7
\[\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 3 regimes
  2. if b < -2.7668189408748547e+100

    1. Initial program 47.2

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

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

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

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

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

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

    if -2.7668189408748547e+100 < b < 7.923524897992037e-153

    1. Initial program 10.8

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

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

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

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

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

      \[\leadsto \frac{\sqrt{\color{blue}{b \cdot b - c \cdot \left(4 \cdot a\right)}} - b}{2 \cdot a}\]
    7. Using strategy rm
    8. Applied clear-num11.0

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

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

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

    if 7.923524897992037e-153 < b

    1. Initial program 50.5

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

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

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

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

Reproduce

herbie shell --seed 2019200 +o rules:numerics
(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)))