Skip to content

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:

{
  "function": "Min",
  "function_params": {
    "left_arg": {
      "size": 2
    },
    "right_arg": {
      "size": 3
    }
  }
}

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},
                    "right_arg": {"size": 3}
                }
            }
        ]
    }
from classiq import ModelDesigner, QUInt
from classiq.builtin_functions import Min

params = Min(
    left_arg=QUInt(size=3).to_register_user_input(),
    right_arg=QUInt(size=3).to_register_user_input(),
)
model_designer = ModelDesigner()
model_designer.Min(params)
circuit = model_designer.synthesize()
circuit.show()

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

img.png

Example 2: Float and Register Minimum

{
    "logic_flow": [
        {
            "function": "Min",
            "function_params": {
                "left_arg": 3.5,
                "right_arg": {
                    "size": 3
                }
            }
        }
    ]
}
from classiq import ModelDesigner
from classiq.builtin_functions import Min
from classiq.interface.generator.arith.arithmetic import RegisterUserInput

params = Min(left_arg=3.5, right_arg=RegisterUserInput(size=3))
model_designer = ModelDesigner()
model_designer.Min(params)
circuit = model_designer.synthesize()
circuit.show()

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.

Generated Circuit

img.png