Average Error: 32.7 → 10.1
Time: 16.5s
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.34601621878688 \cdot 10^{+118}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 1.3115303715225787 \cdot 10^{-131}:\\ \;\;\;\;\frac{1}{a \cdot 2} \cdot \left(\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b\right)\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \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.34601621878688 \cdot 10^{+118}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

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

\mathbf{else}:\\
\;\;\;\;-\frac{c}{b}\\

\end{array}
double f(double a, double b, double c) {
        double r2238341 = b;
        double r2238342 = -r2238341;
        double r2238343 = r2238341 * r2238341;
        double r2238344 = 4.0;
        double r2238345 = a;
        double r2238346 = c;
        double r2238347 = r2238345 * r2238346;
        double r2238348 = r2238344 * r2238347;
        double r2238349 = r2238343 - r2238348;
        double r2238350 = sqrt(r2238349);
        double r2238351 = r2238342 + r2238350;
        double r2238352 = 2.0;
        double r2238353 = r2238352 * r2238345;
        double r2238354 = r2238351 / r2238353;
        return r2238354;
}

double f(double a, double b, double c) {
        double r2238355 = b;
        double r2238356 = -2.34601621878688e+118;
        bool r2238357 = r2238355 <= r2238356;
        double r2238358 = c;
        double r2238359 = r2238358 / r2238355;
        double r2238360 = a;
        double r2238361 = r2238355 / r2238360;
        double r2238362 = r2238359 - r2238361;
        double r2238363 = 1.3115303715225787e-131;
        bool r2238364 = r2238355 <= r2238363;
        double r2238365 = 1.0;
        double r2238366 = 2.0;
        double r2238367 = r2238360 * r2238366;
        double r2238368 = r2238365 / r2238367;
        double r2238369 = r2238355 * r2238355;
        double r2238370 = 4.0;
        double r2238371 = r2238370 * r2238360;
        double r2238372 = r2238358 * r2238371;
        double r2238373 = r2238369 - r2238372;
        double r2238374 = sqrt(r2238373);
        double r2238375 = r2238374 - r2238355;
        double r2238376 = r2238368 * r2238375;
        double r2238377 = -r2238359;
        double r2238378 = r2238364 ? r2238376 : r2238377;
        double r2238379 = r2238357 ? r2238362 : r2238378;
        return r2238379;
}

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

Original32.7
Target20.0
Herbie10.1
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \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 3 regimes
  2. if b < -2.34601621878688e+118

    1. Initial program 48.8

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

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

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

    if -2.34601621878688e+118 < b < 1.3115303715225787e-131

    1. Initial program 10.7

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

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

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

      \[\leadsto \frac{\color{blue}{1 \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} - 1 \cdot b}{2 \cdot a}\]
    6. Applied distribute-lft-out--10.7

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

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

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

    if 1.3115303715225787e-131 < b

    1. Initial program 50.3

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.34601621878688 \cdot 10^{+118}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 1.3115303715225787 \cdot 10^{-131}:\\ \;\;\;\;\frac{1}{a \cdot 2} \cdot \left(\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b\right)\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019134 
(FPCore (a b c)
  :name "quadp (p42, positive)"

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

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