'''simple docstring'''




import qiskit
from qiskit.providers import Backend


def  lowerCamelCase__						(  SCREAMING_SNAKE_CASE :				int    ,				SCREAMING_SNAKE_CASE :				int  ):
  UpperCAmelCase							, UpperCAmelCase  							=		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  							=		y.zfill(len(SCREAMING_SNAKE_CASE  )  )
  else:
    UpperCAmelCase  							=		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  							=		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    ,				):
  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'  )    ,				):

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

  # Store the Integers
  UpperCAmelCase							, UpperCAmelCase							, UpperCAmelCase  							=		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  							=		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'''




def  lowerCamelCase__						(  SCREAMING_SNAKE_CASE :				str  ):
  UpperCAmelCase  							=		str(SCREAMING_SNAKE_CASE  ).strip()
  if not bin_string:
    raise ValueError('Empty string was passed to the function'  )
  UpperCAmelCase  							=		bin_string[0] == '-'
  if is_negative:
    UpperCAmelCase  							=		bin_string[1:]
  if not all(char in '01' for char in bin_string  ):
    raise ValueError('Non-binary value was passed to the function'  )
  UpperCAmelCase  							=		0
  for char in bin_string:
    UpperCAmelCase  							=		2 * decimal_number + int(SCREAMING_SNAKE_CASE  )
  return -decimal_number if is_negative else decimal_number


if __name__ == "__main__":
  from doctest import testmod

  testmod()


