Skip to content

Commit

Permalink
[LoopIntegralFromPropagators] assert "a Lorentz index occurs at most …
Browse files Browse the repository at this point in the history
…twice"
  • Loading branch information
Stephan Jahn committed Aug 9, 2018
1 parent e4e1f1f commit f7244d1
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 35 deletions.
42 changes: 17 additions & 25 deletions pySecDec/loop_integral/from_propagators.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,41 +264,33 @@ def _numerator_tensors(self):
numerator_symbols)
'''
def append_double_indices(expr, lst, momenta, indices):
'''
Append the double indices of an expression of the form
``<momentum>(<index>)`` to `lst`.
Return the remaining factors.
'''
for index in indices:
index_count = 0
for i,momentum in enumerate(momenta):
for j in range(2): # should have the same index at most twice
if expr.subs(momentum(index), 0) == 0: # expression has a factor `momentum(index)`
expr /= momentum(index)
lst.append((i,index))
index_count += 1
else:
break
# should not have factors of `momentum(index)` left after the loop above
assert str(momentum(index)) not in str(expr), 'Could not parse `numerator`'
assert index_count <= 2, 'Could not parse `numerator`'
return expr

numerator_loop_tensors = []
numerator_external_tensors = []
numerator_symbols = []
for term in self.numerator_input_terms:
original_term = term
current_loop_tensor = []
current_external_tensor = []

# search for ``momentum(index)``
term = append_double_indices(term, current_loop_tensor, self.loop_momenta, self.Lorentz_indices)
term = append_double_indices(term, current_external_tensor, self.external_momenta, self.Lorentz_indices)
for index in self.Lorentz_indices:
index_count = 0
for lst,momenta in zip([current_loop_tensor,current_external_tensor],[self.loop_momenta, self.external_momenta]):
for i,momentum in enumerate(momenta):

# search for ``momentum(index)``
while term.subs(momentum(index), 0) == 0: # expression has a factor `momentum(index)`
term /= momentum(index)
lst.append((i,index))
index_count += 1

# should not have found the `index` more than twice
assert index_count <= 2, \
'A term (%s) in the `numerator` has one of the `Lorentz_indices` (%s) occurring more than twice.' % (original_term, index)

numerator_loop_tensors.append(current_loop_tensor)
numerator_external_tensors.append(current_external_tensor)
numerator_symbols.append(term)

return numerator_loop_tensors, numerator_external_tensors, numerator_symbols

@cached_property
Expand Down
57 changes: 47 additions & 10 deletions pySecDec/loop_integral/test_loop_integral.py
Original file line number Diff line number Diff line change
Expand Up @@ -908,16 +908,53 @@ def test_numerator_without_external_momenta(self):
self.assertEqual( (sp.sympify(double_tadpole.exponent_U) - target_exponent_U).simplify() , 0 )
self.assertEqual( (sp.sympify(double_tadpole.numerator) - target_numerator).simplify() , 0 )

# TODO: uncomment when implemented
# def test_error_if_index_too_often(self):
# mu, nu = sp.symbols('mu nu')
# numerator = 'k1(mu)*k2(mu)*k2(1)*k2(2)*p1(1)*p2(2)*p1(mu)'
# loop_momenta = ['k1', 'k2']
# external_momenta = ['p1', 'p2']
# propagators = [] # dummy, do not need to specify propagators for the double index notation
#
# li = LoopIntegralFromPropagators(propagators, loop_momenta, external_momenta, numerator=numerator)
# self.assertRaisesRegexp(AssertionError, '(E|e)ach.*index.*(exactly|at most).*(twice|two times)', lambda: li.numerator)
#@attr('active')
def test_error_if_index_too_often_loop_momenta(self):
li = LoopIntegralFromPropagators(
Lorentz_indices = ('mu', 1, 2),
numerator = 'k1(1)*k1(1)*k1(1) + k2(mu)*k2(2)*p1(mu)*p2(2)',
loop_momenta = ['k1', 'k2'],
external_momenta = ['p1', 'p2'],
propagators = ['(k1-p1)^2','(k2-p1-p2)^2']
)
self.assertRaisesRegexp(
AssertionError,
str(li.numerator_input.args[0]).replace('(',r'\(').replace(')','\)').replace('*',r'\*') + \
'.*Lorentz_indices.*1.*more than.*(twice|two times)',
lambda: li.numerator
)

#@attr('active')
def test_error_if_index_too_often_external_momenta(self):
li = LoopIntegralFromPropagators(
Lorentz_indices = ('mu', 1, 2),
numerator = 'p1(1)*p1(1)*p2(1) + k2(mu)*k2(2)*p1(mu)*p2(2)',
loop_momenta = ['k1', 'k2'],
external_momenta = ['p1', 'p2'],
propagators = ['(k1-p1)^2','(k2-p1-p2)^2']
)
self.assertRaisesRegexp(
AssertionError,
str(li.numerator_input.args[0]).replace('(',r'\(').replace(')','\)').replace('*',r'\*') + \
'.*Lorentz_indices.*1.*more than.*(twice|two times)',
lambda: li.numerator
)

#@attr('active')
def test_error_if_index_too_often_mixed(self):
li = LoopIntegralFromPropagators(
Lorentz_indices = ('mu', 1, 2),
numerator = 'k1(mu)*k2(mu)*k2(1)*k2(2)*p1(1)*p2(2)*p1(mu)',
loop_momenta = ['k1', 'k2'],
external_momenta = ['p1', 'p2'],
propagators = ['(k1-p1)^2','(k2-p1-p2)^2']
)
self.assertRaisesRegexp(
AssertionError,
str(li.numerator_input).replace('(',r'\(').replace(')','\)').replace('*',r'\*') + \
'.*Lorentz_indices.*mu.*more than.*(twice|two times)',
lambda: li.numerator
)


def uf_from_graph_generic(test_case, int_lines, ext_lines, result_L, result_u, result_f, rules=[]):
Expand Down

0 comments on commit f7244d1

Please sign in to comment.