





'''simple docstring'''







import qiskit
from qiskit.providers import Backend





def     lowerCamelCase_ (					SCREAMING_SNAKE_CASE__ :     int,     SCREAMING_SNAKE_CASE__ :     int				)	->		int:
						UpperCAmelCase_     : Optional[Any]         =					bin(SCREAMING_SNAKE_CASE__				)[2:], bin(SCREAMING_SNAKE_CASE__				)[2:]  # Remove leading '0b'

						# Ensure that both strings are of the same length
						if len(SCREAMING_SNAKE_CASE__				) > len(SCREAMING_SNAKE_CASE__				):
												UpperCAmelCase_     : str         =					y.zfill(len(SCREAMING_SNAKE_CASE__				)				)
						else:
												UpperCAmelCase_     : List[Any]         =					x.zfill(len(SCREAMING_SNAKE_CASE__				)				)

						# We need (3 * number of bits in the larger number)+1 qBits
						# The second parameter is the number of classical registers, to measure the result
						UpperCAmelCase_     : Optional[Any]         =					qiskit.QuantumCircuit((len(SCREAMING_SNAKE_CASE__				) * 3) + 1,     len(SCREAMING_SNAKE_CASE__				) + 1				)

						# We are essentially "not-ing" the bits that are 1
						# Reversed because it's easier to perform ops on more significant bits
						for i in range(len(SCREAMING_SNAKE_CASE__				)				):
												if x[::-1][i] == "1":
																		circuit.x(SCREAMING_SNAKE_CASE__				)
						for j in range(len(SCREAMING_SNAKE_CASE__				)				):
												if y[::-1][j] == "1":
																		circuit.x(len(SCREAMING_SNAKE_CASE__				) + j				)

						return circuit, x, y





def     lowerCamelCase_ (					SCREAMING_SNAKE_CASE__ :     qiskit.QuantumCircuit,     SCREAMING_SNAKE_CASE__ :     int,     SCREAMING_SNAKE_CASE__ :     int,     SCREAMING_SNAKE_CASE__ :     int,     SCREAMING_SNAKE_CASE__ :     int,     )	->		str:
						circuit.ccx(SCREAMING_SNAKE_CASE__,     SCREAMING_SNAKE_CASE__,     SCREAMING_SNAKE_CASE__				)
						circuit.cx(SCREAMING_SNAKE_CASE__,     SCREAMING_SNAKE_CASE__				)
						circuit.ccx(SCREAMING_SNAKE_CASE__,     SCREAMING_SNAKE_CASE__,     SCREAMING_SNAKE_CASE__				)
						circuit.cx(SCREAMING_SNAKE_CASE__,     SCREAMING_SNAKE_CASE__				)
						circuit.cx(SCREAMING_SNAKE_CASE__,     SCREAMING_SNAKE_CASE__				)





def     lowerCamelCase_ (					SCREAMING_SNAKE_CASE__ :     int,     SCREAMING_SNAKE_CASE__ :     int,     SCREAMING_SNAKE_CASE__ :     Backend = qiskit.Aer.get_backend('''aer_simulator'''				),     )	->		Union[str, Any]:







						if vala < 0 or vala < 0:
												raise ValueError('''Both Integers must be positive!'''				)

						# Store the Integers
						UpperCAmelCase_     : Tuple         =					store_two_classics(SCREAMING_SNAKE_CASE__,     SCREAMING_SNAKE_CASE__				)
						for i in range(len(SCREAMING_SNAKE_CASE__				)				):
												full_adder(SCREAMING_SNAKE_CASE__,     SCREAMING_SNAKE_CASE__,     len(SCREAMING_SNAKE_CASE__				) + i,     len(SCREAMING_SNAKE_CASE__				) + len(SCREAMING_SNAKE_CASE__				) + i,     len(SCREAMING_SNAKE_CASE__				) + len(SCREAMING_SNAKE_CASE__				) + i + 1				)
												circuit.barrier()  # Optional, just for aesthetics

						# Measure the resultant qBits
						for i in range(len(SCREAMING_SNAKE_CASE__				) + 1				):
												circuit.measure([(len(SCREAMING_SNAKE_CASE__				) * 2) + i],     [i]				)

						UpperCAmelCase_     : Union[str, Any]         =					qiskit.execute(SCREAMING_SNAKE_CASE__,     SCREAMING_SNAKE_CASE__,     shots=1				).result()

						# The result is in binary. Convert it back to int
						return int(list(res.get_counts()				)[0],     2				)


if __name__ == "__main__":
					import doctest

					doctest.testmod()







'''simple docstring'''







import numpy as np
from numpy import floataa
from numpy.typing import NDArray





def     lowerCamelCase_ (					SCREAMING_SNAKE_CASE__ :     NDArray[floataa],     SCREAMING_SNAKE_CASE__ :     NDArray[floataa]				)	->		NDArray[floataa]:
						UpperCAmelCase_  ,    UpperCAmelCase_     : Any         =					np.shape(SCREAMING_SNAKE_CASE__				)

						UpperCAmelCase_     : NDArray[floataa]         =					np.zeros((rows, 1),     dtype=SCREAMING_SNAKE_CASE__				)
						for row in reversed(range(SCREAMING_SNAKE_CASE__				)				):
												UpperCAmelCase_     : Union[str, Any]         =					0
												for col in range(row + 1,     SCREAMING_SNAKE_CASE__				):
																		total += coefficients[row, col] * x[col]

												UpperCAmelCase_     : str         =					(vector[row] - total) / coefficients[row, row]

						return x





def     lowerCamelCase_ (					SCREAMING_SNAKE_CASE__ :     NDArray[floataa],     SCREAMING_SNAKE_CASE__ :     NDArray[floataa]				)	->		NDArray[floataa]:
						UpperCAmelCase_  ,    UpperCAmelCase_     : List[Any]         =					np.shape(SCREAMING_SNAKE_CASE__				)
						if rows != columns:
												return np.array((),     dtype=SCREAMING_SNAKE_CASE__				)

						# augmented matrix
						UpperCAmelCase_     : NDArray[floataa]         =					np.concatenate((coefficients, vector),     axis=1				)
						UpperCAmelCase_     : Optional[Any]         =					augmented_mat.astype('''float64'''				)

						# scale the matrix leaving it triangular
						for row in range(rows - 1				):
												UpperCAmelCase_     : Optional[int]         =					augmented_mat[row, row]
												for col in range(row + 1,     SCREAMING_SNAKE_CASE__				):
																		UpperCAmelCase_     : Optional[Any]         =					augmented_mat[col, row] / pivot
																		augmented_mat[col, :] -= factor * augmented_mat[row, :]

						UpperCAmelCase_     : Optional[Any]         =					retroactive_resolution(
						    augmented_mat[:, 0:columns],     augmented_mat[:, columns : columns + 1]				)

						return x


if __name__ == "__main__":
					import doctest

					doctest.testmod()





