This file is indexed.

/usr/share/gap/lib/mapping.gd is in gap-libs 4r6p5-3.

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
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
#############################################################################
##
#W  mapping.gd                  GAP library                     Thomas Breuer
#W                                                         & Martin Schönert
#W                                                             & Frank Celler
##
##
#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
##
##  This file declares the operations for general mappings.
##

#############################################################################
##
##  <#GAPDoc Label="[1]{mapping}">
##  A <E>general mapping</E> <M>F</M> in &GAP; is described by
##  its source <M>S</M>, its range <M>R</M>, and a subset <M>Rel</M> of the
##  direct product <M>S \times R</M>,
##  which is called the underlying relation of <M>F</M>.
##  <M>S</M>, <M>R</M>, and <M>Rel</M> are generalized domains
##  (see <Ref Chap="Domains"/>).
##  The corresponding attributes for general mappings are
##  <Ref Func="Source"/>, <Ref Func="Range" Label="of a general mapping"/>,
##  and <Ref Func="UnderlyingRelation"/>.
##  <!-- what about the family predicates if the source/range is not a -->
##  <!-- collection? -->
##  <P/>
##  Note that general mappings themselves are <E>not</E> domains.
##  One reason for this is that two general mappings with same underlying
##  relation are regarded as equal only if also the sources are equal and
##  the ranges are equal.
##  Other, more technical, reasons are that general mappings and domains
##  have different basic operations, and that general mappings are
##  arithmetic objects
##  (see&nbsp;<Ref Sect="Arithmetic Operations for General Mappings"/>);
##  both should not apply to domains.
##  <P/>
##  Each element of an underlying relation of a general mapping lies in the
##  category of direct product elements
##  (see&nbsp;<Ref Func="IsDirectProductElement"/>).
##  <P/>
##  For each <M>s \in S</M>, the set <M>\{ r \in R | (s,r) \in Rel \}</M>
##  is called the set of <E>images</E> of <M>s</M>.
##  Analogously, for <M>r \in R</M>,
##  the set <M>\{ s \in S | (s,r) \in Rel \}</M>
##  is called the set of <E>preimages</E> of <M>r</M>.
##  <P/>
##  The <E>ordering</E> of general mappings via <C>&lt;</C> is defined
##  by the ordering of source, range, and underlying relation.
##  Specifically, if the source and range domains of <A>map1</A> and
##  <A>map2</A> are the same, then one considers  the union of the preimages
##  of <A>map1</A> and <A>map2</A> as a strictly ordered set.
##  The smaller of <A>map1</A> and <A>map2</A> is the one whose image is
##  smaller on the  first point of this sequence where they differ.
##  <#/GAPDoc>
##
##  <#GAPDoc Label="[2]{mapping}">
##  <Ref Func="Source"/> and <Ref Func="Range" Label="of a general mapping"/> 
##  are basic operations for general mappings.
##  <Ref Func="UnderlyingRelation"/> is secondary, its default method sets up
##  a domain that delegates tasks to the general mapping.
##  (Note that this allows one to handle also infinite relations by generic
##  methods if source or range of the general mapping is finite.)
##  <P/>
##  The distinction between basic operations and secondary operations for
##  general mappings may be a little bit complicated.
##  Namely, each general mapping must be in one of the two categories
##  <Ref Func="IsNonSPGeneralMapping"/>, <Ref Func="IsSPGeneralMapping"/>.
##  (The category <Ref Func="IsGeneralMapping"/> is defined as the disjoint
##  union of these two.)
##  <P/>
##  For general mappings of the first category, <Ref Func="ImagesElm"/> and
##  <Ref Func="PreImagesElm"/> are basic operations.
##  (Note that in principle it is possible to delegate
##  from <Ref Func="PreImagesElm"/> to <Ref Func="ImagesElm"/>.)
##  Methods for the secondary operations <Ref Func="ImageElm"/>,
##  <Ref Func="PreImageElm"/>, <Ref Func="ImagesSet"/>,
##  <Ref Func="PreImagesSet"/>, <Ref Func="ImagesRepresentative"/>,
##  and <Ref Func="PreImagesRepresentative"/> may use
##  <Ref Func="ImagesElm"/> and <Ref Func="PreImagesElm"/>, respectively,
##  and methods for <Ref Func="ImagesElm"/>, <Ref Func="PreImagesElm"/>
##  must <E>not</E> call the secondary operations.
##  In particular, there are no generic methods for
##  <Ref Func="ImagesElm"/> and <Ref Func="PreImagesElm"/>.
##  <P/>
##  Methods for <Ref Func="ImagesSet"/> and <Ref Func="PreImagesSet"/> must
##  <E>not</E> use <Ref Func="PreImagesRange"/> and
##  <Ref Func="ImagesSource"/>, e.g.,
##  compute the intersection of the set in question with the preimage of the
##  range resp. the image of the source.
##  <P/>
##  For general mappings of the second category (which means structure
##  preserving general mappings), the situation is different.
##  The set of preimages under a group homomorphism, for example, is either
##  empty or can be described as a coset of the (multiplicative) kernel.
##  So it is reasonable to have <Ref Func="ImagesRepresentative"/>,
##  <Ref Func="PreImagesRepresentative"/>,
##  <Ref Func="KernelOfMultiplicativeGeneralMapping"/>, and
##  <Ref Func="CoKernelOfMultiplicativeGeneralMapping"/> as basic operations
##  here, and to make <Ref Func="ImagesElm"/> and <Ref Func="PreImagesElm"/>
##  secondary operations that may delegate to these.
##  <P/>
##  In order to avoid infinite recursions,
##  we must distinguish between the two different types of mappings.
##  <P/>
##  (Note that the basic domain operations such as <Ref Func="AsList"/>
##  for the underlying relation of a general mapping may use either
##  <Ref Func="ImagesElm"/> or <Ref Func="ImagesRepresentative"/> and the
##  appropriate cokernel.
##  Conversely, if <Ref Func="AsList"/> for the underlying relation is known
##  then <Ref Func="ImagesElm"/> resp. <Ref Func="ImagesRepresentative"/>
##  may delegate to it,
##  the general mapping gets the property
##  <Ref Func="IsConstantTimeAccessGeneralMapping"/> for this;
##  note that this is not allowed if only an enumerator of the underlying
##  relation is known.)
##  <P/>
##  Secondary operations are
##  <Ref Func="IsInjective"/>, <Ref Func="IsSingleValued"/>,
##  <Ref Func="IsSurjective"/>, <Ref Func="IsTotal"/>;
##  they may use the basic operations, and must not be used by them.
##  <#/GAPDoc>
##
##  <#GAPDoc Label="[3]{mapping}">
##  General mappings are arithmetic objects.
##  One can form groups and vector spaces of general mappings provided
##  that they are invertible or can be added and admit scalar multiplication,
##  respectively.
##  <P/>
##  For two general mappings with same source, range, preimage, and image,
##  the <E>sum</E> is defined pointwise, i.e.,
##  the images of a point under the sum is the set of all sums with
##  first summand in the images of the first general mapping and
##  second summand in the images of the second general mapping.
##  <P/>
##  <E>Scalar multiplication</E> of general mappings is defined likewise.
##  <P/>
##  The <E>product</E> of two general mappings is defined as the composition.
##  This multiplication is always associative.
##  In addition to the composition via <C>*</C>,
##  general mappings can be composed &ndash;in reversed order&ndash;
##  via <Ref Func="CompositionMapping"/>.
##  <P/>
##  General mappings are in the category of multiplicative elements with
##  inverses.
##  Similar to matrices, not every general mapping has an inverse or an
##  identity, and we define the behaviour of <Ref Func="One"/> and
##  <Ref Func="Inverse"/> for general mappings as follows.
##  <Ref Func="One"/> returns <K>fail</K> when called for a general mapping
##  whose source and range differ,
##  otherwise <Ref Func="One"/> returns the identity mapping of the source.
##  (Note that the source may differ from the preimage).
##  <Ref Func="Inverse"/> returns <K>fail</K> when called for a non-bijective
##  general mapping or for a general mapping whose source and range differ;
##  otherwise <Ref Func="Inverse"/> returns the inverse mapping.
##  <P/>
##  Besides the usual inverse of multiplicative elements, which means that
##  <C>Inverse( <A>g</A> ) * <A>g</A> = <A>g</A> * Inverse( <A>g</A> )
##  = One( <A>g</A> )</C>,
##  for general mappings we have the attribute
##  <Ref Func="InverseGeneralMapping"/>.
##  If <A>F</A> is a general mapping with source <M>S</M>, range <M>R</M>,
##  and underlying relation <M>Rel</M> then
##  <C>InverseGeneralMapping( <A>F</A> )</C> has source <M>R</M>,
##  range <M>S</M>,
##  and underlying relation <M>\{ (r,s) \mid (s,r) \in Rel \}</M>.
##  For a general mapping that has an inverse in the usual sense,
##  i.e., for a bijection of the source, of course both concepts coincide.
##  <P/>
##  <Ref Func="Inverse"/> may delegate to
##  <Ref Func="InverseGeneralMapping"/>.
##  <Ref Func="InverseGeneralMapping"/> must not delegate to
##  <Ref Func="Inverse"/>,
##  but a known value of <Ref Func="Inverse"/> may be fetched.
##  So methods to compute the inverse of a general mapping should be
##  installed for <Ref Func="InverseGeneralMapping"/>.
##  <P/>
##  (Note that in many respects, general mappings behave similar to matrices,
##  for example one can define left and right identities and inverses, which
##  do not fit into the current concepts of &GAP;.)
##  <#/GAPDoc>
##
##  <#GAPDoc Label="[4]{mapping}">
##  Methods for the operations <Ref Func="ImagesElm"/>,
##  <Ref Func="ImagesRepresentative"/>,
##  <Ref Func="ImagesSet"/>, <Ref Func="ImageElm"/>,
##  <Ref Func="PreImagesElm"/>,
##  <Ref Func="PreImagesRepresentative"/>, <Ref Func="PreImagesSet"/>,
##  and <Ref Func="PreImageElm"/> take two arguments, a general mapping
##  <A>map</A> and an element or collection of elements <A>elm</A>.
##  These methods must <E>not</E> check whether <A>elm</A> lies in the source
##  or the range of <A>map</A>.
##  In the case that <A>elm</A> does not, <K>fail</K> may be returned as well
##  as any other &GAP; object, and even an error message is allowed.
##  Checks of the arguments are done only by the functions
##  <Ref Func="Image" Label="set of images of the source of a general mapping"/>,
##  <Ref Func="Images" Label="set of images of the source of a general mapping"/>,
##  <Ref Func="PreImage" Label="set of preimages of the range of a general mapping"/>,
##  and <Ref Func="PreImages" Label="set of preimages of the range of a general mapping"/>,
##  which then delegate to the operations listed above.
##  <#/GAPDoc>
##


#############################################################################
##
#C  IsGeneralMapping( <map> )
##
##  <#GAPDoc Label="IsGeneralMapping">
##  <ManSection>
##  <Filt Name="IsGeneralMapping" Arg='map' Type='Category'/>
##
##  <Description>
##  Each general mapping lies in the category <Ref Func="IsGeneralMapping"/>.
##  It implies the categories
##  <Ref Func="IsMultiplicativeElementWithInverse"/>
##  and <Ref Func="IsAssociativeElement"/>;
##  for a discussion of these implications,
##  see&nbsp;<Ref Sect="Arithmetic Operations for General Mappings"/>.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareCategory( "IsGeneralMapping",
    IsMultiplicativeElementWithInverse and IsAssociativeElement );


#############################################################################
##
#C  IsSPGeneralMapping( <map> )
#C  IsNonSPGeneralMapping( <map> )
##
##  <#GAPDoc Label="IsSPGeneralMapping">
##  <ManSection>
##  <Filt Name="IsSPGeneralMapping" Arg='map' Type='Category'/>
##  <Filt Name="IsNonSPGeneralMapping" Arg='map' Type='Category'/>
##
##  <Description>
##  <!--  What we want to express is that <C>IsGeneralMapping</C> is the disjoint union-->
##  <!--  of <C>IsSPGeneralMapping</C> and <C>IsNonSPGeneralMapping</C>.-->
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareCategory( "IsSPGeneralMapping", IsGeneralMapping );
DeclareCategory( "IsNonSPGeneralMapping", IsGeneralMapping );


#############################################################################
##
#C  IsGeneralMappingCollection( <obj> )
##
##  <ManSection>
##  <Filt Name="IsGeneralMappingCollection" Arg='obj' Type='Category'/>
##
##  <Description>
##  </Description>
##  </ManSection>
##
DeclareCategoryCollections( "IsGeneralMapping" );


#############################################################################
##
#C  IsGeneralMappingFamily( <obj> )
##
##  <#GAPDoc Label="IsGeneralMappingFamily">
##  <ManSection>
##  <Filt Name="IsGeneralMappingFamily" Arg='obj' Type='Category'/>
##
##  <Description>
##  The family category of the category of general mappings.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareCategoryFamily( "IsGeneralMapping" );


#############################################################################
##
#A  FamilyRange( <Fam> )
##
##  <#GAPDoc Label="FamilyRange">
##  <ManSection>
##  <Attr Name="FamilyRange" Arg='Fam'/>
##
##  <Description>
##  is the elements family of the family of the range of each general
##  mapping in the family <A>Fam</A>.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareAttribute( "FamilyRange", IsGeneralMappingFamily );


#############################################################################
##
#A  FamilySource( <Fam> )
##
##  <#GAPDoc Label="FamilySource">
##  <ManSection>
##  <Attr Name="FamilySource" Arg='Fam'/>
##
##  <Description>
##  is the elements family of the family of the source of each general
##  mapping in the family <A>Fam</A>.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareAttribute( "FamilySource", IsGeneralMappingFamily );


#############################################################################
##
#A  FamiliesOfGeneralMappingsAndRanges( <Fam> )
##
##  <#GAPDoc Label="FamiliesOfGeneralMappingsAndRanges">
##  <ManSection>
##  <Attr Name="FamiliesOfGeneralMappingsAndRanges" Arg='Fam'/>
##
##  <Description>
##  is a list that stores at the odd positions the families of general
##  mappings with source in the family <A>Fam</A>, at the even positions the
##  families of ranges of the general mappings.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareAttribute( "FamiliesOfGeneralMappingsAndRanges",
    IsFamily, "mutable" );


#############################################################################
##
#P  IsConstantTimeAccessGeneralMapping( <map> )
##
##  <#GAPDoc Label="IsConstantTimeAccessGeneralMapping">
##  <ManSection>
##  <Prop Name="IsConstantTimeAccessGeneralMapping" Arg='map'/>
##
##  <Description>
##  is <K>true</K> if the underlying relation of the general mapping
##  <A>map</A> knows its <Ref Func="AsList"/> value,
##  and <K>false</K> otherwise.
##  <P/>
##  In the former case, <A>map</A> is allowed to use this list for calls to
##  <Ref Func="ImagesElm"/> etc.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareProperty( "IsConstantTimeAccessGeneralMapping", IsGeneralMapping );


#############################################################################
##
#P  IsEndoGeneralMapping( <obj> )
##
##  <#GAPDoc Label="IsEndoGeneralMapping">
##  <ManSection>
##  <Prop Name="IsEndoGeneralMapping" Arg='obj'/>
##
##  <Description>
##  If a general mapping has this property then its source and range are
##  equal.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareProperty( "IsEndoGeneralMapping", IsGeneralMapping );

#############################################################################
##
#P  IsTotal( <map> )  . . . . . . . . test whether a general mapping is total
##
##  <#GAPDoc Label="IsTotal">
##  <ManSection>
##  <Prop Name="IsTotal" Arg='map'/>
##
##  <Description>
##  is <K>true</K> if each element in the source <M>S</M>
##  of the general mapping <A>map</A> has images, i.e.,
##  <M>s^{<A>map</A>} \neq \emptyset</M> for all <M>s \in S</M>,
##  and <K>false</K> otherwise.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareProperty( "IsTotal", IsGeneralMapping );


#############################################################################
##
#P  IsSingleValued( <map> ) . test whether a general mapping is single-valued
##
##  <#GAPDoc Label="IsSingleValued">
##  <ManSection>
##  <Prop Name="IsSingleValued" Arg='map'/>
##
##  <Description>
##  is <K>true</K> if each element in the source <M>S</M>
##  of the general mapping <A>map</A> has at most one image, i.e.,
##  <M>|s^{<A>map</A>}| \leq 1</M> for all <M>s \in S</M>,
##  and <K>false</K> otherwise.
##  <P/>
##  Equivalently, <C>IsSingleValued( <A>map</A> )</C> is <K>true</K>
##  if and only if the preimages of different elements in <M>R</M> are
##  disjoint.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareProperty( "IsSingleValued", IsGeneralMapping );


#############################################################################
##
#P  IsMapping( <map> )
##
##  <#GAPDoc Label="IsMapping">
##  <ManSection>
##  <Prop Name="IsMapping" Arg='map'/>
##
##  <Description>
##  A <E>mapping</E> <A>map</A> is a general mapping that assigns to each
##  element <C>elm</C> of its source a unique element
##  <C>Image( <A>map</A>, elm )</C> of its range.
##  <P/>
##  Equivalently, the general mapping <A>map</A> is a mapping if and only if
##  it is total and single-valued
##  (see&nbsp;<Ref Func="IsTotal"/>, <Ref Func="IsSingleValued"/>).
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareSynonymAttr( "IsMapping",
    IsGeneralMapping and IsTotal and IsSingleValued );



#############################################################################
##
#P  IsEndoMapping( <obj> )
##
##  <ManSection>
##  <Prop Name="IsEndoMapping" Arg='obj'/>
##
##  <Description>
##  If a mapping has this property then its source and range are
##  equal and it is single valued.
##  </Description>
##  </ManSection>
##
DeclareSynonymAttr( "IsEndoMapping", IsMapping and IsEndoGeneralMapping );


#############################################################################
##
#P  IsInjective( <map> )  . . . . . .  test if a general mapping is injective
##
##  <#GAPDoc Label="IsInjective">
##  <ManSection>
##  <Prop Name="IsInjective" Arg='map'/>
##
##  <Description>
##  is <K>true</K> if the images of different elements in the source <M>S</M>
##  of the general mapping <A>map</A> are disjoint, i.e.,
##  <M>x^{<A>map</A>} \cap y^{<A>map</A>} = \emptyset</M>
##  for <M>x \neq y \in S</M>,
##  and <K>false</K> otherwise.
##  <P/>
##  Equivalently, <C>IsInjective( <A>map</A> )</C> is <K>true</K>
##  if and only if each element in the range of <A>map</A> has at most one
##  preimage in <M>S</M>.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareProperty( "IsInjective", IsGeneralMapping );
DeclareSynonym("IsOneToOne",IsInjective);

#############################################################################
##
#P  IsSurjective( <map> ) . . . . . . test if a general mapping is surjective
##
##  <#GAPDoc Label="IsSurjective">
##  <ManSection>
##  <Prop Name="IsSurjective" Arg='map'/>
##
##  <Description>
##  is <K>true</K> if each element in the range <M>R</M>
##  of the general mapping <A>map</A> has preimages in the source <M>S</M>
##  of <A>map</A>, i.e.,
##  <M>\{ s \in S \mid x \in s^{<A>map</A>} \} \neq \emptyset</M>
##  for all <M>x \in R</M>, and <K>false</K> otherwise.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareProperty( "IsSurjective", IsGeneralMapping );
DeclareSynonym("IsOnto",IsSurjective);


#############################################################################
##
#P  IsBijective( <map> )  . . . . . .  test if a general mapping is bijective
##
##  <#GAPDoc Label="IsBijective">
##  <ManSection>
##  <Prop Name="IsBijective" Arg='map'/>
##
##  <Description>
##  A general mapping <A>map</A> is <E>bijective</E> if and only if it is
##  an injective and surjective mapping (see&nbsp;<Ref Func="IsMapping"/>,
##  <Ref Func="IsInjective"/>, <Ref Func="IsSurjective"/>).
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareSynonymAttr( "IsBijective",
    IsSingleValued and IsTotal and IsInjective and IsSurjective );


#############################################################################
##
#A  Range( <map> )  . . . . . . . . . . . . . . .  range of a general mapping
##
##  <#GAPDoc Label="Range">
##  <ManSection>
##  <Attr Name="Range" Arg='map' Label="of a general mapping"/>
##
##  <Description>
##  The range of a general mapping.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareAttribute( "Range", IsGeneralMapping );


#############################################################################
##
#A  Source( <map> ) . . . . . . . . . . . . . . . source of a general mapping
##
##  <#GAPDoc Label="Source">
##  <ManSection>
##  <Attr Name="Source" Arg='map'/>
##
##  <Description>
##  The source of a general mapping.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareAttribute( "Source", IsGeneralMapping );


#############################################################################
##
#A  UnderlyingRelation( <map> ) . .  underlying relation of a general mapping
##
##  <#GAPDoc Label="UnderlyingRelation">
##  <ManSection>
##  <Attr Name="UnderlyingRelation" Arg='map'/>
##
##  <Description>
##  The <E>underlying relation</E> of a general mapping <A>map</A> is the
##  domain of pairs <M>(s,r)</M>, with <M>s</M> in the source and <M>r</M> in
##  the range of <A>map</A> (see&nbsp;<Ref Func="Source"/>,
##  <Ref Func="Range" Label="of a general mapping"/>),
##  and <M>r \in</M> <C>ImagesElm( <A>map</A>, </C><M>s</M><C> )</C>.
##  <P/>
##  Each element of the underlying relation is represented by
##  a direct product element (see&nbsp;<Ref Func="IsDirectProductElement"/>).
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareAttribute( "UnderlyingRelation", IsGeneralMapping );


#############################################################################
##
#A  UnderlyingGeneralMapping( <map> )
##
##  <#GAPDoc Label="UnderlyingGeneralMapping">
##  <ManSection>
##  <Attr Name="UnderlyingGeneralMapping" Arg='map'/>
##
##  <Description>
##  attribute for underlying relations of general mappings
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareAttribute( "UnderlyingGeneralMapping", IsCollection );


#############################################################################
##
#F  GeneralMappingsFamily( <sourcefam>, <rangefam> )
##
##  <#GAPDoc Label="GeneralMappingsFamily">
##  <ManSection>
##  <Func Name="GeneralMappingsFamily" Arg='sourcefam, rangefam'/>
##
##  <Description>
##  All general mappings with same source family <A>FS</A> and same range
##  family <A>FR</A> lie in the family
##  <C>GeneralMappingsFamily( <A>FS</A>, <A>FR</A> )</C>.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareGlobalFunction( "GeneralMappingsFamily" );


#############################################################################
##
#F  TypeOfDefaultGeneralMapping( <source>, <range>, <filter> )
##
##  <#GAPDoc Label="TypeOfDefaultGeneralMapping">
##  <ManSection>
##  <Func Name="TypeOfDefaultGeneralMapping" Arg='source, range, filter'/>
##
##  <Description>
##  is the type of mappings with <C>IsDefaultGeneralMappingRep</C> with
##  source <A>source</A> and range <A>range</A> and additional categories
##  <A>filter</A>.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareGlobalFunction( "TypeOfDefaultGeneralMapping" );


#############################################################################
##
#A  IdentityMapping( <D> )  . . . . . . . .  identity mapping of a collection
##
##  <#GAPDoc Label="IdentityMapping">
##  <ManSection>
##  <Attr Name="IdentityMapping" Arg='D'/>
##
##  <Description>
##  is the bijective mapping with source and range equal to the collection
##  <A>D</A>, which maps each element of <A>D</A> to itself.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareAttribute( "IdentityMapping", IsCollection );


#############################################################################
##
#A  InverseGeneralMapping( <map> )
##
##  <#GAPDoc Label="InverseGeneralMapping">
##  <ManSection>
##  <Attr Name="InverseGeneralMapping" Arg='map'/>
##
##  <Description>
##  The <E>inverse general mapping</E> of a general mapping <A>map</A> is
##  the general mapping whose underlying relation
##  (see&nbsp;<Ref Func="UnderlyingRelation"/>) contains a pair <M>(r,s)</M>
##  if and only if the underlying relation of <A>map</A> contains the pair
##  <M>(s,r)</M>.
##  <P/>
##  See the introduction to Chapter&nbsp;<Ref Chap="Mappings"/>
##  for the subtleties concerning the difference between
##  <Ref Func="InverseGeneralMapping"/> and <Ref Func="Inverse"/>.
##  <P/>
##  Note that the inverse general mapping of a mapping <A>map</A> is
##  in general only a general mapping.
##  If <A>map</A> knows to be bijective its inverse general mapping will know
##  to be a mapping.
##  In this case also <C>Inverse( <A>map</A> )</C> works.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareAttribute( "InverseGeneralMapping", IsGeneralMapping );


#############################################################################
##
#A  ImagesSource( <map> )
##
##  <#GAPDoc Label="ImagesSource">
##  <ManSection>
##  <Attr Name="ImagesSource" Arg='map'/>
##
##  <Description>
##  is the set of images of the source of the general mapping <A>map</A>.
##  <P/>
##  <Ref Func="ImagesSource"/> delegates to <Ref Func="ImagesSet"/>,
##  it is introduced only to store the image of <A>map</A> as attribute
##  value.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareAttribute( "ImagesSource", IsGeneralMapping );


#############################################################################
##
#A  PreImagesRange( <map> )
##
##  <#GAPDoc Label="PreImagesRange">
##  <ManSection>
##  <Attr Name="PreImagesRange" Arg='map'/>
##
##  <Description>
##  is the set of preimages of the range of the general mapping <A>map</A>.
##  <P/>
##  <Ref Func="PreImagesRange"/> delegates to <Ref Func="PreImagesSet"/>,
##  it is introduced only to store the preimage of <A>map</A> as attribute
##  value.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareAttribute( "PreImagesRange", IsGeneralMapping );


#############################################################################
##
#O  ImagesElm( <map>, <elm> ) . . . all images of an elm under a gen. mapping
##
##  <#GAPDoc Label="ImagesElm">
##  <ManSection>
##  <Oper Name="ImagesElm" Arg='map, elm'/>
##
##  <Description>
##  If <A>elm</A> is an element of the source of the general mapping
##  <A>map</A> then <Ref Func="ImagesElm"/> returns the set of all images
##  of <A>elm</A> under <A>map</A>.
##  <P/>
##  Anything may happen if <A>elm</A> is not an element of the source of
##  <A>map</A>.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareOperation( "ImagesElm", [ IsGeneralMapping, IsObject ] );


#############################################################################
##
#O  ImagesRepresentative(<map>,<elm>) . one image of elm under a gen. mapping
##
##  <#GAPDoc Label="ImagesRepresentative">
##  <ManSection>
##  <Oper Name="ImagesRepresentative" Arg='map,elm'/>
##
##  <Description>
##  If <A>elm</A> is an element of the source of the general mapping
##  <A>map</A> then <Ref Func="ImagesRepresentative"/> returns either
##  a representative of the set of images of <A>elm</A> under <A>map</A>
##  or <K>fail</K>, the latter if and only if <A>elm</A> has no images under
##  <A>map</A>.
##  <P/>
##  Anything may happen if <A>elm</A> is not an element of the source of
##  <A>map</A>.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareOperation( "ImagesRepresentative", [ IsGeneralMapping, IsObject ] );


#############################################################################
##
#O  ImagesSet( <map>, <elms> )
##
##  <#GAPDoc Label="ImagesSet">
##  <ManSection>
##  <Oper Name="ImagesSet" Arg='map, elms'/>
##
##  <Description>
##  If <A>elms</A> is a subset of the source of the general mapping
##  <A>map</A> then <Ref Func="ImagesSet"/> returns the set of all images of
##  <A>elms</A> under <A>map</A>.
##  <P/>
##  The result will be either a proper set or a domain.
##  Anything may happen if <A>elms</A> is not a subset of the source of
##  <A>map</A>.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareOperation( "ImagesSet", [ IsGeneralMapping, IsCollection ] );


#############################################################################
##
#O  ImageElm( <map>, <elm> )  . . . .  unique image of an elm under a mapping
##
##  <#GAPDoc Label="ImageElm">
##  <ManSection>
##  <Oper Name="ImageElm" Arg='map, elm'/>
##
##  <Description>
##  If <A>elm</A> is an element of the source of the total and single-valued
##  mapping <A>map</A> then
##  <Ref Func="ImageElm"/> returns the unique image of <A>elm</A> under
##  <A>map</A>.
##  <P/>
##  Anything may happen if <A>elm</A> is not an element of the source of
##  <A>map</A>.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareOperation( "ImageElm", [ IsMapping, IsObject ] );


#############################################################################
##
#F  Image( <map> )  . . . .  set of images of the source of a general mapping
#F  Image( <map>, <elm> ) . . . .  unique image of an element under a mapping
#F  Image( <map>, <coll> )  . . set of images of a collection under a mapping
##
##  <#GAPDoc Label="Image">
##  <ManSection>
##  <Heading>Image</Heading>
##  <Func Name="Image" Arg='map'
##   Label="set of images of the source of a general mapping"/>
##  <Func Name="Image" Arg='map, elm'
##   Label="unique image of an element under a mapping"/>
##  <Func Name="Image" Arg='map, coll'
##   Label="set of images of a collection under a mapping"/>
##
##  <Description>
##  <C>Image( <A>map</A> )</C> is the <E>image</E> of the general mapping
##  <A>map</A>, i.e.,
##  the subset of elements of the range of <A>map</A>
##  that are actually values of <A>map</A>.
##  <E>Note</E> that in this case the argument may also be multi-valued.
##  <P/>
##  <C>Image( <A>map</A>, <A>elm</A> )</C> is the image of the element
##  <A>elm</A> of the source of the mapping <A>map</A> under <A>map</A>,
##  i.e., the unique element of the range to which <A>map</A> maps
##  <A>elm</A>.
##  This can also be expressed as <A>elm</A><C>^</C><A>map</A>.
##  Note that <A>map</A> must be total and single valued,
##  a multi valued general mapping is not allowed
##  (see&nbsp;<Ref Func="Images" Label="set of images of the source of a general mapping"/>).
##  <P/>
##  <C>Image( <A>map</A>, <A>coll</A> )</C> is the image of the subset
##  <A>coll</A> of the source of the mapping <A>map</A> under <A>map</A>,
##  i.e., the subset of the range to which <A>map</A> maps elements of
##  <A>coll</A>.
##  <A>coll</A> may be a proper set or a domain.
##  The result will be either a proper set or a domain.
##  Note that in this case <A>map</A> may also be multi-valued.
##  (If <A>coll</A> and the result are lists then the positions of
##  entries do in general <E>not</E> correspond.)
##  <P/>
##  <Ref Func="Image" Label="set of images of the source of a general mapping"/>
##  delegates to <Ref Func="ImagesSource"/> when called
##  with one argument, and to <Ref Func="ImageElm"/> resp.
##  <Ref Func="ImagesSet"/> when called with two arguments.
##  <P/>
##  If the second argument is not an element or a subset of the source of
##  the first argument, an error is signalled.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareGlobalFunction( "Image" );


#############################################################################
##
#F  Images( <map> ) . . . .  set of images of the source of a general mapping
#F  Images( <map>, <elm> )  . . . set of images of an element under a mapping
#F  Images( <map>, <coll> ) . . set of images of a collection under a mapping
##
##  <#GAPDoc Label="Images">
##  <ManSection>
##  <Heading>Images</Heading>
##  <Func Name="Images" Arg='map'
##   Label="set of images of the source of a general mapping"/>
##  <Func Name="Images" Arg='map, elm'
##   Label="set of images of an element under a mapping"/>
##  <Func Name="Images" Arg='map, coll'
##   Label="set of images of a collection under a mapping"/>
##
##  <Description>
##  <C>Images( <A>map</A> )</C> is the <E>image</E> of the general mapping
##  <A>map</A>, i.e., the subset of elements of the range of <A>map</A>
##  that are actually values of <A>map</A>.
##  <P/>
##  <C>Images( <A>map</A>, <A>elm</A> )</C> is the set of images of the
##  element <A>elm</A> of the source of the general mapping <A>map</A> under
##  <A>map</A>, i.e., the set of elements of the range to which <A>map</A>
##  maps <A>elm</A>.
##  <P/>
##  <C>Images( <A>map</A>, <A>coll</A> )</C> is the set of images of the
##  subset <A>coll</A> of the source of the general mapping <A>map</A> under
##  <A>map</A>, i.e., the subset of the range to which <A>map</A> maps
##  elements of <A>coll</A>.
##  <A>coll</A> may be a proper set or a domain.
##  The result will be either a proper set or a domain.
##  (If <A>coll</A> and the result are lists then the positions of
##  entries do in general <E>not</E> correspond.)
##  <P/>
##  <Ref Func="Images" Label="set of images of the source of a general mapping"/>
##  delegates to <Ref Func="ImagesSource"/> when called
##  with one argument, and to <Ref Func="ImagesElm"/> resp.
##  <Ref Func="ImagesSet"/> when called with two arguments.
##  <P/>
##  If the second argument is not an element or a subset of the source of
##  the first argument, an error is signalled.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareGlobalFunction( "Images" );


#############################################################################
##
#O  PreImagesElm( <map>, <elm> )  . all preimages of elm under a gen. mapping
##
##  <#GAPDoc Label="PreImagesElm">
##  <ManSection>
##  <Oper Name="PreImagesElm" Arg='map, elm'/>
##
##  <Description>
##  If <A>elm</A> is an element of the range of the general mapping
##  <A>map</A> then <Ref Func="PreImagesElm"/> returns the set of all
##  preimages of <A>elm</A> under <A>map</A>.
##  <P/>
##  Anything may happen if <A>elm</A> is not an element of the range of
##  <A>map</A>.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareOperation( "PreImagesElm", [ IsGeneralMapping, IsObject ] );


#############################################################################
##
#O  PreImageElm( <map>, <elm> )
##
##  <#GAPDoc Label="PreImageElm">
##  <ManSection>
##  <Oper Name="PreImageElm" Arg='map, elm'/>
##
##  <Description>
##  If <A>elm</A> is an element of the range of the injective and surjective
##  general mapping <A>map</A> then
##  <Ref Func="PreImageElm"/> returns the unique preimage of <A>elm</A> under
##  <A>map</A>.
##  <P/>
##  Anything may happen if <A>elm</A> is not an element of the range of
##  <A>map</A>.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareOperation( "PreImageElm",
    [ IsGeneralMapping and IsInjective and IsSurjective, IsObject ] );


#############################################################################
##
#O  PreImagesRepresentative( <map>, <elm> ) . . .  one preimage of an element
##                                                       under a gen. mapping
##
##  <#GAPDoc Label="PreImagesRepresentative">
##  <ManSection>
##  <Oper Name="PreImagesRepresentative" Arg='map, elm'/>
##
##  <Description>
##  If <A>elm</A> is an element of the range of the general mapping
##  <A>map</A> then <Ref Func="PreImagesRepresentative"/> returns either a
##  representative of the set of preimages of <A>elm</A> under <A>map</A> or
##  <K>fail</K>, the latter if and only if <A>elm</A>
##  has no preimages under <A>map</A>.
##  <P/>
##  Anything may happen if <A>elm</A> is not an element of the range of
##  <A>map</A>.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareOperation( "PreImagesRepresentative",
    [ IsGeneralMapping, IsObject ] );


#############################################################################
##
#O  PreImagesSet( <map>, <elms> )
##
##  <#GAPDoc Label="PreImagesSet">
##  <ManSection>
##  <Oper Name="PreImagesSet" Arg='map, elms'/>
##
##  <Description>
##  If <A>elms</A> is a subset of the range of the general mapping <A>map</A>
##  then <Ref Func="PreImagesSet"/> returns the set of all preimages of
##  <A>elms</A> under <A>map</A>.
##  <P/>
##  Anything may happen if <A>elms</A> is not a subset of the range of
##  <A>map</A>.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareOperation( "PreImagesSet", [ IsGeneralMapping, IsCollection ] );


#############################################################################
##
#F  PreImage( <map> ) . .  set of preimages of the range of a general mapping
#F  PreImage( <map>, <elm> )  . unique preimage of an elm under a gen.mapping
#F  PreImage(<map>, <coll>)  set of preimages of a coll. under a gen. mapping
##
##  <#GAPDoc Label="PreImage">
##  <ManSection>
##  <Heading>PreImage</Heading>
##  <Func Name="PreImage" Arg='map'
##   Label="set of preimages of the range of a general mapping"/>
##  <Func Name="PreImage" Arg='map, elm'
##   Label="unique preimage of an element under a general mapping"/>
##  <Func Name="PreImage" Arg='map, coll'
##   Label="set of preimages of a collection under a general mapping"/>
##
##  <Description>
##  <C>PreImage( <A>map</A> )</C> is the preimage of the general mapping
##  <A>map</A>, i.e., the subset of elements of the source of <A>map</A>
##  that actually have values under <A>map</A>.
##  Note that in this case the argument may also be non-injective or
##  non-surjective.
##  <P/>
##  <C>PreImage( <A>map</A>, <A>elm</A> )</C> is the preimage of the element
##  <A>elm</A> of the range of the injective and surjective mapping
##  <A>map</A> under <A>map</A>, i.e., the unique element of the source
##  which is mapped under <A>map</A> to <A>elm</A>.
##  Note that <A>map</A> must be injective and surjective
##  (see&nbsp;<Ref Func="PreImages" Label="set of preimages of the range of a general mapping"/>).
##  <P/>
##  <C>PreImage( <A>map</A>, <A>coll</A> )</C> is the preimage of the subset
##  <A>coll</A> of the range of the general mapping <A>map</A> under
##  <A>map</A>, i.e., the subset of the source which is mapped under
##  <A>map</A> to elements of <A>coll</A>. <A>coll</A> may be a proper set
##  or a domain.
##  The result will be either a proper set or a domain.
##  Note that in this case <A>map</A> may also be non-injective or
##  non-surjective.
##  (If <A>coll</A> and the result are lists then the positions of
##  entries do in general <E>not</E> correspond.)
##  <P/>
##  <Ref Func="PreImage" Label="set of preimages of the range of a general mapping"/>
##  delegates to <Ref Func="PreImagesRange"/> when
##  called with one argument,
##  and to <Ref Func="PreImageElm"/> resp. <Ref Func="PreImagesSet"/> when
##  called with two arguments.
##  <P/>
##  If the second argument is not an element or a subset of the range of
##  the first argument, an error is signalled.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareGlobalFunction( "PreImage" );


#############################################################################
##
#F  PreImages( <map> )  . . . set of preimages of the range of a gen. mapping
#F  PreImages(<map>,<elm>)  . set of preimages of an elm under a gen. mapping
#F  PreImages(<map>,<coll>)  set of preimages of a coll. under a gen. mapping
##
##  <#GAPDoc Label="PreImages">
##  <ManSection>
##  <Heading>PreImages</Heading>
##  <Func Name="PreImages" Arg='map'
##   Label="set of preimages of the range of a general mapping"/>
##  <Func Name="PreImages" Arg='map, elm'
##   Label="set of preimages of an elm under a general mapping"/>
##  <Func Name="PreImages" Arg='map, coll'
##   Label="set of preimages of a collection under a general mapping"/>
##
##  <Description>
##  <C>PreImages( <A>map</A> )</C> is the preimage of the general mapping
##  <A>map</A>, i.e., the subset of elements of the source of <A>map</A>
##  that have actually values under <A>map</A>.
##  <P/>
##  <C>PreImages( <A>map</A>, <A>elm</A> )</C> is the set of preimages of the
##  element <A>elm</A> of the range of the general mapping <A>map</A> under
##  <A>map</A>, i.e., the set of elements of the source which <A>map</A> maps
##  to <A>elm</A>.
##  <P/>
##  <C>PreImages( <A>map</A>, <A>coll</A> )</C> is the set of images of the
##  subset <A>coll</A> of the range of the general mapping <A>map</A> under
##  <A>map</A>, i.e., the subset of the source which <A>map</A> maps to
##  elements of <A>coll</A>.
##  <A>coll</A> may be a proper set or a domain.
##  The result will be either a proper set or a domain.
##  (If <A>coll</A> and the result are lists then the positions of
##  entries do in general <E>not</E> correspond.)
##  <P/>
##  <Ref Func="PreImages" Label="set of preimages of the range of a general mapping"/>
##  delegates to <Ref Func="PreImagesRange"/> when
##  called with one argument,
##  and to <Ref Func="PreImagesElm"/> resp. <Ref Func="PreImagesSet"/> when
##  called with two arguments.
##  <P/>
##  If the second argument is not an element or a subset of the range of
##  the first argument, an error is signalled.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareGlobalFunction( "PreImages" );


#############################################################################
##
#O  CompositionMapping2(<map2>,<map1>)  . . . composition of general mappings
#F  CompositionMapping2General(<map2>,<map1>)
##
##  <#GAPDoc Label="CompositionMapping2">
##  <ManSection>
##  <Oper Name="CompositionMapping2" Arg='map2, map1'/>
##  <Func Name="CompositionMapping2General" Arg='map2, map1'/>
##
##  <Description>
##  <Ref Func="CompositionMapping2"/> returns the composition of <A>map2</A>
##  and <A>map1</A>,
##  this is the general mapping that maps an element first under <A>map1</A>,
##  and then maps the images under <A>map2</A>.
##  <P/>
##  (Note the reverse ordering of arguments in the composition via
##  the multiplication <Ref Func="\*"/>.
##  <P/>
##  <Ref Func="CompositionMapping2General"/> is the method that forms a
##  composite mapping with two constituent mappings.
##  (This is used in some algorithms.)
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareOperation( "CompositionMapping2",
    [ IsGeneralMapping, IsGeneralMapping ] );

DeclareGlobalFunction("CompositionMapping2General");


#############################################################################
##
#F  CompositionMapping( <map1>, <map2>, ... ) . . . . composition of mappings
##
##  <#GAPDoc Label="CompositionMapping">
##  <ManSection>
##  <Func Name="CompositionMapping" Arg='map1, map2, ...'/>
##
##  <Description>
##  <Ref Func="CompositionMapping"/> allows one to compose arbitrarily many
##  general mappings,
##  and delegates each step to <Ref Func="CompositionMapping2"/>.
##  <P/>
##  Additionally, the properties <Ref Func="IsInjective"/> and
##  <Ref Func="IsSingleValued"/> are maintained;
##  if the source of the <M>i+1</M>-th general mapping is identical to
##  the range of the <M>i</M>-th general mapping,
##  also <Ref Func="IsTotal"/> and <Ref Func="IsSurjective"/> are maintained.
##  (So one should not call <Ref Func="CompositionMapping2"/> directly
##  if one wants to maintain these properties.)
##  <P/>
##  Depending on the types of <A>map1</A> and <A>map2</A>,
##  the returned mapping might be constructed completely new (for example by
##  giving domain generators and their images, this is for example the case
##  if both mappings preserve the same algebraic structures and &GAP; can
##  decompose elements of the source of <A>map2</A> into generators) or as an
##  (iterated) composition
##  (see&nbsp;<Ref Func="IsCompositionMappingRep"/>).
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareGlobalFunction( "CompositionMapping" );


#############################################################################
##
#R  IsCompositionMappingRep( <map> )
##
##  <#GAPDoc Label="IsCompositionMappingRep">
##  <ManSection>
##  <Filt Name="IsCompositionMappingRep" Arg='map' Type='Representation'/>
##
##  <Description>
##  Mappings in this representation are stored as composition of two
##  mappings, (pre)images of elements are computed in a two-step process.
##  The constituent mappings of the composition can be obtained via
##  <Ref Func="ConstituentsCompositionMapping"/>.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareRepresentation( "IsCompositionMappingRep",
    IsGeneralMapping and IsAttributeStoringRep, [ "map1", "map2" ] );


#############################################################################
##
#F  ConstituentsCompositionMapping( <map> )
##
##  <#GAPDoc Label="ConstituentsCompositionMapping">
##  <ManSection>
##  <Func Name="ConstituentsCompositionMapping" Arg='map'/>
##
##  <Description>
##  If <A>map</A> is stored in the representation
##  <Ref Func="IsCompositionMappingRep"/> as composition of two mappings
##  <A>map1</A> and <A>map2</A>, this function returns the
##  two constituent mappings in a list <C>[ <A>map1</A>, <A>map2</A> ]</C>.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareGlobalFunction( "ConstituentsCompositionMapping" );


#############################################################################
##
#O  ZeroMapping( <S>, <R> ) . . . . . . . . . .  zero mapping from <S> to <R>
##
##  <#GAPDoc Label="ZeroMapping">
##  <ManSection>
##  <Oper Name="ZeroMapping" Arg='S, R'/>
##
##  <Description>
##  A zero mapping is a total general mapping that maps each element of its
##  source to the zero element of its range.
##  <P/>
##  (Each mapping with empty source is a zero mapping.)
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareOperation( "ZeroMapping", [ IsCollection, IsCollection ] );


#############################################################################
##
#O  RestrictedMapping( <map>, <subdom> )
##
##  <#GAPDoc Label="RestrictedMapping">
##  <ManSection>
##  <Oper Name="RestrictedMapping" Arg='map, subdom'/>
##
##  <Description>
##  If <A>subdom</A> is a subdomain of the source of the general mapping
##  <A>map</A>,
##  this operation returns the restriction of <A>map</A> to <A>subdom</A>.
##  <!--  The general concept of restricted general mappings still missing.-->
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareOperation( "RestrictedMapping", [ IsGeneralMapping, IsDomain ] );


#############################################################################
##
#R  IsGeneralRestrictedMappingRep( <map> )
##
##  Mappings in this representation are stored as wrapper object, containing
##  the original map but new source and range.
##
DeclareRepresentation( "IsGeneralRestrictedMappingRep",
    IsGeneralMapping and IsAttributeStoringRep, [ "map" ] );

#############################################################################
##
#F  GeneralRestrictedMapping( <map>, <source>, <range> )
##
##  <C>GeneralRestrictedMapping</C> allows one to restrict <source> and
##  <range> for an existing mapping, for example enforcing injectivity or
##  surjectivity this way.
##
DeclareGlobalFunction( "GeneralRestrictedMapping" );

#############################################################################
##
#O  Embedding( <S>, <T> ) . . . . . . .  embedding of one domain into another
#O  Embedding( <S>, <i> )
##
##  <#GAPDoc Label="Embedding">
##  <ManSection>
##  <Heading>Embedding</Heading>
##  <Oper Name="Embedding" Arg='S, T' Label="for two domains"/>
##  <Oper Name="Embedding" Arg='S, i'
##   Label="for a domain and a positive integer"/>
##
##  <Description>
##  returns the embedding of the domain <A>S</A> in the domain <A>T</A>,
##  or in the second form, some domain indexed by the positive integer
##  <A>i</A>.
##  The precise natures of the various methods are described elsewhere:
##  for Lie algebras, see <Ref Func="LieFamily"/>; for group  products,
##  see&nbsp;<Ref Sect="Embeddings and Projections for Group Products"/>
##  for a general description, or for examples
##  see&nbsp;<Ref Sect="Direct Products"/> for direct products,
##  <Ref Sect="Semidirect Products"/> for semidirect products,
##  or&nbsp;<Ref Sect="Wreath Products"/> for wreath products; or for
##  magma rings
##  see&nbsp;<Ref Sect="Natural Embeddings related to Magma Rings"/>.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareOperation( "Embedding", [ IsDomain, IsObject ] );


#############################################################################
##
#O  Projection( <S>, <T> )  . . . . . . projection of one domain onto another
#O  Projection( <S>, <i> )
#O  Projection( <S> )
##
##  <#GAPDoc Label="Projection">
##  <ManSection>
##  <Heading>Projection</Heading>
##  <Oper Name="Projection" Arg='S, T' Label="for two domains"/>
##  <Oper Name="Projection" Arg='S, i'
##   Label="for a domain and a positive integer"/>
##  <Oper Name="Projection" Arg='S' Label="for a domain"/>
##
##  <Description>
##  returns the projection of the domain <A>S</A> onto the domain <A>T</A>,
##  or in the second form, some domain indexed by the positive integer
##  <A>i</A>,
##  or in the third form some natural quotient domain of <A>S</A>.
##  Various methods are defined for group products;
##  see&nbsp;<Ref Sect="Embeddings and Projections for Group Products"/> for
##  a general description,
##  or for examples see&nbsp;<Ref Sect="Direct Products"/> for direct
##  products, <Ref Sect="Semidirect Products"/> for semidirect products,
##  <Ref Sect="Subdirect Products"/> for subdirect products,
##  or&nbsp;<Ref Sect="Wreath Products"/> for wreath products.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareOperation( "Projection", [ IsDomain, IsObject ] );


#############################################################################
##
#F  GeneralMappingByElements( <S>, <R>, <elms> )
##
##  <#GAPDoc Label="GeneralMappingByElements">
##  <ManSection>
##  <Func Name="GeneralMappingByElements" Arg='S, R, elms'/>
##
##  <Description>
##  is the general mapping with source <A>S</A> and range <A>R</A>,
##  and with underlying relation consisting of the collection <A>elms</A>
##  of direct product elements.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareGlobalFunction( "GeneralMappingByElements" );


#############################################################################
##                                         
#F  MappingByFunction( <S>, <R>, <fun>[, <invfun>] )
#F  MappingByFunction( <S>, <R>, <fun>, `false', <prefun> )
##
##  <#GAPDoc Label="MappingByFunction">
##  <ManSection>
##  <Heading>MappingByFunction</Heading>
##  <Func Name="MappingByFunction" Arg='S, R, fun[, invfun]'
##   Label="by function (and inverse function) between two domains"/>
##  <Func Name="MappingByFunction" Arg='S, R, fun, false, prefun'
##   Label="by function and function that computes one preimage"/>
##
##  <Description>
##  <Ref Func="MappingByFunction" Label="by function (and inverse function) between two domains"/>
##  returns a mapping <C>map</C> with source
##  <A>S</A> and range <A>R</A>,
##  such that each element <M>s</M> of <A>S</A> is mapped to the element
##  <A>fun</A><M>( s )</M>, where <A>fun</A> is a &GAP; function.
##  <P/>
##  If the argument <A>invfun</A> is bound then <C>map</C> is a bijection
##  between <A>S</A> and <A>R</A>, and the preimage of each element <M>r</M>
##  of <A>R</A> is given by <A>invfun</A><M>( r )</M>,
##  where <A>invfun</A> is a &GAP;  function.
##  <P/>
##  If five arguments are given and the fourth argument is <K>false</K> then
##  the &GAP; function <A>prefun</A> can be used to compute a single preimage
##  also if <C>map</C> is not bijective.
##  <!-- what is <A>prefun</A> expected to return for <A>r</A> outside the image of <A>map</A>-->
##  <!-- if <A>map</A> is not surjective?-->
##  <!-- or must <A>map</A> be surjective in this case?-->
##  <P/>
##  The mapping returned by
##  <Ref Func="MappingByFunction" Label="by function (and inverse function) between two domains"/> lies in the
##  filter <Ref Func="IsNonSPGeneralMapping"/>,
##  see&nbsp;<Ref Sect="Technical Matters Concerning General Mappings"/>.
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareGlobalFunction( "MappingByFunction" );


#############################################################################
##
#m  IsBijective . . . . . . . . . . . . . . . . . . . .  for identity mapping
##
InstallTrueMethod( IsBijective, IsGeneralMapping and IsOne );


#############################################################################
##
#m  IsSingleValued  . . . . . . . . . . . . . . . . . . . .  for zero mapping
#m  IsTotal . . . . . . . . . . . . . . . . . . . . . . . .  for zero mapping
##
InstallTrueMethod( IsSingleValued, IsGeneralMapping and IsZero );
InstallTrueMethod( IsTotal, IsGeneralMapping and IsZero );


#############################################################################
##
#F  CopyMappingAttributes( <from>, <to> )
##
##  <ManSection>
##  <Func Name="CopyMappingAttributes" Arg='from, to'/>
##
##  <Description>
##  Let <A>from</A> and <A>to</A> be two general mappings which are known to be equal.
##  <C>CopyMappingAttributes</C> copies known mapping attributes from <A>from</A> to
##  <A>to</A>. This is used in operations, such as
##  <C>AsGroupGeneralMappingByImages</C>, that produce equal mappings in another
##  representation.
##  </Description>
##  </ManSection>
##
DeclareGlobalFunction( "CopyMappingAttributes" );

#############################################################################
##
#A  MappingGeneratorsImages(<map>)
##
##  <#GAPDoc Label="MappingGeneratorsImages">
##  <ManSection>
##  <Attr Name="MappingGeneratorsImages" Arg='map'/>
##
##  <Description>
##  This attribute contains a list of length 2, the first entry being a list
##  of generators of the source of <A>map</A> and the second entry a list of
##  their images. This attribute is used, for example, by
##  <Ref Func="GroupHomomorphismByImages"/> to store generators and images.
##  <!--  <C>MappingGeneratorsImages</C> is permitted to call           -->
##  <!--  <C>Source</C> and <C>ImagesRepresentative</C>.                -->
##  </Description>
##  </ManSection>
##  <#/GAPDoc>
##
DeclareAttribute( "MappingGeneratorsImages", IsGeneralMapping );


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