Average Error: 34.5 → 6.5
Time: 8.2s
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 -5.52306947897632778228201833866057110671 \cdot 10^{123}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -8.219482842591944840806672041838142939496 \cdot 10^{-296}:\\ \;\;\;\;\frac{\sqrt[3]{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt[3]{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2} \cdot \frac{\sqrt[3]{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{a}\\ \mathbf{elif}\;b \le 1.372075260173852414460256827675964027367 \cdot 10^{126}:\\ \;\;\;\;1 \cdot \frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \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 -5.52306947897632778228201833866057110671 \cdot 10^{123}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

\mathbf{elif}\;b \le -8.219482842591944840806672041838142939496 \cdot 10^{-296}:\\
\;\;\;\;\frac{\sqrt[3]{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt[3]{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2} \cdot \frac{\sqrt[3]{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{a}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r148845 = b;
        double r148846 = -r148845;
        double r148847 = r148845 * r148845;
        double r148848 = 4.0;
        double r148849 = a;
        double r148850 = r148848 * r148849;
        double r148851 = c;
        double r148852 = r148850 * r148851;
        double r148853 = r148847 - r148852;
        double r148854 = sqrt(r148853);
        double r148855 = r148846 + r148854;
        double r148856 = 2.0;
        double r148857 = r148856 * r148849;
        double r148858 = r148855 / r148857;
        return r148858;
}

double f(double a, double b, double c) {
        double r148859 = b;
        double r148860 = -5.523069478976328e+123;
        bool r148861 = r148859 <= r148860;
        double r148862 = 1.0;
        double r148863 = c;
        double r148864 = r148863 / r148859;
        double r148865 = a;
        double r148866 = r148859 / r148865;
        double r148867 = r148864 - r148866;
        double r148868 = r148862 * r148867;
        double r148869 = -8.219482842591945e-296;
        bool r148870 = r148859 <= r148869;
        double r148871 = -r148859;
        double r148872 = r148859 * r148859;
        double r148873 = 4.0;
        double r148874 = r148873 * r148865;
        double r148875 = r148874 * r148863;
        double r148876 = r148872 - r148875;
        double r148877 = sqrt(r148876);
        double r148878 = r148871 + r148877;
        double r148879 = cbrt(r148878);
        double r148880 = r148879 * r148879;
        double r148881 = 2.0;
        double r148882 = r148880 / r148881;
        double r148883 = r148879 / r148865;
        double r148884 = r148882 * r148883;
        double r148885 = 1.3720752601738524e+126;
        bool r148886 = r148859 <= r148885;
        double r148887 = 1.0;
        double r148888 = r148881 * r148863;
        double r148889 = r148871 - r148877;
        double r148890 = r148888 / r148889;
        double r148891 = r148887 * r148890;
        double r148892 = -1.0;
        double r148893 = r148892 * r148864;
        double r148894 = r148886 ? r148891 : r148893;
        double r148895 = r148870 ? r148884 : r148894;
        double r148896 = r148861 ? r148868 : r148895;
        return r148896;
}

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.5
Target21.5
Herbie6.5
\[\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 4 regimes
  2. if b < -5.523069478976328e+123

    1. Initial program 54.0

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

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

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

    if -5.523069478976328e+123 < b < -8.219482842591945e-296

    1. Initial program 8.1

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied add-cube-cbrt9.2

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

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

    if -8.219482842591945e-296 < b < 1.3720752601738524e+126

    1. Initial program 33.6

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied flip-+33.6

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

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

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

      \[\leadsto \color{blue}{\left(1 \cdot \frac{0 + 4 \cdot \left(a \cdot c\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\right)} \cdot \frac{1}{2 \cdot a}\]
    9. Applied associate-*l*16.5

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

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

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

    if 1.3720752601738524e+126 < b

    1. Initial program 60.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -5.52306947897632778228201833866057110671 \cdot 10^{123}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -8.219482842591944840806672041838142939496 \cdot 10^{-296}:\\ \;\;\;\;\frac{\sqrt[3]{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt[3]{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2} \cdot \frac{\sqrt[3]{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{a}\\ \mathbf{elif}\;b \le 1.372075260173852414460256827675964027367 \cdot 10^{126}:\\ \;\;\;\;1 \cdot \frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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