The "Addition" operation, denoted '+', is implemented according to the following truth table. Here $$a$$ and $$b$$ denote numbers, $$i$$ bit index, and $$c_{in / out}$$ the incoming and outgoing carries of that step, respectively.

$$a_i$$ $$b_i$$ $$c_{in}$$ $${(a + b)}_i$$ $$c_{out}$$
0 0 0 0 0
0 1 0 1 0
1 0 0 1 0
1 1 0 0 1
0 0 1 1 0
0 1 1 0 1
1 0 1 0 1
1 1 1 1 1

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¶

• 5 + 3 = 8 , 0101 + 0011 = 1000
• 5 + -3 = 2, 0101 + 1101 = 0010
• -5 + -3 = -8, 1011 + 1101 = 1000

Several adder algorithms, differing in depth, number of gates used, and number of auxiliaries, are implemented [1][2].

## Syntax¶

Parameters:

{
"function_params": {
"left_arg": 3,
"right_arg": {
"size": 3
},
"inplace_arg": null
}
}


### 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 sum, but its name may be overridden by the output_name argument. The inplace_arg argument sets the argument to override. If it is set to None, the input registers are also available as output registers, with the same names. If it is set to left or right, only the right or left argument will be available, respectively. The qubits of the overriden argument will be used for the result.

### Example 1: Two Register Addition¶

{
"logic_flow": [
{
"function_params": {
"left_arg": {"size": 3},
"right_arg": {"size": 3}
}
}
]
}

from classiq import ModelDesigner
from classiq.interface.generator.arith.arithmetic import RegisterUserInput

model_designer = ModelDesigner()
circuit = model_designer.synthesize()


This code example generates a circuit that adds 2 arguments. Both "left_arg" and "right_arg" are defined to be quantum registers of size 3.

### Example 2: Float and Register Addition¶

{
"logic_flow": [
{
"function_params": {
"left_arg": 3.5,
"right_arg": {
"size": 3
}
}
}
]
}

from classiq import ModelDesigner
from classiq.interface.generator.arith.arithmetic import RegisterUserInput

model_designer = ModelDesigner()

This code example generates a circuit that adds 2 arguments. Here "left_arg" is a fixed-point number $$(11.1)_2$$ and "right_arg" a quantum register of size 3.