Procedure is a new concept introduced in HH6. Although similar to sub-patches, procedures offers many advantages.
Let start with a simple example, we want to calculate the sum of nth integers: 1+2+3+...+N = ?
.
We call this procedure ACCUM.
Add a procedure module in the patch and set its name to ACCUM
.
[dbl-click] on the procedure module to edit it and add
and connect them as follow:
The procedure-loop-counter will generate a series of integer 0,1,2,3,...
. The data-accumulation will accumulate incoming numbers from the procedure-loop-counter.
As you can notice, there is a small number on top of the wires. They represent the order of inlets processing.
Generally, in Usine, we dont care about the order of inlet processing but in procedures this order is important. In this example we will execute the procedure N times but we have to reset the data-accumulation only at the beginning. So we have to be sure that reset inlet is marked as processing order 1. If its not the case, we must delete/recreate the wire.
We are now ready to use the procedure. For that just add a procedure-call and set its name to ACCUM
.
And finally complete the patch as follows:
Few remarks:
In this second example we will create a procedure to generate a Fibonacci value F(N). see https://en.wikipedia.org/wiki/Fibonacci_sequence
F(0)=0
F(1)=1
F(2)=1
...
F(n)=F(n-1)+F(n-2)
It's more complex than the first example because it's an iteration where we have to memorize the two previous values.
Few remarks:
1;0
value The call of the procedure looks like:
If we want to obtain all the suite (1;2;3;5;8;13;21;34;55
) we have to adapt the procedure a little :
Few remarks:
And the call procedure as follow:
A procedure can loop on each element of an array.
For example if we want to create an array 1²,2²,3²,4²,...
.
Of course we could do that with 'normal' math modules but let's try with a procedure, but we remind you that the main advantage of procedures is the fact that they're calculated only on demand.
The procedure is very simple:
But on the array-out we can activate the loop-on-each-element. This option tells Usine that the output module will adapt its size to the loop-count and store each result into a separated element of the array.
the size of the array-out will be set to the loop count.
The procedure call looks like:
We can also loop on each element of an input array. For example if we want to calculate the square of of each element of an array.
Another example of procedure utilization in real life: the beta distribution. The following procedure calculate an array of beta distribution coefficients. see https://en.wikipedia.org/wiki/Beta_distribution
The procedure looks like:
The procedure call looks like:
version 6.0.241021
Edit All Pages