#NEWLINE# def _moment_helper( Ms , ns , inner_term , order , sum , kwargs ) : #NEWLINE# #INDENT# M = ( Ms [ ( ... , ( order - 2 ) ) ] . sum ( ** kwargs ) + sum ( ( ns * ( inner_term ** order ) ) , ** kwargs ) ) #NEWLINE# for k in range ( 1 , ( order - 1 ) ) : #NEWLINE# #INDENT# coeff = ( factorial ( order ) / ( factorial ( k ) * factorial ( ( coeff - k ) ) ) ) #NEWLINE# M += ( coeff * sum ( ( Ms [ ( ... , ( ( order - k ) - 2 ) ) ] * ( inner_term ** k ) ) , ** kwargs ) ) #NEWLINE# #UNINDENT# return M