# Execute ARITHMETIC FUNCTION With Initial Conditions¶

Arithmetic functions can also be executed by initializing the function registers. This enables the loading of numbers (only integers) into each register of the arithmetic function (for example adder), and this initial condition will be considered as part of the circuit in the execution process.

from classiq import Model, RegisterUserInput
from classiq import Executor
from classiq.execution import IBMBackendPreferences

# Define a circuit that generates a circuit that includes addition operations

left_arg=RegisterUserInput(size=3),
right_arg=RegisterUserInput(size=3),
output_name="sum",
)
model = Model()
circuit = model.synthesize()

# Execute the circuit and initialize the registers
# as a dictionary(initial_values in the example), note that the registers'
# names are the dictionary keys and the initial values are its values.

initial_values = dict(left_arg=6, right_arg=4)
result = Executor(
num_shots=10,
backend_preferences=IBMBackendPreferences(backend_name="aer_simulator"),
).execute(circuit, initial_values=initial_values)


## EXECUTE ARITHMETIC EXPRESSIONS¶

One can also execute any arithmetic expression with initial condition using the same way showed above. For example, a circuit that calculates arithmetical expression with initial conditions:

from classiq import Model, RegisterUserInput
from classiq.builtin_functions import Arithmetic
from classiq import Executor
from classiq.execution import IBMBackendPreferences

params = Arithmetic(
expression="(a + b -5) == c",
definitions=dict(
a=RegisterUserInput(size=3),
b=RegisterUserInput(size=3),
c=RegisterUserInput(size=3),
),
uncomputation_method="optimized",
qubit_count=25,
output_name="expression_result",
)

model = Model()
model.Arithmetic(params)
circuit = model.synthesize()

initial_values = dict(a=7, b=1, c=3)
result = Executor(
num_shots=10,
backend_preferences=IBMBackendPreferences(backend_name="aer_simulator"),
).execute(circuit, initial_values=initial_values)

Note

You must send a real positive number as an initial condition to get meaningful results. In addition, the 'RegisterUserInput' must have a default definition: - is_signed = False, - fraction_places = 0. Moreover, all the initialized registers should be input registers.