Average Error: 34.1 → 6.9
Time: 6.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 -1.0182283612543797 \cdot 10^{+81}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq -3.089056825403424 \cdot 10^{-228}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 1.3389678122082543 \cdot 10^{+61}:\\ \;\;\;\;-2 \cdot \frac{c}{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \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.0182283612543797 \cdot 10^{+81}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

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

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

\mathbf{else}:\\
\;\;\;\;-\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 -1.0182283612543797e+81)
   (- (/ c b) (/ b a))
   (if (<= b -3.089056825403424e-228)
     (/ (- (sqrt (- (* b b) (* 4.0 (* c a)))) b) (* a 2.0))
     (if (<= b 1.3389678122082543e+61)
       (* -2.0 (/ c (+ b (sqrt (- (* b b) (* 4.0 (* c a)))))))
       (- (/ 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 <= -1.0182283612543797e+81) {
		tmp = (c / b) - (b / a);
	} else if (b <= -3.089056825403424e-228) {
		tmp = (sqrt((b * b) - (4.0 * (c * a))) - b) / (a * 2.0);
	} else if (b <= 1.3389678122082543e+61) {
		tmp = -2.0 * (c / (b + sqrt((b * b) - (4.0 * (c * a)))));
	} else {
		tmp = -(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.1
Target21.3
Herbie6.9
\[\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 4 regimes
  2. if b < -1.0182283612543797e81

    1. Initial program 43.0

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

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

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

    if -1.0182283612543797e81 < b < -3.0890568254034239e-228

    1. Initial program 8.2

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

    if -3.0890568254034239e-228 < b < 1.3389678122082543e61

    1. Initial program 28.2

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Simplified28.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 flip--_binary64_73528.3

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

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

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

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

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

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

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

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

    if 1.3389678122082543e61 < b

    1. Initial program 57.5

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    4. Simplified3.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.0182283612543797 \cdot 10^{+81}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq -3.089056825403424 \cdot 10^{-228}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 1.3389678122082543 \cdot 10^{+61}:\\ \;\;\;\;-2 \cdot \frac{c}{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

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