(expr, symbolname, startnumber, endnumber)
return expr
r"""
    Renumber arbitrary constants in ``expr`` to have numbers 1 through `N`
    where `N` is ``endnumber - startnumber + 1`` at most.
    In the process, this reorders expression terms in a standard way.

    This is a simple function that goes through and renumbers any
    :py:class:`~sympy.core.symbol.Symbol` with a name in the form ``symbolname
    + num`` where ``num`` is in the range from ``startnumber`` to
    ``endnumber``.

    Symbols are renumbered based on ``.sort_key()``, so they should be
    numbered roughly in the order that they appear in the final, printed
    expression.  Note that this ordering is based in part on hashes, so it can
    produce different results on different machines.

    The structure of this function is very similar to that of
    :py:meth:`~sympy.solvers.ode.constantsimp`.

    Examples
    ========

    >>> from sympy import symbols, Eq, pprint
    >>> from sympy.solvers.ode import constant_renumber
    >>> x, C0, C1, C2, C3, C4 = symbols('x,C:5')

    Only constants in the given range (inclusive) are renumbered;
    the renumbering always starts from 1:

    >>> constant_renumber(C1 + C3 + C4, 'C', 1, 3)
    C1 + C2 + C4
    >>> constant_renumber(C0 + C1 + C3 + C4, 'C', 2, 4)
    C0 + 2*C1 + C2
    >>> constant_renumber(C0 + 2*C1 + C2, 'C', 0, 1)
    C1 + 3*C2
    >>> pprint(C2 + C1*x + C3*x**2)
                    2
    C1*x + C2 + C3*x
    >>> pprint(constant_renumber(C2 + C1*x + C3*x**2, 'C', 1, 3))
                    2
    C1 + C2*x + C3*x
r"""
    Renumber arbitrary constants in ``expr`` to have numbers 1 through `N`
    where `N` is ``endnumber - startnumber + 1`` at most.
    In the process, this reorders expression terms in a standard way.
r Renumber arbitrary constants in expr to have numbers 1 through N where N is endnumber - startnumber + 1 at most . In the process this reorders expression terms in a standard way .
def constant_renumber(expr, symbolname, startnumber, endnumber):
    r"""
    Renumber arbitrary constants in ``expr`` to have numbers 1 through `N`
    where `N` is ``endnumber - startnumber + 1`` at most.
    In the process, this reorders expression terms in a standard way.

    This is a simple function that goes through and renumbers any
    :py:class:`~sympy.core.symbol.Symbol` with a name in the form ``symbolname
    + num`` where ``num`` is in the range from ``startnumber`` to
    ``endnumber``.

    Symbols are renumbered based on ``.sort_key()``, so they should be
    numbered roughly in the order that they appear in the final, printed
    expression.  Note that this ordering is based in part on hashes, so it can
    produce different results on different machines.

    The structure of this function is very similar to that of
    :py:meth:`~sympy.solvers.ode.constantsimp`.

    Examples
    ========

    >>> from sympy import symbols, Eq, pprint
    >>> from sympy.solvers.ode import constant_renumber
    >>> x, C0, C1, C2, C3, C4 = symbols('x,C:5')

    Only constants in the given range (inclusive) are renumbered;
    the renumbering always starts from 1:

    >>> constant_renumber(C1 + C3 + C4, 'C', 1, 3)
    C1 + C2 + C4
    >>> constant_renumber(C0 + C1 + C3 + C4, 'C', 2, 4)
    C0 + 2*C1 + C2
    >>> constant_renumber(C0 + 2*C1 + C2, 'C', 0, 1)
    C1 + 3*C2
    >>> pprint(C2 + C1*x + C3*x**2)
                    2
    C1*x + C2 + C3*x
    >>> pprint(constant_renumber(C2 + C1*x + C3*x**2, 'C', 1, 3))
                    2
    C1 + C2*x + C3*x

    """
    if type(expr) in (set, list, tuple):
        return type(expr)(
            [constant_renumber(i, symbolname=symbolname, startnumber=startnumber, endnumber=endnumber)
                for i in expr]
        )
    global newstartnumber
    newstartnumber = 1
    constants_found = [None]*(endnumber + 2)
    constantsymbols = [Symbol(
        symbolname + "%d" % t) for t in range(startnumber,
        endnumber + 1)]

    # make a mapping to send all constantsymbols to S.One and use
    # that to make sure that term ordering is not dependent on
    # the indexed value of C
    C_1 = [(ci, S.One) for ci in constantsymbols]
    sort_key=lambda arg: default_sort_key(arg.subs(C_1))

    def _constant_renumber(expr):
        r"""
        We need to have an internal recursive function so that
        newstartnumber maintains its values throughout recursive calls.

        """
        global newstartnumber

        if isinstance(expr, Equality):
            return Eq(
                _constant_renumber(expr.lhs),
                _constant_renumber(expr.rhs))

        if type(expr) not in (Mul, Add, Pow) and not expr.is_Function and \
                not expr.has(*constantsymbols):
            # Base case, as above.  Hope there aren't constants inside
            # of some other class, because they won't be renumbered.
            return expr
        elif expr.is_Piecewise:
            return expr
        elif expr in constantsymbols:
            if expr not in constants_found:
                constants_found[newstartnumber] = expr
                newstartnumber += 1
            return expr
        elif expr.is_Function or expr.is_Pow or isinstance(expr, C.Tuple):
            return expr.func(
                *[_constant_renumber(x) for x in expr.args])
        else:
            sortedargs = list(expr.args)
            sortedargs.sort(key=sort_key)
            return expr.func(*[_constant_renumber(x) for x in sortedargs])
    expr = _constant_renumber(expr)
    # Renumbering happens here
    newconsts = symbols('C1:%d' % newstartnumber)
    expr = expr.subs(zip(constants_found[1:], newconsts), simultaneous=True)
    return expr
def constant_renumber ( expr , symbolname , startnumber , endnumber ) : if type ( expr ) in ( set , list , tuple ) : return type ( expr ) ( [ constant_renumber ( i , symbolname = symbolname , startnumber = startnumber , endnumber = endnumber ) for i in expr ] ) global newstartnumber newstartnumber = 1 constants_found = [ None ] * ( endnumber + 2 ) constantsymbols = [ Symbol ( symbolname + "%d" % t ) for t in range ( startnumber , endnumber + 1 ) ] # make a mapping to send all constantsymbols to S.One and use # that to make sure that term ordering is not dependent on # the indexed value of C C_1 = [ ( ci , S . One ) for ci in constantsymbols ] sort_key = lambda arg : default_sort_key ( arg . subs ( C_1 ) ) def _constant_renumber ( expr ) : r"""
        We need to have an internal recursive function so that
        newstartnumber maintains its values throughout recursive calls.

        """ global newstartnumber if isinstance ( expr , Equality ) : return Eq ( _constant_renumber ( expr . lhs ) , _constant_renumber ( expr . rhs ) ) if type ( expr ) not in ( Mul , Add , Pow ) and not expr . is_Function and not expr . has ( * constantsymbols ) : # Base case, as above.  Hope there aren't constants inside # of some other class, because they won't be renumbered. return expr elif expr . is_Piecewise : return expr elif expr in constantsymbols : if expr not in constants_found : constants_found [ newstartnumber ] = expr newstartnumber += 1 return expr elif expr . is_Function or expr . is_Pow or isinstance ( expr , C . Tuple ) : return expr . func ( * [ _constant_renumber ( x ) for x in expr . args ] ) else : sortedargs = list ( expr . args ) sortedargs . sort ( key = sort_key ) return expr . func ( * [ _constant_renumber ( x ) for x in sortedargs ] ) expr = _constant_renumber ( expr ) # Renumbering happens here newconsts = symbols ( 'C1:%d' % newstartnumber ) expr = expr . subs ( zip ( constants_found [ 1 : ] , newconsts ) , simultaneous = True ) return expr