Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm curious as to how Decompose works so I decided to use Trace with the option TraceInternal -> True.

For NextPrime, this works well:

AppendTo[$ContextPath, "NumberTheory`NextPrimeDump`"];


Above, we can see some code and get an idea of how NextPrime works. But when I do this with Decompose I get something weird:

With[{p = Expand[(x^2+x+1)^2+2(x^2+x+1)+1]},
  Trace[Decompose[p, x], TraceInternal -> True]

{Decompose[4+4 x+5 x^2+2 x^3+x^4,x],{BitAnd[29,8],BitAnd[8,29],8},
{4+4 x+x^2,x+x^2}}

Is there any way to tell where these bitwise ANDs are coming from? Isn't TraceInternal supposed to show all workings during an execution?

share|improve this question
The reference for the method used by Decompose is: "Fast polynomial decomposition algorithms" by V. S. Alagar and Mai Thanh. I believe it appeared in the proceedings of the EuroCal '85 conference. I've no idea what those BitAnds are from. – Daniel Lichtblau Feb 1 '13 at 20:43
I checked. The BitAnd calls come from some polynomial factorization code used by Decompose. – Daniel Lichtblau Feb 1 '13 at 21:11
Thanks for that. The source was very easy to follow. – Chip Hurst Feb 4 '13 at 4:29

Per Daniel Lichtblau's comment, the method used by Decompose is based on the following reference:

The BitAnd calls come from some polynomial factorization code used by Decompose.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.