Hi,

there is an inconsistency problem with subs:

sage: e = x**2 + 1
sage: e
x^2 + 1
sage: e.subs(x= x**2)
x^4 + 1
sage: e.subs(x**2= x)
------------------------------------------------------------
   File "<ipython console>", line 1
<type 'exceptions.SyntaxError'>: keyword can't be an expression
(<ipython console>, line 1)

sage: e.subs(x**2, x)
---------------------------------------------------------------------------
<type 'exceptions.TypeError'>             Traceback (most recent call last)

/home/ondra/ext/sage-2.8.13-i686-Linux/<ipython console> in <module>()

/home/ondra/ext/sage/local/lib/python2.5/site-packages/sage/calculus/calculus.py
in subs(self, *args, **kwds)
   2506
   2507     def subs(self, *args, **kwds):
-> 2508         return self.substitute(*args, **kwds)
   2509
   2510     def _recursive_sub(self, kwds):

<type 'exceptions.TypeError'>: substitute() takes at most 2 arguments (3 given)


Clearly, there is no way how to substitute for x**2 with the current
syntax, since we are abusing Python keywords arguments. I propose not
to use .subs(x=1), but only .subs(x, 1), because it's clean and it
will work when we implement substituting for x**2 (not yet in Sage). I
think you will disagree with an argument, that mathematicians are used
to writing .subs(x=1), well, I disagree with that,
I think mathematicians are very clever people and they will be able to
handle that, but as a compromise, .subs() should be able to accept
both.

BTW, this is how this works in SymPy:

In [1]: e = x**2 + 1

In [2]: e
Out[2]:
     2
1 + x

In [3]: e.subs(x, x**2)
Out[3]:
     4
1 + x

In [4]: e.subs(x**2, x)
Out[4]: 1 + x


Ondrej

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/
-~----------~----~----~----~------~----~------~--~---

Reply via email to