1 | initial version |
Hello,
Do you really need v to be irreducible in order to do that? Your algorithm looks fine but you can do cleaner using the method quo_rem which returns at once both the quotient and the remainder.
sage: x = polygen(ZZ, 'x')
sage: f = x^6 + 3*x^3 - x^2 + 1
sage: v = x^2 + 1
sage: decomposition = []
sage: q = f
sage: while q:
....: q,r = q.quo_rem(v)
....: decomposition.append(r)
And then you can check that you get back the initial polynomial:
sage: sum(a * v^i for i,a in enumerate(decomposition))
x^6 + 3*x^3 - x^2 + 1
Vincent