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
    },
    "inplace": false
  }
}

Example 1: Two Register Minimum

{
        "constraints": {
          "max_width": 20,
          "max_depth": 300
        },
        "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

{
    "constraints": {
      "max_width": 20,
      "max_depth": 320
    },
    "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