On Tue, Dec 09, 2008 at 07:17:44PM -0800, Lance Larsen wrote: > > Finally got a few moments to put the implicit subs syntax code > together and get it ready to submit. Here it is. > > -Lance > > # HG changeset patch > # User [EMAIL PROTECTED] > # Date 1228878177 25200 > # Node ID dc86dcc8d059f0a2cd3eb498b595c8a45775aa92 > # Parent d1019a5c66d12d524fe64359c1bd8054cab0cfa9 > Substitution syntax extension - implements f({x:1,y:2}) as shorthand > for f.subs({x:1,y:2}) > > diff -r d1019a5c66d1 -r dc86dcc8d059 sympy/core/basic.py > --- a/sympy/core/basic.py Tue Nov 18 17:36:24 2008 +0100 > +++ b/sympy/core/basic.py Tue Dec 09 20:02:57 2008 -0700 > @@ -1932,9 +1932,25 @@ > from sympy.integrals import integrate > return integrate(self, *args, **kwargs) > > - #XXX fix the removeme > - def __call__(self, *args, **removeme): > - return Function(self[0])(*args) > + def __call__(self, subs_dict): > + ''' > + Implements a convenient way to call the subs method. A > dictionary object > + is accepted where the ductionary key is the value to be > replaced, and > + the value is what the key expression will be replaced with. > + > + Example: > + >>> x,y,z = symbols('xyz') > + >>> f = x+y+x*y > + >>> f({x:z})
Just an idea. This syntax isnt far away from f(x=z) Could it be the next (additional) stage of simplification? > + z + y + z*y > + >>> f({x*y,z}) > + x + y + z But sure for this, the syntax f(x*y=z) is wrong. > + This is equivalent to calling f.subs({...}) > + ''' > + if not isinstance(sequence, dict): Just an question. What is 'sequence'? I dont see it definded in the __call__ methode. > + raise TypeError('A dictionary object is expected for > making substitutions.') > + return self.subs(subs_dict) > > def __float__(self): > result = self.evalf() > diff -r d1019a5c66d1 -r dc86dcc8d059 sympy/core/tests/test_subs.py > --- a/sympy/core/tests/test_subs.py Tue Nov 18 17:36:24 2008 +0100 > +++ b/sympy/core/tests/test_subs.py Tue Dec 09 20:02:57 2008 -0700 > @@ -169,3 +169,10 @@ > assert (f(x,y)).subs(f,sin) == f(x,y) > assert (sin(x)+atan2(x,y)).subs([[atan2,f],[sin,g]]) == f(x,y) + g > (x) > assert (g(f(x+y, x))).subs([[f, l], [g, exp]]) == exp(x + sin(x + > y)) > + > +def test_implicit_subs_syntax(): > + x, y, z = map(Symbol, 'xyz') > + f = x + y + x*y > + assert f({x:z}) == f.subs({x:z}) > + assert f({x:z}) == z + y + z*y > + assert f({x*y:z}) == x + y + z > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sympy-patches" group. To post to this group, send email to sympy-patches@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sympy-patches?hl=en -~----------~----~----~----~------~----~------~--~---