"""simple docstring"""







from __future__ import annotations

from typing import Any


def   __lowerCAmelCase(		*__UpperCAmelCase      ):






	"""simple docstring"""





	if all(_check_not_integer(__UpperCAmelCase      ) for m in matrix_s      ):
		for i in matrix_s[1:]:
			_verify_matrix_sizes(matrix_s[0]  ,__UpperCAmelCase      )
		return [[sum(__UpperCAmelCase      ) for t in zip(*__UpperCAmelCase      )] for m in zip(*__UpperCAmelCase      )]
	raise TypeError('Expected a matrix, got int/list instead'      )


def   __lowerCAmelCase(		__UpperCAmelCase  ,__UpperCAmelCase      ):






	"""simple docstring"""





	if (
	    _check_not_integer(__UpperCAmelCase      )
	    and _check_not_integer(__UpperCAmelCase      )
	    and _verify_matrix_sizes(__UpperCAmelCase  ,__UpperCAmelCase      )
	):
		return [[i - j for i, j in zip(*__UpperCAmelCase      )] for m in zip(__UpperCAmelCase  ,__UpperCAmelCase      )]
	raise TypeError('Expected a matrix, got int/list instead'      )


def   __lowerCAmelCase(		__UpperCAmelCase  ,__UpperCAmelCase      ):






	"""simple docstring"""





	return [[x * n for x in row] for row in matrix]


def   __lowerCAmelCase(		__UpperCAmelCase  ,__UpperCAmelCase      ):






	"""simple docstring"""





	if _check_not_integer(__UpperCAmelCase      ) and _check_not_integer(__UpperCAmelCase      ):
		_lowercase					,   _lowercase			:     List[str]      					=				_verify_matrix_sizes(__UpperCAmelCase  ,__UpperCAmelCase      )

	if cols[0] != rows[1]:
		_lowercase			:     Tuple      					=				(
		    'Cannot multiply matrix of dimensions '
		    F'''({rows[0]},{cols[0]}) and ({rows[1]},{cols[1]})'''
		)
		raise ValueError(__UpperCAmelCase      )
	return [
	    [sum(m * n for m, n in zip(__UpperCAmelCase  ,__UpperCAmelCase      )      ) for j in zip(*__UpperCAmelCase      )] for i in matrix_a
	]


def   __lowerCAmelCase(		__UpperCAmelCase      ):






	"""simple docstring"""





	_lowercase			:     int      					=				int(__UpperCAmelCase      )
	return [[int(row == column      ) for column in range(__UpperCAmelCase      )] for row in range(__UpperCAmelCase      )]


def   __lowerCAmelCase(		__UpperCAmelCase  ,__UpperCAmelCase = True      ):






	"""simple docstring"""





	if _check_not_integer(__UpperCAmelCase      ):
		if return_map:
			return map(__UpperCAmelCase  ,zip(*__UpperCAmelCase      )      )
		else:
			return list(map(__UpperCAmelCase  ,zip(*__UpperCAmelCase      )      )      )
	raise TypeError('Expected a matrix, got int/list instead'      )


def   __lowerCAmelCase(		__UpperCAmelCase  ,__UpperCAmelCase  ,__UpperCAmelCase      ):






	"""simple docstring"""





	_lowercase			:     Optional[Any]      					=				matrix[:row] + matrix[row + 1 :]
	return [row[:column] + row[column + 1 :] for row in minor]


def   __lowerCAmelCase(		__UpperCAmelCase      ):






	"""simple docstring"""





	if len(__UpperCAmelCase      ) == 1:
		return matrix[0][0]

	return sum(
	    x * determinant(minor(__UpperCAmelCase  ,0  ,__UpperCAmelCase      )      ) * (-1) ** i
	    for i, x in enumerate(matrix[0]      )      )


def   __lowerCAmelCase(		__UpperCAmelCase      ):






	"""simple docstring"""





	_lowercase			:     Any      					=				determinant(__UpperCAmelCase      )
	if det == 0:
		return None

	_lowercase			:     List[str]      					=				[
	    [determinant(minor(__UpperCAmelCase  ,__UpperCAmelCase  ,__UpperCAmelCase      )      ) for j in range(len(__UpperCAmelCase      )      )]
	    for i in range(len(__UpperCAmelCase      )      )
	]

	_lowercase			:     Tuple      					=				[
	    [x * (-1) ** (row + col) for col, x in enumerate(matrix_minor[row]      )]
	    for row in range(len(__UpperCAmelCase      )      )
	]
	_lowercase			:     Dict      					=				list(transpose(__UpperCAmelCase      )      )
	return scalar_multiply(__UpperCAmelCase  ,1 / det      )


def   __lowerCAmelCase(		__UpperCAmelCase      ):






	"""simple docstring"""





	return not isinstance(__UpperCAmelCase  ,__UpperCAmelCase      ) and not isinstance(matrix[0]  ,__UpperCAmelCase      )


def   __lowerCAmelCase(		__UpperCAmelCase      ):






	"""simple docstring"""





	return len(__UpperCAmelCase      ), len(matrix[0]      )


def   __lowerCAmelCase(		__UpperCAmelCase  ,__UpperCAmelCase      ):






	"""simple docstring"""





	_lowercase			:     List[str]      					=				_shape(__UpperCAmelCase      ) + _shape(__UpperCAmelCase      )
	if shape[0] != shape[3] or shape[1] != shape[2]:
		_lowercase			:     Optional[int]      					=				(
		    'operands could not be broadcast together with shape '
		    F'''({shape[0], shape[1]}), ({shape[2], shape[3]})'''
		)
		raise ValueError(__UpperCAmelCase      )
	return (shape[0], shape[2]), (shape[1], shape[3])


def   __lowerCAmelCase(		):






	"""simple docstring"""





	_lowercase			:     str      					=				[[12, 10], [3, 9]]
	_lowercase			:     Optional[int]      					=				[[3, 4], [7, 4]]
	_lowercase			:     Dict      					=				[[11, 12, 13, 14], [21, 22, 23, 24], [31, 32, 33, 34], [41, 42, 43, 44]]
	_lowercase			:     Dict      					=				[[3, 0, 2], [2, 0, -2], [0, 1, 1]]
	print(F'''Add Operation, {add(__UpperCAmelCase  ,__UpperCAmelCase      ) = } \n'''      )
	print(
	    F'''Multiply Operation, {multiply(__UpperCAmelCase  ,__UpperCAmelCase      ) = } \n'''  ,)
	print(F'''Identity: {identity(5      )}\n'''      )
	print(F'''Minor of {matrix_c} = {minor(__UpperCAmelCase  ,1  ,2      )} \n'''      )
	print(F'''Determinant of {matrix_b} = {determinant(__UpperCAmelCase      )} \n'''      )
	print(F'''Inverse of {matrix_d} = {inverse(__UpperCAmelCase      )}\n'''      )


if __name__ == "__main__":
						import doctest

						doctest.testmod()
						main()




"""simple docstring"""







def   __lowerCAmelCase(		__UpperCAmelCase      ):






	"""simple docstring"""





	if len(__UpperCAmelCase      ) > 1:
		_lowercase			:     Dict      					=				len(__UpperCAmelCase      ) // 2  # Finds the middle of the array
		_lowercase			:     List[str]      					=				arr[
		    :middle_length
		]  # Creates an array of the elements in the first half.
		_lowercase			:     Optional[int]      					=				arr[
		    middle_length:
		]  # Creates an array of the elements in the second half.
		_lowercase			:     Optional[Any]      					=				len(__UpperCAmelCase      )
		_lowercase			:     Optional[int]      					=				len(__UpperCAmelCase      )
		merge(__UpperCAmelCase      )  # Starts sorting the left.
		merge(__UpperCAmelCase      )  # Starts sorting the right
		_lowercase			:     Dict      					=				0  # Left Counter
		_lowercase			:     List[str]      					=				0  # Right Counter
		_lowercase			:     Optional[Any]      					=				0  # Position Counter
		while (
		    left_index < left_size and right_index < right_size
		):  # Runs until the lowers size of the left and right are sorted.
			if left_array[left_index] < right_array[right_index]:
				_lowercase			:     Optional[int]      					=				left_array[left_index]
				left_index += 1
			else:
				_lowercase			:     int      					=				right_array[right_index]
				right_index += 1
			index += 1
		while (
		    left_index < left_size
		):  # Adds the left over elements in the left half of the array
			_lowercase			:     Any      					=				left_array[left_index]
			left_index += 1
			index += 1
		while (
		    right_index < right_size
		):  # Adds the left over elements in the right half of the array
			_lowercase			:     str      					=				right_array[right_index]
			right_index += 1
			index += 1
	return arr


if __name__ == "__main__":
						import doctest

						doctest.testmod()



