Average Error: 34.3 → 6.5
Time: 6.3s
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 -7.6038168240882645 \cdot 10^{144}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -3.2731438419880699 \cdot 10^{-203}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \mathbf{elif}\;b \le 2.1125387673008883 \cdot 10^{122}:\\ \;\;\;\;\frac{\frac{\frac{1}{\frac{2}{4}}}{\frac{1}{c}}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \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 -7.6038168240882645 \cdot 10^{144}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r96675 = b;
        double r96676 = -r96675;
        double r96677 = r96675 * r96675;
        double r96678 = 4.0;
        double r96679 = a;
        double r96680 = r96678 * r96679;
        double r96681 = c;
        double r96682 = r96680 * r96681;
        double r96683 = r96677 - r96682;
        double r96684 = sqrt(r96683);
        double r96685 = r96676 + r96684;
        double r96686 = 2.0;
        double r96687 = r96686 * r96679;
        double r96688 = r96685 / r96687;
        return r96688;
}

double f(double a, double b, double c) {
        double r96689 = b;
        double r96690 = -7.603816824088264e+144;
        bool r96691 = r96689 <= r96690;
        double r96692 = 1.0;
        double r96693 = c;
        double r96694 = r96693 / r96689;
        double r96695 = a;
        double r96696 = r96689 / r96695;
        double r96697 = r96694 - r96696;
        double r96698 = r96692 * r96697;
        double r96699 = -3.27314384198807e-203;
        bool r96700 = r96689 <= r96699;
        double r96701 = -r96689;
        double r96702 = r96689 * r96689;
        double r96703 = 4.0;
        double r96704 = r96703 * r96695;
        double r96705 = r96704 * r96693;
        double r96706 = r96702 - r96705;
        double r96707 = sqrt(r96706);
        double r96708 = sqrt(r96707);
        double r96709 = r96708 * r96708;
        double r96710 = r96701 + r96709;
        double r96711 = 2.0;
        double r96712 = r96711 * r96695;
        double r96713 = r96710 / r96712;
        double r96714 = 2.1125387673008883e+122;
        bool r96715 = r96689 <= r96714;
        double r96716 = 1.0;
        double r96717 = r96711 / r96703;
        double r96718 = r96716 / r96717;
        double r96719 = r96716 / r96693;
        double r96720 = r96718 / r96719;
        double r96721 = r96701 - r96707;
        double r96722 = r96720 / r96721;
        double r96723 = -1.0;
        double r96724 = r96723 * r96694;
        double r96725 = r96715 ? r96722 : r96724;
        double r96726 = r96700 ? r96713 : r96725;
        double r96727 = r96691 ? r96698 : r96726;
        return r96727;
}

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
Herbie6.5
\[\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 < -7.603816824088264e+144

    1. Initial program 61.2

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

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

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

    if -7.603816824088264e+144 < b < -3.27314384198807e-203

    1. Initial program 7.1

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt7.1

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

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

    if -3.27314384198807e-203 < b < 2.1125387673008883e+122

    1. Initial program 29.8

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{\frac{2 \cdot a}{4 \cdot \left(a \cdot c\right)} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}\]
    8. Using strategy rm
    9. Applied associate-/r*15.3

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

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

    if 2.1125387673008883e+122 < b

    1. Initial program 61.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -7.6038168240882645 \cdot 10^{144}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -3.2731438419880699 \cdot 10^{-203}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \mathbf{elif}\;b \le 2.1125387673008883 \cdot 10^{122}:\\ \;\;\;\;\frac{\frac{\frac{1}{\frac{2}{4}}}{\frac{1}{c}}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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