[GAP Forum] suggestion for additional core operations on polynomials and lists
kroeker
kroeker at uni-math.gwdg.de
Wed May 30 18:19:56 BST 2012
Dear GAP-team,
recently I extensively used polynomials, lists and methods to
manipulate them.
From this experience I would like to suggest to add some of the
following manipulation and access methods to the GAP-core:
- get or set the coefficient of a specified monomial in a polynomial. (
'get' parameters: polynomial and the monomial of interest )
- get coefficients for a list of monomials of interest.
- get the nonzero-coefficients as a list.
- flatten a list
( e.g. Flatten( [ 2,[ 3,[4] ] ] ) => [ 2, 3, [4] ] ; Flatten( [
2, 3, [4] ] ) => [ 2, 3, 4 ] );
Some initial implementations are given below.
Any remarks, comments related to this suggestion?
Thanks,
Jakob
DeclareOperation("Flatten", [IsList] );
# Example: [ [1,[2] ],[1] ] changes to [1,[2], 1] changes to [1,2,1] .
InstallMethod(Flatten, "remove the top level nesting ", [IsList],
function(list)
local result, entry;
Assert( 0, IsList(list) );
result := [];
for entry in list do
if IsList(entry) then
Append( result, entry );
else
Append( result, [entry] );
fi;
od;
return result;
end
);
# todo: check that polynomial and monomial are in the same ring.
DeclareOperation( "getCoefficientOfMonomial", [ IsPolynomial,
IsPolynomial ] );
InstallMethod( getCoefficientOfMonomial, " get the coefficient of a
polynomial ", [IsPolynomial, IsPolynomial] ,
function( polynomial, monomial )
local monomData, coeffData, pos;
monomData := ExtRepPolynomialRatFun(monomial);
if Size(monomData) <>2 then
Error( Concatenation( "\"getCoefficientOfMonomial\": the
second parameter (' ", String(monomial), " ') has to be a monomial!") );
fi;
Assert( 0, Size(monomData) =2 );
coeffData := ExtRepPolynomialRatFun(polynomial);
for pos in [1..Size(coeffData)/2] do
if coeffData[pos*2-1]=monomData[1] then
return coeffData[pos*2];
fi;
od;
return Zero( CoefficientsFamily(FamilyObj(polynomial)) ) ;
end
);
DeclareOperation( "getNonzeroCoefficientList", [ IsPolynomial ] );
InstallMethod( getNonzeroCoefficientList, " get the nonzero coefficients
of a polynomial ", [ IsPolynomial ] ,
function( polynomial )
local coeffList, coeffData, pos;
coeffList := [];
coeffData := ExtRepPolynomialRatFun(polynomial);
for pos in [1..Size(coeffData)/2] do
Append(coeffList, [ coeffData[pos*2] ]);
od;
return coeffList;
end
);
More information about the Forum
mailing list