Average Error: 34.1 → 9.0
Time: 23.0s
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 -2.122942397323538653087473965252285768999 \cdot 10^{137}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le -3.408354642852288642375909774932644593067 \cdot 10^{-45}:\\ \;\;\;\;\frac{\frac{\left(b \cdot b - b \cdot b\right) + a \cdot \left(4 \cdot c\right)}{a \cdot 2}}{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} + \left(-b\right)}\\ \mathbf{elif}\;b \le -5.546621280225112292650318866994441138678 \cdot 10^{-56}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le 2.823335453796603439248590818149160856749 \cdot 10^{131}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \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 -2.122942397323538653087473965252285768999 \cdot 10^{137}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\

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

\mathbf{elif}\;b \le -5.546621280225112292650318866994441138678 \cdot 10^{-56}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\

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

\mathbf{else}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

\end{array}
double f(double a, double b, double c) {
        double r3965263 = b;
        double r3965264 = -r3965263;
        double r3965265 = r3965263 * r3965263;
        double r3965266 = 4.0;
        double r3965267 = a;
        double r3965268 = c;
        double r3965269 = r3965267 * r3965268;
        double r3965270 = r3965266 * r3965269;
        double r3965271 = r3965265 - r3965270;
        double r3965272 = sqrt(r3965271);
        double r3965273 = r3965264 - r3965272;
        double r3965274 = 2.0;
        double r3965275 = r3965274 * r3965267;
        double r3965276 = r3965273 / r3965275;
        return r3965276;
}

double f(double a, double b, double c) {
        double r3965277 = b;
        double r3965278 = -2.1229423973235387e+137;
        bool r3965279 = r3965277 <= r3965278;
        double r3965280 = -1.0;
        double r3965281 = c;
        double r3965282 = r3965281 / r3965277;
        double r3965283 = r3965280 * r3965282;
        double r3965284 = -3.4083546428522886e-45;
        bool r3965285 = r3965277 <= r3965284;
        double r3965286 = r3965277 * r3965277;
        double r3965287 = r3965286 - r3965286;
        double r3965288 = a;
        double r3965289 = 4.0;
        double r3965290 = r3965289 * r3965281;
        double r3965291 = r3965288 * r3965290;
        double r3965292 = r3965287 + r3965291;
        double r3965293 = 2.0;
        double r3965294 = r3965288 * r3965293;
        double r3965295 = r3965292 / r3965294;
        double r3965296 = r3965289 * r3965288;
        double r3965297 = r3965281 * r3965296;
        double r3965298 = r3965286 - r3965297;
        double r3965299 = sqrt(r3965298);
        double r3965300 = -r3965277;
        double r3965301 = r3965299 + r3965300;
        double r3965302 = r3965295 / r3965301;
        double r3965303 = -5.546621280225112e-56;
        bool r3965304 = r3965277 <= r3965303;
        double r3965305 = 2.8233354537966034e+131;
        bool r3965306 = r3965277 <= r3965305;
        double r3965307 = r3965300 - r3965299;
        double r3965308 = r3965307 / r3965294;
        double r3965309 = 1.0;
        double r3965310 = r3965277 / r3965288;
        double r3965311 = r3965282 - r3965310;
        double r3965312 = r3965309 * r3965311;
        double r3965313 = r3965306 ? r3965308 : r3965312;
        double r3965314 = r3965304 ? r3965283 : r3965313;
        double r3965315 = r3965285 ? r3965302 : r3965314;
        double r3965316 = r3965279 ? r3965283 : r3965315;
        return r3965316;
}

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.1
Target21.1
Herbie9.0
\[\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 < -2.1229423973235387e+137 or -3.4083546428522886e-45 < b < -5.546621280225112e-56

    1. Initial program 61.6

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

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

    if -2.1229423973235387e+137 < b < -3.4083546428522886e-45

    1. Initial program 45.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 associate-*r*45.3

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

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

      \[\leadsto \color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}} \cdot \frac{1}{2 \cdot a}\]
    8. Applied associate-*l/45.4

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

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

    if -5.546621280225112e-56 < b < 2.8233354537966034e+131

    1. Initial program 12.6

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

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

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

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

    if 2.8233354537966034e+131 < b

    1. Initial program 56.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 associate-*r*56.4

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.122942397323538653087473965252285768999 \cdot 10^{137}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le -3.408354642852288642375909774932644593067 \cdot 10^{-45}:\\ \;\;\;\;\frac{\frac{\left(b \cdot b - b \cdot b\right) + a \cdot \left(4 \cdot c\right)}{a \cdot 2}}{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} + \left(-b\right)}\\ \mathbf{elif}\;b \le -5.546621280225112292650318866994441138678 \cdot 10^{-56}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le 2.823335453796603439248590818149160856749 \cdot 10^{131}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019174 +o rules:numerics
(FPCore (a b c)
  :name "quadm (p42, negative)"

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