2010/4/20 Addison Cugini <ajcug...@gmail.com>: > 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.
Sorry that this got forgotten. It looks fine, I felt free to rebase your patch and fix the commit message formatting a bit. I'm still not sure about nsimplify(). Currently you get: In [2]: nsimplify(1./7 * x) Out[2]: 0.142857142857143⋅x So it does not make a lot of sense to add it to Expr. This is however not a problem with your patch; I opened issue 1975 for this. I pushed it in, thanks! 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. For more options, visit this group at http://groups.google.com/group/sympy-patches?hl=en.
From 3f45845d43f5d450b93841a0271a930f07c639a5 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 for Expr. Signed-off-by: Vinzent Steinberg <vinzent.steinb...@gmail.com> --- 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 ec68a82..1a4ebb3 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, Wild, Real, Integer, Rational, \ sin, cos, exp, log, oo, sqrt, symbols, Integral, sympify, \ WildFunction, Poly, Function, Derivative, Number, pi, var, \ - NumberSymbol, zoo, Piecewise, Mul, Pow + NumberSymbol, zoo, Piecewise, Mul, Pow, nsimplify, ratsimp, trigsimp, \ + radsimp, powsimp, simplify, together, separate, collect, \ + apart, combsimp, factor, refine, cancel, invert from sympy.core.cache import clear_cache @@ -747,3 +749,20 @@ def test_issue1864(): assert hasattr(Pow(x, y, evaluate=False), "is_commutative") expr = Mul(Pow(2, 2, evaluate=False), 3, evaluate=False) + 1 assert hasattr(expr, "is_commutative") + +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.7.1.1