Average Error: 34.1 → 10.0
Time: 16.9s
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 r105275 = b;
        double r105276 = -r105275;
        double r105277 = r105275 * r105275;
        double r105278 = 4.0;
        double r105279 = a;
        double r105280 = r105278 * r105279;
        double r105281 = c;
        double r105282 = r105280 * r105281;
        double r105283 = r105277 - r105282;
        double r105284 = sqrt(r105283);
        double r105285 = r105276 + r105284;
        double r105286 = 2.0;
        double r105287 = r105286 * r105279;
        double r105288 = r105285 / r105287;
        return r105288;
}

double f(double a, double b, double c) {
        double r105289 = b;
        double r105290 = -1.119811545308531e+143;
        bool r105291 = r105289 <= r105290;
        double r105292 = 1.0;
        double r105293 = c;
        double r105294 = r105293 / r105289;
        double r105295 = a;
        double r105296 = r105289 / r105295;
        double r105297 = r105294 - r105296;
        double r105298 = r105292 * r105297;
        double r105299 = 4.718890261991469e-106;
        bool r105300 = r105289 <= r105299;
        double r105301 = r105289 * r105289;
        double r105302 = 4.0;
        double r105303 = r105302 * r105295;
        double r105304 = r105303 * r105293;
        double r105305 = r105301 - r105304;
        double r105306 = sqrt(r105305);
        double r105307 = r105306 - r105289;
        double r105308 = 2.0;
        double r105309 = r105308 * r105295;
        double r105310 = r105307 / r105309;
        double r105311 = -1.0;
        double r105312 = r105311 * r105294;
        double r105313 = r105300 ? r105310 : r105312;
        double r105314 = r105291 ? r105298 : r105313;
        return r105314;
}

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. Using strategy rm
    4. Applied div-inv52.4

      \[\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 pow152.4

      \[\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 pow152.4

      \[\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-down52.4

      \[\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. Simplified52.4

      \[\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 10.9

      \[\leadsto {\color{blue}{\left(-1 \cdot \frac{c}{b}\right)}}^{1}\]
  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 
(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)))