[sympy] Sum bug?

2010-03-04 Thread archeryguru2000
In running a program I've written, I added a summation as follows: >>> Sum((i-i%2)/2, (i, 1, 10)).doit() It's actually a liitle more involved than that, but either way below is the output to that command: --- TypeError

Re: [sympy] Sum bug?

2010-03-04 Thread Ondrej Certik
On Thu, Mar 4, 2010 at 8:46 AM, archeryguru2000 wrote: > In running a program I've written, I added a summation as follows: > Sum((i-i%2)/2, (i, 1, 10)).doit() > > It's actually a liitle more involved than that, but either way below > is the output to that command: > > ---

Re: [sympy] Sum bug?

2010-03-04 Thread Chad File
Ondrej, thanks for the reply. What I mean is exactly that, i%2.  If 'i' is even, i%2 = 0, if 'i' is odd, i%2 = 1.  How else would one write that? I have a very large program that actually uses this 'remainder' operator many times.  However, only in the summation do I have any problems with it

Re: [sympy] Sum bug?

2010-03-04 Thread Ondrej Certik
On Thu, Mar 4, 2010 at 10:10 AM, Chad File wrote: > Ondrej, thanks for the reply. > > What I mean is exactly that, i%2.  If 'i' is even, i%2 = 0, if 'i' is odd, > i%2 = 1.  How else would one write that? > > I have a very large program that actually uses this 'remainder' operator > many times.  Ho

Re: [sympy] Sum bug?

2010-03-04 Thread Ondrej Certik
On Thu, Mar 4, 2010 at 10:21 AM, Ondrej Certik wrote: > On Thu, Mar 4, 2010 at 10:10 AM, Chad File wrote: >> Ondrej, thanks for the reply. >> >> What I mean is exactly that, i%2.  If 'i' is even, i%2 = 0, if 'i' is odd, >> i%2 = 1.  How else would one write that? >> >> I have a very large program

Re: [sympy] Sum bug?

2010-03-04 Thread Chad File
Ondrej, The only opportunity with the below statement Sum(f(i), (i, 1, 2*n)) = Sum(f(2*k)+f(2*k-1), (k, 1, n)) is that 2*n would have to be even.  And in my case it is certainly not always true.  This summation is part of a function that is called many hundreds of times.  And each time it is

Re: [sympy] Sum bug?

2010-03-04 Thread Ondrej Certik
On Thu, Mar 4, 2010 at 11:40 AM, Chad File wrote: > Ondrej, > The only opportunity with the below statement > > Sum(f(i), (i, 1, 2*n)) = Sum(f(2*k)+f(2*k-1), (k, 1, n)) > > is that 2*n would have to be even.  And in my case it is certainly not > always true.  This summation is part of a function

Re: [sympy] Sum bug?

2010-03-04 Thread Aaron S. Meurer
You are making your life unnecessarily difficult. The standard way to alternate between numbers is to use (-1)**i. In this case, you could do ((-1)**(i+1) + 1)/2. Another option is to use sin or cos, for example, here you could use abs(sin(pi/2*i)). With that being said, maybe we should creat

Re: [sympy] Sum bug?

2010-03-04 Thread Chad File
Thank Aaron, I'm not sure why I didn't think of (-1)**i in the first place (or the cos/sin equivalent).  I have to run for now, but tomorrow morning I'll give that a shot. Thanks, -- ~~archery~~ Aaron S. Meurer wrote: You are making your life unnecessarily difficult. The standard way t

Re: [sympy] Sum bug?

2010-03-04 Thread Ondrej Certik
Indeed, here is how to do your sum: In [15]: Sum((i-((-1)**(i+1) + 1)/2)/2, (i, 1, 10)).doit() Out[15]: 25 e.g. just replace i%2 by ((-1)**(i+1) + 1)/2 and things just work. Thanks Aaron! Ondrej On Thu, Mar 4, 2010 at 12:30 PM, Chad File wrote: > Thank Aaron, > I'm not sure why I didn't think