I think what you are getting is expected behavior.  Remember that when you 
switch n and n + 1, you are switching the side of the equation that they will 
end up on.  So in the first one, you have all terms with n on the right-hand 
side, and in the second one, you have all the terms with n + 1 on the 
right-hand side.  If you have something like p[1, 2, n]*p[1, 2, n + 1], the one 
that you choose to collect with respect to in your script (Idx(n) or Idx(n + 
1)) will determine the tie breaker.  

Aaron Meurer

On Oct 8, 2010, at 1:34 PM, Nicholas Kinar wrote:

>> 
>>>> Here's a short comment: using Idx(n+1) seems to work a little better for 
>>>> me, since I've noticed that if I use Idx(n) with a very complicated 
>>>> expression, there is a possibility of terms with (n+1) indices ending up 
>>>> on the same side as the (n) indices.
>>> That sounds like a bug.  Can you give a specific example of an expression 
>>> that does that?
>>> 
>>> Aaron Meurer
>>> 
>> 
>> Sure, I can attempt to give an example.  I've been unable to reproduce this 
>> behavior with a simple expression, so I am pasting below the full expression 
>> that I've been using.  Of course, it may be something that I'm doing wrong, 
>> so I'm reluctant to cry wolf.  But in a similar fashion to working with a 
>> building, if the pipes are a bit leaky, perhaps a small patch job would be 
>> beneficial if warranted.
>> 
> 
> Okay, here is a test program with a much simpler expression.  The output of 
> the program shows what I suspect to be right and wrong behavior.  The 
> questioned behavior seems to occur when two indexed terms are multiplied 
> together:
> 
> This appears to be wrong:
> (p[1, 2, 1 + n], -p[1, 2, n] + p[2, 2, n]*p[1, 2, 1 + n])
> This appears to be right:
> (-p[1, 2, n], p[2, 2, n]*p[1, 2, 1 + n] + p[1, 2, 1 + n])
> 
> 
> Nicholas
> 
> 
> #begin sample code
> from sympy import *
> from sympy.tensor import Indexed, Idx, IndexedBase
> from sympy.matrices import *
> 
> p = IndexedBase('p')
> var('deltax deltay delta deltat A B')
> i,j,n = symbols('i j n', integer = True)
> 
> 
> def test_as_independent(expr):
>    expr0 = expr.lhs - expr.rhs
>    expr1 = expr0.as_independent(*filter(lambda t: t.args[-1] == Idx(n), 
> expr0.atoms(Indexed) ) )
>    print 'This appears to be wrong: '
>    print expr1
>    print 'This appears to be right: '
>    expr2 = expr0.as_independent(*filter(lambda t: t.args[-1] == Idx(n+1), 
> expr0.atoms(Indexed) ) )
>    print expr2
> 
> 
> def run_scheme():
>    expr1 = Eq( p[1,2,n+1] + p[2,2,n]*p[1,2,n+1], p[1,2,n])
>    test_as_independent(expr1)
> 
> def main():
>    run_scheme()
> 
> if __name__ == "__main__":
>    main()
> # end sample code
> 
> 
> 
> -- 
> 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.
> 

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

Reply via email to