# Arithmetic oracle¶

A grover oracle is a black-box which sets a minus phase to specific states.

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 result qubit with the $$\ket{-}$$ state[1]. An example for such expression is an expression that uses 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, FixPointNumber, RegisterUserInput]
• uncomputation_method: ['naive', 'optimized']
• qubit_count: Optional[PositiveInt]
• simplify: bool
• max_fraction_places: 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:¶

{
"logic_flow": [
{
"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 ModelDesigner
from classiq.builtin_functions import ArithmeticOracle
from classiq.interface.generator.arith.arithmetic import RegisterUserInput

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_designer = ModelDesigner()
model_designer.ArithmeticOracle(params)
circuit = model_designer.synthesize()


This examples marks all states which make the expression $$\verb!(a + b) == 3 and c ^ a == 2!$$ true. The qubit $$q_0$$ is initialized with $$\ket{-}$$ state.

The Classiq executor allows you to find a solution to the oracle using Grover's algorithm. An explanation of execution of a Grover Operator can be found in the Amplitude Amplification section.

## References¶

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