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

Commit

Permalink
22162: change more is_xyz() methods and doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
rwst committed Jan 10, 2017
1 parent 5f5d134 commit bb6f53f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/sage/symbolic/assumptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
sage: var('x')
x
sage: x.is_real()
False
Unknown
sage: assume(x,'real')
sage: x.is_real()
True
sage: forget()
sage: x.is_real()
False
Unknown
Here is the list of acceptable features::
Expand Down
41 changes: 31 additions & 10 deletions src/sage/symbolic/expression.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1897,7 +1897,7 @@ cdef class Expression(CommutativeRingElement):
sage: from sage.symbolic.assumptions import GenericDeclaration
sage: decl = GenericDeclaration(x, 'real')
sage: x.is_real()
False
Unknown
sage: x.decl_assume(decl._assumption)
sage: x.is_real()
True
Expand Down Expand Up @@ -1956,11 +1956,16 @@ cdef class Expression(CommutativeRingElement):
True
sage: SR(1.2).is_algebraic()
False
sage: x.is_algebraic()
Unknown
"""
try:
ex = sage.rings.all.QQbar(self)
except (TypeError, ValueError, NotImplementedError):
except (TypeError, ValueError):
return False
except NotImplementedError:
from sage.misc.unknown import Unknown
return Unknown
return True

def is_real(self):
Expand All @@ -1973,21 +1978,21 @@ cdef class Expression(CommutativeRingElement):
sage: t0.is_real()
True
sage: t0.is_positive()
False
Unknown
sage: t1 = SR.symbol("t1", domain='positive')
sage: (t0+t1).is_real()
True
sage: (t0+x).is_real()
False
Unknown
sage: (t0*t1).is_real()
True
sage: (t0*x).is_real()
False
Unknown
The following is real, but we cannot deduce that.::
sage: (x*x.conjugate()).is_real()
False
Unknown
Assumption of real has the same effect as setting the domain::
Expand All @@ -1997,7 +2002,11 @@ cdef class Expression(CommutativeRingElement):
True
sage: forget()
"""
return self._gobj.info(info_real)
if self._gobj.info(info_real):
return True
else:
from sage.misc.unknown import Unknown
return Unknown

def is_positive(self):
"""
Expand All @@ -2018,7 +2027,7 @@ cdef class Expression(CommutativeRingElement):
sage: (t0 + t1).is_positive()
True
sage: (t0*x).is_positive()
False
Unknown
::
Expand All @@ -2032,7 +2041,13 @@ cdef class Expression(CommutativeRingElement):
True
sage: forget()
"""
return self._gobj.info(info_positive)
if self._gobj.info(info_positive):
return True
elif self._gobj.info(info_negative) or self.is_trivial_zero():
return False
else:
from sage.misc.unknown import Unknown
return Unknown

def is_negative(self):
"""
Expand All @@ -2053,7 +2068,13 @@ cdef class Expression(CommutativeRingElement):
sage: (-pi).is_negative()
True
"""
return self._gobj.info(info_negative)
if self._gobj.info(info_negative):
return True
elif self._gobj.info(info_positive) or self.is_trivial_zero():
return False
else:
from sage.misc.unknown import Unknown
return Unknown

def is_integer(self):
"""
Expand Down
8 changes: 4 additions & 4 deletions src/sage/symbolic/ring.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,9 @@ cdef class SymbolicRing(CommutativeRing):
sage: k.<a> = GF(9)
sage: SR(a).is_real()
False
Unknown
sage: SR(a).is_positive()
False
Unknown
We get a sensible error message if conversion fails::
Expand All @@ -325,11 +325,11 @@ cdef class SymbolicRing(CommutativeRing):
sage: sin(x).subs(x=RR('NaN'))
sin(NaN)
sage: SR(RR('NaN')).is_real()
False
Unknown
sage: sin(x).subs(x=float('NaN'))
sin(NaN)
sage: SR(float('NaN')).is_real()
False
Unknown
sage: sin(x).subs(x=complex('NaN'))
sin(NaN)
"""
Expand Down

0 comments on commit bb6f53f

Please sign in to comment.