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

Commit

Permalink
correct parent of result of an_element
Browse files Browse the repository at this point in the history
  • Loading branch information
dkrenn committed Oct 19, 2015
1 parent 852959a commit e4837e9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/sage/symbolic/ring.pyx
Expand Up @@ -266,7 +266,6 @@ cdef class SymbolicRing(CommutativeRing):
"""
cdef GEx exp

if is_Expression(x):
if (<Expression>x)._parent is self:
return x
Expand Down
23 changes: 19 additions & 4 deletions src/sage/symbolic/subring.py
Expand Up @@ -342,12 +342,15 @@ def _element_constructor_(self, x):
sage: S = SymbolicSubring(accepting_variables=('a',))
sage: S('a') # indirect doctest
a
sage: _.parent()
Symbolic Subring accepting the variable a
sage: S('x') # indirect doctest
Traceback (most recent call last):
...
TypeError: x is not contained in Symbolic Subring accepting the variable a
"""
expression = SR(x)
expression = super(GenericSymbolicSubring, self)._element_constructor_(x)
assert(expression.parent() is self)
if not all(self.is_variable_valid(var)
for var in expression.variables()):
raise TypeError('%s is not contained in %s' % (x, self))
Expand Down Expand Up @@ -707,8 +710,10 @@ def _an_element_(self):
sage: from sage.symbolic.subring import SymbolicSubring
sage: SymbolicSubring(accepting_variables=('a',)).an_element()
a
sage: _.parent()
Symbolic Subring accepting the variable a
"""
return sorted(self._vars_, key=str)[0]
return self(sorted(self._vars_, key=str)[0])


class SymbolicSubringAcceptingVarsFunctor(GenericSymbolicSubringFunctor):
Expand Down Expand Up @@ -897,17 +902,25 @@ def _an_element_(self):
sage: from sage.symbolic.subring import SymbolicSubring
sage: SymbolicSubring(rejecting_variables=('r',)).an_element()
some_variable
sage: _.parent()
Symbolic Subring rejecting the variable r
sage: SymbolicSubring(rejecting_variables=('some_variable',)).an_element()
some_some_variable
sage: _.parent()
Symbolic Subring rejecting the variable some_variable
sage: SymbolicSubring(rejecting_variables=('some_some_variable',)).an_element()
some_variable
sage: _.parent()
Symbolic Subring rejecting the variable some_some_variable
sage: SymbolicSubring(rejecting_variables=('some_variable','some_some_variable')).an_element()
some_some_some_variable
sage: _.parent()
Symbolic Subring rejecting the variables some_some_variable, some_variable
"""
v = SR.an_element()
while not self.is_variable_valid(v):
v = SR('some_' + str(v))
return v
return self(v)


class SymbolicSubringRejectingVarsFunctor(GenericSymbolicSubringFunctor):
Expand Down Expand Up @@ -1042,5 +1055,7 @@ def _an_element_(self):
sage: from sage.symbolic.subring import SymbolicSubring
sage: SymbolicSubring(no_variables=True).an_element()
I*pi*e
sage: _.parent()
Symbolic Constants Subring
"""
return SR('I') * SR('pi') * SR('e')
return self(SR('I') * SR('pi') * SR('e'))

0 comments on commit e4837e9

Please sign in to comment.