Average Error: 33.8 → 6.8
Time: 1.0m
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 -4.3671561050226844 \cdot 10^{+101}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le -2.5255536235408963 \cdot 10^{-284}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}}\\ \mathbf{elif}\;b \le 1.4199128551722248 \cdot 10^{+110}:\\ \;\;\;\;\frac{1}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + b} \cdot \left(-2 \cdot c\right)\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]
double f(double a, double b, double c) {
        double r12385559 = b;
        double r12385560 = -r12385559;
        double r12385561 = r12385559 * r12385559;
        double r12385562 = 4.0;
        double r12385563 = a;
        double r12385564 = r12385562 * r12385563;
        double r12385565 = c;
        double r12385566 = r12385564 * r12385565;
        double r12385567 = r12385561 - r12385566;
        double r12385568 = sqrt(r12385567);
        double r12385569 = r12385560 + r12385568;
        double r12385570 = 2.0;
        double r12385571 = r12385570 * r12385563;
        double r12385572 = r12385569 / r12385571;
        return r12385572;
}

double f(double a, double b, double c) {
        double r12385573 = b;
        double r12385574 = -4.3671561050226844e+101;
        bool r12385575 = r12385573 <= r12385574;
        double r12385576 = c;
        double r12385577 = r12385576 / r12385573;
        double r12385578 = a;
        double r12385579 = r12385573 / r12385578;
        double r12385580 = r12385577 - r12385579;
        double r12385581 = -2.5255536235408963e-284;
        bool r12385582 = r12385573 <= r12385581;
        double r12385583 = 1.0;
        double r12385584 = 2.0;
        double r12385585 = r12385578 * r12385584;
        double r12385586 = r12385573 * r12385573;
        double r12385587 = 4.0;
        double r12385588 = r12385576 * r12385578;
        double r12385589 = r12385587 * r12385588;
        double r12385590 = r12385586 - r12385589;
        double r12385591 = sqrt(r12385590);
        double r12385592 = r12385591 - r12385573;
        double r12385593 = r12385585 / r12385592;
        double r12385594 = r12385583 / r12385593;
        double r12385595 = 1.4199128551722248e+110;
        bool r12385596 = r12385573 <= r12385595;
        double r12385597 = r12385591 + r12385573;
        double r12385598 = r12385583 / r12385597;
        double r12385599 = -2.0;
        double r12385600 = r12385599 * r12385576;
        double r12385601 = r12385598 * r12385600;
        double r12385602 = -r12385577;
        double r12385603 = r12385596 ? r12385601 : r12385602;
        double r12385604 = r12385582 ? r12385594 : r12385603;
        double r12385605 = r12385575 ? r12385580 : r12385604;
        return r12385605;
}

\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 -4.3671561050226844 \cdot 10^{+101}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

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

\mathbf{elif}\;b \le 1.4199128551722248 \cdot 10^{+110}:\\
\;\;\;\;\frac{1}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + b} \cdot \left(-2 \cdot c\right)\\

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

\end{array}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.8
Target21.0
Herbie6.8
\[\begin{array}{l} \mathbf{if}\;b \lt 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 4 regimes
  2. if b < -4.3671561050226844e+101

    1. Initial program 44.7

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

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

      \[\leadsto \color{blue}{\frac{c}{b} - \frac{b}{a}}\]

    if -4.3671561050226844e+101 < b < -2.5255536235408963e-284

    1. Initial program 9.0

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

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

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

    if -2.5255536235408963e-284 < b < 1.4199128551722248e+110

    1. Initial program 32.0

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

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

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

      \[\leadsto \frac{1}{\frac{2 \cdot a}{\color{blue}{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} \cdot \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b \cdot b}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b}}}}\]
    7. Applied associate-/r/32.2

      \[\leadsto \frac{1}{\color{blue}{\frac{2 \cdot a}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} \cdot \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b \cdot b} \cdot \left(\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b\right)}}\]
    8. Applied *-un-lft-identity32.2

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

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

      \[\leadsto \color{blue}{\frac{0 - \left(c \cdot a\right) \cdot 4}{\frac{a}{\frac{1}{2}}}} \cdot \frac{1}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b}\]
    11. Taylor expanded around -inf 9.3

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

    if 1.4199128551722248e+110 < b

    1. Initial program 59.7

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    4. Simplified2.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -4.3671561050226844 \cdot 10^{+101}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le -2.5255536235408963 \cdot 10^{-284}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}}\\ \mathbf{elif}\;b \le 1.4199128551722248 \cdot 10^{+110}:\\ \;\;\;\;\frac{1}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + b} \cdot \left(-2 \cdot c\right)\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

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

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