Thank you for that detailed and lucid description. It seems then, that my confusion was caused not by mapping a command across a matrix, but by the fact that I couldn't have a matrix of my desired output type - I wasn't aware of the distinction between python ints and Sage ZZ. And I didn't know about the log_to_int command. So:
sage: map_threaded(lambda x:x.log_to_int(),M) works fine. Thanks again, Alasdair On Oct 25, 12:10 pm, Simon King <[email protected]> wrote: > Hi Alasdair! > > On 24 Okt., 20:01, Alasdair <[email protected]> wrote: > > > Actually, just worked it out: > > > matrix(ZZ,2,2,map(int,M.list())) > > Do you want to convert your matrix into a matrix of Integers (= > elements of Sage's ZZ) or into a matrix of Python integers (type int)? > Since Python integers don't form a parent structure, there are no > Python-int matrices in Sage, if I am not mistaken. > > This is why you get the error > TypeError: base_ring (=<type 'int'>) must be a ring > when you try map_threaded(int,M) > > So, from now on, I assume that you want a transformation into Integer > (not int) matrices. > > > So I need to convert the matrix to a list, apply map to that list, and > > then convert the result back to a matrix. But why can't I do this > > with a single map command? > > Your original base ring is G.<x>=GF(2^8). There is no homomorphism > from GF(2^8) to ZZ (at least if you want that 1 is mapped to 1...). > > So, why *should* there be a single command to transform a matrix over > GF(2^8) into the "corresponding" matrix over ZZ? The point is, there > is no "corresponding" matrix in that case! > > Note that a transformation is easy, as long as it mathematically makes > sense: > > sage: MZ = random_matrix(ZZ,6,6) > sage: MQ1 = map_threaded(QQ,MZ) > sage: MQ2 = MZ*QQ(1) > sage: MZ = random_matrix(ZZ,6,6) > sage: MGF3a = map_threaded(GF(3),MZ) > sage: MGF3b = MZ*GF(3)(1) > sage: MGF3a == MGF3b > True > sage: MGF3a.parent() == MGF3b.parent() > True > > If I am not mistaken, the problems you encountered are all about > coercion, which is described > athttp://www.sagemath.org/doc/reference/coercion.html > > One more remark. It is still not clear to me what exactly you mean by > a transformation from G to ZZ. But perhaps you know the log_to_int > method of G? This expresses an element of G (which is a polynomial in > x) into a Python int. So, no surprize about this error: > sage: map_threaded(G.log_to_int,M) > Traceback > ... > TypeError: base_ring (=<type 'int'>) must be a ring > > However, going one step further, you can proceed to "proper" Sage > integers. For example: > sage: f = lambda x: ZZ(G.log_to_int(x)) > sage: map_threaded(f,M) > > [ 7 138] > [212 169] > > 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 -~----------~----~----~----~------~----~------~--~---
