Average Error: 34.5 → 6.3
Time: 40.0s
Precision: 64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4.0 \cdot a\right) \cdot c}}{2.0 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -3.0775171197265305 \cdot 10^{+143}:\\ \;\;\;\;\frac{\frac{-2 \cdot b}{2.0}}{a}\\ \mathbf{elif}\;b \le -6.459611810046018 \cdot 10^{-256}:\\ \;\;\;\;\left(\sqrt{b \cdot b - 4.0 \cdot \left(a \cdot c\right)} - b\right) \cdot \frac{\frac{1}{2.0}}{a}\\ \mathbf{elif}\;b \le 5.413497103300552 \cdot 10^{+144}:\\ \;\;\;\;\frac{c \cdot -2.0}{\sqrt{b \cdot b - 4.0 \cdot \left(a \cdot c\right)} + b}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -1.0\\ \end{array}\]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4.0 \cdot a\right) \cdot c}}{2.0 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \le -3.0775171197265305 \cdot 10^{+143}:\\
\;\;\;\;\frac{\frac{-2 \cdot b}{2.0}}{a}\\

\mathbf{elif}\;b \le -6.459611810046018 \cdot 10^{-256}:\\
\;\;\;\;\left(\sqrt{b \cdot b - 4.0 \cdot \left(a \cdot c\right)} - b\right) \cdot \frac{\frac{1}{2.0}}{a}\\

\mathbf{elif}\;b \le 5.413497103300552 \cdot 10^{+144}:\\
\;\;\;\;\frac{c \cdot -2.0}{\sqrt{b \cdot b - 4.0 \cdot \left(a \cdot c\right)} + b}\\

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

\end{array}
double f(double a, double b, double c) {
        double r4103336 = b;
        double r4103337 = -r4103336;
        double r4103338 = r4103336 * r4103336;
        double r4103339 = 4.0;
        double r4103340 = a;
        double r4103341 = r4103339 * r4103340;
        double r4103342 = c;
        double r4103343 = r4103341 * r4103342;
        double r4103344 = r4103338 - r4103343;
        double r4103345 = sqrt(r4103344);
        double r4103346 = r4103337 + r4103345;
        double r4103347 = 2.0;
        double r4103348 = r4103347 * r4103340;
        double r4103349 = r4103346 / r4103348;
        return r4103349;
}

double f(double a, double b, double c) {
        double r4103350 = b;
        double r4103351 = -3.0775171197265305e+143;
        bool r4103352 = r4103350 <= r4103351;
        double r4103353 = -2.0;
        double r4103354 = r4103353 * r4103350;
        double r4103355 = 2.0;
        double r4103356 = r4103354 / r4103355;
        double r4103357 = a;
        double r4103358 = r4103356 / r4103357;
        double r4103359 = -6.459611810046018e-256;
        bool r4103360 = r4103350 <= r4103359;
        double r4103361 = r4103350 * r4103350;
        double r4103362 = 4.0;
        double r4103363 = c;
        double r4103364 = r4103357 * r4103363;
        double r4103365 = r4103362 * r4103364;
        double r4103366 = r4103361 - r4103365;
        double r4103367 = sqrt(r4103366);
        double r4103368 = r4103367 - r4103350;
        double r4103369 = 1.0;
        double r4103370 = r4103369 / r4103355;
        double r4103371 = r4103370 / r4103357;
        double r4103372 = r4103368 * r4103371;
        double r4103373 = 5.413497103300552e+144;
        bool r4103374 = r4103350 <= r4103373;
        double r4103375 = -2.0;
        double r4103376 = r4103363 * r4103375;
        double r4103377 = r4103367 + r4103350;
        double r4103378 = r4103376 / r4103377;
        double r4103379 = r4103363 / r4103350;
        double r4103380 = -1.0;
        double r4103381 = r4103379 * r4103380;
        double r4103382 = r4103374 ? r4103378 : r4103381;
        double r4103383 = r4103360 ? r4103372 : r4103382;
        double r4103384 = r4103352 ? r4103358 : r4103383;
        return r4103384;
}

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

Original34.5
Target20.9
Herbie6.3
\[\begin{array}{l} \mathbf{if}\;b \lt 0.0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4.0 \cdot a\right) \cdot c}}{2.0 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(4.0 \cdot a\right) \cdot c}}{2.0 \cdot a}}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if b < -3.0775171197265305e+143

    1. Initial program 59.8

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

      \[\leadsto \color{blue}{\frac{\frac{\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} - b}{2.0}}{a}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt59.8

      \[\leadsto \frac{\frac{\sqrt{\color{blue}{\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} \cdot \sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)}}} - b}{2.0}}{a}\]
    5. Applied sqrt-prod59.8

      \[\leadsto \frac{\frac{\color{blue}{\sqrt{\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)}} \cdot \sqrt{\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)}}} - b}{2.0}}{a}\]
    6. Applied fma-neg59.8

      \[\leadsto \frac{\frac{\color{blue}{\mathsf{fma}\left(\sqrt{\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)}}, \sqrt{\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)}}, -b\right)}}{2.0}}{a}\]
    7. Taylor expanded around -inf 3.0

      \[\leadsto \frac{\frac{\color{blue}{-2 \cdot b}}{2.0}}{a}\]
    8. Simplified3.0

      \[\leadsto \frac{\frac{\color{blue}{-2 \cdot b}}{2.0}}{a}\]

    if -3.0775171197265305e+143 < b < -6.459611810046018e-256

    1. Initial program 8.0

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

      \[\leadsto \color{blue}{\frac{\frac{\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} - b}{2.0}}{a}}\]
    3. Using strategy rm
    4. Applied *-un-lft-identity7.9

      \[\leadsto \frac{\frac{\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} - b}{2.0}}{\color{blue}{1 \cdot a}}\]
    5. Applied div-inv7.9

      \[\leadsto \frac{\color{blue}{\left(\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} - b\right) \cdot \frac{1}{2.0}}}{1 \cdot a}\]
    6. Applied times-frac8.1

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} - b}{1} \cdot \frac{\frac{1}{2.0}}{a}}\]
    7. Simplified8.1

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

    if -6.459611810046018e-256 < b < 5.413497103300552e+144

    1. Initial program 33.1

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

      \[\leadsto \color{blue}{\frac{\frac{\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} - b}{2.0}}{a}}\]
    3. Using strategy rm
    4. Applied *-un-lft-identity33.1

      \[\leadsto \frac{\frac{\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} - b}{2.0}}{\color{blue}{1 \cdot a}}\]
    5. Applied div-inv33.1

      \[\leadsto \frac{\color{blue}{\left(\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} - b\right) \cdot \frac{1}{2.0}}}{1 \cdot a}\]
    6. Applied times-frac33.1

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} - b}{1} \cdot \frac{\frac{1}{2.0}}{a}}\]
    7. Simplified33.1

      \[\leadsto \color{blue}{\left(\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} - b\right)} \cdot \frac{\frac{1}{2.0}}{a}\]
    8. Using strategy rm
    9. Applied flip--33.2

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} \cdot \sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} - b \cdot b}{\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} + b}} \cdot \frac{\frac{1}{2.0}}{a}\]
    10. Applied associate-*l/33.2

      \[\leadsto \color{blue}{\frac{\left(\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} \cdot \sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} - b \cdot b\right) \cdot \frac{\frac{1}{2.0}}{a}}{\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} + b}}\]
    11. Simplified13.6

      \[\leadsto \frac{\color{blue}{\frac{\left(b \cdot b - b \cdot b\right) - 4.0 \cdot \left(c \cdot a\right)}{a \cdot 2.0}}}{\sqrt{b \cdot b - 4.0 \cdot \left(c \cdot a\right)} + b}\]
    12. Taylor expanded around 0 8.3

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

    if 5.413497103300552e+144 < b

    1. Initial program 62.8

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -3.0775171197265305 \cdot 10^{+143}:\\ \;\;\;\;\frac{\frac{-2 \cdot b}{2.0}}{a}\\ \mathbf{elif}\;b \le -6.459611810046018 \cdot 10^{-256}:\\ \;\;\;\;\left(\sqrt{b \cdot b - 4.0 \cdot \left(a \cdot c\right)} - b\right) \cdot \frac{\frac{1}{2.0}}{a}\\ \mathbf{elif}\;b \le 5.413497103300552 \cdot 10^{+144}:\\ \;\;\;\;\frac{c \cdot -2.0}{\sqrt{b \cdot b - 4.0 \cdot \left(a \cdot c\right)} + b}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -1.0\\ \end{array}\]

Reproduce

herbie shell --seed 2019165 +o rules:numerics
(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)))