From b336046c20b400eb5ecdde199f35e1eec2793a47 Mon Sep 17 00:00:00 2001 From: Clemens Heuberger Date: Wed, 17 Feb 2016 18:46:28 +0200 Subject: [PATCH 1/6] Trac #20051: introduce failing doctest --- src/sage/rings/asymptotic/asymptotic_expansion_generators.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/sage/rings/asymptotic/asymptotic_expansion_generators.py b/src/sage/rings/asymptotic/asymptotic_expansion_generators.py index 5ba8ae94294..c8418f2b6c0 100644 --- a/src/sage/rings/asymptotic/asymptotic_expansion_generators.py +++ b/src/sage/rings/asymptotic/asymptotic_expansion_generators.py @@ -942,6 +942,9 @@ def _SingularityAnalysis_non_normalized_(var, zeta=1, alpha=0, beta=0, delta=0, -1/2/sqrt(pi)*n^(-3/2)*log(n) + (-1/2*(euler_gamma + 2*log(2) - 2)/sqrt(pi))*n^(-3/2) + O(n^(-5/2)*log(n)) + sage: asymptotic_expansions._SingularityAnalysis_non_normalized_( + ....: 'n', 1/2, alpha=0, beta=1, precision=3) + 2^n * n^(-1) + O(2^n * n^(-2)) .. SEEALSO:: From 0b248671c787067b8772dd2ac577ff19ee75110f Mon Sep 17 00:00:00 2001 From: Clemens Heuberger Date: Wed, 17 Feb 2016 19:01:47 +0200 Subject: [PATCH 2/6] Trac #20051: rewrite code --- .../asymptotic_expansion_generators.py | 28 ++++++++++++------- src/sage/rings/asymptotic/growth_group.py | 2 +- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/sage/rings/asymptotic/asymptotic_expansion_generators.py b/src/sage/rings/asymptotic/asymptotic_expansion_generators.py index c8418f2b6c0..cb8e1d4cb45 100644 --- a/src/sage/rings/asymptotic/asymptotic_expansion_generators.py +++ b/src/sage/rings/asymptotic/asymptotic_expansion_generators.py @@ -582,7 +582,7 @@ def Binomial_kn_over_n(var, k, precision=None, skip_constant_factor=False): @staticmethod def SingularityAnalysis(var, zeta=1, alpha=0, beta=0, delta=0, - precision=None): + precision=None, renormalize=True): r""" Return the asymptotic expansion of the coefficients of an power series with specified pole and logarithmic singularity. @@ -612,6 +612,13 @@ def SingularityAnalysis(var, zeta=1, alpha=0, beta=0, delta=0, - ``precision`` -- (default: ``None``) an integer. If ``None``, then the default precision of the asymptotic ring is used. + - ``renormalize`` -- (default: ``True``) a boolean. If ``False``, then + the coefficient of `[z^n] \left(\frac{1}{1-z}\right)^\alpha + \left(\log \frac{1}{1-z}\right)^\beta + \left(\log + \left(\frac{1}{z} \log \frac{1}{1-z}\right)\right)^\delta` + is computed. + OUTPUT: An asymptotic expansion. @@ -835,6 +842,8 @@ def inverse_gamma_derivative(shift, r): precision = AsymptoticRing.__default_prec__ + if not renormalize and not (beta in ZZ and delta in ZZ): + raise ValueError("beta and delta must be integers") if delta != 0: raise NotImplementedError @@ -874,7 +883,11 @@ def inverse_gamma_derivative(shift, r): log_n = 1 it = reversed(list(islice(it, precision+1))) - L = _sa_coefficients_lambda_(max(1, k_max), beta=beta) + if renormalize: + beta_denominator = beta + else: + beta_denominator = 0 + L = _sa_coefficients_lambda_(max(1, k_max), beta=beta_denominator) (k, r) = next(it) result = (n**(-k) * log_n**(-r)).O() @@ -944,7 +957,7 @@ def _SingularityAnalysis_non_normalized_(var, zeta=1, alpha=0, beta=0, delta=0, + O(n^(-5/2)*log(n)) sage: asymptotic_expansions._SingularityAnalysis_non_normalized_( ....: 'n', 1/2, alpha=0, beta=1, precision=3) - 2^n * n^(-1) + O(2^n * n^(-2)) + 2^n*n^(-1) + O(2^n*n^(-2)) .. SEEALSO:: @@ -1007,13 +1020,8 @@ def _SingularityAnalysis_non_normalized_(var, zeta=1, alpha=0, beta=0, delta=0, ... ValueError: beta and delta must be integers """ - from sage.rings.integer_ring import ZZ - if not (beta in ZZ and delta in ZZ): - raise ValueError("beta and delta must be integers") - result = AsymptoticExpansionGenerators.SingularityAnalysis( - var, zeta, alpha, beta, delta, precision) - n = result.parent()(var) - return result.subs({n: n-(beta+delta)}) + return AsymptoticExpansionGenerators.SingularityAnalysis( + var, zeta, alpha, beta, delta, precision, renormalize=False) def _sa_coefficients_lambda_(K, beta=0): diff --git a/src/sage/rings/asymptotic/growth_group.py b/src/sage/rings/asymptotic/growth_group.py index ed0f718502f..3a0565ae9fc 100644 --- a/src/sage/rings/asymptotic/growth_group.py +++ b/src/sage/rings/asymptotic/growth_group.py @@ -2887,7 +2887,7 @@ def _singularity_analysis_(self, var, zeta, precision): sage: G(log(x))._singularity_analysis_('n', 1, precision=5) n^(-1) + O(n^(-3)) sage: G(log(x)^2)._singularity_analysis_('n', 2, precision=3) - 8*(1/2)^n*n^(-1)*log(n) + 8*euler_gamma*(1/2)^n*n^(-1) + 2*(1/2)^n*n^(-1)*log(n) + 2*euler_gamma*(1/2)^n*n^(-1) + O((1/2)^n*n^(-2)*log(n)^2) TESTS:: From 9ef4c0509d6cddbe33e6ecfc1f2c795b1ec48478 Mon Sep 17 00:00:00 2001 From: Clemens Heuberger Date: Wed, 17 Feb 2016 19:02:26 +0200 Subject: [PATCH 3/6] Trac #20051: better error for delta != 0 --- .../rings/asymptotic/asymptotic_expansion_generators.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/sage/rings/asymptotic/asymptotic_expansion_generators.py b/src/sage/rings/asymptotic/asymptotic_expansion_generators.py index cb8e1d4cb45..e487c9addb3 100644 --- a/src/sage/rings/asymptotic/asymptotic_expansion_generators.py +++ b/src/sage/rings/asymptotic/asymptotic_expansion_generators.py @@ -787,6 +787,13 @@ def SingularityAnalysis(var, zeta=1, alpha=0, beta=0, delta=0, ....: 'n', alpha=1/2, zeta=2, precision=3) 1/sqrt(pi)*(1/2)^n*n^(-1/2) - 1/8/sqrt(pi)*(1/2)^n*n^(-3/2) + 1/128/sqrt(pi)*(1/2)^n*n^(-5/2) + O((1/2)^n*n^(-7/2)) + + :: + sage: asymptotic_expansions.SingularityAnalysis( + ....: 'n', alpha=0, beta=0, delta=1, precision=3) + Traceback (most recent call last): + ... + NotImplementedError: not implemented for delta!=0 """ from itertools import islice, count from asymptotic_ring import AsymptoticRing @@ -845,7 +852,7 @@ def inverse_gamma_derivative(shift, r): if not renormalize and not (beta in ZZ and delta in ZZ): raise ValueError("beta and delta must be integers") if delta != 0: - raise NotImplementedError + raise NotImplementedError("not implemented for delta!=0") groups = [] if zeta != 1: From 142b61f173b8e96d152c473a943bd5945d8a7a6b Mon Sep 17 00:00:00 2001 From: Clemens Heuberger Date: Wed, 17 Feb 2016 19:15:51 +0200 Subject: [PATCH 4/6] Trac #20051: remove method _SingularityAnalysis_non_normalized_ --- .../asymptotic_expansion_generators.py | 190 +++++++----------- src/sage/rings/asymptotic/growth_group.py | 4 +- .../asymptotic/growth_group_cartesian.py | 4 +- 3 files changed, 81 insertions(+), 117 deletions(-) diff --git a/src/sage/rings/asymptotic/asymptotic_expansion_generators.py b/src/sage/rings/asymptotic/asymptotic_expansion_generators.py index e487c9addb3..6691afe6ee9 100644 --- a/src/sage/rings/asymptotic/asymptotic_expansion_generators.py +++ b/src/sage/rings/asymptotic/asymptotic_expansion_generators.py @@ -705,6 +705,18 @@ def SingularityAnalysis(var, zeta=1, alpha=0, beta=0, delta=0, sage: ae.subs(n=n-2) 2*n^(-1)*log(n) + 2*euler_gamma*n^(-1) - n^(-2) - 1/6*n^(-3) + O(n^(-5)) + :: + + sage: asymptotic_expansions.SingularityAnalysis( + ....: 'n', 1, alpha=-1/2, beta=1, precision=2, renormalize=False) + -1/2/sqrt(pi)*n^(-3/2)*log(n) + + (-1/2*(euler_gamma + 2*log(2) - 2)/sqrt(pi))*n^(-3/2) + + O(n^(-5/2)*log(n)) + sage: asymptotic_expansions.SingularityAnalysis( + ....: 'n', 1/2, alpha=0, beta=1, precision=3, renormalize=False) + 2^n*n^(-1) + O(2^n*n^(-2)) + + ALGORITHM: See [FS2009]_ together with the @@ -788,7 +800,72 @@ def SingularityAnalysis(var, zeta=1, alpha=0, beta=0, delta=0, 1/sqrt(pi)*(1/2)^n*n^(-1/2) - 1/8/sqrt(pi)*(1/2)^n*n^(-3/2) + 1/128/sqrt(pi)*(1/2)^n*n^(-5/2) + O((1/2)^n*n^(-7/2)) + The following tests correspond to Table VI.5 in [FS2009]_. :: + + sage: A. = AsymptoticRing('n^QQ * log(n)^QQ', QQ) + sage: asymptotic_expansions.SingularityAnalysis( + ....: 'n', 1, alpha=-1/2, beta=1, precision=2, + ....: renormalize=False) * (- sqrt(pi*n^3)) + 1/2*log(n) + 1/2*euler_gamma + log(2) - 1 + O(n^(-1)*log(n)) + sage: asymptotic_expansions.SingularityAnalysis( + ....: 'n', 1, alpha=0, beta=1, precision=3, + ....: renormalize=False) + n^(-1) + O(n^(-2)) + sage: asymptotic_expansions.SingularityAnalysis( + ....: 'n', 1, alpha=0, beta=2, precision=14, + ....: renormalize=False) * n + 2*log(n) + 2*euler_gamma - n^(-1) - 1/6*n^(-2) + O(n^(-4)) + sage: (asymptotic_expansions.SingularityAnalysis( + ....: 'n', 1, alpha=1/2, beta=1, precision=4, + ....: renormalize=False) * sqrt(pi*n)).\ + ....: map_coefficients(lambda x: x.expand()) + log(n) + euler_gamma + 2*log(2) - 1/8*n^(-1)*log(n) + + (-1/8*euler_gamma - 1/4*log(2))*n^(-1) + O(n^(-2)*log(n)) + sage: asymptotic_expansions.SingularityAnalysis( + ....: 'n', 1, alpha=1, beta=1, precision=13, + ....: renormalize=False) + log(n) + euler_gamma + 1/2*n^(-1) - 1/12*n^(-2) + 1/120*n^(-4) + + O(n^(-6)) + sage: asymptotic_expansions.SingularityAnalysis( + ....: 'n', 1, alpha=1, beta=2, precision=4, + ....: renormalize=False) + log(n)^2 + 2*euler_gamma*log(n) + euler_gamma^2 - 1/6*pi^2 + + O(n^(-1)*log(n)) + sage: asymptotic_expansions.SingularityAnalysis( + ....: 'n', 1, alpha=3/2, beta=1, precision=3, + ....: renormalize=False) * sqrt(pi/n) + 2*log(n) + 2*euler_gamma + 4*log(2) - 4 + 3/4*n^(-1)*log(n) + + O(n^(-1)) + sage: asymptotic_expansions.SingularityAnalysis( + ....: 'n', 1, alpha=2, beta=1, precision=5, + ....: renormalize=False) + n*log(n) + (euler_gamma - 1)*n + log(n) + euler_gamma + 1/2 + + O(n^(-1)) + sage: asymptotic_expansions.SingularityAnalysis( + ....: 'n', 1, alpha=2, beta=2, precision=4, + ....: renormalize=False) / n + log(n)^2 + (2*euler_gamma - 2)*log(n) + - 2*euler_gamma + euler_gamma^2 - 1/6*pi^2 + 2 + + n^(-1)*log(n)^2 + O(n^(-1)*log(n)) + + Be aware that the last result does *not* coincide with [FS2009]_, + they do have a different error term. + + Checking parameters:: + + sage: asymptotic_expansions.SingularityAnalysis( + ....: 'n', 1, 1, 1/2, precision=0, renormalize=False) + Traceback (most recent call last): + ... + ValueError: beta and delta must be integers + sage: asymptotic_expansions.SingularityAnalysis( + ....: 'n', 1, 1, 1, 1/2, renormalize=False) + Traceback (most recent call last): + ... + ValueError: beta and delta must be integers + :: + sage: asymptotic_expansions.SingularityAnalysis( ....: 'n', alpha=0, beta=0, delta=1, precision=3) Traceback (most recent call last): @@ -918,119 +995,6 @@ def inverse_gamma_derivative(shift, r): return result - @staticmethod - def _SingularityAnalysis_non_normalized_(var, zeta=1, alpha=0, beta=0, delta=0, - precision=None): - r""" - Return the asymptotic expansion of the coefficients of - an power series with specified pole and logarithmic singularity - (without normalization). - - More precisely, this extracts the `n`-th coefficient - - .. MATH:: - - [z^n] \left(\frac{1}{1-z}\right)^\alpha - \left( \log \frac{1}{1-z}\right)^\beta - \left( \log - \left(\frac{1}{z} \log \frac{1}{1-z}\right)\right)^\delta. - - INPUT: - - - ``var`` -- a string for the variable name. - - - ``zeta`` -- (default: `1`) the location of the singularity. - - - ``alpha`` -- (default: `0`) the pole order of the singularty. - - - ``beta`` -- an integer (default: `0`): the order of the logarithmic singularity. - - - ``delta`` -- an integer (default: `0`): the order of the log-log singularity. - Not yet implemented for ``delta != 0``. - - - ``precision`` -- (default: ``None``) an integer. If ``None``, then - the default precision of the asymptotic ring is used. - - OUTPUT: - - An asymptotic expansion. - - EXAMPLES:: - - sage: asymptotic_expansions._SingularityAnalysis_non_normalized_( - ....: 'n', 1, alpha=-1/2, beta=1, precision=2) - -1/2/sqrt(pi)*n^(-3/2)*log(n) - + (-1/2*(euler_gamma + 2*log(2) - 2)/sqrt(pi))*n^(-3/2) - + O(n^(-5/2)*log(n)) - sage: asymptotic_expansions._SingularityAnalysis_non_normalized_( - ....: 'n', 1/2, alpha=0, beta=1, precision=3) - 2^n*n^(-1) + O(2^n*n^(-2)) - - .. SEEALSO:: - - :meth:`SingularityAnalysis` - - TESTS: - - The following tests correspond to Table VI.5 in [FS2009]_. :: - - sage: A. = AsymptoticRing('n^QQ * log(n)^QQ', QQ) - sage: asymptotic_expansions._SingularityAnalysis_non_normalized_( - ....: 'n', 1, alpha=-1/2, beta=1, precision=2) * (- sqrt(pi*n^3)) - 1/2*log(n) + 1/2*euler_gamma + log(2) - 1 + O(n^(-1)*log(n)) - sage: asymptotic_expansions._SingularityAnalysis_non_normalized_( - ....: 'n', 1, alpha=0, beta=1, precision=3) - n^(-1) + O(n^(-2)) - sage: asymptotic_expansions._SingularityAnalysis_non_normalized_( - ....: 'n', 1, alpha=0, beta=2, precision=14) * n - 2*log(n) + 2*euler_gamma - n^(-1) - 1/6*n^(-2) + O(n^(-4)) - sage: (asymptotic_expansions._SingularityAnalysis_non_normalized_( - ....: 'n', 1, alpha=1/2, beta=1, precision=4) * sqrt(pi*n)).\ - ....: map_coefficients(lambda x: x.expand()) - log(n) + euler_gamma + 2*log(2) - 1/8*n^(-1)*log(n) + - (-1/8*euler_gamma - 1/4*log(2))*n^(-1) + O(n^(-2)*log(n)) - sage: asymptotic_expansions._SingularityAnalysis_non_normalized_( - ....: 'n', 1, alpha=1, beta=1, precision=13) - log(n) + euler_gamma + 1/2*n^(-1) - 1/12*n^(-2) + 1/120*n^(-4) - + O(n^(-6)) - sage: asymptotic_expansions._SingularityAnalysis_non_normalized_( - ....: 'n', 1, alpha=1, beta=2, precision=4) - log(n)^2 + 2*euler_gamma*log(n) + euler_gamma^2 - 1/6*pi^2 - + O(n^(-1)*log(n)) - sage: asymptotic_expansions._SingularityAnalysis_non_normalized_( - ....: 'n', 1, alpha=3/2, beta=1, precision=3) * sqrt(pi/n) - 2*log(n) + 2*euler_gamma + 4*log(2) - 4 + 3/4*n^(-1)*log(n) - + O(n^(-1)) - sage: asymptotic_expansions._SingularityAnalysis_non_normalized_( - ....: 'n', 1, alpha=2, beta=1, precision=5) - n*log(n) + (euler_gamma - 1)*n + log(n) + euler_gamma + 1/2 - + O(n^(-1)) - sage: asymptotic_expansions._SingularityAnalysis_non_normalized_( - ....: 'n', 1, alpha=2, beta=2, precision=4) / n - log(n)^2 + (2*euler_gamma - 2)*log(n) - - 2*euler_gamma + euler_gamma^2 - 1/6*pi^2 + 2 - + n^(-1)*log(n)^2 + O(n^(-1)*log(n)) - - Be aware that the last result does *not* coincide with [FS2009]_, - they do have a different error term. - - Checking parameters:: - - sage: asymptotic_expansions._SingularityAnalysis_non_normalized_( - ....: 'n', 1, 1, 1/2, 0) - Traceback (most recent call last): - ... - ValueError: beta and delta must be integers - sage: asymptotic_expansions._SingularityAnalysis_non_normalized_( - ....: 'n', 1, 1, 1, 1/2) - Traceback (most recent call last): - ... - ValueError: beta and delta must be integers - """ - return AsymptoticExpansionGenerators.SingularityAnalysis( - var, zeta, alpha, beta, delta, precision, renormalize=False) - - def _sa_coefficients_lambda_(K, beta=0): r""" Return the coefficients `\lambda_{k, \ell}(\beta)` used in singularity analysis. diff --git a/src/sage/rings/asymptotic/growth_group.py b/src/sage/rings/asymptotic/growth_group.py index 3a0565ae9fc..a1ea7830b58 100644 --- a/src/sage/rings/asymptotic/growth_group.py +++ b/src/sage/rings/asymptotic/growth_group.py @@ -2920,9 +2920,9 @@ def _singularity_analysis_(self, var, zeta, precision): self, self.exponent)) from sage.rings.asymptotic.asymptotic_expansion_generators import \ asymptotic_expansions - return asymptotic_expansions._SingularityAnalysis_non_normalized_( + return asymptotic_expansions.SingularityAnalysis( var=var, zeta=zeta, alpha=0, beta=ZZ(self.exponent), delta=0, - precision=precision) + precision=precision, renormalize=False) else: raise NotImplementedError( 'singularity analysis of {} not implemented'.format(self)) diff --git a/src/sage/rings/asymptotic/growth_group_cartesian.py b/src/sage/rings/asymptotic/growth_group_cartesian.py index e0e2960a08a..57869531ae6 100644 --- a/src/sage/rings/asymptotic/growth_group_cartesian.py +++ b/src/sage/rings/asymptotic/growth_group_cartesian.py @@ -1272,10 +1272,10 @@ def _singularity_analysis_(self, var, zeta, precision): from sage.rings.asymptotic.asymptotic_expansion_generators import \ asymptotic_expansions - return asymptotic_expansions._SingularityAnalysis_non_normalized_( + return asymptotic_expansions.SingularityAnalysis( var=var, zeta=zeta, alpha=a.exponent, beta=ZZ(b.exponent), delta=0, - precision=precision) + precision=precision, renormalize=False) else: raise NotImplementedError( 'singularity analysis of {} not implemented'.format(self)) From 4f32094ab2f8178738eca5049580e82dcd0d1900 Mon Sep 17 00:00:00 2001 From: Clemens Heuberger Date: Wed, 17 Feb 2016 19:24:20 +0200 Subject: [PATCH 5/6] Trac #20051: rename 'renormalize' to 'normalized' --- .../asymptotic_expansion_generators.py | 34 +++++++++---------- src/sage/rings/asymptotic/growth_group.py | 2 +- .../asymptotic/growth_group_cartesian.py | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/sage/rings/asymptotic/asymptotic_expansion_generators.py b/src/sage/rings/asymptotic/asymptotic_expansion_generators.py index 6691afe6ee9..c89d3c5d711 100644 --- a/src/sage/rings/asymptotic/asymptotic_expansion_generators.py +++ b/src/sage/rings/asymptotic/asymptotic_expansion_generators.py @@ -582,7 +582,7 @@ def Binomial_kn_over_n(var, k, precision=None, skip_constant_factor=False): @staticmethod def SingularityAnalysis(var, zeta=1, alpha=0, beta=0, delta=0, - precision=None, renormalize=True): + precision=None, normalized=True): r""" Return the asymptotic expansion of the coefficients of an power series with specified pole and logarithmic singularity. @@ -612,7 +612,7 @@ def SingularityAnalysis(var, zeta=1, alpha=0, beta=0, delta=0, - ``precision`` -- (default: ``None``) an integer. If ``None``, then the default precision of the asymptotic ring is used. - - ``renormalize`` -- (default: ``True``) a boolean. If ``False``, then + - ``normalized`` -- (default: ``True``) a boolean. If ``False``, then the coefficient of `[z^n] \left(\frac{1}{1-z}\right)^\alpha \left(\log \frac{1}{1-z}\right)^\beta \left(\log @@ -708,12 +708,12 @@ def SingularityAnalysis(var, zeta=1, alpha=0, beta=0, delta=0, :: sage: asymptotic_expansions.SingularityAnalysis( - ....: 'n', 1, alpha=-1/2, beta=1, precision=2, renormalize=False) + ....: 'n', 1, alpha=-1/2, beta=1, precision=2, normalized=False) -1/2/sqrt(pi)*n^(-3/2)*log(n) + (-1/2*(euler_gamma + 2*log(2) - 2)/sqrt(pi))*n^(-3/2) + O(n^(-5/2)*log(n)) sage: asymptotic_expansions.SingularityAnalysis( - ....: 'n', 1/2, alpha=0, beta=1, precision=3, renormalize=False) + ....: 'n', 1/2, alpha=0, beta=1, precision=3, normalized=False) 2^n*n^(-1) + O(2^n*n^(-2)) @@ -805,45 +805,45 @@ def SingularityAnalysis(var, zeta=1, alpha=0, beta=0, delta=0, sage: A. = AsymptoticRing('n^QQ * log(n)^QQ', QQ) sage: asymptotic_expansions.SingularityAnalysis( ....: 'n', 1, alpha=-1/2, beta=1, precision=2, - ....: renormalize=False) * (- sqrt(pi*n^3)) + ....: normalized=False) * (- sqrt(pi*n^3)) 1/2*log(n) + 1/2*euler_gamma + log(2) - 1 + O(n^(-1)*log(n)) sage: asymptotic_expansions.SingularityAnalysis( ....: 'n', 1, alpha=0, beta=1, precision=3, - ....: renormalize=False) + ....: normalized=False) n^(-1) + O(n^(-2)) sage: asymptotic_expansions.SingularityAnalysis( ....: 'n', 1, alpha=0, beta=2, precision=14, - ....: renormalize=False) * n + ....: normalized=False) * n 2*log(n) + 2*euler_gamma - n^(-1) - 1/6*n^(-2) + O(n^(-4)) sage: (asymptotic_expansions.SingularityAnalysis( ....: 'n', 1, alpha=1/2, beta=1, precision=4, - ....: renormalize=False) * sqrt(pi*n)).\ + ....: normalized=False) * sqrt(pi*n)).\ ....: map_coefficients(lambda x: x.expand()) log(n) + euler_gamma + 2*log(2) - 1/8*n^(-1)*log(n) + (-1/8*euler_gamma - 1/4*log(2))*n^(-1) + O(n^(-2)*log(n)) sage: asymptotic_expansions.SingularityAnalysis( ....: 'n', 1, alpha=1, beta=1, precision=13, - ....: renormalize=False) + ....: normalized=False) log(n) + euler_gamma + 1/2*n^(-1) - 1/12*n^(-2) + 1/120*n^(-4) + O(n^(-6)) sage: asymptotic_expansions.SingularityAnalysis( ....: 'n', 1, alpha=1, beta=2, precision=4, - ....: renormalize=False) + ....: normalized=False) log(n)^2 + 2*euler_gamma*log(n) + euler_gamma^2 - 1/6*pi^2 + O(n^(-1)*log(n)) sage: asymptotic_expansions.SingularityAnalysis( ....: 'n', 1, alpha=3/2, beta=1, precision=3, - ....: renormalize=False) * sqrt(pi/n) + ....: normalized=False) * sqrt(pi/n) 2*log(n) + 2*euler_gamma + 4*log(2) - 4 + 3/4*n^(-1)*log(n) + O(n^(-1)) sage: asymptotic_expansions.SingularityAnalysis( ....: 'n', 1, alpha=2, beta=1, precision=5, - ....: renormalize=False) + ....: normalized=False) n*log(n) + (euler_gamma - 1)*n + log(n) + euler_gamma + 1/2 + O(n^(-1)) sage: asymptotic_expansions.SingularityAnalysis( ....: 'n', 1, alpha=2, beta=2, precision=4, - ....: renormalize=False) / n + ....: normalized=False) / n log(n)^2 + (2*euler_gamma - 2)*log(n) - 2*euler_gamma + euler_gamma^2 - 1/6*pi^2 + 2 + n^(-1)*log(n)^2 + O(n^(-1)*log(n)) @@ -854,12 +854,12 @@ def SingularityAnalysis(var, zeta=1, alpha=0, beta=0, delta=0, Checking parameters:: sage: asymptotic_expansions.SingularityAnalysis( - ....: 'n', 1, 1, 1/2, precision=0, renormalize=False) + ....: 'n', 1, 1, 1/2, precision=0, normalized=False) Traceback (most recent call last): ... ValueError: beta and delta must be integers sage: asymptotic_expansions.SingularityAnalysis( - ....: 'n', 1, 1, 1, 1/2, renormalize=False) + ....: 'n', 1, 1, 1, 1/2, normalized=False) Traceback (most recent call last): ... ValueError: beta and delta must be integers @@ -926,7 +926,7 @@ def inverse_gamma_derivative(shift, r): precision = AsymptoticRing.__default_prec__ - if not renormalize and not (beta in ZZ and delta in ZZ): + if not normalized and not (beta in ZZ and delta in ZZ): raise ValueError("beta and delta must be integers") if delta != 0: raise NotImplementedError("not implemented for delta!=0") @@ -967,7 +967,7 @@ def inverse_gamma_derivative(shift, r): log_n = 1 it = reversed(list(islice(it, precision+1))) - if renormalize: + if normalized: beta_denominator = beta else: beta_denominator = 0 diff --git a/src/sage/rings/asymptotic/growth_group.py b/src/sage/rings/asymptotic/growth_group.py index a1ea7830b58..f98a33c1b13 100644 --- a/src/sage/rings/asymptotic/growth_group.py +++ b/src/sage/rings/asymptotic/growth_group.py @@ -2922,7 +2922,7 @@ def _singularity_analysis_(self, var, zeta, precision): asymptotic_expansions return asymptotic_expansions.SingularityAnalysis( var=var, zeta=zeta, alpha=0, beta=ZZ(self.exponent), delta=0, - precision=precision, renormalize=False) + precision=precision, normalized=False) else: raise NotImplementedError( 'singularity analysis of {} not implemented'.format(self)) diff --git a/src/sage/rings/asymptotic/growth_group_cartesian.py b/src/sage/rings/asymptotic/growth_group_cartesian.py index 57869531ae6..2a70a7a7bd5 100644 --- a/src/sage/rings/asymptotic/growth_group_cartesian.py +++ b/src/sage/rings/asymptotic/growth_group_cartesian.py @@ -1275,7 +1275,7 @@ def _singularity_analysis_(self, var, zeta, precision): return asymptotic_expansions.SingularityAnalysis( var=var, zeta=zeta, alpha=a.exponent, beta=ZZ(b.exponent), delta=0, - precision=precision, renormalize=False) + precision=precision, normalized=False) else: raise NotImplementedError( 'singularity analysis of {} not implemented'.format(self)) From c80933da15af6a60fa2b1e6cef7f92f755dded01 Mon Sep 17 00:00:00 2001 From: Clemens Heuberger Date: Thu, 18 Feb 2016 10:37:07 +0200 Subject: [PATCH 6/6] Trac #20051: move formula for normalized --- .../asymptotic_expansion_generators.py | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/sage/rings/asymptotic/asymptotic_expansion_generators.py b/src/sage/rings/asymptotic/asymptotic_expansion_generators.py index c89d3c5d711..9f9d4d7a121 100644 --- a/src/sage/rings/asymptotic/asymptotic_expansion_generators.py +++ b/src/sage/rings/asymptotic/asymptotic_expansion_generators.py @@ -594,7 +594,18 @@ def SingularityAnalysis(var, zeta=1, alpha=0, beta=0, delta=0, [z^n] \left(\frac{1}{1-z}\right)^\alpha \left(\frac{1}{z} \log \frac{1}{1-z}\right)^\beta \left(\frac{1}{z} \log - \left(\frac{1}{z} \log \frac{1}{1-z}\right)\right)^\delta. + \left(\frac{1}{z} \log \frac{1}{1-z}\right)\right)^\delta + + (if ``normalized=True``, the default) or + + .. MATH:: + + [z^n] \left(\frac{1}{1-z}\right)^\alpha + \left(\log \frac{1}{1-z}\right)^\beta + \left(\log + \left(\frac{1}{z} \log \frac{1}{1-z}\right)\right)^\delta + + (if ``normalized=False``). INPUT: @@ -612,12 +623,7 @@ def SingularityAnalysis(var, zeta=1, alpha=0, beta=0, delta=0, - ``precision`` -- (default: ``None``) an integer. If ``None``, then the default precision of the asymptotic ring is used. - - ``normalized`` -- (default: ``True``) a boolean. If ``False``, then - the coefficient of `[z^n] \left(\frac{1}{1-z}\right)^\alpha - \left(\log \frac{1}{1-z}\right)^\beta - \left(\log - \left(\frac{1}{z} \log \frac{1}{1-z}\right)\right)^\delta` - is computed. + - ``normalized`` -- (default: ``True``) a boolean, see above. OUTPUT: