





import timeit


class 					__magic_name__  :





     """simple docstring"""



     def __init__(							self       :str			,      snake_case       :Tuple  ):





        '''simple docstring'''




        if isinstance(snake_case			,      snake_case  ):  # Initializes a matrix identical to the one provided.
           A_					:				List[Any]          =			arg
           A_					:				Optional[Any]          =			len(snake_case  )
        else:  # Initializes a square matrix of the given size and set values to zero.
           A_					:				str          =			arg
           A_					:				str          =			[[0 for _ in range(self.n  )] for _ in range(self.n  )]





     def __mul__(							self       :Dict			,      snake_case       :List[str]  ):





        '''simple docstring'''




        A_					:				Dict          =			Matrix(self.n  )
        for i in range(self.n  ):
           for j in range(self.n  ):
              for k in range(self.n  ):
                 matrix.t[i][j] += self.t[i][k] * b.t[k][j]
        return matrix




def      __snake_case						(					_lowerCAmelCase : Dict				,				_lowerCAmelCase : Any	):
   A_					:				str          =			Matrix([[1, 0], [0, 1]]	)
   while b > 0:
      if b & 1:
         matrix *= a
      a *= a
      b >>= 1
   return matrix

def      __snake_case						(					_lowerCAmelCase : Any				,				_lowerCAmelCase : List[Any]				,				_lowerCAmelCase : Optional[Any]	):
   # Trivial Cases
   if n == 1:
      return fa
   elif n == 2:
      return fa
   A_					:				Optional[Any]          =			Matrix([[1, 1], [1, 0]]	)
   A_					:				int          =			modular_exponentiation(lowerCAmelCase__				,				n - 2	)
   return fa * matrix.t[0][0] + fa * matrix.t[0][1]

def      __snake_case						(					_lowerCAmelCase : int				,				_lowerCAmelCase : Dict				,				_lowerCAmelCase : Optional[int]	):
   # Trivial Cases
   if n == 1:
      return fa
   elif n == 2:
      return fa

   A_					:				Tuple          =			fa
   A_					:				List[str]          =			fa
   n -= 2

   while n > 0:
      A_					:				Optional[Any]          =			fn_a + fn_a, fn_a
      n -= 1

   return fn_a

def      __snake_case						(					):
   A_					:				str          =			'\nfrom random import randint\nfrom __main__ import fibonacci_with_matrix_exponentiation\n'
   A_					:				Union[str, Any]          =			'fibonacci_with_matrix_exponentiation(randint(1,70000), 1, 1)'
   A_					:				Dict          =			timeit.timeit(setup=lowerCAmelCase__				,				stmt=lowerCAmelCase__				,				number=100	)
   print("With matrix exponentiation the average execution time is "				,				exec_time / 100	)
   return exec_time

def      __snake_case						(					):
   A_					:				Union[str, Any]          =			'\nfrom random import randint\nfrom __main__ import simple_fibonacci\n'
   A_					:				Dict          =			'simple_fibonacci(randint(1,70000), 1, 1)'
   A_					:				Optional[Any]          =			timeit.timeit(setup=lowerCAmelCase__				,				stmt=lowerCAmelCase__				,				number=100	)
   print(
       "Without matrix exponentiation the average execution time is "				,				exec_time / 100	)
   return exec_time

def      __snake_case						(					):
   matrix_exponentiation_time()
   simple_fibonacci_time()


if __name__ == "__main__":
 main()







import warnings
from collections.abc import Callable
from typing import Any

import numpy
from matplotlib import pyplot

_lowerCAmelCase							:      Union[str, Any]						=	0.25 + 0.0j
_lowerCAmelCase							:      str						=	-0.4 + 0.6j
_lowerCAmelCase							:      Optional[int]						=	-0.1 + 0.6_5_1j
_lowerCAmelCase							:      Union[str, Any]						=	-2.0
_lowerCAmelCase							:      str						=	56
_lowerCAmelCase							:      Optional[Any]						=	2.0
_lowerCAmelCase							:      Dict						=	666

def      __snake_case						(					_lowerCAmelCase : complex				,				_lowerCAmelCase : numpy.ndarray	) ->						numpy.ndarray:
   return numpy.exp(_lowerCAmelCase	) + c_parameter

def      __snake_case						(					_lowerCAmelCase : complex				,				_lowerCAmelCase : numpy.ndarray	) ->						numpy.ndarray:
   return z_values * z_values + c_parameter

def      __snake_case						(					_lowerCAmelCase : float				,				_lowerCAmelCase : int	) ->						numpy.ndarray:
   A_					:				Tuple          =			numpy.linspace(-window_size				,				_lowerCAmelCase				,				_lowerCAmelCase	)
   A_					:				Optional[int]          =			x.reshape((nb_pixels, 1)	)
   A_					:				str          =			numpy.linspace(-window_size				,				_lowerCAmelCase				,				_lowerCAmelCase	)
   A_					:				Tuple          =			y.reshape((1, nb_pixels)	)
   return x + 1.0j * y

def      __snake_case						(					_lowerCAmelCase : Callable[[Any, numpy.ndarray], numpy.ndarray]				,				_lowerCAmelCase : Any				,				_lowerCAmelCase : int				,				_lowerCAmelCase : numpy.ndarray				,				_lowerCAmelCase : float | None = None				,				) ->						numpy.ndarray:
   A_					:				List[Any]          =			z_a.astype("complex64"	)
   for _ in range(_lowerCAmelCase	):
      A_					:				List[Any]          =			eval_function(_lowerCAmelCase				,				_lowerCAmelCase	)
      if infinity is not None:
         numpy.nan_to_num(_lowerCAmelCase				,				copy=_lowerCAmelCase				,				nan=_lowerCAmelCase	)
         A_					:				List[Any]          =			infinity
   return z_n

def      __snake_case						(					_lowerCAmelCase : str				,				_lowerCAmelCase : Any				,				_lowerCAmelCase : float				,				_lowerCAmelCase : numpy.ndarray				,				) ->						None:
   A_					:				Optional[int]          =			(abs(_lowerCAmelCase	)).transpose()
   A_					:				Optional[int]          =			abs_z_final[::-1, :]
   pyplot.matshow(abs_z_final < escape_radius	)
   pyplot.title(f"Julia set of ${function_label}$, $c={function_params}$"	)
   pyplot.show()

def      __snake_case						(					) ->						None:
   warnings.filterwarnings(
       "ignore"				,				category=_lowerCAmelCase				,				message="overflow encountered in multiply"	)
   warnings.filterwarnings(
       "ignore"				,				category=_lowerCAmelCase				,				message="invalid value encountered in multiply"				,				)
   warnings.filterwarnings(
       "ignore"				,				category=_lowerCAmelCase				,				message="overflow encountered in absolute"	)
   warnings.filterwarnings(
       "ignore"				,				category=_lowerCAmelCase				,				message="overflow encountered in exp"	)


if __name__ == "__main__":
 _lowerCAmelCase							:      List[str]						=	prepare_grid(window_size, nb_pixels)

 ignore_overflow_warnings()  # See file header for explanations

 _lowerCAmelCase							:      str						=	24
 _lowerCAmelCase							:      str						=	2 * abs(c_cauliflower) + 1
 _lowerCAmelCase							:      Optional[Any]						=	iterate_function(
     eval_quadratic_polynomial,
     c_cauliflower,
     nb_iterations,
     z_a,
     infinity=1.1 * escape_radius,
 )
 show_results('''z^2+c''', c_cauliflower, escape_radius, z_final)

 _lowerCAmelCase							:      Optional[int]						=	64
 _lowerCAmelCase							:      List[Any]						=	2 * abs(c_polynomial_a) + 1
 _lowerCAmelCase							:      List[str]						=	iterate_function(
     eval_quadratic_polynomial,
     c_polynomial_a,
     nb_iterations,
     z_a,
     infinity=1.1 * escape_radius,
 )
 show_results('''z^2+c''', c_polynomial_a, escape_radius, z_final)

 _lowerCAmelCase							:      Tuple						=	161
 _lowerCAmelCase							:      int						=	2 * abs(c_polynomial_a) + 1
 _lowerCAmelCase							:      List[Any]						=	iterate_function(
     eval_quadratic_polynomial,
     c_polynomial_a,
     nb_iterations,
     z_a,
     infinity=1.1 * escape_radius,
 )
 show_results('''z^2+c''', c_polynomial_a, escape_radius, z_final)

 _lowerCAmelCase							:      List[str]						=	12
 _lowerCAmelCase							:      str						=	1_0000.0
 _lowerCAmelCase							:      Tuple						=	iterate_function(
     eval_exponential,
     c_exponential,
     nb_iterations,
     z_a + 2,
     infinity=1.0e10,
 )
 show_results('''e^z+c''', c_exponential, escape_radius, z_final)
