-
Notifications
You must be signed in to change notification settings - Fork 165
/
Copy pathmatobj2.gd
1928 lines (1789 loc) · 71.5 KB
/
matobj2.gd
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
#############################################################################
##
## This file is part of GAP, a system for computational discrete algebra.
##
## SPDX-License-Identifier: GPL-2.0-or-later
##
## Copyright of GAP belongs to its developers, whose names are too numerous
## to list here. Please refer to the COPYRIGHT file for details.
##
#############################################################################
##
## This file together with 'matobj1.gd' formally define the interface to
## those vector and matrix objects in GAP that are not represented
## by plain lists.
## In this file all the operations, attributes and constructors are defined.
## It is read later in the GAP library reading process.
##
#############################################################################
##
## <#GAPDoc Label="MatObj_Overview">
##
## Traditionally, vectors and matrices in &GAP; have been represented by
## (lists of) lists, see the chapters
## <Ref Chap="Row Vectors"/> and <Ref Chap="Matrices"/>.
## More precisely, the term <Q>vector</Q>
## (corresponding to the filter <Ref Filt="IsVector"/>)
## is used in the abstract sense of an <Q>element of a vector space</Q>,
## the term <Q>row vector</Q> (corresponding to <Ref Filt="IsRowVector"/>)
## is used to denote a <Q>coordinate vector</Q> which is represented by
## a &GAP; list (see <Ref Filt="IsList"/>),
## and the term <Q>matrix</Q> is used to denote a list of lists, with
## additional properties (see <Ref Filt="IsMatrix"/>).
## <P/>
## Unfortunately, such lists (objects in <Ref Filt="IsPlistRep"/>)
## cannot store their type,
## and so it is impossible to use the advantages of &GAP;'s method selection
## on them.
## This situation is unsustainable in the long run
## since more special representations (compressed, sparse, etc.)
## have already been and even more will be implemented.
## Here we describe a programming interface to vectors and matrices,
## which solves this problem,
## <P/>
## The idea of this interface is that &GAP; should be able to
## represent vectors and matrices by objects that store their type,
## in order to benefit from method selection.
## These objects are created by <Ref Func="Objectify"/>,
## we therefore refer to the them as <Q>vector objects</Q> and
## <Q>matrix objects</Q> respectively.
## <P/>
## (Of course the terminology is somewhat confusing:
## An abstract matrix should be thought of as represented by
## a matrix object; it can be detected from the filter
## <Ref Filt="IsMatrixObj"/>, whereas the filter <Ref Filt="IsMatrix"/>
## denotes matrices represented by lists of lists.
## We regard the objects in <Ref Filt="IsMatrix"/> as special cases of
## objects in <Ref Filt="IsMatrixObj"/>.)
## <P/>
## We want to be able to write (efficient) code that is independent of the
## actual representation (in the sense of &GAP;'s representation filters,
## see Section <Ref Sect="Representation"/>)
## and preserves it.
## <P/>
## This latter requirement makes it necessary to distinguish between
## different representations of matrices:
## <Q>Row list</Q> matrices (see <Ref Filt="IsRowListMatrix"/>
## behave basically like lists of rows,
## in particular the rows are individual &GAP; objects that can
## be shared between different matrix objects.
## One can think of other representations of matrices,
## such as matrices whose subobjects represent columns,
## or <Q>flat</Q> matrices which do not have subobjects like rows or
## columns at all.
## The different kinds of matrices have to be distinguished
## already with respect to the definition of the operations for them.
## <P/>
## In particular vector and matrix objects know their base domain
## (see <Ref Attr="BaseDomain" Label="for a vector object"/>)
## and their dimensions.
## The basic condition is that the entries of vector and matrix objects
## must either lie in the base domain or naturally embed in the sense that
## addition and multiplication automatically work with elements of the
## base domain;
## for example, a matrix object over a polynomial ring may also contain
## entries from the coefficient ring.
## <P/>
## Vector and matrix objects may be mutable or immutable.
## Of course all operations changing an object are only allowed/implemented
## for mutable variants.
## <P/>
## Vector objects are equal with respect to <Ref Oper="\="/>
## if they have the same length and the same entries.
## It is not necessary that they have the same base domain.
## Matrices are equal with respect to <Ref Oper="\="/>
## if they have the same dimensions and the same entries.
## <P/>
## For a row list matrix object, it is not guaranteed that all its rows
## have the same vector type.
## It is for example thinkable that a matrix object stores some of its rows
## in a sparse representation and some in a dense one.
## However, it is guaranteed that the rows of two matrices in the same
## representation are compatible in the sense that all vector operations
## defined in this interface can be applied to them and that new matrices
## in the same representation as the original matrix can be formed out of
## them.
## <P/>
## Note that there is neither a default mapping from the set of
## matrix object representations to the set of vector representations
## nor one in the reverse direction.
## There is in general no <Q>associated</Q> vector object representation
## to a matrix object representation or vice versa.
## (However,
## <Ref Attr="CompatibleVectorFilter" Label="for a matrix object"/>
## may describe a vector object representation that is compatible with a
## given matrix object.)
## <P/>
## The recommended way to write code that preserves the representation
## basically works by using constructing operations that take template
## objects to decide about the intended representation for the new object.
## <P/>
## Vector and matrix objects do not have to be &GAP; lists in the sense of
## <Ref Filt="IsList"/>.
## Note that objects not in the filter <Ref Filt="IsList"/> need not
## support all list operations, and their behaviour is not prescribed by the
## rules for lists, e.g., behaviour w.r.t. arithmetic operations.
## However, row list matrices behave nearly like lists of row vectors
## that insist on being dense and containing only vectors of the same
## length and with the same base domain.
## <#/GAPDoc>
##
#############################################################################
##
#A BaseDomain( <vector> )
#A BaseDomain( <matrix> )
##
## <#GAPDoc Label="BaseDomain">
## <ManSection>
## <Heading>BaseDomain</Heading>
## <Attr Name="BaseDomain" Arg='vector' Label="for a vector object"/>
## <Attr Name="BaseDomain" Arg='matrix' Label="for a matrix object"/>
##
## <Description>
## The vector object <A>vector</A> or matrix object <A>matrix</A>,
## respectively, is defined over the domain given by its
## <Ref Attr="BaseDomain" Label="for a vector object"/> value.
## <P/>
## Note that not all entries of the object necessarily lie in
## its base domain with respect to
## <Ref Oper="\in" Label="for a collection"/>, see Section
## <Ref Sect="Concepts and Rules for Vector and Matrix Objects"/>.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareAttribute( "BaseDomain", IsVectorObj );
DeclareAttribute( "BaseDomain", IsMatrixObj );
#############################################################################
##
#A NumberRows( <M> )
#A NrRows( <M> )
#A NumberColumns( <M> )
#A NrCols( <M> )
##
## <#GAPDoc Label="NumberRowsNumberColumns">
## <ManSection>
## <Heading>NumberRows and NumberColumns</Heading>
## <Attr Name="NumberRows" Arg='M' Label="for a matrix object"/>
## <Attr Name="NrRows" Arg='M' Label="for a matrix object"/>
## <Attr Name="NumberColumns" Arg='M' Label="for a matrix object"/>
## <Attr Name="NrCols" Arg='M' Label="for a matrix object"/>
##
## <Description>
## For a matrix object <A>M</A>,
## <Ref Attr="NumberRows" Label="for a matrix object"/> and
## <Ref Attr="NumberColumns" Label="for a matrix object"/> store the
## number of rows and columns of <A>M</A>, respectively.
## <P/>
## <Ref Attr="NrRows" Label="for a matrix object"/> and
## <Ref Attr="NrCols" Label="for a matrix object"/> are synonyms of
## <Ref Attr="NumberRows" Label="for a matrix object"/> and
## <Ref Attr="NumberColumns" Label="for a matrix object"/>, respectively.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareAttribute( "NumberRows", IsMatrixObj );
DeclareSynonymAttr( "NrRows", NumberRows );
DeclareAttribute( "NumberColumns", IsMatrixObj );
DeclareSynonymAttr( "NrCols", NumberColumns );
#############################################################################
##
#A OneOfBaseDomain( <v> )
#A OneOfBaseDomain( <M> )
#A ZeroOfBaseDomain( <v> )
#A ZeroOfBaseDomain( <M> )
##
## <#GAPDoc Label="OneOfBaseDomain">
## <ManSection>
## <Heading>OneOfBaseDomain and ZeroOfBaseDomain</Heading>
## <Attr Name="OneOfBaseDomain" Arg='v' Label="for a vector object"/>
## <Attr Name="OneOfBaseDomain" Arg='M' Label="for a matrix object"/>
## <Attr Name="ZeroOfBaseDomain" Arg='v' Label="for a vector object"/>
## <Attr Name="ZeroOfBaseDomain" Arg='M' Label="for a matrix object"/>
##
## <Description>
## These attributes return the identity element and the zero element
## of the <Ref Attr="BaseDomain" Label="for a vector object"/> value
## of the vector object <A>v</A> or the matrix object <A>M</A>,
## respectively.
## <P/>
## If <A>v</A> or <A>M</A>, respectively, is a plain list
## (see <Ref Filt="IsPlistRep"/>) then computing its
## <Ref Attr="BaseDomain" Label="for a vector object"/> value can be
## regarded as expensive,
## whereas calling <Ref Attr="OneOfBaseDomain" Label="for a vector object"/>
## or <Ref Attr="ZeroOfBaseDomain" Label="for a vector object"/>
## can be regarded as cheap.
## If <A>v</A> or <A>M</A>, respectively, is not a plain list then
## one can also call <Ref Attr="BaseDomain" Label="for a vector object"/>
## first, without loss of performance.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareAttribute( "OneOfBaseDomain", IsVectorObj );
DeclareAttribute( "OneOfBaseDomain", IsMatrixObj );
DeclareAttribute( "ZeroOfBaseDomain", IsVectorObj );
DeclareAttribute( "ZeroOfBaseDomain", IsMatrixObj );
#############################################################################
##
#A Length( <v> )
##
## <#GAPDoc Label="Length_IsVectorObj">
## <ManSection>
## <Attr Name="Length" Arg='v' Label="for a vector object"/>
##
## <Description>
## returns the length of the vector object <A>v</A>,
## which is defined to be the number of entries of <A>v</A>.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareAttribute( "Length", IsVectorObj );
#############################################################################
##
#A ConstructingFilter( <v> )
#A ConstructingFilter( <M> )
##
## <#GAPDoc Label="ConstructingFilter">
## <ManSection>
## <Heading>ConstructingFilter</Heading>
## <Attr Name="ConstructingFilter" Arg="v" Label="for a vector object"/>
## <Attr Name="ConstructingFilter" Arg="M" Label="for a matrix object"/>
##
## <Returns>a filter</Returns>
## <Description>
## Called with a vector object <A>v</A> or a matrix object <A>M</A>,
## respectively,
## <Ref Attr="ConstructingFilter" Label="for a vector object"/> returns
## a filter <C>f</C> such that when
## <Ref Constr="NewVector"/> or <Ref Constr="NewMatrix"/>, respectively,
## is called with <C>f</C> then a vector object or a matrix object,
## respectively, in the same representation as the argument is produced.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareAttribute( "ConstructingFilter", IsVectorObj );
DeclareAttribute( "ConstructingFilter", IsMatrixObj );
#############################################################################
##
#A CompatibleVectorFilter( <M> )
##
## <#GAPDoc Label="CompatibleVectorFilter">
## <ManSection>
## <Heading>CompatibleVectorFilter</Heading>
## <Attr Name="CompatibleVectorFilter" Arg="M" Label="for a matrix object"/>
##
## <Returns>a filter</Returns>
## <Description>
## Called with a matrix object <A>M</A>,
## <Ref Attr="CompatibleVectorFilter" Label="for a matrix object"/> returns
## either a filter <C>f</C> such that vector objects with
## <Ref Attr="ConstructingFilter" Label="for a vector object"/> value
## <C>f</C> are compatible in the sense that <A>M</A> can be multiplied with
## these vector objects, of <K>fail</K> if no such filter is known.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareAttribute( "CompatibleVectorFilter", IsMatrixObj );
#############################################################################
##
## List Like Operations for Vector Objects
##
#############################################################################
##
#O \[\]( <v>, <i> )
#O \[\]\:\=( <v>, <i>, <obj> )
#O \{\}( <v>, <list> )
##
## <#GAPDoc Label="ElementAccessVectorObj">
## <ManSection>
## <Heading>Element Access and Assignment for Vector Objects</Heading>
##
## <Oper Name="\[\]" Arg="v,i" Label="for a vector object and an integer"/>
## <Oper Name="\[\]\:\=" Arg="v,i,obj"
## Label="for a vector object and an integer"/>
## <Oper Name="\{\}" Arg="v,list" Label="for a vector object and a list"/>
##
## <Description>
## For a vector object <A>v</A> and a positive integer <A>i</A> that is
## not larger than the length of <A>v</A>
## (see <Ref Attr="Length" Label="for a vector object"/>),
## <A>v</A><C>[</C><A>i</A><C>]</C> is the entry at position <A>i</A>.
## <P/>
## If <A>v</A> is mutable, <A>i</A> is as above, and <A>obj</A> is an object
## from the base domain of <A>v</A> then
## <A>v</A><C>[</C><A>i</A><C>]:= </C><A>obj</A> assigns <A>obj</A> to the
## <A>i</A>-th position of <A>v</A>.
## <P/>
## If <A>list</A> is a list of positive integers that are not larger than
## the length of <A>v</A> then
## <A>v</A><C>{</C><A>list</A><C>}</C> returns a vector object in the same
## representation as <A>v</A>
## (see <Ref Attr="ConstructingFilter" Label="for a vector object"/>)
## that contains the <A>list</A><M>[ k ]</M>-th entry of <A>v</A> at
## position <M>k</M>.
## <P/>
## It is not specified what happens if <A>i</A> is larger than the length
## of <A>v</A>,
## or if <A>obj</A> is not in the base domain of <A>v</A>,
## or if <A>list</A> contains entries not in the allowed range.
## <P/>
## Note that the sublist assignment operation <Ref Oper="\{\}\:\="/>
## is left out here since it tempts the programmer to use constructions like
## <C>v{ [ 1 .. 3 ] }:= w{ [ 4 .. 6 ] }</C>
## which produces an unnecessary intermediate object;
## one should use <Ref Oper="CopySubVector"/> instead.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "[]", [ IsVectorObj, IsPosInt ] );
DeclareOperation( "[]:=", [ IsVectorObj, IsPosInt, IsObject ] );
DeclareOperation( "{}", [ IsVectorObj, IsList ] );
#############################################################################
##
## <#GAPDoc Label="MatObj_PositionNonZero">
## <ManSection>
## <Oper Name="PositionNonZero" Arg="v" Label="for a vector object"/>
##
## <Returns>An integer</Returns>
## <Description>
## Returns the index of the first entry in the vector object <A>v</A>
## that is not zero.
## If all entries are zero,
## the function returns <C>Length(<A>v</A>) + 1</C>.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "PositionNonZero", [ IsVectorObj ] );
#############################################################################
##
## <#GAPDoc Label="MatObj_PositionLastNonZero">
## <ManSection>
## <Oper Name="PositionLastNonZero" Arg="v"
## Label="for a vector object"/>
##
## <Returns>An integer</Returns>
## <Description>
## Returns the index of the last entry in the vector object <A>v</A>
## that is not zero.
## If all entries are zero, the function returns <M>0</M>.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "PositionLastNonZero", [ IsVectorObj ] );
#############################################################################
##
#O ListOp( <v>[, <func>] )
##
## <#GAPDoc Label="MatObj_ListOp">
## <ManSection>
## <Oper Name="ListOp" Arg="v[, func]"
## Label="for vector object and function"/>
##
## <Returns>A plain list</Returns>
## <Description>
## Applies the function <A>func</A> to each entry of the vector object
## <A>v</A> and returns the results as a mutable plain list.
## This allows for calling <Ref Func="List" Label="for a collection"/>
## on vector objects.
## <P/>
## If the argument <A>func</A> is not given,
## applies <Ref Func="IdFunc"/> to all entries.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "ListOp", [ IsVectorObj ] );
DeclareOperation( "ListOp", [ IsVectorObj, IsFunction ] );
#############################################################################
##
#O Unpack( <v> )
#O Unpack( <M> )
##
## <#GAPDoc Label="Unpack">
## <ManSection>
## <Heading>Unpack</Heading>
## <Oper Name="Unpack" Arg="v" Label="for a vector object"/>
## <Oper Name="Unpack" Arg="M" Label="for a matrix object"/>
##
## <Returns>A plain list</Returns>
## <Description>
## Returns a new mutable plain list (see <Ref Filt="IsPlistRep"/>)
## containing the entries of the vector object <A>v</A> or the matrix object
## <A>M</A>, respectively.
## In the case of a matrix object,
## the result is a plain list of plain lists.
## <P/>
## Changing the result does not change <A>v</A> or <A>M</A>, respectively.
## The entries themselves are not copied.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
## Note that 'AsList' would not be suitable in the case of vector objects
## because its result would be immutable.
##
DeclareOperation( "Unpack", [ IsVectorObj ] );
DeclareOperation( "Unpack", [ IsMatrixObj ] );
#############################################################################
##
## <#GAPDoc Label="MatObj_ConcatenationOfVectors">
## <ManSection>
## <Heading>ConcatenationOfVectors</Heading>
## <Func Name="ConcatenationOfVectors" Arg="v1,v2,..."
## Label="for arbitrary many vector objects"/>
## <Func Name="ConcatenationOfVectors" Arg="vlist"
## Label="for a list of vector objects"/>
##
## <Returns>a vector object</Returns>
##
## <Description>
## Returns a new mutable vector object in the representation of <A>v1</A>
## or the first entry of the nonempty list <A>vlist</A> of vector objects,
## respectively,
## such that the entries are the concatenation of the given vector objects.
## <P/>
## (Note that <Ref Func="Concatenation" Label="for several lists"/>
## is a function for which no methods can be installed.)
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareGlobalFunction( "ConcatenationOfVectors" );
#############################################################################
##
## <#GAPDoc Label="MatObj_ExtractSubVector">
## <ManSection>
## <Oper Name="ExtractSubVector" Arg="v,l"/>
##
## <Returns>a vector object</Returns>
##
## <Description>
## Returns a new mutable vector object of the same vector representation
## as <A>v</A>, containing the entries of <A>v</A> at the positions in
## the list <A>l</A>.
## <P/>
## This is the same as <A>v</A><C>{</C><A>l</A><C>}</C>,
## the name <Ref Oper="ExtractSubVector"/> was introduced in analogy to
## <Ref Oper="ExtractSubMatrix"/>, for which no equivalent syntax using
## curly brackets is available.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "ExtractSubVector", [ IsVectorObj, IsList ] );
#############################################################################
##
## Arithmetical operations for vector objects
##
#############################################################################
##
#O AddVector( <dst>, <src>[, <mul>[, <from>, <to>]] )
#O AddVector( <dst>, <mul>, <src>[, <from>, <to>] )
##
## <#GAPDoc Label="MatObj_AddVector">
## <ManSection>
## <Oper Name="AddVector" Arg='dst, src[, from, to]'
## Label="for two vector objects"/>
## <Oper Name="AddVector" Arg='dst, mul, src[, from, to]'
## Label="for a vector object"/>
##
## <Returns>nothing</Returns>
##
## <Description>
## Called with two vector objects <A>dst</A> and <A>src</A>,
## this function replaces the entries of <A>dst</A> in-place
## by the entries of the sum <A>dst</A><C> + </C><A>src</A>.
## <P/>
## If a scalar <A>mul</A> is given as the third or second argument,
## respectively, then the entries of <A>dst</A> get replaced by those of
## <A>dst</A><C> + </C><A>src</A><C> * </C><A>mul</A> or
## <A>dst</A><C> + </C><A>mul</A><C> * </C><A>src</A>, respectively.
## <P/>
## If the optional parameters <A>from</A> and <A>to</A> are given then
## only the index range <C>[<A>from</A>..<A>to</A>]</C> is guaranteed to be
## affected.
## Other indices <E>may</E> be affected, if it is more convenient to do so.
## This can be helpful if entries of <A>src</A> are known to be zero.
## <P/>
## If <A>from</A> is bigger than <A>to</A>, the operation does nothing.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "AddVector",
[ IsVectorObj and IsMutable, IsVectorObj ] );
DeclareOperation( "AddVector",
[ IsVectorObj and IsMutable, IsVectorObj, IsObject ] );
DeclareOperation( "AddVector",
[ IsVectorObj and IsMutable, IsObject, IsVectorObj ] );
DeclareOperation( "AddVector",
[ IsVectorObj and IsMutable, IsVectorObj, IsObject, IsPosInt, IsPosInt ] );
DeclareOperation( "AddVector",
[ IsVectorObj and IsMutable, IsObject, IsVectorObj, IsPosInt, IsPosInt ] );
#############################################################################
##
#O MultVector( <vec>, <mul>[, <from>, <to>] )
#O MultVectorLeft( <vec>, <mul>[, <from>, <to>] )
#O MultVectorRight( <vec>, <mul>[, <from>, <to>] )
##
## <#GAPDoc Label="MatObj_MultVectorLeft">
## <ManSection>
## <Oper Name="MultVector" Arg='vec, mul[, from, to]'
## Label="for a vector object"/>
## <Oper Name="MultVectorLeft" Arg='vec, mul[, from, to]'
## Label="for a vector object"/>
## <Oper Name="MultVectorRight" Arg='vec, mul[, from, to]'
## Label="for a vector object"/>
##
## <Returns>nothing</Returns>
##
## <Description>
## These operations multiply <A>mul</A> with <A>vec</A> in-place
## where <Ref Oper="MultVectorLeft" Label="for a vector object"/>
## multiplies with <A>mul</A> from the left
## and <Ref Oper="MultVectorRight" Label="for a vector object"/>
## does so from the right.
## <P/>
## Note that <Ref Oper="MultVector" Label="for a vector object"/>
## is just a synonym for
## <Ref Oper="MultVectorLeft" Label="for a vector object"/>.
## <P/>
## If the optional parameters <A>from</A> and <A>to</A> are given then
## only the index range <C>[<A>from</A>..<A>to</A>]</C> is guaranteed to be
## affected. Other indices <E>may</E> be affected, if it is more convenient
## to do so.
## This can be helpful if entries of <A>vec</A> are known to be zero.
## <P/>
## If <A>from</A> is bigger than <A>to</A>, the operation does nothing.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "MultVectorLeft",
[ IsVectorObj and IsMutable, IsObject ] );
DeclareOperation( "MultVectorLeft",
[ IsVectorObj and IsMutable, IsObject, IsInt, IsInt ] );
DeclareOperation( "MultVectorRight",
[ IsVectorObj and IsMutable, IsObject ] );
DeclareOperation( "MultVectorRight",
[ IsVectorObj and IsMutable, IsObject, IsInt, IsInt ] );
# This is defined for two vectors of equal length,
# it returns the standard scalar product.
# (The documentation is in the section about arithm. operations.)
DeclareOperation( "ScalarProduct", [ IsVectorObj, IsVectorObj ] );
#############################################################################
##
#O ZeroVector( <filt>, <R>, <len> )
#O ZeroVector( <R>, <len> )
#O ZeroVector( <len>, <v> )
#O ZeroVector( <len>, <M> )
##
## <#GAPDoc Label="VectorObj_ZeroVector">
## <ManSection>
## <Heading>ZeroVector</Heading>
## <Oper Name="ZeroVector" Arg="filt,R,len" Label="for filter, base domain and length"/>
## <Oper Name="ZeroVector" Arg="R,len" Label="for base domain and length"/>
## <Oper Name="ZeroVector" Arg="len,v" Label="for length and vector object"/>
## <Oper Name="ZeroVector" Arg="len,M" Label="for length and matrix object"/>
##
## <Returns>a vector object</Returns>
## <Description>
## For a filter <A>filt</A>, a semiring <A>R</A> and a nonnegative integer <A>len</A>,
## this operation returns a new mutable vector object of length <A>len</A> over <A>R</A>
## in the representation <A>filt</A> containing only zeros.
## <P/>
## If only <A>R</A> and <A>len</A> are given, then GAP guesses a suitable representation.
## <P/>
## For a vector object <A>v</A> and a nonnegative integer <A>len</A>,
## this operation returns a new mutable vector object of length <A>len</A>
## in the same representation as <A>v</A> containing only zeros.
## <P/>
## For a matrix object <A>M</A> and a nonnegative integer <A>len</A>,
## this operation returns a new mutable zero vector object of length
## <A>len</A> in the representation given by the
## <Ref Attr="CompatibleVectorFilter" Label="for a matrix object"/> value
## of <A>M</A>, provided that such a representation exists.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "ZeroVector", [ IsOperation, IsSemiring, IsInt ] );
DeclareOperation( "ZeroVector", [ IsSemiring, IsInt ] );
DeclareOperation( "ZeroVector", [ IsInt, IsVectorObj ] );
DeclareOperation( "ZeroVector", [ IsInt, IsMatrixObj ] );
#############################################################################
##
#O Vector( <filt>, <R>, <list> )
#O Vector( <filt>, <R>, <vec> )
#O Vector( <R>, <list> )
#O Vector( <R>, <vec> )
#O Vector( <list>, <vec> )
#O Vector( <vec1>, <vec2> )
##
## <#GAPDoc Label="Vector">
## <ManSection>
## <Heading>Vector</Heading>
## <Oper Name="Vector" Arg='filt,R,list'
## Label="for filter, base domain, and list"/>
## <Oper Name="Vector" Arg='filt,R,vec'
## Label="for filter, base domain, and vector object"/>
## <Oper Name="Vector" Arg='R,list'
## Label="for base domain and list"/>
## <Oper Name="Vector" Arg='R,vec'
## Label="for base domain and vector object"/>
## <Oper Name="Vector" Arg='list,vec'
## Label="for a list and a vector object"/>
## <Oper Name="Vector" Arg='vec1,vec2'
## Label="for two vector objects"/>
## <Oper Name="Vector" Arg='list'
## Label="for a list"/>
##
## <Returns>a vector object</Returns>
## <Description>
## If a filter <A>filt</A> is given as the first argument then
## a vector object is returned that has
## <Ref Attr="ConstructingFilter" Label="for a vector object"/>
## value <A>filt</A>, is defined over the base domain <A>R</A>,
## and has the entries given by the list <A>list</A> or the vector object
## <A>vec</A>, respectively.
## <P/>
## If a semiring <A>R</A> is given as the first argument then
## a vector object is returned whose
## <Ref Attr="ConstructingFilter" Label="for a vector object"/>
## value is guessed from <A>R</A>, again with base domain <A>R</A>
## and entries given by the last argument.
## <P/>
## In the remaining cases with two arguments,
## the first argument is a list or a vector object
## that defines the entries of the result,
## and the second argument is a vector object whose
## <Ref Attr="ConstructingFilter" Label="for a vector object"/> and
## <Ref Attr="BaseDomain" Label="for a vector object"/> are taken for the
## result.
## <P/>
## If only a list <A>list</A> is given then both the
## <Ref Attr="ConstructingFilter" Label="for a vector object"/> and the
## <Ref Attr="BaseDomain" Label="for a vector object"/> are guessed from
## this list.
## <P/>
## It is <E>not</E> guaranteed that the given list of entries is copied.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "Vector", [ IsOperation, IsSemiring, IsList ] );
DeclareOperation( "Vector", [ IsOperation, IsSemiring, IsVectorObj ] );
DeclareOperation( "Vector", [ IsSemiring, IsList ] );
DeclareOperation( "Vector", [ IsSemiring, IsVectorObj ] );
DeclareOperation( "Vector", [ IsList, IsVectorObj ] );
DeclareOperation( "Vector", [ IsVectorObj, IsVectorObj ] );
DeclareOperation( "Vector", [ IsList ] );
#############################################################################
##
#O NewVector( <filt>, <R>, <list> )
#O NewZeroVector( <filt>, <R>, <n> )
##
## <#GAPDoc Label="NewVector">
## <ManSection>
## <Heading>NewVector and NewZeroVector</Heading>
## <Constr Name="NewVector" Arg='filt,R,list'/>
## <Constr Name="NewZeroVector" Arg='filt,R,n'/>
##
## <Description>
## For a filter <A>filt</A>, a semiring <A>R</A>, and a list <A>list</A>
## of elements that belong to <A>R</A>,
## <Ref Constr="NewVector"/> returns a mutable vector object which has
## the <Ref Attr="ConstructingFilter" Label="for a vector object"/>
## <A>filt</A>,
## the <Ref Attr="BaseDomain" Label="for a vector object"/> <A>R</A>,
## and the entries in <A>list</A>.
## The list <A>list</A> is guaranteed not to be changed by this operation.
## <P/>
## Similarly, <Ref Constr="NewZeroVector"/> returns a mutable vector object
## of length <A>n</A> which has <A>filt</A> and <A>R</A> as
## <Ref Attr="ConstructingFilter" Label="for a vector object"/> and
## <Ref Attr="BaseDomain" Label="for a vector object"/> values,
## and contains the zero of <A>R</A> in each position.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareConstructor( "NewVector", [ IsVectorObj, IsSemiring, IsList ] );
DeclareConstructor( "NewZeroVector", [ IsVectorObj, IsSemiring, IsInt ] );
#############################################################################
##
#O NewMatrix( <filt>, <R>, <ncols>, <list> )
#O NewZeroMatrix( <filt>, <R>, <m>, <n> )
#O NewIdentityMatrix( <filt>, <R>, <n> )
##
## <#GAPDoc Label="NewMatrix">
## <ManSection>
## <Heading>NewMatrix, NewZeroMatrix, NewIdentityMatrix</Heading>
## <Constr Name="NewMatrix" Arg='filt,R,ncols,list'/>
## <Constr Name="NewZeroMatrix" Arg='filt,R,m,n'/>
## <Constr Name="NewIdentityMatrix" Arg='filt,R,n'/>
##
## <Description>
## For a filter <A>filt</A>, a semiring <A>R</A>,
## a positive integer <A>ncols</A>, and a list <A>list</A>,
## <Ref Constr="NewMatrix"/> returns a mutable matrix object which has
## the <Ref Attr="ConstructingFilter" Label="for a vector object"/>
## <A>filt</A>,
## the <Ref Attr="BaseDomain" Label="for a matrix object"/> <A>R</A>,
## <A>n</A> columns
## (see <Ref Attr="NumberColumns" Label="for a matrix object"/>),
## and the entries described by <A>list</A>,
## which can be either a plain list of vector objects of length <A>ncols</A>
## or a plain list of plain lists of length <A>ncols</A>
## or a plain list of length a multiple of <A>ncols</A> containing the
## entries in row major order.
## The list <A>list</A> is guaranteed not to be changed by this operation.
## <P/>
## The corresponding entries must be in or compatible with <A>R</A>.
## If <A>list</A> already contains vector objects, they are copied.
## <P/>
## Similarly, <Ref Constr="NewZeroMatrix"/> returns a mutable zero matrix
## object with <A>m</A> rows and <A>n</A> columns
## which has <A>filt</A> and <A>R</A> as
## <Ref Attr="ConstructingFilter" Label="for a vector object"/> and
## <Ref Attr="BaseDomain" Label="for a vector object"/> values.
## <P/>
## Similarly, <Ref Constr="NewIdentityMatrix"/> returns a mutable identity
## matrix object with <A>m</A> rows and <A>n</A> columns
## which has <A>filt</A> and <A>R</A> as
## <Ref Attr="ConstructingFilter" Label="for a vector object"/> and
## <Ref Attr="BaseDomain" Label="for a vector object"/> values,
## and contains the identity element of <A>R</A> in the diagonal
## and the zero of <A>R</A> in each off-diagonal position.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareConstructor( "NewMatrix", [ IsMatrixObj, IsSemiring, IsInt, IsList] );
DeclareConstructor( "NewZeroMatrix",
[ IsMatrixObj, IsSemiring, IsInt, IsInt ] );
DeclareConstructor( "NewIdentityMatrix",
[ IsMatrixObj, IsSemiring, IsInt ] );
#############################################################################
##
#O ChangedBaseDomain( <v>, <R> )
#O ChangedBaseDomain( <M>, <R> )
##
## <#GAPDoc Label="ChangedBaseDomain">
## <ManSection>
## <Heading>ChangedBaseDomain</Heading>
## <Oper Name="ChangedBaseDomain" Arg='v,R' Label="for a vector object"/>
## <Oper Name="ChangedBaseDomain" Arg='M,R' Label="for a matrix object"/>
##
## <Description>
## For a vector object <A>v</A> (a matrix object <A>M</A>)
## and a semiring <A>R</A>,
## <Ref Oper="ChangedBaseDomain" Label="for a vector object"/> returns
## a new vector object (matrix object)
## with <Ref Attr="BaseDomain" Label="for a vector object"/> value <A>R</A>,
## <Ref Attr="ConstructingFilter" Label="for a vector object"/> value
## equal to that of <A>v</A> (<A>M</A>),
## and the same entries as <A>v</A> (<A>M</A>).
## <P/>
## The result is mutable if and only if <A>v</A> (<A>M</A>) is mutable.
## <P/>
## For example, one can create a vector defined over <C>GF(4)</C>
## from a vector defined over <C>GF(2)</C> with this operation.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "ChangedBaseDomain", [ IsVectorObj, IsSemiring ] );
DeclareOperation( "ChangedBaseDomain", [ IsMatrixObj, IsSemiring ] );
############################################################################
##
#O Randomize( [Rs, ]v )
#O Randomize( [Rs, ]M )
##
## <#GAPDoc Label="Randomize">
## <ManSection>
## <Heading>Randomize</Heading>
## <Oper Name="Randomize" Arg="[Rs,]v" Label="for a vector object"/>
## <Oper Name="Randomize" Arg="[Rs,]M" Label="for a matrix object"/>
## <Description>
## Replaces every entry in the mutable vector object <A>v</A>
## or matrix object <A>M</A>, respectively, with
## a random one from the base domain of <A>v</A> or <A>M</A>,
## respectively, and returns the argument.
## <P/>
## If given, the random source <A>Rs</A> is used to compute the
## random elements.
## Note that in this case,
## a <Ref Oper="Random" Label="for random source and collection"/>
## method must be available that takes a random source as its first
## argument and the base domain as its second argument.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "Randomize", [ IsVectorObj and IsMutable ] );
DeclareOperation( "Randomize", [ IsRandomSource, IsVectorObj and IsMutable ] );
DeclareOperation( "Randomize", [ IsMatrixObj and IsMutable ] );
DeclareOperation( "Randomize", [ IsRandomSource, IsMatrixObj and IsMutable ] );
#############################################################################
##
#O CopySubVector( <src>, <dst>, <scols>, <dcols> )
##
## <#GAPDoc Label="CopySubVector">
## <ManSection>
## <Oper Name="CopySubVector" Arg='src, dst, scols, dcols'/>
##
## <Returns>nothing</Returns>
##
## <Description>
## For two vector objects <A>dst</A> and <A>src</A>,
## such that <A>dst</A> is mutable,
## and two lists <A>dcols</A> and <A>scols</A> of positions,
## <Ref Oper="CopySubVector"/> assigns the entries
## <A>src</A><C>{ </C><A>scols</A><C> }</C>
## (see <Ref Oper="ExtractSubVector"/>)
## to the positions <A>dcols</A> in <A>dst</A>,
## but without creating an intermediate object and thus
## –at least in special cases–
## much more efficiently.
## <P/>
## For certain objects like compressed vectors this might be significantly
## more efficient if <A>scols</A> and <A>dcols</A> are ranges
## with increment 1.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "CopySubVector",
[ IsVectorObj, IsVectorObj and IsMutable, IsList, IsList ] );
#############################################################################
##
## <#GAPDoc Label="MatObj_WeightOfVector">
## <ManSection>
## <Oper Name="WeightOfVector" Arg="v" Label="for a vector object"/>
## <Returns>an integer</Returns>
## <Description>
## returns the Hamming weight of the vector object <A>v</A>,
## i.e., the number of nonzero entries in <A>v</A>.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "WeightOfVector", [ IsVectorObj ] );
#############################################################################
##
## <#GAPDoc Label="MatObj_DistanceOfVectors">
## <ManSection>
## <Oper Name="DistanceOfVectors" Arg="v1,v2"
## Label="for two vector objects"/>
## <Returns>an integer</Returns>
## <Description>
## returns the Hamming distance of the vector objects <A>v1</A> and
## <A>v2</A>, i.e., the number of entries in which the vectors differ.
## The vectors must have equal length.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "DistanceOfVectors", [ IsVectorObj, IsVectorObj ] );
#############################################################################
##
#O ExtractSubMatrix( <mat>, <rows>, <cols> )
##
## <#GAPDoc Label="ExtractSubMatrix">
## <ManSection>
## <Oper Name="ExtractSubMatrix" Arg='mat, rows, cols'/>
##
## <Description>
## Creates a fully mutable copy of the submatrix described by the two
## lists, which mean subsets of row and column positions, respectively.
## This does <A>mat</A>{<A>rows</A>}{<A>cols</A>} and returns the result.
## It preserves the representation of the matrix.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "ExtractSubMatrix", [ IsMatrixObj, IsList, IsList ] );
#############################################################################
##
#O MutableCopyMatrix( <mat> )
##
## <#GAPDoc Label="MutableCopyMatrix">
## <ManSection>
## <Oper Name="MutableCopyMatrix" Arg='mat' Label="for a matrix object"/>
##
## <Description>
## For a matrix object <A>mat</A>, this operation returns a fully mutable
## copy of <A>mat</A>, with the same
## <Ref Attr="ConstructingFilter" Label="for a matrix object"/> and
## <Ref Attr="BaseDomain" Label="for a matrix object"/> values,
## </Description>