File: CompanionMatrix.tst

package info (click to toggle)
gap 4.15.1-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 110,212 kB
  • sloc: ansic: 97,261; xml: 48,343; cpp: 13,946; sh: 4,900; perl: 1,650; javascript: 255; makefile: 252; ruby: 9
file content (149 lines) | stat: -rw-r--r-- 4,018 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
gap> START_TEST("CompanionMatrix.tst");
gap> ReadGapRoot("tst/testinstall/MatrixObj/testmatobj.g");

#
# IsGF2MatrixRep
#
gap> F:= GF(2);;  x:= X(F);;
gap> TestCompanionMatrix(IsGF2MatrixRep, x+1, F);
<a 1x1 matrix over GF2>
gap> TestCompanionMatrix(IsGF2MatrixRep, x^2+x+1, F);
<a 2x2 matrix over GF2>

# test error handling
gap> TestCompanionMatrix(IsGF2MatrixRep, Zero(x), F);
Error, NewCompanionMatrix: degree of <pol> must be at least 1
gap> TestCompanionMatrix(IsGF2MatrixRep, One(x), F);
Error, NewCompanionMatrix: degree of <pol> must be at least 1

#
# Is8BitMatrixRep
#
gap> F:= GF(3);;  x:= X(F);;
gap> TestCompanionMatrix(Is8BitMatrixRep, x+1, F);
[ [ Z(3) ] ]
gap> TestCompanionMatrix(Is8BitMatrixRep, x^2+x+1, F);
[ [ 0*Z(3), Z(3) ], [ Z(3)^0, Z(3) ] ]

# test error handling
gap> TestCompanionMatrix(Is8BitMatrixRep, Zero(x), F);
Error, NewCompanionMatrix: degree of <pol> must be at least 1
gap> TestCompanionMatrix(Is8BitMatrixRep, One(x), F);
Error, NewCompanionMatrix: degree of <pol> must be at least 1

#
gap> F:= GF(251);;  x:= X(F);;
gap> TestCompanionMatrix(Is8BitMatrixRep, x+1, F);
[ [ Z(251)^125 ] ]
gap> TestCompanionMatrix(Is8BitMatrixRep, x^2+x+1, F);
[ [ 0*Z(251), Z(251)^125 ], [ Z(251)^0, Z(251)^125 ] ]

# test error handling
gap> TestCompanionMatrix(Is8BitMatrixRep, Zero(x), F);
Error, NewCompanionMatrix: degree of <pol> must be at least 1
gap> TestCompanionMatrix(Is8BitMatrixRep, One(x), F);
Error, NewCompanionMatrix: degree of <pol> must be at least 1

#
# IsPlistMatrixRep
#
gap> F:= GF(251);;  x:= X(F);;
gap> TestCompanionMatrix(IsPlistMatrixRep, x+1, F);
<1x1-matrix over GF(251)>
gap> TestCompanionMatrix(IsPlistMatrixRep, x^2+x+1, F);
<2x2-matrix over GF(251)>

#
gap> F:= Integers;;  x:= X(F);;
gap> TestCompanionMatrix(IsPlistMatrixRep, x+1, F);
<1x1-matrix over Integers>
gap> TestCompanionMatrix(IsPlistMatrixRep, x^2+x+1, F);
<2x2-matrix over Integers>

#
gap> F:= Rationals;;  x:= X(F);;
gap> TestCompanionMatrix(IsPlistMatrixRep, x+1, F);
<1x1-matrix over Rationals>
gap> TestCompanionMatrix(IsPlistMatrixRep, x^2+x+1, F);
<2x2-matrix over Rationals>

#
# IsPlistRep
#
gap> F:= GF(251);;  x:= X(F);;
gap> TestCompanionMatrix(IsPlistRep, x+1, F);
[ [ Z(251)^125 ] ]
gap> TestCompanionMatrix(IsPlistRep, x^2+x+1, F);
[ [ 0*Z(251), Z(251)^125 ], [ Z(251)^0, Z(251)^125 ] ]

#
gap> F:= Integers;;  x:= X(F);;
gap> TestCompanionMatrix(IsPlistRep, x+1, F);
Error, Assertion failure
gap> TestCompanionMatrix(IsPlistRep, x^2+x+1, F);
Error, Assertion failure

#
gap> F:= Rationals;;  x:= X(F);;
gap> TestCompanionMatrix(IsPlistRep, x+1, F);
[ [ -1 ] ]
gap> TestCompanionMatrix(IsPlistRep, x^2+x+1, F);
[ [ 0, -1 ], [ 1, -1 ] ]

#
gap> F:= Integers mod 4;;  x:= X(F);;
gap> TestCompanionMatrix(IsPlistRep, x+1, F);
[ [ ZmodnZObj( 3, 4 ) ] ]
gap> TestCompanionMatrix(IsPlistRep, x^2+x+1, F);
[ [ ZmodnZObj( 0, 4 ), ZmodnZObj( 3, 4 ) ], 
  [ ZmodnZObj( 1, 4 ), ZmodnZObj( 3, 4 ) ] ]

#
# Test CompanionMatrix variant which "guesses" a suitable representation, i.e.:
#    CompanionMatrix( <pol>, <R> )
#

#
gap> F:= GF(2);;  x:= X(F);;
gap> CompanionMatrix(x+1, F);
<a 1x1 matrix over GF2>
gap> CompanionMatrix(x^2+x+1, F);
<a 2x2 matrix over GF2>

#
gap> F:= GF(3);;  x:= X(F);;
gap> CompanionMatrix(x+1, F);
[ [ Z(3) ] ]
gap> CompanionMatrix(x^2+x+1, F);
[ [ 0*Z(3), Z(3) ], [ Z(3)^0, Z(3) ] ]

#
gap> F:= GF(4);;  x:= X(F);;
gap> CompanionMatrix(x+1, F);
[ [ Z(2)^0 ] ]
gap> CompanionMatrix(x^2+x+1, F);
[ [ 0*Z(2), Z(2)^0 ], [ Z(2)^0, Z(2)^0 ] ]

#
gap> F:= Integers;;  x:= X(F);;
gap> CompanionMatrix(x+1, F);
<1x1-matrix over Integers>
gap> CompanionMatrix(x^2+x+1, F);
<2x2-matrix over Integers>

#
gap> F:= Rationals;;  x:= X(F);;
gap> CompanionMatrix(x+1, F);
<1x1-matrix over Rationals>
gap> CompanionMatrix(x^2+x+1, F);
<2x2-matrix over Rationals>

#
gap> F:= Integers mod 4;;  x:= X(F);;
gap> CompanionMatrix(x+1, F);
<1x1-matrix over (Integers mod 4)>
gap> CompanionMatrix(x^2+x+1, F);
<2x2-matrix over (Integers mod 4)>

#
gap> STOP_TEST("CompanionMatrix.tst");