Average Error: 34.1 → 6.7
Time: 29.3s
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 -4.463381827278506 \cdot 10^{+97}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le -2.7394104193355045 \cdot 10^{-295}:\\ \;\;\;\;\frac{1}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b} \cdot \left(2 \cdot c\right)\\ \mathbf{elif}\;b \le 4.0392005370549217 \cdot 10^{+149}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \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 -4.463381827278506 \cdot 10^{+97}:\\
\;\;\;\;-\frac{c}{b}\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r4236103 = b;
        double r4236104 = -r4236103;
        double r4236105 = r4236103 * r4236103;
        double r4236106 = 4.0;
        double r4236107 = a;
        double r4236108 = c;
        double r4236109 = r4236107 * r4236108;
        double r4236110 = r4236106 * r4236109;
        double r4236111 = r4236105 - r4236110;
        double r4236112 = sqrt(r4236111);
        double r4236113 = r4236104 - r4236112;
        double r4236114 = 2.0;
        double r4236115 = r4236114 * r4236107;
        double r4236116 = r4236113 / r4236115;
        return r4236116;
}

double f(double a, double b, double c) {
        double r4236117 = b;
        double r4236118 = -4.463381827278506e+97;
        bool r4236119 = r4236117 <= r4236118;
        double r4236120 = c;
        double r4236121 = r4236120 / r4236117;
        double r4236122 = -r4236121;
        double r4236123 = -2.7394104193355045e-295;
        bool r4236124 = r4236117 <= r4236123;
        double r4236125 = 1.0;
        double r4236126 = r4236117 * r4236117;
        double r4236127 = 4.0;
        double r4236128 = a;
        double r4236129 = r4236128 * r4236120;
        double r4236130 = r4236127 * r4236129;
        double r4236131 = r4236126 - r4236130;
        double r4236132 = sqrt(r4236131);
        double r4236133 = r4236132 - r4236117;
        double r4236134 = r4236125 / r4236133;
        double r4236135 = 2.0;
        double r4236136 = r4236135 * r4236120;
        double r4236137 = r4236134 * r4236136;
        double r4236138 = 4.0392005370549217e+149;
        bool r4236139 = r4236117 <= r4236138;
        double r4236140 = r4236128 * r4236135;
        double r4236141 = -r4236117;
        double r4236142 = r4236141 - r4236132;
        double r4236143 = r4236140 / r4236142;
        double r4236144 = r4236125 / r4236143;
        double r4236145 = r4236117 / r4236128;
        double r4236146 = r4236121 - r4236145;
        double r4236147 = r4236139 ? r4236144 : r4236146;
        double r4236148 = r4236124 ? r4236137 : r4236147;
        double r4236149 = r4236119 ? r4236122 : r4236148;
        return r4236149;
}

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.1
Target21.0
Herbie6.7
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \mathbf{else}:\\ \;\;\;\;\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 < -4.463381827278506e+97

    1. Initial program 58.7

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Taylor expanded around -inf 2.1

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

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

    if -4.463381827278506e+97 < b < -2.7394104193355045e-295

    1. Initial program 32.9

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

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

      \[\leadsto \frac{\left(-\color{blue}{1 \cdot b}\right) - 1 \cdot \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    5. Applied distribute-rgt-neg-in32.9

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

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

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

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

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

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

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

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

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

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

    if -2.7394104193355045e-295 < b < 4.0392005370549217e+149

    1. Initial program 9.4

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

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

      \[\leadsto \frac{\left(-\color{blue}{1 \cdot b}\right) - 1 \cdot \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    5. Applied distribute-rgt-neg-in9.4

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

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

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

    if 4.0392005370549217e+149 < b

    1. Initial program 59.1

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Taylor expanded around inf 2.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -4.463381827278506 \cdot 10^{+97}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le -2.7394104193355045 \cdot 10^{-295}:\\ \;\;\;\;\frac{1}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b} \cdot \left(2 \cdot c\right)\\ \mathbf{elif}\;b \le 4.0392005370549217 \cdot 10^{+149}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< b 0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))

  (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))