Average Error: 34.2 → 10.5
Time: 5.4s
Precision: 64
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -4.4270058556435274 \cdot 10^{-117}:\\ \;\;\;\;1 \cdot \left(-1 \cdot \frac{c}{b}\right)\\ \mathbf{elif}\;b \le 2.49922826628406174 \cdot 10^{84}:\\ \;\;\;\;1 \cdot \frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\right)\\ \end{array}\]
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \le -4.4270058556435274 \cdot 10^{-117}:\\
\;\;\;\;1 \cdot \left(-1 \cdot \frac{c}{b}\right)\\

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

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

\end{array}
double code(double a, double b, double c) {
	return ((-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a));
}
double code(double a, double b, double c) {
	double temp;
	if ((b <= -4.4270058556435274e-117)) {
		temp = (1.0 * (-1.0 * (c / b)));
	} else {
		double temp_1;
		if ((b <= 2.4992282662840617e+84)) {
			temp_1 = (1.0 * (1.0 / ((2.0 * a) / (-b - sqrt(((b * b) - (4.0 * (a * c))))))));
		} else {
			temp_1 = (1.0 * (1.0 * ((c / b) - (b / a))));
		}
		temp = temp_1;
	}
	return temp;
}

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.2
Target21.2
Herbie10.5
\[\begin{array}{l} \mathbf{if}\;b \lt 0.0:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if b < -4.4270058556435274e-117

    1. Initial program 51.5

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied clear-num51.5

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity51.5

      \[\leadsto \frac{1}{\color{blue}{1 \cdot \frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}\]
    6. Applied add-cube-cbrt51.5

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{1 \cdot \frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}\]
    7. Applied times-frac51.5

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

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

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

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

    if -4.4270058556435274e-117 < b < 2.4992282662840617e+84

    1. Initial program 12.4

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied clear-num12.5

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity12.5

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

    if 2.4992282662840617e+84 < b

    1. Initial program 43.2

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied clear-num43.2

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity43.2

      \[\leadsto \frac{1}{\color{blue}{1 \cdot \frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}\]
    6. Applied add-cube-cbrt43.2

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{1 \cdot \frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}\]
    7. Applied times-frac43.2

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

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

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

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

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

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

Reproduce

herbie shell --seed 2020056 +o rules:numerics
(FPCore (a b c)
  :name "quadm (p42, negative)"
  :precision binary64

  :herbie-target
  (if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))

  (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))