Average Error: 34.2 → 6.5
Time: 7.6s
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 -9.560667674887568 \cdot 10^{+134}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq 4.428128095775905 \cdot 10^{-281}:\\ \;\;\;\;2 \cdot \frac{c}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}\\ \mathbf{elif}\;b \leq 2.2264978507093777 \cdot 10^{+94}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-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 -9.560667674887568 \cdot 10^{+134}:\\
\;\;\;\;-\frac{c}{b}\\

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

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

\mathbf{else}:\\
\;\;\;\;\frac{-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 -9.560667674887568e+134)
   (- (/ c b))
   (if (<= b 4.428128095775905e-281)
     (* 2.0 (/ c (- (sqrt (- (* b b) (* 4.0 (* c a)))) b)))
     (if (<= b 2.2264978507093777e+94)
       (/ (- (- b) (sqrt (+ (* b b) (* c (* a -4.0))))) (* 2.0 a))
       (/ (- 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 <= -9.560667674887568e+134) {
		tmp = -(c / b);
	} else if (b <= 4.428128095775905e-281) {
		tmp = 2.0 * (c / (sqrt((b * b) - (4.0 * (c * a))) - b));
	} else if (b <= 2.2264978507093777e+94) {
		tmp = (-b - sqrt((b * b) + (c * (a * -4.0)))) / (2.0 * a);
	} else {
		tmp = -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

Original34.2
Target21.2
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 < -9.5606676748875676e134

    1. Initial program 62.0

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

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

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

    if -9.5606676748875676e134 < b < 4.42812809577590528e-281

    1. Initial program 33.4

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a} \]
    2. Using strategy rm
    3. Applied flip--_binary6433.4

      \[\leadsto \frac{\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)}}}}{2 \cdot a} \]
    4. Simplified15.8

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

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

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

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

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

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

      \[\leadsto 2 \cdot \color{blue}{\left(1 \cdot \frac{c}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}\right)} \]
    12. Taylor expanded in b around 0 8.2

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

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

    if 4.42812809577590528e-281 < b < 2.22649785070937769e94

    1. Initial program 9.2

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a} \]
    2. Using strategy rm
    3. Applied sub-neg_binary649.2

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

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

    if 2.22649785070937769e94 < b

    1. Initial program 45.1

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

      \[\leadsto \frac{\left(-b\right) - \color{blue}{b}}{2 \cdot a} \]
    3. Simplified4.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -9.560667674887568 \cdot 10^{+134}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq 4.428128095775905 \cdot 10^{-281}:\\ \;\;\;\;2 \cdot \frac{c}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}\\ \mathbf{elif}\;b \leq 2.2264978507093777 \cdot 10^{+94}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array} \]

Reproduce

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