Shifted interaction functions, explained

The paper (Xu, Morella Violeta, García de Marina), written out step by step for its own four agents: what a shifted actuator or sensor does to consensus, which motion the team ends up in, and the program each agent runs at every tick

Published

November 14, 2026

From the Swarm Systems Lab, University of Granada. To try the results by hand, open the playground.

What this page does. It takes the paper Shifted Interaction Functions: A Unified Framework for Imperfect Actuation and Sensing in Consensus Networks (its LaTeX source, main.tex) and writes it out for the paper’s own example: four agents on the graph of its Fig. 1, and the three agents of its Fig. 5. It goes step by step: two measurement channels per edge (Section 2 of the paper), the shift functions that model imperfect actuators and sensors (Section 4), the one velocity a team with shifted actuators can share (Lemma 2 and Theorem 1), when that motion is a static consensus (Corollaries 1 and 2), what shifted sensors do instead (Theorems 2 and 3, Proposition 4), and the linear case, where everything has a closed form (Proposition 3). It ends with the program each agent runs at every tick, and with the paper’s simulations run again.

Source and status. The results are the paper’s, and this page does not re-prove them. It adds three things, each marked where it appears: the closed-form velocities of the two clusters of Fig. 5 (Section 5.2.1), a measurement of how conservative the rate of Theorem 3 is on the paper’s example (Section 5.3.1), and a re-run of every simulation of the paper with its parameters, recovered from the code that drew the figures, which finds one small mismatch in the text (Section 7). Every number on the page is computed by core.py when the page is rendered. The interactive figures run assets/core.js, and make check proves that the two agree.

1 The problem

NN agents (robots, drones, satellites) each have one number to agree on, xi∈ℝx_i \in \mathbb{R}: a position along a road, a heading, a phase on a path. Each agent is a single integrator,

ẋi=ui,i=1,…,N. \dot x_i = u_i, \qquad i = 1, \dots, N .

Sensing. Agent ii measures, for each neighbour jj, the relative state zij=xi−xjz_{ij} = x_i - x_j. Nobody measures an absolute state, and nothing is shared beyond these measurements.

The ideal law. The standard consensus protocol sums the measurements, ui=−∑j∈𝒩i(xi−xj)u_i = -\sum_{j \in \mathcal{N}_i} (x_i - x_j). On a connected undirected graph, every agent then converges to the average of the initial states, and stops there: a static consensus.

The imperfections. Real hardware does not compute that sum. A sensor reads ψij(zij)\psi_{ij}(z_{ij}) instead of zijz_{ij}: with a bias, a gain error, a saturation, a dead zone. An actuator delivers Fi(ui)F_i(u_i) instead of uiu_i: a fixed-wing aircraft cannot fly backwards or below its stall speed, a thruster may only push, a motor may be jammed in part of its range. The paper writes the closed loop as

ẋi=Fi(ui),ui=−∑j∈𝒩iψij(xi−xj), \dot x_i = F_i(u_i), \qquad u_i = -\sum_{j \in \mathcal{N}_i} \psi_{ij}(x_i - x_j),

with every FiF_i and ψij\psi_{ij} a shift function: a monotone map that need not pass through the origin.

The question. Not whether the team reaches consensus, since with imperfections it usually does not, but what it does instead. The paper finds three outcomes: a static consensus (rare), a common drift velocity with fixed offsets between the agents (generic for actuators), and groups of agents that each share a velocity and drift apart (possible with sensors).

Why it is hard. The maps are unknown, different for every agent, and nonlinear. The two agents at the ends of an edge process the same physical distance with different maps, so the interaction is no longer symmetric: the graph is undirected, but the dynamics on it are not.

2 Step 1: two measurement channels on every edge

2.1 The graph of the example

The paper’s example has four agents and five edges, {1,2}\{1,2\}, {1,3}\{1,3\}, {1,4}\{1,4\}, {2,3}\{2,3\}, {3,4}\{3,4\} (its Fig. 1). Each edge ℓ={i,j}\ell = \{i,j\} carries two measurements: zij=xi−xjz_{ij} = x_i - x_j, taken by ii, and zji=xj−xiz_{ji} = x_j - x_i, taken by jj. The paper picks one orientation of each edge as positive, ℓi=(i,j)\ell^{\mathrm i} = (i,j), and calls the other negative, ℓo=(j,i)\ell^{\mathrm o} = (j,i). Here the positive one goes from the smaller index to the larger.

The incidence matrix BB has +1+1 at the initial node and −1-1 at the terminal node of each positive edge. It splits as B=Bo+BiB = B^{\mathrm o} + B^{\mathrm i}: the out-incidence BoB^{\mathrm o} keeps the +1+1 entries, the in-incidence BiB^{\mathrm i} the −1-1 entries.

B=(11100−100100−10−1100−10−1),Bo=(11100000100000100000),Bi=(00000−100000−10−1000−10−1). B = \begin{pmatrix}1 & 1 & 1 & 0 & 0 \\ -1 & 0 & 0 & 1 & 0 \\ 0 & -1 & 0 & -1 & 1 \\ 0 & 0 & -1 & 0 & -1\end{pmatrix},\qquad B^{\mathrm o} = \begin{pmatrix}1 & 1 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 1 \\ 0 & 0 & 0 & 0 & 0\end{pmatrix},\qquad B^{\mathrm i} = \begin{pmatrix}0 & 0 & 0 & 0 & 0 \\ -1 & 0 & 0 & 0 & 0 \\ 0 & -1 & 0 & -1 & 0 \\ 0 & 0 & -1 & 0 & -1\end{pmatrix}.

The columns are the edges in the order above, the rows the agents. The measurement along ℓi\ell^{\mathrm i} is taken by the initial node and enters the input through BoB^{\mathrm o}; the one along ℓo\ell^{\mathrm o} enters through BiB^{\mathrm i}. Stacking the processed measurements of each orientation into z̃i\tilde z^{\mathrm i} and z̃o\tilde z^{\mathrm o}, the input of every agent is (eq. (9) of the paper)

u=−Boz̃i+Biz̃o. u = -B^{\mathrm o}\,\tilde z^{\mathrm i} + B^{\mathrm i}\,\tilde z^{\mathrm o}.

With perfect sensors, z̃i=B⊤x\tilde z^{\mathrm i} = B^\top x and z̃o=−B⊤x\tilde z^{\mathrm o} = -B^\top x, and u=−(Bo+Bi)B⊤x=−Lxu = -(B^{\mathrm o} + B^{\mathrm i}) B^\top x = -Lx with the Laplacian

L=BB⊤=(3−1−1−1−12−10−1−13−1−10−12),eigenvalues 0,2,4,4. L = BB^\top = \begin{pmatrix}3 & -1 & -1 & -1 \\ -1 & 2 & -1 & 0 \\ -1 & -1 & 3 & -1 \\ -1 & 0 & -1 & 2\end{pmatrix},\qquad \text{eigenvalues } 0, 2, 4, 4.

The graph is connected (one zero eigenvalue), which is Assumption 1. The paper insists that the two channels of an edge are independent (its Remark 1): the graph is undirected, but each agent processes its own measurement with its own map, so in practice the interaction is directed.

3 Step 2: shift functions

3.1 A monotone map moved off the origin

The ideal interactions in consensus are maps ff that are increasing and vanish at the origin, such as f(s)=sf(s) = s or f(s)=tanh⁡(s)f(s) = \tanh(s). A shift function moves such a map horizontally and vertically and scales it,

sft⁡(s)=af(s−h)+b,a>0,h∈ℝ,b∈ℝ. \operatorname{sft}(s) = a\, f(s - h) + b, \qquad a > 0,\ h \in \mathbb{R},\ b \in \mathbb{R}.

A miscalibrated sensor reads a horizontal offset hh and a bias bb; a one-way actuator is a map that is zero for negative inputs; a saturated one is flat beyond its limits. The paper asks only this of every map (Assumption 2): locally Lipschitz and non-decreasing. So flat pieces (dead zones, saturations, jammed ranges) are allowed, and sft⁡(0)\operatorname{sft}(0) need not be zero.

Two facts of Subsection 4.D matter later. The range R=b+af(ℝ)R = b + a f(\mathbb{R}) moves with the vertical shift and stretches with the scale, but a horizontal shift never changes the range. And in the linear case f(s)=sf(s) = s the two shifts are the same thing, a(s−h)+b=as+(b−ah)a(s - h) + b = as + (b - ah); in the nonlinear case they are not.

4 Step 3: shifted actuation

4.1 The closed loop

With perfect sensors and shifted actuators, every agent computes the ideal input ui=−(Lx)iu_i = -(Lx)_i and gets the velocity Fi(ui)F_i(u_i) (eq. (12)):

ẋ=SFT⁡(−Lx),SFT⁡(u)=(F1(u1),…,FN(uN)). \dot x = \operatorname{SFT}(-Lx), \qquad \operatorname{SFT}(u) = \big(F_1(u_1), \dots, F_N(u_N)\big).

The paper works with η=Lx\eta = Lx, the vector of the agents’ disagreements. It lives in im⁡(L)\operatorname{im}(L), so its entries sum to zero, ∑iηi=0\sum_i \eta_i = 0. Its dynamics are η̇=LSFT⁡(−η)\dot\eta = L\,\operatorname{SFT}(-\eta).

4.2 Which velocity can the team share? Lemma 2

If all agents end up with the same velocity yy, each agent’s disagreement ηi\eta_i must satisfy Fi(−ηi)=yF_i(-\eta_i) = y, and the disagreements must still add up to zero. Lemma 2 says that, if the ranges Ri=Fi(ℝ)R_i = F_i(\mathbb{R}) share an interval of non-zero length (Assumption 3), there is exactly one such velocity y*y^*.

The proof (Appendix A) minimises a convex potential for existence; uniqueness is one line: a higher yy needs a higher input at every agent, so the inputs cannot add up to zero at two different velocities. Geometrically (the paper’s Fig. 10): let Ti(y)T_i(y) be the set of ηi\eta_i with Fi(−ηi)=yF_i(-\eta_i) = y. It is an interval, a single point where FiF_i is increasing and a segment where FiF_i is flat. Their sum T(y)=∑iTi(y)T(y) = \sum_i T_i(y) moves down as yy grows, and y*y^* is where it crosses zero.

For the two maps of Fig. 10, F1(u)=tanh⁡(u−0.4)F_1(u) = \tanh(u - 0.4) and a piecewise-linear F2F_2 with a dead zone on [−0.2,0.2][-0.2, 0.2], the common range is (−1,0.8](-1, 0.8], and the page’s bisection on T(y)T(y) finds y*y^* = -0.1140, with η‾\bar\eta = (−0.2855, 0.2855). The two disagreements add up to zero, as they must.

4.3 Theorem 1: velocity alignment under shifted actuation

Theorem 1 (Shifted Actuation Alignment). On a connected graph, with monotone actuation maps whose ranges are compatible (Assumptions 1 to 3), every agent’s velocity converges to the same value, the y*y^* of Lemma 2:

limt→∞ẋ(t)=y*𝟏N,η(t)=Lx(t)→η‾ with SFT⁡(−η‾)=y*𝟏N. \lim_{t\to\infty} \dot x(t) = y^*\mathbf{1}_N, \qquad \eta(t) = Lx(t) \to \bar\eta \text{ with } \operatorname{SFT}(-\bar\eta) = y^*\mathbf{1}_N .

The proof uses the potential V(η)=∑i∫0−ηiFi(s)dsV(\eta) = \sum_i \int_0^{-\eta_i} F_i(s)\,\mathrm ds, which decreases along the motion, V̇=−SFT⁡(−η)⊤LSFT⁡(−η)≤0\dot V = -\operatorname{SFT}(-\eta)^\top L\, \operatorname{SFT}(-\eta) \le 0, and is zero exactly when all velocities are equal. LaSalle gives the alignment, and a monotone distance argument gives convergence of η\eta to one point.

The limit η‾\bar\eta fixes the offsets between the agents: Πx(t)→L†η‾\Pi x(t) \to L^\dagger \bar\eta, where Π\Pi removes the average. So the team ends up as a rigid group moving at y*y^*, x(t)=L†η‾+y*t𝟏N+α∞𝟏N+o(1)x(t) = L^\dagger\bar\eta + y^* t\,\mathbf{1}_N + \alpha_\infty\mathbf{1}_N + o(1). If the maps have flat pieces, several η‾\bar\eta can give the same y*y^*, and which one the team reaches depends on where it starts; the velocity does not.

On the example. The paper’s Fig. 7 gives every agent the smooth, invertible map Fi(u)=asinh⁡(u−hi)+biF_i(u) = \operatorname{asinh}(u - h_i) + b_i, with hh = (−0.1, −0.2, 0.3, 0.1) and bb = (0.1, −0.1, 0.2, −0.3). These values are not in the paper; they were recovered from the vector data of the original figure, and the code that drew the revised figure uses them (TCNS_R1/img_shift/make_figures.py). The ranges are all of ℝ\mathbb{R}, so Assumption 3 holds. Since Fi(−ηi)=yF_i(-\eta_i) = y means ηi=−hi−sinh⁡(y−bi)\eta_i = -h_i - \sinh(y - b_i), Lemma 2 is the scalar equation ∑i[hi+sinh⁡(y−bi)]=0\sum_i [h_i + \sinh(y - b_i)] = 0, whose root is y*y^* = -0.0499. Then η‾\bar\eta = (0.2504, 0.1498, −0.0475, −0.3527) and the predicted offsets are L†η‾L^\dagger\bar\eta = (0.0626, 0.1003, −0.0119, −0.1510). The simulation (Euler, 1 ms) reaches the velocity -0.0499 at t=10t = 10, and its offsets differ from the prediction by 2.9e-9 at most.

4.4 When is it a static consensus? Corollaries 1 and 2

With invertible maps (Assumption 5), η‾\bar\eta is unique, and Corollary 1 reads off the outcome from the value of each map at zero input:

  • the team reaches consensus (zero offsets) if and only if all maps agree at zero, Fi(0)=Fj(0)F_i(0) = F_j(0) for all i,ji,j;
  • the consensus is static if and only if all maps pass through the origin, Fi(0)=0F_i(0) = 0.

In the example, Fi(0)F_i(0) = (0.200, 0.099, −0.096, −0.400): four different values, so the team neither stops nor agrees. This is the paper’s point: a single imperfect agent is enough to make the team drift with offsets, and static consensus is the exception. Read the other way, a known shift is a design tool: the maps decide both the drift and the offsets.

With purely horizontal shifts of one map (bi=0b_i = 0, the same aa and ff for all), Lemma 2 gives y*=af(−h‾)y^* = a f(-\bar h) with h‾\bar h the average shift, and η‾i=h‾−hi\bar\eta_i = \bar h - h_i: the average shift sets the drift, the deviations from it set the offsets, whatever ff is (Subsection 4.D). For the example’s hh, h‾\bar h = 0.025 and, without the vertical shifts, the team would drift at asinh⁡(−h‾)\operatorname{asinh}(-\bar h) = -0.0250.

Corollary 2 (Anchored Network). If one agent i0i_0 cannot move at all, Fi0≡0F_{i_0} \equiv 0, Assumption 3 fails (the common range is the single point 0), but the proof still works with y*=0y^* = 0: everybody stops. The drift becomes a static distortion, x(t)→L†η‾+(xi0(0)−(L†η‾)i0)𝟏Nx(t) \to L^\dagger\bar\eta + \big(x_{i_0}(0) - (L^\dagger\bar\eta)_{i_0}\big)\mathbf{1}_N, with η‾i=−Fi−1(0)\bar\eta_i = -F_i^{-1}(0) for i≠i0i \neq i_0. Anchoring agent 1 of the example at its start, the formula predicts x*x^* = (0.0000, −0.0128, −0.1255, −0.2650), and the simulation is there at t=20t = 20 to within 3.1e-9.

A different kind of agent is one with a constant velocity va≠0v_{\mathrm a} \ne 0, a leader. The paper notes (after Theorem 1) that if vav_{\mathrm a} is inside every other agent’s range and is not one of their saturation levels, the whole team ends up moving at vav_{\mathrm a}. The playground lets you jam a drone’s throttle and watch this happen, and break it.

5 Step 4: shifted sensing

5.1 The closed loop

Now the actuators are perfect and the sensors are not. Agent ii applies its own map sft⁡ij\operatorname{sft}_{ij} to its measurement of each neighbour (eq. (17)):

ẋi=−∑j∈𝒩isft⁡ij(xi−xj). \dot x_i = -\sum_{j \in \mathcal{N}_i} \operatorname{sft}_{ij}(x_i - x_j).

In general sft⁡ij(xi−xj)≠−sft⁡ji(xj−xi)\operatorname{sft}_{ij}(x_i - x_j) \neq -\operatorname{sft}_{ji}(x_j - x_i): the two ends of an edge disagree about the same distance. Range compatibility is no longer enough. The ranges of the nodal inputs can overlap and the agents still not align, because all of them must realise the same velocity at one edge configuration z∈im⁡(B⊤)z \in \operatorname{im}(B^\top), and the cycles of the graph constrain that configuration (Remark 4).

5.2 Theorem 2: a maximum principle, and clusters

Theorem 2(i). With monotone sensing maps (Assumption 2 only), the largest velocity v¯(t)=max⁡iẋi(t)\overline v(t) = \max_i \dot x_i(t) never increases and the smallest v_(t)\underline v(t) never decreases. So the velocity spread S(t)=v¯−v_S(t) = \overline v - \underline v never grows. The proof compares the solution with itself shifted in time: at the agent that leads the comparison, every measurement is larger than in the other copy, and monotonicity does the rest.

Theorem 2(ii). For smooth maps whose two orientations have comparable slopes, K−1sft⁡ji′(−s)≤sft⁡ij′(s)≤Ksft⁡ji′(−s)K^{-1}\operatorname{sft}'_{ji}(-s) \le \operatorname{sft}'_{ij}(s) \le K \operatorname{sft}'_{ji}(-s) (the paired-sensitivity condition, eq. (18)), every velocity converges, and agents joined by edges with infinite accumulated sensitivity, ∫0∞sft⁡ij′(xi(t)−xj(t))dt=∞\int_0^\infty \operatorname{sft}'_{ij}(x_i(t) - x_j(t))\,\mathrm dt = \infty, end with the same velocity. These edges form the active graph 𝒢a\mathcal{G}_a. The velocities obey a consensus protocol with time-varying weights aij(t)=sft⁡ij′(zij(t))a_{ij}(t) = \operatorname{sft}'_{ij}(z_{ij}(t)), and the paired-sensitivity condition makes it cut-balanced, so a result of Hendrickx and Tsitsiklis applies. An edge whose sensors saturate, because the two agents drift apart, stops counting, and the team can split along it.

On the example (the paper’s Fig. 5). Three agents on a triangle, with sft⁡ij(s)=tanh⁡(s)+bij\operatorname{sft}_{ij}(s) = \tanh(s) + b_{ij} and one large bias, b21=−3.5b_{21} = -3.5. Each tanh\tanh is bounded by 1, so the input of agent ii ranges over (−∑jbij−2,−∑jbij+2)(-\sum_j b_{ij} - 2,\, -\sum_j b_{ij} + 2): centred at (0.4, 3.4, 0.0), these intervals overlap on 1.4 to 2.0. They are compatible, and still the agents do not align. The slopes of the two orientations of an edge are equal, sft⁡ij′(s)=sech⁡2(s)=sft⁡ji′(−s)\operatorname{sft}'_{ij}(s) = \operatorname{sech}^2(s) = \operatorname{sft}'_{ji}(-s), so Theorem 2(ii) applies with K=1K = 1. The simulation ends with velocities (1.2000, 1.4000, 1.2000) at t=50t = 50: two clusters, {1,3}\{1, 3\} and {2}\{2\}, as the paper says. Over the run, the spread S(t)S(t) goes from 6.85 down to 0.22 at t=7t = 7, and never increases between two samples.

5.2.1 The two cluster velocities, in closed form

This calculation is ours. Agent 2 drifts away from the others, so both its measurements saturate, tanh⁡(x2−x1)→1\tanh(x_2 - x_1) \to 1 and tanh⁡(x2−x3)→1\tanh(x_2 - x_3) \to 1, and its velocity tends to −(1−3.5)−(1+0.1)-(1 - 3.5) - (1 + 0.1) = 1.4. Agents 1 and 3 see agent 2 saturated at −1-1, and each other at a bounded distance d=x1−x3d = x_1 - x_3. Their velocities are 1.4−tanh⁡d1.4 - \tanh d and 1+tanh⁡d1 + \tanh d; they are equal when tanh⁡d=0.2\tanh d = 0.2. So the cluster {1,3}\{1, 3\} moves at 1.2 with x1−x3→atanh⁡(0.2)x_1 - x_3 \to \operatorname{atanh}(0.2) = 0.2027, the simulation’s 0.2027 at t=50t = 50. The edges {1,2}\{1,2\} and {2,3}\{2,3\} have sensitivity sech⁡2\operatorname{sech}^2 of a distance that grows linearly, which is integrable: they leave the active graph, and the team splits along them.

Why must it split? Because tanh\tanh is odd, the two measurements of an edge cancel in the sum of all velocities, and ∑iẋi=−∑i,jbij\sum_i \dot x_i = -\sum_{i,j} b_{ij} at every instant. So if the three agents aligned, they would align at −∑bij/3=(0.3−b21)/3-\sum b_{ij}/3 = (0.3 - b_{21})/3, which is 1.267 for b21=−3.5b_{21} = -3.5. Agent 2 would then need tanh⁡(z21)+tanh⁡(z23)=−ẋ2−b21−0.1\tanh(z_{21}) + \tanh(z_{23}) = -\dot x_2 - b_{21} - 0.1 = 2.133, more than the largest value two tanh\tanh can reach, 2. The aligned motion of Remark 4 exists only for b21>−3.3b_{21} > -3.3; below, agent 2 cannot be held back, and runs ahead at its own saturated velocity. The figure below lets you cross that threshold.

5.3 Theorem 3: global alignment when every sensor stays responsive

Assumption 4 (Uniform Sensing Sensitivity) asks every sensing map to have slopes between two positive constants, κ_≤(sft⁡ij(s)−sft⁡ij(r))/(s−r)≤κ¯\underline\kappa \le (\operatorname{sft}_{ij}(s) - \operatorname{sft}_{ij}(r))/(s - r) \le \overline\kappa. It rules out saturation and dead zones: every edge stays in the active graph forever.

Theorem 3 (All-Edge Sensing Alignment). Under Assumptions 1, 2 and 4, all velocities converge to one value, and exponentially: for any T>0T > 0, S(t)≤(1−γ)⌊t/T⌋S(0)S(t) \le (1 - \gamma)^{\lfloor t/T \rfloor} S(0), with γ=min⁡kγk\gamma = \min_k \gamma_k, γk=e−aT(κ_τe−aT)k\gamma_k = e^{-aT}(\underline\kappa\, \tau\, e^{-aT})^k, a=dmaxκ¯a = d_{\max}\overline\kappa and τ=T/(N−1)\tau = T/(N-1) (eq. (21)).

On the example (the paper’s Fig. 8). The four agents of Fig. 1 sense with sft⁡ij(z)=tanh⁡(z−hij)+0.2z+bij\operatorname{sft}_{ij}(z) = \tanh(z - h_{ij}) + 0.2 z + b_{ij}. The slopes lie between 0.2 and 1.2, so κ_=0.2\underline\kappa = 0.2, κ¯=1.2\overline\kappa = 1.2, as the paper says. The ten shifts hijh_{ij} and the four sums of biases ∑jbij\sum_j b_{ij} (all the dynamics see) are not in the paper; they come from the original figure, through make_figures.py. The velocities start spread over 4.62 and align at 0.1987; the states keep drifting.

5.3.1 How conservative is the rate?

This measurement is ours. The paper says that γ\gamma “certifies an exponential rate rather than estimating it”. On the example (N=4N = 4, dmax=3d_{\max} = 3), the best certified rate −ln⁡(1−γ)/T-\ln(1-\gamma)/T over TT is 7.7·10⁻⁷ per unit of time, at TT = 0.14 (where γ\gamma = 1.1·10⁻⁷). The spread of the simulation shrinks at an average rate of 1.84 over [0,4][0, 4]. The bound is correct and about 2·10⁶ times slower than the team.

5.4 Proposition 4: when sensing gives a static consensus

If both ends of every edge use the same odd map, sft⁡ij=sft⁡ji\operatorname{sft}_{ij} = \operatorname{sft}_{ji} with sft⁡(−s)=−sft⁡(s)\operatorname{sft}(-s) = -\operatorname{sft}(s), and the map is strictly positive for positive arguments, then the measurements of an edge cancel exactly, the edge potential ∑ℓ∫0zℓsft⁡ℓ\sum_\ell \int_0^{z_\ell}\operatorname{sft}_\ell is a Lyapunov function, and the team reaches a static consensus (Proposition 4). The strict sign condition matters: with an odd dead zone, every configuration where all neighbours are closer than the dead zone is already an equilibrium. Such perfectly matched endpoints are the exception; in general relative-state inconsistencies propagate and the team drifts.

6 Step 5: linear shifts

6.1 One affine system for both channels

With linear maps, sft⁡(s)=as+b\operatorname{sft}(s) = as + b, both channels lead to (eq. (24))

ẋ=−L̃x+b. \dot x = -\tilde L x + b .

For actuation, L̃=diag⁡(ai)L\tilde L = \operatorname{diag}(a_i) L. For sensing, with slopes aℓi,aℓoa_{\ell^{\mathrm i}}, a_{\ell^{\mathrm o}} and biases bℓi,bℓob_{\ell^{\mathrm i}}, b_{\ell^{\mathrm o}} on the two orientations of each edge, L̃=BoDiB⊤+BiDoB⊤\tilde L = B^{\mathrm o} D^{\mathrm i} B^\top + B^{\mathrm i} D^{\mathrm o} B^\top and b=−Bobi+Bibob = -B^{\mathrm o} b^{\mathrm i} + B^{\mathrm i} b^{\mathrm o}. In both cases L̃\tilde L is a weighted Laplacian with kernel 𝟏N\mathbf{1}_N, and its left null vector vv can be taken positive.

Actuation is a special case of sensing. A linear actuation aiu+bia_i u + b_i is the linear sensing with aℓ=aia_\ell = a_i and bℓ=−bi/|ℰi|b_\ell = -b_i/|\mathcal{E}_i| on every measurement of agent ii. Conversely, a linear sensing is an actuation if and only if each agent uses one slope for all its measurements. One consequence: diag⁡(ai)L\operatorname{diag}(a_i)L is similar to a symmetric matrix and has real eigenvalues, while a sensing Laplacian can have complex ones.

An example with complex eigenvalues (ours). Give the sensing slopes 3 to the measurements that go around the triangle 1→2→3→11 \to 2 \to 3 \to 1 and 0.2 to the ones against it, with slopes aia^{\mathrm i} = (3.0, 0.2, 1.0, 3.0, 1.5), aoa^{\mathrm o} = (0.2, 3.0, 1.0, 0.2, 0.5) and small biases. Then

L̃=(4.2−3−0.2−1−0.23.2−30−3−0.24.7−1.5−10−0.51.5),eigenvalues 0,2.214,5.693−2.280i,5.693+2.280i. \tilde L = \begin{pmatrix}4.2 & -3 & -0.2 & -1 \\ -0.2 & 3.2 & -3 & 0 \\ -3 & -0.2 & 4.7 & -1.5 \\ -1 & 0 & -0.5 & 1.5\end{pmatrix}, \qquad \text{eigenvalues } 0,\ 2.214,\ 5.693 − 2.280i,\ 5.693 + 2.280i.

No agent uses one slope for all its measurements, so this sensing is not an actuation (the page’s test sens_is_act says so too, and says yes for the actuation of Fig. 9 written as a sensing).

6.2 Proposition 3: the drift and the offsets, in closed form

Proposition 3 (Linear Drift Formula). The solution approaches a straight motion exponentially:

x(t)=P1bt+L̃†P2b+c′𝟏N+o(1),P1=𝟏Nv⊤𝟏N⊤v,P2=I−P1,c′=v⊤(x(0)−L̃†P2b)v⊤𝟏N. x(t) = P_1 b\, t + \tilde L^\dagger P_2 b + c'\mathbf{1}_N + o(1), \qquad P_1 = \frac{\mathbf{1}_N v^\top}{\mathbf{1}_N^\top v},\quad P_2 = I - P_1,\quad c' = \frac{v^\top(x(0) - \tilde L^\dagger P_2 b)}{v^\top\mathbf{1}_N}.

The bias splits in two: b∥=P1b=c𝟏Nb_\parallel = P_1 b = c\,\mathbf{1}_N with c=v⊤b/v⊤𝟏Nc = v^\top b / v^\top\mathbf{1}_N sets the common velocity, and b⟂=P2bb_\perp = P_2 b sets the non-consensus distortion L̃†b⟂\tilde L^\dagger b_\perp, whose norm is at most ∥b⟂∥/σ2(L̃)\|b_\perp\|/\sigma_2(\tilde L).

In the rotating example, vv = (0.2313, 0.2289, 0.1928, 0.3470) (normalised to sum 1), so the team drifts at cc = -0.1275; the simulation’s velocities at t=12t = 12 are (−0.1275, −0.1275, −0.1275, −0.1275). The page computes L̃†\tilde L^\dagger as (L̃+wu⊤)−1−uw⊤(\tilde L + w u^\top)^{-1} - u w^\top with u=𝟏/Nu = \mathbf{1}/\sqrt N and w=v/∥v∥w = v/\|v\|, a formula for rank-one-deficient matrices that matches numpy.linalg.pinv to 1.7e-16. The distortion has norm 0.213, under the bound 0.401.

6.3 Second-order agents

Section 7 of the paper shows the same mechanism one derivative higher: double integrators with linear actuation shifts, ẍ=diag⁡(ai)u+b\ddot x = \operatorname{diag}(a_i)u + b with u=−L(x+γẋ)u = -L(x + \gamma\dot x). The left null vector of diag⁡(ai)L\operatorname{diag}(a_i)L is w=diag⁡(ai)−1𝟏Nw = \operatorname{diag}(a_i)^{-1}\mathbf{1}_N, so w⊤ẍ=w⊤bw^\top\ddot x = w^\top b, and the accelerations align at c=∑i(bi/ai)/∑i(1/ai)c = \sum_i (b_i/a_i) / \sum_i (1/a_i): a common constant acceleration, and velocities that grow linearly. With the paper’s aa = (1.0, 0.8, 1.2, 1.0), bb = (0.2, −0.1, 0.3, 0.0) and γ=1\gamma = 1, cc = 0.0796. If ∑ibi/ai=0\sum_i b_i/a_i = 0 instead, as for bb = (0.80, −0.96, 1.20, −0.60), agents that start at rest stop with the offsets L†diag⁡(ai)−1bL^\dagger\operatorname{diag}(a_i)^{-1}b = (0.2000, −0.3750, 0.2500, −0.0750).

7 Corrections to the published version

The page re-runs every simulation of the paper with the parameters of the code that drew its figures (TCNS_R1/img_shift/make_figures.py), and compares the result with what the text says. Everything matches but one number, and three figures depend on parameters that the paper does not state.

The second-order example (Section 7). The text says that the predicted acceleration c≈0.0796c \approx 0.0796 is matched by the accelerations of Fig. 9 “to within 10−910^{-9}”. The exact solution (a matrix exponential of the linear system, computed on this page) gives, at the last time of the figure, t=20t = 20, a largest deviation max⁡i|ẍi(20)−c|\max_i|\ddot x_i(20) - c| = 2.4·10⁻⁹. The slowest mode decays like e−λ2t/2e^{-\lambda_2 t/2} with λ2\lambda_2 = 1.782 the smallest non-zero eigenvalue of diag⁡(ai)L\operatorname{diag}(a_i)L, and it oscillates, so the deviation is still above 10−910^{-9} at t=22t = 22 and below it by t=25t = 25 (table). The figure and the prediction are right; the sentence would read “to within 3⋅10−93\cdot 10^{-9}”.

time tt max⁡i|ẍi(t)−c|\max_i \lvert \ddot x_i(t) - c\rvert (exact)
10 3.0·10⁻⁵
15 1.1·10⁻⁶
20 2.4·10⁻⁹
22 1.7·10⁻⁹
25 1.3·10⁻¹⁰
30 1.1·10⁻¹²

Parameters not stated in the paper. Figs. 6, 7 and 8 use values that the reader cannot find in the text: the breakpoints of the four non-negative maps of Fig. 6, the shifts h=(−0.1,−0.2,0.3,0.1)h = (-0.1, -0.2, 0.3, 0.1) and b=(0.1,−0.1,0.2,−0.3)b = (0.1, -0.1, 0.2, -0.3) of Fig. 7, and the ten shifts and four bias sums of Fig. 8. The figure script recovered them from the original figures. Stating them (in the captions or in a table) would make the simulations reproducible from the paper alone. The initial conditions are not stated either.

What does not change. No result, proof or claim about the qualitative behaviour is affected. Every number the text gives for Figs. 5 to 10 (the clusters {1,3}\{1,3\} and {2}\{2\}, the static consensus at the maximum initial state, the predicted drift and offsets, κ_=0.2\underline\kappa = 0.2 and κ¯=1.2\overline\kappa = 1.2, c≈0.0796c \approx 0.0796, the static offsets for ∑ibi/ai=0\sum_i b_i/a_i = 0) is reproduced below.

8 The program each agent runs

Every agent runs the same short program; only its maps differ, and it does not know them.

Before take-off: nothing to configure. The agent knows who its neighbours are.

At every tick: 1. measure zij=xi−xjz_{ij} = x_i - x_j for every neighbour jj (the sensor delivers ψij(zij)\psi_{ij}(z_{ij}), not zijz_{ij}); 2. compute the consensus input ui=−∑jψij(zij)u_i = -\sum_j \psi_{ij}(z_{ij}); 3. send uiu_i to the actuator, which delivers the velocity Fi(ui)F_i(u_i).

The shifts are in the hardware, not in the program: ψij\psi_{ij} and FiF_i are what the sensors and the actuator do to the ideal signals. In the simulator they are explicit, so that the page can say what the team will do.

def program(z, psi, F):
    """What agent i runs at every tick: its measurements z_ij = x_i - x_j (one per neighbour), its sensing maps
    psi (one per neighbour; None for perfect sensing) and its actuation map F (None for faithful actuation).
    Returns the velocity it actually gets, F(u) with u = -sum_j psi_ij(z_ij)."""
    u = 0.0
    for k in range(len(z)):
        u -= z[k] if (psi is None or psi[k] is None) else sft(psi[k], z[k])
    return u if F is None else sft(F, u)

9 The simulator

The whole model is one file, core.py: the graphs, the shift functions, the program above, the Euler simulator, the bisection of Lemma 2, the linear algebra of Proposition 3 and the paper’s examples. Every number on this page comes from it. The interactive figures run assets/core.js, a line-by-line port, and make check compares the two.

core.py: the core of this page (the JavaScript of the figures is a line-by-line port)
"""The Python core of the paper's pages: every number the explainer prints is computed here, at render time.

A line-by-line twin of assets/core.js: same functions, same names, same order of operations. `make check` runs
check() here and EX.core.check() in deno, and compares every value (1e-9).

The model (paper, eq. (6)-(8)): N agents on a line, x_i in R, single integrators. Agent i measures z_ij = x_i - x_j
for each neighbour j, passes it through its sensing map psi_ij, adds the results, and its actuator turns the sum into
a velocity: xdot_i = F_i(u_i), u_i = -sum_j psi_ij(z_ij). Every map is a "shift function" (monotone, Lipschitz).
The world is Euler with the velocities held for one tick. Plain lists and loops, so that the JavaScript computes
exactly the same sums in the same order.
"""
import math

BIG = 1e6            # the "infinity" of the preimage searches (Lemma 2): |u| < BIG
NBIS = 120           # bisection steps (from 2e6 wide to below 1e-29)


# ------------------------------------------------------------------ graphs
EDGES4 = [[0, 1], [0, 2], [0, 3], [1, 2], [2, 3]]   # Fig. 1: {1,2},{1,3},{1,4},{2,3},{3,4}; positive orientation (i, j)
EDGES3 = [[0, 1], [0, 2], [1, 2]]                   # the triangle of Fig. 5


def neighbours(n, edges):
    nb = [[] for _ in range(n)]
    for e in edges:
        nb[e[0]].append(e[1])
        nb[e[1]].append(e[0])
    return nb


def incidence(n, edges):
    """B, B^o (out) and B^i (in), N x M: [B]_{il} = +1 (-1) if i is the initial (terminal) node of edge l."""
    m = len(edges)
    B = [[0.0] * m for _ in range(n)]
    Bo = [[0.0] * m for _ in range(n)]
    Bi = [[0.0] * m for _ in range(n)]
    for k in range(m):
        i, j = edges[k][0], edges[k][1]
        B[i][k] = 1.0
        B[j][k] = -1.0
        Bo[i][k] = 1.0
        Bi[j][k] = -1.0
    return B, Bo, Bi


def laplacian(n, edges):
    L = [[0.0] * n for _ in range(n)]
    for e in edges:
        i, j = e[0], e[1]
        L[i][i] += 1.0
        L[j][j] += 1.0
        L[i][j] -= 1.0
        L[j][i] -= 1.0
    return L


def ring(n, k):
    """The circulant graph: i is a neighbour of i +- 1, ..., i +- k (mod n)."""
    edges = []
    for i in range(n):
        for d in range(1, k + 1):
            j = (i + d) % n
            if [j, i] not in edges and [i, j] not in edges:
                edges.append([i, j] if i < j else [j, i])
    return edges


# ------------------------------------------------------------------ shift functions
def interp(xs, ys, s):
    """Piecewise linear through the knots, flat outside them (numpy.interp)."""
    if s <= xs[0]:
        return ys[0]
    n = len(xs)
    if s >= xs[n - 1]:
        return ys[n - 1]
    k = 0
    while xs[k + 1] < s:
        k += 1
    return ys[k] + (ys[k + 1] - ys[k]) * (s - xs[k]) / (xs[k + 1] - xs[k])


def sft(m, s):
    """A shift function, as a list [kind, parameters...]:
      ["lin", a, h, b]          a (s - h) + b
      ["tanh", a, h, b, c]      a tanh(s - h) + c s + b          (Figs. 5 and 8; c > 0 gives Assumption 4)
      ["asinh", a, h, b]        a asinh(s - h) + b                (Fig. 7)
      ["pwl", xs, ys]           piecewise linear, flat outside the knots (Figs. 6 and 10)
      ["sat", a, h, b, lo, hi]  a (s - h) + b clipped to [lo, hi] (a speed band: no reverse, a top speed)
      ["dead", a, w]            0 on [-w, w], a (s -+ w) outside   (the dead zone after Proposition 4)
      ["const", v]              v whatever the input              (a jammed actuator, or an anchor with v = 0)"""
    k = m[0]
    if k == "lin":
        return m[1] * (s - m[2]) + m[3]
    if k == "tanh":
        return m[1] * math.tanh(s - m[2]) + m[4] * s + m[3]
    if k == "asinh":
        return m[1] * math.asinh(s - m[2]) + m[3]
    if k == "pwl":
        return interp(m[1], m[2], s)
    if k == "sat":
        v = m[1] * (s - m[2]) + m[3]
        return m[4] if v < m[4] else (m[5] if v > m[5] else v)
    if k == "dead":
        if s > m[2]:
            return m[1] * (s - m[2])
        if s < -m[2]:
            return m[1] * (s + m[2])
        return 0.0
    if k == "const":
        return m[1]
    raise ValueError(k)


def dsft(m, s):
    """The slope of a shift function (its sensitivity), where it has one; for pwl, sat and dead, the one-sided slope."""
    k = m[0]
    if k == "lin":
        return m[1]
    if k == "tanh":
        c = math.cosh(s - m[2])
        return m[1] / (c * c) + m[4]
    if k == "asinh":
        d = s - m[2]
        return m[1] / math.sqrt(1 + d * d)
    if k == "pwl":
        xs, ys, n = m[1], m[2], len(m[1])
        if s < xs[0] or s >= xs[n - 1]:
            return 0.0
        q = 0
        while xs[q + 1] <= s:
            q += 1
        return (ys[q + 1] - ys[q]) / (xs[q + 1] - xs[q])
    if k == "sat":
        v = m[1] * (s - m[2]) + m[3]
        return 0.0 if (v < m[4] or v > m[5]) else m[1]
    if k == "dead":
        return m[1] if (s > m[2] or s < -m[2]) else 0.0
    return 0.0


# ------------------------------------------------------------------ the robots and the world
def program(z, psi, F):
    """What agent i runs at every tick: its measurements z_ij = x_i - x_j (one per neighbour), its sensing maps
    psi (one per neighbour; None for perfect sensing) and its actuation map F (None for faithful actuation).
    Returns the velocity it actually gets, F(u) with u = -sum_j psi_ij(z_ij)."""
    u = 0.0
    for k in range(len(z)):
        u -= z[k] if (psi is None or psi[k] is None) else sft(psi[k], z[k])
    return u if F is None else sft(F, u)


def network(n, edges, F=None, psi=None):
    """A team: the graph, an actuation map per agent (or None) and a sensing map per agent and neighbour (or None).
    psi may be given as a dict {(i, j): map} over oriented edges; it is stored in the order of neighbours(n, edges)."""
    nb = neighbours(n, edges)
    P = None
    if psi is not None:
        P = [[psi.get((i, j)) for j in nb[i]] for i in range(n)]
    return {"n": n, "edges": edges, "nb": nb, "F": F, "psi": P}


def velocity(net, x):
    v = []
    for i in range(net["n"]):
        z = [x[i] - x[j] for j in net["nb"][i]]
        v.append(program(z, None if net["psi"] is None else net["psi"][i], None if net["F"] is None else net["F"][i]))
    return v


def simulate(net, x0, dt, steps, every=1):
    """The world: Euler with the velocities held for one tick. Returns the states and velocities every `every` ticks."""
    n = net["n"]
    x = [float(q) for q in x0]
    v = velocity(net, x)
    X, V = [x], [v]
    for s in range(1, steps + 1):
        x = [x[i] + dt * v[i] for i in range(n)]
        v = velocity(net, x)
        if s % every == 0:
            X.append(x)
            V.append(v)
    return X, V


def simulate2(net2, x0, v0, dt, steps, every=1):
    """Double integrators with linear actuation shifts (Section 7): xddot = diag(a) u + b, u = -L (x + gamma xdot)."""
    n, L, a, b, gam = net2["n"], net2["L"], net2["a"], net2["b"], net2["gamma"]
    x = [float(q) for q in x0]
    v = [float(q) for q in v0]

    def acc(x, v):
        out = []
        for i in range(n):
            u = 0.0
            for j in range(n):
                u -= L[i][j] * (x[j] + gam * v[j])
            out.append(a[i] * u + b[i])
        return out

    A = acc(x, v)
    X, Vs, As = [x], [v], [A]
    for s in range(1, steps + 1):
        x, v = [x[i] + dt * v[i] for i in range(n)], [v[i] + dt * A[i] for i in range(n)]
        A = acc(x, v)
        if s % every == 0:
            X.append(x)
            Vs.append(v)
            As.append(A)
    return X, Vs, As


def mean(v):
    s = 0.0
    for q in v:
        s += q
    return s / len(v)


def spread(v):
    """S = max_i v_i - min_i v_i, the velocity spread of Theorem 2."""
    lo, hi = v[0], v[0]
    for q in v:
        lo = q if q < lo else lo
        hi = q if q > hi else hi
    return hi - lo


def project(x):
    """Pi x: the non-consensus part of the state (the mean removed)."""
    m = mean(x)
    return [q - m for q in x]


# ------------------------------------------------------------------ Lemma 2: the unique compatible velocity y*
def rng_of(m):
    """The range of a shift function, up to the closure: [sft(-BIG), sft(BIG)]."""
    return [sft(m, -BIG), sft(m, BIG)]


def pre_lo(m, y):
    """inf { u : sft(u) >= y } (the lower end of the preimage of y)."""
    lo, hi = -BIG, BIG
    if sft(m, hi) < y:
        return math.inf
    if sft(m, lo) >= y:
        return -math.inf
    for _ in range(NBIS):
        mid = 0.5 * (lo + hi)
        if sft(m, mid) >= y:
            hi = mid
        else:
            lo = mid
    return hi


def pre_hi(m, y):
    """sup { u : sft(u) <= y } (the upper end of the preimage of y)."""
    lo, hi = -BIG, BIG
    if sft(m, lo) > y:
        return -math.inf
    if sft(m, hi) <= y:
        return math.inf
    for _ in range(NBIS):
        mid = 0.5 * (lo + hi)
        if sft(m, mid) <= y:
            lo = mid
        else:
            hi = mid
    return lo


def common_range(maps):
    """The set R of Assumption 3, [max_i inf R_i, min_i sup R_i] (empty if the first is not below the second)."""
    lo, hi = -math.inf, math.inf
    for m in maps:
        r = rng_of(m)
        lo = r[0] if r[0] > lo else lo
        hi = r[1] if r[1] < hi else hi
    return [lo, hi]


def ystar(maps):
    """The y* of Lemma 2: the one velocity y in R with u_i in sft_i^{-1}(y) and sum_i u_i = 0. NaN if R has no length.
    Bisection on y: the sums of the preimages move up with y (the right panel of Fig. 10)."""
    R = common_range(maps)
    lo, hi = R[0], R[1]
    if not lo < hi:
        return math.nan
    for _ in range(NBIS):
        y = 0.5 * (lo + hi)
        if y <= lo or y >= hi:
            break
        s = 0.0
        for m in maps:
            s += pre_lo(m, y)
        if s > 0:
            hi = y
            continue
        s = 0.0
        for m in maps:
            s += pre_hi(m, y)
        if s < 0:
            lo = y
            continue
        return y
    return 0.5 * (lo + hi)


def etabar(maps, y):
    """For invertible maps: the limit of eta = L x, eta_i = -sft_i^{-1}(y*) (Theorem 1 and the text after it)."""
    return [-pre_lo(m, y) for m in maps]


# ------------------------------------------------------------------ small dense linear algebra (the same in both)
def solve(A, b):
    """Gaussian elimination with partial pivoting; A is n x n (a copy is made), b a vector."""
    n = len(A)
    M = [list(A[i]) + [b[i]] for i in range(n)]
    for c in range(n):
        p = c
        for r in range(c + 1, n):
            if abs(M[r][c]) > abs(M[p][c]):
                p = r
        M[c], M[p] = M[p], M[c]
        for r in range(c + 1, n):
            f = M[r][c] / M[c][c]
            for k in range(c, n + 1):
                M[r][k] -= f * M[c][k]
    x = [0.0] * n
    for r in range(n - 1, -1, -1):
        s = M[r][n]
        for k in range(r + 1, n):
            s -= M[r][k] * x[k]
        x[r] = s / M[r][r]
    return x


def matvec(A, x):
    out = []
    for r in A:
        s = 0.0
        for k in range(len(x)):
            s += r[k] * x[k]
        out.append(s)
    return out


def dot(a, b):
    s = 0.0
    for k in range(len(a)):
        s += a[k] * b[k]
    return s


def left_null(Lt):
    """The left null vector v of a weighted Laplacian (v^T Lt = 0), normalised to sum 1: solve Lt^T v = 0 with the last
    equation replaced by sum v = 1."""
    n = len(Lt)
    A = [[Lt[j][i] for j in range(n)] for i in range(n)]
    A[n - 1] = [1.0] * n
    rhs = [0.0] * n
    rhs[n - 1] = 1.0
    return solve(A, rhs)


def pinv_laplacian(Lt, v):
    """The Moore-Penrose pseudoinverse of a rank n-1 matrix with right null vector 1 and left null vector v:
    Lt^+ = (Lt + w u^T)^{-1} - u w^T, u = 1/sqrt(n), w = v/|v| (checked against numpy.linalg.pinv on the page)."""
    n = len(Lt)
    u = 1.0 / math.sqrt(n)
    nv = math.sqrt(dot(v, v))
    w = [q / nv for q in v]
    M = [[Lt[i][j] + w[i] * u for j in range(n)] for i in range(n)]
    cols = []
    for j in range(n):
        e = [0.0] * n
        e[j] = 1.0
        cols.append(solve(M, e))
    return [[cols[j][i] - u * w[j] for j in range(n)] for i in range(n)]


# ------------------------------------------------------------------ Section 6: linear shift functions
def lin_act(n, edges, a, b):
    """Linear shifted actuation F_i(u) = a_i u + b_i: xdot = -diag(a) L x + b."""
    L = laplacian(n, edges)
    return [[a[i] * L[i][j] for j in range(n)] for i in range(n)], [float(q) for q in b]


def lin_sens(n, edges, ai, ao, bi, bo):
    """Linear shifted sensing psi_l(z) = a_l z + b_l on both orientations of each edge k = (i, j):
    the positive one (measured by i) has slope ai[k], bias bi[k]; the negative one (by j) ao[k], bo[k].
    Lt = B^o D^i B^T + B^i D^o B^T and b = -B^o b^i + B^i b^o, written out entry by entry."""
    Lt = [[0.0] * n for _ in range(n)]
    b = [0.0] * n
    for k in range(len(edges)):
        i, j = edges[k][0], edges[k][1]
        Lt[i][i] += ai[k]
        Lt[i][j] -= ai[k]
        Lt[j][j] += ao[k]
        Lt[j][i] -= ao[k]
        b[i] -= bi[k]
        b[j] -= bo[k]
    return Lt, b


def act_as_sens(n, edges, a, b):
    """The linear sensing that reproduces a linear actuation: a_l = a_i and b_l = -b_i / |E_i| on the l measured by i."""
    deg = [len(q) for q in neighbours(n, edges)]
    ai = [a[e[0]] for e in edges]
    ao = [a[e[1]] for e in edges]
    bi = [-b[e[0]] / deg[e[0]] for e in edges]
    bo = [-b[e[1]] / deg[e[1]] for e in edges]
    return ai, ao, bi, bo


def linear_limit(Lt, b, x0):
    """Proposition 3: x(t) = c t 1 + x* + o(1), with c = v^T b / v^T 1 and x* = Lt^+ P2 b + c' 1.
    Returns c, x* (the whole limiting offset, c' included), v and Lt^+."""
    n = len(Lt)
    v = left_null(Lt)
    s1 = 0.0
    for q in v:
        s1 += q
    c = dot(v, b) / s1
    P2b = [b[i] - c for i in range(n)]
    Lp = pinv_laplacian(Lt, v)
    xs = matvec(Lp, P2b)
    cp = (dot(v, x0) - dot(v, xs)) / s1
    return c, [q + cp for q in xs], v, Lp


def sens_is_act(n, edges, ai, ao, tol=1e-12):
    """A linear sensing is a linear actuation iff each agent uses one slope for all its measurements."""
    nb_slopes = [[] for _ in range(n)]
    for k in range(len(edges)):
        nb_slopes[edges[k][0]].append(ai[k])
        nb_slopes[edges[k][1]].append(ao[k])
    for s in nb_slopes:
        for q in s:
            if abs(q - s[0]) > tol:
                return False
    return True


# ------------------------------------------------------------------ Theorem 3: the certified contraction factor
def gamma_bound(T, n, dmax, klo, khi):
    """gamma = min_k gamma_k, gamma_k = e^{-aT} (klo tau e^{-aT})^k, a = dmax khi, tau = T/(n-1)  (eq. (21))."""
    a = dmax * khi
    tau = T / (n - 1)
    g0 = math.exp(-a * T)
    q = klo * tau * g0
    g, gk = g0, g0
    for _ in range(1, n):
        gk = gk * q
        g = gk if gk < g else g
    return g


# ------------------------------------------------------------------ a seeded generator (xorshift32, as in JavaScript)
class Rng:
    def __init__(self, seed):
        self.s = (seed & 0xFFFFFFFF) or 1

    def u(self):
        s = self.s
        s ^= (s << 13) & 0xFFFFFFFF
        s ^= s >> 17
        s ^= (s << 5) & 0xFFFFFFFF
        self.s = s
        return s / 4294967296


def random_pwl(r, lo_max=-0.3, hi_min=0.3):
    """A random non-decreasing piecewise-linear map with flat pieces (a jammed or saturated actuator), whose range
    contains [lo_max, hi_min]: five knots, every gap with probability 0.35 flat."""
    xs, ys = [-3.0 + 2.0 * r.u()], [lo_max - 0.2 - 0.8 * r.u()]
    for _ in range(4):
        xs.append(xs[-1] + 0.3 + 1.2 * r.u())
        ys.append(ys[-1] + (0.0 if r.u() < 0.35 else 0.2 + 0.6 * r.u()))
    if ys[-1] < hi_min + 0.1:
        ys[-1] = hi_min + 0.1 + 0.4 * r.u()
    return ["pwl", xs, ys]


def census_act(count, seed, T=60.0, dt=0.01):
    """Theorem 1 on random teams: four agents on the graph of Fig. 1 with random piecewise-linear actuation (flat pieces
    included) and a random start. Returns, per case, [y* of Lemma 2, the final mean velocity, the final spread]."""
    r = Rng(seed)
    out = []
    for _ in range(count):
        maps = [random_pwl(r) for _ in range(4)]
        x0 = [4.0 * r.u() - 2.0 for _ in range(4)]
        y = ystar(maps)
        X, V = simulate(network(4, EDGES4, F=maps), x0, dt, int(round(T / dt)), int(round(T / dt)))
        out.append([y, mean(V[-1]), spread(V[-1])])
    return out


# ------------------------------------------------------------------ the paper's examples (TCNS_R1/img_shift/make_figures.py)
def fig5_net(b21=-3.5, c=0.0):
    """Fig. 5: the triangle, sft_ij(s) = tanh(s) + b_ij (+ c s, for Assumption 4)."""
    b = {(0, 1): -0.3, (0, 2): -0.1, (1, 0): b21, (1, 2): 0.1, (2, 0): -0.2, (2, 1): 0.2}
    return network(3, EDGES3, psi={k: ["tanh", 1.0, 0.0, v, c] for k, v in b.items()})


FIG5_X0 = [0.0, -1.0, 1.0]

FIG6_KNOTS = [[[0, 2, 6, 9, 10, 13], [0, 0.5, 0.5, 1.5, 1.5, 2.0]],
              [[0, 1, 8, 9, 11, 12], [0, 0.4, 0.4, 1.4, 1.4, 1.9]],
              [[0, 3, 7, 8, 10, 11], [0, 0.6, 0.6, 1.6, 1.6, 2.1]],
              [[0, 5, 10, 11, 13, 14], [0, 0.45, 0.45, 1.45, 1.45, 1.95]]]
FIG6_MAPS = [["pwl", [float(q) for q in k[0]], [float(q) for q in k[1]]] for k in FIG6_KNOTS]
FIG6_X0 = [0.5, 1.0, -1.0, -1.5]

FIG7_H = [-0.1, -0.2, 0.3, 0.1]
FIG7_B = [0.1, -0.1, 0.2, -0.3]
FIG7_MAPS = [["asinh", 1.0, FIG7_H[i], FIG7_B[i]] for i in range(4)]
FIG7_X0 = [0.0, 1.0, -1.0, 2.0]

# Fig. 8: horizontal shifts h_ij and the bias sum of each agent (recovered from the original figure); the sum of an
# agent's biases is all the dynamics see, so it is split evenly over its measurements.
FIG8_H = {(0, 1): -0.274, (0, 2): 1.580, (0, 3): 0.416, (1, 0): -1.056, (1, 2): 0.187,
          (2, 0): 0.549, (2, 1): -0.082, (2, 3): -0.590, (3, 0): -0.294, (3, 2): 1.077}
FIG8_BSUM = [-0.027, -0.204, 0.278, 0.196]
FIG8_X0 = [0.0, 1.0, -1.0, -2.0]


def fig8_net():
    nb = neighbours(4, EDGES4)
    psi = {}
    for i in range(4):
        for j in nb[i]:
            psi[(i, j)] = ["tanh", 1.0, FIG8_H[(i, j)], FIG8_BSUM[i] / len(nb[i]), 0.2]
    return network(4, EDGES4, psi=psi)


FIG9_A = [1.0, 0.8, 1.2, 1.0]
FIG9_B1 = [0.2, -0.1, 0.3, 0.0]
FIG9_B2 = [0.8, -0.96, 1.2, -0.6]
FIG9_X0 = [0.0, 1.0, -1.0, 2.0]

FIG10_MAPS = [["tanh", 1.0, 0.4, 0.0, 0.0], ["pwl", [-1.1, -0.2, 0.2, 0.8], [-1.2, 0.0, 0.0, 0.8]]]

# a linear sensing on the graph of Fig. 1 whose weights turn around the triangle 1 -> 2 -> 3: complex eigenvalues
ROT_AI = [3.0, 0.2, 1.0, 3.0, 1.5]
ROT_AO = [0.2, 3.0, 1.0, 0.2, 0.5]
ROT_BI = [0.3, -0.2, 0.1, 0.0, 0.4]
ROT_BO = [-0.1, 0.2, 0.0, 0.3, -0.2]


def fig_runs():
    """The paper's simulations, with Euler steps of 1 ms (the same calls the figures of the page make)."""
    out = {}
    out["fig5"] = simulate(fig5_net(), FIG5_X0, 1e-3, 7000, 10)
    out["fig6"] = simulate(network(4, EDGES4, F=FIG6_MAPS), FIG6_X0, 1e-3, 70000, 100)
    out["fig7"] = simulate(network(4, EDGES4, F=FIG7_MAPS), FIG7_X0, 1e-3, 3000, 5)
    out["fig8"] = simulate(fig8_net(), FIG8_X0, 1e-3, 4000, 5)
    return out


def check():
    """The same keys as EX.core.check() in assets/core.js."""
    out = {}
    L = laplacian(4, EDGES4)
    out["L4"] = [q for r in L for q in r]
    runs = fig_runs()
    for k in ("fig5", "fig6", "fig7", "fig8"):
        X, V = runs[k]
        out[k + "_x"] = X[-1]
        out[k + "_v"] = V[-1]
    out["fig5_S"] = [spread(v) for v in runs["fig5"][1][::20]]
    y7 = ystar(FIG7_MAPS)
    e7 = etabar(FIG7_MAPS, y7)
    Lt, b = lin_act(4, EDGES4, [1.0] * 4, [0.0] * 4)
    v = left_null(Lt)
    Lp = pinv_laplacian(Lt, v)
    out["fig7_ystar"] = [y7]
    out["fig7_offsets"] = matvec(Lp, e7)
    out["fig6_ystar"] = [ystar(FIG6_MAPS)]
    out["fig10_ystar"] = [ystar(FIG10_MAPS)]
    out["fig10_eta"] = etabar(FIG10_MAPS, ystar(FIG10_MAPS))
    out["fig8_slopes"] = [dsft(m, 0.3) for r in fig8_net()["psi"] for m in r]
    # Section 6: the rotating sensing, and an actuation written as a sensing
    Lt, b = lin_sens(4, EDGES4, ROT_AI, ROT_AO, ROT_BI, ROT_BO)
    c, xs, v, Lp = linear_limit(Lt, b, FIG9_X0)
    out["rot_c"] = [c]
    out["rot_xstar"] = xs
    out["rot_v"] = v
    out["rot_pinv"] = [q for r in Lp for q in r]
    psi = {}
    for k in range(5):
        i, j = EDGES4[k]
        psi[(i, j)] = ["lin", ROT_AI[k], 0.0, ROT_BI[k]]
        psi[(j, i)] = ["lin", ROT_AO[k], 0.0, ROT_BO[k]]
    X, V = simulate(network(4, EDGES4, psi=psi), FIG9_X0, 1e-3, 8000, 8000)
    out["rot_sim_x"] = X[-1]
    out["rot_sim_v"] = V[-1]
    ai, ao, bi, bo = act_as_sens(4, EDGES4, FIG9_A, FIG9_B1)
    Lt2, b2 = lin_sens(4, EDGES4, ai, ao, bi, bo)
    Lt1, b1 = lin_act(4, EDGES4, FIG9_A, FIG9_B1)
    out["act_as_sens"] = [q for r in Lt2 for q in r] + b2 + [q for r in Lt1 for q in r] + b1
    out["is_act"] = [1.0 if sens_is_act(4, EDGES4, ai, ao) else 0.0, 1.0 if sens_is_act(4, EDGES4, ROT_AI, ROT_AO) else 0.0]
    net2 = {"n": 4, "L": laplacian(4, EDGES4), "a": FIG9_A, "b": FIG9_B1, "gamma": 1.0}
    X, Vs, As = simulate2(net2, FIG9_X0, [0.0] * 4, 1e-3, 20000, 20000)
    out["fig9_acc"] = As[-1]
    out["gamma_log"] = [math.log(gamma_bound(T, 4, 3, 0.2, 1.2)) for T in (0.05, 0.1, 0.14, 0.5, 1.0)]
    out["census"] = [q for row in census_act(6, 2026, 30.0, 0.01) for q in row]
    r = Rng(7)
    out["rng"] = [r.u() for _ in range(5)]
    out["ring"] = [q for e in ring(10, 2) for q in e]
    return out

10 Running it: the paper’s simulations again

Every run below is the core’s Euler simulation with steps of 1 ms, with the parameters and initial states of make_figures.py. The paper’s figures were drawn with an adaptive integrator (solve_ivp, tolerance 10−1010^{-10}); at this step the two agree to plotting accuracy, and the limits (which Euler preserves exactly, since its fixed points are those of the flow) agree to round-off.

10.1 Fig. 5: compatible ranges, and still two clusters

The paper’s Fig. 5, run again: states, velocities, the six sensing maps (coloured by the agent that applies them) and the ranges of the nodal inputs (their overlap in grey). Two velocity clusters, {1, 3} at 1.2 and {2} at 1.4.

The paper: “the velocities form two clusters, {1,3}\{1,3\} and {2}\{2\} … a bounded x1−x3x_1 - x_3 and growing inter-cluster separations”. The run: at t=7t = 7 the velocities are (1.195, 1.410, 1.194), x1−x3x_1 - x_3 = 0.201 (its limit is 0.2027), and x2−x1x_2 - x_1 = 2.88 and growing. It matches.

10.2 Fig. 6: non-negative actuation, a static consensus

The paper’s Fig. 6, run again: piecewise-linear non-negative actuation with flat pieces. The agent that starts highest (agent 2) never moves; the others climb to it.

The ranges [0,2][0, 2], [0,1.9][0, 1.9], [0,2.1][0, 2.1], [0,1.95][0, 1.95] meet on [0,1.9][0, 1.9], and Lemma 2 gives y*y^* = 0.000. Every FiF_i is zero exactly on u≤0u \le 0, so the set of compatible η\eta is {η:∑iηi=0,ηi≥0}={0}\{\eta : \sum_i\eta_i = 0,\ \eta_i \ge 0\} = \{0\}: a static consensus. The agent at the top has u≤0u \le 0 and stays, the others can only move up: the consensus is at the maximum initial state, 1. At t=70t = 70 (the end of the figure) the agents are within 0.012 of it, still approaching.

10.3 Fig. 7: smooth invertible actuation, a predicted drift

The paper’s Fig. 7, run again: F_i(u) = asinh(u − h_i) + b_i. The dashed lines are the predictions of Theorem 1 and Lemma 2: the common velocity y* and the offsets L†η̄.

The paper: “all velocities converge to the same nonzero value … the dashed reference lines … match the limits”. The run: y*y^* = -0.0499, the velocities at t=3t = 3 are (−0.0498, −0.0444, −0.0497, −0.0555), and the offsets at t=3t = 3 are within 0.003 of the prediction (within 2.9e-9 at t=10t = 10). It matches.

10.4 Fig. 8: sensing with uniform sensitivity, global alignment

The paper’s Fig. 8, run again: sft_ij(z) = tanh(z − h_ij) + 0.2 z + b_ij. The velocities align; the states drift.

The paper: “their states do not approach static values, whereas the velocities align”. The run: the spread falls from 4.62 to 3.0e-3 at t=4t = 4; the certified bound of Theorem 3 (grey) is a flat line on this scale. It matches.

10.5 Fig. 9: second-order agents

The paper’s Fig. 9, run again (Euler, 1 ms). Top: b = (0.2, −0.1, 0.3, 0), the accelerations align at c (dashed). Bottom: b = (0.8, −0.96, 1.2, −0.6), with Σ b_i/a_i = 0, the agents stop with the predicted offsets (dashed).

The paper: c≈0.0796c \approx 0.0796, and static offsets L†diag⁡(ai)−1bL^\dagger\operatorname{diag}(a_i)^{-1}b for the second bias. The run: the accelerations at t=20t = 20 are (0.079592, 0.079592, 0.079592, 0.079592) against cc = 0.0796, and the offsets at t=20t = 20 are (0.2000, −0.3750, 0.2500, −0.0750) against (0.2000, −0.3750, 0.2500, −0.0750). It matches, up to the 10−910^{-9} of Section 7.

10.6 Fig. 10: Lemma 2

The paper’s Fig. 10, run again. Left: F_1(−η_1) and F_2(−η_2), and the level y* where the two disagreements add up to zero (circles). Right: the sum T(y) of the preimage intervals; it moves down as y grows and contains 0 exactly at y*.

The flat piece of F2F_2 at 0 gives a vertical segment of T(y)T(y) at y=0y = 0, and the saturation at sup⁡ℛ=0.8\sup\mathcal{R} = 0.8 another one; neither contains 0, and the crossing is at y*y^* = -0.1140, as in the paper’s figure.

11 What changes with more agents, and what the page does not cover

  • Any connected graph. Theorems 1 to 3 and Proposition 3 hold on every connected graph, for any number of agents [proved]. The playground flies twenty drones on a ring with three neighbours on each side; that the predictions match there too is [numerical].
  • States in the plane. The paper treats scalar states. Its Remark 1 says that with axis-wise shifts and a common orientation of the agents’ frames, a state in ℝd\mathbb{R}^d is dd scalar problems over the same graph [proved]. This page does not simulate states in the plane.
  • Where the clusters form. Theorem 2 says that clusters share a velocity, not which clusters form or at which velocities; the paper says so (Remark 4) [open]. The closed form of Section 5.2.1 works for the triangle because agent 2 saturates both its links.
  • Saturated or dead-zone sensing. Theorem 3 needs every sensor to stay responsive. Global alignment with saturating sensors is left for future work in the paper [open].
  • Discontinuous actuators. On-off thrusters are not Lipschitz and are outside Assumption 2; the paper covers them only through a velocity-tracking loop that obeys the hypotheses (Remark 1) [open].
  • Higher order. The page reproduces the linear second-order example [proved] for linear shifts; nonlinear shifts on second-order agents are not covered [open].
  • The simulator. Euler steps of 1 ms with velocities held for one tick. The limits of Theorems 1 and 3 and of Proposition 3 are fixed points of the Euler map too, so the discretisation does not move them [numerical], and the maximum principle holds at every step of every run on this page [numerical].

12 Glossary

symbol meaning
xix_i the state of agent ii (a position, a phase)
zij=xi−xjz_{ij} = x_i - x_j the relative state that agent ii measures of neighbour jj
ψij\psi_{ij}, sft⁡ij\operatorname{sft}_{ij} the sensing map of agent ii on its measurement of jj
FiF_i, sft⁡i\operatorname{sft}_i the actuation map of agent ii: input in, velocity out
SFT\operatorname{SFT} the stacked maps, SFT⁡(u)=(F1(u1),…,FN(uN))\operatorname{SFT}(u) = (F_1(u_1), \dots, F_N(u_N))
a,h,ba, h, b the scale, horizontal shift and vertical shift of a shift function
ℓi,ℓo\ell^{\mathrm i}, \ell^{\mathrm o} the positive and negative orientations of edge ℓ\ell
B,Bo,BiB, B^{\mathrm o}, B^{\mathrm i} incidence, out-incidence and in-incidence matrices, B=Bo+BiB = B^{\mathrm o} + B^{\mathrm i}
L=BB⊤L = BB^\top the Laplacian
η=Lx\eta = Lx the disagreement vector; its entries add up to zero
RiR_i, ℛ\mathcal R the range of FiF_i, and the common range ⋂iRi\bigcap_i R_i (Assumption 3)
y*y^* the unique compatible velocity of Lemma 2
η‾\bar\eta the limit of η\eta; the offsets are L†η‾L^\dagger\bar\eta
Π\Pi the projection that removes the average, I−𝟏𝟏⊤/NI - \mathbf{1}\mathbf{1}^\top/N
v¯,v_,S\overline v, \underline v, S the largest and smallest velocity, and the spread S=v¯−v_S = \overline v - \underline v
𝒢a\mathcal G_a the active graph: edges with infinite accumulated sensitivity (Theorem 2)
KK the paired-sensitivity constant (eq. (18))
κ_,κ¯\underline\kappa, \overline\kappa the bounds on the slopes of the sensing maps (Assumption 4)
γ\gamma the certified contraction factor of Theorem 3
L̃\tilde L, vv the weighted Laplacian of the linear case, and its left null vector
P1,P2P_1, P_2 the projections onto the drift and onto the distortion (Proposition 3)
cc the drift velocity of the linear case, v⊤b/v⊤𝟏v^\top b/v^\top\mathbf 1