Average Error: 34.2 → 6.8
Time: 5.0s
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 -2.40284932349203652 \cdot 10^{128}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le 5.877669040907696 \cdot 10^{-167}:\\ \;\;\;\;{\left(\frac{2 \cdot c}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}\right)}^{1}\\ \mathbf{elif}\;b \le 1.58497213944565541 \cdot 10^{84}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\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 -2.40284932349203652 \cdot 10^{128}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\

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

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

\mathbf{else}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\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 <= -2.4028493234920365e+128)) {
		temp = (-1.0 * (c / b));
	} else {
		double temp_1;
		if ((b <= 5.877669040907696e-167)) {
			temp_1 = pow(((2.0 * c) / (sqrt(((b * b) - (4.0 * (a * c)))) - b)), 1.0);
		} else {
			double temp_2;
			if ((b <= 1.5849721394456554e+84)) {
				temp_2 = ((-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a));
			} else {
				temp_2 = (1.0 * ((c / b) - (b / a)));
			}
			temp_1 = temp_2;
		}
		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
Herbie6.8
\[\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 4 regimes
  2. if b < -2.4028493234920365e+128

    1. Initial program 61.5

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]

    if -2.4028493234920365e+128 < b < 5.877669040907696e-167

    1. Initial program 29.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 div-inv29.6

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

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

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

      \[\leadsto \frac{0 + 1 \cdot \left(4 \cdot \left(a \cdot c\right)\right)}{\color{blue}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}} \cdot \frac{1}{2 \cdot a}\]
    8. Using strategy rm
    9. Applied pow116.1

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

      \[\leadsto \color{blue}{{\left(\frac{0 + 1 \cdot \left(4 \cdot \left(a \cdot c\right)\right)}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}\right)}^{1}} \cdot {\left(\frac{1}{2 \cdot a}\right)}^{1}\]
    11. Applied pow-prod-down16.1

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

      \[\leadsto {\color{blue}{\left(\frac{\frac{4 \cdot \left(a \cdot c\right)}{2 \cdot a}}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}\right)}}^{1}\]
    13. Taylor expanded around 0 10.0

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

    if 5.877669040907696e-167 < b < 1.5849721394456554e+84

    1. Initial program 7.0

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

    if 1.5849721394456554e+84 < b

    1. Initial program 43.1

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

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

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

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

Reproduce

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