<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def RenameInstance(r, instance, new_name, ip_check, name_check=None):
 """ Changes the name of an instance. @type instance: string @param instance: Instance name @type new_name: string @param new_name: New instance name @type ip_check: bool @param ip_check: Whether to ensure instance's IP address is inactive @type name_check: bool @param name_check: Whether to ensure instance's name is resolvable """


    body = {
        "ip_check": ip_check,
        "new_name": new_name,
    }

    if name_check is not None:
        body["name_check"] = name_check

    return r.request("put", "/2/instances/%s/rename" % instance, content=body)