File: compat3.tst

package info (click to toggle)
gap 4r4p12-2
  • links: PTS
  • area: main
  • in suites: squeeze, wheezy
  • size: 29,584 kB
  • ctags: 7,113
  • sloc: ansic: 98,786; sh: 3,299; perl: 2,263; makefile: 498; asm: 63; awk: 6
file content (324 lines) | stat: -rw-r--r-- 10,490 bytes parent folder | download | duplicates (3)
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#############################################################################
##
#W  compat3.tst                 GAP library                     Thomas Breuer
##
#H  @(#)$Id: compat3.tst,v 1.4.8.2 2005/05/10 08:48:44 gap Exp $
##
#Y  Copyright (C)  1998,  Lehrstuhl D fuer Mathematik,  RWTH Aachen,  Germany
##
##  Exclude from testall.g: not expected to be of interest for users
##

gap> START_TEST("$Id: compat3.tst,v 1.4.8.2 2005/05/10 08:48:44 gap Exp $");

# Read the library files `compat3a.g', `compat3b.g', `compat3c.g'.
gap> ReadLib( "compat3c.g" );

# Check the behaviour of ordinary domains w.r.t. component access.
gap> g:= Group( (1,2,3,4), (1,2) );
Group([ (1,2,3,4), (1,2) ])

gap> IsBound( g.size );
false
gap> g.size;
24
gap> IsBound( g.size );
true
gap> IsBound( g.isAbelian );
false
gap> g.operations.IsAbelian( g );
false
gap> IsBound( g.isAbelian );
true

gap> IsBound( g.derivedSubgroup );
false
gap> der:= Subgroup( g, [ (1,2,3), (1,2)(3,4) ] );;
gap> SetName( der, "der" );
gap> g.derivedSubgroup:= der;;
gap> IsBound( g.derivedSubgroup );
true
gap> g.derivedSubgroup;
der

gap> IsBound( g.private );
false
gap> g.private:= [ 1 .. 100 ];;
gap> IsBound( g.private );
true
gap> g.private;
[ 1 .. 100 ]
gap> Compat3Info( g );
rec(
  private := [ 1 .. 100 ] )

gap> # Check the behaviour of new objects represented by records with
gap> # operations record.
gap> # The objects used here implement complex numbers with rational real
gap> # and imaginary part, stored in the components `re' and `im'.
gap> CompOps := OperationsRecord( "CompOps" );;
HasCompOps := NewFilter( "HasCompOps" );
gap> CompOps;
CompOps
gap> CompOps.Print := function( c )
>     Print( "C( ", c.re, " + ", c.im, "*I )" );
> end;;
# If the following method installation matches the requirements
# of the operation `PRINT_OBJ' then `InstallMethod' should be used.
# It might be useful to replace the rank `SUM_FLAGS' by `0'.
InstallOtherMethod( PRINT_OBJ,
    "for object with `CompOps' as first argument",
    [ HasCompOps ], SUM_FLAGS,
    CompOps.Print );

# For printing objects, also a `ViewObj' method is installed.
InstallOtherMethod( ViewObj,
    "for object with `CompOps' as first argument",
    [ HasCompOps ], SUM_FLAGS,
    CompOps.Print );

gap> CompOps.\= := function( l, r )
>     return l.re = r.re and l.im = r.im;
> end;;
# If the following method installation matches the requirements
# of the operation `EQ' then `InstallMethod' should be used.
# It might be useful to replace the rank `SUM_FLAGS' by `0'.
InstallOtherMethod( EQ,
    "for object with `CompOps' as first argument",
    [ HasCompOps, IsObject ], SUM_FLAGS,
    CompOps.\= );

# For binary infix operators, a second method is installed
# for the case that the object with `CompOps' is the right operand;
# since this case has priority on GAP 3, the method is
# installed with higher rank `SUM_FLAGS + 1'.
InstallOtherMethod( EQ,
    "for object with `CompOps' as second argument",
    [ IsObject, HasCompOps ], SUM_FLAGS + 1,
    CompOps.\= );

gap> CompOps.\< := function( l, r )
>     return l.re < r.re or ( l.re = r.re and l.im < r.im );
> end;;
gap> CompOps.\+ := function( l, r )
>     return rec( re:= l.re + r.re, im:= l.im + r.im, operations:= CompOps );
> end;;
# If the following method installation matches the requirements
# of the operation `SUM' then `InstallMethod' should be used.
# It might be useful to replace the rank `SUM_FLAGS' by `0'.
InstallOtherMethod( SUM,
    "for object with `CompOps' as first argument",
    [ HasCompOps, IsObject ], SUM_FLAGS,
    CompOps.\+ );

# For binary infix operators, a second method is installed
# for the case that the object with `CompOps' is the right operand;
# since this case has priority on GAP 3, the method is
# installed with higher rank `SUM_FLAGS + 1'.
InstallOtherMethod( SUM,
    "for object with `CompOps' as second argument",
    [ IsObject, HasCompOps ], SUM_FLAGS + 1,
    CompOps.\+ );

gap> CompOps.\- := function( l, r )
>     return rec( re:= l.re - r.re, im:= l.im - r.im, operations:= CompOps );
> end;;
# If the following method installation matches the requirements
# of the operation `DIFF' then `InstallMethod' should be used.
# It might be useful to replace the rank `SUM_FLAGS' by `0'.
InstallOtherMethod( DIFF,
    "for object with `CompOps' as first argument",
    [ HasCompOps, IsObject ], SUM_FLAGS,
    CompOps.\- );

# For binary infix operators, a second method is installed
# for the case that the object with `CompOps' is the right operand;
# since this case has priority on GAP 3, the method is
# installed with higher rank `SUM_FLAGS + 1'.
InstallOtherMethod( DIFF,
    "for object with `CompOps' as second argument",
    [ IsObject, HasCompOps ], SUM_FLAGS + 1,
    CompOps.\- );

gap> CompOps.\* := function( l, r )
>     if IsList( l ) then
>       return List( l, x -> x * r );
>     elif IsList( r ) then
>       return List( r, x -> l * x );
>     elif IsRat( l ) then
>       return rec( re:= l * r.re,
>                   im:= l * r.im,
>                   operations:= CompOps );
>     elif IsRat( r ) then
>       return rec( re:= l.re * r,
>                   im:= l.im * r,
>                   operations:= CompOps );
>     else
>       return rec( re:= l.re * r.re - l.im * r.im,
>                   im:= l.im * r.re + l.re * r.im,
>                   operations:= CompOps );
>     fi;
> end;;
# If the following method installation matches the requirements
# of the operation `PROD' then `InstallMethod' should be used.
# It might be useful to replace the rank `SUM_FLAGS' by `0'.
InstallOtherMethod( PROD,
    "for object with `CompOps' as first argument",
    [ HasCompOps, IsObject ], SUM_FLAGS,
    CompOps.\* );

# For binary infix operators, a second method is installed
# for the case that the object with `CompOps' is the right operand;
# since this case has priority on GAP 3, the method is
# installed with higher rank `SUM_FLAGS + 1'.
InstallOtherMethod( PROD,
    "for object with `CompOps' as second argument",
    [ IsObject, HasCompOps ], SUM_FLAGS + 1,
    CompOps.\* );

gap> Comp:= function( re, im )
>     return rec( re:= re, im:= im, operations:= CompOps );
> end;;

gap> e:= Comp( 1, 0 );
C( 1 + 0*I )
gap> i:= Comp( 0, 1 );
C( 0 + 1*I )
gap> z:= Comp( 0, 0 );
C( 0 + 0*I )

gap> 7*e + 5*i = 5*i + 7*e;
true
gap> m1:= [ [ i, z ], [ z, i ] ];
[ [ C( 0 + 1*I ), C( 0 + 0*I ) ], [ C( 0 + 0*I ), C( 0 + 1*I ) ] ]
gap> m2:= [ [ z, e ], [ e, z ] ];
[ [ C( 0 + 0*I ), C( 1 + 0*I ) ], [ C( 1 + 0*I ), C( 0 + 0*I ) ] ]
gap> m1 * m2;
[ [ C( 0 + 0*I ), C( 0 + 1*I ) ], [ C( 0 + 1*I ), C( 0 + 0*I ) ] ]
gap> m1 + m2;
[ [ C( 0 + 1*I ), C( 1 + 0*I ) ], [ C( 1 + 0*I ), C( 0 + 1*I ) ] ]
gap> m1^4 = m2^2;
true
gap> ( m1 + m2 )^2;
[ [ C( 0 + 0*I ), C( 0 + 2*I ) ], [ C( 0 + 2*I ), C( 0 + 0*I ) ] ]


#T The following would *not* work, for various reasons.
#T OrderMat( m1 ); OrderMat( m2 );
#T It is impossible to compute the order because of a call of `RankMat'
#T in the default method, which calls `Inverse'.

#T Size( Group( m1, m2 ) );
#T It is impossible to form groups of matrices over the `Comp' objects,
#T already `FieldOfMatrixGroup' complains.
#T Anyhow, also {\GAP}~3 did not admit all meaningful elements with
#T multiplication as group elements.


# Check the behaviour of domains with new operations records.
gap> MyOps:= OperationsRecord( "MyOps", PermGroupOps );
HasMyOps := NewFilter( "HasMyOps" );
MyOps
gap> MyOps.IsFinite:= function( G )
>     Print( "always finite!\n" );
>     return true;
> end;;
# If the following method installation matches the requirements
# of the operation `IsFinite' then `InstallMethod' should be used.
# It might be useful to replace the rank `SUM_FLAGS' by `0'.
InstallOtherMethod( IsFinite,
    "for object with `MyOps' as first argument",
    [ HasMyOps ], SUM_FLAGS,
    MyOps.IsFinite );

gap> MyOps.Size:= function( G )
>     Print( "my method for `Size':\n" );
>     return Size( Group( G.generators, G.identity ) );
> end;;
# If the following method installation matches the requirements
# of the operation `Size' then `InstallMethod' should be used.
# It might be useful to replace the rank `SUM_FLAGS' by `0'.
InstallOtherMethod( Size,
    "for object with `MyOps' as first argument",
    [ HasMyOps ], SUM_FLAGS,
    MyOps.Size );

gap> MyOps.IsSubset:= function( G, H )
>     Print( "my method for `IsSubset':\n" );
>     if IsGroup( G ) and IsGroup( H ) then
>       return IsSubset( Group( G.generators, G.identity ),
>                        Group( H.generators, H.identity ) );
>     elif G.operations = MyOps then
>       return IsSubset( Group( G.generators, G.identity ), H );
>     else
>       return IsSubset( G, Group( H.generators, H.identity ) );
>     fi;
> end;;
# If the following method installation matches the requirements
# of the operation `IsSubset' then `InstallMethod' should be used.
# It might be useful to replace the rank `SUM_FLAGS' by `0'.
InstallOtherMethod( IsSubset,
    "for object with `MyOps' as first argument",
    [ HasMyOps, IsObject ], SUM_FLAGS,
    MyOps.IsSubset );

gap> MyOps.SylowSubgroup:= function( G, p )
>     Print( "my method for `SylowSubgroup':\n" );
>     return SylowSubgroup( Group( G.generators, G.identity ), p );
> end;;
# If the following method installation matches the requirements
# of the operation `SylowSubgroup' then `InstallMethod' should be used.
# It might be useful to replace the rank `SUM_FLAGS' by `0'.
InstallOtherMethod( SylowSubgroup,
    "for object with `MyOps' as first argument",
    [ HasMyOps, IsObject ], SUM_FLAGS,
    MyOps.SylowSubgroup );

gap> g:= Group( (1,2,3,4), (1,2) );
Group([ (1,2,3,4), (1,2) ])
gap> g.operations:= MyOps;
MyOps

gap> IsFinite( g );
true
gap> g.operations.IsFinite( g );
always finite!
true
gap> g.isFinite;
true

gap> Size( g );
my method for `Size':
24
gap> g.operations.Size( g );
my method for `Size':
24
gap> g.size;
24

gap> h:= DerivedSubgroup( g );
my method for `IsSubset':
my method for `IsSubset':
Group([ (1,3,2), (2,4,3) ])
gap> IsSubset( g, h );
true
gap> g.operations.IsSubset( g, h );
my method for `IsSubset':
true
gap> h.operations.IsSubset( g, h );
true

gap> SylowSubgroup( g, 2 );
my method for `SylowSubgroup':
Group([ (3,4), (1,4)(2,3), (1,3)(2,4) ])
gap> g.operations.SylowSubgroup( g, 2 );
my method for `SylowSubgroup':
Group([ (3,4), (1,4)(2,3), (1,3)(2,4) ])

gap> STOP_TEST( "compat3.tst", infinity );


#############################################################################
##
#E