Average Error: 33.5 → 10.0
Time: 8.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 -1.478406535480561669630649836752919254545 \cdot 10^{60}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 2.175674080408202904737521150531781836244 \cdot 10^{-169}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{elif}\;b \le 3.705250296078930544323375298653357812472 \cdot 10^{-110} \lor \neg \left(b \le 29494967590524297216\right):\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\left(c \cdot 4\right) \cdot a}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \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.478406535480561669630649836752919254545 \cdot 10^{60}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

\mathbf{elif}\;b \le 3.705250296078930544323375298653357812472 \cdot 10^{-110} \lor \neg \left(b \le 29494967590524297216\right):\\
\;\;\;\;-1 \cdot \frac{c}{b}\\

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

\end{array}
double f(double a, double b, double c) {
        double r92618 = b;
        double r92619 = -r92618;
        double r92620 = r92618 * r92618;
        double r92621 = 4.0;
        double r92622 = a;
        double r92623 = r92621 * r92622;
        double r92624 = c;
        double r92625 = r92623 * r92624;
        double r92626 = r92620 - r92625;
        double r92627 = sqrt(r92626);
        double r92628 = r92619 + r92627;
        double r92629 = 2.0;
        double r92630 = r92629 * r92622;
        double r92631 = r92628 / r92630;
        return r92631;
}

double f(double a, double b, double c) {
        double r92632 = b;
        double r92633 = -1.4784065354805617e+60;
        bool r92634 = r92632 <= r92633;
        double r92635 = 1.0;
        double r92636 = c;
        double r92637 = r92636 / r92632;
        double r92638 = a;
        double r92639 = r92632 / r92638;
        double r92640 = r92637 - r92639;
        double r92641 = r92635 * r92640;
        double r92642 = 2.175674080408203e-169;
        bool r92643 = r92632 <= r92642;
        double r92644 = -r92632;
        double r92645 = r92632 * r92632;
        double r92646 = 4.0;
        double r92647 = r92646 * r92638;
        double r92648 = r92647 * r92636;
        double r92649 = r92645 - r92648;
        double r92650 = sqrt(r92649);
        double r92651 = r92644 + r92650;
        double r92652 = 2.0;
        double r92653 = r92652 * r92638;
        double r92654 = r92651 / r92653;
        double r92655 = 3.7052502960789305e-110;
        bool r92656 = r92632 <= r92655;
        double r92657 = 2.9494967590524297e+19;
        bool r92658 = r92632 <= r92657;
        double r92659 = !r92658;
        bool r92660 = r92656 || r92659;
        double r92661 = -1.0;
        double r92662 = r92661 * r92637;
        double r92663 = r92636 * r92646;
        double r92664 = r92663 * r92638;
        double r92665 = r92644 - r92650;
        double r92666 = r92664 / r92665;
        double r92667 = r92666 / r92653;
        double r92668 = r92660 ? r92662 : r92667;
        double r92669 = r92643 ? r92654 : r92668;
        double r92670 = r92634 ? r92641 : r92669;
        return r92670;
}

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
Target20.5
Herbie10.0
\[\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 < -1.4784065354805617e+60

    1. Initial program 39.0

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity39.0

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

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

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

    if -1.4784065354805617e+60 < b < 2.175674080408203e-169

    1. Initial program 10.7

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity10.7

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

    if 2.175674080408203e-169 < b < 3.7052502960789305e-110 or 2.9494967590524297e+19 < b

    1. Initial program 52.0

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity52.0

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

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

    if 3.7052502960789305e-110 < b < 2.9494967590524297e+19

    1. Initial program 37.3

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.478406535480561669630649836752919254545 \cdot 10^{60}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 2.175674080408202904737521150531781836244 \cdot 10^{-169}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{elif}\;b \le 3.705250296078930544323375298653357812472 \cdot 10^{-110} \lor \neg \left(b \le 29494967590524297216\right):\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\left(c \cdot 4\right) \cdot a}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< b 0.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)))