Average Error: 33.1 → 6.6
Time: 56.9s
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.1884247920746475 \cdot 10^{+101}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le -1.6086609448752587 \cdot 10^{-299}:\\ \;\;\;\;\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} \cdot \frac{1}{a \cdot 2} - \frac{b}{a \cdot 2}\\ \mathbf{elif}\;b \le 9.34348145460108 \cdot 10^{+88}:\\ \;\;\;\;\frac{1}{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} + b} \cdot \left(c \cdot -2\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.1884247920746475 \cdot 10^{+101}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r3609683 = b;
        double r3609684 = -r3609683;
        double r3609685 = r3609683 * r3609683;
        double r3609686 = 4.0;
        double r3609687 = a;
        double r3609688 = c;
        double r3609689 = r3609687 * r3609688;
        double r3609690 = r3609686 * r3609689;
        double r3609691 = r3609685 - r3609690;
        double r3609692 = sqrt(r3609691);
        double r3609693 = r3609684 + r3609692;
        double r3609694 = 2.0;
        double r3609695 = r3609694 * r3609687;
        double r3609696 = r3609693 / r3609695;
        return r3609696;
}

double f(double a, double b, double c) {
        double r3609697 = b;
        double r3609698 = -2.1884247920746475e+101;
        bool r3609699 = r3609697 <= r3609698;
        double r3609700 = c;
        double r3609701 = r3609700 / r3609697;
        double r3609702 = a;
        double r3609703 = r3609697 / r3609702;
        double r3609704 = r3609701 - r3609703;
        double r3609705 = -1.6086609448752587e-299;
        bool r3609706 = r3609697 <= r3609705;
        double r3609707 = r3609697 * r3609697;
        double r3609708 = 4.0;
        double r3609709 = r3609702 * r3609708;
        double r3609710 = r3609709 * r3609700;
        double r3609711 = r3609707 - r3609710;
        double r3609712 = sqrt(r3609711);
        double r3609713 = 1.0;
        double r3609714 = 2.0;
        double r3609715 = r3609702 * r3609714;
        double r3609716 = r3609713 / r3609715;
        double r3609717 = r3609712 * r3609716;
        double r3609718 = r3609697 / r3609715;
        double r3609719 = r3609717 - r3609718;
        double r3609720 = 9.34348145460108e+88;
        bool r3609721 = r3609697 <= r3609720;
        double r3609722 = r3609712 + r3609697;
        double r3609723 = r3609713 / r3609722;
        double r3609724 = -2.0;
        double r3609725 = r3609700 * r3609724;
        double r3609726 = r3609723 * r3609725;
        double r3609727 = -r3609700;
        double r3609728 = r3609727 / r3609697;
        double r3609729 = r3609721 ? r3609726 : r3609728;
        double r3609730 = r3609706 ? r3609719 : r3609729;
        double r3609731 = r3609699 ? r3609704 : r3609730;
        return r3609731;
}

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.1
Target20.3
Herbie6.6
\[\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 4 regimes
  2. if b < -2.1884247920746475e+101

    1. Initial program 44.5

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

      \[\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 div-sub44.5

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

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

    if -2.1884247920746475e+101 < b < -1.6086609448752587e-299

    1. Initial program 8.7

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Simplified8.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 div-sub8.7

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

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

    if -1.6086609448752587e-299 < b < 9.34348145460108e+88

    1. Initial program 31.3

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

      \[\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-identity31.3

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

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

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

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

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

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

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

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

    if 9.34348145460108e+88 < b

    1. Initial program 57.8

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Simplified57.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 2.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.1884247920746475 \cdot 10^{+101}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le -1.6086609448752587 \cdot 10^{-299}:\\ \;\;\;\;\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} \cdot \frac{1}{a \cdot 2} - \frac{b}{a \cdot 2}\\ \mathbf{elif}\;b \le 9.34348145460108 \cdot 10^{+88}:\\ \;\;\;\;\frac{1}{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} + b} \cdot \left(c \cdot -2\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\]

Reproduce

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