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

APN-Pucky / feynamp / 9267239762

28 May 2024 09:53AM UTC coverage: 80.215% (-2.1%) from 82.348%
9267239762

Pull #67

github

APN-Pucky
fix: PREFACTOR
Pull Request #67: add: spin correlation

13 of 43 new or added lines in 5 files covered. (30.23%)

31 existing lines in 3 files now uncovered.

896 of 1117 relevant lines covered (80.21%)

0.8 hits per line

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

84.21
/feynamp/form/color.py
1
from typing import List
1✔
2

3
from feynamp.form.form import get_dummy_index, init, run, run_parallel, string_to_form
1✔
4
from feynamp.leg import (
1✔
5
    color_vector_to_id,
6
    color_vector_to_index,
7
    color_vector_to_operator,
8
    get_color_vector,
9
    get_leg_momentum,
10
    is_swapped_color_vector,
11
)
12
from feynamp.log import debug
1✔
13

14
from .colorh import colorh
1✔
15

16
colorh_init = f"""
1✔
17
{colorh}
18
AutoDeclare Index Color=NR;
19
AutoDeclare Index Glu=NA;
20
"""
21

22
color_init = """
1✔
23
AutoDeclare Index Color;
24
AutoDeclare Index Glu;
25
Tensors f(antisymmetric), colorcorrelation;
26
CFunctions T;
27
Symbols NA,I2R;
28
"""
29

30
color_ids = """
1✔
31
repeat;
32
* remove df(k,j)
33
   id df(k?,l?)*df(l?,j?)=df(k,j);
34
   id T(a?,k?,l?)*df(k?,j?)=T(a,j,l);
35
   id T(a?,k?,l?)*df(l?,j?)=T(a,k,j);
36
* remove da(a,b)
37
   id da(a?,b?)*da(b?,c?)=da(a,c);
38
   id T(a?,k?,l?)*da(a?,b?)=T(b,k,l);
39
   id f(a?,b?,c?)*da(a?,d?)=f(d,b,c);
40
* simplify traces
41
   id T(b?,k?,k?)=0;
42
   id da(a?,a?)=Nc*Cf/Tr;
43
   id df(a?,a?)=Nc;
44
endrepeat;
45
"""
46

47
colorh_ids = """
1✔
48
* https://www.nikhef.nl/~form/maindir/packages/color/color.pdf
49
* Appendix D
50
id d33(cOlpR1,cOlpR2) = I2R^3/(2*Nc)*(Nc^2-1)*(Nc^2-4);
51
id d44(cOlpR1,cOlpR2) = I2R^4/(6*Nc^2)*(Nc^2-1)*(Nc^4-6*Nc^2+18);
52
repeat;
53
* remove df(k,j)
54
   id df(k?,l?)*df(l?,j?)=df(k,j);
55
   id T(k?,l?,a?)*df(k?,j?)=T(j,l,a);
56
   id T(k?,l?,a?)*df(l?,j?)=T(k,j,a);
57
* remove da(a,b)
58
   id da(a?,b?)*da(b?,c?)=da(a,c);
59
   id T(k?,l?,a?)*da(a?,b?)=T(k,l,b);
60
   id f(b?,c?,a?)*da(a?,d?)=f(b,c,d);
61
* simplify traces
62
   id T(k?,k?,b?)=0;
63
   id da(a?,a?)=Nc*Cf/Tr;
64
   id df(a?,a?)=Nc;
65
endrepeat;
66
"""
67

68
color_simplify = """
1✔
69
* simplify combination of factors
70
*   id Nc^-2=2-Nc^2+Cf^2*Tr^-2;
71
*   id Nc^2=1+Nc*Cf/Tr;
72
   id NA=Nc*Cf/Tr;
73
   id cA=Nc;
74
   id cR=Cf;
75
   id I2R=1/2;
76
   id Tr=1/2;
77
   id Tr^-1=2;
78
"""
79

80
old_color = f"""
1✔
81
**********************************************************
82
*                  COLOUR STRUCTURE SIMPLIFY             *
83
**********************************************************
84
    
85
repeat;
86
{color_ids}
87
* length-three objects simplify:
88
   id T(b?,k?,j?)*T(a?,j?,c?)*T(b?,c?,l?)=(-Tr/Nc*T(a,k,l));
89
   id T(b?,j?,l?)*T(c?,l?,k?)*f(a?,b?,c?)=(i_*Nc*Tr*T(a,j,k));
90
* length-two objects that give out df(k,j)
91
   id T(a?,c?,j?)*T(a?,k?,l?)=(-1/Nc*df(c, j)*df(k, l)*Tr + df(c, l)*df(j, k)*Tr);
92
   id T(a?,k?,l?)*T(a?,l?,j?)=(Cf*df(k,j));
93
* length-two objects that give out da(a,b)
94
   id T(a?,k?,l?)*T(b?,l?,k?)=(Tr*da(a,b));
95
   id f(a?,b?,c?)*f(d?,b?,c?)=Nc*da(a,d); 
96
{color_simplify}
97
* double f(a,b,c) simplify
98
*  id f(a?,b?,e?)*f(c?,d?,e?)=-2 * {{ [T(a), T(b)] [T(c), T(d)]}};
99
   id f(a?,b?,e?)*f(c?,d?,e?)=-2 * (T(a,e,N1_?)*T(b,N1_?,N2_?) - T(b,e,N1_?)*T(a,N1_?,N2_?))*(T(c,N2_?,N3_?)*T(d,N3_?,e)-T(d,N2_?,N3_?)*T(c,N3_?,e));
100
endrepeat;
101
"""
102

103

104
color = """
1✔
105
#call docolor
106
"""
107
# TODO do the color stuff manually (cf. MG) since the simplifications here are very expensive
108

109
color_sum = """
1✔
110
**********************************************************
111
*                  COLOUR SUM SIMPLIFY                   *
112
**********************************************************
113
repeat;
114
  id VA(Glua?,Momb?)*VA(Gluc?,Momb?) = da(Glua,Gluc);
115
  id VC(Colora?,Momb?)*VC(Colorc?,Momb?) = df(Colora,Colorc);
116
endrepeat;
117
"""
118

119

120
def rep(s: str):
1✔
121
    return f"""
1✔
122
repeat;
123
   {s}
124
endrepeat;
125
"""
126

127

128
repeat = rep
1✔
129

130

131
def get_color(fds=None, legs=None, model=None, colorcorrelation=False, s2=None):
1✔
132
    assert not colorcorrelation or (
1✔
133
        fds is not None and legs is not None and model is not None
134
    )
135
    # return get_color_v1()
136
    return get_color_v3(fds, legs, model, colorcorrelation=colorcorrelation, s2=s2)
1✔
137

138

139
def get_full_color_correlation_matrix(fds, legs, model, s2):
1✔
140

141
    left = ""
1✔
142
    right = ""
1✔
143
    vec = []
1✔
144
    ops = []
1✔
145
    ind = []
1✔
146
    ind1 = []
1✔
147
    ind2 = []
1✔
148
    mom = []
1✔
149
    swap = []
1✔
150
    ids = []
1✔
151
    for i in range(len(legs)):
1✔
152
        swap += [is_swapped_color_vector(fds[0], legs[i], model, s2)]
1✔
153
        vec += [get_color_vector(fds[0], legs[i], model)]
1✔
154
        ids += [color_vector_to_id(vec[i])]
1✔
155
        mom += [get_leg_momentum(legs[i])]
1✔
156
        ops += [("(-1)*" if swap[i] else "") + str(color_vector_to_operator(vec[i]))]
1✔
157
        ind += [color_vector_to_index(vec[i])]
1✔
158
        ind1 += [str(ind[i]) + legs[i].id]
1✔
159
        ind2 += [str(ind[i]) + get_dummy_index(underscore=False, questionmark=False)]
1✔
160
    dummy = "Glu" + get_dummy_index(underscore=False, questionmark=False)
1✔
161
    for i in range(len(legs)):
1✔
162
        if vec[i] is not None:
1✔
163
            i1 = ind1[i] + " "
1✔
164
            i2 = ind2[i] + "?"
1✔
165
            if swap[i]:
1✔
166
                i1, i2 = i2, i1
1✔
167
            left += f"{vec[i]}({i1},{mom[i]})*{vec[i]}({i2},{mom[i]})*"
1✔
168
            i1, i2 = i1[:-1], i2[:-1]
1✔
169
            for j in range(i + 1, len(legs)):
1✔
170
                if vec[j] is not None:
1✔
171

172
                    j1 = ind1[j]
1✔
173
                    j2 = ind2[j]
1✔
174
                    if swap[j]:
1✔
175
                        j1, j2 = j2, j1
1✔
176
                    deltas = "*"
1✔
177
                    for k in range(len(legs)):
1✔
178
                        if vec[k] is not None and i != k and j != k:
1✔
179
                            deltas += f"{ids[k]}({ind1[k]},{ind2[k]})*"
1✔
180
                    right += f"\ncolorcorrelation({mom[i]},{mom[j]})*{ops[i]}({i1},{i2},{dummy})*{ops[j]}({j1},{j2},{dummy}){deltas[:-1]}+"
1✔
181
                    # right += f"\n{ops[i]}({i1},{i2},{dummy})*{ops[j]}({j1},{j2},{dummy}){deltas[:-1]}+"
182
                    # right += f"\ncolorcorrelation({mom[i]},{mom[j]})*d_({i1},{i2})*d_({j1},{j2}){deltas[:-1]}+"
183
    if left == "" or right == "":
1✔
184
        # Nothing to color correlate => abort/return 0
NEW
185
        return "id PREFACTOR = 0;"
×
186
    # The minus sign below is from https://arxiv.org/pdf/1002.2581 Eq. 2.6
187
    ret = f"""
1✔
188
    id {left[:-1]} = -({right[:-1]});
189
    """
190
    # print(ret)
191
    return ret
1✔
192

193

194
def get_color_sum_v1(mom1=None, mom2=None):
1✔
195
    ret = ""
×
196
    if mom1 is not None and mom2 is not None:
×
197
        # new index that is summed over
198
        dummy = "Glu" + get_dummy_index()
×
199
        ret += repeat(
×
200
            f"""
201
         id VA(Glua?,{mom1})*VA(Gluc?,{mom1}) = f(Glua,Gluc,{dummy});
202
         id VA(Glua?,{mom2})*VA(Gluc?,{mom2}) = f(Glua,Gluc,{dummy});
203
         id VC(Colora?,{mom1})*VC(Colorc?,{mom1}) = T(Colora,Colorc,{dummy});
204
         id VC(Colora?,{mom2})*VC(Colorc?,{mom2}) = T(Colora,Colorc,{dummy});
205
"""
206
        )
207
    return ret + color_sum
×
208

209

210
def get_color_v3(fds, legs, model, colorcorrelation=False, s2=None):
1✔
211
    ret = ""
1✔
212
    if colorcorrelation:
1✔
213
        ret += get_full_color_correlation_matrix(fds, legs, model, s2=s2)
1✔
214
    else:
215
        ret += color_sum
1✔
216
    return ret + colorh_ids + color + colorh_ids + rep(color_simplify)
1✔
217

218

219
def get_color_v2():
1✔
220
    return color_sum + colorh_ids + color + colorh_ids + rep(color_simplify)
×
221

222

223
def get_color_v1():
1✔
224
    return color_sum + color_ids + old_color
×
225

226

227
def get_color_ids():
1✔
228
    return color_sum + colorh_ids
×
229

230

231
def apply_color_ids(string_expr):
1✔
232
    s = string_to_form(string_expr)
×
233
    return run(init + colorh_init + f"Local TMP = {s};" + get_color_ids())
×
234

235

236
def apply_color_parallel(string_exprs: List[str], **kwargs):
1✔
237
    return run_parallel(
1✔
238
        init + colorh_init,
239
        # we only forward one
240
        get_color(s2=string_exprs[0], **kwargs),
241
        [string_to_form(a) for a in string_exprs],
242
    )
243

244

245
def apply_color(string_expr):
1✔
246
    s = string_to_form(string_expr)
1✔
247
    return run(init + colorh_init + f"Local TMP = {s};" + get_color())
1✔
248

249

250
def apply_color_sum(string_expr):
1✔
251
    s = string_to_form(string_expr)
×
252
    return run(init + f"Local TMP = {s};" + color_sum)
×
253

254

255
def apply_color_simplify(string_expr):
1✔
256
    s = string_to_form(string_expr)
×
257
    return run(init + f"Local TMP = {s};" + color)
×
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