prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Registers cannot be index with negative integers or slices
  <!-- ⚠️ If you do not respect this template, your issue will be closed -->
  <!-- ⚠️ Make sure to browse the opened and closed issues to confirm this idea does not exist. -->
  
  ### What is the expected enhancement?
  
  It would be nice if the behavior mimicked python lists more. e.g.
  
  ```python
  q = QuantumRegister(5)
  q[-1]
  q[-3:-1]
  etc.
  ```
  
  </issue>
  <code>
  [start of qiskit/circuit/register.py]
  1 # -*- coding: utf-8 -*-
  2 
  3 # Copyright 2017, IBM.
  4 #
  5 # This source code is licensed under the Apache License, Version 2.0 found in
  6 # the LICENSE.txt file in the root directory of this source tree.
  7 
  8 """
  9 Base register reference object.
  10 """
  11 import re
  12 import logging
  13 import itertools
  14 
  15 from qiskit.exceptions import QiskitError, QiskitIndexError
  16 
  17 logger = logging.getLogger(__name__)
  18 
  19 
  20 class Register:
  21     """Implement a generic register."""
  22 
  23     # Counter for the number of instances in this class.
  24     instances_counter = itertools.count()
  25     # Prefix to use for auto naming.
  26     prefix = 'reg'
  27 
  28     def __init__(self, size, name=None):
  29         """Create a new generic register.
  30         """
  31 
  32         if name is None:
  33             name = '%s%i' % (self.prefix, next(self.instances_counter))
  34 
  35         if not isinstance(name, str):
  36             raise QiskitError("The circuit name should be a string "
  37                               "(or None for autogenerate a name).")
  38 
  39         test = re.compile('[a-z][a-zA-Z0-9_]*')
  40         if test.match(name) is None:
  41             raise QiskitError("%s is an invalid OPENQASM register name." % name)
  42 
  43         self.name = name
  44         self.size = size
  45         if size <= 0:
  46             raise QiskitError("register size must be positive")
  47 
  48     def __repr__(self):
  49         """Return the official string representing the register."""
  50         return "%s(%d, '%s')" % (self.__class__.__qualname__,
  51                                  self.size, self.name)
  52 
  53     def __len__(self):
  54         """Return register size"""
  55         return self.size
  56 
  57     def check_range(self, j):
  58         """Check that j is a valid index into self."""
  59         if isinstance(j, int):
  60             if j < 0 or j >= self.size:
  61                 raise QiskitIndexError("register index out of range")
  62             elif isinstance(j, slice):
  63                 if j.start < 0 or j.stop >= self.size or (j.step is not None and
  64                                                           j.step <= 0):
  65                     raise QiskitIndexError("register index slice out of range")
  66 
  67     def __getitem__(self, key):
  68         """
  69         Arg:
  70             key (int|slice|list): index of the bit/qubit to be retrieved.
  71 
  72         Returns:
  73             tuple[Register, int]: a tuple in the form `(self, key)` if key is int.
  74                 If key is a slice, return a `list((self,key))`.
  75 
  76         Raises:
  77             QiskitError: if the `key` is not an integer.
  78             QiskitIndexError: if the `key` is not in the range
  79                 `(0, self.size)`.
  80         """
  81         if not isinstance(key, (int, slice, list)):
  82             raise QiskitError("expected integer or slice index into register")
  83         self.check_range(key)
  84         if isinstance(key, slice):
  85             return [(self, ind) for ind in range(*key.indices(len(self)))]
  86         elif isinstance(key, list):  # list of qubit indices
  87             if max(key) < len(self):
  88                 return [(self, ind) for ind in key]
  89             else:
  90                 raise QiskitError('register index out of range')
  91         else:
  92             return self, key
  93 
  94     def __iter__(self):
  95         """
  96         Returns:
  97             iterator: an iterator over the bits/qubits of the register, in the
  98                 form `tuple (Register, int)`.
  99         """
  100         return zip([self]*self.size, range(self.size))
  101 
  102     def __eq__(self, other):
  103         """Two Registers are the same if they are of the same type
  104         (i.e. quantum/classical), and have the same name and size.
  105 
  106         Args:
  107             other (Register): other Register
  108 
  109         Returns:
  110             bool: are self and other equal.
  111         """
  112         res = False
  113         if type(self) is type(other) and \
  114                 self.name == other.name and \
  115                 self.size == other.size:
  116             res = True
  117         return res
  118 
  119     def __hash__(self):
  120         """Make object hashable, based on the name and size to hash."""
  121         return hash((type(self), self.name, self.size))
  122
  [end of qiskit/circuit/register.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/qiskit/circuit/register.py b/qiskit/circuit/register.py
  --- a/qiskit/circuit/register.py
  +++ b/qiskit/circuit/register.py
  @@ -80,6 +80,8 @@
           """
           if not isinstance(key, (int, slice, list)):
               raise QiskitError("expected integer or slice index into register")
  +        if isinstance(key, int) and key < 0:
  +            key = self.size + key
           self.check_range(key)
           if isinstance(key, slice):
               return [(self, ind) for ind in range(*key.indices(len(self)))]
  
verification_info: {"golden_diff": "diff --git a/qiskit/circuit/register.py b/qiskit/circuit/register.py\n--- a/qiskit/circuit/register.py\n+++ b/qiskit/circuit/register.py\n@@ -80,6 +80,8 @@\n         \"\"\"\n         if not isinstance(key, (int, slice, list)):\n             raise QiskitError(\"expected integer or slice index into register\")\n+        if isinstance(key, int) and key < 0:\n+            key = self.size + key\n         self.check_range(key)\n         if isinstance(key, slice):\n             return [(self, ind) for ind in range(*key.indices(len(self)))]\n", "issue": "Registers cannot be index with negative integers or slices\n<!-- \u26a0\ufe0f If you do not respect this template, your issue will be closed -->\r\n<!-- \u26a0\ufe0f Make sure to browse the opened and closed issues to confirm this idea does not exist. -->\r\n\r\n### What is the expected enhancement?\r\n\r\nIt would be nice if the behavior mimicked python lists more. e.g.\r\n\r\n```python\r\nq = QuantumRegister(5)\r\nq[-1]\r\nq[-3:-1]\r\netc.\r\n```\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\n# Copyright 2017, IBM.\n#\n# This source code is licensed under the Apache License, Version 2.0 found in\n# the LICENSE.txt file in the root directory of this source tree.\n\n\"\"\"\nBase register reference object.\n\"\"\"\nimport re\nimport logging\nimport itertools\n\nfrom qiskit.exceptions import QiskitError, QiskitIndexError\n\nlogger = logging.getLogger(__name__)\n\n\nclass Register:\n    \"\"\"Implement a generic register.\"\"\"\n\n    # Counter for the number of instances in this class.\n    instances_counter = itertools.count()\n    # Prefix to use for auto naming.\n    prefix = 'reg'\n\n    def __init__(self, size, name=None):\n        \"\"\"Create a new generic register.\n        \"\"\"\n\n        if name is None:\n            name = '%s%i' % (self.prefix, next(self.instances_counter))\n\n        if not isinstance(name, str):\n            raise QiskitError(\"The circuit name should be a string \"\n                              \"(or None for autogenerate a name).\")\n\n        test = re.compile('[a-z][a-zA-Z0-9_]*')\n        if test.match(name) is None:\n            raise QiskitError(\"%s is an invalid OPENQASM register name.\" % name)\n\n        self.name = name\n        self.size = size\n        if size <= 0:\n            raise QiskitError(\"register size must be positive\")\n\n    def __repr__(self):\n        \"\"\"Return the official string representing the register.\"\"\"\n        return \"%s(%d, '%s')\" % (self.__class__.__qualname__,\n                                 self.size, self.name)\n\n    def __len__(self):\n        \"\"\"Return register size\"\"\"\n        return self.size\n\n    def check_range(self, j):\n        \"\"\"Check that j is a valid index into self.\"\"\"\n        if isinstance(j, int):\n            if j < 0 or j >= self.size:\n                raise QiskitIndexError(\"register index out of range\")\n            elif isinstance(j, slice):\n                if j.start < 0 or j.stop >= self.size or (j.step is not None and\n                                                          j.step <= 0):\n                    raise QiskitIndexError(\"register index slice out of range\")\n\n    def __getitem__(self, key):\n        \"\"\"\n        Arg:\n            key (int|slice|list): index of the bit/qubit to be retrieved.\n\n        Returns:\n            tuple[Register, int]: a tuple in the form `(self, key)` if key is int.\n                If key is a slice, return a `list((self,key))`.\n\n        Raises:\n            QiskitError: if the `key` is not an integer.\n            QiskitIndexError: if the `key` is not in the range\n                `(0, self.size)`.\n        \"\"\"\n        if not isinstance(key, (int, slice, list)):\n            raise QiskitError(\"expected integer or slice index into register\")\n        self.check_range(key)\n        if isinstance(key, slice):\n            return [(self, ind) for ind in range(*key.indices(len(self)))]\n        elif isinstance(key, list):  # list of qubit indices\n            if max(key) < len(self):\n                return [(self, ind) for ind in key]\n            else:\n                raise QiskitError('register index out of range')\n        else:\n            return self, key\n\n    def __iter__(self):\n        \"\"\"\n        Returns:\n            iterator: an iterator over the bits/qubits of the register, in the\n                form `tuple (Register, int)`.\n        \"\"\"\n        return zip([self]*self.size, range(self.size))\n\n    def __eq__(self, other):\n        \"\"\"Two Registers are the same if they are of the same type\n        (i.e. quantum/classical), and have the same name and size.\n\n        Args:\n            other (Register): other Register\n\n        Returns:\n            bool: are self and other equal.\n        \"\"\"\n        res = False\n        if type(self) is type(other) and \\\n                self.name == other.name and \\\n                self.size == other.size:\n            res = True\n        return res\n\n    def __hash__(self):\n        \"\"\"Make object hashable, based on the name and size to hash.\"\"\"\n        return hash((type(self), self.name, self.size))\n", "path": "qiskit/circuit/register.py"}]}