def test_factorial_simplify(): # There are more tests in test_factorials.py. These are just to # ensure that simplify() calls factorial_simplify correctly from sympy.specfun.factorials import factorial x = Symbol('x') assert simplify(factorial(x)/x) == factorial(x-1) assert simplify(factorial(factorial(x))) == factorial(factorial(x))
def test_hypersimp(): n, k = symbols('nk', integer=True) assert hypersimp(factorial(k), k) == k + 1 assert hypersimp(factorial(k**2), k) is None assert hypersimp(2**k/factorial(k)**2, k) == 2/(k+1)**2 assert hypersimp(binomial(n, k), k) == (n-k)/(k+1) assert hypersimp(binomial(n+1, k), k) == (n-k+1)/(k+1) term = (4*k+1)*factorial(k)/factorial(2*k+1) assert hypersimp(term, k) == (4*k + 5)/(6 + 16*k**2 + 28*k) term = 1/((2*k-1)*factorial(2*k+1)) assert hypersimp(term, k) == (2*k-1)/(2*k+1)/(2*k+2)/(2*k+3) term = binomial(n, k)*(-1)**k/factorial(k) assert hypersimp(term, k) == (k - n)/(k+1)**2