Average Error: 34.2 → 10.4
Time: 13.3s
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 -4.12310353364421125 \cdot 10^{95}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 3.446447862996811 \cdot 10^{-75}:\\ \;\;\;\;\frac{1}{\frac{a}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \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 -4.12310353364421125 \cdot 10^{95}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r153020 = b;
        double r153021 = -r153020;
        double r153022 = r153020 * r153020;
        double r153023 = 4.0;
        double r153024 = a;
        double r153025 = r153023 * r153024;
        double r153026 = c;
        double r153027 = r153025 * r153026;
        double r153028 = r153022 - r153027;
        double r153029 = sqrt(r153028);
        double r153030 = r153021 + r153029;
        double r153031 = 2.0;
        double r153032 = r153031 * r153024;
        double r153033 = r153030 / r153032;
        return r153033;
}

double f(double a, double b, double c) {
        double r153034 = b;
        double r153035 = -4.123103533644211e+95;
        bool r153036 = r153034 <= r153035;
        double r153037 = 1.0;
        double r153038 = c;
        double r153039 = r153038 / r153034;
        double r153040 = a;
        double r153041 = r153034 / r153040;
        double r153042 = r153039 - r153041;
        double r153043 = r153037 * r153042;
        double r153044 = 3.446447862996811e-75;
        bool r153045 = r153034 <= r153044;
        double r153046 = 1.0;
        double r153047 = r153034 * r153034;
        double r153048 = 4.0;
        double r153049 = r153048 * r153040;
        double r153050 = r153049 * r153038;
        double r153051 = r153047 - r153050;
        double r153052 = sqrt(r153051);
        double r153053 = r153052 - r153034;
        double r153054 = 2.0;
        double r153055 = r153053 / r153054;
        double r153056 = r153040 / r153055;
        double r153057 = r153046 / r153056;
        double r153058 = -1.0;
        double r153059 = r153058 * r153039;
        double r153060 = r153045 ? r153057 : r153059;
        double r153061 = r153036 ? r153043 : r153060;
        return r153061;
}

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.2
Target21.1
Herbie10.4
\[\begin{array}{l} \mathbf{if}\;b \lt 0.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 < -4.123103533644211e+95

    1. Initial program 47.3

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

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

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

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

    if -4.123103533644211e+95 < b < 3.446447862996811e-75

    1. Initial program 13.3

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

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

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

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

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

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

    if 3.446447862996811e-75 < 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(4 \cdot a\right) \cdot c} - b}{2}}{a}}\]
    3. Taylor expanded around inf 9.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -4.12310353364421125 \cdot 10^{95}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 3.446447862996811 \cdot 10^{-75}:\\ \;\;\;\;\frac{1}{\frac{a}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< b 0.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)))