Ask Your Question
1

Number of factors of a polynomial

asked 8 years ago

nebuckandazzer gravatar image

updated 8 years ago

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].

Preview: (hide)

Comments

len(f.factor())

FrédéricC gravatar imageFrédéricC ( 8 years ago )

1 Answer

Sort by » oldest newest most voted
3

answered 8 years ago

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
Preview: (hide)
link

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: 8 years ago

Seen: 1,371 times

Last updated: Sep 23 '16