### 3.7.109. Glue matrix

A reversible constraint for which the catalogue provides an automaton with counters and a glue matrix. A glue matrix is indexed by the states of the automaton associated with the considered constraint as well as by the states of the automaton associated with the reverse of the considered constraint. In the following we assume that the signature constraint involves $a$ consecutive variables of the sequence of variables of the reversible constraint (the signature constraint encodes the mapping of the sequence of variables of the constraint to symbols of the alphabet of the automaton). We consider a sequence of variables and a prefix and suffix of this sequence such that the prefix and suffix have $a-1$ variables in common. Let $\stackrel{\to }{q}$ (resp. $\stackrel{←}{q}$) be the state of the automaton associated with the constraint (resp. the reverse constraint) upon reading the prefix (resp. the reverse of the suffix). The entry of the glue matrix corresponding to the state pair $\left(\stackrel{\to }{q},\stackrel{←}{q}\right)$ provides a function for computing the result associated with the sequence from the counters values associated with the prefix and the reverse suffix.

As an example consider the $\mathrm{𝚙𝚎𝚊𝚔}$$\left(𝙽,\mathrm{𝚅𝙰𝚁𝙸𝙰𝙱𝙻𝙴𝚂}\right)$, which holds if $𝙽$ is equal to the number of peaks of the sequence of variables $\mathrm{𝚅𝙰𝚁𝙸𝙰𝙱𝙻𝙴𝚂}$. A peak corresponds to an increase between consecutive variables followed by a decrease between consecutive variables. Figure 3.7.32 gives the corresponding automaton that returns the number of peak of a sequence where, to each pair of consecutive variables $\left({\mathrm{𝚅𝙰𝚁}}_{i},{\mathrm{𝚅𝙰𝚁}}_{i+1}\right)$ corresponds a signature variable ${S}_{i}$ passed to the automaton. The following signature constraint links ${\mathrm{𝚅𝙰𝚁}}_{i}$, ${\mathrm{𝚅𝙰𝚁}}_{i+1}$ and ${S}_{i}$: $\left({\mathrm{𝚅𝙰𝚁}}_{i}<{\mathrm{𝚅𝙰𝚁}}_{i+1}⇔{S}_{i}=0\right)\wedge \left({\mathrm{𝚅𝙰𝚁}}_{i}={\mathrm{𝚅𝙰𝚁}}_{i+1}⇔{S}_{i}=1\right)\wedge \left({\mathrm{𝚅𝙰𝚁}}_{i}>{\mathrm{𝚅𝙰𝚁}}_{i+1}⇔{S}_{i}=2\right)$.

##### Figure 3.7.32. Automaton of the $\mathrm{𝚙𝚎𝚊𝚔}$ constraint and its glue matrix Figure 3.7.33 illustrates the use of the glue matrix of the $\mathrm{𝚙𝚎𝚊𝚔}$ constraint on the sequence $1,1,4,8,6,2,7,1$ decomposed in a prefix $1,1,4,8$ and a suffix $8,6,2,7,1$ that overlap by one position, one position since the arity of the signature constraint is equal to two. Since the automaton of the $\mathrm{𝚙𝚎𝚊𝚔}$ constraint ends up in state $u$ when applied to the prefix and to the reverse suffix we use the lower rightmost entry of the glue matrix to link the total number of peaks of the sequence $1,1,4,8,6,2,7,1$ with the number of peaks of the prefix $1,1,4,8$ and the suffix $8,6,2,7,1$.

##### Figure 3.7.33. Illustrating the use of the state pair $\left(u,u\right)$ of the glue matrix for linking $𝙽$ with the counters variables obtained after reading the prefix $1,1,4,8$ and corresponding suffix $8,6,2,7,1$ of the sequence $1,1,4,8,6,2,7,1$; note that the suffix $8,6,2,7,1$ (in pink) is proceed in reverse order; the left (resp. right) table shows the initialisation (for $i=0$) and the evolution (for $i>0$) of the state of the automaton and of its counter $C$ upon reading the prefix $1,1,4,8$ (resp. the suffix $1,7,2,6,8$). 