Average Error: 34.4 → 9.7
Time: 6.7s
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 -8.40319311655512752 \cdot 10^{80}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.3018033153892369 \cdot 10^{-62}:\\ \;\;\;\;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 \frac{c}{b}\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 -8.40319311655512752 \cdot 10^{80}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

\mathbf{elif}\;b \le 1.3018033153892369 \cdot 10^{-62}:\\
\;\;\;\;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 \frac{c}{b}\right)\\

\end{array}
double code(double a, double b, double c) {
	return ((double) (((double) (((double) -(b)) + ((double) sqrt(((double) (((double) (b * b)) - ((double) (4.0 * ((double) (a * c)))))))))) / ((double) (2.0 * a))));
}
double code(double a, double b, double c) {
	double VAR;
	if ((b <= -8.403193116555128e+80)) {
		VAR = ((double) (1.0 * ((double) (((double) (c / b)) - ((double) (b / a))))));
	} else {
		double VAR_1;
		if ((b <= 1.301803315389237e-62)) {
			VAR_1 = ((double) (1.0 * ((double) (((double) (((double) -(b)) + ((double) sqrt(((double) (((double) (b * b)) - ((double) (4.0 * ((double) (a * c)))))))))) / ((double) (2.0 * a))))));
		} else {
			VAR_1 = ((double) (1.0 * ((double) (-1.0 * ((double) (c / b))))));
		}
		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.4
Target21.1
Herbie9.7
\[\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 3 regimes
  2. if b < -8.403193116555128e+80

    1. Initial program 43.0

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

    if -8.403193116555128e+80 < b < 1.301803315389237e-62

    1. Initial program 13.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 *-un-lft-identity13.5

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

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

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

      \[\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.301803315389237e-62 < b

    1. Initial program 54.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-identity54.0

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\color{blue}{1 \cdot \left(2 \cdot a\right)}}\]
    4. Applied *-un-lft-identity54.0

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -8.40319311655512752 \cdot 10^{80}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.3018033153892369 \cdot 10^{-62}:\\ \;\;\;\;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 \frac{c}{b}\right)\\ \end{array}\]

Reproduce

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