Average Error: 33.7 → 8.8
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 -4.739519777490095733488952130644039307968 \cdot 10^{139}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.034940633201112123069802876954999016687 \cdot 10^{-134}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}\\ \mathbf{elif}\;b \le 1.942537531933752129700502847729005312685 \cdot 10^{102}:\\ \;\;\;\;\frac{\sqrt[3]{c \cdot \left(4 \cdot a\right)} \cdot \sqrt[3]{c \cdot \left(4 \cdot a\right)}}{2} \cdot \frac{\frac{\sqrt[3]{c \cdot \left(4 \cdot a\right)}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot 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 -4.739519777490095733488952130644039307968 \cdot 10^{139}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

\mathbf{elif}\;b \le 1.942537531933752129700502847729005312685 \cdot 10^{102}:\\
\;\;\;\;\frac{\sqrt[3]{c \cdot \left(4 \cdot a\right)} \cdot \sqrt[3]{c \cdot \left(4 \cdot a\right)}}{2} \cdot \frac{\frac{\sqrt[3]{c \cdot \left(4 \cdot a\right)}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{a}\\

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

\end{array}
double f(double a, double b, double c) {
        double r109814 = b;
        double r109815 = -r109814;
        double r109816 = r109814 * r109814;
        double r109817 = 4.0;
        double r109818 = a;
        double r109819 = r109817 * r109818;
        double r109820 = c;
        double r109821 = r109819 * r109820;
        double r109822 = r109816 - r109821;
        double r109823 = sqrt(r109822);
        double r109824 = r109815 + r109823;
        double r109825 = 2.0;
        double r109826 = r109825 * r109818;
        double r109827 = r109824 / r109826;
        return r109827;
}

double f(double a, double b, double c) {
        double r109828 = b;
        double r109829 = -4.7395197774900957e+139;
        bool r109830 = r109828 <= r109829;
        double r109831 = 1.0;
        double r109832 = c;
        double r109833 = r109832 / r109828;
        double r109834 = a;
        double r109835 = r109828 / r109834;
        double r109836 = r109833 - r109835;
        double r109837 = r109831 * r109836;
        double r109838 = 1.0349406332011121e-134;
        bool r109839 = r109828 <= r109838;
        double r109840 = r109828 * r109828;
        double r109841 = 4.0;
        double r109842 = r109841 * r109834;
        double r109843 = r109842 * r109832;
        double r109844 = r109840 - r109843;
        double r109845 = sqrt(r109844);
        double r109846 = r109845 - r109828;
        double r109847 = 2.0;
        double r109848 = r109847 * r109834;
        double r109849 = r109846 / r109848;
        double r109850 = 1.9425375319337521e+102;
        bool r109851 = r109828 <= r109850;
        double r109852 = r109832 * r109842;
        double r109853 = cbrt(r109852);
        double r109854 = r109853 * r109853;
        double r109855 = r109854 / r109847;
        double r109856 = -r109828;
        double r109857 = r109856 - r109845;
        double r109858 = r109853 / r109857;
        double r109859 = r109858 / r109834;
        double r109860 = r109855 * r109859;
        double r109861 = -1.0;
        double r109862 = r109861 * r109833;
        double r109863 = r109851 ? r109860 : r109862;
        double r109864 = r109839 ? r109849 : r109863;
        double r109865 = r109830 ? r109837 : r109864;
        return r109865;
}

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.7
Target20.6
Herbie8.8
\[\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 < -4.7395197774900957e+139

    1. Initial program 58.8

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

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

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

    if -4.7395197774900957e+139 < b < 1.0349406332011121e-134

    1. Initial program 10.8

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

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

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

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

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

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

    if 1.0349406332011121e-134 < b < 1.9425375319337521e+102

    1. Initial program 39.4

      \[\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-+39.4

      \[\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. Simplified14.9

      \[\leadsto \frac{\frac{\color{blue}{0 + \left(4 \cdot a\right) \cdot c}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity14.9

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

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

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

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

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

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

    if 1.9425375319337521e+102 < b

    1. Initial program 59.0

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Taylor expanded around inf 2.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -4.739519777490095733488952130644039307968 \cdot 10^{139}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.034940633201112123069802876954999016687 \cdot 10^{-134}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}\\ \mathbf{elif}\;b \le 1.942537531933752129700502847729005312685 \cdot 10^{102}:\\ \;\;\;\;\frac{\sqrt[3]{c \cdot \left(4 \cdot a\right)} \cdot \sqrt[3]{c \cdot \left(4 \cdot a\right)}}{2} \cdot \frac{\frac{\sqrt[3]{c \cdot \left(4 \cdot a\right)}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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