Average Error: 33.8 → 8.2
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 -4.751555112720535 \cdot 10^{+107}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq -3.835865055607966 \cdot 10^{-308}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 574334605182495:\\ \;\;\;\;\frac{\frac{c \cdot -4}{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{c \cdot -4}{2 \cdot \left(b - \frac{c \cdot a}{b}\right)}}{2}\\ \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 -4.751555112720535 \cdot 10^{+107}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

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

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

\mathbf{else}:\\
\;\;\;\;\frac{\frac{c \cdot -4}{2 \cdot \left(b - \frac{c \cdot a}{b}\right)}}{2}\\

\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 -4.751555112720535e+107)
   (- (/ c b) (/ b a))
   (if (<= b -3.835865055607966e-308)
     (/ (- (sqrt (+ (* b b) (* a (* c -4.0)))) b) (* a 2.0))
     (if (<= b 574334605182495.0)
       (/ (/ (* c -4.0) (+ b (sqrt (+ (* b b) (* a (* c -4.0)))))) 2.0)
       (/ (/ (* c -4.0) (* 2.0 (- b (/ (* c a) b)))) 2.0)))))
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 <= -4.751555112720535e+107) {
		tmp = (c / b) - (b / a);
	} else if (b <= -3.835865055607966e-308) {
		tmp = (sqrt((b * b) + (a * (c * -4.0))) - b) / (a * 2.0);
	} else if (b <= 574334605182495.0) {
		tmp = ((c * -4.0) / (b + sqrt((b * b) + (a * (c * -4.0))))) / 2.0;
	} else {
		tmp = ((c * -4.0) / (2.0 * (b - ((c * a) / b)))) / 2.0;
	}
	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.8
Target20.8
Herbie8.2
\[\begin{array}{l} \mathbf{if}\;b < 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \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 < -4.751555112720535e107

    1. Initial program 48.3

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

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

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

    if -4.751555112720535e107 < b < -3.83586505560796617e-308

    1. Initial program 9.4

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

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

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

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

    if -3.83586505560796617e-308 < b < 574334605182495

    1. Initial program 26.5

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

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

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

      \[\leadsto \frac{\sqrt{b \cdot b + \color{blue}{a \cdot \left(c \cdot -4\right)}} - b}{a \cdot 2}\]
    6. Using strategy rm
    7. Applied flip--_binary64_73526.6

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

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

      \[\leadsto \frac{\frac{a \cdot \left(c \cdot -4\right) + 0}{\color{blue}{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}}}}{a \cdot 2}\]
    10. Using strategy rm
    11. Applied associate-/r*_binary64_70417.0

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

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

    if 574334605182495 < b

    1. Initial program 56.1

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

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

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

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

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

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

      \[\leadsto \frac{\frac{a \cdot \left(c \cdot -4\right) + 0}{\color{blue}{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}}}}{a \cdot 2}\]
    10. Using strategy rm
    11. Applied associate-/r*_binary64_70427.1

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

      \[\leadsto \frac{\color{blue}{\frac{\frac{c \cdot -4}{1}}{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}}}}{2}\]
    13. Taylor expanded around inf 8.1

      \[\leadsto \frac{\frac{\frac{c \cdot -4}{1}}{\color{blue}{2 \cdot b - 2 \cdot \frac{a \cdot c}{b}}}}{2}\]
    14. Simplified8.1

      \[\leadsto \frac{\frac{\frac{c \cdot -4}{1}}{\color{blue}{2 \cdot \left(b - \frac{a \cdot c}{b}\right)}}}{2}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification8.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -4.751555112720535 \cdot 10^{+107}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq -3.835865055607966 \cdot 10^{-308}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 574334605182495:\\ \;\;\;\;\frac{\frac{c \cdot -4}{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{c \cdot -4}{2 \cdot \left(b - \frac{c \cdot a}{b}\right)}}{2}\\ \end{array}\]

Reproduce

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

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

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