On Wed, Jun 3, 2009 at 7:03 PM, David Joyner <wdjoy...@gmail.com> wrote:
>
> On Wed, Jun 3, 2009 at 9:20 PM, James Parson <par...@hood.edu> wrote:
>>
>>> > Here is a variant on the original question: suppose I wanted to write
>>> > a line that creates a polynomial ring whose variables are a_{ij} for i
>>> > +j<=d. How should I do it? I might want to set this up, for example,
>>>
>>> sage: Inds = CartesianProduct(range(5), range(5))
>>> sage: vars = ["a"+str(i)+str(j) for i,j in Inds]
>>> sage: PolynomialRing(QQ,25,vars)
>>> Multivariate Polynomial Ring in a00, a01, a02, a03, a04, a10, a11,
>>> a12, a13, a14, a20, a21, a22, a23, a24, a30, a31, a32, a33, a34, a40,
>>> a41, a42, a43, a44 over Rational Field
>>
>> Thanks again for the suggestions. I have one more foolish question
>> about this sort of construction: if I type those lines into Sage and
>> then type something like
>>
>> a00 + a11,
>>
>> I get an error
>>
>> NameError: name 'a00' is not defined.
>>
>> I read about this sort of thing in the Sage Tutorial, but I couldn't
>> understand it well enough to figure out how to name the variables what
>> I wanted. Is there any easy way to do this?
>
>
> Sorry, I'm stuck here too. Can you just write R("a00")+R("a11") instead?
>
>

Two options:

(1) Just type inject_on() and then aij will be defined:

sage: inject_on()
Redefining: FiniteField Frac FractionField FreeMonoid GF
LaurentSeriesRing NumberField PolynomialRing quo quotient
sage: Inds = CartesianProduct(range(5), range(5))
sage: vars = ["a"+str(i)+str(j) for i,j in Inds]
sage: PolynomialRing(QQ,25,vars)
Defining a00, a01, a02, a03, a04, a10, a11, a12, a13, a14, a20, a21,
a22, a23, a24, a30, a31, a32, a33, a34, a40, a41, a42, a43, a44
Multivariate Polynomial Ring in a00, a01, a02, a03, a04, a10, a11,
a12, a13, a14, a20, a21, a22, a23, a24, a30, a31, a32, a33, a34, a40,
a41, a42, a43, a44 over Rational Field
sage: a00 + a01
a00 + a01
sage: (a00 + a01)^3
a00^3 + 3*a00^2*a01 + 3*a00*a01^2 + a01^3

(2) Edit the globals dictionary:

sage: Inds = CartesianProduct(range(5), range(5))
sage: vars = ["a"+str(i)+str(j) for i,j in Inds]
sage: R = PolynomialRing(QQ,25,vars)
sage: for v in R.gens(): globals()[str(v)] = v
....:
sage: (a00 + a01)^3
a00^3 + 3*a00^2*a01 + 3*a00*a01^2 + a01^3

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to