Average Error: 33.3 → 6.4
Time: 1.3m
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 -3.263941314600607 \cdot 10^{+152}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le -4.687918346756617 \cdot 10^{-254}:\\ \;\;\;\;\frac{\left(\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b\right) \cdot \frac{1}{2}}{a}\\ \mathbf{elif}\;b \le 1.817261397602966 \cdot 10^{+121}:\\ \;\;\;\;\frac{c \cdot -2}{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} + b}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -2}{\left(b - \frac{c}{b} \cdot a\right) \cdot 2}\\ \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 -3.263941314600607 \cdot 10^{+152}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r5890034 = b;
        double r5890035 = -r5890034;
        double r5890036 = r5890034 * r5890034;
        double r5890037 = 4.0;
        double r5890038 = a;
        double r5890039 = c;
        double r5890040 = r5890038 * r5890039;
        double r5890041 = r5890037 * r5890040;
        double r5890042 = r5890036 - r5890041;
        double r5890043 = sqrt(r5890042);
        double r5890044 = r5890035 + r5890043;
        double r5890045 = 2.0;
        double r5890046 = r5890045 * r5890038;
        double r5890047 = r5890044 / r5890046;
        return r5890047;
}

double f(double a, double b, double c) {
        double r5890048 = b;
        double r5890049 = -3.263941314600607e+152;
        bool r5890050 = r5890048 <= r5890049;
        double r5890051 = c;
        double r5890052 = r5890051 / r5890048;
        double r5890053 = a;
        double r5890054 = r5890048 / r5890053;
        double r5890055 = r5890052 - r5890054;
        double r5890056 = -4.687918346756617e-254;
        bool r5890057 = r5890048 <= r5890056;
        double r5890058 = r5890048 * r5890048;
        double r5890059 = 4.0;
        double r5890060 = r5890053 * r5890059;
        double r5890061 = r5890060 * r5890051;
        double r5890062 = r5890058 - r5890061;
        double r5890063 = sqrt(r5890062);
        double r5890064 = r5890063 - r5890048;
        double r5890065 = 0.5;
        double r5890066 = r5890064 * r5890065;
        double r5890067 = r5890066 / r5890053;
        double r5890068 = 1.817261397602966e+121;
        bool r5890069 = r5890048 <= r5890068;
        double r5890070 = -2.0;
        double r5890071 = r5890051 * r5890070;
        double r5890072 = r5890063 + r5890048;
        double r5890073 = r5890071 / r5890072;
        double r5890074 = r5890052 * r5890053;
        double r5890075 = r5890048 - r5890074;
        double r5890076 = 2.0;
        double r5890077 = r5890075 * r5890076;
        double r5890078 = r5890071 / r5890077;
        double r5890079 = r5890069 ? r5890073 : r5890078;
        double r5890080 = r5890057 ? r5890067 : r5890079;
        double r5890081 = r5890050 ? r5890055 : r5890080;
        return r5890081;
}

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.3
Target20.3
Herbie6.4
\[\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 < -3.263941314600607e+152

    1. Initial program 60.1

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

      \[\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 div-inv60.1

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

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

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

    if -3.263941314600607e+152 < b < -4.687918346756617e-254

    1. Initial program 7.8

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

      \[\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 div-inv8.0

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

      \[\leadsto \left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right) \cdot \color{blue}{\frac{\frac{1}{2}}{a}}\]
    6. Using strategy rm
    7. Applied associate-*r/7.8

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

    if -4.687918346756617e-254 < b < 1.817261397602966e+121

    1. Initial program 31.6

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

      \[\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 div-inv31.7

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

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

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

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

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

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

    if 1.817261397602966e+121 < b

    1. Initial program 59.8

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

      \[\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 div-inv59.8

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -3.263941314600607 \cdot 10^{+152}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le -4.687918346756617 \cdot 10^{-254}:\\ \;\;\;\;\frac{\left(\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b\right) \cdot \frac{1}{2}}{a}\\ \mathbf{elif}\;b \le 1.817261397602966 \cdot 10^{+121}:\\ \;\;\;\;\frac{c \cdot -2}{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} + b}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -2}{\left(b - \frac{c}{b} \cdot a\right) \cdot 2}\\ \end{array}\]

Reproduce

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