Skip to content

Commit 68e124d

Browse files
authored
Implemented the method MultVectorRight for lists (#6280)
1 parent e19636f commit 68e124d

File tree

3 files changed

+144
-30
lines changed

3 files changed

+144
-30
lines changed

lib/listcoef.gd

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,27 @@ DeclareOperation(
105105
##
106106
## <#GAPDoc Label="MultVector">
107107
## <ManSection>
108-
## <Oper Name="MultVector" Arg='list1, mul'/>
109-
## <Oper Name="MultVectorLeft" Arg='list1, mul'/>
108+
## <Oper Name="MultVector" Arg='list, mul'/>
109+
## <Oper Name="MultVectorLeft" Arg='list, mul'/>
110+
## <Oper Name="MultVectorRight" Arg='list, mul'/>
110111
## <Returns>nothing</Returns>
111112
##
112113
## <Description>
113-
## This operation calculates <A>mul</A>*<A>list1</A> in-place.
114+
## The operation <Ref Oper="MultVectorLeft"/> multiplies the entries of <A>list</A>
115+
## by the scalar <A>mul</A> from the left, in-place.
116+
## <P/>
117+
## The operation <Ref Oper="MultVectorRight"/> multiplies the entries of <A>list</A>
118+
## by the scalar <A>mul</A> from the right, in-place.
114119
## <P/>
115120
## Note that <C>MultVector</C> is just a synonym for
116121
## <C>MultVectorLeft</C>.
122+
## <Example><![CDATA[
123+
## gap> A:= FreeAssociativeAlgebraWithOne( Rationals, "a", "b", "c" );;
124+
## gap> l:=[A.1,A.2];; MultVectorLeft(l, A.3); l;
125+
## [ (1)*c*a, (1)*c*b ]
126+
## gap> l:=[A.1,A.2];; MultVectorRight(l, A.3); l;
127+
## [ (1)*a*c, (1)*b*c ]
128+
## ]]></Example>
117129
## </Description>
118130
## </ManSection>
119131
## <#/GAPDoc>
@@ -122,7 +134,10 @@ DeclareOperation(
122134
"MultVectorLeft",
123135
[ IsMutable and IsList,
124136
IsObject ] );
125-
# For VectorObj objects there also exists a MultVectorRight operation
137+
DeclareOperation(
138+
"MultVectorRight",
139+
[ IsMutable and IsList,
140+
IsObject ] );
126141
DeclareSynonym( "MultVector", MultVectorLeft );
127142

128143
#############################################################################

lib/listcoef.gi

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -271,36 +271,76 @@ InstallMethod( MultVectorLeft,
271271
[ IsDenseList and IsMutable,
272272
IsObject ],
273273
function( l, m )
274-
local i;
275-
for i in [ 1 .. Length(l) ] do
274+
local i;
275+
for i in [ 1 .. Length(l) ] do
276276
l[i] := m * l[i];
277277
od;
278278
end );
279+
279280
InstallOtherMethod( MultVectorLeft, "error if immutable",
280281
[ IsList, IsObject ],
281-
L1_IMMUTABLE_ERROR);
282+
L1_IMMUTABLE_ERROR );
282283

283284
InstallMethod( MultVectorLeft,
284285
"kernel method for a mutable dense small list, and an object",
285286
IsCollsElms,
286287
[ IsSmallList and IsDenseList and IsMutable,
287288
IsObject ],
288-
MULT_VECTOR_LEFT_2
289-
);
289+
MULT_VECTOR_LEFT_2 );
290+
290291
InstallMethod( MultVectorLeft,
291-
"kernel method for a mutable dense plain list of \
292-
cyclotomics, and a cyclotomic",
292+
"kernel method for a mutable dense plain list of cyclotomics, and a cyclotomic",
293293
IsCollsElms,
294294
[ IsDenseList and IsMutable and IsPlistRep and IsCyclotomicCollection,
295295
IsCyclotomic ],
296-
MULT_VECTOR_2_FAST
297-
);
296+
MULT_VECTOR_2_FAST );
297+
298298
InstallMethod( MultVectorLeft,
299-
"kernel method for a mutable row vector of ffes in \
300-
plain list rep, and an ffe",
299+
"kernel method for a mutable row vector of ffes in plain list rep, and an ffe",
300+
IsCollsElms,
301+
[ IsRowVector and IsMutable and IsPlistRep and IsFFECollection,
302+
IsFFE],
303+
MULT_VECTOR_VECFFES );
304+
305+
306+
#############################################################################
307+
##
308+
#M MultVectorRight( <list>, <mul> )
309+
##
310+
InstallMethod( MultVectorRight,
311+
"for a mutable dense list, and an object",
312+
[ IsDenseList and IsMutable,
313+
IsObject ],
314+
function( l, m )
315+
local i;
316+
for i in [ 1 .. Length(l) ] do
317+
l[i] := l[i] * m;
318+
od;
319+
end );
320+
321+
InstallOtherMethod( MultVectorRight, "error if immutable",
322+
[ IsList, IsObject ],
323+
L1_IMMUTABLE_ERROR);
324+
325+
InstallMethod( MultVectorRight,
326+
"kernel method for a mutable dense small list, and an object",
327+
IsCollsElms,
328+
[ IsSmallList and IsDenseList and IsMutable,
329+
IsObject ],
330+
MULT_VECTOR_RIGHT_2 );
331+
332+
InstallMethod( MultVectorRight,
333+
"kernel method for a mutable dense plain list of cyclotomics, and a cyclotomic",
334+
IsCollsElms,
335+
[ IsDenseList and IsMutable and IsPlistRep and IsCyclotomicCollection,
336+
IsCyclotomic ],
337+
MULT_VECTOR_2_FAST );
338+
339+
InstallMethod( MultVectorRight,
340+
"kernel method for a mutable row vector of ffes in plain list rep, and an ffe",
301341
IsCollsElms,
302342
[ IsRowVector and IsMutable and IsPlistRep and IsFFECollection,
303-
IsFFE],0,
343+
IsFFE],
304344
MULT_VECTOR_VECFFES );
305345

306346

Lines changed: 73 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,83 @@
11
gap> START_TEST("MultVector.tst");
22

3-
# Finite Fields
4-
gap> v := NewVector( IsPlistVectorRep, GF(5), [Z(5)^1, Z(5)^2, Z(5)^0, Z(5)^4, 0*Z(5), Z(5)^3 ] );
3+
# Dense plain lists
4+
gap> li := [ 1, -2, 0, 3 ];;
5+
gap> MultVectorRight(li, -2);
6+
gap> li;
7+
[ -2, 4, 0, -6 ]
8+
gap> MultVectorLeft(li, -1);
9+
gap> li;
10+
[ 2, -4, 0, 6 ]
11+
12+
# Plain row vectors of ffes
13+
gap> lf := [ Z(5)^0, Z(5)^1, 0*Z(5), Z(5)^3 ];;
14+
gap> IsRowVector(lf);
15+
true
16+
gap> MultVectorLeft(lf, Z(5)^2);
17+
gap> lf;
18+
[ Z(5)^2, Z(5)^3, 0*Z(5), Z(5) ]
19+
gap> MultVectorRight(lf, Z(5)^3);
20+
gap> lf;
21+
[ Z(5), Z(5)^2, 0*Z(5), Z(5)^0 ]
22+
23+
# Compressed vectors: IsGF2VectorRep
24+
gap> vg2 := NewVector( IsGF2VectorRep, GF(2),
25+
> [ Z(2)^0, 0*Z(2), Z(2)^0, Z(2)^0 ] );;
26+
gap> IsGF2VectorRep(vg2);
27+
true
28+
gap> MultVectorLeft(vg2, Z(2)^0);
29+
gap> Unpack(vg2);
30+
[ Z(2)^0, 0*Z(2), Z(2)^0, Z(2)^0 ]
31+
gap> MultVectorRight(vg2, Z(2)^0);
32+
gap> Unpack(vg2);
33+
[ Z(2)^0, 0*Z(2), Z(2)^0, Z(2)^0 ]
34+
35+
# Compressed vectors: Is8BitVectorRep
36+
gap> vg5 := NewVector( Is8BitVectorRep, GF(5),
37+
> [ Z(5)^0, Z(5)^1, 0*Z(5), Z(5)^3 ] );;
38+
gap> Is8BitVectorRep(vg5);
39+
true
40+
gap> MultVectorLeft(vg5, Z(5)^2);
41+
gap> Unpack(vg5);
42+
[ Z(5)^2, Z(5)^3, 0*Z(5), Z(5) ]
43+
gap> MultVectorRight(vg5, Z(5)^3);
44+
gap> Unpack(vg5);
45+
[ Z(5), Z(5)^2, 0*Z(5), Z(5)^0 ]
46+
47+
# IsPlistVectorRep vectors
48+
gap> vp := NewVector( IsPlistVectorRep, GF(5),
49+
> [ Z(5)^1, Z(5)^2, Z(5)^0, Z(5)^4, 0*Z(5), Z(5)^3 ] );
550
<plist vector over GF(5) of length 6>
6-
gap> MultVector(v, Z(5)^3);
7-
gap> Unpack(v);
51+
gap> IsPlistVectorRep(vp);
52+
true
53+
gap> MultVectorLeft(vp, Z(5)^3);
54+
gap> Unpack(vp);
855
[ Z(5)^0, Z(5), Z(5)^3, Z(5)^3, 0*Z(5), Z(5)^2 ]
9-
gap> MultVector(v, -1);
10-
gap> Unpack(v);
11-
[ Z(5)^2, Z(5)^3, Z(5), Z(5), 0*Z(5), Z(5)^0 ]
12-
gap> MultVector(v, Z(5)^3, 3, 4);
13-
gap> Unpack(v);
14-
[ Z(5)^2, Z(5)^3, Z(5)^0, Z(5)^0, 0*Z(5), Z(5)^0 ]
15-
16-
# Integers
17-
gap> n := NewVector( IsPlistVectorRep, Integers, [1,2,0] );
56+
gap> vp := NewVector( IsPlistVectorRep, GF(5),
57+
> [ Z(5)^1, Z(5)^2, Z(5)^0, Z(5)^4, 0*Z(5), Z(5)^3 ] );;
58+
gap> MultVectorRight(vp, Z(5)^3);
59+
gap> Unpack(vp);
60+
[ Z(5)^0, Z(5), Z(5)^3, Z(5)^3, 0*Z(5), Z(5)^2 ]
61+
gap> vp := NewVector( IsPlistVectorRep, GF(5),
62+
> [ Z(5)^1, Z(5)^2, Z(5)^0, Z(5)^4, 0*Z(5), Z(5)^3 ] );;
63+
gap> MultVectorLeft(vp, Z(5)^3, 3, 4);
64+
gap> Unpack(vp);
65+
[ Z(5), Z(5)^2, Z(5)^3, Z(5)^3, 0*Z(5), Z(5)^3 ]
66+
gap> vp := NewVector( IsPlistVectorRep, GF(5),
67+
> [ Z(5)^1, Z(5)^2, Z(5)^0, Z(5)^4, 0*Z(5), Z(5)^3 ] );;
68+
gap> MultVectorRight(vp, Z(5)^3, 3, 4);
69+
gap> Unpack(vp);
70+
[ Z(5), Z(5)^2, Z(5)^3, Z(5)^3, 0*Z(5), Z(5)^3 ]
71+
gap> n := NewVector( IsPlistVectorRep, Integers, [ 1, 2, 0 ] );
1872
<plist vector over Integers of length 3>
1973
gap> IsIntVector(n);
2074
true
21-
gap> MultVector(n, 2);
75+
gap> MultVectorRight(n, 2);
2276
gap> Unpack(n);
2377
[ 2, 4, 0 ]
78+
gap> MultVectorLeft(n, -1);
79+
gap> Unpack(n);
80+
[ -2, -4, 0 ]
2481

2582
# Quaternions: multiplication from left and right
2683
gap> Q := QuaternionAlgebra( Rationals );
@@ -42,4 +99,6 @@ gap> Unpack(q);
4299
gap> MultVectorLeft(q, Q.2, 3, 4);
43100
gap> Unpack(q);
44101
[ (-1)*e, 0*e, i, j ]
102+
103+
#
45104
gap> STOP_TEST("MultVector.tst");

0 commit comments

Comments
 (0)