Average Error: 33.6 → 9.9
Time: 15.3s
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 -3.396811349079212 \cdot 10^{+61}:\\ \;\;\;\;\frac{\left(\frac{c}{\frac{b}{a}} - b\right) \cdot 2}{2 \cdot a}\\ \mathbf{elif}\;b \le 1.3659668388152999 \cdot 10^{-67}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\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 -3.396811349079212 \cdot 10^{+61}:\\
\;\;\;\;\frac{\left(\frac{c}{\frac{b}{a}} - b\right) \cdot 2}{2 \cdot a}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r3780181 = b;
        double r3780182 = -r3780181;
        double r3780183 = r3780181 * r3780181;
        double r3780184 = 4.0;
        double r3780185 = a;
        double r3780186 = r3780184 * r3780185;
        double r3780187 = c;
        double r3780188 = r3780186 * r3780187;
        double r3780189 = r3780183 - r3780188;
        double r3780190 = sqrt(r3780189);
        double r3780191 = r3780182 + r3780190;
        double r3780192 = 2.0;
        double r3780193 = r3780192 * r3780185;
        double r3780194 = r3780191 / r3780193;
        return r3780194;
}

double f(double a, double b, double c) {
        double r3780195 = b;
        double r3780196 = -3.396811349079212e+61;
        bool r3780197 = r3780195 <= r3780196;
        double r3780198 = c;
        double r3780199 = a;
        double r3780200 = r3780195 / r3780199;
        double r3780201 = r3780198 / r3780200;
        double r3780202 = r3780201 - r3780195;
        double r3780203 = 2.0;
        double r3780204 = r3780202 * r3780203;
        double r3780205 = r3780203 * r3780199;
        double r3780206 = r3780204 / r3780205;
        double r3780207 = 1.3659668388152999e-67;
        bool r3780208 = r3780195 <= r3780207;
        double r3780209 = r3780195 * r3780195;
        double r3780210 = r3780198 * r3780199;
        double r3780211 = 4.0;
        double r3780212 = r3780210 * r3780211;
        double r3780213 = r3780209 - r3780212;
        double r3780214 = sqrt(r3780213);
        double r3780215 = r3780214 - r3780195;
        double r3780216 = r3780215 / r3780205;
        double r3780217 = -r3780198;
        double r3780218 = r3780217 / r3780195;
        double r3780219 = r3780208 ? r3780216 : r3780218;
        double r3780220 = r3780197 ? r3780206 : r3780219;
        return r3780220;
}

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.6
Target20.8
Herbie9.9
\[\begin{array}{l} \mathbf{if}\;b \lt 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 3 regimes
  2. if b < -3.396811349079212e+61

    1. Initial program 37.6

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

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

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

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

    if -3.396811349079212e+61 < b < 1.3659668388152999e-67

    1. Initial program 13.9

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

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

    if 1.3659668388152999e-67 < b

    1. Initial program 53.0

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -3.396811349079212 \cdot 10^{+61}:\\ \;\;\;\;\frac{\left(\frac{c}{\frac{b}{a}} - b\right) \cdot 2}{2 \cdot a}\\ \mathbf{elif}\;b \le 1.3659668388152999 \cdot 10^{-67}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019130 
(FPCore (a b c)
  :name "The quadratic formula (r1)"

  :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)))