import sympy


def check_unit(formula_unit_dimension,answer_unit):
    """Check if input unit corresponds to formula unit."""
    #unit_correct = answer_unit == formula_unit_dimension
    try:
        # clean
        #answer_unit = clean_unit_answer(answer_unit)
        # sets (for unit sequence invariance)
        answer_units = set(answer_unit.split())
        correct_units = set(formula_unit_dimension.split())
        # check
        unit_correct = answer_units == correct_units

    except:
        unit_correct = False

    if not unit_correct:
        try:
            # check sympy unit rearrangements
            unit_correct =\
                sympy.sympify(answer_unit.replace(' ','*'))\
                           == sympy.sympify(formula_unit_dimension.replace(' ','*'))
        except:
            pass

    return unit_correct