Re: Factorising polynomials
- To: mathgroup at smc.vnet.net
- Subject: [mg63995] Re: Factorising polynomials
- From: Peter Pein <petsie at dordos.net>
- Date: Thu, 26 Jan 2006 03:43:53 -0500 (EST)
- References: <dr80c0$phj$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Tony King schrieb: > I am trying to find the number of irreducible polynomials over the integers > in the factorisation of x^n+1 > > I used the following code > > data = Factor[x^# + 1] & /@ Range[6] > > Followed by > > Table[Length[data[[k]]], {k, 1, 6}] > > And Mathematica returned {2,2,2,2,2,2}, one assumes because it was counting > terms such as 1+x as 2 terms. However, when the number of factors exceeds 1, > Mathematica returns them as a list and counts them correctly. The output > that I was looking for should have been {1,1,2,1,2,2}. > > Does anyone have any ideas how I might modify the above code so that it > returns the correct number of terms > > Many thanks > > Tony > Hi Tony, you can use patterns: (#1 /. t_Times :> Length[t] /. _Plus -> 1 &) /@ Table[Factor[x^n + 1], {n, 10}] --> {1, 1, 2, 1, 2, 2, 2, 1, 3, 2} or use FactorList, not Factor: Total[Last /@ Rest[#1]]& /@ Table[FactorList[x^n + 1], {n, 10}] --> {1, 1, 2, 1, 2, 2, 2, 1, 3, 2} or Switch[]: In[6]:= Switch[#1, _Plus, 1, _Times, Length[#1]]& /@ Table[Factor[x^n + 1], {n, 10}] --> {1, 1, 2, 1, 2, 2, 2, 1, 3, 2} and I'm sure there are other ways to do this. Regards, Peter