# 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
}
}
}


### 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 product, 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 Multiplication¶

{
"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_interactive()


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.

### Example 2: Float and Register Multiplication¶

{
"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_interactive()


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.