Average Error: 34.2 → 9.4
Time: 2.8min
Precision: binary64
Cost: 8386
\[\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 -1.615117109155005 \cdot 10^{+61}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq -1.3641711845431856 \cdot 10^{-290}:\\ \;\;\;\;\frac{\frac{a \cdot \left(c \cdot 4\right)}{\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b}}{a \cdot 2}\\ \mathbf{elif}\;b \leq 7.942031390488743 \cdot 10^{+46}:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;\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 -1.615117109155005 \cdot 10^{+61}:\\
\;\;\;\;-\frac{c}{b}\\

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

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

\mathbf{else}:\\
\;\;\;\;\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 -1.615117109155005e+61)
   (- (/ c b))
   (if (<= b -1.3641711845431856e-290)
     (/
      (/ (* a (* c 4.0)) (- (sqrt (+ (* b b) (* a (* c -4.0)))) b))
      (* a 2.0))
     (if (<= b 7.942031390488743e+46)
       (* -0.5 (/ (+ b (sqrt (- (* b b) (* 4.0 (* c a))))) a))
       (/ (- b) a)))))
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 <= -1.615117109155005e+61) {
		tmp = -(c / b);
	} else if (b <= -1.3641711845431856e-290) {
		tmp = ((a * (c * 4.0)) / (sqrt((b * b) + (a * (c * -4.0))) - b)) / (a * 2.0);
	} else if (b <= 7.942031390488743e+46) {
		tmp = -0.5 * ((b + sqrt((b * b) - (4.0 * (c * a)))) / a);
	} else {
		tmp = -b / a;
	}
	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.2
Target20.4
Herbie9.4
\[\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}\]

Alternatives

Alternative 1
Error9.3
Cost8386
\[\begin{array}{l} \mathbf{if}\;b \leq -1.688687182540498 \cdot 10^{+61}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq -1.1049660614135754 \cdot 10^{-164}:\\ \;\;\;\;-0.5 \cdot \frac{\frac{4 \cdot \left(c \cdot a\right)}{b - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}}{a}\\ \mathbf{elif}\;b \leq 7.942031390488743 \cdot 10^{+46}:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\]
Alternative 2
Error10.9
Cost8258
\[\begin{array}{l} \mathbf{if}\;b \leq -1.1914175080084799 \cdot 10^{-29}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq 6.852065077857368 \cdot 10^{+46}:\\ \;\;\;\;-0.5 \cdot \frac{b}{a} - \frac{\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\]
Alternative 3
Error10.9
Cost8002
\[\begin{array}{l} \mathbf{if}\;b \leq -1.1914175080084799 \cdot 10^{-29}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq 7.397048234173055 \cdot 10^{+46}:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\]
Alternative 4
Error11.0
Cost8002
\[\begin{array}{l} \mathbf{if}\;b \leq -1.165376592702905 \cdot 10^{-29}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq 3.932388830389278 \cdot 10^{+44}:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\]
Alternative 5
Error14.6
Cost9030
\[\begin{array}{l} \mathbf{if}\;b \leq -1.1132947620917554 \cdot 10^{-29}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq -2.0636023529259967 \cdot 10^{-75}:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{-4 \cdot \left(c \cdot a\right)}}{a}\\ \mathbf{elif}\;b \leq -1.0958056759141235 \cdot 10^{-103}:\\ \;\;\;\;\left(-\frac{c}{b}\right) - \frac{a \cdot \left(c \cdot c\right)}{{b}^{3}}\\ \mathbf{elif}\;b \leq 4.5456072667014904 \cdot 10^{-73}:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{a \cdot \left(c \cdot -4\right)}}{a}\\ \mathbf{elif}\;b \leq 5.941593363568897 \cdot 10^{-57}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 561226648.3438514:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{-4 \cdot \left(c \cdot a\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]
Alternative 6
Error14.5
Cost9030
\[\begin{array}{l} \mathbf{if}\;b \leq -1.1914175080084799 \cdot 10^{-29}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq -6.26166103267307 \cdot 10^{-66}:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{-4 \cdot \left(c \cdot a\right)}}{a}\\ \mathbf{elif}\;b \leq -8.470867209365325 \cdot 10^{-104}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq 3.076579487085727 \cdot 10^{-76}:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{a \cdot \left(c \cdot -4\right)}}{a}\\ \mathbf{elif}\;b \leq 5.941593363568897 \cdot 10^{-57}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 561226648.3438514:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{-4 \cdot \left(c \cdot a\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]
Alternative 7
Error14.5
Cost9030
\[\begin{array}{l} \mathbf{if}\;b \leq -1.0872538467861805 \cdot 10^{-29}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq -2.5727230087426245 \cdot 10^{-66}:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{-4 \cdot \left(c \cdot a\right)}}{a}\\ \mathbf{elif}\;b \leq -8.159968515643336 \cdot 10^{-104}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq 1.3969847469406258 \cdot 10^{-70}:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{-4 \cdot \left(c \cdot a\right)}}{a}\\ \mathbf{elif}\;b \leq 5.941593363568897 \cdot 10^{-57}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 561226648.3438514:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{-4 \cdot \left(c \cdot a\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]
Alternative 8
Error15.1
Cost8902
\[\begin{array}{l} \mathbf{if}\;b \leq -1.0872538467861805 \cdot 10^{-29}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq -2.551763611402685 \cdot 10^{-79}:\\ \;\;\;\;-0.5 \cdot \frac{\sqrt{-4 \cdot \left(c \cdot a\right)}}{a}\\ \mathbf{elif}\;b \leq -5.983677659589416 \cdot 10^{-104}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq 2.631871001127332 \cdot 10^{-70}:\\ \;\;\;\;-0.5 \cdot \frac{\sqrt{c \cdot \left(a \cdot -4\right)}}{a}\\ \mathbf{elif}\;b \leq 5.941593363568897 \cdot 10^{-57}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 561226648.3438514:\\ \;\;\;\;-0.5 \cdot \frac{\sqrt{-4 \cdot \left(c \cdot a\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]
Alternative 9
Error15.0
Cost8902
\[\begin{array}{l} \mathbf{if}\;b \leq -1.0872538467861805 \cdot 10^{-29}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq -6.972674796872848 \cdot 10^{-72}:\\ \;\;\;\;-0.5 \cdot \frac{\sqrt{-4 \cdot \left(c \cdot a\right)}}{a}\\ \mathbf{elif}\;b \leq -1.0647158065419246 \cdot 10^{-103}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq 3.2583865685001763 \cdot 10^{-76}:\\ \;\;\;\;-0.5 \cdot \frac{\sqrt{-4 \cdot \left(c \cdot a\right)}}{a}\\ \mathbf{elif}\;b \leq 5.941593363568897 \cdot 10^{-57}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 561226648.3438514:\\ \;\;\;\;-0.5 \cdot \frac{\sqrt{-4 \cdot \left(c \cdot a\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]
Alternative 10
Error22.6
Cost7169
\[\begin{array}{l} \mathbf{if}\;b \leq -3.081150325371919 \cdot 10^{-247}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{b + \left|b\right|}{a}\\ \end{array}\]
Alternative 11
Error22.6
Cost577
\[\begin{array}{l} \mathbf{if}\;b \leq -2.4090299573481037 \cdot 10^{-268}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\]
Alternative 12
Error39.6
Cost256
\[-\frac{c}{b}\]
Alternative 13
Error56.4
Cost64
\[0\]
Alternative 14
Error61.5
Cost64
\[-1\]

Error

Derivation

  1. Split input into 4 regimes
  2. if b < -1.615117109155005e61

    1. Initial program 57.8

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

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

      \[\leadsto \color{blue}{-\frac{c}{b}}\]
    4. Simplified3.7

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

    if -1.615117109155005e61 < b < -1.36417118454318557e-290

    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 sub-neg_binary64_75331.5

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

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

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

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

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

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

    if -1.36417118454318557e-290 < b < 7.94203139048874288e46

    1. Initial program 10.5

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

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

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

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

    if 7.94203139048874288e46 < b

    1. Initial program 36.4

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
    3. Simplified5.6

      \[\leadsto \color{blue}{\frac{-b}{a}}\]
    4. Simplified5.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.615117109155005 \cdot 10^{+61}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq -1.3641711845431856 \cdot 10^{-290}:\\ \;\;\;\;\frac{\frac{a \cdot \left(c \cdot 4\right)}{\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b}}{a \cdot 2}\\ \mathbf{elif}\;b \leq 7.942031390488743 \cdot 10^{+46}:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\]

Reproduce

herbie shell --seed 2021014 
(FPCore (a b c)
  :name "quadm (p42, negative)"
  :precision binary64
  :herbie-expected #f

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