Skip to content

Bitwise Or

The Bitwise Or (denoted as '|') is implemented by applying the following truth table between each pair of qubits (or qubit and bit) in registers A and B.

a b a or b
0 0 0
0 1 1
1 0 1
1 1 1

Note that integer and fixed-point numbers are represented in a two-complement method during function evaluation. The binary number is extended in the case of a register size mismatch.

For example, the positive signed number \((110)_2=6\) is expressed as \((00110)_2\) when operating with a five-qubit register. Similarly, the negative signed number \((110)_2=-2\) is expressed as \((11110)_2\).

Examples:

5 | 3 = 7 since 101 | 011 = 111

5 | -3 = -3 since 0101 | 1101 = 1101

-5 | -3 = -1 since 1011 | 1101 = 1111

Syntax

Function: BitwiseOr

Parameters:

Register Names:

  • left_arg: left_arg
  • right_arg: right_arg
  • result: bitwise_or
{
  "functions": [
    {
      "name": "main",
      "body": [
        {
          "function": "BitwiseOr",
          "function_params": {
            "left_arg": 3,
            "right_arg": { "size": 3 }
          }
        }
      ]
    }
  ]
}

Example 1: Two Register

{
  "functions": [
    {
      "name": "main",
      "body": [
        {
          "function": "BitwiseOr",
          "function_params": {
            "left_arg": {
              "size": 5,
              "is_signed": true
            },
            "right_arg": {
              "size": 3
            }
          }
        }
      ]
    }
  ]
}
from classiq import Model, QUInt, QSInt, synthesize
from classiq.builtin_functions import BitwiseOr

params = BitwiseOr(
    left_arg=QSInt(size=5).to_register_user_input(),
    right_arg=QUInt(size=3).to_register_user_input(),
)
model = Model()
model.BitwiseOr(params)
quantum_prgram = synthesize(model.get_model())

This example generates a quantum program that performs bitwise 'or' between two registers. The left arg is signed with five qubits and the right arg is unsigned with three qubits.

img_7.png

Example 2: Integer and Register

{
  "functions": [
    {
      "name": "main",
      "body": [
        {
          "function": "BitwiseOr",
          "function_params": {
            "left_arg": 3,
            "right_arg": { "size": 3 }
          }
        }
      ]
    }
  ]
}
from classiq import Model, RegisterUserInput, synthesize
from classiq.builtin_functions import BitwiseOr

params = BitwiseOr(left_arg=3, right_arg=RegisterUserInput(size=3))
model = Model()
model.BitwiseOr(params)
quantum_program = synthesize(model.get_model())

This example generates a quantum program that performs a bitwise 'or' between a quantum register and an integer. The left arg is an integer equal to three and the right arg is an unsigned quantum register with three qubits.

img_8.png