Average Error: 33.8 → 10.3
Time: 24.4s
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 -2.025649824816678368861606895534923213042 \cdot 10^{153}:\\ \;\;\;\;\left(1 \cdot \frac{c}{b} - \frac{b}{a} \cdot 0.5\right) - \frac{\frac{b}{2}}{a}\\ \mathbf{elif}\;b \le 3.047677256636077515553757160900796353717 \cdot 10^{-81}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}}{2}}{a} - \frac{\frac{b}{2}}{a}\\ \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 -2.025649824816678368861606895534923213042 \cdot 10^{153}:\\
\;\;\;\;\left(1 \cdot \frac{c}{b} - \frac{b}{a} \cdot 0.5\right) - \frac{\frac{b}{2}}{a}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r4485266 = b;
        double r4485267 = -r4485266;
        double r4485268 = r4485266 * r4485266;
        double r4485269 = 4.0;
        double r4485270 = a;
        double r4485271 = r4485269 * r4485270;
        double r4485272 = c;
        double r4485273 = r4485271 * r4485272;
        double r4485274 = r4485268 - r4485273;
        double r4485275 = sqrt(r4485274);
        double r4485276 = r4485267 + r4485275;
        double r4485277 = 2.0;
        double r4485278 = r4485277 * r4485270;
        double r4485279 = r4485276 / r4485278;
        return r4485279;
}

double f(double a, double b, double c) {
        double r4485280 = b;
        double r4485281 = -2.0256498248166784e+153;
        bool r4485282 = r4485280 <= r4485281;
        double r4485283 = 1.0;
        double r4485284 = c;
        double r4485285 = r4485284 / r4485280;
        double r4485286 = r4485283 * r4485285;
        double r4485287 = a;
        double r4485288 = r4485280 / r4485287;
        double r4485289 = 0.5;
        double r4485290 = r4485288 * r4485289;
        double r4485291 = r4485286 - r4485290;
        double r4485292 = 2.0;
        double r4485293 = r4485280 / r4485292;
        double r4485294 = r4485293 / r4485287;
        double r4485295 = r4485291 - r4485294;
        double r4485296 = 3.0476772566360775e-81;
        bool r4485297 = r4485280 <= r4485296;
        double r4485298 = r4485280 * r4485280;
        double r4485299 = r4485284 * r4485287;
        double r4485300 = 4.0;
        double r4485301 = r4485299 * r4485300;
        double r4485302 = r4485298 - r4485301;
        double r4485303 = sqrt(r4485302);
        double r4485304 = r4485303 / r4485292;
        double r4485305 = r4485304 / r4485287;
        double r4485306 = r4485305 - r4485294;
        double r4485307 = -1.0;
        double r4485308 = r4485307 * r4485285;
        double r4485309 = r4485297 ? r4485306 : r4485308;
        double r4485310 = r4485282 ? r4485295 : r4485309;
        return r4485310;
}

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.8
Target20.6
Herbie10.3
\[\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 3 regimes
  2. if b < -2.0256498248166784e+153

    1. Initial program 63.6

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

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

      \[\leadsto \frac{\color{blue}{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}}{2} - \frac{b}{2}}}{a}\]
    5. Applied div-sub63.6

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

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

    if -2.0256498248166784e+153 < b < 3.0476772566360775e-81

    1. Initial program 11.9

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

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

      \[\leadsto \frac{\color{blue}{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}}{2} - \frac{b}{2}}}{a}\]
    5. Applied div-sub11.9

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

    if 3.0476772566360775e-81 < b

    1. Initial program 52.2

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.025649824816678368861606895534923213042 \cdot 10^{153}:\\ \;\;\;\;\left(1 \cdot \frac{c}{b} - \frac{b}{a} \cdot 0.5\right) - \frac{\frac{b}{2}}{a}\\ \mathbf{elif}\;b \le 3.047677256636077515553757160900796353717 \cdot 10^{-81}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}}{2}}{a} - \frac{\frac{b}{2}}{a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))))

  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))