Average Error: 33.9 → 6.8
Time: 6.9s
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.338340640721482 \cdot 10^{+157}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq 2.2068850198815852 \cdot 10^{-141}:\\ \;\;\;\;2 \cdot \frac{c}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}\\ \mathbf{elif}\;b \leq 2.404688834790521 \cdot 10^{+51}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt[3]{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}} \cdot \left(\sqrt[3]{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}} \cdot \sqrt[3]{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\right)}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \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 -1.338340640721482 \cdot 10^{+157}:\\
\;\;\;\;-\frac{c}{b}\\

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

\mathbf{elif}\;b \leq 2.404688834790521 \cdot 10^{+51}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt[3]{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}} \cdot \left(\sqrt[3]{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}} \cdot \sqrt[3]{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\right)}{2 \cdot a}\\

\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \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 -1.338340640721482e+157)
   (- (/ c b))
   (if (<= b 2.2068850198815852e-141)
     (* 2.0 (/ c (- (sqrt (- (* b b) (* 4.0 (* c a)))) b)))
     (if (<= b 2.404688834790521e+51)
       (/
        (-
         (- b)
         (*
          (cbrt (sqrt (- (* b b) (* 4.0 (* c a)))))
          (*
           (cbrt (sqrt (- (* b b) (* 4.0 (* c a)))))
           (cbrt (sqrt (- (* b b) (* 4.0 (* c a))))))))
        (* 2.0 a))
       (- (/ c b) (/ 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 <= -1.338340640721482e+157) {
		tmp = -(c / b);
	} else if (b <= 2.2068850198815852e-141) {
		tmp = 2.0 * (c / (sqrt((b * b) - (4.0 * (c * a))) - b));
	} else if (b <= 2.404688834790521e+51) {
		tmp = (-b - (cbrt(sqrt((b * b) - (4.0 * (c * a)))) * (cbrt(sqrt((b * b) - (4.0 * (c * a)))) * cbrt(sqrt((b * b) - (4.0 * (c * a))))))) / (2.0 * a);
	} else {
		tmp = (c / b) - (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

Original33.9
Target20.8
Herbie6.8
\[\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.33834064072148198e157

    1. Initial program 64.0

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Taylor expanded around -inf 1.6

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

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

    if -1.33834064072148198e157 < b < 2.2068850198815852e-141

    1. Initial program 29.9

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

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

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

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

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

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

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

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

    if 2.2068850198815852e-141 < b < 2.40468883479052089e51

    1. Initial program 6.1

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

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

    if 2.40468883479052089e51 < b

    1. Initial program 39.1

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Taylor expanded around inf 5.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.338340640721482 \cdot 10^{+157}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq 2.2068850198815852 \cdot 10^{-141}:\\ \;\;\;\;2 \cdot \frac{c}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}\\ \mathbf{elif}\;b \leq 2.404688834790521 \cdot 10^{+51}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt[3]{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}} \cdot \left(\sqrt[3]{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}} \cdot \sqrt[3]{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\right)}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Reproduce

herbie shell --seed 2020280 
(FPCore (a b c)
  :name "The quadratic formula (r2)"
  :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)))