pytket.circuit.logic_exp

For more discussion of classical logic in pytket see the manual section.

Classes and functions for constructing logical expressions over Bit and BitRegister.

class pytket.circuit.logic_exp.And[source]
eval_vals()[source]

Attempt to evaluate all sub-expressions; simple constant folding.

Return type:

Union[LogicExp, Bit, BitRegister, int]

class pytket.circuit.logic_exp.BinaryOp[source]

Expresion for operation on two arguments.

class pytket.circuit.logic_exp.BitAnd(arg1, arg2)[source]
class pytket.circuit.logic_exp.BitEq(arg1, arg2)[source]
class pytket.circuit.logic_exp.BitLogicExp[source]

Expression acting only on Bit or Constant types.

class pytket.circuit.logic_exp.BitNeq(arg1, arg2)[source]
class pytket.circuit.logic_exp.BitNot(arg1)[source]
class pytket.circuit.logic_exp.BitOne[source]
class pytket.circuit.logic_exp.BitOr(arg1, arg2)[source]
eval_vals()[source]

Attempt to evaluate all sub-expressions; simple constant folding.

Return type:

Union[LogicExp, Bit, BitRegister, int]

enum pytket.circuit.logic_exp.BitWiseOp(value)[source]

Enum for operations on Bit.

Valid values are as follows:

AND = <BitWiseOp.AND: '&'>
OR = <BitWiseOp.OR: '|'>
XOR = <BitWiseOp.XOR: '^'>
EQ = <BitWiseOp.EQ: '=='>
NEQ = <BitWiseOp.NEQ: '!='>
NOT = <BitWiseOp.NOT: '~'>
ZERO = <BitWiseOp.ZERO: '0'>
ONE = <BitWiseOp.ONE: '1'>
class pytket.circuit.logic_exp.BitXor(arg1, arg2)[source]
class pytket.circuit.logic_exp.BitZero[source]
class pytket.circuit.logic_exp.Eq[source]
class pytket.circuit.logic_exp.LogicExp[source]

Logical expressions over Bit or BitRegister. Encoded as a tree of expressions

all_inputs()[source]
Returns:

All variables involved in expression.

Return type:

Set[Variable]

all_inputs_ordered()[source]
Returns:

All variables involved in expression, in order of first appearance.

Return type:

list[Variable]

eval_vals()[source]

Attempt to evaluate all sub-expressions; simple constant folding.

Return type:

Union[LogicExp, Bit, BitRegister, int]

classmethod factory(op)[source]

Return matching operation class for enum.

Return type:

type[LogicExp]

classmethod from_dict(dic)[source]

Load from JSON serializable nested dictionary.

Return type:

LogicExp

rename_args(cmap)[source]

Rename the Bits according to a Bit map. Raise ValueError if a bit is being used in a register-wise expression.

Return type:

bool

set_value(var, val)[source]

Set value of var to val recursively.

Return type:

None

to_dict()[source]

Output JSON serializable nested dictionary.

Return type:

dict[str, Any]

class pytket.circuit.logic_exp.Neq[source]
class pytket.circuit.logic_exp.NullaryOp[source]

Expression for operation on no arguments (i.e. constant).

class pytket.circuit.logic_exp.Or[source]
class pytket.circuit.logic_exp.PredicateExp[source]

A binary predicate where the arguments are either Bits, BitRegisters, or Constants.

class pytket.circuit.logic_exp.RegAdd(arg1, arg2)[source]
class pytket.circuit.logic_exp.RegAnd(arg1, arg2)[source]
class pytket.circuit.logic_exp.RegDiv(arg1, arg2)[source]
class pytket.circuit.logic_exp.RegEq(arg1, arg2)[source]
class pytket.circuit.logic_exp.RegGeq(arg1, arg2)[source]
class pytket.circuit.logic_exp.RegGt(arg1, arg2)[source]
class pytket.circuit.logic_exp.RegLeq(arg1, arg2)[source]
class pytket.circuit.logic_exp.RegLogicExp[source]

Expression acting only on BitRegister or Constant types.

class pytket.circuit.logic_exp.RegLsh(arg1, arg2)[source]
class pytket.circuit.logic_exp.RegLt(arg1, arg2)[source]
class pytket.circuit.logic_exp.RegMul(arg1, arg2)[source]
class pytket.circuit.logic_exp.RegNeg(arg1)[source]
class pytket.circuit.logic_exp.RegNeq(arg1, arg2)[source]
class pytket.circuit.logic_exp.RegNot(arg1)[source]
class pytket.circuit.logic_exp.RegOr(arg1, arg2)[source]
class pytket.circuit.logic_exp.RegPow(arg1, arg2)[source]
class pytket.circuit.logic_exp.RegRsh(arg1, arg2)[source]
class pytket.circuit.logic_exp.RegSub(arg1, arg2)[source]
enum pytket.circuit.logic_exp.RegWiseOp(value)[source]

Enum for operations on BitRegister.

Valid values are as follows:

AND = <RegWiseOp.AND: '&'>
OR = <RegWiseOp.OR: '|'>
XOR = <RegWiseOp.XOR: '^'>
EQ = <RegWiseOp.EQ: '=='>
NEQ = <RegWiseOp.NEQ: '!='>
LT = <RegWiseOp.LT: '<'>
GT = <RegWiseOp.GT: '>'>
LEQ = <RegWiseOp.LEQ: '<='>
GEQ = <RegWiseOp.GEQ: '>='>
ADD = <RegWiseOp.ADD: '+'>
SUB = <RegWiseOp.SUB: '-'>
MUL = <RegWiseOp.MUL: '*'>
DIV = <RegWiseOp.DIV: '/'>
POW = <RegWiseOp.POW: '**'>
LSH = <RegWiseOp.LSH: '<<'>
RSH = <RegWiseOp.RSH: '>>'>
NOT = <RegWiseOp.NOT: '~'>
class pytket.circuit.logic_exp.RegXor(arg1, arg2)[source]
class pytket.circuit.logic_exp.UnaryOp[source]

Expression for operation on one argument.

class pytket.circuit.logic_exp.Xor[source]
pytket.circuit.logic_exp.filter_by_type(seq, var_type)[source]

Return enumeration of seq, with only elements of type var_type.

Return type:

Iterator[tuple[int, TypeVar(T)]]

pytket.circuit.logic_exp.if_bit(bit)[source]

Equivalent of if bit:.

Return type:

PredicateExp

pytket.circuit.logic_exp.if_not_bit(bit)[source]

Equivalent of if not bit:.

Return type:

PredicateExp

pytket.circuit.logic_exp.reg_eq(register, value)[source]

Function to express a BitRegister equality predicate, i.e. for a register r, (r == 5) is expressed as reg_eq(r, 5)

Return type:

RegLogicExp

pytket.circuit.logic_exp.reg_geq(register, value)[source]

Function to express a BitRegister greater than or equal to predicate, i.e. for a register r, (r >= 5) is expressed as reg_geq(r, 5)

Return type:

RegLogicExp

pytket.circuit.logic_exp.reg_gt(register, value)[source]

Function to express a BitRegister greater than predicate, i.e. for a register r, (r > 5) is expressed as reg_gt(r, 5)

Return type:

RegLogicExp

pytket.circuit.logic_exp.reg_leq(register, value)[source]

Function to express a BitRegister less than or equal to predicate, i.e. for a register r, (r <= 5) is expressed as reg_leq(r, 5)

Return type:

RegLogicExp

pytket.circuit.logic_exp.reg_lt(register, value)[source]

Function to express a BitRegister less than predicate, i.e. for a register r, (r < 5) is expressed as reg_lt(r, 5)

Return type:

RegLogicExp

pytket.circuit.logic_exp.reg_neq(register, value)[source]

Function to express a BitRegister inequality predicate, i.e. for a register r, (r != 5) is expressed as reg_neq(r, 5)

Return type:

RegLogicExp