Average Error: 33.6 → 6.5
Time: 9.8s
Precision: binary64
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \leq -2.986384134100874 \cdot 10^{+125}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq -1.9251932428213444 \cdot 10^{-304}:\\ \;\;\;\;-0.5 \cdot \frac{4}{\frac{b - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{c}}\\ \mathbf{elif}\;b \leq 3.346781742900937 \cdot 10^{+117}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{b + 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 \leq -2.986384134100874 \cdot 10^{+125}:\\
\;\;\;\;-\frac{c}{b}\\

\mathbf{elif}\;b \leq -1.9251932428213444 \cdot 10^{-304}:\\
\;\;\;\;-0.5 \cdot \frac{4}{\frac{b - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{c}}\\

\mathbf{elif}\;b \leq 3.346781742900937 \cdot 10^{+117}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\

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

\end{array}
(FPCore (a b c)
 :precision binary64
 (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
(FPCore (a b c)
 :precision binary64
 (if (<= b -2.986384134100874e+125)
   (- (/ c b))
   (if (<= b -1.9251932428213444e-304)
     (* -0.5 (/ 4.0 (/ (- b (sqrt (- (* b b) (* 4.0 (* c a))))) c)))
     (if (<= b 3.346781742900937e+117)
       (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
       (* -0.5 (/ (+ b b) a))))))
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 tmp;
	if (b <= -2.986384134100874e+125) {
		tmp = -(c / b);
	} else if (b <= -1.9251932428213444e-304) {
		tmp = -0.5 * (4.0 / ((b - sqrt((b * b) - (4.0 * (c * a)))) / c));
	} else if (b <= 3.346781742900937e+117) {
		tmp = (-b - sqrt((b * b) - (4.0 * (c * a)))) / (a * 2.0);
	} else {
		tmp = -0.5 * ((b + b) / a);
	}
	return tmp;
}

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.6
Target20.0
Herbie6.5
\[\begin{array}{l} \mathbf{if}\;b < 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.9863841341008739e125

    1. Initial program 60.9

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{b + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a}}\]
    3. Taylor expanded around -inf 2.1

      \[\leadsto -0.5 \cdot \color{blue}{\left(2 \cdot \frac{c}{b}\right)}\]
    4. Taylor expanded around 0 2.1

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

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

    if -2.9863841341008739e125 < b < -1.9251932428213444e-304

    1. Initial program 33.1

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{b + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a}}\]
    3. Using strategy rm
    4. Applied flip-+_binary64_73433.1

      \[\leadsto -0.5 \cdot \frac{\color{blue}{\frac{b \cdot b - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} \cdot \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{b - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}{a}\]
    5. Simplified15.3

      \[\leadsto -0.5 \cdot \frac{\frac{\color{blue}{4 \cdot \left(a \cdot c\right)}}{b - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}{a}\]
    6. Using strategy rm
    7. Applied *-un-lft-identity_binary64_76015.3

      \[\leadsto -0.5 \cdot \frac{\frac{4 \cdot \left(a \cdot c\right)}{b - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}{\color{blue}{1 \cdot a}}\]
    8. Applied *-un-lft-identity_binary64_76015.3

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

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

      \[\leadsto -0.5 \cdot \left(\color{blue}{1} \cdot \frac{\frac{4 \cdot \left(a \cdot c\right)}{b - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}{a}\right)\]
    11. Simplified7.6

      \[\leadsto -0.5 \cdot \left(1 \cdot \color{blue}{\frac{4}{1 \cdot \frac{b - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{c}}}\right)\]
    12. Using strategy rm
    13. Applied associate-/r*_binary64_7047.6

      \[\leadsto -0.5 \cdot \left(1 \cdot \color{blue}{\frac{\frac{4}{1}}{\frac{b - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{c}}}\right)\]
    14. Simplified7.6

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

    if -1.9251932428213444e-304 < b < 3.3467817429009369e117

    1. Initial program 9.1

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

    if 3.3467817429009369e117 < b

    1. Initial program 52.0

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{b + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a}}\]
    3. Taylor expanded around inf 3.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -2.986384134100874 \cdot 10^{+125}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq -1.9251932428213444 \cdot 10^{-304}:\\ \;\;\;\;-0.5 \cdot \frac{4}{\frac{b - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{c}}\\ \mathbf{elif}\;b \leq 3.346781742900937 \cdot 10^{+117}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{b + b}{a}\\ \end{array}\]

Reproduce

herbie shell --seed 2021032 
(FPCore (a b c)
  :name "quadm (p42, negative)"
  :precision binary64

  :herbie-target
  (if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))

  (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))