Average Error: 33.5 → 6.5
Time: 9.3s
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.587685883918172 \cdot 10^{+93}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq -2.647768469823155 \cdot 10^{-306}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 5.425482410905856 \cdot 10^{+139}:\\ \;\;\;\;-2 \cdot \frac{c}{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \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.587685883918172 \cdot 10^{+93}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

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

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

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

\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.587685883918172e+93)
   (- (/ c b) (/ b a))
   (if (<= b -2.647768469823155e-306)
     (/ (- (sqrt (- (* b b) (* 4.0 (* c a)))) b) (* a 2.0))
     (if (<= b 5.425482410905856e+139)
       (* -2.0 (/ c (+ b (sqrt (- (* b b) (* 4.0 (* c a)))))))
       (- (/ c b))))))
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.587685883918172e+93) {
		tmp = (c / b) - (b / a);
	} else if (b <= -2.647768469823155e-306) {
		tmp = (sqrt((b * b) - (4.0 * (c * a))) - b) / (a * 2.0);
	} else if (b <= 5.425482410905856e+139) {
		tmp = -2.0 * (c / (b + sqrt((b * b) - (4.0 * (c * a)))));
	} else {
		tmp = -(c / b);
	}
	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.5
Target20.7
Herbie6.5
\[\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 < -2.5876858839181722e93

    1. Initial program 45.8

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

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

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

    if -2.5876858839181722e93 < b < -2.64776846982315499e-306

    1. Initial program 8.9

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

    if -2.64776846982315499e-306 < b < 5.4254824109058555e139

    1. Initial program 33.5

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Simplified33.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 flip--_binary64_5333.5

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

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

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

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

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

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

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

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

    if 5.4254824109058555e139 < b

    1. Initial program 62.1

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -2.587685883918172 \cdot 10^{+93}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq -2.647768469823155 \cdot 10^{-306}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 5.425482410905856 \cdot 10^{+139}:\\ \;\;\;\;-2 \cdot \frac{c}{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

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