Ticket #7748: trac_7748-incomplete_gamma_ver2.patch
File trac_7748-incomplete_gamma_ver2.patch, 7.2 KB (added by , 12 years ago) |
---|
-
sage/functions/all.py
# HG changeset patch # User Flavia Stan <flavia.stan@gmail.com> # Date 1266276321 -3600 # Node ID 2f2ba60c8b2253ab41cfa7a4b9855972b172b976 # Parent 6f981d100b5cf86dea860b77a46e3562f7fbd21e Trac 7748: Make incomplete gamma function symbolic. diff --git a/sage/functions/all.py b/sage/functions/all.py
a b 17 17 18 18 from other import ( ceil, floor, gamma, factorial, 19 19 abs_symbolic, erf, sqrt, 20 gamma_inc, incomplete_gamma, 20 21 real_part, real, 21 22 imag_part, imag, imaginary, conjugate) 22 23 … … 24 25 25 26 26 27 from transcendental import (exponential_integral_1, 27 gamma_inc, incomplete_gamma,28 28 zeta, zeta_symmetric, 29 29 Li, Ei, 30 30 dickman_rho) -
sage/functions/other.py
diff --git a/sage/functions/other.py b/sage/functions/other.py
a b 5 5 from sage.symbolic.expression import Expression 6 6 from sage.libs.pari.gen import pari 7 7 from sage.symbolic.all import SR 8 from sage.rings.all import Integer, Rational, RealField, CC, RR 8 from sage.rings.all import Integer, Rational, RealField, CC, RR, \ 9 is_ComplexNumber, ComplexField 9 10 from sage.misc.latex import latex 10 11 import math 11 12 13 import sage.structure.element 14 coercion_model = sage.structure.element.get_coercion_model() 15 16 from sage.structure.coerce import parent 17 from sage.symbolic.constants import pi 18 from sage.symbolic.function import is_inexact 19 from sage.functions.log import exp 20 from sage.functions.transcendental import Ei 21 12 22 one_half = ~SR(2) 13 23 14 24 class Function_erf(BuiltinFunction): … … 538 548 539 549 gamma = Function_gamma() 540 550 551 class Function_gamma_inc(BuiltinFunction): 552 def __init__(self): 553 """ 554 The incomplete gamma function. 555 556 EXAMPLES:: 557 558 sage: gamma_inc(CDF(0,1), 3) 559 0.00320857499337 + 0.0124061858119*I 560 sage: gamma_inc(RDF(1), 3) 561 0.0497870683678639 562 sage: gamma_inc(3,2) 563 gamma(3, 2) 564 sage: gamma_inc(x,0) 565 gamma(x) 566 sage: latex(gamma_inc(3,2)) 567 \Gamma\left(3, 2\right) 568 sage: loads(dumps((gamma_inc(3,2)))) 569 gamma(3, 2) 570 sage: i = ComplexField(30).0; gamma_inc(2, 1 + i) 571 0.70709210 - 0.42035364*I 572 sage: gamma_inc(2., 5) 573 0.0404276819945128 574 """ 575 BuiltinFunction.__init__(self, "gamma", nargs=2, latex_name=r"\Gamma") 576 577 def _eval_(self, x, y): 578 """ 579 EXAMPLES:: 580 581 sage: gamma_inc(2.,0) 582 1.00000000000000 583 sage: gamma_inc(2,0) 584 1 585 sage: gamma_inc(1/2,2) 586 -(erf(sqrt(2)) - 1)*sqrt(pi) 587 sage: gamma_inc(1/2,1) 588 -(erf(1) - 1)*sqrt(pi) 589 sage: gamma_inc(1/2,0) 590 sqrt(pi) 591 sage: gamma_inc(x,0) 592 gamma(x) 593 sage: gamma_inc(1,2) 594 e^(-2) 595 sage: gamma_inc(0,2) 596 -Ei(-2) 597 """ 598 if not isinstance(x, Expression) and not isinstance(y, Expression) and \ 599 (is_inexact(x) or is_inexact(y)): 600 x, y = coercion_model.canonical_coercion(x, y) 601 return self._evalf_(x, y, parent(x)) 602 603 if y == 0: 604 return gamma(x) 605 if x == 1: 606 return exp(-y) 607 if x == 0: 608 return -Ei(-y) 609 if x == Rational(1)/2: #only for x>0 610 return sqrt(pi)*(1-erf(sqrt(y))) 611 return None 612 613 def _evalf_(self, x, y, parent=None): 614 """ 615 EXAMPLES:: 616 617 sage: gamma_inc(0,2) 618 -Ei(-2) 619 sage: gamma_inc(0,2.) 620 0.0489005107080611 621 sage: gamma_inc(3,2).n() 622 1.35335283236613 623 """ 624 try: 625 return x.gamma_inc(y) 626 except AttributeError: 627 if not (is_ComplexNumber(x)): 628 if is_ComplexNumber(y): 629 C = y.parent() 630 else: 631 C = ComplexField() 632 x = C(x) 633 return x.gamma_inc(y) 634 635 # synonym. 636 incomplete_gamma = gamma_inc=Function_gamma_inc() 637 638 541 639 class Function_factorial(GinacFunction): 542 640 def __init__(self): 543 641 r""" -
sage/functions/transcendental.py
diff --git a/sage/functions/transcendental.py b/sage/functions/transcendental.py
a b 101 101 else: 102 102 return [float(z) for z in pari(x).eint1(n)] 103 103 104 def gamma_inc(s, t):105 """106 Incomplete Gamma function Gamma(s,t).107 108 EXAMPLES::109 110 sage: gamma_inc(CDF(0,1), 3)111 0.00320857499337 + 0.0124061858119*I112 sage: gamma_inc(3, 3)113 0.846380162253687114 sage: gamma_inc(RDF(1), 3)115 0.0497870683678639116 """117 try:118 return s.gamma_inc(t)119 except AttributeError:120 if not (is_ComplexNumber(s)):121 if is_ComplexNumber(t):122 C = t.parent()123 else:124 C = ComplexField()125 s = C(s)126 return s.gamma_inc(t)127 128 129 # synonym.130 incomplete_gamma = gamma_inc131 104 132 105 def zeta(s): 133 106 """ -
sage/rings/complex_number.pyx
diff --git a/sage/rings/complex_number.pyx b/sage/rings/complex_number.pyx
a b 1606 1606 -0.0013781309 + 0.0065198200*I 1607 1607 sage: C(2).gamma_inc(1 + i) 1608 1608 0.70709210 - 0.42035364*I 1609 sage: gamma_inc(2, 1 + i) 1610 0.70709210 - 0.42035364*I 1611 sage: gamma_inc(2, 5) 1609 sage: CC(2).gamma_inc(5) 1612 1610 0.0404276819945128 1613 1611 """ 1614 1612 return self._parent(self._pari_().incgam(t)) -
sage/symbolic/random_tests.py
diff --git a/sage/symbolic/random_tests.py b/sage/symbolic/random_tests.py
a b 202 202 203 203 sage: from sage.symbolic.random_tests import * 204 204 sage: random_expr(50, nvars=3, coeff_generator=CDF.random_element) 205 sinh(arcsech(- heaviside(v2)/erf(-(0.615863165633 + 0.879368031485*I)*v1^2*v3) - gamma(pi) + erf(-(0.708874026302 - 0.954135400334*I)*v3)))^coth(-cosh(-polylog((v2 + 0.913564344312 + 0.0898040160336*I)^(-(0.723896589334 - 0.799038508886*I)*v2), -v1 - v3))/dilog(-(0.0263902659909 + 0.153261789843*I)*arctan2(pi, arccot(pi))))205 sinh(arcsech(-(0.314177274493 + 0.144437996366*I)/erf(-v1^2*e/v3) + erf(-(0.708874026302 - 0.954135400334*I)*v3) + 0.0275857401668 - 0.479027260657*I))^(-cosh(-polylog((v2^2 + (0.067987275089 + 1.08529153495*I)*v3)^(-v1 - v3), (5.29385548262 + 2.57440711353*I)*e/arctan2(arccsch(catalan), unit_step(-0.436810529675 + 0.736945423566*I))))) 206 206 sage: random_expr(5, verbose=True) 207 207 About to apply <built-in function add> to [v1, v1] 208 About to apply <built-in function div> to [-1/3, 2*v1] 209 -1/6/v1 208 About to apply <built-in function mul> to [v1, -1/2] 209 About to apply <built-in function mul> to [2*v1, -1/2*v1] 210 -v1^2 210 211 """ 211 212 vars = [(1.0, sage.calculus.calculus.var('v%d' % (n+1))) for n in range(nvars)] 212 213 if ncoeffs is None: