491635f0fc00102c6729b704b30f64d1f271be23,sympy/solvers/ode/ode.py,,constant_renumber,#Any#Any#Any#,2821

Before Change


    E1 + E2*x + E3*x**2

    
    if type(expr) in (set, list, tuple):
        renumbered = [constant_renumber(e, variables, newconstants) for e in expr]
        return type(expr)(renumbered)

    // Symbols in solution but not ODE are constants
    if variables is not None:
        variables = set(variables)
        constantsymbols = list(expr.free_symbols - variables)
    // Any Cn is a constant...
    else:
        variables = set()
        isconstant = lambda s: s.startswith("C") and s[1:].isdigit()
        constantsymbols = [sym for sym in expr.free_symbols if isconstant(sym.name)]

    // Find new constants checking that they aren"t already in the ODE
    if newconstants is None:
        iter_constants = numbered_symbols(start=1, prefix="C", exclude=variables)
    else:
        iter_constants = (sym for sym in newconstants if sym not in variables)

    // XXX: This global newstartnumber hack should be removed
    global newstartnumber
    newstartnumber = 1
    endnumber = len(constantsymbols)
    constants_found = [None]*(endnumber + 2)

    // 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

After Change


    else:
        iter_constants = (sym for sym in newconstants if sym not in variables)

    constants_found = []

    // 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
        

        // For system of expressions
        if isinstance(expr, Tuple):
            renumbered = [_constant_renumber(e) for e in expr]
            return Tuple(*renumbered)

        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.append(expr)
            return expr
        elif expr.is_Function or expr.is_Pow:
            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)

    // Don"t renumber symbols present in the ODE.
    constants_found = [c for c in constants_found if c not in variables]

    // Renumbering happens here
    subs_dict = {var: cons for var, cons in zip(constants_found, iter_constants)}
    expr = expr.subs(subs_dict, simultaneous=True)

    return expr
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 8

Instances


Project Name: sympy/sympy
Commit Name: 491635f0fc00102c6729b704b30f64d1f271be23
Time: 2020-07-13
Author: milan.cs16@iitp.ac.in
File Name: sympy/solvers/ode/ode.py
Class Name:
Method Name: constant_renumber


Project Name: PetrochukM/PyTorch-NLP
Commit Name: bb9335bbc981c0541e37a875d79d0ef419008574
Time: 2018-03-25
Author: petrochukm@gmail.com
File Name: torchnlp/text_encoders/subword_encoder.py
Class Name: SubwordEncoder
Method Name: __init__


Project Name: pantsbuild/pants
Commit Name: 0c099396ea3f96919b3e613b16b399516e446c16
Time: 2015-10-05
Author: tansy.arron@gmail.com
File Name: src/python/pants/cache/cache_setup.py
Class Name: CacheFactory
Method Name: select_best_url