23.3 Coefficient List Arithmetic

The following operations all perform arithmetic on row vectors. given as homogeneous lists of the same length, containing elements of a commutative ring.

There are two reasons for using AddRowVector in preference to arithmetic operators. Firstly, the three argument form has no single-step equaivalent. Secondly AddRowVector changes its first argument in-place, rather than allocating a new vector to hold the result, and may thus produce less garbage

  • AddRowVector( dst, src, [mul[, from, to]] ) O

    Adds the product of src and mul to dst, changing dst. If from and to are given then only the index range [from..to] is guaranteed to be affected. Other indices MAY be affected, if it is more convenient to do so. Even when from and to are given, dst and src must be row vectors of the same length

    If mul is not given either then this Operation simply adds src to dst

  • AddCoeffs( list1, poss1, list2, poss2, mul ) O
  • AddCoeffs( list1, list2, mul ) O
  • AddCoeffs( list1, list2 ) O

    AddCoeffs adds the entries of list2{poss2}, multiplied by the scalar mul, to list1{poss1}. Non-existing entries in list1 are assumed to be zero. The position of the right-most non-zero element is returned.

    If the ranges poss1 and poss2 are not given, they are assumed to span the whole vectors. If the scalar mul is omitted, one is used as a default.

    Note that it is the responsibility of the caller to ensure that the list2 has elements at position poss2 and that the result (in list1) will be a dense list.

    The function is free to remove trailing (right-most) zeros.

    gap> l:=[1,2,3,4];;m:=[5,6,7];;AddCoeffs(l,m);
    4
    gap> l;
    [ 6, 8, 10, 4 ]
    

  • MultRowVector( list1, poss1, list2, poss2, mul ) O
  • MultRowVector( list, mul ) O

    The five-argument version of this Operation replaces list1[poss1[i]] by mul*list2[poss2[i]] for i between 1 and Length(poss1)

    The two-argument version simply multiplies each element of list, in-place, by mul

  • CoeffsMod( list1, [len1, ]mod ) O

    returns the coefficient list obtained by reducing the entries in list1 modulo mod. After reducing it shrinks the list to remove trailing zeroes.

    gap> l:=[1,2,3,4];;CoeffsMod(l,2);
    [ 1, 0, 1 ]
    

    [Top] [Previous] [Up] [Next] [Index]

    GAP 4 manual
    February 2000