Function libwalrus::hafnian_approx

Function Documentation

double libwalrus::hafnian_approx(std::vector<double> &mat, int &nsamples)

Returns the approximation to the hafnian of a matrix with non-negative entries.

The approximation follows an stochastic algorithm according to which the hafnian can be approximated as the sum of determinants of matrices. The accuracy of the approximation increases with increasing number of iterations.

This is a wrapper around the templated function libwalrus::hafnian_nonneg for Python integration. It accepts and returns double numeric types, and returns sensible values for empty and non-even matrices.

In addition, this wrapper function automatically casts all matrices to type long double, allowing for greater precision than supported by Python and NumPy.

Return

the approximate hafnian

Parameters
  • mat: vector representing the flattened matrix

  • nsamples: positive integer representing the number of samples to perform