Average Error: 33.5 → 8.8
Time: 48.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 -5.4077460761521334 \cdot 10^{+100}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 9.200893940383185 \cdot 10^{-150}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + \left(-b\right)}}\\ \mathbf{elif}\;b \le 2.1530452932539196 \cdot 10^{-07}:\\ \;\;\;\;\frac{\frac{c \cdot a}{\frac{-1}{2}}}{a} \cdot \frac{-1}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \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 -5.4077460761521334 \cdot 10^{+100}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r8588949 = b;
        double r8588950 = -r8588949;
        double r8588951 = r8588949 * r8588949;
        double r8588952 = 4.0;
        double r8588953 = a;
        double r8588954 = c;
        double r8588955 = r8588953 * r8588954;
        double r8588956 = r8588952 * r8588955;
        double r8588957 = r8588951 - r8588956;
        double r8588958 = sqrt(r8588957);
        double r8588959 = r8588950 + r8588958;
        double r8588960 = 2.0;
        double r8588961 = r8588960 * r8588953;
        double r8588962 = r8588959 / r8588961;
        return r8588962;
}

double f(double a, double b, double c) {
        double r8588963 = b;
        double r8588964 = -5.4077460761521334e+100;
        bool r8588965 = r8588963 <= r8588964;
        double r8588966 = c;
        double r8588967 = r8588966 / r8588963;
        double r8588968 = a;
        double r8588969 = r8588963 / r8588968;
        double r8588970 = r8588967 - r8588969;
        double r8588971 = 9.200893940383185e-150;
        bool r8588972 = r8588963 <= r8588971;
        double r8588973 = 1.0;
        double r8588974 = 2.0;
        double r8588975 = r8588968 * r8588974;
        double r8588976 = r8588963 * r8588963;
        double r8588977 = 4.0;
        double r8588978 = r8588966 * r8588968;
        double r8588979 = r8588977 * r8588978;
        double r8588980 = r8588976 - r8588979;
        double r8588981 = sqrt(r8588980);
        double r8588982 = -r8588963;
        double r8588983 = r8588981 + r8588982;
        double r8588984 = r8588975 / r8588983;
        double r8588985 = r8588973 / r8588984;
        double r8588986 = 2.1530452932539196e-07;
        bool r8588987 = r8588963 <= r8588986;
        double r8588988 = -0.5;
        double r8588989 = r8588978 / r8588988;
        double r8588990 = r8588989 / r8588968;
        double r8588991 = -1.0;
        double r8588992 = r8588982 - r8588981;
        double r8588993 = r8588991 / r8588992;
        double r8588994 = r8588990 * r8588993;
        double r8588995 = -r8588967;
        double r8588996 = r8588987 ? r8588994 : r8588995;
        double r8588997 = r8588972 ? r8588985 : r8588996;
        double r8588998 = r8588965 ? r8588970 : r8588997;
        return r8588998;
}

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

Original33.5
Target20.4
Herbie8.8
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \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 < -5.4077460761521334e+100

    1. Initial program 44.3

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

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

    if -5.4077460761521334e+100 < b < 9.200893940383185e-150

    1. Initial program 10.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-identity10.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-identity10.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}\]
    5. Applied distribute-lft-out10.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}\]
    6. Applied associate-/l*11.1

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

    if 9.200893940383185e-150 < b < 2.1530452932539196e-07

    1. Initial program 32.2

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

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

      \[\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}\]
    5. Applied distribute-lft-out32.2

      \[\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}\]
    6. Applied associate-/l*32.2

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

      \[\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)}}}}}\]
    9. Applied associate-/r/32.4

      \[\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)}}\]
    10. Applied add-sqr-sqrt32.4

      \[\leadsto \frac{\color{blue}{\sqrt{1} \cdot \sqrt{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)}\]
    11. Applied times-frac32.4

      \[\leadsto \color{blue}{\frac{\sqrt{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{\sqrt{1}}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}\]
    12. Simplified16.6

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

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

    if 2.1530452932539196e-07 < b

    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 6.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -5.4077460761521334 \cdot 10^{+100}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 9.200893940383185 \cdot 10^{-150}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + \left(-b\right)}}\\ \mathbf{elif}\;b \le 2.1530452932539196 \cdot 10^{-07}:\\ \;\;\;\;\frac{\frac{c \cdot a}{\frac{-1}{2}}}{a} \cdot \frac{-1}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019104 
(FPCore (a b c)
  :name "quadp (p42, positive)"

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