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.BitLogicExp[source]¶
Expression acting only on Bit or Constant types.
- 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.LogicExp[source]¶
Logical expressions over Bit or BitRegister. Encoded as a tree of expressions
- 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]
- class pytket.circuit.logic_exp.NullaryOp[source]¶
Expression for operation on no arguments (i.e. constant).
- class pytket.circuit.logic_exp.PredicateExp[source]¶
A binary predicate where the arguments are either Bits, BitRegisters, or Constants.
- class pytket.circuit.logic_exp.RegLogicExp[source]¶
Expression acting only on BitRegister or Constant types.
- 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: '~'>¶
- pytket.circuit.logic_exp.filter_by_type(seq, var_type)[source]¶
Return enumeration of seq, with only elements of type var_type.
- 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 asreg_eq(r, 5)
- Return type:
- 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 asreg_geq(r, 5)
- Return type:
- 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 asreg_gt(r, 5)
- Return type:
- 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 asreg_leq(r, 5)
- Return type:
- 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 asreg_lt(r, 5)
- Return type: