#NEWLINE# def enum_range( self , multiplicities , lb , ub ) : #NEWLINE# #INDENT# "Enumerate the partitions of a multiset with\n        ``lb < num(parts) <= ub``.\n\n        In particular, if partitions with exactly ``k`` parts are\n        desired, call with ``(multiplicities, k - 1, k)``.  This\n        method generalizes enum_all, enum_small, and enum_large.\n\n        Examples\n        ========\n\n        >>> from sympy.utilities.enumerative import list_visitor\n        >>> from sympy.utilities.enumerative import MultisetPartitionTraverser\n        >>> m = MultisetPartitionTraverser()\n        >>> states = m.enum_range([2,2], 1, 2)\n        >>> list(list_visitor(state, 'ab') for state in states)\n        [[['a', 'a', 'b'], ['b']],\n        [['a', 'a'], ['b', 'b']],\n        [['a', 'b', 'b'], ['a']],\n        [['a', 'b'], ['a', 'b']]]\n\n        " #NEWLINE# self . discarded = 0 #NEWLINE# if ( ( ub <= 0 ) or ( lb >= sum ( multiplicities ) ) ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# self . _initialize_enumeration ( multiplicities ) #NEWLINE# self . decrement_part_large ( self . top_part ( ) , 0 , lb ) #NEWLINE# while True : #NEWLINE# #INDENT# good_partition = True #NEWLINE# while self . spread_part_multiplicity ( ) : #NEWLINE# #INDENT# self . db_trace ( 'spread 1' ) #NEWLINE# if ( not self . decrement_part_large ( self . top_part ( ) , 0 , lb ) ) : #NEWLINE# #INDENT# self . db_trace ( '  Discarding (large cons)' ) #NEWLINE# self . discarded += 1 #NEWLINE# good_partition = False #NEWLINE# break #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( state . lpart >= ub ) : #NEWLINE# #INDENT# self . discarded += 1 #NEWLINE# good_partition = False #NEWLINE# self . db_trace ( '  Discarding small cons' ) #NEWLINE# self . lpart = ( ub - 2 ) #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if good_partition : #NEWLINE# #INDENT# state = [ self . f , self . lpart , self . pstack ] #NEWLINE# ( yield state ) #NEWLINE# #UNINDENT# while ( not self . decrement_part_range ( self . top_part ( ) , lb , ub ) ) : #NEWLINE# #INDENT# self . db_trace ( 'Failed decrement, going to backtrack' ) #NEWLINE# if ( self . lpart == 0 ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# self . lpart -= 1 #NEWLINE# self . db_trace ( 'Backtracked to' ) #NEWLINE# #UNINDENT# self . db_trace ( 'decrement ok, about to expand' )