SAGE: Is it possible to extract the irreducible factor of a polynomial for the purpose of constructing a Number Field?

1.3k Views Asked by At

I'm in the middle of making a program that tests a certain fact for many number fields. At this current step I get say a hundred polynomials, which are reducible. I want to factor them (over Q), take the irreducible factor, and create a number field using it.

Individually, given the desired polynomial g, I can use the command g.factor() and choose the irreducible factor myself and then make the Number Field, and find the info I want, but I want to make a program to do this for many poly's to make a conjecture. So I want to know if there is a command to extract this irreducible factor of g for use in the "for loop".

Note: -I'm new to making programs (period), so while a for loop may not be the best option, don't give me grief about it.

-I don't want to post the program or be too much more specific because it's a HW assignment and I don't want anyone to give me an answer or a better way to do it. I just want to know if the above is possible and if it's not possible, what are some other workarounds. I've been searching Google for a command, or alternative way, but haven't found anything.

-Noticing that for the range of polynomials I'm starting this for (i.e. of the same form, just varying a the constant with a range command) many have a common factor, so I tried defining h=g/(this particular common factor), and then adding the command: if h.is_irreducible: K.=NumberField(h), BUT, this is not allowable because h is considered in the quotient field the moment I divide. If there is a workaround this way I would be happy too.

Thanks for the help.

P.S. This is my first post on this, and I'm not too familiar with the culture, so please don't be a troll, jerk, diva about my question :)

1

There are 1 best solutions below

1
On

I'm not sure what you mean by "the" irreducible factor, since some polynomials will have many irreducible non-linear (I guess you mean this) factors over $\mathbb{Q}$. But if you know exactly what it looks like, you could use this syntax.

sage: F = (x^2+1)*(x^2+2)
sage: F.factor_list().index((x^2+2,1))
0

Don't forget that the symbolic ring factors over the integers; you'll need to use polynomials rings to get what you want, probably. Naturally, you are right that the for i in list: do something loop syntax is what you want to go through the loop, although "list comprehensions" will end up being nicer in the long run.

Also, if you don't know the exact factor, then you could still search for the form of it by doing something

<inside your loop>
if the_factor_im_looking_at[0].degree(x) == 2:
    do something with it...

I'm giving less detail because you asked for that. Good luck! A little bit of basic programming will go a LONG way for you.