Average Error: 34.3 → 6.5
Time: 7.5s
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 -1.3091834909018501 \cdot 10^{+152}:\\ \;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\ \mathbf{elif}\;b \leq 1.4031237401242977 \cdot 10^{-270}:\\ \;\;\;\;-0.5 \cdot \left(4 \cdot \left(c \cdot \frac{1}{b - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\right)\right)\\ \mathbf{elif}\;b \leq 2.1578323955249213 \cdot 10^{+116}:\\ \;\;\;\;-0.5 \cdot \frac{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 -1.3091834909018501 \cdot 10^{+152}:\\
\;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\

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

\mathbf{elif}\;b \leq 2.1578323955249213 \cdot 10^{+116}:\\
\;\;\;\;-0.5 \cdot \frac{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 -1.3091834909018501e+152)
   (* -0.5 (* 2.0 (/ c b)))
   (if (<= b 1.4031237401242977e-270)
     (* -0.5 (* 4.0 (* c (/ 1.0 (- b (sqrt (- (* b b) (* 4.0 (* c a)))))))))
     (if (<= b 2.1578323955249213e+116)
       (* -0.5 (/ (+ 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 <= -1.3091834909018501e+152) {
		tmp = -0.5 * (2.0 * (c / b));
	} else if (b <= 1.4031237401242977e-270) {
		tmp = -0.5 * (4.0 * (c * (1.0 / (b - sqrt((b * b) - (4.0 * (c * a)))))));
	} else if (b <= 2.1578323955249213e+116) {
		tmp = -0.5 * ((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.3
Target21.5
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 < -1.30918349090185012e152

    1. Initial program 63.9

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

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

    if -1.30918349090185012e152 < b < 1.4031237401242977e-270

    1. Initial program 33.8

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

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

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

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

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

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

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

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

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

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

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

    if 1.4031237401242977e-270 < b < 2.1578323955249213e116

    1. Initial program 8.2

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

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

    if 2.1578323955249213e116 < b

    1. Initial program 50.8

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.3091834909018501 \cdot 10^{+152}:\\ \;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\ \mathbf{elif}\;b \leq 1.4031237401242977 \cdot 10^{-270}:\\ \;\;\;\;-0.5 \cdot \left(4 \cdot \left(c \cdot \frac{1}{b - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\right)\right)\\ \mathbf{elif}\;b \leq 2.1578323955249213 \cdot 10^{+116}:\\ \;\;\;\;-0.5 \cdot \frac{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 2020292 
(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)))