def contains_rewrite(node, name, expr, assumed_result):
    """
    Takes an AST tree (node), and an expression with its
    name. Returns a new AST tree with the expr taking the
    assumed_result value, with potential optimizations.
    """
    # Get the set from the rewrite expression
    expr_set = expr.left.value

    # Replace function to handle AST re-writes
    def replace_func(pattern, node):
        # Determine the subset based on the assumed result
        if assumed_result is True:
            set_prime = node.left.value & expr_set

            # If this set is a super-set of the expression,
            # then we can re-write to true
            if set_prime == expr_set:
                return ast.Constant(True)

            # If there is no overlap, we are false
            elif len(set_prime) == 0:
                return ast.Constant(False)

            # Check if the set difference is smaller, and use negate
            set_prime_diff = expr_set - node.left.value
            if len(set_prime) < len(set_prime_diff):
                node.left.value = set_prime_diff
                return ast.NegateOperator(node)

        else:
            set_prime = node.left.value - expr_set

            # If we end up with the empty set
            # meaning subset, then its false
            if len(set_prime) == 0:
                return ast.Constant(False)

        # Alter the set we are checking
        node.left.value = set_prime
        return None

    # Tile to replace
    pattern = SimplePattern("types:ContainsOperator",
            "types:LiteralSet", ASTPattern(expr.right))
    return tile(node, [pattern], replace_func)
dataset/ETHPy150Open armon/pypred/pypred/contains.py/contains_rewrite/swapped operands of `<`