Hi David! I can only give you a partial answer, and at one point I became totally puzzled, myself. But let's try:
On 23 Okt., 15:16, David Madore <[email protected]> wrote: <snip> > sage: R.<x0,x1,x2> = QQ['x0','x1','x2'] > sage: x3=-(x0+x1+x2) > sage: e = SFAElementary(QQ) > sage: e([1]).expand(4) > x0 + x1 + x2 + x3 > sage: e([1]).expand(4,alphabet=[x0,x1,x2,x3]) No surprise that it does not work, because the optional argument "alphabet" must be formed by alphanumeric data. It is fine to give x0,x1 and x2, because these variables stand "for themselves"; but x3 is -x0-x1-x2, and this is certainly not alphanumeric. You may try to pass it as a string, but the result is not what you want: sage: p = e([1]).expand(4,alphabet=[x0,x1,x2,'x3']) sage: p x0 + x1 + x2 + x3 But at least it enables you to substitute now: sage: p.subs(x3=x3) 0 sage: p(x0,x1,x2,x3) 0 > sage: e([1]).expand(4).subs([x0,x1,x2,x3]) > <snip another long error trace> > AttributeError: 'list' object has no attribute 'iteritems' This is because the argument of subs() must be a dictionary -- you can read the documentation by typing "p.subs?". Note that p.subs(x3=x3) should be as much as giving a dictionary, but see below. > sage: e([1]).expand(4).subs({x0:x0,x1:x1,x2:x2,x3:x3,x4:x4}) > --------------------------------------------------------------------------- > NameError Traceback (most recent call last) > > /usr/src/local/sage-4.1.2/<ipython console> in <module>() > > NameError: name 'x4' is not defined Well, the problem is, as the traceback says, that x4 is not defined. But even omitting it, you get an error: sage: p.subs({x0:x0,x1:x1,x2:x2,x3:x3}) Traceback ... TypeError: keys do not match self's parent Indeed: sage: x0.parent() Multivariate Polynomial Ring in x0, x1, x2 over Rational Field sage: p.parent() Multivariate Polynomial Ring in x0, x1, x2, x3 over Rational Field 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? 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 -~----------~----~----~----~------~----~------~--~---
