Average Error: 33.9 → 6.4
Time: 5.4s
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.1036730520568813 \cdot 10^{+101}:\\ \;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\ \mathbf{elif}\;b \leq -9.177620980737481 \cdot 10^{-299}:\\ \;\;\;\;-0.5 \cdot \frac{c \cdot 4}{b - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\\ \mathbf{elif}\;b \leq 1.7352320966708498 \cdot 10^{+98}:\\ \;\;\;\;-0.5 \cdot \left(\left(b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}\right) \cdot \frac{1}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \left(2 \cdot \frac{b}{a}\right)\\ \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.1036730520568813 \cdot 10^{+101}:\\
\;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\

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

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

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

\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.1036730520568813e+101)
   (* -0.5 (* 2.0 (/ c b)))
   (if (<= b -9.177620980737481e-299)
     (* -0.5 (/ (* c 4.0) (- b (sqrt (- (* b b) (* 4.0 (* c a)))))))
     (if (<= b 1.7352320966708498e+98)
       (* -0.5 (* (+ b (sqrt (- (* b b) (* 4.0 (* c a))))) (/ 1.0 a)))
       (* -0.5 (* 2.0 (/ 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 <= -2.1036730520568813e+101) {
		tmp = -0.5 * (2.0 * (c / b));
	} else if (b <= -9.177620980737481e-299) {
		tmp = -0.5 * ((c * 4.0) / (b - sqrt((b * b) - (4.0 * (c * a)))));
	} else if (b <= 1.7352320966708498e+98) {
		tmp = -0.5 * ((b + sqrt((b * b) - (4.0 * (c * a)))) * (1.0 / a));
	} else {
		tmp = -0.5 * (2.0 * (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.5
Herbie6.4
\[\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 < -2.1036730520568813e101

    1. Initial program 59.1

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

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

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

    if -2.1036730520568813e101 < b < -9.177620980737481e-299

    1. Initial program 32.5

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

      \[\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 div-inv_binary64_142232.5

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

      \[\leadsto -0.5 \cdot \left(\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)}}} \cdot \frac{1}{a}\right)\]
    7. Applied associate-*l/_binary64_137032.6

      \[\leadsto -0.5 \cdot \color{blue}{\frac{\left(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)}\right) \cdot \frac{1}{a}}{b - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}\]
    8. Simplified14.5

      \[\leadsto -0.5 \cdot \frac{\color{blue}{\frac{4 \cdot \left(a \cdot c\right)}{a}}}{b - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}\]
    9. Using strategy rm
    10. Applied *-un-lft-identity_binary64_142514.5

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

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

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

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

    if -9.177620980737481e-299 < b < 1.7352320966708498e98

    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}{-0.5 \cdot \frac{b + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a}}\]
    3. Using strategy rm
    4. Applied div-inv_binary64_14229.5

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

    if 1.7352320966708498e98 < b

    1. Initial program 47.3

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

      \[\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 div-inv_binary64_142247.4

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

      \[\leadsto -0.5 \cdot \left(\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)}}} \cdot \frac{1}{a}\right)\]
    7. Applied associate-*l/_binary64_137063.5

      \[\leadsto -0.5 \cdot \color{blue}{\frac{\left(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)}\right) \cdot \frac{1}{a}}{b - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}\]
    8. Simplified62.6

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

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

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

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

      \[\leadsto -0.5 \cdot \frac{4 \cdot \color{blue}{c}}{b - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}\]
    14. Taylor expanded around 0 3.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -2.1036730520568813 \cdot 10^{+101}:\\ \;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\ \mathbf{elif}\;b \leq -9.177620980737481 \cdot 10^{-299}:\\ \;\;\;\;-0.5 \cdot \frac{c \cdot 4}{b - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\\ \mathbf{elif}\;b \leq 1.7352320966708498 \cdot 10^{+98}:\\ \;\;\;\;-0.5 \cdot \left(\left(b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}\right) \cdot \frac{1}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \left(2 \cdot \frac{b}{a}\right)\\ \end{array}\]

Reproduce

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