Skip to content

Commit

Permalink
[expansion] fix expand_sympy if x-expansion starts lower than `…
Browse files Browse the repository at this point in the history
…`1/x``
  • Loading branch information
Stephan Jahn committed May 7, 2018
1 parent 3a7ea5a commit e84343b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pySecDec/expansion.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,10 @@ def recursion(expression, variables, orders, index):
# all higher orders are exactly zero
truncated = False
break
current_term_order = sp.poly(next_term, variable).monoms()[0][0]
try:
current_term_order = sp.poly(next_term, variable).monoms()[0][0]
except sp.PolynomialError:
current_term_order = -sp.poly(next_term**-1, variable).monoms()[0][0]
# if some intermediate orders are zero, append zeros to the expansion
while current_order < current_term_order and current_order <= order:
coeffs.append(_sympy_zero)
Expand Down
24 changes: 24 additions & 0 deletions pySecDec/test_expansion.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,27 @@ def test_missing_intermediate_order(self):

for coeff in expansion.coeffs:
self.assertTrue(isinstance(coeff, sp.Expr))

#@attr('active')
def test_higher_pole(self):
expression = 'gamma(eps)/eps'
variables = ['eps']

expansion = expand_sympy(expression, variables, orders=[0])

target_expansion_expolist = np.arange(3).reshape([3,1]) - 2
target_expansion_coeffs = [
'1', # eps ** -2
'-EulerGamma', # eps ** -1
'EulerGamma**2/2 + pi**2/12' # eps ** 0
]
target_expansion = Polynomial(target_expansion_expolist, target_expansion_coeffs, ['eps'])

self.assertEqual( sp.sympify(expansion - target_expansion).simplify() , 0 )

np.testing.assert_array_equal(expansion.expolist, target_expansion.expolist)
np.testing.assert_array_equal(expansion.coeffs, target_expansion.coeffs)
self.assertTrue(expansion.truncated is True)

for coeff in expansion.coeffs:
self.assertTrue(isinstance(coeff, sp.Expr))

0 comments on commit e84343b

Please sign in to comment.