Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
17489: deprecate superfluous functions
Browse files Browse the repository at this point in the history
  • Loading branch information
rwst committed Dec 19, 2014
1 parent 80274a1 commit 3b54c75
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
29 changes: 28 additions & 1 deletion src/sage/rings/arith.py
Expand Up @@ -334,6 +334,30 @@ def bernoulli(n, algorithm='default', num_threads=1):
raise ValueError("invalid choice of algorithm")


def factorial(n, algorithm='gmp'):
r"""
This version of ``factorial`` is deprecated. Please use
:meth:`sage.functions.other.factorial`.
EXAMPLES::
sage: from sage.rings.arith import factorial as fact
sage: fact(8)
doctest:...: DeprecationWarning: This version of factorial is deprecated. Please use sage.functions.other.factorial.
See http://trac.sagemath.org/17489 for details.
40320
"""
from sage.misc.superseded import deprecation
deprecation(17489, 'This version of factorial is deprecated. Please use sage.functions.other.factorial.')
if n < 0:
raise ValueError("factorial -- must be nonnegative")
if algorithm == 'gmp':
return ZZ(n).factorial()
elif algorithm == 'pari':
return pari.factorial(n)
else:
raise ValueError('unknown algorithm')

def is_prime(n):
r"""
Returns ``True`` if `n` is prime, and ``False`` otherwise.
Expand Down Expand Up @@ -3194,7 +3218,9 @@ def binomial(x, m, **kwds):
P = type(x)
if m < 0:
return P(0)
return misc.prod([x-i for i in xrange(m)])/factorial(m)
else:
from sage.functions.other import factorial
return misc.prod([x-i for i in xrange(m)])/factorial(m)

def multinomial(*ks):
r"""
Expand Down Expand Up @@ -5266,6 +5292,7 @@ def subfactorial(n):
- Jaap Spies (2007-01-23)
"""
from sage.functions.other import factorial
return factorial(n)*sum(((-1)**k)/factorial(k) for k in range(n+1))


Expand Down
18 changes: 6 additions & 12 deletions src/sage/symbolic/pynac.pyx
Expand Up @@ -1294,19 +1294,11 @@ def py_tgamma_for_doctests(x):
cdef public object py_factorial(object x) except +:
"""
The factorial function exported to pynac.
TESTS::
sage: from sage.symbolic.pynac import py_factorial_py as py_factorial
sage: py_factorial(4)
24
sage: py_factorial(-2/3)
2.67893853470775
"""
# factorial(x) is only defined for non-negative integers x
# so we first test if x can be coerced into ZZ and is non-negative.
# If this is not the case then we return the symbolic expression gamma(x+1)
# This fixes Trac 9240
# This fixes :trac:`9240`
try:
x_in_ZZ = ZZ(x)
coercion_success = True
Expand All @@ -1320,16 +1312,18 @@ cdef public object py_factorial(object x) except +:

def py_factorial_py(x):
"""
This function is a python wrapper around py_factorial(). This wrapper
is needed when we override the eval() method for GiNaC's factorial
function in sage.functions.other.Function_factorial.
Deprecated.
TESTS::
sage: from sage.symbolic.pynac import py_factorial_py
sage: py_factorial_py(3)
doctest:...: DeprecationWarning: This version of factorial is deprecated. Please use sage.functions.other.factorial.
See http://trac.sagemath.org/17489 for details.
6
"""
from sage.misc.superseded import deprecation
deprecation(17489, 'This version of factorial is deprecated. Please use sage.functions.other.factorial.')
return py_factorial(x)

cdef public object py_doublefactorial(object x) except +:
Expand Down

0 comments on commit 3b54c75

Please sign in to comment.