Average Error: 34.2 → 7.0
Time: 5.1s
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 -8.400344984829291 \cdot 10^{+127}:\\ \;\;\;\;\frac{4}{2} \cdot \frac{c}{a \cdot \frac{2}{\frac{b}{c}} + b \cdot -2}\\ \mathbf{elif}\;b \leq -1.8516422739532216 \cdot 10^{-298}:\\ \;\;\;\;\frac{4}{2} \cdot \frac{c}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}\\ \mathbf{elif}\;b \leq 1.342597879577989 \cdot 10^{+92}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{b}{a}\\ \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 -8.400344984829291 \cdot 10^{+127}:\\
\;\;\;\;\frac{4}{2} \cdot \frac{c}{a \cdot \frac{2}{\frac{b}{c}} + b \cdot -2}\\

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

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

\mathbf{else}:\\
\;\;\;\;-1 \cdot \frac{b}{a}\\

\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 -8.400344984829291e+127)
   (* (/ 4.0 2.0) (/ c (+ (* a (/ 2.0 (/ b c))) (* b -2.0))))
   (if (<= b -1.8516422739532216e-298)
     (* (/ 4.0 2.0) (/ c (- (sqrt (- (* b b) (* 4.0 (* c a)))) b)))
     (if (<= b 1.342597879577989e+92)
       (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* 2.0 a))
       (* -1.0 (/ b a))))))
double code(double a, double b, double c) {
	return (((double) (((double) -(b)) - ((double) sqrt(((double) (((double) (b * b)) - ((double) (4.0 * ((double) (a * c)))))))))) / ((double) (2.0 * a)));
}
double code(double a, double b, double c) {
	double VAR;
	if ((b <= -8.400344984829291e+127)) {
		VAR = ((double) ((4.0 / 2.0) * (c / ((double) (((double) (a * (2.0 / (b / c)))) + ((double) (b * -2.0)))))));
	} else {
		double VAR_1;
		if ((b <= -1.8516422739532216e-298)) {
			VAR_1 = ((double) ((4.0 / 2.0) * (c / ((double) (((double) sqrt(((double) (((double) (b * b)) - ((double) (4.0 * ((double) (c * a)))))))) - b)))));
		} else {
			double VAR_2;
			if ((b <= 1.342597879577989e+92)) {
				VAR_2 = (((double) (((double) -(b)) - ((double) sqrt(((double) (((double) (b * b)) - ((double) (4.0 * ((double) (c * a)))))))))) / ((double) (2.0 * a)));
			} else {
				VAR_2 = ((double) (-1.0 * (b / a)));
			}
			VAR_1 = VAR_2;
		}
		VAR = VAR_1;
	}
	return VAR;
}

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.2
Target20.8
Herbie7.0
\[\begin{array}{l} \mathbf{if}\;b < 0:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \mathbf{else}:\\ \;\;\;\;\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 < -8.4003449848292906e127

    1. Initial program 61.0

      \[\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--61.0

      \[\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. Simplified33.4

      \[\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. Simplified33.4

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

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

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

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

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

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

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

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

    if -8.4003449848292906e127 < b < -1.85164227395322156e-298

    1. Initial program 35.4

      \[\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--35.4

      \[\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. Simplified17.0

      \[\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. Simplified17.0

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

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

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

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

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

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

    if -1.85164227395322156e-298 < b < 1.34259787957798912e92

    1. Initial program 10.0

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

    if 1.34259787957798912e92 < b

    1. Initial program 44.8

      \[\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--62.7

      \[\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. Simplified61.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. Simplified61.8

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification7.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -8.400344984829291 \cdot 10^{+127}:\\ \;\;\;\;\frac{4}{2} \cdot \frac{c}{a \cdot \frac{2}{\frac{b}{c}} + b \cdot -2}\\ \mathbf{elif}\;b \leq -1.8516422739532216 \cdot 10^{-298}:\\ \;\;\;\;\frac{4}{2} \cdot \frac{c}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}\\ \mathbf{elif}\;b \leq 1.342597879577989 \cdot 10^{+92}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{b}{a}\\ \end{array}\]

Reproduce

herbie shell --seed 2020198 
(FPCore (a b c)
  :name "The quadratic formula (r2)"
  :precision binary64

  :herbie-target
  (if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))

  (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))