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 .

## Syntax¶

Parameters:

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


### Example 1: Two Register Addition¶

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

#### Generated Circuit¶ ### Example 2: Float and Register Addition¶

{
"constraints": {
"max_width": 5,
"max_depth": 100
},
"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. 