Average Error: 30.4 → 9.3
Time: 6.8s
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 -3.033237869256851 \cdot 10^{+153}:\\ \;\;\;\;\frac{\left(-b_2\right) - b_2}{a}\\ \mathbf{elif}\;b_2 \leq 4.8226896466439825 \cdot 10^{-28}:\\ \;\;\;\;\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 -3.033237869256851 \cdot 10^{+153}:\\
\;\;\;\;\frac{\left(-b_2\right) - b_2}{a}\\

\mathbf{elif}\;b_2 \leq 4.8226896466439825 \cdot 10^{-28}:\\
\;\;\;\;\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 -3.033237869256851e+153)
   (/ (- (- b_2) b_2) a)
   (if (<= b_2 4.8226896466439825e-28)
     (/ (- (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 <= -3.033237869256851e+153) {
		tmp = (-b_2 - b_2) / a;
	} else if (b_2 <= 4.8226896466439825e-28) {
		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 < -3.0332378692568511e153

    1. Initial program 35.9

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

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

      \[\leadsto \frac{\color{blue}{-1 \cdot b_2} - b_2}{a} \]
    4. Simplified1.3

      \[\leadsto \frac{\color{blue}{\left(-b_2\right)} - b_2}{a} \]

    if -3.0332378692568511e153 < b_2 < 4.82268964664398249e-28

    1. Initial program 13.2

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

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]
    3. Applied clear-num_binary6413.3

      \[\leadsto \color{blue}{\frac{1}{\frac{a}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}} \]
    4. Applied associate-/r/_binary6413.3

      \[\leadsto \color{blue}{\frac{1}{a} \cdot \left(\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2\right)} \]
    5. Applied associate-*l/_binary6413.2

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

    if 4.82268964664398249e-28 < b_2

    1. Initial program 54.1

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \leq -3.033237869256851 \cdot 10^{+153}:\\ \;\;\;\;\frac{\left(-b_2\right) - b_2}{a}\\ \mathbf{elif}\;b_2 \leq 4.8226896466439825 \cdot 10^{-28}:\\ \;\;\;\;\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 2022067 
(FPCore (a b_2 c)
  :name "quad2p (problem 3.2.1, positive)"
  :precision binary64
  (/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))