def monomial_count(V, N): r""" Computes the number of monomials. The number of monomials is given by the following formula: .. math:: \frac{(\#V + N)!}{\#V! N!} where ``N`` is a total degree and ``V`` is a set of variables. **Examples** >>> from sympy import monomials, monomial_count >>> from sympy.abc import x, y >>> monomial_count(2, 2) 6 >>> M = monomials([x, y], 2) >>> sorted(M) [1, x, y, x**2, y**2, x*y] >>> len(M) 6 """ return C.Factorial(V + N) / C.Factorial(V) / C.Factorial(N)
def eval(cls, n, m, x): if n.is_integer and n >= 0 and m.is_integer and abs(m) <= n: assoc = cls.calc(int(n), abs(int(m))) if m < 0: assoc *= (-1)**(-m) * (C.Factorial(n + m)/C.Factorial(n - m)) return assoc.subs(_x, x) if n.is_negative: raise ValueError("%s : 1st index must be nonnegative integer (got %r)" % (cls, n)) if abs(m) > n: raise ValueError("%s : abs('2nd index') must be <= '1st index' (got %r, %r)" % (cls, n, m))
def taylor_term(n, x, *previous_terms): if n<0: return S.Zero if n==0: return S.One x = sympify(x) if previous_terms: p = previous_terms[-1] if p is not None: return p * x / n return x**n/C.Factorial()(n)
def taylor_term(n, x, *previous_terms): if n < 0 or n % 2 == 1: return S.Zero else: x = sympify(x) if len(previous_terms) > 2: p = previous_terms[-2] return -p * x**2 / (n * (n - 1)) else: return (-1)**(n // 2) * x**(n) / C.Factorial(n)
def taylor_term(n, x, *previous_terms): if n == 0: return 1 / sympify(x) elif n < 0 or n % 2 == 0: return S.Zero else: x = sympify(x) B = S.Bernoulli(n + 1) F = C.Factorial(n + 1) return (-1)**((n + 1) // 2) * 2**(n + 1) * B / F * x**n
def taylor_term(n, x, *previous_terms): if n < 0 or n % 2 == 0: return S.Zero else: x = sympify(x) a, b = ((n - 1) // 2), 2**(n + 1) B = C.bernoulli(n + 1) F = C.Factorial(n + 1) return (-1)**a * b * (b - 1) * B / F * x**n
def taylor_term(n, x, *previous_terms): if n < 0 or n % 2 == 0: return S.Zero else: x = sympify(x) k = (n - 1) // 2 if len(previous_terms) > 2: return -previous_terms[-2] * x**2 * (n - 2) / (n * k) else: return 2 * (-1)**k * x**n / (n * C.Factorial(k) * sqrt(S.Pi))
def taylor_term(n, x, *previous_terms): if n < 0 or n % 2 == 0: return S.Zero else: x = sympify(x) a = 2**(n + 1) B = C.bernoulli(n + 1) F = C.Factorial(n + 1) return a * (a - 1) * B / F * x**n
def taylor_term(n, x, *previous_terms): if n < 0 or n % 2 == 0: return S.Zero else: x = sympify(x) if len(previous_terms) >= 2 and n > 2: p = previous_terms[-2] return p * (n - 2)**2 / (n * (n - 1)) * x**2 else: k = (n - 1) // 2 R = C.RisingFactorial(S.Half, k) F = C.Factorial(k) return R / F * x**n / n
def taylor_term(n, x, *previous_terms): if n == 0: return S.Pi * S.ImaginaryUnit / 2 elif n < 0 or n % 2 == 0: return S.Zero else: x = sympify(x) if len(previous_terms) > 2: p = previous_terms[-2] return p * (n - 2)**2 / (k * (k - 1)) * x**2 else: k = (n - 1) // 2 R = C.RisingFactorial(S.Half, k) F = C.Factorial(k) return -R / F * S.ImaginaryUnit * x**n / n