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

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

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: flow-project/flow
Commit Name: 1439884477e114f630a4dec1b043dc87d9254d98
Time: 2017-11-03
Author: kanaadp@gmail.com
File Name: flow/core/generator.py
Class Name: Generator
Method Name: make_routes


Project Name: pfnet-research/chainer-chemistry
Commit Name: f35b10ad6e8bd19dba0cc1eb1d1338f51fefcdcf
Time: 2018-07-14
Author: mottodora@gmail.com
File Name: examples/molnet/train_molnet.py
Class Name:
Method Name: main