-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdirect.tex
4126 lines (3968 loc) · 152 KB
/
direct.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
In this chapter we show how to construct a set of reversible rules
and their forward and backward rate constants from an energy function.
In the spirit of rule-based modelling languages like Kappa
where rules and observables are defined in terms of patterns,\footnote{
Recall that a pattern is a contact map used to find subgraphs in states.}
we use a set of connected \emph{energy patterns} $\shapes$
for our energy function.
We assign an \emph{energy cost} $\cost(g)$ to each of them
and build the energy function as a linear combination
of their number of ocurrences. % of each energy pattern.
\begin{equation}
\label{eq:graph-energy}
E(m) = \sum_{g \in \shapes} \cost(g) \abs{\matches{g}{m}}
\end{equation}
This is reminiscent of group contribution methods
used to estimate the standard Gibbs free energy of formation
of biomolecules \citep{group-contrib}.
As mentioned at the end of \sct{kappa},
we will derive the set of rules with detailed balance
from a set of generator rules $\generators$ (without rates).
We suppose that $\generators$ is closed under
rule inversion, \ie $\generators = \inv{\generators}$.
Given a contact graph $C$,
a simple option would be to include
every possible minimal rule in this set,
that is, include a creation and a destruction rule
for each edge in the contact graph.
Each of these rules is minimal in the sense that
it only asks for the presence of
the two participating agents and sites.
The example rule in \sct{kappa}
(page~\pageref{p:example}) %, redisplayed below for convenience)
where agents of type $1$ and $2$ bind
% in whatever context,
% whatever the context,
% in whatever context they are,
% in whatever context they happen to be,
% regardless of the surrounding context,
regardless of the context
% in which they happen to be
% in which these two agents happen to be,
% which we denote here by $r^+_{12}$,
is one such minimal rule
that can be derived from the contact graph $T$.
We call this rule $r^+_{12}$.
\begin{equation}
\label{eq:r+12}
r^+_{12} :=\;\; %\resizebox{.37\linewidth}{!}{%
\tikz[thick,baseline=-.1cm]{
\node[grphnode] (lhs) at (0,0) {
\tikz[ingrphdiag]{
\begin{scope}[shift={(0,0)}]
\n[n1]{x}{0,0};
\e{x}{.5,0};
\site{rx}{x.east};
\node at (26:.42) {\scriptsize $r$};
\end{scope}
\begin{scope}[shift={(1.2,0)}]
\n[n2]{y}{0,0};
\e{y}{-.5,0};
\site{ly}{y.west};
\node at (206:.42) {\scriptsize $l$};
\end{scope}
}};
\path (lhs.east) +(.3,0) edge[rule] +(1,0)
+(1.3,0) coordinate (r);
\node[grphnode,anchor=west] (rhs) at (r) {
\tikz[ingrphdiag]{
\e{0,0}{1.1,0};
\begin{scope}
\n[n1]{x}{0,0};
\site{rx}{x.east};
\node at (26:.42) {\scriptsize $r$};
\end{scope}
\begin{scope}[shift={(1.1,0)}]
\n[n2]{y}{0,0};
\site{ly}{y.west};
\node at (206:.42) {\scriptsize $l$};
\end{scope}
}};
}%}
\end{equation}
This option is \emph{maximally permissive}
% as every possible transformation
% allowed by the contact graph
% is allowed by $\generators$.\footnote{
with respect to the contact graph.\footnote{
Intuitively, this is analogous to the case of classical mechanics
% where the topology of the space gives us the possible transformations
where, a priori, movement is not constrained along any coordinate.}
Even if all transformations are possible,
many of them may be unlikely due to having a high energy.
Still one might prefer to forbid certain transformations
in some scenarios.
This is indeed the case in the example
that will be presented in \sct{alloring}.
In our previous example (\sct{kappa}),
we might want to favour the formation of
triangles over chains and other cycles.
For this we give a negative energy cost to the triangle $t$,
\ie $\cost(t) < 0$.
If $t$ is the only energy pattern,
then the energy of a state $m$ is
$E(m) = \cost(t) \abs{\matches{t}{m}}$.
In this model one might, for instance,
wonder how low the energy cost of $t$ must be
to have at least $90\%$ of all agents in a triangle
at equilibrium at least $90\%$ of the time.
We would like to find rules that have detailed balance
with respect to this energy function.
Consider the rule $r^+_{12}$ and its inverse $r^-_{12}$,
the unbinding of agents $1$ and $2$.
% Given the maximally permissive set of generator rules
% $\generators=\set{r^+_{12},r^-_{12},r^+_{23},r^-_{23},r^+_{31},r^-_{31}}$,
% we first ask ourselves if these reversible rules
We first ask ourselves if this pair of rules
could have detailed balance
for some assignment of kinetic rates.
% to the forward and backward rule.
Suppose we assign kinetic rates $k^+$ and $k^-$
to $r^+_{12}$ and $r^-_{12}$.
Recall from \sct{bg} that $\exp{E(n)-E(m)} = q_{nm}/q_{mn}$
for systems with detailed balance.
From \eqn{kappa-ctmc}
\[ q_{mn} = \sum_{\substack{r \in \generators\\r = \tuple{r_L,r_R}}}
k(r) \; \abs{\setof{\psi \in \matches{r_L}{m}}{m^{(r,\psi)} = n}}
\]
where $m^{(r,\psi)}$ is the outcome of rewriting $m$
% using rule $r$ and embedding $\psi$.
with event $(r,\psi)$.
% It is clear that
At most one of the two rules
can bring us from state $m$ to $n$,
say it is $r^+_{12}$.
By rule reversibility (\lem{reversibility})
$r^-_{12}$ brings us from $n$ back to $m$
and the number of matches of $r^-_{12}$ in $n$
is equal to the number of matches of $r^+_{12}$ in $m$.
Hence, $\exp{E(n)-E(m)} = k^+/k^-$.
In words, the change in energy produced by the rule application
fixes the ratio between the kinetic rates.
As a consequence,
each rule application should produce the same energy change
for there to be an assignment of kinetic rates with detailed balance.
Whenever a rule produces the same energy change
regardless of where it is applied
we say that the rule has an \emph{unambiguous energy balance}
or is $\shapes$-balanced.
More generally, we define $\shapes$-balance as follows.
\begin{definition}
Given a contact graph $C$
and a set $\shapes$ of contact maps over $C$,
a rule $r$ is $\shapes$-balanced
if, for all mixtures $m$ and embeddings $\psi: r_L \to m$,
the number of ocurrences of $p \in \shapes$
produced and consumed by $r$ when applied to $\psi$
is a fixed number
$\Delta_r p = |[p;m^{(r,\psi)}]| - \abs{\matches{p}{m}}$.
% is a fixed number $\Delta_r p$,
% \ie $|[p;m^{(r,\psi)}]| - \abs{\matches{p}{m}} = \Delta_r p\;$
% for all $p \in \shapes$.
We refer to $\Delta_r p$ as the balance of $r$ with respect to $p$.
% We refer to the vector of ocurrence changes as $\Delta_r \shapes$.
\end{definition}
% TODO: perhaps add a remark about unambiguous stoichiometry
The following two rule applications show that
$r^+_{12}$ is not $\shapes$-balanced.
\begin{center}
\resizebox{.9\linewidth}{!}{%
\begin{tikzpicture}[thick]
% first row
\node[grphnode,anchor=east] (lhs1) at (0,0) {
\tikz[ingrphdiag]{
\begin{scope}[shift={(0,0)}]
\n[n1]{x}{0,0};
\e{x}{.5,0};
\site{rx}{x.east};
\node at (26:.42) {\scriptsize $r$};
\end{scope}
\begin{scope}[shift={(1.2,0)}]
\n[n2]{y}{0,0};
\e{y}{-.5,0};
\site{ly}{y.west};
\node at (206:.42) {\scriptsize $l$};
\end{scope}
}};
\path (lhs1.east) +(.3,0) edge[rule,dotted] +(1,0)
+(1.3,0) coordinate (r1);
\node[grphnode,anchor=west] (rhs1) at (r1) {
\tikz[ingrphdiag]{
\e{0,0}{1.1,0};
\begin{scope}
\n[n1]{x}{0,0};
\site{rx}{x.east};
\node at (26:.42) {\scriptsize $r$};
\end{scope}
\begin{scope}[shift={(1.1,0)}]
\n[n2]{y}{0,0};
\site{ly}{y.west};
\node at (206:.42) {\scriptsize $l$};
\end{scope}
}};
% second column
\node[grphnode,anchor=east] (lhs2) at (9,0) {
\tikz[ingrphdiag]{
\begin{scope}[shift={(0,0)}]
\n[n1]{x}{0,0};
\e{x}{.5,0};
\site{rx}{x.east};
\node at (26:.42) {\scriptsize $r$};
\end{scope}
\begin{scope}[shift={(1.2,0)}]
\n[n2]{y}{0,0};
\e{y}{-.5,0};
\site{ly}{y.west};
\node at (206:.42) {\scriptsize $l$};
\end{scope}
}};
\path (lhs2.east) +(.3,0) edge[rule,dotted] +(1,0)
+(1.3,0) coordinate (r2);
\node[grphnode,anchor=west] (rhs2) at (r2) {
\tikz[ingrphdiag]{
\e{0,0}{1.1,0};
\begin{scope}
\n[n1]{x}{0,0};
\site{rx}{x.east};
\node at (26:.42) {\scriptsize $r$};
\end{scope}
\begin{scope}[shift={(1.1,0)}]
\n[n2]{y}{0,0};
\site{ly}{y.west};
\node at (206:.42) {\scriptsize $l$};
\end{scope}
}};
% second row
\path (lhs1.south) +(0,-.2) edge[rule] +(0,-.6);
\node[grphnode,anchor=east] (lhs3) at (0,-2) {
\tikz[ingrphdiag]{
\begin{scope}[shift={(0,0)}]
\n[n1]{x}{0,0};
\e{x}{.5,0};
\e{x}{-.5,0};
\site{lx}{x.west};
\site{rx}{x.east};
\node at (206:.42) {\scriptsize $l$};
\node at (26:.42) {\scriptsize $r$};
\end{scope}
\e{1.2,0}{2.3,0};
\begin{scope}[shift={(1.2,0)}]
\n[n2]{y}{0,0};
\e{y}{-.5,0};
\site{ly}{y.west};
\site{ry}{y.east};
\node at (206:.42) {\scriptsize $l$};
\node at (26:.42) {\scriptsize $r$};
\end{scope}
\begin{scope}[shift={(2.3,0)}]
\n[n3]{z}{0,0};
\e{z}{.5,0};
\site{lz}{z.west};
\site{rz}{z.east};
\node at (206:.42) {\scriptsize $l$};
\node at (26:.42) {\scriptsize $r$};
\end{scope}
}};
\path (lhs3.east) +(.3,0) edge[rule,dotted] +(1,0)
+(1.3,0) coordinate (r3);
\path (rhs1.south) +(0,-.2) edge[rule] +(0,-.6);
\node[grphnode,anchor=west] (rhs3) at (r3) {
\tikz[ingrphdiag]{
\e{0,0}{2.2,0};
\begin{scope}[shift={(0,0)}]
\n[n1]{x}{0,0};
\e{x}{-.5,0};
\site{lx}{x.west};
\site{rx}{x.east};
\node at (206:.42) {\scriptsize $l$};
\node at (26:.42) {\scriptsize $r$};
\end{scope}
\begin{scope}[shift={(1.1,0)}]
\n[n2]{y}{0,0};
\site{ly}{y.west};
\site{ry}{y.east};
\node at (206:.42) {\scriptsize $l$};
\node at (26:.42) {\scriptsize $r$};
\end{scope}
\begin{scope}[shift={(2.2,0)}]
\n[n3]{z}{0,0};
\e{z}{.5,0};
\site{lz}{z.west};
\site{rz}{z.east};
\node at (206:.42) {\scriptsize $l$};
\node at (26:.42) {\scriptsize $r$};
\end{scope}
}};
% second row, second column
\path (lhs2.south) +(0,-.2) edge[rule] +(0,-.6);
\node[grphnode,anchor=east] (lhs4) at (9,-2.4) {
\tikz[ingrphdiag]{
\path[use as bounding box] (-.3,.38) rectangle (1.5,-1.22);
\e{0,0}{-56.944:1.1};
\e{0:1.2}{-56.944:1.1};
\begin{scope}[shift={(0,0)}]
\n[n1]{x}{0,0};
\e{x}{.5,0};
\site{r1}{0:7pt};
\site{l1}{-60:7pt};
\node at (-86:12pt) {\scriptsize $l$};
\node at (26:12pt) {\scriptsize $r$};
\end{scope}
\begin{scope}[shift={(0:1.2)}]
\n[n2]{y}{0,0};
\e{y}{-.5,0};
\site{r2}{180:7pt};
\site{l2}{-120:7pt};
\node at (154:12pt) {\scriptsize $l$};
\node at (-94:12pt) {\scriptsize $r$};
\end{scope}
\begin{scope}[shift={(-56.944:1.1)}]
\n[n3]{z}{0,0};
% angle is 66.111 deg
\site{r3}{123.0555:7pt};
\site{l3}{56.9445:7pt};
\node at (146:12pt) {\scriptsize $r$};
\node at (34:12pt) {\scriptsize $l$};
\end{scope}
}};
\path (lhs4.east) +(.3,0) edge[rule,dotted] +(1,0)
+(1.3,0) coordinate (r4);
\path (rhs2.south) +(0,-.2) edge[rule] +(0,-.6);
\node[grphnode,anchor=west] (rhs4) at (r4) {
\tikz[ingrphdiag]{
\path[use as bounding box] (-.3,.38) rectangle (1.4,-1.22);
\e{0,0}{0:1.1};
\e{0,0}{-60:1.1};
\e{0:1.1}{-60:1.1};
\begin{scope}[shift={(0,0)}]
\n[n1]{x}{0,0};
\site{r1}{0:7pt};
\site{l1}{-60:7pt};
\node at (-86:12pt) {\scriptsize $l$};
\node at (26:12pt) {\scriptsize $r$};
\end{scope}
\begin{scope}[shift={(0:1.1)}]
\n[n2]{y}{0,0};
\site{r2}{180:7pt};
\site{l2}{-120:7pt};
\node at (154:12pt) {\scriptsize $l$};
\node at (-94:12pt) {\scriptsize $r$};
\end{scope}
\begin{scope}[shift={(-60:1.1)}]
\n[n3]{z}{0,0};
\site{r3}{120:7pt};
\site{l3}{60:7pt};
\node at (146:12pt) {\scriptsize $r$};
\node at (34:12pt) {\scriptsize $l$};
\end{scope}
}};
\end{tikzpicture}}
\end{center}
We see that, while the application on the left
does not produce any change in energy ($\Delta E = 0$),
the one on the right creates a triangle
and thus $\Delta E = \cost(t)$. %\footnote{
% And we won't tolerate energetical ambiguity in this house!}
We must then split $r^+_{12}$ into subrules that check
the surroundings of the rule application
to make sure that, for instance,
every application of such a subrule
creates one triangle or none at all.
It is important that the partition of the rule
has certain properties.
In particular, one would like that every match of the rule
can be mapped to exactly one match of one of the subrules.
Prior work by \citet{refinement} has shown how
one can obtain a partition of rules with this property
and will be presented, in a slightly modified version,
in \sct{refinements}. % the next section.
% NOTE: not possible to put refinement section
% before minimal glueings because the proof of the
% unique decomposition theorem uses minimal glueings.
But before diving into rule partitioning,
or rule refinement as we call it,
it would be good to have a more rigourous idea of
when a rule is $\shapes$-balanced or not.
In the examples shown above we see that
our energy pattern, the triangle,
must be fully incorporated into
the left- or the right-hand side of the rule
to be sure it produces or consumes it in every application.
On the other hand, a rule that is incompatible
with our energy pattern will also be $\shapes$-balanced
by making it impossible for the rule to match a triangle.
This is true whenever there is no glueing % union
of the left-hand side of a rule with the energy pattern
where they overlap in a site that is modified by the rule.
In the next section,
we introduce the concept of overlapping glueings
of contact maps by means of multi-sums,
a concept related to local coproducts and relative pushouts.
% in $\rSGe_C$.
\section{Minimal glueings}
\label{sec:mg}
The category $\SG$ has all pullbacks,
constructed from those in $\Set$,
and they indeed restrict to $\rSGe_C$.
\begin{lemma}\label{lemma:pullbacks}
Given a cospan $\phi_1: g_1 \to h \gets g_2 :\phi_2$ in $\rSGe_C$
there is a unique span $\psi_1: g_1 \gets p \to g_2 :\psi_2$
(up to unique isomorphism)
such that any span $\omega_1: g_1 \gets q \to g_2 :\omega_2$
that forms a commuting square $\omega_1,\omega_2,\phi_1,\phi_2\;$
factors \emph{uniquely} through it.
\begin{center}
\begin{tikzpicture}
\node (h1) at (0,0) {$g_1$};
\node (h2) at (6,0) {$g_2$};
\node (h) at (3,-1) {$h$};
\node (p) at (3,1) {$p$};
\node (q) at (3,2.2) {$q$};
\draw (q) edge[hom,bend right=20] node[above left] {$\omega_1$} (h1);
\draw (q) edge[hom,bend left=20] node[above right] {$\omega_2$} (h2);
\draw[hom] (p) -- node[above] {$\psi_1$} (h1);
\draw[hom] (p) -- node[above] {$\psi_2$} (h2);
\draw[hom] (h1) -- node[below] {$\phi_1$} (h);
\draw[hom] (h2) -- node[below] {$\phi_2$} (h);
\draw[hom,dotted] (q) -- node[right] {$!$} (p);
\end{tikzpicture}
\end{center}
\end{lemma}
\begin{proof}
We construct contact map $p: G \to C$ by taking the intersection
of the agents, sites and edges in the image of $\phi_1,\phi_2$
and restricting $\sitemap$ accordingly.
With some abuse of notation, we have
\begin{alignat*}{3}
\agents_G & {}= \phi_{1,\agents}(\agents_{\anon{g_1}}) & {}\cap{} &
\,\phi_{2,\agents}(\agents_{\anon{g_2}}) \\
\sites_G & {}= \,\phi_{1,\sites}(\sites_{\anon{g_1}}) & {}\cap{} &
\,\,\phi_{2,\sites}(\sites_{\anon{g_2}}) \\
\edges_G & {}= \,\phi_{1,\sites}(\edges_{\anon{g_1}}) & {}\cap{} &
\,\,\phi_{2,\sites}(\edges_{\anon{g_2}})
\end{alignat*}
and $\sitemap_G = \rest{\sitemap_{\anon{h}}}{\sites_G}$.
Functions $p_\agents,p_\sites$ are the restriction of
$h_\agents,h_\sites$ to $\agents_G,\sites_G$, respectively.
Embeddings $\psi_1$ and $\psi_2$ map agents and sites
in $G$ to their pre-images along $\phi_1$ and $\phi_2$;
by construction, all agents and sites in $G$
are guaranteed to have such a pre-image.
It is easy to see that
(i) $\psi_1$ and $\psi_2$ are type-preserving
and thus embeddings in $\rSGe_C$; and that
(ii) the square formed by $\psi_1,\psi_2,\phi_1,\phi_2$ commutes.
Consider any span $\omega_1: g_1 \gets q \to g_2 :\omega_2$ in $\rSGe_C$.
If the square formed by $\omega_1$, $\omega_2,\phi_1,\phi_2$ commutes,
then $q$ can have at most one copy of each agent and site
in the intersection of the images of $\phi_1$ and $\phi_2$
because $\phi_1\,\omega_1$ and $\phi_2\,\omega_2$ are injective.
Hence, every agent and site in the image of $\omega_1,\omega_2$
has a \emph{unique} pre-image along $\psi_1,\psi_2$, respectively,
with the same type.
This fixes a pair of functions $\omega_\agents,\omega_\sites$
that map agents and sites in $q$ to those in $p$ injectively
and form an embedding $\omega$ in $\rSGe_C$.
Since the pre-image along $\psi_1,\psi_2$ always exists and is unique,
any embedding $\omega': p \to q$ must be equal to $\omega$
whenever $\phi_1\,\omega' = \omega_1$ and
$\phi_2\,\omega' = \omega_2$.
\end{proof}
$\SG$ also has all pushouts and all sums,
but these do not in general restrict to $\rSGe_C$,
just as pushouts and sums in $\Set$ do not restrict to
the subcategory of injective functions.
% all pushouts; but these do not generally restrict to $\rSGe_C$ since
% (i) the pushout object need not be realisable,
% even if all objects in the starting span were;
% (ii) the arrows in the resulting cospan need not be embeddings,
% even if all arrows in the starting span were;
% and (iii) the mediating arrow need not even be injective
% (on agents or sites).
However, $\rSGe_C$ has \emph{multi-sums}.
\begin{lemma}\label{lemma:mg}
For all pairs of contact maps over $C$,
$g_1: G_1 \to C$ and $g_2: G_2 \to C$,
% there exists a finite set $I$ and a family of cospans ... with i \in I
there exists a finite family of cospans
$\theta^i_1: g_1 \to s_i \gets g_2 :\theta^i_2$,
such that any cospan $\phi_1: g_1 \to h \gets g_2 :\phi_2\;$
factors through \emph{exactly one} of the family
and does so \emph{uniquely}.
\begin{center}
\begin{tikzpicture}
\node (h1) at (0,0) {$g_1$};
\node (si) at (1.8,0) {$s_i$};
\node (h2) at (3.6,0) {$g_2$};
\node (h) at (1.8,-1.8) {$h$};
\draw[hom] (h1) -- node[above] {$\theta^i_1$} (si);
\draw[hom] (h2) -- node[above] {$\theta^i_2$} (si);
\draw[hom] (h1) -- node[below left] {$\phi_1$} (h);
\draw[hom] (h2) -- node[below right] {$\phi_2$} (h);
\draw[hom,dotted] (si) -- node[right] {$!$} (h);
\end{tikzpicture}
\end{center}
\end{lemma}
\begin{proof}
Take subsets $A_i$ of the cartesian product
of $\agents_{\anon{g_1}}$ and $\agents_{\anon{g_2}}$
that have each agent of $g_1$ and $g_2$ at most once
($(a,b) \in A_i \wedge (a,b') \in A_i \then b = b'$)
and where each pair $(a,b) \in A_i$ has the same type,
% that are type-compatible,
\ie $g_{1,\agents}(a) = g_{2,\agents}(b)$.
% for all $(a,b) \in A_i$,
To each $A_i$ assign all subsets $S_{ij}$ of
$\sites_{\anon{g_1}} \times \sites_{\anon{g_2}}$
that are type-compatible
and whose elements belong to agents paired in $A_i$,
that is, if $(x,y) \in S_{ij}$
then $g_{1,\sites}(x) = g_{2,\sites}(y)$
and $(\sitemap_{\anon{g_1}}(x),\sitemap_{\anon{g_2}}(y)) \in A_i$.
% Note that the latter predicate fixes ...
Note how this fixes a mapping $\sitemap_{ij}$
between elements of $S_{ij}$ to elements of $A_i$
defined by
$\sitemap_{ij}((x,y)) =
(\sitemap_{\anon{g_1}}(x),\sitemap_{\anon{g_2}}(y))$.
% Discard all sets $S_ij$ that are subsets
% of a set $S_jk$ with $j \neq k$.
For each $A_i$ keep only the set $S_{ij}$
that is a superset of all other sets $S_{ik}$ ($k \neq j$).
% and discard all others.
There must be one such maximal set because
if any two pairs of sites $(x_1,y_1),(x_2,y_2)$
are type-preserving and belong to the same agents,
then there will be one set among the $S_{ij}$s that has both
and thus $\{S_{ij}\}_j$ is a directed partial order
for the inclusion relation.
% Hence, we can drop the $j$ subscript
% in $S_{ij}$ and $\sitemap_{ij}$.
Let $S_i$ be the maximal element of $\{S_{ij}\}_j$,
which exists by directedness and finiteness of this family,
and $\sitemap_i$ the corresponding mapping to $A_i$.
Intuitively, the maximal set $S_i$ is the set of all sites
that are defined in both agents at the same time.
Next we discard those pairs $A_i,S_i$
whose elements do not agree on their edge structure;
if $(x,y) \in S_i$ then either both sites must be free
or connected to sites $(x',y') \in S_i$.
We construct a family of contact maps $p_i: P_i \to C$
using $\agents_{P_i} = A_i$ as its agents,
$\sites_{P_i} = S_i$ as its sites,
$\sitemap_{P_i} = \sitemap_i$ and
$\edges_{P_i} = \{((x_1,y_1), (x_2,y_2)) \in S_i \times S_i \st
x_1 \edges_{\anon{g_1}} x_2 \wedge
y_1 \edges_{\anon{g_2}} y_2\}$.
Functions $p_{i,\agents},p_{i,\sites}$
are defined straightforwardly.
Spans $\psi^i_1: g_1 \gets p_i \to g_2 :\psi^i_2$
are then obtained by mapping agents $(a,b)$ in $p_i$
to $a$ in $g_1$ and $b$ in $g_2$
and similarly for sites.
Multi-sums $\theta^i_1: g_1 \to s_i \gets g_2 :\theta^i_2$
are pushouts of such spans:
they are obtained by adding to $p_i$
all the missing agents, sites and edges from $g_1$ and $g_2$.
Since all sites that are in $g_1$ but not in $p_i$
cannot be in $g_2$ by maximality of $S_i$,
there can be no conflict when adding sites or edges.
The same argument holds for sites in $g_2$ that are not in $p_i$.
Note that the family $A_i$ is finite
and thus the family of multi-sums is finite as well.
Also, it is easy to see that the spans $\psi^i_1,\psi^i_2$
are pullbacks of $\theta^i_1,\theta^i_2$.
Hence, (isomorphism classes of) multi-sums
are in a one-to-one correspondence
with (isomorphism classes of) pullbacks.
This implies that there is only one multi-sum
that factors any given cospan.
\end{proof}
The pairs $\theta^i_1,\theta^i_2$ enumerate
all minimal ways in which one can glue $g_1$ and $g_2$.
% and thus all the minimal contexts in which they can occur.
Hence, we refer to them as minimal glueings.
%
The notion of multi-sum dates back to \citet{diers}.
% We call them \emph{minimal glueings} in $\rSGe_C$
% according to their intuition in this concrete context
% and use them in \sct{energy-gp} to construct balanced rules.
% TODO: elaborate on relation to RPOs
They are very close to relative pushouts \citep{leifer}
and will be used in the same way,
to minimise rewriting contexts.
Indeed, each minimal glueing $i$
in the family of cospans $\theta^i_1,\theta^i_2$
accounts for one minimal rewriting context.
To illustrate how this construction operates,
consider the minimal glueings of the following
two contact maps over $T$ % (the triangle)
with their respective pullbacks.
% as shown in the following diagram.
\input{mg}
I have implemented an online tool that computes minimal glueings
available at \url{https://rhz.github.com/thesis/mg.html}.
Its source code can be found at \url{https://github.com/rhz/thesis/}.
Using minimal glueings we can test whether
a rule $r$ is $\shapes$-balanced,
that is, whether $r$ consumes and produces
the same number of instances of each energy pattern $p$
when applied to any mixture $m$.
In particular, for an $r$-event $\psi$
to \emph{consume} an instance $\phi$ of $p$ in a mixture $m$,
$\phi_\sites$ and $\psi_\sites$ must have images
which intersect on at least one site which is modified by $r$
(\eg by adding an edge if it was free). % or removing its edge).
% Otherwise the energy pattern is left intact by the action of the rule.
This is the case iff
the minimal glueing $\phi',\psi'$ of $r_L$ and $p$
\begin{wrapfigure}[5]{r}{0.41\textwidth}
\vspace{-1.8em}
\begin{equation}
\label{eq:p-balanced}
\tikz[baseline=-1.1cm]{
% \begin{center}
% \begin{tikzpicture}
\node (p) at (0,0) {$p$};
\node (s) at (1.8,0) {$s$};
\node (l) at (3.6,0) {$r_L$};
\node (m) at (1.8,-1.8) {$m$};
\draw[hom] (p) -- node[above] {$\phi'$} (s);
\draw[hom] (l) -- node[above] {$\psi'$} (s);
\draw[hom] (p) -- node[below left] {$\phi$} (m);
\draw[hom] (l) -- node[below right] {$\psi$} (m);
\draw[hom,dotted] (s) -- (m);}
% \end{tikzpicture}
% \end{center}
\end{equation}
\end{wrapfigure}
that factors the cospan $\phi,\psi$ has the same property.
Likewise, for an $r$-event to \emph{produce} an instance of $p$,
the associated minimal glueing between $p$ and $r_R$
must have a modified intersection.
We call such minimal glueings \emph{relevant}.
% ; they are the ones which underlie events
% that can affect the instances of $p$.
To illustrate the idea of relevant minimal glueings,
let us consider a different example.
In this example, the contact graph is very simple:
just one agent type with two sites, $l$ and $r$,
that can bind each other.
% The maximally permissive set of generators rules
% contains only one reversible rule.
% One extension of this rule is
Imagine we have the following reversible rule.
\begin{center}
\begin{tikzpicture}[thick]
\node[grphnode,anchor=east] (lhs1) at (0,0) {
\tikz[ingrphdiag]{
\e{0,0}{2.2,0};
\begin{scope}
\n[n]{x}{0,0};
\site{rx}{x.east};
\node at (26:.42) {\scriptsize $r$};
\end{scope}
\begin{scope}[shift={(1.1,0)}]
\n[n]{y}{0,0};
\site{ly}{y.west};
\site{ry}{y.east};
\node at (206:.42) {\scriptsize $l$};
\node at (26:.42) {\scriptsize $r$};
\end{scope}
\begin{scope}[shift={(2.2,0)}]
\n[n]{z}{0,0};
\site{lz}{z.west};
\node at (206:.42) {\scriptsize $l$};
\end{scope}
}};
\path (lhs1.east) +(.3,0) edge[rule] +(1,0)
+(1.3,0) coordinate (r1);
\node[grphnode,anchor=west] (rhs1) at (r1) {
\tikz[ingrphdiag]{
\e{1.1,0}{2.3,0};
\begin{scope}[shift={(0,0)}]
\n[n]{x}{0,0};
\e{x}{.5,0};
\site{rx}{x.east};
\node at (26:.42) {\scriptsize $r$};
\end{scope}
\begin{scope}[shift={(1.2,0)}]
\n[n]{y}{0,0};
\e{y}{-.5,0};
\site{ly}{y.west};
\site{ry}{y.east};
\node at (206:.42) {\scriptsize $l$};
\node at (26:.42) {\scriptsize $r$};
\end{scope}
\begin{scope}[shift={(2.3,0)}]
\n[n]{z}{0,0};
\site{lz}{z.west};
\node at (206:.42) {\scriptsize $l$};
\end{scope}
}};
\end{tikzpicture}
\end{center}
Take the chain of 3 agents as our energy pattern.
The minimal glueings of the left-hand side of the rule
with the energy pattern are shown below.
On the left of each diagram is the energy pattern.
The relevant minimal glueings are marked
with a light green background.
\input{relevant-mg}
An online tool to compute relevant minimal glueings
can be found at \url{https://rhz.github.com/thesis/rmg.html}.
% and its source code at \url{https://github.com/rhz/thesis/}.
Whenever $\psi': r_L \to s$ in \diagram{p-balanced} is an iso,
then the energy pattern $p$ is fully included % contained
in the left-hand side of rule $r$.
This implies the rule contains all the relevant context needed
to make sure that an instance of $p$ is consumed
by any $r$-event $\psi: r_L \to m$.
We say that $r$ is $\shapes$-\emph{left-balanced} iff,
for all $p \in \shapes$ and relevant minimal glueings
$\theta^i_1: p \to s_i \gets r_L :\theta^i_2$,
the right leg $\theta^i_2$ is an isomorphism.
Symmetrically, one says that $r$ is $\shapes$-\emph{right-balanced}
iff $\inv{r}$ is $\shapes$-left-balanced.
Then $r$ is $\shapes$-\emph{balanced}
iff it is $\shapes$-left- and $\shapes$-right-balanced.
% TODO: where should this lemma be cited?
\begin{lemma}
Rule $r$ is $\shapes$-balanced if and only if
$r$ is $\shapes$-left- and $\shapes$-right-balanced.
Moreover, if $r$ is $\shapes$-balanced then,
for any mixture $m$, embedding $\psi: r_L \to m$,
and energy pattern $p \in \shapes$,
\[ \Delta_r p = |[p;m^{(r,\psi)}]| % \abs{\matches{p}{\comatch{m}}}
- \abs{\matches{p}{m}}
= \abs{\matches{p}{r_R}}
- \abs{\matches{p}{r_L}} \]
\end{lemma}
\begin{proof}
Suppose there are two mixtures $m$, $n$
and embeddings $\psi: r_L \to m$, $\phi: r_L \to n$
such that, when $r$ is applied to $\psi$ and $\phi$,
it has a different balance
with respect to a pattern $p \in \shapes$,
\ie $|[p;m^{(r,\psi)}]| - \abs{\matches{p}{m}} \neq
|[p;n^{(r,\phi)}]| - \abs{\matches{p}{n}}$.
%
We have
\begin{equation*}
\abs{\matches{p}{m}} = |\{p \to m \getsby{\psi} r_L\}|
= \abs{\set{\tikz[baseline=-.6cm,x=1.2cm,y=1.2cm]{
\node (p) at (0,0) {$p$};
\node (s) at (1,0) {$s$};
\node (l) at (2,0) {$r_L$};
\node (m) at (1,-1) {$m$};
\draw[hom] (p) -- (s);
\draw[hom] (p) -- (m);
\draw[hom] (l) -- (s);
\draw[hom] (l) -- node[below right] {$\psi$} (m);
\draw[hom,dotted] (s) -- (m);}}}
\end{equation*}
where $p \to s \gets r_L$ is the minimal glueing
that factors the cospan $p \to m \getsby{\psi} r_L$.
A similar equality can be obtained for $r_R$,
$m^{(r,\psi)}$ and $\comatch{\psi}$.
%
The \emph{irrelevant} minimal glueings on each side of the rule
are in bijection: the rule does not destroy nor create them.
Hence, when taking the difference
$|[p;m^{(r,\psi)}]| - \abs{\matches{p}{m}}$
they cancel each other out and we are left with
a difference of \emph{relevant} minimal glueings on each side.
%
Since $s \iso r_L$ for each relevant minimal glueing on the left
then
\begin{equation*}
\abs{\set{\tikz[baseline=-.6cm,x=1.2cm,y=1.2cm]{
\node (p) at (0,0) {$p$};
\node (s) at (1,0) {$s$};
\node (l) at (2,0) {$r_L$};
\node (m) at (1,-1) {$m$};
\draw[hom] (p) -- (s);
\draw[hom] (p) -- (m);
\path (l) -- node[onarrow] {$\iso$} (s);
\draw[hom] (l) -- node[below right] {$\psi$} (m);
\draw[hom,dotted] (s) -- (m);}}}
= \abs{\matches{p}{r_L}}
\end{equation*}
Again, a similar equality can be obtained for $r_R$,
$m^{(r,\psi)}$ and $\comatch{\psi}$.
Thus we have proved that
$|[p;m^{(r,\psi)}]| - \abs{\matches{p}{m}} =
\abs{\matches{p}{r_R}} - \abs{\matches{p}{r_L}}$
for any $m$ and $\psi$,
contradicting our original assumption.
\end{proof}
\section{Refinements}
\label{sec:refinements}
A rule is refined into another rule by adding context.
For example, we can add a common neighbour
to the agents in $r^+_{12}$ to obtain a refinement.
% \begin{center}
% \begin{tikzpicture}
\begin{equation}
\label{eq:refined1}
\tikz[baseline=-.16cm]{
\node[grphnode,anchor=east] (lhs) at (0,0) {
\tikz[ingrphdiag]{
\path[use as bounding box] (-.3,.38) rectangle (1.5,-1.22);
\e{0,0}{-56.944:1.1};
\e{0:1.2}{-56.944:1.1};
\begin{scope}[shift={(0,0)}]
\n[n1]{x}{0,0};
\e{x}{.5,0};
\site{r1}{0:7pt};
\site{l1}{-60:7pt};
\node at (-86:12pt) {\scriptsize $l$};
\node at (26:12pt) {\scriptsize $r$};
\end{scope}
\begin{scope}[shift={(0:1.2)}]
\n[n2]{y}{0,0};
\e{y}{-.5,0};
\site{r2}{180:7pt};
\site{l2}{-120:7pt};
\node at (154:12pt) {\scriptsize $l$};
\node at (-94:12pt) {\scriptsize $r$};
\end{scope}
\begin{scope}[shift={(-56.944:1.1)}]
\n[n3]{z}{0,0};
% angle is 66.111 deg
\site{r3}{123.0555:7pt};
\site{l3}{56.9445:7pt};
\node at (146:12pt) {\scriptsize $r$};
\node at (34:12pt) {\scriptsize $l$};
\end{scope}
}};
\path (lhs.east) +(.3,0) edge[rule] +(1,0)
+(1.3,0) coordinate (r);
\node[grphnode,anchor=west] (rhs) at (r) {
\tikz[ingrphdiag]{
\path[use as bounding box] (-.3,.38) rectangle (1.4,-1.22);
\e{0,0}{0:1.1};
\e{0,0}{-60:1.1};
\e{0:1.1}{-60:1.1};
\begin{scope}[shift={(0,0)}]
\n[n1]{x}{0,0};
\site{r1}{0:7pt};
\site{l1}{-60:7pt};
\node at (-86:12pt) {\scriptsize $l$};
\node at (26:12pt) {\scriptsize $r$};
\end{scope}
\begin{scope}[shift={(0:1.1)}]
\n[n2]{y}{0,0};
\site{r2}{180:7pt};
\site{l2}{-120:7pt};
\node at (154:12pt) {\scriptsize $l$};
\node at (-94:12pt) {\scriptsize $r$};
\end{scope}
\begin{scope}[shift={(-60:1.1)}]
\n[n3]{z}{0,0};
\site{r3}{120:7pt};
\site{l3}{60:7pt};
\node at (146:12pt) {\scriptsize $r$};
\node at (34:12pt) {\scriptsize $l$};
\end{scope}
}};
}
\end{equation}
% \end{tikzpicture}
% \end{center}
This refinement happens to be $\shapes$-balanced.
Another refinement of $r^+_{12}$ could be
% \begin{center}
% \begin{tikzpicture}
\begin{equation}
\label{eq:refined2}
\tikz[baseline=-.16cm]{
\node[grphnode,anchor=east] (lhs) at (0,0) {
\tikz[ingrphdiag]{
\begin{scope}[shift={(0,0)}]
\n[n1]{x}{0,0};
\e{x}{.5,0};
\site{rx}{x.east};
\node at (26:.42) {\scriptsize $r$};
\end{scope}
\begin{scope}[shift={(1.2,0)}]
\n[n2]{y}{0,0};
\e{y}{-.5,0};
\e{y}{.5,0};
\site{ly}{y.west};
\site{ry}{y.east};
\node at (206:.42) {\scriptsize $l$};
\node at (26:.42) {\scriptsize $r$};
\end{scope}
}};
\path (lhs.east) +(.3,0) edge[rule] +(1,0)
+(1.3,0) coordinate (r);
\node[grphnode,anchor=west] (rhs) at (r) {
\tikz[ingrphdiag]{
\e{0,0}{1.1,0};
\begin{scope}
\n[n1]{x}{0,0};
\site{rx}{x.east};
\node at (26:.42) {\scriptsize $r$};
\end{scope}
\begin{scope}[shift={(1.1,0)}]
\n[n2]{y}{0,0};
\e{y}{.5,0};
\site{ly}{y.west};
\site{ry}{y.east};
\node at (206:.42) {\scriptsize $l$};
\node at (26:.42) {\scriptsize $r$};
\end{scope}
}};
}
\end{equation}
% \end{tikzpicture}
% \end{center}
Here we have added a free site to the blue node.
This second refinement is also $\shapes$-balanced
because the free $r$ site on the blue node guarantees that
(i) the rule will never create a triangle and
(ii) there is no embedding from the left-hand side
into a triangle and hence no triangle can be destroyed
by the action of the rule.
The following refinement, however, is not $\shapes$-balanced.
\begin{center}
\begin{tikzpicture}
\node[grphnode,anchor=east] (lhs) at (0,0) {
\tikz[ingrphdiag]{
\begin{scope}[shift={(0,0)}]
\n[n1]{x}{0,0};
\e{x}{.5,0};
\site{rx}{x.east};
\node at (26:.42) {\scriptsize $r$};
\end{scope}
\e{1.2,0}{2.3,0};
\begin{scope}[shift={(1.2,0)}]
\n[n2]{y}{0,0};
\e{y}{-.5,0};
\site{ly}{y.west};
\site{ry}{y.east};
\node at (206:.42) {\scriptsize $l$};
\node at (26:.42) {\scriptsize $r$};
\end{scope}
\begin{scope}[shift={(2.3,0)}]
\n[n3]{z}{0,0};
\site{lz}{z.west};
\node at (206:.42) {\scriptsize $l$};
\end{scope}
}};
\path (lhs.east) +(.3,0) edge[rule] +(1,0)
+(1.3,0) coordinate (r);
\node[grphnode,anchor=west] (rhs) at (r) {
\tikz[ingrphdiag]{
\e{0,0}{2.2,0};
\begin{scope}[shift={(0,0)}]
\n[n1]{x}{0,0};
\site{rx}{x.east};
\node at (26:.42) {\scriptsize $r$};
\end{scope}
\begin{scope}[shift={(1.1,0)}]
\n[n2]{y}{0,0};
\site{ly}{y.west};
\site{ry}{y.east};
\node at (206:.42) {\scriptsize $l$};
\node at (26:.42) {\scriptsize $r$};
\end{scope}
\begin{scope}[shift={(2.2,0)}]
\n[n3]{z}{0,0};
\site{lz}{z.west};