Average Error: 33.8 → 8.2
Time: 13.7s
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 -8.301687926884188663878043402578250574713 \cdot 10^{98}:\\ \;\;\;\;\frac{1}{2} \cdot \left(2 \cdot \frac{c}{b} - 2 \cdot \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -2.429882607187263696810803427497685533949 \cdot 10^{-231}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a}\\ \mathbf{elif}\;b \le 2.016226033463546396558528786021161574763 \cdot 10^{61}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{\frac{4 \cdot a}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b}{c}}}{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 -8.301687926884188663878043402578250574713 \cdot 10^{98}:\\
\;\;\;\;\frac{1}{2} \cdot \left(2 \cdot \frac{c}{b} - 2 \cdot \frac{b}{a}\right)\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r116815 = b;
        double r116816 = -r116815;
        double r116817 = r116815 * r116815;
        double r116818 = 4.0;
        double r116819 = a;
        double r116820 = r116818 * r116819;
        double r116821 = c;
        double r116822 = r116820 * r116821;
        double r116823 = r116817 - r116822;
        double r116824 = sqrt(r116823);
        double r116825 = r116816 + r116824;
        double r116826 = 2.0;
        double r116827 = r116826 * r116819;
        double r116828 = r116825 / r116827;
        return r116828;
}

double f(double a, double b, double c) {
        double r116829 = b;
        double r116830 = -8.301687926884189e+98;
        bool r116831 = r116829 <= r116830;
        double r116832 = 1.0;
        double r116833 = 2.0;
        double r116834 = r116832 / r116833;
        double r116835 = c;
        double r116836 = r116835 / r116829;
        double r116837 = r116833 * r116836;
        double r116838 = 2.0;
        double r116839 = a;
        double r116840 = r116829 / r116839;
        double r116841 = r116838 * r116840;
        double r116842 = r116837 - r116841;
        double r116843 = r116834 * r116842;
        double r116844 = -2.4298826071872637e-231;
        bool r116845 = r116829 <= r116844;
        double r116846 = r116829 * r116829;
        double r116847 = 4.0;
        double r116848 = r116847 * r116839;
        double r116849 = r116848 * r116835;
        double r116850 = r116846 - r116849;
        double r116851 = sqrt(r116850);
        double r116852 = r116851 - r116829;
        double r116853 = r116852 / r116839;
        double r116854 = r116834 * r116853;
        double r116855 = 2.0162260334635464e+61;
        bool r116856 = r116829 <= r116855;
        double r116857 = -1.0;
        double r116858 = r116857 / r116833;
        double r116859 = r116851 + r116829;
        double r116860 = r116859 / r116835;
        double r116861 = r116848 / r116860;
        double r116862 = r116861 / r116839;
        double r116863 = r116858 * r116862;
        double r116864 = -1.0;
        double r116865 = r116864 * r116836;
        double r116866 = r116856 ? r116863 : r116865;
        double r116867 = r116845 ? r116854 : r116866;
        double r116868 = r116831 ? r116843 : r116867;
        return r116868;
}

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.8
Herbie8.2
\[\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 < -8.301687926884189e+98

    1. Initial program 46.2

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

      \[\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 *-un-lft-identity46.2

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

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

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

    if -8.301687926884189e+98 < b < -2.4298826071872637e-231

    1. Initial program 8.1

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified8.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 *-un-lft-identity8.1

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

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

    if -2.4298826071872637e-231 < b < 2.0162260334635464e+61

    1. Initial program 27.6

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

      \[\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 *-un-lft-identity27.6

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

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

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

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

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

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

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

    if 2.0162260334635464e+61 < b

    1. Initial program 57.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -8.301687926884188663878043402578250574713 \cdot 10^{98}:\\ \;\;\;\;\frac{1}{2} \cdot \left(2 \cdot \frac{c}{b} - 2 \cdot \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -2.429882607187263696810803427497685533949 \cdot 10^{-231}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a}\\ \mathbf{elif}\;b \le 2.016226033463546396558528786021161574763 \cdot 10^{61}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{\frac{4 \cdot a}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b}{c}}}{a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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