Average Error: 33.4 → 9.9
Time: 18.9s
Precision: 64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -5.148407540792454 \cdot 10^{+110}:\\ \;\;\;\;\frac{\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 2}{2}\\ \mathbf{elif}\;b \le 2.326372645943808 \cdot 10^{-74}:\\ \;\;\;\;\frac{\frac{1}{a} \cdot \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - \frac{b}{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{c}{b} \cdot -2}{2}\\ \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 \le -5.148407540792454 \cdot 10^{+110}:\\
\;\;\;\;\frac{\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 2}{2}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r1763445 = b;
        double r1763446 = -r1763445;
        double r1763447 = r1763445 * r1763445;
        double r1763448 = 4.0;
        double r1763449 = a;
        double r1763450 = r1763448 * r1763449;
        double r1763451 = c;
        double r1763452 = r1763450 * r1763451;
        double r1763453 = r1763447 - r1763452;
        double r1763454 = sqrt(r1763453);
        double r1763455 = r1763446 + r1763454;
        double r1763456 = 2.0;
        double r1763457 = r1763456 * r1763449;
        double r1763458 = r1763455 / r1763457;
        return r1763458;
}

double f(double a, double b, double c) {
        double r1763459 = b;
        double r1763460 = -5.148407540792454e+110;
        bool r1763461 = r1763459 <= r1763460;
        double r1763462 = c;
        double r1763463 = r1763462 / r1763459;
        double r1763464 = a;
        double r1763465 = r1763459 / r1763464;
        double r1763466 = r1763463 - r1763465;
        double r1763467 = 2.0;
        double r1763468 = r1763466 * r1763467;
        double r1763469 = r1763468 / r1763467;
        double r1763470 = 2.326372645943808e-74;
        bool r1763471 = r1763459 <= r1763470;
        double r1763472 = 1.0;
        double r1763473 = r1763472 / r1763464;
        double r1763474 = r1763459 * r1763459;
        double r1763475 = 4.0;
        double r1763476 = r1763462 * r1763464;
        double r1763477 = r1763475 * r1763476;
        double r1763478 = r1763474 - r1763477;
        double r1763479 = sqrt(r1763478);
        double r1763480 = r1763473 * r1763479;
        double r1763481 = r1763480 - r1763465;
        double r1763482 = r1763481 / r1763467;
        double r1763483 = -2.0;
        double r1763484 = r1763463 * r1763483;
        double r1763485 = r1763484 / r1763467;
        double r1763486 = r1763471 ? r1763482 : r1763485;
        double r1763487 = r1763461 ? r1763469 : r1763486;
        return r1763487;
}

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.4
Target20.3
Herbie9.9
\[\begin{array}{l} \mathbf{if}\;b \lt 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}\]

Derivation

  1. Split input into 3 regimes
  2. if b < -5.148407540792454e+110

    1. Initial program 46.9

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

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

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

      \[\leadsto \frac{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}}{\color{blue}{1 \cdot a}} - \frac{b}{a}}{2}\]
    7. Applied add-sqr-sqrt46.9

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

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

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

      \[\leadsto \frac{\color{blue}{2 \cdot \frac{c}{b} - 2 \cdot \frac{b}{a}}}{2}\]
    11. Simplified3.6

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

    if -5.148407540792454e+110 < b < 2.326372645943808e-74

    1. Initial program 12.8

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

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

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

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

    if 2.326372645943808e-74 < b

    1. Initial program 52.5

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

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

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

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

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

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

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

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

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

Reproduce

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

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