Minimum and Maximum¶
The minimum and maximum operators determine the smallest and largest input, respectively. Both functions receive two inputs, each one may be fixed point number or quantum register.
Syntax¶
Function: Min/Max
Parameters:
- left_arg: Union[float, int, FixPointNumber, RegisterUserInput]
- right_arg: Union[float, int, FixPointNumber, RegisterUserInput]
- output_size: Optional[PositiveInt]
- output_name: Optional[str]
{
"function": "Min",
"function_params": {
"left_arg": { "size": 2, "name": "left" },
"right_arg": { "size": 3, "name": "right" }
}
}
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 max_value
or min_value
, but its name may be overridden by the output_name
argument.
In addition, since the computation is done out-of-place, input registers are also
available as output registers, with the same names.
Example 1: Two Register Minimum¶
{
"logic_flow": [
{
"function": "Min",
"function_params": {
"left_arg": {"size": 3, "name": "left"},
"right_arg": {"size": 3, "name": "right"}
}
}
]
}
from classiq import Model, QUInt
from classiq.builtin_functions import Min
params = Min(
left_arg=QUInt(size=3).to_register_user_input(name="left"),
right_arg=QUInt(size=3).to_register_user_input(name="right"),
)
model = Model()
model.Min(params)
circuit = model.synthesize()
circuit.show_interactive()
This code example generates a circuit that returns the minimum of 2 arguments. Both "left_arg" and "right_arg" are defined to be quantum registers of size 3.
Generated Circuit¶
Example 2: Float and Register Minimum¶
{
"logic_flow": [
{
"function": "Min",
"function_params": {
"left_arg": 3.5,
"right_arg": {"size": 3, "name": "arg"}
}
}
]
}
from classiq import Model, RegisterUserInput
from classiq.builtin_functions import Min
params = Min(left_arg=3.5, right_arg=RegisterUserInput(size=3, name="arg"))
model = Model()
model.Min(params)
circuit = model.synthesize()
circuit.show_interactive()
This code example returns a circuit that returns the minimum of 2 arguments. Here "left_arg" is a fixed-point number \((11.1)_2\) and "right_arg" a quantum register of size 3.