# Grover Operator¶

The grover operator is a unitary used in amplitude estimation and amplitude amplification algorithms.

The grover operator can be given as:

$Q = Q(A,\chi) = AS_0A^{-1}S_\chi$

where $$A$$ is state preparation operator,

$A\ket{0}= \ket{\psi}$

$$S_x$$ marks good states, and $$S_0$$, called diffuser, flips around the zero state,

$S_0 = I - 2\ket{0}\bra{0}$

By default, the state preparation used is the uniform superposition by applying hadamard on all inputs.

$A = H^{\bigotimes n}$

## Syntax¶

Function: GroverOperator

Parameters:

{
"function": "GroverOperator",
"function_params": {
"oracle": {
"expression": "(a + b + (c & 6)) % 4 | 4 & c  == 4",
"definitions": {
"a": {
"size": 2
},
"b": {
"size": 2
},
"c": {
"size": 3
}
},
"uncomputation_method": "optimized",
"qubit_count": 16
},
"state_preparation": null
}
}


### Example 1:¶

{
"constraints": {
"max_width": 16,
"max_depth": 415
},
"logic_flow": [
{
"function": "GroverOperator",
"function_params": {
"oracle": {
"expression": "(a + b + (c & 6)) % 4 | 4 & c  == 4",
"definitions": {
"a": {
"size": 2
},
"b": {
"size": 2
},
"c": {
"size": 3
}
},
"uncomputation_method": "optimized",
"qubit_count": 16
},
"state_preparation": null
}
}
]
}

from classiq import ModelDesigner
from classiq.builtin_functions import ArithmeticOracle, GroverOperator
from classiq.interface.generator.arith.arithmetic import RegisterUserInput

oracle_params = ArithmeticOracle(
expression="(a + b + (c & 6)) % 4 | 4 & c  == 4",
definitions=dict(
a=RegisterUserInput(size=2),
b=RegisterUserInput(size=2),
c=RegisterUserInput(size=3),
),
uncomputation_method="optimized",
qubit_count=16,
)
grover_params = GroverOperator(oracle=oracle_params)

model_designer = ModelDesigner()
model_designer.GroverOperator(grover_params)

circuit = model_designer.synthesize()


This examples generate a grover operator for the oracle $$\verb!a & (b | c) ^ a == 2!$$. The first part it the arithmetic oracle, the second is the state preparation, the third is the diffuser and lastly the state preparation again. An explanation of execution of a Grover Operator can be found in the Amplitude Amplification section.

G. Brassard, P. Hoyer, M. Mosca, and A. Tapp, “Quantum Amplitude Amplification and Estimation,” arXiv:quant-ph/0005055, vol. 305, pp. 53–74, 2002, doi: 10.1090/conm/305/05215.