Average Error: 34.1 → 14.6
Time: 9.3s
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}\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2} \leq -\infty:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2} \leq -2.1057940873359677 \cdot 10^{-201}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a \cdot 2} - \frac{b}{a \cdot 2}\\ \mathbf{elif}\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2} \leq 0 \lor \neg \left(\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2} \leq 3.49982254304359 \cdot 10^{+282}\right):\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{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}\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2} \leq -\infty:\\
\;\;\;\;-\frac{c}{b}\\

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

\mathbf{elif}\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2} \leq 0 \lor \neg \left(\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2} \leq 3.49982254304359 \cdot 10^{+282}\right):\\
\;\;\;\;-\frac{c}{b}\\

\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{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 (<= (/ (- (sqrt (- (* b b) (* 4.0 (* a c)))) b) (* a 2.0)) (- INFINITY))
   (- (/ c b))
   (if (<=
        (/ (- (sqrt (- (* b b) (* 4.0 (* a c)))) b) (* a 2.0))
        -2.1057940873359677e-201)
     (- (/ (sqrt (- (* b b) (* 4.0 (* a c)))) (* a 2.0)) (/ b (* a 2.0)))
     (if (or (<= (/ (- (sqrt (- (* b b) (* 4.0 (* a c)))) b) (* a 2.0)) 0.0)
             (not
              (<=
               (/ (- (sqrt (- (* b b) (* 4.0 (* a c)))) b) (* a 2.0))
               3.49982254304359e+282)))
       (- (/ c b))
       (/ (- (sqrt (- (* b b) (* 4.0 (* a c)))) b) (* 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 (((sqrt((b * b) - (4.0 * (a * c))) - b) / (a * 2.0)) <= -((double) INFINITY)) {
		tmp = -(c / b);
	} else if (((sqrt((b * b) - (4.0 * (a * c))) - b) / (a * 2.0)) <= -2.1057940873359677e-201) {
		tmp = (sqrt((b * b) - (4.0 * (a * c))) / (a * 2.0)) - (b / (a * 2.0));
	} else if ((((sqrt((b * b) - (4.0 * (a * c))) - b) / (a * 2.0)) <= 0.0) || !(((sqrt((b * b) - (4.0 * (a * c))) - b) / (a * 2.0)) <= 3.49982254304359e+282)) {
		tmp = -(c / b);
	} else {
		tmp = (sqrt((b * b) - (4.0 * (a * c))) - b) / (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.1
Target21.0
Herbie14.6
\[\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 (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 4 (*.f64 a c))))) (*.f64 2 a)) < -inf.0 or -2.10579408733596768e-201 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 4 (*.f64 a c))))) (*.f64 2 a)) < 0.0 or 3.4998225430435901e282 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 4 (*.f64 a c))))) (*.f64 2 a))

    1. Initial program 58.7

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

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

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

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

    if -inf.0 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 4 (*.f64 a c))))) (*.f64 2 a)) < -2.10579408733596768e-201

    1. Initial program 4.5

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

      \[\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 div-sub_binary64_7654.5

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

    if 0.0 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 4 (*.f64 a c))))) (*.f64 2 a)) < 3.4998225430435901e282

    1. Initial program 4.6

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification14.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2} \leq -\infty:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2} \leq -2.1057940873359677 \cdot 10^{-201}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a \cdot 2} - \frac{b}{a \cdot 2}\\ \mathbf{elif}\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2} \leq 0 \lor \neg \left(\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2} \leq 3.49982254304359 \cdot 10^{+282}\right):\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2}\\ \end{array}\]

Reproduce

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