Hi, On 30 May 2011 19:12, Vinzent Steinberg <[email protected]>wrote:
> On 29 Mai, 21:49, Mateusz Paprocki <[email protected]> wrote: > > If you want to write generic algorithms, you can't assume that you work > with > > any particular ground type. The same as you can't assume that integer > > multiplication is implemented efficiently (mpz vs. int), the same you > can't > > assume that Add() exists. What exists is + operator. It's SymPy's problem > > that sum(X) is O(len(X)**2) algorithm, but this is just because we use > lists > > instead of dicts for the internal implementation of Add. This will change > in > > future. > > It might make sense to define a generic 'sum' which depends on the > context (the ground type). For Expr instances it should be Add(*...), > for python integer sum(...), for mpmath numbers it would be fsum(...) > etc. > That could work: ZZ.sum([1, 2, 3]) -> sum([1, 2, 3]) RR.sum([1.0, 2.0]) -> mpmath.fsum([1.0, 2.0]) EX.sum([x, y, z]) -> Add(*[x, y, z]) etc. > Vinzent > > -- > You received this message because you are subscribed to the Google Groups > "sympy" 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?hl=en. > > Mateusz -- You received this message because you are subscribed to the Google Groups "sympy" 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?hl=en.
