~maddevelopers/mg5amcnlo/2.9.4

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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
################################################################################
#
# Copyright (c) 2010 The MadGraph5_aMC@NLO Development team and Contributors
#
# This file is a part of the MadGraph5_aMC@NLO project, an application which 
# automatically generates Feynman diagrams and matrix elements for arbitrary
# high-energy processes in the Standard Model and beyond.
#
# It is subject to the MadGraph5_aMC@NLO license which should accompany this 
# distribution.
#
# For more information, visit madgraph.phys.ucl.ac.be and amcatnlo.web.cern.ch
#
################################################################################
##   Diagram of Class
##
##    Variable <--- aloha_lib.Variable 
##               |
##               +- LorentzObject <--- Gamma
##                                  |
##                                  +- Sigma
##                                  |
##                                  +- P
##
##    list <--- AddVariable   
##           |
##           +- MultVariable  <--- MultLorentz 
##           
##    list <--- LorentzObjectRepresentation <-- ConstantObject
##
################################################################################
from __future__ import division
import aloha.aloha_lib as aloha_lib
import aloha
import cmath

#===============================================================================
# P (Momenta)
#===============================================================================
class L_P(aloha_lib.LorentzObject):
    """ Helas Object for an Impulsion """
    
    contract_first = 1
    
    def __init__(self, name, lorentz1, particle):
        self.particle = particle
        aloha_lib.LorentzObject.__init__(self, name,[lorentz1], [],['P%s'%particle])
        aloha_lib.KERNEL.add_tag((name,))
    
    def create_representation(self):
        self.sub0 = aloha_lib.DVariable('P%s_0' % self.particle)
        self.sub1 = aloha_lib.DVariable('P%s_1' % self.particle)
        self.sub2 = aloha_lib.DVariable('P%s_2' % self.particle)
        self.sub3 = aloha_lib.DVariable('P%s_3' % self.particle)

        self.representation= aloha_lib.LorentzObjectRepresentation(
                                    {(0,): self.sub0, (1,): self.sub1, \
                                     (2,): self.sub2, (3,): self.sub3},                              
                                    self.lorentz_ind, [])


class P(aloha_lib.FactoryLorentz):
    """ Helas Object for an Impulsion """
    
    object_class = L_P
    
    #def __init__(self, lorentz1, particle):
    @classmethod
    def get_unique_name(self, lorentz1, particle):
        return '_P^%s_%s' % (particle, lorentz1)



#===============================================================================
# Pslash
#===============================================================================
class L_PSlash(aloha_lib.LorentzObject):
    """ Gamma Matrices """
    
    #gamma0 = [[0, 0, 1, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 1, 0, 0]]
    #gamma1 = [[0, 0, 0, 1], [0, 0, 1, 0], [0, -1, 0, 0], [-1, 0, 0, 0]]
    #gamma2 = [[0, 0, 0, -complex(0,1)],[0, 0, complex(0,1), 0],
    #                    [0, complex(0,1), 0, 0], [-complex(0,1), 0, 0, 0]]
    #gamma3 = [[0, 0, 1, 0], [0, 0, 0, -1], [-1, 0, 0, 0], [0, 1, 0, 0]]
    #    
    #gamma = [gamma0, gamma1, gamma2, gamma3]

    def __init__(self, name, spin1, spin2, particle):
        
        self.particle = particle
        aloha_lib.LorentzObject.__init__(self,name,[], [spin1, spin2])
    
    def create_representation(self):
        """create representation"""
        p0 = aloha_lib.DVariable('P%s_0' % self.particle)
        p1 = aloha_lib.DVariable('P%s_1' % self.particle)
        p2 = aloha_lib.DVariable('P%s_2' % self.particle)
        p3 = aloha_lib.DVariable('P%s_3' % self.particle)    
    
    
        gamma = {
             (0, 0): 0, (0, 1): 0, (0, 2): p0-p3, (0, 3): -1*p1+1j*p2,
             (1, 0): 0, (1, 1): 0, (1, 2): -1*p1-1j*p2, (1, 3): p0+p3,
             (2, 0): p0+p3, (2, 1): p1-1j*p2, (2, 2): 0, (2, 3): 0,
             (3, 0): p1+1j*p2, (3, 1): p0-p3, (3, 2): 0, (3, 3): 0}

                
        self.representation = aloha_lib.LorentzObjectRepresentation(gamma,
                                self.lorentz_ind,self.spin_ind)

class PSlash(aloha_lib.FactoryLorentz):

    object_class = L_PSlash
    
    @classmethod
    def get_unique_name(self, spin1, spin2, particle):
        return '_P%s/_%s_%s' % (particle, spin1,spin2)


#===============================================================================
# Mass
#===============================================================================
class L_Mass(aloha_lib.LorentzObject):
    """ Helas Object for a Mass"""
       
    
    def __init__(self, name, particle):
        self.particle = particle
        aloha_lib.LorentzObject.__init__(self, name,[], [])
            
    def create_representation(self):
        mass = aloha_lib.DVariable('M%s' % self.particle)

        self.representation = aloha_lib.LorentzObjectRepresentation(
                                mass, self.lorentz_ind, self.spin_ind)

class Mass(aloha_lib.FactoryLorentz):

    object_class = L_Mass
    
    @classmethod
    def get_unique_name(self, particle):
        return '_M%s' % particle

#===============================================================================
# Mass
#===============================================================================
class L_Coup(aloha_lib.LorentzObject):
    """ Helas Object for a Mass"""
       
    
    def __init__(self, name, nb):
        self.nb = nb
        aloha_lib.LorentzObject.__init__(self, name,[], [])
            
    def create_representation(self):
        coup = aloha_lib.Variable('COUP%s' % self.nb)

        self.representation = aloha_lib.LorentzObjectRepresentation(
                                coup, self.lorentz_ind, self.spin_ind)

class Coup(aloha_lib.FactoryLorentz):

    object_class = L_Coup
    
    @classmethod
    def get_unique_name(self, nb):
        return 'coup%s' % nb


#===============================================================================
# FCT
#===============================================================================
class L_FCT(aloha_lib.LorentzObject):
    """ Helas Object for a Mass"""
       
    
    def __init__(self, name, id):
        self.fctid = id
        aloha_lib.LorentzObject.__init__(self, name,[], [])
            
    def create_representation(self):
        var = aloha_lib.Variable('FCT%s' % self.fctid)

        self.representation = aloha_lib.LorentzObjectRepresentation(
                                var, self.lorentz_ind, self.spin_ind)
  
class FCT(aloha_lib.FactoryLorentz):

    object_class = L_FCT
    
    @classmethod
    def get_unique_name(self, name):
        
        return '_FCT%s' % name


#===============================================================================
# OverMass2
#===============================================================================
class L_OverMass2(aloha_lib.LorentzObject):
    """ Helas Object for 1/M**2 """
      
    def __init__(self, name, particle):
        self.particle = particle
        aloha_lib.LorentzObject.__init__(self, name, [], [], tags=['OM%s' % particle])
    
    def create_representation(self):
        mass = aloha_lib.DVariable('OM%s' % self.particle)

        self.representation = aloha_lib.LorentzObjectRepresentation(
                                mass, self.lorentz_ind, self.spin_ind)

class OverMass2(aloha_lib.FactoryLorentz):
    
    object_class = L_OverMass2
    
    @classmethod
    def get_unique_name(self, particle):
        return '_OM2_%s' % particle

#===============================================================================
# Width
#===============================================================================
class L_Width(aloha_lib.LorentzObject):
    """ Helas Object for an Impulsion """
 
    
    def __init__(self, name, particle):
        self.particle = particle
        aloha_lib.LorentzObject.__init__(self, name, [], [])
        
    def create_representation(self):
        width = aloha_lib.DVariable('W%s' % self.particle)

        self.representation= aloha_lib.LorentzObjectRepresentation(
                            width, self.lorentz_ind, self.spin_ind)

class Width(aloha_lib.FactoryLorentz):
    
    object_class = L_Width
    
    @classmethod
    def get_unique_name(self, particle):
        return '_W%s' % particle

#===============================================================================
# Param
#===============================================================================
class L_Param(aloha_lib.LorentzObject):
    """ Object for a Model Parameter """
 
    
    def __init__(self, Lname, name):
        self.varname = name
        aloha_lib.LorentzObject.__init__(self, name, [], [])
        
    def create_representation(self):
        param = aloha_lib.Variable( self.varname, aloha_lib.ExtVariable)

        self.representation= aloha_lib.LorentzObjectRepresentation(
                            param, [], [])

class Param(aloha_lib.FactoryLorentz):
    
    object_class = L_Param
    
    @classmethod
    def get_unique_name(self, name):
        if name == 'Pi':
            KERNEL.has_pi = True
        return 'Param_%s' % name

#===============================================================================
# Scalar
#===============================================================================
class L_Scalar(aloha_lib.LorentzObject):
    """ Helas Object for a Spinor"""
       
    
    def __init__(self, name, particle):
        self.particle = particle
        aloha_lib.LorentzObject.__init__(self, name, [], [])
    

        
    def create_representation(self):
        rep = aloha_lib.Variable('S%s_1' % self.particle)
        self.representation= aloha_lib.LorentzObjectRepresentation(        
                                                                    rep, [], [])        

class Scalar(aloha_lib.FactoryLorentz):
    
    object_class = L_Scalar
    
    @classmethod   
    def get_unique_name(self,particle):
        return '_S%s' % particle       
#===============================================================================
# Spinor
#===============================================================================
class L_Spinor(aloha_lib.LorentzObject):
    """ Helas Object for a Spinor"""
    
    contract_first = 1
        
    def __init__(self, name, spin1, particle, prefactor=1):        
        self.particle = particle
        aloha_lib.LorentzObject.__init__(self, name,[], [spin1])
       
    def create_representation(self):
        self.sub0 = aloha_lib.Variable('F%s_1' % self.particle)
        self.sub1 = aloha_lib.Variable('F%s_2' % self.particle)
        self.sub2 = aloha_lib.Variable('F%s_3' % self.particle)
        self.sub3 = aloha_lib.Variable('F%s_4' % self.particle)

        self.representation= aloha_lib.LorentzObjectRepresentation(
                                    {(0,): self.sub0, (1,): self.sub1, \
                                     (2,): self.sub2, (3,): self.sub3},         
                                    [],self.spin_ind)

class Spinor(aloha_lib.FactoryLorentz):
    """ Helas Object for a Spinor"""

    object_class = L_Spinor
    
    @classmethod
    def get_unique_name(self,spin1, particle):  
        return '_F%s_%s' % (particle,spin1)

#===============================================================================
# Vector
#===============================================================================
class L_Vector(aloha_lib.LorentzObject):
    """ Helas Object for a Vector"""
    
    contract_first = 1
    
    def __init__(self, name, lorentz, particle):
        
        self.particle = particle
        aloha_lib.LorentzObject.__init__(self, name, [lorentz], [])
           
    def create_representation(self):
        self.sub0 = aloha_lib.Variable('V%s_1' % self.particle)
        self.sub1 = aloha_lib.Variable('V%s_2' % self.particle)
        self.sub2 = aloha_lib.Variable('V%s_3' % self.particle)
        self.sub3 = aloha_lib.Variable('V%s_4' % self.particle)

        self.representation= aloha_lib.LorentzObjectRepresentation( 
                                    {(0,): self.sub0, (1,): self.sub1, \
                                     (2,): self.sub2, (3,): self.sub3},  
                                    self.lorentz_ind, [])

class Vector(aloha_lib.FactoryLorentz):
    
    object_class = L_Vector
    
    @classmethod
    def get_unique_name(self, lor, particle):
        return '_V%s_%s' % (particle, lor)    

#===============================================================================
# Spin3/2
#===============================================================================
class L_Spin3Half(aloha_lib.LorentzObject):
    """ Helas Object for a Spin2"""
    
    def __init__(self, name, lorentz, spin, particle):
        
        self.particle = particle
        aloha_lib.LorentzObject.__init__(self, name, [lorentz], [spin])

    
    def create_representation(self):

        self.sub00 = aloha_lib.Variable('R%s_1' % self.particle)
        self.sub01 = aloha_lib.Variable('R%s_2' % self.particle)
        self.sub02 = aloha_lib.Variable('R%s_3' % self.particle)
        self.sub03 = aloha_lib.Variable('R%s_4' % self.particle)

        self.sub10 = aloha_lib.Variable('R%s_5' % self.particle)
        self.sub11 = aloha_lib.Variable('R%s_6' % self.particle)
        self.sub12 = aloha_lib.Variable('R%s_7' % self.particle)
        self.sub13 = aloha_lib.Variable('R%s_8' % self.particle)
    
        self.sub20 = aloha_lib.Variable('R%s_9' % self.particle)
        self.sub21 = aloha_lib.Variable('R%s_10' % self.particle)
        self.sub22 = aloha_lib.Variable('R%s_11' % self.particle)
        self.sub23 = aloha_lib.Variable('R%s_12' % self.particle)
    
        self.sub30 = aloha_lib.Variable('R%s_13' % self.particle)
        self.sub31 = aloha_lib.Variable('R%s_14' % self.particle)
        self.sub32 = aloha_lib.Variable('R%s_15' % self.particle)
        self.sub33 = aloha_lib.Variable('R%s_16' % self.particle)
        
        rep = {(0,0): self.sub00, (0,1): self.sub01, (0,2): self.sub02, (0,3): self.sub03,
               (1,0): self.sub10, (1,1): self.sub11, (1,2): self.sub12, (1,3): self.sub13,
               (2,0): self.sub20, (2,1): self.sub21, (2,2): self.sub22, (2,3): self.sub23,
               (3,0): self.sub30, (3,1): self.sub31, (3,2): self.sub32, (3,3): self.sub33}
        
                
        self.representation= aloha_lib.LorentzObjectRepresentation( rep, \
                                    self.lorentz_ind, self.spin_ind)

class Spin3Half(aloha_lib.FactoryLorentz):
    
    object_class = L_Spin3Half

    @classmethod
    def get_unique_name(self, lor, spin, part):
        return 'Spin3Half%s^%s_%s' % (part, lor, spin)

#===============================================================================
# Spin2
#===============================================================================
class L_Spin2(aloha_lib.LorentzObject):
    """ Helas Object for a Spin2"""
    
        
    def __init__(self, name, lorentz1, lorentz2, particle):
        
        self.particle = particle
        aloha_lib.LorentzObject.__init__(self, name, [lorentz1, lorentz2], [])
    
    def create_representation(self):

        self.sub00 = aloha_lib.Variable('T%s_1' % self.particle)
        self.sub01 = aloha_lib.Variable('T%s_2' % self.particle)
        self.sub02 = aloha_lib.Variable('T%s_3' % self.particle)
        self.sub03 = aloha_lib.Variable('T%s_4' % self.particle)

        self.sub10 = aloha_lib.Variable('T%s_5' % self.particle)
        self.sub11 = aloha_lib.Variable('T%s_6' % self.particle)
        self.sub12 = aloha_lib.Variable('T%s_7' % self.particle)
        self.sub13 = aloha_lib.Variable('T%s_8' % self.particle)
	
        self.sub20 = aloha_lib.Variable('T%s_9' % self.particle)
        self.sub21 = aloha_lib.Variable('T%s_10' % self.particle)
        self.sub22 = aloha_lib.Variable('T%s_11' % self.particle)
        self.sub23 = aloha_lib.Variable('T%s_12' % self.particle)
	
        self.sub30 = aloha_lib.Variable('T%s_13' % self.particle)
        self.sub31 = aloha_lib.Variable('T%s_14' % self.particle)
        self.sub32 = aloha_lib.Variable('T%s_15' % self.particle)
        self.sub33 = aloha_lib.Variable('T%s_16' % self.particle)
        
        rep = {(0,0): self.sub00, (0,1): self.sub01, (0,2): self.sub02, (0,3): self.sub03,
               (1,0): self.sub10, (1,1): self.sub11, (1,2): self.sub12, (1,3): self.sub13,
               (2,0): self.sub20, (2,1): self.sub21, (2,2): self.sub22, (2,3): self.sub23,
               (3,0): self.sub30, (3,1): self.sub31, (3,2): self.sub32, (3,3): self.sub33}
        
                
        self.representation= aloha_lib.LorentzObjectRepresentation( rep, \
                                    self.lorentz_ind, [])

class Spin2(aloha_lib.FactoryLorentz):
    
    object_class = L_Spin2

    @classmethod
    def get_unique_name(self, lor1, lor2, part):
        return 'Spin2^%s_%s_%s' % (part, lor1, lor2)

#===============================================================================
# Gamma
#===============================================================================
class L_Gamma(aloha_lib.LorentzObject):
    """ Gamma Matrices """
    
    #gamma0 = [[0, 0, 1, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 1, 0, 0]]
    #gamma1 = [[0, 0, 0, 1], [0, 0, 1, 0], [0, -1, 0, 0], [-1, 0, 0, 0]]
    #gamma2 = [[0, 0, 0, -complex(0,1)],[0, 0, complex(0,1), 0],
    #                    [0, complex(0,1), 0, 0], [-complex(0,1), 0, 0, 0]]
    #gamma3 = [[0, 0, 1, 0], [0, 0, 0, -1], [-1, 0, 0, 0], [0, 1, 0, 0]]
    #    
    #gamma = [gamma0, gamma1, gamma2, gamma3]
    gamma = { #Gamma0
             (0, 0, 0): 0, (0, 0, 1): 0, (0, 0, 2): 1, (0, 0, 3): 0,
             (0, 1, 0): 0, (0, 1, 1): 0, (0, 1, 2): 0, (0, 1, 3): 1,
             (0, 2, 0): 1, (0, 2, 1): 0, (0, 2, 2): 0, (0, 2, 3): 0,
             (0, 3, 0): 0, (0, 3, 1): 1, (0, 3, 2): 0, (0, 3, 3): 0,
             #Gamma1
             (1, 0, 0): 0, (1, 0, 1): 0, (1, 0, 2): 0, (1, 0, 3): 1,
             (1, 1, 0): 0, (1, 1, 1): 0, (1, 1, 2): 1, (1, 1, 3): 0,
             (1, 2, 0): 0, (1, 2, 1): -1, (1, 2, 2): 0, (1, 2, 3): 0,
             (1, 3, 0): -1, (1, 3, 1): 0, (1, 3, 2): 0, (1, 3, 3): 0,
             #Gamma2
             (2, 0, 0): 0, (2, 0, 1): 0, (2, 0, 2): 0, (2, 0, 3): -1j,
             (2, 1, 0): 0, (2, 1, 1): 0, (2, 1, 2): 1j, (2, 1, 3): 0,
             (2, 2, 0): 0, (2, 2, 1): 1j, (2, 2, 2): 0, (2, 2, 3): 0,
             (2, 3, 0): -1j, (2, 3, 1): 0, (2, 3, 2): 0, (2, 3, 3): 0,
             #Gamma3
             (3, 0, 0): 0, (3, 0, 1): 0, (3, 0, 2): 1, (3, 0, 3): 0,
             (3, 1, 0): 0, (3, 1, 1): 0, (3, 1, 2): 0, (3, 1, 3): -1,
             (3, 2, 0): -1, (3, 2, 1): 0, (3, 2, 2): 0, (3, 2, 3): 0,
             (3, 3, 0): 0, (3, 3, 1): 1, (3, 3, 2): 0, (3, 3, 3): 0
             }

    def __init__(self, name, lorentz, spin1, spin2):
        aloha_lib.LorentzObject.__init__(self,name,[lorentz], [spin1, spin2])
            
    def create_representation(self):
                
        self.representation = aloha_lib.LorentzObjectRepresentation(self.gamma,
                                self.lorentz_ind,self.spin_ind)

class Gamma(aloha_lib.FactoryLorentz):
    
    object_class = L_Gamma
    
    @classmethod
    def get_unique_name(self, lor, spin1, spin2):
        return 'Gamma^%s_%s_%s' % (lor, spin1, spin2)
        
        
#===============================================================================
# Sigma
#===============================================================================
class L_Sigma(aloha_lib.LorentzObject):
    """ Sigma Matrices """
    
    
    
    #zero = [[0,0,0,0]]*4
    #i = complex(0,1)
    #sigma01 = [[ 0, -i, 0, 0], [-i, 0, 0, 0], [0, 0, 0, i], [0, 0, i, 0]]
    #sigma02 = [[ 0, -1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1], [0, 0, -1, 0]]
    #sigma03 = [[-i, 0, 0, 0], [0, i, 0, 0], [0, 0, i, 0], [0, 0, 0, -i]]
    #sigma12 = [[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, 1, 0], [0, 0, 0, -1]]
    #sigma13 = [[0, i, 0, 0], [-i, 0, 0, 0], [0, 0, 0, i], [0, 0, -i, 0]]
    #sigma23 = [[0, 1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]]
    #def inv(matrice):     
    #    out=[]
    #    for i in range(4):
    #        out2=[]
    #        out.append(out2)
    #        for j in range(4):
    #            out2.append(-1*matrice[i][j])
    #    return out
    #                    
    #sigma =[[zero, sigma01, sigma02, sigma03], \
    #        [inv(sigma01), zero, sigma12, sigma13],\
    #        [inv(sigma02), inv(sigma12), zero, sigma23],\
    #        [inv(sigma03), inv(sigma13), inv(sigma23), zero]]

    sigma={(0, 2, 0, 1): -0.5, (3, 1, 2, 0): 0, (3, 2, 3, 1): 0, (1, 3, 1, 3): 0, 
           (2, 3, 3, 2): 0.5, (2, 1, 3, 1): 0, (0, 2, 2, 1): 0, (3, 1, 0, 0): 0, 
           (2, 3, 3, 1): 0, (3, 3, 1, 2): 0, (3, 1, 0, 3): 0, (1, 1, 0, 3): 0, 
           (0, 1, 2, 2): 0, (3, 2, 3, 2): -0.5, (2, 1, 0, 1): 0, (3, 3, 3, 3): 0, 
           (1, 1, 2, 2): 0, (2, 2, 3, 2): 0, (2, 1, 2, 1): 0, (0, 1, 0, 3): 0, 
           (2, 1, 2, 2): -0.5, (1, 2, 2, 1): 0, (2, 2, 1, 3): 0, (0, 3, 1, 3): 0, 
           (3, 0, 3, 2): 0, (1, 2, 0, 1): 0, (3, 0, 3, 1): 0, (0, 0, 2, 2): 0, 
           (1, 2, 0, 2): 0, (2, 0, 0, 3): 0, (0, 0, 2, 1): 0, (0, 3, 3, 2): 0, 
           (3, 0, 1, 1): -0.5j, (3, 2, 0, 1): -0.5, (1, 0, 1, 0): 0.5j, (0, 0, 0, 1): 0,
            (0, 2, 1, 1): 0, (3, 1, 3, 2): 0.5j, (3, 2, 2, 1): 0, (1, 3, 2, 3): 0.5j, 
            (1, 0, 3, 0): 0, (3, 2, 2, 2): 0, (0, 2, 3, 1): 0, (1, 0, 3, 3): 0, 
            (2, 3, 2, 1): 0, (0, 2, 3, 2): -0.5, (3, 1, 1, 3): 0, (1, 1, 1, 3): 0, 
            (1, 3, 0, 2): 0, (2, 3, 0, 1): 0.5, (1, 1, 1, 0): 0, (2, 3, 0, 2): 0, 
            (3, 3, 0, 3): 0, (1, 1, 3, 0): 0, (0, 1, 3, 3): 0, (2, 2, 0, 1): 0, 
            (2, 1, 1, 0): 0, (3, 3, 2, 2): 0, (2, 3, 1, 0): 0.5, (2, 2, 2, 3): 0, 
            (0, 3, 0, 3): 0, (0, 1, 1, 2): 0, (0, 3, 0, 0): -0.5j, (2, 3, 1, 1): 0, 
            (1, 2, 3, 0): 0, (2, 0, 1, 3): 0, (0, 0, 3, 1): 0, (0, 3, 2, 0): 0, 
            (2, 3, 1, 2): 0, (2, 0, 1, 0): -0.5, (1, 2, 1, 0): 0, (3, 0, 0, 2): 0, 
            (1, 0, 0, 2): 0, (0, 0, 1, 1): 0, (1, 2, 1, 3): 0, (2, 3, 1, 3): 0, 
            (2, 0, 3, 0): 0, (0, 0, 1, 2): 0, (1, 3, 3, 3): 0, (3, 2, 1, 0): -0.5, 
            (1, 3, 3, 0): 0, (1, 0, 2, 3): -0.5j, (0, 2, 0, 0): 0, (3, 1, 2, 3): -0.5j, 
            (3, 2, 3, 0): 0, (1, 3, 1, 0): -0.5j, (3, 2, 3, 3): 0, (0, 2, 2, 0): 0, 
            (2, 3, 3, 0): 0, (3, 3, 1, 3): 0, (0, 2, 2, 3): 0.5, (3, 1, 0, 2): 0, 
            (1, 1, 0, 2): 0, (3, 3, 1, 0): 0, (0, 1, 2, 3): 0.5j, (1, 1, 0, 1): 0,
            (2, 1, 0, 2): 0, (0, 1, 2, 0): 0, (3, 3, 3, 0): 0, (1, 1, 2, 1): 0,
            (2, 2, 3, 3): 0, (0, 1, 0, 0): 0, (2, 2, 3, 0): 0, (2, 1, 2, 3): 0,
            (1, 2, 2, 2): 0.5, (2, 2, 1, 0): 0, (0, 3, 1, 2): 0, (0, 3, 1, 1): 0.5j, 
            (3, 0, 3, 0): 0, (1, 2, 0, 3): 0, (2, 0, 0, 2): 0, (0, 0, 2, 0): 0, 
            (0, 3, 3, 1): 0, (3, 0, 1, 0): 0, (2, 0, 0, 1): 0.5, (3, 2, 0, 2): 0, 
            (3, 0, 1, 3): 0, (1, 0, 1, 3): 0, (0, 0, 0, 0): 0, (0, 2, 1, 2): 0, 
            (3, 1, 3, 3): 0, (0, 0, 0, 3): 0, (1, 3, 2, 2): 0, (3, 1, 3, 0): 0, 
            (3, 2, 2, 3): -0.5, (1, 3, 2, 1): 0, (1, 0, 3, 2): -0.5j, (2, 3, 2, 2): 0, 
            (0, 2, 3, 3): 0, (3, 1, 1, 0): 0.5j, (1, 3, 0, 1): 0.5j, (1, 1, 1, 1): 0, 
            (2, 1, 3, 2): 0, (2, 3, 0, 3): 0, (3, 3, 0, 2): 0, (1, 1, 3, 1): 0, 
            (3, 3, 0, 1): 0, (2, 1, 3, 3): 0.5, (0, 1, 3, 2): 0.5j, (1, 1, 3, 2): 0, 
            (2, 1, 1, 3): 0, (3, 0, 2, 1): 0, (0, 1, 3, 1): 0, (3, 3, 2, 1): 0, 
            (2, 2, 2, 2): 0, (0, 1, 1, 1): 0, (2, 2, 2, 1): 0, (0, 3, 0, 1): 0, 
            (3, 0, 2, 2): -0.5j, (1, 2, 3, 3): -0.5, (0, 0, 3, 2): 0, (0, 3, 2, 1): 0, 
            (2, 0, 1, 1): 0, (2, 2, 0, 0): 0, (0, 3, 2, 2): 0.5j, (3, 0, 0, 3): 0, 
            (1, 0, 0, 3): 0, (1, 2, 1, 2): 0, (2, 0, 3, 1): 0, (1, 0, 0, 0): 0, 
            (0, 0, 1, 3): 0, (2, 0, 3, 2): 0.5, (3, 2, 1, 3): 0, (1, 3, 3, 1): 0, 
            (1, 0, 2, 0): 0, (2, 2, 0, 2): 0, (0, 2, 0, 3): 0, (3, 1, 2, 2): 0, 
            (1, 3, 1, 1): 0, (3, 1, 2, 1): 0, (2, 2, 0, 3): 0, (3, 0, 0, 1): 0, 
            (1, 3, 1, 2): 0, (2, 3, 3, 3): 0, (0, 2, 2, 2): 0, (3, 1, 0, 1): -0.5j, 
            (3, 3, 1, 1): 0, (1, 1, 0, 0): 0, (2, 1, 0, 3): 0, (0, 1, 2, 1): 0, 
            (3, 3, 3, 1): 0, (2, 1, 0, 0): -0.5, (1, 1, 2, 0): 0, (3, 3, 3, 2): 0, 
            (0, 1, 0, 1): -0.5j, (1, 1, 2, 3): 0, (2, 2, 3, 1): 0, (2, 1, 2, 0): 0,
             (0, 1, 0, 2): 0, (1, 2, 2, 3): 0, (2, 0, 2, 1): 0, (2, 2, 1, 1): 0, 
             (1, 2, 2, 0): 0, (2, 2, 1, 2): 0, (0, 3, 1, 0): 0, (3, 0, 3, 3): 0.5j, 
             (2, 1, 3, 0): 0, (1, 2, 0, 0): 0.5, (0, 0, 2, 3): 0, (0, 3, 3, 0): 0, 
             (2, 0, 0, 0): 0, (3, 2, 0, 3): 0, (0, 3, 3, 3): -0.5j, (3, 0, 1, 2): 0, 
             (1, 0, 1, 2): 0, (3, 2, 0, 0): 0, (0, 2, 1, 3): 0, (1, 0, 1, 1): 0, 
             (0, 0, 0, 2): 0, (0, 2, 1, 0): 0.5, (3, 1, 3, 1): 0, (3, 2, 2, 0): 0, 
             (1, 3, 2, 0): 0, (1, 0, 3, 1): 0, (2, 3, 2, 3): 0.5, (0, 2, 3, 0): 0, 
             (3, 1, 1, 1): 0, (2, 3, 2, 0): 0, (1, 3, 0, 0): 0, (3, 1, 1, 2): 0, 
             (1, 1, 1, 2): 0, (1, 3, 0, 3): 0, (2, 3, 0, 0): 0, (2, 0, 2, 0): 0, 
             (3, 3, 0, 0): 0, (1, 1, 3, 3): 0, (2, 1, 1, 2): 0, (0, 1, 3, 0): 0, 
             (3, 3, 2, 0): 0, (2, 1, 1, 1): 0.5, (2, 0, 2, 2): 0, (3, 3, 2, 3): 0, 
             (0, 1, 1, 0): -0.5j, (2, 2, 2, 0): 0, (0, 3, 0, 2): 0, (3, 0, 2, 3): 0, 
             (0, 1, 1, 3): 0, (2, 0, 2, 3): -0.5, (1, 2, 3, 2): 0, (3, 0, 2, 0): 0, 
             (0, 0, 3, 3): 0, (1, 2, 3, 1): 0, (2, 0, 1, 2): 0, (0, 0, 3, 0): 0, 
             (0, 3, 2, 3): 0, (3, 0, 0, 0): 0.5j, (1, 2, 1, 1): -0.5, (1, 0, 0, 1): 0.5j, 
             (0, 0, 1, 0): 0, (2, 0, 3, 3): 0, (3, 2, 1, 2): 0, (1, 3, 3, 2): -0.5j, 
             (1, 0, 2, 1): 0, (3, 2, 1, 1): 0, (0, 2, 0, 2): 0, (1, 0, 2, 2): 0}

    def __init__(self, name, lorentz1, lorentz2, spin1, spin2):
            aloha_lib.LorentzObject.__init__(self, name, [lorentz1, lorentz2], \
                                                  [spin1, spin2])

    def create_representation(self):
                
        self.representation = aloha_lib.LorentzObjectRepresentation(self.sigma,
                                self.lorentz_ind,self.spin_ind)

class Sigma(aloha_lib.FactoryLorentz):
    
    object_class = L_Sigma

    @classmethod
    def get_unique_name(self, lorentz1, lorentz2, spin1, spin2):
        return 'Sigma_[%s,%s]^[%s,%s]' % (spin1, spin2, lorentz1, lorentz2)


#===============================================================================
# Gamma5
#===============================================================================        
class L_Gamma5(aloha_lib.LorentzObject):
    
    #gamma5 = [[-1, 0, 0, 0, 0], [0, -1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]
    gamma5 = {(0,0): -1, (0,1): 0, (0,2): 0, (0,3): 0,\
              (1,0): 0, (1,1): -1, (1,2): 0, (1,3): 0,\
              (2,0): 0, (2,1): 0, (2,2): 1, (2,3): 0,\
              (3,0): 0, (3,1): 0, (3,2): 0, (3,3): 1}
    
    def __init__(self, name, spin1, spin2):
        aloha_lib.LorentzObject.__init__(self, name, [], [spin1, spin2])

    def create_representation(self):
        
        self.representation = aloha_lib.LorentzObjectRepresentation(self.gamma5,
                                             self.lorentz_ind,self.spin_ind) 

class Gamma5(aloha_lib.FactoryLorentz):
    
    object_class = L_Gamma5

    @classmethod
    def get_unique_name(self, spin1, spin2):
        return 'Gamma5_%s_%s' % (spin1, spin2)
        
#===============================================================================
# Conjugate Matrices
#===============================================================================
class L_C(aloha_lib.LorentzObject):
    
    #[0, -1, 0, 0] [1,0,0,0] [0,0,0,1],[0,0,-1,0]
    
    Cmetrix = {(0,0): 0, (0,1): -1, (0,2): 0, (0,3): 0,\
              (1,0): 1, (1,1): 0, (1,2): 0, (1,3): 0,\
              (2,0): 0, (2,1): 0, (2,2): 0, (2,3): 1,\
              (3,0): 0, (3,1): 0, (3,2): -1, (3,3): 0} 
    
    def __init__(self, name, spin_list):

        # spin_list is automatically ordered. The sign for the symmetrization
        # is set in the Factory routine       
        aloha_lib.LorentzObject.__init__(self, name, [], spin_list)


    def create_representation(self):
        self.representation = aloha_lib.LorentzObjectRepresentation(self.Cmetrix,
                                             self.lorentz_ind,self.spin_ind) 
    
class C(aloha_lib.FactoryLorentz):
    
    object_class = L_C
    
    def __new__(cls, spin1, spin2):
        
       spin_list = [spin1, spin2]
       spin_list.sort()
       sign = give_sign_perm(spin_list, [spin1, spin2])
       name = cls.get_unique_name(spin_list)
       if sign == 1:
           return aloha_lib.FactoryVar.__new__(cls, name, cls.object_class, spin_list)
       else:
           out = aloha_lib.FactoryVar.__new__(cls, name, cls.object_class, spin_list)
           out.prefactor = -1
           return out

    @classmethod
    def get_unique_name(cls, spin_list):
        return "C_%s_%s" % tuple(spin_list)

#===============================================================================
# EPSILON  
#===============================================================================
#Helpfull function
def give_sign_perm(perm0, perm1):
    """Check if 2 permutations are of equal parity.

    Assume that both permutation lists are of equal length
    and have the same elements. No need to check for these
    conditions.
    """
    assert len(perm0) == len(perm1) 
        
    perm1 = list(perm1) ## copy this into a list so we don't mutate the original
    perm1_map = dict((v, i) for i,v in enumerate(perm1))

    transCount = 0
    for loc, p0 in enumerate(perm0):
        p1 = perm1[loc]
        if p0 != p1:
            sloc = perm1_map[p0]                       # Find position in perm1
            perm1[loc], perm1[sloc] = p0, p1           # Swap in perm1
            perm1_map[p0], perm1_map[p1] = loc, sloc   # Swap the map
            transCount += 1
            
    # Even number of transposition means equal parity
    return -2 * (transCount % 2) + 1
    
# Practical definition of Epsilon
class L_Epsilon(aloha_lib.LorentzObject):
    """ The fully anti-symmetric object in Lorentz-Space """
 
    def give_parity(self, perm):
        """return the parity of the permutation"""
        assert set(perm) == set([0,1,2,3]) 
        
        i1 , i2, i3, i4 = perm
        #formula found on wikipedia
        return -self.sign * ((i2-i1) * (i3-i1) *(i4-i1) * (i3-i2) * (i4-i2) *(i4-i3))/12 
   
    # DEFINE THE REPRESENTATION OF EPSILON
           
    def __init__(self, name, lorentz1, lorentz2, lorentz3, lorentz4):
       
       lorentz_list = [lorentz1 , lorentz2, lorentz3, lorentz4]
       #order_lor = list(lorentz_list)
       #order_lor.sort()
       
       #self.sign = give_sign_perm(order_lor, lorentz_list)
       self.sign=1
       aloha_lib.LorentzObject.__init__(self, name, lorentz_list, [])


    def create_representation(self):

        if not hasattr(self, 'epsilon'):
            # init all element to zero
            epsilon = dict( ((l1, l2, l3, l4), 0)
                                  for l1 in range(4) \
                                  for l2 in range(4) \
                                  for l3 in range(4) \
                                  for l4 in range(4))        
            # update non trivial one
            epsilon.update(dict(
             ((l1, l2, l3, l4), self.give_parity((l1,l2,l3,l4)))
                                 for l1 in range(4) \
                                 for l2 in range(4) if l2 != l1\
                                 for l3 in range(4) if l3 not in [l1,l2]\
                                 for l4 in range(4) if l4 not in [l1,l2,l3]))

            L_Epsilon.epsilon = epsilon
        
        self.representation = aloha_lib.LorentzObjectRepresentation(self.epsilon,
                                self.lorentz_ind,self.spin_ind)


class Epsilon(aloha_lib.FactoryLorentz):
         
    object_class = L_Epsilon
    
    @classmethod
    def get_unique_name(cls,l1,l2,l3,l4):
        return '_EPSILON_%s_%s_%s_%s' % (l1,l2,l3,l4)
    
            
#===============================================================================
# Metric
#===============================================================================
class L_Metric(aloha_lib.LorentzObject):
    
    metric = {(0,0): 1, (0,1): 0, (0,2): 0, (0,3): 0,\
              (1,0): 0, (1,1): -1, (1,2): 0, (1,3): 0,\
              (2,0): 0, (2,1): 0, (2,2): -1, (2,3): 0,\
              (3,0): 0, (3,1): 0, (3,2): 0, (3,3): -1}
    
    
    #[[1, 0, 0,0], [0, -1, 0, 0], [0, 0, -1, 0], [0, 0, 0, -1]]
        
    def __init__(self, name, lorentz1, lorentz2):
        aloha_lib.LorentzObject.__init__(self,name,[lorentz1, lorentz2], [])
            
    def create_representation(self):
        
        self.representation = aloha_lib.LorentzObjectRepresentation(self.metric,
                                             self.lorentz_ind,self.spin_ind)     

class Metric(aloha_lib.FactoryLorentz):
         
    object_class = L_Metric
    
    @classmethod
    def get_unique_name(cls,l1,l2):
        if l1<l2:
            return '_ETA_%s_%s' % (l1,l2)
        else:
            return '_ETA_%s_%s' % (l2,l1)
#===============================================================================
# Identity
#===============================================================================
class L_Identity(aloha_lib.LorentzObject):
    
    #identity = [[1, 0, 0,0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]
    identity = {(0,0): 1, (0,1): 0, (0,2): 0, (0,3): 0,\
              (1,0): 0, (1,1): 1, (1,2): 0, (1,3): 0,\
              (2,0): 0, (2,1): 0, (2,2): 1, (2,3): 0,\
              (3,0): 0, (3,1): 0, (3,2): 0, (3,3): 1}

    
    def __init__(self, name, spin1, spin2):
        aloha_lib.LorentzObject.__init__(self, name, [],[spin1, spin2])
            
    def create_representation(self):
        
        self.representation = aloha_lib.LorentzObjectRepresentation(self.identity,
                                             self.lorentz_ind,self.spin_ind)

class Identity(aloha_lib.FactoryLorentz):
    
    object_class = L_Identity

    @classmethod
    def get_unique_name(self, spin1, spin2):
        return 'Id_%s_%s' % (spin1, spin2)
        
##===============================================================================
## IdentityL  (Commented since not use)
##===============================================================================
#class IdentityL(aloha_lib.LorentzObject):
#    
#    identity = [[1, 0, 0,0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]
#    
#    def __init__(self, lorentz1, lorentz2, prefactor=1):
#        if lorentz1 < lorentz2:
#            aloha_lib.LorentzObject.__init__(self,[lorentz1, lorentz2], [])
#        else:
#            aloha_lib.LorentzObject.__init__(self,[lorentz1, lorentz2], [])
#            
#    def create_representation(self):
#        
#        self.representation = aloha_lib.LorentzObjectRepresentation(self.identity,
#                                             self.lorentz_ind,self.spin_ind)
#    
#===============================================================================
# ProjM 
#===============================================================================    
class L_ProjM(aloha_lib.LorentzObject):
    """ A object for (1-gamma5)/2 """
    
    #projm = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
    projm= {(0,0): 1, (0,1): 0, (0,2): 0, (0,3): 0,\
              (1,0): 0, (1,1): 1, (1,2): 0, (1,3): 0,\
              (2,0): 0, (2,1): 0, (2,2): 0, (2,3): 0,\
              (3,0): 0, (3,1): 0, (3,2): 0, (3,3): 0}
                
    def __init__(self,name, spin1, spin2):
        """Initialize the object"""
        aloha_lib.LorentzObject.__init__(self, name, [], [spin1, spin2])
            
    def create_representation(self):
        
        self.representation = aloha_lib.LorentzObjectRepresentation(self.projm,
                                             self.lorentz_ind,self.spin_ind)    

class ProjM(aloha_lib.FactoryLorentz):
    
    object_class = L_ProjM
    
    @classmethod
    def get_unique_name(self, spin1, spin2):
            return 'PROJM_%s_%s' % (spin1, spin2)
#===============================================================================
# ProjP 
#===============================================================================    
class L_ProjP(aloha_lib.LorentzObject):
    """A object for (1+gamma5)/2 """
    
    #projp = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]
    projp = {(0,0): 0, (0,1): 0, (0,2): 0, (0,3): 0,\
              (1,0): 0, (1,1): 0, (1,2): 0, (1,3): 0,\
              (2,0): 0, (2,1): 0, (2,2): 1, (2,3): 0,\
              (3,0): 0, (3,1): 0, (3,2): 0, (3,3): 1}
    
    def __init__(self,name, spin1, spin2):
        """Initialize the object"""
        aloha_lib.LorentzObject.__init__(self, name, [], [spin1, spin2])

          
    def create_representation(self):
        
        self.representation = aloha_lib.LorentzObjectRepresentation(self.projp,
                                            self.lorentz_ind, self.spin_ind)    

class ProjP(aloha_lib.FactoryLorentz):
    
    object_class = L_ProjP
    
    @classmethod
    def get_unique_name(self, spin1, spin2):
        
        return 'PROJP_%s_%s' % (spin1, spin2)
        

#===============================================================================
# Denominator Propagator 
#===============================================================================    
class DenominatorPropagator(aloha_lib.LorentzObject):
    """The Denominator of the Propagator"""
    
    def __new__(cls, particle):
    
        name = 'DenomP%s' % particle
        return  aloha_lib.Variable.__new__(cls, name)    
    
    def __init__(self, particle):
        if self:
            return
        self.particle = particle
        aloha_lib.LorentzObject.__init__(self, [], [])
    
    def get_unique_name(self,*args):
        return 'DenomP%s' % self.particle
    
    
    def simplify(self):
        """Return the Denominator in a abstract way"""

        mass = Mass(self.particle)
        width = Width(self.particle)       
        denominator = P('i1', self.particle) * P('i1', self.particle) - \
                      mass * mass + complex(0,1) * mass* width
         
        return denominator
     
    def create_representation(self):
        """Create the representation for the Vector propagator"""
        
        object = self.simplify()
        self.representation = object.expand()

                
#===============================================================================
# Numerator Propagator 
#===============================================================================            


SpinorPropagatorout = lambda spin1, spin2, particle: -1 * (Gamma('mu', spin1, spin2) * \
                    P('mu', particle) - Mass(particle) * Identity(spin1, spin2))

SpinorPropagatorin = lambda spin1, spin2, particle: (Gamma('mu', spin1, spin2) * \
                    P('mu', particle) + Mass(particle) * Identity(spin1, spin2))

VectorPropagator = lambda l1, l2, part: complex(0,1)*(-1 * Metric(l1, l2) + OverMass2(part) * \
                                    Metric(l1,'I3')* P('I3', part) * P(l2, part))

VectorPropagatorMassless= lambda l1, l2, part: complex(0,-1) * Metric(l1, l2)


Spin3halfPropagatorin =  lambda mu, nu, s1, s2, part: (\
    -1/3 * (Gamma(mu,s1,-2) + Identity(s1, -2) *  P(mu, part) * Mass(part) * OverMass2(part))* \
    (PSlash(-2,-3, part) - Identity(-2,-3) * Mass(part)) * \
    ( Gamma(nu, -3, s2)+ Mass(part) * OverMass2(part) * Identity(-3, s2) * P(nu, part) ) - \
    (PSlash(s1,s2, part) + Mass(part) * Identity(s1,s2)) * (Metric(mu, nu) - OverMass2(part) * P(mu, part) * P(nu,part)))


Spin3halfPropagatorout =  lambda mu, nu, s1, s2, part: ( \
  -1/3 * (Gamma(mu,s1,-2) - Identity(s1, -2) *  P(mu, part) * Mass(part) * OverMass2(part))* \
    (-1*PSlash(-2,-3, part) - Identity(-2,-3) * Mass(part)) * \
    ( Gamma(nu, -3, s2)- Mass(part) * OverMass2(part) * Identity(-3, s2) * P(nu, part) ) - \
    (-1*PSlash(s1,s2, part) 
     + Mass(part) * Identity(s1,s2)) * (Metric(mu, nu) - OverMass2(part) * P(mu, part) * P(nu,part)))


Spin3halfPropagatorMasslessOut = lambda mu, nu, s1, s2, part: Gamma(nu, s1,-1) * PSlash(-1,-2, part) * Gamma(mu,-2, s2)
Spin3halfPropagatorMasslessIn = lambda mu, nu, s1, s2, part: -1 * Gamma(mu, s1,-1) * PSlash(-1,-2, part) * Gamma(nu,-2, s2)


Spin2masslessPropagator = lambda mu, nu, alpha, beta: 1/2 *( Metric(mu, alpha)* Metric(nu, beta) +\
                     Metric(mu, beta) * Metric(nu, alpha) - Metric(mu, nu) * Metric(alpha, beta))



Spin2Propagator =  lambda mu, nu, alpha, beta, part: Spin2masslessPropagator(mu, nu, alpha, beta) + \
                - 1/2 * OverMass2(part) * (Metric(mu,alpha)* P(nu, part) * P(beta, part) + \
                                Metric(nu, beta) * P(mu, part) * P(alpha, part) + \
                                Metric(mu, beta) * P(nu, part) * P(alpha, part) + \
                                Metric(nu, alpha) * P(mu, part) * P(beta , part) )+ \
                1/6 * (Metric(mu,nu) + 2 * OverMass2(part) * P(mu, part) * P(nu, part)) * \
                      (Metric(alpha,beta) + 2 * OverMass2(part) * P(alpha, part) * P(beta, part))