#NEWLINE# def canonicalize_naive( g , dummies , sym , * v ) : #NEWLINE# #INDENT# '\n    Canonicalize tensor formed by tensors of the different types\n\n    g  permutation representing the tensor\n    dummies  list of dummy indices\n    msym symmetry of the metric\n\n    v is a list of (base_i, gens_i, n_i, sym_i) for tensors of type `i`\n    base_i, gens_i BSGS for tensors of this type\n    n_i  number ot tensors of type `i`\n\n    sym_i symmetry under exchange of two component tensors of type `i`\n          None  no symmetry\n          0     commuting\n          1     anticommuting\n\n    Return 0 if the tensor is zero, else return the array form of\n    the permutation representing the canonical form of the tensor.\n\n    Examples\n    ========\n\n    >>> from sympy.combinatorics.testutil import canonicalize_naive\n    >>> from sympy.combinatorics.tensor_can import get_symmetric_group_sgs\n    >>> from sympy.combinatorics import Permutation, PermutationGroup\n    >>> g = Permutation([1, 3, 2, 0, 4, 5])\n    >>> base2, gens2 = get_symmetric_group_sgs(2)\n    >>> canonicalize_naive(g, [2, 3], 0, (base2, gens2, 2, 0))\n    [0, 2, 1, 3, 4, 5]\n    ' #NEWLINE# from sympy.combinatorics.perm_groups import PermutationGroup #NEWLINE# from sympy.combinatorics.tensor_can import gens_products , dummy_sgs #NEWLINE# from sympy.combinatorics.permutations import Permutation , _af_rmul #NEWLINE# v1 = [ ] #NEWLINE# for i in range ( len ( v ) ) : #NEWLINE# #INDENT# ( base_i , gens_i , n_i , sym_i ) = v [ i ] #NEWLINE# v1 . append ( ( base_i , gens_i , ( [ [ ] ] * n_i ) , sym_i ) ) #NEWLINE# #UNINDENT# ( size , sbase , sgens ) = gens_products ( * v1 ) #NEWLINE# dgens = dummy_sgs ( dummies , sym , ( size - 2 ) ) #NEWLINE# if isinstance ( sym , int ) : #NEWLINE# #INDENT# num_types = 1 #NEWLINE# dummies = [ dummies ] #NEWLINE# sym = [ sym ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# num_types = len ( sym ) #NEWLINE# #UNINDENT# dgens = [ ] #NEWLINE# for i in range ( num_types ) : #NEWLINE# #INDENT# dgens . extend ( dummy_sgs ( dummies [ i ] , sym [ i ] , ( a - 2 ) ) ) #NEWLINE# #UNINDENT# S = PermutationGroup ( sgens ) #NEWLINE# D = PermutationGroup ( [ Permutation ( x ) for x in dgens ] ) #NEWLINE# dlist = list ( D . generate ( af = True ) ) #NEWLINE# g = g . array_form #NEWLINE# st = set ( ) #NEWLINE# for s in S . generate ( af = True ) : #NEWLINE# #INDENT# h = _af_rmul ( g , s ) #NEWLINE# for d in dlist : #NEWLINE# #INDENT# q = tuple ( _af_rmul ( d , h ) ) #NEWLINE# st . add ( q ) #NEWLINE# #UNINDENT# #UNINDENT# a = list ( st ) #NEWLINE# a . sort ( ) #NEWLINE# prev = ( ( 0 , ) * size ) #NEWLINE# for h in a : #NEWLINE# #INDENT# if ( h [ : ( - 2 ) ] == prev [ : ( - 2 ) ] ) : #NEWLINE# #INDENT# if ( h [ ( - 1 ) ] != prev [ ( - 1 ) ] ) : #NEWLINE# #INDENT# return 0 #NEWLINE# #UNINDENT# #UNINDENT# prev = h #NEWLINE# #UNINDENT# return list ( a [ 0 ] )