Average Error: 32.9 → 6.4
Time: 55.4s
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 -2.880394710329243 \cdot 10^{+120}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 5.818192251940127 \cdot 10^{-227}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 6.6006279600139335 \cdot 10^{+131}:\\ \;\;\;\;\left(c \cdot -2\right) \cdot \frac{1}{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} + b}\\ \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 -2.880394710329243 \cdot 10^{+120}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r4793051 = b;
        double r4793052 = -r4793051;
        double r4793053 = r4793051 * r4793051;
        double r4793054 = 4.0;
        double r4793055 = a;
        double r4793056 = c;
        double r4793057 = r4793055 * r4793056;
        double r4793058 = r4793054 * r4793057;
        double r4793059 = r4793053 - r4793058;
        double r4793060 = sqrt(r4793059);
        double r4793061 = r4793052 + r4793060;
        double r4793062 = 2.0;
        double r4793063 = r4793062 * r4793055;
        double r4793064 = r4793061 / r4793063;
        return r4793064;
}

double f(double a, double b, double c) {
        double r4793065 = b;
        double r4793066 = -2.880394710329243e+120;
        bool r4793067 = r4793065 <= r4793066;
        double r4793068 = c;
        double r4793069 = r4793068 / r4793065;
        double r4793070 = a;
        double r4793071 = r4793065 / r4793070;
        double r4793072 = r4793069 - r4793071;
        double r4793073 = 5.818192251940127e-227;
        bool r4793074 = r4793065 <= r4793073;
        double r4793075 = r4793065 * r4793065;
        double r4793076 = 4.0;
        double r4793077 = r4793070 * r4793076;
        double r4793078 = r4793077 * r4793068;
        double r4793079 = r4793075 - r4793078;
        double r4793080 = sqrt(r4793079);
        double r4793081 = r4793080 - r4793065;
        double r4793082 = 2.0;
        double r4793083 = r4793070 * r4793082;
        double r4793084 = r4793081 / r4793083;
        double r4793085 = 6.6006279600139335e+131;
        bool r4793086 = r4793065 <= r4793085;
        double r4793087 = -2.0;
        double r4793088 = r4793068 * r4793087;
        double r4793089 = 1.0;
        double r4793090 = r4793080 + r4793065;
        double r4793091 = r4793089 / r4793090;
        double r4793092 = r4793088 * r4793091;
        double r4793093 = -r4793069;
        double r4793094 = r4793086 ? r4793092 : r4793093;
        double r4793095 = r4793074 ? r4793084 : r4793094;
        double r4793096 = r4793067 ? r4793072 : r4793095;
        return r4793096;
}

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

Original32.9
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 < -2.880394710329243e+120

    1. Initial program 49.1

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

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

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

    if -2.880394710329243e+120 < b < 5.818192251940127e-227

    1. Initial program 9.3

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

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

    if 5.818192251940127e-227 < b < 6.6006279600139335e+131

    1. Initial program 35.9

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

      \[\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 clear-num36.0

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

      \[\leadsto \frac{1}{\frac{2 \cdot a}{\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}}}}\]
    7. Applied associate-/r/36.1

      \[\leadsto \frac{1}{\color{blue}{\frac{2 \cdot a}{\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} \cdot \left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b\right)}}\]
    8. Applied *-un-lft-identity36.1

      \[\leadsto \frac{\color{blue}{1 \cdot 1}}{\frac{2 \cdot a}{\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} \cdot \left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b\right)}\]
    9. Applied times-frac36.1

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

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

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

    if 6.6006279600139335e+131 < b

    1. Initial program 60.5

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.880394710329243 \cdot 10^{+120}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 5.818192251940127 \cdot 10^{-227}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 6.6006279600139335 \cdot 10^{+131}:\\ \;\;\;\;\left(c \cdot -2\right) \cdot \frac{1}{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} + b}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

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