(blst)
return new_blst_coef, new_blst_expand
Repetitively applies reduce_basis_loop to blst
        product representation until normal form is realized.
Repetitively applies reduce_basis_loop to blst
        product representation until normal form is realized.
Repetitively applies reduce_basis_loop to blst product representation until normal form is realized .
def reduce_basis(blst):
        """
        Repetitively applies reduce_basis_loop to blst
        product representation until normal form is realized.
        """
        if blst == []:  # blst represents scalar
            blst_coef = [S.One]
            blst_expand = [[]]
            return blst_coef, blst_expand
        blst_expand = [blst]
        blst_coef = [S.One]
        blst_flg = [False]
        # reduce untill all blst revise flgs are True
        while not reduce(operator.and_, blst_flg):
            for i in range(len(blst_flg)):
                if not blst_flg[i]:  # keep revising if revise flg is False
                    tmp = MV.reduce_basis_loop(blst_expand[i])
                    if isinstance(tmp, bool):
                        blst_flg[i] = tmp  # revision of blst_expand[i] complete
                    elif len(tmp) == 3:  # blst_expand[i] contracted
                        blst_coef[i] = tmp[0] * blst_coef[i]
                        blst_expand[i] = tmp[1]
                        blst_flg[i] = tmp[2]
                    else:  # blst_expand[i] revised
                        blst_coef[i] = -blst_coef[i]
                        # if revision force one more pass in case revision
                        # causes repeated index previous to revised pair of
                        # indexes
                        blst_flg[i] = False
                        blst_expand[i] = tmp[3]
                        blst_coef.append(-blst_coef[i] * tmp[0])
                        blst_expand.append(tmp[1])
                        blst_flg.append(tmp[2])
        new_blst_coef = []
        new_blst_expand = []
        for (coef, expand) in zip(blst_coef, blst_expand):
            if expand in new_blst_expand:
                i = new_blst_expand.index(expand)
                new_blst_coef[i] += coef
            else:
                new_blst_expand.append(expand)
                new_blst_coef.append(coef)
        return new_blst_coef, new_blst_expand
def reduce_basis ( blst ) : if blst == [ ] : # blst represents scalar blst_coef = [ S . One ] blst_expand = [ [ ] ] return blst_coef , blst_expand blst_expand = [ blst ] blst_coef = [ S . One ] blst_flg = [ False ] # reduce untill all blst revise flgs are True while not reduce ( operator . and_ , blst_flg ) : for i in range ( len ( blst_flg ) ) : if not blst_flg [ i ] : # keep revising if revise flg is False tmp = MV . reduce_basis_loop ( blst_expand [ i ] ) if isinstance ( tmp , bool ) : blst_flg [ i ] = tmp # revision of blst_expand[i] complete elif len ( tmp ) == 3 : # blst_expand[i] contracted blst_coef [ i ] = tmp [ 0 ] * blst_coef [ i ] blst_expand [ i ] = tmp [ 1 ] blst_flg [ i ] = tmp [ 2 ] else : # blst_expand[i] revised blst_coef [ i ] = - blst_coef [ i ] # if revision force one more pass in case revision # causes repeated index previous to revised pair of # indexes blst_flg [ i ] = False blst_expand [ i ] = tmp [ 3 ] blst_coef . append ( - blst_coef [ i ] * tmp [ 0 ] ) blst_expand . append ( tmp [ 1 ] ) blst_flg . append ( tmp [ 2 ] ) new_blst_coef = [ ] new_blst_expand = [ ] for ( coef , expand ) in zip ( blst_coef , blst_expand ) : if expand in new_blst_expand : i = new_blst_expand . index ( expand ) new_blst_coef [ i ] += coef else : new_blst_expand . append ( expand ) new_blst_coef . append ( coef ) return new_blst_coef , new_blst_expand