Average Error: 33.1 → 9.3
Time: 1.3m
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 -1.6405873985286624 \cdot 10^{+100}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 3.369909182519315 \cdot 10^{-189}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}\\ \mathbf{elif}\;b \le 538194855109.15985:\\ \;\;\;\;-\frac{\frac{\left(4 \cdot a\right) \cdot c}{\frac{a}{\frac{1}{2}}}}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b}\\ \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 -1.6405873985286624 \cdot 10^{+100}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r5723005 = b;
        double r5723006 = -r5723005;
        double r5723007 = r5723005 * r5723005;
        double r5723008 = 4.0;
        double r5723009 = a;
        double r5723010 = c;
        double r5723011 = r5723009 * r5723010;
        double r5723012 = r5723008 * r5723011;
        double r5723013 = r5723007 - r5723012;
        double r5723014 = sqrt(r5723013);
        double r5723015 = r5723006 + r5723014;
        double r5723016 = 2.0;
        double r5723017 = r5723016 * r5723009;
        double r5723018 = r5723015 / r5723017;
        return r5723018;
}

double f(double a, double b, double c) {
        double r5723019 = b;
        double r5723020 = -1.6405873985286624e+100;
        bool r5723021 = r5723019 <= r5723020;
        double r5723022 = c;
        double r5723023 = r5723022 / r5723019;
        double r5723024 = a;
        double r5723025 = r5723019 / r5723024;
        double r5723026 = r5723023 - r5723025;
        double r5723027 = 3.369909182519315e-189;
        bool r5723028 = r5723019 <= r5723027;
        double r5723029 = 1.0;
        double r5723030 = 2.0;
        double r5723031 = r5723024 * r5723030;
        double r5723032 = r5723019 * r5723019;
        double r5723033 = 4.0;
        double r5723034 = r5723033 * r5723024;
        double r5723035 = r5723034 * r5723022;
        double r5723036 = r5723032 - r5723035;
        double r5723037 = sqrt(r5723036);
        double r5723038 = r5723037 - r5723019;
        double r5723039 = r5723031 / r5723038;
        double r5723040 = r5723029 / r5723039;
        double r5723041 = 538194855109.15985;
        bool r5723042 = r5723019 <= r5723041;
        double r5723043 = 0.5;
        double r5723044 = r5723024 / r5723043;
        double r5723045 = r5723035 / r5723044;
        double r5723046 = r5723037 + r5723019;
        double r5723047 = r5723045 / r5723046;
        double r5723048 = -r5723047;
        double r5723049 = -r5723023;
        double r5723050 = r5723042 ? r5723048 : r5723049;
        double r5723051 = r5723028 ? r5723040 : r5723050;
        double r5723052 = r5723021 ? r5723026 : r5723051;
        return r5723052;
}

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.2
Herbie9.3
\[\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 < -1.6405873985286624e+100

    1. Initial program 45.5

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

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

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

    if -1.6405873985286624e+100 < b < 3.369909182519315e-189

    1. Initial program 10.3

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

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

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

      \[\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.4

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

    if 3.369909182519315e-189 < b < 538194855109.15985

    1. Initial program 32.9

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

      \[\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-identity32.9

      \[\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-identity32.9

      \[\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--32.9

      \[\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*32.9

      \[\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 flip--33.0

      \[\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}}}}\]
    10. Applied associate-/r/33.1

      \[\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)}}\]
    11. Applied associate-/r*33.1

      \[\leadsto \color{blue}{\frac{\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}}}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b}}\]
    12. Simplified19.1

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

    if 538194855109.15985 < b

    1. Initial program 54.5

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.6405873985286624 \cdot 10^{+100}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 3.369909182519315 \cdot 10^{-189}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}\\ \mathbf{elif}\;b \le 538194855109.15985:\\ \;\;\;\;-\frac{\frac{\left(4 \cdot a\right) \cdot c}{\frac{a}{\frac{1}{2}}}}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

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