This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
from timeit import * | |
def collect_results(): | |
results = [] | |
for i in range(1000, 2000001, 100000): | |
f = "fast_doubling_fibonacci_recursive" | |
t1 = Timer(f"{f}({i})", | |
f"from __main__ import {f}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def collect_results(): | |
results = [] | |
for i in range(1000, 2000001, 100000): | |
f = "fast_doubling_fibonacci_recursive" | |
t1 = Timer(f"{f}({i})", | |
f"from __main__ import {f}") | |
st1 = t1.timeit(number=10) | |
f = "matrix_fibonacci" | |
t2 = Timer(f"{f}({i})", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from timeit import * | |
def collect_results(): | |
results = [] | |
for i in range(1000, 2000001, 100000): | |
f = "fast_doubling_fibonacci_recursive" | |
t1 = Timer(f"{f}({i})", | |
f"from __main__ import {f}") | |
st1 = t1.timeit(number=10) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fast_doubling_fibonacci_iterative(n): | |
""" | |
Args: | |
n (): | |
Returns: | |
>>> fast_doubling_fibonacci_iterative(80) | |
23416728348467685 | |
>>> fast_doubling_fibonacci_iterative(800) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fast_doubling_fibonacci_iterative(n): | |
""" | |
Args: | |
n (): | |
Returns: | |
>>> fast_doubling_fibonacci_iterative(80) | |
23416728348467685 | |
>>> fast_doubling_fibonacci_iterative(800) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
@functools.lru_cache() | |
def _fd_fib(n: int) -> tuple: | |
"""_fd_fib. | |
Args: | |
n (int): n | |
Returns: | |
tuple: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def karatsuba_fast_multiply(multiplier: int, multiplicand: int) -> int: | |
""" | |
Karatsuba fast multiplication, published in 1962 | |
https://en.wikipedia.org/wiki/Karatsuba_algorithm | |
Args: | |
x (): | |
y (): | |
Returns: int |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def karatsuba_fast_multiply(multiplier: int, multiplicand: int) -> int: | |
""" | |
Karatsuba fast multiplication, published in 1962 | |
https://en.wikipedia.org/wiki/Karatsuba_algorithm | |
Args: | |
x (): | |
y (): | |
Returns: int |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def karatsuba_fast_multiply(multiplier: int, multiplicand: int) -> int: | |
""" | |
Karatsuba fast multiplication, published in 1962 | |
https://en.wikipedia.org/wiki/Karatsuba_algorithm | |
Args: | |
x (): | |
y (): | |
Returns: int |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def lucas_power(n: float): | |
"""lucas_power. | |
Args: | |
n (float): n | |
""" | |
if n == 1: | |
return (1, 1) | |
L, F = lucas_power(n // 2) |