-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathKiHA.wl
1733 lines (1268 loc) · 86.7 KB
/
KiHA.wl
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
(* ::Package:: *)
(*Copyright 2022,Gang Chen AmplitudeGravity/kinematicHofpAlgebra is licensed under the
GNU General Public License v3.0 . Permissions of this strong copyleft license are
conditioned on making available complete source code of licensed works and modifications,
which include larger works using a licensed work,under the same license.
Copyright and license notices must be preserved.Contributors provide an express grant
of patent rights.*)
(*KiHA is dependent on some basis functions which are written by Gustav Mogull and Gregor Kaelin in Uppsala theoritical physics group
*)(* Updating version can be find in
https://github.com/AmplitudeGravity/kinematicHofpAlgebra
*)
BeginPackage["KiHA`"]
Unprotect@@Names["KiHA`*"];
(* Exported symbols added here with SymbolName::usage *)
If[$Notebooks,
CellPrint[Cell[#,"Print",CellFrame->0.5,FontColor->Blue]]&,
Print][" KiHA(v6.0),Copyright 2022,author Gang Chen. It is licensed under the GNU General Public License v3.0.
KiHA is based on the work of Kinematic Hopf Algebra in CTP of Queen Mary University of London. It generates the duality all-n numerator for colour-kinematic duality and double copy in heavy mass effective
theory(HEFT), YM, YM-Scalar, YM-fermion, F3+F4 theory and DF2+YM theory. KiHA is built on some basic functions written by Gustav Mogull and Gregor Kaelin.
use ?KiHA`* for help and a series of papers (2111.15649, 2208.05519, 2208.05886,2310.11943) for more reference." ]
(* ::Subsection:: *)
(*KiHA Output function and variables*)
nice::usage ="nice the output form, //.nice"
niceT::usage ="nice the output form, //.niceT"
rmzero::usage ="remove the trivial terms dot prodoct functions"
rmzeroT::usage ="remove the trivial terms in T generator"
BinaryProduct::usage ="the binary products in a given order"
GBinaryProduct::usage ="all the binary products"
X::usage="Empty bracket"
ET::usage="extended generator of GT with flavor ET[GT[{1,3,2},{{3}}],{a[1],a[2]}]"
FT::usage="extended generator of GT with flavor FT[{{1,2},3}]"
GT::usage="extended generator of T with colour group GT[{1,3,2},{{3}}], first arg is colour order, sencond arg is the kinematic partitions"
T::usage="algebra generator, e.g. T[{1},{2,3}],"
\[DoubleStruckA]::usage="generator index of the flavor group"
p::usage="momentum vector"
\[Epsilon]::usage="polarization vector"
F::usage="strengthen tensor"
m::usage="mass of the field,"
\[DoubleStruckT]::usage="generator of the flavor group"
v::usage="velocity of the heavy particle or black hole"
T2F::usage ="transform abelian generators to strengthen tensor form in HEFT amplitude"
GT2F::usage ="transform non-abelian generators to strengthen tensor form in HEFT amplitude"
ET2F::usage ="transform generators to strengthen tensor form in amplitude with three more scalars"
ET2F2s ::usage ="transform generators to strengthen tensor form in amplitude with two scalars"
\[FivePointedStar] ::usage ="funsion product of the generators"
\[ScriptCapitalK] ::usage ="generators for the external states \[ScriptCapitalK][stateIndex_Integer, Spin_Integer]"
\[CapitalOmega] ::usage ="left nested commutators"
\[DoubleStruckCapitalS] ::usage ="antipode"
\[CapitalDelta] ::usage ="coproduct"
\[DoubleStruckCapitalI] ::usage ="Identity"
fsp::usage="fermion spin chain product"
Diamond::usage="a distributive general product"
KSetPartitions::usage="KSetPartitions[list,number of subsets]"
KSetPartitionsEmpty::usage="including empty sets KSetPartitionsEmpty[list,number of subsets]"
SetPartitionsOrdered::usage="SetPartitionsOrdered[number of subsets]"
ddmBasis::usage ="generate the ddm basis, ddmBasis[n]"
KLTR::usage ="generate the one elemment of the KLT matrix KLTR[f_List]"
KLTRM::usage ="generate the first row of the KLT matrix, e.g. KLTRM[5] generate the KLT matrix element for the colour order{1,2,3,4,5} "
ExpandNCM::usage ="Expand the non-commutative multiply"
NC::usage="commutator of the non-commutative multiply"
(* ::Subsection:: *)
(*QCD current*)
numRecQCD::usage="BCJ numerator for QCD amplitude numRecQCD[n] or numRecQCD[{1,2,3...}] "
NumRec::usage="BCJ numerator for QCD amplitude NumRec[{1,2,3...}] "
FT2F::usage="transform fermion algebra to F form "
FRank2::usage="G2 function "
JQCD::usage="Generate the qcd current from current algebra JQCD[{1,2,3,4}]"
X2Prop::usage="The propagators from the binary product. The last line is taken as on-shell"
(* ::Subsection:: *)
(*alpha' higher orders*)
T2FF3F4::usage="transform F^3+F^4 kinematic algebra to F form"
T2YMLocal::usage="transform YM local kinematic algebra to F form "
WFun::usage="W prime function in F^3+F^4 evaluation map"
W::usage="Abstract W prime function"
\[Alpha]::usage="string tension constant"
W0::usage="Abstract W0 function"
WFunDF2::usage="W prime function in the DF^2+YM evaluation map,WFunDF2[1,2,3,4,5],WFunDF2[1,2,3,4,5,{{{1,2},{3,4,5}}}]"
MultiTrace::usage="generate terms in the BCJ numerator corresponding to the multi trace partitions, e.g. MultiTrace[5]
MultiTrace[1,2,3,4,5],MultiTrace[5,{{{1,2},{3,4,5}}}],MultiTrace[1,2,3,4,5,{{{1,2},{3,4,5}}}]"
WFunDF2SingleTr::usage="W prime single trace function in the DF^2+YM evaluation map,WFunDF2SingleTr[1,2,3,4,5]"
SingleTrace::usage="generate single trace terms in the BCJ numerator corresponding to the multi trace partitions, e.g. SingleTrace[5]
SingleTrace[1,2,3,4,5]"
W0Relations::usage="generate all the relations of W0 or W prime function, e.g. W0Relations[5],W0Relations[1,2,3,4,5]"
repW0::usage="replace all the W0 function to their basis"
repWp::usage="replace all the W prime function to their basis"
trFLA::usage="value of W0 function, e.g. trFLA[1,2,3,4,5]"
WFun0::usage="value of W function, e.g. WFun0[1,2,3,4,5]"
W2basis::usage="efficient replace all the W prime function to their basis,W2basis[W[2,1,3,5,4]]"
W02basis::usage="efficient replace all the W0 function to their basis"
WFun2YM::usage="Generate the W function for pure Yang-Mills BCJ numerator, e.g WFun2YM[1,2,3,4,5]"
TScalar::usage="transform scalar-YM kinematic algebra to F form, e.g.TScalar[1,2,3,4]"
(* ::Subsection:: *)
(*Scalars*)
setGlobalDim::usage = "setGlobalDim[d] sets d as the global dimension."
setGlobalDim::ssle = "Protected objects cannot be set as the global dimension."
setGlobalDim::author = "Gustav Mogull"
declareAntisymmetric::usage="set function is antisymmetric under exchange the order of the variables"
declareSymmetric::usage="set function do not dependent order of the variables"
(* ::Subsection::Closed:: *)
(*Vectors*)
tensorQ::usage = "tensorQ[p] yields True if p is a tensor, and yields False otherwise."
tensorQ::author = "Gustav Mogull"
vectorQ::usage = "vectorQ[p] yields True if p is a vector (rank-1 tensor), and yields False otherwise."
vectorQ::author = "Gustav Mogull"
tensorQR2::usage = "vectorQ[p] yields True if p is a vector (rank-1 tensor), and yields False otherwise."
tensorQR2::author = "Gustav Mogull"
antiTensorQ::usage="antiTensorQ[p[1]] yields True if p is tensor head"
tensorDim::usage = "tensorDim[p] returns the dimensionality of the declared vector p."
tensorDim::argx = "tensorDim should only be called on tensors."
tensorDim::author = "Gustav Mogull"
tensorRank::usage = "tensorRank[p] yields the rank of the declared tensor p."
tensorRank::argx = "tensorRank should only be called on tensors."
tensorRank::author = "Gustav Mogull"
declareVector::usage = "declareVector[p] declares p as a vector (rank-1 tensor).
declareVector[{p1,p2,...}] declares p1, p2, ... as vectors.
declareVector has options 'dim' and 'verbose'. By default, 'dim' is the global dimension and 'verbose' is true."
declareVector::safe = "Only unprotected symbols can be declared as vectors."
declareVector::author = "Gustav Mogull"
declareVectorHead::usage = "declareVectorHead[p] declares that all objects with header p should be treated as vectors (rank-1 tensors).
declareVectorHead[{p1,p2,...}] declares p1, p2, ... as vector headers.
declareVectorHead has options 'dim' and 'verbose'. By default, 'dim' is the global dimension and 'verbose' is true."
declareVectorHead::safe = "Only unprotected symbols can be declared as vector headers."
declareVectorHead::author = "Gustav Mogull"
declareTensor::usage = "declareTensor[F] declares F as a tensor.
declareTensor[{F1,F2,...}] declares F1, F2, ... as tensors.
declareTensor has options 'dim', 'rank' and 'verbose'. By default, 'dim' is the global dimension, 'rank' is 1 and 'verbose' is true."
declareTensor::safe = "Only unprotected symbols can be declared as tensors."
declareTensor::author = "Gustav Mogull"
declareTensorHead::usage = "declareTensorHead[p] declares that all objects with header p should be treated as tensors.
declareTensorHead[{F1,F2,...}] declares F1, F2, ... as tensor headers.
declareTensorHead has options 'dim', 'rank' and 'verbose'. By default, 'dim' is the global dimension, 'rank' is 1 and 'verbose' is true."
declareTensorHead::safe = "Only unprotected symbols can be declared as tensor headers."
declareTensorHead::author = "Gustav Mogull"
declareAntiTensorHead::usage="declareAntiTensorHead[p], declareAntiTensorHead[{F1, F2}] declare the antiSymmetric tensor "
undeclareTensor::usage = "undeclareTensor[p] undeclares p as a vector.
undeclareTensor has the option 'verbose', by default taken as True."
undeclareTensor::author = "Gustav Mogull"
undeclareTensorHead::usage = "undeclareTensorHead[p] undeclares p as a tensor header.
undeclareTensorHead has the option 'verbose', by default taken as True."
undeclareTensorHead::author = "Gustav Mogull"
dot::usage = "dot[p1,p2] represents the symmetric Lorentz inner product between the two vectors p1 and p2.
dot[p1,F1,F2,...,p2] represents an inner product where p1, p2 are vectors and F1, F2, ... are rank-2 tensors.
dot[p] evaluates as dot[p,p]."
dot::badrank = "The first and last arguments of dot should be rank-1 tensors (vectors); any inbetween should be rank-2 tensors."
dot::author = "Gustav Mogull"
tr::usage = "tr[F1,F2,...] represents the trace of rank-2 tensors F1, F2, ...."
tr::author = "Gustav Mogull"
eps::usage = "eps[p1,p2,...,pd] represents the integer d-dimensional Levi-Civita symbol acting on vectors p1, p2, ..., pd."
eps::author = "Gustav Mogull"
outer::usage = "outer[p1,p2] is a rank-2 tensor representing the outer product between two vectors p1, p2."
outer::author = "Gustav Mogull"
eta::usage = "eta is a rank-2 tensor representing the flat (mostly-minus) metric."
eta::author = "Gustav Mogull"
mu::usage = "mu[l1,l2] represents the symmetric Lorentz inner product between the extra-dimensional parts of the two vectors l1 and l2.
mu[l] evaluates as mu[l,l]."
mu::argx = "mu called with `1` arguments; 1 or 2 arguments are expected."
mu::badrank = "The arguments of mu should be rank-1 tensors (vectors)."
mu::author = "Gustav Mogull"
aMu::usage = "aMu[l1,l2] represents the antisymmetric product of the extra-dimensional part of two vectors l1 and l2"
aMu::author = "Gregor Kaelin"
(* ::Subsection::Closed:: *)
(*Spinors*)
spQ::usage = "spQ[p] yields True if p is a spinor, and yields False otherwise."
spQ::author = "Gustav Mogull"
spA::usage = "spA[p] represents the angle spinor of a vector p."
spB::usage = "spB[p] represents the square spinor of a vector p."
spA::author = "Gustav Mogull"
spB::author = "Gustav Mogull"
spAA::usage = "spAA[p1,p2,...,pn] yields the spinor bracket sp[spA[p1],p2,...,spA[pn]]."
spAB::usage = "spAB[p1,p2,...,pn] yields the spinor bracket sp[spA[p1],p2,...,spB[pn]]."
spBA::usage = "spBA[p1,p2,...,pn] yields the spinor bracket sp[spB[p1],p2,...,spA[pn]]."
spBB::usage = "spBB[p1,p2,...,pn] yields the spinor bracket sp[spB[p1],p2,...,spB[pn]]."
spAA::author = "Gustav Mogull"
spBB::author = "Gustav Mogull"
spAB::author = "Gustav Mogull"
spBA::author = "Gustav Mogull"
spp::usage = "spp[sp1,sp2] represents an antisymmetric inner product between the two spinors sp1 and sp2 (angle or square bracket).
spp[sp1,p1,p2,...,sp2] represents a spinor product with vectors p1, p2, ... inserted."
spp::author = "Gustav Mogull"
spOuter::usage = "spOuter[sp1,sp2] is a vector formed from the outer product of an angle and a square spinor.
spOuter[p] returns spOuter[spA[p],spB[p]]."
spOuter::notvector = "spOuter with one argument should only be applied to vectors."
spOuter::badspinors = "spOuter should act on one angle and one square spinor."
spOuter::argx = "spOuter called with `1` arguments; 1 or 2 arguments are expected."
spOuter::author = "Gustav Mogull"
toSpinors::usage = "toSpinors[expr,vecs] converts all instances of the four-dimensional vectors vecs in expr to spinors."
toSpinors::ssle = "Only four-dimensional vectors can be converted to spinors."
toSpinors::author = "Gustav Mogull"
(* ::Subsection::Closed:: *)
(*Free Indices*)
lI::usage = "lI[i] represents the i'th Lorentz (spacetime) index."
lI::author = "Gustav Mogull"
ui::usage = "ui[j] represents the i'th general metric up index."
ui::author = "Gang Chen"
di::usage = "di[j] represents the i'th general metric down index."
di::author = "Gang Chen"
(* spI::usage = "spI[i] represents the i'th spinor index."
spI::author = "Gustav Mogull" *)
contract::usage = "contract[expr] contracts all pairs of raised and lowered Lorentz indices in expr."
contract::author = "Gustav Mogull"
contractAnti::usage = "contractAnti[expr] contract in expr with the anti-symmetric tensor or vectors"
contractAnti::author = "Gang Chen"
contractspp::usage = "contractspp[expr] contract in expr with index in spp"
contractspp::author = "Gang Chen"
contractSp::usage = "contractSp[expr] nice form of the contract in expr with index in spp"
contractSp::author = "Gang Chen"
expandTensor::usage="expandTensor[dot[f]] expands all the tensor into the conponent"
expandTensor::author="Gang Chen"
dressIndex::usage = "dressIndex[expr,i] dresses the expression expr with the free Lorentz index i."
dressIndex::author = "Gustav Mogull"
freeIndices::usage = "freeIndices[expr] finds the overall free index structure in expr."
freeIndices::author = "Gustav Mogull"
exposeIndex::author = "Gustav Mogull"
indexCoefficient::author = "Gustav Mogull"
(* ::Subsection::Closed:: *)
(*Other*)
parkeTaylor::usage = "parkeTaylor[p1,p2,...,pn] gives the Parke-Taylor factor for n four-dimensional vectors p1, p2, ..., pn."
parkeTaylor::ssle = "parkeTaylor should only be called on four-dimensional vectors."
parkeTaylor::author = "Gustav Mogull"
basisExpand::author = "Gustav Mogull"
lgScaling::usage = "lgScaling[expr,vec] counts the little-group scaling of expr with respect to the on-shell vector vec."
lgScaling::author = "Gustav Mogull"
massDim::usage = "massDim[expr] counts the mass dimension of expr."
massDim::author = "Gustav Mogull"
protectedQ::usage = "protectedQ[expr] checks whether expr is an unprotected symbol."
protectedQ::author = "Gustav Mogull"
(* safeVariableQ::usage = "safeVariableQ[expr] checks whether expr is an unprotected symbol."
safeVariableQ::author = "Gustav Mogull" *)
distributive::usage = "distributive is an option used for distributive functions to determine their behavior."
distributive::author = "Gustav Mogull"
verbose::usage = "verbose is an option used to determine whether certain functions give printed output statements."
verbose::author = "Gustav Mogull"
declareDistributive::usage = "declareDistributive[s,test] declares that the symbol s should linearly distribute its arguments over objects satisfying test.
declareDistributive[s,test, n1, n2] specifies that the first n1 and last n2 arguments of s should be excluded.
declareDistributive[s,test, n1, n2, default] specifies that the default value of distributive should be default."
declareDistributive::author = "Gustav Mogull, Gregor Kaelin"
declareDistributiveMiddle::author = "Gustav Mogull, Gregor Kaelin"
declareDistributiveFirst::author = "Gustav Mogull, Gregor Kaelin"
declareDistributiveLast::author = "Gustav Mogull, Gregor Kaelin"
distributiveRules::author = "Gustav Mogull, Gregor Kaelin"
patternFreeQ::usage = "Checks if an expression is free of any any pattern (i.e. Pattern, Blank, BlankSequence, BlankNullSequence)"
patternFreeQ::author = "Gregor Kaelin"
(* ::Section:: *)
(*Private*)
Begin["`Private`"]
(*declareVectorHead[{p}];
declareTensorHead[{F},{"rank"-> 2}];*)
(* ::Subsection:: *)
(*Simplifications*)
nice={p[i__]:> Subscript[p, i],F[i_]:> Subscript[F, i],\[DoubleStruckA][i_]:> Subscript[\[DoubleStruckA], i],
dot[f___]:> CenterDot[f],CenterDot[p[i_],\[Epsilon][j_]]:>CenterDot[\[Epsilon][j],p[i]],
a_[i_]?vectorQ:> Subscript[a, i],a_[i_]?tensorQ:> Subscript[a, i],spp-> Diamond,J[f1_,f2_,f3_]:> Subscript[J, f2],J[f1_,f2_]:> Subscript[J, f2]};
(*niceF={dot[f_]:> CenterDot[f,f],dot[f__]:> CenterDot[f],p[i__]:> Subscript[p, i],F[i_]:> Subscript[F, i],a[i_]:> Subscript[a, i]};*)
(*niceT={T[f___]:>(Subscript[T, f]/. List->L),L[f1___]:>"("<>ToString/@{f1}<>")"}*)
niceT={T[f___]:>(Subscript[T, f]/. List->L),\[DoubleStruckA][i_]:>\[DoubleStruckT]^Subscript[\[DoubleStruckA], i],GT[{f1___},{f2___}]:>(\!\(\*SuperscriptBox[
SubscriptBox[\(T\), \(f2\)], \("\<(\>" <> ToString /@ {f1} <> "\<)\>"\)]\)/. List->L),L[f1___]:>"("<>ToString/@{f1}<>")",ET[f1_GT,{f2__}]:>f1 tr[CenterDot[f2]]}
rmzero={dot[a_,F[i_],a_]:> 0,dot[p[],f__,v]:> 0,dot[p[],g___]:> 0,dot[g___,p[]]:> 0};
rmzeroT={T[{i_},g___]:> 0,T[f__,{1,h___},g___]:>0,FT[f1_,g__]:>0/;(Length[f1[[1]]]==1||f1[[1,1]]=!=1)};
SetAttributes[Diamond,{NHoldAll}];
declareDistributive[Diamond,tensorQ];
declareDistributive[Diamond,vectorQ];
(*Generating the binary product*)
(* ::Subsection:: *)
(*BinaryProduct and DDM*)
shuffle[s1_List,s2_List]:=shuffle[s1,s2]=Module[{p,tp,ord},p=Permutations@Join[1&/@s1,0&/@s2]\[Transpose];
tp=BitXor[p,1];
ord=Accumulate[p] p+(Accumulate[tp]+Length[s1]) tp;
Outer[Part,{Join[s1,s2]},ord,1][[1]]\[Transpose]]
BinaryProduct[n_]:=Block[{v,bpX,bpvars2,h,h0,tt},
v=Range[n];
If[n>=2,bpX={X[v[[1]],v[[2]]]};bpvars2={{v[[2]]}},Return[v[[1]]]];
Do[h={};
h0={};(*Print[i];*)
tt=addOne[v[[i]],bpX,bpvars2];bpX=tt[[1]];bpvars2=tt[[2]],{i,3,Length[v]}];
Return[bpX]
]
addOne[vi_,bpX_,bpvars2_]:=Block[{sexpr,vars2,lv2,newvars,h,h0},h={};h0={};Do[(*Print[ii];*)sexpr=bpX[[ii]];vars2=bpvars2[[ii]];lv2=Length[vars2];
Do[h=Join[h,{sexpr/.vars2[[jj]]-> X[vars2[[jj]],vi]}];
newvars=Table[vars2[[k]]/.vars2[[jj]]-> X[vars2[[jj]],vi],{k,jj}];
newvars=Join[newvars,{vi}];
h0=Join[h0,{newvars}],{jj,lv2}];
h=Join[h,{X[sexpr,vi]}];
h0=Join[h0,{{vi}}],
{ii,Length[bpX]}];
(*Print[h,h0];*)
Return[{h,h0}]
]
BinaryProduct[f_List]:=BinaryProduct[Length[f]]/.i_/;IntegerQ[i]:> f[[i]]
GBinaryProduct[h_List/;Length[h]>2]:=Module[{pts,res,r1,r2},pts=partition[h]//Cases[f_/;Length[f]==2];(*pts=Drop[pts,{-1}];*)Table[r1=(GBinaryProduct[pts[[ii,1]]]);r2=(GBinaryProduct[pts[[ii,2]]]);res=Table[X[r1[[ii1]],r2[[ii2]]],{ii1,Length@r1},{ii2,Length@r2}]//Flatten,{ii,Length@pts}]//Flatten]
GBinaryProduct[h_List/;Length[h]==2]:={X[h[[1]],h[[2]] ]}
GBinaryProduct[h_List/;Length[h]==1]:={h[[1]]}
diagNumber[n_]:=1/(n-2+1)*Binomial[2*(n-2),n-2]
(*Programms on the closed form and convolution map*)
ddmBasis[momlist_List] /; If[Length[momlist]>=3,True,Message[ddmBasis::notenoughpoints];False]:=Block[{},
If[!vectorQ[#],declareTensor[#]]&/@momlist;
Prepend[#,momlist[[1]]]&/@(Append[#,momlist[[-1]]]&/@Permutations[momlist[[2;;-2]]])
]
replace[otherDDMOrder_,n_]:=Table[(p/@Range[n-1])[[i]]-> otherDDMOrder[[i]],{i,n-1}];
KLTR[f_List]:=KLTR[f]=Which[Length[f]>2,Module[{imax=Max[f],idmax,fr,fl},idmax=Position[f,imax]//Flatten;fr=Drop[f,idmax];
fl=f[[1;;(idmax[[1]]-1)]];2dot[p[imax],(p/@fl)//Total]KLTR[fr]],Length[f]==2,2dot@@(p/@f),Length[f]<2,Print["Length of f should be large than 2"]]
KLTRM[n_]:=KLTR/@(Drop[#,-1]&/@ddmBasis[Range[n]])
(* ::Subsection:: *)
(*SetPartitions*)
KSetPartitions[0,0]:={{}}
KSetPartitions[{},0]:={{}}
KSetPartitions[s_List,0]:={}
KSetPartitions[s_List,k_Integer]:={}/;k>Length[s]
KSetPartitions[s_List,k_Integer]:={({#1}&)/@s}/;k===Length[s]
KSetPartitions[s_List,k_Integer]:=Block[{$RecursionLimit=Infinity,j},Join[(Prepend[#1,{First[s]}]&)/@KSetPartitions[Rest[s],k-1],Flatten[(Table[Prepend[Delete[#1,j],Prepend[#1[[j]],s[[1]]]],{j,Length[#1]}]&)/@KSetPartitions[Rest[s],k],1]]]/;k>0&&k<Length[s]
KSetPartitions[0,(k_Integer)?Positive]:={}
KSetPartitions[(n_Integer)?Positive,0]:={}
KSetPartitions[(n_Integer)?Positive,(k_Integer)?Positive]:=KSetPartitions[Range[n],k]
NSetPartitions[s_List,n_Integer]:=Select[SetPartitions[s],Union[Length/@#]=={2}&];
KSetPartitionsEmpty[s_List,k_Integer]:=Module[{app,KMod},app=KSetPartitions[s,k];
Do[KMod=KSetPartitions[s,q];
Do[Do[AppendTo[KMod[[i]],{}],{j,1,k-q}];
AppendTo[app,KMod[[i]]],{i,Length[KSetPartitions[s,q]]}],{q,1,k-1}];Return[app]];
KSetPartitionsEmptyPerm[s_List,k_Integer]:=Module[{app,KMod,app2={}},app=KSetPartitions[s,k];
Do[KMod=KSetPartitions[s,q];
Do[Do[AppendTo[KMod[[i]],{}],{j,1,k-q}];
AppendTo[app,KMod[[i]]],{i,Length[KSetPartitions[s,q]]}],{q,1,k-1}];
Do[AppendTo[app2,Permutations[app[[ii]]]],{ii,Length[app]}];
app2=Flatten[app2,1]//DeleteDuplicates;Return[app2]];
SetPartitionsOrdered[1]={{{1}}};
SetPartitionsOrdered[n_Integer]:=Module[{app={},previous=SetPartitionsOrdered[n-1]},Do[app=Join[app,{Append[previous[[ii,1;;-2]],Append[previous[[ii,-1]],n]],AppendTo[previous[[ii]],{n}]}],{ii,Length[previous]}];
Return[app]];
(* ::Subsection:: *)
(*Algebraic generators to dot product of F*)
(*Tt[od_]:=Module[{phat=Range[Length@od],leftv,num,den},phat[[1]]=v;Table[(*If[od[[i,1]]>Max[Flatten[od\[LeftDoubleBracket]1;;(i-1)\[RightDoubleBracket]]],*)phat[[i]]=p@@Select[Flatten[od[[1;;(i-1)]]],#<od[[i,1]]&](*,phat[[i]]=p@@Range[od[[i,1]]-1]]*),{i,2,Length@od}];leftv=phat;
num=Times@@Table[dot[leftv[[i]],F/@od[[i]],v]/.dot[gg_,List[gf___],hh_]:> dot[gg,gf,hh],{i,Length@od}];
den=(-1)^Length@od dot[v,p[1]]Product[dot[v,p@@Flatten[od[[1;;(i-1)]]]],{i,2,Length@od}];
num/den
]*)
T2F[{i_}]:=dot[\[Epsilon][i],v]
T2F[f__]:=Module[{od={f},phat,leftv,num,den},phat=Range[Length@od];
(*If[od===T[{i_}]];*)
phat[[1]]=v;Table[(*If[od[[i,1]]>Max[Flatten[od\[LeftDoubleBracket]1;;(i-1)\[RightDoubleBracket]]],*)phat[[i]]=p@@Select[Flatten[od[[1;;(i-1)]]],#<od[[i,1]]&](*,phat[[i]]=p@@Range[od[[i,1]]-1]]*),{i,2,Length@od}];leftv=phat;
num=Times@@Table[dot[leftv[[i]],F/@od[[i]],v]/.dot[gg_,List[gf___],hh_]:> dot[gg,gf,hh],{i,Length@od}];
den=dot[v,p[1]]Product[dot[v,p@@Flatten[od[[1;;(i-1)]]]],{i,2,Length@od}];
num/den
]
GT2F[{g__},{{i_}}]:=dot[\[Epsilon][i],v]
GT2F[f1_List,f2_List]:=Module[{cod=f1,od=f2,phat,leftv,num,den},phat=Range[Length@od];phat[[1]]=v;Table[(*If[od[[i,1]]>Max[Flatten[od\[LeftDoubleBracket]1;;(i-1)\[RightDoubleBracket]]],*)phat[[i]]=p@@Select[Flatten[od[[1;;(i-1)]]],Position[cod,#][[1,1]]<Position[cod,od[[i,1]]][[1,1]]&](*,phat[[i]]=p@@Range[od[[i,1]]-1]]*),{i,2,Length@od}];leftv=phat;
num=Times@@Table[dot[leftv[[i]],F/@od[[i]],v]/.dot[gg_,List[gf___],hh_]:> dot[gg,gf,hh],{i,Length@od}];
den=dot[v,p[MinimalBy[od//Flatten,Position[cod,#1]&]//First]]Product[dot[v,p@@Flatten[od[[1;;(i-1)]]]],{i,2,Length@od}];
num/den
]
GTRM0[f1_List,f2_List]:=Module[{cod=f1,od=f2,phat},phat=Range[Length@od];phat[[1]]=v;Table[(*If[od[[i,1]]>Max[Flatten[od\[LeftDoubleBracket]1;;(i-1)\[RightDoubleBracket]]],*)phat[[i]]=p@@Select[Flatten[od[[1;;(i-1)]]],Position[cod,#][[1,1]]<Position[cod,od[[i,1]]][[1,1]]&](*,phat[[i]]=p@@Range[od[[i,1]]-1]]*),{i,2,Length@od}];
(*Print[phat];*)
If[MemberQ[phat,p[]],0,GT[f1,f2]]
]
TScalar[{i_}]:=dot[\[Epsilon][i],p[0]]
TScalar[f__]:=Module[{od={f},phat,leftv,rightv,num,den},phat=Range[Length@od];
(*If[od===T[{i_}]];*)
phat[[1]]=p[0];Table[(*If[od[[i,1]]>Max[Flatten[od\[LeftDoubleBracket]1;;(i-1)\[RightDoubleBracket]]],*)phat[[i]]=p@@Select[Flatten[od[[1;;(i-1)]]],#<od[[i,1]]&](*,phat[[i]]=p@@Range[od[[i,1]]-1]]*),{i,2,Length@od}];leftv=phat;
rightv=Range[Length@od];
rightv[[1]]=p[0];
Table[(*If[od[[i,1]]>Max[Flatten[od\[LeftDoubleBracket]1;;(i-1)\[RightDoubleBracket]]],*)rightv[[i]]=p[0]+p@@Select[Flatten[od[[1;;(i-1)]]],#>od[[i,-1]]&](*,phat[[i]]=p@@Range[od[[i,1]]-1]]*),{i,2,Length@od}];
num=Times@@Table[dot[leftv[[i]],F/@od[[i]],rightv[[i]]]/.dot[gg_,List[gf___],hh_]:> dot[gg,gf,hh],{i,Length@od}];
den=1/2 dot[p[0]+p[1]]Product[1/2 dot[p[0]+p@@Flatten[od[[1;;(i-1)]]]],{i,2,Length@od}];
num/den
]
ET2F[f_GT,flavors_List]:=Module[{flavor=flavors,od=f[[2]],cod=f[[1]],phat,leftv,rightv,num,den,scalars},phat=Range[Length@od];
scalars=Complement[Flatten[cod],Flatten[od]];
(*If[od===T[{i_}]];*)
Table[(*If[od[[i,1]]>Max[Flatten[od\[LeftDoubleBracket]1;;(i-1)\[RightDoubleBracket]]],*)phat[[i]]=p@@Select[Flatten[Join[scalars,od[[1;;(i-1)]]]],Position[cod,#][[1,1]]<Position[cod,od[[i,1]]][[1,1]]&](*,phat[[i]]=p@@Range[od[[i,1]]-1]]*),{i,1,Length@od}];leftv=phat;
rightv=Range[Length@od];
Table[(*If[od[[i,1]]>Max[Flatten[od\[LeftDoubleBracket]1;;(i-1)\[RightDoubleBracket]]],*)rightv[[i]]=p@@Select[Flatten[Join[scalars,od[[1;;(i-1)]]]],Position[cod,#][[1,1]]>Position[cod,od[[i,-1]]][[1,1]]&](*,phat[[i]]=p@@Range[od[[i,1]]-1]]*),{i,1,Length@od}];
num=Times@@Table[dot[leftv[[i]],F/@od[[i]],rightv[[i]]]/.dot[gg_,List[gf___],hh_]:> dot[gg,gf,hh],{i,Length@od}];
den=1/2 dot[p@@scalars]Product[1/2 dot[(p@@scalars)+p@@Flatten[od[[1;;(i-1)]]]],{i,2,Length@od}];
den=den/.dot[gg__]:>dot[gg]-m^2;
flavor=CenterDot@@(flavor/.\[DoubleStruckA][i_]:>\[DoubleStruckT]^\[DoubleStruckA][i]);
flavor num/den
]
ET2F2s[f_GT,flavors_List]:=Module[{flavor=flavors,od=f[[2]],cod=f[[1]],phat,leftv,rightv,num,den,refs,sc,refg},leftv=Range[Length@od];
refs=Join[Complement[Flatten[cod],Flatten[od]],{Min[Flatten[od]]}];
sc=First@Complement[Flatten[cod],Flatten[od]];
refg=Min[Flatten[od]];
If[Not[(cod[[1]]==sc&&cod[[-1]]==refg)||(cod[[1]]==refg&&cod[[-1]]==sc)],num=0;Return[num]];
(*If[od===T[{i_}]];*)
leftv[[1]]=p@@Complement[Flatten[cod],Flatten[od]];
Table[(*If[od[[i,1]]>Max[Flatten[od\[LeftDoubleBracket]1;;(i-1)\[RightDoubleBracket]]],*)leftv[[i]]=p@@Select[DeleteDuplicates[Flatten[Join[refs,od[[1;;(i-1)]]]]],Position[cod,#][[1,1]]<Position[cod,od[[i,1]]][[1,1]]&](*,phat[[i]]=p@@Range[od[[i,1]]-1]]*),{i,2,Length@od}];
rightv=Range[Length@od];
rightv[[1]]=p@@Complement[Flatten[cod],Flatten[od]];
Table[(*If[od[[i,1]]>Max[Flatten[od\[LeftDoubleBracket]1;;(i-1)\[RightDoubleBracket]]],*)rightv[[i]]=p@@Select[DeleteDuplicates[Flatten[Join[refs,od[[1;;(i-1)]]]]],Position[cod,#][[1,1]]>Position[cod,od[[i,-1]]][[1,1]]&](*,phat[[i]]=p@@Range[od[[i,1]]-1]]*),{i,2,Length@od}];
num=Times@@Table[dot[leftv[[i]],F/@od[[i]],rightv[[i]]]/.dot[gg_,List[gf___],hh_]:> dot[gg,gf,hh],{i,1,Length@od}];
den=dot[p@@refs]Product[1/2 dot[(p@@DeleteDuplicates[Flatten[Join[refs,od[[1;;(i-1)]]]]])],{i,2,Length@od}];
den=den/.dot[gg__]:>dot[gg]-m^2;
flavor=CenterDot@@(flavor/.\[DoubleStruckA][i_]:>\[DoubleStruckT]^\[DoubleStruckA][i]);
flavor num/den
]
FT2F[f_FT]:=Module[{fls,od,odl,n,phat,leftv,rightv,num,num1,den,refs,sc,refg},
fls=List@@f;
od=fls[[All,1]];
n=2+Length@(od//Flatten);
leftv=Range[Length@od];
leftv[[1]]=0;
rightv=Range[Length@od];
rightv[[1]]=0;
Table[
odl=Flatten[od[[1;;(i-1)]]];
leftv[[i]]=p@@Select[odl,#<od[[i,1]]&];
rightv[[i]]=p@@Join[{n},Select[odl,#>od[[i,-1]]&]],{i,2,Length@od}];
num=dot[p[n],F[Sequence@@od[[1]]],lI[1]]fsp[lI[1]]+1/4 dot[p[1],F[Sequence@@Rest[od[[1]]]],lI[1]] fsp[F[1], lI[1]];
Do[If[fls[[ii,2]]==2,num=num/.fsp[gg__]:>fsp[gg,F[leftv[[ii]],od[[ii]]]],num=num/.fsp[gg__]:>2dot[leftv[[ii]],F[Sequence@@od[[ii]]],rightv[[ii]]]fsp[gg]],{ii,2,Length@fls}];
den=dot[p[n,1]]Product[ dot[(p@@Flatten[Join[{n},od[[1;;(i-1)]]]])],{i,2,Length@od}];
den=den;
(num/den)//.fsp[f1___,F[p[g__],{i_,h___}],f2___]:>FRank2[p[g],{i,h}]fsp[f1,lI[i],lI[i,0],f2]
]
(*FRank2[pv_,{i_}]:=dot[pv,F[i],lI[i]]p[i][lI[i,0]]
FRank2[pv_,od_List]:=FRank2[pv,od]=Module[{fewF,newF1,newF2},fewF=FRank2[pv,od[[1;;-2]]]//Expand;newF1=fewF/.dot[f__,lI[i_,0]]:>dot[f,F[od[[-1]]],lI[i,0]]/.p[ii__][lI[i_,0]]:>dot[p[ii],F[od[[-1]]],lI[i,0]];
newF2=fewF/.dot[h__,lI[i_]]dot[p[f__],g__,lI[i_,0]]:>0(*/.dot[h__,lI[i_]]dot[p[f__],g__,lI[i_,0]]:>dot[h,Sequence@@{First[{g}]},lI[i]]dot[p[f],Sequence@@Rest[{g}],F[od[[-1]]],lI[i,0]]*)/.dot[h__,lI[i_]]p[ii__][lI[i_,0]]:>dot[h,F[od[[-1]]],lI[i]]dot[p[ii,od[[-1]]],lI[i,0]];
newF1+newF2
]*)
FRank2[pv_,od_List]:=Module[{pts,lv,res},pts=KSetPartitionsEmpty[od,2];res=Sum[lv=p@@Select[pts[[ii,1]],#<pts[[ii,2,1]]&];dot[pv,F@@pts[[ii,1]],lI[od[[1]]]]dot[lv,F@@pts[[ii,2]],lI[od[[1]],0]],{ii,-1+Length@pts}];
res=res+dot[pv,F@@od,lI[od[[1]]]]dot[p@@od,lI[od[[1]],0]]
]
partition[{x_}]:={{{x}}}
partition[{r__,x_}]:=partition[{r,x}]=Join@@(ReplaceList[#,{{b___,{S__},a___}:>{b,{S,x},a},{S__}:>{S,{x}}}]&/@partition[{r}])
mypartition[ls_,j_]:=Module[{allpt,tb1,tb2},allpt=partition[ls];
allpt=Permutations/@allpt//Flatten[#,1]&;tb1=Table[Join[{Join[{j},allpt[[ii,1]]]},allpt[[ii,2;;Length@allpt[[ii]]]]],{ii,Length@allpt}];
tb2=Join[{{j}},#]&/@allpt;
Join[tb1,tb2]]
mypartition[ls_]:=Module[{allpt,tb1,tb2},allpt=partition[ls];
allpt=Permutations/@allpt//Flatten[#,1]&;tb1=Table[Join[{Join[{1},allpt[[ii,1]]]},allpt[[ii,2;;Length@allpt[[ii]]]]],{ii,Length@allpt}]
(*tb2=Join[{{1}},#]&/@allpt;*)
(*Join[tb1,tb2]*)]
partitionPreNum[ls_]:=mypartition[ls[[2;;-1]],ls[[1]]]
partitionOrdered[ls_]:=Module[{allpt},allpt=partition[ls];
(*allpt=Permutations/@allpt//Flatten[#,1]&;*)Table[Join[{Join[{1},allpt[[ii,1]]]},allpt[[ii,2;;Length@allpt[[ii]]]]],{ii,Length@allpt}]]
partitionOd[fl_]:= Module[{allpt},allpt=partition[fl];Cases[allpt,x_/;OrderedQ[Flatten[x]]]]
MyPartitionOd[f_]:=Cases[partitionOd[Sort[f]]/.MapThread[Rule,{Sort[f],f}],x_/;And@@OrderedQ/@x]
inLeft[i_, ls_, top_]:=MemberQ[ls[[1;;Flatten[Position[ls,i]][[1]] ]],(top//Cases[Rule[ii_,i]:> ii])[[1]]]
inLeft[ls_, top_]:=And@@Table[inLeft[ls[[ii]],ls,top],{ii,2,Length@ls}]
ConsistentOrder[nm1_,top_]:=Module[{allorder},allorder=Join[{2},#]&/@Permutations[Range[3,nm1]];allorder=allorder//Cases[#,f_/;inLeft[f,top]]&]
list2top[ls_List]:= If[Length[ls]==1,{},Table[Rule[ls[[ii-1]],ls[[ii]]],{ii,2,Length@ls}]]
order2Mfun[od_,top_]:=Module[{ls,allowedPartitions},allowedPartitions=Cases[MyPartitionOd[od],f_/;And@@(MemberQ[top,#]&/@(list2top/@f//Flatten))]; ls=(M@@@allowedPartitions)/.M[f1_,f___]:> M[L@@Join[{1},f1],f];
Table[ls[[iii]]/.List[f1_,g___]:> R[(top//Cases[Rule[ii_,f1]:> ii])[[1]],f1,g],{iii,Length@ls}]]
Mt[ls_M]:=Module[{od=List@@ls,phat,leftv,num,den},phat=od/.L[f___]:>{}/.R[f1_,f___]:> f1//Flatten; phat=Join[{v},p/@phat];leftv=phat;
od=od/.L[f___]:>{f}/.R[f1_,f___]:> {f};
(*Print[leftv,od];*)
num=Times@@Table[dot[leftv[[i]],F/@od[[i]],v]/.dot[gg_,List[gf___],hh_]:> dot[gg,gf,hh],{i,Length@od}];
den=(*(-1)^Length@od*)dot[v,p[1]]Product[dot[v,p@@Flatten[od[[1;;(i-1)]]]],{i,2,Length@od}];
num/den]
Mt[a_ ls_M]:=a Mt[ls]
NumPre[n_]:=Module[{alltop,lenTop,allods,res,res2},alltop=List[(KLTRM[n]//.nice/.CenterDot[Subscript[p, i_],Subscript[p, j_]]:> s[i,j]/.s[1,i_]:> 0/;i>2//Union//Expand//Total)/.a_ b_s:> b/;NumericQ[a]]/.Plus-> List//Flatten//Union;
alltop=(List@@@alltop)/.s-> Rule;
lenTop=Length/@((Keys@Select[Counts[#1],#==1&])&/@(Flatten/@(alltop/.Rule-> List)));
allods=Table[R[ConsistentOrder[n-1,alltop[[ii]]],alltop[[ii]]],{ii,Length@alltop}];
res=Table[allods[[ii]]/.R[f1_,f2_]:> (order2Mfun[#,f2]&/@f1)//Flatten,{ii,Length@alltop}];
(*Print[res,lenTop];*)
res=(Total/@res) . (Power[#,-1]&/@lenTop)/.M[f___]:> (-1)^Length[{f}] M[f];
res=res/.M[f___]:> Mt[M[f]]
]
(*ClearAll[NumRec]*)
NumRec[{1}]:=fsp[\[Epsilon][1]]
NumRec[{1,i2_}]:=-(1/(4dot[p[nv,1]]))dot[p[1],F[i2],lI[1]]fsp[F[1],lI[1]]-1/dot[p[nv,1]] dot[p[nv],F[1],F[i2],lI[1]]fsp[lI[1]]
NumRec[od_List/;Length[od]>2]:=(*NumRec[od]=*)Module[{allsets,leftall,rightall,leftv,res,remains,partitions},
partitions=KSetPartitions[od,2];
(*Print[partitions];*)
allsets=Drop[partitions,1];
remains=partitions[[1]];
res=Sum[
leftall=allsets[[ii,1]];
rightall=allsets[[ii,2]];
leftv=p@@Join[{nv},Select[od,#<rightall[[1]]&]];
NumRec[leftall]/.fsp[f__]:>(-1)^(Length[rightall]+1) (dot[leftv[[2;;-1]],F[rightall],lI[rightall[[1]]]]/dot[p@@Join[{nv},leftall]])fsp[f,p@@Join[{nv},leftall],lI[rightall[[1]]]],{ii,Length@allsets}];
res=res+(-1)^Length[remains[[2]]]/(4dot[p[nv,1]]) dot[p[1],F[remains[[2]]],lI[1]]fsp[F[1],lI[1]]+(-1)^Length[remains[[2]]]/dot[p[nv,1]] dot[p[nv],F[1],F[remains[[2]]],lI[1]]fsp[lI[1]]
]
numRecQCD[n_]:=NumRec[Range[n-2]]/.fsp[f__]:>spAB[p[n],f,p[n-1]]/.nv->n/.F[f_List]:>T@@(F/@f)/.T[f__]:>f
numRecQCD[od_List]:=NumRec[Range[Length@od]]/.fsp[f__]:>spAB[p[Length@od],f,p[-1+Length@od]]/.nv->Length@od/.F[f_List]:>T@@(F/@f)/.T[f__]:>f
(*Programs on the Hopf algebra*)
(* ::Subsection:: *)
(*Hopf algebra*)
mC[f_]:=If[Head[f]=!=Plus&&Length[f]>=2,True,False]
nMC[f_]:= Not[mC[f]]&& Head[f]=!=Plus
ExpandNCM[(h:NonCommutativeMultiply)[a___,b_Plus,c___]]:=Distribute[h[a,b,c],Plus,h,Plus,ExpandNCM[h[##]]&]
ExpandNCM[(h:NonCommutativeMultiply)[a___,b_Times,c___]]:=Most[b]ExpandNCM[h[a,Last[b],c]]
ExpandNCM[a_Plus]:=ExpandNCM[#]&/@a
ExpandNCM[c_Times]:=c[[1]]*ExpandNCM[c[[2]]]
ExpandNCM[a_]:=ExpandAll[a]
ExpandT[f_]:=((NonCommutativeMultiply@@f//ExpandNCM)/.T[hh__]:> hh/.NonCommutativeMultiply-> T)
ExpandCT[f_]:=((NonCommutativeMultiply@@f//ExpandNCM)/.NonCommutativeMultiply-> CircleTimes)
GetTId[f_]:=(f/.T[hh__]:> hh)
ExpandCircleTimes[f_]:=(f/.CircleTimes->NonCommutativeMultiply//ExpandNCM)/.NonCommutativeMultiply->CircleTimes
NC[i_,j_]:=NonCommutativeMultiply[i,j]-NonCommutativeMultiply[j,i]
\[FivePointedStar][f_T?mC,g_T?mC]:=(T[f[[1]],\[FivePointedStar][f[[2;;-1]],g]]//ExpandT)+(T[g[[1]],\[FivePointedStar][f,g[[2;;-1]]]]//ExpandT)-(T[Join[f[[1]],g[[1]]],\[FivePointedStar][f[[2;;-1]],g[[2;;-1]]]]//ExpandT)/.T[gg___]:>T@@(Sort/@{gg})
\[FivePointedStar][f_T?nMC,g_T?mC]:=T[f[[1]],(g[[1;;-1]]//GetTId)]+(T[g[[1]],\[FivePointedStar][f,g[[2;;-1]]]]//ExpandT)-T[Join[f[[1]],g[[1]]],(g[[2;;-1]]//GetTId)]/.T[gg___]:>T@@(Sort/@{gg})
\[FivePointedStar][f_T?mC,g_T?nMC]:=(T[f[[1]],\[FivePointedStar][f[[2;;-1]],g]]//ExpandT)+T[g[[1]],(f[[1;;-1]]//GetTId)]-T[Join[f[[1]],g[[1]]],(f[[2;;-1]]/.T[hh__]:> hh)]/.T[gg___]:>T@@(Sort/@{gg})
\[FivePointedStar][f_T?nMC,g_T?nMC]:=T[f[[1]],g[[1]]]+T[g[[1]],f[[1]]]-T[Join[f[[1]],g[[1]]]]/.T[gg___]:>T@@(Sort/@{gg})
\[FivePointedStar][f_Plus,g_]:=(NonCommutativeMultiply[f,g]//ExpandNCM)/.NonCommutativeMultiply-> \[FivePointedStar]
\[FivePointedStar][f_,g_Plus]:=(NonCommutativeMultiply[f,g]//ExpandNCM)/.NonCommutativeMultiply-> \[FivePointedStar]
\[FivePointedStar][f_Times,g_]:=(NonCommutativeMultiply[f,g]//ExpandNCM)/.NonCommutativeMultiply-> \[FivePointedStar]
\[FivePointedStar][f_,g_Times]:=(NonCommutativeMultiply[f,g]//ExpandNCM)/.NonCommutativeMultiply-> \[FivePointedStar]
\[FivePointedStar][\[DoubleStruckCapitalI],g_]:=g
\[FivePointedStar][g_,\[DoubleStruckCapitalI]]:=g
\[FivePointedStar][f1_,f2_,g__]:=\[FivePointedStar][\[FivePointedStar][f1,f2],g]
\[FivePointedStar][g_T]:=g
\[FivePointedStar][f_GT,g_GT]:=If[f[[2]]=={}||g[[2]]=={},T@@Join[f[[2]],g[[2]]]/.T[h___]:> GT[Join[f[[1]],g[[1]]],SortBy[#1,Position[Join[f[[1]],g[[1]]],#]&]&/@{h}],\[FivePointedStar][T@@f[[2]],T@@g[[2]]]/.T[h__]:> GT[Join[f[[1]],g[[1]]],SortBy[#1,Position[Join[f[[1]],g[[1]]],#]&]&/@{h}]
]
\[FivePointedStar][f_ET ,g_ET]:=Module[{groupGens},groupGens=Join[f[[2]],g[[2]]] ;\[FivePointedStar][f[[1]] ,g[[1]]]/.GT[gg__]:>ET[GT[gg],groupGens]]
\[FivePointedStar][J1_FT,J2_FT]:=Module[{tausJ1,tausJ2,ranks0a,ranks0,ranks2,tlist,res0,res2,res},
tausJ1=T@@J1[[All,1]];
tausJ2=T@@J2[[All,1]];
ranks0a=List@@J1[[All,2]];
ranks0=Join[List@@J1[[All,2]],{0}];
ranks2=Join[List@@J1[[All,2]],{2}];
tlist=\[FivePointedStar][tausJ1,tausJ2];
res0=tlist/.T[f__]:>FT@@MapThread[List,{{f},ranks0}]/;Length[{f}]==Length[ranks0]/.T[f__]:>FT@@MapThread[List,{{f},ranks0a}]/;Length[{f}]==(Length[ranks0]-1);
res2=tlist/.T[f__]:>FT@@MapThread[List,{{f},ranks2}]/;Length[{f}]==Length[ranks2]/.T[f__]:>0/;Length[{f}]==(Length[ranks0]-1);
res0+res2
]
\[ScriptCapitalK][i_,0]:=ET[GT[{i},{}],{\[DoubleStruckA][i]}]
\[ScriptCapitalK][i_,1]:=ET[GT[{i},{{i}}],{}]
\[CapitalOmega][f_,g_]:=\[FivePointedStar][f,g]-\[FivePointedStar][g,f]
\[CapitalOmega][f1_,f2_,g__]:=\[CapitalOmega][\[CapitalOmega][f1,f2],g]
\[DoubleStruckCapitalS][f_T]:=If[Length[f]>1,-f-Sum[\[FivePointedStar][\[DoubleStruckCapitalS][f[[1;;i]]],f[[i+1;;Length[f]]]],{i,1,Length[f]-1}],-f]/.T[gg___]:>T@@(Sort/@{gg})
\[DoubleStruckCapitalS][f_Plus]:=(NonCommutativeMultiply[f]//ExpandNCM)/.NonCommutativeMultiply-> \[DoubleStruckCapitalS]
\[DoubleStruckCapitalS][f_Times]:=(NonCommutativeMultiply[f]//ExpandNCM)/.NonCommutativeMultiply-> \[DoubleStruckCapitalS]
\[DoubleStruckCapitalS][\[DoubleStruckCapitalI]]:=\[DoubleStruckCapitalI]
\[CapitalDelta][f_T]:=If[Length[f]>1,CircleTimes[\[DoubleStruckCapitalI],f]+CircleTimes[f,\[DoubleStruckCapitalI]]+Sum[CircleTimes[f[[1;;i]],f[[i+1;;Length[f]]]]//ExpandCT,{i,1,Length[f]-1}],CircleTimes[\[DoubleStruckCapitalI],f]+CircleTimes[f,\[DoubleStruckCapitalI]]]
\[CapitalDelta][f_Plus]:=(NonCommutativeMultiply[f]//ExpandNCM)/.NonCommutativeMultiply-> \[CapitalDelta]
\[CapitalDelta][f_Times]:=(NonCommutativeMultiply[f]//ExpandNCM)/.NonCommutativeMultiply-> \[CapitalDelta]
\[CapitalDelta][f_GT]:=\[CapitalDelta][T@@f[[2]]]/.T[h__]:>GT[f[[1]],{h}]
\[CapitalDelta][\[DoubleStruckCapitalI]]:=CircleTimes[\[DoubleStruckCapitalI],\[DoubleStruckCapitalI]]
picCTR[ls_]:=CircleTimes[f__,g_]:> 0/;g===\[DoubleStruckCapitalI]||(Sort[Flatten[List@@g]]=!=ls)
picCTL[ls_]:=CircleTimes[g_,f__]:> 0/;g===\[DoubleStruckCapitalI]||(Sort[Flatten[List@@g]]=!=ls)
picTR[h_T]:=CircleTimes[f__,g_]:> 0/;g=!=h
picTL[h_T]:=CircleTimes[g_,f__]:> 0/;g=!=h
CtCut[f__]:=Module[{od={f},phat,leftv,num,den},phat=Range[Length@od];
If[MemberQ[od,\[DoubleStruckCapitalI]],Return[0]];
phat[[1]]=v;Table[(*If[od[[i,1]]>Max[Flatten[od\[LeftDoubleBracket]1;;(i-1)\[RightDoubleBracket]]],*)phat[[i]]=p@@Select[Flatten[od[[1;;(i-1)]]],#<First[Min[od[[i]]]]&](*,phat[[i]]=p@@Range[od[[i,1]]-1]]*),{i,2,Length@od}];leftv=phat;
num=Times@@Table[dot[leftv[[i]],p[od[[i,1]]]],{i,2,Length@od}];
den=Product[dot[v,p@@Flatten[od[[1;;(i-1)]]]],{i,2,Length@od}];
num/den
]
CTCut[f__]:= (CtCut@@(({f}/.T[g__]:>Flatten[{g}])))Times[f]
GT2Cut[fc_,fk_]:=Module[{od=fk,odc=fc,phat,leftv,num,den},phat=Range[Length@od];
phat[[1]]=v;Table[(*If[od[[i,1]]>Max[Flatten[od\[LeftDoubleBracket]1;;(i-1)\[RightDoubleBracket]]],*)phat[[i]]=p@@Select[Flatten[od[[1;;(i-1)]]],Position[odc,#][[1,1]]<Position[odc,MinimalBy[od[[i]],Position[odc,#1]&]//First][[1,1]]&](*,phat[[i]]=p@@Range[od[[i,1]]-1]]*),{i,2,Length@od}];leftv=phat;
num=Times@@Table[dot[leftv[[i]],p[MinimalBy[od[[i]],Position[odc,#1]&]//First]],{i,2,Length@od}];
den=Product[dot[v,p@@Flatten[od[[1;;(i-1)]]]],{i,2,Length@od}];
num/den
]
CT2GT[f__]:= If[MemberQ[{f},\[DoubleStruckCapitalI]],Return[0],(GT2Cut@@{({f}/.GT[c_,g_]:>c)//Union//Flatten,({f}/.GT[c_,g_]:>Flatten[g])})Times[f]]
(* ::Subsection::Closed:: *)
(*basic functions*)
$globalDim = 4;
setGlobalDim[dim_] /; If[!NumericQ[dim] && protectedQ[dim],Message[setGlobalDim::ssle]; False, True] := Set[$globalDim,dim];
protectedQ[expr_Symbol] := MemberQ[Attributes[expr],Protected]
(* protectedQ[expr_] := TrueQ[MemberQ[Quiet[Attributes[expr]], Protected] || !FreeQ[expr, _?(MemberQ[Quiet[Attributes[#]], Protected] &), Infinity]] *)
protectedQ[_] := False
patternFreeQ[expr_] := FreeQ[expr,Pattern]&&FreeQ[expr,Blank]&&FreeQ[expr,BlankSequence]&&FreeQ[expr,BlankNullSequence]
declareDistributive[function_Symbol,test_,default_:True] := (
declareDistributiveMiddle[function,test,default];
declareDistributiveFirst[function,test,default];
declareDistributiveLast[function,test,default];
)
declareDistributiveMiddle[function_Symbol,test_,default_:True] := (
If[!MemberQ[Options[function][[All,1]],distributive],AppendTo[Options[function],distributive->default]];
function[__,0,__] := 0;
function[p1__,n_ p2_?test,p3__,OptionsPattern[]] := n*function[p1, p2, p3] /; OptionValue[distributive];
(*function[p1__,p2_Plus,p3__,OptionsPattern[]] := Total[function[p1, #, p3] & /@ List @@ p2] /; OptionValue[distributive];*)
(*function[p1__,Times[a___, p2_Plus, b___],p3__,OptionsPattern[]] := function[p1,Expand[a*p2*b],p3] /; OptionValue[distributive];*)
function[p1__, a_. p2_Plus ,p3__,OptionsPattern[]] := function[p1, #, p3]& /@ Distribute[a p2] /; OptionValue[distributive];
)
declareDistributiveFirst[function_Symbol,test_,default_:True] := (
If[!MemberQ[Options[function][[All,1]],distributive],AppendTo[Options[function],distributive->default]];
function[0,___] := 0;
function[n_ p1_?test,p2___,OptionsPattern[]] := n*function[p1, p2] /; OptionValue[distributive];
(*function[p1_Plus,p2___,OptionsPattern[]] := Total[function[#,p2] & /@ List @@ p1] /; OptionValue[distributive];*)
(*function[Times[a___, p1_Plus, b___],p2___,OptionsPattern[]] := function[Expand[a*p1*b],p2] /; OptionValue[distributive];*)
function[a_. p1_Plus ,p2___,OptionsPattern[]] := function[#, p2]& /@ Distribute[a p1] /; OptionValue[distributive];
)
declareDistributiveLast[function_Symbol,test_,default_:True] := (
If[!MemberQ[Options[function][[All,1]],distributive],AppendTo[Options[function],distributive->default]];
function[___,0] := 0;
function[p1___,n_ p2_?test,OptionsPattern[]] := n*function[p1, p2] /; OptionValue[distributive];
(*function[p1___,p2_Plus,OptionsPattern[]] := Total[function[p1,#] & /@ List @@ p2] /; OptionValue[distributive];*)
(*function[p1___,Times[a___, p2_Plus, b___],OptionsPattern[]] := function[p1,Expand[a*p2*b]] /; OptionValue[distributive];*)
function[p1___, a_. p2_Plus, OptionsPattern[]] := function[p1, #]& /@ Distribute[a p2] /; OptionValue[distributive];
)
distributiveRules[function_Symbol,test_,excfront_:0,excback_:0] := With[
{uniqueFront = Sequence @@ (Unique[]& /@ Range[excfront]), uniqueBack = Sequence @@ (Unique[]& /@ Range[excback])},
{
HoldPattern[function][Sequence @@ (Pattern[#, _]& /@ {uniqueFront}), ___, 0, ___, Sequence @@ (Pattern[#, _]& /@ {uniqueBack})] :> 0,
HoldPattern[function][Sequence @@ (Pattern[#, _]& /@ {uniqueFront}), p1___, n_ p2_?test, p3___, Sequence @@ (Pattern[#, _]& /@ {uniqueBack})] :> n*function[uniqueFront, p1, p2, p3, uniqueBack],
HoldPattern[function][Sequence @@ (Pattern[#, _]& /@ {uniqueFront}), p1___, a_. p2_Plus, p3___, Sequence @@ (Pattern[#, _]& /@ {uniqueBack})] :> (function[uniqueFront, p1, #, p3, uniqueBack]& /@ Distribute[a p2])
}
]
declareSymmetric[function_Symbol] := SetAttributes[function,Orderless];
(* Todo: give an option to not automatically antisymmetrise *)
declareAntisymmetric[function_Symbol] := (
(*orderes arguments and puts correct sign if it's not used as a pattern!*)
function[x___] := Signature[{x}] (function @@ Sort@{x}) /; (! OrderedQ[{x}] && FreeQ[{x}, Pattern]);
(*two equal arguments make the function vanish*)
function[___,x_,x_,___] := 0;
)
(* ::Subsection::Closed:: *)
(*Vectors*)
(* Todo: fix dimensionality of dot and eps *)
(* $declaredTensors = {{dot,$globalDim,2},{eps,4,4}}; *)
$declaredTensors = {{eta,4,2}};
$declaredTensorHeads = {{spOuter,4,1},{outer,4,2}};
$declaredAntiTensorHeads={};
(* Todo: there should be an (optional) function that declares these...? *)
$extMomLabel = "p";
$loopLabel = "l";
antiTensorQ[tens_]:=tensorQ[tens]&&MemberQ[$declaredAntiTensorHeads,Head[tens]]
tensorQ[tens_] := If[patternFreeQ[tens],MemberQ[$declaredTensors[[All,1]],tens] || MemberQ[$declaredTensorHeads[[All,1]],Head[tens]],False]
vectorQ[vec_] := If[patternFreeQ[vec],tensorQ[vec] && (tensorRank[vec]===1),False]
tensorQR2[ten_] := If[patternFreeQ[ten],tensorQ[ten] && (tensorRank[ten]===2),False]
tensorDim[tens_] /; If[tensorQ[tens],True,Message[tensorDim::argx]; False] :=
FirstCase[$declaredTensors,_?(#[[1]]===tens&),FirstCase[$declaredTensorHeads,_?(#[[1]]===Head[tens]&)]][[2]]
tensorRank[tens_] /; If[tensorQ[tens],True,Message[tensorRank::argx]; False] :=
FirstCase[$declaredTensors,_?(#[[1]]===tens&),FirstCase[$declaredTensorHeads,_?(#[[1]]===Head[tens]&)]][[3]]
expandTensor[f_dot]:=Module[{lt=Length[f],ls,tlsid,lsT},tlsid=Range[lt];ls=List@@f;lsT=dot@@MapThread[T,{ls,tlsid}];(lsT//.dot[ff__,T[g_?tensorQR2,i_],h__]:> dot[ff,lI[i,1]]dressIndex[g,{lI[i,1],lI[i,2]}]dot[lI[i,2],h])/.T[gg_,i_]:> gg]
(* Todo: should I really distinguish between declareVector and declareTensor? *)
Options[declareVector] := {"dim"->$globalDim,"verbose"->True}
declareVector[expr_List,options___] := Scan[declareVector[#,options]&,expr];
declareVector[vec_Symbol,OptionsPattern[]] /; If[!protectedQ[vec],True,Message[declareVector::safe]; False] := (
If[tensorQ[vec],undeclareTensor[vec];];
vec /: MakeBoxes[vec[KiHA`lI[KiHA`Private`i_]],TraditionalForm] :=
FormBox[SuperscriptBox[MakeBoxes[vec,TraditionalForm],SubscriptBox["\[Nu]",ToString[KiHA`Private`i]]],TraditionalForm];
AppendTo[$declaredTensors,{vec,OptionValue["dim"],1}];
If[OptionValue["verbose"],Print[ToString[vec]<>" declared as a "<>ToString[OptionValue["dim"]]<>"-dimensional vector."]];
)
declareVector[__] := $Failed
Options[declareVectorHead] := {"dim"->$globalDim,"verbose"->True}
declareVectorHead[expr_List,options___] := Scan[declareVectorHead[#,options]&,expr];
declareVectorHead[vec_Symbol,OptionsPattern[]] /; If[!protectedQ[vec],True,Message[declareVectorHead::safe]; False] := (
If[tensorQ[vec[1]],undeclareTensorHead[vec];];
vec /: MakeBoxes[vec[i_],TraditionalForm] := FormBox[SubscriptBox[ToString[vec],MakeBoxes[i,TraditionalForm]],TraditionalForm];
MakeBoxes[vec[KiHA`Private`i_][basicfun`lI[KiHA`Private`j_]],TraditionalForm] :=
FormBox[SuperscriptBox[MakeBoxes[vec[KiHA`Private`i],TraditionalForm],SubscriptBox["\[Nu]",ToString[KiHA`Private`j]]],TraditionalForm];
AppendTo[$declaredTensorHeads,{vec,OptionValue["dim"],1}];
If[OptionValue["verbose"],Print[ToString[vec]<>" declared as a "<>ToString[OptionValue["dim"]]<>"-dimensional vector header."]];
)
declareVectorHead[__] := $Failed
Options[declareTensor] := {"dim"->$globalDim,"rank"->1,"verbose"->True}
declareTensor[expr_List,options___] := Scan[declareTensor[#,options]&,expr];
declareTensor[tens_Symbol,OptionsPattern[]] /; If[!protectedQ[tens],True,Message[declareTensor::safe]; False] := (
If[tensorQ[tens],undeclareTensor[tens];];
(* Todo: formatting for free indices on tensors *)
AppendTo[$declaredTensors,{tens,OptionValue["dim"],OptionValue["rank"]}];
If[OptionValue["verbose"],Print[ToString[tens]<>" declared as a "<>ToString[OptionValue["dim"]]<>"-dimensional rank-"<>ToString[OptionValue["rank"]]<>" tensor."]];
)
declareTensor[__] := $Failed
Options[declareTensorHead] := {"dim"->$globalDim,"rank"->1,"verbose"->True}
declareTensorHead[expr_List,options___] := Scan[declareTensorHead[#,options]&,expr];
declareTensorHead[tens_Symbol,OptionsPattern[]] /; If[!protectedQ[tens],True,Message[declareTensorHead::safe]; False] := (
If[tensorQ[tens],undeclareTensorHead[tens];];
tens /: MakeBoxes[tens[i_],TraditionalForm] := FormBox[SubscriptBox[ToString[tens],MakeBoxes[i,TraditionalForm]],TraditionalForm];
AppendTo[$declaredTensorHeads,{tens,OptionValue["dim"],OptionValue["rank"]}];
If[OptionValue["verbose"],Print[ToString[tens]<>" declared as a "<>ToString[OptionValue["dim"]]<>"-dimensional rank-"<>ToString[OptionValue["rank"]]<>" tensor header."]];
)
declareTensorHead[__] := $Failed
declareAntiTensorHead[expr_List] := Scan[declareAntiTensorHead[#]&,expr];
declareAntiTensorHead[tens_Symbol] := (
AppendTo[$declaredAntiTensorHeads,tens];
)
Options[undeclareTensor] = {"verbose"->True};
undeclareTensor[args_List,options___] := Scan[undeclareTensor[#,options]&,args];
undeclareTensor[vec_?tensorQ,OptionsPattern[]] /; !MemberQ[$declaredTensorHeads,Head[vec]] := (
$declaredTensors = DeleteCases[$declaredTensors,_?(#[[1]]==vec &)];
(* If[Head[vec]===Symbol,
FormatValues[vec] = {}; DownValues[vec] = {}; UpValues[vec] = {}; SubValues[vec] = {};,
FormatValues[Evaluate[Head[vec]]] = DeleteCases[FormatValues[Evaluate[Head[vec]]],_?(MemberQ[#,vec,Infinity]&)];
UpValues[Evaluate[Head[vec]]] = DeleteCases[UpValues[Evaluate[Head[vec]]],_?(MemberQ[#,vec,Infinity]&)];
DownValues[Evaluate[Head[vec]]] = DeleteCases[DownValues[Evaluate[Head[vec]]],_?(MemberQ[#,vec,Infinity]&)];
SubValues[Evaluate[Head[vec]]] = DeleteCases[SubValues[Evaluate[Head[vec]]],_?(MemberQ[#,vec,Infinity]&)];
]; *)
If[OptionValue["verbose"],Print[ToString[vec]<>" undeclared as a tensor."]];
)
undeclareTensor[__] := Null
Options[undeclareTensorHead] = {"verbose"->True};
undeclareTensorHead[args_List,options___] := Scan[undeclareTensorHead[#,options]&,args];
undeclareTensorHead[vec_Symbol,OptionsPattern[]] := (
$declaredTensorHeads = DeleteCases[$declaredTensorHeads,_?(#[[1]]==vec &)];
If[OptionValue["verbose"],Print[ToString[vec]<>" undeclared as a tensor header."]];
)
undeclareTensorHead[__] := Null
SetAttributes[dot,{NHoldAll}];
dot[expr_] := dot[expr,expr] /; patternFreeQ[expr]
dot[p_?tensorQ,__] /; If[vectorQ[p],False,Message[dot::badrank]; True] := $Failed
dot[__,p_?tensorQ] /; If[vectorQ[p],False,Message[dot::badrank]; True] := $Failed
dot[__,p_?tensorQ,__] /; If[tensorRank[p]===2,False,Message[dot::badrank]; True] := $Failed
declareDistributive[dot,tensorQ];
dot[p1_,p2_] := dot[p2,p1] /; (!OrderedQ[{p1,p2}] && patternFreeQ[{p1,p2}])
dot[vec_?vectorQ,ix_lI] := vec[ix]
dot[ix_lI,vec_?vectorQ] := vec[ix]
dot[ix1_lI,ix2_lI] := eta[ix1,ix2]
dot[vec_?vectorQ,ix_ui] := vec[ix]
dot[ix_ui,vec_?vectorQ] := vec[ix]
dot[vec_?vectorQ,ix_di] := vec[ix]
dot[ix_di,vec_?vectorQ] := vec[ix]
dot /: MakeBoxes[dot[p1_Plus,p1_Plus],TraditionalForm] := FormBox[SuperscriptBox[RowBox[{"(",MakeBoxes[p1,TraditionalForm],")"}],"2"],TraditionalForm]
dot /: MakeBoxes[dot[p1_,p1_],TraditionalForm] := FormBox[SuperscriptBox[MakeBoxes[p1,TraditionalForm],"2"],TraditionalForm]
dot /: MakeBoxes[dot[p1_Plus,p2_Plus],TraditionalForm] := FormBox[RowBox[{"(",MakeBoxes[p1,TraditionalForm],")","\[CenterDot]","(",MakeBoxes[p2,TraditionalForm],")"}],TraditionalForm]
dot /: MakeBoxes[dot[p1_Plus,p2_],TraditionalForm] := FormBox[RowBox[{"(",MakeBoxes[p1,TraditionalForm],")","\[CenterDot]",MakeBoxes[p2,TraditionalForm]}],TraditionalForm]
dot /: MakeBoxes[dot[p1_,p2_Plus],TraditionalForm] := FormBox[RowBox[{MakeBoxes[p1,TraditionalForm],"\[CenterDot]","(",MakeBoxes[p2,TraditionalForm],")"}],TraditionalForm]
dot /: MakeBoxes[dot[p1_,p2_],TraditionalForm] := FormBox[RowBox[{MakeBoxes[p1,TraditionalForm],"\[CenterDot]",MakeBoxes[p2,TraditionalForm]}],TraditionalForm]
(* Todo: fix for arguments as sums *)
dot /: MakeBoxes[dot[args__],TraditionalForm] := FormBox[RowBox[Join[Riffle[MakeBoxes[#,TraditionalForm]&/@{args},"\[CenterDot]"]]], TraditionalForm]
SetAttributes[tr, {NHoldAll}];
declareDistributive[tr, tensorQ];
tr[] := $globalDim
tr[args__] /; patternFreeQ[{args}] && {args}[[1]]=!=Sort[{args}][[1]] := tr@@RotateLeft@{args}
declareAntisymmetric[eps];
SetAttributes[eps,NHoldAll];
declareDistributive[eps,tensorQ];
eps /: MakeBoxes[eps[expr__],TraditionalForm] := FormBox[RowBox[Join[{"\[Epsilon]("}, Riffle[MakeBoxes[#,TraditionalForm]&/@{expr}, ","],{")"}]], TraditionalForm]
declareDistributive[outer,vectorQ,tensorQR2];