/** Number of partitions into distinct parts. * @param[in] n the number to be decomposed. * @return The number of ways of partitioning n into a sum of strictly positive * and distinct terms. * @test The case n=5 returns 3, which represents the 3 different sums * 5, 1+4, and 2+3. * @see table 24.5 in M. Abramowitz and I. A. Stegun, Handbook of Mathematical * Functions, Dover. * @since 2007-09-24 * @author Richard J. Mathar */ numbpartq(n)={ if( type(n) != "t_INT", error("Argument ", n, " to numbpartq() is not an integer!") ) ; /* We simply refer to the generating function. This correctly returns * zero for negative n. */ polcoeff(prod(j=1,n,1+x^j),n); } /** Number of restricted partitions. * Return the number of partitions of n into parts which are restricted to * be each <=m. * @note None of the advanced methods related to the generating functions are used. * See for example Wright in J. Reine Angew. Math 216 (1964) p 101 * @param n the number to be decomposed * @param m the maximum value of each compoment * @author Richard J. Mathar * @since 2008-07-09 */ numbpartr(n,m)={ local(gf,On=n+1) ; if( type(n) != "t_INT", error("Argument ", n, " to numbpartr() is not an integer!") ) ; if( type(m) != "t_INT", error("Argument ", m, " to numbpartr() is not an integer!") ) ; if( m>=n, return( numbpart(n)) ; ) ; gf = 1/(1-x)+O(x^On) ; for(i=2,m, gf *= 1/(1-x^i) ; ) ; return( polcoeff(gf,n,x)) ; }