The problem is that the iterable() function in compatibility thinks
that y is iterable, so it's trying to iterate through y. The fix is to
add IndexedBase to the set of ignored iterables in the function.

Aaron Meurer

On Sat, Jan 25, 2014 at 5:04 AM, Björn Dahlgren <bjo...@gmail.com> wrote:
> Hi!
>
> while using the Indexed class from sympy.tensor I have run into the
> following problem:
>
> cse(...) fails for expressions having "Indexed" instances. They are not
> handled correctly in opt_cse() in cse_main.py
> A possible work-around is to substitute the Indexed instances with dummies,
> perform the CSE elimination and then
> resubstitute the dummies for the indexed symbols. But this is not pretty and
> I think that cse(...) should handle this
> on its own.
>
> Example:
>
>     from sympy import *
>
>     len_y = 5
>     y = IndexedBase('y', shape=(len_y,))
>     x = IndexedBase('x', shape=(len_y,))
>     Dy = IndexedBase('Dy', shape=(len_y-1,))
>     i = Idx('i', len_y-1)
>
>     expr1 = (y[i+1]-y[i])/(x[i+1]-x[i])
>     expr2 = 1/(x[i+1]-x[i])
>     print(cse([expr1, expr2]))
>
> this will cause an infinite recursive call stack to _find_opts raising:
>     RuntimeError: maximum recursion depth exceeded in __instancecheck__
>
>
> Does anybody know what the best approach here would be? Add something to the
> Indexed class or modify
> opt_cse?
>
> Best regards
> /Björn
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+unsubscr...@googlegroups.com.
> To post to this group, send email to sympy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to