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

Commit

Permalink
22162: Return Unknown from ex.is_xyz() if Pynac returns false
Browse files Browse the repository at this point in the history
  • Loading branch information
rwst committed Dec 12, 2017
1 parent 07d6c37 commit c866181
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 37 deletions.
4 changes: 2 additions & 2 deletions src/sage/functions/trig.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ def __init__(self):
sage: bool(asin(SR(2.1)) == NaN)
True
sage: asin(SR(2.1)).is_real()
False
Unknown
"""
GinacFunction.__init__(self, 'arcsin', latex_name=r"\arcsin",
conversions=dict(maxima='asin', sympy='asin', fricas="asin", giac="asin"))
Expand Down Expand Up @@ -601,7 +601,7 @@ def __init__(self):
sage: bool(acos(SR(2.1)) == NaN)
True
sage: acos(SR(2.1)).is_real()
False
Unknown
"""
GinacFunction.__init__(self, 'arccos', latex_name=r"\arccos",
conversions=dict(maxima='acos', sympy='acos', fricas='acos', giac='acos'))
Expand Down
4 changes: 2 additions & 2 deletions src/sage/symbolic/assumptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,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
91 changes: 60 additions & 31 deletions src/sage/symbolic/expression.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1914,7 +1914,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 All @@ -1928,13 +1928,13 @@ cdef class Expression(CommutativeRingElement):
sage: from sage.symbolic.assumptions import GenericDeclaration
sage: decl = GenericDeclaration(x, 'integer')
sage: x.is_integer()
False
Unknown
sage: x.decl_assume(decl._assumption)
sage: x.is_integer()
True
sage: x.decl_forget(decl._assumption)
sage: x.is_integer()
False
Unknown
"""
pynac_forget_gdecl(self._gobj, decl)

Expand Down Expand Up @@ -1968,16 +1968,17 @@ cdef class Expression(CommutativeRingElement):
sage: (I*golden_ratio + sqrt(2)).is_algebraic()
True
sage: (sqrt(2) + pi).is_algebraic()
False
Unknown
sage: SR(QQ(2/3)).is_algebraic()
True
sage: SR(1.2).is_algebraic()
False
Unknown
"""
from sage.misc.unknown import Unknown
try:
ex = sage.rings.all.QQbar(self)
except (TypeError, ValueError, NotImplementedError):
return False
return Unknown
return True

def is_real(self):
Expand All @@ -1990,21 +1991,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: t2 = SR.symbol("t2", domain='positive')
sage: (t1**t2).is_real()
True
sage: (t0*x).is_real()
False
Unknown
sage: (t0^t1).is_real()
False
Unknown
sage: (t1^t2).is_real()
True
sage: gamma(pi).is_real()
Expand All @@ -2016,20 +2017,20 @@ cdef class Expression(CommutativeRingElement):
sage: gamma(t1).is_real()
True
sage: (x^pi).is_real()
False
Unknown
sage: (cos(exp(t0) + log(t1))^8).is_real()
True
sage: cos(I + 1).is_real()
False
Unknown
sage: sin(2 - I).is_real()
False
Unknown
sage: (2^t0).is_real()
True
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 @@ -2051,9 +2052,16 @@ cdef class Expression(CommutativeRingElement):
Check that :trac:`23093` is fixed::
sage: sqrt(-2).is_real()
False
Unknown
"""
return self._gobj.info(info_real)
from sage.misc.unknown import Unknown
sig_on()
try:
if self._gobj.info(info_real):
return True
finally:
sig_off()
return Unknown

def is_positive(self):
"""
Expand All @@ -2065,7 +2073,7 @@ cdef class Expression(CommutativeRingElement):
sage: t0.is_positive()
True
sage: t0.is_negative()
False
Unknown
sage: t0.is_real()
True
sage: t1 = SR.symbol("t1", domain='positive')
Expand All @@ -2074,7 +2082,7 @@ cdef class Expression(CommutativeRingElement):
sage: (t0 + t1).is_positive()
True
sage: (t0*x).is_positive()
False
Unknown
::
Expand All @@ -2093,33 +2101,40 @@ cdef class Expression(CommutativeRingElement):
::
sage: cosh(x).is_positive()
False
Unknown
sage: cosh(real(x)).is_positive()
True
sage: (cosh(real(x))^2).is_positive()
True
sage: ((real(x))^2).is_positive()
False
Unknown
sage: gamma(x^2).is_positive()
False
Unknown
sage: gamma(x^2+1).is_positive()
False
Unknown
sage: gamma(cosh(real(x))).is_positive()
True
sage: (real(x)^2).is_positive()
False
Unknown
sage: (real(x)^2+1).is_positive()
True
sage: (abs(x)^2+1).is_positive()
True
sage: gamma(real(x)^2+1).is_positive()
True
sage: cos(I + 1).is_positive()
False
Unknown
sage: sin(2 - I).is_positive()
False
Unknown
"""
return self._gobj.info(info_positive)
from sage.misc.unknown import Unknown
sig_on()
try:
if self._gobj.info(info_positive):
return True
finally:
sig_off()
return Unknown

def is_negative(self):
"""
Expand All @@ -2134,7 +2149,7 @@ cdef class Expression(CommutativeRingElement):
sage: t0 = SR.symbol("t0", domain='positive')
sage: t0.is_negative()
False
Unknown
sage: (-t0).is_negative()
True
sage: (-pi).is_negative()
Expand All @@ -2145,12 +2160,19 @@ cdef class Expression(CommutativeRingElement):
sage: y = var('y')
sage: assume(y < 0)
sage: y.is_positive()
False
Unknown
sage: y.is_negative()
True
sage: forget()
"""
return self._gobj.info(info_negative)
from sage.misc.unknown import Unknown
sig_on()
try:
if self._gobj.info(info_negative):
return True
finally:
sig_off()
return Unknown

def is_integer(self):
"""
Expand All @@ -2177,7 +2199,14 @@ cdef class Expression(CommutativeRingElement):
True
sage: forget()
"""
return self._gobj.info(info_integer)
from sage.misc.unknown import Unknown
sig_on()
try:
if self._gobj.info(info_integer):
return True
finally:
sig_off()
return Unknown

def is_symbol(self):
"""
Expand Down Expand Up @@ -3633,7 +3662,7 @@ cdef class Expression(CommutativeRingElement):
sage: t = I*x-1/2; t
I*x - 1/2
sage: t.subs(x=I*x).subs(x=0).is_positive()
False
Unknown
Check if :trac:`16397` is fixed:
Expand Down
4 changes: 2 additions & 2 deletions src/sage/symbolic/ring.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,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 c866181

Please sign in to comment.