Status: Accepted
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 1581 by ondrej.certik: subs(dict()) sometimes breaks
http://code.google.com/p/sympy/issues/detail?id=1581

In [1]: N = 3

In [2]: (1 + x).subs(dict(N=3))
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (24, 0))

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)

/home/ondrej/repos/sympy/<ipython console> in <module>()

/home/ondrej/repos/sympy/sympy/core/basic.pyc in subs(self, *args)
    1021             sequence = args[0]
    1022             if isinstance(sequence, dict):
-> 1023                 return self._subs_dict(sequence)
    1024             elif isinstance(sequence, (list, tuple)):
    1025                 return self._subs_list(sequence)

/home/ondrej/repos/sympy/sympy/core/basic.pyc in _subs_dict(self, sequence)
    1111                 subst.append(pattern)
    1112         subst.reverse()
-> 1113         return self._subs_list(subst)
    1114
    1115     def _seq_subs(self, old, new):

/home/ondrej/repos/sympy/sympy/core/basic.pyc in _subs_list(self, sequence)
    1064         for old, new in sequence:
    1065             if hasattr(result, 'subs'):
-> 1066                 result = result.subs(old, new)
    1067         return result
    1068

/home/ondrej/repos/sympy/sympy/core/basic.pyc in subs(self, *args)
    1028         elif len(args) == 2:
    1029             old, new = args
-> 1030             return self._subs_old_new(old, new)
    1031         else:
    1032             raise TypeError("subs accepts either 1 or 2 arguments")

/home/ondrej/repos/sympy/sympy/core/cache.pyc in wrapper(*args, **kw_args)
      83         except KeyError:
      84             pass
---> 85         func_cache_it_cache[k] = r = func(*args, **kw_args)
      86         return r
      87

/home/ondrej/repos/sympy/sympy/core/basic.pyc in _subs_old_new(self, old,  
new)
    1037         old = sympify(old)
    1038         new = sympify(new)
-> 1039         return self._eval_subs(old, new)
    1040
    1041     def _eval_subs(self, old, new):

/home/ondrej/repos/sympy/sympy/core/add.pyc in _eval_subs(self, old, new)
     293             return self.__class__(*[s._eval_subs(old, new) for s in
self.args ])
     294         coeff_self, factors_self = self.as_coeff_factors()
--> 295         coeff_old, factors_old = old.as_coeff_factors()
     296         if factors_self == factors_old: # (2+a).subs(3+a,y) -> 2-3+y
     297             return Add(new, coeff_self, -coeff_old)

AttributeError: 'function' object has no attribute 'as_coeff_factors'





but this works:

In [3]: (1 + x).subs({N: 3})
Out[3]: 1 + x


--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sympy-issues" 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-issues?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to