Average Error: 33.7 → 9.9
Time: 11.4s
Precision: binary64
Cost: 8258
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \leq -9.934253510808862 \cdot 10^{+120}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 2.7658541670298186 \cdot 10^{-38}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}{a \cdot 2} - \frac{b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \leq -9.934253510808862 \cdot 10^{+120}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

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

\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 -9.934253510808862e+120)
   (- (/ c b) (/ b a))
   (if (<= b 2.7658541670298186e-38)
     (- (/ (sqrt (- (* b b) (* c (* a 4.0)))) (* a 2.0)) (/ b (* a 2.0)))
     (- (/ 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 <= -9.934253510808862e+120) {
		tmp = (c / b) - (b / a);
	} else if (b <= 2.7658541670298186e-38) {
		tmp = (sqrt((b * b) - (c * (a * 4.0))) / (a * 2.0)) - (b / (a * 2.0));
	} 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

Original33.7
Target20.3
Herbie9.9
\[\begin{array}{l} \mathbf{if}\;b < 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}}\\ \end{array}\]

Alternatives

Alternative 1
Error34.4
Cost79936
\[\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{\frac{\sqrt[3]{a} \cdot \sqrt[3]{a}}{\sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b} \cdot \sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}} \cdot \frac{\sqrt[3]{1}}{\frac{\sqrt[3]{a}}{\frac{\sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}{2}}}\]
Alternative 2
Error34.1
Cost47040
\[\left(\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}\right) \cdot \frac{\sqrt[3]{1}}{\frac{a}{\sqrt{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}}}\]
Alternative 3
Error34.2
Cost40896
\[\frac{\sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b} \cdot \sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}{\frac{a}{\frac{\sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}{2}}}\]
Alternative 4
Error34.2
Cost40896
\[\frac{\sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}{2} \cdot \frac{\sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b} \cdot \sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}{a}\]
Alternative 5
Error34.2
Cost40896
\[\frac{\sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b} \cdot \left(\sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b} \cdot \sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}\right)}{a \cdot 2}\]
Alternative 6
Error35.5
Cost40640
\[\frac{\sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \left(\sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt[3]{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\right) - b}{a \cdot 2}\]
Alternative 7
Error34.1
Cost39872
\[\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{\sqrt{2}} \cdot \frac{\sqrt[3]{1}}{\frac{a}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{\sqrt{2}}}}\]
Alternative 8
Error52.6
Cost34176
\[\frac{\frac{\sqrt{{b}^{6} - {\left(\left(4 \cdot a\right) \cdot c\right)}^{3}}}{\sqrt{{b}^{4} + 4 \cdot \left(\left(b \cdot b + \left(4 \cdot a\right) \cdot c\right) \cdot \left(a \cdot c\right)\right)}} - b}{a \cdot 2}\]
Alternative 9
Error52.5
Cost27776
\[\frac{\sqrt{\frac{{b}^{6} - {\left(\left(4 \cdot a\right) \cdot c\right)}^{3}}{{b}^{4} + 4 \cdot \left(\left(b \cdot b + \left(4 \cdot a\right) \cdot c\right) \cdot \left(a \cdot c\right)\right)}} - b}{a \cdot 2}\]
Alternative 10
Error34.1
Cost27456
\[\frac{\sqrt{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}}{\frac{a}{\sqrt{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}}}\]
Alternative 11
Error34.1
Cost27456
\[\sqrt{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}} \cdot \frac{\sqrt{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}}{a}\]
Alternative 12
Error34.1
Cost27328
\[\frac{\sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}{a} \cdot \frac{\sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}{2}\]
Alternative 13
Error34.1
Cost27328
\[\frac{\sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b} \cdot \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}{a \cdot 2}\]
Alternative 14
Error45.3
Cost27200
\[\frac{\sqrt{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}}{\frac{a}{\sqrt{\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{2}}}}\]
Alternative 15
Error35.0
Cost27200
\[\frac{\left|\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}\right| \cdot \sqrt{\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}} - b}{a \cdot 2}\]
Alternative 16
Error34.5
Cost27200
\[\frac{\sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} - b}{a \cdot 2}\]
Alternative 17
Error45.1
Cost27072
\[\frac{\sqrt{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}}{\frac{a}{\sqrt{\frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{2}}}}\]
Alternative 18
Error42.8
Cost20352
\[\frac{1}{\frac{a}{\frac{\sqrt[3]{{\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}^{3}} - b}{2}}}\]
Alternative 19
Error52.0
Cost20224
\[\frac{\sqrt{\sqrt[3]{{\left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)}^{3}}} - b}{a \cdot 2}\]
Alternative 20
Error42.7
Cost20224
\[\frac{\sqrt[3]{{\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}^{3}} - b}{a \cdot 2}\]
Alternative 21
Error37.0
Cost20160
\[\frac{e^{\log \left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)} - b}{a \cdot 2}\]
Alternative 22
Error61.5
Cost20160
\[\frac{\log \left(e^{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\right) - b}{a \cdot 2}\]
Alternative 23
Error35.8
Cost20160
\[\frac{e^{\log \left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right)}}{a \cdot 2}\]
Alternative 24
Error60.5
Cost20160
\[\frac{\log \left(e^{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}\right)}{a \cdot 2}\]
Alternative 25
Error53.8
Cost14592
\[\frac{\sqrt{\frac{{b}^{4} - \left(\left(c \cdot c\right) \cdot \left(a \cdot a\right)\right) \cdot 16}{b \cdot b + \left(4 \cdot a\right) \cdot c}} - b}{a \cdot 2}\]
Alternative 26
Error46.1
Cost14272
\[\frac{\left(\sqrt{a \cdot \left(c \cdot -4\right)} + 0.5 \cdot \frac{b \cdot b}{\sqrt{a \cdot \left(c \cdot -4\right)}}\right) - b}{a \cdot 2}\]
Alternative 27
Error44.0
Cost8384
\[\frac{1}{\frac{a}{\frac{\frac{b \cdot b - \left(b \cdot b + \left(4 \cdot a\right) \cdot c\right)}{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2}}}\]
Alternative 28
Error44.0
Cost8256
\[\frac{\frac{b \cdot b - \left(b \cdot b + \left(4 \cdot a\right) \cdot c\right)}{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{a \cdot 2}\]
Alternative 29
Error34.0
Cost7616
\[\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2} - \frac{b}{a \cdot 2}\]
Alternative 30
Error33.8
Cost7488
\[\frac{1}{\frac{a}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}}\]
Alternative 31
Error33.8
Cost7488
\[\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2} \cdot \frac{1}{a}\]
Alternative 32
Error50.1
Cost7424
\[\frac{a \cdot \left(c \cdot c\right)}{{b}^{3}} + \left(\frac{c}{b} - \frac{b}{a}\right)\]
Alternative 33
Error33.7
Cost7360
\[\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a \cdot 2}\]
Alternative 34
Error33.8
Cost7360
\[\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right) \cdot \frac{0.5}{a}\]
Alternative 35
Error44.5
Cost7232
\[\frac{1}{\frac{a}{\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{2}}}\]
Alternative 36
Error43.8
Cost7104
\[\frac{1}{\frac{a}{\frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{2}}}\]
Alternative 37
Error44.5
Cost7104
\[\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\]
Alternative 38
Error43.8
Cost6976
\[\frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a \cdot 2}\]
Alternative 39
Error45.3
Cost704
\[\frac{-2 \cdot \frac{a \cdot c}{b}}{a \cdot 2}\]
Alternative 40
Error45.2
Cost640
\[\frac{1}{\frac{a}{\frac{\left(-b\right) - b}{2}}}\]
Alternative 41
Error45.2
Cost576
\[\frac{1}{\frac{a}{\frac{b \cdot -2}{2}}}\]
Alternative 42
Error45.1
Cost512
\[\frac{\left(-b\right) - b}{a \cdot 2}\]
Alternative 43
Error45.3
Cost448
\[\frac{c}{b} - \frac{b}{a}\]
Alternative 44
Error45.1
Cost448
\[\frac{b \cdot -2}{a \cdot 2}\]
Alternative 45
Error56.4
Cost448
\[\frac{b - b}{a \cdot 2}\]
Alternative 46
Error45.1
Cost256
\[\frac{-b}{a}\]
Alternative 47
Error39.8
Cost256
\[-\frac{c}{b}\]
Alternative 48
Error61.6
Cost64
\[1\]
Alternative 49
Error56.4
Cost64
\[0\]
Alternative 50
Error61.6
Cost64
\[-1\]

Error

Derivation

  1. Split input into 3 regimes
  2. if b < -9.9342535108088619e120

    1. Initial program 51.6

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

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

      \[\leadsto \color{blue}{\frac{c}{b} - \frac{b}{a}}\]
    4. Simplified2.8

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

    if -9.9342535108088619e120 < b < 2.7658541670298186e-38

    1. Initial program 13.5

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

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

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

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

    if 2.7658541670298186e-38 < b

    1. Initial program 54.8

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

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

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

      \[\leadsto \color{blue}{-\frac{c}{b}}\]
    5. Simplified7.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -9.934253510808862 \cdot 10^{+120}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 2.7658541670298186 \cdot 10^{-38}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}{a \cdot 2} - \frac{b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

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

  :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)))