• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

APN-Pucky / feynamp / 8573202894

05 Apr 2024 05:00PM UTC coverage: 83.939% (+0.1%) from 83.825%
8573202894

Pull #50

github

APN-Pucky
update color
Pull Request #50: gg_gg

79 of 100 new or added lines in 9 files covered. (79.0%)

35 existing lines in 5 files now uncovered.

716 of 853 relevant lines covered (83.94%)

0.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

79.31
/feynamp/form/lorentz.py
1
from typing import List
1✔
2

3
from feynml.feynmandiagram import FeynmanDiagram
1✔
4
from feynml.leg import Leg
1✔
5
from feynmodel.feyn_model import FeynModel
1✔
6

7
from feynamp.form.form import get_dummy_index, init, run, string_to_form
1✔
8
from feynamp.leg import find_leg_in_model
1✔
9
from feynamp.log import debug
1✔
10
from feynamp.momentum import insert_momentum
1✔
11
from feynamp.util import is_mass_zero
1✔
12

13
gammas = """
1✔
14
repeat;
15
* identity
16
    id Gamma(Mua?,Spinb?,Spinc?) * GammaId(Spinc?,Spind?) = Gamma(Mua,Spinb,Spind);
17
    id Gamma(Mua?,Spinb?,Spinc?) * GammaId(Spind?,Spinb?) = Gamma(Mua,Spind,Spinc);
18
    id GammaId(Spina?,Spinb?) * GammaId(Spinb?,Spind?) = GammaId(Spina,Spind);
19
    id GammaId(Spina?,Spina?) = 4;
20
* Metric
21
    id Metric(Mua?,Mub?) * Gamma(Mua?,Spind?,Spinf?) = Gamma(Mub,Spind,Spinf);
22
    id Metric(Mua?,Mub?) * P(Mua?,Momd?) = P(Mub,Momd);
23
    id Metric(Mua?,Mub?) * Metric(Mub?,Mua?) = 4;
24
    id Metric(Mua?,Mub?) * Metric(Mub?,Muc?) = Metric(Mua,Muc);
25
    id Metric(Mua?,Mua?) = 4;
26
* standard Gamma algebra
27
    id Gamma(Mua?,Spinb?,Spinc?)*Gamma(Mua?,Spinc?,Spind?) = -GammaId(Spinb,Spind);
28
    id Gamma(Mua?,Spinb?,Spinc?)*Gamma(Mud?,Spinc?,Spine?)*Gamma(Mua?,Spine?,Spinf?) = -2*Gamma(Mud,Spinb,Spinf);
29
    id Gamma(Mua?,Spinb?,Spinc?)*Gamma(Mud?,Spinc?,Spine?)*Gamma(Muf?,Spine?,Spinm?)*Gamma(Mua?,Spinm?,Spink?) = 4*Metric(Mud,Muf)*GammaId(Spinb,Spink);
30
    id Gamma(Mua?,Spinb?,Spinc?)*Gamma(Mud?,Spinc?,Spine?)*Gamma(Muf?,Spine?,Spinm?)*Gamma(Muk?,Spinm?,Spinl?)*Gamma(Mua?,Spinl?,Spinj?) = -2*Gamma(Muk,Spinb,Spinc)*Gamma(Muf,Spinc,Spinl)*Gamma(Mud,Spinl,Spinj);
31
* traces of Gamma
32
    id Gamma(Mua?,Spinb?,Spinb?) = 0;
33
    id Gamma(Mua?,Spinb?,Spinc?)*Gamma(Mub?,Spinc?,Spinb?) = 4*Metric(Mua,Mub);
34
    id Gamma(Mua?,Spinb?,Spinc?)*Gamma(Mub?,Spinc?,Spind?)*Gamma(Muc?,Spind?,Spinb?) = 0;
35
    id Gamma(Mua?,Spinb?,Spinc?)*Gamma(Mub?,Spinc?,Spind?)*Gamma(Muc?,Spind?,Spine?)*Gamma(Mud?,Spine?,Spinb?) 
36
        = 4*(Metric(Mua,Mub)*Metric(Muc,Mud) - Metric(Mua,Muc)*Metric(Mub,Mud)+ Metric(Mua,Mud)*Metric(Mub,Muc)) ;
37
    id Gamma(Mua?,Spinb?,Spinc?)*Gamma(Mub?,Spinc?,Spind?)*Gamma(Muc?,Spind?,Spine?)*Gamma(Mud?,Spine?,Spinf?)*Gamma(Mue?,Spinf?,Sping?)*Gamma(Muf?,Sping?,Spinb?)
38
        = 4*(Metric(Mua,Mub)*Metric(Muc,Mud)*Metric(Mue,Muf) 
39
           - Metric(Mua,Mub)*Metric(Muc,Mue)*Metric(Mud,Muf) 
40
           + Metric(Mua,Mub)*Metric(Muc,Muf)*Metric(Mud,Mue) 
41
           - Metric(Mua,Muc)*Metric(Mub,Mud)*Metric(Mue,Muf) 
42
           + Metric(Mua,Muc)*Metric(Mub,Mue)*Metric(Mud,Muf) 
43
           - Metric(Mua,Muc)*Metric(Mub,Muf)*Metric(Mud,Mue) 
44
           + Metric(Mua,Mud)*Metric(Mub,Muc)*Metric(Mue,Muf) 
45
           - Metric(Mua,Mud)*Metric(Mub,Mue)*Metric(Muc,Muf) 
46
           + Metric(Mua,Mud)*Metric(Mub,Muf)*Metric(Muc,Mue)
47
           - Metric(Mua,Mue)*Metric(Mub,Muc)*Metric(Mud,Muf)
48
           + Metric(Mua,Mue)*Metric(Mub,Mud)*Metric(Muc,Muf)
49
           - Metric(Mua,Mue)*Metric(Mub,Muf)*Metric(Muc,Mud)
50
           + Metric(Mua,Muf)*Metric(Mub,Muc)*Metric(Mud,Mue)
51
           - Metric(Mua,Muf)*Metric(Mub,Mud)*Metric(Muc,Mue)
52
           + Metric(Mua,Muf)*Metric(Mub,Mue)*Metric(Muc,Mud));
53
endrepeat;
54
"""
55

56

57
# TODO implement collecting of gammas and form calc solving of it
58
# idea: GammaCollect(1,spin1,spin2, mu,nu,...) run through and then apply to expression
59
gamma_collect = """
1✔
60
#do i = 1, 10
61
once Gamma(Mux?,Spin1?,Spin2?) = GammaCollect(`i',Spin1,Spin2,Mux);
62
repeat;
63
id GammaCollect(`i',Spin1?,Spin2?,?mus)*Gamma(Mux?, Spin2?,Spin3?) = GammaCollect(`i',Spin1,Spin3, ?mus, Mux);
64
id GammaCollect(`i',Spin1?,Spin2?,?mus)*GammaId(Spin2?,Spin3?) = GammaCollect(`i',Spin1,Spin3, ?mus)*gi_(`i');
65
endrepeat;
66
id GammaCollect(`i',Spin1?,Spin1?,?mus) = g_(`i',?mus);
67
trace4, `i';
68
#enddo
69
#do i = 11, 21
70
once GammaId(Spin1?,Spin2?) = GammaIdCollect(`i',Spin1,Spin2);
71
repeat;
72
id GammaIdCollect(`i',Spin1?,Spin2?)*GammaId(Spin2?,Spin3?) = GammaIdCollect(`i',Spin1,Spin3)*gi_(`i');
73
endrepeat;
74
id GammaIdCollect(`i',Spin1?,Spin1?) = 1;
75
trace4, `i';
76
#enddo
77
"""
78

79
metrics = """
1✔
80
* Simplify metrics, here let form handle it 
81
repeat;
82
id Metric(Mua?,Mub?) = d_(Mua,Mub);
83
endrepeat;
84
"""
85

86

87
def get_metrics():
1✔
88
    return metrics
1✔
89

90

91
def get_gammas():
1✔
92
    return new_get_gammas()
1✔
93

94

95
def new_get_gammas():
1✔
96
    return get_dirac_trick() + get_metrics() + gamma_collect
1✔
97

98

99
def get_gammas_v1():
1✔
UNCOV
100
    return get_polarisation_sum_v1() + get_dirac_trick() + gammas
×
101

102

103
def apply_gammas(string_expr):
1✔
104
    s = string_to_form(string_expr)
1✔
105
    return run(init + f"Local TMP = {s};" + get_gammas())
1✔
106

107

108
def get_orthogonal_polarisation_momentum(
1✔
109
    leg: Leg, fds: List[FeynmanDiagram], model: FeynModel
110
):
111
    for fd in [fds[0]]:
1✔
112
        for fleg in fd.legs:
1✔
113
            p = find_leg_in_model(fd, fleg, model)
1✔
114
            if (
1✔
115
                is_mass_zero(p)
116
                and fleg != leg
117
                and leg.is_incoming() == fleg.is_incoming()
118
            ):
119
                mom = insert_momentum(fleg.momentum.name)
1✔
120
                return mom
1✔
UNCOV
121
    raise ValueError("No orthogonal momentum found")
×
122

123

124
def get_polarisation_sums(fds: List[FeynmanDiagram], model: FeynModel):
1✔
125
    pol_sums = ""
1✔
126
    # TODO might want to loop over all fds?
127
    for fd in [fds[0]]:
1✔
128
        for l in fd.legs:
1✔
129
            p = find_leg_in_model(fd, l, model)
1✔
130
            mom = insert_momentum(l.momentum.name)
1✔
131
            # mass = insert_mass(string_to_form(p.mass.name))
132
            if p.spin == 3:
1✔
133
                if is_mass_zero(p):
1✔
134
                    if p.color == 8:
1✔
135
                        mom_n = get_orthogonal_polarisation_momentum(l, fds, model)
1✔
136
                        pol_sums += get_polarisation_sum_physical(mom, mom_n)
1✔
137
                        # pol_sums += get_polarisation_sum_feynman(mom)
138
                        debug(f"mom: {mom}, mom_n: {mom_n}")
1✔
139
                    elif p.color == 1:
1✔
140
                        pol_sums += get_polarisation_sum_feynman(mom)
1✔
141
                else:
UNCOV
142
                    pol_sums += get_polarisation_sum_massive(mom)
×
143
    debug(f"pol_sums: {pol_sums}")
1✔
144
    return pol_sums
1✔
145

146

147
def get_polarisation_sum_massive(mom_a):
1✔
UNCOV
148
    pol_sum = f"""
×
149
    id epsstar(Muc?,Polb?,{mom_a}) * eps(Mul?,Pold?,{mom_a}) = -Metric(Mul,Muc) + (P(Mul,{mom_a})*P(Muc,{mom_a}))*Den({mom_a}.{mom_a});
150
    """
UNCOV
151
    return pol_sum
×
152

153

154
def get_polarisation_sum_feynman(mom_a):
1✔
155
    pol_sum = f"""
1✔
156
    id epsstar(Muc?,Polb?,{mom_a}) * eps(Mul?,Pold?,{mom_a}) = -Metric(Mul,Muc);
157
    """
158
    return pol_sum
1✔
159

160

161
def get_polarisation_sum_physical(mom_a, mom_b):
1✔
162
    pol_sum = f"""
1✔
163
    id epsstar(Muc?,Polb?,{mom_a}) * eps(Mul?,Pold?,{mom_a}) = -Metric(Muc,Mul) 
164
    + (P(Muc,{mom_a})*P(Mul,{mom_b}) +  P(Mul,{mom_a})*P(Muc,{mom_b}))*Den({mom_b}.{mom_a}) 
165
    - P(Muc,{mom_a})*P(Mul,{mom_a})*({mom_b}.{mom_b})*Den({mom_b}.{mom_a})*Den({mom_b}.{mom_a});
166
    """
167
    return pol_sum
1✔
168

169

170
def get_polarisation_sum(mom_a, mom_b=None):
1✔
UNCOV
171
    if mom_b is None:
×
172
        # massive case
UNCOV
173
        return get_polarisation_sum_massive(mom_a)
×
UNCOV
174
    elif mom_b == 0:
×
175
        # photon massless case
UNCOV
176
        return get_polarisation_sum_feynman(mom_a)
×
177
    else:
178
        # gluon massless case
UNCOV
179
        return get_polarisation_sum_physical(mom_a, mom_b)
×
180

181

182
def get_polarisation_sum_v1():
1✔
183
    polsum_feyn = """
×
184
    id epsstar(Muc?,Polb?,Moma?) * eps(Mul?,Pold?,Moma?) = -Metric(Muc,Mul);
185
    """
186
    polsum_feyn = """
×
187
    id epsstar(Muc?,Polb?,Moma?) * eps(Mul?,Pold?,Moma?) = -Metric(Mul,Muc);
188
    """
UNCOV
189
    return polsum_feyn
×
190

191

192
# TODO figure out why this does not work but manual dummies work
193
dirac_trick = """
1✔
194
repeat;
195
    id u(Spinc?,Momb?)*ubar(Spina?,Momb?) = Gamma(N5_?,Spinc,Spina) * P(N5_?,Momb) + GammaId(Spinc,Spina) * P(N5_?,Momb) * P(N5_?,Momb);
196
    id vbar(Spinc?,Momb?)*v(Spina?,Momb?) = Gamma(N7_?,Spinc,Spina) * P(N7_?,Momb) - GammaId(Spinc,Spina) * P(N7_?,Momb) * P(N7_?,Momb);
197
endrepeat;
198
"""
199

200

201
def get_dirac_trick(N=10):
1✔
202
    ret = ""
1✔
203
    for i in range(N):
1✔
204
        dummy = get_dummy_index()
1✔
205
        dirac_trick = f"""
1✔
206
    once u(Spinc?,Momb?)*ubar(Spina?,Momb?) = Gamma({dummy},Spinc,Spina) * P({dummy},Momb) + GammaId(Spinc,Spina) * P({dummy},Momb) * P({dummy},Momb);
207
    """
208
        ret += dirac_trick
1✔
209
    for i in range(N):
1✔
210
        dummy = get_dummy_index()
1✔
211
        dirac_trick = f"""
1✔
212
    once vbar(Spinc?,Momb?)*v(Spina?,Momb?) = Gamma({dummy},Spinc,Spina) * P({dummy},Momb) - GammaId(Spinc,Spina) * P({dummy},Momb) * P({dummy},Momb);
213
    """
214
        ret += dirac_trick
1✔
215
    return ret
1✔
216

217

218
# TODO: look above
219
# def get_dirac_trick():
220
#    return dirac_trick
221

222

223
def apply_dirac_trick(string_expr):
1✔
UNCOV
224
    s = string_to_form(string_expr)
×
UNCOV
225
    return run(init + f"Local TMP = {s};" + get_dirac_trick())
×
226

227

228
def apply_polarisation_sum(string_expr):
1✔
UNCOV
229
    s = string_to_form(string_expr)
×
UNCOV
230
    return run(init + f"Local TMP = {s};" + get_polarisation_sum())
×
231

232

233
# TODO: implement this use forms gamma algebra
234
def replace_indices_by_line():
1✔
235
    # return list of lines
236
    pass
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc