





import math

import qiskit



def 		A_    (					_lowerCAmelCase = 1							,       _lowerCAmelCase = 1							,       _lowerCAmelCase = 1					)						->			qiskit.result.counts.Counts:
 if (
     isinstance(_lowerCAmelCase							,       _lowerCAmelCase					)
     or isinstance(_lowerCAmelCase							,       _lowerCAmelCase					)
     or isinstance(_lowerCAmelCase							,       _lowerCAmelCase					)
 ):
  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(_lowerCAmelCase					) != input_a)
     or (math.floor(_lowerCAmelCase					) != input_a)
     or (math.floor(_lowerCAmelCase					) != 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     : str	     =       qiskit.QuantumRegister(4							,       "qr"					)
 UpperCamelCase     : List[str]	     =       qiskit.ClassicalRegister(2							,       "cr"					)
 # list the entries
 UpperCamelCase     : int	     =       [input_a, input_a, carry_in]

 UpperCamelCase     : Dict	     =       qiskit.QuantumCircuit(_lowerCAmelCase							,       _lowerCAmelCase					)

 for i in range(0							,       3					):
  if entry[i] == 2:
   quantum_circuit.h(_lowerCAmelCase					)  # for hadamard entries
  elif entry[i] == 1:
   quantum_circuit.x(_lowerCAmelCase					)  # for 1 entries
  elif entry[i] == 0:
   quantum_circuit.i(_lowerCAmelCase					)  # 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]							,       _lowerCAmelCase					)  # measure the last two qbits

 UpperCamelCase     : List[str]	     =       qiskit.Aer.get_backend("aer_simulator"					)
 UpperCamelCase     : List[Any]	     =       qiskit.execute(_lowerCAmelCase							,       _lowerCAmelCase							,       shots=1000					)

 return job.result().get_counts(_lowerCAmelCase					)


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







from __future__ import annotations

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



def 		A_    (					_lowerCAmelCase							,       _lowerCAmelCase							,       _lowerCAmelCase							,       _lowerCAmelCase							,       )						->			list[float]:
 UpperCamelCase     ,   UpperCamelCase     : List[Any]	     =       coefficient_matrix.shape
 UpperCamelCase     ,   UpperCamelCase     : Optional[int]	     =       constant_matrix.shape

 if rowsa != colsa:
  UpperCamelCase     : List[Any]	     =       F"""Coefficient matrix dimensions must be nxn but received {rowsa}x{colsa}"""
  raise ValueError(_lowerCAmelCase					)

 if colsa != 1:
  UpperCamelCase     : Any	     =       F"""Constant matrix must be nx1 but received {rowsa}x{colsa}"""
  raise ValueError(_lowerCAmelCase					)

 if rowsa != rowsa:
  UpperCamelCase     : Tuple	     =       (
      "Coefficient and constant matrices dimensions must be nxn and nx1 but "
      F"""received {rowsa}x{colsa} and {rowsa}x{colsa}"""
  )
  raise ValueError(_lowerCAmelCase					)

 if len(_lowerCAmelCase					) != rowsa:
  UpperCamelCase     : Any	     =       (
      "Number of initial values must be equal to number of rows in coefficient "
      F"""matrix but received {len(_lowerCAmelCase					)} and {rowsa}"""
  )
  raise ValueError(_lowerCAmelCase					)

 if iterations <= 0:
  raise ValueError("Iterations must be at least 1"					)

 UpperCamelCase     : NDArray[floataa]	     =       np.concatenate(
     (coefficient_matrix, constant_matrix)							,       axis=1					)

 UpperCamelCase     ,   UpperCamelCase     : str	     =       table.shape

 strictly_diagonally_dominant(_lowerCAmelCase					)

 # Iterates the whole matrix for given number of times
 for _ in range(_lowerCAmelCase					):
  UpperCamelCase     : Optional[Any]	     =       []
  for row in range(_lowerCAmelCase					):
   UpperCamelCase     : Optional[int]	     =       0
   for col in range(_lowerCAmelCase					):
    if col == row:
     UpperCamelCase     : Union[str, Any]	     =       table[row][col]
    elif col == cols - 1:
     UpperCamelCase     : List[Any]	     =       table[row][col]
    else:
     temp += (-1) * table[row][col] * init_val[col]
   UpperCamelCase     : Dict	     =       (temp + val) / denom
   new_val.append(_lowerCAmelCase					)
  UpperCamelCase     : List[str]	     =       new_val

 return [float(_lowerCAmelCase					) for i in new_val]



def 		A_    (					_lowerCAmelCase					)						->			bool:
 UpperCamelCase     ,   UpperCamelCase     : Dict	     =       table.shape

 UpperCamelCase     : List[Any]	     =       True

 for i in range(0							,       _lowerCAmelCase					):
  UpperCamelCase     : Union[str, Any]	     =       0
  for j in range(0							,       cols - 1					):
   if i == j:
    continue
   else:
    total += table[i][j]

  if table[i][i] <= total:
   raise ValueError("Coefficient matrix is not strictly diagonally dominant"					)

 return is_diagonally_dominant


# Test Cases
if __name__ == "__main__":
    import doctest

    doctest.testmod()
