Average Error: 34.9 → 6.3
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 -2.3585860632819396 \cdot 10^{+97}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq -3.316085297718727 \cdot 10^{-287}:\\ \;\;\;\;\left(\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b\right) \cdot \frac{0.5}{a}\\ \mathbf{elif}\;b \leq 2.2382631606544506 \cdot 10^{+82}:\\ \;\;\;\;2 \cdot \frac{c}{\left(-b\right) - \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 -2.3585860632819396 \cdot 10^{+97}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

\mathbf{elif}\;b \leq -3.316085297718727 \cdot 10^{-287}:\\
\;\;\;\;\left(\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b\right) \cdot \frac{0.5}{a}\\

\mathbf{elif}\;b \leq 2.2382631606544506 \cdot 10^{+82}:\\
\;\;\;\;2 \cdot \frac{c}{\left(-b\right) - \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 -2.3585860632819396e+97)
   (- (/ c b) (/ b a))
   (if (<= b -3.316085297718727e-287)
     (* (- (sqrt (- (* b b) (* 4.0 (* c a)))) b) (/ 0.5 a))
     (if (<= b 2.2382631606544506e+82)
       (* 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 <= -2.3585860632819396e+97) {
		tmp = (c / b) - (b / a);
	} else if (b <= -3.316085297718727e-287) {
		tmp = (sqrt((b * b) - (4.0 * (c * a))) - b) * (0.5 / a);
	} else if (b <= 2.2382631606544506e+82) {
		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.9
Target20.9
Herbie6.3
\[\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 < -2.3585860632819396e97

    1. Initial program 47.0

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Taylor expanded around -inf 3.6

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

    if -2.3585860632819396e97 < b < -3.3160852977187271e-287

    1. Initial program 8.7

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied div-inv_binary64_7648.9

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

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

    if -3.3160852977187271e-287 < b < 2.23826316065445063e82

    1. Initial program 31.5

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied flip-+_binary64_74131.6

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

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

      \[\leadsto \frac{\frac{4 \cdot \left(a \cdot c\right)}{\color{blue}{1 \cdot \left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}}}{2 \cdot a}\]
    7. Applied times-frac_binary64_77315.8

      \[\leadsto \frac{\color{blue}{\frac{4}{1} \cdot \frac{a \cdot c}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}{2 \cdot a}\]
    8. Applied times-frac_binary64_77315.7

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

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

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

    if 2.23826316065445063e82 < b

    1. Initial program 58.8

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Taylor expanded around inf 2.8

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    3. Simplified2.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -2.3585860632819396 \cdot 10^{+97}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq -3.316085297718727 \cdot 10^{-287}:\\ \;\;\;\;\left(\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b\right) \cdot \frac{0.5}{a}\\ \mathbf{elif}\;b \leq 2.2382631606544506 \cdot 10^{+82}:\\ \;\;\;\;2 \cdot \frac{c}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

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