Function Repository Resource:

Compute the adjacency tensor of an arbitrary hypergraph

Contributed by: Jonathan Gorard
 ResourceFunction["AdjacencyTensor"][h] gives the vertex adjacency tensor of the (ordered or orderless) hypergraph h.

## Details and Options

An adjacency tensor is a generalization of the concept of an adjacency matrix from graphs to hypergraphs, in which hyperedges may be of arbitrary arity.
The rank of the adjacency tensor is equal to the arity of the hyperedges in the hypergraph.
The adjacency tensor for a hypergraph will have dimensions n×n××n, where n is the number of vertices.
ResourceFunction["AdjacencyTensor"] returns a SparseArray object, which can be converted into ordinary nested lists using Normal.
Each entry aij…k of the adjacency tensor represents the number of hyperedges of the form {vi,vj,,vk}.
The diagonal entries aii…i count the number of self-loops for each vertex vi.
 "OrderedHyperedges" False whether to treat hyperedges as being ordered (directed)
When all hyperedges are of arity 2, the output of ResourceFunction["AdjacencyTensor"] is identical to that of AdjacencyMatrix.

## Examples

### Basic Examples (3)

The adjacency tensor of an orderless hypergraph, with hyperedges of arity 3:

 In[1]:=
 Out[1]=
 In[2]:=
 Out[2]=

The adjacency tensor of an ordered hypergraph, with hyperedges of arity 3:

 In[3]:=
 Out[3]=
 In[4]:=
 Out[4]=

The adjacency tensor of an orderless hypergraph, with hyperedges of arity 5:

 In[5]:=
 Out[5]=

### Scope (6)

AdjacencyTensor supports multihypergraphs, in which case the tensor entries represent hyperedge multiplicities:

 In[6]:=
 Out[6]=
 In[7]:=
 Out[7]=

When the arity of hyperedges is equal to 2, the output of AdjacencyTensor is identical to the output of AdjacencyMatrix:

 In[8]:=
 Out[8]=
 In[9]:=
 Out[9]=
 In[10]:=
 Out[10]=

The adjacency tensor of an orderless hypergraph is always symmetric across all indices:

 In[11]:=
 Out[11]=
 In[12]:=
 Out[12]=

The adjacency tensor of an ordered hypergraph is not necessarily symmetric across all indices:

 In[13]:=
 Out[13]=
 In[14]:=
 Out[14]=

The adjacency tensor of a hypergraph with self-loops has diagonal entries:

 In[15]:=
 Out[15]=
 In[16]:=
 Out[16]=
 In[17]:=
 Out[17]=

Hyperedges can be of arbitrary arity:

 In[18]:=
 Out[18]=

### Options (2)

By default, all hyperedges are treated as orderless (i.e. undirected):

 In[19]:=
 Out[19]=
 In[20]:=
 Out[20]=

Use "OrderedHyperedges"True to treat hyperedges as ordered (i.e. directed):

 In[21]:=
 Out[21]=
 In[22]:=
 Out[22]=

Jonathan Gorard

## Version History

• 1.0.0 – 17 March 2021