Status: Accepted
Owner: ----
Labels: Type-Defect Priority-High
New issue 1527 by ondrej.certik: bug in the printer (function + subs)
http://code.google.com/p/sympy/issues/detail?id=1527
In [1]: F = Function('F')
In [2]: x, y, t = symbols('x y t')
In [3]: a = Symbol('a', Real=True)
In [4]: eq = Derivative(F(x, t), x)
In [5]: eq
Out[5]:
d
──(F(x, t))
dx
In [6]: pat = -33*t*x + F(x + exp(-t))
In [7]: pat
Out[7]:
⎛ -t⎞
-33⋅t⋅x + F⎝x + ℯ ⎠
In [8]: sub = eq.subs(F(x, t), pat)
In [9]: sub
Out[9]:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/home/ondrej/repos/sympy/<ipython console> in <module>()
/home/ondrej/usr/lib/python/IPython/Prompts.pyc in __call__(self, arg)
550
551 # and now call a possibly user-defined print mechanism
--> 552 manipulated_val = self.display(arg)
553
554 # user display hooks can change the variable to be
stored in
/home/ondrej/usr/lib/python/IPython/Prompts.pyc in _display(self, arg)
576 return IPython.generics.result_display(arg)
577 except TryNext:
--> 578 return self.shell.hooks.result_display(arg)
579
580 # Assign the default display method:
/home/ondrej/usr/lib/python/IPython/hooks.pyc in __call__(self, *args, **kw)
137 #print "prio",prio,"cmd",cmd #dbg
138 try:
--> 139 ret = cmd(*args, **kw)
140 return ret
141 except ipapi.TryNext, exc:
/home/ondrej/repos/sympy/sympy/interactive/__init__.pyc in
result_display(self, arg)
24 """
25 if self.rc.pprint:
---> 26 out = stringify_func(arg)
27
28 if '\n' in out:
/home/ondrej/repos/sympy/<input> in <lambda>(arg)
/home/ondrej/repos/sympy/sympy/printing/pretty/pretty.pyc in pretty(expr,
profile, **kargs)
610 try:
611 pp = PrettyPrinter(profile)
--> 612 return pp.doprint(expr)
613 finally:
614 pretty_use_unicode(uflag)
/home/ondrej/repos/sympy/sympy/printing/pretty/pretty.pyc in doprint(self,
expr)
29
30 def doprint(self, expr):
---> 31 return self._print(expr).render(**self._settings)
32
33 # empty op so _print(stringPict) returns the same
/home/ondrej/repos/sympy/sympy/printing/printer.pyc in _print(self, expr,
*args)
212 printmethod = '_print_' + cls.__name__
213 if hasattr(self, printmethod):
--> 214 res = getattr(self, printmethod)(expr, *args)
215 if res is None:
216 raise RuntimeError("Printing method '%s'
did return None"%\
/home/ondrej/repos/sympy/sympy/printing/pretty/pretty.pyc in
_print_Add(self, sum)
401 def _print_Add(self, sum):
402 args = list(sum.args)
--> 403 args.sort(Basic._compare_pretty)
404 pforms = []
405 for x in args:
/home/ondrej/repos/sympy/sympy/core/basic.pyc in _compare_pretty(a, b)
531 # because 1 = x^0, but 0 2 3 4 ... = x^1
532 p1, p2, p3 = Wild("p1"), Wild("p2"), Wild("p3")
--> 533 r_a = a.match(p1 * p2**p3)
534 r_b = b.match(p1 * p2**p3)
535 if r_a is not None and r_b is not None:
/home/ondrej/repos/sympy/sympy/core/basic.pyc in match(self, pattern)
1432 """
1433 pattern = sympify(pattern)
-> 1434 return pattern.matches(self, {})
1435
1436 def solve4linearsymbol(eqn, rhs, symbols = None):
/home/ondrej/repos/sympy/sympy/core/mul.pyc in matches(pattern, expr,
repl_dict, evaluate)
549 expr = sympify(expr)
550 if pattern.is_commutative and expr.is_commutative:
--> 551 return AssocOp._matches_commutative(pattern, expr,
repl_dict, evaluate)
552 # todo for commutative parts, until then use the default
matches method for non-commutative products
553 return Basic.matches(pattern, expr, repl_dict, evaluate)
/home/ondrej/repos/sympy/sympy/core/operations.pyc in
_matches_commutative(pattern, expr, repl_dict, evaluate)
134 d1 = w.matches(last_op, repl_dict)
135 if d1 is not None:
--> 136 d2 = pattern.matches(expr, d1, evaluate=True)
137 if d2 is not None:
138 return d2
/home/ondrej/repos/sympy/sympy/core/mul.pyc in matches(pattern, expr,
repl_dict, evaluate)
549 expr = sympify(expr)
550 if pattern.is_commutative and expr.is_commutative:
--> 551 return AssocOp._matches_commutative(pattern, expr,
repl_dict, evaluate)
552 # todo for commutative parts, until then use the default
matches method for non-commutative products
553 return Basic.matches(pattern, expr, repl_dict, evaluate)
/home/ondrej/repos/sympy/sympy/core/operations.pyc in
_matches_commutative(pattern, expr, repl_dict, evaluate)
94 pat = pattern
95 for old,new in repl_dict.items():
---> 96 pat = pat.subs(old, new)
97 if pat != pattern:
98 return pat.matches(expr, repl_dict)
/home/ondrej/repos/sympy/sympy/core/basic.pyc in subs(self, *args)
1037 elif len(args) == 2:
1038 old, new = args
-> 1039 return self._subs_old_new(old, new)
1040 else:
1041 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)
1046 old = sympify(old)
1047 new = sympify(new)
-> 1048 return self._eval_subs(old, new)
1049
1050 def _eval_subs(self, old, new):
/home/ondrej/repos/sympy/sympy/core/mul.pyc in _eval_subs(self, old, new)
752 ret_set = self_set - old_set
753 return Mul(new, coeff_self/coeff_old,
*[s._eval_subs(old, new) for s in ret_set])
--> 754 return self.__class__(*[s._eval_subs(old, new) for s in
self.args])
755
756 def _eval_nseries(self, x, x0, n):
/home/ondrej/repos/sympy/sympy/core/power.pyc in _eval_subs(self, old, new)
213 coeff2,terms2 = (self.exp *
C.log(self.base)).as_coeff_terms()
214 if terms1==terms2: return new ** (coeff1/coeff2) #
(x**(2*y)).subs(exp(3*y*log(x)),z) -> z**(2/3*y)
--> 215 return self.base._eval_subs(old, new) **
self.exp._eval_subs(old, new)
216
217 def as_powers_dict(self):
/home/ondrej/repos/sympy/sympy/core/function.pyc in _eval_subs(self, old,
new)
617 if self==old:
618 return new
--> 619 return Derivative(*map(lambda x: x._eval_subs(old, new),
self.args), **{'evaluate': True})
620
621 def matches(pattern, expr, repl_dict={}, evaluate=False):
/home/ondrej/repos/sympy/sympy/core/function.pyc in __new__(cls, expr,
*symbols, **assumptions)
576 s = sympify(s)
577 if not isinstance(s, Symbol):
--> 578 raise ValueError('Invalid literal: %s is not a
valid variable' % s)
579 if not expr.has(s):
580 return S.Zero
ValueError: Invalid literal: x + exp(-t) is not a valid variable
--
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
-~----------~----~----~----~------~----~------~--~---