def make_qs ( n , m = None ) : try : import sympy except ImportError : raise ImportError ( "This function requires sympy. Please install it." ) if m is None : syms = sympy . symbols ( " " . join ( f"q{i}" for i in range ( n ) ) ) if isinstance ( syms , tuple ) : return syms else : return ( syms , ) syms = sympy . symbols ( " " . join ( f"q{i}" for i in range ( n , m ) ) ) if isinstance ( syms , tuple ) : return syms else : return ( syms , )
setting up sympy in python
Make sympy symbols q0 q1 ... Args : n ( int ) m ( int optional ) : If specified both n and m returns [ qn q ( n + 1 ) ... qm ] Only n is specified returns [ q0 q1 ... qn ] .
def make_qs(n, m=None):
    """Make sympy symbols q0, q1, ...
    
    Args:
        n(int), m(int, optional):
            If specified both n and m, returns [qn, q(n+1), ..., qm],
            Only n is specified, returns[q0, q1, ..., qn].

    Return:
        tuple(Symbol): Tuple of sympy symbols.
    """
    try:
        import sympy
    except ImportError:
        raise ImportError("This function requires sympy. Please install it.")
    if m is None:
        syms = sympy.symbols(" ".join(f"q{i}" for i in range(n)))
        if isinstance(syms, tuple):
            return syms
        else:
            return (syms,)
    syms = sympy.symbols(" ".join(f"q{i}" for i in range(n, m)))
    if isinstance(syms, tuple):
        return syms
    else:
        return (syms,)