Dear Thomas, thank you! That clarifies a lot!
On Jul 29, 3:45 pm, eggartmumie <[email protected]> wrote: > def goppapolynomial(F,z): > # returns a polynomial over F in indeterminant z > X = PolynomialRing(F,repr(z)).gen(); > return (X^3+F(1))*X That should work. For example: sage: def goppapolynomial(F,z): ....: X = PolynomialRing(F,repr(z)).gen() # note that ; is not needed ....: return (X^3+F(1))*X ....: sage: R.<t> = GF(2^4) sage: goppapolynomial(R,'x') x^4 + x sage: goppapolynomial(R,'x').parent() Univariate Polynomial Ring in x over Finite Field in t of size 2^4 > expecting it the function would return a polynomial over F in > indeterminant z. To be precise: In an indeterminate given by the string representation of z (in my example above, z is the string 'x'). > I thought the indeterminant essential, because the elements of F, e.g. > in case F = GF(2^2), are given as polynomials in another > indeterminant. Agreed! > I expect to get an coefficient array c=[0,1,0,0,1] of elements in F > with > y=var('y'); goppapolynomial(F,y) == c[0]*y^0+c[1]*y^1+c[2]*y^2+.... Ah! Since you have a univariate polynomial, such coefficient array can actually be passed to the polynomial ring. So, you could do: sage: def goppapolynomial(F,z,C): ....: return PolynomialRing(F,repr(z))(C) ....: sage: C = [R.random_element() for _ in range(5)] sage: C [t, t + 1, t^3 + t + 1, t^3 + 1, t^3 + t^2] sage: goppapolynomial(R,'x',C) (t^3 + t^2)*x^4 + (t^3 + 1)*x^3 + (t^3 + t + 1)*x^2 + (t + 1)*x + t > sorry, I meant coefficients in the linear combination of monomials, > and not coefficients with a Newton base or a Lagrange base. Did I now understand correctly that you *have* the list of coefficients and want to get the polynomial with these coefficients, as in my previous example? > > sage: p>>1 > > -x + 4/9 > > sorry, in reading reference.pdf I never came across this operation, Sorry, I don't know if the shift operator for polynomials is explained somewhere. > I just did not know that You can shift a polynomial! And this can certainly not be detected by tab completion. Sorry again. > This is exactly what I intended to get by calling the function (!) > goppapolynomial with parameters ZZ['t'] and var('x'), expecting it to > return the polynomial > (-3*t^2 - t - 1)*x^2 + (t^2 - t + 1)*x - 3*t - 2 > over ZZ['t'] in indeterminant x. I was confused by the different > result I get on f = goppapolynomial(F,z) when printing > type(f) > or > f.parent() Yes, the difference between type(f) and f.parent() is quite important, though certainly not easy. I guess a first approximation can be phrased like this: The type tells you how an object is implemented. The parent tells you to what algebraic structure it belongs. Objects of the same type can have very different parents, and theoretically objects of different types can have the same parent. > Even though I use tab completion quite a lot I did not find the > methods coefficient and coeffs because I only tried the tab completion > on the rings and not on their elements, the polynomials. If you want to *get* the coefficients from an existing polynomial, I think using tab completion on this polynomial is natural. However, from your example c[0]*y^0+c[1]*y^1+c[2]*y^2, it seems that you have a list of coefficients and a ring and want to get an element of that ring. Here, the answer *should* be available with "R?", because this will also show you the documentation of the call method. Unfortunately, it seems that calling a univariate polynomial ring R['x'] on a list, like R['x']([1,3,0,1]), is not sufficiently documented. > Although I now know how to get the coefficients I'd still like to know > whether I can coerce some > polynomial to an symbolic expression so I can do differentiation or ... I thought the following should work (SR is the symbolic ring): sage: p = goppapolynomial(R,'x',C) sage: p (t^3 + t^2)*x^4 + (t^3 + 1)*x^3 + (t^3 + t + 1)*x^2 + (t + 1)*x + t sage: SR(p) Traceback (most recent call last): ... TypeError: __call__() takes exactly 1 positional argument (0 given) Not good. Although string evaluation should, if possible, be avoided, it may help you. Note, however, that the symbolic ring does not know your field of coefficients! sage: q = SR(repr(p)) sage: q (t^3 + t^2)*x^4 + (t^3 + 1)*x^3 + (t^3 + t + 1)*x^2 + (t + 1)*x + t sage: type(q) <type 'sage.symbolic.expression.Expression'> sage: q.diff(x) 4*(t^3 + t^2)*x^3 + 3*(t^3 + 1)*x^2 + 2*(t^3 + t + 1)*x + t + 1 sage: q.integral(x) 1/5*(t^3 + t^2)*x^5 + 1/4*(t^3 + 1)*x^4 + 1/3*(t^3 + t + 1)*x^3 + 1/2*(t + 1)*x^2 + t*x And back to the polynomial ring: sage: P = p.parent() sage: P(repr(q.diff(x))) (t^3 + 1)*x^2 + t + 1 If you are only interested in the derivative, you may stay in the algebraic world and do sage: p.derivative() (t^3 + 1)*x^2 + t + 1 //////////////////// QUESTION to the list: Do you agree that the following (with the definitions above) are bugs: 1) sage: SR(p) Traceback (most recent call last): ... TypeError: __call__() takes exactly 1 positional argument (0 given) 2) P? does not tell that it is possible to construct a polynomial from a list of coefficients (and from a dictionary as well). Is this a bug in the documentation? 3) We have sage: P(1/5) 1 sage: P('1/5') 1 sage: P(1/5*x) x but sage: P('1/5*x') BOOM Best regards, 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
