I would be glad to, but I think I need to understand the code better to write a valid test. Should that line get executed any time there is 1/term in the experssion?
On Mon, Sep 7, 2009 at 12:32 PM, Aaron S. Meurer <asmeu...@gmail.com> wrote: > > If you run the coverage script in bin/, you will find that that line > is not covered by the test suite, so it is quite possible that it is > wrong. Indeed, if I make the change you specify, the tests still all > pass. Could you create a patch that fixes it and includes a test? > > Aaron Meurer > On Sep 7, 2009, at 11:23 AM, Ryan Krauss wrote: > > > I think I have stumbled onto a bug in core/mul/_eval_subs. > > > > I have the following expression: > > In [103]: temp > > Out[103]: c3*L**2/(EI*beta**2) > > > > and am trying to substitute a = L**2/EI: > > > > In [104]: temp.subs(L**2/EI, a) > > > > which produces the following traceback: > > > > /home/ryan/git/sympy/sympy/core/mul.pyc in _eval_subs(self, old, new) > > 733 for i in range(o.exp): otemp.append > > (o.base) > > 734 elif o.exp.is_negative: > > --> 735 for i in range(abs(o.exp)): otemp.append > > (1/s.base) > > 736 else: otemp.append(o) > > 737 for s in terms_self: > > > > UnboundLocalError: local variable 's' referenced before assignment > > > > I have not put a lot of effort into disecting the code, but from the > > context it seems like 1/s.base in line 735 should be changed to 1/ > > o.base: > > > > # break up powers, i.e., x**2 -> x*x > > otemp, stemp = [], [] > > for o in terms_old: > > if isinstance(o,Pow) and isinstance(o.exp, Integer): > > if o.exp.is_positive: > > for i in range(o.exp): otemp.append(o.base) > > elif o.exp.is_negative: > > for i in range(abs(o.exp)): otemp.append(1/ > > s.base)#this is line 735 > > else: otemp.append(o) > > for s in terms_self: > > if isinstance(s,Pow) and isinstance(s.exp, Integer): > > if s.exp.is_positive: > > for i in range(s.exp): stemp.append(s.base) > > elif s.exp.is_negative: > > for i in range(abs(s.exp)): stemp.append(1/s.base) > > else: stemp.append(s) > > terms_old = otemp > > terms_self = stemp > > > > > > Making this change leads to the expected result: > > > > In [5]: temp > > Out[5]: c3*L**2/(EI*beta**2) > > > > In [6]: temp.subs(L**2/EI, a) > > Out[6]: a*c3/beta**2 > > > > > > Am I thinking correctly here? > > > > Ryan > > > > > > > > > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---