Skip to content

Commit

Permalink
Trac #19436: fixup of 19431: convert asymptotic expansion to the symb…
Browse files Browse the repository at this point in the history
…olic ring

#19431 changed `SymbolicRing._element_constructor_` which was not
needed. A method `_symbolic_` suffices in the !AsymptoticRing. An
additional parameter `R` in `.symbolic_expression` will be needed to
make it work.

URL: http://trac.sagemath.org/19436
Reported by: dkrenn
Ticket author(s): Daniel Krenn
Reviewer(s): Clemens Heuberger
  • Loading branch information
Release Manager authored and vbraun committed Oct 24, 2015
2 parents 6889b9e + ee52932 commit a016066
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 18 deletions.
33 changes: 27 additions & 6 deletions src/sage/rings/asymptotic/asymptotic_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -2032,10 +2032,16 @@ def _substitute_(self, rules):
substitute_raise_exception(self, e)


def symbolic_expression(self):
def symbolic_expression(self, R=None):
r"""
Return this asymptotic expansion as a symbolic expression.
INPUT:
- ``R`` -- (a subring of) the symbolic ring or ``None``.
The output is will be an element of ``R``. If ``None``,
then the symbolic ring is used.
OUTPUT:
A symbolic expression.
Expand All @@ -2057,11 +2063,26 @@ def symbolic_expression(self):
Order((1/2)^z*x*sqrt(y)*sqrt(z)*sqrt(log(y)))
sage: _.parent()
Symbolic Ring
::
sage: from sage.symbolic.ring import SymbolicRing
sage: class MySymbolicRing(SymbolicRing):
....: pass
sage: mySR = MySymbolicRing()
sage: a.symbolic_expression(mySR).parent() is mySR
True
"""
from sage.symbolic.ring import SR
return self.substitute(dict((g, SR.var(str(g)))
if R is None:
from sage.symbolic.ring import SR
R = SR

return self.substitute(dict((g, R(R.var(str(g))))
for g in self.parent().gens()),
domain=SR)
domain=R)


_symbolic_ = symbolic_expression # will be used by SR._element_constructor_


class AsymptoticRing(Algebra, UniqueRepresentation):
Expand Down Expand Up @@ -2641,12 +2662,12 @@ def _element_constructor_(self, data, simplify=True, convert=True):
return self.create_summand('exact', data)

from misc import combine_exceptions
from sage.symbolic.ring import SR
from sage.symbolic.ring import SymbolicRing
from sage.rings.polynomial.polynomial_ring import is_PolynomialRing
from sage.rings.polynomial.multi_polynomial_ring_generic import is_MPolynomialRing
from sage.rings.power_series_ring import is_PowerSeriesRing

if P is SR:
if isinstance(P, SymbolicRing):
from sage.symbolic.operators import add_vararg
if data.operator() == add_vararg:
summands = []
Expand Down
12 changes: 6 additions & 6 deletions src/sage/rings/asymptotic/growth_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -3014,13 +3014,13 @@ def _convert_(self, data):
from sage.symbolic.ring import SR
return self._convert_(SR(data))

from sage.symbolic.ring import SR
from sage.symbolic.ring import SymbolicRing
from sage.rings.polynomial.polynomial_ring import PolynomialRing_general
from sage.rings.polynomial.multi_polynomial_ring_generic import \
MPolynomialRing_generic
from sage.rings.power_series_ring import PowerSeriesRing_generic
import operator
if P is SR:
if isinstance(P, SymbolicRing):
if data.operator() == operator.pow:
base, exponent = data.operands()
if str(base) == var:
Expand Down Expand Up @@ -3636,25 +3636,25 @@ def _convert_(self, data):
else:
return # end of parsing

from sage.symbolic.ring import SR
from sage.symbolic.ring import SymbolicRing
import operator
from sage.symbolic.operators import mul_vararg
if P is SR:
if isinstance(P, SymbolicRing):
op = data.operator()
if op == operator.pow:
base, exponent = data.operands()
if str(exponent) == var:
return base
elif exponent.operator() == mul_vararg:
return base ** (exponent / SR(var))
return base ** (exponent / P(var))
elif isinstance(op, sage.functions.log.Function_exp):
from sage.functions.log import exp
base = exp(1)
exponent = data.operands()[0]
if str(exponent) == var:
return base
elif exponent.operator() == mul_vararg:
return base ** (exponent / SR(var))
return base ** (exponent / P(var))

elif data == 1: # can be expensive, so let's put it at the end
return self.base().one()
Expand Down
8 changes: 5 additions & 3 deletions src/sage/rings/asymptotic/term_monoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -1843,8 +1843,8 @@ def _get_factors_(self, data):
except AttributeError:
return (data,)

from sage.symbolic.ring import SR
if P is SR:
from sage.symbolic.ring import SymbolicRing
if isinstance(P, SymbolicRing):
from sage.symbolic.operators import mul_vararg
if data.operator() == mul_vararg:
return tuple(data.operands())
Expand Down Expand Up @@ -2340,10 +2340,12 @@ def _substitute_(self, rules):
pass
else:
from asymptotic_ring import AsymptoticRing
from sage.symbolic.ring import SymbolicRing

if isinstance(P, AsymptoticRing):
return g.O()

elif P is sage.symbolic.ring.SR:
elif isinstance(P, SymbolicRing):
return g.Order()

try:
Expand Down
3 changes: 0 additions & 3 deletions src/sage/symbolic/ring.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ cdef class SymbolicRing(CommutativeRing):

from sage.rings.infinity import (infinity, minus_infinity,
unsigned_infinity)
from sage.rings.asymptotic.asymptotic_ring import AsymptoticExpansion
from sage.structure.factorization import Factorization

if isinstance(x, (Integer, RealNumber, float, long, complex)):
Expand All @@ -312,8 +311,6 @@ cdef class SymbolicRing(CommutativeRing):
return new_Expression_from_GEx(self, g_mInfinity)
elif x is unsigned_infinity:
return new_Expression_from_GEx(self, g_UnsignedInfinity)
elif isinstance(x, AsymptoticExpansion):
return x.symbolic_expression()
elif isinstance(x, (RingElement, Matrix)):
GEx_construct_pyobject(exp, x)
elif isinstance(x, Factorization):
Expand Down

0 comments on commit a016066

Please sign in to comment.