Skip to content

Commit

Permalink
XXX fix _eval_is_rational helpers for inverse trig
Browse files Browse the repository at this point in the history
Validation:

In[2]:= FullSimplify[ArcSin[x] \[Element] Rationals,
 Assumptions -> x != 0 && x \[Element] Rationals]

Out[2]= False

In[5]:= FullSimplify[ArcCos[x] \[Element] Rationals,
 Assumptions -> x != 1 && x \[Element] Rationals]

Out[5]= False

In[9]:= FullSimplify[ArcTan[x] \[Element] Rationals,
 Assumptions -> x != 0 && x \[Element] Rationals]

Out[9]= False

In[16]:= FullSimplify[ArcCot[x] \[Element] Rationals,
 Assumptions -> x \[Element] Rationals]

Out[16]= False
  • Loading branch information
skirpichev committed Aug 27, 2016
1 parent c2ddd7e commit 9fd0956
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
34 changes: 34 additions & 0 deletions diofant/functions/elementary/tests/test_trigonometric.py
Expand Up @@ -665,6 +665,15 @@ def test_asin():
assert asin(-2).is_extended_real is False
assert asin(r).is_extended_real is None

assert asin(0, evaluate=False).is_rational
assert asin(1, evaluate=False).is_rational is False

z = Symbol('z', zero=True)
rn = Symbol('rn', rational=True, nonzero=True)
assert asin(z).is_rational
assert asin(rn).is_rational is False
assert asin(x).is_rational is None

assert asin(-2*I) == -I*asinh(2)

assert asin(Rational(1, 7), evaluate=False).is_positive is True
Expand Down Expand Up @@ -712,6 +721,15 @@ def test_acos():
assert acos(-2).is_extended_real is False
assert acos(r).is_extended_real is None

assert acos(1, evaluate=False).is_rational
assert acos(0, evaluate=False).is_rational is False

z = Symbol('z', zero=True)
rn = Symbol('rn', rational=True, nonzero=True)
assert acos(1 + z).is_rational
assert acos(1 + rn).is_rational is False
assert acos(x).is_rational is None

assert acos(Rational(1, 7), evaluate=False).is_positive is True
assert acos(Rational(-1, 7), evaluate=False).is_positive is True
assert acos(Rational(3, 2), evaluate=False).is_positive is False
Expand Down Expand Up @@ -766,6 +784,15 @@ def test_atan():
assert atan(n).is_positive is False
assert atan(x).is_positive is None

assert atan(0, evaluate=False).is_rational
assert atan(1, evaluate=False).is_rational is False

z = Symbol('z', zero=True)
rn = Symbol('rn', rational=True, nonzero=True)
assert atan(z).is_rational
assert atan(rn).is_rational is False
assert atan(x).is_rational is None


def test_atan_rewrite():
assert atan(x).rewrite(log) == I*log((1 - I*x)/(1 + I*x))/2
Expand Down Expand Up @@ -857,6 +884,13 @@ def test_acot():
assert acot(p).is_positive is True
assert acot(I).is_positive is False

assert acot(0, evaluate=False).is_rational is False

z = Symbol('z', zero=True)
rn = Symbol('rn', rational=True, nonzero=True)
assert acot(1 + rn).is_rational is False
assert acot(x).is_rational is None


def test_acot_rewrite():
assert acot(x).rewrite(log) == I*log((x - I)/(x + I))/2
Expand Down
14 changes: 10 additions & 4 deletions diofant/functions/elementary/trigonometric.py
Expand Up @@ -1510,7 +1510,9 @@ def fdiff(self, argindex=1):
def _eval_is_rational(self):
s = self.func(*self.args)
if s.func == self.func:
if s.args[0].is_rational:
if s.args[0].is_zero:
return True
elif s.args[0].is_rational and s.args[0].is_nonzero:
return False
else:
return s.is_rational
Expand Down Expand Up @@ -1680,7 +1682,9 @@ def fdiff(self, argindex=1):
def _eval_is_rational(self):
s = self.func(*self.args)
if s.func == self.func:
if s.args[0].is_rational:
if (s.args[0] - 1).is_zero:
return True
elif s.args[0].is_rational and (s.args[0] - 1).is_nonzero:
return False
else:
return s.is_rational
Expand Down Expand Up @@ -1845,7 +1849,9 @@ def fdiff(self, argindex=1):
def _eval_is_rational(self):
s = self.func(*self.args)
if s.func == self.func:
if s.args[0].is_rational:
if s.args[0].is_zero:
return True
elif s.args[0].is_rational and s.args[0].is_nonzero:
return False
else:
return s.is_rational
Expand Down Expand Up @@ -1990,7 +1996,7 @@ def fdiff(self, argindex=1):
def _eval_is_rational(self):
s = self.func(*self.args)
if s.func == self.func:
if s.args[0].is_rational:
if s.args[0].is_rational and (s.args[0] - 1).is_nonzero:
return False
else:
return s.is_rational
Expand Down

0 comments on commit 9fd0956

Please sign in to comment.