





import numpy as np







def  A					(				UpperCAmelCase					):
					_snake_case							,			_snake_case							:       Any												= a.shape
					_snake_case							:       List[Any]												= min(UpperCAmelCase	,	UpperCAmelCase					)
					_snake_case							:       Any												= np.eye(UpperCAmelCase					)
					_snake_case							:       List[Any]												= a.copy()

					for k in range(t - 1					):
										# select a column of modified matrix A':
										_snake_case							:       int												= r[k:, [k]]
										# construct first basis vector
										_snake_case							:       Any												= np.zeros_like(UpperCAmelCase					)
										_snake_case							:       List[Any]												= 1.0
										# determine scaling factor
										_snake_case							:       Union[str, Any]												= np.linalg.norm(UpperCAmelCase					)
										# construct vector v for Householder reflection
										_snake_case							:       Optional[int]												= x + np.sign(x[0]					) * alpha * ea
										v /= np.linalg.norm(UpperCAmelCase					)

										# construct the Householder matrix
										_snake_case							:       Dict												= np.eye(m - k					) - 2.0 * v @ v.T
										# pad with ones and zeros as necessary
										_snake_case							:       Optional[int]												= np.block([[np.eye(UpperCAmelCase					), np.zeros((k, m - k)					)], [np.zeros((m - k, k)					), q_k]]					)

										_snake_case							:       str												= q @ q_k.T
										_snake_case							:       Optional[Any]												= q_k @ r

					return q, r


if __name__ == "__main__":
							import doctest

							doctest.testmod()






from __future__ import annotations

from collections.abc import Generator







def  A					(				UpperCAmelCase					):
					if not isinstance(UpperCAmelCase	,	UpperCAmelCase					) or n < 1:
										raise Exception("Sequence only defined for positive integers"					)

					yield n
					while n != 1:
										if n % 2 == 0:
															n //= 2
										else:
															_snake_case							:       Any												= 3 * n + 1
										yield n







def  A					(				):
					_snake_case							:       Dict												= 43
					_snake_case							:       List[str]												= tuple(collatz_sequence(UpperCAmelCase					)					)
					print(UpperCAmelCase					)
					print(F"""Collatz sequence from {n} took {len(UpperCAmelCase					)} steps."""					)


if __name__ == "__main__":
							main()