Logical Gate

Not

class Not(bit)[source]

Logical NOT of input.

Parameters:bit (Express) – expression to be binary

Examples

>>> from pyqubo import Binary, Not
>>> a = Binary('a')
>>> exp = Not(a)
>>> model = exp.compile()
>>> for a in (0, 1):
...   print(a, int(model.energy({'a': a}, vartype='BINARY')))
0 1
1 0

And

class And(bit_a, bit_b)[source]

Logical AND of inputs.

Parameters:
  • bit_a (Express) – expression to be binary
  • bit_b (Express) – expression to be binary

Examples

>>> from pyqubo import Binary, And
>>> import itertools
>>> a, b = Binary('a'), Binary('b')
>>> exp = And(a, b)
>>> model = exp.compile()
>>> for a, b in itertools.product(*[(0, 1)] * 2):
...   print(a, b, int(model.energy({'a': a, 'b': b}, vartype='BINARY')))
0 0 0
0 1 0
1 0 0
1 1 1

Or

class Or(bit_a, bit_b)[source]

Logical OR of inputs.

Parameters:
  • bit_a (Express) – expression to be binary
  • bit_b (Express) – expression to be binary

Examples

>>> from pyqubo import Binary, Or
>>> import itertools
>>> a, b = Binary('a'), Binary('b')
>>> exp = Or(a, b)
>>> model = exp.compile()
>>> for a, b in itertools.product(*[(0, 1)] * 2):
...   print(a, b, int(model.energy({'a': a, 'b': b}, vartype='BINARY')))
0 0 0
0 1 1
1 0 1
1 1 1

Xor

class Xor(bit_a, bit_b)[source]

Logical XOR of inputs.

Parameters:
  • bit_a (Express) – expression to be binary
  • bit_b (Express) – expression to be binary

Examples

>>> from pyqubo import Binary, Xor
>>> import itertools
>>> a, b = Binary('a'), Binary('b')
>>> exp = Xor(a, b)
>>> model = exp.compile()
>>> for a, b in itertools.product(*[(0, 1)] * 2):
...   print(a, b, int(model.energy({'a': a, 'b': b}, vartype='BINARY')))
0 0 0
0 1 1
1 0 1
1 1 0