Average Error: 34.9 → 6.7
Time: 14.3s
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.322469259707235906288389821512289579342 \cdot 10^{143}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -6.20678454373036183326394005062875842192 \cdot 10^{-301}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}{2 \cdot a}\\ \mathbf{elif}\;b \le 3.765731214908860535516414597984905004486 \cdot 10^{106}:\\ \;\;\;\;\frac{\frac{1}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{\frac{2}{\frac{1}{\frac{\frac{1}{c}}{4}}}}\\ \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.322469259707235906288389821512289579342 \cdot 10^{143}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r109681 = b;
        double r109682 = -r109681;
        double r109683 = r109681 * r109681;
        double r109684 = 4.0;
        double r109685 = a;
        double r109686 = r109684 * r109685;
        double r109687 = c;
        double r109688 = r109686 * r109687;
        double r109689 = r109683 - r109688;
        double r109690 = sqrt(r109689);
        double r109691 = r109682 + r109690;
        double r109692 = 2.0;
        double r109693 = r109692 * r109685;
        double r109694 = r109691 / r109693;
        return r109694;
}

double f(double a, double b, double c) {
        double r109695 = b;
        double r109696 = -2.322469259707236e+143;
        bool r109697 = r109695 <= r109696;
        double r109698 = 1.0;
        double r109699 = c;
        double r109700 = r109699 / r109695;
        double r109701 = a;
        double r109702 = r109695 / r109701;
        double r109703 = r109700 - r109702;
        double r109704 = r109698 * r109703;
        double r109705 = -6.206784543730362e-301;
        bool r109706 = r109695 <= r109705;
        double r109707 = -r109695;
        double r109708 = r109695 * r109695;
        double r109709 = 4.0;
        double r109710 = r109709 * r109701;
        double r109711 = r109699 * r109710;
        double r109712 = r109708 - r109711;
        double r109713 = sqrt(r109712);
        double r109714 = r109707 + r109713;
        double r109715 = 2.0;
        double r109716 = r109715 * r109701;
        double r109717 = r109714 / r109716;
        double r109718 = 3.7657312149088605e+106;
        bool r109719 = r109695 <= r109718;
        double r109720 = 1.0;
        double r109721 = r109710 * r109699;
        double r109722 = r109708 - r109721;
        double r109723 = sqrt(r109722);
        double r109724 = r109707 - r109723;
        double r109725 = r109720 / r109724;
        double r109726 = r109720 / r109699;
        double r109727 = r109726 / r109709;
        double r109728 = r109720 / r109727;
        double r109729 = r109715 / r109728;
        double r109730 = r109725 / r109729;
        double r109731 = -1.0;
        double r109732 = r109731 * r109700;
        double r109733 = r109719 ? r109730 : r109732;
        double r109734 = r109706 ? r109717 : r109733;
        double r109735 = r109697 ? r109704 : r109734;
        return r109735;
}

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.9
Target21.3
Herbie6.7
\[\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 4 regimes
  2. if b < -2.322469259707236e+143

    1. Initial program 59.5

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied flip-+64.0

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

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

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

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

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

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

    if -2.322469259707236e+143 < b < -6.206784543730362e-301

    1. Initial program 9.2

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied *-commutative9.2

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

    if -6.206784543730362e-301 < b < 3.7657312149088605e+106

    1. Initial program 33.5

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied flip-+33.5

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

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

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

      \[\leadsto \frac{\frac{1}{\color{blue}{\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{4 \cdot \left(a \cdot c\right)}}}}{2 \cdot a}\]
    8. Using strategy rm
    9. Applied div-inv17.0

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

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

      \[\leadsto \frac{\color{blue}{\frac{1}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \frac{1}{\frac{1}{4 \cdot \left(a \cdot c\right)}}}}{2 \cdot a}\]
    12. Applied associate-/l*16.2

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

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

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

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

    if 3.7657312149088605e+106 < b

    1. Initial program 60.2

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied flip-+60.2

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

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

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

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

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

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

Reproduce

herbie shell --seed 2019235 
(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)))