From e93ce464932caf42c0c3a95c7dc525f951ffabd9 Mon Sep 17 00:00:00 2001 From: Daniel Krenn Date: Wed, 4 Nov 2015 15:23:59 -0500 Subject: [PATCH] simplify coefficients automatically and use the faster algorithm per default --- .../asymptotic_expansion_generators.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/sage/rings/asymptotic/asymptotic_expansion_generators.py b/src/sage/rings/asymptotic/asymptotic_expansion_generators.py index 5e707821c5b..c0ccd4ced88 100644 --- a/src/sage/rings/asymptotic/asymptotic_expansion_generators.py +++ b/src/sage/rings/asymptotic/asymptotic_expansion_generators.py @@ -273,14 +273,17 @@ def Binomial_kn_over_n(var, k, precision=None, skip_constant_factor=False, TESTS:: - sage: asymptotic_expansions.Binomial_kn_over_n( - ....: 'n', k=2, precision=5, algorithm='log') - sage: asymptotic_expansions.Binomial_kn_over_n( - ....: 'n', k=3, precision=5, algorithm='log') - + sage: all( # long time + ....: asymptotic_expansions.Binomial_kn_over_n('n', k=k, + ....: precision=5, algorithm='direct').has_same_summands( + ....: asymptotic_expansions.Binomial_kn_over_n('n', k=k, + ....: precision=5, algorithm='log')) + ....: for k in (2, 4)) + True """ if algorithm is None: - algorithm = 'direct' + algorithm = 'log' # 'log' seems to be faster, so we use it + # as a default. from sage.symbolic.ring import SR SCR = SR.subring(no_variables=True) @@ -315,7 +318,8 @@ def Binomial_kn_over_n(var, k, precision=None, skip_constant_factor=False, if not skip_constant_factor: result /= (2*SCR('pi')).sqrt() - return result + return result.map_coefficients( + lambda c: c.canonicalize_radical()) else: raise ValueError('Unknown algorithm %s.' % (algorithm,))