> ## Documentation Index
> Fetch the complete documentation index at: https://prod-mint.classiq.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Minimum and Maximum

<Card title="View on GitHub" icon="github" href="https://github.com/Classiq/classiq-library/blob/main/functions/function_usage_examples/arithmetic/extremum/extremum_example.ipynb">
  Open this notebook in GitHub to run it yourself
</Card>

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.

## Examples

#

### Example 1: Two Quantum Variables Minimum

This code example generates a quantum program that returns a minimum of two arguments.

Both the left and right arguments are defined as quantum variables of size three.

```python theme={null}
from classiq import *
from classiq.qmod.symbolic import min


@qfunc
def main(a: Output[QNum], b: Output[QNum], res: Output[QNum]) -> None:
    a |= 4
    allocate(3, b)
    hadamard_transform(b)

    res |= min(a, b)


qmod = create_model(main)
```

```python theme={null}

qprog = synthesize(qmod)

result = execute(qprog).result_value()
result.parsed_counts
```

<Info>
  **Output:**

  ```
  [{'a': 4.0, 'b': 1.0, 'res': 1.0}: 136,
     {'a': 4.0, 'b': 7.0, 'res': 4.0}: 129,
     {'a': 4.0, 'b': 6.0, 'res': 4.0}: 126,
     {'a': 4.0, 'b': 4.0, 'res': 4.0}: 125,
     {'a': 4.0, 'b': 2.0, 'res': 2.0}: 122,
     {'a': 4.0, 'b': 3.0, 'res': 3.0}: 122,
     {'a': 4.0, 'b': 5.0, 'res': 4.0}: 122,
     {'a': 4.0, 'b': 0.0, 'res': 0.0}: 118]
    

  ```
</Info>

#

### Example 2: Float and Quantum Variable Maximum

This code example returns a quantum program with a maximum of two arguments.
Here, the left arg is a fixed-point number $(11.1)_2$ (3.5),
and the right arg is a quantum variable of size three.

```python theme={null}
from classiq.qmod.symbolic import max


@qfunc
def main(a: Output[QNum], res: Output[QNum]) -> None:
    allocate(3, a)
    hadamard_transform(a)

    res |= max(3.5, a)


qmod = create_model(main)
```

```python theme={null}

qprog = synthesize(qmod)

result = execute(qprog).result_value()
result.parsed_counts
```

<Info>
  **Output:**

  ```
  [{'a': 5.0, 'res': 5.0}: 135,
     {'a': 0.0, 'res': 3.5}: 131,
     {'a': 3.0, 'res': 3.5}: 130,
     {'a': 6.0, 'res': 6.0}: 129,
     {'a': 2.0, 'res': 3.5}: 127,
     {'a': 7.0, 'res': 7.0}: 122,
     {'a': 1.0, 'res': 3.5}: 115,
     {'a': 4.0, 'res': 4.0}: 111]
    

  ```
</Info>
