$$|d\rangle |0\rangle \rightarrow \sqrt{1-\tilde{f}(d)}|d\rangle |0\rangle + \sqrt{\tilde{f}(d)}|d\rangle |1\rangle$$

for any input, $$|d\rangle$$, piecewise linear function $$f(d)$$. Where $$\tilde{f}$$ is a normalized and rescaled function of the given $$f(d)$$:

$$\tilde{f}(d) = 2c \cdot \frac{f(\phi(d)) - f_{min}}{f_{max} - f_{min}} - c + 0.5$$

when:

$$\phi(d) = x_{min} + \frac{x_{max} - x_{min}}{2^{n} - 1}d$$

$$c$$ is the given rescaling factor. $$f_{min}$$, $$f_{max}$$ are the minimal and maximal values of the function in the given domain, and $$x_{min}$$, $$x_{max}$$ are the boundaries of the domain.

The linear functions and the transitions between them are defined by the affine_maps and breakpoints fields, respectively, which are expected to be ordered. Each linear function is defined by an AffineMap object, that has two attributes - offset and slope. For example, AffineMap(offset=a, slope=b) represents f(x) = a + bx. The function is approximated using piecewise linear rotation amplitude loading, and expected to work for small enough rescaling factors, such that Taylor approximations work in leading order.

The function is intended to serve as a basis for computations of the expectation value of $$f(x)$$, where the probability is set by the initial distribution of $$d$$ as in . The function is automatically scaled to be approximated by piecewise linear rotation amplitude loading. To do the inverse transformation, use the "compute_expectation_value" method of PiecewiseLinearAmplitudeLoading params, as in the SDK example below.

## Syntax¶

Function: PiecewiseLinearAmplitudeLoading

Parameters:

• num_qubits: PositiveInt
• breakpoints: List[float]
• affine_maps: List[AffineMap]
• rescaling_factor: float

## Example 1 - generation¶

{
"functions": [
{
"name": "main",
"body": [
{
"function_params": {
"num_qubits": 3,
"breakpoints": [0.5, 3.14, 5.0],
"affine_maps": [
{"offset": 0, "slope": 0},
{"offset": -3.14, "slope": 1.6}
],
"rescaling_factor": 0.001
}
}
]
}
]
}

from classiq.builtin_functions import PiecewiseLinearAmplitudeLoading
from classiq import Model, synthesize

model = Model()
num_qubits=3,
breakpoints=[0.5, 3.14, 5.0],
affine_maps=[{"offset": 0, "slope": 0}, {"offset": -3.14, "slope": 1.6}],
rescaling_factor=0.001,
)
qprog = synthesize(model.get_model())


## Example 2 - computing the expectation value¶

from classiq.builtin_functions import PiecewiseLinearAmplitudeLoading