Bitwise Xor¶
The Bitwise Xor (denoted as '^') is implemented by applying the following truth table
a | b | a ^ b |
---|---|---|
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 0 |
between each pair of qubits (or qubit and bit) in registers A and B .
Note that integer and fixed-point numbers are represented in a 2-complement method during function evaluation. The binary number is extended in the case of a register size miss-match. For example, the positive signed number \((110)_2=6\) is expressed as \((00110)_2\) when operating with a 5-qubit register. Similarly, the negative signed number \((110)_2=-2\) is expressed as \((11110)_2\).
Examples:
5 ^ 3 = 6 since 101 ^ 011 = 110
5 ^ -3 = -8 since 0101 ^ 1101 = 1000
-5 ^ -3 = 6 since 1011 ^ 1101 = 0110
Syntax¶
Function: BitwiseXor
Parameters:
- left_arg: Union[int, RegisterUserInput]
- right_arg: Union[int, RegisterUserInput]
- output_size: Optional[PositiveInt]
- output_name: Optional[str]
inplace_arg
: Optional[str] = None
{
"function": "BitwiseXor",
"function_params": {
"left_arg": 3,
"right_arg": {
"size": 3
}
}
}
Register Names¶
By default, the input registers are called left_arg
and right_arg
. If the name field
of a RegisterUserInput
object is specified, then the name of the register is
determined accordingly. If one of the arguments is a constant then it is not available
as an input register.
The output registers include the result register. By default, it is called bitwise_xor
,
but its name may be overridden by the output_name
argument.
The inplace_arg
argument sets the argument to override.
If it is set to None
, the input registers are also available as output registers, with the
same names. If it is set to left
or right
, only the right or left argument will be available, respectively.
The qubits of the overriden argument will be used for the result.
Example 1: Two Register¶
{
"logic_flow": [
{
"function": "BitwiseXor",
"function_params": {
"left_arg": {
"size": 5,
"is_signed": true
},
"right_arg": {
"size": 3
}
}
}
]
}
from classiq import Model, QUInt, QSInt
from classiq.builtin_functions import BitwiseXor
params = BitwiseXor(
left_arg=QSInt(size=5).to_register_user_input(),
right_arg=QUInt(size=3).to_register_user_input(),
)
model = Model()
model.BitwiseXor(params)
circuit = model.synthesize()
This example generates a circuit that performs bitwise 'xor' between two registers. The left arg is a signed register with 5 qubits and the right arg is an unsigned register with 3 qubits.
Example 2: Integer and Register¶
{
"logic_flow": [
{
"function": "BitwiseXor",
"function_params": {
"left_arg": 3,
"right_arg": {
"size": 3
}
}
}
]
}
from classiq import Model, RegisterUserInput
from classiq.builtin_functions import BitwiseXor
params = BitwiseXor(left_arg=3, right_arg=RegisterUserInput(size=3))
model = Model()
model.BitwiseXor(params)
circuit = model.synthesize()
This example generates a circuit that performs bitwise 'and' between a quantum register and an integer. The left arg is an integer equal to three and the right arg is unsigned quantum register with 3 qubits.