Skip to content

Commit addceff

Browse files
committed
Merge main
2 parents 35202ff + cc87eec commit addceff

File tree

9 files changed

+77
-42
lines changed

9 files changed

+77
-42
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010

1111
### Added
1212

13+
- Support for arbitrary Gram determinants, e.g. for a box gram: `Δ_12|3|4|5`
14+
1315
### Changed
1416

1517
### Fixed
1618

19+
- Sphinx fails if autodoc fails, instead of quitely raising a warning.
20+
1721
### Deprecated
1822

1923

lips/hardcoded_limits/particles_set.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,11 @@ def _set_Sijk(self, temp_string, temp_value, fix_mom=True, mode=1):
314314

315315
def _set_Dijk(self, temp_string, temp_value, fix_mom=True, mode=1): # Set Dijk, change angle bracket (odd mode) or square bracket (even mode)
316316

317-
match_list = pDijk.findall(temp_string)[0]
318-
if match_list[0] == '':
319-
NonOverlappingLists = [list(map(int, corner)) for corner in match_list[1:]]
317+
match = pDijk.findall(temp_string)[0]
318+
if "|" in match:
319+
NonOverlappingLists = [list(map(int, corner)) for corner in match.split("|")]
320320
else:
321-
NonOverlappingLists = self.ijk_to_3NonOverlappingLists(list(map(int, match_list[0])))
321+
NonOverlappingLists = self.ijk_to_3NonOverlappingLists(list(map(int, match)))
322322

323323
to_be_changed = NonOverlappingLists[0].pop((mode - 1) // 2)
324324

lips/hardcoded_limits/particles_set_pair.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -334,13 +334,13 @@ def _set_pair_A2_or_S2_and_Dijk(self, t_s1, t_v1, t_s2, t_v2): # Current faile
334334
ab = list(map(int, list(pS2.findall(t_s1)[0])))
335335

336336
ab = list(map(int, ab))
337-
match_list = pDijk.findall(t_s2)[0]
338-
if match_list[0] == '':
337+
match = pDijk.findall(t_s2)[0]
338+
if "|" in match:
339339
adjacent = False
340-
NonOverlappingLists = [list(map(int, corner)) for corner in match_list[1:]]
340+
NonOverlappingLists = [list(map(int, corner)) for corner in match.split("|")]
341341
else:
342342
adjacent = True
343-
NonOverlappingLists = self.ijk_to_3NonOverlappingLists(list(map(int, match_list[0])))
343+
NonOverlappingLists = self.ijk_to_3NonOverlappingLists(list(map(int, match)))
344344

345345
both_in_List = -1 # if both ab in a single List:
346346
for i, List in enumerate(NonOverlappingLists):
@@ -707,13 +707,13 @@ def reverse_order(t_s):
707707

708708
def reorder_invariants(t_s1, t_s2):
709709
l3B, l3Bs, l3Bm, l3Be, a_or_s, l3Bc = unpack(t_s1)
710-
match_list = pDijk.findall(t_s2)[0]
711-
if match_list[0] == '':
710+
match = pDijk.findall(t_s2)[0]
711+
if "|" in match:
712712
adjacent = False
713-
NonOverlappingLists = [list(map(int, corner)) for corner in match_list[1:]]
713+
NonOverlappingLists = [list(map(int, corner)) for corner in match.split("|")]
714714
else:
715715
adjacent = True
716-
NonOverlappingLists = self.ijk_to_3NonOverlappingLists(list(map(int, match_list[0])))
716+
NonOverlappingLists = self.ijk_to_3NonOverlappingLists(list(map(int, match)))
717717
if l3Bs == l3Be:
718718
for NonOverlappingList in NonOverlappingLists:
719719
if l3Bs in NonOverlappingList and [entry for entry in NonOverlappingList if entry != l3Bs][0] in l3Bm:
@@ -765,11 +765,11 @@ def there_are_two_free_particles(*args):
765765
return "Not implemented."
766766

767767
l3B, l3Bs, l3Bm, l3Be, a_or_s, l3Bc = unpack(t_s1)
768-
match_list = pDijk.findall(t_s2)[0]
769-
if match_list[0] == '':
770-
NonOverlappingLists = [list(map(int, corner)) for corner in match_list[1:]]
768+
match = pDijk.findall(t_s2)[0]
769+
if "|" in match:
770+
NonOverlappingLists = [list(map(int, corner)) for corner in match.split("|")]
771771
else:
772-
NonOverlappingLists = self.ijk_to_3NonOverlappingLists(list(map(int, match_list[0])))
772+
NonOverlappingLists = self.ijk_to_3NonOverlappingLists(list(map(int, match)))
773773

774774
self._set(t_s1, t_v1, fix_mom=False)
775775
if t_s1[0] == "⟨":
@@ -836,11 +836,11 @@ def _set_pair_Sijk_and_Dijk(self, t_s1, t_v1, t_s2, t_v2): # Current failed: 8/
836836
from .DoubleCollinearLimit_D_and_S_e import expression_for_e
837837

838838
Sijk = list(map(int, pSijk.findall(t_s1)[0]))
839-
match_list = pDijk.findall(t_s2)[0]
840-
if match_list[0] == '':
841-
NonOverlappingLists = [list(map(int, corner)) for corner in match_list[1:]]
839+
match = pDijk.findall(t_s2)[0]
840+
if "|" in match:
841+
NonOverlappingLists = [list(map(int, corner)) for corner in match.split("|")]
842842
else:
843-
NonOverlappingLists = self.ijk_to_3NonOverlappingLists(list(map(int, match_list[0])))
843+
NonOverlappingLists = self.ijk_to_3NonOverlappingLists(list(map(int, match)))
844844

845845
FirstNonOverlappingList = -1
846846
SecondNonOverlappingList = -1

lips/particle.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import numpy
1111
import sympy
12-
import mpmath
1312
import random
1413
import lips
1514

@@ -42,6 +41,7 @@ def __init__(self, kinematics=None, real_momentum=False, field=Field('mpc', 0, 3
4241
(2, 2) : rank 2 spinor;
4342
( (2, 1), (1, 2) ) : (right spinor index down, left spinor index down).
4443
"""
44+
# Should check the field is consistent with the kinematics info, or even compute it from there.
4545
self.field = field
4646
if kinematics is None and field.name in ("mpc", "gaussian rational", "finite field", "padic"):
4747
self.randomise(real_momentum=real_momentum)
@@ -320,7 +320,7 @@ def randomise_mpc(self, real_momentum=False):
320320
if not (abs(p[0]) == 0 and abs(p[1]) == 0 and p[2].real <= 0 and p[2].imag == 0): # make sure it is not in the
321321
break # negative z direction or null
322322
p2 = p[0] * p[0] + p[1] * p[1] + p[2] * p[2]
323-
p_zero = mpmath.sqrt(p2)
323+
p_zero = self.field.sqrt(p2)
324324
self.four_mom = numpy.array([p_zero] + p)
325325

326326
def randomise_rational(self):
@@ -379,7 +379,7 @@ def _set_r_sp_d(self, P0_plus_P3, P1_plus_iP2): # r_sp_d is \lambda_\alpha
379379
if lips.spinor_convention == 'symmetric' and abs(P0_plus_P3) <= self.field.tollerance:
380380
raise ValueError("Encountered zero denominator in spinor.")
381381
elif lips.spinor_convention == 'symmetric':
382-
lambda_one = mpmath.sqrt(P0_plus_P3)
382+
lambda_one = self.field.sqrt(P0_plus_P3)
383383
lambda_two = P1_plus_iP2 / lambda_one
384384
elif lips.spinor_convention == 'asymmetric':
385385
lambda_one = P0_plus_P3
@@ -397,7 +397,7 @@ def _set_l_sp_d(self, P0_plus_P3, P1_minus_iP2): # l_sp_d is \bar{\lambda}_{\do
397397
if lips.spinor_convention == 'symmetric' and abs(P0_plus_P3) <= self.field.tollerance:
398398
raise ValueError("Encountered zero denominator in spinor.")
399399
elif lips.spinor_convention == 'symmetric':
400-
lambda_one = mpmath.sqrt(P0_plus_P3)
400+
lambda_one = self.field.sqrt(P0_plus_P3)
401401
lambda_two = P1_minus_iP2 / lambda_one
402402
elif lips.spinor_convention == 'asymmetric':
403403
lambda_one = self.field(1)

lips/particles_compute.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
import numpy
1313
import re
1414
import mpmath
15+
import warnings
1516

1617
from .tools import pSijk, pMi, pMVar, pd5, pDijk, pOijk, pPijk, pA2, pAu, pAd, pS2, pSu, pSd, \
17-
pNB, pNB_open_begin, pNB_open_end, ptr5, ptr, det2x2
18+
pNB, pNB_open_begin, pNB_open_end, ptr5, ptr, det
1819

1920
mpmath.mp.dps = 300
2021

@@ -94,14 +95,19 @@ def compute(self, temp_string):
9495
return Pi
9596

9697
if pDijk.findall(temp_string) != []: # Δ_ijk or Δ_ij|kl|lm
97-
match_list = pDijk.findall(temp_string)[0]
98-
if match_list[0] == '':
99-
NonOverlappingLists = [list(map(int, corner)) for corner in match_list[1:]]
100-
else:
101-
NonOverlappingLists = self.ijk_to_3NonOverlappingLists(list(map(int, match_list[0])))
98+
match = pDijk.findall(temp_string)[0]
99+
if "|" in match:
100+
indices_in_corners = [list(map(int, corner)) for corner in match.split("|")]
101+
r2_sps = [sum([self[_i].r2_sp for _i in indices]) for indices in indices_in_corners]
102+
r2_sps_b = [sum([self[_i].r2_sp_b for _i in indices]) for indices in indices_in_corners]
103+
n = len(indices_in_corners)
104+
matrix = numpy.array([[numpy.trace(numpy.dot(r2_sps[i], r2_sps_b[j])) / 2 for j in range(n)] for i in range(n)])
105+
return (-1) ** n * det(matrix[:-1, :-1])
106+
warnings.warn("The shorthand Δ_ijk is deprecated and will be removed.", DeprecationWarning, stacklevel=2)
107+
NonOverlappingLists = self.ijk_to_3NonOverlappingLists(list(map(int, match)))
102108
r2_sp_1 = sum([self[_i].r2_sp for _i in NonOverlappingLists[0]])
103109
r2_sp_b_2 = sum([self[_i].r2_sp_b for _i in NonOverlappingLists[1]])
104-
return (numpy.trace(numpy.dot(r2_sp_1, r2_sp_b_2)) / 2) ** 2 - det2x2(r2_sp_1) * det2x2(r2_sp_b_2)
110+
return (numpy.trace(numpy.dot(r2_sp_1, r2_sp_b_2)) / 2) ** 2 - det(r2_sp_1) * det(r2_sp_b_2)
105111

106112
if pd5.findall(temp_string) != []:
107113
return (2 * self.compute("s_12") * self.compute("s_23") * self.compute("s_34") * self.compute("s_45") +
@@ -128,7 +134,7 @@ def compute(self, temp_string):
128134
r"""Mandelstam variables: s_{i \dots k} = (P_i + \dots + P_k)^2. Computed via determinant of rank 2 spinor."""
129135
ijk = list(map(int, pSijk.findall(temp_string)[0]))
130136
tot_r2_sp = sum([self[_i].r2_sp for _i in ijk])
131-
return det2x2(tot_r2_sp)
137+
return det(tot_r2_sp)
132138

133139
if pA2.findall(temp_string) != []: # ⟨A|B⟩ -- contraction is up -> down : lambda[A]^alpha.lambda[B]_alpha
134140
A, B = map(int, pA2.findall(temp_string)[0])

lips/particles_eval.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
pOijk = re.compile(r'(?:Ω_)(\d+)')
3636
pPijk = re.compile(r'(?:Π_)(\d+)')
3737
pDijk_adjacent = re.compile(r'(?:Δ_(\d+)(?![\d\|]))')
38-
pDijk_non_adjacent = re.compile(r'(?:Δ_(\d+)\|(\d+)\|(\d+))')
38+
pDijk_non_adjacent = re.compile(r'(?:Δ_(\d+(?:\|\d+)*))')
3939
# p3B = re.compile(r'(?:\u27e8|\[)(\d+)(?:\|\({0,1})([\d+[\+|-]*]*)(?:\){0,1}\|)(\d+)(?:\u27e9|\])')
4040
# pNB = re.compile(r'((?:⟨|\[)\d+\|(?:(?:\([\d+\+|-]{1,}\))|(?:[\d+\+|-]{1,}))*\|\d+(?:⟩|\]))') # this messes up on strings like: '|2⟩⟨1|4+5|3|+|3|4+5|2⟩⟨1|'
4141
pNB = re.compile(r'((?:⟨|\[)\d+\|(?:(?:(?!\|[\+|-]\|)\([\d+\+|-]{1,}\))|(?:(?!\|[\+|-]\|)[\d+\+|-]))*\|\d+(?:⟩|\]))')
@@ -106,7 +106,7 @@ def _parse(string):
106106
string = ptr5.sub(r"oPs.compute('tr5\1')", string)
107107
string = ptr.sub(r"oPs.compute('\1')", string)
108108
string = pDijk_adjacent.sub(r"oPs.compute('Δ_\1')", string)
109-
string = pDijk_non_adjacent.sub(r"oPs.compute('Δ_\1|\2|\3')", string)
109+
string = pDijk_non_adjacent.sub(r"oPs.compute('Δ_\1')", string)
110110
string = pNB.sub(r"oPs.compute('\1')", string)
111111
string = pNB_open_begin.sub(r"oPs.compute('\1')", string)
112112
string = pNB_open_end.sub(r"oPs.compute('\1')", string)

lips/tools.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import numpy
88
import random
99
import re
10+
import warnings
1011

1112
mpmath.mp.dps = 300
1213

@@ -32,7 +33,7 @@
3233
pd5 = re.compile(r'^δ5$')
3334
ptr5 = re.compile(r'^tr5_(\d+)$|^tr5\(([\d\|\+\-]+)\)$')
3435
ptr = re.compile(r'^tr\((?P<middle>(?:(?:\([\d+\+|-]{1,}\))|(?:[\d+\+|-]{1,}))*)\)$') # the 'middle' pattern should be like in pNB
35-
pDijk = re.compile(r'(?:^Δ_(\d+)$)|(?:^Δ_(\d+)\|(\d+)\|(\d+)$)')
36+
pDijk = re.compile(r'^Δ_(\d+(?:\|\d+)*)$')
3637
pOijk = re.compile(r'^(?:Ω_)(\d+)$')
3738
pPijk = re.compile(r'^(?:Π_)(\d+)$')
3839
pAu = re.compile(r'^(?:⟨|<)(\d+)(?:\|)$')
@@ -92,8 +93,21 @@ def subs_dict(text, substitutions):
9293
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
9394

9495

95-
def det2x2(array):
96-
return array[0, 0] * array[1, 1] - array[0, 1] * array[1, 0]
96+
def det(matrix):
97+
if matrix.shape == (1, 1):
98+
return matrix[0, 0]
99+
100+
det_sum = 0
101+
for col in range(matrix.shape[1]):
102+
sub_matrix = matrix[1:, [i for i in range(matrix.shape[1]) if i != col]]
103+
det_sum += (-1) ** col * matrix[0, col] * det(sub_matrix)
104+
105+
return det_sum
106+
107+
108+
def det2x2(matrix):
109+
warnings.warn("det2x2 is deprecated, use det.", DeprecationWarning, stacklevel=2)
110+
return det(matrix)
97111

98112

99113
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #

sphinx/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33

44
# You can set these variables from the command line.
5-
SPHINXOPTS =
5+
SPHINXOPTS = -W
66
SPHINXBUILD = sphinx-build
77
SOURCEDIR = source
88
BUILDDIR = build

tests/test_particles_compute.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ def test_particles_compute_three_mass_gram():
101101
"""Test computation of 3-mass Gram w.r.t. summed particles object."""
102102
oParticles = Particles(9)
103103
temp_string = "Δ_135|249|678"
104-
match_list = pDijk.findall(temp_string)[0]
105-
if match_list[0] == '':
106-
NonOverlappingLists = [list(map(int, corner)) for corner in match_list[1:]]
104+
match = pDijk.findall(temp_string)[0]
105+
if "|" in match:
106+
NonOverlappingLists = [list(map(int, corner)) for corner in match.split("|")]
107107
else:
108-
NonOverlappingLists = oParticles.ijk_to_3NonOverlappingLists(list(map(int, match_list[0])))
108+
NonOverlappingLists = oParticles.ijk_to_3NonOverlappingLists(list(map(int, match)))
109109
temp_oParticles = oParticles.cluster(NonOverlappingLists)
110110
assert temp_oParticles.ldot(1, 2)**2 - temp_oParticles.ldot(1, 1) * temp_oParticles.ldot(2, 2) == oParticles(temp_string)
111111

@@ -120,3 +120,14 @@ def test_particles_compute_tr5_1234():
120120
oParticles[3].four_mom[k] *
121121
oParticles[4].four_mom[l]))
122122
assert abs(tr5 - oParticles("tr5_1234")) < 10 ** -290
123+
124+
125+
def test_particles_compute_four_mass_box_gram():
126+
oPs = Particles(8, field=Field("finite field", 2 ** 31 - 19, 1), seed=0)
127+
oPs._singular_variety(("⟨34⟩+[34]", "⟨34⟩-⟨56⟩", "⟨56⟩+[56]"), (1, 1, 1))
128+
oPs.mt2 = oPs("s_34")
129+
oPs.mt = oPs("<34>")
130+
oPs = oPs.cluster([[1, ], [2, ], [3, 4], [5, 6], [7, 8]])
131+
assert oPs.mt ** 2 == oPs.mt2
132+
assert oPs("Δ_12|3|4|5") == oPs("(1/4*(s12*(tr(3|3)²-tr(3|4)²)+tr(3|4)*tr(1+2|4)*tr(1+2|3)-1/2*tr(3|3)*(tr(1+2|4)²+tr(1+2|3)²)))")
133+
assert oPs("Δ_12|3|4|5²") == oPs("(1/4*(s12*(tr(3|3)²-tr(3|4)²)+tr(3|4)*tr(1+2|4)*tr(1+2|3)-1/2*tr(3|3)*(tr(1+2|4)²+tr(1+2|3)²)))²")

0 commit comments

Comments
 (0)