> M=random_matrix(IntegerModRing(10),3,3) > > Now the adjoint certainly exists, but M.adjoint() isn't as yet > implemented over general rings - only over ZZ or QQ. How can I use, > say, Maxima or Pari within Sage to compute the adjoint of M? >
It's pretty friendly to use Pari to do this ... in general, given any sage object a, you can try pari(a) to convert it to Pari. In this example, it works fine (though the pari output isn't the most pleasant to read): sage: M = random_matrix(IntegerModRing(10),3,3) sage: Mp = pari(M) sage: M [4 2 0] [5 4 8] [9 6 2] sage: Mp [Mod(4, 10), Mod(2, 10), Mod(0, 10); Mod(5, 10), Mod(4, 10), Mod(8, 10); Mod(9, 10), Mod(6, 10), Mod(2, 10)] Then you can call Mp.matadjoint() to get the adjoint. However, in this case, Pari fails to find the adjoint: sage: Mp.matadjoint() --------------------------------------------------------------------------- PariError Traceback (most recent call last) /Users/craigcitro/.sage/temp/sharma.local/8072/_Users_craigcitro__sage_init_sage_0.py in <module>() ----> 1 2 3 4 5 /sage/local/lib/python2.5/site-packages/sage/libs/pari/gen.so in sage.libs.pari.gen._pari_trap (sage/libs/pari/gen.c:38577)() 8048 8049 -> 8050 8051 8052 PariError: impossible inverse modulo: (36) This is actually Pari behaving badly, not sage -- doing the same thing in a GP session gets the same error. Apparently Pari can't find the determinant of non-invertible square matrices of size at least 3x3 (???). I'll try to look at this and submit a bug report soon -- or you could beat me to it. :) In any event, say it worked (so I'll use 2x2 as an example). You *should* be able to just call M.parent()(Mp.matadjoint()), but that currently hits an error. However, the pari object Mp.matadjoint() has a _sage_ method that knows how to convert back to sage. So this works: sage: m = random_matrix(Integers(10),2,2) ; m [0 9] [3 5] sage: mp = pari(m) sage: mp.matadjoint() [Mod(5, 10), Mod(1, 10); Mod(7, 10), Mod(0, 10)] sage: mp.matadjoint()._sage_() [5 1] [7 0] sage: pari(m).matadjoint()._sage_() [5 1] [7 0] As you point out at the beginning, though, we really should have our own native adjoint function. Here's a one-liner: sage: M = random_matrix(Integers(10),3,3) ; M [9 7 5] [2 9 5] [7 8 8] sage: M.parent()([ (-1)^(i+j)*M.matrix_from_rows_and_columns([x for x in range(M.nrows()) if x != i], [y for y in range(M.ncols()) if y != j]).det() for i in range(M.nrows()) for j in range(M.nrows()) ]).transpose() [2 4 0] [9 7 5] [3 7 7] That function is terrible in a lot of ways -- but if you need something right now, it works. :) -cc --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---