forked from dmurfet/mf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmfweb.lib
2236 lines (1887 loc) · 74.6 KB
/
mfweb.lib
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
version="1.0";
category="Miscellaneous";
info="
LIBRARY: mfweb.lib Compilation of webs of matrix factorisations
AUTHOR: Nils Carqueville, Daniel Murfet
KEYWORDS: matrix factorisation
PROCEDURES:
";
LIB "linalg.lib";
LIB "matrix.lib";
LIB "ring.lib";
LIB "blow.lib";
LIB "linkhom.lib";
////////////////////////////////////////////////////////////////////
// USAGE GUIDE
//
// A web is an oriented graph where edges are allowed to begin or end, but not
// both, on some unspecified "boundary". All edges are labelled with a set of variables
// and a potential, and every vertex is assigned a matrix factorisation
// of the sum of all the "outgoing" potential minus the sum of all the incoming
// potentials. There must be at least one variable on each edge, disjoint variables
// on distinct edges, and potentials must have isolated singularities. Throughout
// comments in this file, V denotes the total number of vertices in the web (always >0)
// We implicitly order the vertices and consider them as elements in the set {1,...,V}.
//
// WARNING: We do not allow isolated vertices, with no incoming or outgoing vertices.
// The ordering of the variables in L1 and L2 may matter.
////////////////////////////////////////////////////////////////////
// USAGE GUIDE: parameters
//
// We allow rings of the form (0,r),(variables),dp where r is a parameter.
// If this is an algebraic extension with minimum polynomial "minpoly" then
// there should also be defined a polynomial minpolyblow, in the first ring variable
// var(1), equal to substituting var(1) for r in minpoly.
/////////////////////////////////////////////////
// DATA TYPE: edge
//
// An edge is a list (S,T,L,W) where S,T are integers in the range 0,...,V, L is a
// nonempty list of variables in the ring, and W is a polynomial in the variables
// present in L. Here S, T are the indices, respectively of the "S"ource and "T"arget
// of the edge, where "0" stands for the boundary.
/////////////////////////////////////////////////
// DATA TYPE: augmented edge
//
// An augmented edge is a list (S,T,L,W,B,C) where (S,T,L,W) is an edge, B is a list
// of size n = size(L), and C is a nxn matrix of polynomials such that for each i
// between 1 and n = |L|, we have
//
// L[i]^B[i] = C[1,i] * diff(W,L[1]) + ... + C[n,i] * diff(W,L[n]).
//
// The existence of such integers B[i] and polynomials C[i,j] follows from the assumption
// that W defines an isolated singularity, hence the partial derivatives of W generate an
// ideal primary for the ideal generated by all the variables on the edge.
//
// NOTE (8/7/2015): The old code had the C matrix rows and columns confused. The variables
// are indexed by i, and each variable has a corresponding _column_ in C.
/////////////////////////////////////////////////
// TERMINOLOGY
//
// We say that a variable is "adjacent" at a vertex if the variable lies on an edge
// adjacent to the vertex. A variable is "external" if it lies on an edge involving
// the boundary, and "internal" otherwise.
//
// The total potential of a web is the sum of the potentials associated with
// each vertex of the web.
/////////////////////////////////////////////////
// DATA TYPE: web
//
// A web is represented by a tuple (V, L1, L2[,L3]) where V is an integer > 0, giving
// number of vertices in the web, and two or three lists, where
//
// 1. L1 is a list of edges.
// 2. L2 is a list of matrices, of size V, with the matrix in posn i
// being the differential of a matrix factorisation defined in the
// set of variables adjacent with the vertex i, factorising the potential
// explained in the Usage Guide.
// 3. L3 is an optional list of intvecs, also of size v, making each
// of the MFs into a graded MF.
//
// NOTE: Distinct edges in the web MUST be assigned disjoint sets of variables!
/////////////////////////////////////////////////
// DATA TYPE: compilation strategy
//
// Compilation of a web means taking the tensor product over all MFs in the
// web and pushing forward to the ring with all internal variables in the web
// deleted. A compilation strategy represents one way of effecting this pushforward
// in practice.
//
// Precisely, a compilation strategy consists of a pair (L1,L2), where
// L1 is a permutation of the set {1,...,V} and L2 is a list
// containing each internal variable in the web precisely once. The idea is that L1 tells
// us the order in which to tensor the MFs in the web together (for example, if
// L1 were 3,1,2 we should first tensor the MF at vertex 3 with the one at vertex 1,
// and then tensor the result with the MF at vertex 2) and L2 tells us the ordering
// on the variables to use in the reduction/pushforward procedure.
//
// NOTE: There is no implied relationship between the variable ordering and the
// vertex ordering, e.g., the variables around the first vertex do not need to
// go first.
//
// IMPORTANT: For a compilation strategy to be valid, each fusion has to involve
// a nonzero number of variables. That is, if L1 = {v1,...,vn} then for each 1 <= i <= n-1
// we are trying to fuse v(i+1) with the result of fusing v1,...,vi. We require that
// there is an edge between one of the v1,...,vi and v(i+1).
/////////////////////////////////////////////////
// Settor and Accessor methods for an edge.
//
// The point of these being that if we change the structure of the lists underlying
// an edge, or web, then we only need change the following routines.
proc edgeSource(list edge){ return(edge[1]); }
proc edgeTarget(list edge){ return(edge[2]); }
proc edgeVariables(list edge){ return(edge[3]); }
proc edgePotential(list edge){ return(edge[4]); }
proc augedgePowers(list augedge){ return(augedge[5]); }
proc augedgeTransform(list augedge){ return(augedge[6]); }
proc setEdgeSource(list edge, int src){ edge[1] = src; return(edge); }
proc setEdgeTarget(list edge, int tar){ edge[2] = tar; return(edge); }
proc setEdgeVariables(list edge, list var){ edge[3] = var; return(edge); }
proc setEdgePotential(list edge, poly W){ edge[4] = W; return(edge); }
proc isEdgeBetweenVertices(list edge, int v1, int v2)
{
if( edgeSource(edge) == v1 && edgeTarget(edge) == v2 ){ return(1); }
if( edgeSource(edge) == v2 && edgeTarget(edge) == v1 ){ return(1); }
return(0);
}
proc edgeVerify(list edge)
{
if( typeof(edge[1]) != "int" ){ return(0); }
if( edge[1] < 0 ){ return(0); }
if( typeof(edge[2]) != "int" ){ return(0); }
if( edge[2] < 0 ){ return(0); }
if( typeof(edge[3]) != "list" ){ return(0); }
if( size(edge[3]) == 0 ){ return(0); }
int i;
for(i=1; i<=size(edge[3]); i++)
{
// Each entry must be a ring variable
if( rvar(edge[3][i]) == 0 ){ return(0); }
}
if( typeof(edge[4]) != "poly" ){ return(0); }
return(1);
}
// NOTE: augmentedEdgeForEdge breaks the setter/getter barrier.
/////////////////////////////////////////////////
// Settor and Accessor methods for a web.
proc webSize(list web){ return(web[1]); }
proc webEdges(list web){ return(web[2]); }
proc webMFs(list web){ return(web[3]); }
proc webMFatVertex(list web, int vertex){ return(web[3][vertex]); }
proc webMFgr(list web){ return(web[4]); }
proc webMFgratVertex(list web, int vertex){ return(web[4][vertex]); }
proc webIsGraded(list web){ int t = (size(web) == 4); return(t); }
/////////////////////////////////////////////////
// Basic methods for vertices
proc vertexVariables(list web, int vertex)
{
list vars;
list edgeList = webEdges(web);
int i;
for(i = 1; i <= size(edgeList); i++)
{
list edge = edgeList[i];
if( edgeSource(edge) == vertex || edgeTarget(edge) == vertex )
{
vars = vars + edgeVariables(edge);
}
kill edge;
}
kill edgeList;
return(vars);
}
/////////////////////////////////////////////////
// vertexIncomingEdges
//
// Return a list (possibly empty) of indices into
// the array of edges giving those edges with target
// the given vertex (possibly the boundary 0).
proc vertexIncomingEdges(list web, int vertex)
{
list eList;
list edgeList = webEdges(web);
int i;
for(i = 1; i <= size(edgeList); i++ )
{
list edge = edgeList[i];
if( edgeTarget(edge) == vertex )
{
eList = eList + list(i);
}
kill edge;
}
return(eList);
}
proc vertexOutgoingEdges(list web, int vertex)
{
list eList;
list edgeList = webEdges(web);
int i;
for(i = 1; i <= size(edgeList); i++ )
{
list edge = edgeList[i];
if( edgeSource(edge) == vertex )
{
eList = eList + list(i);
}
kill edge;
}
return(eList);
}
proc vertexPotential(list web, int vertex)
{
poly W;
list edgeList = webEdges(web);
int i;
for(i=1; i <= size(edgeList); i++ )
{
list edge = edgeList[i];
int nc;
if( edgeSource(edge) == vertex ){ nc = 1; }
if( edgeTarget(edge) == vertex ){ nc = -1; }
W = W + nc * edgePotential(edge);
kill edge;
}
return(W);
}
/////////////////////////////////////////////////
// ringWithoutVars
//
// Given a set of variables in the ring, returns
// the ring with those variables deleted (but otherwise
// preserved, for example parameters). We do NOT change
// the current basering. Note that vars should be a list
// of polynomials, not strings.
proc ringWithOnlyVars(list vars)
{
list exvars;
int i;
for(i=1; i<=nvars(basering); i++)
{
if( !checklist(vars,var(i)) )
{
exvars = exvars + list(var(i));
}
}
def nR = ringWithoutVars(exvars);
return(nR);
}
proc ringWithoutVars(list vars)
{
if( size(vars) == nvars(basering) )
{
print("[ringWithoutVars] Asked to create a ring with no variables, exiting.");
return(0);
}
def SSS = basering;
list rlist = ringlist(SSS);
list newVar;
// Go through and form newVar = current variables minus vars
int i;
for(i = 1; i <= size(rlist[2]); i++)
{
int found = 0;
int j;
for(j = 1; j <= size(vars); j++ )
{
if( string(vars[j]) == rlist[2][i] )
{
found = 1;
break;
}
}
if( !found ){ newVar = newVar + list(rlist[2][i]); }
}
list newringList = rlist;
newringList[2] = newVar;
// Fix the variable weighting
intvec kk = (1..size(newVar));
for(i=1; i<=size(newVar); i++)
{
kk[i] = 1;
}
newringList[3][1][2] = kk;
kill kk;
int useParameter;
if( defined(minpolyblow) && defined(r) )
{
newringList[1][4][1] = 0; // set minpoly to zero, put it back to the right value below...
useParameter = 1;
}
// Create our new ring
def nR = ring(newringList);
kill rlist, newringList;
// Now complete the correct definition of nR by specifying the right minpoly:
if( useParameter )
{
setring nR;
// Note that fetch uses the position of the ring variables, not the name, so
// that fetch(var(1)) is always var(1).
poly minpolyblow = fetch(SSS,minpolyblow);
poly z = subst(minpolyblow,var(1),r);
number nu = leadcoef(z);
minpoly = nu;
poly minpolyblow = fetch(SSS,minpolyblow);
export(minpolyblow);
// NOTE: The double definition of minpolyblow is because Singular nukes
// all variables in our ring when we set minpoly
setring SSS;
}
return(nR);
}
/////////////////////////////////////////////////
// augmentedEdgeForEdge
//
// Given an edge, creates an associated augmented edge
proc augmentedEdgeForEdge(list edge)
{
int powerCutoff = blowFlags("power_cutoff_jacobi");
int useSanityChecks = blowFlags("sanity_checks");
if( useSanityChecks )
{
if( !edgeVerify(edge) )
{
print("[augmentedEdgeForEdge] Passed invalid edge, exiting.");
return();
}
}
// Recall that an edge has the format (S,T,L,W) and an augmented edge has the format
// (S,T,L,W,B,C) where B is an intvec and C a matrix.
// First change ourselves into the ring with only the variables present on the given edge
def RRR = basering;
def nR = ringWithOnlyVars(edgeVariables(edge));
setring nR;
// Note it's important that we respect the order of the variables in the edge, NOT
// the natural ordering in the ring.
list edge = imap(RRR,edge);
list augEdge = edge;
list L = edgeVariables(edge);
poly W = edgePotential(edge);
// Build the Jacobi ideal
ideal J;
int i;
for(i=1; i <= size(L); i++)
{
J[i] = diff(W,L[i]);
}
ideal Jstd = std(J);
list B;
matrix C;
for(i=1; i <= size(L); i++)
{
// Find a power of the variable va belonging to the ideal generated by the partials of W
poly va = L[i];
int p;
int power = 0;
for(p=1; p <= powerCutoff; p++)
{
if( reduce(va^p, Jstd) == 0 )
{
power = p;
B[i] = p;
matrix T = lift(J, va^p);
if( ncols(T) != 1 || nrows(T) != size(J) )
{
print("[augmentedEdgeForEdge] Something wrong with the lift, exiting.");
return(0);
}
if( i == 1 )
{
C = T;
}
else
{
C = concat(C,T);
}
break;
}
}
if( power == 0 )
{
print("[augmentedEdgeForEdge] Failed to find power of variable in Jacobi ideal, exiting.");
return(0);
}
}
augEdge[5] = B;
augEdge[6] = C;
setring RRR;
list augEdge = imap(nR, augEdge);
ideal J = imap(nR,J);
// Perform sanity check
if( useSanityChecks )
{
matrix Q = matrix(J) * augEdge[6];
list edgeVar = edgeVariables(edge);
int i;
for(i=1; i <= size(edgeVar); i++)
{
if( Q[1,i] != edgeVar[i]^(augEdge[5][i]) )
{
print("[augmentedEdgeForEdge] Failed to correct compute augmented edge correctly, exiting.");
return(0);
}
}
}
return(augEdge);
}
/////////////////////////////////////////////////
// isEdgeInternal
proc isEdgeInternal(list edge)
{
if( edgeSource(edge) != 0 && edgeTarget(edge) != 0 )
{
return(1);
}
return(0);
}
/////////////////////////////////////////////////
// webVariables
//
// Returns the list consisting of all variables lying
// on all edges in the web.
proc webVariables(list web)
{
list edgeList = webEdges(web);
list vars;
int i;
for(i=1; i<=size(edgeList); i++)
{
list edge = edgeList[i];
vars = vars + edgeVariables(edge);
kill edge;
}
kill edgeList;
return(vars);
}
/////////////////////////////////////////////////
// webInternalVariables
//
// Returns the list consisting of all internal variables
proc webInternalVariables(list web)
{
list edgeList = webEdges(web);
list vars;
int i;
for(i=1; i<=size(edgeList); i++)
{
list edge = edgeList[i];
if( isEdgeInternal(edge) )
{
vars = vars + edgeVariables(edge);
}
kill edge;
}
kill edgeList;
return(vars);
}
/////////////////////////////////////////////////
// webExternalVariables
//
// Returns the list consisting of all external variables
proc webExternalVariables(list web)
{
list edgeList = webEdges(web);
list vars;
int i;
for(i=1; i<=size(edgeList); i++)
{
list edge = edgeList[i];
if( !isEdgeInternal(edge) )
{
vars = vars + edgeVariables(edge);
}
kill edge;
}
kill edgeList;
return(vars);
}
/////////////////////////////////////////////////
// subwebWithVertices
//
// Returns the subweb consisting of the given vertices in the original web
// together with all edges adjacent to those vertices, EVEN THOSE ENDING ON
// VERTICES NOT IN THE LIST. If an edge begins or ends on a vertex in our
// list, but does not end (resp. begin) on a vertex in our list (or 0, which
// is implicitly in every subweb) then we consider it to have ended or begun
// on the boundary; so that in forming the subweb we "shrink" the boundary until
// it cuts across all edges going outside our set of vertices.
//
// NOTE: You should not pass 0 as a vertex to any routines.
proc subwebWithVertices(list web, list vertices)
{
int useSanityChecks = blowFlags("sanity_checks");
if( size(vertices) == 0 )
{
print("[subwebWithVertices] Given no vertices in list, exiting.");
return();
}
int useGrading = webIsGraded(web);
// The easy part is building the list of MFs and gradings, so let us do that first
list MFlist = webMFs(web);
if( useGrading ){ list MFgrlist = webMFgr(web); }
list subMFlist;
if( useGrading ){ list subMFgrlist; }
int i;
for(i=1; i<=size(vertices); i++)
{
subMFlist = subMFlist + list(MFlist[vertices[i]]);
if( useGrading ){ subMFgrlist = subMFgrlist + list(MFgrlist[vertices[i]]); }
}
// Now we need to build up the edges. First of all we discard any edges not
// beginning or ending at one of the vertices in our list.
// Then in each of these edges replace the integer vertices[i] by i.
list edgeList = webEdges(web);
list subEdgeList;
for(i=1; i<=size(edgeList); i++)
{
list edge = edgeList[i];
if( checklist(vertices,edgeSource(edge)) || checklist(vertices,edgeTarget(edge)) )
{
// Add this edge to our list. The only modification we make is to set
// the source or target to 0 if it was previously a vertex not in our list
if( !checklist(vertices,edgeSource(edge)) )
{
edge = setEdgeSource(edge, 0);
}
if( !checklist(vertices,edgeTarget(edge)) )
{
edge = setEdgeTarget(edge, 0);
}
subEdgeList = subEdgeList + list(edge);
}
kill edge;
}
list finalEdgeList;
// Now go through and modify all the edges in subEdgeList.
int j;
for(j=1; j<=size(subEdgeList); j++)
{
list edge = subEdgeList[j];
int fixedSource;
int fixedTarget;
for(i=1; i<=size(vertices); i++)
{
if( edgeSource(edge) == vertices[i] && !fixedSource )
{
edge = setEdgeSource(edge, i);
// After we change the source, in a later i iteration a
// vertex could recognise us as having them as the source,
// so to avoid this we use a flag.
fixedSource = 1;
}
if( edgeTarget(edge) == vertices[i] && !fixedTarget )
{
edge = setEdgeTarget(edge, i);
fixedTarget = 1;
}
}
finalEdgeList = finalEdgeList + list(edge);
kill edge;
}
kill subEdgeList;
list subweb = size(vertices), finalEdgeList, subMFlist;
kill finalEdgeList, subMFlist;
if( useGrading ){ subweb = subweb + list(subMFgrlist); kill subMFgrlist; }
if( useSanityChecks )
{
if( !webVerify(subweb) )
{
print("[subwebWithVertices] Produced invalid subweb, exiting.");
return();
}
}
return(subweb);
}
/////////////////////////////////////////////////
// compilationStratVerify
//
// Verify that the given list is a valid compilation strategy
proc compilationStratVerify(list web, list compStrat)
{
int numVertices = webSize(web);
list edges = webEdges(web);
list vertexOrder = compStrat[1];
if( size(vertexOrder) != numVertices )
{
dbprint(printlevel, "[compilationStratVerify] Wrong number of vertices in compilation strategy, failed.");
return(0);
}
// For each 1 <= i <= n-1 check that one of the first i vertices is connected
// to the (i+1)st vertex by an edge (vertices indexed according to the comp strat)
int i;
for(i=1;i<numVertices;i++)
{
int k;
int foundEdge = 0;
for(k=1;k<=i;k++)
{
int j;
for(j=1; j<=size(edges); j++)
{
if( isEdgeBetweenVertices(edges[j],vertexOrder[k],vertexOrder[i+1]) )
{
// Found an edge between one of the first i vertices and the (i+1)st
foundEdge = 1;
break;
}
}
if( foundEdge ){ break; }
}
if( !foundEdge )
{
//dbprint(printlevel, "[compilationStratVerify] Found no edges between the first " + string(i) + " vertices and vertex " + string(i+1) + ", failing.");
return(0);
}
}
return(1);
}
////////////////////////////////////////////////////////////////////
// permuteCompStrat
//
// Tries permuting the order of the vertices in a given compilation
// strategy to find a valid compilation strategy. Since we check
// all possible permutations, this could be very slow!
proc permuteCompStrat(list web, list compStrat)
{
int numVertices = webSize(web);
list vertexOrder = compStrat[1];
list varOrder = compStrat[2];
list perms = SGroupintvecs(numVertices);
int i;
for(i=1;i<=size(perms);i++)
{
intvec p = perms[i];
list newV;
int j;
for(j=1;j<=numVertices;j++)
{
newV[j] = vertexOrder[p[j]];
}
list testStrat = newV, varOrder;
if( compilationStratVerify(web, testStrat) )
{
// We found a valid permutation, return it
dbprint(printlevel, "[permuteCompStrat] Found a valid permutation of the vertices: " + string(p));
return(testStrat);
}
kill newV, p, testStrat;
}
// We failed to find a valid permutation
dbprint(printlevel, "[permuteCompStrat] Failed to find a valid permutation.");
return();
}
/////////////////////////////////////////////////
// webDual
//
// Returns the dual web, obtained by reversing the direction
// of all edges, multiplying by -1 the potential at each vertex
// and replacing every MF by its dual. We take care of the gradings
// as well, if they are present.
proc webDual(list web)
{
int useSanityChecks = blowFlags("sanity_checks");
// Extract the content of the web
int numVertices = webSize(web);
list edgeList = webEdges(web);
list mfList = webMFs(web);
int useGrading = webIsGraded(web);
if( useGrading ){ list mfGradings = webMFgr(web); }
// First reverse all edges
list dualEdgeList;
int i;
for(i=1;i<=size(edgeList);i++)
{
list e = edgeList[i];
int s = e[1];
int t = e[2];
e[1] = t;
e[2] = s;
dualEdgeList = dualEdgeList + list(e);
}
// Now dualise all matrices
list dualMfList;
list dualMfGradings;
for(i=1;i<=size(mfList);i++)
{
matrix D = MFdual(mfList[i]);
dualMfList = dualMfList + list(D);
kill D;
if( useGrading )
{
intvec v = MFdualGrading(mfGradings[i]);
dualMfGradings = dualMfGradings + list(v);
kill v;
}
}
list retWeb = numVertices, dualEdgeList, dualMfList;
if( useGrading ){ retWeb = retWeb + list(dualMfGradings); }
if( useSanityChecks )
{
if( !webVerify(retWeb) )
{
dbprint(printlevel, "[webDual] Failed to create valid dual web.");
return();
}
}
return(retWeb);
}
/////////////////////////////////////////////////
// webVerify
//
// Verify that the given list satisfies (some of) the conditions to be a web.
proc webVerify(list web)
{
if( typeof(web[1]) != "int" || typeof(web[2]) != "list" || typeof(web[3]) != "list" )
{
print("[webVerify] Entries in web are not of type int, list, list, failed.");
return(0);
}
int useGrading = webIsGraded(web);
int numVertices = webSize(web);
if( numVertices != size(webMFs(web)) )
{
print("[webVerify] There is size mismatch between vertices and MFs, failed.");
return(0);
}
int i;
for( i=1; i<=numVertices; i++ )
{
matrix A = webMFatVertex(web, i);
poly W = vertexPotential(web, i);
if( useGrading ){ intvec Agr = webMFgratVertex(web, i); }
//if( size(vertexIncomingEdges(web,i)) + size(vertexOutgoingEdges(web,i)) == 0 )
//{
// print("[webVerify] Vertex " + string(i) + " is isolated, failed.");
// return(0);
//}
// Is A a MF of this potential?
if( A * A != W * unitmat(ncols(A)) )
{
print("[webVerify] At vertex " + string(i) + " the MF does not factorise the local potential W=" + string(W) + ", failed.");
return(0);
}
// Is A a graded MF?
if( useGrading )
{
if( !isGradingValid(A, Agr) )
{
print("[webVerify] At vertex " + string(i) + " the grading is not valid, failed.");
return(0);
}
}
}
return(1);
}
/////////////////////////////////////////////////
// webCompilePair
//
// The backbone of our compilation routines. We are given a web with only
// two vertices and a compilation strategy. Next we describe the output in
// the standard case, but be aware there is an important special case to be
// explained at the end.
//
// We first return a matrix factorisation in the set of external variables
// of the total potential of the given web. Let X denote the tensor product
// over all vertices of the associated MFs, defined in the ordering determined
// by our compilation strategy. Let pX denote the pushforward/restriction of
// scalars to the ring with all internal variables in the web deleted. Our
// first return value is the differential of a MF Y homotopy equivalent to pX.
//
// The second return value is the grading vector for Y, if we are using gradings.
//
// The third (or second, if there is no grading) return value is a list
// R = (F1,G1,x1,exp1),(F1,G2,x2,exp2),... whose length is equal to the number of
// internal variables in the web. These are the maps returned by mfPushforwardInductive
// applied to the set of internal variables ordered according to our compilation strategy.
//
// In more detail: let p1X denote the pushforward of X just to the ring without the
// "first" internal variable, where "first" means first in the compilation strategy.
// This is a direct summand of Xblow[1], and (F1,G1) is a pair splitting, in the
// homotopy category of finite rank MFs, the corresponding idempotent. Say the
// splitting is Y1. Then F1: Xblow[1] -> Y1 and G1: Y1 -> Xblow[1] with F1 * G1 = 1
// and G1 * Y1 the idempotent corresponding to p1X.
//
// Next, we push forward Y1 to the ring without the first and second internal variables,
// and the same yoga produces maps (F2,G2) splitting an idempotent on Y1blow[1], etc.
//
// This list R is referred to as a "splitting record".
//
// NOTE: Special case
//
// If the total potential of the web is zero, and if in the last step of the compilation
// process we end up with non-square matrices (may not happen) then it is not safe to
// return the differential on Y (it will not be square) so our return list looks like
//
// "nonsquare", [r1,r2,] R
//
// where r1,r2 are grading vectors on the even and odd parts of Y resp. (if we are
// using the grading) and R is as described above, but where the last (F,G,x,exp) pair is
// a tuple f0,f1,g0,g1,x,exp with f0,g0 splitting the even part of the very last idempotent
// and similarly for f1,g1.
proc webCompilePair(list web, list compStrat)
{
int useSanityChecks = blowFlags("sanity_checks");
int useGrading = webIsGraded(web);
if( useSanityChecks )
{
if( !webVerify(web) )
{
print("[webCompilePair] Given web is not valid, exiting.");
return();
}
if( webSize(web) != 2 )
{
print("[webCompilePair] We only compile pairs. Duh. Exiting.");
return();
}
}
// Extract the content of the web
int numVertices = webSize(web);
list edgeList = webEdges(web);
list mfList = webMFs(web);
if( useGrading ){ list mfGradings = webMFgr(web); }
// And the compilation strategy
list vertexOrder = compStrat[1];
list varOrder = compStrat[2];
if( size(vertexOrder) != 2 )
{
print("[webCompilePair] We only compile pairs, exiting.");
return();
}
// Order the vertices according to the compilation strategy
int i;
for(i=1;i<=2;i++)
{
matrix mf(i) = mfList[vertexOrder[i]];
if( useGrading ){ intvec mfgr(i) = mfGradings[vertexOrder[i]]; }
}
// Our task is to build up the input to mfPushforwardInductive and
// then interpret its output.
matrix A = MFtensor( mf(1), mf(2) );
if( useGrading ){ intvec Agr = MFtensorGradings( mfgr(1), mfgr(2) ); }
// Build up a list of the internal variables, ordered according to the
// compilation strategy, a list of powers and a list of homotopies. The
// powers we collect are the powers of the variables which act null-homotopically
// on A, with associated homotopies stored in H.