Average Error: 34.5 → 9.6
Time: 36.4s
Precision: 64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4.0 \cdot a\right) \cdot c}}{2.0 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -2.3213399824345094 \cdot 10^{+149}:\\ \;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1.0\\ \mathbf{elif}\;b \le 1.1804820682342164 \cdot 10^{-93}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot 4.0\right) \cdot a} - b}{a \cdot 2.0}\\ \mathbf{else}:\\ \;\;\;\;-1.0 \cdot \frac{c}{b}\\ \end{array}\]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4.0 \cdot a\right) \cdot c}}{2.0 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \le -2.3213399824345094 \cdot 10^{+149}:\\
\;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1.0\\

\mathbf{elif}\;b \le 1.1804820682342164 \cdot 10^{-93}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot 4.0\right) \cdot a} - b}{a \cdot 2.0}\\

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

\end{array}
double f(double a, double b, double c) {
        double r4772709 = b;
        double r4772710 = -r4772709;
        double r4772711 = r4772709 * r4772709;
        double r4772712 = 4.0;
        double r4772713 = a;
        double r4772714 = r4772712 * r4772713;
        double r4772715 = c;
        double r4772716 = r4772714 * r4772715;
        double r4772717 = r4772711 - r4772716;
        double r4772718 = sqrt(r4772717);
        double r4772719 = r4772710 + r4772718;
        double r4772720 = 2.0;
        double r4772721 = r4772720 * r4772713;
        double r4772722 = r4772719 / r4772721;
        return r4772722;
}

double f(double a, double b, double c) {
        double r4772723 = b;
        double r4772724 = -2.3213399824345094e+149;
        bool r4772725 = r4772723 <= r4772724;
        double r4772726 = c;
        double r4772727 = r4772726 / r4772723;
        double r4772728 = a;
        double r4772729 = r4772723 / r4772728;
        double r4772730 = r4772727 - r4772729;
        double r4772731 = 1.0;
        double r4772732 = r4772730 * r4772731;
        double r4772733 = 1.1804820682342164e-93;
        bool r4772734 = r4772723 <= r4772733;
        double r4772735 = r4772723 * r4772723;
        double r4772736 = 4.0;
        double r4772737 = r4772726 * r4772736;
        double r4772738 = r4772737 * r4772728;
        double r4772739 = r4772735 - r4772738;
        double r4772740 = sqrt(r4772739);
        double r4772741 = r4772740 - r4772723;
        double r4772742 = 2.0;
        double r4772743 = r4772728 * r4772742;
        double r4772744 = r4772741 / r4772743;
        double r4772745 = -1.0;
        double r4772746 = r4772745 * r4772727;
        double r4772747 = r4772734 ? r4772744 : r4772746;
        double r4772748 = r4772725 ? r4772732 : r4772747;
        return r4772748;
}

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.5
Target20.9
Herbie9.6
\[\begin{array}{l} \mathbf{if}\;b \lt 0.0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4.0 \cdot a\right) \cdot c}}{2.0 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(4.0 \cdot a\right) \cdot c}}{2.0 \cdot a}}\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if b < -2.3213399824345094e+149

    1. Initial program 62.6

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

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

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

    if -2.3213399824345094e+149 < b < 1.1804820682342164e-93

    1. Initial program 11.6

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4.0 \cdot a\right) \cdot c}}{2.0 \cdot a}\]
    2. Using strategy rm
    3. Applied div-inv11.8

      \[\leadsto \color{blue}{\left(\left(-b\right) + \sqrt{b \cdot b - \left(4.0 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2.0 \cdot a}}\]
    4. Using strategy rm
    5. Applied associate-*r/11.6

      \[\leadsto \color{blue}{\frac{\left(\left(-b\right) + \sqrt{b \cdot b - \left(4.0 \cdot a\right) \cdot c}\right) \cdot 1}{2.0 \cdot a}}\]
    6. Simplified11.6

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

    if 1.1804820682342164e-93 < b

    1. Initial program 52.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.3213399824345094 \cdot 10^{+149}:\\ \;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1.0\\ \mathbf{elif}\;b \le 1.1804820682342164 \cdot 10^{-93}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot 4.0\right) \cdot a} - b}{a \cdot 2.0}\\ \mathbf{else}:\\ \;\;\;\;-1.0 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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