



import math

import numpy as np
import qiskit
from qiskit import Aer, ClassicalRegister, QuantumCircuit, QuantumRegister, execute





def 							A			(  _UpperCAmelCase       :     int = 3					)       ->				qiskit.result.counts.Counts:







			'''simple docstring'''
			if isinstance(_UpperCAmelCase							,     _UpperCAmelCase					):
						raise TypeError('number of qubits must be a integer.'					)
			if number_of_qubits <= 0:
						raise ValueError('number of qubits must be > 0.'					)
			if math.floor(_UpperCAmelCase					) != number_of_qubits:
						raise ValueError('number of qubits must be exact integer.'					)
			if number_of_qubits > 10:
						raise ValueError('number of qubits too large to simulate(>10).'					)

			_UpperCAmelCase	 =     QuantumRegister(_UpperCAmelCase							,     'qr'					)
			_UpperCAmelCase	 =     ClassicalRegister(_UpperCAmelCase							,     'cr'					)

			_UpperCAmelCase	 =     QuantumCircuit(_UpperCAmelCase							,     _UpperCAmelCase					)

			_UpperCAmelCase	 =     number_of_qubits

			for i in range(_UpperCAmelCase					):
						quantum_circuit.h(number_of_qubits - i - 1					)
						counter -= 1
						for j in range(_UpperCAmelCase					):
									quantum_circuit.cp(np.pi / 2 ** (counter - j)							,     _UpperCAmelCase							,     _UpperCAmelCase					)

			for k in range(number_of_qubits // 2					):
						quantum_circuit.swap(_UpperCAmelCase							,     number_of_qubits - k - 1					)

			# measure all the qubits
			quantum_circuit.measure(_UpperCAmelCase							,     _UpperCAmelCase					)
			# simulate with 10000 shots
			_UpperCAmelCase	 =     Aer.get_backend('qasm_simulator'					)
			_UpperCAmelCase	 =     execute(_UpperCAmelCase							,     _UpperCAmelCase							,     shots=10_000					)

			return job.result().get_counts(_UpperCAmelCase					)


if __name__ == "__main__":
							print(
							    f"""Total count for quantum fourier transform state is: \
    {quantum_fourier_transform(3)}"""
							)





from sympy import diff, lambdify, symbols
from sympy.functions import *  # noqa: F403





def 							A			(  _UpperCAmelCase       :     str							,     _UpperCAmelCase       :     complex							,     _UpperCAmelCase       :     str = "x"							,     _UpperCAmelCase       :     float = 10**-10							,     _UpperCAmelCase       :     int = 1							,     )       ->				complex:







			'''simple docstring'''
			_UpperCAmelCase	 =     symbols(_UpperCAmelCase					)
			_UpperCAmelCase	 =     lambdify(_UpperCAmelCase							,     _UpperCAmelCase					)
			_UpperCAmelCase	 =     lambdify(_UpperCAmelCase							,     diff(_UpperCAmelCase							,     _UpperCAmelCase					)					)

			_UpperCAmelCase	 =     starting_point

			while True:
						if diff_function(_UpperCAmelCase					) != 0:
									_UpperCAmelCase	 =     prev_guess - multiplicity * func(_UpperCAmelCase					) / diff_function(
									    _UpperCAmelCase					)
						else:
									raise ZeroDivisionError('Could not find root'					) from None

						# Precision is checked by comparing the difference of consecutive guesses
						if abs(next_guess - prev_guess					) < precision:
									return next_guess

						_UpperCAmelCase	 =     next_guess


# Let's Execute
if __name__ == "__main__":
							# Find root of trigonometric function
							# Find value of pi
							print(f"""The root of sin(x) = 0 is {newton_raphson("sin(x)", 2)}""")

							# Find root of polynomial
							# Find fourth Root of 5
							print(f"""The root of x**4 - 5 = 0 is {newton_raphson("x**4 -5", 0.4 +5J)}""")

							# Find value of e
							print(
							    "The root of log(y) - 1 = 0 is ",
							    f"""{newton_raphson("log(y) - 1", 2, variable="y")}""",
							)

							# Exponential Roots
							print(
							    "The root of exp(x) - 1 = 0 is",
							    f"""{newton_raphson("exp(x) - 1", 10, precision=0.005)}""",
							)

							# Find root of cos(x)
							print(f"""The root of cos(x) = 0 is {newton_raphson("cos(x)", 0)}""")
