From the principal window,
choose **File / Save as**
and save your fourth application under your tutorial folder
with the name `example4`.

In this section, we create a multiplication function
of a *N* elements vector by a scalar
by repeating *N* times a multiplication function on scalars.

In a new algorithm window:

- create a new sensor definition
named
`ins`with an integer output port`o`; - create a new function definition
named
`mul`with two integer input ports`a`and`b`and an integer ouput port`o`).

To create the vectors:

- to create the definition
`inv`:- from the algorithm window,
create a new sensor definition named
`inv`, - from the
`inv`definition window, type`N`in the**Parameters**textfield of its**Definition Properties**(it has*N*elements), - create its integer output port named
`o`with length`N`:`! int[N] o`;

- from the algorithm window,
create a new sensor definition named
- to create the definition
`outv`:- from the algorithm window,
create a new actuator definition
`outv`, - in
`outv`definition window, type`N`in the**Parameters**textfield of its**Definition Properties**(it has*N*elements), - create its integer input port named
`i`with length`N`:`? int[N] i`.

- from the algorithm window,
create a new actuator definition

To create the `AlgorithmMain1` algorithm:

- from the algorithm window,
create a new function definition named
`AlgorithmMain1`and from its definition window, define it as main; - in the
`AlgorithmMain1`definition mode:- create a reference
`s_input`to the scalar`ins`, - create a reference
`v_input<N>`to the vector`inv`, - create a reference
`mul`to the function`mul`and type`N`in the**Repeat**textfield of its**Reference Properties**(it is repeated*N*times), - create a reference
`v_output<N>`to the vector`outv`;

- create a reference
- create dependences between the references,
in order to obtain the main algorithm
(
*cf.*figure 4.2); - type
`N`in the**Parameters**textfield of the**Definition Properties**of the main algorithm and`3`in the**Values**textfield (*cf.*figure 4.1). Notice that this value is keeped as long as the algorithm remains the main one.

The repetition consists in multiplying
each of the *3* elements of the `v_input` vector
with the `s_input` scalar
and placing the result
in the *3* elements `v_output` vector.

The parameter `N` is here the repetition factor of the
`mul` function.

In this section, we create a multiplication function
of a vector by a scalar by using the `int` library.

From the principal window choose **File / Specify Library Directories**
and add the `SYNDEXPATH/libs` where `SYNDEXPATH`
is the absolute path of the SynDEx distribution.

From the principal window,
choose **File / Included Libraries / int**
(*cf.* figure 4.3).

Notice that this library
contains `input`, `mul`,
and `output` definitions
parameterized with `length`.

We will need to set it to `1`
for the scalar and the multiplication function,
and to `N` for the vectors:

- from the algorithm window,
create the function definition
`AlgorithmMain2`and define it as main; - in
`AlgorithmMain2`definition mode:- drag and drop the sensor definition
**int/input**from the**Definition list**to the`AlgorithmMain2`window → dialog window:`s_input<1>`(*cf.*figure 4.4) (it is a scalar), - drag and drop the sensor definition
**int/input**→ dialog window:`v_input<N>`(it has*N*elements), - drag and drop the function definition
**int/Arit_mul**→ dialog window:`mul<1>`then type`N`in the**Repeat**textfield of its**Reference Properties**, (it is a multiplication on scalars, repeated*N*times), - drag and drop the actuator definition
**int/output**→ dialog window:`v_output<N>`(it has*N*elements);

- drag and drop the sensor definition
- create dependences between the references
in order to obtain the main algorithm
(
*cf.*figure 4.5); - type
`N`in the**Parameters**textfield of the**Definition Properties**, and`3`in the**Values**textfield.

Notice the difference of the `mul` reference
when it is seen
from the `AlgorithmMain2` definition mode
or from the main mode (**Main** button).

In this section, we create a multiplication function
of a *N*M* matrix
by a *M* elements vector
by repeating *N* times a multiplication function on vectors.

Include the library `float`
(**File / Included Libraries / Float**).

This function is a multiplication function on scalars with an accumulator:

- create a new function definition named
`dpacc`; - create a reference
`mul<1>`to the function**float/Arit_mul**(the reference works on scalars); - create a reference
`add<1>`to the function**float/Arit_add**(the reference works on scalars); - add it three input ports and one output port:
`? float s1 ? float s2 ? float acc ! float acc`; - then create dependences to obtain an algorithm
(
*cf.*figure 4.6).

Notice that `acc`
is an input port and an output port of the function.
It will be used as an accumulator to store the partial sum.

This function is a multiplication function on vectors with an accumulator:

- create a new function definition named
`dp`; - add it a parameter
`dpaccn`; - create a reference
`zero<{0}>`to the constant**float/cst**(it is the`{0}`scalar); - create a reference
`dpacc`to the function`dpacc`then type`dpaccn`in the**Repeat**textfield of its**Reference Properties**(it is repeated`dpaccn`times); - add it two input ports:
`? float[dpaccn] v1 ? float[dpaccn] v2`and one output port:`! float dp`(vectors have`dpaccn`elements); - create dependences to obtain an algorithm
(
*cf.*figure 4.7). To build the dependence between the output port`acc`of`dpacc`and its input port`acc`, choose**Iterate**on the dialog window (it is the connection between two successive calls of the function).

The repetition consists in multiplying
two *dpaccn* elements vectors
by calling *dpaccn* times
the `dpacc` multiplication function
on scalars with accumulator.
The initial value of its accumulator
is given by the `zero` constant
and the following are given by the accumulator itself.

This function is a multiplication function of a matrix by a vector:

- create a new function definition named
`prodmatvec`; - type
`a;b`in the**Parameters**textfield of its**Definition Properties**; - create a reference
`dotprod<b>`to the function`dp`(input vectors have`b`elements) and type`a`in the**Repeat**textfield of its**Reference Properties**(it is repeated`a`times); - add it two input ports:
`? float[a*b] inm ? float[b] inv`and one output port:`! float[a] outv`; - then create dependences to obtain an algorithm
(
*cf.*figure 4.8).

The repetition consists in multiplying
a *a*b* matrix by a *b* elements vector
by calling *a* times
the `dp` multiplication function on vectors.

To create the `AlgorithmMain3` algorithm:

- create the definition of the sensor
`inm`, with two parameters names`N`and`M`, and with an output port:`! float [N*M] o`; - create a new function definition named
`AlgorithmMain3`and define it as main; - add it two parameters:
`N;M`with values`3;4`; - create a reference
`m1<N;M>`to the matrix**inm**; - create a reference
`inv<N>`to the vector**float/input**; - create a reference
`matprodvec<N;M>`to the function**prodmatvec**; - create a reference
`outv<M>`to the vector**float/output**; - then create dependences to obtain an algorithm
(
*cf.*figure 4.9).

From the principal window,
choose **File / Close**.
In the dialog window, click on the **Save** button.