Average Error: 33.8 → 6.6
Time: 4.6s
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 -3.08129433547527851 \cdot 10^{156}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le 2.419240425439938 \cdot 10^{-264}:\\ \;\;\;\;\left(4 \cdot c\right) \cdot \frac{\frac{1}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}}{2}\\ \mathbf{elif}\;b \le 1.06732918955854865 \cdot 10^{103}:\\ \;\;\;\;\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{b}{a}\\ \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 -3.08129433547527851 \cdot 10^{156}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\

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

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

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

\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 <= -3.0812943354752785e+156)) {
		VAR = (-1.0 * (c / b));
	} else {
		double VAR_1;
		if ((b <= 2.4192404254399383e-264)) {
			VAR_1 = ((4.0 * c) * ((1.0 / (sqrt(((b * b) - (4.0 * (a * c)))) - b)) / 2.0));
		} else {
			double VAR_2;
			if ((b <= 1.0673291895585486e+103)) {
				VAR_2 = ((-b - sqrt(((b * b) - (4.0 * (a * c))))) * (1.0 / (2.0 * a)));
			} else {
				VAR_2 = (-1.0 * (b / a));
			}
			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

Original33.8
Target20.6
Herbie6.6
\[\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 < -3.0812943354752785e+156

    1. Initial program 64.0

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

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

    if -3.0812943354752785e+156 < b < 2.4192404254399383e-264

    1. Initial program 32.8

      \[\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--32.8

      \[\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. Simplified15.5

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

      \[\leadsto \frac{\frac{\mathsf{fma}\left(a, 4 \cdot c, 0\right)}{\color{blue}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}}}{2 \cdot a}\]
    6. Using strategy rm
    7. Applied *-commutative15.5

      \[\leadsto \frac{\frac{\mathsf{fma}\left(a, 4 \cdot c, 0\right)}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}}{\color{blue}{a \cdot 2}}\]
    8. Applied div-inv15.5

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(a, 4 \cdot c, 0\right) \cdot \frac{1}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}}}{a \cdot 2}\]
    9. Applied times-frac13.9

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, 4 \cdot c, 0\right)}{a} \cdot \frac{\frac{1}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}}{2}}\]
    10. Taylor expanded around 0 8.2

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

    if 2.4192404254399383e-264 < b < 1.0673291895585486e+103

    1. Initial program 9.0

      \[\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-inv9.1

      \[\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}}\]

    if 1.0673291895585486e+103 < b

    1. Initial program 47.7

      \[\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--63.4

      \[\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. Simplified62.5

      \[\leadsto \frac{\frac{\color{blue}{\mathsf{fma}\left(a, 4 \cdot c, 0\right)}}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}{2 \cdot a}\]
    5. Simplified62.5

      \[\leadsto \frac{\frac{\mathsf{fma}\left(a, 4 \cdot c, 0\right)}{\color{blue}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}}}{2 \cdot a}\]
    6. Using strategy rm
    7. Applied *-commutative62.5

      \[\leadsto \frac{\frac{\mathsf{fma}\left(a, 4 \cdot c, 0\right)}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}}{\color{blue}{a \cdot 2}}\]
    8. Applied div-inv62.5

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(a, 4 \cdot c, 0\right) \cdot \frac{1}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}}}{a \cdot 2}\]
    9. Applied times-frac62.5

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, 4 \cdot c, 0\right)}{a} \cdot \frac{\frac{1}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}}{2}}\]
    10. Taylor expanded around 0 62.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -3.08129433547527851 \cdot 10^{156}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le 2.419240425439938 \cdot 10^{-264}:\\ \;\;\;\;\left(4 \cdot c\right) \cdot \frac{\frac{1}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}}{2}\\ \mathbf{elif}\;b \le 1.06732918955854865 \cdot 10^{103}:\\ \;\;\;\;\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{b}{a}\\ \end{array}\]

Reproduce

herbie shell --seed 2020078 +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)))