





'''simple docstring'''

import numpy as np
import qiskit


def 		__UpperCamelCase		(       _UpperCAmelCase,    _UpperCAmelCase   ):
		__UpperCAmelCase     :				Tuple					   =			qiskit.QuantumCircuit(num_qubits + 1   )

		# First, let's deal with the case in which oracle is balanced
		if case == "balanced":
				# First generate a random number that tells us which CNOTs to
				# wrap in X-gates:
				__UpperCAmelCase     :				List[str]					   =			np.random.randint(1,    2**num_qubits   )
				# Next, format 'b' as a binary string of length 'n', padded with zeros:
				__UpperCAmelCase     :				int					   =			format(_UpperCamelCase,    F"0{num_qubits}b"   )
				# Next, we place the first X-gates. Each digit in our binary string
				# corresponds to a qubit, if the digit is 0, we do nothing, if it's 1
				# we apply an X-gate to that qubit:
				for index, bit in enumerate(_UpperCamelCase   ):
						if bit == "1":
								oracle_qc.x(_UpperCamelCase   )
        # Do the controlled-NOT gates for each qubit, using the output qubit
        # as the target:
				for index in range(_UpperCamelCase   ):
						oracle_qc.cx(_UpperCamelCase,    _UpperCamelCase   )
				# Next, place the final X-gates
				for index, bit in enumerate(_UpperCamelCase   ):
						if bit == "1":
								oracle_qc.x(_UpperCamelCase   )

    # Case in which oracle is constant
		if case == "constant":
				# First decide what the fixed output of the oracle will be
				# (either always 0 or always 1)
				__UpperCAmelCase     :				Tuple					   =			np.random.randint(2   )
				if output == 1:
						oracle_qc.x(_UpperCamelCase   )

		__UpperCAmelCase     :				str					   =			oracle_qc.to_gate()
		__UpperCAmelCase     :				Tuple					   =			"Oracle"  # To show when we display the circuit
		return oracle_gate


def 		__UpperCamelCase		(       _UpperCAmelCase,    _UpperCAmelCase   ):
		__UpperCAmelCase     :				int					   =			qiskit.QuantumCircuit(num_qubits + 1,    _UpperCamelCase   )
		# Set up the output qubit:
		dj_circuit.x(_UpperCamelCase   )
		dj_circuit.h(_UpperCamelCase   )
		# And set up the input register:
		for qubit in range(_UpperCamelCase   ):
				dj_circuit.h(_UpperCamelCase   )
		# Let's append the oracle gate to our circuit:
		dj_circuit.append(_UpperCamelCase,    range(num_qubits + 1   )   )
		# Finally, perform the H-gates again and measure:
		for qubit in range(_UpperCamelCase   ):
				dj_circuit.h(_UpperCamelCase   )

		for i in range(_UpperCamelCase   ):
				dj_circuit.measure(_UpperCamelCase,    _UpperCamelCase   )

		return dj_circuit


def 		__UpperCamelCase		(       _UpperCAmelCase,    _UpperCAmelCase   ):
		__UpperCAmelCase     :				Optional[Any]					   =			qiskit.Aer.get_backend("aer_simulator"   )

		__UpperCAmelCase     :				str					   =			dj_oracle(_UpperCamelCase,    _UpperCamelCase   )
		__UpperCAmelCase     :				Optional[int]					   =			dj_algorithm(_UpperCamelCase,    _UpperCamelCase   )

		# Execute the circuit on the simulator
		__UpperCAmelCase     :				Optional[int]					   =			qiskit.execute(_UpperCamelCase,    _UpperCamelCase,    shots=1000   )

		# Return the histogram data of the results of the experiment.
		return job.result().get_counts(_UpperCamelCase   )


if __name__ == "__main__":
			print(f"Deutsch Jozsa - Constant Oracle: {deutsch_jozsa('constant', 3)}")
			print(f"Deutsch Jozsa - Balanced Oracle: {deutsch_jozsa('balanced', 3)}")





'''simple docstring'''




import math





def      _UpperCAmelCase    (							_UpperCamelCase    :	int   )	->      float:
    A_     =   math.log(2,   10   ) * number
    A_     =   round((log_number - int(_UpperCamelCase   )),   15   )

    return difference





def      _UpperCAmelCase    (							_UpperCamelCase    :	int = 67_89_10   )	->      int:
    A_     =   90
    A_     =   0

    A_     =   math.log(1.2_3,   10   )
    A_     =   math.log(1.2_4,   10   )
    A_     =   0

    while position < number:
        A_     =   log_difference(_UpperCamelCase   )

        if difference >= upper_limit:
            power_iterator += 93

        elif difference < lower_limit:
            power_iterator += 1_96

        else:
            A_     =   power_iterator
            power_iterator += 1_96
            position += 1

    return previous_power


if __name__ == "__main__":
  import doctest

  doctest.testmod()

  print(F"""{solution() = }""")






