I think you have found a bug with subs. Can you report it in the issues, with the traceback?
Aaron Meurer On Sep 19, 2010, at 11:19 AM, Nicholas Kinar wrote: > Thanks for your response, smichr; that's greatly appreciated. > >> >>> However, this does not seem to work, since the following error is produced: >>> >>> Traceback (most recent call last): >>> File "test-1.py", line 17, in<module> >>> print collect(expr.subs([(a**(n+1), u*a**(n+1)) for a in _]), u) >>> NameError: name '_' is not defined >>> >> The underscore in an interactive session refers to the last output. In >> a script it doesn't have that meaning; it's just a variable name which >> you haven't defined yet. >> > Ah yes, I haven't been using iPython or something similar. > >> You are also missing some of what happened in the example I gave. >> Atoms was used to find the bases of the powers of interest and then >> those, raised to the n+1 power, where replaced with themselves*u. What >> you wrote above should appear something like this in a script: >> >> ... >> u = C.Dummy('u') >> IE_atoms = expr1.atoms(IndexedElement) >> print collect(expr.subs([(a**(n+1), u*a**(n+1)) for a in IE_atoms]), >> u) >> >> > I've tried changing some sections of my script, but I still don't know what I > am doing wrong: > > # begin code > from sympy import * > from sympy.tensor import Indexed, Idx, IndexedElement > > M = Indexed('M') > var('A B C D E') > i,j,n = symbols('i j n', integer = True) > i = 1 > j = 1 > expr = Eq( A*M(i,j)**n + B*M(i+1,j)**(n+1), > C*M(i,j+1)**n + D*M(i,j)**(n+1) + > E*M(i+1,j)**(n+1) ) > expr1 = expr.lhs - expr.rhs > u = Symbol('u', dummy=True) > IE_atoms = expr1.atoms(IndexedElement) > > print collect(expr1.subs([(a**(n+1), u*a**(n+1)) for a in IE_atoms]), u) # > begin code > # end code > > After a few seconds, this script generates a very long output, ending with > the following error: > > RuntimeError: maximum recursion depth exceeded while calling a Python object > > So what would I have to change to make this script work as intended? > > Nicholas > > > > > > > > > > > > > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To post to this group, send email to sy...@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. > -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sy...@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.