[PATCH] Fixes Symbol(x, integer=True).is_number bug

0 views
Skip to first unread message

Ondrej Certik

unread,
Jan 8, 2008, 6:14:33 PM1/8/08
to sympy-...@googlegroups.com
sympy.patch

Kirill Smelkov

unread,
Jan 9, 2008, 2:49:58 PM1/9/08
to sympy-...@googlegroups.com
Ondrej,

On Wed, Jan 09, 2008 at 12:14:33AM +0100, Ondrej Certik wrote:
> # HG changeset patch
> # User Ondrej Certik <ond...@certik.cz>
> # Date 1199833939 -3600
> # Node ID f6e8e584dfc2c2397d2f307f254de34847bfadd3
> # Parent e2c8006f700923d2cfae7f0f67b6685804a7dd2a
> Fixes Symbol(x, integer=True).is_number bug
>
> diff --git a/sympy/core/basic.py b/sympy/core/basic.py
> --- a/sympy/core/basic.py
> +++ b/sympy/core/basic.py
> @@ -309,6 +309,8 @@ class Basic(BasicMeths):
> def is_number(self):
> """Returns True if self is a number (like 1, or 1+log(2)), and False
> otherwise (e.g. 1+x)."""
> + if self.is_integer:
> + return True

Thanks for the spot, but what will this return for

( 1+Symbol('x', integer=True) ).is_number ?

Also, there are is_complex, is_rational, is_real, is_zero, etc...

> return len(self.atoms(Basic.Symbol)) == 0

I think the right way is to check 'self.atoms(Basic.Symbol)' - set(atoms
with is_integer or the like), to be empty.

>
> def is_fraction(self, *syms):
> diff --git a/sympy/core/tests/test_numbers.py b/sympy/core/tests/test_numbers.py
> --- a/sympy/core/tests/test_numbers.py
> +++ b/sympy/core/tests/test_numbers.py
> @@ -180,3 +180,7 @@ def test_len():
> assert len(Rational(2)) == 1
> assert len(Rational(2,3)) == 1
> assert len(Integer(2)) == 1
> +
> +def test_issue400():
> + k = Symbol("k", integer=True)
> + assert k.is_number

Maybe also check for 1+k, sin(k)? See above.


BTW, with your patch applied:

In [1]: integrate(x**k, x)
Out[1]:
1 + k
x
──────
1 + k

In [2]: integrate(2*x**k +3*x**m, x)
Out[2]:
1 + k 1 + m
2*x 3*x
──────── + ────────
1 + k 1 + m


So it works, thanks!


--
Всего хорошего, Кирилл.
http://landau.phys.spbu.ru/~kirr/aiv/

Reply all
Reply to author
Forward
0 new messages