Ask Your Question
1

Number of factors of a polynomial

asked 2016-09-23 17:41:06 +0100

nebuckandazzer gravatar image

updated 2016-09-23 17:42:25 +0100

Given a polynomial f, the command f.factor() gives the factorization of f. I want to find out the number of factors of f. Is there any command for that ?

The polynomial ring is assumed to be ZZ[x].

edit retag flag offensive close merge delete

Comments

len(f.factor())

FrédéricC gravatar imageFrédéricC ( 2016-09-23 18:19:20 +0100 )edit

1 Answer

Sort by » oldest newest most voted
3

answered 2016-09-23 22:03:59 +0100

tmonteil gravatar image

The factorization of a polynomial is an object with its methods:

sage: R.<x> = ZZ[]
sage: f = (x-1)^3*(x+2) ; f
x^4 - x^3 - 3*x^2 + 5*x - 2

sage: F = f.factor() ; F
(x + 2) * (x - 1)^3
sage: type(F)
<class 'sage.structure.factorization.Factorization'>

So, this objects has its methods, which you can call more or less directely:

sage: F.__len__()
2
sage: len(F)
2
sage: list(F)
[(x + 2, 1), (x - 1, 3)]
sage: dict(F)
{x - 1: 3, x + 2: 1}

You question is a bit ambiguous, since it is not clear whether you want the number of factors counting with or without cultiplicity.

Without multiplicity, you canjust call the length:

sage: len(F)
2
sage: len(dict(F))
2

With multiplicity, you have to sum the multipicities of all factors:

sage: dict(F).values()
[1, 3]
sage: sum(dict(F).values())
4
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-09-23 17:41:06 +0100

Seen: 1,273 times

Last updated: Sep 23 '16