Average Error: 34.2 → 6.4
Time: 4.5s
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.7863758169125638 \cdot 10^{138}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -4.96206905407944466 \cdot 10^{-170}:\\ \;\;\;\;\frac{1}{\frac{a}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b} \cdot 2}\\ \mathbf{elif}\;b \le 2.73926902980269393 \cdot 10^{102}:\\ \;\;\;\;\frac{1}{2} \cdot \left(1 \cdot \frac{c}{\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{4}}\right)\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \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.7863758169125638 \cdot 10^{138}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

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

\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 VAR;
	if ((b <= -2.7863758169125638e+138)) {
		VAR = (1.0 * ((c / b) - (b / a)));
	} else {
		double VAR_1;
		if ((b <= -4.962069054079445e-170)) {
			VAR_1 = (1.0 / ((a / (sqrt(((b * b) - (4.0 * (a * c)))) - b)) * 2.0));
		} else {
			double VAR_2;
			if ((b <= 2.739269029802694e+102)) {
				VAR_2 = ((1.0 / 2.0) * (1.0 * (c / ((-b - sqrt(((b * b) - (4.0 * (a * c))))) / 4.0))));
			} else {
				VAR_2 = (-1.0 * (c / b));
			}
			VAR_1 = VAR_2;
		}
		VAR = VAR_1;
	}
	return VAR;
}

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
Target20.9
Herbie6.4
\[\begin{array}{l} \mathbf{if}\;b \lt 0.0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \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.7863758169125638e+138

    1. Initial program 58.6

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

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

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

    if -2.7863758169125638e+138 < b < -4.962069054079445e-170

    1. Initial program 5.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-num5.4

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

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

    if -4.962069054079445e-170 < b < 2.739269029802694e+102

    1. Initial program 29.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 flip-+29.6

      \[\leadsto \frac{\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)}}}}{2 \cdot a}\]
    4. Simplified17.2

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

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

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

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

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

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

    if 2.739269029802694e+102 < b

    1. Initial program 60.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.7863758169125638 \cdot 10^{138}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -4.96206905407944466 \cdot 10^{-170}:\\ \;\;\;\;\frac{1}{\frac{a}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b} \cdot 2}\\ \mathbf{elif}\;b \le 2.73926902980269393 \cdot 10^{102}:\\ \;\;\;\;\frac{1}{2} \cdot \left(1 \cdot \frac{c}{\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{4}}\right)\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2020078 +o rules:numerics
(FPCore (a b c)
  :name "quadp (p42, positive)"
  :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)))