def _evalf_(self, x, y, parent=None, algorithm='mpmath'): """ EXAMPLES:: sage: gamma_inc_lower(3,2.) 0.646647167633873 sage: gamma_inc_lower(3,2).n(200) 0.646647167633873081060005050275155... sage: gamma_inc_lower(0,2.) +infinity """ R = parent or s_parent(x) # C is the complex version of R # prec is the precision of R if R is float: prec = 53 C = complex else: try: prec = R.precision() except AttributeError: prec = 53 try: C = R.complex_field() except AttributeError: C = R if algorithm == 'pari': try: v = ComplexField(prec)(x).gamma() - ComplexField(prec)( x).gamma_inc(y) except AttributeError: if not (is_ComplexNumber(x)): if is_ComplexNumber(y): C = y.parent() else: C = ComplexField() x = C(x) v = ComplexField(prec)(x).gamma() - ComplexField(prec)( x).gamma_inc(y) else: import mpmath v = ComplexField(prec)(mpmath_utils.call(mpmath.gammainc, x, 0, y, parent=R)) if v.is_real(): return R(v) else: return C(v)
def _evalf_(self, x, y, parent=None, algorithm='mpmath'): """ EXAMPLES:: sage: gamma_inc_lower(3,2.) 0.646647167633873 sage: gamma_inc_lower(3,2).n(200) 0.646647167633873081060005050275155... sage: gamma_inc_lower(0,2.) +infinity """ R = parent or s_parent(x) # C is the complex version of R # prec is the precision of R if R is float: prec = 53 C = complex else: try: prec = R.precision() except AttributeError: prec = 53 try: C = R.complex_field() except AttributeError: C = R if algorithm == 'pari': try: v = ComplexField(prec)(x).gamma() - ComplexField(prec)(x).gamma_inc(y) except AttributeError: if not (is_ComplexNumber(x)): if is_ComplexNumber(y): C = y.parent() else: C = ComplexField() x = C(x) v = ComplexField(prec)(x).gamma() - ComplexField(prec)(x).gamma_inc(y) else: import mpmath v = ComplexField(prec)(mpmath_utils.call(mpmath.gammainc, x, 0, y, parent=R)) if v.is_real(): return R(v) else: return C(v)
def _evalf_(self, x, y, parent=None, algorithm='pari'): """ EXAMPLES:: sage: gamma_inc(0,2) -Ei(-2) sage: gamma_inc(0,2.) 0.0489005107080611 sage: gamma_inc(0,2).n(algorithm='pari') 0.0489005107080611 sage: gamma_inc(0,2).n(200) 0.048900510708061119567239835228... sage: gamma_inc(3,2).n() 1.35335283236613 TESTS: Check that :trac:`7099` is fixed:: sage: R = RealField(1024) sage: gamma(R(9), R(10^-3)) # rel tol 1e-308 40319.99999999999999999999999999988898884344822911869926361916294165058203634104838326009191542490601781777105678829520585311300510347676330951251563007679436243294653538925717144381702105700908686088851362675381239820118402497959018315224423868693918493033078310647199219674433536605771315869983788442389633 sage: numerical_approx(gamma(9, 10^(-3)) - gamma(9), digits=40) # abs tol 1e-36 -1.110111598370794007949063502542063148294e-28 Check that :trac:`17328` is fixed:: sage: gamma_inc(float(-1), float(-1)) (-0.8231640121031085+3.141592653589793j) sage: gamma_inc(RR(-1), RR(-1)) -0.823164012103109 + 3.14159265358979*I sage: gamma_inc(-1, float(-log(3))) - gamma_inc(-1, float(-log(2))) # abs tol 1e-15 (1.2730972164471142+0j) Check that :trac:`17130` is fixed:: sage: r = gamma_inc(float(0), float(1)); r 0.21938393439552029 sage: type(r) <... 'float'> """ R = parent or s_parent(x) # C is the complex version of R # prec is the precision of R if R is float: prec = 53 C = complex else: try: prec = R.precision() except AttributeError: prec = 53 try: C = R.complex_field() except AttributeError: C = R if algorithm == 'pari': v = ComplexField(prec)(x).gamma_inc(y) else: import mpmath v = ComplexField(prec)(mpmath_utils.call(mpmath.gammainc, x, y, parent=R)) if v.is_real(): return R(v) else: return C(v)