-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprops.dtx
2470 lines (2470 loc) · 85.8 KB
/
props.dtx
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
%
% \iffalse driver
%<*driver>
\documentclass{mtmtcl}
\usepackage{amsmath}
\providecommand*{\mc}[1]{\ensuremath{\mathcal{#1}}}
\providecommand*{\Fpil}{\longrightarrow}
\providecommand*{\cross}[2]{{}^{#1}\mathsf{X}^{#2}}
\providecommand*{\heads}[1]{\ensuremath{{}_{#1}}}
\providecommand*{\tails}[1]{\ensuremath{{}^{#1}}}
\providecommand*{\theads}[1]{\heads{\text{#1}}}
\providecommand*{\ttails}[1]{\tails{\text{#1}}}
\begin{document}
\DocInput{props.dtx}
\PrintIndex
\end{document}
%</driver>
% \fi
%
% \title{PROPs and matrices}
% \author{Lars Hellstr\"om}
% \date{2008/09/23--}
% \maketitle
%
%
% \begin{abstract}
% This file collects an interface for PROPs and matrix
% implementations of these.
% \end{abstract}
%
%
% \section{The interface}
%
% \begin{APIspec}{PROP}{1.0}
% A \textbf{PROP} is a special case of a symmetric monoidal
% category in which the type of an element is uniquely determined
% by its arity and coarity. PROPs are not assumed to be algebraic,
% so there need not be a linear structure, but implementations are
% welcome to provide one when possible.
%
% PROPs are single-sorted structures, but elements can be of
% different types, and not all operations are valid for all type
% combinations. PROPs also make heavy use of permutations.
%
% Following tradition, version~1.0 of this interface only provides
% binary operations and injection of permutations. Higher versions
% provide more user-friendly operations.
% \begin{APIdescription}{PROP}
% \begin{APImethod}{=}
% \word{element} \word{element}
% \end{APImethod}
% This method fulfills the \APIref+{equality}{1.0} interface.
%
% \begin{APImethod}{arity}
% \word{element}
% \end{APImethod}
% \begin{APImethod}{coarity}
% \word{element}
% \end{APImethod}
% Return the arity and coarity respectively of the
% \word{element}. These are nonnegative integers and together
% they determine the type of the element. They are both
% congruent, which conversely means elements of different
% types must never be equal.
%
% \begin{APImethod}{*}
% \word{element} \word{element}
% \end{APImethod}
% This is the composition operation. If $a$ and $b$ are
% elements of a PROP $\mc{P}$ such that \texttt{[$\mc{P}$ arity
% $a$]${}={}$[$\mc{P}$ coarity $b$]} then \texttt{[$\mc{P}$ *
% $a$ $b$]} returns an element with arity \texttt{[$\mc{P}$ arity
% $b$]} and coarity \texttt{[$\mc{P}$ coarity $a$]}, otherwise
% it throws an error with |-errorcode|
% \begin{displaysyntax}
% API PROP typenomatch
% \end{displaysyntax}
% See below for the axioms a composition operation must
% satisfy.
%
% \begin{APImethod}{permutation}
% \word{permutation}
% \end{APImethod}
% Returns the PROP element corresponding to the permutation
% \word{permutation}. The arity and coarity of this element are
% both equal to the list-length of the \word{permutation}.
%
% \begin{APImethod}{tensor}
% \word{element} \word{element}
% \end{APImethod}
% This is the tensor product operation, which is defined for
% arbitrary pairs of \word{element}s. The arity and coarity of
% the result is the sum of the arities and coarities
% respectively of the factors.
% \end{APIdescription}
%
% Naturally, these methods satisfy the axioms for a PROP $\mc{P}$,
% namely the following:
% \begin{description}
% \item[Composition associativity]
% For any \(a,b,c \in \mc{P}\), the following are |=|-equal
% if they do not throw an error:
% \begin{displaysyntax}
% [$\mc{P}$ * [$\mc{P}$ * $a$ $b$] $c$]\par
% [$\mc{P}$ * $a$ [$\mc{P}$ * $b$ $c$]]
% \end{displaysyntax}
% \item[Composition identity]
% Let \(a \in \mc{P}\) be arbitrary, let $\sigma$ be the
% identity permutation of length \texttt{[$\mc{P}$ coarity $a$]},
% and let $\tau$ be the identity permutation of length
% \texttt{[$\mc{P}$ arity $a$]}. Then the following are
% |=|-equal:
% \begin{displaysyntax}
% [$\mc{P}$ * [$\mc{P}$ permutation $\sigma$] $a$]\par
% $a$\par
% [$\mc{P}$ * $a$ [$\mc{P}$ permutation $\tau$]]
% \end{displaysyntax}
% \item[Tensor associativity]
% For any \(a,b,c \in \mc{P}\), the following are |=|-equal:
% \begin{displaysyntax}
% [$\mc{P}$ tensor [$\mc{P}$ tensor $a$ $b$] $c$]\par
% [$\mc{P}$ tensor $a$ [$\mc{P}$ tensor $b$ $c$]]
% \end{displaysyntax}
% \item[Tensor identity]
% For any \(a \in \mc{P}\), the following are |=|-equal:
% \begin{displaysyntax}
% [$\mc{P}$ tensor [$\mc{P}$ permutation \{\}] $a$]\par
% $a$\par
% [$\mc{P}$ tensor $a$ [$\mc{P}$ permutation \{\}]]
% \end{displaysyntax}
% \item[Permutation composition]
% The following are |=|-equal for all permutations $\sigma$ and
% $\tau$ of equal length:
% \begin{displaysyntax}
% [$\mc{P}$ permutation $\sigma\tau$]\par
% [$\mc{P}$ * [$\mc{P}$ permutation $\sigma$]
% [$\mc{P}$ permutation $\tau$]]
% \end{displaysyntax}
% \item[Permutation tensor]
% The following are |=|-equal for all permutations $\sigma$ and
% $\tau$:
% \begin{displaysyntax}
% [$\mc{P}$ permutation $\sigma \star \tau$]\par
% [$\mc{P}$ tensor [$\mc{P}$ permutation $\sigma$]
% [$\mc{P}$ permutation $\tau$]]
% \end{displaysyntax}
% where $\star$ denotes the juxtaposition of two permutations,
% i.e.,
% \begin{equation*}
% (\sigma \star \tau)(i) = \begin{cases}
% \sigma(i)& \text{if \(i<n\),}\\
% n + \tau(i-n)& \text{otherwise}
% \end{cases}
% \qquad\text{where $n$ is the length of $\sigma$.}
% \end{equation*}
%
% \item[Tensor crossing]
% For all \(a,b \in \mc{P}\), the following are |=|-equal:
% \begin{displaysyntax}
% [$\mc{P}$ * [$\mc{P}$ permutation $\cross{k}{m}$]
% [$\mc{P}$ tensor $a$ $b$]]\par
% [$\mc{P}$ * [$\mc{P}$ tensor $b$ $a$]
% [$\mc{P}$ permutation $\cross{l}{n}$]]
% \end{displaysyntax}
% where $k$ is the coarity of $a$, $l$ is the arity of $a$, $m$
% is the coarity of $b$, and $n$ is the arity of $b$. The
% symbol $\cross{m}{n}$ stands for the permutation of $m+n$
% elements which switches places between an $m$-group and an
% $n$-group, i.e.,
% \begin{equation*}
% \cross{m}{n}(i) = \begin{cases}
% i+n& \text{if \(0 \leqslant i<m\),}\\
% i-m& \text{if \(m \leqslant i<m+n\).}
% \end{cases}
% \end{equation*}
%
% \item[Tensor--composition compatibility]
% For all \(a,b,c,d \in \mc{P}\) such that the arity of $a$ is
% equal to the coarity of $b$ and the arity of $c$ is equal to
% the coarity of $d$, the following are |=|-equal:
% \begin{displaysyntax}
% [$\mc{P}$ tensor [$\mc{P}$ * $a$ $b$]
% [$\mc{P}$ * $c$ $d$]]\par
% [$\mc{P}$ * [$\mc{P}$ tensor $a$ $c$]
% [$\mc{P}$ tensor $b$ $d$]]
% \end{displaysyntax}
% \end{description}
% \end{APIspec}
%
% \begin{APIspec}{PROP}{1.1}
% Version 1.1 of the |PROP| interface adds methods for the left and
% right actions of permutations on PROP elements, and also for
% taking the tensor product with an identity. These are often
% convenient and can have faster implementations than composition
% with a permutation element.
%
% \begin{APIdescription}{PROP}
% \begin{APImethod}{perm.}
% \word{permutation} \word{element}
% \end{APImethod}
% This method performs the left action of permutation
% operation. It returns a PROP element of the same type as the
% \word{element} if the list-length of the \word{permutation}
% is equal to the coarity of the \word{element}, and throws an
% error with |-errorcode|
% \begin{displaysyntax}
% API PROP typenomatch
% \end{displaysyntax}
% otherwise.
%
% \begin{APImethod}{.perm}
% \word{element} \word{permutation}
% \end{APImethod}
% This method performs the right action of permutation
% operation. It returns a PROP element of the same type as the
% \word{element} if the list-length of the \word{permutation}
% is equal to the arity of the \word{element}, and throws an
% error with |-errorcode|
% \begin{displaysyntax}
% API PROP typenomatch
% \end{displaysyntax}
% otherwise.
%
% \begin{APImethod}{tensorpad}
% \word{element} \word{integer}
% \end{APImethod}
% This method returns the tensor product of the \word{element}
% by the identity of arity and coarity \word{integer}. This can
% often be constructed merely by copying data.
% \end{APIdescription}
%
% For any version 1.1 PROP $\mc{P}$, any element \(a \in \mc{P}\),
% and any two permutations $\sigma$ and $\tau$ which have
% list-lengths equal to the coarity and arity respectively of $a$,
% the two expressions
% \begin{displaysyntax}
% [$\mc{P}$ perm. $\sigma$ $a$]\par
% [$\mc{P}$ * [$\mc{P}$ permutation $\sigma$] $a$]
% \end{displaysyntax}
% are |=|-equal, as are
% \begin{displaysyntax}
% [$\mc{P}$ .perm $a$ $\tau$]\par
% [$\mc{P}$ * $a$ [$\mc{P}$ permutation $\tau$]]
% \end{displaysyntax}
% Finally, if $\iota$ is the identity permutation of length $n$
% then the two expressions
% \begin{displaysyntax}
% [$\mc{P}$ tensorpad $a$ $n$]\par
% [$\mc{P}$ tensor $a$ [$\mc{P}$ permutation $\iota$]]
% \end{displaysyntax}
% are |=|-equal.
% \end{APIspec}
%
% \begin{APIspec}{PROP}{2.0}
% Version~2 of |PROP| does not obsolete version~1, but rather
% introduces the PROP concept starting from a different fundamental
% operation |fuse|: the kind of products used with numeric style
% tensors, combined with Einstein summation convention contractions
% on repeated indices. This operation can be used to implement tensor
% product (no contraction), composition (contraction on all inputs
% of first factor, which are also the outputs of the second
% factor), and permutations (empty product), but the converse is
% possible too.
%
% \begin{APIdescription}{PROP}
% \begin{APImethod}{=}
% \word{element} \word{element}
% \end{APImethod}
% This method fulfills the \APIref+{equality}{1.0} interface.
%
% \begin{APImethod}{arity}
% \word{element}
% \end{APImethod}
% \begin{APImethod}{coarity}
% \word{element}
% \end{APImethod}
% Return the arity and coarity respectively of the
% \word{element}. These are nonnegative integers and together
% they determine the type of the element. They are both
% congruent, which conversely means elements of different
% types must never be equal.
%
% \begin{APImethod}{fuse}
% \word{heads out} \begin{regblock}[\regstar] \word{tails}
% \word{element} \word{heads} \end{regblock} \word{tails in}
% \end{APImethod}
% This method returns the (numeric tensor style) product of
% the given \word{element}s, contracted on repeated indices
% according to the Einstein summation convention. The
% \word{heads} and \word{tails} are all lists of ``index
% labels'', which can be arbitrary strings.
%
% For
% \begin{displaysyntax}
% \(b :={}\)[\meta{PROP} fuse $h_{\mathrm{out}}$
% $t_1$ $a_1$ $h_1$ $\dots$ $t_n$ $a_n$ $h_n$
% $t_{\mathrm{in}}$]
% \end{displaysyntax}
% one has that
% \begin{align*}
% \texttt{[\meta{PROP} arity $b$]} ={}&
% \texttt{[llength $t_{\mathrm{in}}$]} \\
% \texttt{[\meta{PROP} coarity $b$]} ={}&
% \texttt{[llength $h_{\mathrm{out}}$]}
% \end{align*}
% and the basic syntactic restrictions on this call are that
% \begin{align*}
% \texttt{[\meta{PROP} coarity $a_i$]} ={}&
% \texttt{[llength $t_i$]}
% && \text{for \(1 \leqslant i \leqslant n\),}\\
% \texttt{[\meta{PROP} arity $a_i$]} ={}&
% \texttt{[llength $h_i$]}
% && \text{for \(1 \leqslant i \leqslant n\),}\\
% h_{\mathrm{out}} \mathbin{\dot{\cup}}
% \bigcup_{1 \leqslant i \leqslant n}^\bullet h_i ={}&
% t_{\mathrm{in}} \mathbin{\dot{\cup}}
% \bigcup_{1 \leqslant i \leqslant n}^\bullet t_i
% \end{align*}
% where $\dot{\cup}$ denotes disjoint union, i.e., every index
% label occurring anywhere must occur exactly once in a
% heads-list and once in a tails-list. Whenever any of these
% restrictions is violated, this method throws
% an error with |-errorcode|
% \begin{displaysyntax}
% API PROP typenomatch
% \end{displaysyntax}
%
% There is also a restriction that there must be a partial
% order $P$ on the set of all labels such that if \(e \in t_i\)
% and \(f \in h_i\) for some \(i=1,\dotsc,n\) then \(e < f
% \mathrel{\mathrm{in}} P\). This restriction is necessary for
% the result of the |fuse| method to be expressible in terms of
% the |PROP| version~1.0 operations, but it is not required
% that violations of it throw an error, since some PROPs can
% support contraction of cycles (a.k.a.~``trace map'').
% \end{APIdescription}
%
% In order for a command prefix \mc{P} to satisfy this interface,
% it must fulfill five axioms on equality and |fuse|.
% For any injection $f$, the expressions
% \begin{displaysyntax}
% [$\mc{P}$ fuse $h_{\mathrm{out}}$ $t_1$ $a_1$ $h_1$ $\dots$
% $t_n$ $a_n$ $h_n$ $t_{\mathrm{in}}$]\par
% [$\mc{P}$ fuse $f(h_{\mathrm{out}})$ $f(t_1)$ $a_1$ $f(h_1)$
% $\dots$ $f(t_n)$ $a_n$ $f(h_n)$ $f(t_{\mathrm{in}})$]
% \end{displaysyntax}
% are |=|-equal.
%
% For any permutation \(\sigma\colon \{1,\dotsc,n\} \Fpil
% \{1,\dotsc,n\}\), the two expressions
% \begin{displaysyntax}
% [$\mc{P}$ fuse $h_{\mathrm{out}}$ $t_1$ $a_1$ $h_1$ $\dots$
% $t_n$ $a_n$ $h_n$ $t_{\mathrm{in}}$]\par
% [$\mc{P}$ fuse $h_{\mathrm{out}}$ $t_{\sigma(1)}$ $a_{\sigma(1)}$
% $h_{\sigma(1)}$ $\dots$ $t_{\sigma(n)}$ $a_{\sigma(n)}$
% $h_{\sigma(n)}$ $t_{\mathrm{in}}$]
% \end{displaysyntax}
% are |=|-equal.
%
% For any \(a \in \mc{P}\) and lists $h$ and $t$, the two
% expressions
% \begin{displaysyntax}
% [$\mc{P}$ fuse $h$ $h$ $a$ $t$ $t$]\par
% $a$
% \end{displaysyntax}
% are |=|-equal whenever the former exists.
%
% Let \word{left} and \word{right} be lists of the form
% \begin{quote}
% \begin{regblock}[\regstar] \word{tails} \word{element}
% \word{head} \end{regblock}
% \end{quote}
% Let $L_i$ and $M_i$ for \(i=0,1,2,3\) be arbitrary lists.
% Whenever both of
% \begin{displaysyntax}
% [\mc{P} fuse $L_0$ \meta{left} \meta{right} $L_2$]\par
% [\mc{P} fuse $M_0$
% $M_0$ [\mc{P} fuse $L_0$ \meta{left} $L_1$] $M_1$
% \linebreak[1]
% $M_1$ [\mc{P} fuse $L_1$ \meta{right} $L_2$] $M_2$
% $M_2$]
% \end{displaysyntax}
% are syntactically correct, they are |=|-equal. Similarly whenever
% both of
% \begin{displaysyntax}
% [\mc{P} fuse [concat $L_0$ $L_1$]
% \meta{left} \meta{right} [concat $L_2$ $L_3$]]\par
% [\mc{P} fuse [concat $M_0$ $M_1$]
% $M_0$ [\mc{P} fuse $L_0$ \meta{left} $L_2$] $M_2$
% \linebreak[1]
% $M_1$ [\mc{P} fuse $L_1$ \meta{right} $L_3$] $M_3$
% [concat $M_2$ $M_3$]]
% \end{displaysyntax}
% are syntactically correct, they are |=|-equal.
%
% \iffalse
%
% The expressions
% \begin{displaysyntax}
% [$\mc{P}$ fuse $h_{\mathrm{out}}$
% $t_0$ [$\mc{P}$ fuse $\sigma$ $\iota$] $h_0$
% $t_1$ $a_1$ $h_1$ $\dots$
% $t_n$ $a_n$ $h_n$ $t_{\mathrm{in}}$]\par
% [$\mc{P}$ fuse $f(h_{\mathrm{out}})$ $f(t_1)$ $a_1$ $f(h_1)$
% $\dots$ $f(t_n)$ $a_n$ $f(h_n)$ $f(t_{\mathrm{in}})$]
% \end{displaysyntax}
% are |=|-equal for
% \begin{equation*}
% f(e) = \begin{cases}
% \texttt{[lindex $h_0$ $i$]}&
% \text{if \(e = \texttt{[lindex $t_0$ $\sigma(i)$]}\),}\\
% e& \text{otherwise}
% \end{cases}
% \end{equation*}
% where $\sigma$ is a permutation, $\iota$ is an identity
% permutation, and $t_0$, $\sigma$, $\iota$, and $h_0$ all have the
% same list-length.
%
% \iffalse
% For all lists $h_0,\dotsc,h_{n+m}$ and $t_0,\dotsc,t_{n+m}$ such
% that
% \begin{equation*}
% h_{\mathrm{out}} \mathbin{\dot{\cup}}
% \bigcup_{1 \leqslant i \leqslant n+m}^\bullet h_i =
% t_{\mathrm{in}} \mathbin{\dot{\cup}}
% \bigcup_{1 \leqslant i \leqslant n+m}^\bullet t_i
% \text{,}
% \end{equation*}
% \fi
% The two expressions
% \begin{displaysyntax}
% [$\mc{P}$ fuse $h_{\mathrm{out}}$ $t_1$ $a_1$ $h_1$ $\dots$
% $t_{n+m}$ $a_{n+m}$ $h_{n+m}$ $t_{\mathrm{in}}$]\par
% [$\mc{P}$ fuse $h_{\mathrm{out}}$
% $h_0$ [$\mc{P}$ fuse $h_0$ $t_1\ a_1\ h_1$ $\dots$
% $t_n$ $a_n$ $h_n$ $t_0$] $t_0$
% $t_{n+1}\ a_{n+1}\ h_{n+1}$ $\dots$
% $t_{n+m}\ a_{n+m}\ h_{n+m}$
% $t_{\mathrm{in}}$]
% \end{displaysyntax}
% are |=|-equal whenever both exist.
%
% \fi
% \end{APIspec}
%
% \begin{APIspec}{PROP}{2.1}
% Version~2.1 of |PROP| extends version~2.0 with the methods needed
% to support \APIref+{PROP}{1.1}. (That it always will support also
% that version of the interface is the subject of a theorem below;
% this is just the definition.)
%
% In order to specify the methods, it is convenient to employ a
% generic list constructor for the labels. To that end, define
% \begin{quote}
% \MacroFont
% |proc E {n args} {|\\
% | set res {}|\\
% | for {set k 0} {$k<$n} {incr k} {|\\
% | lappend res [linsert $args 0 $k]|\\
% | }|\\
% | return $res|\\
% |}|
% \end{quote}
% which however will be ``called'' using mathematical notation, so
% instead of \texttt{[E $n$]}${}={}$`|0 1 |\dots~$n{-}1$' it's
% $E(n)$, and instead of \texttt{[E $m$ 7]}${}={}$`|{0 7} {1 7} |\dots
% |{|$m{-}1$| 7}|' it's $E(m,7)$, etc.
% Also, the convention is used to write head arguments in a
% subscript position and tail arguments in a superscript
% position\Dash not attached to anything; just not on the standard
% baseline. This helps clarify the structure of expressions.
% \begin{APIdescription}{PROP}
% \begin{APImethod}{*}
% \word{element} \word{element}
% \end{APImethod}
% This is the composition operation, defined by the condition
% that
% \begin{displaysyntax}
% [\meta{PROP} * $a$ $b$]\par
% [\meta{PROP} fuse \heads{E(l,1)}
% \tails{E(l,1)} $a$ \heads{E(m,2)}
% \tails{E(m,2)} $b$ \heads{E(n,3)} \tails{E(n,3)}]
% \end{displaysyntax}
% are |=|-equal when $l$ is the coarity of $a$, $m$ is is the
% arity of $a$ and coarity of $b$, and $n$ is the arity of $b$.
%
% \begin{APImethod}{permutation}
% \word{permutation}
% \end{APImethod}
% Returns the PROP element corresponding to the permutation
% \word{permutation}, i.e., the two expressions
% \begin{displaysyntax}
% [\meta{PROP} permutation $\sigma$]\par
% [\meta{PROP} fuse \heads{E(n)} \tails{\sigma}]
% \end{displaysyntax}
% are |=|-equal for every permutation $\sigma$ of list-length
% $n$.
%
% \begin{APImethod}{tensor}
% \word{element} \word{element}
% \end{APImethod}
% This is the tensor product operation, which is defined for
% arbitrary pairs of \word{element}s by the condition that
% \begin{displaysyntax}
% [\meta{PROP} tensor $a$ $b$]\par
% [\meta{PROP} fuse [concat $E(k,1)$ $E(m,3)$]
% $\tails{E(k,1)}\ a\ \heads{E(l,2)}$
% $\tails{E(m,3)}\ b\ \heads{E(n,4)}$
% [concat $E(l,2)$ $E(n,4)$]]
% \end{displaysyntax}
% are |=|-equal when $k$ is the coarity of $a$, $l$ is is the
% arity of $a$, $m$ is the coarity of $b$, and $n$ is the
% arity of $b$.
%
% \end{APIdescription}
%
% \end{APIspec}
%
% \begin{theorem}
% That a structure $\mc{P}$ satisfies \APIref+{PROP}{2.1} implies
% that it satisfies \APIref+{PROP}{1.1}.
% \end{theorem}
% \begin{proof}
% This is simply a routine verification that one set of axioms
% follows from the other. In the interest of some brevity, the
% definitions are implicitly combined with the relabelling axiom
% so that the head- and tail-lists need not be exactly the $E(n,k)$
% in the definition statement.
%
% Composition associativity follows from the stepwise |=|-equality
% of:
% \begin{displaysyntax}
% [\mc{P} * [\mc{P} * $a$ $b$] $c$]\par
% [\mc{P} * [\mc{P} fuse $E(k,1)$ $E(k,1)$ $a$ $E(l,2)$
% $E(l,2)$ $b$ $E(m,3)$ $E(m,3)$] $c$]\par
% [\mc{P} fuse $E(k,1)$
% $E(k,1)$ [\mc{P} fuse $E(k,1)$ $E(k,1)$ $a$ $E(l,2)$
% $E(l,2)$ $b$ $E(m,3)$ $E(m,3)$] $E(m,3)$
% $E(m,3)$ $c$ $E(n,4)$ $E(n,4)$]\par
% [\mc{P} fuse $E(k,1)$
% $E(k,1)$ $a$ $E(l,2)$
% $E(l,2)$ $b$ $E(m,3)$
% $E(m,3)$ $c$ $E(n,4)$ $E(n,4)$]\par
% [\mc{P} fuse $E(k,1)$
% $E(l,2)$ $b$ $E(m,3)$
% $E(m,3)$ $c$ $E(n,4)$
% $E(k,1)$ $a$ $E(l,2)$ $E(n,4)$]\par
% [\mc{P} fuse $E(k,1)$
% $E(l,2)$ [\mc{P} fuse $E(l,2)$ $E(l,2)$ $b$ $E(m,3)$
% $E(m,3)$ $c$ $E(n,4)$ $E(n,4)$] $E(n,4)$
% $E(k,1)$ $a$ $E(l,2)$ $E(n,4)$]\par
% [\mc{P} fuse $E(k,1)$
% $E(l,2)$ [\mc{P} * $b$ $c$] $E(n,4)$
% $E(k,1)$ $a$ $E(l,2)$ $E(n,4)$]\par
% [\mc{P} fuse $E(k,1)$ $E(k,1)$ $a$ $E(l,2)$
% $E(l,2)$ [\mc{P} * $b$ $c$] $E(n,4)$ $E(n,4)$]\par
% [\mc{P} * $a$ [\mc{P} * $b$ $c$]]
% \end{displaysyntax}
% Composition identity follows from the stepwise |=|-equalities of
% \begin{displaysyntax}
% [\mc{P} * $a$ [\mc{P} permutation $E(n)$]]
%
% [\mc{P} * $a$ [\mc{P} fuse $E(n)$ $E(n)$]]
%
% [\mc{P} fuse $E(1,m)$ $E(1,m)$ $a$ $E(2,n)$
% $E(2,n)$ [\mc{P} fuse $E(n)$ $E(n)$] $E(3,n)$ $E(3,n)$]
%
% [\mc{P} fuse $E(1,m)$ $E(1,m)$ $a$ $E(3,n)$ $E(3,n)$]
%
% $a$
%
% [\mc{P} fuse $E(2,m)$ $E(2,m)\ a\ E(3,n)$ $E(3,n)$]
%
% [\mc{P} fuse $E(1,m)$
% $E(1,m)$ [\mc{P} fuse $E(m)$ $E(m)$] $E(2,m)$
% $E(2,m)\ a\ E(3,n)$ $E(3,n)$]
%
% [\mc{P} * [\mc{P} fuse $E(m)$ $E(m)$] $a$]
%
% [\mc{P} * [\mc{P} permutation $E(m)$] $a$]
% \end{displaysyntax}
% where $m$ and $n$ are the coarity and arity respectively of $a$.
%
% Tensor-permutation compatibility follows from the stepwise
% |=|-equality of
% \begin{displaysyntax}
% [\mc{P} * [\mc{P} permutation $\cross{k}{m}$]
% [\mc{P} tensor $a$ $b$]]
%
% [\mc{P} *
% [\mc{P} permutation $\cross{k}{m}$]
% [\mc{P} fuse [concat $E(1,k)$ $E(3,m)$]
% $E(1,k)\ a\ E(2,l)$ $E(3,m)\ b\ E(4,n)$
% [concat $E(2,l)$ $E(4,n)$]]]
%
% [\mc{P} fuse $E(0,k+m)$
% $E(0,k+m)$ [\mc{P} permutation $\cross{k}{m}$]
% [concat $E(1,k)$ $E(3,m)$]
% [concat $E(1,k)$ $E(3,m)$]
% [\mc{P} fuse [concat $E(1,k)$ $E(3,m)$]
% $E(1,k)\ a\ E(2,l)$ $E(3,m)\ b\ E(4,n)$
% [concat $E(2,l)$ $E(4,n)$]]
% [concat $E(2,l)$ $E(4,n)$]
% [concat $E(2,l)$ $E(4,n)$]]
%
% [\mc{P} fuse $E(0,k+m)$
% $E(0,k+m)$ [\mc{P} permutation $\cross{k}{m}$]
% [concat $E(1,k)$ $E(3,m)$]
% $E(1,k)\ a\ E(2,l)$
% $E(3,m)\ b\ E(4,n)$
% [concat $E(2,l)$ $E(4,n)$]]
%
% [\mc{P} fuse $E(0,k+m)$
% $E(0,k+m)$
% [\mc{P} fuse [concat $E(3,m)$ $E(1,k)$]
% [concat $E(1,k)$ $E(3,m)$]]
% [concat $E(1,k)$ $E(3,m)$]
% $E(1,k)\ a\ E(2,l)$
% $E(3,m)\ b\ E(4,n)$
% [concat $E(2,l)$ $E(4,n)$]]
%
% [\mc{P} fuse [concat $E(3,m)$ $E(1,k)$]
% $E(1,k)\ a\ E(2,l)$
% $E(3,m)\ b\ E(4,n)$
% [concat $E(2,l)$ $E(4,n)$]]
%
% [\mc{P} fuse [concat $E(3,m)$ $E(1,k)$]
% $E(3,m)\ b\ E(4,n)$
% $E(1,k)\ a\ E(2,l)$
% [concat $E(2,l)$ $E(4,n)$]]
%
% [\mc{P} fuse [concat $E(3,m)$ $E(1,k)$]
% $E(3,m)\ b\ E(6,n)$
% $E(1,k)\ a\ E(5,l)$
% [concat $E(6,n)$ $E(5,l)$]
% [\mc{P} fuse [concat $E(4,n)$ $E(2,l)$]
% [concat $E(2,l)$ $E(4,n)$]]
% [concat $E(2,l)$ $E(4,n)$]
% [concat $E(2,l)$ $E(4,n)$]]
%
% [\mc{P} fuse [concat $E(3,m)$ $E(1,k)$]
% $E(3,m)\ b\ E(6,n)$
% $E(1,k)\ a\ E(5,l)$
% [concat $E(6,n)$ $E(5,l)$]
% [\mc{P} permutation $\cross{l}{n}$]
% [concat $E(2,l)$ $E(4,n)$]
% [concat $E(2,l)$ $E(4,n)$]]
%
% [\mc{P} fuse [concat $E(3,m)$ $E(1,k)$]
% [concat $E(3,m)$ $E(1,k)$]
% [\mc{P} fuse [concat $E(3,m)$ $E(1,k)$]
% $E(3,m)\ b\ E(6,n)$
% $E(1,k)\ a\ E(5,l)$
% [concat $E(6,n)$ $E(5,l)$]]
% [concat $E(6,n)$ $E(5,l)$]
% [concat $E(6,n)$ $E(5,l)$]
% [\mc{P} permutation $\cross{l}{n}$]
% [concat $E(2,l)$ $E(4,n)$]
% [concat $E(2,l)$ $E(4,n)$]]
%
% [\mc{P} *
% [\mc{P} fuse [concat $E(3,m)$ $E(1,k)$]
% $E(3,m)\ b\ E(6,n)$
% $E(1,k)\ a\ E(5,l)$
% [concat $E(6,n)$ $E(5,l)$]]
% [\mc{P} permutation $\cross{l}{n}$]]
%
% [\mc{P} *
% [\mc{P} tensor $b$ $a$]
% [\mc{P} permutation $\cross{l}{n}$]]
%
% \end{displaysyntax}
% \end{proof}
%
%
% \section{Trivial matrix implementation}
%
% The trivial matrix implementation of |PROP| has the coarity and
% arity equal to the number of rows and columns respectively of the
% matrix. This is not the algebraic definition (since the tensor
% product is not bilinear), but it is a good test case.
%
% \begin{ensemble}[mtmtcl::matprop]{trivial}
% This implementation of a |PROP| is as the command prefix
% \begin{displaysyntax}
% mtmtcl::matprop::trivial any \word{ring}
% \end{displaysyntax}
% where the base command is an ensemble with two parameters
% \word{shape} (which is ignored) and \word{ring} (which must be
% a \APIref{ring}{1.0} and \APIref{monoid}{1.0}).
% \begin{tcl}
%<*pkg>
package require Tcl 8.6a3
if {[namespace which tailcall] eq ""} then {
interp alias {} tailcall {} tcl::unsupported::tailcall
}
if {[catch {lrepeat 0 x}]} then {
rename lrepeat mtmtcl::matprop::_lrepeat
proc lrepeat {count args} {
if {$count>0} then {mtmtcl::matprop::_lrepeat $count {*}$args}
}
}
namespace eval mtmtcl::matprop::trivial {
namespace ensemble create -parameters {shape ring}
namespace export *
}
% \end{tcl}
% The purpose of making the ensemble take two parameters when the
% first is anyway ignored is twofold. First, the |homfdpower| PROP
% in Section~\ref{Sec:homfdpower} takes two parameters and can
% share some method implementations with |trivial| if this does it
% too. Second, many command implementations can also be shared with
% a matrix ring, and several of its methods need to know the matrix
% side (or sides), which is then what the \word{shape} parameter
% will tell them.
% \changes{0}{2008/12/13}{Added \texttt{shape} parameter. (LH)}
%
% The data format is as a list of rows, where each row is a list
% of elements of the \word{ring}, just as one might expect. A
% problem with this is that it wouldn't be possible to distinguish
% between different arities for elements of coarity $0$, since any
% element of coarity $0$ is just the empty list. (Arity $0$ is on
% the other hand not such a representation problem, since a matrix
% with $m$ rows and $0$ columns is a list of $m$ empty lists.)
% \textbf{Therefore} this PROP has a unique element with coarity
% and arity $0$, and all other elements have positive arity and
% coarity.
%
% \begin{ensproc}{arity}
% Since the arity is the number of columns, it is measured as the
% length of the first row. This works also in the degenerate $0
% \times 0$ matrix.
% \begin{tcl}
proc mtmtcl::matprop::trivial::arity {shape ring matrix} {
llength [lindex $matrix 0]
}
% \end{tcl}
% \end{ensproc}
%
% \begin{ensproc}{coarity}
% The coarity is similar, but easier.
% \begin{tcl}
proc mtmtcl::matprop::trivial::coarity {shape ring matrix} {
llength $matrix
}
% \end{tcl}
% \end{ensproc}
%
% \begin{ensproc}{=}
% Equality testing is to first check that the sides match, and
% then compare the matrices element by element.
% \begin{tcl}
proc mtmtcl::matprop::trivial::= {shape ring A B} {
if {[llength $A] != [llength $B]} then {return 0}
if {[llength [lindex $A 0]] != [llength [lindex $B 0]]} then {return 0}
foreach arow $A brow $B {
foreach a $arow b $brow {
if {![{*}$ring = $a $b]} then {return 0}
}
}
return 1
}
% \end{tcl}
% \end{ensproc}
%
% \begin{ensproc}{*}
% Composition in this PROP is ordinary matrix multiplication.
% \begin{tcl}
proc mtmtcl::matprop::trivial::* {shape ring A B} {
if {[llength [lindex $A 0]] != [llength $B]} then {
return -code error -errorcode {API PROP typenomatch}\
"Left factor arity does not match right factor coarity"
}
set zerorow [lrepeat [llength [lindex $B 0]] [{*}$ring 0]]
set res {}
foreach Arow $A {
set rrow $zerorow
foreach a $Arow Brow $B {
set nrow {}
foreach sum $rrow b $Brow {
lappend nrow [{*}$ring + $sum [{*}$ring * $a $b]]
}
set rrow $nrow
}
lappend res $rrow
}
return $res
}
% \end{tcl}
% \end{ensproc}
%
% \begin{ensproc}{tensor}
% The ``tensor product'' just mounts the two factors as blocks on
% the diagonal: \(\left( \begin{smallmatrix} A&0\\0&B
% \end{smallmatrix} \right)\).
% \begin{tcl}
proc mtmtcl::matprop::trivial::tensor {shape ring A B} {
set res {}
set zeroes [lrepeat [llength [lindex $B 0]] [{*}$ring 0]]
foreach Arow $A {
lappend res [concat $Arow $zeroes]
}
set zeroes [lrepeat [llength [lindex $A 0]] [{*}$ring 0]]
foreach Brow $B {
lappend res [concat $zeroes $Brow]
}
return $res
}
% \end{tcl}
% \end{ensproc}
%
% \begin{ensproc}{permutation}
% The permutation elements in this PROP are the ordinary
% permutation matrices, which when multiplied by a column vector
% on the right send element $j$ to position $\sigma(j)$. Hence
% the entries that are $1$ are those at $(i,j)$ which have
% \(i=\sigma(j)\).
% \begin{tcl}
proc mtmtcl::matprop::trivial::permutation {shape ring sigma} {
set one [{*}$ring 1]
set zerorow [lrepeat [llength $sigma] [{*}$ring 0]]
set res {}
foreach i $sigma {
set row $zerorow
lset row $i $one
lappend res $row
}
return $res
}
% \end{tcl}
% \end{ensproc}
%
%
% \begin{ensproc}{perm.}
% The left action of permutations on PROP elements. It amounts to
% taking rows of the original matrix and putting them in the
% positions specified by the permutation.
% \begin{tcl}
proc mtmtcl::matprop::trivial::perm. {shape ring sigma A} {
if {[llength $sigma] != [llength $A]} then {
return -code error -errorcode {API PROP typenomatch}\
"Permutation length and number of rows do not match"
}
set res $A
foreach row $A i $sigma {
lset res $i $row
}
return $res
}
% \end{tcl}
% \end{ensproc}
%
% \begin{ensproc}{.perm}
% The right action of permutations on PROP elements. The
% permutation is here used to select columns from the matrix, and
% since the columns do not exist as explicit values, this
% selection must be repeated for each row of the matrix.
% \begin{tcl}
proc mtmtcl::matprop::trivial::.perm {shape ring A sigma} {
if {[llength $sigma] != [llength [lindex $A 0]]} then {
return -code error -errorcode {API PROP typenomatch}\
"Permutation length and number of columns do not match"
}
set res {}
foreach Arow $A {
set row {}
foreach i $sigma {
lappend row [lindex $Arow $i]
}
lappend res $row
}
return $res
}
% \end{tcl}
% \end{ensproc}
%
% \begin{ensproc}{+}
% This is just ordinary matrix addition.
% \begin{tcl}
proc mtmtcl::matprop::trivial::+ {shape ring A B} {
if {[llength $A] != [llength $B] ||\
[llength [lindex $A 0]] != [llength [lindex $B 0]]} then {
return -code error "Matrix sides do not match"
}
set res {}
foreach Arow $A Brow $B {
set row {}
foreach a $Arow b $Brow {
lappend row [{*}$ring + $a $b]
}
lappend res $row
}
return $res
}
% \end{tcl}
% \end{ensproc}
%
% \begin{ensproc}{neg}
% This is just ordinary matrix negation.
% \begin{tcl}
proc mtmtcl::matprop::trivial::neg {shape ring A} {
set res {}
foreach Arow $A {
set row {}
foreach a $Arow {lappend row [{*}$ring neg $a]}
lappend res $row
}
return $res
}
% \end{tcl}
% \end{ensproc}
%
% \begin{ensproc}{-}
% This is just ordinary matrix subtraction.
% \begin{tcl}
proc mtmtcl::matprop::trivial::- {shape ring A B} {
if {[llength $A] != [llength $B] ||\
[llength [lindex $A 0]] != [llength [lindex $B 0]]} then {
return -code error "Matrix sides do not match"
}
set res {}
foreach Arow $A Brow $B {
set row {}
foreach a $Arow b $Brow {
lappend row [{*}$ring - $a $b]
}
lappend res $row
}
return $res
}
% \end{tcl}
% \end{ensproc}
%
% \begin{ensproc}{.}
% And this is just multiplication by a scalar.
% \begin{tcl}
proc mtmtcl::matprop::trivial::. {shape ring s A} {
set res {}
foreach Arow $A {
set row {}
foreach a $Arow {lappend row [{*}$ring * $s $a]}
lappend res $row
}
return $res
}
% \end{tcl}
% \end{ensproc}
%
% \begin{ensproc}{scalar}
% As in a \APIref{ring-module}{1.1}, the |scalar| method gives
% access to the underlying ring.
% \begin{tcl}
proc mtmtcl::matprop::trivial::scalar {shape ring args} {
tailcall {*}$ring {*}$args
}
% \end{tcl}
% \end{ensproc}
%
% \begin{ensproc}{0}
% A |0| method needed for the \APIref{ring-module}{2.1} interface
% cannot be defined in the PROP, since every nonempty component
% has a separate zero element, but the \word{shape} parameter will
% in a specific matrix ring (or bimodule) provide the necessary
% information.
% \begin{tcl}
proc mtmtcl::matprop::trivial::0 {shape ring} {
set m [lindex $shape 0]
set n [lindex $shape end]
incr m 0; incr n 0
set zero [{*}$ring 0]
set row {}
for {set j 0} {$j<$n} {incr j} {lappend row $zero}
set res {}
for {set i 0} {$i<$m} {incr i} {lappend res $row}
return $res
}
% \end{tcl}
% Even when the \word{shape} is not fixed, it is straightfoward
% to multiply an existing element by the |scalar 0| to produce a
% same-size zero.
% \end{ensproc}
%
% \begin{ensproc}{iszero}
% Although a |0| method cannot be defined in the PROP in general,
% it is straightforward to test an element for being a zero.
% \begin{tcl}
proc mtmtcl::matprop::trivial::iszero {shape ring A} {
foreach Arow $A {
foreach a $Arow {
if {![{*}$ring iszero $a]} then {return 0}
}
}
return 1
}
% \end{tcl}
% \end{ensproc}
%
% \begin{ensproc}{1}
% A |1| method needed for the \APIref{monoid}{1.0} interface
% cannot be defined in the PROP, since every arity has a separate