File: addmagma.gi

package info (click to toggle)
gap 4r8p6-2
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 33,476 kB
  • ctags: 7,663
  • sloc: ansic: 108,841; xml: 47,807; sh: 3,628; perl: 2,342; makefile: 796; asm: 62; awk: 6
file content (805 lines) | stat: -rw-r--r-- 25,050 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
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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
#############################################################################
##
#W  addmagma.gi                 GAP library                     Thomas Breuer
##
##
#Y  Copyright (C)  1997,  Lehrstuhl D für Mathematik,  RWTH Aachen,  Germany
#Y  (C) 1998 School Math and Comp. Sci., University of St Andrews, Scotland
#Y  Copyright (C) 2002 The GAP Group
##


#############################################################################
##
#M  Print( <A> )  . . . . . . . . . . . . . . . . . . print an additive magma
##
InstallMethod( PrintObj,
    "for an add. magma",
    [ IsAdditiveMagma ],
    function( A )
    Print( "AdditiveMagma( ... )" );
    end );

InstallMethod( PrintObj,
    "for an add. magma with generators",
    [ IsAdditiveMagma and HasGeneratorsOfAdditiveMagma ],
    function( A )
    Print( "AdditiveMagma( ", GeneratorsOfAdditiveMagma( A ), " )" );
    end );

InstallMethod( PrintObj,
    "for an add. magma-with-zero with generators",
    [ IsAdditiveMagmaWithZero and HasGeneratorsOfAdditiveMagmaWithZero ],
    function( A )
    if IsEmpty( GeneratorsOfAdditiveMagmaWithZero( A ) ) then
      Print( "AdditiveMagmaWithZero( ", Zero( A ), " )" );
    else
      Print( "AdditiveMagmaWithZero( ",
             GeneratorsOfAdditiveMagmaWithZero( A ), " )" );
    fi;
    end );

InstallMethod( PrintObj,
    "for an add. magma-with-inverses with generators",
    [ IsAdditiveGroup and HasGeneratorsOfAdditiveGroup ],
    function( A )
    if IsEmpty( GeneratorsOfAdditiveGroup( A ) ) then
      Print( "AdditiveGroup( ", Zero( A ), " )" );
    else
      Print( "AdditiveGroup( ",
             GeneratorsOfAdditiveGroup( A ), " )" );
    fi;
    end );


#############################################################################
##
#M  ViewObj( <A> )  . . . . . . . . . . . . . . . . . . .  view an add. magma
##
InstallMethod( ViewObj,
    "for an add. magma",
    [ IsAdditiveMagma ],
    function( A )
    Print( "<additive magma>" );
    end );

InstallMethod( ViewObj,
    "for an add. magma with generators",
    [ IsAdditiveMagma and HasGeneratorsOfAdditiveMagma ],
    function( A )
    Print( "<additive magma with ",
           Length( GeneratorsOfAdditiveMagma( A ) ), " generators>" );
    end );

InstallMethod( ViewObj,
    "for an add. magma-with-zero with generators",
    [ IsAdditiveMagmaWithZero and HasGeneratorsOfAdditiveMagmaWithZero ],
    function( A )
    if IsEmpty( GeneratorsOfAdditiveMagmaWithZero( A ) ) then
      Print( "<trivial additive magma-with-zero>" );
    else
      Print( "<additive magma-with-zero with ",
             Length( GeneratorsOfAdditiveMagmaWithZero( A ) ),
             " generators>" );
    fi;
    end );

InstallMethod( ViewObj,
    "for an add. magma-with-inverses with generators",
    [ IsAdditiveGroup and HasGeneratorsOfAdditiveGroup ],
    function( A )
    if IsEmpty( GeneratorsOfAdditiveGroup( A ) ) then
      Print( "<trivial additive magma-with-inverses>" );
    else
      Print( "<additive magma-with-inverses with ",
             Length( GeneratorsOfAdditiveGroup( A ) ),
             " generators>" );
    fi;
    end );


#############################################################################
##
#M  IsTrivial( <A> )  . . . . . . . test whether an additive magma is trivial
##
InstallImmediateMethod( IsTrivial,
    IsAdditiveMagmaWithZero and HasGeneratorsOfAdditiveMagmaWithZero, 0,
    function( A )
    return ForAll( GeneratorsOfAdditiveMagmaWithZero( A ), IsZero );
    end );

InstallImmediateMethod( IsTrivial,
    IsAdditiveGroup and HasGeneratorsOfAdditiveGroup, 0,
    function( A )
    return ForAll( GeneratorsOfAdditiveGroup( A ), IsZero );
    end );


#############################################################################
##
#F  AdditiveMagma( <gens> )
#F  AdditiveMagma( <Fam>, <gens> )
##
InstallGlobalFunction( AdditiveMagma, function( arg )

    # list of generators
    if Length( arg ) = 1 and IsList( arg[1] ) and 0 < Length( arg[1] ) then
      return AdditiveMagmaByGenerators( arg[1] );

    # family plus list of generators
    elif Length( arg ) = 2 and IsFamily( arg[1] ) and IsList( arg[1] ) then
      return AdditiveMagmaByGenerators( arg[1], arg[2] );

    # generators
    elif 0 < Length( arg ) then
      return AdditiveMagmaByGenerators( arg );
    fi;

    # no argument given, error
    Error("usage: AdditiveMagma(<gens>), AdditiveMagma(<Fam>,<gens>)");
end );


#############################################################################
##
#F  SubadditiveMagma( <M>, <gens> )  add. submagma of <M> generated by <gens>
##
InstallGlobalFunction( SubadditiveMagma, function( M, gens )

    if not IsAdditiveMagma( M ) then
        Error( "<M> must be an additive magma" );
    elif IsEmpty( gens ) then
        return SubadditiveMagmaNC( M, gens );
    elif not IsHomogeneousList(gens)  then
        Error( "<gens> must be a homogeneous list of elements" );
    elif not IsIdenticalObj( FamilyObj(M), FamilyObj(gens) )  then
        Error( "families of <gens> and <M> are different" );
    fi;
    if not ForAll( gens, x -> x in M ) then
        Error( "<gens> must be elements in <M>" );
    fi;
    return SubadditiveMagmaNC( M, gens );
end );


#############################################################################
##
#F  SubadditiveMagmaNC( <M>, <gens> )
##
##  Note that `SubadditiveMagmaNC' is allowed to call `Objectify'
##  in the case that <gens> is empty.
##
InstallGlobalFunction( SubadditiveMagmaNC, function( M, gens )
    local K, S;

    if IsEmpty( gens ) then
      K:= NewType( FamilyObj(M),
                       IsAdditiveMagma
                   and IsTrivial
                   and IsAttributeStoringRep );
      S:= Objectify( K, rec() );
      SetGeneratorsOfAdditiveMagma( S, [] );
    else
      S:= AdditiveMagmaByGenerators(gens);
    fi;
    SetParent( S, M );
    return S;

end );


#############################################################################
##
#F  AdditiveMagmaWithZero( <gens> )
#F  AdditiveMagmaWithZero( <Fam>, <gens> )
##
InstallGlobalFunction( AdditiveMagmaWithZero, function( arg )

    # list of generators
    if Length( arg ) = 1 and IsList( arg[1] ) and 0 < Length( arg[1] ) then
      return AdditiveMagmaWithZeroByGenerators( arg[1] );

    # family plus list of generators
    elif Length( arg ) = 2 and IsFamily( arg[1] ) and IsList( arg[1] ) then
      return AdditiveMagmaWithZeroByGenerators( arg[1], arg[2] );

    # generators
    elif 0 < Length( arg ) then
      return AdditiveMagmaWithZeroByGenerators( arg );
    fi;

    # no argument given, error
    Error("usage: AdditiveMagmaWithZero(<gens>), ",
          "AdditiveMagmaWithZero(<Fam>,<gens>)");

end );


#############################################################################
##
#F  SubadditiveMagmaWithZero( <M>, <gens> )
#F                        . . .  add. submagma-with-one of <M> gen. by <gens>
##
InstallGlobalFunction( SubadditiveMagmaWithZero, function( M, gens )
    if not IsAdditiveMagmaWithZero( M ) then
        Error( "<M> must be an additive magma-with-zero" );
    elif IsEmpty( gens ) then
        return SubadditiveMagmaWithZeroNC( M, gens );
    elif not IsHomogeneousList(gens)  then
        Error( "<gens> must be a homogeneous list of elements" );
    elif not IsIdenticalObj( FamilyObj(M), FamilyObj(gens) )  then
        Error( "families of <gens> and <M> are different" );
    fi;
    if not ForAll( gens, x -> x in M ) then
        Error( "<gens> must be elements in <M>" );
    fi;
    return SubadditiveMagmaWithZeroNC( M, gens );
end );


#############################################################################
##
#F  SubadditiveMagmaWithZeroNC( <M>, <gens> )
##
##  Note that `SubadditiveMagmaWithZeroNC' is allowed to call `Objectify'
##  in the case that <gens> is empty.
##
##  Furthermore note that a trivial additive magma with zero is automatically
##  an additive group.
##
InstallGlobalFunction( SubadditiveMagmaWithZeroNC, function( M, gens )
    local K, S;

    if IsEmpty( gens ) then
      K:= NewType( FamilyObj(M),
                       IsAdditiveGroup
                   and IsTrivial
                   and IsAttributeStoringRep );
      S:= Objectify( K, rec() );
      SetGeneratorsOfAdditiveGroup( S, [] );
    else
      S:= AdditiveMagmaWithZeroByGenerators(gens);
    fi;
    SetParent( S, M );
    return S;
end );


#############################################################################
##
#F  AdditiveGroup( <gens> )
#F  AdditiveGroup( <Fam>, <gens> )
##
InstallGlobalFunction( AdditiveGroup, function( arg )

    # list of generators
    if Length( arg ) = 1 and IsList( arg[1] ) and 0 < Length( arg[1] ) then
      return AdditiveGroupByGenerators( arg[1] );

    # family plus list of generators
    elif Length( arg ) = 2 and IsFamily( arg[1] ) and IsList( arg[1] ) then
      return AdditiveGroupByGenerators( arg[1], arg[2] );

    # generators
    elif 0 < Length( arg ) then
      return AdditiveGroupByGenerators( arg );
    fi;

    # no argument given, error
    Error("usage: AdditiveGroup(<gens>), ",
          "AdditiveGroup(<Fam>,<gens>)");
end );


#############################################################################
##
#F  SubadditiveGroup( <M>, <gens> ) . . . add. subgroup of <M> gen. by <gens>
##
InstallGlobalFunction( SubadditiveGroup, function( M, gens )
    if not IsAdditiveGroup( M ) then
        Error( "<M> must be an additive group" );
    elif IsEmpty( gens ) then
        return SubadditiveGroupNC( M, gens );
    elif not IsHomogeneousList(gens)  then
        Error( "<gens> must be a homogeneous list of elements" );
    elif not IsIdenticalObj( FamilyObj(M), FamilyObj(gens) )  then
        Error( "families of <gens> and <M> are different" );
    fi;
    if not ForAll( gens, x -> x in M ) then
        Error( "<gens> must be elements in <M>" );
    fi;
    return SubadditiveGroupNC( M, gens );
end );


#############################################################################
##
#F  SubadditiveGroupNC( <M>, <gens> )
##
##  Note that `SubadditiveGroupNC' is allowed to call `Objectify'
##  in the case that <gens> is empty.
##
InstallGlobalFunction( SubadditiveGroupNC, function( M, gens )
    local K, S;

    if IsEmpty( gens ) then
      K:= NewType( FamilyObj(M),
                       IsAdditiveGroup
                   and IsTrivial
                   and IsAttributeStoringRep );
      S:= Objectify( K, rec() );
      SetGeneratorsOfAdditiveGroup( S, [] );
    else
      S:= AdditiveGroupByGenerators(gens);
    fi;
    SetParent( S, M );
    return S;
end );


#############################################################################
##
#M  TrivialSubadditiveMagmaWithZero( <M> )  . . . for an add.-magma-with-zero
##
InstallMethod( TrivialSubadditiveMagmaWithZero,
    "for add.-magma-with-zero",
    [ IsAdditiveMagmaWithZero ],
    M -> SubadditiveMagmaWithZeroNC( M, [] ) );


#############################################################################
##
#M  AdditiveMagmaByGenerators( <gens> ) . . . . . . . . . .  for a collection
##
InstallMethod( AdditiveMagmaByGenerators,
    "for collection",
    [ IsCollection ],
    function( gens )
    local M;
    M:= Objectify( NewType( FamilyObj( gens ),
                            IsAdditiveMagma and IsAttributeStoringRep ),
                   rec() );
    SetGeneratorsOfAdditiveMagma( M, AsList( gens ) );
    return M;
    end );


#############################################################################
##
#M  AdditiveMagmaByGenerators( <Fam>, <gens> )  . . . . . for family and list
##
InstallOtherMethod( AdditiveMagmaByGenerators,
    "for family and list",
    [ IsFamily, IsList ],
    function( family, gens )
    local M;
    if not ( IsEmpty(gens) or IsIdenticalObj( FamilyObj(gens), family ) ) then
      Error( "<family> and family of <gens> do not match" );
    fi;
    M:= Objectify( NewType( family,
                            IsAdditiveMagma and IsAttributeStoringRep ),
                   rec() );
    SetGeneratorsOfAdditiveMagma( M, AsList( gens ) );
    return M;
    end );


#############################################################################
##
#M  AdditiveMagmaWithZeroByGenerators( <gens> ) . . . . . .  for a collection
##
InstallMethod( AdditiveMagmaWithZeroByGenerators,
    "for collection",
    [ IsCollection ],
    function( gens )
    local M;
    M:= Objectify( NewType( FamilyObj( gens ),
                       IsAdditiveMagmaWithZero and IsAttributeStoringRep ),
                   rec() );
    SetGeneratorsOfAdditiveMagmaWithZero( M, AsList( gens ) );
    return M;
    end );


#############################################################################
##
#M  AdditiveMagmaWithZeroByGenerators( <Fam>, <gens> )  . for family and list
##
InstallOtherMethod( AdditiveMagmaWithZeroByGenerators,
    "for family and list",
    [ IsFamily, IsList ],
    function( family, gens )
    local M;
    if not ( IsEmpty(gens) or IsIdenticalObj( FamilyObj(gens), family ) ) then
      Error( "<family> and family of <gens> do not match" );
    fi;
    M:= Objectify( NewType( family,
                       IsAdditiveMagmaWithZero and IsAttributeStoringRep ),
                   rec() );
    SetGeneratorsOfAdditiveMagmaWithZero( M, AsList( gens ) );
    return M;
    end );


#############################################################################
##
#M  AdditiveGroupByGenerators( <gens> ) . . . .  for a collection
##
InstallMethod( AdditiveGroupByGenerators,
    "for collection",
    [ IsCollection ],
    function( gens )
    local M;
    M:= Objectify( NewType( FamilyObj( gens ),
                     IsAdditiveGroup and IsAttributeStoringRep ),
                   rec() );
    SetGeneratorsOfAdditiveGroup( M, AsList( gens ) );
    return M;
    end );


#############################################################################
##
#M  AdditiveGroupByGenerators(<Fam>,<gens>) . for family and list
##
InstallOtherMethod( AdditiveGroupByGenerators,
    "for family and list",
    [ IsFamily, IsList ],
    function( family, gens )
    local M;
    if not ( IsEmpty(gens) or IsIdenticalObj( FamilyObj(gens), family ) ) then
      Error( "<family> and family of <gens> do not match" );
    fi;
    M:= Objectify( NewType( family,
                     IsAdditiveGroup and IsAttributeStoringRep ),
                   rec() );
    SetGeneratorsOfAdditiveGroup( M, AsList( gens ) );
    return M;
    end );


#############################################################################
##
#M  GeneratorsOfAdditiveMagma( <A> )
#M  GeneratorsOfAdditiveMagmaWithZero( <A> )
#M  GeneratorsOfAdditiveGroup( <A> )
##
##  If nothing special is known about the additive magma <A> we have
##  no chance to get the required generators.
##
##  If we know `GeneratorsOfAdditiveMagma',
##  they are also `GeneratorsOfAdditiveMagmaWithZero'.
##  If we know `GeneratorsOfAdditiveMagmaWithZero',
##  they are also `GeneratorsOfAdditiveGroup'.
##
InstallImmediateMethod( GeneratorsOfAdditiveMagmaWithZero,
    IsAdditiveMagmaWithZero and HasGeneratorsOfAdditiveMagma
    and IsAttributeStoringRep, 0,
    A -> GeneratorsOfAdditiveMagma( A ) );

InstallImmediateMethod( GeneratorsOfAdditiveGroup,
    IsAdditiveGroup and HasGeneratorsOfAdditiveMagmaWithZero
    and IsAttributeStoringRep, 0,
    A -> GeneratorsOfAdditiveMagmaWithZero( A ) );


InstallMethod( GeneratorsOfAdditiveMagma,
    [ IsAdditiveMagmaWithZero and HasGeneratorsOfAdditiveMagmaWithZero ],
    A -> Concatenation( GeneratorsOfAdditiveMagmaWithZero( A ),
              [ Zero( A ) ] ) );

InstallMethod( GeneratorsOfAdditiveMagma,
    [ IsAdditiveGroup and HasGeneratorsOfAdditiveGroup ],
    A -> Concatenation( GeneratorsOfAdditiveGroup( A ),
              [ Zero( A ) ],
              List( GeneratorsOfAdditiveGroup( A ),
                    AdditiveInverse ) ) );

InstallMethod( GeneratorsOfAdditiveMagmaWithZero,
    [ IsAdditiveGroup and HasGeneratorsOfAdditiveGroup ],
    A -> Concatenation( GeneratorsOfAdditiveGroup( A ),
              List( GeneratorsOfAdditiveGroup( A ),
                    AdditiveInverse ) ) );


#############################################################################
##
#M  Representative( <A> ) . . . . . . . . .  one element of an additive magma
##
InstallMethod( Representative,
    "for additive magma with known generators",
    [ IsAdditiveMagma and HasGeneratorsOfAdditiveMagma ],
    RepresentativeFromGenerators( GeneratorsOfAdditiveMagma ) );

InstallMethod( Representative,
    "for additive-magma-with-zero with known generators",
    [ IsAdditiveMagmaWithZero and HasGeneratorsOfAdditiveMagmaWithZero ],
    RepresentativeFromGenerators( GeneratorsOfAdditiveMagmaWithZero ) );

InstallMethod( Representative,
    "for additive-magma-with-inverses with known generators",
    [ IsAdditiveGroup and HasGeneratorsOfAdditiveGroup ],
    RepresentativeFromGenerators( GeneratorsOfAdditiveGroup ) );

InstallMethod( Representative,
    "for additive-magma-with-zero with known zero",
    [ IsAdditiveMagmaWithZero and HasZero ], SUM_FLAGS,
    Zero );

InstallMethod( Representative,
    "for additive-magma-with-zero with stored parent",
    [ IsAdditiveMagmaWithZero and HasParentAttr ],
    function( A )
    if not IsIdenticalObj( A, Parent( A ) ) then
      return Zero( Representative( Parent( A ) ) );
    fi;
    TryNextMethod();
    end );


#############################################################################
##
#M  AdditiveNeutralElement( <A> ) . . . . . . . . . zero of an additive magma
##
InstallMethod( AdditiveNeutralElement,
    [ IsAdditiveMagma ],
    function( M )
    local m;
    if IsFinite( M ) then
      for m in M do
        if ForAll( M, n -> n + m = n ) then
          return m;
        fi;
      od;
      return fail;
    else
      TryNextMethod();
    fi;
    end );


#############################################################################
##
#M  Zero( <A> ) . . . . . . . . . . . . . . . . . . zero of an additive magma
##
InstallOtherMethod( Zero,
    "for additive magma",
    [ IsAdditiveMagma ],
    function( A )
    local zero;
    zero:= Zero( Representative( A ) );
    if zero <> fail and zero in A then
      return zero;
    else
      return fail;
    fi;
    end );

InstallOtherMethod( Zero,
    "for additive magma with zero (look at family)",
    [ IsAdditiveMagmaWithZero ], SUM_FLAGS,
    function( A )
    A:= ElementsFamily( FamilyObj( A ) );
    if HasZero( A ) then
      return Zero( A );
    else
      TryNextMethod();
    fi;
    end );
#T immediate?

InstallOtherMethod( Zero,
    "for an add. magma-with-zero with parent (ask the parent)",
    [ IsAdditiveMagmaWithZero and HasParent ],
    function( A )
    if not IsIdenticalObj( A, Parent( A ) ) then
      return Zero( Parent( A ) );
    fi;
    TryNextMethod();
    end );
#T really ask the parent for such information?

InstallOtherMethod( Zero,
    "for additive magma with zero",
    [ IsAdditiveMagmaWithZero ],
    A -> Zero( Representative( A ) ) );


#############################################################################
##
#M  Characteristic(<obj>)
##

InstallMethod( Characteristic,
    "delegate to family (magma)",
    [ IsAdditiveMagmaWithZero ],
    function( el )
      return Characteristic( FamilyObj(el) );
    end );

#############################################################################
##
#M  Enumerator( <A> ) . . . .  enumerator of trivial additive magma with zero
##
EnumeratorOfTrivialAdditiveMagmaWithZero := A -> Immutable( [ Zero( A ) ] );

InstallMethod( Enumerator,
    "for trivial add. magma-with-zero",
    [ IsAdditiveMagmaWithZero and IsTrivial ],
    EnumeratorOfTrivialAdditiveMagmaWithZero );


#############################################################################
##
#F  ClosureAdditiveMagmaDefault( <A>, <elm> )  closure of add. magma with elm
##
BindGlobal( "ClosureAdditiveMagmaDefault", function( A, elm )
    local   C,          # closure `\< <a>, <obj> \>', result
            gens,       # generators of <A>
            gen,        # generator of <A> or <C>
            Celements,  # intermediate list of elements
            len;        # current number of elements

    gens:= GeneratorsOfAdditiveMagma( A );

    # try to avoid adding an element to a add. magma that already contains it
    if   elm in gens
      or ( HasAsSSortedList( A ) and elm in AsSSortedList( A ) )
    then
        return A;
    fi;

    # make the closure add. magma
    gens:= Concatenation( gens, [ elm ] );
    C:= AdditiveMagmaByGenerators( gens );
    UseSubsetRelation( C, A );

    # if the elements of <A> are known then extend this list
    # (multiply each element from the left and right with the new
    # generator, and then multiply with all elements until the
    # list becomes stable)
    if HasAsSSortedList( A ) then

        Celements := ShallowCopy( AsSSortedList( A ) );
        AddSet( Celements, elm );
        UniteSet( Celements, Celements + elm );
        UniteSet( Celements, elm + Celements );
        repeat
            len:= Length( Celements );
            for gen in Celements do
                UniteSet( Celements, Celements + gen );
                UniteSet( Celements, gen + Celements );
            od;
        until len = Length( Celements );

        SetAsSSortedList( C, AsSSortedList( Celements ) );
        SetIsFinite( C, true );
        SetSize( C, Length( Celements ) );

    fi;

    # return the closure
    return C;
end );


#############################################################################
##
#M  Enumerator( <A> ) . . . . . . . . .  set of the elements of an add. magma
##
BindGlobal( "EnumeratorOfAdditiveMagma", function( A )
    local   gens,       # add. magma generators of <A>
            H,          # subadd. magma of the first generators of <A>
            gen;        # generator of <A>

    # handle the case of an empty add. magma
    gens:= GeneratorsOfAdditiveMagma( A );
    if IsEmpty( gens ) then
      return [];
    fi;

    # start with the empty add. magma and its element list
    H:= SubadditiveMagma( A, [] );
    SetAsSSortedList( H, Immutable( [ ] ) );

    # Add the generators one after the other.
    # We use a function that maintains the elements list for the closure.
    for gen in gens do
      H:= ClosureAdditiveMagmaDefault( H, gen );
    od;

    # return the list of elements
    Assert( 2, HasAsSSortedList( H ) );
    return AsSSortedList( H );
end );

InstallMethod( Enumerator,
    "generic method for an add. magma",
    [ IsAdditiveMagma and IsAttributeStoringRep ],
    EnumeratorOfAdditiveMagma );



#############################################################################
##
#M  IsSubset( <M>, <N> )  . . . . . . . . . . . . . . for two additive magmas
##
InstallMethod( IsSubset,
    "for two additive magmas",
    IsIdenticalObj,
    [ IsAdditiveMagma, IsAdditiveMagma ],
    function( M, N )
    return IsSubset( M, GeneratorsOfAdditiveMagma( N ) );
    end );


#############################################################################
##
#M  IsSubset( <M>, <N> )  . . . . . . . . . for two additive magmas with zero
##
InstallMethod( IsSubset,
    "for two additive magmas with zero",
    IsIdenticalObj,
    [ IsAdditiveMagmaWithZero, IsAdditiveMagmaWithZero ],
    function( M, N )
    return IsSubset( M, GeneratorsOfAdditiveMagmaWithZero( N ) );
    end );


#############################################################################
##
#M  IsSubset( <M>, <N> )  . . . . . . . for two additive magmas with inverses
##
InstallMethod( IsSubset,
    "for two additive magmas with inverses",
    IsIdenticalObj,
    [ IsAdditiveGroup, IsAdditiveGroup ],
    function( M, N )
    return IsSubset( M, GeneratorsOfAdditiveGroup( N ) );
    end );


#############################################################################
##
#M  ClosureAdditiveGroup( <A>, <a> )  . . . . . .  for add. group and element
##
InstallMethod( ClosureAdditiveGroup,
    "for add. group and element",
    IsCollsElms,
    [ IsAdditiveGroup, IsAdditiveElement ],
    function( A, a )

    # if possible test if the element lies in the add. group already
    if a in GeneratorsOfAdditiveGroup( A ) or
       ( HasAsList( A ) and a in AsList( A ) ) then
      return A;
    fi;

    # Otherwise make a new add. group.
    return AdditiveGroupByGenerators(
               Concatenation( GeneratorsOfAdditiveGroup( A ), [ a ] ) );
    end );


#############################################################################
##
#M  ClosureAdditiveGroup( <A>, <B> )  . . . . . . . . . . for two add. groups
##
InstallOtherMethod( ClosureAdditiveGroup,
    "for two add. groups",
    IsIdenticalObj,
    [ IsAdditiveGroup, IsAdditiveGroup ],
    function( A, B )
    local C, b;
    C:= A;
    for b in GeneratorsOfAdditiveGroup( B ) do
      C:= ClosureAdditiveGroup( C, b );
    od;
    return C;
    end );


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