Average Error: 33.9 → 9.6
Time: 8.4s
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.049220194580872 \cdot 10^{+133}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_0 := 4 \cdot \left(c \cdot a\right)\\ t_1 := \sqrt{b \cdot b - t_0}\\ \mathbf{if}\;b \leq -2.2556714692887474 \cdot 10^{-119}:\\ \;\;\;\;\frac{t_0 \cdot \frac{0.5}{a}}{t_1 - b}\\ \mathbf{elif}\;b \leq 2.4148286761692006 \cdot 10^{+24}:\\ \;\;\;\;\frac{\left(-b\right) - t_1}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\\ \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.049220194580872 \cdot 10^{+133}:\\
\;\;\;\;-\frac{c}{b}\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_0 := 4 \cdot \left(c \cdot a\right)\\
t_1 := \sqrt{b \cdot b - t_0}\\
\mathbf{if}\;b \leq -2.2556714692887474 \cdot 10^{-119}:\\
\;\;\;\;\frac{t_0 \cdot \frac{0.5}{a}}{t_1 - b}\\

\mathbf{elif}\;b \leq 2.4148286761692006 \cdot 10^{+24}:\\
\;\;\;\;\frac{\left(-b\right) - t_1}{a \cdot 2}\\

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


\end{array}\\


\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.049220194580872e+133)
   (- (/ c b))
   (let* ((t_0 (* 4.0 (* c a))) (t_1 (sqrt (- (* b b) t_0))))
     (if (<= b -2.2556714692887474e-119)
       (/ (* t_0 (/ 0.5 a)) (- t_1 b))
       (if (<= b 2.4148286761692006e+24)
         (/ (- (- b) t_1) (* a 2.0))
         (/ (- 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.049220194580872e+133) {
		tmp = -(c / b);
	} else {
		double t_0 = 4.0 * (c * a);
		double t_1 = sqrt((b * b) - t_0);
		double tmp_1;
		if (b <= -2.2556714692887474e-119) {
			tmp_1 = (t_0 * (0.5 / a)) / (t_1 - b);
		} else if (b <= 2.4148286761692006e+24) {
			tmp_1 = (-b - t_1) / (a * 2.0);
		} else {
			tmp_1 = -b / a;
		}
		tmp = tmp_1;
	}
	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.9
Target21.2
Herbie9.6
\[\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.0492201945808721e133

    1. Initial program 62.3

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

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

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

    if -2.0492201945808721e133 < b < -2.2556714692887474e-119

    1. Initial program 40.4

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

      \[\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}} \]
    3. Simplified40.4

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

      \[\leadsto \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{0.5}{a} \]
    5. Applied associate-*l/_binary6440.5

      \[\leadsto \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{0.5}{a}}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}} \]
    6. Simplified12.9

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

    if -2.2556714692887474e-119 < b < 2.4148286761692006e24

    1. Initial program 13.4

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a} \]
    2. Applied *-un-lft-identity_binary6413.4

      \[\leadsto \frac{\left(-b\right) - \color{blue}{1 \cdot \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}{2 \cdot a} \]
    3. Applied cancel-sign-sub-inv_binary6413.4

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

    if 2.4148286761692006e24 < b

    1. Initial program 35.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -2.049220194580872 \cdot 10^{+133}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq -2.2556714692887474 \cdot 10^{-119}:\\ \;\;\;\;\frac{\left(4 \cdot \left(c \cdot a\right)\right) \cdot \frac{0.5}{a}}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}\\ \mathbf{elif}\;b \leq 2.4148286761692006 \cdot 10^{+24}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array} \]

Reproduce

herbie shell --seed 2022081 
(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)))