This file is indexed.

/usr/share/gap/lib/ideal.gi is in gap-libs 4r7p9-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
#############################################################################
##
#W  ideal.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
##
##


#############################################################################
##
#F  TwoSidedIdeal( <R>, <gens> )
#F  TwoSidedIdeal( <R>, <gens>, "basis" )
##
InstallGlobalFunction( TwoSidedIdeal, function( arg )
    local I;
    if    Length( arg ) <= 1
       or not IsRing( arg[1] )
       or not IsHomogeneousList( arg[2] ) then
      Error( "first argument must be a ring,\n",
             "second argument must be a list of generators" );

    elif IsEmpty( arg[2] ) then

      return TwoSidedIdealNC( arg[1], arg[2] );

    elif     IsIdenticalObj( FamilyObj( arg[1] ),
                          FamilyObj( arg[2] ) )
         and ForAll( arg[2], v -> v in arg[1] ) then

      I:= IdealByGenerators( arg[1], arg[2] );
      if Length( arg ) = 3 and arg[3] = "basis" then
        UseBasis( I, arg[2] );
      fi;
      UseSubsetRelation( arg[1], I );
      return I;

    fi;
    Error( "usage: TwoSidedIdeal( <R>, <gens> [, \"basis\"] )" );
end );


#############################################################################
##
#F  TwoSidedIdealNC( <R>, <gens>, "basis" )
#F  TwoSidedIdealNC( <R>, <gens> )
##
InstallGlobalFunction( TwoSidedIdealNC, function( arg )
    local I;
    if IsEmpty( arg[2] ) then

      # If <R> is a FLMLOR then also the ideal is a FLMLOR.
      if IsFLMLOR( arg[1] ) then
        I:= SubFLMLORNC( arg[1], arg[2] );
      else
        I:= Objectify( NewType( FamilyObj( arg[1] ),
                                    IsRing
                                and IsTrivial
                                and IsAttributeStoringRep ),
                       rec() );
      fi;
      SetGeneratorsOfRing( I, AsList( arg[2] ) );
      SetLeftActingRingOfIdeal( I, arg[1] );
      SetRightActingRingOfIdeal( I, arg[1] );

    else

      I:= TwoSidedIdealByGenerators( arg[1], arg[2] );

    fi;
    if Length( arg ) = 3 and arg[3] = "basis" then
      UseBasis( I, arg[2] );
    fi;
    UseSubsetRelation( arg[1], I );
    return I;
end );


#############################################################################
##
#F  LeftIdeal( <R>, <gens> )
#F  LeftIdeal( <R>, <gens>, "basis" )
##
InstallGlobalFunction( LeftIdeal, function( arg )
    local I;
    if    Length( arg ) <= 1
       or not IsRing( arg[1] )
       or not IsHomogeneousList( arg[2] ) then
      Error( "first argument must be a ring,\n",
             "second argument must be a list of generators" );

    elif IsEmpty( arg[2] ) then

      return TwoSidedIdealNC( arg[1], arg[2] );

    elif     IsIdenticalObj( FamilyObj( arg[1] ),
                          FamilyObj( arg[2] ) )
         and ForAll( arg[2], v -> v in arg[1] ) then

      I:= LeftIdealByGenerators( arg[1], arg[2] );
      if Length( arg ) = 3 and arg[3] = "basis" then
        UseBasis( I, arg[2] );
      fi;
      UseSubsetRelation( arg[1], I );
      return I;

    fi;
    Error( "usage: LeftIdeal( <R>, <gens> [, \"basis\"] )" );
end );


#############################################################################
##
#F  LeftIdealNC( <R>, <gens>, "basis" )
#F  LeftIdealNC( <R>, <gens> )
##
InstallGlobalFunction( LeftIdealNC, function( arg )
    local I;
    if IsEmpty( arg[2] ) then
      return TwoSidedIdealNC( arg[1], arg[2] );
    fi;

    I:= LeftIdealByGenerators( arg[1], arg[2] );
    if Length( arg ) = 3 and arg[3] = "basis" then
      UseBasis( I, arg[2] );
    fi;
    UseSubsetRelation( arg[1], I );

    return I;
end );


#############################################################################
##
#F  RightIdeal( <R>, <gens> )
#F  RightIdeal( <R>, <gens>, "basis" )
##
InstallGlobalFunction( RightIdeal, function( arg )
    local I;
    if    Length( arg ) <= 1
       or not IsRing( arg[1] )
       or not IsHomogeneousList( arg[2] ) then
      Error( "first argument must be a ring,\n",
             "second argument must be a list of generators" );

    elif IsEmpty( arg[2] ) then

      return TwoSidedIdealNC( arg[1], arg[2] );

    elif     IsIdenticalObj( FamilyObj( arg[1] ),
                          FamilyObj( arg[2] ) )
         and ForAll( arg[2], v -> v in arg[1] ) then

      I:= RightIdealByGenerators( arg[1], arg[2] );
      if Length( arg ) = 3 and arg[3] = "basis" then
        UseBasis( I, arg[2] );
      fi;
      UseSubsetRelation( arg[1], I );
      return I;

    fi;
    Error( "usage: RightIdeal( <R>, <gens> [, \"basis\"] )" );
end );


#############################################################################
##
#F  RightIdealNC( <R>, <gens>, "basis" )
#F  RightIdealNC( <R>, <gens> )
##
InstallGlobalFunction( RightIdealNC, function( arg )
    local I;
    if IsEmpty( arg[2] ) then
      return TwoSidedIdealNC( arg[1], arg[2] );
    fi;

    I:= RightIdealByGenerators( arg[1], arg[2] );
    if Length( arg ) = 3 and arg[3] = "basis" then
      UseBasis( I, arg[2] );
    fi;
    UseSubsetRelation( arg[1], I );

    return I;
end );


#############################################################################
##
#M  TwoSidedIdealByGenerators( <R>, <gens> ) . . .  create an ideal in a ring
##
InstallMethod( TwoSidedIdealByGenerators,
    "for ring and collection",
    IsIdenticalObj,
    [ IsRing, IsCollection ], 0,
    function( R, gens )
    local I;
    I:= Objectify( NewType( FamilyObj( R ),
                                IsRing
                            and IsAttributeStoringRep ),
                   rec() );
    SetGeneratorsOfTwoSidedIdeal( I, gens );
    SetLeftActingRingOfIdeal( I, R );
    SetRightActingRingOfIdeal( I, R );
    return I;
    end );
    

#############################################################################
##
#M  LeftIdealByGenerators( <R>, <gens> ) . . .  create a left ideal in a ring
##
InstallMethod( LeftIdealByGenerators,
    "for ring and collection",
    IsIdenticalObj,
    [ IsRing, IsCollection ], 0,
    function( R, gens )
    local I;
    I:= Objectify( NewType( FamilyObj( R ),
                                IsRing
                            and IsAttributeStoringRep ),
                   rec() );
    SetGeneratorsOfLeftIdeal( I, gens );
    SetLeftActingRingOfIdeal( I, R );
    return I;
    end );


#############################################################################
##
#M  RightIdealByGenerators( <R>, <gens> ) . .  create a right ideal in a ring
##
InstallMethod( RightIdealByGenerators,
    "for ring and collection",
    IsIdenticalObj,
    [ IsRing, IsCollection ], 0,
    function( R, gens )
    local I;
    I:= Objectify( NewType( FamilyObj( R ),
                                IsRing
                            and IsAttributeStoringRep ),
                   rec() );
    SetGeneratorsOfRightIdeal( I, gens );
    SetRightActingRingOfIdeal( I, R );
    return I;
    end );


#############################################################################
##
#M  LeftIdealByGenerators(  <R>, <gens> )  . . . . . .  for commutative rings
#M  RightIdealByGenerators( <R>, <gens> )  . . . . . .  for commutative rings
##
##  If R is a commutative ring, then we create a two-sided ideal in a ring R
##  instead of its left or right ideal
##
InstallMethod( LeftIdealByGenerators,
    "to construct ideals of commutative rings",
    true,
    [ IsFLMLOR and IsCommutative, IsCollection ],
    0,
    function( R, gens )
    return TwoSidedIdealByGenerators( R, gens );
    end );

InstallMethod( RightIdealByGenerators,
    "to construct ideals of commutative rings",
    true,
    [ IsFLMLOR and IsCommutative, IsCollection ],
    0,
    function( R, gens )
    return TwoSidedIdealByGenerators( R, gens );
    end );
    

#############################################################################
##
#M  IsIdealInParent(<I>)  . for left resp. right ideals in a commutative ring
##
InstallImmediateMethod( IsIdealInParent,
    IsLeftIdealInParent and HasParent, 10,
    function( I )
    I:= Parent( I );
    if    ( HasIsCommutative( I ) and IsCommutative( I ) )
       or ( HasIsAnticommutative( I ) and IsAnticommutative( I ) ) then
      return true;
    else
      TryNextMethod();
    fi;
    end );

InstallImmediateMethod( IsIdealInParent,
    IsRightIdealInParent and HasParent, 10,
    function( I )
    I:= Parent( I );
    if    ( HasIsCommutative( I ) and IsCommutative( I ) )
       or ( HasIsAnticommutative( I ) and IsAnticommutative( I ) ) then
      return true;
    else
      TryNextMethod();
    fi;
    end );


#############################################################################
##
#M  PrintObj( <I> ) . . . . . . . . . . . . . . . . . . . . . .  for an ideal
##
InstallMethod( PrintObj,
    "for a left ideal with known generators",
    true,
    [ IsRing and HasLeftActingRingOfIdeal and HasGeneratorsOfLeftIdeal ],
    0,
    function( I )
    Print( "LeftIdeal( ", LeftActingRingOfIdeal( I ), ", ",
           GeneratorsOfLeftIdeal( I ), " )" );
    end );

InstallMethod( PrintObj,
    "for a right ideal with known generators",
    true,
    [ IsRing and HasRightActingRingOfIdeal and HasGeneratorsOfRightIdeal ],
    0,
    function( I )
    Print( "RightIdeal( ", RightActingRingOfIdeal( I ), ", ",
           GeneratorsOfRightIdeal( I ), " )" );
    end );

InstallMethod( PrintObj,
    "for a two-sided ideal with known generators",
    true,
    [ IsRing and HasLeftActingRingOfIdeal and HasRightActingRingOfIdeal
             and HasGeneratorsOfTwoSidedIdeal ],
    0,
    function( I )
    Print( "TwoSidedIdeal( ", RightActingRingOfIdeal( I ), ", ",
           GeneratorsOfTwoSidedIdeal( I ), " )" );
    end );


#############################################################################
##
#M  ViewObj( <I> )  . . . . . . . . . . . . . . . . . . . . . .  for an ideal
##
InstallMethod( ViewObj,
    "for a left ideal with known generators",
    true,
    [ IsRing and HasLeftActingRingOfIdeal and HasGeneratorsOfLeftIdeal ],
    100,  # stronger than methods for the different kinds of algebras
    function( I )
    Print( "\>\><left ideal in \>\>" );
    View( LeftActingRingOfIdeal( I ) );
    if HasDimension( I ) then
      Print( "\<,\< \>\>(dimension ", Dimension( I ), "\<\<\<\<)>" );
    else
      Print( "\<,\< \>\>(", Length( GeneratorsOfLeftIdeal( I ) ),
             " generators)\<\<\<\<>" );
    fi;
    end );

InstallMethod( ViewObj,
    "for a right ideal with known generators",
    true,
    [ IsRing and HasRightActingRingOfIdeal and HasGeneratorsOfRightIdeal ],
    100,  # stronger than methods for the different kinds of algebras
    function( I )
    Print( "\>\><right ideal in \>\>" );
    View( RightActingRingOfIdeal( I ) );
    if HasDimension( I ) then
      Print( "\<,\< \>\>(dimension ", Dimension( I ), "\<\<\<\<)>" );
    else
      Print( "\<,\< \>\>(", Length( GeneratorsOfRightIdeal( I ) ),
             " generators)\<\<\<\<>" );
    fi;
    end );

InstallMethod( ViewObj,
    "for a two-sided ideal with known generators",
    true,
    [ IsRing and HasLeftActingRingOfIdeal and HasRightActingRingOfIdeal
             and HasGeneratorsOfTwoSidedIdeal ],
    100,  # stronger than methods for the different kinds of algebras
    function( I )
    Print( "\>\><two-sided ideal in \>\>" );
    View( RightActingRingOfIdeal( I ) );
    if HasDimension( I ) then
      Print( "\<,\< \>\>(dimension ", Dimension( I ), "\<\<\<\<)>" );
    else
      Print( "\<,\< \>\>(", Length( GeneratorsOfTwoSidedIdeal( I ) ),
             " generators)\<\<\<\<>" );
    fi;
    end );


#############################################################################
##
#M  Zero( <I> ) . . . . . . . . . . . . . . . . . . . . . . . .  for an ideal
##
InstallOtherMethod( Zero,
    "for a left ideal",
    true,
    [ IsRing and HasLeftActingRingOfIdeal ], 0,
    I -> Zero( LeftActingRingOfIdeal( I ) ) );


InstallOtherMethod( Zero,
    "for a right ideal",
    true,
    [ IsRing and HasRightActingRingOfIdeal ], 0,
    I -> Zero( RightActingRingOfIdeal( I ) ) );


#############################################################################
##
#M  Enumerator( <I> ) . . . . . . . . . . . . . . . . . . . . .  for an ideal
##
EnumeratorOfIdeal := function( I )

    local   left,       # we must multiply with ring elements from the left
            right,      # we must multiply with ring elements from the right
            elms,       # elements of <I>, result
            set,        # set corresponding to <elms>
            Igens,      # ideal generators of <I>
            R,          # the acting ring
            Rgens,      # ring generators of `R'
	    elmsgens,   # additive generators
            elm,        # one element of <elms>
            gen,        # one generator of <I>
            new;        # product or sum of <elm> and <gen>

    # check that we can handle this ideal
    if HasIsFinite( I ) and not IsFinite( I ) then
        TryNextMethod();
    fi;

    # Check from what sides we must multiply with ring elements.
    if   HasGeneratorsOfLeftIdeal( I ) then
      Igens := GeneratorsOfLeftIdeal( I );
      R     := LeftActingRingOfIdeal( I );
      left  := true;
      right := false;
    elif HasGeneratorsOfRightIdeal( I ) then
      Igens := GeneratorsOfRightIdeal( I );
      R     := RightActingRingOfIdeal( I );
      left  := false;
      right := true;
    elif HasGeneratorsOfTwoSidedIdeal( I ) then
      Igens := GeneratorsOfTwoSidedIdeal( I );
      R     := LeftActingRingOfIdeal( I );
      left  := true;
      right := true;
    else
      TryNextMethod();
    fi;


    # the elements of the ideal are sums of elements of the form r*g*s where
    # g is an ideal generator and r and s are ring elements. Therefore
    # *first* compute the ring multiples of the generators and then form the
    # additive closure.
    elms := Set(ShallowCopy(Igens));
    set  := ShallowCopy( elms );

    # Compute the closure under the action of the acting ring
    # from the left and from the right.
    # If this ring is associative then it is sufficient to multiply
    # with generators, otherwise we act with all elements.
    if HasIsAssociative( R ) and IsAssociative( R ) then
      Rgens:= GeneratorsOfRing( R );
    else
      Rgens:= Enumerator( R );
    fi;
    for elm  in elms  do
        for gen  in Rgens  do
            if left then
              new := gen * elm;
              if not new in set  then
                  Add( elms, new );
                  AddSet( set, new );
              fi;
            fi;
            if right then
              new := elm * gen;
              if not new in set  then
                  Add( elms, new );
                  AddSet( set, new );
              fi;
            fi;
        od;
    od;

    elms := set;
    elmsgens:=ShallowCopy(elms);
    set  := ShallowCopy( elms );

    # Use an orbit like algorithm.
    # Compute the additive closure of elms
    for elm  in elms  do
        for gen  in elmsgens  do
            new := elm + gen;
            if not new in set  then
                Add( elms, new );
                AddSet( set, new );
            fi;
        od;
    od;

    return set;
end;

InstallMethod( Enumerator,
    "generic method for a left ideal with known generators",
    true,
    [ IsRing and HasGeneratorsOfLeftIdeal ], 0,
    EnumeratorOfIdeal );

InstallMethod( Enumerator,
    "generic method for a right ideal with known generators",
    true,
    [ IsRing and HasGeneratorsOfRightIdeal ], 0,
    EnumeratorOfIdeal );

InstallMethod( Enumerator,
    "generic method for a two-sided ideal with known generators",
    true,
    [ IsRing and HasGeneratorsOfIdeal ], 0,
    EnumeratorOfIdeal );



#############################################################################
##
#M  GeneratorsOfRing( <I> ) . . . . . . . . . . . . . . . . . .  for an ideal
##
GeneratorsOfRingForIdeal := function( I )

    local   left,       # we must multiply with ring elements from the left
            right,      # we must multiply with ring elements from the right
            Igens,      # ideal generators of <I>
            R,          # the acting ring
            Rgens,      # ring generators of `R'
            gens,       # generators list, result
            S,          # subring generated by `gens'
            s, r,       # loop over lists
            prod;       # product of `s' and `r'

    # check that we can handle this ideal
    if HasIsFinite( I ) and not IsFinite( I ) then
        TryNextMethod();
    fi;

    # Check from what sides we must multiply with elements
    # of the acting ring.
    if   HasGeneratorsOfLeftIdeal( I ) then
      Igens := GeneratorsOfLeftIdeal( I );
      R     := LeftActingRingOfIdeal( I );
      left  := true;
      right := false;
    elif HasGeneratorsOfRightIdeal( I ) then
      Igens := GeneratorsOfRightIdeal( I );
      R     := RightActingRingOfIdeal( I );
      left  := false;
      right := true;
    elif HasGeneratorsOfTwoSidedIdeal( I ) then
      Igens := GeneratorsOfTwoSidedIdeal( I );
      R     := LeftActingRingOfIdeal( I );
      left  := true;
      right := true;
    else
      Error( "no ideal generators of <I> known" );
    fi;

    # Handle the case of trivial ideals.
    if IsEmpty( Igens ) then
      return [];
    fi;

    # Start with the ring generated by the ideal generators,
    # and close it until it becomes stable.
    S     := SubringNC( R, Igens );
    gens  := ShallowCopy( Igens );
    Rgens := GeneratorsOfRing( R );
    for s in gens do
      for r in Rgens do
        if left then
          prod:= r * s;
          if not prod in S then
            S:= ClosureRing( S, prod );
            Add( gens, prod );
          fi;
        fi;
        if right then
          prod:= s * r;
          if not prod in S then
            S:= ClosureRing( S, prod );
            Add( gens, prod );
          fi;
        fi;
      od;
    od;

    return gens;
end;


InstallMethod( GeneratorsOfRing,
    "generic method for a left ideal with known generators",
    true,
    [ IsRing and HasGeneratorsOfLeftIdeal ], 0,
    GeneratorsOfRingForIdeal );

InstallMethod( GeneratorsOfRing,
    "generic method for a right ideal with known generators",
    true,
    [ IsRing and HasGeneratorsOfRightIdeal ], 0,
    GeneratorsOfRingForIdeal );

InstallMethod( GeneratorsOfRing,
    "generic method for a two-sided ideal with known generators",
    true,
    [ IsRing and HasGeneratorsOfTwoSidedIdeal ], 0,
    GeneratorsOfRingForIdeal );


#############################################################################
##
#M  GeneratorsOfTwoSidedIdeal( <I> )  . . .  for known left/right ideal gens.
#M  GeneratorsOfLeftIdeal( <I> )  . . . . . . for known two-sided ideal gens.
#M  GeneratorsOfRightIdeal( <I> ) . . . . . . for known two-sided ideal gens.
##
InstallMethod( GeneratorsOfTwoSidedIdeal,
    "for a two-sided ideal with known `GeneratorsOfLeftIdeal'",
    true,
    [ IsRing and HasLeftActingRingOfIdeal and HasRightActingRingOfIdeal
             and HasGeneratorsOfLeftIdeal ], 0,
    GeneratorsOfLeftIdeal );

InstallMethod( GeneratorsOfTwoSidedIdeal,
    "for a two-sided ideal with known `GeneratorsOfRightIdeal'",
    true,
    [ IsRing and HasLeftActingRingOfIdeal and HasRightActingRingOfIdeal
             and HasGeneratorsOfRightIdeal ], 0,
    GeneratorsOfRightIdeal );

InstallMethod( GeneratorsOfLeftIdeal,
    "for an ideal with known `GeneratorsOfTwoSidedIdeal'",
    true,
    [ IsRing and HasLeftActingRingOfIdeal and HasRightActingRingOfIdeal
             and HasGeneratorsOfTwoSidedIdeal ], 0,
    GeneratorsOfRing );

InstallMethod( GeneratorsOfRightIdeal,
    "for an ideal with known `GeneratorsOfTwoSidedIdeal'",
    true,
    [ IsRing and HasLeftActingRingOfIdeal and HasRightActingRingOfIdeal
             and HasGeneratorsOfTwoSidedIdeal ], 0,
    GeneratorsOfRing );

     
#############################################################################
##
#M  \+( <I1>, <I2> )  . . . . . . . . . . . . . . . . . . . sum of two ideals
##
InstallMethod( \+,
    "method for two left ideals",
    IsIdenticalObj,
    [ IsRing and HasLeftActingRingOfIdeal,
      IsRing and HasLeftActingRingOfIdeal ], 0,
    function( I1, I2 )
    if LeftActingRingOfIdeal( I1 ) <> LeftActingRingOfIdeal( I2 ) then
      TryNextMethod();
    else
      return LeftIdealByGenerators( LeftActingRingOfIdeal( I1 ),
                 Concatenation( GeneratorsOfLeftIdeal( I1 ),
                                GeneratorsOfLeftIdeal( I2 ) ) );
    fi;
    end );

InstallMethod( \+,
    "method for two right ideals",
    IsIdenticalObj,
    [ IsRing and HasRightActingRingOfIdeal,
      IsRing and HasRightActingRingOfIdeal ], 0,
    function( I1, I2 )
    if RightActingRingOfIdeal( I1 ) <> RightActingRingOfIdeal( I2 ) then
      TryNextMethod();
    else
      return RightIdealByGenerators( RightActingRingOfIdeal( I1 ),
                 Concatenation( GeneratorsOfRightIdeal( I1 ),
                                GeneratorsOfRightIdeal( I2 ) ) );
    fi;
    end );

InstallMethod( \+,
    "method for two two-sided ideals",
    IsIdenticalObj,
    [ IsRing and HasLeftActingRingOfIdeal and HasRightActingRingOfIdeal,
      IsRing and HasLeftActingRingOfIdeal and HasRightActingRingOfIdeal ], 0,
    function( I1, I2 )
    if RightActingRingOfIdeal( I1 ) <> RightActingRingOfIdeal( I2 ) then
      TryNextMethod();
    else
      return TwoSidedIdealByGenerators( RightActingRingOfIdeal( I1 ),
                 Concatenation( GeneratorsOfTwoSidedIdeal( I1 ),
                                GeneratorsOfTwoSidedIdeal( I2 ) ) );
    fi;
    end );


#############################################################################
##
#M  \*( <r>, <R> )  . . . . . . . . . . . . . . . . . construct a right ideal
#M  \*( <R>, <r> )  . . . . . . . . . . . . . . . . .  construct a left ideal
##
##  If <r> is an element in <R> then the result is the right or left ideal in
##  <R> spanned by <r>.
##  If <r> is not contained in <R> then the product is in general not closed
##  under multiplication, and the default is to return the strictly sorted
##  (note that the result shall be regarded as equal to the result of a
##  method that returns a domain object) list of elements.
##  (If <R> is trivial then the result is also trivial.)
##
InstallMethod( \*,
    "for ring element and ring (construct a right ideal)",
    IsElmsColls,
    [ IsRingElement, IsRing ], 0,
    function( r, R )
    local z;
    if r in R then
      return RightIdealByGenerators( R, [ r ] );
    fi;
    if IsTrivial( R ) then
      z:= Zero( R );
      if r * z = z then
        return R;
      else
        return [ r * z ];
      fi;
    elif IsFinite( R ) then
      return Set( List( Enumerator( R ), elm -> r * elm ) );
    else
      TryNextMethod();
    fi;
    end );

InstallMethod( \*,
    "for ring and ring element (construct a left ideal)",
    IsCollsElms,
    [ IsRing, IsRingElement ], 0,
    function( R, r )
    local z;
    if r in R then
      return LeftIdealByGenerators( R, [ r ] );
    fi;
    if IsTrivial( R ) then
      z:= Zero( R );
      if z * r = z then
        return R;
      else
        return [ z * r ];
      fi;
    elif IsFinite( R ) then
      return Set( List( Enumerator( R ), elm -> elm * r ) );
    else
      TryNextMethod();
    fi;
    end );


#############################################################################
##
#M  \*( <I>, <R> )  . . . . . . . . . . . . . . . construct a two-sided ideal
#M  \*( <R>, <I> )  . . . . . . . . . . . . . . . construct a two-sided ideal
##
InstallMethod( \*,
    "for left ideal and ring (construct a two-sided ideal)",
    IsIdenticalObj,
    [ IsRing and HasLeftActingRingOfIdeal, IsRing ], 0,
    function( I, R )
    if HasRightActingRingOfIdeal( I ) then
      if IsSubset( RightActingRingOfIdeal( I ), R ) and One(R) <> fail then
        return I;
      fi;
    elif LeftActingRingOfIdeal( I ) = R then
      return TwoSidedIdealByGenerators( R, GeneratorsOfLeftIdeal( I ) );
    else
      TryNextMethod();
    fi;
    end );

InstallMethod( \*,
    "for ring and right ideal (construct a two-sided ideal)",
    IsCollsElms,
    [ IsRing, IsRing and HasRightActingRingOfIdeal ], 0,
    function( R, I )
    if HasLeftActingRingOfIdeal( I ) then
      if IsSubset( LeftActingRingOfIdeal( I ), R ) and One(R) <> fail then
        return I;
      fi;
    elif RightActingRingOfIdeal( I ) = R then
      return TwoSidedIdealByGenerators( R, GeneratorsOfRightIdeal( I ) );
    else
      TryNextMethod();
    fi;
    end );


#############################################################################
##
#M  AsLeftIdeal( <R>, <S> ) . . . . . . . . . . . . . . . . . . for two rings
#M  AsRightIdeal( <R>, <S> )  . . . . . . . . . . . . . . . . . for two rings
#M  AsTwoSidedIdeal( <R>, <S> ) . . . . . . . . . . . . . . . . for two rings
##
InstallMethod( AsLeftIdeal,
    "for two rings",
    IsIdenticalObj,
    [ IsRing, IsRing ], 0,
    function( R, S )
    local I, gens;
    if not IsLeftIdeal( R, S ) then
      I:= fail;
    else
      gens:= GeneratorsOfRing( S );
      I:= LeftIdealByGenerators( R, gens );
      SetGeneratorsOfRing( I, gens );
    fi;
    return I;
    end );

InstallMethod( AsRightIdeal,
    "for two rings",
    IsIdenticalObj,
    [ IsRing, IsRing ], 0,
    function( R, S )
    local I, gens;
    if not IsRightIdeal( R, S ) then
      I:= fail;
    else
      gens:= GeneratorsOfRing( S );
      I:= RightIdealByGenerators( R, gens );
      SetGeneratorsOfRing( I, gens );
    fi;
    return I;
    end );

InstallMethod( AsTwoSidedIdeal,
    "for two rings",
    IsIdenticalObj,
    [ IsRing, IsRing ], 0,
    function( R, S )
    local I, gens;
    if not IsTwoSidedIdeal( R, S ) then
      I:= fail;
    else
      gens:= GeneratorsOfRing( S );
      I:= TwoSidedIdealByGenerators( R, gens );
      SetGeneratorsOfRing( I, gens );
    fi;
    return I;
    end );

InstallMethod(IsSubset,"2-sided ideal in ring, naive",IsIdenticalObj,
  [IsRing,IsRing and HasRightActingRingOfIdeal and HasLeftActingRingOfIdeal],
  2*SIZE_FLAGS(FLAGS_FILTER(IsFLMLOR)),
function(R,I)
  if IsIdenticalObj(R,RightActingRingOfIdeal(I)) and
     IsIdenticalObj(R,LeftActingRingOfIdeal(I)) then
     return IsSubset(R,GeneratorsOfTwoSidedIdeal(I)); 
   fi;
   TryNextMethod();
end);

InstallMethod(IsLeftIdeal,"left ideal in ring, naive",IsIdenticalObj,
  [IsRing,IsRing and HasLeftActingRingOfIdeal],
  2*SIZE_FLAGS(FLAGS_FILTER(IsFLMLOR)),
function(R,I)
  if IsIdenticalObj(LeftActingRingOfIdeal(I),R) then
    return true;
  else
    TryNextMethod();
  fi;
end);


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