Average Error: 34.1 → 9.4
Time: 17.5s
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.356959927988237168348139414849710212524 \cdot 10^{-56}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le 3.087668654677018032633364446323411964642 \cdot 10^{130}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \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.356959927988237168348139414849710212524 \cdot 10^{-56}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\

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

\mathbf{else}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

\end{array}
double f(double a, double b, double c) {
        double r3810884 = b;
        double r3810885 = -r3810884;
        double r3810886 = r3810884 * r3810884;
        double r3810887 = 4.0;
        double r3810888 = a;
        double r3810889 = c;
        double r3810890 = r3810888 * r3810889;
        double r3810891 = r3810887 * r3810890;
        double r3810892 = r3810886 - r3810891;
        double r3810893 = sqrt(r3810892);
        double r3810894 = r3810885 - r3810893;
        double r3810895 = 2.0;
        double r3810896 = r3810895 * r3810888;
        double r3810897 = r3810894 / r3810896;
        return r3810897;
}

double f(double a, double b, double c) {
        double r3810898 = b;
        double r3810899 = -4.356959927988237e-56;
        bool r3810900 = r3810898 <= r3810899;
        double r3810901 = -1.0;
        double r3810902 = c;
        double r3810903 = r3810902 / r3810898;
        double r3810904 = r3810901 * r3810903;
        double r3810905 = 3.087668654677018e+130;
        bool r3810906 = r3810898 <= r3810905;
        double r3810907 = -r3810898;
        double r3810908 = r3810898 * r3810898;
        double r3810909 = 4.0;
        double r3810910 = a;
        double r3810911 = r3810909 * r3810910;
        double r3810912 = r3810902 * r3810911;
        double r3810913 = r3810908 - r3810912;
        double r3810914 = sqrt(r3810913);
        double r3810915 = r3810907 - r3810914;
        double r3810916 = 2.0;
        double r3810917 = r3810916 * r3810910;
        double r3810918 = r3810915 / r3810917;
        double r3810919 = 1.0;
        double r3810920 = r3810898 / r3810910;
        double r3810921 = r3810903 - r3810920;
        double r3810922 = r3810919 * r3810921;
        double r3810923 = r3810906 ? r3810918 : r3810922;
        double r3810924 = r3810900 ? r3810904 : r3810923;
        return r3810924;
}

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.1
Herbie9.4
\[\begin{array}{l} \mathbf{if}\;b \lt 0.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 3 regimes
  2. if b < -4.356959927988237e-56

    1. Initial program 54.0

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

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

    if -4.356959927988237e-56 < b < 3.087668654677018e+130

    1. Initial program 12.6

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

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

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

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

    if 3.087668654677018e+130 < b

    1. Initial program 56.2

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

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

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

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

Reproduce

herbie shell --seed 2019174 
(FPCore (a b c)
  :name "quadm (p42, negative)"

  :herbie-target
  (if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))

  (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))