Return symbolic logic for an N-bit ripple carry adder.
504996
def ripple_carry_add(A, B, cin=0):
    """"""
    if len(A) != len(B):
        raise ValueError("expected A and B to be equal length")
    ss, cs = list(), list()
    for i, a in enumerate(A):
        c = (cin if i == 0 else cs[i-1])
        ss.append(a ^ B[i] ^ c)
        cs.append(a & B[i] | a & c | B[i] & c)
    return farray(ss), farray(cs)
109473
def _neg8(ins):
    
    output = _8bit_oper(ins.quad[2])
    output.append('neg')
    output.append('push af')

    return output
805756
def _symm_current(C):
    """"""
    nans = np.isnan(C)
    C[nans] = np.einsum('klij', C)[nans]
    return C
858604
def _xor8(ins):
    
    op1, op2 = tuple(ins.quad[2:])
    if _int_ops(op1, op2) is not None:
        op1, op2 = _int_ops(op1, op2)

        output = _8bit_oper(op1)  # True or X = not X
        if op2 == 0:  # False xor X = X
            output.append('push af')
            return output

        output.append('sub 1')
        output.append('sbc a, a')
        output.append('push af')
        return output

    output = _8bit_oper(op1, op2)
    output.append('call __XOR8')
    output.append('push af')
    REQUIRES.add('xor8.asm')

    return output
1325392
def num_qubits(self) -> Optional[int]:
        """"""
        if not self:
            return None
        any_gate = next(iter(self))
        return any_gate.num_qubits()
55268
def BitVecFuncSym(
        name: str,
        func_name: str,
        size: int,
        annotations: Annotations = None,
        input_: Union[int, "BitVec"] = None,
    ) -> BitVecFunc:
        """"""
        raw = z3.BitVec(name, size)
        return BitVecFunc(raw, func_name, input_, annotations)
606493
def mem_concrete(self, *args, **kwargs):
        
        e = self.memory.load(*args, **kwargs)
        if self.solver.symbolic(e):
            raise SimValueError("target of mem_concrete is symbolic!")
        return self.solver.eval(e)
267393
def symbolic(self, e): # pylint:disable=R0201
        
        if type(e) in (int, bytes, float, bool):
            return False
        return e.symbolic
1132281
def _eq16(ins):
    ''' 
    '''
    output = _16bit_oper(ins.quad[2], ins.quad[3])
    output.append('call __EQ16')
    output.append('push af')
    REQUIRES.add('eq16.asm')

    return output
472000
def Pad(self, n):
        """"""
        for i in range_func(n):
            self.Place(0, N.Uint8Flags)
1278696
def ucc_circuit(theta):
    
    generator = sX(0) * sY(1)
    initial_prog = Program().inst(X(1), X(0))

    # compiled program
    program = initial_prog + exponentiate(float(theta) * generator)  # float is required because pyquil has weird casting behavior
    return program
337387
def toBCD (n):

    """"""
    bcd  = 0
    bits = 0

    while True:
        n, r  = divmod(n, 10)
        bcd  |= (r << bits)
        if n is 0:
            break
        bits += 4

    return bcd
1032517
function (input, alphabetName) {
        var alphabet = alphabets[alphabetName || 'ripple'],
            base     = new sjcl.bn(alphabet.length),
            bi       = sjcl.bn.fromBits(sjcl.codec.bytes.toBits(input)),
            buffer   = [];

        while (bi.greaterEquals(base)) {
          var mod = bi.mod(base);
          buffer.push(alphabet[mod.limbs[0]]);
          bi = bi.div(base);
        }
        buffer.push(alphabet[bi.limbs[0]]);

        // Convert leading zeros too.
        for (var i = 0; i != input.length && !input[i]; i += 1) {
          buffer.push(alphabet[0]);
        }

        return buffer.reverse().join("");
      }
819503
def bitwise_xor(self, t):
        

        # Using same variables as in paper
        s = self
        new_interval = (s.bitwise_not().bitwise_or(t)).bitwise_not().bitwise_or(s.bitwise_or(t.bitwise_not()).bitwise_not())
        return new_interval.normalize()
206205
function (input, alphabetName) {
        var alphabet = alphabets[alphabetName || 'ripple'],
            base     = new sjcl.bn(alphabet.length),
            bi       = new sjcl.bn(0);

        var i;
        while (i != input.length && input[i] === alphabet[0]) {
          i += 1;
        }

        for (i = 0; i != input.length; i += 1) {
          var v = alphabet.indexOf(input[i]);

          if (v < 0) {
            return null;
          }

          bi = bi.mul(base).addM(v);
        }

        var bytes = sjcl.codec.bytes.fromBits(bi.toBits()).reverse();

        // Remove leading zeros
        while(bytes[bytes.length-1] === 0) {
          bytes.pop();
        }

        // Add the right number of leading zeros
        for (i = 0; input[i] === alphabet[0]; i++) {
          bytes.push(0);
        }

        bytes.reverse();

        return bytes;
      }
92956
def make_oracle(input_qubits,
                output_qubit,
                secret_factor_bits,
                secret_bias_bit):
    """"""

    if secret_bias_bit:
        yield cirq.X(output_qubit)

    for qubit, bit in zip(input_qubits, secret_factor_bits):
        if bit:
            yield cirq.CNOT(qubit, output_qubit)
1371977
def _bnot16(ins):
    ''' 
    '''
    output = _16bit_oper(ins.quad[2])
    output.append('call __BNOT16')
    output.append('push hl')
    REQUIRES.add('bnot16.asm')
    return output