Average Error: 34.7 → 7.6
Time: 5.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.2136550152753833 \cdot 10^{+95}:\\ \;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\ \mathbf{elif}\;b \leq 3.772087380287071 \cdot 10^{-236}:\\ \;\;\;\;-0.5 \cdot \frac{4}{\frac{b - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{c}}\\ \mathbf{elif}\;b \leq 371841908308.4654:\\ \;\;\;\;-0.5 \cdot \frac{\sqrt{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}} \cdot \sqrt{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{b \cdot 2}{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.2136550152753833 \cdot 10^{+95}:\\
\;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\

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

\mathbf{elif}\;b \leq 371841908308.4654:\\
\;\;\;\;-0.5 \cdot \frac{\sqrt{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}} \cdot \sqrt{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}}{a}\\

\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{b \cdot 2}{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.2136550152753833e+95)
   (* -0.5 (* 2.0 (/ c b)))
   (if (<= b 3.772087380287071e-236)
     (* -0.5 (/ 4.0 (/ (- b (sqrt (- (* b b) (* 4.0 (* c a))))) c)))
     (if (<= b 371841908308.4654)
       (*
        -0.5
        (/
         (*
          (sqrt (+ b (sqrt (- (* b b) (* 4.0 (* c a))))))
          (sqrt (+ b (sqrt (- (* b b) (* 4.0 (* c a)))))))
         a))
       (* -0.5 (/ (* b 2.0) 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.2136550152753833e+95) {
		tmp = -0.5 * (2.0 * (c / b));
	} else if (b <= 3.772087380287071e-236) {
		tmp = -0.5 * (4.0 / ((b - sqrt((b * b) - (4.0 * (c * a)))) / c));
	} else if (b <= 371841908308.4654) {
		tmp = -0.5 * ((sqrt(b + sqrt((b * b) - (4.0 * (c * a)))) * sqrt(b + sqrt((b * b) - (4.0 * (c * a))))) / a);
	} else {
		tmp = -0.5 * ((b * 2.0) / 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

Original34.7
Target21.2
Herbie7.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.21365501527538328e95

    1. Initial program 59.0

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

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

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

    if -2.21365501527538328e95 < b < 3.772087380287071e-236

    1. Initial program 30.9

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

      \[\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-+_binary6431.0

      \[\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. Simplified16.4

      \[\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_binary6416.4

      \[\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_binary6416.4

      \[\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_binary6416.4

      \[\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. Simplified16.4

      \[\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. Simplified9.7

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

    if 3.772087380287071e-236 < b < 371841908308.465393

    1. Initial program 9.7

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

      \[\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 add-sqr-sqrt_binary6410.0

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

    if 371841908308.465393 < b

    1. Initial program 34.2

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Simplified34.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-+_binary6460.3

      \[\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. Simplified59.7

      \[\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. Taylor expanded around 0 7.7

      \[\leadsto -0.5 \cdot \frac{\color{blue}{2 \cdot b}}{a}\]
    7. Simplified7.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -2.2136550152753833 \cdot 10^{+95}:\\ \;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\ \mathbf{elif}\;b \leq 3.772087380287071 \cdot 10^{-236}:\\ \;\;\;\;-0.5 \cdot \frac{4}{\frac{b - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{c}}\\ \mathbf{elif}\;b \leq 371841908308.4654:\\ \;\;\;\;-0.5 \cdot \frac{\sqrt{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}} \cdot \sqrt{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{b \cdot 2}{a}\\ \end{array}\]

Reproduce

herbie shell --seed 2020339 
(FPCore (a b c)
  :name "quadm (p42, negative)"
  :precision binary64
  :herbie-expected #f

  :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)))