#NEWLINE# def tensor_gens( base , gens , list_free_indices , sym = 0 ) : #NEWLINE# #INDENT# '\n    Returns size, res_base, res_gens BSGS for n tensors of the\n    same type\n\n    base, gens BSGS for tensors of this type\n    list_free_indices  list of the slots occupied by fixed indices\n                       for each of the tensors\n\n    sym symmetry under commutation of two tensors\n    sym   None  no symmetry\n    sym   0     commuting\n    sym   1     anticommuting\n\n    Examples\n    ========\n\n    >>> from sympy.combinatorics import Permutation\n    >>> from sympy.combinatorics.tensor_can import tensor_gens, get_symmetric_group_sgs\n    >>> Permutation.print_cyclic = True\n\n    two symmetric tensors with 3 indices without free indices\n\n    >>> base, gens = get_symmetric_group_sgs(3)\n    >>> tensor_gens(base, gens, [[], []])\n    (8, [0, 1, 3, 4], [(7)(0 1), (7)(1 2), (7)(3 4), (7)(4 5), (7)(0 3)(1 4)(2 5)])\n\n    two symmetric tensors with 3 indices with free indices in slot 1 and 0\n\n    >>> tensor_gens(base, gens, [[1], [0]])\n    (8, [0, 4], [(7)(0 2), (7)(4 5)])\n\n    four symmetric tensors with 3 indices, two of which with free indices\n\n    ' #NEWLINE# def _get_bsgs( G , base , gens , free_indices ) : #NEWLINE# #INDENT# '\n        return the BSGS for G.pointwise_stabilizer(free_indices)\n        ' #NEWLINE# if ( not free_indices ) : #NEWLINE# #INDENT# return ( base [ : ] , gens [ : ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# H = G . pointwise_stabilizer ( free_indices ) #NEWLINE# ( base , sgs ) = H . schreier_sims_incremental ( ) #NEWLINE# return ( base , sgs ) #NEWLINE# #UNINDENT# #UNINDENT# if ( ( not base ) and ( list_free_indices . count ( [ ] ) < 2 ) ) : #NEWLINE# #INDENT# n = len ( list_free_indices ) #NEWLINE# size = gens [ 0 ] . size #NEWLINE# size = ( ( n * ( gens [ 0 ] . size - 2 ) ) + 2 ) #NEWLINE# return ( size , [ ] , [ _af_new ( list ( range ( size ) ) ) ] ) #NEWLINE# #UNINDENT# if any ( list_free_indices ) : #NEWLINE# #INDENT# G = PermutationGroup ( gens ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# G = None #NEWLINE# #UNINDENT# no_free = [ ] #NEWLINE# size = gens [ 0 ] . size #NEWLINE# id_af = list ( range ( size ) ) #NEWLINE# num_indices = ( size - 2 ) #NEWLINE# if ( not list_free_indices [ 0 ] ) : #NEWLINE# #INDENT# no_free . append ( list ( range ( num_indices ) ) ) #NEWLINE# #UNINDENT# ( res_base , res_gens ) = _get_bsgs ( G , base , gens , list_free_indices [ 0 ] ) #NEWLINE# for i in range ( 1 , len ( list_free_indices ) ) : #NEWLINE# #INDENT# ( base1 , gens1 ) = _get_bsgs ( G , base , gens , list_free_indices [ i ] ) #NEWLINE# ( res_base , res_gens ) = bsgs_direct_product ( res_base , res_gens , base1 , gens1 , 1 ) #NEWLINE# if ( not list_free_indices [ i ] ) : #NEWLINE# #INDENT# no_free . append ( list ( range ( ( size - 2 ) , ( ( size - 2 ) + num_indices ) ) ) ) #NEWLINE# #UNINDENT# size += num_indices #NEWLINE# #UNINDENT# nr = ( size - 2 ) #NEWLINE# res_gens = [ h for h in res_gens if ( h . _array_form != id_af ) ] #NEWLINE# if ( ( sym is None ) or ( not no_free ) ) : #NEWLINE# #INDENT# if ( not res_gens ) : #NEWLINE# #INDENT# res_gens = [ _af_new ( id_af ) ] #NEWLINE# #UNINDENT# return ( size , res_base , res_gens ) #NEWLINE# #UNINDENT# base_comm = [ ] #NEWLINE# for i in range ( ( len ( no_free ) - 1 ) ) : #NEWLINE# #INDENT# ind1 = no_free [ i ] #NEWLINE# ind2 = no_free [ ( i + 1 ) ] #NEWLINE# a = list ( range ( ind1 [ 0 ] ) ) #NEWLINE# a . extend ( ind2 ) #NEWLINE# a . extend ( ind1 ) #NEWLINE# base_comm . append ( ind1 [ 0 ] ) #NEWLINE# a . extend ( list ( range ( ( ind2 [ ( - 1 ) ] + 1 ) , nr ) ) ) #NEWLINE# if ( sym == 0 ) : #NEWLINE# #INDENT# a . extend ( [ nr , ( nr + 1 ) ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# a . extend ( [ ( nr + 1 ) , nr ] ) #NEWLINE# #UNINDENT# res_gens . append ( _af_new ( a ) ) #NEWLINE# #UNINDENT# res_base = list ( res_base ) #NEWLINE# for i in base_comm : #NEWLINE# #INDENT# if ( i not in res_base ) : #NEWLINE# #INDENT# res_base . append ( i ) #NEWLINE# #UNINDENT# #UNINDENT# res_base . sort ( ) #NEWLINE# if ( not res_gens ) : #NEWLINE# #INDENT# res_gens = [ _af_new ( id_af ) ] #NEWLINE# #UNINDENT# return ( size , res_base , res_gens )