"""simple docstring"""






import numpy as np



def   a_						(					lowerCamelCase					,			lowerCamelCase					,			lowerCamelCase = 1e-1_2					,			lowerCamelCase = 1_0_0					,			):
				assert np.shape(lowerCamelCase       )[0] == np.shape(lowerCamelCase       )[1]
				# Ensure proper dimensionality.
				assert np.shape(lowerCamelCase       )[0] == np.shape(lowerCamelCase       )[0]
				# Ensure inputs are either both complex or both real
				assert np.iscomplexobj(lowerCamelCase       ) == np.iscomplexobj(lowerCamelCase       )
				UpperCAmelCase__             =							np.iscomplexobj(lowerCamelCase       )
				if is_complex:
								# Ensure complex input_matrix is Hermitian
								assert np.array_equal(lowerCamelCase					,			input_matrix.conj().T       )

				# Set convergence to False. Will define convergence when we exceed max_iterations
				# or when we have small changes from one iteration to next.

				UpperCAmelCase__             =							False
				UpperCAmelCase__             =							0
				UpperCAmelCase__             =							0
				UpperCAmelCase__             =							1e1_2

				while not convergence:
								# Multiple matrix by the vector.
								UpperCAmelCase__             =							np.dot(lowerCamelCase					,			lowerCamelCase       )
								# Normalize the resulting output vector.
								UpperCAmelCase__             =							w / np.linalg.norm(lowerCamelCase       )
								# Find rayleigh quotient
								# (faster than usual b/c we know vector is normalized already)
								UpperCAmelCase__             =							vector.conj().T if is_complex else vector.T
								UpperCAmelCase__             =							np.dot(lowerCamelCase					,			np.dot(lowerCamelCase					,			lowerCamelCase       )       )

								# Check convergence.
								UpperCAmelCase__             =							np.abs(lambda_ - lambda_previous       ) / lambda_
								iterations += 1

								if error <= error_tol or iterations >= max_iterations:
												UpperCAmelCase__             =							True

								UpperCAmelCase__             =							lambda_

				if is_complex:
								UpperCAmelCase__             =							np.real(lambda_       )

				return lambda_, vector



def   a_						(					):
				UpperCAmelCase__             =							np.array([[4_1, 4, 2_0], [4, 2_6, 3_0], [2_0, 3_0, 5_0]]       )
				UpperCAmelCase__             =							np.array([4_1, 4, 2_0]       )
				UpperCAmelCase__             =							real_input_matrix.astype(np.complexaaa       )
				UpperCAmelCase__             =							np.triu(1J * complex_input_matrix					,			1       )
				complex_input_matrix += imag_matrix
				complex_input_matrix += -1 * imag_matrix.T
				UpperCAmelCase__             =							np.array([4_1, 4, 2_0]       ).astype(np.complexaaa       )

				for problem_type in ["real", "complex"]:
								if problem_type == "real":
												UpperCAmelCase__             =							real_input_matrix
												UpperCAmelCase__             =							real_vector
								elif problem_type == "complex":
												UpperCAmelCase__             =							complex_input_matrix
												UpperCAmelCase__             =							complex_vector

								# Our implementation.
								UpperCAmelCase__      ,	UpperCAmelCase__             =							power_iteration(lowerCamelCase					,			lowerCamelCase       )

								# Numpy implementation.

								# Get eigenvalues and eigenvectors using built-in numpy
								# eigh (eigh used for symmetric or hermetian matrices).
								UpperCAmelCase__      ,	UpperCAmelCase__             =							np.linalg.eigh(lowerCamelCase       )
								# Last eigenvalue is the maximum one.
								UpperCAmelCase__             =							eigen_values[-1]
								# Last column in this matrix is eigenvector corresponding to largest eigenvalue.
								UpperCAmelCase__             =							eigen_vectors[:, -1]

								# Check our implementation and numpy gives close answers.
								assert np.abs(eigen_value - eigen_value_max       ) <= 1e-6
								# Take absolute values element wise of each eigenvector.
								# as they are only unique to a minus sign.
								assert np.linalg.norm(np.abs(lowerCamelCase       ) - np.abs(lowerCamelCase       )       ) <= 1e-6


if __name__ == "__main__":
						import doctest

						doctest.testmod()
						test_power_iteration()




"""simple docstring"""






def   a_						(					lowerCamelCase       ):
				return str(lowerCamelCase       ) == str(lowerCamelCase       )[::-1]



def   a_						(					lowerCamelCase       ):
				return int(lowerCamelCase       ) + int(str(lowerCamelCase       )[::-1]       )



def   a_						(					lowerCamelCase = 1_0_0_0_0       ):
				UpperCAmelCase__             =							[]
				for num in range(1					,			lowerCamelCase       ):
								UpperCAmelCase__             =							0
								UpperCAmelCase__             =							num
								while iterations < 5_0:
												UpperCAmelCase__             =							sum_reverse(lowerCamelCase       )
												iterations += 1
												if is_palindrome(lowerCamelCase       ):
																break
								else:
												lychrel_nums.append(lowerCamelCase       )
				return len(lowerCamelCase       )


if __name__ == "__main__":
						print(F"""{solution() = }""")



