Average Error: 34.8 → 16.2
Time: 7.0s
Precision: binary64
\[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\]
\[\begin{array}{l} \mathbf{if}\;b_2 \leq -1.3308472529742322 \cdot 10^{+154}:\\ \;\;\;\;\frac{\sqrt{\frac{1}{b_2 \cdot b_2}} - b_2}{\sqrt[3]{a} \cdot \sqrt[3]{a}} \cdot \frac{1}{\sqrt[3]{a}}\\ \mathbf{elif}\;b_2 \leq 1.9966424328827729 \cdot 10^{-38}:\\ \;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b_2}\\ \end{array}\]
\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}
\begin{array}{l}
\mathbf{if}\;b_2 \leq -1.3308472529742322 \cdot 10^{+154}:\\
\;\;\;\;\frac{\sqrt{\frac{1}{b_2 \cdot b_2}} - b_2}{\sqrt[3]{a} \cdot \sqrt[3]{a}} \cdot \frac{1}{\sqrt[3]{a}}\\

\mathbf{elif}\;b_2 \leq 1.9966424328827729 \cdot 10^{-38}:\\
\;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}\\

\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b_2}\\

\end{array}
(FPCore (a b_2 c)
 :precision binary64
 (/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))
(FPCore (a b_2 c)
 :precision binary64
 (if (<= b_2 -1.3308472529742322e+154)
   (*
    (/ (- (sqrt (/ 1.0 (* b_2 b_2))) b_2) (* (cbrt a) (cbrt a)))
    (/ 1.0 (cbrt a)))
   (if (<= b_2 1.9966424328827729e-38)
     (/ (- (sqrt (- (* b_2 b_2) (* a c))) b_2) a)
     (* -0.5 (/ c b_2)))))
double code(double a, double b_2, double c) {
	return (-b_2 + sqrt((b_2 * b_2) - (a * c))) / a;
}
double code(double a, double b_2, double c) {
	double tmp;
	if (b_2 <= -1.3308472529742322e+154) {
		tmp = ((sqrt(1.0 / (b_2 * b_2)) - b_2) / (cbrt(a) * cbrt(a))) * (1.0 / cbrt(a));
	} else if (b_2 <= 1.9966424328827729e-38) {
		tmp = (sqrt((b_2 * b_2) - (a * c)) - b_2) / a;
	} else {
		tmp = -0.5 * (c / b_2);
	}
	return tmp;
}

Error

Bits error versus a

Bits error versus b_2

Bits error versus c

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if b_2 < -1.3308472529742322e154

    1. Initial program 64.0

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

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}}\]
    3. Using strategy rm
    4. Applied div-inv_binary6464.0

      \[\leadsto \color{blue}{\left(\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2\right) \cdot \frac{1}{a}}\]
    5. Using strategy rm
    6. Applied add-cube-cbrt_binary6464.0

      \[\leadsto \left(\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2\right) \cdot \frac{1}{\color{blue}{\left(\sqrt[3]{a} \cdot \sqrt[3]{a}\right) \cdot \sqrt[3]{a}}}\]
    7. Applied *-un-lft-identity_binary6464.0

      \[\leadsto \left(\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2\right) \cdot \frac{\color{blue}{1 \cdot 1}}{\left(\sqrt[3]{a} \cdot \sqrt[3]{a}\right) \cdot \sqrt[3]{a}}\]
    8. Applied times-frac_binary6464.0

      \[\leadsto \left(\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2\right) \cdot \color{blue}{\left(\frac{1}{\sqrt[3]{a} \cdot \sqrt[3]{a}} \cdot \frac{1}{\sqrt[3]{a}}\right)}\]
    9. Applied associate-*r*_binary6464.0

      \[\leadsto \color{blue}{\left(\left(\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2\right) \cdot \frac{1}{\sqrt[3]{a} \cdot \sqrt[3]{a}}\right) \cdot \frac{1}{\sqrt[3]{a}}}\]
    10. Simplified64.0

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{\sqrt[3]{a} \cdot \sqrt[3]{a}}} \cdot \frac{1}{\sqrt[3]{a}}\]
    11. Taylor expanded around inf 52.2

      \[\leadsto \frac{\sqrt{\color{blue}{\frac{1}{{b_2}^{2}}}} - b_2}{\sqrt[3]{a} \cdot \sqrt[3]{a}} \cdot \frac{1}{\sqrt[3]{a}}\]
    12. Simplified52.2

      \[\leadsto \frac{\sqrt{\color{blue}{\frac{1}{b_2 \cdot b_2}}} - b_2}{\sqrt[3]{a} \cdot \sqrt[3]{a}} \cdot \frac{1}{\sqrt[3]{a}}\]

    if -1.3308472529742322e154 < b_2 < 1.99664243288277287e-38

    1. Initial program 13.9

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

    if 1.99664243288277287e-38 < b_2

    1. Initial program 54.9

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\]
    2. Simplified54.9

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}}\]
    3. Taylor expanded around 0 7.4

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b_2}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification16.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \leq -1.3308472529742322 \cdot 10^{+154}:\\ \;\;\;\;\frac{\sqrt{\frac{1}{b_2 \cdot b_2}} - b_2}{\sqrt[3]{a} \cdot \sqrt[3]{a}} \cdot \frac{1}{\sqrt[3]{a}}\\ \mathbf{elif}\;b_2 \leq 1.9966424328827729 \cdot 10^{-38}:\\ \;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b_2}\\ \end{array}\]

Reproduce

herbie shell --seed 2020344 
(FPCore (a b_2 c)
  :name "quad2p (problem 3.2.1, positive)"
  :precision binary64
  (/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))