multiplication_table() of Zmod(p)

asked 2024-05-25 13:10:41 +0200

dantetante gravatar image

updated 2024-06-20 15:48:11 +0200

dan_fulea gravatar image

I want to print multiplication tables of Z_n (for n prime but this is irrelevant for my needs at the moment). When I try e.g. Zmod(5).multiplication_table(names='digits') I get

 *  0 1 2 3
  +--------
 0| 0 1 2 3
 1| 1 2 3 0
 2| 2 3 0 1    
 3| 3 0 1 2

what is not really what I want, I want the canonical representants. If I don't use the names-key, I get letters. How can I get 1, 2, 3, 4, or even better -2, -1, 1, 2?

edit retag flag offensive close merge delete

Comments

1

What Sage are you using ? in 10.4.beta6, I get :

sage: Zmod(5).multiplication_table(names='digits')
*  0 1 2 3 4
 +----------
0| 0 0 0 0 0
1| 0 1 2 3 4
2| 0 2 4 1 3
3| 0 3 1 4 2
4| 0 4 3 2 1

Your system seems to give you a (seriously mangled) version of the addition table :

sage: Zmod(5).addition_table(names='digits')
+  0 1 2 3 4
 +----------
0| 0 1 2 3 4
1| 1 2 3 4 0
2| 2 3 4 0 1
3| 3 4 0 1 2
4| 4 0 1 2 3
Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2024-05-25 17:28:55 +0200 )edit

I've typed a long answer, but submitting it was leading to an error... Have to type a shorter one.

EDIT: Nope... the shorter answer is also failing to work:

system error log is recorded, error will be fixed as soon as possible please report the error to the site administrators

dan_fulea gravatar imagedan_fulea ( 2024-06-20 16:11:05 +0200 )edit

OK, i am trying to type the answer as a comment...

sage: GF(5).multiplication_table(names=['1', '2', '-2', '-1'], elements=[1,2,3,4])
 *   1  2 -2 -1
  +------------
 1|  1  2 -2 -1
 2|  2 -1  1 -2
-2| -2  1 -1  2
-1| -1 -2  2  1

sage:
dan_fulea gravatar imagedan_fulea ( 2024-06-20 16:15:29 +0200 )edit

I have no chance to put an answer in here... and this is not the first time. Here is a more complicated case:

The table for $\Bbb F_p$ with $p=17$, using the representatives $\pm1,\pm2,\dots,\pm8$:

p = 17
r = p//2
elements = [1..r] + [-r..-1]
names = [str(k) for k in elements]
GF(p).multiplication_table(names=names, elements=elements)

This gives:

 *   1  2  3  4  5  6  7  8 -8 -7 -6 -5 -4 -3 -2 -1
  +------------------------------------------------
 1|  1  2  3  4  5  6  7  8 -8 -7 -6 -5 -4 -3 -2 -1
 2|  2  4  6  8 -7 -5 -3 -1  1  3  5  7 -8 -6 -4 -2
 3|  3  6 -8 -5 -2  1  4  7 -7 -4 -1  2  5  8 -6 -3
 4|  4  8 -5 -1  3  7 -6 -2  2  6 -7 -3  1  5 -8 -4
 5|  5 ...
(more)
dan_fulea gravatar imagedan_fulea ( 2024-06-20 16:20:15 +0200 )edit

The OP table seems to be:

sage: GF(5).unit_group().multiplication_table(names='digits')
*  0 1 2 3
 +--------
0| 0 1 2 3
1| 1 2 3 0
2| 2 3 0 1
3| 3 0 1 2

It was not easy to guess...

dan_fulea gravatar imagedan_fulea ( 2024-06-20 16:22:33 +0200 )edit