





'''simple docstring'''





import math

import qiskit





def     _UpperCamelCase     (a__   :List[Any] = 1   ,			a__   :Any = 1   ,			a__   :List[str] = 1       ):






							"""simple docstring"""





							if (
							    isinstance(SCREAMING_SNAKE_CASE_   ,			SCREAMING_SNAKE_CASE_       )
							    or isinstance(SCREAMING_SNAKE_CASE_   ,			SCREAMING_SNAKE_CASE_       )
							    or isinstance(SCREAMING_SNAKE_CASE_   ,			SCREAMING_SNAKE_CASE_       )
							):
														raise TypeError("""inputs must be integers."""       )

							if (input_a < 0) or (input_a < 0) or (carry_in < 0):
														raise ValueError("""inputs must be positive."""       )

							if (
							    (math.floor(SCREAMING_SNAKE_CASE_       ) != input_a)
							    or (math.floor(SCREAMING_SNAKE_CASE_       ) != input_a)
							    or (math.floor(SCREAMING_SNAKE_CASE_       ) != carry_in)
							):
														raise ValueError("""inputs must be exact integers."""       )

							if (input_a > 2) or (input_a > 2) or (carry_in > 2):
														raise ValueError("""inputs must be less or equal to 2."""       )

							# build registers
							UpperCamelCase__				     =			qiskit.QuantumRegister(4   ,			"""qr"""       )
							UpperCamelCase__				     =			qiskit.ClassicalRegister(2   ,			"""cr"""       )
							# list the entries
							UpperCamelCase__				     =			[input_a, input_a, carry_in]

							UpperCamelCase__				     =			qiskit.QuantumCircuit(SCREAMING_SNAKE_CASE_   ,			SCREAMING_SNAKE_CASE_       )

							for i in range(0   ,			3       ):
														if entry[i] == 2:
																					quantum_circuit.h(SCREAMING_SNAKE_CASE_       )  # for hadamard entries
														elif entry[i] == 1:
																					quantum_circuit.x(SCREAMING_SNAKE_CASE_       )  # for 1 entries
														elif entry[i] == 0:
																					quantum_circuit.i(SCREAMING_SNAKE_CASE_       )  # for 0 entries

    # build the circuit
							quantum_circuit.ccx(0   ,			1   ,			3       )  # ccx = toffoli gate
							quantum_circuit.cx(0   ,			1       )
							quantum_circuit.ccx(1   ,			2   ,			3       )
							quantum_circuit.cx(1   ,			2       )
							quantum_circuit.cx(0   ,			1       )

							quantum_circuit.measure([2, 3]   ,			SCREAMING_SNAKE_CASE_       )  # measure the last two qbits

							UpperCamelCase__				     =			qiskit.Aer.get_backend("""aer_simulator"""       )
							UpperCamelCase__				     =			qiskit.execute(SCREAMING_SNAKE_CASE_   ,			SCREAMING_SNAKE_CASE_   ,			shots=1000       )

							return job.result().get_counts(SCREAMING_SNAKE_CASE_       )


if __name__ == "__main__":
					print(f"""Total sum count for state is: {quantum_full_adder(1, 1, 1)}""")











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





def     _UpperCamelCase     (a__   :str   ,			a__   :complex   ,			a__   :str = "x"   ,			a__   :float = 10**-10   ,			a__   :int = 1   ,			):






							"""simple docstring"""





							UpperCamelCase__				     =			symbols(a__       )
							UpperCamelCase__				     =			lambdify(a__   ,			a__       )
							UpperCamelCase__				     =			lambdify(a__   ,			diff(a__   ,			a__       )       )

							UpperCamelCase__				     =			starting_point

							while True:
														if diff_function(a__       ) != 0:
																					UpperCamelCase__				     =			prev_guess - multiplicity * func(a__       ) / diff_function(
																					    a__       )
														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.0_05)}""",
					)

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




