import sympy


def _freesyms(expr):
    """ 
    Helper function that either returns free symbols for sympy expressions
    or an empty set if constant.
    """
    if isinstance(expr, sympy.Basic):
        return expr.free_symbols
    return {}