Average Error: 34.3 → 10.1
Time: 17.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 -1.569310777886352095486911207889814773134 \cdot 10^{111}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 5.202443222624254327680309207854310362882 \cdot 10^{-45}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a \cdot 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 -1.569310777886352095486911207889814773134 \cdot 10^{111}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r106086 = b;
        double r106087 = -r106086;
        double r106088 = r106086 * r106086;
        double r106089 = 4.0;
        double r106090 = a;
        double r106091 = r106089 * r106090;
        double r106092 = c;
        double r106093 = r106091 * r106092;
        double r106094 = r106088 - r106093;
        double r106095 = sqrt(r106094);
        double r106096 = r106087 + r106095;
        double r106097 = 2.0;
        double r106098 = r106097 * r106090;
        double r106099 = r106096 / r106098;
        return r106099;
}

double f(double a, double b, double c) {
        double r106100 = b;
        double r106101 = -1.569310777886352e+111;
        bool r106102 = r106100 <= r106101;
        double r106103 = 1.0;
        double r106104 = c;
        double r106105 = r106104 / r106100;
        double r106106 = a;
        double r106107 = r106100 / r106106;
        double r106108 = r106105 - r106107;
        double r106109 = r106103 * r106108;
        double r106110 = 5.2024432226242543e-45;
        bool r106111 = r106100 <= r106110;
        double r106112 = r106100 * r106100;
        double r106113 = 4.0;
        double r106114 = r106113 * r106106;
        double r106115 = r106114 * r106104;
        double r106116 = r106112 - r106115;
        double r106117 = sqrt(r106116);
        double r106118 = r106117 - r106100;
        double r106119 = 2.0;
        double r106120 = r106106 * r106119;
        double r106121 = r106118 / r106120;
        double r106122 = -1.0;
        double r106123 = r106122 * r106105;
        double r106124 = r106111 ? r106121 : r106123;
        double r106125 = r106102 ? r106109 : r106124;
        return r106125;
}

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.3
Target21.1
Herbie10.1
\[\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 < -1.569310777886352e+111

    1. Initial program 50.4

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

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

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

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

    if -1.569310777886352e+111 < b < 5.2024432226242543e-45

    1. Initial program 14.0

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

      \[\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 clear-num14.1

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

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

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

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

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

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

    if 5.2024432226242543e-45 < b

    1. Initial program 54.5

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{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. Using strategy rm
    4. Applied clear-num54.5

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

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

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

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

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

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

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

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

Reproduce

herbie shell --seed 2019303 +o rules:numerics
(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)))