prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Rewrite *other* fibonacci.py
  I opened issue #5665 to have `fibonacci.py` rewritten, but apparently there are multiple files with that name. The PR that @citharus made (#5677) revamps the file `dynamic_programming/fibonacci.py` (thanks for your contributions btw!) whereas this issue seeks to revamp the file `maths/fibonacci.py`.
  
  I'm opening this as a new issue since it's technically a different algorithm file and the two `fibonacci.py` files each use different algorithms to calculate the Fibonacci sequence.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `maths/fibonacci.py`
  Content:
  ```
  1 # fibonacci.py
  2 """
  3 Calculates the Fibonacci sequence using iteration, recursion, and a simplified
  4 form of Binet's formula
  5 
  6 NOTE 1: the iterative and recursive functions are more accurate than the Binet's
  7 formula function because the iterative function doesn't use floats
  8 
  9 NOTE 2: the Binet's formula function is much more limited in the size of inputs
  10 that it can handle due to the size limitations of Python floats
  11 """
  12 
  13 from math import sqrt
  14 from time import time
  15 
  16 
  17 def time_func(func, *args, **kwargs):
  18     """
  19     Times the execution of a function with parameters
  20     """
  21     start = time()
  22     output = func(*args, **kwargs)
  23     end = time()
  24     if int(end - start) > 0:
  25         print(f"{func.__name__} runtime: {(end - start):0.4f} s")
  26     else:
  27         print(f"{func.__name__} runtime: {(end - start) * 1000:0.4f} ms")
  28     return output
  29 
  30 
  31 def fib_iterative(n: int) -> list[int]:
  32     """
  33     Calculates the first n (0-indexed) Fibonacci numbers using iteration
  34     >>> fib_iterative(0)
  35     [0]
  36     >>> fib_iterative(1)
  37     [0, 1]
  38     >>> fib_iterative(5)
  39     [0, 1, 1, 2, 3, 5]
  40     >>> fib_iterative(10)
  41     [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
  42     >>> fib_iterative(-1)
  43     Traceback (most recent call last):
  44     ...
  45     Exception: n is negative
  46     """
  47     if n < 0:
  48         raise Exception("n is negative")
  49     if n == 0:
  50         return [0]
  51     fib = [0, 1]
  52     for _ in range(n - 1):
  53         fib.append(fib[-1] + fib[-2])
  54     return fib
  55 
  56 
  57 def fib_recursive(n: int) -> list[int]:
  58     """
  59     Calculates the first n (0-indexed) Fibonacci numbers using recursion
  60     >>> fib_iterative(0)
  61     [0]
  62     >>> fib_iterative(1)
  63     [0, 1]
  64     >>> fib_iterative(5)
  65     [0, 1, 1, 2, 3, 5]
  66     >>> fib_iterative(10)
  67     [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
  68     >>> fib_iterative(-1)
  69     Traceback (most recent call last):
  70     ...
  71     Exception: n is negative
  72     """
  73 
  74     def fib_recursive_term(i: int) -> int:
  75         """
  76         Calculates the i-th (0-indexed) Fibonacci number using recursion
  77         """
  78         if i < 0:
  79             raise Exception("n is negative")
  80         if i < 2:
  81             return i
  82         return fib_recursive_term(i - 1) + fib_recursive_term(i - 2)
  83 
  84     if n < 0:
  85         raise Exception("n is negative")
  86     return [fib_recursive_term(i) for i in range(n + 1)]
  87 
  88 
  89 def fib_binet(n: int) -> list[int]:
  90     """
  91     Calculates the first n (0-indexed) Fibonacci numbers using a simplified form
  92     of Binet's formula:
  93     https://en.m.wikipedia.org/wiki/Fibonacci_number#Computation_by_rounding
  94 
  95     NOTE 1: this function diverges from fib_iterative at around n = 71, likely
  96     due to compounding floating-point arithmetic errors
  97 
  98     NOTE 2: this function overflows on n >= 1475 because of the size limitations
  99     of Python floats
  100     >>> fib_binet(0)
  101     [0]
  102     >>> fib_binet(1)
  103     [0, 1]
  104     >>> fib_binet(5)
  105     [0, 1, 1, 2, 3, 5]
  106     >>> fib_binet(10)
  107     [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
  108     >>> fib_binet(-1)
  109     Traceback (most recent call last):
  110     ...
  111     Exception: n is negative
  112     >>> fib_binet(1475)
  113     Traceback (most recent call last):
  114     ...
  115     Exception: n is too large
  116     """
  117     if n < 0:
  118         raise Exception("n is negative")
  119     if n >= 1475:
  120         raise Exception("n is too large")
  121     sqrt_5 = sqrt(5)
  122     phi = (1 + sqrt_5) / 2
  123     return [round(phi ** i / sqrt_5) for i in range(n + 1)]
  124 
  125 
  126 if __name__ == "__main__":
  127     num = 20
  128     time_func(fib_iterative, num)
  129     time_func(fib_recursive, num)
  130     time_func(fib_binet, num)
  131
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/maths/fibonacci.py b/maths/fibonacci.py
  --- a/maths/fibonacci.py
  +++ b/maths/fibonacci.py
  @@ -95,8 +95,8 @@
       NOTE 1: this function diverges from fib_iterative at around n = 71, likely
       due to compounding floating-point arithmetic errors
   
  -    NOTE 2: this function overflows on n >= 1475 because of the size limitations
  -    of Python floats
  +    NOTE 2: this function doesn't accept n >= 1475 because it overflows
  +    thereafter due to the size limitations of Python floats
       >>> fib_binet(0)
       [0]
       >>> fib_binet(1)
  
verification_info: {"golden_diff": "diff --git a/maths/fibonacci.py b/maths/fibonacci.py\n--- a/maths/fibonacci.py\n+++ b/maths/fibonacci.py\n@@ -95,8 +95,8 @@\n     NOTE 1: this function diverges from fib_iterative at around n = 71, likely\n     due to compounding floating-point arithmetic errors\n \n-    NOTE 2: this function overflows on n >= 1475 because of the size limitations\n-    of Python floats\n+    NOTE 2: this function doesn't accept n >= 1475 because it overflows\n+    thereafter due to the size limitations of Python floats\n     >>> fib_binet(0)\n     [0]\n     >>> fib_binet(1)\n", "issue": "Rewrite *other* fibonacci.py\nI opened issue #5665 to have `fibonacci.py` rewritten, but apparently there are multiple files with that name. The PR that @citharus made (#5677) revamps the file `dynamic_programming/fibonacci.py` (thanks for your contributions btw!) whereas this issue seeks to revamp the file `maths/fibonacci.py`.\r\n\r\nI'm opening this as a new issue since it's technically a different algorithm file and the two `fibonacci.py` files each use different algorithms to calculate the Fibonacci sequence.\n", "before_files": [{"content": "# fibonacci.py\n\"\"\"\nCalculates the Fibonacci sequence using iteration, recursion, and a simplified\nform of Binet's formula\n\nNOTE 1: the iterative and recursive functions are more accurate than the Binet's\nformula function because the iterative function doesn't use floats\n\nNOTE 2: the Binet's formula function is much more limited in the size of inputs\nthat it can handle due to the size limitations of Python floats\n\"\"\"\n\nfrom math import sqrt\nfrom time import time\n\n\ndef time_func(func, *args, **kwargs):\n    \"\"\"\n    Times the execution of a function with parameters\n    \"\"\"\n    start = time()\n    output = func(*args, **kwargs)\n    end = time()\n    if int(end - start) > 0:\n        print(f\"{func.__name__} runtime: {(end - start):0.4f} s\")\n    else:\n        print(f\"{func.__name__} runtime: {(end - start) * 1000:0.4f} ms\")\n    return output\n\n\ndef fib_iterative(n: int) -> list[int]:\n    \"\"\"\n    Calculates the first n (0-indexed) Fibonacci numbers using iteration\n    >>> fib_iterative(0)\n    [0]\n    >>> fib_iterative(1)\n    [0, 1]\n    >>> fib_iterative(5)\n    [0, 1, 1, 2, 3, 5]\n    >>> fib_iterative(10)\n    [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]\n    >>> fib_iterative(-1)\n    Traceback (most recent call last):\n    ...\n    Exception: n is negative\n    \"\"\"\n    if n < 0:\n        raise Exception(\"n is negative\")\n    if n == 0:\n        return [0]\n    fib = [0, 1]\n    for _ in range(n - 1):\n        fib.append(fib[-1] + fib[-2])\n    return fib\n\n\ndef fib_recursive(n: int) -> list[int]:\n    \"\"\"\n    Calculates the first n (0-indexed) Fibonacci numbers using recursion\n    >>> fib_iterative(0)\n    [0]\n    >>> fib_iterative(1)\n    [0, 1]\n    >>> fib_iterative(5)\n    [0, 1, 1, 2, 3, 5]\n    >>> fib_iterative(10)\n    [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]\n    >>> fib_iterative(-1)\n    Traceback (most recent call last):\n    ...\n    Exception: n is negative\n    \"\"\"\n\n    def fib_recursive_term(i: int) -> int:\n        \"\"\"\n        Calculates the i-th (0-indexed) Fibonacci number using recursion\n        \"\"\"\n        if i < 0:\n            raise Exception(\"n is negative\")\n        if i < 2:\n            return i\n        return fib_recursive_term(i - 1) + fib_recursive_term(i - 2)\n\n    if n < 0:\n        raise Exception(\"n is negative\")\n    return [fib_recursive_term(i) for i in range(n + 1)]\n\n\ndef fib_binet(n: int) -> list[int]:\n    \"\"\"\n    Calculates the first n (0-indexed) Fibonacci numbers using a simplified form\n    of Binet's formula:\n    https://en.m.wikipedia.org/wiki/Fibonacci_number#Computation_by_rounding\n\n    NOTE 1: this function diverges from fib_iterative at around n = 71, likely\n    due to compounding floating-point arithmetic errors\n\n    NOTE 2: this function overflows on n >= 1475 because of the size limitations\n    of Python floats\n    >>> fib_binet(0)\n    [0]\n    >>> fib_binet(1)\n    [0, 1]\n    >>> fib_binet(5)\n    [0, 1, 1, 2, 3, 5]\n    >>> fib_binet(10)\n    [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]\n    >>> fib_binet(-1)\n    Traceback (most recent call last):\n    ...\n    Exception: n is negative\n    >>> fib_binet(1475)\n    Traceback (most recent call last):\n    ...\n    Exception: n is too large\n    \"\"\"\n    if n < 0:\n        raise Exception(\"n is negative\")\n    if n >= 1475:\n        raise Exception(\"n is too large\")\n    sqrt_5 = sqrt(5)\n    phi = (1 + sqrt_5) / 2\n    return [round(phi ** i / sqrt_5) for i in range(n + 1)]\n\n\nif __name__ == \"__main__\":\n    num = 20\n    time_func(fib_iterative, num)\n    time_func(fib_recursive, num)\n    time_func(fib_binet, num)\n", "path": "maths/fibonacci.py"}], "after_files": [{"content": "# fibonacci.py\n\"\"\"\nCalculates the Fibonacci sequence using iteration, recursion, and a simplified\nform of Binet's formula\n\nNOTE 1: the iterative and recursive functions are more accurate than the Binet's\nformula function because the iterative function doesn't use floats\n\nNOTE 2: the Binet's formula function is much more limited in the size of inputs\nthat it can handle due to the size limitations of Python floats\n\"\"\"\n\nfrom math import sqrt\nfrom time import time\n\n\ndef time_func(func, *args, **kwargs):\n    \"\"\"\n    Times the execution of a function with parameters\n    \"\"\"\n    start = time()\n    output = func(*args, **kwargs)\n    end = time()\n    if int(end - start) > 0:\n        print(f\"{func.__name__} runtime: {(end - start):0.4f} s\")\n    else:\n        print(f\"{func.__name__} runtime: {(end - start) * 1000:0.4f} ms\")\n    return output\n\n\ndef fib_iterative(n: int) -> list[int]:\n    \"\"\"\n    Calculates the first n (0-indexed) Fibonacci numbers using iteration\n    >>> fib_iterative(0)\n    [0]\n    >>> fib_iterative(1)\n    [0, 1]\n    >>> fib_iterative(5)\n    [0, 1, 1, 2, 3, 5]\n    >>> fib_iterative(10)\n    [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]\n    >>> fib_iterative(-1)\n    Traceback (most recent call last):\n    ...\n    Exception: n is negative\n    \"\"\"\n    if n < 0:\n        raise Exception(\"n is negative\")\n    if n == 0:\n        return [0]\n    fib = [0, 1]\n    for _ in range(n - 1):\n        fib.append(fib[-1] + fib[-2])\n    return fib\n\n\ndef fib_recursive(n: int) -> list[int]:\n    \"\"\"\n    Calculates the first n (0-indexed) Fibonacci numbers using recursion\n    >>> fib_iterative(0)\n    [0]\n    >>> fib_iterative(1)\n    [0, 1]\n    >>> fib_iterative(5)\n    [0, 1, 1, 2, 3, 5]\n    >>> fib_iterative(10)\n    [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]\n    >>> fib_iterative(-1)\n    Traceback (most recent call last):\n    ...\n    Exception: n is negative\n    \"\"\"\n\n    def fib_recursive_term(i: int) -> int:\n        \"\"\"\n        Calculates the i-th (0-indexed) Fibonacci number using recursion\n        \"\"\"\n        if i < 0:\n            raise Exception(\"n is negative\")\n        if i < 2:\n            return i\n        return fib_recursive_term(i - 1) + fib_recursive_term(i - 2)\n\n    if n < 0:\n        raise Exception(\"n is negative\")\n    return [fib_recursive_term(i) for i in range(n + 1)]\n\n\ndef fib_binet(n: int) -> list[int]:\n    \"\"\"\n    Calculates the first n (0-indexed) Fibonacci numbers using a simplified form\n    of Binet's formula:\n    https://en.m.wikipedia.org/wiki/Fibonacci_number#Computation_by_rounding\n\n    NOTE 1: this function diverges from fib_iterative at around n = 71, likely\n    due to compounding floating-point arithmetic errors\n\n    NOTE 2: this function doesn't accept n >= 1475 because it overflows\n    thereafter due to the size limitations of Python floats\n    >>> fib_binet(0)\n    [0]\n    >>> fib_binet(1)\n    [0, 1]\n    >>> fib_binet(5)\n    [0, 1, 1, 2, 3, 5]\n    >>> fib_binet(10)\n    [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]\n    >>> fib_binet(-1)\n    Traceback (most recent call last):\n    ...\n    Exception: n is negative\n    >>> fib_binet(1475)\n    Traceback (most recent call last):\n    ...\n    Exception: n is too large\n    \"\"\"\n    if n < 0:\n        raise Exception(\"n is negative\")\n    if n >= 1475:\n        raise Exception(\"n is too large\")\n    sqrt_5 = sqrt(5)\n    phi = (1 + sqrt_5) / 2\n    return [round(phi ** i / sqrt_5) for i in range(n + 1)]\n\n\nif __name__ == \"__main__\":\n    num = 20\n    time_func(fib_iterative, num)\n    time_func(fib_recursive, num)\n    time_func(fib_binet, num)\n", "path": "maths/fibonacci.py"}]}