converting integer vectors to monomials

113 views
Skip to first unread message

Ursula Whitcher

unread,
Oct 1, 2013, 8:46:29 AM10/1/13
to sage-s...@googlegroups.com
I recently learned that if A is a polynomial ring in Sage in variables x, y, and z, the command

A({tuple([1,1,1]):1})

returns x*y*z.

Can somebody explain this syntax to me?  I understand tuple([1,1,1]), but what are the curly brackets and the colon doing?

Also, is there a reason that A.monomial([1,1,1]) does not return the same result?

--Ursula.

John Cremona

unread,
Oct 1, 2013, 9:51:32 AM10/1/13
to SAGE support
On 1 October 2013 13:46, Ursula Whitcher <whit...@uwec.edu> wrote:
> I recently learned that if A is a polynomial ring in Sage in variables x, y,
> and z, the command
>
> A({tuple([1,1,1]):1})
>
> returns x*y*z.
>
> Can somebody explain this syntax to me? I understand tuple([1,1,1]), but
> what are the curly brackets and the colon doing?

The argument is a python dict, which you should read up about for more
details. It's a collection of key:value pairs. Here the keys are
tuples giveing the vector of exponents and the values are the
coefficients. In your example there is only one term, the exponent
tuple is [1,1,1] and the coefficient is 1. You could also write

sage: A({(1,1,1):1})

since the key must be a tuple like (1,1,1) and not a list like [1,1,1]
(these are Python basics).

>
> Also, is there a reason that A.monomial([1,1,1]) does not return the same

You did not make precise what type your A is but if I define

sage: A.<x,y,z> = QQ[]
sage: A
Multivariate Polynomial Ring in x, y, z over Rational Field
sage: type(A)
<type 'sage.rings.polynomial.multi_polynomial_libsingular.MPolynomialRing_libsingular'>

then A has no method called "monomial".

John Cremona

> result?
>
> --Ursula.
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-support...@googlegroups.com.
> To post to this group, send email to sage-s...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sage-support.
> For more options, visit https://groups.google.com/groups/opt_out.

Ursula Whitcher

unread,
Oct 1, 2013, 10:58:51 AM10/1/13
to sage-s...@googlegroups.com
On 10/1/2013 8:51 AM, John Cremona wrote:

>> Can somebody explain this syntax to me? I understand tuple([1,1,1]), but
>> what are the curly brackets and the colon doing?
>
> The argument is a python dict, which you should read up about for more
> details.

Thanks, that's exactly what I needed to know!

>> Also, is there a reason that A.monomial([1,1,1]) does not return the same result?
>
> You did not make precise what type your A is but if I define
>
> sage: A.<x,y,z> = QQ[]
> sage: A
> Multivariate Polynomial Ring in x, y, z over Rational Field
> sage: type(A)
> <type 'sage.rings.polynomial.multi_polynomial_libsingular.MPolynomialRing_libsingular'>
>
> then A has no method called "monomial".

Very true. I suppose what I was asking was, would it be useful to human
beings who are not me to wrap the python-esque syntax in a Sage
function? And if so, is "monomial" the right thing to call the
function, or should A.monomial() naturally refer to some other operation?

--Ursula.

John Cremona

unread,
Oct 1, 2013, 12:13:48 PM10/1/13
to SAGE support
I would have thought that A.monomial(L) where L is either a listor
tuple of the right length would be a very natural thing to add for
multivariate polynomial rings. You could define your own as a
work-around:

sage: def monomial(A,L):
return A({tuple(L): A.base_ring().one_element()})

sage: monomial(A,[2,3,4])
x^2*y^3*z^4

John
Reply all
Reply to author
Forward
0 new messages