📜  Python| sympy.subfactorial() 方法

📅  最后修改于: 2022-05-13 01:54:28.184000             🧑  作者: Mango

Python| sympy.subfactorial() 方法

sympy.subfactorial()方法的帮助下,我们可以在 SymPy 中找到一个数的 Subfactorial。一个数字的子阶乘由下式给出 -

 !n = \begin{cases} 1 & n = 0 \\ 0 & n = 1 \\ (n-1)(!(n-1) + !(n-2)) & n > 1 \end{cases}

示例 #1:

# import sympy 
from sympy import * 
  
n = 4
print("Value of n = {}".format(n))
   
# Use sympy.subfactorial() method 
subfactorial_n = subfactorial(n)  
      
print("Subfactorial of n : {}".format(subfactorial_n))  

输出:

Value of n = 4
Subfactorial of n : 9

示例 #2:

# import sympy 
from sympy import * 
  
n = 9
print("Value of n = {}".format(n))
   
# Use sympy.subfactorial() method 
subfactorial_n = subfactorial(n)  
      
print("Subfactorial of n : {}".format(subfactorial_n))  

输出:

Value of n = 9
Subfactorial of n : 133496