Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions lib/listcoef.gd
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,27 @@ DeclareOperation(
##
## <#GAPDoc Label="MultVector">
## <ManSection>
## <Oper Name="MultVector" Arg='list1, mul'/>
## <Oper Name="MultVectorLeft" Arg='list1, mul'/>
## <Oper Name="MultVector" Arg='list, mul'/>
## <Oper Name="MultVectorLeft" Arg='list, mul'/>
## <Oper Name="MultVectorRight" Arg='list, mul'/>
## <Returns>nothing</Returns>
##
## <Description>
## This operation calculates <A>mul</A>*<A>list1</A> in-place.
## The operation <Ref Oper="MultVectorLeft"/> multiplies the entries of <A>list</A>
## by the scalar <A>mul</A> from the left, in-place.
## <P/>
## The operation <Ref Oper="MultVectorRight"/> multiplies the entries of <A>list</A>
## by the scalar <A>mul</A> from the right, in-place.
## <P/>
## Note that <C>MultVector</C> is just a synonym for
## <C>MultVectorLeft</C>.
## <Example><![CDATA[
## gap> A:= FreeAssociativeAlgebraWithOne( Rationals, "a", "b", "c" );;
## gap> l:=[A.1,A.2];; MultVectorLeft(l, A.3); l;
## [ (1)*c*a, (1)*c*b ]
## gap> l:=[A.1,A.2];; MultVectorRight(l, A.3); l;
## [ (1)*a*c, (1)*b*c ]
## ]]></Example>
## </Description>
## </ManSection>
## <#/GAPDoc>
Expand All @@ -122,7 +134,10 @@ DeclareOperation(
"MultVectorLeft",
[ IsMutable and IsList,
IsObject ] );
# For VectorObj objects there also exists a MultVectorRight operation
DeclareOperation(
"MultVectorRight",
[ IsMutable and IsList,
IsObject ] );
DeclareSynonym( "MultVector", MultVectorLeft );

#############################################################################
Expand Down
64 changes: 52 additions & 12 deletions lib/listcoef.gi
Original file line number Diff line number Diff line change
Expand Up @@ -271,36 +271,76 @@ InstallMethod( MultVectorLeft,
[ IsDenseList and IsMutable,
IsObject ],
function( l, m )
local i;
for i in [ 1 .. Length(l) ] do
local i;
for i in [ 1 .. Length(l) ] do
l[i] := m * l[i];
od;
end );

InstallOtherMethod( MultVectorLeft, "error if immutable",
[ IsList, IsObject ],
L1_IMMUTABLE_ERROR);
L1_IMMUTABLE_ERROR );

InstallMethod( MultVectorLeft,
"kernel method for a mutable dense small list, and an object",
IsCollsElms,
[ IsSmallList and IsDenseList and IsMutable,
IsObject ],
MULT_VECTOR_LEFT_2
);
MULT_VECTOR_LEFT_2 );

InstallMethod( MultVectorLeft,
"kernel method for a mutable dense plain list of \
cyclotomics, and a cyclotomic",
"kernel method for a mutable dense plain list of cyclotomics, and a cyclotomic",
IsCollsElms,
[ IsDenseList and IsMutable and IsPlistRep and IsCyclotomicCollection,
IsCyclotomic ],
MULT_VECTOR_2_FAST
);
MULT_VECTOR_2_FAST );

InstallMethod( MultVectorLeft,
"kernel method for a mutable row vector of ffes in \
plain list rep, and an ffe",
"kernel method for a mutable row vector of ffes in plain list rep, and an ffe",
IsCollsElms,
[ IsRowVector and IsMutable and IsPlistRep and IsFFECollection,
IsFFE],
MULT_VECTOR_VECFFES );


#############################################################################
##
#M MultVectorRight( <list>, <mul> )
##
InstallMethod( MultVectorRight,
"for a mutable dense list, and an object",
[ IsDenseList and IsMutable,
IsObject ],
function( l, m )
local i;
for i in [ 1 .. Length(l) ] do
l[i] := l[i] * m;
od;
end );

InstallOtherMethod( MultVectorRight, "error if immutable",
[ IsList, IsObject ],
L1_IMMUTABLE_ERROR);

InstallMethod( MultVectorRight,
"kernel method for a mutable dense small list, and an object",
IsCollsElms,
[ IsSmallList and IsDenseList and IsMutable,
IsObject ],
MULT_VECTOR_RIGHT_2 );

InstallMethod( MultVectorRight,
"kernel method for a mutable dense plain list of cyclotomics, and a cyclotomic",
IsCollsElms,
[ IsDenseList and IsMutable and IsPlistRep and IsCyclotomicCollection,
IsCyclotomic ],
MULT_VECTOR_2_FAST );

InstallMethod( MultVectorRight,
"kernel method for a mutable row vector of ffes in plain list rep, and an ffe",
IsCollsElms,
[ IsRowVector and IsMutable and IsPlistRep and IsFFECollection,
IsFFE],0,
IsFFE],
MULT_VECTOR_VECFFES );


Expand Down
87 changes: 73 additions & 14 deletions tst/testinstall/MatrixObj/MultVector.tst
Original file line number Diff line number Diff line change
@@ -1,26 +1,83 @@
gap> START_TEST("MultVector.tst");

# Finite Fields
gap> v := NewVector( IsPlistVectorRep, GF(5), [Z(5)^1, Z(5)^2, Z(5)^0, Z(5)^4, 0*Z(5), Z(5)^3 ] );
# Dense plain lists
gap> li := [ 1, -2, 0, 3 ];;
gap> MultVectorRight(li, -2);
gap> li;
[ -2, 4, 0, -6 ]
gap> MultVectorLeft(li, -1);
gap> li;
[ 2, -4, 0, 6 ]

# Plain row vectors of ffes
gap> lf := [ Z(5)^0, Z(5)^1, 0*Z(5), Z(5)^3 ];;
gap> IsRowVector(lf);
true
gap> MultVectorLeft(lf, Z(5)^2);
gap> lf;
[ Z(5)^2, Z(5)^3, 0*Z(5), Z(5) ]
gap> MultVectorRight(lf, Z(5)^3);
gap> lf;
[ Z(5), Z(5)^2, 0*Z(5), Z(5)^0 ]

# Compressed vectors: IsGF2VectorRep
gap> vg2 := NewVector( IsGF2VectorRep, GF(2),
> [ Z(2)^0, 0*Z(2), Z(2)^0, Z(2)^0 ] );;
gap> IsGF2VectorRep(vg2);
true
gap> MultVectorLeft(vg2, Z(2)^0);
gap> Unpack(vg2);
[ Z(2)^0, 0*Z(2), Z(2)^0, Z(2)^0 ]
gap> MultVectorRight(vg2, Z(2)^0);
gap> Unpack(vg2);
[ Z(2)^0, 0*Z(2), Z(2)^0, Z(2)^0 ]

# Compressed vectors: Is8BitVectorRep
gap> vg5 := NewVector( Is8BitVectorRep, GF(5),
> [ Z(5)^0, Z(5)^1, 0*Z(5), Z(5)^3 ] );;
gap> Is8BitVectorRep(vg5);
true
gap> MultVectorLeft(vg5, Z(5)^2);
gap> Unpack(vg5);
[ Z(5)^2, Z(5)^3, 0*Z(5), Z(5) ]
gap> MultVectorRight(vg5, Z(5)^3);
gap> Unpack(vg5);
[ Z(5), Z(5)^2, 0*Z(5), Z(5)^0 ]

# IsPlistVectorRep vectors
gap> vp := NewVector( IsPlistVectorRep, GF(5),
> [ Z(5)^1, Z(5)^2, Z(5)^0, Z(5)^4, 0*Z(5), Z(5)^3 ] );
<plist vector over GF(5) of length 6>
gap> MultVector(v, Z(5)^3);
gap> Unpack(v);
gap> IsPlistVectorRep(vp);
true
gap> MultVectorLeft(vp, Z(5)^3);
gap> Unpack(vp);
[ Z(5)^0, Z(5), Z(5)^3, Z(5)^3, 0*Z(5), Z(5)^2 ]
gap> MultVector(v, -1);
gap> Unpack(v);
[ Z(5)^2, Z(5)^3, Z(5), Z(5), 0*Z(5), Z(5)^0 ]
gap> MultVector(v, Z(5)^3, 3, 4);
gap> Unpack(v);
[ Z(5)^2, Z(5)^3, Z(5)^0, Z(5)^0, 0*Z(5), Z(5)^0 ]

# Integers
gap> n := NewVector( IsPlistVectorRep, Integers, [1,2,0] );
gap> vp := NewVector( IsPlistVectorRep, GF(5),
> [ Z(5)^1, Z(5)^2, Z(5)^0, Z(5)^4, 0*Z(5), Z(5)^3 ] );;
gap> MultVectorRight(vp, Z(5)^3);
gap> Unpack(vp);
[ Z(5)^0, Z(5), Z(5)^3, Z(5)^3, 0*Z(5), Z(5)^2 ]
gap> vp := NewVector( IsPlistVectorRep, GF(5),
> [ Z(5)^1, Z(5)^2, Z(5)^0, Z(5)^4, 0*Z(5), Z(5)^3 ] );;
gap> MultVectorLeft(vp, Z(5)^3, 3, 4);
gap> Unpack(vp);
[ Z(5), Z(5)^2, Z(5)^3, Z(5)^3, 0*Z(5), Z(5)^3 ]
gap> vp := NewVector( IsPlistVectorRep, GF(5),
> [ Z(5)^1, Z(5)^2, Z(5)^0, Z(5)^4, 0*Z(5), Z(5)^3 ] );;
gap> MultVectorRight(vp, Z(5)^3, 3, 4);
gap> Unpack(vp);
[ Z(5), Z(5)^2, Z(5)^3, Z(5)^3, 0*Z(5), Z(5)^3 ]
gap> n := NewVector( IsPlistVectorRep, Integers, [ 1, 2, 0 ] );
<plist vector over Integers of length 3>
gap> IsIntVector(n);
true
gap> MultVector(n, 2);
gap> MultVectorRight(n, 2);
gap> Unpack(n);
[ 2, 4, 0 ]
gap> MultVectorLeft(n, -1);
gap> Unpack(n);
[ -2, -4, 0 ]

# Quaternions: multiplication from left and right
gap> Q := QuaternionAlgebra( Rationals );
Expand All @@ -42,4 +99,6 @@ gap> Unpack(q);
gap> MultVectorLeft(q, Q.2, 3, 4);
gap> Unpack(q);
[ (-1)*e, 0*e, i, j ]

#
gap> STOP_TEST("MultVector.tst");
Loading