Average Error: 34.1 → 10.0
Time: 14.1s
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 -1.11981154530853106611761327467786604265 \cdot 10^{143}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 4.718890261991468628346768591871377778707 \cdot 10^{-106}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot 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 -1.11981154530853106611761327467786604265 \cdot 10^{143}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r122221 = b;
        double r122222 = -r122221;
        double r122223 = r122221 * r122221;
        double r122224 = 4.0;
        double r122225 = a;
        double r122226 = r122224 * r122225;
        double r122227 = c;
        double r122228 = r122226 * r122227;
        double r122229 = r122223 - r122228;
        double r122230 = sqrt(r122229);
        double r122231 = r122222 + r122230;
        double r122232 = 2.0;
        double r122233 = r122232 * r122225;
        double r122234 = r122231 / r122233;
        return r122234;
}

double f(double a, double b, double c) {
        double r122235 = b;
        double r122236 = -1.119811545308531e+143;
        bool r122237 = r122235 <= r122236;
        double r122238 = 1.0;
        double r122239 = c;
        double r122240 = r122239 / r122235;
        double r122241 = a;
        double r122242 = r122235 / r122241;
        double r122243 = r122240 - r122242;
        double r122244 = r122238 * r122243;
        double r122245 = 4.718890261991469e-106;
        bool r122246 = r122235 <= r122245;
        double r122247 = r122235 * r122235;
        double r122248 = 4.0;
        double r122249 = r122248 * r122241;
        double r122250 = r122249 * r122239;
        double r122251 = r122247 - r122250;
        double r122252 = sqrt(r122251);
        double r122253 = r122252 - r122235;
        double r122254 = 2.0;
        double r122255 = r122254 * r122241;
        double r122256 = r122253 / r122255;
        double r122257 = -1.0;
        double r122258 = r122257 * r122240;
        double r122259 = r122246 ? r122256 : r122258;
        double r122260 = r122237 ? r122244 : r122259;
        return r122260;
}

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.1
Target21.0
Herbie10.0
\[\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 < -1.119811545308531e+143

    1. Initial program 59.0

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

      \[\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.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. Using strategy rm
    6. Applied pow159.0

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

      \[\leadsto \color{blue}{{\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right)}^{1}} \cdot {\left(\frac{1}{2 \cdot a}\right)}^{1}\]
    8. Applied pow-prod-down59.0

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

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

      \[\leadsto {\color{blue}{\left(1 \cdot \frac{c}{b} - 1 \cdot \frac{b}{a}\right)}}^{1}\]
    11. Simplified2.4

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

    if -1.119811545308531e+143 < b < 4.718890261991469e-106

    1. Initial program 11.1

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified11.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-inv11.2

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

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

      \[\leadsto \color{blue}{{\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right)}^{1}} \cdot {\left(\frac{1}{2 \cdot a}\right)}^{1}\]
    8. Applied pow-prod-down11.2

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

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

    if 4.718890261991469e-106 < b

    1. Initial program 52.4

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.11981154530853106611761327467786604265 \cdot 10^{143}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 4.718890261991468628346768591871377778707 \cdot 10^{-106}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019326 +o rules:numerics
(FPCore (a b c)
  :name "The quadratic formula (r1)"
  :precision binary64

  :herbie-target
  (if (< b 0.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)))