bridge/class-master/depend/pari/src/basemath/RgV.c
/*                    ADDITION SCALAR + MATRIX                     */
/* x square matrix, y scalar; create the square matrix x + y*Id */
ADDITION SCALAR + MATRIX
x square matrix, y scalar; create the square matrix x + y*Id
ADDITION SCALAR + MATRIX x square matrix y scalar ; create the square matrix x + y * Id
GEN
RgM_Rg_add(GEN x, GEN y)
{
  long l = lg(x), i, j;
  GEN z = cgetg(l,t_MAT);
  if (l==1) return z;
  if (l != lgcols(x)) pari_err_OP( "+", x, y);
  z = cgetg(l,t_MAT);
  for (i=1; i<l; i++)
  {
    GEN zi = cgetg(l,t_COL), xi = gel(x,i);
    gel(z,i) = zi;
    for (j=1; j<l; j++)
      gel(zi,j) = i==j? gadd(y,gel(xi,j)): gcopy(gel(xi,j));
  }
  return z;
}
GEN RgM_Rg_add ( GEN x , GEN y ) { long l = lg ( x ) , i , j ; GEN z = cgetg ( l , t_MAT ) ; if ( l == 1 ) return z ; if ( l != lgcols ( x ) ) pari_err_OP ( " " , x , y ) ; z = cgetg ( l , t_MAT ) ; for ( i = 1 ; i < l ; i ++ ) { GEN zi = cgetg ( l , t_COL ) , xi = gel ( x , i ) ; gel ( z , i ) = zi ; for ( j = 1 ; j < l ; j ++ ) gel ( zi , j ) = i == j ? gadd ( y , gel ( xi , j ) ) : gcopy ( gel ( xi , j ) ) ; } return z ; }
ADDITION SCALAR + MATRIX
x square matrix, y scalar; create the square matrix x + y*Id
ADDITION SCALAR + MATRIX x square matrix y scalar ; create the square matrix x + y * Id