Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 2622 by [email protected]: Map functions over iterables
http://code.google.com/p/sympy/issues/detail?id=2622

Sympy functions should map over iterables like lists or Matrices
by default. For example, simplify should work with a list of expressions,
limit for a Matrix depending on a parameter ...

Concrete example, start with the matrix:

In [35]: M = Matrix([[x-x, x**2/x],[x**4*1/x, x/exp(-x)]])

In [36]: M
Out[36]:
[   0,        x]
[x**3, x*exp(x)]

Then limit(M,x,oo) throws: SympifyError: 'Matrix cannot be sympified'
but the intent was to get the limit computed elementwise. Another example
would be

In [38]: N = Matrix([[0, pi], [2*pi, 2*pi/3]])

In [39]: sin(N)

which makes much sense when we interpret "sin" elementwise. (Not to confuse
with SIN(M) the sine of a square matrix defined via matrix exponential.)

One solution that was presented on irc is to use the "threaded" decorator.
(Which has an odd name and I never would have guessed it. Maybe
"mapover" or similar would be better.) According to its help page it does exactly what we want (and some things more).

Define:

In [41]: @threaded
   ....: def mylimit(expr, var, lim):
   ....:        return limit(expr, var, lim)

and use:

In [42]: mylimit(M,x,oo)
Out[42]:
[ 0, oo]
[oo, oo]

So it really works as advertised, great. However a user should not have to decorate all functions, they should just work out of the box. And there are many functions where it is obvious how they should distribute, for example "simplify". On the opposite we also would like to have "sin(N)" which acts
as matrix function and also carries the name "sin". So this is a detail
which might be difficult to resolve, at least without static typing. I
wonder what the "prefect" solution would be.


--
You received this message because you are subscribed to the Google Groups 
"sympy-issues" group.
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/sympy-issues?hl=en.

Reply via email to