Ticket #9240: trac_9240_full_simplify_gamma.patch

File trac_9240_full_simplify_gamma.patch, 2.2 KB (added by tomc, 11 years ago)

based on Sage 4.4.1

  • sage/symbolic/expression.pyx

    # HG changeset patch
    # User Tom Coates <tomc@imperial.ac.uk>
    # Date 1276573549 25200
    # Node ID a0911505b956f708ba4fd3acd07910a8e21e7787
    # Parent  263f1caae32dd7ac94a108e8b279a9872b56f260
    trac 9240: fix full_simplify() of gamma functions
    
    diff -r 263f1caae32d -r a0911505b956 sage/symbolic/expression.pyx
    a b  
    57565756            n + 1
    57575757
    57585758        ::
     5759       
    57595760            sage: f = factorial(n)*(n+1); f
    57605761            (n + 1)*factorial(n)
    57615762            sage: simplify(f)
     
    57785779            1/2*(x - 1)*x + 1/2*x + 1/2
    57795780            sage: g.simplify_rational()
    57805781            1/2*x^2 + 1/2
     5782
     5783
     5784        TESTS:
     5785       
     5786        Check that the problem with applying full_simplify() to gamma functions (Trac 9240)
     5787        has been fixed::
     5788
     5789            sage: gamma(37)
     5790            371993326789901217467999448150835200000000
     5791            sage: gamma(0)
     5792            Infinity
     5793            sage: gamma(-4)
     5794            Infinity
     5795            sage: gamma(-4/3)
     5796            gamma(-4/3)
     5797            sage: gamma(1/3).full_simplify()
     5798            gamma(1/3)
     5799            sage: gamma(4/3).full_simplify()
     5800            1/3*gamma(1/3)
     5801
    57815802        """
    57825803        return self.parent()(self._maxima_().makefact().factcomb().minfactorial())
    57835804
  • sage/symbolic/pynac.pyx

    diff -r 263f1caae32d -r a0911505b956 sage/symbolic/pynac.pyx
    a b  
    11311131
    11321132from sage.rings.arith import factorial
    11331133cdef public object py_factorial(object x) except +:
     1134    # factorial(x) is only defined for non-negative integers x
     1135    # so we first test if x can be coerced into ZZ and is non-negative.
     1136    # If this is not the case then we return the symbolic expression gamma(x+1)
     1137    # This fixes Trac 9240
    11341138    try:
     1139        x_in_ZZ = ZZ(x)
     1140        coercion_success = True
     1141    except TypeError:
     1142        coercion_success = False
     1143       
     1144    if coercion_success and x_in_ZZ >= 0:
    11351145        return factorial(x)
    1136     except TypeError:
     1146    else:
    11371147        return py_tgamma(x+1)
    11381148
    11391149cdef public object py_doublefactorial(object x) except +: