2
$\begingroup$

This question is a follow-up of my last question.

Summary

The user Henrik Schumacher gave an excellent answer about how to store equations efficiently and solve the associated homogeneous system by using Nullspace. Here, I write again his code. The function cf generate the matrix of coefficients of the linear equations

cf = With[{Part = Compile`GetElement},
   Compile[{{λ, _Real, 2}},
    Block[{f, mm},
     mm = Length[λ];
     f = Table[λ[[i, 1]] λ[[j, 2]] - λ[[i, 2]] λ[[j, 1]], {i, 1, mm}, {j, 1, mm}];
     Flatten@Table[
       f[[i, j]] f[[k, m]] f[[n, p]], {i, 1, mm}, {j, 1, mm}, {k, 1, mm}, {m, 1, mm}, {n, 1, mm}, {p, 1, mm}
       ]
     ],
    CompilationTarget -> "C",
    RuntimeAttributes -> {Listable},
    Parallelization -> True,
    RuntimeOptions -> "Speed"
    ]
   ];

You can then generate 250 equations in one shoot in only 30ms

A = cf[
     Divide[
      Developer`ToPackedArray[
       N[RandomInteger[{-30, 30}, {250, 5, 2}]]],
      Developer`ToPackedArray[N[RandomInteger[{1, 4}, {250, 5}]]]
      ]
     ]; // AbsoluteTiming // First

0.03101

Now we can solve the system numerically with NullSpace in only 7 seconds

nullspace = NullSpace[A]; // AbsoluteTiming // First

7.59116

Question

I find the method suggested by Henrik Schumacher very useful but I am wondering whether I can improve it more. Indeed, the quantity f defined in the body of the function cf is a two rank tensor, anti-symmetric in its indexes. So, in the Table output there a lot of redundant terms. For example, for mm=5, the code generates a matrix with $5^6=15625$ entries. If you consider that f is a rank-2 anti-symmetric matrix in 5 dimension, then only $(10)^3 = 1000$ terms should be computed, which would be a good achievement.

I would like to use the symmetry property of f to further improve the code and speed up the whole process. Indeed, if you only add an extra factor of f[[y,u]] in the Table inside cf, i.e.

     Flatten@Table[
       f[[i, j]] f[[k, m]] f[[n, p]]f[[y,u]], {i, 1, mm}, {j, 1, mm}, {k, 1, mm}, {m, 1, mm}, {n, 1, mm}, {p, 1, mm},{y,1,mm},{u,1,mm}
       ]

then the time to generate the matrix A gets multiplied by a factor of 10 and Mathematica's kernel aborts when evaluating Nullspace.

It is even worse if I add two extra factors of f, in which case Mathematica takes 50 seconds to generate the matrix and i have no hope to compute the NullSpace.

How can I include anti-symmetry of f to simplify the system?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.