[PATCH] Basic.simplify() implemented.

4 views
Skip to first unread message

Ondrej Certik

unread,
Oct 15, 2008, 9:47:08 AM10/15/08
to sympy-...@googlegroups.com, Ondrej Certik
This just calls simplify(self). This is so that you can do stuff like
a.integrate(x).simplify().
---
sympy/core/basic.py | 9 +++++++++
sympy/core/tests/test_basic.py | 3 +++
2 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/sympy/core/basic.py b/sympy/core/basic.py
index d5e4262..742ec9c 100644
--- a/sympy/core/basic.py
+++ b/sympy/core/basic.py
@@ -1899,6 +1899,15 @@ class Basic(AssumeMeths):
from sympy.integrals import integrate
return integrate(self, *args, **kwargs)

+ def simplify(self):
+ """
+ Calls simplify(self).
+
+ See simplify's doctest for more documentation.
+ """
+ from sympy import simplify
+ return simplify(self)
+
#XXX fix the removeme
def __call__(self, *args, **removeme):
return Function(self[0])(*args)
diff --git a/sympy/core/tests/test_basic.py b/sympy/core/tests/test_basic.py
index 41730c5..b3c60cc 100644
--- a/sympy/core/tests/test_basic.py
+++ b/sympy/core/tests/test_basic.py
@@ -575,3 +575,6 @@ def test_integrate():
assert (log(x)).integrate((x, 0, 1)) == -1
assert sin(x).integrate(x) == -cos(x)
assert sin(x).integrate(('x',0,1)) == 1 - cos(1)
+
+def test_simplify():
+ assert sin(x).simplify() == sin(x)
--
1.5.6.5

Fabian Seoane

unread,
Oct 15, 2008, 11:42:13 AM10/15/08
to sympy-...@googlegroups.com


I'm 0 for this. Don't see the need for this, I think that there are already too many classmethods for Basic, and having sympify as a classmethod and as a static method (same name, different arguments expected) would only confuse users ...

2008/10/15 Ondrej Certik <ond...@certik.cz>

Ondrej Certik

unread,
Oct 15, 2008, 12:22:19 PM10/15/08
to sympy-...@googlegroups.com
On Wed, Oct 15, 2008 at 5:42 PM, Fabian Seoane <fabian...@gmail.com> wrote:
>
>
> I'm 0 for this. Don't see the need for this, I think that there are already
> too many classmethods for Basic, and having sympify as a classmethod and as
> a static method (same name, different arguments expected) would only confuse
> users ...

Yeah. I find it handy sometimes, but I agree with your point.

Others, what do you think?


Ondrej

Vinzent Steinberg

unread,
Oct 16, 2008, 9:48:23 AM10/16/08
to sympy-patches
I think we should really decide which methods should be kept as class
methods and which not.

I don't like it for example that all linear algebra functions are an
attribute of Matrix.

Currently, it doesn't seem to be systematic or consistent. Maybe we
should discuss

* when to use class methods
* when to use static methods and
* when to use both.

Are there important reasons or motivations?

Vinzent

On Oct 15, 6:22 pm, "Ondrej Certik" <ond...@certik.cz> wrote:

Ondrej Certik

unread,
Oct 16, 2008, 10:54:43 AM10/16/08
to sympy-...@googlegroups.com
On Thu, Oct 16, 2008 at 3:48 PM, Vinzent Steinberg
<vinzent....@googlemail.com> wrote:
>
> I think we should really decide which methods should be kept as class
> methods and which not.
>
> I don't like it for example that all linear algebra functions are an
> attribute of Matrix.
>
> Currently, it doesn't seem to be systematic or consistent. Maybe we
> should discuss
>
> * when to use class methods
> * when to use static methods and
> * when to use both.
>
> Are there important reasons or motivations?

Let's discuss this on our main list:

http://groups.google.com/group/sympy/browse_thread/thread/761421dc172c44f0

Ondrej

Reply all
Reply to author
Forward
0 new messages