very easy polynomial question

90 views
Skip to first unread message

Kevin Buzzard

unread,
Apr 8, 2014, 1:20:23 PM4/8/14
to sage-s...@googlegroups.com
I am new to sage. I am not scared of reading docs for computer programs. I cannot work out how to answer basic questions I have from the sage docs though :-( and it's so easy just to ask for help, so here I am.

Here's my question. I have a polynomial with coefficients in a cyclotomic field and I want to know how to compute the product of that polynomial with all its Galois conjugates (because I want to run newton_slopes on it but the manual is not, as far as I can see, clear on whether this will work, so I'm going to build a polynomial for which I know it will work).

Here's my issue: although I would love to work out how to do this myself by reading the docs, I spent 30 minutes failing and now I have to go and feed my kids :-/ Here is why I failed.

1) I went to http://www.sagemath.org/doc/reference/index.html and typed cyclotomic fields into the quick search box, in an attempt to find a simple page about how to access the Galois group of a cyclotomic field. I got 53 results and none of them seemed to be about cyclotomic fields :-(

2) I gave up on this, created a cyclotomic field K, and typed "K.[tab]" and spotted the answer: K.galois_group() .

3) Now I have my group. Let g be an element. I have my polynomial f. How to hit it with an element of the group? g(f)? No. Probably need to access the coefficients by hand. How do I turn a polynomial into a list of coefficients? How do I turn a list of coefficients into a polynomial? I search the sage docs for "polynomial". Am I being naive here? If I were searching the python docs for something, I would probably find a page about that something, containing explanations of how to create the something and how to manipulate it. The search for polynomial in the sage docs gives me unusable results. I give up with the docs again.

4) f.[tab] tells me that it's f.coefficients() I'm after.

5) I manage to hit the list of coefficients with the element of Galois!

6) Now I have to turn the new list of coefficients back into a polynomial. And now I'm in trouble because I can't use the tab trick any more and I don't understand the docs. Of course I can try and remind myself how python lists work (from the python manual :-/ ) and then just build the conjugate by summing the conjugates of the coefficients and multiplying by powers of x. But surely there is a command which does this and not only do I not know the command, I don't know how to find it out without simply asking. And to be honest I am not 100% confident that I will be able to create sum_i a_i x^i in sage because I am still a bit unsure about x and x^i at this point (although probably more reading the manual will sort this out for me).

So the question I actually want to know the answer to is how to compute prod_{g in G}g(f) in sage, G a Galois group, f a polynomial. But the question I should really be told the answer to is how I am supposed to be using the sage manual to answer my questions, because when the tab trick doesn't work I am lost.

Kevin

William Stein

unread,
Apr 8, 2014, 4:00:27 PM4/8/14
to sage-support
On Tue, Apr 8, 2014 at 10:20 AM, Kevin Buzzard
<kevin.m...@gmail.com> wrote:
> I am new to sage. I am not scared of reading docs for computer programs. I
> cannot work out how to answer basic questions I have from the sage docs
> though :-( and it's so easy just to ask for help, so here I am.
>
> Here's my question. I have a polynomial with coefficients in a cyclotomic
> field and I want to know how to compute the product of that polynomial with
> all its Galois conjugates (because I want to run newton_slopes on it but the
> manual is not, as far as I can see, clear on whether this will work, so I'm
> going to build a polynomial for which I know it will work).

The line you want is

h = prod(R([sigma(a) for a in f.list()]) for sigma in G.list()); h

Here's a complete example:

K.<z> = CyclotomicField(5)
R.<x> = K[]
f = (x-(z^3 + 2*z^2 + z + 2))^2*(x - 5*z)
f.newton_slopes(11) # not useful... / wrong?

G = K.galois_group()
h = prod(R([sigma(a) for a in f.list()]) for sigma in G.list()); h
h.newton_slopes(11)

William
> --
> 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/d/optout.



--
William Stein
Professor of Mathematics
University of Washington
http://wstein.org

Nils Bruin

unread,
Apr 8, 2014, 4:55:49 PM4/8/14
to sage-s...@googlegroups.com
On Tuesday, April 8, 2014 1:00:27 PM UTC-7, William wrote:
On Tue, Apr 8, 2014 at 10:20 AM, Kevin Buzzard
<kevin.m...@gmail.com> wrote:
> I am new to sage. I am not scared of reading docs for computer programs. I
> cannot work out how to answer basic questions I have from the sage docs
> though :-( and it's so easy just to ask for help, so here I am.
>
> Here's my question. I have a polynomial with coefficients in a cyclotomic
> field and I want to know how to compute the product of that polynomial with
> all its Galois conjugates (because I want to run newton_slopes on it but the
> manual is not, as far as I can see, clear on whether this will work, so I'm
> going to build a polynomial for which I know it will work).

The line you want is

  h = prod(R([sigma(a) for a in f.list()]) for sigma in G.list()); h

Of, if you want to be able to do these computations for non-galois extensions, you can use that a norm computation boils down to taking a resultant with the appropriate minimal polynomial. This example also highlights how sage's coercion discovery based on variable names can sometimes be very convenient (it also highlights the pain of having lots of different quantities lying around with the same print name):


 K.<z> = CyclotomicField(5)
R.<x> = K[]
f = (x-(z^3 + 2*z^2 + z + 2))^2*(x - 5*z)
Qxz=QQ['x,z']
F=Qxz(f)                       #this conveniently lifts z to a transcendental in Q[x,z]
G=z.minpoly()(Qxz.1)    #getting the minimal polynomial expressed seems a little more painful
H=F.resultant(G,Qxz.1)  #but then taking the norm is pretty quick
h=QQ['x'](H)                  #but we have to do some work to get it as a univariate poly again

One would think that this should work with nested univariate polynomial rings too: QQ['x']['z'], but unfortunately it doesn't.

Nils Bruin

unread,
Apr 8, 2014, 7:05:45 PM4/8/14
to sage-s...@googlegroups.com
On Tuesday, April 8, 2014 1:55:49 PM UTC-7, Nils Bruin wrote:
F=Qxz(f)                       #this conveniently lifts z to a transcendental in Q[x,z]
 
Oops, that only works because of the last-resort attempt of converting f to a string and then feeding the string to Qxz. One probably shouldn't rely on such code in production situations. You'd be better off using

F=Qxz({ (degx,degz) :cfz for degx,cfx in enumerate(f.list()) for degz,cfz in enumerate(cfx.list())})

which won't win any prizes for legibility and only qualifies as a one-liner in the technical sense, but it is much faster than the string-based conversion.

John Cremona

unread,
Apr 9, 2014, 3:59:11 AM4/9/14
to SAGE support
These clever hacks do not take away from Kevin's main points: that
getting field automorphisms to act on objects like polynomials over
the field, with related functionality (norms etc); and that basic
functions related to polynomials (extracting coefficients and creating
a poly from a list of coeffs) should not be hard to find in the
documentation.

John
Message has been deleted

Kevin Buzzard

unread,
Apr 9, 2014, 5:45:39 AM4/9/14
to sage-s...@googlegroups.com
Thanks William and Nils!

So now I can write better code than yesterday and, as John says, the only remaining question is how someone with no sage experience is supposed to work out for themselves that if R is a polynomial ring then R([1,2,3]) is the way to create 3x^2+2x+1.
Let me stress that I am not ruling out that there is a sensible algorithmic way to do this from the docs! I'm just saying I couldn't figure out how to use the docs to answer this sort of question yesterday, whereas my experience with other programming languages is that in the end I find a resource (possibly via google) which, whenever you want to know about how to know about foobars, will offer you a page titled "foobars" with an essentially complete list of how to create foobars, coerce them to and from other data structures, and manipulate them. I'm not talking about a tutorial with examples, I'm talking about a resource giving essentially complete documentation about certain common objects.

Of course it could well be just a matter of experience. For all I know, it might be a general thing in sage that if the parent of f is R, and if S is a bunch of data that can be used to build an f, then R(S) will pretty much always work. If this is the case then I should just do some more coding until I get the hang of it.

Kevin

William Stein

unread,
Apr 9, 2014, 8:05:19 AM4/9/14
to sage-support support


On Apr 9, 2014 1:21 AM, "Kevin Buzzard" <kevin.m...@gmail.com> wrote:
>
> Thanks William and Niels!


>
> So now I can write better code than yesterday and, as John says, the only remaining question is how someone with no sage experience is supposed to work out for themselves that if R is a polynomial ring then R([1,2,3]) is the way to create 3x^2+2x+1.
> Let me stress that I am not ruling out that there is a sensible algorithmic way to do this from the docs! I'm just saying I couldn't figure out how to use the docs to answer this sort of question yesterday, whereas my experience with other programming languages is that in the end I find a resource (possibly via google) which, whenever you want to know about how to know about foobars, will offer you a page titled "foobars" with an essentially complete list of how to create foobars, coerce them to and from other data structures, and manipulate them. I'm not talking about a tutorial with examples, I'm talking about a resource giving essentially complete documentation about certain common objects.
>
> Of course it could well be just a matter of experience. For all I know, it might be a general thing in sage that if the parent of f is R, and if S is a bunch of data that can be used to build an f, then R(S) will pretty much always work. If this is the case then I should just do some more coding until I get the hang of it.
>

This is the case in Python more generally.  R(S) in Python is supposes to be the analog of R!S in Magma.

> Kevin
>
>
>
> On Wednesday, 9 April 2014 08:59:11 UTC+1, John Cremona wrote:
>>

Nils Bruin

unread,
Apr 9, 2014, 5:51:25 PM4/9/14
to sage-s...@googlegroups.com
On Wednesday, April 9, 2014 2:45:39 AM UTC-7, Kevin Buzzard wrote:
Thanks William and Nils!

So now I can write better code than yesterday and, as John says, the only remaining question is how someone with no sage experience is supposed to work out for themselves that if R is a polynomial ring then R([1,2,3]) is the way to create 3x^2+2x+1.

This is something we could do better on. I think "R?" would be a good place to display such facts. However, the only help displayed there is completely generic stuff from the category framework. The help from "R._element_constructor_?" is much more topical (although it doesn't happen to have the `R([1,2,3])` example, it could easily be added there), but that of course is completely non-discoverable.

The problem (and this hopefully can be fixed):

 - "R?" displays the docstring of the class itself, which could contain specific things (but presently doesn't because it is more concerned with construction of polynomial rings than with construction of elements in it)

 - "R?" also displays the docstring of `R.__call__`, because that WOULD normally be a good place to document element constructions. However, with the current coercion framework, the routine there tends to be a completely generic, technical thing that defers to `R._element_constructor_`, which does have specific documentation, but is completely undiscoverable.

Oddly enough, the more advanced parent, category, and coercion framework makes our documentation system worse.
Reply all
Reply to author
Forward
0 new messages