Average Error: 33.8 → 10.3
Time: 23.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 r4774260 = b;
        double r4774261 = -r4774260;
        double r4774262 = r4774260 * r4774260;
        double r4774263 = 4.0;
        double r4774264 = a;
        double r4774265 = r4774263 * r4774264;
        double r4774266 = c;
        double r4774267 = r4774265 * r4774266;
        double r4774268 = r4774262 - r4774267;
        double r4774269 = sqrt(r4774268);
        double r4774270 = r4774261 + r4774269;
        double r4774271 = 2.0;
        double r4774272 = r4774271 * r4774264;
        double r4774273 = r4774270 / r4774272;
        return r4774273;
}

double f(double a, double b, double c) {
        double r4774274 = b;
        double r4774275 = -2.0256498248166784e+153;
        bool r4774276 = r4774274 <= r4774275;
        double r4774277 = 1.0;
        double r4774278 = c;
        double r4774279 = r4774278 / r4774274;
        double r4774280 = r4774277 * r4774279;
        double r4774281 = a;
        double r4774282 = r4774274 / r4774281;
        double r4774283 = 0.5;
        double r4774284 = r4774282 * r4774283;
        double r4774285 = r4774280 - r4774284;
        double r4774286 = 2.0;
        double r4774287 = r4774274 / r4774286;
        double r4774288 = r4774287 / r4774281;
        double r4774289 = r4774285 - r4774288;
        double r4774290 = 3.0476772566360775e-81;
        bool r4774291 = r4774274 <= r4774290;
        double r4774292 = r4774274 * r4774274;
        double r4774293 = r4774278 * r4774281;
        double r4774294 = 4.0;
        double r4774295 = r4774293 * r4774294;
        double r4774296 = r4774292 - r4774295;
        double r4774297 = sqrt(r4774296);
        double r4774298 = r4774297 / r4774286;
        double r4774299 = r4774298 / r4774281;
        double r4774300 = r4774299 - r4774288;
        double r4774301 = -1.0;
        double r4774302 = r4774301 * r4774279;
        double r4774303 = r4774291 ? r4774300 : r4774302;
        double r4774304 = r4774276 ? r4774289 : r4774303;
        return r4774304;
}

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