Average Error: 34.2 → 7.2
Time: 18.1s
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.065832835277420955864657569887710364937 \cdot 10^{109}:\\ \;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\ \mathbf{elif}\;b \le -4.565615297402513793822059617442033581563 \cdot 10^{-201}:\\ \;\;\;\;\left(\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} + \left(-b\right)\right) \cdot \frac{1}{a \cdot 2}\\ \mathbf{elif}\;b \le 4.287176096066254708923845932443784224798 \cdot 10^{77}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{\frac{1}{\frac{1}{4 \cdot c}}}{\left(-b\right) - \sqrt{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a}} \cdot \sqrt{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -1\\ \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.065832835277420955864657569887710364937 \cdot 10^{109}:\\
\;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r53824 = b;
        double r53825 = -r53824;
        double r53826 = r53824 * r53824;
        double r53827 = 4.0;
        double r53828 = a;
        double r53829 = r53827 * r53828;
        double r53830 = c;
        double r53831 = r53829 * r53830;
        double r53832 = r53826 - r53831;
        double r53833 = sqrt(r53832);
        double r53834 = r53825 + r53833;
        double r53835 = 2.0;
        double r53836 = r53835 * r53828;
        double r53837 = r53834 / r53836;
        return r53837;
}

double f(double a, double b, double c) {
        double r53838 = b;
        double r53839 = -4.065832835277421e+109;
        bool r53840 = r53838 <= r53839;
        double r53841 = c;
        double r53842 = r53841 / r53838;
        double r53843 = a;
        double r53844 = r53838 / r53843;
        double r53845 = r53842 - r53844;
        double r53846 = 1.0;
        double r53847 = r53845 * r53846;
        double r53848 = -4.565615297402514e-201;
        bool r53849 = r53838 <= r53848;
        double r53850 = r53838 * r53838;
        double r53851 = 4.0;
        double r53852 = r53851 * r53843;
        double r53853 = r53841 * r53852;
        double r53854 = r53850 - r53853;
        double r53855 = sqrt(r53854);
        double r53856 = -r53838;
        double r53857 = r53855 + r53856;
        double r53858 = 1.0;
        double r53859 = 2.0;
        double r53860 = r53843 * r53859;
        double r53861 = r53858 / r53860;
        double r53862 = r53857 * r53861;
        double r53863 = 4.2871760960662547e+77;
        bool r53864 = r53838 <= r53863;
        double r53865 = r53858 / r53859;
        double r53866 = r53851 * r53841;
        double r53867 = r53858 / r53866;
        double r53868 = r53858 / r53867;
        double r53869 = r53866 * r53843;
        double r53870 = r53850 - r53869;
        double r53871 = sqrt(r53870);
        double r53872 = sqrt(r53871);
        double r53873 = r53872 * r53872;
        double r53874 = r53856 - r53873;
        double r53875 = r53868 / r53874;
        double r53876 = r53865 * r53875;
        double r53877 = -1.0;
        double r53878 = r53842 * r53877;
        double r53879 = r53864 ? r53876 : r53878;
        double r53880 = r53849 ? r53862 : r53879;
        double r53881 = r53840 ? r53847 : r53880;
        return r53881;
}

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.2
Target21.0
Herbie7.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 < -4.065832835277421e+109

    1. Initial program 49.5

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

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

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

    if -4.065832835277421e+109 < b < -4.565615297402514e-201

    1. Initial program 8.1

      \[\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-inv8.2

      \[\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. Simplified8.2

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

    if -4.565615297402514e-201 < b < 4.2871760960662547e+77

    1. Initial program 28.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-+28.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.7

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

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

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

      \[\leadsto \frac{\frac{\color{blue}{1 \cdot \left(0 + \left(4 \cdot c\right) \cdot a\right)}}{1 \cdot \left(\left(-b\right) - \sqrt{\mathsf{fma}\left(a \cdot c, -4, b \cdot b\right)}\right)}}{2 \cdot a}\]
    9. Applied times-frac16.7

      \[\leadsto \frac{\color{blue}{\frac{1}{1} \cdot \frac{0 + \left(4 \cdot c\right) \cdot a}{\left(-b\right) - \sqrt{\mathsf{fma}\left(a \cdot c, -4, b \cdot b\right)}}}}{2 \cdot a}\]
    10. Applied times-frac16.7

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

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

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

      \[\leadsto \frac{1}{2} \cdot \frac{\color{blue}{\frac{1}{\frac{a}{\left(4 \cdot c\right) \cdot a}}}}{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, \left(-a\right) \cdot \left(4 \cdot c\right)\right)}}\]
    15. Simplified10.3

      \[\leadsto \frac{1}{2} \cdot \frac{\frac{1}{\color{blue}{\frac{1}{4 \cdot c}}}}{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, \left(-a\right) \cdot \left(4 \cdot c\right)\right)}}\]
    16. Using strategy rm
    17. Applied add-sqr-sqrt10.3

      \[\leadsto \frac{1}{2} \cdot \frac{\frac{1}{\frac{1}{4 \cdot c}}}{\left(-b\right) - \sqrt{\color{blue}{\sqrt{\mathsf{fma}\left(b, b, \left(-a\right) \cdot \left(4 \cdot c\right)\right)} \cdot \sqrt{\mathsf{fma}\left(b, b, \left(-a\right) \cdot \left(4 \cdot c\right)\right)}}}}\]
    18. Applied sqrt-prod10.5

      \[\leadsto \frac{1}{2} \cdot \frac{\frac{1}{\frac{1}{4 \cdot c}}}{\left(-b\right) - \color{blue}{\sqrt{\sqrt{\mathsf{fma}\left(b, b, \left(-a\right) \cdot \left(4 \cdot c\right)\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(b, b, \left(-a\right) \cdot \left(4 \cdot c\right)\right)}}}}\]
    19. Simplified10.5

      \[\leadsto \frac{1}{2} \cdot \frac{\frac{1}{\frac{1}{4 \cdot c}}}{\left(-b\right) - \color{blue}{\sqrt{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a}}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(b, b, \left(-a\right) \cdot \left(4 \cdot c\right)\right)}}}\]
    20. Simplified10.5

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

    if 4.2871760960662547e+77 < b

    1. Initial program 58.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -4.065832835277420955864657569887710364937 \cdot 10^{109}:\\ \;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\ \mathbf{elif}\;b \le -4.565615297402513793822059617442033581563 \cdot 10^{-201}:\\ \;\;\;\;\left(\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} + \left(-b\right)\right) \cdot \frac{1}{a \cdot 2}\\ \mathbf{elif}\;b \le 4.287176096066254708923845932443784224798 \cdot 10^{77}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{\frac{1}{\frac{1}{4 \cdot c}}}{\left(-b\right) - \sqrt{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a}} \cdot \sqrt{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -1\\ \end{array}\]

Reproduce

herbie shell --seed 2019196 +o rules:numerics
(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)))