import numpy as np
from qiskit import *

def Qand(First_bool,Second_bool):

    #input two booleans into the function
    a = int(First_bool)
    b = int(Second_bool)

    #quantum circuit that applies a Toffoli gate 
    q = QuantumRegister(3)

    qc = QuantumCircuit(q)
    if a is 1:
        qc.x(0)
    if b is 1:
        qc.x(1)
    qc.ccx(q[0], q[1], q[2])
    
    # Code for giving a True if the 3rd qubit is 1 and False if the 3rd qubit is 0
    backend = Aer.get_backend('statevector_simulator')
    job = execute(qc, backend)
    result = job.result()
    outputstate = result.get_statevector(qc, decimals=8)
    Q_and = bool(int(np.real(outputstate[7])))
    
    return Q_and

def Qor(First_bool,Second_bool):

    #input two booleans into the function
    a = int(First_bool)
    b = int(Second_bool)

    #quantum circuit that applies a Toffoli gate 
    q = QuantumRegister(3)

    qc = QuantumCircuit(q)
    if a is 1:
        qc.x(0)
    if b is 1:
        qc.x(1)
    qc.ccx(q[0], q[1], q[2])

    # Code for giving a True at least one of the two control qubits are in state 1
    backend = Aer.get_backend('statevector_simulator')
    job = execute(qc, backend)
    result = job.result()
    outputstate = result.get_statevector(qc, decimals=8)

    if a is 1 and b is 0:
        Q_or = bool(int(np.real(outputstate[1])))
    elif a is 0 and b is 1:
        Q_or = bool(int(np.real(outputstate[2])))
    else:
        Q_or = bool(int(np.real(outputstate[7])))
    
    return(Q_or)