Average Error: 34.7 → 9.3
Time: 2.1min
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 -0.12367712522464153:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq -8.356600830588859 \cdot 10^{-253}:\\ \;\;\;\;-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 6.584163964176897 \cdot 10^{+58}:\\ \;\;\;\;\frac{-0.5 \cdot \left(b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}\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 -0.12367712522464153:\\
\;\;\;\;-\frac{c}{b}\\

\mathbf{elif}\;b \leq -8.356600830588859 \cdot 10^{-253}:\\
\;\;\;\;-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 6.584163964176897 \cdot 10^{+58}:\\
\;\;\;\;\frac{-0.5 \cdot \left(b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}\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 -0.12367712522464153)
   (- (/ c b))
   (if (<= b -8.356600830588859e-253)
     (*
      -0.5
      (/ (/ (* 4.0 (* c a)) (- b (sqrt (- (* b b) (* 4.0 (* c a)))))) a))
     (if (<= b 6.584163964176897e+58)
       (/ (* -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 <= -0.12367712522464153) {
		tmp = -(c / b);
	} else if (b <= -8.356600830588859e-253) {
		tmp = -0.5 * (((4.0 * (c * a)) / (b - sqrt((b * b) - (4.0 * (c * a))))) / a);
	} else if (b <= 6.584163964176897e+58) {
		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.7
Target21.3
Herbie9.3
\[\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.9
Cost8451
\[\begin{array}{l} \mathbf{if}\;b \leq -6.950881560457148:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq -3.3145832091508264 \cdot 10^{-133}:\\ \;\;\;\;\frac{4 \cdot \left(c \cdot a\right)}{\left(\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b\right) \cdot \left(a \cdot 2\right)}\\ \mathbf{elif}\;b \leq 6.584163964176897 \cdot 10^{+58}:\\ \;\;\;\;-0.5 \cdot \left(\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a} + \frac{b}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\]
Alternative 2
Error10.5
Cost8130
\[\begin{array}{l} \mathbf{if}\;b \leq -1.7658993441531842 \cdot 10^{-99}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq 6.584163964176897 \cdot 10^{+58}:\\ \;\;\;\;-0.5 \cdot \left(\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a} + \frac{b}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\]
Alternative 3
Error10.5
Cost8002
\[\begin{array}{l} \mathbf{if}\;b \leq -2.22034042432551 \cdot 10^{-99}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq 2.3018188694599006 \cdot 10^{+58}:\\ \;\;\;\;\frac{-0.5 \cdot \left(b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\]
Alternative 4
Error13.6
Cost7746
\[\begin{array}{l} \mathbf{if}\;b \leq -1.7968403855442245 \cdot 10^{-100}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq 1.3902737789955247 \cdot 10^{-26}:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{a \cdot \left(c \cdot -4\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]
Alternative 5
Error14.0
Cost7618
\[\begin{array}{l} \mathbf{if}\;b \leq -1.798231941782608 \cdot 10^{-99}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq 3.5241943098311867 \cdot 10^{-28}:\\ \;\;\;\;-0.5 \cdot \frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]
Alternative 6
Error22.1
Cost769
\[\begin{array}{l} \mathbf{if}\;b \leq -5.555147341543503 \cdot 10^{-303}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]
Alternative 7
Error22.1
Cost577
\[\begin{array}{l} \mathbf{if}\;b \leq -8.816227157884985 \cdot 10^{-240}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\]
Alternative 8
Error39.2
Cost256
\[-\frac{c}{b}\]
Alternative 9
Error56.3
Cost64
\[0\]
Alternative 10
Error61.6
Cost64
\[1\]

Error

Time

Derivation

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

    1. Initial program 55.5

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

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

      \[\leadsto \color{blue}{-\frac{c}{b}}\]
    4. Simplified5.9

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

    if -0.12367712522464153 < b < -8.35660083058885925e-253

    1. Initial program 29.7

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

      \[\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 flip-+_binary64_107529.7

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

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

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

    if -8.35660083058885925e-253 < b < 6.58416396417689721e58

    1. Initial program 10.3

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity_binary64_110110.3

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

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

      \[\leadsto \frac{\left(-b\right) - \color{blue}{1} \cdot \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    6. Using strategy rm
    7. Applied add-sqr-sqrt_binary64_112310.3

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

      \[\leadsto \frac{\left(-b\right) - 1 \cdot \color{blue}{\left|\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right|}}{2 \cdot a}\]
    9. Using strategy rm
    10. Applied associate-/r*_binary64_104510.3

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

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

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

    if 6.58416396417689721e58 < b

    1. Initial program 39.1

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -0.12367712522464153:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq -8.356600830588859 \cdot 10^{-253}:\\ \;\;\;\;-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 6.584163964176897 \cdot 10^{+58}:\\ \;\;\;\;\frac{-0.5 \cdot \left(b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\]

Reproduce

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