08.02.2015 Views

Sage Reference Manual: Matrices and Spaces of Matrices - Mirrors

Sage Reference Manual: Matrices and Spaces of Matrices - Mirrors

Sage Reference Manual: Matrices and Spaces of Matrices - Mirrors

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Sage</strong> <strong>Reference</strong> <strong>Manual</strong>: <strong>Matrices</strong> <strong>and</strong> <strong>Spaces</strong> <strong>of</strong> <strong>Matrices</strong>, Release 6.1.1<br />

With the right functions <strong>and</strong> a list comprehension, custom names can be easier. A multiplication table for hex<br />

digits (without carries):<br />

sage: from sage.matrix.operation_table import OperationTable<br />

sage: R=Integers(16)<br />

sage: names=[hex(Integer(a)) for a in R]<br />

sage: OperationTable(R, operation=operator.mul, names=names)<br />

* 0 1 2 3 4 5 6 7 8 9 a b c d e f<br />

+--------------------------------<br />

0| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br />

1| 0 1 2 3 4 5 6 7 8 9 a b c d e f<br />

2| 0 2 4 6 8 a c e 0 2 4 6 8 a c e<br />

3| 0 3 6 9 c f 2 5 8 b e 1 4 7 a d<br />

4| 0 4 8 c 0 4 8 c 0 4 8 c 0 4 8 c<br />

5| 0 5 a f 4 9 e 3 8 d 2 7 c 1 6 b<br />

6| 0 6 c 2 8 e 4 a 0 6 c 2 8 e 4 a<br />

7| 0 7 e 5 c 3 a 1 8 f 6 d 4 b 2 9<br />

8| 0 8 0 8 0 8 0 8 0 8 0 8 0 8 0 8<br />

9| 0 9 2 b 4 d 6 f 8 1 a 3 c 5 e 7<br />

a| 0 a 4 e 8 2 c 6 0 a 4 e 8 2 c 6<br />

b| 0 b 6 1 c 7 2 d 8 3 e 9 4 f a 5<br />

c| 0 c 8 4 0 c 8 4 0 c 8 4 0 c 8 4<br />

d| 0 d a 7 4 1 e b 8 5 2 f c 9 6 3<br />

e| 0 e c a 8 6 4 2 0 e c a 8 6 4 2<br />

f| 0 f e d c b a 9 8 7 6 5 4 3 2 1<br />

This should be flexible enough to create a variety <strong>of</strong> such tables.<br />

sage: from sage.matrix.operation_table import OperationTable<br />

sage: from operator import xor<br />

sage: T=OperationTable(ZZ, xor, elements=range(8))<br />

sage: T<br />

. a b c d e f g h<br />

+----------------<br />

a| a b c d e f g h<br />

b| b a d c f e h g<br />

c| c d a b g h e f<br />

d| d c b a h g f e<br />

e| e f g h a b c d<br />

f| f e h g b a d c<br />

g| g h e f c d a b<br />

h| h g f e d c b a<br />

sage: names=[’000’, ’001’,’010’,’011’,’100’,’101’,’110’,’111’]<br />

sage: T.change_names(names)<br />

sage: T.set_print_symbols(’^’, ’\\l<strong>and</strong>’)<br />

sage: T<br />

^ 000 001 010 011 100 101 110 111<br />

+--------------------------------<br />

000| 000 001 010 011 100 101 110 111<br />

001| 001 000 011 010 101 100 111 110<br />

010| 010 011 000 001 110 111 100 101<br />

011| 011 010 001 000 111 110 101 100<br />

100| 100 101 110 111 000 001 010 011<br />

101| 101 100 111 110 001 000 011 010<br />

110| 110 111 100 101 010 011 000 001<br />

111| 111 110 101 100 011 010 001 000<br />

sage: T = OperationTable([False, True], operator.or_, names = ’elements’)<br />

sage: T<br />

406 Chapter 23. Operation Tables

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!