Hi David! Here is a follow-up.
On Oct 24, 8:48 am, Simon King <[email protected]> wrote: [...] > Here comes the point where I am puzzled. Can please someone explain > what happens here? > > I thought that p.subs(x3=x3) is equivalent to p.subs({'x3':x3}). But > in contrast to any other example that I met so far, one gets: > > sage: p.subs({'x3':x3}) > Traceback > ... > TypeError: keys do not match self's parent > > How is it possible that p.subs(x3=x3) works while p.subs({'x3':x3}) > doesn't? I thought this is how Python works? At http://groups.google.com/group/sage-devel/browse_thread/thread/e8cd8d6f4e334141 I raised that question as well, and Martin Albrecht explained it: * We have the signature subs(self, fixed, **kw=None) * Doing p.subs({'x3':x3}), the dictionary {'x3':x3} is assigned to the argument "fixed". But if "fixed" gets a dictionary, then the dict keys must be variables of the polynomial. Here, the key is a string, therefore: error! * If you want to work with a dictionary, it should be p.subs(** {'x3':x3}). Then, the dictionary is assigned to the argument "kw", and here string keys are fine: sage: R.<x0,x1,x2> = QQ['x0','x1','x2'] sage: x3=-(x0+x1+x2) sage: e = SFAElementary(QQ) sage: p = e([1]).expand(4) sage: p.subs(**{'x3':x3}) 0 Pretty tricky! :( One more remark. When you do p.subs({x0:1}), there will also be an error, namely sage: p.subs({x0:1}) Traceback ... TypeError: keys do not match self's parent The reason is that x0 belongs to R, but the variable x0 from p belongs to a different polynomial ring: sage: p.lm() x0 sage: p.lm().parent() Multivariate Polynomial Ring in x0, x1, x2, x3 over Rational Field sage: x0.parent() Multivariate Polynomial Ring in x0, x1, x2 over Rational Field The two x0's are equal, but not identical: sage: p.lm() == x0 True sage: p.lm() is x0 False So: p.subs({x0:1}) tries to replace x0. But x0 is an element of R by your definition and is *not* the same as the variable x0 of p. Therefore the error. Cheers, Simon --~--~---------~--~----~------------~-------~--~----~ 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/sage-support URL: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---
