Average Error: 34.3 → 17.5
Time: 8.0s
Precision: binary64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \leq -4.1675890391810646 \cdot 10^{+147}:\\ \;\;\;\;\frac{-b}{a \cdot 2}\\ \mathbf{elif}\;b \leq -1.346684968652724 \cdot 10^{-176}:\\ \;\;\;\;\frac{\sqrt{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b} \cdot \sqrt{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}}{a \cdot 2}\\ \mathbf{elif}\;b \leq 2.857075353436113 \cdot 10^{+153}:\\ \;\;\;\;-2 \cdot \frac{c}{b + \sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \frac{c}{b}\\ \end{array}\]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \leq -4.1675890391810646 \cdot 10^{+147}:\\
\;\;\;\;\frac{-b}{a \cdot 2}\\

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

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

\mathbf{else}:\\
\;\;\;\;-2 \cdot \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 -4.1675890391810646e+147)
   (/ (- b) (* a 2.0))
   (if (<= b -1.346684968652724e-176)
     (/
      (*
       (sqrt (- (sqrt (- (* b b) (* (* a 4.0) c))) b))
       (sqrt (- (sqrt (- (* b b) (* (* a 4.0) c))) b)))
      (* a 2.0))
     (if (<= b 2.857075353436113e+153)
       (* -2.0 (/ c (+ b (sqrt (- (* b b) (* (* a 4.0) c))))))
       (* -2.0 (/ 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 <= -4.1675890391810646e+147) {
		tmp = -b / (a * 2.0);
	} else if (b <= -1.346684968652724e-176) {
		tmp = (sqrt(sqrt((b * b) - ((a * 4.0) * c)) - b) * sqrt(sqrt((b * b) - ((a * 4.0) * c)) - b)) / (a * 2.0);
	} else if (b <= 2.857075353436113e+153) {
		tmp = -2.0 * (c / (b + sqrt((b * b) - ((a * 4.0) * c))));
	} else {
		tmp = -2.0 * (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

Original34.3
Target20.6
Herbie17.5
\[\begin{array}{l} \mathbf{if}\;b < 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if b < -4.1675890391810646e147

    1. Initial program 61.7

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

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

      \[\leadsto \frac{\color{blue}{0} - b}{a \cdot 2}\]

    if -4.1675890391810646e147 < b < -1.346684968652724e-176

    1. Initial program 7.1

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

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

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

    if -1.346684968652724e-176 < b < 2.8570753534361131e153

    1. Initial program 30.9

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

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

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

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

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

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

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

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

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

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

    if 2.8570753534361131e153 < b

    1. Initial program 63.9

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -4.1675890391810646 \cdot 10^{+147}:\\ \;\;\;\;\frac{-b}{a \cdot 2}\\ \mathbf{elif}\;b \leq -1.346684968652724 \cdot 10^{-176}:\\ \;\;\;\;\frac{\sqrt{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b} \cdot \sqrt{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}}{a \cdot 2}\\ \mathbf{elif}\;b \leq 2.857075353436113 \cdot 10^{+153}:\\ \;\;\;\;-2 \cdot \frac{c}{b + \sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2020270 
(FPCore (a b c)
  :name "The quadratic formula (r1)"
  :precision binary64

  :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)))