Vincent,

I added a tester method in test_expr.py for the patch and added the missing
functions.

I can't get the document attribute to copy as suggested without causing
circular importation (I have to import the global function above the class
which in turn imports expr, ad infinitum). This agrees with what is stated
here http://code.google.com/p/sympy/issues/detail?id=1901&q=action%20verb:

"Also I don't think we can have the methods copy the docstrings of the
global functions because
that would require importing the global function at the top of
sympy.core.expr, which we DON'T
want to do."


I might just be doing the document importation wrong.

I am not sure if moving the diff(), conjugate() and coeff() functions makes
sense as they seem to be in the right place grouped with similar methods.
e.g. the diff() function is below a comment label "DERIVATIVE, INTEGRAL,
FUNCTIONAL METHODS". I was intending the section for the action verbs
section to only contain the wrapper methods. I'll do whichever way you think
is best though.

--Addison--

On Mon, Apr 19, 2010 at 10:24 AM, Vinzent Steinberg <
vinzent.steinb...@googlemail.com> wrote:

> 2010/4/19 Addison Cugini <ajcug...@gmail.com>:
> > Per the issue here:
> >
> >
> http://groups.google.com/group/sympy/browse_thread/thread/59e5dfb987963204/eca6fd634?pli=1
> >
> > I have created methods which allows 'action verbs' to be called both as
> > global functions and as methods. Any suggestions you have would be
> > appreciated!
>
> Thanks, looks good, here a few remarks. Wouldn't it make sense to
> create some tests for a consistent user interface?
>
> What about diff(), conjugate() and coeff()? Shouldn't they also be
> moved to the action verbs section?
>
> I think you missed some functions, for example refine() and cancel(),
> please double-check your patch against the functions mentioned in the
> cited thread:
>
> """
> * take the global functions:
>
> simplify
> nsimplify
> *simp
> refine
> cancel
> invert
> expand_*
> apart
> collect
> separate
> together
> factor
>
> and add them as simple (3 lines) methods of Basic, together with
> automatically transferring the docs.
> """
>
> Maybe the docs should be automatically transfered? This can be done
> with ease using the __doc__ attribute.
>
> I'm not sure whether nsimplify() should be added to Expr(). See for
> example:
>
> In [1]: nsimplify(1./7)
> Out[1]: 1/7
>
> In [2]: nsimplify(1./7*x)
> Out[2]: 0.142857142857143⋅x
>
> But this is not an issue of your patch.
>
> Vinzent
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy-patches" group.
> To post to this group, send email to sympy-patc...@googlegroups.com.
> To unsubscribe from this group, send email to
> sympy-patches+unsubscr...@googlegroups.com<sympy-patches%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/sympy-patches?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy-patches" group.
To post to this group, send email to sympy-patc...@googlegroups.com.
To unsubscribe from this group, send email to 
sympy-patches+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy-patches?hl=en.

From 37210921dcbe4ab1c1acdde707e3c411f2af3ba2 Mon Sep 17 00:00:00 2001
From: Addison Cugini <ajcug...@gmail.com>
Date: Mon, 19 Apr 2010 19:20:30 -0700
Subject: [PATCH] Added functionality for action verbs
 Now, they can be called both as global functions and as methods
 e.g. a.simplify() = simplify(a)
 Tests added to tester for Expr

---
 sympy/core/expr.py            |   89 ++++++++++++++++++++++++++++++++++++++--
 sympy/core/tests/test_expr.py |   21 +++++++++-
 2 files changed, 104 insertions(+), 6 deletions(-)

diff --git a/sympy/core/expr.py b/sympy/core/expr.py
index 2ead924..a6de993 100644
--- a/sympy/core/expr.py
+++ b/sympy/core/expr.py
@@ -840,11 +840,6 @@ def fdiff(self, *indices):
         # FIXME FApply -> ?
         return C.FApply(C.FDerivative(*indices), self)
 
-    def integrate(self, *args, **kwargs):
-        from sympy.integrals import integrate
-        return integrate(self, *args, **kwargs)
-
-
     ###########################################################################
     ###################### EXPRESSION EXPANSION METHODS #######################
     ###########################################################################
@@ -896,6 +891,90 @@ def expand(self, deep=True, power_base=True, power_exp=True, mul=True, \
                     expr = func(deep=deep, **hints)
         return expr
 
+    ###########################################################################
+    ################### GLOBAL ACTION VERB WRAPPER METHODS ####################
+    ###########################################################################
+
+    def integrate(self, *args, **kwargs):
+        """See the integrate function in sympy.integrals"""
+        from sympy.integrals import integrate
+        return integrate(self, *args, **kwargs)
+
+    def simplify(self):
+        """See the simplify function in sympy.simplify"""
+        from sympy.simplify import simplify
+        return simplify(self)
+
+    def together(self, *args, **kwargs):
+        """See the together function in sympy.simplify"""
+        from sympy.simplify import together
+        return together(self, *args, **kwargs)
+
+    def nsimplify(self, constants=[], tolerance=None, full=False):
+        """See the nsimplify function in sympy.simplify"""
+        from sympy.simplify import nsimplify
+        return nsimplify(self, constants, tolerance, full)
+
+    def separate(self, deep=False):
+        """See the seperate function in sympy.simplify"""
+        from sympy.simplify import separate
+        return separate(self, deep)
+
+    def collect(self, syms, evaluate=True, exact=False):
+        """See the collect function in sympy.simplify"""
+        from sympy.simplify import collect
+        return collect(self, syms, evaluate, exact)
+
+    def apart(self, z=None, **args):
+        """See the apart function in sympy.simplify"""
+        from sympy.simplify import apart
+        return apart(self, z=None, **args)
+
+    def ratsimp(self):
+        """See the ratsimp function in sympy.simplify"""
+        from sympy.simplify import ratsimp
+        return ratsimp(self)
+
+    def trigsimp(self, deep=False, recursive=False):
+        """See the trigsimp function in sympy.simplify"""
+        from sympy.simplify import trigsimp
+        return trigsimp(self, deep, recursive)
+
+    def radsimp(self):
+        """See the radsimp function in sympy.simplify"""
+        from sympy.simplify import radsimp
+        return radsimp(self)
+
+    def powsimp(self, deep=False, combine='all'):
+        """See the powsimp function in sympy.simplify"""
+        from sympy.simplify import powsimp
+        return powsimp(self, deep, combine)
+
+    def combsimp(self):
+        """See the combsimp function in sympy.simplify"""
+        from sympy.simplify import combsimp
+        return combsimp(self)
+
+    def factor(self, *gens, **args):
+        """See the factor function in sympy.simplify"""
+        from sympy.polys import factor
+        return factor(self, *gens, **args)
+
+    def refine(self, assumption=True):
+        """See the refine function in sympy.assumptions"""
+        from sympy.assumptions import refine
+        return refine(self, assumption)
+
+    def cancel(self, *gens, **args):
+        """See the cancel function in sympy.polys"""
+        from sympy.polys import cancel
+        return cancel(self, *gens, **args)
+
+    def invert(self, g):
+        """See the invert function in sympy.polys"""
+        from sympy.polys import invert
+        return invert(self, g)
+
 from mul import Mul
 from power import Pow
 from add import Add
diff --git a/sympy/core/tests/test_expr.py b/sympy/core/tests/test_expr.py
index 14b8d5d..c65c6bc 100644
--- a/sympy/core/tests/test_expr.py
+++ b/sympy/core/tests/test_expr.py
@@ -1,7 +1,9 @@
 from sympy import Basic, S, Symbol, Real, Integer, Rational,  \
     sin, cos, exp, log, oo, sqrt, symbols, Integral, sympify, \
     WildFunction, Poly, Function, Derivative, Number, pi, var, \
-    NumberSymbol, zoo, Piecewise, Mul
+    NumberSymbol, zoo, Piecewise, Mul, nsimplify, ratsimp, trigsimp, \
+    radsimp, powsimp, simplify, together, separate, collect, \
+    apart, combsimp, factor, refine, cancel, invert
 
 from sympy.core.cache import clear_cache
 
@@ -733,3 +735,20 @@ def test_Basic_keep_sign():
     Basic.keep_sign = False
     assert Mul(x - 1, x + 1) == -(1 - x)*(1 + x)
     assert (1/(x - 1)).as_coeff_terms()[0] == -1
+
+def test_action_verbs():
+    a,b,c,d = symbols('abcd')
+    assert nsimplify((1/(exp(3*pi*x/5)+1))) == (1/(exp(3*pi*x/5)+1)).nsimplify()
+    assert ratsimp(1/x + 1/y) == (1/x + 1/y).ratsimp()
+    assert trigsimp(log(x), deep=True) == (log(x)).trigsimp(deep = True)
+    assert radsimp(1/(2+sqrt(2))) == (1/(2+sqrt(2))).radsimp()
+    assert powsimp(x**y*x**z*y**z, combine='all') == (x**y*x**z*y**z).powsimp(combine='all')
+    assert simplify(x**y*x**z*y**z) == (x**y*x**z*y**z).simplify()
+    assert together(1/x + 1/y) == (1/x + 1/y).together()
+    assert separate((x*(y*z)**3)**2) == ((x*(y*z)**3)**2).separate()
+    assert collect(a*x**2 + b*x**2 + a*x - b*x + c, x) == (a*x**2 + b*x**2 + a*x - b*x + c).collect(x)
+    assert apart(y/(y+2)/(y+1), y) == (y/(y+2)/(y+1)).apart(y)
+    assert combsimp(y/(x+2)/(x+1)) == (y/(x+2)/(x+1)).combsimp()
+    assert factor(x**2+5*x+6) == (x**2+5*x+6).factor()
+    assert refine(sqrt(x**2)) == sqrt(x**2).refine()
+    assert cancel((x**2+5*x+6)/(x+2)) == ((x**2+5*x+6)/(x+2)).cancel()
-- 
1.6.3.3

Reply via email to