当前位置: 首页>>代码示例>>Python>>正文


Python factorials.factorial函数代码示例

本文整理汇总了Python中sympy.functions.combinatorial.factorials.factorial函数的典型用法代码示例。如果您正苦于以下问题:Python factorial函数的具体用法?Python factorial怎么用?Python factorial使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了factorial函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _eval_rewrite_as_polynomial

 def _eval_rewrite_as_polynomial(self, n, a, b, x):
     from sympy import Sum
     # TODO: Make sure n \in N
     k = Dummy("k")
     kern = (RisingFactorial(-n, k) * RisingFactorial(a + b + n + 1, k) * RisingFactorial(a + k + 1, n - k) /
             factorial(k) * ((1 - x)/2)**k)
     return 1 / factorial(n) * Sum(kern, (k, 0, n))
开发者ID:amitsaha,项目名称:sympy,代码行数:7,代码来源:polynomials.py

示例2: taylor_term

 def taylor_term(n, x, *previous_terms):
     if n < 0:
         return S.Zero
     else:
         x = sympify(x)
         if len(previous_terms) > 1:
             p = previous_terms[-1]
             return (
                 (3 ** (S(1) / 3) * x) ** (-n)
                 * (3 ** (S(1) / 3) * x) ** (n + 1)
                 * sin(pi * (2 * n / 3 + S(4) / 3))
                 * factorial(n)
                 * gamma(n / 3 + S(2) / 3)
                 / (sin(pi * (2 * n / 3 + S(2) / 3)) * factorial(n + 1) * gamma(n / 3 + S(1) / 3))
                 * p
             )
         else:
             return (
                 S.One
                 / (3 ** (S(2) / 3) * pi)
                 * gamma((n + S.One) / S(3))
                 * sin(2 * pi * (n + S.One) / S(3))
                 / factorial(n)
                 * (root(3, 3) * x) ** n
             )
开发者ID:LuckyStrikes1090,项目名称:sympy,代码行数:25,代码来源:bessel.py

示例3: wedge

def wedge(first_tensor, second_tensor):
    """
    Finds outer product (wedge) of two tensor arguments.
    The algoritm is too find the asymmetric form of tensor product of
    two arguments. The resulted array is multiplied on coefficient which is
    coeff = factorial(p+s)/factorial(p)*factorial(s)

    Examples
    ========
    from tensor_analysis.arraypy import Arraypy, Tensor
    from tensor_analysis.tensor_methods import wedge
    >>> a = Arraypy((3,), 'A').to_tensor((-1))
    >>> b = Arraypy((3,), 'B').to_tensor((1,))
    >>> c = wedge(a, b)
    >>> print(c)
    0  10*A[0]*B[1] - 10*A[1]*B[0]  10*A[0]*B[2] - 10*A[2]*B[0]  
    -10*A[0]*B[1] + 10*A[1]*B[0]  0  10*A[1]*B[2] - 10*A[2]*B[1]  
    -10*A[0]*B[2] + 10*A[2]*B[0]  -10*A[1]*B[2] + 10*A[2]*B[1]  0 


    """
    if not isinstance(first_tensor, TensorArray):
        raise TypeError('Input must be of TensorArray type')
    if not isinstance(second_tensor, TensorArray):
        raise TypeError('Input must be of TensorArray type')

    p = len(first_tensor)
    s = len(second_tensor)

    coeff = factorial(p + s) / (factorial(p) * factorial(s))
    return coeff * asymmetric(tensor_product(first_tensor, second_tensor))
开发者ID:AunShiLord,项目名称:Tensor-analysis,代码行数:31,代码来源:tensor_methods.py

示例4: calc2

 def calc2(n,m):
     if m >= 0:
         return assoc_legendre._calc2(n,m)
     else:
         factorial = C.Factorial
         m = -m
         return (-1)**m *factorial(n-m)/factorial(n+m) * assoc_legendre._calc2(n, m)
开发者ID:Aang,项目名称:sympy,代码行数:7,代码来源:polynomials.py

示例5: asymmetric

def asymmetric(in_arr):
    """
    Creates the asymmetric form of input tensor.
    Input: Arraypy or TensorArray with equal axes (array shapes).
    Output: asymmetric array. Output type - Arraypy or TensorArray, depends of input

    Examples
    ========

    >>> from sympy.tensor.arraypy import list2arraypy
    >>> from sympy.tensor.tensor_methods import asymmetric
    >>> a = list2arraypy(list(range(9)), (3,3))
    >>> b = asymmetric(a)
    >>> print (b)
    0  -1.00000000000000  -2.00000000000000
    1.00000000000000  0  -1.00000000000000
    2.00000000000000  1.00000000000000  0
    """
    if not isinstance(in_arr, Arraypy):
        raise TypeError('Input must be Arraypy or TensorArray type')

    flag = 0
    for j in range(in_arr.rank):
        if (in_arr.shape[0] != in_arr.shape[j]):
            raise ValueError('Different size of arrays axes')

    # forming list of tuples for Arraypy constructor of type a = Arraypy( [(a,
    # b), (c, d), ... , (y, z)] )
    arg = [(in_arr.start_index[i], in_arr.end_index[i])
           for i in range(in_arr.rank)]

    # if in_arr TensorArray, then res_arr will be TensorArray, else it will be
    # Arraypy
    if isinstance(in_arr, TensorArray):
        res_arr = TensorArray(Arraypy(arg), in_arr.ind_char)
    else:
        res_arr = Arraypy(arg)

    signs = [0 for i in range(factorial(in_arr.rank))]
    temp_i = 0
    for p in permutations(range(in_arr.rank)):
        signs[temp_i] = perm_parity(list(p))
        temp_i += 1

    index = [in_arr.start_index[i] for i in range(in_arr.rank)]

    for i in range(len(in_arr)):
        perm = list(permutations(index))
        perm_number = 0
        for temp_index in perm:
            res_arr[tuple(index)] += signs[perm_number] * \
                in_arr[tuple(temp_index)]
            perm_number += 1
        if isinstance(res_arr[tuple(index)], int):
            res_arr[tuple(index)] = float(res_arr[tuple(index)])
        res_arr[tuple(index)] /= factorial(in_arr.rank)

        index = in_arr.next_index(index)

    return res_arr
开发者ID:AunShiLord,项目名称:Tensor-analysis,代码行数:60,代码来源:tensor_methods.py

示例6: as_real_imag

 def as_real_imag(self, deep=True, **hints):
     # TODO: Handle deep and hints
     n, m, theta, phi = self.args
     re = (sqrt((2*n + 1)/(4*pi) * factorial(n - m)/factorial(n + m)) *
           cos(m*phi) * assoc_legendre(n, m, cos(theta)))
     im = (sqrt((2*n + 1)/(4*pi) * factorial(n - m)/factorial(n + m)) *
           sin(m*phi) * assoc_legendre(n, m, cos(theta)))
     return (re, im)
开发者ID:asmeurer,项目名称:sympy,代码行数:8,代码来源:spherical_harmonics.py

示例7: _eval_rewrite_as_polynomial

 def _eval_rewrite_as_polynomial(self, n, x):
     from sympy import Sum
     # Make sure n \in N_0
     if n.is_negative or n.is_integer is False:
         raise ValueError("Error: n should be a non-negative integer.")
     k = Dummy("k")
     kern = RisingFactorial(
         -n, k) / (gamma(k + alpha + 1) * factorial(k)) * x**k
     return gamma(n + alpha + 1) / factorial(n) * Sum(kern, (k, 0, n))
开发者ID:ChaliZhg,项目名称:sympy,代码行数:9,代码来源:polynomials.py

示例8: interpolate

def interpolate(data, x):
    """
    Construct an interpolating polynomial for the data points.

    Examples
    ========

    >>> from sympy.polys.polyfuncs import interpolate
    >>> from sympy.abc import x

    A list is interpreted as though it were paired with a range starting
    from 1:

    >>> interpolate([1, 4, 9, 16], x)
    x**2

    This can be made explicit by giving a list of coordinates:

    >>> interpolate([(1, 1), (2, 4), (3, 9)], x)
    x**2

    The (x, y) coordinates can also be given as keys and values of a
    dictionary (and the points need not be equispaced):

    >>> interpolate([(-1, 2), (1, 2), (2, 5)], x)
    x**2 + 1
    >>> interpolate({-1: 2, 1: 2, 2: 5}, x)
    x**2 + 1

    """
    n = len(data)
    poly = None

    if isinstance(data, dict):
        X, Y = list(zip(*data.items()))
        poly = interpolating_poly(n, x, X, Y)
    else:
        if isinstance(data[0], tuple):
            X, Y = list(zip(*data))
            poly = interpolating_poly(n, x, X, Y)
        else:
            Y = list(data)

            numert = Mul(*[(x - i) for i in range(1, n + 1)])
            denom = -factorial(n - 1) if n%2 == 0 else factorial(n - 1)
            coeffs = []
            for i in range(1, n + 1):
                coeffs.append(numert/(x - i)/denom)
                denom = denom/(i - n)*i

            poly = Add(*[coeff*y for coeff, y in zip(coeffs, Y)])

    return poly.expand()
开发者ID:asmeurer,项目名称:sympy,代码行数:53,代码来源:polyfuncs.py

示例9: taylor_term

 def taylor_term(n, x, *previous_terms):
     if n < 0:
         return S.Zero
     else:
         x = sympify(x)
         if len(previous_terms) > 1:
             p = previous_terms[-1]
             return (3**(S(1)/3)*x * Abs(sin(2*pi*(n + S.One)/S(3))) * factorial((n - S.One)/S(3)) /
                     ((n + S.One) * Abs(cos(2*pi*(n + S.Half)/S(3))) * factorial((n - 2)/S(3))) * p)
         else:
             return (S.One/(root(3, 6)*pi) * gamma((n + S.One)/S(3)) * Abs(sin(2*pi*(n + S.One)/S(3))) /
                     factorial(n) * (root(3, 3)*x)**n)
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:12,代码来源:bessel.py

示例10: _nP

def _nP(n, k=None, replacement=False):
    from sympy.functions.combinatorial.factorials import factorial
    from sympy.core.mul import prod

    if k == 0:
        return 1
    if isinstance(n, SYMPY_INTS):  # n different items
        # assert n >= 0
        if k is None:
            return sum(_nP(n, i, replacement) for i in range(n + 1))
        elif replacement:
            return n**k
        elif k > n:
            return 0
        elif k == n:
            return factorial(k)
        elif k == 1:
            return n
        else:
            # assert k >= 0
            return _product(n - k + 1, n)
    elif isinstance(n, _MultisetHistogram):
        if k is None:
            return sum(_nP(n, i, replacement) for i in range(n[_N] + 1))
        elif replacement:
            return n[_ITEMS]**k
        elif k == n[_N]:
            return factorial(k)/prod([factorial(i) for i in n[_M] if i > 1])
        elif k > n[_N]:
            return 0
        elif k == 1:
            return n[_ITEMS]
        else:
            # assert k >= 0
            tot = 0
            n = list(n)
            for i in range(len(n[_M])):
                if not n[i]:
                    continue
                n[_N] -= 1
                if n[i] == 1:
                    n[i] = 0
                    n[_ITEMS] -= 1
                    tot += _nP(_MultisetHistogram(n), k - 1)
                    n[_ITEMS] += 1
                    n[i] = 1
                else:
                    n[i] -= 1
                    tot += _nP(_MultisetHistogram(n), k - 1)
                    n[i] += 1
                n[_N] += 1
            return tot
开发者ID:Zulko,项目名称:sympy,代码行数:52,代码来源:numbers.py

示例11: eval

 def eval(cls, n, m, x):
     if m.could_extract_minus_sign():
         # P^{-m}_n  --->  F * P^m_n
         return S.NegativeOne**(-m) * (factorial(m + n)/factorial(n - m)) * assoc_legendre(n, -m, x)
     if m == 0:
         # P^0_n  --->  L_n
         return legendre(n, x)
     if x == 0:
         return 2**m*sqrt(S.Pi) / (gamma((1 - m - n)/2)*gamma(1 - (m - n)/2))
     if n.is_Number and m.is_Number and n.is_integer and m.is_integer:
         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))
         return cls._eval_at_order(int(n), abs(int(m))).subs(_x, x)
开发者ID:ChaliZhg,项目名称:sympy,代码行数:15,代码来源:polynomials.py

示例12: _eval_expand_func

    def _eval_expand_func(self, **hints):
        n, z = self.args

        if n.is_Integer and n.is_nonnegative:
            if z.is_Add:
                coeff = z.args[0]
                if coeff.is_Integer:
                    e = -(n + 1)
                    if coeff > 0:
                        tail = Add(*[Pow(
                            z - i, e) for i in range(1, int(coeff) + 1)])
                    else:
                        tail = -Add(*[Pow(
                            z + i, e) for i in range(0, int(-coeff))])
                    return polygamma(n, z - coeff) + (-1)**n*factorial(n)*tail

            elif z.is_Mul:
                coeff, z = z.as_two_terms()
                if coeff.is_Integer and coeff.is_positive:
                    tail = [ polygamma(n, z + Rational(
                        i, coeff)) for i in range(0, int(coeff)) ]
                    if n == 0:
                        return Add(*tail)/coeff + log(coeff)
                    else:
                        return Add(*tail)/coeff**(n + 1)
                z *= coeff

        return polygamma(n, z)
开发者ID:SungSingSong,项目名称:sympy,代码行数:28,代码来源:gamma_functions.py

示例13: _compute_formula

def _compute_formula(f, x, P, Q, k, m, k_max):
    """Computes the formula for f."""
    from sympy.polys import roots

    sol = []
    for i in range(k_max + 1, k_max + m + 1):
        r = f.diff(x, i).limit(x, 0) / factorial(i)
        if r is S.Zero:
            continue

        kterm = m*k + i
        res = r

        p = P.subs(k, kterm)
        q = Q.subs(k, kterm)
        c1 = p.subs(k, 1/k).leadterm(k)[0]
        c2 = q.subs(k, 1/k).leadterm(k)[0]
        res *= (-c1 / c2)**k

        for r, mul in roots(p, k).items():
            res *= rf(-r, k)**mul
        for r, mul in roots(q, k).items():
            res /= rf(-r, k)**mul

        sol.append((res, kterm))

    return sol
开发者ID:chris-turner137,项目名称:sympy,代码行数:27,代码来源:formal.py

示例14: eval

    def eval(cls, arg):
        if arg.is_Number:
            if arg is S.NaN:
                return S.NaN
            elif arg is S.Infinity:
                return S.Infinity
            elif arg.is_Integer:
                if arg.is_positive:
                    return factorial(arg - 1)
                else:
                    return S.ComplexInfinity
            elif arg.is_Rational:
                if arg.q == 2:
                    n = abs(arg.p) // arg.q

                    if arg.is_positive:
                        k, coeff = n, S.One
                    else:
                        n = k = n + 1

                        if n & 1 == 0:
                            coeff = S.One
                        else:
                            coeff = S.NegativeOne

                    for i in range(3, 2*k, 2):
                        coeff *= i

                    if arg.is_positive:
                        return coeff*sqrt(S.Pi) / 2**n
                    else:
                        return 2**n*sqrt(S.Pi) / coeff

        if arg.is_integer and arg.is_nonpositive:
            return S.ComplexInfinity
开发者ID:SungSingSong,项目名称:sympy,代码行数:35,代码来源:gamma_functions.py

示例15: taylor_term

 def taylor_term(n, x, *previous_terms):
     from sympy.functions.combinatorial.numbers import euler
     if n < 0 or n % 2 == 1:
         return S.Zero
     else:
         x = sympify(x)
         return euler(n) / factorial(n) * x**(n)
开发者ID:moorepants,项目名称:sympy,代码行数:7,代码来源:hyperbolic.py


注:本文中的sympy.functions.combinatorial.factorials.factorial函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。