import random
import re


def sometimes_replace_1x_with_x(expr, var_name):
    """
    Half of the time converts "1x" to "x".
    "31x", "461x", "4.1x", etc will always remain the same.
    """
    if random.choice([0, 1]):
        expr = re.sub(r'(?<![0-9.])1{}'.format(var_name), r'{}'.format(var_name), expr)
    return expr