Skip to content

Minimum and Maximum

The minimum and maximum operators determine the smallest and largest input, respectively. Both functions receive two inputs. Each may be a fixed point number or a quantum register.

Syntax

Function: Min/Max

Parameters:

  • left_arg: Union[float, int, RegisterUserInput] (see RegisterUserInput)
  • right_arg: Union[float, int, RegisterUserInput] (see RegisterUserInput)
  • output_size: Optional[PositiveInt]

Register names:

  • left_arg: left_arg
  • right_arg: right_arg
  • result: min_value/max_value
{
  "function": "Min",
  "function_params": {
    "left_arg": { "size": 2, "name": "left" },
    "right_arg": { "size": 3, "name": "right" }
  }
}

Example 1: Two-Register Minimum

{
  "functions": [
    {
      "name": "main",
      "body": [
          {
              "function": "Min",
              "function_params": {
                  "left_arg": {"size": 3, "name": "left"},
                  "right_arg": {"size": 3, "name": "right"}
              }
          }
      ]
    }
  ]
}
from classiq import Model, QUInt, synthesize, show
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)
quantum_program = synthesize(model.get_model())
show(quantum_program)

This code example generates a circuit that returns a minimum of two arguments. Both left_arg and right_arg are defined as quantum registers of size three.

Generated Circuit

img.png

Example 2: Float and Register Minimum

{
  "functions": [
    {
      "name": "main",
      "body": [
          {
              "function": "Min",
              "function_params": {
                  "left_arg": 3.5,
                  "right_arg": {"size": 3, "name": "arg"}
              }
          }
      ]
    }
  ]
}
from classiq import Model, RegisterUserInput, synthesize, show
from classiq.builtin_functions import Min

params = Min(left_arg=3.5, right_arg=RegisterUserInput(size=3, name="arg"))
model = Model()
model.Min(params)
quantum_program = synthesize(model.get_model())
show(quantum_program)

This code example returns a circuit with a minimum of two arguments. Here, left_arg is a fixed-point number \((11.1)_2\) and "right_arg" is a quantum register of size three.

Generated Circuit

img.png