(tokens, local_dict, global_dict)
return result
Allows functions to be exponentiated, e.g. ``cos**2(x)``.

    Example:

    >>> from sympy.parsing.sympy_parser import (parse_expr,
    ... standard_transformations, function_exponentiation)
    >>> transformations = standard_transformations + (function_exponentiation,)
    >>> parse_expr('sin**4(x)', transformations=transformations)
    sin(x)**4
Allows functions to be exponentiated, e.g. ``cos**2(x)``.
Allows functions to be exponentiated e . g . cos ** 2 ( x ) .
def function_exponentiation(tokens, local_dict, global_dict):
    """Allows functions to be exponentiated, e.g. ``cos**2(x)``.

    Example:

    >>> from sympy.parsing.sympy_parser import (parse_expr,
    ... standard_transformations, function_exponentiation)
    >>> transformations = standard_transformations + (function_exponentiation,)
    >>> parse_expr('sin**4(x)', transformations=transformations)
    sin(x)**4
    """
    result = []
    exponent = []
    consuming_exponent = False
    level = 0
    for tok, nextTok in zip(tokens, tokens[1:]):
        if tok[0] == NAME and nextTok[0] == OP and nextTok[1] == '**':
            if _token_callable(tok, local_dict, global_dict):
                consuming_exponent = True
        elif consuming_exponent:
            exponent.append(tok)

            # only want to stop after hitting )
            if tok[0] == nextTok[0] == OP and tok[1] == ')' and nextTok[1] == '(':
                consuming_exponent = False
            # if implicit multiplication was used, we may have )*( instead
            if tok[0] == nextTok[0] == OP and tok[1] == '*' and nextTok[1] == '(':
                consuming_exponent = False
                del exponent[-1]
            continue
        elif exponent and not consuming_exponent:
            if tok[0] == OP:
                if tok[1] == '(':
                    level += 1
                elif tok[1] == ')':
                    level -= 1
            if level == 0:
                result.append(tok)
                result.extend(exponent)
                exponent = []
                continue
        result.append(tok)
    if tokens:
        result.append(tokens[-1])
    if exponent:
        result.extend(exponent)
    return result
def function_exponentiation ( tokens , local_dict , global_dict ) : result = [ ] exponent = [ ] consuming_exponent = False level = 0 for tok , nextTok in zip ( tokens , tokens [ 1 : ] ) : if tok [ 0 ] == NAME and nextTok [ 0 ] == OP and nextTok [ 1 ] == '**' : if _token_callable ( tok , local_dict , global_dict ) : consuming_exponent = True elif consuming_exponent : exponent . append ( tok ) # only want to stop after hitting ) if tok [ 0 ] == nextTok [ 0 ] == OP and tok [ 1 ] == ')' and nextTok [ 1 ] == '(' : consuming_exponent = False # if implicit multiplication was used, we may have )*( instead if tok [ 0 ] == nextTok [ 0 ] == OP and tok [ 1 ] == '*' and nextTok [ 1 ] == '(' : consuming_exponent = False del exponent [ - 1 ] continue elif exponent and not consuming_exponent : if tok [ 0 ] == OP : if tok [ 1 ] == '(' : level += 1 elif tok [ 1 ] == ')' : level -= 1 if level == 0 : result . append ( tok ) result . extend ( exponent ) exponent = [ ] continue result . append ( tok ) if tokens : result . append ( tokens [ - 1 ] ) if exponent : result . extend ( exponent ) return result