def asymptotic_simplify_term(term, x): """ Recursively drop additive terms which are dominated asymptotically by other terms. :param term: term to process :param x: variable going to infinity :returns: a simpler term with the same asymptotic behaviour .. note:: This should be replaced by Sage's asymptotic ring. """ from sage.symbolic.operators import add_vararg, mul_vararg if term.operator() == add_vararg: ret = [] for op1 in term.operands(): for op2 in term.operands(): # akward notation to make limit(foo, kappa=infinity) work if limit(abs(op1)/abs(op2), **{str(x):Infinity}) < 1: break else: ret.append(asymptotic_simplify_term(op1, x)) ret = add_vararg(*ret) elif term.operator() == mul_vararg: ret = mul_vararg(*[asymptotic_simplify_term(op, x) for op in term.operands()]) else: ret = term return ret
def asymptotic_simplify_term(term, x): """ Recursively drop additive terms which are dominated asymptotically by other terms. :param term: term to process :param x: variable going to infinity :returns: a simpler term with the same asymptotic behaviour .. note:: This should be replaced by Sage's asymptotic ring. """ from sage.symbolic.operators import add_vararg, mul_vararg if term.operator() == add_vararg: ret = [] for op1 in term.operands(): for op2 in term.operands(): # akward notation to make limit(foo, kappa=infinity) work if limit(abs(op1) / abs(op2), **{str(x): Infinity}) < 1: break else: ret.append(asymptotic_simplify_term(op1, x)) ret = add_vararg(*ret) elif term.operator() == mul_vararg: ret = mul_vararg( *[asymptotic_simplify_term(op, x) for op in term.operands()]) else: ret = term return ret
def _substitute_(self, rules): r""" Substitute the given ``rules`` in this Cartesian product growth element. INPUT: - ``rules`` -- a dictionary. The neutral element of the group is replaced by the value to key ``'_one_'``. OUTPUT: An object. TESTS:: sage: from sage.rings.asymptotic.growth_group import GrowthGroup sage: G = GrowthGroup('x^QQ * log(x)^QQ') sage: G(x^3 * log(x)^5)._substitute_({'x': SR.var('z')}) z^3*log(z)^5 sage: _.parent() Symbolic Ring sage: G(x^3 * log(x)^5)._substitute_({'x': 2.2}) # rel tol 1e-6 3.24458458945 sage: _.parent() Real Field with 53 bits of precision sage: G(1 / x)._substitute_({'x': 0}) Traceback (most recent call last): ... ZeroDivisionError: Cannot substitute in x^(-1) in Growth Group x^QQ * log(x)^QQ. > *previous* ZeroDivisionError: Cannot substitute in x^(-1) in Growth Group x^QQ. >> *previous* ZeroDivisionError: rational division by zero sage: G(1)._substitute_({'_one_': 'one'}) 'one' """ if self.is_one(): return rules["_one_"] from sage.symbolic.operators import mul_vararg try: return mul_vararg(*tuple(x._substitute_(rules) for x in self.cartesian_factors())) except (ArithmeticError, TypeError, ValueError) as e: from misc import substitute_raise_exception substitute_raise_exception(self, e)
def _substitute_(self, rules): r""" Substitute the given ``rules`` in this Cartesian product growth element. INPUT: - ``rules`` -- a dictionary. The neutral element of the group is replaced by the value to key ``'_one_'``. OUTPUT: An object. TESTS:: sage: from sage.rings.asymptotic.growth_group import GrowthGroup sage: G = GrowthGroup('x^QQ * log(x)^QQ') sage: G(x^3 * log(x)^5)._substitute_({'x': SR.var('z')}) z^3*log(z)^5 sage: _.parent() Symbolic Ring sage: G(x^3 * log(x)^5)._substitute_({'x': 2.2}) # rel tol 1e-6 3.24458458945 sage: _.parent() Real Field with 53 bits of precision sage: G(1 / x)._substitute_({'x': 0}) Traceback (most recent call last): ... ZeroDivisionError: Cannot substitute in x^(-1) in Growth Group x^QQ * log(x)^QQ. > *previous* ZeroDivisionError: Cannot substitute in x^(-1) in Growth Group x^QQ. >> *previous* ZeroDivisionError: rational division by zero sage: G(1)._substitute_({'_one_': 'one'}) 'one' """ if self.is_one(): return rules['_one_'] from sage.symbolic.operators import mul_vararg try: return mul_vararg( *tuple(x._substitute_(rules) for x in self.cartesian_factors())) except (ArithmeticError, TypeError, ValueError) as e: from .misc import substitute_raise_exception substitute_raise_exception(self, e)