Average Error: 34.8 → 6.7
Time: 5.8s
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 -6.199403977267283 \cdot 10^{+152}:\\ \;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\ \mathbf{elif}\;b \leq -1.0003654787895762 \cdot 10^{-265}:\\ \;\;\;\;-0.5 \cdot \frac{c \cdot 4}{b - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\\ \mathbf{elif}\;b \leq 1.2594828022150501 \cdot 10^{+81}:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a}\\ \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 -6.199403977267283 \cdot 10^{+152}:\\
\;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\

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

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

\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 -6.199403977267283e+152)
   (* -0.5 (* 2.0 (/ c b)))
   (if (<= b -1.0003654787895762e-265)
     (* -0.5 (/ (* c 4.0) (- b (sqrt (- (* b b) (* 4.0 (* c a)))))))
     (if (<= b 1.2594828022150501e+81)
       (* -0.5 (/ (+ b (sqrt (- (* b b) (* 4.0 (* c a))))) 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 <= -6.199403977267283e+152) {
		tmp = -0.5 * (2.0 * (c / b));
	} else if (b <= -1.0003654787895762e-265) {
		tmp = -0.5 * ((c * 4.0) / (b - sqrt((b * b) - (4.0 * (c * a)))));
	} else if (b <= 1.2594828022150501e+81) {
		tmp = -0.5 * ((b + sqrt((b * b) - (4.0 * (c * a)))) / 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

Original34.8
Target21.1
Herbie6.7
\[\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 < -6.1994039772672828e152

    1. Initial program 63.9

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

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

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

    if -6.1994039772672828e152 < b < -1.0003654787895762e-265

    1. Initial program 35.6

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

      \[\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_76435.6

      \[\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_74135.6

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

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

      \[\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_76714.1

      \[\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_77314.1

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

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

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

    if -1.0003654787895762e-265 < b < 1.25948280221505013e81

    1. Initial program 10.7

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

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

    if 1.25948280221505013e81 < b

    1. Initial program 43.3

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Simplified43.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_76443.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_74162.7

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

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

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

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

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

      \[\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. Simplified61.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -6.199403977267283 \cdot 10^{+152}:\\ \;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\ \mathbf{elif}\;b \leq -1.0003654787895762 \cdot 10^{-265}:\\ \;\;\;\;-0.5 \cdot \frac{c \cdot 4}{b - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\\ \mathbf{elif}\;b \leq 1.2594828022150501 \cdot 10^{+81}:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \left(2 \cdot \frac{b}{a}\right)\\ \end{array}\]

Reproduce

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