Hi Ondrej, Thanks for the quick response. I took a look at the Sum class tests, but there is still one part I'm not clear on.
In defining a summation, I would like to have the sum over an array of symbols, indexed by an iterate. For example, In the sum \sum_{i=0}^4 tau_i, I'd like each tau[i] to itself be a symbol, since I later want to differentiate with respect to these symbols. I'd like to do this: In [17]: tau = [] In [18]: for i in range(10): ....: tau.append(Symbol('tau_%s' % i)) In [19]: Sum(tau[i]**2, (i, 0, 9)) --------------------------------------------------------------------------- ValueError Traceback (most recent call last) or In [20]: Sum(i**2, (i, tau)) --------------------------------------------------------------------------- ValueError Traceback (most recent call last) Ideally, this would give some compact representation of tau[0]**2 + tau[1]**2 + ... + tau[9]**2 Is there something I'm missing? Thanks again, Danny On Dec 30, 7:26 am, "Ondrej Certik" <ond...@certik.cz> wrote: > Hi Danny! > > On Mon, Dec 29, 2008 at 4:01 PM, Danny Tarlow <dannytar...@gmail.com> wrote: > > [...] > > >> Is this possible to do with Sympy? If I were interested in working on > >> something like this, how hard would it be for a sympy newbie (but > >> competent programmer) to implement? Any tips on where to start? > > Thanks for both your emails. You need to use the Sum class for that, > and I think it will probably need a little enhancements so that > everything runs smoothly. I think it should be pretty easy for you to > get going with sympy, it's our aim to have the code hackable, so that > people can take it and customize it for their needs and enhance it to > get the job done. I suggest you learn git, just a few commands are > enough, see our tutorial: > > http://docs.sympy.org/sympy-patches-tutorial.html > > feel free to ask any question if you don't understand something in the > sources. You can also come to #sympy at freenode to chat in live. > > > For concreteness, here is an example of one of my attempts: > > [...] > > > The output is a mess: > > mu := [tau_0/5 + tau_1/5 + tau_2/5 + tau_3/5 + tau_4/5] > > sigma := [2*mu*tau_0 + 2*mu*tau_1 + 2*mu*tau_2 + 2*mu*tau_3 + > > 2*mu*tau_4 - tau_0**2 - tau_1**2 - tau_2**2 - tau_3**2 - tau_4**2 - > > 5*mu**2] > > tau_0 := [mu] > > > Ideally, I'd like to get something more like this, where the sums are > > left in tact: > > mu := 1/5 * \sum_{i=0}^4 tau_i > > sigma := 1/5 * \sum_{i=0}^4 (mu - tau_i) ** 2 > > tau_0 := [mu] > > I see. You need to keep things in the Sum class, unfortunately the > docstring of it is not so much helpful (it can be your first patch if > you want:), but read it's tests here: > > sympy/concrete/tests/test_sums_products.py > > to get dozens of examples of usage. E.g.: > > In [3]: Sum(1/k**k, (k, 1, oo)) > Out[3]: Sum(k**(-k), (k, 1, oo)) > > In your case probably more something like this: > > In [4]: Sum(1/k**k, (k, 1, 5)) > Out[4]: Sum(k**(-k), (k, 1, 5)) > > In [5]: Sum(1/k**k, (k, 1, 5)).doit() > Out[5]: > 27891287 > ──────── > 21600000 > > E.g. you don't want to call the "doit()" function. Please report > everything that isn't working with the Sum into our issues. If things > are easy to fix, I'll fix it myself, if it takes more time, I'll help > you fix it. > > > > > For extra credit, there would also be a way to substitute sufficient > > statistics for the \sum_{i=0}^4 tau_i terms, for example, so that the > > sample mean could be computed once, then used many times in the > > updates. > > the .subs() method should do that. > > > > > Thanks in advance. > > Ondrej --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sympy@googlegroups.com To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sympy?hl=en -~----------~----~----~----~------~----~------~--~---