M2 icon indicating copy to clipboard operation
M2 copied to clipboard

Hom trims unnecessarily

Open mahrud opened this issue 1 year ago • 0 comments

The key line in Hom(M, N) runs:

     H := trim kernel (transpose presentation M ** N);

I suspect trim is there to remove generators that give zero homomorphisms, for example. However, this trim can be very slow without even changing the result. Here is an example:

R = quotient Grassmannian(1,3, CoefficientRing => ZZ/3);
X = Proj R;
-- blackbox what N is, but it has 97 generators and 32 relations
N = module frobeniusPushforward(1, OO_X); -- rank 81
M = R^{0,-1, 43:-1, 52:-2}; -- rank 97

Now compare:

i13 : elapsedTime H = kernel (transpose presentation M ** N);
 -- 0.0469308 seconds elapsed

i14 : elapsedTime H' = trim H;
 -- 167.708 seconds elapsed

i15 : betti H', betti H

                 0    1            0    1
o15 = (total: 9409 3104, total: 9409 3104)
          -2:   52    .     -2:   52    .
          -1: 2332    .     -1: 2332    .
           0: 4641 1664      0: 4641 1664
           1: 2332 1408      1: 2332 1408
           2:   52   32      2:   52   32

Which means that there was nothing to trim, but nearly 3 minutes (almost 100% of the computation) was a time waste.

I can think of two solutions:

  1. add an optional argument MinimalGenerators for Hom, perhaps set to false by default, which determines whether to trim the result;
  2. never trim the result and leave it to the user to do that.

As an aside, we should do this anyway:

  • fix prune and trim to keep cached homomorphism, formation, components, etc. if present (what other cached results are important to keep?)

mahrud avatar Dec 14 '23 14:12 mahrud