/** Stirling number of the 2nd kind. @param[in] n positive integer first argument @param[in] m positive integer second argument @return Stirling number of the 2nd kind. The number of ways of partitioning a set of n elements into m non-empty subsets. @author Richard J. Mathar @since 2006-11-26 */ stirling2(n,m)= { if( type(n)!="t_INT" || type(m) != "t_INT", error("Non-integer n or m in stirling2(n,m) !") ; ) ; if(n<0, error("Negative n = ",n," in stirling2(n,m) !") ; ) ; if(m<0, error("Negative m = ",m," in stirling2(n,m) !") ; ) ; return(sum(k=0,m,(-1)^(m-k)*binomial(m,k)*k^n)/m!) ; } /** Stirling number of the 1st kind. @param[in] n positive integer first argument @param[in] m positive integer second argument @return Stirling number of the first kind. Up to the sign, the number of permutations of n symbols which have exactly m cycles. @author Richard J. Mathar @since 2006-11-26 */ stirling(n,m)= { if( type(n)!="t_INT" || type(m) != "t_INT", error("Non-integer n or m in stirling(n,m) !") ; ) ; if(n<0, error("Negative n = ",n," in stirling(n,m) !") ; ) ; if(m<0, error("Negative m = ",m," in stirling(n,m) !") ; ) ; if( n==m, return(1), return(sum(k=0,n-m, (-1)^k*binomial(n-1+k,n-m+k)*binomial(2*n-m,n-m-k) *stirling2(n-m+k,k)) ) ; ) ; }