Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Trac #19306: fix error terms for low precision
Browse files Browse the repository at this point in the history
  • Loading branch information
cheuberg committed Jan 15, 2016
1 parent 31e4dc4 commit a3fad56
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/sage/rings/asymptotic/asymptotic_expansion_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,25 @@ def log_Stirling(var, precision=None, skip_constant_summand=False):
sage: _.parent()
Asymptotic Ring <n^ZZ * log(n)^ZZ> over Rational Field
sage: asymptotic_expansions.log_Stirling(
....: 'n', precision=0)
O(n*log(n))
sage: asymptotic_expansions.log_Stirling(
....: 'n', precision=1)
n*log(n) + O(n)
sage: asymptotic_expansions.log_Stirling(
....: 'n', precision=2)
n*log(n) - n + O(log(n))
sage: asymptotic_expansions.log_Stirling(
....: 'n', precision=3)
n*log(n) - n + 1/2*log(n) + O(1)
sage: asymptotic_expansions.log_Stirling(
....: 'n', precision=4)
n*log(n) - n + 1/2*log(n) + 1/2*log(2*pi) + O(n^(-1))
sage: asymptotic_expansions.log_Stirling(
....: 'n', precision=5)
n*log(n) - n + 1/2*log(n) + 1/2*log(2*pi) + 1/12*n^(-1)
+ O(n^(-3))
sage: asymptotic_expansions.log_Stirling(
....: 'm', precision=7, skip_constant_summand=True)
m*log(m) - m + 1/2*log(m) + 1/12*m^(-1) - 1/360*m^(-3) +
1/1260*m^(-5) + O(m^(-7))
Expand Down Expand Up @@ -247,7 +266,17 @@ def log_Stirling(var, precision=None, skip_constant_summand=False):
for k in srange(2, 2*precision - 6, 2):
result += bernoulli(k) / k / (k-1) / n**(k-1)

result += (1 / n**(2*precision - 7)).O()
if precision < 1:
result += (n * log(n)).O()
elif precision == 1:
result += n.O()
elif precision == 2:
result += log(n).O()
elif precision ==3:
result += A(1).O()
else:
result += (1 / n**(2*precision - 7)).O()

return result


Expand Down

0 comments on commit a3fad56

Please sign in to comment.