Skip to content

Multiplication

The "Multiplication" operation, denoted '\(*\)', can be seen as a series of addition ("long multiplication"). Therefore, there are different implementations to the multiplier depending on the of adder being used.

Note that integer and fixed-point numbers are represented in a 2-complement method during function evaluation. The binary number is extended in the case of a register size miss-match. For example, the positive signed number \((110)_2=6\) is expressed as \((00110)_2\) when operating with a 5-qubit register. Similarly, the negative signed number \((110)_2=-2\) is expressed as \((11110)_2\).

Examples

The calculation of -5 * 3 = -15 is done in the following manner:

The left arg -5 is represented as 1011 and 3 as 11. The number of digits needed to store the answer would be 4+2-1 = 5. The multiplication is done in the 'regular' way where each number is extended to 5 bits and only 5 digit are kept in the intermediary results:

\[ \begin{equation*}\begin{array}{c} \phantom{\times}11011\\ \underline{\times\phantom{000}11}\\ \phantom{\times}11011\\ \underline{\phantom\times1011\phantom9}\\ \phantom\times10001 \end{array}\end{equation*} \]

Syntax

Function: Multiplier

Parameters:

{
  "function": "Multiplier",
  "function_params": {
    "left_arg": 3,
    "right_arg": {
      "size": 3
    },
    "inplace": false
  }
}

Example 1: Two Register Multiplication

{
        "constraints": {
          "max_width": 20,
          "max_depth": 300
        },
        "logic_flow": [
            {
                "function": "Multiplier",
                "function_params": {
                    "left_arg": {"size": 3},
                    "right_arg": {"size": 3}
                }
            }
        ]
    }
from classiq import ModelDesigner, QUInt
from classiq.builtin_functions import Multiplier

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

This code example generates a circuit that multiplies 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 Multiplication

{
    "constraints": {
      "max_width": 20,
      "max_depth": 300
    },
    "logic_flow": [
        {
            "function": "Multiplier",
            "function_params": {
                "left_arg": 3.5,
                "right_arg": {
                    "size": 3
                }
            }
        }
    ]
}
from classiq import ModelDesigner
from classiq.builtin_functions import Multiplier
from classiq.interface.generator.arith.arithmetic import RegisterUserInput

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

This code example generates a circuit that multiplies 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