I don't think so, According to Bently there' exists sightly faster algorithm than this, thoughI think the best solution is O(n^3).
i don't know that.
what's pack , i know it as back ,yeah it's used in neural network? I used it to
computing the weights of a MLP.