[R] Permanent of a matrix Hello all, Does anyone know of a function for calculating the permanent of a matrix?  I have found only the function for calculating a matrix's determinant,  and my beginner attempts to figure out a working script (see below) have  failed.  (That is, I don't get the same answer as when I calculate the  permanent in Maple or Mathematica.) My understanding and experience is that it can be an exceedingly  difficult (memory intensive) calculation for matrices larger than ~24x24  (which also suggests that there is something wrong in the way I've coded  this) but I can't seem to figure out where my error lies; whether it's  in my code or in my understanding of how a matrix permanent is defined. Thanks in advance -Mark perm<-function(A){        m<-dim(A)[1]     M1<-dim(0)     for (i in  1:nrow(A)){temp.M<-c(A)[i+0:(m-i)*(m+1)];M1<-c(M1,prod(temp.M))}         M2<-dim(0)     for (i in  2:nrow(A)){temp.M<-c(t(A))[i+0:(m-i)*(m+1)];M2<-c(M2,prod(temp.M))}         B<-A[nrow(A):1,]     M3<-dim(0)     for (i in  1:nrow(B)){temp.M<-c(B)[i+0:(m-i)*(m+1)];M3<-c(M3,prod(temp.M))}         M4<-dim(0)     for (i in  2:nrow(B)){temp.M<-c(t(B))[i+0:(m-i)*(m+1)];M4<-c(M4,prod(temp.M))}         Perm<-sum(M1,M2,M3,M4)     Perm } S<-4 A<-array(seq(1,S^2),dim=c(S,S)) perm(A) --    ~~~~~~~~~~~~~~~~~~~~~~~~~~ Dept. of Ecology & Evolution 1101 E. 57th St., U. of Chicago Chicago, IL 60637 Office/Lab: 773-702-4815 Cell: 773-256-8645 Fax: 773-702-9740 http://home.uchicago.edu/~mnovak/  ~~~~~~~~~~~~~~~~~~~~~~~~~~ ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.