Average Error: 34.3 → 10.3
Time: 15.8s
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.006239684017339546564770304051967174461 \cdot 10^{118}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.892098135471955771557857083920836890719 \cdot 10^{-53}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{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 -1.006239684017339546564770304051967174461 \cdot 10^{118}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r101638 = b;
        double r101639 = -r101638;
        double r101640 = r101638 * r101638;
        double r101641 = 4.0;
        double r101642 = a;
        double r101643 = r101641 * r101642;
        double r101644 = c;
        double r101645 = r101643 * r101644;
        double r101646 = r101640 - r101645;
        double r101647 = sqrt(r101646);
        double r101648 = r101639 + r101647;
        double r101649 = 2.0;
        double r101650 = r101649 * r101642;
        double r101651 = r101648 / r101650;
        return r101651;
}

double f(double a, double b, double c) {
        double r101652 = b;
        double r101653 = -1.0062396840173395e+118;
        bool r101654 = r101652 <= r101653;
        double r101655 = 1.0;
        double r101656 = c;
        double r101657 = r101656 / r101652;
        double r101658 = a;
        double r101659 = r101652 / r101658;
        double r101660 = r101657 - r101659;
        double r101661 = r101655 * r101660;
        double r101662 = 1.8920981354719558e-53;
        bool r101663 = r101652 <= r101662;
        double r101664 = r101652 * r101652;
        double r101665 = 4.0;
        double r101666 = r101665 * r101658;
        double r101667 = r101666 * r101656;
        double r101668 = r101664 - r101667;
        double r101669 = sqrt(r101668);
        double r101670 = r101669 - r101652;
        double r101671 = 2.0;
        double r101672 = r101671 * r101658;
        double r101673 = r101670 / r101672;
        double r101674 = -1.0;
        double r101675 = r101674 * r101657;
        double r101676 = r101663 ? r101673 : r101675;
        double r101677 = r101654 ? r101661 : r101676;
        return r101677;
}

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.3
Target21.2
Herbie10.3
\[\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 < -1.0062396840173395e+118

    1. Initial program 52.3

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

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

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

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

    if -1.0062396840173395e+118 < b < 1.8920981354719558e-53

    1. Initial program 13.9

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

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} - \frac{b}{2 \cdot a}}\]
    5. Using strategy rm
    6. Applied sub-div13.9

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

    if 1.8920981354719558e-53 < b

    1. Initial program 54.0

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

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

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

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

Reproduce

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