import re


def add_white_spaces(expression):
    """ Adds white spaces in between <,>,=,<=, and >= so it can be easily parsed
    Example:
        "0.2>=p*q >=0.1"    --->  "0.2 >= p*q >= 0.1"

    """
    just_equal = r"[^\s<>]=[^<>]|[^<>]=[^\s<>]"
    match = re.findall(just_equal, expression)
    # print(match)
    if match:
        expression.replace("=", " = ")

    with_equal = r"[^\s]>=|[^\s]<=|[^\s]=>|[^\s]=<|>=[^\s]|<=[^\s]|=>[^\s]|=<[^\s]"
    match = re.findall(with_equal, expression)
    # print(match)
    if match:
        greater_eq_check = True
        smaller_eq_check = True
        eq_greater_check = True
        eq_smaller_check = True
        for item in match:
            if ">=" in item and greater_eq_check:
                expression = expression.replace(">=", " >= ")
                greater_eq_check = False
            if "<=" in item and smaller_eq_check:
                expression = expression.replace("<=", " <= ")
                smaller_eq_check = False
            if "=>" in item and eq_greater_check:
                expression = expression.replace("=>", " >= ")
                greater_eq_check = False
            if "=<" in item and eq_smaller_check:
                expression = expression.replace("=<", " <= ")
                smaller_eq_check = False

    without_equal = r"<[^\s=]|>[^\s=]|[^\s=]<|[^\s=]>"
    match = re.findall(without_equal, expression)
    # print(match)
    if match:
        greater_check = True
        smaller_check = True
        for item in match:
            if ">" in item and greater_check:
                expression = expression.replace(">", " > ")
                greater_check = False
            if "<" in item and smaller_check:
                expression = expression.replace("<", " < ")
                smaller_check = False

    expression = re.sub(r' +', ' ', expression).strip()
    return expression