Skip to content

Arithmetic Oracle

The arithmetic oracle function takes an arithmetic expression and implements it as a Grover oracle. Any arithmetic expression that outputs a Boolean—i.e., the result is '1' if the expression is true and '0' if false— can be used by initializing the resulting qubit with the \(|->\) state[1]. An example is an expression that uses a logical comparator ('==','<','>', etc.) and binary connectives (and, or, etc.). The oracle can later be incorporated into a Grover operator.

Syntax

Function: ArithmeticOracle

Parameters:

  • expression: str
  • definitions: Dict[str, Union[int, float, RegisterUserInput] (see RegisterUserInput)
  • uncomputation_method: ['naive', 'optimized']
  • qubit_count: Optional[PositiveInt]
  • machine_precision: Optional[PositiveInt]
{
  "function": "ArithmeticOracle",
  "function_params": {
    "expression": "(a + b) == 3 and c ^ a == 2",
    "definitions": {
      "a": {
        "size": 2
      },
      "b": {
        "size": 1
      },
      "c": {
        "size": 3
      }
    },
    "uncomputation_method": "optimized"
  }
}

Register Names

The names of the input and output registers are determined by the definitions field. Each defined variable has a corresponding input and output register with the same name.

Example 1

{
  "functions": [
    {
      "name": "main",
      "body": [
          {
              "function": "ArithmeticOracle",
              "function_params": {
                  "expression": "(a + b) == 3 and c ^ a == 2",
                  "definitions": {
                      "a": {
                          "size": 2
                      },
                      "b": {
                          "size": 1
                      },
                      "c": {
                          "size": 3
                      }
                  },
                  "uncomputation_method": "optimized"
              }
          }
      ]
    }
  ]
}
from classiq import Model, RegisterUserInput, synthesize
from classiq.builtin_functions import ArithmeticOracle

params = ArithmeticOracle(
    expression="(a + b) == 3 and c ^ a == 2",
    definitions=dict(
        a=RegisterUserInput(size=2),
        b=RegisterUserInput(size=1),
        c=RegisterUserInput(size=3),
    ),
    uncomputation_method="optimized",
)
model = Model()
model.ArithmeticOracle(params)
quantum_program = synthesize(model.get_model())

This example marks all states that make the expression \(\verb!(a + b) == 3 and c ^ a == 2!\) true. The \(q_0\) qubit is initialized with the \(|->\) state.

img_4.png

References

[1] Nielsen, M., & Chuang, I. (2010). Quantum Computation and Quantum Information: 10th Anniversary Edition. Cambridge: Cambridge University Press. doi:10.1017/CBO9780511976667, p. 249.