Hi Andrew! On Sep 2, 6:56 pm, andrew ewart <[email protected]> wrote: > ... > degx= f.degree(z1) > degy= f.degree(z2) > degree=2*degx*degy > ... > for q in xrange(0,degree+1): > for ja in range(0,degx): > lee=li[ja].coeffs() > print lee > lei=lee[q].list() > print lei > > ... > and at moment i get this as output > > 1 > 8 > Univariate Polynomial Ring in y over Univariate Quotient Polynomial Ring in > t over Finite Field of size 5 with modulus t^2 + 3 > 4*t > t > 3*t*y^6 + 2*t*y^4 + t*y^2 + t > 6 > (1, 3*t*y^6 + 2*t*y^4 + t*y^2 + t, 4*y^2 + 2) > [1] > [1, 0] > [t, 0, t, 0, 2*t, 0, 3*t] > [0, 1] > [1] > Traceback (most recent call last): > File "quickfact.py", line 72, in <module> > print factor_bivar(f) > File "quickfact.py", line 63, in factor_bivar > lei=lee[q].list() > IndexError: list index out of range
Could it be that it is simply a programming error? q ranges from 0 to ``degree``. Then, there is an index error when you do ``lee[q]``. So, are you *sure* that lee has at least length ``degree``? You do ``lee=li[ja].coeffs()``, but I did not attempt to understand the definition of ``li``. But apparently, lee is a list of coefficients, so, its length depends on the degree of li[ja], which, I assume, is a univariate polynomial. Do you have the following, perhaps? - By definition, li[ja] is a polynomial of *at most* the degree ``degree``, but it may happen that higher terms cancel, so that the actual degree is smaller. - You want that lee[q] returns zero if q exceeds the degree of li[ja]. Then I see two potential solutions: 1) Compute the actual degree of li[ja] and do not try to access lee[q] if q exceeds that degree; so, you need an "if ...:" in front of ``lei=lee[q].list()``. 2) Work with ``lee[q].dict()`` and not with ``lee[q].list()``. It could be that the following gives you an idea: sage: C.<a,b,c,d,e,f> = QQ[] sage: R.<x> = C[] sage: D = (a+c*x^2).dict() sage: for q in range(5): ....: print q, D.get(q,0) ....: 0 a 1 0 2 c 3 0 4 0 If you would instead do: sage: L = (a+c*x^2).list() sage: for q in range(5): ....: print q, L[q] you would of course get an index error. But all depends on what you really want to achieve. And so far, you did not state concisely what you want to compute. Cheers, Simon -- To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
