Average Error: 34.0 → 9.1
Time: 5.2s
Precision: 64
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -1.0366436397824178 \cdot 10^{68}:\\ \;\;\;\;1 \cdot \left(-1 \cdot \frac{c}{b}\right)\\ \mathbf{elif}\;b \le -8.21218726880377109 \cdot 10^{-92}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\frac{\left({b}^{2} - {b}^{2}\right) + 4 \cdot \left(a \cdot c\right)}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}}}\\ \mathbf{elif}\;b \le -4.05237835825691163 \cdot 10^{-102}:\\ \;\;\;\;1 \cdot \left(-1 \cdot \frac{c}{b}\right)\\ \mathbf{elif}\;b \le 8.7111013098697189 \cdot 10^{145}:\\ \;\;\;\;1 \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\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 \le -1.0366436397824178 \cdot 10^{68}:\\
\;\;\;\;1 \cdot \left(-1 \cdot \frac{c}{b}\right)\\

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

\mathbf{elif}\;b \le -4.05237835825691163 \cdot 10^{-102}:\\
\;\;\;\;1 \cdot \left(-1 \cdot \frac{c}{b}\right)\\

\mathbf{elif}\;b \le 8.7111013098697189 \cdot 10^{145}:\\
\;\;\;\;1 \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\

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

\end{array}
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 temp;
	if ((b <= -1.0366436397824178e+68)) {
		temp = (1.0 * (-1.0 * (c / b)));
	} else {
		double temp_1;
		if ((b <= -8.212187268803771e-92)) {
			temp_1 = (1.0 / ((2.0 * a) / (((pow(b, 2.0) - pow(b, 2.0)) + (4.0 * (a * c))) / (sqrt(((b * b) - (4.0 * (a * c)))) - b))));
		} else {
			double temp_2;
			if ((b <= -4.052378358256912e-102)) {
				temp_2 = (1.0 * (-1.0 * (c / b)));
			} else {
				double temp_3;
				if ((b <= 8.711101309869719e+145)) {
					temp_3 = (1.0 * ((-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)));
				} else {
					temp_3 = (-1.0 * (b / a));
				}
				temp_2 = temp_3;
			}
			temp_1 = temp_2;
		}
		temp = temp_1;
	}
	return temp;
}

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.0
Target20.7
Herbie9.1
\[\begin{array}{l} \mathbf{if}\;b \lt 0.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 < -1.0366436397824178e+68 or -8.212187268803771e-92 < b < -4.052378358256912e-102

    1. Initial program 57.1

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied clear-num57.1

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}\]
    4. Using strategy rm
    5. Applied div-inv57.1

      \[\leadsto \frac{1}{\color{blue}{\left(2 \cdot a\right) \cdot \frac{1}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}\]
    6. Applied associate-/r*57.1

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

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

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

      \[\leadsto \frac{\frac{1}{2 \cdot a}}{\color{blue}{\frac{\sqrt{1}}{1} \cdot \frac{\sqrt{1}}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}\]
    11. Applied *-un-lft-identity57.1

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

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

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

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

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

    if -1.0366436397824178e+68 < b < -8.212187268803771e-92

    1. Initial program 42.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 clear-num42.5

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}\]
    4. Using strategy rm
    5. Applied flip--42.5

      \[\leadsto \frac{1}{\frac{2 \cdot a}{\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)}}}}}\]
    6. Simplified16.0

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

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

    if -4.052378358256912e-102 < b < 8.711101309869719e+145

    1. Initial program 11.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 clear-num11.5

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}\]
    4. Using strategy rm
    5. Applied div-inv11.5

      \[\leadsto \frac{1}{\color{blue}{\left(2 \cdot a\right) \cdot \frac{1}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}\]
    6. Applied associate-/r*11.6

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

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

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

      \[\leadsto \frac{\frac{1}{2 \cdot a}}{\color{blue}{\frac{\sqrt{1}}{1} \cdot \frac{\sqrt{1}}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}\]
    11. Applied *-un-lft-identity11.6

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

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

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

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

    if 8.711101309869719e+145 < b

    1. Initial program 60.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 clear-num60.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.0366436397824178 \cdot 10^{68}:\\ \;\;\;\;1 \cdot \left(-1 \cdot \frac{c}{b}\right)\\ \mathbf{elif}\;b \le -8.21218726880377109 \cdot 10^{-92}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\frac{\left({b}^{2} - {b}^{2}\right) + 4 \cdot \left(a \cdot c\right)}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}}}\\ \mathbf{elif}\;b \le -4.05237835825691163 \cdot 10^{-102}:\\ \;\;\;\;1 \cdot \left(-1 \cdot \frac{c}{b}\right)\\ \mathbf{elif}\;b \le 8.7111013098697189 \cdot 10^{145}:\\ \;\;\;\;1 \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{b}{a}\\ \end{array}\]

Reproduce

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

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

  (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))