Function Repository Resource:

Pfaffian

Source Notebook

Compute the Pfaffian of an antisymmetric (skew-symmetric) matrix

Contributed by: Wolfram Staff (original content by M. Wimmer)

ResourceFunction["Pfaffian"][m]

gives the Pfaffian of a skew-symmetric matrix m.

Details and Options

The Pfaffian of a skew-symmetric matrix m is an integer-coefficient polynomial in the entries of m whose square is the determinant of m.
Skew-symmetric matrices are also called antisymmetric.
ResourceFunction["Pfaffian"] takes the Method option with the following possible values:
"ParlettReid"Parlett–Reid tridiagonalization
"Householder"Householder tridiagonalization
"Hessenberg"Hessenberg decomposition
"Pauli"uses the second Pauli matrix
"Det"uses the built-in Det
The "Householder" and "Hessenberg" methods are applicable only to explicitly-numeric matrices m.
For Method"Hessenberg", the matrix m must be real.
With Method"Pauli", the Pfaffian of a 2n2n matrix m is computed in terms of the eigenvalues of , where σ2 is the second Pauli matrix and In is the n×n identity matrix.
For Method"Det", ResourceFunction["Pfaffian"] is calculated as Sqrt[Det[m]] and is not guaranteed to conform in sign with values obtained by other methods.

Examples

Basic Examples (1) 

Pfaffian of an antisymmetric matrix:

In[1]:=
ResourceFunction["Pfaffian"][( {
    {0, a, b, c},
    {-a, 0, d, e},
    {-b, -d, 0, f},
    {-c, -e, -f, 0}
   } )] // Simplify
Out[1]=

Scope (3) 

The Pfaffian of a real antisymmetric matrix:

In[2]:=
# - Transpose[#] &@RandomReal[1, {6, 6}]
Out[2]=
In[3]:=
ResourceFunction["Pfaffian"][%]
Out[3]=

A complex matrix:

In[4]:=
# - Transpose[#] &@RandomComplex[1 + I, {6, 6}]
Out[4]=
In[5]:=
ResourceFunction["Pfaffian"][%]
Out[5]=

A symbolic matrix:

In[6]:=
ResourceFunction["Pfaffian"][( {
    {0, a, b, c, d, e},
    {-a, 0, f, g, h, i},
    {-b, -f, 0, j, k, l},
    {-c, -g, -j, 0, m, n},
    {-d, -h, -k, -m, 0, o},
    {-e, -i, -l, -n, -o, 0}
   } )] // Simplify
Out[6]=

Options (3) 

Method (3) 

Methods applicable to real matrices:

In[7]:=
mat = (# - Transpose[#]) &@RandomReal[1, {8, 8}]
Out[7]=
In[8]:=
Table[ResourceFunction["Pfaffian"][mat, Method -> method], {method, {"ParlettReid", "Householder", "Hessenberg", "Pauli", "Det"}}]
Out[8]=
In[9]:=
Equal @@ Abs[Chop[%]]
Out[9]=

Methods applicable to complex matrices:

In[10]:=
mat = (# - Transpose[#]) &@RandomComplex[1 + I, {8, 8}];
In[11]:=
Table[ResourceFunction["Pfaffian"][mat, Method -> method], {method, {"ParlettReid", "Householder", "Pauli", "Det"}}]
Out[11]=
In[12]:=
Max[Abs[#1 - #2]/(Abs[#1] + Abs[#2]) & @@@ Subsets[%^2, {2}]]
Out[12]=

Methods applicable to symbolic matrices:

In[13]:=
mat = ( {
   {0, a, b, c, d, e},
   {-a, 0, f, g, h, i},
   {-b, -f, 0, j, k, l},
   {-c, -g, -j, 0, m, n},
   {-d, -h, -k, -m, 0, o},
   {-e, -i, -l, -n, -o, 0}
  } )
Out[13]=
In[14]:=
Table[ResourceFunction["Pfaffian"][mat, Method -> method], {method, {"ParlettReid", "Pauli", "Det"}}] // Simplify
Out[14]=
In[15]:=
SameQ @@ Simplify[%^2]
Out[15]=

Properties and Relations (6) 

The Pfaffian of an antisymmetric matrix of odd dimension is zero:

In[16]:=
ResourceFunction["Pfaffian"][( {
   {0, a, b},
   {-a, 0, c},
   {-b, -c, 0}
  } )]
Out[16]=

For a 2n×2n skew-symmetric matrix m, the Pfaffian of the matrix transpose mT is equal to (-1)nPfaffian[m]:

In[17]:=
AntisymmetricMatrix[symb_, n_] := # - Transpose[#] &@
  SparseArray[{{i_, j_} /; j > i -> Subscript[symb, i, j]}, {2 n, 2 n}]
In[18]:=
n = 3;
In[19]:=
(mat = AntisymmetricMatrix[a, 3]) // MatrixForm
Out[19]=
In[20]:=
SameQ @@ Simplify[{ResourceFunction["Pfaffian"][Transpose[mat]], (-1)^
    n ResourceFunction["Pfaffian"][mat]}]
Out[20]=

For such matrices, the Pfaffian of λm is equal to λnPfaffian[m]:

In[21]:=
SameQ @@ Simplify[{ResourceFunction["Pfaffian"][\[Lambda] mat], \[Lambda]^
    n ResourceFunction["Pfaffian"][mat]}]
Out[21]=

Also, for such matrices, the square of the Pfaffian is equal to the determinant of the matrix:

In[22]:=
SameQ @@ Simplify[{ResourceFunction["Pfaffian"][ mat]^2, Det[mat]}]
Out[22]=

For a 2n×2n skew-symmetric matrix m and an arbitrary 2n×2n matrix x, Pfaffian[x.m.xT]Det[x]*Pfaffian[m]:

In[23]:=
n = 3;
In[24]:=
mat = (# - Transpose[#]) &@RandomReal[1, {2 n, 2 n}]
Out[24]=
In[25]:=
x = RandomReal[1, {2 n, 2 n}]
Out[25]=
In[26]:=
ResourceFunction["Pfaffian"][ x . mat . Transpose[x]] == Det[x] ResourceFunction["Pfaffian"][mat]
Out[26]=

The Pfaffian of a 2n×2n skew-symmetric block diagonal matrix is the product of its non-zero superdiagonal values:

In[27]:=
AntisymmetricBlockDiagonalMatrix[symb_, n_] := # - Transpose[#] &@
  SparseArray[{{i_, j_} /; j - i == 1 && EvenQ[j] -> Subscript[symb, j/2]}, {2 n, 2 n}]
In[28]:=
AntisymmetricBlockDiagonalMatrix[a, 3] // MatrixForm
Out[28]=
In[29]:=
ResourceFunction["Pfaffian"][%]
Out[29]=

The Pfaffian of a 2n×2n skew-symmetric tridiagonal matrix is the product of the entries at odd positions on the superdiagonal:

In[30]:=
AntisymmetricTridiagonalMatrix[symb_, n_] := # - Transpose[#] &@
  SparseArray[{{i_, j_} /; j - i == 1 -> Subscript[symb, j - 1]}, {2 n, 2 n}]
In[31]:=
AntisymmetricTridiagonalMatrix[a, 3] // MatrixForm
Out[31]=
In[32]:=
ResourceFunction["Pfaffian"][%]
Out[32]=

Reducing an antisymmetric matrix to its tridiagonal form gives a numerically stable way to compute the Pfaffian from the superdiagonal values:

In[33]:=
PfaffianTridiagonal[m_] := Times @@ First /@ Partition[Diagonal[m, 1], UpTo[2]]
In[34]:=
mat = (# - Transpose[#]) &@RandomReal[1, {8, 8}]
Out[34]=

Tridiagonalize using the resource function SkewLTLDecomposition:

In[35]:=
{l, t, p} = ResourceFunction["SkewLTLDecomposition"][mat];
In[36]:=
t // MatrixForm
Out[36]=
In[37]:=
PfaffianTridiagonal[t]^2 == ResourceFunction["Pfaffian"][mat]^2
Out[37]=

Using the resource function SkewTridiagonalDecomposition:

In[38]:=
{q, t} = ResourceFunction["SkewTridiagonalDecomposition"][mat];
In[39]:=
t // MatrixForm
Out[39]=
In[40]:=
PfaffianTridiagonal[t]^2 == ResourceFunction["Pfaffian"][mat]^2
Out[40]=

Version History

  • 1.0.0 – 06 November 2020

Source Metadata

Related Resources

License Information