Updates:
        Status: NeedsDecision
Cc: Vinzent.Steinberg [email protected] [email protected] [email protected]

Comment #1 on issue 2622 by asmeurer: Map functions over iterables
http://code.google.com/p/sympy/issues/detail?id=2622

There's also @vectorize, though see issue 2182.

But I'm not a fan of this. First off, using a decorator destroys information about the function. For example, do apart?? in isympy (or source(apart) if you don't have IPython).

But to the point, I don't like implicit vectorization anyway. Remember that explicit is better than implicit. You mention one problem with this, which is that you might want a function to apply differently over a container object, like exp(Matrix) representing the exponential of the matrix, rather than the exponential of each item of the matrix.

Another example is functions that apply over lists of expressions. The best example is solve(), which doesn't vectorize over a list, but rather treats the list like a system of equations.

The solution in my opinion is to not have any automatic vectorization at all. You can explicitly vectorize very easily in Python. If you have a list, you can use a list comprehension ([sin(i) for i in yourlist]). For matrix, we have Matrix.applyfunc. For sets and dictionaries, in Python 2.7 and Python 3 we have set and dictionary comprehensions.

So I'm tempted to mark this as WontFix. But I'll take the more cautious path and mark it as NeedsDecision. For one thing, we already do have functions that do this, and it's very inconsistant. Perhaps this should be a separate issue, but there is also an inconsistency with automatic sympification of strings.

Also, this behavior already exists, albiet inconsistently, for many SymPy functions:

In [26]: simplify(a)
Out[26]:
⎡  1       x   ⎤
⎢──────, ──────⎥
⎢ 2       2    ⎥
⎣x  - 1  x  - 1⎦

In [27]: simplify(Tuple(*a))
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/Users/aaronmeurer/Documents/python/sympy/sympy/<ipython-input-27-cc6abdb5bbd7> in <module>()
----> 1 simplify(Tuple(*a))

/Users/aaronmeurer/Documents/python/sympy/sympy/sympy/simplify/simplify.pyc in simplify(expr, ratio)
   1625         return together(powsimp(expr))
   1626
-> 1627     expr = together(cancel(powsimp(expr)).expand())
   1628
   1629     if not isinstance(expr, Basic): # XXX: temporary hack

AttributeError: 'tuple' object has no attribute 'expand'

As for Functions, it doesn't already work in most cases:

In [28]: sin(a)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/Users/aaronmeurer/Documents/python/sympy/sympy/<ipython-input-28-66bf5e82d1e2> in <module>()
----> 1 sin(a)

/Users/aaronmeurer/Documents/python/sympy/sympy/sympy/core/cache.pyc in wrapper(*args, **kw_args)
     98         k = k + tuple(map(lambda x: type(x), k))
     99         try:
--> 100             return func_cache_it_cache[k]
    101         except KeyError:
    102             pass

TypeError: unhashable type: 'list'

In [29]: sin(Tuple(*a))
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/Users/aaronmeurer/Documents/python/sympy/sympy/<ipython-input-29-e37745b0e5f5> in <module>()
----> 1 sin(Tuple(*a))

/Users/aaronmeurer/Documents/python/sympy/sympy/sympy/core/cache.pyc in wrapper(*args, **kw_args)
    101         except KeyError:
    102             pass
--> 103         func_cache_it_cache[k] = r = func(*args, **kw_args)
    104         return r
    105     return wrapper

/Users/aaronmeurer/Documents/python/sympy/sympy/sympy/core/function.pyc in __new__(cls, *args, **options)
    188         evaluate = options.pop('evaluate', True)
    189         if evaluate:
--> 190             evaluated = cls.eval(*args)
    191             if evaluated is not None:
    192                 return evaluated

/Users/aaronmeurer/Documents/python/sympy/sympy/sympy/functions/elementary/trigonometric.pyc in eval(cls, arg)
    159                 return
    160
--> 161         if arg.could_extract_minus_sign():
    162             return -cls(-arg)
    163

AttributeError: 'Tuple' object has no attribute 'could_extract_minus_sign'

So we need to decide what should be done universally, and apply it universally.

--
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