-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSymTensor.m
More file actions
8040 lines (5852 loc) · 378 KB
/
Copy pathSymTensor.m
File metadata and controls
8040 lines (5852 loc) · 378 KB
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
classdef SymTensor
%UNTITLED2 Summary of this class goes here
% Detailed explanation goes here
properties(GetAccess = 'public', SetAccess = 'public')
TensorEntries %The parts of the tensors
TensorEntriesSizes %the sizes of the tensors
Structure %How to combine the tripoints and endpoints, note that we start counting from zero.
ChargeDirections %what directions the tripoints are going in, +1 = Out of Core, -1 = Into core
ChargeLabelsExternal %the external charges, they change only due to braidings
ChargeLabelsInternal %the internal charges, they change with internal restructuring
MultiplicitiesInternal %the internal multiplicities, they can change with internal restructuring
Braidings %a list of the charges braided, this is always the leftmost of CyclicLegs.
%note that this doesn't reference the output leg as a label but is an internal thing.
BraidingDirections %directions for the braidings, +1 = line going upright is above, -1 = line going upleft is above,
%note that this is regardless of where it is which means it can
%have fiferent meanings and actions on top side and bottom
StoredLocations %quick reference for the ordering at the output.
CapType %tells us what the cap and cups are like +1 means going to right, -1 means going to the left
ChargeLegDimensions % a list of dimensions associated to each charge on each leg. indexes are charges, then legs
ChargeSide %a list of which side of the block the leg is, +1 = top, -1 = bottom
ChargeSideInt %a list of which side of the vertex it directs into the leg is, -1 = top, +1 = bottom;
%NOTE: this is different to ChargeSide only because
%we want these to be +1 if on top half (going into
%bottom of vertex) and -1 if on bottom half (going
%into top of vertex).
SymHandle %the Symmetry associated
FlagIsNotSymmetric %If this tensors has only used the trival irrep
FlagIsANumber %If this tensors is actually a number
FlagIsAShape = false; %if this tensor is actually a shape
%FreePermuteTracker
CyclicLegs %this is the leg ordering after the braiding
CyclicLegsBraided %this is the leg ordering when we change to have top then bottom, note that this is when we have braidings in addition to this.
end
properties(GetAccess = 'public', SetAccess = 'private')
end
methods(Access = 'public', Static = true)
function OutTensor = CreateTensor(Sym, TypeMatrix, ChargeDimensionsBottom, ChargeDimensionsTop, NumberOfLegsBottom, NumberOfLegsTop)
if nargin<4
ChargeDimensionsTop = ChargeDimensionsBottom;
end
if nargin<5
NumberOfLegsBottom = size(ChargeDimensionsBottom,2);
end
if nargin<6
NumberOfLegsTop = size(ChargeDimensionsTop,2);
end
%now check that the number of dimensions is consistant
TempDim = Sym.getDimExternal();
if size(ChargeDimensionsBottom,1) ~= size(ChargeDimensionsTop,1)
error('error: ChargeDimensionsBottom and ChargeDimensionsTop should agree')
end
if length(size(ChargeDimensionsBottom))>3
error('error: ChargeDimensionsBottom should be a vector, not 3D')
end
if length(size(ChargeDimensionsTop))>3
error('error: ChargeDimensionsTop should be a vector, not 3D')
end
if ~(size(ChargeDimensionsBottom,2)==1)
%Then either we are assigning seperately
if size(ChargeDimensionsBottom,2)==sum(abs(NumberOfLegsBottom))
if (size(ChargeDimensionsBottom,1)~=size(TempDim,1))
error('error: ChargeDimensionsBottom should have the same number of entries as the number of Charges in the symmetry being used')
end
FlagAssignSeperateLegsBottom = true;
elseif size(ChargeDimensionsBottom,1)==size(TempDim,1) && size(ChargeDimensionsBottom,2) == 1
FlagAssignSeperateLegsBottom = false;
else
error('error: ChargeDimensionsBottom should be a vector, not a matrix')
end
else
if (size(ChargeDimensionsBottom,1)~=size(TempDim,1))
error('error: ChargeDimensions should have the same number of entries as the number of Charges in the symmetry being used')
end
FlagAssignSeperateLegsBottom = false;
end
if any(ChargeDimensionsBottom~=round(ChargeDimensionsBottom))
error('error: the degeneracy dimension must be an integer (specifically positive non-negative)')
end
if any(ChargeDimensionsBottom~=real(ChargeDimensionsBottom))
error('error: the degeneray dimension must be a real integer (specifically non-negative)')
end
if any(ChargeDimensionsBottom < 0)
error('error: The degeneracy dimension must be zero or a positive number')
end
if ~(size(ChargeDimensionsTop,2)==1)
%Then either we are assigning seperately
if size(ChargeDimensionsTop,2)==sum(abs(NumberOfLegsTop))
if (size(ChargeDimensionsTop,1)~=size(TempDim,1))
error('error: ChargeDimensionsTop should have the same number of entries as the number of Charges in the symmetry being used')
end
FlagAssignSeperateLegsTop = true;
elseif size(ChargeDimensionsTop,1)==size(TempDim,1) && size(ChargeDimensionsTop,2) == 1
FlagAssignSeperateLegsTop = false;
else
error('error: ChargeDimensionsTop should be a vector, not a matrix')
end
else
if (size(ChargeDimensionsTop,1)~=size(TempDim,1))
error('error: ChargeDimensionsTop should have the same number of entries as the number of Charges in the symmetry being used')
end
FlagAssignSeperateLegsTop = false;
end
if any(ChargeDimensionsTop~=round(ChargeDimensionsTop))
error('error: the degeneracy dimension must be an integer (specifically positive non-negative)')
end
if any(ChargeDimensionsTop~=real(ChargeDimensionsTop))
error('error: the degeneray dimension must be a real integer (specifically non-negative)')
end
if any(ChargeDimensionsTop < 0)
error('error: The degeneracy dimension must be zero or a positive number')
end
%now begin
%first work out if there are multiplicities, and if it is
%abelian, self dualness is in the next part when we work out
%the legs properly, Braiding is unimportant
FlagNonAbelian = IsNonAbelian(Sym);
FlagMultiplicities = IsMultiplicities(Sym);
Fusion2 = getFusion2(Sym);
%now create list of Allowed charges
AllowedSingleCharges = TempDim(:,1)';
AllowedSingleCharges = AllowedSingleCharges(any([ChargeDimensionsBottom,ChargeDimensionsTop]~=0,2));
InverseIrrep = Sym.getInverseIrrep;
%now work out the legs;
TotalLegsBottom = sum(abs(NumberOfLegsBottom));
TotalLegsTop = sum(abs(NumberOfLegsTop));
TotalLegs = sum(abs(NumberOfLegsBottom))+sum(abs(NumberOfLegsTop));
ChargeDirectionsUsedBottom = ones([size(TempDim,1),TotalLegsBottom]);
ChargeDirectionsUsedTop = ones([size(TempDim,1),TotalLegsTop]);
%if ~IsSelfDual(Sym)
ChargeDirectionsUsedBottom = [];
for jj = 1:size(NumberOfLegsBottom,1)
ChargeDirectionsUsedBottom = [ChargeDirectionsUsedBottom,-sign(NumberOfLegsBottom(jj))*ones([1,abs(NumberOfLegsBottom(jj))])];
end
%end
%if ~IsSelfDual(Sym)
ChargeDirectionsUsedTop = [];
for jj = 1:size(NumberOfLegsTop,1)
ChargeDirectionsUsedTop = [ChargeDirectionsUsedTop,sign(NumberOfLegsTop(jj))*ones([1,abs(NumberOfLegsTop(jj))])];
end
%end
%now work out the combinations allowed
if TotalLegsBottom>1
AllowedSingleCharges = TempDim(:,1)';
AllowedSingleCharges = AllowedSingleCharges(ChargeDimensionsBottom(:,1)~=0)';
ChargeLabelsExternalBottom = AllowedSingleCharges;
if FlagAssignSeperateLegsBottom
for jj = 2:TotalLegsBottom
AllowedSingleCharges = TempDim(:,1)';
AllowedSingleCharges = AllowedSingleCharges(ChargeDimensionsBottom(:,jj)~=0)';
ChargeLabelsExternalBottom = [repmat(ChargeLabelsExternalBottom, [size(AllowedSingleCharges,1), 1]),...
reshape(repmat(reshape(AllowedSingleCharges,[1,numel(AllowedSingleCharges)]), [size(ChargeLabelsExternalBottom,1),1]),[size(ChargeLabelsExternalBottom,1)*size(AllowedSingleCharges,1),1])];
end
else
for jj = 2:TotalLegsBottom
AllowedSingleCharges = TempDim(:,1)';
AllowedSingleCharges = AllowedSingleCharges(ChargeDimensionsBottom(:,1)~=0)';
ChargeLabelsExternalBottom = [repmat(ChargeLabelsExternalBottom, [size(AllowedSingleCharges,1), 1]),...
reshape(repmat(reshape(AllowedSingleCharges,[1,numel(AllowedSingleCharges)]), [size(ChargeLabelsExternalBottom,1),1]),[size(ChargeLabelsExternalBottom,1)*size(AllowedSingleCharges,1),1])];
end
end
ChargeLabelsInternalBottom = zeros([size(ChargeLabelsExternalBottom,1),size(ChargeLabelsExternalBottom,2)-1]);
MultiplicitiesInternalBottom = ones([size(ChargeLabelsExternalBottom,1),size(ChargeLabelsExternalBottom,2)-1]);
%in the abelian case we know that the sum is fixed as one
%output, we want to store that as we are using the Symmetry
%to fix the dimension, may add an additional option later
%where we store if we have an abelian model even if it
%isn't know, however this will be important in cases where
%we have braiding where knowing the internal structure is a
%must, so it would have to be mutually exclusive to the
%symmetry containing braiding in general.
%first one is special:
%FIXHERE need to take case of one leg each side into
%account
if ChargeDirectionsUsedBottom(1) == +1
Charge1 = InverseIrrep(ChargeLabelsExternalBottom(:,1));
else
Charge1 = ChargeLabelsExternalBottom(:,1);
end
if ChargeDirectionsUsedBottom(2) == +1
Charge2 = InverseIrrep(ChargeLabelsExternalBottom(:,2));
else
Charge2 = ChargeLabelsExternalBottom(:,2);
end
ChargeLabelsInternalBottom = zeros([size(ChargeLabelsExternalBottom,1), size(ChargeLabelsExternalBottom,2)-1]);
MultiplicitiesInternalBottom = zeros([size(ChargeLabelsExternalBottom,1), size(ChargeLabelsExternalBottom,2)-1]);
%first one
[TempChargeLabelsInternal, MultList, Multiplicities] = Sym.FuseChargeList(Charge1,Charge2);
ChargeLabelsExternalBottom = ChargeLabelsExternalBottom(MultList,:);
ChargeLabelsInternalBottom = ChargeLabelsInternalBottom(MultList,:);
MultiplicitiesInternalBottom = MultiplicitiesInternalBottom(MultList,:);
ChargeLabelsInternalBottom(:,1) = TempChargeLabelsInternal;
MultiplicitiesInternalBottom(:,1) = Multiplicities;
for kk = 2:size(ChargeLabelsInternalBottom,2)
if ChargeDirectionsUsedBottom(kk+1) == +1
[TempChargeLabelsInternal, MultList, Multiplicities] = Sym.FuseChargeList(ChargeLabelsInternalBottom(:,kk-1),InverseIrrep(ChargeLabelsExternalBottom(:,kk+1)));
else
[TempChargeLabelsInternal, MultList, Multiplicities] = Sym.FuseChargeList(ChargeLabelsInternalBottom(:,kk-1),ChargeLabelsExternalBottom(:,kk+1));
end
ChargeLabelsExternalBottom = ChargeLabelsExternalBottom(MultList,:);
ChargeLabelsInternalBottom = ChargeLabelsInternalBottom(MultList,:);
MultiplicitiesInternalBottom = MultiplicitiesInternalBottom(MultList,:);
ChargeLabelsInternalBottom(:,kk) = TempChargeLabelsInternal;
MultiplicitiesInternalBottom(:,kk) = Multiplicities;
end
elseif TotalLegsBottom == 1
AllowedSingleCharges = TempDim(:,1)';
AllowedSingleCharges = AllowedSingleCharges(ChargeDimensionsBottom(:,1)~=0);
if ChargeDirectionsUsedBottom(1) == +1
ChargeLabelsExternalBottom = InverseIrrep(AllowedSingleCharges');
else
ChargeLabelsExternalBottom = AllowedSingleCharges';
end
ChargeLabelsInternalBottom = ones([size(ChargeLabelsExternalBottom,1),0]);
MultiplicitiesInternalBottom = ones([size(ChargeLabelsExternalBottom,1),0]);
else %if TotalLegsBottom == 0
ChargeLabelsExternalBottom = ones([1,0]);
ChargeLabelsInternalBottom = ones([1,0]);
MultiplicitiesInternalBottom = ones([1,0]);
end
%now work out the combinations allowed
if TotalLegsBottom>1
UniqueBottom = ChargeLabelsInternalBottom(:,end);
elseif TotalLegsBottom == 1
UniqueBottom = ChargeLabelsExternalBottom(:,end);
else %if TotalLegsBottom == 0
UniqueBottom = TrivialIrrep;
end
if TotalLegsTop>1
AllowedSingleCharges = TempDim(:,1)';
AllowedSingleCharges = AllowedSingleCharges(ChargeDimensionsTop(:,1)~=0)';
ChargeLabelsExternalTop = AllowedSingleCharges;
if FlagAssignSeperateLegsBottom
for jj = 2:TotalLegsTop
AllowedSingleCharges = TempDim(:,1)';
AllowedSingleCharges = AllowedSingleCharges(ChargeDimensionsTop(:,jj)~=0)';
ChargeLabelsExternalTop = [repmat(ChargeLabelsExternalTop, [size(AllowedSingleCharges,1), 1]),...
reshape(repmat(reshape(AllowedSingleCharges,[1,numel(AllowedSingleCharges)]), [size(ChargeLabelsExternalTop,1),1]),[size(ChargeLabelsExternalTop,1)*size(AllowedSingleCharges,1),1])];
end
else
for jj = 2:TotalLegsTop
AllowedSingleCharges = TempDim(:,1)';
AllowedSingleCharges = AllowedSingleCharges(ChargeDimensionsTop(:,1)~=0)';
ChargeLabelsExternalTop = [repmat(ChargeLabelsExternalTop, [size(AllowedSingleCharges,1), 1]),...
reshape(repmat(reshape(AllowedSingleCharges,[1,numel(AllowedSingleCharges)]), [size(ChargeLabelsExternalTop,1),1]),[size(ChargeLabelsExternalTop,1)*size(AllowedSingleCharges,1),1])];
end
end
ChargeLabelsInternalTop = zeros([size(ChargeLabelsExternalTop,1),size(ChargeLabelsExternalTop,2)-1]);
MultiplicitiesInternalTop = ones([size(ChargeLabelsExternalTop,1),size(ChargeLabelsExternalTop,2)-1]);
if ChargeDirectionsUsedTop(1) == -1
Charge1 = InverseIrrep(ChargeLabelsExternalTop(:,1));
else
Charge1 = ChargeLabelsExternalTop(:,1);
end
if ChargeDirectionsUsedTop(2) == -1
Charge2 = InverseIrrep(ChargeLabelsExternalTop(:,2));
else
Charge2 = ChargeLabelsExternalTop(:,2);
end
%first one
[TempChargeLabelsInternal, MultList, Multiplicities] = Sym.FuseChargeList(Charge1,Charge2);
ChargeLabelsExternalTop = ChargeLabelsExternalTop(MultList,:);
ChargeLabelsInternalTop = ChargeLabelsInternalTop(MultList,:);
MultiplicitiesInternalTop = MultiplicitiesInternalTop(MultList,:);
ChargeLabelsInternalTop(:,1) = TempChargeLabelsInternal;
MultiplicitiesInternalTop(:,1) = Multiplicities;
for kk = 2:size(ChargeLabelsInternalTop,2)
if ChargeDirectionsUsedTop(kk+1) == -1
[TempChargeLabelsInternal, MultList, Multiplicities] = Sym.FuseChargeList(ChargeLabelsInternalTop(:,kk-1),InverseIrrep(ChargeLabelsExternalTop(:,kk+1)));
else
[TempChargeLabelsInternal, MultList, Multiplicities] = Sym.FuseChargeList(ChargeLabelsInternalTop(:,kk-1),ChargeLabelsExternalTop(:,kk+1));
end
ChargeLabelsExternalTop = ChargeLabelsExternalTop(MultList,:);
ChargeLabelsInternalTop = ChargeLabelsInternalTop(MultList,:);
MultiplicitiesInternalTop = MultiplicitiesInternalTop(MultList,:);
ChargeLabelsInternalTop(:,kk) = TempChargeLabelsInternal;
MultiplicitiesInternalTop(:,kk) = Multiplicities;
end
elseif TotalLegsTop == 1
AllowedSingleCharges = TempDim(:,1)';
AllowedSingleCharges = AllowedSingleCharges(ChargeDimensionsTop(:,1)~=0);
if ChargeDirectionsUsedTop(1) == -1
ChargeLabelsExternalTop = InverseIrrep(AllowedSingleCharges');
else
ChargeLabelsExternalTop = AllowedSingleCharges';
end
ChargeLabelsInternalTop = ones([size(ChargeLabelsExternalTop,1),0]);
MultiplicitiesInternalTop = ones([size(ChargeLabelsExternalTop,1),0]);
else
ChargeLabelsExternalTop = ones([1,0]);
ChargeLabelsInternalTop = ones([1,0]);
MultiplicitiesInternalTop = ones([1,0]);
end
%now work out the unique weights
if TotalLegsTop>1
UniqueTop = ChargeLabelsInternalTop(:,end);
elseif TotalLegsTop == 1
UniqueTop = ChargeLabelsExternalTop(:,end);
else %if TotalLegsTop == 0
UniqueTop = TrivialIrrep;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%secondly we need to convert this list into a list of Matrix
%sizes with dimensions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BottomEntries = [ChargeLabelsExternalBottom,ChargeLabelsInternalBottom, MultiplicitiesInternalBottom];
TopEntries = [ChargeLabelsExternalTop,ChargeLabelsInternalTop, MultiplicitiesInternalTop];
[UniqueEntries, ~, UniqueLabels] = unique([UniqueBottom;UniqueTop]);
UniqueLabelsBottom = UniqueLabels(1:size(UniqueBottom,1),1);
UniqueLabelsTop = UniqueLabels((size(UniqueBottom,1)+1):end,1);
UniqueEntriesBottom = cell([size(UniqueEntries,1),1]);
UniqueEntriesTop = cell([size(UniqueEntries,1),1]);
KeepUnique = true([size(UniqueEntries,1),1]);
ChargeDimensionsBottom = ChargeDimensionsBottom';
ChargeDimensionsTop = ChargeDimensionsTop';
for jj = 1:size(UniqueEntries,1)
UniqueEntriesBottom{jj} = BottomEntries(UniqueLabelsBottom == jj,:);
UniqueEntriesTop{jj} = TopEntries(UniqueLabelsTop == jj,:);
if TotalLegsBottom>0
UniqueDimensionsBottom{jj} = ChargeDimensionsBottom(1,UniqueEntriesBottom{jj}(:,1))';
if FlagAssignSeperateLegsBottom
for kk = 2:TotalLegsBottom
UniqueDimensionsBottom{jj} = [UniqueDimensionsBottom{jj}, ChargeDimensionsBottom(kk,UniqueEntriesBottom{jj}(:,kk))'];
end
else
for kk = 2:TotalLegsBottom
UniqueDimensionsBottom{jj} = [UniqueDimensionsBottom{jj}, ChargeDimensionsBottom(1,UniqueEntriesBottom{jj}(:,kk))'];
end
end
else
UniqueDimensionsBottom{jj} = zeros([1,0]);
end
if TotalLegsTop>0
UniqueDimensionsTop{jj} = ChargeDimensionsTop(1,UniqueEntriesTop{jj}(:,1))';
if FlagAssignSeperateLegsTop
for kk = 2:TotalLegsTop
UniqueDimensionsTop{jj} = [UniqueDimensionsTop{jj}, ChargeDimensionsTop(kk,UniqueEntriesTop{jj}(:,kk))'];
end
else
for kk = 2:TotalLegsTop
UniqueDimensionsTop{jj} = [UniqueDimensionsTop{jj}, ChargeDimensionsTop(1,UniqueEntriesTop{jj}(:,kk))'];
end
end
else
UniqueDimensionsTop{jj} = zeros([1,0]);
end
KeepUnique(jj) = ~isempty(UniqueEntriesBottom{jj})&&~isempty(UniqueEntriesTop{jj});
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Thirdly, create the matricies
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
sizes(1) = sum(prod(UniqueDimensionsBottom{jj},2));
sizes(2) = sum(prod(UniqueDimensionsTop{jj},2));
switch TypeMatrix
case 1 %random Unitary
Temp = randn(max(sizes));
%here we make sure it is symmetric
Temp = 0.5*(Temp + Temp');
%here we make sure it is traceless
Temp(max(sizes),max(sizes)) = -sum(diag(Temp))+Temp(max(sizes),max(sizes));
%now change it to a unitary square matrix
Temp = expm(1i*Temp);
%now get the size correct (note that this is just a random projection
%operator occuring)
Matrix{jj} = Temp(1:sizes(1), 1:sizes(2));%/sqrt(Sym.Dim(jj,2));
case 2 %identity
Matrix{jj} = eye(sizes);
case 3 % ones
Matrix{jj} = ones(sizes);
end
end
Matrix = Matrix(KeepUnique);
UniqueEntriesBottom = UniqueEntriesBottom(KeepUnique);
UniqueEntriesTop = UniqueEntriesTop(KeepUnique);
UniqueDimensionsBottom = UniqueDimensionsBottom(KeepUnique);
UniqueDimensionsTop = UniqueDimensionsTop(KeepUnique);
UniqueEntries = UniqueEntries(KeepUnique);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Finally use SymTen2Mat to create the matrix
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Legs = [TotalLegsBottom,TotalLegsTop];
if TotalLegsBottom*TotalLegsTop >0
Structure = zeros([2,TotalLegsBottom+TotalLegsTop-1]);
ChargeDirections = ones([2,TotalLegsBottom+TotalLegsTop-1]);
if TotalLegsBottom == 1
Structure(1,1) = -1;
ChargeDirections(1,1) = ChargeDirectionsUsedBottom(1);
else
Structure(1,1) = TotalLegsBottom-1;
ChargeDirections(1,1) = -1;
Structure(2,TotalLegsBottom) = -TotalLegsBottom;
ChargeDirections(2,TotalLegsBottom) = ChargeDirectionsUsedBottom(TotalLegsBottom);
end
for jj = 2:(TotalLegsBottom-1)
Structure(1,TotalLegsBottom-jj+2) = TotalLegsBottom-jj;
ChargeDirections(1,TotalLegsBottom-jj+2) = -1;
Structure(2,TotalLegsBottom-jj+1) = -(TotalLegsBottom-jj+1);
ChargeDirections(2,TotalLegsBottom-jj+1) = ChargeDirectionsUsedBottom(TotalLegsBottom-jj+1);
end
if TotalLegsBottom>=2
Structure(1,2) = -1;
ChargeDirections(1,2) = ChargeDirectionsUsedBottom(1);
end
if TotalLegsTop == 1
Structure(2,1) = -TotalLegsBottom-1;
ChargeDirections(2,1) = ChargeDirectionsUsedTop(1);
else
Structure(2,1) = TotalLegsBottom+TotalLegsTop-2;
Structure(2,TotalLegsBottom+TotalLegsTop-1) = -(TotalLegsBottom+TotalLegsTop);
ChargeDirections(2,TotalLegsBottom+TotalLegsTop-1) = ChargeDirectionsUsedTop(TotalLegsTop);
end
for jj = 2:(TotalLegsTop-1)
Structure(1,TotalLegsTop-jj+2+TotalLegsBottom-1) = TotalLegsTop-jj-1+TotalLegsBottom;
Structure(2,TotalLegsTop-jj+1+TotalLegsBottom-1) = -(TotalLegsTop-jj+1+TotalLegsBottom);
ChargeDirections(2,TotalLegsTop-jj+1+TotalLegsBottom-1) = ChargeDirectionsUsedTop(TotalLegsTop-jj+1);
end
if TotalLegsTop>=2
Structure(1,TotalLegsBottom+1) = -(TotalLegsBottom+1);
ChargeDirections(1,TotalLegsBottom+1) = ChargeDirectionsUsedTop(1);
end
else
if TotalLegsBottom == 0
else %if TotalLegsTop == 0
end
end
Data = {UniqueEntries, UniqueDimensionsBottom, UniqueDimensionsTop, Legs, UniqueEntriesBottom, UniqueEntriesTop,...
ChargeDirections, [],[],Sym, Structure,0};
OutTensor = SymTensor.SymMat2Ten(Matrix,Data);
end
function OutTensor = CreateIdentity(Sym, ChargeDimensionsBottom, ChargeDimensionsTop, Legs)
NumberOfLegsBottom = Legs(1);
NumberOfLegsTop = Legs(2);
OutTensor = SymTensor.CreateTensor(Sym,2,ChargeDimensionsBottom, ChargeDimensionsTop, NumberOfLegsBottom, NumberOfLegsTop);
end
function OutTensor = CreateRandomUnitary(Sym, ChargeDimensionsBottom, ChargeDimensionsTop, Legs)
NumberOfLegsBottom = Legs(1);
NumberOfLegsTop = Legs(2);
OutTensor = SymTensor.CreateTensor(Sym,1,ChargeDimensionsBottom, ChargeDimensionsTop, NumberOfLegsBottom, NumberOfLegsTop);
end
function OutTensor = CreateOnes(Sym, ChargeDimensionsBottom, ChargeDimensionsTop, Legs)
NumberOfLegsBottom = Legs(1);
NumberOfLegsTop = Legs(2);
OutTensor = SymTensor.CreateTensor(Sym,3,ChargeDimensionsBottom, ChargeDimensionsTop, NumberOfLegsBottom, NumberOfLegsTop);
end
function OutTensor = CreateIdentityFrom(InTensor, Legs)
%if ~InTensor.SymHandle.IsSelfDual
InverseIrrep = InTensor.SymHandle.getInverseIrrep;
if isequal(InTensor.ChargeSide, [-ones([1,Legs(1)]),ones([1,Legs(2)])])
FlagCorrectSides = true;
elseif isequal(InTensor.ChargeSide, [ones([1,Legs(1)]),-ones([1,Legs(2)])])
FlagCorrectSides = false;
InTensor.ChargeSide = -InTensor.ChargeSide;
InTensor.ChargeDirections = -InTensor.ChargeDirections;
%for kk = 1:max(InTensor.Structure(:))
% if
% InTensor.ChargeLabelsInternal = InverseIrrep(InTensor.ChargeLabelsInternal);
% InTensor.ChargeDirections(self.Structure>0) = -InTensor.ChargeDirections(self.Structure>0);
%end
else
error('Error: The Tensor SVD doesn''t work unless all the legs of a side are grouped up at any one time')
end
%else
%end
[Matrix,Data] = SymTensor.SymTen2Mat(InTensor, Legs);
for nn = 1:numel(Matrix)
Matrix{nn} = eye(size(Matrix{nn}));
end
OutTensor = SymTensor.SymMat2Ten(Matrix,Data);
if ~FlagCorrectSides
OutTensor.ChargeSide = -OutTensor.ChargeSide;
OutTensor.ChargeDirections = -OutTensor.ChargeDirections;
end
end
function OutTensor = CreateRawTensors(TensorEntries, Structure, ChargeDirections, ChargeLabelsExternal, ChargeLabelsInternal,...
MultiplicitiesInternal, SymHandle,ChargeSide,ChargeSideInt, CorrectDimensions,Braiding,BraidingDirection,KeepZeros)
MinNonZero = 10^-14;
if nargin<11
Braiding = [];
end
if nargin<12
BraidingDirection = [];
end
if nargin<10
CorrectDimensions = false;
%this means we have already accounted for converting from a
%matrix into a series of parts
end
if nargin<13
KeepZeros = false;
end
ChargeLegDimensions = zeros([size(SymHandle.getDim,1),size(ChargeLabelsExternal,2)]);
for kk = 1:size(ChargeLabelsExternal,2)
[ListExternalCharges,FirstUniqueExternalCharge,AllExternalCharge] = unique(ChargeLabelsExternal(:,kk)');
for ll = 1:length(ListExternalCharges)
ChargeLegDimensions(ListExternalCharges(ll),kk) = size(TensorEntries{FirstUniqueExternalCharge(ll)},kk);
end
end
%HERA: need to add checks in here
%here we correct dimensions as required.
if CorrectDimensions && SymHandle.IsNonAbelian
SideStructure = zeros(size(Structure));
[~,IndexExt] = sort(-Structure(Structure<0),'ascend');
[~,IndexInt] = sort(Structure(Structure>0),'ascend');
SideStructure(Structure<0) = ChargeSide(IndexExt);
SideStructure(Structure>0) = -ChargeSideInt(IndexInt);
PowerTerms = zeros(size(Structure));
OutSameSide = SideStructure(1,:)==SideStructure(2,:);
PowerTerms = PowerTerms + 1*repmat(OutSameSide,[2,1]);
PowerTerms(:,2:end) = PowerTerms(:,2:end) + (~OutSameSide([1,1],2:end)).*(1-2*([ChargeSideInt;ChargeSideInt] ~= SideStructure(:,2:end) ));
PowerTermsInt = PowerTerms(Structure>0); PowerTermsInt = PowerTermsInt(:)';
PowerTermsInt = PowerTermsInt(IndexInt) + (-1).^OutSameSide(:,2:end);
PowerTermsExt = PowerTerms(Structure<0); PowerTermsExt = PowerTermsExt(:)';
PowerTermsExt = PowerTermsExt(IndexExt);
Dim = SymHandle.Dim;
DimCorrections = prod(reshape(Dim([ChargeLabelsExternal,ChargeLabelsInternal],2),size([ChargeLabelsExternal,ChargeLabelsInternal]))...
.^(repmat([PowerTermsExt,PowerTermsInt],[size(ChargeLabelsExternal,1),1])/4),2);
for kk = 1:numel(TensorEntries)
TensorEntries{kk} = TensorEntries{kk}*DimCorrections(kk);
end
end
if ~KeepZeros
for kk = numel(TensorEntries):-1:1
if max(abs(TensorEntries{kk}(:)))<MinNonZero
TensorEntries(kk) = [];
MultiplicitiesInternal(kk,:) = [];
ChargeLabelsInternal(kk,:) = [];
ChargeLabelsExternal(kk,:) = [];
end
end
end
OutTensor = SymTensor(TensorEntries, Structure, ChargeDirections, MultiplicitiesInternal, ChargeLabelsInternal,...
ChargeLabelsExternal, Braiding,BraidingDirection,[],ChargeLegDimensions,SymHandle,ChargeSide,ChargeSideInt);
end
function OutTensor = CreateRawTensorFrom(TensorEntries, InTensor, CorrectDimensions,KeepZeros)
Structure = InTensor.Structure;
ChargeDirections = InTensor.ChargeDirections;
MultiplicitiesInternal = InTensor.MultiplicitiesInternal;
ChargeLabelsInternal = InTensor.ChargeLabelsInternal;
ChargeLabelsExternal = InTensor.ChargeLabelsExternal;
SymHandle = InTensor.SymHandle;
ChargeSide = InTensor.ChargeSide;
ChargeSideInt = InTensor.ChargeSideInt;
Braidings = InTensor.Braidings;
BraidingDirections = InTensor.BraidingDirections;
clear InTensor;
if nargin<3||isempty(CorrectDimensions)
CorrectDimensions = false;
%this means we have already accounted for converting from a
%matrix into a series of parts
end
if nargin<4 || isempty(KeepZeros)
KeepZeros = false;
%this means we have already accounted for converting from a
%matrix into a series of parts
end
OutTensor = SymTensor.CreateRawTensors(TensorEntries(:), Structure, ChargeDirections, ChargeLabelsExternal, ChargeLabelsInternal,...
MultiplicitiesInternal, SymHandle, ChargeSide, ChargeSideInt, CorrectDimensions,Braidings,BraidingDirections,KeepZeros);
end
function OutTensor = CreateDelta(Sym, ChargeDimensions, Legs)
if numel(Legs)<2; Legs = [Legs,0]; end;
Location = find(ChargeDimensions~=0, 1,'first');
Numbers = 1:numel(ChargeDimensions);
OutTensor = SymTensor.CreateOnes(Sym, ChargeDimensions.*(Numbers==Location), ChargeDimensions.*(Numbers==Location), Legs);
Temp = zeros(size(OutTensor.TensorEntries{1}));
mm = sum((repmat(1:size(Temp,1), [numel(size(Temp)),1])-1).*repmat(size(Temp,1).^((0:(numel(size(Temp))-1))'), [1,size(Temp,1)]),1)+1;
Temp(mm) = ones([1,size(Temp,1)]);
for kk = 1:numel(OutTensor.TensorEntries)
OutTensor.TensorEntries{kk} = Temp;
end
Location = Location+1;
while Location<=numel(ChargeDimensions)
if ChargeDimension(Location) == 0
Location = Location+1;
continue;
end
Location = Location+1;
TempTensor = SymTensor.CreateOnes(Sym, ChargeDimensions.*(Numbers==Location), ChargeDimensions.*(Numbers==Location), Legs);
Temp = zeros(size(TempTensor.TensorEntries{1}));
mm = (repmat(1:size(Temp,1), [1,size(Temp,1)])-1).*repmat(size(Temp,1).^(0:(size(Temp,1)-1)), [1,size(Temp,1)])+1;
Temp(mm) = ones([1,size(Temp,1)]);
for kk = 1:numel(TempTensor.TensorEntries)
TempTensor.TensorEntries{kk} = Temp;
end
OutTensor = OutTensor+TempTensor;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Load Ratio
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%this signals the updating with charges
function [Matrix, Data] = SymTen2Mat(Tensor, Legs, Shape)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%first step is to work out how we want to reshape it.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ReshapeData = 0;
if nargin<2 | isempty(Legs)
NumberLegsBottom = sum(Tensor.ChargeSide ==-1);
NumberLegsTop = sum(Tensor.ChargeSide ==+1);
else
NumberLegsBottom = Legs(1);
NumberLegsTop = Legs(2);
end
if nargin==3
if SymCanInsert(Tensor,Shape)
ChargeLabelsA = [Tensor.ChargeLabelsExternal,Tensor.ChargeLabelsInternal,Tensor.MultiplicitiesInternal];
ChargeLabelsB = [Shape.ChargeLabelsExternal,Shape.ChargeLabelsInternal,Shape.MultiplicitiesInternal];
[~,Index,FullIndex] = unique([ChargeLabelsB;ChargeLabelsA],'rows','first');
if any(Index>size(ChargeLabelsB,1))
error('Affirmation Error: Something is wrong with Shape and working out unique charges')
end
Locations = Index(FullIndex((size(ChargeLabelsB,1)+1):end));
ReplaceTensorEntries = Shape.TensorEntries;
if Shape.FlagIsAShape
for kk = 1:numel(ReplaceTensorEntries)
ReplaceTensorEntries{kk} = zeros(Shape.TensorEntriesSizes(kk,:));
end
else
for kk = 1:numel(ReplaceTensorEntries)
ReplaceTensorEntries{kk} = ReplaceTensorEntries{kk}*0;
end
end
ReplaceTensorEntries(Locations) = Tensor.TensorEntries;
Tensor = SymTensor.CreateRawTensorFrom(ReplaceTensorEntries, Shape,[],true);
else
error('Error: The input Shape is either not larger then the tensor we wish to find the matrix of, or of a qualitatively different layout, therefore we cannot insert Tensor Entries into Shape');
end
end
%check that this agrees with my code:
%check we haven't done something stupid, only way we could is
%by putting the wrong number of legs in:
if (NumberLegsBottom + NumberLegsTop) ~= size(Tensor.ChargeLabelsExternal,2)
error('The number of input legs is wrong for this tensor, we should have a different number')
end
if sum(Tensor.ChargeSide ==+1) ~= NumberLegsTop;
error('Error: Wrong number of Top Legs')
end
if sum(Tensor.ChargeSide ==-1) ~= NumberLegsBottom;
error('Error: Wrong number of Bottom Legs')
end
if ~isequal(Tensor.ChargeSide, [ones([1,NumberLegsBottom]),-ones([1,NumberLegsTop])])
[~,PermuteOrder] = sort(Tensor.ChargeSide);
Tensor = Tensor.Permute(PermuteOrder);
end
% Tensor = Tensor.SymReshape(ReshapeData);
Tensor = Tensor.SortLabels;
%check that the shape is correct
NumbersLegs = (1:(NumberLegsTop+NumberLegsBottom));
if NumberLegsBottom~=1
if ~isequal(sort(Tensor.StoredLocations{Tensor.Structure(1,1)},'ascend'), NumbersLegs(Tensor.ChargeSide == -1))
error('Error: The organisation sets the Bottom to be wrong')
end
else
if Tensor.Structure(1,1) ~= -1;
error('Error: The organisation sets the Bottom to be wrong')
end
end
if NumberLegsTop~=1
if ~isequal(sort(Tensor.StoredLocations{Tensor.Structure(2,1)},'ascend'), NumbersLegs(Tensor.ChargeSide == +1))
error('Error: The organisation sets the Top to be wrong')
end
else
if Tensor.Structure(2,1) ~= -(1+NumberLegsBottom);
error('Error: The organisation sets the Top to be wrong')
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%second step is to sort into matrix blocks
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Dim = Tensor.SymHandle.Dim;
%{
if Tensor.SymHandle.IsNonAbelian
SideStructure = zeros(size(Tensor.Structure));
[~,IndexExt] = sort(-Tensor.Structure(Tensor.Structure<0),'ascend');
[~,IndexInt] = sort(Tensor.Structure(Tensor.Structure>0),'ascend');
SideStructure(Tensor.Structure<0) = Tensor.ChargeSide(IndexExt);
SideStructure(Tensor.Structure>0) = -Tensor.ChargeSideInt(IndexInt);
PowerTerms = zeros(size(Tensor.Structure));
OutSameSide = SideStructure(1,:)==SideStructure(2,:);
PowerTerms = PowerTerms + 1*repmat(OutSameSide,[2,1]);
PowerTerms(:,2:end) = PowerTerms(:,2:end) + (~OutSameSide([1,1],2:end)).*(1-2*([Tensor.ChargeSideInt;Tensor.ChargeSideInt] ~= SideStructure(:,2:end) ));
PowerTermsInt = PowerTerms(Tensor.Structure>0); PowerTermsInt = PowerTermsInt(:)';
PowerTermsInt = PowerTermsInt(IndexInt) + (-1).^OutSameSide(:,2:end);
PowerTermsExt = PowerTerms(Tensor.Structure<0); PowerTermsExt = PowerTermsExt(:)';
PowerTermsExt = PowerTermsExt(IndexExt);
Dim = Tensor.SymHandle.Dim;
DimCorrections = prod(reshape(Dim([Tensor.ChargeLabelsExternal,Tensor.ChargeLabelsInternal],2),size([Tensor.ChargeLabelsExternal,Tensor.ChargeLabelsInternal]))...
.^(-repmat([PowerTermsExt,PowerTermsInt],[size(Tensor.ChargeLabelsExternal,1),1])/4),2);
for kk = 1:numel(Tensor.TensorEntries)
Tensor.TensorEntries{kk} = Tensor.TensorEntries{kk}*DimCorrections(kk);
end
end
%}
if NumberLegsBottom*NumberLegsTop ~= 0
if NumberLegsBottom > 1
[UniqueEntries,~,BlockLabelBottom] = unique(Tensor.ChargeLabelsInternal(:,NumberLegsBottom-1));
else %NumberLegsBottom == 1; as it can't be zero
[UniqueEntries,~,BlockLabelBottom] = unique(Tensor.ChargeLabelsExternal(:,1));
end
%UniqueEntries is the list of unique values that the matrix