Average Error: 34.0 → 21.5
Time: 4.6s
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.3398860289927658 \cdot 10^{+154}:\\ \;\;\;\;\frac{-b}{a \cdot 2}\\ \mathbf{elif}\;b \leq -2.877828598460869 \cdot 10^{-307}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{a \cdot \left(c \cdot -4\right)}{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}}}{a \cdot 2}\\ \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.3398860289927658 \cdot 10^{+154}:\\
\;\;\;\;\frac{-b}{a \cdot 2}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{\frac{a \cdot \left(c \cdot -4\right)}{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}}}{a \cdot 2}\\

\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.3398860289927658e+154)
   (/ (- b) (* a 2.0))
   (if (<= b -2.877828598460869e-307)
     (/ 1.0 (/ (* a 2.0) (- (sqrt (- (* b b) (* 4.0 (* a c)))) b)))
     (/
      (/ (* a (* c -4.0)) (+ b (sqrt (+ (* b b) (* a (* c -4.0))))))
      (* a 2.0)))))
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.3398860289927658e+154) {
		tmp = -b / (a * 2.0);
	} else if (b <= -2.877828598460869e-307) {
		tmp = 1.0 / ((a * 2.0) / (sqrt((b * b) - (4.0 * (a * c))) - b));
	} else {
		tmp = ((a * (c * -4.0)) / (b + sqrt((b * b) + (a * (c * -4.0))))) / (a * 2.0);
	}
	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.0
Target21.1
Herbie21.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 3 regimes
  2. if b < -1.33988602899276581e154

    1. Initial program 64.0

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

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

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

    if -1.33988602899276581e154 < b < -2.8778285984608691e-307

    1. Initial program 9.2

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

      \[\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 *-un-lft-identity_binary649.2

      \[\leadsto \frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - \color{blue}{1 \cdot b}}{a \cdot 2}\]
    5. Applied *-un-lft-identity_binary649.2

      \[\leadsto \frac{\color{blue}{1 \cdot \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}} - 1 \cdot b}{a \cdot 2}\]
    6. Applied distribute-lft-out--_binary649.2

      \[\leadsto \frac{\color{blue}{1 \cdot \left(\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b\right)}}{a \cdot 2}\]
    7. Applied associate-/l*_binary649.4

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

    if -2.8778285984608691e-307 < b

    1. Initial program 43.8

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.3398860289927658 \cdot 10^{+154}:\\ \;\;\;\;\frac{-b}{a \cdot 2}\\ \mathbf{elif}\;b \leq -2.877828598460869 \cdot 10^{-307}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{a \cdot \left(c \cdot -4\right)}{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}}}{a \cdot 2}\\ \end{array}\]

Reproduce

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