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

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

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

\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 VAR;
	if ((b <= -3.0812943354752785e+156)) {
		VAR = (1.0 * (-1.0 * (c / b)));
	} else {
		double VAR_1;
		if ((b <= 1.6944972861664959e-264)) {
			VAR_1 = (1.0 * ((2.0 * c) / (-b + sqrt(((b * b) - (4.0 * (a * c)))))));
		} else {
			double VAR_2;
			if ((b <= 1.0673291895585486e+103)) {
				VAR_2 = (1.0 * ((-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)));
			} else {
				VAR_2 = (1.0 * (1.0 * ((c / b) - (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.4
\[\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. Using strategy rm
    3. Applied *-un-lft-identity64.0

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

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

    if -3.0812943354752785e+156 < b < 1.6944972861664959e-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 *-un-lft-identity32.8

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

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

      \[\leadsto 1 \cdot \left(\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}\right)\]
    8. Applied associate-*l/32.9

      \[\leadsto 1 \cdot \color{blue}{\frac{\left(\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)}\right) \cdot \frac{1}{2 \cdot a}}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}\]
    9. Simplified13.9

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

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

    if 1.6944972861664959e-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 *-un-lft-identity9.0

      \[\leadsto \color{blue}{1 \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{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 *-un-lft-identity47.7

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

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

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

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

Reproduce

herbie shell --seed 2020078 
(FPCore (a b c)
  :name "The quadratic formula (r2)"
  :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)))